作者 陈志颖

test:合约变更记录

1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "crypto/md5"
  5 + "encoding/hex"
4 "fmt" 6 "fmt"
5 "strconv" 7 "strconv"
6 "time" 8 "time"
@@ -1266,8 +1268,19 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1266,8 +1268,19 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1266 } 1268 }
1267 } else if cooperationContractFound.IncentivesType == cooperationContract.IncentivesType { // 2.激励规则内容变更 1269 } else if cooperationContractFound.IncentivesType == cooperationContract.IncentivesType { // 2.激励规则内容变更
1268 if cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES { // 业绩分红规则内容变更 1270 if cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES { // 业绩分红规则内容变更
1269 - if !cooperationContract.DividendsIncentivesRuleSliceEqualBCE(cooperationContractFound.DividendsIncentivesRules, cooperationContract.DividendsIncentivesRules) { 1271 + // 计算原合约哈希值
  1272 + cooperationContractFoundByte := utils.AnyToHex(cooperationContractFound.MoneyIncentivesRules)
  1273 + cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
  1274 + cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
  1275 +
  1276 + // 计算更新后的合约哈希值
  1277 + cooperationContractByte := utils.AnyToHex(cooperationContract.MoneyIncentivesRules)
  1278 + cooperationContractHashValue := md5.Sum(cooperationContractByte)
  1279 + cooperationContractHashString := hex.EncodeToString(cooperationContractHashValue[:])
  1280 + //if !cooperationContract.DividendsIncentivesRuleSliceEqualBCE(cooperationContractFound.DividendsIncentivesRules, cooperationContract.DividendsIncentivesRules) {
  1281 + if cooperationContractFoundHashString != cooperationContractHashString {
1270 // 业绩分红-->业绩分红 1282 // 业绩分红-->业绩分红
  1283 +
1271 incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContract.IncentivesType)) 1284 incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContract.IncentivesType))
1272 //【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】 1285 //【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】
1273 // 原业绩分红激励规则 1286 // 原业绩分红激励规则
@@ -1296,7 +1309,18 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1296,7 +1309,18 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1296 incentivesRuleChangeDetail = dividendsIncentivesRuleOriginalTmp + " 变更为 " + dividendsIncentivesRuleChangedTmp 1309 incentivesRuleChangeDetail = dividendsIncentivesRuleOriginalTmp + " 变更为 " + dividendsIncentivesRuleChangedTmp
1297 } 1310 }
1298 } else if cooperationContractFound.IncentivesType == domain.MONEY_INCENTIVES { // 金额激励规则内容变更 1311 } else if cooperationContractFound.IncentivesType == domain.MONEY_INCENTIVES { // 金额激励规则内容变更
1299 - if !cooperationContract.MoneyIncentivesRuleSliceEqualBCE(cooperationContractFound.MoneyIncentivesRules, cooperationContract.MoneyIncentivesRules) { 1312 + // 计算原合约哈希值
  1313 + cooperationContractFoundByte := utils.AnyToHex(cooperationContractFound.MoneyIncentivesRules)
  1314 + cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
  1315 + cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
  1316 +
  1317 + // 计算更新后的合约哈希值
  1318 + cooperationContractByte := utils.AnyToHex(cooperationContract.MoneyIncentivesRules)
  1319 + cooperationContractHashValue := md5.Sum(cooperationContractByte)
  1320 + cooperationContractHashString := hex.EncodeToString(cooperationContractHashValue[:])
  1321 +
  1322 + //if !cooperationContract.MoneyIncentivesRuleSliceEqualBCE(cooperationContractFound.MoneyIncentivesRules, cooperationContract.MoneyIncentivesRules) {
  1323 + if cooperationContractFoundHashString != cooperationContractHashString {
1300 incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContract.IncentivesType)) 1324 incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContract.IncentivesType))
1301 //【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】 1325 //【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】
1302 // 原金额激励规则 1326 // 原金额激励规则
@@ -1326,7 +1350,18 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1326,7 +1350,18 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1326 } 1350 }
1327 1351
1328 // 承接人变更 1352 // 承接人变更
1329 - if !cooperationContract.UndertakerSliceEqualBCE(cooperationContractFound.Undertakers, cooperationContract.Undertakers) { // 【1(张三,李四,王五)2(买买买,,)】变更为【1(张三,,)】 1353 + // 计算原合约哈希值
  1354 + cooperationContractFoundByte := utils.AnyToHex(cooperationContractFound.Undertakers)
  1355 + cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
  1356 + cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
  1357 +
  1358 + // 计算更新后的合约哈希值
  1359 + cooperationContractByte := utils.AnyToHex(cooperationContract.Undertakers)
  1360 + cooperationContractHashValue := md5.Sum(cooperationContractByte)
  1361 + cooperationContractHashString := hex.EncodeToString(cooperationContractHashValue[:])
  1362 +
  1363 + //if !cooperationContract.UndertakerSliceEqualBCE(cooperationContractFound.Undertakers, cooperationContract.Undertakers) { // 【1(张三,李四,王五)2(买买买,,)】变更为【1(张三,,)】
  1364 + if cooperationContractFoundHashString != cooperationContractHashString {
1330 // 原承接人 1365 // 原承接人
1331 var undertakersOriginal string 1366 var undertakersOriginal string
1332 for i, undertaker := range cooperationContractFound.Undertakers { 1367 for i, undertaker := range cooperationContractFound.Undertakers {
1 package utils 1 package utils
2 2
3 import ( 3 import (
  4 + "bytes"
  5 + "encoding/binary"
4 "fmt" 6 "fmt"
5 "github.com/shopspring/decimal" 7 "github.com/shopspring/decimal"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
6 "strconv" 9 "strconv"
7 "strings" 10 "strings"
8 ) 11 )
@@ -160,3 +163,13 @@ func IsContain64(items []int64, item int64) bool { @@ -160,3 +163,13 @@ func IsContain64(items []int64, item int64) bool {
160 } 163 }
161 return false 164 return false
162 } 165 }
  166 +
  167 +func AnyToHex(any interface{}) []byte {
  168 + buff := new(bytes.Buffer)
  169 + //数据写入buff
  170 + err := binary.Write(buff, binary.BigEndian, any)
  171 + if err != nil {
  172 + log.Logger.Error(err.Error())
  173 + }
  174 + return buff.Bytes()
  175 +}