...
|
...
|
@@ -705,12 +705,12 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
if err := updateCooperationContractCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
transactionContext, err1 := factory.CreateTransactionContext(nil)
|
|
|
if err1 != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err1.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
if err2 := transactionContext.StartTransaction(); err2 != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
...
|
...
|
@@ -718,59 +718,76 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
|
|
|
// 公司REST服务初始化
|
|
|
var companyService service.CompanyService
|
|
|
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
if value, err3 := factory.CreateCompanyService(map[string]interface{}{}); err3 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
|
|
|
} else {
|
|
|
companyService = value
|
|
|
}
|
|
|
|
|
|
// 获取公司信息
|
|
|
var company *domain.Company
|
|
|
if data, err := companyService.CompanyFrom(updateCooperationContractCommand.CompanyId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
if data, err4 := companyService.CompanyFrom(updateCooperationContractCommand.CompanyId); err4 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
|
|
|
} else {
|
|
|
company = data
|
|
|
}
|
|
|
|
|
|
// 组织机构REST服务初始化
|
|
|
var organizationService service.OrgService
|
|
|
if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
if value, err5 := factory.CreateOrganizationService(map[string]interface{}{}); err5 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err5.Error())
|
|
|
} else {
|
|
|
organizationService = value
|
|
|
}
|
|
|
|
|
|
// 获取组织机构信息
|
|
|
var organization *domain.Org
|
|
|
if data, err := organizationService.OrgFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
if data, err6 := organizationService.OrgFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId); err6 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
|
|
|
} else {
|
|
|
organization = data
|
|
|
}
|
|
|
|
|
|
var cooperationContractRepository domain.CooperationContractRepository
|
|
|
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
|
|
|
// 共创合约变更记录仓储初始化
|
|
|
var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
|
|
|
if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationContractChangeLogRepository = value
|
|
|
}
|
|
|
|
|
|
// 共创合约仓储初始化
|
|
|
var cooperationContractRepository domain.CooperationContractRepository
|
|
|
if value, err7 := factory.CreateCooperationContractRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err7 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err7.Error())
|
|
|
} else {
|
|
|
cooperationContractRepository = value
|
|
|
}
|
|
|
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": updateCooperationContractCommand.CooperationContractId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
|
|
// 获取待更新的共创合约
|
|
|
cooperationContract, err8 := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": updateCooperationContractCommand.CooperationContractId})
|
|
|
if err8 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err8.Error())
|
|
|
}
|
|
|
if cooperationContract == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId)))
|
|
|
}
|
|
|
|
|
|
cooperationContractFound := cooperationContract
|
|
|
|
|
|
// 更新合约基础信息
|
|
|
if err := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
if err9 := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err9 != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err9.Error())
|
|
|
}
|
|
|
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
if value, err10 := factory.CreateUserService(map[string]interface{}{}); err10 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err10.Error())
|
|
|
} else {
|
|
|
userService = value
|
|
|
}
|
...
|
...
|
@@ -778,8 +795,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
// 获取发起人
|
|
|
var sponsor *domain.User
|
|
|
sponsorUid, _ := strconv.ParseInt(updateCooperationContractCommand.SponsorUid, 10, 64)
|
|
|
if data, err := userService.OperatorFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, sponsorUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
if data, err11 := userService.OperatorFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, sponsorUid); err11 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err11.Error())
|
|
|
} else {
|
|
|
sponsor = data
|
|
|
}
|
...
|
...
|
@@ -792,8 +809,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
for _, relevantPersonUid := range updateCooperationContractCommand.RelevantPeople {
|
|
|
var relevantDomain *domain.Relevant
|
|
|
relevantUid, _ := strconv.ParseInt(relevantPersonUid, 10, 64)
|
|
|
if data, err := userService.RelevantFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, relevantUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
if data, err12 := userService.RelevantFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, relevantUid); err12 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err12.Error())
|
|
|
} else {
|
|
|
relevantDomain = data
|
|
|
}
|
...
|
...
|
@@ -821,8 +838,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
for _, undertaker := range updateCooperationContractCommand.Undertakers {
|
|
|
var undertakerDomain *domain.Undertaker
|
|
|
undertakerUid, _ := strconv.ParseInt(undertaker.UserId, 10, 64)
|
|
|
if data, err := userService.UndertakerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, undertakerUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
if data, err13 := userService.UndertakerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, undertakerUid); err13 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err13.Error())
|
|
|
} else {
|
|
|
undertakerDomain = data
|
|
|
}
|
...
|
...
|
@@ -831,8 +848,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
var referrerDomain *domain.Referrer
|
|
|
referrerUid, _ := strconv.ParseInt(undertaker.ReferrerId, 10, 64)
|
|
|
if referrerUid > 0 {
|
|
|
if data, err := userService.ReferrerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, referrerUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
if data, err14 := userService.ReferrerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, referrerUid); err14 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err14.Error())
|
|
|
} else {
|
|
|
referrerDomain = data
|
|
|
}
|
...
|
...
|
@@ -840,18 +857,21 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
|
|
|
// 获取业务员
|
|
|
var salesmanDomain *domain.Salesman
|
|
|
salesmanUid, _ := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
|
|
|
salesmanUid, err22 := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
|
|
|
if err22 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err22.Error())
|
|
|
}
|
|
|
if salesmanUid > 0 {
|
|
|
if data, err := userService.SalesmanFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, salesmanUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
if data, err15 := userService.SalesmanFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, salesmanUid); err15 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err15.Error())
|
|
|
} else {
|
|
|
salesmanDomain = data
|
|
|
}
|
|
|
}
|
|
|
|
|
|
undertakerId, err3 := strconv.ParseInt(undertaker.UndertakerId, 10, 64)
|
|
|
if err3 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
|
|
|
undertakerId, err16 := strconv.ParseInt(undertaker.UndertakerId, 10, 64)
|
|
|
if err16 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err16.Error())
|
|
|
}
|
|
|
undertakers = append(undertakers, &domain.Undertaker{
|
|
|
UndertakerId: undertakerId,
|
...
|
...
|
@@ -877,9 +897,9 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
// 获取分红规则列表
|
|
|
var dividendsIncentivesRules []*domain.DividendsIncentivesRule
|
|
|
for _, dividendsIncentivesRule := range updateCooperationContractCommand.DividendsIncentivesRules {
|
|
|
dividendsIncentivesRuleId, err2 := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)
|
|
|
if err2 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
|
|
|
dividendsIncentivesRuleId, err17 := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)
|
|
|
if err17 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err17.Error())
|
|
|
}
|
|
|
dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
|
|
|
DividendsIncentivesRuleId: dividendsIncentivesRuleId,
|
...
|
...
|
@@ -903,9 +923,9 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
// 获取金额激励规则列表
|
|
|
var moneyIncentivesRules []*domain.MoneyIncentivesRule
|
|
|
for _, moneyIncentivesRule := range updateCooperationContractCommand.MoneyIncentivesRules {
|
|
|
moneyIncentivesRuleId, err4 := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)
|
|
|
if err4 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
|
|
|
moneyIncentivesRuleId, err18 := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)
|
|
|
if err18 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err18.Error())
|
|
|
}
|
|
|
moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
|
|
|
MoneyIncentivesRuleId: moneyIncentivesRuleId,
|
...
|
...
|
@@ -927,13 +947,35 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
// 更新金额激励规则列表
|
|
|
cooperationContract.MoneyIncentivesRules = moneyIncentivesRules
|
|
|
|
|
|
if cooperationContract, err := cooperationContractRepository.Save(cooperationContract); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// 保存共创合约变更
|
|
|
if cooperationContractSaved, err19 := cooperationContractRepository.Save(cooperationContract); err19 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err19.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
// TODO 保存共创合约变更记录
|
|
|
var incentivesRule string
|
|
|
var incentivesRuleDetail string
|
|
|
if cooperationContractFound.IncentivesType != cooperationContractSaved.IncentivesType { // 1.激励规则变更
|
|
|
|
|
|
}
|
|
|
return cooperationContract, nil
|
|
|
|
|
|
newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
|
|
|
IncentivesRule: incentivesRule,
|
|
|
IncentivesRuleDetail: incentivesRuleDetail,
|
|
|
OperationType: 0,
|
|
|
Undertakers: "",
|
|
|
CooperationContractNumber: cooperationContractSaved.CooperationContractNumber,
|
|
|
Company: company,
|
|
|
Operator: nil,
|
|
|
UpdatedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
}
|
|
|
if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
|
|
|
}
|
|
|
if err21 := transactionContext.CommitTransaction(); err21 != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err21.Error())
|
|
|
}
|
|
|
return cooperationContractSaved, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|