Selaa lähdekoodia

Merge branch 'master' of http://192.168.1.41:3000/caipin/design_quantity

caipin 4 vuotta sitten
vanhempi
commit
801f7b72b5

+ 7 - 0
dao/tree_contract_dao.go

@@ -559,3 +559,10 @@ func (d *TreeContractDao) replaceContractAttribution(session *xorm.Session, attr
 	}
 	return nil
 }
+
+// 更新合同id
+func (d *TreeContractDao) UpdateContract(id int, contractId int) error {
+	data := &models.CmTreeContracts{Id: id, ContractId: contractId}
+	_, err := d.engine.Where("id = ?", id).Cols("contract_id").Update(data)
+	return err
+}

+ 6 - 0
services/contract_section_tree_service.go

@@ -438,3 +438,9 @@ func (s *contractService) makeSectionView(data *models.CmTreeContracts) *viewmod
 	section.CreateTime = data.CreateTime.Format(conf.SysTimeform)
 	return section
 }
+
+// 更新项目节-合同id
+func (s *contractService) UpdateContractId(id int, contractId int) error {
+	err := s.treeContractDao.UpdateContract(id, contractId)
+	return err
+}

+ 19 - 0
services/contract_service.go

@@ -27,6 +27,7 @@ type ContractService interface {
 	ValidRuleSectionDelete(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 	ValidRuleSectionNot(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 	ValidRuleGet(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
+	ValidRuleUpdateFile(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 	ValidRuleSerial(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 
 	// 项目节
@@ -39,6 +40,7 @@ type ContractService interface {
 	SectionDelete(treeId int) error
 	MoveDepth(sectionData *viewmodels.TreeSectionContract) error
 	MoveSerial(sectionData *viewmodels.TreeSectionContract) error
+	UpdateContractId(id int, contractId int) error
 
 	SaveUpload(Location string, Filename string, ext string) (int, error)
 }
@@ -189,6 +191,23 @@ func (s *contractService) ValidRuleSerial(ctx iris.Context) (*viewmodels.TreeSec
 	return treeSectionVaild, nil
 }
 
+// 验证更新附件相关
+func (s *contractService) ValidRuleUpdateFile(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
+	treeSectionVaild := &viewmodels.TreeSectionContract{}
+	err := ctx.ReadJSON(treeSectionVaild)
+	if err != nil {
+		log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
+		return treeSectionVaild, err
+	}
+
+	err = treeSectionVaild.ValidateFile()
+	if err != nil {
+		log.Println("参数验证错误, error=", err)
+		return treeSectionVaild, err
+	}
+	return treeSectionVaild, nil
+}
+
 // 新增合同参数验证
 func (s *contractService) ValidRuleContractAdd(ctx iris.Context) (*viewmodels.Contracts, error) {
 	// 创建一个存放前端传过来参数

+ 40 - 0
web/api/contract_section_tree_api.go

@@ -426,3 +426,43 @@ func (c *ContractApi) DeleteSection() {
 	}
 	c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功"})
 }
+
+// @Summary 保存 项目节附件
+// @Tags 合同管理-项目节
+// @Description 附件 合同项目节
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   id     body    string     true        "项目节ID"
+// @Param   fid    body    string     true        "附件id"
+// @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
+// @Router /api/contract/file [post]
+func (c *ContractApi) PostFile() {
+	sectionData, err := c.ServiceContract.ValidRuleUpdateFile(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
+		return
+	}
+
+	// 项目节ID
+	treeId, err := utils.GetDecryptId(sectionData.Id)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	// 项目节ID
+	contractId, err := utils.GetDecryptId(sectionData.ContractId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	err = c.ServiceContract.UpdateContractId(treeId, contractId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	c.Ctx.JSON(iris.Map{"code": 0, "msg": "保存成功"})
+}

+ 8 - 0
web/viewmodels/tree_section_contract.go

@@ -93,6 +93,14 @@ func (l TreeSectionContract) ValidateSectionSerial() error {
 	)
 }
 
+func (l TreeSectionContract) ValidateFile() error {
+	return validation.ValidateStruct(&l,
+		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),
+		// validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
+		validation.Field(&l.ContractId, validation.Required.Error("附件不能为空")),
+	)
+}
+
 // func (l TreeSectionContract) ValidRuleGet() error {
 // 	return validation.ValidateStruct(&l,
 // 		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),