Просмотр исходного кода

feature: 合同提交审核修改为使用文件地址

liuyaqi 2 лет назад
Родитель
Сommit
78baa36757

+ 13 - 0
opms_parent/app/handler/contract/ctr_contract.go

@@ -115,6 +115,19 @@ func (c *CtrContract) Commit(ctx context.Context, req *model.CtrContractCommitRe
 	return nil
 }
 
+func (c *CtrContract) CommitWithFileUrl(ctx context.Context, req *model.CtrContractCommitWithFileUrlReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("CtrContract.CommitWithFileUrl request %#v ", *req)
+	s, err := service.NewCtrContractService(ctx)
+	if err != nil {
+		return err
+	}
+	err = s.CommitWithFileUrl(ctx, req)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
 type CtrContractHandler struct{}
 
 func (h *CtrContractHandler) CommitWithFile(ctx context.Context, args *multipart.Form, rsp *comm_def.CommonMsg) error {

+ 9 - 0
opms_parent/app/model/contract/ctr_contract.go

@@ -159,3 +159,12 @@ type CtrContractCommitReq struct {
 	PayTerms      string         `json:"payTerms"`      // 付款条件
 	File          []DingFileInfo `json:"file"`          // 附件
 }
+
+type CtrContractCommitWithFileUrlReq struct {
+	Id            int    `json:"id" v:"required#请输入Id"`
+	ContractModel string `json:"contractModel"` // 合同模板 值可以是:大数模板, 客户模板
+	Terms         string `json:"terms"`         // 条款情况 值可以是:接纳全部条款, 不接纳全部条款
+	PayTerms      string `json:"payTerms"`      // 付款条件
+	FileName      string `json:"fileName" v:"required#附件名不能为空"`
+	FileUrl       string `json:"fileUrl" v:"required#附件地址不能为空"`
+}

+ 44 - 0
opms_parent/app/service/contract/ctr_contract.go

@@ -21,6 +21,7 @@ import (
 	proj "dashoo.cn/micro/app/model/proj"
 	workflowModel "dashoo.cn/micro/app/model/workflow"
 	"dashoo.cn/micro/app/service"
+	baseService "dashoo.cn/micro/app/service/base"
 	projsrv "dashoo.cn/micro/app/service/proj"
 	worksrv "dashoo.cn/micro/app/service/work"
 	workflowService "dashoo.cn/micro/app/service/workflow"
@@ -656,6 +657,49 @@ func (s CtrContractService) CommitWithFile(ctx context.Context, formData *multip
 	return nil
 }
 
+func (s CtrContractService) CommitWithFileUrl(ctx context.Context, req *model.CtrContractCommitWithFileUrlReq) error {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return myerrors.TipsError(validErr.Current().Error())
+	}
+	fileinfoByte, err := baseService.UploadDingtalk(s.userInfo.DingtalkId, req.FileUrl, req.FileName)
+	if err != nil {
+		return err
+	}
+	var fileinfo = []model.DingFileInfo{}
+	err = json.Unmarshal(fileinfoByte, &fileinfo)
+	if err != nil {
+		return err
+	}
+
+	_, err = s.Commit(ctx, &model.CtrContractCommitReq{
+		Id:            req.Id,
+		ContractModel: req.ContractModel,
+		Terms:         req.Terms,
+		PayTerms:      req.PayTerms,
+		File:          fileinfo,
+	})
+	if err != nil {
+		return err
+	}
+
+	appendSrv, err := NewCtrContractAppendService(ctx)
+	if err != nil {
+		return err
+	}
+	_, err = appendSrv.Add(ctx, &model.CtrContractAppendAddReq{
+		ContractId: req.Id,
+		FileName:   fileinfo[0].FileName,
+		FileType:   fileinfo[0].FileType,
+		FileUrl:    strings.Join([]string{"dingtalk", fileinfo[0].SpaceId, fileinfo[0].FileId}, ":"),
+		Remark:     "",
+	})
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
 func (s CtrContractService) DownloadDingtalkFile(ctx context.Context, id int) (string, error) {
 	ent, err := s.AppendDao.Where("id= ?", id).One()
 	if err != nil {