|
|
@@ -72,8 +72,19 @@ func CreateFlowByTemplateDirectly(tmplateName string, userType int,
|
|
|
record *models.Useresignrecord,
|
|
|
idCardType int) (flowId, signUrl string, err error) {
|
|
|
|
|
|
+ var (
|
|
|
+ appId *string
|
|
|
+ proxyOrganizationOpenId *string
|
|
|
+ proxyOperatorOpenId *string
|
|
|
+ )
|
|
|
+ if esignConfig, err := models.GetEsignareatemplateconfig(int(record.AREAUSERID)); err == nil && esignConfig.USERID != 0 {
|
|
|
+ appId = &esignConfig.APPID
|
|
|
+ proxyOrganizationOpenId = &esignConfig.PROXYORGANIZATIONOPENID
|
|
|
+ proxyOperatorOpenId = &esignConfig.PROXYOPERATOROPENID
|
|
|
+ }
|
|
|
+
|
|
|
// 获取模板信息
|
|
|
- templateInfo, err := GetTemplateInfo(&tmplateName)
|
|
|
+ templateInfo, err := GetTemplateInfo(&tmplateName, appId, proxyOrganizationOpenId, proxyOperatorOpenId)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
@@ -96,13 +107,23 @@ func CreateFlowByTemplateDirectly(tmplateName string, userType int,
|
|
|
for i := range recipients {
|
|
|
recipient := recipients[i]
|
|
|
|
|
|
- if config.SerCfg.TencentCfg.ProxyOrganizationName == *recipient.RoleName {
|
|
|
- if *recipient.SignType != 1 {
|
|
|
- // 签署方为本企业,同时不是自动签署时(一般为甲方非自动签署)
|
|
|
- flowApproverInfos = append(flowApproverInfos, buildSelfOrganizationApprovers(recipient)...)
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 乙方
|
|
|
+ // if config.SerCfg.TencentCfg.ProxyOrganizationName == *recipient.RoleName {
|
|
|
+ // if *recipient.SignType != 1 {
|
|
|
+ // // 签署方为本企业,同时不是自动签署时(一般为甲方非自动签署)
|
|
|
+ // flowApproverInfos = append(flowApproverInfos, buildSelfOrganizationApprovers(recipient)...)
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // // 乙方
|
|
|
+ // if userType == 1 {
|
|
|
+ // // 个人
|
|
|
+ // flowApproverInfos = append(flowApproverInfos, buildPersonApprovers(personName, personMobile, personIdCardNumber, idCardType, recipient)...)
|
|
|
+ // } else {
|
|
|
+ // // 企业
|
|
|
+ // flowApproverInfos = append(flowApproverInfos, buildOrganizationApprovers(organizationName, recipient)...)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ if *recipient.SignType != 1 {
|
|
|
if userType == 1 {
|
|
|
// 个人
|
|
|
flowApproverInfos = append(flowApproverInfos, buildPersonApprovers(personName, personMobile, personIdCardNumber, idCardType, recipient)...)
|
|
|
@@ -113,8 +134,17 @@ func CreateFlowByTemplateDirectly(tmplateName string, userType int,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 判断是否添加发起方角色的填写控件
|
|
|
+ // 说明:如果合同模板开启了“本企业自动填写”,合同甲乙双方都不能添加填写控件,需要由发起方添加填写控件
|
|
|
+ fields, err := models.GetEsignTemplateFields(int(record.TEMPLATECONFIGID), 3)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ formFields := buildSelfFormFields(int(record.AREAUSERID), int(record.USERID), fields)
|
|
|
+
|
|
|
// 发起合同
|
|
|
- resp, err := essapi.CreateFlowByTemplateDirectly(*templateInfo.TemplateName, *templateInfo.TemplateId, flowApproverInfos)
|
|
|
+ resp, err := essapi.CreateFlowByTemplateDirectly(*templateInfo.TemplateName, *templateInfo.TemplateId, flowApproverInfos, formFields,
|
|
|
+ appId, proxyOrganizationOpenId, proxyOperatorOpenId)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
@@ -143,7 +173,25 @@ func CreateFlowByTemplateDirectly(tmplateName string, userType int,
|
|
|
|
|
|
// GetFlowStatus 获取合同状态
|
|
|
func GetFlowStatus(flowId string) (recordStatus int, err error) {
|
|
|
- agent := utils.SetAgent()
|
|
|
+ // 获取对应电子签信息
|
|
|
+ var record *models.Useresignrecord
|
|
|
+ record, err = models.GetUseresignRecordByFlowID(flowId)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("获取电子签信息失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var (
|
|
|
+ appId *string
|
|
|
+ proxyOrganizationOpenId *string
|
|
|
+ proxyOperatorOpenId *string
|
|
|
+ )
|
|
|
+ if esignConfig, err := models.GetEsignareatemplateconfig(int(record.AREAUSERID)); err == nil && esignConfig.USERID != 0 {
|
|
|
+ appId = &esignConfig.APPID
|
|
|
+ proxyOrganizationOpenId = &esignConfig.PROXYORGANIZATIONOPENID
|
|
|
+ proxyOperatorOpenId = &esignConfig.PROXYOPERATOROPENID
|
|
|
+ }
|
|
|
+ agent := utils.SetAgent(appId, proxyOrganizationOpenId, proxyOperatorOpenId)
|
|
|
response, err := essapi.DescribeFlowDetailInfo(agent, []*string{&flowId})
|
|
|
if err == nil {
|
|
|
if len(response.Response.FlowInfo) == 0 {
|
|
|
@@ -152,14 +200,6 @@ func GetFlowStatus(flowId string) (recordStatus int, err error) {
|
|
|
}
|
|
|
flowDetailInfo := response.Response.FlowInfo[0]
|
|
|
|
|
|
- // 获取对应电子签信息
|
|
|
- var record *models.Useresignrecord
|
|
|
- record, err = models.GetUseresignRecordByFlowID(flowId)
|
|
|
- if err != nil {
|
|
|
- err = fmt.Errorf("获取电子签信息失败")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
// 更新电子签信息状态
|
|
|
if *flowDetailInfo.FlowStatus == "ALL" {
|
|
|
recordStatus = 3
|
|
|
@@ -236,8 +276,8 @@ func UpdateMdUserSwapProtocol(flowId string) (err error) {
|
|
|
}
|
|
|
|
|
|
// GetTemplateInfo 获取模板信息
|
|
|
-func GetTemplateInfo(contractName *string) (templateInfo *essbasic.TemplateInfo, err error) {
|
|
|
- agent := utils.SetAgent()
|
|
|
+func GetTemplateInfo(contractName, appId, proxyOrganizationOpenId, proxyOperatorOpenId *string) (templateInfo *essbasic.TemplateInfo, err error) {
|
|
|
+ agent := utils.SetAgent(appId, proxyOrganizationOpenId, proxyOperatorOpenId)
|
|
|
templatesResp, err := essapi.DescribeTemplates(agent, contractName)
|
|
|
if err == nil {
|
|
|
if len(templatesResp.Response.Templates) > 0 {
|
|
|
@@ -308,6 +348,7 @@ func buildSelfOrganizationApprovers(recipient *essbasic.Recipient) []*essbasic.F
|
|
|
approverType := "ORGANIZATION"
|
|
|
flowApproverInfo.ApproverType = &approverType
|
|
|
flowApproverInfo.OrganizationOpenId = &config.SerCfg.TencentCfg.ProxyOrganizationOpenId // 本企业OpenID
|
|
|
+
|
|
|
// 模板中对应签署方的参与方id
|
|
|
flowApproverInfo.RecipientId = recipient.RecipientId
|
|
|
flowApproverInfo.OpenId = &config.SerCfg.TencentCfg.ProxyOperatorOpenId // 本企业员工OpenID
|
|
|
@@ -317,6 +358,72 @@ func buildSelfOrganizationApprovers(recipient *essbasic.Recipient) []*essbasic.F
|
|
|
return flowApproverInfos
|
|
|
}
|
|
|
|
|
|
+// buildSelfFormFields 构造本企业填写控件
|
|
|
+// selfUserId 本企业用户ID
|
|
|
+// userId 乙方用户ID
|
|
|
+func buildSelfFormFields(selfUserId int, userId int, fields []models.Esigntemplatefield) (formFields []*essbasic.FormField) {
|
|
|
+ formFields = make([]*essbasic.FormField, 0)
|
|
|
+
|
|
|
+ // 获取本企业信息(合同发起方,一般为交易所或合同所属机构)
|
|
|
+ selfuserInfo, err := models.GetUserInfo(selfUserId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ userInfo, err := models.GetUserInfo(userId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ key, _ := hex.DecodeString(utils.AESSecretKey)
|
|
|
+ for _, item := range fields {
|
|
|
+ filedName := item.FIELDNAME
|
|
|
+ switch filedName {
|
|
|
+ case "甲方地址":
|
|
|
+ address := selfuserInfo.Province + selfuserInfo.City + selfuserInfo.District + selfuserInfo.Address
|
|
|
+ formFields = append(formFields, &essbasic.FormField{
|
|
|
+ ComponentName: &filedName,
|
|
|
+ ComponentValue: &address,
|
|
|
+ })
|
|
|
+ case "甲方邮箱":
|
|
|
+ email := ""
|
|
|
+ if len(selfuserInfo.Email) > 0 {
|
|
|
+ // 手机号码解密
|
|
|
+ if h, err := hex.DecodeString(selfuserInfo.Email); err == nil { // hex -> []byte
|
|
|
+ if d, err := utils.AESDecrypt(h, key); err == nil {
|
|
|
+ email = string(d)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ formFields = append(formFields, &essbasic.FormField{
|
|
|
+ ComponentName: &filedName,
|
|
|
+ ComponentValue: &email,
|
|
|
+ })
|
|
|
+ case "甲方电话号码":
|
|
|
+ telphone := ""
|
|
|
+ if len(selfuserInfo.Email) > 0 {
|
|
|
+ // 手机号码解密
|
|
|
+ if h, err := hex.DecodeString(selfuserInfo.Telphone); err == nil { // hex -> []byte
|
|
|
+ if d, err := utils.AESDecrypt(h, key); err == nil {
|
|
|
+ telphone = string(d)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ formFields = append(formFields, &essbasic.FormField{
|
|
|
+ ComponentName: &filedName,
|
|
|
+ ComponentValue: &telphone,
|
|
|
+ })
|
|
|
+ case "乙方地址":
|
|
|
+ address := userInfo.Province + userInfo.City + userInfo.District + userInfo.Address
|
|
|
+ formFields = append(formFields, &essbasic.FormField{
|
|
|
+ ComponentName: &filedName,
|
|
|
+ ComponentValue: &address,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func ProcessNotice(content string) {
|
|
|
// "{\"MsgId\":\"yDSLWUUckposmdf8UBxiJvuDbgiYRYbj\",\"MsgType\":\"FlowStatusChange\",\"MsgVersion\":\"ThirdPartyApp\",\"MsgData\":{\"ApplicationId\":\"yDwiuUUckpogfoa4UxhigrYChFMdSJQV\",\"ProxyOrganizationOpenId\":\"TJMD\",\"CustomerData\":\"\",\"FlowId\":\"yDSLWUUckposcsthUwvcaGSuV5EKZAzu\",\"FlowName\":\"1000_P_风险揭示书\",\"FlowType\":\"合同\",\"FlowStatus\":\"INIT\",\"FlowMessage\":\"\",\"CreateOn\":1699077064,\"Deadline\":1730613064,\"FlowApproverInfo\":[{\"ProxyOrganizationOpenId\":\"\",\"ProxyOperatorOpenId\":\"\",\"recipientId\":\"yDSLNUUckpos1i71UuGNih5yMGbZij46\",\"RecipientId\":\"yDSLNUUckpos1i71UuGNih5yMGbZij46\",\"PhoneNumber\":\"15914012152\",\"ProxyOrganizationName\":\"\",\"SignOrder\":0,\"ApproveName\":\"曹晓亮\",\"ApproveStatus\":\"PENDING\",\"ApproveMessage\":\"\",\"ApproveTime\":0,\"CaSign\":\"\"}],\"OccurTime\":1699077064,\"CcInfo\":[]}}"
|
|
|
m := make(map[string]interface{})
|