作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-cooperation into dev
... ... @@ -4,6 +4,7 @@ go 1.16
require (
github.com/Shopify/sarama v1.25.0
github.com/Tnze/go.num/v2 v2.0.0-20191006170829-cb483d4c9152 // indirect
github.com/ajg/form v1.5.1 // indirect
github.com/beego/beego/v2 v2.0.1
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
... ...
... ... @@ -5,6 +5,8 @@ github.com/Shopify/sarama v1.25.0 h1:ch1ywjRLjfJtU+EaiJ+l0rWffQ6TRpyYmW4DX7Cb2SU
github.com/Shopify/sarama v1.25.0/go.mod h1:y/CFFTO9eaMTNriwu/Q+W4eioLqiDMGkA1W+gmdfj8w=
github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/Tnze/go.num/v2 v2.0.0-20191006170829-cb483d4c9152 h1:6Ny2zcG2k/0aOE8rLbDdLdPMr0o7lqMfdnYJe6pZj9w=
github.com/Tnze/go.num/v2 v2.0.0-20191006170829-cb483d4c9152/go.mod h1:fNGLFjpxgDvBqQPv1HYSuGi6pRuI8wdKvvspYvUQufc=
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
... ...
... ... @@ -507,7 +507,7 @@ func (cooperationContractService *CooperationContractService) OperateCooperation
}); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if cooperationContract, err := cooperationContractRepository.Save(cooperationContract); err != nil {
if cooperationContract, err := cooperationContractRepository.UpdateOne(cooperationContract); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
... ...
... ... @@ -8,6 +8,6 @@ type Attachment struct {
Name string `json:"name"`
// 附件地址
Url string `json:"url"`
// 附件文件大小
FileSize int64 `json:"fileSize,string"`
// 附件文件大小,保存KB单位
FileSize int64 `json:"fileSize"`
}
... ...
... ... @@ -50,7 +50,8 @@ type CooperationContract struct {
type CooperationContractRepository interface {
Save(cooperationContract *CooperationContract) (*CooperationContract, error)
UpdateMany(cooperationContract []*CooperationContract) ([]*CooperationContract, error)
UpdateOne(cooperationContract *CooperationContract) (*CooperationContract, error)
UpdateMany(cooperationContracts []*CooperationContract) ([]*CooperationContract, error)
Remove(cooperationContract *CooperationContract) (*CooperationContract, error)
BatchRemove(cooperationContracts []*CooperationContract) ([]*CooperationContract, error)
FindOne(queryOptions map[string]interface{}) (*CooperationContract, error)
... ...
package domain
import "time"
import (
"time"
)
// DividendsIncentivesRule 金额激励规则实体
type DividendsIncentivesRule struct {
... ... @@ -15,7 +17,9 @@ type DividendsIncentivesRule struct {
// 分红规则激励百分点
DividendsIncentivesPercentage float64 `json:"dividendsIncentivesPercentage"`
// 分红规则激励阶段,阶段返回时需要转换为中文数字
DividendsIncentivesStage int64 `json:"dividendsIncentivesStage,string"`
DividendsIncentivesStage int64 `json:"dividendsIncentivesStage"`
// 分红激励规则阶段中文表示
DividendsIncentivesStageCN string `json:"dividendsIncentivesStageCN"`
// 分红规则激励阶段结束
DividendsIncentivesStageEnd time.Time `json:"dividendsIncentivesStageEnd"`
// 分红规则激励阶段开始
... ... @@ -73,20 +77,5 @@ func (dividendsIncentivesRule *DividendsIncentivesRule) Update(data map[string]i
if dividendsIncentivesStageStart, ok := data["dividendsIncentivesStageStart"]; ok {
dividendsIncentivesRule.DividendsIncentivesStageStart = dividendsIncentivesStageStart.(time.Time)
}
if orgId, ok := data["orgId"]; ok {
dividendsIncentivesRule.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
dividendsIncentivesRule.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
dividendsIncentivesRule.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
dividendsIncentivesRule.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
dividendsIncentivesRule.Org.Company.CompanyName = companyName.(string)
}
return nil
}
... ...
package domain
import "time"
import (
"time"
)
// MoneyIncentivesRule 金额激励规则实体
type MoneyIncentivesRule struct {
... ... @@ -11,7 +13,9 @@ type MoneyIncentivesRule struct {
// 激励金额
MoneyIncentivesAmount float64 `json:"moneyIncentivesAmount"`
// 金额激励阶段,阶段返回时需要转换为中文数字
MoneyIncentivesStage int64 `json:"moneyIncentivesStage,string"`
MoneyIncentivesStage int64 `json:"moneyIncentivesStage"`
// 金额激励规则阶段中文表示
MoneyIncentivesStageCN string `json:"moneyIncentivesStageCN"`
// 金额激励阶段有效期结束
MoneyIncentivesStageEnd time.Time `json:"moneyIncentivesStageEnd"`
// 金额激励阶段有效期开始
... ... @@ -78,20 +82,5 @@ func (moneyIncentivesRule *MoneyIncentivesRule) Update(data map[string]interface
if salesmanPercentage, ok := data["salesmanPercentage"]; ok {
moneyIncentivesRule.SalesmanPercentage = salesmanPercentage.(float64)
}
if orgId, ok := data["orgId"]; ok {
moneyIncentivesRule.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
moneyIncentivesRule.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
moneyIncentivesRule.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
moneyIncentivesRule.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
moneyIncentivesRule.Org.Company.CompanyName = companyName.(string)
}
return nil
}
... ...
... ... @@ -3,6 +3,7 @@ package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
)
func TransformToCooperationContractDomainModelFromPgModels(
... ... @@ -15,6 +16,7 @@ func TransformToCooperationContractDomainModelFromPgModels(
// 分红激励规则
var dividendsIncentivesRulesDomain []*domain.DividendsIncentivesRule
for _, rule := range dividendsIncentivesRules {
stageString := utils.NumberToCNNumber(int(rule.DividendsIncentivesStage))
dividendsIncentivesRulesDomain = append(dividendsIncentivesRulesDomain, &domain.DividendsIncentivesRule{
DividendsIncentivesRuleId: rule.DividendsIncentivesRuleId,
CooperationContractNumber: rule.CooperationContractNumber,
... ... @@ -22,6 +24,7 @@ func TransformToCooperationContractDomainModelFromPgModels(
SalesmanPercentage: rule.SalesmanPercentage,
DividendsIncentivesPercentage: rule.DividendsIncentivesPercentage,
DividendsIncentivesStage: rule.DividendsIncentivesStage,
DividendsIncentivesStageCN: stageString,
DividendsIncentivesStageEnd: rule.DividendsIncentivesStageEnd,
DividendsIncentivesStageStart: rule.DividendsIncentivesStageStart,
Org: rule.Org,
... ... @@ -34,11 +37,13 @@ func TransformToCooperationContractDomainModelFromPgModels(
// 金额激励规则
var moneyIncentivesRulesDomain []*domain.MoneyIncentivesRule
for _, rule := range moneyIncentivesRules {
stageString := utils.NumberToCNNumber(int(rule.MoneyIncentivesStage))
moneyIncentivesRulesDomain = append(moneyIncentivesRulesDomain, &domain.MoneyIncentivesRule{
MoneyIncentivesRuleId: rule.MoneyIncentivesRuleId,
CooperationContractNumber: rule.CooperationContractNumber,
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
MoneyIncentivesStage: rule.MoneyIncentivesStage,
MoneyIncentivesStageCN: stageString,
MoneyIncentivesStageEnd: rule.MoneyIncentivesStageEnd,
MoneyIncentivesStageStart: rule.MoneyIncentivesStageStart,
MoneyIncentivesTime: rule.MoneyIncentivesTime,
... ... @@ -77,6 +82,8 @@ func TransformToCooperationContractDomainModelFromPgModels(
Orgs: undertaker.Orgs,
Department: undertaker.Department,
Roles: undertaker.Roles,
Referrer: undertaker.Referrer,
Salesman: undertaker.Salesman,
UserInfo: undertaker.UserInfo,
UserType: undertaker.UserType,
Status: undertaker.Status,
... ...
... ... @@ -3,9 +3,11 @@ package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
)
func TransformToDividendsIncentivesRuleDomainModelFromPgModels(dividendsIncentivesRuleModel *models.DividendsIncentivesRule) (*domain.DividendsIncentivesRule, error) {
stageString := utils.NumberToCNNumber(int(dividendsIncentivesRuleModel.DividendsIncentivesStage))
return &domain.DividendsIncentivesRule{
DividendsIncentivesRuleId: dividendsIncentivesRuleModel.DividendsIncentivesRuleId,
CooperationContractNumber: dividendsIncentivesRuleModel.CooperationContractNumber,
... ... @@ -13,6 +15,7 @@ func TransformToDividendsIncentivesRuleDomainModelFromPgModels(dividendsIncentiv
SalesmanPercentage: dividendsIncentivesRuleModel.SalesmanPercentage,
DividendsIncentivesPercentage: dividendsIncentivesRuleModel.DividendsIncentivesPercentage,
DividendsIncentivesStage: dividendsIncentivesRuleModel.DividendsIncentivesStage,
DividendsIncentivesStageCN: stageString,
DividendsIncentivesStageEnd: dividendsIncentivesRuleModel.DividendsIncentivesStageEnd,
DividendsIncentivesStageStart: dividendsIncentivesRuleModel.DividendsIncentivesStageStart,
Remarks: dividendsIncentivesRuleModel.Remarks,
... ...
... ... @@ -3,14 +3,17 @@ package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
)
func TransformToMoneyIncentivesRuleDomainModelFromPgModels(moneyIncentivesRuleModel *models.MoneyIncentivesRule) (*domain.MoneyIncentivesRule, error) {
stageString := utils.NumberToCNNumber(int(moneyIncentivesRuleModel.MoneyIncentivesStage))
return &domain.MoneyIncentivesRule{
MoneyIncentivesRuleId: moneyIncentivesRuleModel.MoneyIncentivesRuleId,
CooperationContractNumber: moneyIncentivesRuleModel.CooperationContractNumber,
MoneyIncentivesAmount: moneyIncentivesRuleModel.MoneyIncentivesAmount,
MoneyIncentivesStage: moneyIncentivesRuleModel.MoneyIncentivesStage,
MoneyIncentivesStageCN: stageString,
MoneyIncentivesStageEnd: moneyIncentivesRuleModel.MoneyIncentivesStageEnd,
MoneyIncentivesStageStart: moneyIncentivesRuleModel.MoneyIncentivesStageStart,
MoneyIncentivesTime: moneyIncentivesRuleModel.MoneyIncentivesTime,
... ...
... ... @@ -591,6 +591,33 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return cooperationContract, nil
}
func (repository *CooperationContractRepository) UpdateOne(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
tx := repository.transactionContext.PgTx
cooperationContractModel := new(models.CooperationContract)
cooperationContractModel = &models.CooperationContract{
CooperationContractId: cooperationContract.CooperationContractId,
CooperationContractDescription: cooperationContract.CooperationContractDescription,
CooperationContractName: cooperationContract.CooperationContractName,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
CooperationProjectNumber: cooperationContract.CooperationProjectNumber,
CooperationContractUndertakerTypes: cooperationContract.CooperationContractUndertakerTypes,
CooperationContractSponsor: cooperationContract.CooperationContractSponsor,
CooperationModeNumber: cooperationContract.CooperationMode.CooperationModeNumber,
Status: cooperationContract.Status,
Org: cooperationContract.Org,
Company: cooperationContract.Company,
Operator: cooperationContract.Operator,
OperateTime: cooperationContract.OperateTime,
CreatedAt: cooperationContract.CreatedAt,
DeletedAt: cooperationContract.DeletedAt,
UpdatedAt: time.Now(),
}
if _, err := tx.Model(cooperationContractModel).WherePK().Update(); err != nil {
return nil, err
}
return cooperationContract, nil
}
func (repository *CooperationContractRepository) UpdateMany(cooperationContracts []*domain.CooperationContract) ([]*domain.CooperationContract, error) {
tx := repository.transactionContext.PgTx
var cooperationContractModels []*models.CooperationContract
... ... @@ -653,7 +680,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
if _, err := tx.Model(&cooperationContractUndertakerModels).Delete(); err != nil {
return nil, err
}
}
... ... @@ -663,7 +690,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
if _, err := tx.Model(&cooperationContractRelevantModels).Delete(); err != nil {
return nil, err
}
}
... ... @@ -710,7 +737,7 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
if _, err := tx.Model(&cooperationContractUndertakerModels).Delete(); err != nil {
return nil, err
}
}
... ... @@ -720,7 +747,7 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
if _, err := tx.Model(&cooperationContractRelevantModels).Delete(); err != nil {
return nil, err
}
}
... ...
package utils
import (
"strconv"
"fmt"
"github.com/shopspring/decimal"
"strconv"
"strings"
)
// Intersect 返回两个数组的交集
... ... @@ -25,23 +27,6 @@ func Intersect(nums1 []int64, nums2 []int64) []int64 {
return intersection
}
////求交集
//func intersect(slice1, slice2 []int64) []int64 {
// m := make(map[int64]int)
// nn := make([]int64, 0)
// for _, v := range slice1 {
// m[v]++
// }
//
// for _, v := range slice2 {
// times, _ := m[v]
// if times == 1 {
// nn = append(nn, v)
// }
// }
// return nn
//}
// Difference 求差集 slice1-并集
func Difference(slice1, slice2 []int64) []int64 {
m := make(map[int64]int)
... ... @@ -77,4 +62,41 @@ func Round(value float64, places int32) float64 {
d := quantity.Round(places)
rsp, _ := d.Float64()
return rsp
}
\ No newline at end of file
}
// NumberToCNNumber 数字转中文数字
func NumberToCNNumber(num int) string {
chineseMap := []string{"", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千"}
chineseNum := []string{"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}
var listNum []int
for ; num > 0; num = num / 10 {
listNum = append(listNum, num%10)
}
n := len(listNum)
chinese := ""
//注意这里是倒序的
for i := n - 1; i >= 0; i-- {
chinese = fmt.Sprintf("%s%s%s", chinese, chineseNum[listNum[i]], chineseMap[i])
}
//注意替换顺序
for {
copyChinese := chinese
copyChinese = strings.Replace(copyChinese, "零万", "万", 1)
copyChinese = strings.Replace(copyChinese, "零亿", "亿", 1)
copyChinese = strings.Replace(copyChinese, "零十", "零", 1)
copyChinese = strings.Replace(copyChinese, "零百", "零", 1)
copyChinese = strings.Replace(copyChinese, "零千", "零", 1)
copyChinese = strings.Replace(copyChinese, "零零", "", 1)
//copyChinese = strings.Replace(copyChinese, "零圆", "", 1)
//copyChinese = strings.Replace(copyChinese, "零", "", 1)
if copyChinese == chinese {
break
} else {
chinese = copyChinese
}
}
return "第" + chinese + "阶段"
}
... ...
... ... @@ -12,9 +12,4 @@ func init() {
Logger = logrus.NewLogrusLogger()
Logger.SetServiceName(constant.SERVICE_NAME)
Logger.SetLevel(constant.LOG_LEVEL)
//if constant.ENABLE_KAFKA_LOG {
// w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOSTS, constant.TOPIC_LOG_STASH, false)
// Logger.AddHook(w)
//}
}
... ...