|
|
@@ -33,6 +33,9 @@ func (t *THJNtf) Process(msg *[]byte) {
|
|
|
// 等待两秒
|
|
|
<-time.After(2 * time.Second)
|
|
|
onTHJPurchaseTradeNtf(&bytes)
|
|
|
+ case uint32(global.THJPurchaseTradeNtf):
|
|
|
+ <-time.After(2 * time.Second)
|
|
|
+ onTHJPurchaseTransferNtf(&bytes)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -54,7 +57,7 @@ func onTHJPurchaseTradeNtf(bytes *[]byte) {
|
|
|
// 铁合金采购成交扩展信息
|
|
|
thjpurchasetradedetail := model.Thjpurchasetradedetail{WRTRADEDETAILID: int64(p.GetWRTradeDetailID())}
|
|
|
if has, err := thjpurchasetradedetail.Get(); err != nil || !has {
|
|
|
- global.M2A_LOG.Error("[onTHJPurchaseTradeNtf] 获取铁合金采购成交扩展信息失败", zap.Error(err))
|
|
|
+ global.M2A_LOG.Error("[铁合金成交通知] 获取铁合金采购成交扩展信息失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
// 交割方式
|
|
|
@@ -66,27 +69,27 @@ func onTHJPurchaseTradeNtf(bytes *[]byte) {
|
|
|
// 现货商品信息
|
|
|
wrstandard := model.Wrstandard{WRSTANDARDID: int64(thjpurchasetradedetail.WRSTANDARDID)}
|
|
|
if has, err := wrstandard.Get(); err != nil || !has {
|
|
|
- global.M2A_LOG.Error("[onTHJPurchaseTradeNtf] 获取现货商品信息失败", zap.Error(err))
|
|
|
+ global.M2A_LOG.Error("[铁合金成交通知] 获取现货商品信息失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 仓单预售信息
|
|
|
wrpresaleinfo := model.Wrpresaleinfo{PRESALEAPPLYID: thjpurchasetradedetail.PRESALEAPPLYID}
|
|
|
if has, err := wrpresaleinfo.Get(); err != nil || !has {
|
|
|
- global.M2A_LOG.Error("[onTHJPurchaseTradeNtf] 获取仓单预售信息失败", zap.Error(err))
|
|
|
+ global.M2A_LOG.Error("[铁合金成交通知] 获取仓单预售信息失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 甲方信息
|
|
|
userinfo := model.Userinfo{USERID: thjpurchasetradedetail.BUYUSERID}
|
|
|
if has, err := userinfo.Get(); err != nil || !has {
|
|
|
- global.M2A_LOG.Error("[onTHJPurchaseTradeNtf] 获取甲方信息失败", zap.Error(err))
|
|
|
+ global.M2A_LOG.Error("[铁合金成交通知] 获取甲方信息失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
division := model.Division{AUTOID: int64(userinfo.DISTRICTID)}
|
|
|
totalAddress, err := division.GetTotalAddressByDistrictID(userinfo.ADDRESS)
|
|
|
if err != nil {
|
|
|
- global.M2A_LOG.Error("[onTHJPurchaseTradeNtf] 获取甲方地址信息失败", zap.Error(err))
|
|
|
+ global.M2A_LOG.Error("[铁合金成交通知] 获取甲方地址信息失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
// 证件号码解密
|
|
|
@@ -110,7 +113,7 @@ func onTHJPurchaseTradeNtf(bytes *[]byte) {
|
|
|
// 甲方签约信息
|
|
|
bankaccountsign := model.Bankaccountsign{}
|
|
|
if has, err := bankaccountsign.GetByUserID(uint64(thjpurchasetradedetail.BUYUSERID)); err != nil || !has {
|
|
|
- global.M2A_LOG.Error("[onTHJPurchaseTradeNtf] 获取甲方签约信息失败", zap.Error(err))
|
|
|
+ global.M2A_LOG.Error("[铁合金成交通知] 获取甲方签约信息失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
// 账号解密
|
|
|
@@ -125,14 +128,14 @@ func onTHJPurchaseTradeNtf(bytes *[]byte) {
|
|
|
// 银行信息
|
|
|
bankinfo := model.Bankbankinfo{BANKID: bankaccountsign.BANKID}
|
|
|
if has, err := bankinfo.Get(); err != nil || !has {
|
|
|
- global.M2A_LOG.Error("[onTHJPurchaseTradeNtf] 获取银行信息失败", zap.Error(err))
|
|
|
+ global.M2A_LOG.Error("[铁合金成交通知] 获取银行信息失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 生产厂家信息
|
|
|
selluserinfo := model.Userinfo{USERID: thjpurchasetradedetail.SELLUSERID}
|
|
|
if has, err := selluserinfo.Get(); err != nil || !has {
|
|
|
- global.M2A_LOG.Error("[onTHJPurchaseTradeNtf] 获取生产厂家信息失败", zap.Error(err))
|
|
|
+ global.M2A_LOG.Error("[铁合金成交通知] 获取生产厂家信息失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -185,7 +188,7 @@ func onTHJPurchaseTradeNtf(bytes *[]byte) {
|
|
|
success := utils.ConvertToPDF("./.tmp/"+docxFilename, savePath)
|
|
|
if !success {
|
|
|
// 转换失败
|
|
|
- global.M2A_LOG.Error("[onTHJPurchaseTradeNtf] docx转换pdf失败", zap.Error(err))
|
|
|
+ global.M2A_LOG.Error("[铁合金成交通知] docx转换pdf失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -193,8 +196,219 @@ func onTHJPurchaseTradeNtf(bytes *[]byte) {
|
|
|
// pdfFilename = docxFilename // 临时代码
|
|
|
thjpurchasetradedetail.CONTRACTADDRBUY = fmt.Sprintf("./uploadFile/%v/%v", folderPath, pdfFilename)
|
|
|
if err = thjpurchasetradedetail.UpdateContractAddrBuy(); err != nil {
|
|
|
- global.M2A_LOG.Error("[onTHJPurchaseTradeNtf] 更新数据库失败", zap.Error(err))
|
|
|
+ global.M2A_LOG.Error("[铁合金成交通知] 更新数据库失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ global.M2A_LOG.Info("[铁合金成交通知] 合同生成成功", zap.Any("file", savePath+pdfFilename))
|
|
|
+}
|
|
|
+
|
|
|
+// onTHJPurchaseTransferNtf 铁合金协议转让通知
|
|
|
+func onTHJPurchaseTransferNtf(bytes *[]byte) {
|
|
|
+ // Read from docx file
|
|
|
+ r, err := docx.ReadDocxFile("./static/协议转让合同.docx")
|
|
|
+ if err != nil {
|
|
|
+ global.M2A_LOG.Error("读取合同文件失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var p pb.PurchaseTransferNtf
|
|
|
+ if err := proto.Unmarshal(*bytes, &p); err != nil {
|
|
|
+ global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 铁合金采购协议表
|
|
|
+ thjpurchasetransfer := model.Thjpurchasetransfer{TRANSFERID: int64(p.GetTransferID())}
|
|
|
+ if has, err := thjpurchasetransfer.Get(); err != nil || !has {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 获取铁合金采购成交扩展信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 铁合金采购成交扩展信息
|
|
|
+ thjpurchasetradedetail := model.Thjpurchasetradedetail{WRTRADEDETAILID: thjpurchasetransfer.WRTRADEDETAILID}
|
|
|
+ if has, err := thjpurchasetradedetail.Get(); err != nil || !has {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 获取铁合金采购成交扩展信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 现货商品信息
|
|
|
+ wrstandard := model.Wrstandard{WRSTANDARDID: int64(thjpurchasetradedetail.WRSTANDARDID)}
|
|
|
+ if has, err := wrstandard.Get(); err != nil || !has {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 获取现货商品信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // ******************* 甲方信息(卖方)*******************
|
|
|
+ a_userinfo := model.Userinfo{USERID: thjpurchasetransfer.SELLUSERID}
|
|
|
+ if has, err := a_userinfo.Get(); err != nil || !has {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 获取甲方信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ a_division := model.Division{AUTOID: int64(a_userinfo.DISTRICTID)}
|
|
|
+ a_totalAddress, err := a_division.GetTotalAddressByDistrictID(a_userinfo.ADDRESS)
|
|
|
+ if err != nil {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 获取甲方地址信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 证件号码解密
|
|
|
+ key, _ := hex.DecodeString(utils.AESSecretKey)
|
|
|
+ if len(a_userinfo.CARDNUM) > 0 {
|
|
|
+ if cardnum, err := hex.DecodeString(a_userinfo.CARDNUM); err == nil { // hex -> []byte
|
|
|
+ if c, err := utils.AESDecrypt(cardnum, key); err == nil {
|
|
|
+ a_userinfo.CARDNUM = string(c)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 手机号码解密
|
|
|
+ if len(a_userinfo.MOBILE) > 0 {
|
|
|
+ if phonenum, err := hex.DecodeString(a_userinfo.MOBILE); err == nil { // hex -> []byte
|
|
|
+ if mobile, err := utils.AESDecrypt(phonenum, key); err == nil {
|
|
|
+ a_userinfo.MOBILE = string(mobile)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 签约信息
|
|
|
+ a_bankaccountsign := model.Bankaccountsign{}
|
|
|
+ if has, err := a_bankaccountsign.GetByUserID(uint64(thjpurchasetradedetail.BUYUSERID)); err != nil || !has {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 获取甲方签约信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 账号解密
|
|
|
+ if len(a_bankaccountsign.BANKACCOUNTNO) > 0 {
|
|
|
+ if tt, err := hex.DecodeString(a_bankaccountsign.BANKACCOUNTNO); err == nil { // hex -> []byte
|
|
|
+ if dd, err := utils.AESDecrypt(tt, key); err == nil {
|
|
|
+ a_bankaccountsign.BANKACCOUNTNO = string(dd)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 银行信息
|
|
|
+ a_bankinfo := model.Bankbankinfo{BANKID: a_bankaccountsign.BANKID}
|
|
|
+ if has, err := a_bankinfo.Get(); err != nil || !has {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 获取银行信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // ******************* 乙方信息(买方)*******************
|
|
|
+ b_userinfo := model.Userinfo{USERID: thjpurchasetransfer.SELLUSERID}
|
|
|
+ if has, err := b_userinfo.Get(); err != nil || !has {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 获取甲方信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ b_division := model.Division{AUTOID: int64(b_userinfo.DISTRICTID)}
|
|
|
+ b_totalAddress, err := b_division.GetTotalAddressByDistrictID(b_userinfo.ADDRESS)
|
|
|
+ if err != nil {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 获取甲方地址信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 证件号码解密
|
|
|
+ if len(b_userinfo.CARDNUM) > 0 {
|
|
|
+ if cardnum, err := hex.DecodeString(b_userinfo.CARDNUM); err == nil { // hex -> []byte
|
|
|
+ if c, err := utils.AESDecrypt(cardnum, key); err == nil {
|
|
|
+ b_userinfo.CARDNUM = string(c)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 手机号码解密
|
|
|
+ if len(b_userinfo.MOBILE) > 0 {
|
|
|
+ if phonenum, err := hex.DecodeString(b_userinfo.MOBILE); err == nil { // hex -> []byte
|
|
|
+ if mobile, err := utils.AESDecrypt(phonenum, key); err == nil {
|
|
|
+ b_userinfo.MOBILE = string(mobile)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 签约信息
|
|
|
+ b_bankaccountsign := model.Bankaccountsign{}
|
|
|
+ if has, err := b_bankaccountsign.GetByUserID(uint64(thjpurchasetradedetail.BUYUSERID)); err != nil || !has {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 获取甲方签约信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 账号解密
|
|
|
+ if len(b_bankaccountsign.BANKACCOUNTNO) > 0 {
|
|
|
+ if tt, err := hex.DecodeString(b_bankaccountsign.BANKACCOUNTNO); err == nil { // hex -> []byte
|
|
|
+ if dd, err := utils.AESDecrypt(tt, key); err == nil {
|
|
|
+ b_bankaccountsign.BANKACCOUNTNO = string(dd)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 银行信息
|
|
|
+ b_bankinfo := model.Bankbankinfo{BANKID: a_bankaccountsign.BANKID}
|
|
|
+ if has, err := b_bankinfo.Get(); err != nil || !has {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 获取银行信息失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ docx1 := r.Editable()
|
|
|
+ docx1.Replace("TRANSFERID", strconv.Itoa(int(thjpurchasetransfer.TRANSFERID)), -1)
|
|
|
+ if transfertradedate, e := time.Parse("20060102", thjpurchasetransfer.TRANSFERTRADEDATE); e != nil {
|
|
|
+ docx1.Replace("TRANSFERTRADEDATE", transfertradedate.Format("2006年01月02日"), -1)
|
|
|
+ }
|
|
|
+ docx1.Replace("WRSTANDARDNAME", wrstandard.WRSTANDARDNAME, -1)
|
|
|
+ docx1.Replace("WRTRADEDETAILID", strconv.Itoa(int(thjpurchasetradedetail.WRTRADEDETAILID)), -1)
|
|
|
+ docx1.Replace("TRANSFERQTY", strconv.Itoa(int(thjpurchasetransfer.TRANSFERQTY)), -1)
|
|
|
+ docx1.Replace("TRADEAMOUNT", strconv.FormatFloat(thjpurchasetradedetail.TRADEAMOUNT, 'f', -1, 64), -1)
|
|
|
+ docx1.Replace("TRANSFERAMOUNT", strconv.FormatFloat(thjpurchasetransfer.TRANSFERAMOUNT, 'f', -1, 64), -1)
|
|
|
+ docx1.Replace("TRANSFERPRICE", strconv.FormatFloat(thjpurchasetransfer.TRANSFERPRICE, 'f', -1, 64), -1)
|
|
|
+ // ********************* 甲方 *********************
|
|
|
+ // 判断甲方是公司还是个人
|
|
|
+ if a_userinfo.USERINFOTYPE == 1 {
|
|
|
+ // 个人
|
|
|
+ docx1.Replace("PARTYA_COMPANY", "", -1)
|
|
|
+ docx1.Replace("PARTYA_LEGALPERSONNAME", a_userinfo.CUSTOMERNAME, -1)
|
|
|
+ } else {
|
|
|
+ // 公司
|
|
|
+ docx1.Replace("PARTYA_COMPANY", a_userinfo.CUSTOMERNAME, -1)
|
|
|
+ docx1.Replace("PARTYA_LEGALPERSONNAME", a_userinfo.LEGALPERSONNAME, -1)
|
|
|
+ }
|
|
|
+ docx1.Replace("PARTYA_DESADDRESS", a_totalAddress, -1)
|
|
|
+ docx1.Replace("PARTYA_CARDNUM", a_userinfo.CARDNUM, -1)
|
|
|
+ docx1.Replace("PARTYA_MOBILE", a_userinfo.MOBILE, -1)
|
|
|
+ docx1.Replace("PARTYA_BANK_BANKACCOUNTNO",
|
|
|
+ fmt.Sprintf("%v%v", a_bankinfo.BANKNAME, a_bankaccountsign.BANKACCOUNTNO), -1)
|
|
|
+ // ********************* 乙方 *********************
|
|
|
+ // 判断乙方是公司还是个人
|
|
|
+ if b_userinfo.USERINFOTYPE == 1 {
|
|
|
+ // 个人
|
|
|
+ docx1.Replace("PARTYB_COMPANY", "", -1)
|
|
|
+ docx1.Replace("PARTYB_LEGALPERSONNAME", b_userinfo.CUSTOMERNAME, -1)
|
|
|
+ } else {
|
|
|
+ // 公司
|
|
|
+ docx1.Replace("PARTYB_COMPANY", b_userinfo.CUSTOMERNAME, -1)
|
|
|
+ docx1.Replace("PARTYB_LEGALPERSONNAME", b_userinfo.LEGALPERSONNAME, -1)
|
|
|
+ }
|
|
|
+ docx1.Replace("PARTYB_DESADDRESS", b_totalAddress, -1)
|
|
|
+ docx1.Replace("PARTYB_CARDNUM", b_userinfo.CARDNUM, -1)
|
|
|
+ docx1.Replace("PARTYB_MOBILE", b_userinfo.MOBILE, -1)
|
|
|
+ docx1.Replace("PARTYB_BANK_BANKACCOUNTNO",
|
|
|
+ fmt.Sprintf("%v%v", b_bankinfo.BANKNAME, b_bankaccountsign.BANKACCOUNTNO), -1)
|
|
|
+
|
|
|
+ // 暂存docx文件
|
|
|
+ if exist, _ := utils.PathExists("./.tmp"); !exist {
|
|
|
+ os.Mkdir("./.tmp", os.ModePerm)
|
|
|
+ }
|
|
|
+ uid, _ := uuid.NewV4()
|
|
|
+ docxFilename := fmt.Sprintf("%v_%v.docx", strconv.Itoa(int(thjpurchasetransfer.TRANSFERID)), uid.String())
|
|
|
+ pdfFilename := strings.Replace(docxFilename, "docx", "pdf", -1)
|
|
|
+ docx1.WriteToFile("./.tmp/" + docxFilename)
|
|
|
+ r.Close()
|
|
|
+
|
|
|
+ // 导出pdf到目标目录
|
|
|
+ folderPath := "Agreement_Assignment/" + time.Now().Format("20060102")
|
|
|
+ savePath := global.M2A_CONFIG.System.StorePath + "/" + folderPath
|
|
|
+ if exist, _ := utils.PathExists(savePath); !exist {
|
|
|
+ os.MkdirAll(savePath, os.ModePerm)
|
|
|
+ }
|
|
|
+ success := utils.ConvertToPDF("./.tmp/"+docxFilename, savePath)
|
|
|
+ if !success {
|
|
|
+ // 转换失败
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] docx转换pdf失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新数据库
|
|
|
+ thjpurchasetransfer.CONTRACTADDR = fmt.Sprintf("./uploadFile/%v/%v", folderPath, pdfFilename)
|
|
|
+ if err = thjpurchasetransfer.UpdateContractAddr(); err != nil {
|
|
|
+ global.M2A_LOG.Error("[铁合金协议转让通知] 更新数据库失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
- global.M2A_LOG.Info("[onTHJPurchaseTradeNtf] 合同生成成功", zap.Any("file", savePath+pdfFilename))
|
|
|
+ global.M2A_LOG.Info("[铁合金协议转让通知] 合同生成成功", zap.Any("file", savePath+pdfFilename))
|
|
|
}
|