zhou.xiaoning преди 2 години
родител
ревизия
ad054425fb
променени са 6 файла, в които са добавени 54 реда и са изтрити 27 реда
  1. 5 5
      api/v1/account/certification.go
  2. 3 0
      docs/docs.go
  3. 3 0
      docs/swagger.json
  4. 2 0
      docs/swagger.yaml
  5. 6 0
      model/account/response/certification.go
  6. 35 22
      service/sign/sign.go

+ 5 - 5
api/v1/account/certification.go

@@ -42,7 +42,7 @@ func QueryUserESignRecord(c *gin.Context) {
 // @accept   application/json
 // @Produce  application/json
 // @Param    data body     request.AddUserReq            true "入参"
-// @Success  200  {object} response.Response{msg=string}         "出参"
+// @Success  200  {object} response.Response{msg=string} "出参"
 // @Router   /Account/AddUser [post]
 // @Tags     账户服务
 func AddUser(c *gin.Context) {
@@ -72,8 +72,8 @@ func AddUser(c *gin.Context) {
 // @Security ApiKeyAuth
 // @accept   application/json
 // @Produce  application/json
-// @Param    data body     request.CreateContractAndAddSignerReq true "入参"
-// @Success  200  {object} response.Response{msg=string} "出参"
+// @Param    data body     request.CreateContractAndAddSignerReq      true "入参"
+// @Success  200  {object} response.Response{data=string,msg=string} "出参"
 // @Router   /Account/CreateContractAndAddSigner [post]
 // @Tags     账户服务
 func CreateContractAndAddSigner(c *gin.Context) {
@@ -90,8 +90,8 @@ func CreateContractAndAddSigner(c *gin.Context) {
 		return
 	}
 
-	if err := signService.CreateContractAndAddSigner(r, claims.UserID); err == nil {
-		response.Ok(g.C)
+	if rsp, err := signService.CreateContractAndAddSigner(r, claims.UserID); err == nil {
+		response.OkWithDetailed(rsp, "操作成功", g.C)
 	} else {
 		global.M2A_LOG.Error(err.Error(), zap.Error(err))
 		response.FailWithMessage(err.Error(), c)

+ 3 - 0
docs/docs.go

@@ -105,6 +105,9 @@ const docTemplate = `{
                                 {
                                     "type": "object",
                                     "properties": {
+                                        "data": {
+                                            "type": "string"
+                                        },
                                         "msg": {
                                             "type": "string"
                                         }

+ 3 - 0
docs/swagger.json

@@ -96,6 +96,9 @@
                                 {
                                     "type": "object",
                                     "properties": {
+                                        "data": {
+                                            "type": "string"
+                                        },
                                         "msg": {
                                             "type": "string"
                                         }

+ 2 - 0
docs/swagger.yaml

@@ -239,6 +239,8 @@ paths:
             allOf:
             - $ref: '#/definitions/response.Response'
             - properties:
+                data:
+                  type: string
                 msg:
                   type: string
               type: object

+ 6 - 0
model/account/response/certification.go

@@ -0,0 +1,6 @@
+package response
+
+// CreateContractAndAddSignerRsp 上传待签署文件和添加签署方响应参数
+type CreateContractAndAddSignerRsp struct {
+	SignUrl string `json:"signUrl"` // 合同签署链接
+}

+ 35 - 22
service/sign/sign.go

@@ -7,6 +7,7 @@ import (
 	"mtp20access/global"
 	"mtp20access/model/account"
 	"mtp20access/model/account/request"
+	"mtp20access/model/account/response"
 	"mtp20access/service/asign"
 	"strconv"
 	"time"
@@ -24,6 +25,14 @@ func QueryUserESignRecord(userId int) (rsp []account.Useresignrecord, err error)
 
 // AddUser 添加用户
 func AddUser(req request.AddUserReq, userId int) (err error) {
+	// 获取用户电子签记录
+	useresignrecord := new(account.Useresignrecord)
+	has, _ := global.M2A_DB.Where("USERID = ? AND TEMPLATETYPE = 1 AND RECORDSTATUS = 3", userId).Get(useresignrecord)
+	if has {
+		err = errors.New("用户已同步")
+		return
+	}
+
 	// 调用爱签API-添加个人用户(https://{host}/user/addPersonalUser)
 	rsp, err := asign.AddPersonalUserBy(
 		strconv.Itoa(userId),
@@ -55,7 +64,7 @@ func AddUser(req request.AddUserReq, userId int) (err error) {
 		WHERE USERID = %v
 	`, string(authinfo), userId)
 	if _, err = global.M2A_DB.Exec(sql); err != nil {
-		global.M2A_LOG.Error("【AddUser】 添加用户电子签记录", zap.Error(err))
+		global.M2A_LOG.Error("【AddUser】 更新用户电子签记录失败", zap.Error(err))
 		return
 	}
 
@@ -63,7 +72,7 @@ func AddUser(req request.AddUserReq, userId int) (err error) {
 }
 
 // CreateContractAndAddSigner 上传待签署文件和添加签署方
-func CreateContractAndAddSigner(req request.CreateContractAndAddSignerReq, userId int) (err error) {
+func CreateContractAndAddSigner(req request.CreateContractAndAddSignerReq, userId int) (rsp response.CreateContractAndAddSignerRsp, err error) {
 	// 获取用户电子签记录
 	useresignrecord := new(account.Useresignrecord)
 	has, err := global.M2A_DB.Where("USERID = ? AND TEMPLATENO = ?", userId, req.TemplateNo).Get(useresignrecord)
@@ -79,7 +88,7 @@ func CreateContractAndAddSigner(req request.CreateContractAndAddSignerReq, userI
 		contractNo := fmt.Sprintf("%d_%s_%v", userId, time.Now().Format("2006-01-02 15:04:05"), useresignrecord.RECORDID)
 
 		// 调用爱签API-上传待签署文件(https://{host}/contract/createContract)
-		rsp, e := asign.CreateContract(
+		r, e := asign.CreateContract(
 			contractNo,
 			useresignrecord.TEMPLATENAME,
 			useresignrecord.TEMPLATENO,
@@ -88,8 +97,8 @@ func CreateContractAndAddSigner(req request.CreateContractAndAddSignerReq, userI
 			err = e
 			return
 		}
-		if rsp.Code != 100000 {
-			err = errors.New(strconv.Itoa(rsp.Code))
+		if r.Code != 100000 {
+			err = errors.New(strconv.Itoa(r.Code))
 			global.M2A_LOG.Error("【CreateContractAndAddSigner】 上传待签署文件接口调用失败", zap.Error(err))
 			return
 		}
@@ -108,9 +117,11 @@ func CreateContractAndAddSigner(req request.CreateContractAndAddSignerReq, userI
 	}
 
 	// 判断是否需要添加签署方(获取合同签约地址)
-	if useresignrecord.SIGNURL == "" {
+	if useresignrecord.SIGNURL != "" {
+		err = errors.New("合同签署链接已存在")
+	} else {
 		// 调用爱签API-添加签署方(https://{host}/contract/addSigner)
-		rsp, e := asign.AddSigner(
+		r, e := asign.AddSigner(
 			useresignrecord.CONTRACTNO,
 			strconv.Itoa(userId),
 		)
@@ -118,24 +129,26 @@ func CreateContractAndAddSigner(req request.CreateContractAndAddSignerReq, userI
 			err = e
 			return
 		}
-		if rsp.Code != 100000 {
-			err = errors.New(strconv.Itoa(rsp.Code))
+		if r.Code != 100000 {
+			err = errors.New(strconv.Itoa(r.Code))
 			global.M2A_LOG.Error("【CreateContractAndAddSigner】 添加签署方接口调用失败", zap.Error(err))
 			return
 		}
-		if len(rsp.Data.SignUser) > 0 {
-			useresignrecord.SIGNURL = rsp.Data.SignUser[0].SignUrl
-		}
-		// 将返回的合同编号写入数据库
-		sql := fmt.Sprintf(`
-			UPDATE useresignrecord 
-			SET SIGNURL = '%v' 
-				UPDATETIME = SYSDATE
-			WHERE RECORDID = %v
-		`, useresignrecord.SIGNURL, useresignrecord.RECORDID)
-		if _, err = global.M2A_DB.Exec(sql); err != nil {
-			global.M2A_LOG.Error("【CreateContractAndAddSigner】 写入合同签署链接失败", zap.Error(err))
-			return
+		if len(r.Data.SignUser) > 0 {
+			useresignrecord.SIGNURL = r.Data.SignUser[0].SignUrl
+			// 将返回的合同编号写入数据库
+			sql := fmt.Sprintf(`
+				UPDATE useresignrecord 
+				SET SIGNURL = '%v' 
+					UPDATETIME = SYSDATE
+				WHERE RECORDID = %v
+			`, useresignrecord.SIGNURL, useresignrecord.RECORDID)
+			if _, err = global.M2A_DB.Exec(sql); err != nil {
+				global.M2A_LOG.Error("【CreateContractAndAddSigner】 写入合同签署链接失败", zap.Error(err))
+				return
+			}
+			// 给客户端返回合同签署地址
+			rsp.SignUrl = useresignrecord.SIGNURL
 		}
 	}