作者 陈志颖

feat:共创合约新增合约编号生成方法

... ... @@ -51,9 +51,7 @@ type CreateRelevantPeopleCommand struct {
type CreateCooperationContractCommand struct {
// 共创合约描述
CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription" valid:"Required"`
// 共创合约编号
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber" valid:"Required"`
// 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001
// 共创项目编号
CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber" valid:"Required"`
// 共创合约发起部门编码
DepartmentId string `cname:"共创合约发起部门ID" json:"departmentId" valid:"Required"`
... ...
... ... @@ -9,6 +9,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"strconv"
"time"
)
... ... @@ -90,6 +91,30 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
organization = data
}
// 共创合约DAO初始化
var cooperationContractDao *dao.CooperationContractDao
if value, err := factory.CreateCooperationContractDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
cooperationContractDao = value
}
// 生成共创合约编号
contractNumber, err2 := cooperationContractDao.GenerateContractNumber()
if err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 校验共创合约编号是否唯一
numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{
"companyId": createCooperationContractCommand.CompanyId,
"orgId": createCooperationContractCommand.OrgId,
"cooperationContractNumber": contractNumber,
})
if !numberAvailable {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增共创合约异常")
}
// 获取承接人
var undertakers []*domain.Undertaker
for _, undertaker := range createCooperationContractCommand.Undertakers {
... ... @@ -122,7 +147,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
undertakers = append(undertakers, &domain.Undertaker{
UndertakerId: 0,
UserId: undertakerDomain.UserId,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationContractNumber: contractNumber,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Orgs: undertakerDomain.Orgs,
... ... @@ -150,7 +175,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
}
relevantPeople = append(relevantPeople, &domain.Relevant{
RelevantId: 0,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationContractNumber: contractNumber,
UserId: relevantDomain.UserId,
UserBaseId: relevantDomain.UserBaseId,
Org: relevantDomain.Org,
... ... @@ -169,7 +194,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
for _, dividendsIncentivesRule := range createCooperationContractCommand.DividendsIncentivesRules {
dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
DividendsIncentivesRuleId: 0,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationContractNumber: contractNumber,
ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage,
SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage,
DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage,
... ... @@ -189,7 +214,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
for _, moneyIncentivesRule := range createCooperationContractCommand.MoneyIncentivesRules {
moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
MoneyIncentivesRuleId: 0,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationContractNumber: contractNumber,
MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount),
MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage),
MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
... ... @@ -224,7 +249,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
newCooperationContract := &domain.CooperationContract{
CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription,
CooperationContractName: createCooperationContractCommand.CooperationContractName,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationContractNumber: contractNumber,
CooperationContractUndertakerTypes: createCooperationContractCommand.CooperationContractUndertakerTypes,
CooperationContractSponsor: sponsor,
CooperationMode: cooperationMode,
... ...
... ... @@ -157,7 +157,7 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
"cooperationProjectNumber": projectNumber,
})
if !numberAvailable {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "共创项目编码已存在")
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增共创项目异常")
}
newCooperationProject := &domain.CooperationProject{
CooperationProjectNumber: projectNumber,
... ...