caipin 4 年之前
父節點
當前提交
a81b1e7aa4

+ 1 - 0
dao/contract_dao.go

@@ -89,6 +89,7 @@ func (d *ContractDao) Add(contractData *models.CmContracts) error {
 	if err != nil {
 		return errors.New("新增合同出错-db")
 	}
+
 	// 1.写入合同表
 	_, err = session.Insert(contractData)
 	if err != nil {

+ 3 - 1
dao/tree_contract_dao.go

@@ -59,7 +59,7 @@ func (d *TreeContractDao) GetAll(bidsectionId int, projectId int, treeType int)
 }
 
 // 获得项目下的项目节不包含合同
-func (d *TreeContractDao) GetAllNoContract(bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
+func (d *TreeContractDao) GetAllNotContract(bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
 
 	datalist := make([]models.CmTreeContracts, 0)
 	err := d.engine.
@@ -438,6 +438,8 @@ func (d *TreeContractDao) Create(data *models.CmTreeContracts) error {
 		log.Println(" error=", err)
 		return errors.New("新增失败")
 	}
+	fmt.Println("=======================================")
+	fmt.Println(data)
 
 	// 更新合同节树ID
 	// data.TreeId = data.Id

+ 11 - 0
services/contract_section_tree_service.go

@@ -26,6 +26,17 @@ func (s *contractService) GetSecionTree(bidsectionId int, projectId int, treeTyp
 	return Node
 }
 
+// 获得合同项目节
+func (s *contractService) GetSecionTreeNotContract(bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract {
+	dataList := s.treeContractDao.GetAllNotContract(bidsectionId, projectId, treeType)
+	sectionList := s.makeSectionTreeView(dataList)
+
+	// Node := sectionRoot //父节点
+	Node := sectionList[0] //父节点
+	comm.MakeSectionContract(sectionList, Node)
+	return Node
+}
+
 // 获得项目节树和孩子们下的合同数据
 func (s *contractService) GetSectionTreeContract(attribution string, bidsectionId int, projectId int, treeType int) []*viewmodels.Contracts {
 	s.treeContractDao.GetAttribution(attribution, bidsectionId, projectId, treeType)

+ 21 - 1
services/contract_service.go

@@ -29,6 +29,7 @@ type ContractService interface {
 	ValidRuleTemplate(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 	ValidRuleSectionAdd(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 	ValidRuleSectionDelete(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
+	ValidRuleSectionNot(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 	ValidRuleGet(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 	ValidRuleSerial(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 	ValidRuleContractAdd(ctx iris.Context) (*viewmodels.Contracts, error)
@@ -42,6 +43,7 @@ type ContractService interface {
 	ValidRuleContractPaid(ctx iris.Context) (*viewmodels.ContractsPaid, error)
 	ValidRuleContractPaidDel(ctx iris.Context) (*viewmodels.ContractsPaid, error)
 
+	// 项目节
 	Get(treeId int, bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract
 	GetSectionTreeContract(attribution string, bidsectionId int, projectId int, treeType int) []*viewmodels.Contracts
 	GetSecionTree(bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract
@@ -52,6 +54,7 @@ type ContractService interface {
 	SectionDelete(treeId int, bidsectionId int, projectId int, treeType int) error
 	MoveDepth(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error
 	MoveSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error
+	GetSecionTreeNotContract(bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract
 
 	GetContract(contractId int) *viewmodels.Contracts
 	Add(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error
@@ -172,6 +175,23 @@ func (s *contractService) ValidRuleSectionDelete(ctx iris.Context) (*viewmodels.
 	return treeSectionVaild, nil
 }
 
+func (s *contractService) ValidRuleSectionNot(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
+	treeSectionVaild := &viewmodels.TreeSectionContract{}
+	err := ctx.ReadForm(treeSectionVaild)
+	if err != nil {
+		log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
+		return treeSectionVaild, err
+	}
+
+	err = treeSectionVaild.ValidateSectionNot()
+	if err != nil {
+		log.Println("参数验证错误, error=", err)
+		return treeSectionVaild, err
+	}
+
+	return treeSectionVaild, nil
+}
+
 func (s *contractService) ValidRuleGet(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
 	treeSectionVaild := &viewmodels.TreeSectionContract{}
 	err := ctx.ReadForm(treeSectionVaild)
@@ -314,7 +334,7 @@ func (s *contractService) Add(contractData *viewmodels.Contracts, projectId int,
 	if contracts.Id == 0 {
 		return errors.New("未找到项目节")
 	}
-	// k := int32(projectId)
+
 	// 2.项目节是没有合同
 	if contracts.ContractId != 0 {
 		return errors.New("该项目节上已经存在合同")

+ 6 - 0
web/api/contract_api.go

@@ -205,6 +205,7 @@ func (c *ContractApi) GetIncome() {
 // @Param   bidsectionId     path    string     true        "标段ID"
 // @Param   code     path    string     true        "合同编号"
 // @Param   name     path    string     true        "合同名称"
+// @Param   sectionName     path    string     true        "项目节名称"
 // @Param   contractsType     path    int     true        "合同类型(1)"
 // @Param   price     path    string     true        "合同金额"
 // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
@@ -236,6 +237,11 @@ func (c *ContractApi) PostIncomeCreate() {
 		return
 	}
 
+	sectionData := &viewmodels.TreeSectionContract{}
+	sectionData.Id = contractData.TreeId
+	sectionData.Name = contractData.Name
+	// c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt, 0)
+
 	err = c.ServiceContract.Add(contractData, projectIdInt, bidsectionId, treeId)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})

+ 45 - 0
web/api/contract_section_tree_api.go

@@ -381,3 +381,48 @@ func (c *ContractApi) DeleteSection() {
 	}
 	c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功"})
 }
+
+// @Summary 获得项目节(不含合同)
+// @Tags 合同管理-项目节
+// @Description 获得项目节(不含合同)
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   bidsectionId     path    string     true        "标段ID"
+// @Param   treeType     path    int     true        "项目节类型(0收入,1支出)"
+// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,data:viewmodels.TreeSectionContract,msg:错误信息}"
+// @Router /api/contract/section/not [get]
+func (c *ContractApi) GetSectionNot() {
+
+	// 验证规则
+	sectionData, err := c.ServiceContract.ValidRuleSectionNot(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	// 解密
+	bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
+		return
+	}
+
+	// 项目ID
+	projectIdInt, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	//获得合同项目节
+	sectionTree := c.ServiceContract.GetSecionTreeNotContract(bidsectionId, projectIdInt, sectionData.TreeType)
+
+	// 2.已设置项目节
+	c.Ctx.JSON(iris.Map{
+		"code":        0,
+		"msg":         "",
+		"sectionTree": sectionTree,
+	})
+
+}

+ 4 - 0
web/viewmodels/contract.go

@@ -33,6 +33,8 @@ type Contracts struct {
 	PartyBSigner string `form:"partyBSigner" json:"partyBSigner" `
 	SignerTime   string `form:"signerTime" json:"signerTime" `
 	Remarks      string `form:"remarks" json:"remarks" `
+
+	SectionName string `form:"sectionName" json:"sectionName" `
 }
 
 // 验证方法
@@ -44,6 +46,8 @@ func (l Contracts) ValidateAdd() error {
 		validation.Field(&l.Name, validation.Required.Error("名称不能为空")),
 		//validation.Field(&l.ContractsType, validation.Required.Error("合同类型不能为空"), validation.In(1, 2).Error("未找到相关合同类型")),
 		validation.Field(&l.Price, validation.Required.Error("合同金额不能为空")),
+
+		validation.Field(&l.SectionName, validation.Required.Error("项目名称不能为空")),
 	)
 }
 

+ 7 - 0
web/viewmodels/tree_section_contract.go

@@ -51,6 +51,13 @@ func (l TreeSectionContract) ValidateDepth() error {
 	)
 }
 
+func (l TreeSectionContract) ValidateSectionNot() error {
+	return validation.ValidateStruct(&l,
+		validation.Field(&l.TreeType, validation.In(0, 1).Error("请输入数字0或1")),
+		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
+	)
+}
+
 func (l TreeSectionContract) ValidateTemplate() error {
 	return validation.ValidateStruct(&l,
 		validation.Field(&l.TemplateNumber, validation.Required.Error("模板号不能为空"), validation.In(1, 2).Error("未找到相关模板")),