caipin %!s(int64=4) %!d(string=hai) anos
pai
achega
34a08949f3

+ 7 - 2
dao/tree_contract_dao.go

@@ -75,7 +75,7 @@ func (d *TreeContractDao) GetElderBrother(serial int, depth int, parentId int, b
 	datalist := make([]models.CmTreeContracts, 0)
 	err := d.engine.
 		Desc("serial").
-		Where("serial < ? and depth = ? and bidsection_id=?  and project_id=?", serial, depth, bidsectionId, projectId).
+		Where("serial < ? and depth = ? and  parent_id =? and bidsection_id=?  and project_id=?", serial, depth, parentId, bidsectionId, projectId).
 		Find(&datalist)
 	if err != nil {
 		return datalist
@@ -89,7 +89,7 @@ func (d *TreeContractDao) GetYoungerBrother(serial int, depth int, parentId int,
 	datalist := make([]models.CmTreeContracts, 0)
 	err := d.engine.
 		Asc("serial").
-		Where("serial > ? and depth = ? and bidsection_id=?  and project_id=?", serial, depth, bidsectionId, projectId).
+		Where("serial > ? and depth = ? and  parent_id =? and bidsection_id=?   and project_id=?", serial, depth, parentId, bidsectionId, projectId).
 		Find(&datalist)
 	if err != nil {
 		return datalist
@@ -236,6 +236,11 @@ func (d *TreeContractDao) MoveSerial(section *models.CmTreeContracts, brother *m
 		return errors.New("操作失败-db")
 	}
 
+	fmt.Println(brother.BidsectionId)
+
+	fmt.Println(section.Id)
+	fmt.Println(brother.Id)
+
 	//1.上下移
 	// 1.项目节序号替换为兄弟序号
 	_, err = session.Exec("UPDATE  cm_tree_contracts SET  serial = ? , `code` = replace(`code`, '"+section.Code+"', '"+brother.Code+"')  where id = ? ", brother.Serial, section.Id)

+ 60 - 41
services/contract_section_tree_service.go

@@ -17,53 +17,21 @@ import (
 
 // 获得合同项目节
 func (s *contractService) GetSecionTree(bidsectionId int, projectId int) *viewmodels.TreeSectionContract {
-	sectionList := make([]*viewmodels.TreeSectionContract, 0)
 	dataList := s.treeContractDao.GetAll(bidsectionId, projectId)
-	// 生成根
-	sectionRoot := &viewmodels.TreeSectionContract{}
-	id, _ := comm.AesEncrypt(strconv.Itoa(0), conf.SignSecret)
-	parentId, _ := comm.AesEncrypt(strconv.Itoa(-1), conf.SignSecret)
-	sectionRoot.Id = id
-	sectionRoot.Name = "root"
-	sectionRoot.ParentId = parentId
-	sectionList = append(sectionList, sectionRoot)
-	for _, data := range dataList {
-		section := &viewmodels.TreeSectionContract{}
-		id, _ := comm.AesEncrypt(strconv.Itoa(data.TreeId), conf.SignSecret)
-		parentId, _ := comm.AesEncrypt(strconv.Itoa(data.ParentId), conf.SignSecret)
-		projectId, _ := comm.AesEncrypt(strconv.Itoa(data.ProjectId), conf.SignSecret)
-		contractId, _ := comm.AesEncrypt(strconv.Itoa(data.ContractId), conf.SignSecret)
-		bidsectionId, _ := comm.AesEncrypt(strconv.Itoa(data.BidsectionId), conf.SignSecret)
-		section.Id = id
-		section.Name = data.Name
-		section.ParentId = parentId
-		section.Depth = data.Depth + 1
-		section.Serial = data.Serial
-		section.Attribution = data.Attribution
-		section.Code = data.Code
-		section.ProjectId = projectId
-		section.BidsectionId = bidsectionId
-		section.ContractId = contractId
-
-		section.ElderBrother = true
-		section.IsEnd = false
-
-		section.Name = data.Name
-		section.ContractCode = data.ContractCode
-		section.ContractPrice = data.ContractPrice
-		section.ContractReturned = data.ContractReturned
-		section.ContractsPaid = data.ContractsPaid
-		section.ContractStatus = data.ContractStatus
-
-		section.CreateTime = data.CreateTime.Format(conf.SysTimeform)
-		sectionList = append(sectionList, section)
-	}
+	sectionList := s.makeSectionTreeView(dataList)
 
-	Node := sectionRoot //父节点
+	// Node := sectionRoot //父节点
+	Node := sectionList[0] //父节点
 	comm.MakeSectionContract(sectionList, Node)
 	return Node
 }
 
+// 获得项目节树和孩子们下的合同数据
+func (s *contractService) GetSectionTreeContract(attribution string, bidsectionId int, projectId int) []*viewmodels.Contracts {
+	s.treeContractDao.GetAttribution(attribution, bidsectionId, projectId)
+	return nil
+}
+
 // 设置合同项目节初始数据-根据模板导入
 func (s *contractService) SetSection(templateNumber int, bidsectionId int, projectId int) error {
 	// 获得模板数据
@@ -268,3 +236,54 @@ func (s *contractService) MoveSerial(sectionData *viewmodels.TreeSectionContract
 	}
 	return nil
 }
+
+// 构造项目节树
+func (s *contractService) makeSectionTreeView(dataList []models.CmTreeContracts) []*viewmodels.TreeSectionContract {
+	sectionList := make([]*viewmodels.TreeSectionContract, 0)
+	// 生成根
+	sectionRoot := &viewmodels.TreeSectionContract{}
+	id, _ := comm.AesEncrypt(strconv.Itoa(0), conf.SignSecret)
+	parentId, _ := comm.AesEncrypt(strconv.Itoa(-1), conf.SignSecret)
+	sectionRoot.Id = id
+	sectionRoot.Name = "root"
+	sectionRoot.ParentId = parentId
+	sectionList = append(sectionList, sectionRoot)
+	for _, data := range dataList {
+		section := s.makeSectionView(&data)
+		sectionList = append(sectionList, section)
+	}
+	return sectionList
+}
+
+// 构造一个项目节View
+func (s *contractService) makeSectionView(data *models.CmTreeContracts) *viewmodels.TreeSectionContract {
+	section := &viewmodels.TreeSectionContract{}
+	id, _ := comm.AesEncrypt(strconv.Itoa(data.TreeId), conf.SignSecret)
+	parentId, _ := comm.AesEncrypt(strconv.Itoa(data.ParentId), conf.SignSecret)
+	projectId, _ := comm.AesEncrypt(strconv.Itoa(data.ProjectId), conf.SignSecret)
+	contractId, _ := comm.AesEncrypt(strconv.Itoa(data.ContractId), conf.SignSecret)
+	bidsectionId, _ := comm.AesEncrypt(strconv.Itoa(data.BidsectionId), conf.SignSecret)
+	section.Id = id
+	section.Name = data.Name
+	section.ParentId = parentId
+	section.Depth = data.Depth + 1
+	section.Serial = data.Serial
+	section.Attribution = data.Attribution
+	section.Code = data.Code
+	section.ProjectId = projectId
+	section.BidsectionId = bidsectionId
+	section.ContractId = contractId
+
+	section.ElderBrother = true
+	section.IsEnd = false
+
+	section.Name = data.Name
+	section.ContractCode = data.ContractCode
+	section.ContractPrice = data.ContractPrice
+	section.ContractReturned = data.ContractReturned
+	section.ContractsPaid = data.ContractsPaid
+	section.ContractStatus = data.ContractStatus
+
+	section.CreateTime = data.CreateTime.Format(conf.SysTimeform)
+	return section
+}

+ 7 - 3
services/contract_service.go

@@ -25,6 +25,7 @@ type ContractService interface {
 
 	Get(treeId int, bidsectionId int, projectId int) *viewmodels.TreeSectionContract
 	GetAll()
+	GetSectionTreeContract(attribution string, bidsectionId int, projectId int) []*viewmodels.Contracts
 	GetSecionTree(bidsectionId int, projectId int) *viewmodels.TreeSectionContract
 	SetSection(templateNumber int, bidsectionId int, projectIdInt int) error
 	SectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error
@@ -113,7 +114,7 @@ func (s *contractService) ValidRuleSectionAdd(ctx iris.Context) (*viewmodels.Tre
 // 模板规则新增项目节
 func (s *contractService) ValidRuleSectionDelete(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
 	treeSectionVaild := &viewmodels.TreeSectionContract{}
-	err := ctx.ReadJSON(treeSectionVaild)
+	err := ctx.ReadForm(treeSectionVaild)
 	if err != nil {
 		log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
 		return treeSectionVaild, err
@@ -146,8 +147,11 @@ func (s *contractService) ValidRuleGet(ctx iris.Context) (*viewmodels.TreeSectio
 
 // 获得项目节
 func (s *contractService) Get(treeId int, bidsectionId int, projectId int) *viewmodels.TreeSectionContract {
-
-	return nil
+	// 1.获得项目节
+	section := s.treeContractDao.Get(treeId, bidsectionId, projectId)
+	// 2.构造数据
+	sectionVM := s.makeSectionView(section)
+	return sectionVM
 }
 
 // 获得合同标段内容

+ 4 - 4
services/project_account_service.go

@@ -121,10 +121,10 @@ func (s *projectAccountService) GetAll(projectId int) []viewmodels.ProjectAccoun
 	accountList := s.dao.GetAll(projectId)
 	accountListVM := make([]viewmodels.ProjectAccount, 0)
 	for _, data := range accountList {
-		if data.IsAdmin != 1 {
-			account := comm.MakeProjectAccountVM(&data)
-			accountListVM = append(accountListVM, account)
-		}
+		//if data.IsAdmin != 1 {
+		account := comm.MakeProjectAccountVM(&data)
+		accountListVM = append(accountListVM, account)
+		//}
 	}
 	return accountListVM
 }

+ 23 - 7
web/api/contract_api.go

@@ -7,8 +7,6 @@
 package api
 
 import (
-	"fmt"
-
 	"github.com/kataras/iris/v12"
 	"go.mod/lib"
 	"go.mod/services"
@@ -144,12 +142,30 @@ func (c *ContractApi) Get() {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
 		return
 	}
-	fmt.Println(projectId)
-	fmt.Println(bidsectionId)
-	fmt.Println(treeId)
+
 	// 获得项目节详情
-	c.ServiceContract.GetAll()
-	// 获得合同详情
+	section := c.ServiceContract.Get(treeId, bidsectionId, projectId)
+
+	// 该项目节 子树下是否有合同
+	isContract := true
+	contractList := c.ServiceContract.GetSectionTreeContract(section.Attribution, bidsectionId, projectId)
+	if len(contractList) == 0 {
+		isContract = false
+	}
+	// // 获得合同详情
+	// contractId, err := utils.GetDecryptId(section.ContractId)
+	// if err != nil {
+	// 	c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+	// 	return
+	// }
+	// contract := c.ServiceContract.GetContract(contractId)
+	c.Ctx.JSON(iris.Map{
+		"code":       0,
+		"msg":        "",
+		"section":    section,
+		"isContract": isContract,
+		// "contract":   contract,
+	})
 }
 
 // 新增合同

+ 13 - 4
web/api/contract_section_tree_api.go

@@ -153,7 +153,7 @@ func (c *ContractApi) PostSectionTemplate() {
 // @Accept  json
 // @Produce  json
 // @Security ApiKeyAuth
-// @Param   id     body    int     true        "项目节ID"
+// @Param   id     body    string     true        "项目节ID"
 // @Param   bidsectionId     body    string     true        "标段ID"
 // @Param   name     body    string     true        "项目节名称"
 // @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
@@ -187,7 +187,17 @@ func (c *ContractApi) PostSectionAdd() {
 	c.Ctx.JSON(iris.Map{"code": 0, "msg": "新增成功"})
 }
 
-// 修改合同项目节号或者名称
+// @Summary 修改合同项目节 名称
+// @Tags 合同管理
+// @Description 修改合同项目节 名称
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   id     body    string     true        "项目节ID"
+// @Param   bidsectionId     body    string     true        "标段ID"
+// @Param   name     body    string     true        "项目节名称"
+// @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
+// @Router /api/contract/section/save [post]
 func (c *ContractApi) PostSectionSave() {
 	// 获得模板号
 	sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
@@ -217,14 +227,13 @@ func (c *ContractApi) PostSectionSave() {
 	c.Ctx.JSON(iris.Map{"code": 0, "msg": "修改成功"})
 }
 
-//
 // @Summary 删除 合同项目节
 // @Tags 合同管理
 // @Description 删除 合同项目节
 // @Accept  json
 // @Produce  json
 // @Security ApiKeyAuth
-// @Param   id     body    int     true        "项目节ID"
+// @Param   id     body    string     true        "项目节ID"
 // @Param   bidsectionId     body    string     true        "标段ID"
 // @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Router /api/contract/section [delete]

+ 27 - 0
web/viewmodels/contract.go

@@ -0,0 +1,27 @@
+/*
+ * @description:合同 视图
+ * @Author: CP
+ * @Date: 2020-11-11 11:19:30
+ * @FilePath: \construction_management\web\viewmodels\contract.go
+ */
+package viewmodels
+
+import (
+	"time"
+)
+
+type Contracts struct {
+	Id            string    `form:"id" json:"id" `
+	TreeId        string    `xorm:"not null default 0 comment('树ID') INT(11)"`
+	ContractsType int       `xorm:"not null comment('合同类型(1收入合同2支出合同)') TINYINT(1)"`
+	ProjectId     string    `xorm:"not null default 0 comment('项目ID') INT(11)"`
+	BidsectionId  string    `xorm:"comment('标段ID') INT(11)"`
+	Name          string    `xorm:"not null comment('名称') VARCHAR(64)"`
+	Code          string    `xorm:"comment('合同编号') VARCHAR(32)"`
+	Price         string    `xorm:"not null comment('合同金额 0') DECIMAL(12,2)"`
+	Returned      string    `xorm:"not null comment('回款总金额 0') DECIMAL(12,2)"`
+	Paid          string    `xorm:"not null default 0.00 comment('合同已支付金额 0') DECIMAL(12,2)"`
+	Status        int       `xorm:"not null comment('合同状态 0') TINYINT(1)"`
+	CreateTime    time.Time `xorm:"comment('创建时间') DATETIME"`
+	UpdateTime    time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
+}

+ 7 - 0
web/viewmodels/tree_section_contract.go

@@ -70,6 +70,13 @@ func (l TreeSectionContract) ValidateSectionDelete() error {
 	)
 }
 
+// func (l TreeSectionContract) ValidRuleGet() error {
+// 	return validation.ValidateStruct(&l,
+// 		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),
+// 		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
+// 	)
+// }
+
 // Isfolder int `form:"isfolder" json:"isfolder"`
 
 // 	UpdateTime     string `form:"updateTime" json:"updateTime"`