作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

... ... @@ -619,6 +619,15 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
var dividendsEstimates []*domain.DividendsEstimate
// 统计当前分红预算单数
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var countDividendsEstimate int64
for _, orderGood := range orderGoods {
dividendsEstimate := &domain.DividendsEstimate{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
... ... @@ -637,18 +646,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// 统计当前分红预算单数
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
for i, dividendsEstimateDetail := range dividendsEstimateDetails {
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), int64(i))
dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
countDividendsEstimate = countDividendsEstimate + 1
dividendsEstimate = &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
... ... @@ -735,7 +739,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
// TODO 分析成功和失败原因
successfullyCount := len(dividendsEstimatesSaved)
return fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d订单分红预算失败,失败原因:%s", countDividendsOrders, successfullyCount, 0, ""), nil
return fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", countDividendsOrders, successfullyCount, 0, ""), nil
}
}
}
... ...
... ... @@ -80,6 +80,12 @@ func (dao *DividendsEstimateDao) CountDividendsEstimate(queryOptions map[string]
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return 0, err
} else {
... ...
... ... @@ -44,7 +44,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
// 获取合约
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractNumber": orderGood.CooperationContractNumber})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创合约不存在")
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber))
... ... @@ -112,7 +112,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Roles: undertaker.Referrer.Roles,
UserInfo: undertaker.Referrer.UserInfo,
UserType: undertaker.Referrer.UserType,
UserName: undertaker.Referrer.UserInfo.UserName,
UserName: undertaker.Referrer.UserName,
UserPhone: undertaker.Referrer.UserPhone,
Company: undertaker.Referrer.Company,
},
... ...
... ... @@ -1041,7 +1041,15 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string
cooperationContractModel := new(models.CooperationContract)
query := sqlbuilder.BuildQuery(tx.Model(cooperationContractModel), queryOptions)
query.SetWhereByQueryOption("cooperation_contract.cooperation_contract_id = ?", "cooperationContractId")
query.SetWhereByQueryOption("cooperation_contract.cooperation_contract_number = ?", "cooperationContractNumber")
if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
query.Where("cooperation_contract.cooperation_contract_number = ?", cooperationContractNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("共创合约不存在")
... ... @@ -1053,62 +1061,78 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string
return nil, nil
} else {
// 获取共创模式
cooperationModeModels := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModels)
if err := cooperationModeQuery.
//cooperationModeModels := new(models.CooperationMode)
//cooperationModeQuery := tx.Model(cooperationModeModels)
//if err := cooperationModeQuery.
// Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
// Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
// Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).
// First(); err != nil {
// return nil, fmt.Errorf("共创合约关联的共创模式不存在")
//}
var cooperationModeModels []*models.CooperationMode
cooperationModeQuery := tx.Model(&cooperationModeModels)
if countMode, err := cooperationModeQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).
First(); err != nil {
return nil, fmt.Errorf("共创合约关联的共创模式不存在")
}
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("共创合约关联的分红激励规则不存在")
}
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("共创合约关联的金额激励规则不存在")
}
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("合约承接人不存在")
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("合约相关人不存在")
Limit(1).
SelectAndCount(); err != nil {
log.Logger.Error("合约关联的共创模式不存在", map[string]interface{}{
"cooperationContractModel": cooperationContractModel,
})
} else {
if countMode > 0 {
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("共创合约关联的分红激励规则不存在")
}
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("共创合约关联的金额激励规则不存在")
}
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("合约承接人不存在")
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("合约相关人不存在")
}
return transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
cooperationModeModels[0],
dividendsIncentivesRuleModels,
moneyIncentivesRuleModels,
cooperationContractRelevantModels,
cooperationContractUndertakerModels)
}
}
return transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
cooperationModeModels,
dividendsIncentivesRuleModels,
moneyIncentivesRuleModels,
cooperationContractRelevantModels,
cooperationContractUndertakerModels)
return nil, fmt.Errorf("共创合约不存在")
}
}
... ...