|
|
@@ -1,14 +1,18 @@
|
|
|
package sign
|
|
|
|
|
|
import (
|
|
|
+ "bytes"
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "io"
|
|
|
"mtp20access/global"
|
|
|
"mtp20access/model/account"
|
|
|
"mtp20access/model/account/request"
|
|
|
"mtp20access/model/account/response"
|
|
|
"mtp20access/service/asign"
|
|
|
+ "mtp20access/utils"
|
|
|
+ "net/http"
|
|
|
"os"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
@@ -140,7 +144,8 @@ func CreateContractAndAddSigner(req request.CreateContractAndAddSignerReq, userI
|
|
|
// 将返回的合同编号写入数据库
|
|
|
sql := fmt.Sprintf(`
|
|
|
UPDATE useresignrecord
|
|
|
- SET SIGNURL = '%v',
|
|
|
+ SET RECORDSTATUS = 2,
|
|
|
+ SIGNURL = '%v',
|
|
|
UPDATETIME = SYSDATE
|
|
|
WHERE RECORDID = %v
|
|
|
`, useresignrecord.SIGNURL, useresignrecord.RECORDID)
|
|
|
@@ -165,13 +170,135 @@ func SignCompleted(userId int) (err error) {
|
|
|
global.M2A_LOG.Error("SignCompleted 获取用户电子签记录失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
- for _, item := range datas {
|
|
|
- if item.RECORDSTATUS != 3 {
|
|
|
+
|
|
|
+ // mgk
|
|
|
+ var record *account.Useresignrecord
|
|
|
+ for i, item := range datas {
|
|
|
+ if item.TEMPLATETYPE == 1 {
|
|
|
+ record = &datas[i]
|
|
|
+ }
|
|
|
+ // 如果是签署中状态,则查询一下合同状态
|
|
|
+ if item.RECORDSTATUS == 2 {
|
|
|
+ rspCTStatus, e := asign.ContractStatus(item.CONTRACTNO)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ global.M2A_LOG.Error("[SignCompleted] 查询合同状态失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if rspCTStatus.Data.Status == 2 {
|
|
|
+ // 已签约
|
|
|
+ // 下载合同
|
|
|
+ r, e := asign.DownloadContract(item.CONTRACTNO)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if r.Code != 100000 {
|
|
|
+ err = errors.New(strconv.Itoa(r.Code))
|
|
|
+ global.M2A_LOG.Error("[SignCompleted] 下载合同接口调用失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if r.Data.Data != "" {
|
|
|
+ // 获取网上开户地址(用于客户端下载文件)
|
|
|
+ openconfig := account.Wskhopenaccountconfig{CONFIGID: 6}
|
|
|
+ has, e := openconfig.Get()
|
|
|
+ if e != nil || !has {
|
|
|
+ err = e
|
|
|
+ global.M2A_LOG.Error("[SignCompleted] 获取网上开户地址失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 将Base64写入目标文件
|
|
|
+ uid, _ := uuid.NewV4()
|
|
|
+ fileName := fmt.Sprintf("%v.pdf", uid.String())
|
|
|
+ // openconfig.CONFIGVALUE = "./" // FIXME: - 测试代码
|
|
|
+ folderPath := "sign/" + time.Now().Format("20060102")
|
|
|
+ savePath := openconfig.CONFIGVALUE + "/uploadFile/" + folderPath
|
|
|
+ if exist, _ := utils.PathExists(savePath); !exist {
|
|
|
+ os.MkdirAll(savePath, os.ModePerm)
|
|
|
+ }
|
|
|
+ f, e := os.OpenFile(savePath+"/"+fileName, os.O_RDWR|os.O_CREATE, os.ModePerm)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ global.M2A_LOG.Error("【HandleASignCompleted】 获取网上开户地址失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer f.Close()
|
|
|
+
|
|
|
+ // 更新数据库记录
|
|
|
+ contractfileaddr := fmt.Sprintf("./uploadFile/%v/%v", folderPath, fileName)
|
|
|
+ sql := fmt.Sprintf(`
|
|
|
+ UPDATE useresignrecord
|
|
|
+ SET RECORDSTATUS = 3,
|
|
|
+ UPDATETIME = SYSDATE,
|
|
|
+ CONTRACTFILEADDR = '%v'
|
|
|
+ WHERE CONTRACTNO = '%v'
|
|
|
+ `, contractfileaddr, item.CONTRACTNO)
|
|
|
+ if _, err = global.M2A_DB.Exec(sql); err != nil {
|
|
|
+ global.M2A_LOG.Error("【HandleASignCompleted】 更新用户电子签记录失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if item.RECORDSTATUS != 3 && item.RECORDSTATUS != 2 {
|
|
|
err = errors.New("未完成所有合同签署")
|
|
|
+ global.M2A_LOG.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 获取临时存储的用户信息
|
|
|
+ if record == nil || record.AUTHINFO == "" {
|
|
|
+ global.M2A_LOG.Error("[SignCompleted] 获取实名认证信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // {"name":"甘肃碳交","idCard":"360428200007287603","idCardType":1,"idCardPhoto":"./uploadFile/20230812/202308121518494929.png","idCardPhotoBackURL":"./uploadFile/20230812/202308121518529223.png","mobile":"15914012151"}
|
|
|
+ cacheMap := make(map[string]interface{})
|
|
|
+ err = json.Unmarshal([]byte(record.AUTHINFO), &cacheMap)
|
|
|
+ if err != nil {
|
|
|
+ global.M2A_LOG.Error("[SignCompleted] 反序列化临时存储用户信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用JAVA实名认证接口
|
|
|
+ reqParam := make(map[string]interface{})
|
|
|
+ reqParam["userid"] = userId
|
|
|
+ reqParam["cardnum"] = cacheMap["idCard"]
|
|
|
+ reqParam["username"] = cacheMap["name"]
|
|
|
+ reqParam["cardtype"] = 0 // 目前写死证件类型为身份证 - 0
|
|
|
+ reqParam["cardfrontphotourl"] = cacheMap["idCardPhoto"]
|
|
|
+ reqParam["cardbackphotourl"] = cacheMap["idCardPhotoBackURL"]
|
|
|
+ reqParam["userinfotype"] = 1 // 目前写死为个人 - 1
|
|
|
+ jsonParam, err := json.Marshal(&reqParam)
|
|
|
+ if err != nil {
|
|
|
+ global.M2A_LOG.Error("[SignCompleted] 反序列化JAVA实名认证入参失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建请求
|
|
|
+ javaUrl := global.M2A_CONFIG.Asign.OpenApiUrl + "/onlineopen/userInfo/addAuth"
|
|
|
+ req, err := http.NewRequest("POST", javaUrl, bytes.NewReader(jsonParam))
|
|
|
+ // 设置请求头
|
|
|
+ req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
|
|
+
|
|
|
+ client := &http.Client{}
|
|
|
+ rsp, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ global.M2A_LOG.Error("[SignCompleted] 请求失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer rsp.Body.Close()
|
|
|
+ body, err := io.ReadAll(rsp.Body)
|
|
|
+ if err != nil {
|
|
|
+ global.M2A_LOG.Error("[SignCompleted] 获取body失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rspData := make(map[string]interface{})
|
|
|
+ if err = json.Unmarshal(body, &rspData); err != nil {
|
|
|
+ global.M2A_LOG.Error("[SignCompleted] 反序列化java body失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println("rspData:", rspData)
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -180,7 +307,7 @@ handleASignCompleted 处理爱签合同签署完成后回调通知
|
|
|
|
|
|
req 异步推送参数
|
|
|
*/
|
|
|
-func HandleASignCompleted(req request.HandleASignCompletedReq) (err error) {
|
|
|
+func HandleASignCompleted(contractNo, status string) (err error) {
|
|
|
/*
|
|
|
// 合同签署完成后回调通知示例
|
|
|
String publickey = "MFwwDQcccccxxxxmEz/nw27Ln6AP90ZCMPi+iNF1m9mhNECAwEAAQ==";
|
|
|
@@ -204,19 +331,19 @@ func HandleASignCompleted(req request.HandleASignCompletedReq) (err error) {
|
|
|
*/
|
|
|
|
|
|
// 获取合同编号
|
|
|
- if req.ContractNo == "" {
|
|
|
- global.M2A_LOG.Error("【HandleASignCompleted】 获取合同编号失败", zap.Any("req", req))
|
|
|
+ if contractNo == "" {
|
|
|
+ global.M2A_LOG.Error("【HandleASignCompleted】 获取合同编号失败")
|
|
|
return
|
|
|
}
|
|
|
// 获取合同状态
|
|
|
- if req.Status == "" {
|
|
|
- global.M2A_LOG.Error("【HandleASignCompleted】 获取获取合同状态失败", zap.Any("req", req))
|
|
|
+ if status == "" {
|
|
|
+ global.M2A_LOG.Error("【HandleASignCompleted】 获取获取合同状态失败")
|
|
|
return
|
|
|
}
|
|
|
- if req.Status == "2" {
|
|
|
+ if status == "2" {
|
|
|
// 已签约
|
|
|
// 下载合同
|
|
|
- r, e := asign.DownloadContract(req.ContractNo)
|
|
|
+ r, e := asign.DownloadContract(contractNo)
|
|
|
if e != nil {
|
|
|
err = e
|
|
|
return
|
|
|
@@ -237,11 +364,13 @@ func HandleASignCompleted(req request.HandleASignCompletedReq) (err error) {
|
|
|
}
|
|
|
// 将Base64写入目标文件
|
|
|
uid, _ := uuid.NewV4()
|
|
|
- fileName := fmt.Sprintf("%v_%v.pdf", r.Data.FileName, uid.String())
|
|
|
- openconfig.CONFIGVALUE = "./" // FIXME: - 测试代码
|
|
|
+ fileName := fmt.Sprintf("%v.pdf", uid.String())
|
|
|
+ // openconfig.CONFIGVALUE = "./" // FIXME: - 测试代码
|
|
|
folderPath := "sign/" + time.Now().Format("20060102")
|
|
|
savePath := openconfig.CONFIGVALUE + "/uploadFile/" + folderPath
|
|
|
- fmt.Println(savePath + "/" + fileName)
|
|
|
+ if exist, _ := utils.PathExists(savePath); !exist {
|
|
|
+ os.MkdirAll(savePath, os.ModePerm)
|
|
|
+ }
|
|
|
f, e := os.OpenFile(savePath+"/"+fileName, os.O_RDWR|os.O_CREATE, os.ModePerm)
|
|
|
if e != nil {
|
|
|
err = e
|
|
|
@@ -249,23 +378,16 @@ func HandleASignCompleted(req request.HandleASignCompletedReq) (err error) {
|
|
|
return
|
|
|
}
|
|
|
defer f.Close()
|
|
|
+
|
|
|
// 更新数据库记录
|
|
|
- // 获取用户电子签记录
|
|
|
- // useresignrecord := new(account.Useresignrecord)
|
|
|
- // has, e = global.M2A_DB.Where("CONTRACTNO = ?", req.ContractNo).Get(useresignrecord)
|
|
|
- // if e != nil || !has {
|
|
|
- // err = e
|
|
|
- // global.M2A_LOG.Error("【HandleASignCompleted】 获取用户电子签记录失败", zap.Error(err))
|
|
|
- // return
|
|
|
- // }
|
|
|
contractfileaddr := fmt.Sprintf("./uploadFile/%v/%v", folderPath, fileName)
|
|
|
sql := fmt.Sprintf(`
|
|
|
UPDATE useresignrecord
|
|
|
SET RECORDSTATUS = 3,
|
|
|
UPDATETIME = SYSDATE,
|
|
|
CONTRACTFILEADDR = '%v'
|
|
|
- WHERE CONTRACTNO = %v
|
|
|
- `, contractfileaddr, req.ContractNo)
|
|
|
+ WHERE CONTRACTNO = '%v'
|
|
|
+ `, contractfileaddr, contractNo)
|
|
|
if _, err = global.M2A_DB.Exec(sql); err != nil {
|
|
|
global.M2A_LOG.Error("【HandleASignCompleted】 更新用户电子签记录失败", zap.Error(err))
|
|
|
return
|