作者 陈志颖

feat:调整共创合约编辑服务

... ... @@ -21,31 +21,32 @@ type CreateDividendsIncentivesRulesCommand struct {
}
type CreateMoneyIncentivesRulesCommand struct {
MoneyIncentivesRuleIdString string `cname:"" json:"moneyIncentivesRuleId,string"`
CooperationContractNumber string `cname:"" json:"cooperationContractNumber"`
MoneyIncentivesAmount int `cname:"" json:"moneyIncentivesAmount"`
MoneyIncentivesStage int `cname:"" json:"moneyIncentivesStage"`
MoneyIncentivesStageEnd time.Time `cname:"" json:"moneyIncentivesStageEnd"`
MoneyIncentivesStageStart time.Time `cname:"" json:"moneyIncentivesStageStart"`
MoneyIncentivesTime time.Time `cname:"" json:"moneyIncentivesTime"`
ReferrerPercentage float64 `cname:"" json:"referrerPercentage"`
SalesmanPercentage float64 `cname:"" json:"salesmanPercentage"`
MoneyIncentivesRuleId string `cname:"" json:"moneyIncentivesRuleId,string"`
CooperationContractNumber string `cname:"" json:"cooperationContractNumber"`
MoneyIncentivesAmount int `cname:"" json:"moneyIncentivesAmount"`
MoneyIncentivesStage int `cname:"" json:"moneyIncentivesStage"`
MoneyIncentivesStageEnd time.Time `cname:"" json:"moneyIncentivesStageEnd"`
MoneyIncentivesStageStart time.Time `cname:"" json:"moneyIncentivesStageStart"`
MoneyIncentivesTime time.Time `cname:"" json:"moneyIncentivesTime"`
ReferrerPercentage float64 `cname:"" json:"referrerPercentage"`
SalesmanPercentage float64 `cname:"" json:"salesmanPercentage"`
}
type CreateUndertakersCommand struct {
UndertakerId int64 `cname:"承接人ID" json:"relevantId"`
UserId string `cname:"承接人UID" json:"userId"`
ContractAttachment []struct {
FileType string `json:"fileType"`
Name string `json:"name"`
Url string `json:"url"`
FileSize int64 `json:"fileSize"`
} `json:"contractAttachment"`
ReferrerId string `json:"referrerId"`
SalesmanId string `json:"salesmanId"`
FileType string `cname:"文件类型" json:"fileType"`
Name string `cname:"文件名称" json:"name"`
Url string `cname:"文件路径" json:"url"`
FileSize int64 `cname:"文件大小" json:"fileSize"`
} `cname:"附件" json:"contractAttachment"`
ReferrerId string `cname:"推荐UID" json:"referrerId"`
SalesmanId string `cname:"业务员UID" json:"salesmanId"`
}
type CreateRelevantPeopleCommand struct {
UserId string `json:"userId"`
UserId string `cname:"相关人UID" json:"userId"`
}
type CreateCooperationContractCommand struct {
... ...
... ... @@ -330,7 +330,7 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont
} else {
cooperationContractDao = value
}
//TODO 获取可删除的承接对象类型
// 获取可删除的承接对象类型
undertakerTypesUncheckedAvailable, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
"cooperationContractNumber": cooperationContract.CooperationContractNumber,
"cooperationContractUndertakerTypes": cooperationContract.CooperationContractUndertakerTypes,
... ... @@ -502,6 +502,38 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
_ = transactionContext.RollbackTransaction()
}()
// 公司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())
} 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())
} 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())
} 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())
} else {
organization = data
}
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -517,6 +549,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId)))
}
// 更新合约基础信息
if err := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
// 用户REST服务初始化
var userService service.UserService
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
... ... @@ -549,9 +585,106 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
Company: relevantDomain.Company,
})
}
if err := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
// 更新合约相关人
cooperationContract.RelevantPeople = relevantPeople
//TODO 获取承接人
var undertakers []*domain.Undertaker
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())
} else {
undertakerDomain = data
}
// 获取推荐人
var referrerDomain *domain.Referrer
referrerUid, _ := strconv.ParseInt(undertaker.ReferrerId, 10, 64)
if data, err := userService.ReferrerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, referrerUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
referrerDomain = data
}
// 获取业务员
var salesmanDomain *domain.Salesman
salesmanUid, _ := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
if data, err := userService.SalesmanFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, salesmanUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
salesmanDomain = data
}
undertakers = append(undertakers, &domain.Undertaker{
UndertakerId: undertaker.UndertakerId,
UserId: undertakerDomain.UserId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Orgs: undertakerDomain.Orgs,
Department: undertakerDomain.Department,
Roles: undertakerDomain.Roles,
UserInfo: undertakerDomain.UserInfo,
UserType: undertakerDomain.UserType,
Referrer: referrerDomain,
Salesman: salesmanDomain,
Status: undertakerDomain.Status,
Company: undertakerDomain.Company,
ContractAttachment: nil,
})
}
//TODO 更新承接人
cooperationContract.Undertakers = undertakers
//TODO 获取分红规则列表
var dividendsIncentivesRules []*domain.DividendsIncentivesRule
for _, dividendsIncentivesRule := range updateCooperationContractCommand.DividendsIncentivesRules {
dividendsIncentivesRuleId, _ := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)
dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
DividendsIncentivesRuleId: dividendsIncentivesRuleId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage,
SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage,
DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage,
DividendsIncentivesStage: int64(dividendsIncentivesRule.DividendsIncentivesStage),
DividendsIncentivesStageEnd: dividendsIncentivesRule.DividendsIncentivesStageEnd,
DividendsIncentivesStageStart: dividendsIncentivesRule.DividendsIncentivesStageStart,
Org: organization,
Company: company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
//TODO 更新分红规则列表
cooperationContract.DividendsIncentivesRules = dividendsIncentivesRules
//TODO 获取金额激励规则列表
var moneyIncentivesRules []*domain.MoneyIncentivesRule
for _, moneyIncentivesRule := range updateCooperationContractCommand.MoneyIncentivesRules {
moneyIncentivesRuleId, _ := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)
moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
MoneyIncentivesRuleId: moneyIncentivesRuleId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount),
MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage),
MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart,
MoneyIncentivesTime: time.Now(),
ReferrerPercentage: moneyIncentivesRule.ReferrerPercentage,
SalesmanPercentage: moneyIncentivesRule.SalesmanPercentage,
Org: organization,
Company: company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
//TODO 更新金额激励规则列表
cooperationContract.MoneyIncentivesRules = moneyIncentivesRules
if cooperationContract, err := cooperationContractRepository.Save(cooperationContract); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -22,7 +22,7 @@ type CooperationContract struct {
CooperationContractSponsor *User `json:"cooperationContractSponsor"`
// 共创模式或者合伙模式
CooperationMode *CooperationMode `json:"cooperationMode"`
// 合约状态,1启用,2禁用
// 合约状态,1恢复,2暂停
Status int32 `json:"status"`
// 数据所属组织机构
Org *Org `json:"org"`
... ...
... ... @@ -282,8 +282,10 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
})
}
// 添加相关人
if _, err := tx.Model(&cooperationContractRelevantPeopleToAddModels).Insert(); err != nil {
return nil, err
if len(cooperationContractRelevantPeopleToAddModels) > 0 {
if _, err := tx.Model(&cooperationContractRelevantPeopleToAddModels).Insert(); err != nil {
return nil, err
}
}
// 待更新或者删除的ids
... ... @@ -302,8 +304,10 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
if _, err := tx.Model(&relevantModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
if len(relevantModelsToUpdate) > 0 {
if _, err := tx.Model(&relevantModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
}
}
// 待删除的相关人id
... ... @@ -316,7 +320,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
if _, err := tx.Model(&relevantModelsToDelete).WherePK().Delete(); err != nil {
if _, err := tx.Model(&relevantModelsToDelete).Delete(); err != nil {
return nil, err
}
... ... @@ -367,8 +371,10 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
})
}
// 添加承接人
if _, err := tx.Model(&cooperationContractUndertakersToAddModels).Insert(); err != nil {
return nil, err
if len(cooperationContractUndertakersToAddModels) > 0 {
if _, err := tx.Model(&cooperationContractUndertakersToAddModels).Insert(); err != nil {
return nil, err
}
}
// 待更新或者删除的ids
... ... @@ -387,11 +393,13 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
if len(undertakerModelsToUpdate) > 0 {
if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
}
}
// 待删除的相关人id
// 待删除的承接人id
undertakerIdsToDelete := utils.Difference(cooperationContractUndertakersIdsFetched, cooperationContractUndertakersToUpdateOrDeleteIds)
var undertakerModelsToDelete []*models.CooperationContractUndertaker
for _, id := range undertakerIdsToDelete {
... ... @@ -401,7 +409,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
if _, err := tx.Model(&relevantModelsToDelete).WherePK().Delete(); err != nil {
if _, err := tx.Model(&undertakerModelsToDelete).Delete(); err != nil {
return nil, err
}
... ... @@ -450,8 +458,10 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
})
}
// 添加分红激励规则
if _, err := tx.Model(&dividendsIncentivesRulesToAddModels).Insert(); err != nil {
return nil, err
if len(dividendsIncentivesRulesToAddModels) > 0 {
if _, err := tx.Model(&dividendsIncentivesRulesToAddModels).Insert(); err != nil {
return nil, err
}
}
// 待更新或者删除的ids
... ... @@ -470,8 +480,10 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
if _, err := tx.Model(&dividendsRuleModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
if len(dividendsRuleModelsToUpdate) > 0 {
if _, err := tx.Model(&dividendsRuleModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
}
}
// 待删除的分红激励规则id
... ... @@ -484,7 +496,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
if _, err := tx.Model(&dividendsIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil {
if _, err := tx.Model(&dividendsIncentivesRuleModelsToDelete).Delete(); err != nil {
return nil, err
}
... ... @@ -533,8 +545,10 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
})
}
// 添加金额激励规则
if _, err := tx.Model(&moneyIncentivesRulesToAddModels).Insert(); err != nil {
return nil, err
if len(moneyIncentivesRulesToAddModels) > 0 {
if _, err := tx.Model(&moneyIncentivesRulesToAddModels).Insert(); err != nil {
return nil, err
}
}
// 待更新或者删除的ids
... ... @@ -553,8 +567,10 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
if _, err := tx.Model(&moneyRuleModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
if len(moneyRuleModelsToUpdate) > 0 {
if _, err := tx.Model(&moneyRuleModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
}
}
// 待删除的金额激励规则id
... ... @@ -567,7 +583,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
if _, err := tx.Model(&moneyIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil {
if _, err := tx.Model(&moneyIncentivesRuleModelsToDelete).Delete(); err != nil {
return nil, err
}
... ...