|
|
@@ -2,9 +2,14 @@ package contract
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "fmt"
|
|
|
+ "strconv"
|
|
|
|
|
|
model "dashoo.cn/micro/app/model/contract"
|
|
|
service "dashoo.cn/micro/app/service/contract"
|
|
|
+ "dashoo.cn/opms_libary/micro_srv"
|
|
|
+ "dashoo.cn/opms_libary/multipart"
|
|
|
+ "dashoo.cn/opms_libary/plugin/dingtalk"
|
|
|
|
|
|
"dashoo.cn/common_definition/comm_def"
|
|
|
"github.com/gogf/gf/frame/g"
|
|
|
@@ -114,6 +119,68 @@ func (c *CtrContract) Commit(ctx context.Context, req *model.CtrContractCommitRe
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+type CtrContractHandler struct{}
|
|
|
+
|
|
|
+var spaceId = "21042518430"
|
|
|
+
|
|
|
+func (h *CtrContractHandler) CommitWithFile(ctx context.Context, args *multipart.MultipartFile, rsp *comm_def.CommonMsg) error {
|
|
|
+ g.Log().Infof("CtrContractHandler.CommitWithFile request %#v ", *args)
|
|
|
+ // 获取用户信息
|
|
|
+ userInfo, err := micro_srv.GetUserInfo(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("获取用户信息异常:%s", err.Error())
|
|
|
+ }
|
|
|
+ if userInfo.DingtalkUid == "" {
|
|
|
+ return fmt.Errorf("该用户钉钉 uid 为空")
|
|
|
+ }
|
|
|
+ s, err := service.NewCtrContractService(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if args.FileName == "" {
|
|
|
+ return fmt.Errorf("文件名称不能为空")
|
|
|
+ }
|
|
|
+ if args.File == nil {
|
|
|
+ return fmt.Errorf("文件不能为空")
|
|
|
+ }
|
|
|
+ if args.File.Name() == "" {
|
|
|
+ return fmt.Errorf("文件路径不能为空")
|
|
|
+ }
|
|
|
+ contractId, err := strconv.Atoi(args.Meta["contractId"])
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("合同 Id 不合法 %s", args.Meta["contractId"])
|
|
|
+ }
|
|
|
+
|
|
|
+ fmt.Println(args.File.Name(), args.FileName, args.FileSize, args.Meta)
|
|
|
+ fmt.Println(spaceId, userInfo.DingtalkId, args.FileName, args.File.Name())
|
|
|
+ // resp, err := s.UploadFile("21042518430", "8xljy04PZiS9iPxp5PhDnUzQiEiE", "引物导入模板-000000.xlsx", "/Users/chengjian/Downloads/引物导入模板.xlsx")
|
|
|
+
|
|
|
+ resp, err := dingtalk.Client.GetStorage().UploadFile(spaceId, userInfo.DingtalkId, args.FileName, args.File.Name())
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("钉钉上传文件异常 %s", err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ err = s.Commit(ctx, &model.CtrContractCommitReq{
|
|
|
+ Id: contractId,
|
|
|
+ ContractModel: args.Meta["contractModel"],
|
|
|
+ Terms: args.Meta["terms"],
|
|
|
+ PayTerms: args.Meta["payTerms"],
|
|
|
+ File: []model.DingFileInfo{
|
|
|
+ {
|
|
|
+ SpaceId: resp.Dentry.SpaceId,
|
|
|
+ FileId: resp.Dentry.Id,
|
|
|
+ FileName: resp.Dentry.Name,
|
|
|
+ FileSize: resp.Dentry.Size,
|
|
|
+ FileType: resp.Dentry.Extension,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
// Swagger:CtrContract 合同,测试tag 更新合同
|
|
|
func (c *CtrContract) Update(ctx context.Context, req *model.CtrContractUpdateReq, rsp *comm_def.CommonMsg) error {
|
|
|
g.Log().Infof("CtrContract.Update request %#v ", *req)
|