caipin 4 vuotta sitten
vanhempi
commit
6a20286cba

+ 8 - 7
dao/tree_contract_dao.go

@@ -424,22 +424,23 @@ func (d *TreeContractDao) CreateAll(data []*models.CmTreeContracts) error {
 }
 
 // 新增项目节
-func (d *TreeContractDao) Create(data *models.CmTreeContracts) error {
+func (d *TreeContractDao) Create(data *models.CmTreeContracts) (*models.CmTreeContracts, error) {
 
 	session := d.engine.NewSession()
 	defer session.Close()
 	err := session.Begin()
 	if err != nil {
-		return errors.New("新增失败-db")
+		return nil, errors.New("新增失败-db")
 	}
 
 	_, err = session.Insert(data)
 	if err != nil {
 		log.Println(" error=", err)
-		return errors.New("新增失败")
+		return nil, errors.New("新增失败")
 	}
-	fmt.Println("=======================================")
-	fmt.Println(data)
+	// 插入成功后,ID自动赋值到data.Id里
+	// fmt.Println("=======================================")
+	// fmt.Println(data)
 
 	// 更新合同节树ID
 	// data.TreeId = data.Id
@@ -452,9 +453,9 @@ func (d *TreeContractDao) Create(data *models.CmTreeContracts) error {
 	err = session.Commit()
 	if err != nil {
 		session.Rollback()
-		return errors.New("新增失败-db")
+		return nil, errors.New("新增失败-db")
 	}
-	return nil
+	return data, nil
 }
 
 // 保存项目节

+ 11 - 7
services/contract_section_tree_service.go

@@ -92,15 +92,15 @@ func (s *contractService) SetSection(templateNumber int, bidsectionId int, proje
 }
 
 // 新增项目节
-func (s *contractService) SectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error {
+func (s *contractService) SectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) (*models.CmTreeContracts, error) {
 	// 1.验证项目节ID
 	treeId, err := utils.GetDecryptId(sectionData.Id)
 	if err != nil {
-		return err
+		return nil, err
 	}
 	sectionFather := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
 	if sectionFather.Id == 0 {
-		return errors.New("未找到合同项目节")
+		return nil, errors.New("未找到合同项目节")
 	}
 	// 1-1 深度为>=2才能新增项目节
 	// if sectionFather.Depth < 3 {
@@ -108,7 +108,7 @@ func (s *contractService) SectionAdd(sectionData *viewmodels.TreeSectionContract
 	// }
 	// 1-2 项目节是否有合同
 	if sectionFather.ContractId != 0 {
-		return errors.New("该项目节已存在合同")
+		return nil, errors.New("该项目节已存在合同")
 	}
 
 	// 2 获得最大序号
@@ -142,11 +142,11 @@ func (s *contractService) SectionAdd(sectionData *viewmodels.TreeSectionContract
 	sectionCM.ContractReturned = "0"
 	sectionCM.ContractsPaid = "0"
 
-	err = s.treeContractDao.Create(sectionCM)
+	data, err := s.treeContractDao.Create(sectionCM)
 	if err != nil {
-		return err
+		return nil, err
 	}
-	return nil
+	return data, nil
 }
 
 // 保存名称
@@ -378,5 +378,9 @@ func (s *contractService) makeSectionView(data *models.CmTreeContracts) *viewmod
 	section.ContractLocking = data.ContractLocking
 
 	section.CreateTime = data.CreateTime.Format(conf.SysTimeform)
+
+	//
+	section.Title = fmt.Sprintf("%s%d ", data.Attribution, data.Serial) + data.Name
+	section.Key = id
 	return section
 }

+ 1 - 1
services/contract_service.go

@@ -48,7 +48,7 @@ type ContractService interface {
 	GetSectionTreeContract(attribution string, bidsectionId int, projectId int, treeType int) []*viewmodels.Contracts
 	GetSecionTree(bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract
 	SetSection(templateNumber int, bidsectionId int, projectIdInt int, treeType int) error
-	SectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error
+	SectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) (*models.CmTreeContracts, error)
 	SectionSave(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error
 	UpdateSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error
 	SectionDelete(treeId int, bidsectionId int, projectId int, treeType int) error

+ 8 - 2
web/api/contract_api.go

@@ -240,10 +240,16 @@ func (c *ContractApi) PostIncomeCreate() {
 	sectionData := &viewmodels.TreeSectionContract{}
 	sectionData.Id = contractData.TreeId
 	sectionData.Name = contractData.Name
-	// c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt, 0)
+	sectionResult, err := c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt, 0)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
 
-	err = c.ServiceContract.Add(contractData, projectIdInt, bidsectionId, treeId)
+	err = c.ServiceContract.Add(contractData, projectIdInt, bidsectionId, sectionResult.Id)
 	if err != nil {
+		// 需要删除项目节
+		c.ServiceContract.SectionDelete(sectionResult.Id, bidsectionId, projectIdInt, 0)
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
 	}

+ 1 - 1
web/api/contract_section_tree_api.go

@@ -271,7 +271,7 @@ func (c *ContractApi) PostSectionAdd() {
 		return
 	}
 
-	err = c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)
+	_, err = c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return

+ 4 - 0
web/viewmodels/tree_section_contract.go

@@ -41,6 +41,10 @@ type TreeSectionContract struct {
 	Operation      string `form:"operation" json:"operation"`
 	ElderBrother   bool   `form:"elderBrother" json:"elderBrother"`
 	IsEnd          bool   `form:"isEnd" json:"isEnd"`
+
+	// 前端需要
+	Key   string `form:"key" json:"key"`
+	Title string `form:"title" json:"title"`
 }
 
 func (l TreeSectionContract) ValidateDepth() error {