作者 yangfu

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

…ion-cooperation into dev
... ... @@ -1303,7 +1303,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
UserPhone: "",
}
}
undertakersOriginal = undertakersOriginal + strconv.FormatInt(int64(i), 10) + "(" + undertaker.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
undertakersOriginal = undertakersOriginal + strconv.FormatInt(int64(i+1), 10) + "(" + undertaker.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
}
undertakerChangeTmp1 := "【" + undertakersOriginal + "】"
... ... @@ -1340,7 +1340,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
UserPhone: "",
}
}
undertakersChanged = undertakersChanged + strconv.FormatInt(int64(i), 10) + "(" + undertaker.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
undertakersChanged = undertakersChanged + strconv.FormatInt(int64(i+1), 10) + "(" + undertaker.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
}
undertakerChangeTemp2 := "【" + undertakersChanged + "】"
// 拼接承接人变更记录
... ...
... ... @@ -617,7 +617,9 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}, nil
}
// 批量导入创建分红订单
var creatDividendsOrder []*domain.DividendsOrder
// 批量创建分红订单
for _, dividendsOrder := range createDividendsOrderCommands {
// 生成分红订单号
dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber()
... ... @@ -732,19 +734,14 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
Operator: operator,
}
if _, err2 := dividendsOrderRepository.Save(newDividendsOrder); err2 != nil {
row := &domain.ImportInfo{
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err)),
LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
GoodLine: map[int]interface{}{},
}
errorDataList = append(errorDataList, row)
continue
}
creatDividendsOrder = append(creatDividendsOrder, newDividendsOrder)
}
// 错误报告处理
if len(errorDataList) <= 0 { // 成功返回
if _, err2 := dividendsOrderRepository.SaveMany(creatDividendsOrder); err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
}
if err3 := transactionContext.CommitTransaction(); err3 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
}
... ...
... ... @@ -66,6 +66,7 @@ type FailInfo struct {
type DividendsOrderRepository interface {
Save(dividendsOrder *DividendsOrder) (*DividendsOrder, error)
SaveMany(dividendsOrders []*DividendsOrder) ([]*DividendsOrder, error)
UpdateMany(dividendsOrders []*DividendsOrder) ([]*DividendsOrder, error)
Remove(dividendsOrder *DividendsOrder) (*DividendsOrder, error)
BatchRemove(dividendsOrders []*DividendsOrder) ([]*DividendsOrder, error)
... ...
... ... @@ -134,7 +134,7 @@ func (repository *ContractUndertakerFeedbackRepository) FindOne(queryOptions map
query.SetWhereByQueryOption("contract_undertaker_feedback.feedback_id = ?", "contractUndertakerFeedbackId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("承接人反馈信息不存在")
} else {
return nil, err
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"time"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
... ... @@ -189,7 +190,7 @@ func (repository *CooperationApplicationRepository) FindOne(queryOptions map[str
query.SetWhereByQueryOption("cooperation_application.cooperation_application_id = ?", "cooperationApplicationId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("共创申请不存在")
} else {
return nil, err
}
... ... @@ -200,14 +201,26 @@ func (repository *CooperationApplicationRepository) FindOne(queryOptions map[str
// 获取共创项目
cooperationProjectModel := new(models.CooperationProject)
cooperationProjectQuery := tx.Model(cooperationProjectModel)
if err := cooperationProjectQuery.Where("cooperation_project_number = ?", cooperationApplicationModel.CooperationProjectNumber).First(); err != nil {
return nil, err
if err := cooperationProjectQuery.
Where("company->>'companyId' = '?'", cooperationApplicationModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationApplicationModel.Org.OrgId).
Where("cooperation_project_number = ?", cooperationApplicationModel.CooperationProjectNumber).First(); err != nil {
log.Logger.Error("申请关联的共创项目不存在", map[string]interface{}{
"cooperationApplicationModel": cooperationApplicationModel,
})
return nil, fmt.Errorf("申请关联的共创项目不存在")
}
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).First(); err != nil {
return nil, err
if err := cooperationModeQuery.
Where("company->>'companyId' = '?'", cooperationApplicationModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationApplicationModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).First(); err != nil {
log.Logger.Error("申请关联的共创模式不存在", map[string]interface{}{
"cooperationApplicationModel": cooperationApplicationModel,
})
return nil, fmt.Errorf("申请关联的共创模式不存在")
}
return transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel, cooperationProjectModel, cooperationModeModel)
}
... ... @@ -271,7 +284,10 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
Where("org->>'orgId' = '?'", cooperationApplicationModel.Org.OrgId).
Where("cooperation_project_number = ?", cooperationApplicationModel.CooperationProjectNumber).
First(); err != nil {
return 0, nil, err
log.Logger.Error("申请关联的共创项目不存在", map[string]interface{}{
"cooperationApplicationModel": cooperationApplicationModel,
})
return 0, nil, fmt.Errorf("申请关联的共创项目不存在")
}
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
... ... @@ -282,7 +298,10 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
Where("org->>'orgId' = '?'", cooperationApplicationModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).
First(); err != nil {
return 0, nil, err
log.Logger.Error("申请关联的共创模式不存在", map[string]interface{}{
"cooperationApplicationModel": cooperationApplicationModel,
})
return 0, nil, fmt.Errorf("申请关联的共创模式不存在")
}
if cooperationApplication, err := transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel, cooperationProjectModel, cooperationModeModel); err != nil {
return 0, cooperationApplications, err
... ...
... ... @@ -139,7 +139,7 @@ func (repository *CooperationContractChangeLogRepository) FindOne(queryOptions m
query.SetWhereByQueryOption("cooperation_contract_change_log.cooperation_contract_change_log_id = ?", "cooperationContractChangeLogId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("共创合约变更记录不存在")
} else {
return nil, err
}
... ...
... ... @@ -154,7 +154,7 @@ func (repository *CooperationContractRelevantRepository) FindOne(queryOptions ma
query.SetWhereByQueryOption("cooperation_contract_relevant.cooperation_contract_relevant_id = ?", "cooperationContractRelevantId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("合约相关人不存在")
} else {
return nil, err
}
... ...
... ... @@ -1032,7 +1032,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).
First(); err != nil {
return 0, nil, err
return 0, nil, fmt.Errorf("合约关联的共创模式不存在")
}
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
... ... @@ -1042,7 +1042,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, err
return 0, nil, fmt.Errorf("合约关联的分红激励规则列表不存在")
}
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
... ... @@ -1052,7 +1052,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, err
return 0, nil, fmt.Errorf("合约关联的金额激励规则列表不存在")
}
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
... ... @@ -1062,7 +1062,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, err
return 0, nil, fmt.Errorf("合约相关的承接人列表不存在")
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
... ... @@ -1072,7 +1072,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, err
return 0, nil, fmt.Errorf("合约相关的相关人列表不存在")
}
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
... ...
... ... @@ -169,7 +169,7 @@ func (repository *CooperationContractUndertakerRepository) FindOne(queryOptions
query.SetWhereByQueryOption("cooperation_contract_undertaker.cooperation_contract_undertaker_id = ?", "cooperationContractUndertakerId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("合约承接人不存在")
} else {
return nil, err
}
... ...
... ... @@ -156,7 +156,7 @@ func (repository *CooperationModeRepository) FindOne(queryOptions map[string]int
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("共创模式不存在")
} else {
return nil, err
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"time"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
... ... @@ -218,7 +219,7 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("共创项目不存在")
} else {
return nil, err
}
... ... @@ -230,7 +231,10 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).First(); err != nil {
return nil, err
log.Logger.Error("共创项目关联的共创模式不存在", map[string]interface{}{
"cooperationProjectModel": cooperationProjectModel,
})
return nil, fmt.Errorf("共创项目关联的共创模式不存在")
}
return transform.TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel, cooperationModeModel)
}
... ... @@ -287,7 +291,10 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
Where("org->>'orgId' = '?'", cooperationProjectModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).
First(); err != nil {
return 0, nil, err
log.Logger.Error("共创项目关联的共创模式不存在", map[string]interface{}{
"cooperationProjectModel": cooperationProjectModel,
})
return 0, nil, fmt.Errorf("共创项目关联的共创模式不存在")
}
if cooperationProject, err := transform.TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel, cooperationModeModel); err != nil {
return 0, cooperationProjects, err
... ...
... ... @@ -184,7 +184,7 @@ func (repository *CreditAccountRepository) FindOne(queryOptions map[string]inter
query.SetWhereByQueryOption("credit_account.credit_account_id = ?", "creditAccountId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("账期结算单不存在")
} else {
return nil, err
}
... ...
... ... @@ -264,7 +264,7 @@ func (repository *DividendsEstimateRepository) FindOne(queryOptions map[string]i
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("分红预算单不存在")
} else {
return nil, err
}
... ...
... ... @@ -149,7 +149,7 @@ func (repository *DividendsIncentivesRuleRepository) FindOne(queryOptions map[st
query.SetWhereByQueryOption("dividends_incentives_rule.dividends_incentives_rule_id = ?", "dividendsIncentivesRuleId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("分红激励规则不存在")
} else {
return nil, err
}
... ...
... ... @@ -295,6 +295,80 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
return dividendsOrder, nil
}
func (repository *DividendsOrderRepository) SaveMany(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) {
tx := repository.transactionContext.PgTx
var dividendsOrderModels []*models.DividendsOrder
var orderGoodsModel []*models.OrderGood
for _, dividendsOrder := range dividendsOrders {
dividendsOrderModels = append(dividendsOrderModels, &models.DividendsOrder{
DividendsOrderNumber: dividendsOrder.DividendsOrderNumber,
DividendsOriginalOrderNum: dividendsOrder.DividendsOriginalOrderNum,
DividendsOrderAmount: dividendsOrder.DividendsOrderAmount,
OrderTime: dividendsOrder.OrderTime,
DividendTime: dividendsOrder.DividendTime,
DividendStatus: dividendsOrder.DividendStatus,
Region: dividendsOrder.Region,
CustomerName: dividendsOrder.CustomerName,
Org: dividendsOrder.Org,
Company: dividendsOrder.Company,
CreatedAt: time.Now(),
DeletedAt: dividendsOrder.DeletedAt,
UpdatedAt: dividendsOrder.UpdatedAt,
OperateTime: time.Now(),
Operator: dividendsOrder.Operator,
Remarks: dividendsOrder.Remarks,
})
for _, good := range dividendsOrder.Goods {
orderGoodsModel = append(orderGoodsModel, &models.OrderGood{
OrderGoodAmount: good.OrderGoodAmount,
OrderGoodName: good.OrderGoodName,
OrderGoodPrice: good.OrderGoodPrice,
OrderGoodQuantity: good.OrderGoodQuantity,
DividendsOrderNumber: dividendsOrder.DividendsOrderNumber,
DividendsReturnedOrderNumber: "",
CooperationContractNumber: good.CooperationContractNumber,
CompanyId: good.CompanyId,
OrgId: good.OrgId,
OrderGoodExpense: good.OrderGoodExpense,
OrderGoodDividendsStatus: good.OrderGoodDividendsStatus,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
})
}
}
if _, err := tx.Model(&dividendsOrderModels).Insert(); err != nil { // 新增分红订单
return nil, err
} else { // 新增分红订单产品
if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil {
return nil, err
}
}
var dividendsOrdersSaved []*domain.DividendsOrder
for _, dividendsOrderModel := range dividendsOrderModels {
//获取订单产品
var orderGoodModels []*models.OrderGood
orderGoodModelQuery := tx.Model(&orderGoodModels)
if err := orderGoodModelQuery.
Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
Where("org_id = ?", dividendsOrderModel.Org.OrgId).
Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).
Select(); err != nil {
log.Logger.Error("分红订单关联的产品不存在", map[string]interface{}{
"dividendsOrderModel": dividendsOrderModel,
})
return nil, fmt.Errorf("分红订单关联的产品不存在")
}
// 聚合分红订单
if dividendsOrder, err := transform.TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel, orderGoodModels); err != nil {
return dividendsOrders, err
} else {
dividendsOrders = append(dividendsOrders, dividendsOrder)
}
}
return dividendsOrdersSaved, nil
}
func (repository *DividendsOrderRepository) UpdateMany(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) {
tx := repository.transactionContext.PgTx
var dividendsOrderModels []*models.DividendsOrder
... ... @@ -379,7 +453,7 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("分红订单不存在")
} else {
return nil, err
}
... ... @@ -394,7 +468,7 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
Where("org_id = ?", dividendsOrderModel.Org.OrgId).
Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).Select(); err != nil {
return nil, err
return nil, fmt.Errorf("分红订单关联的产品不存在")
}
// 聚合分红订单
return transform.TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel, orderGoodModels)
... ... @@ -446,7 +520,10 @@ func (repository *DividendsOrderRepository) Find(queryOptions map[string]interfa
Where("org_id = ?", dividendsOrderModel.Org.OrgId).
Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).
Select(); err != nil {
return 0, nil, err
log.Logger.Error("分红订单关联的产品不存在", map[string]interface{}{
"dividendsOrderModel": dividendsOrderModel,
})
return 0, nil, fmt.Errorf("分红订单关联的产品不存在")
}
// 聚合分红订单
if dividendsOrder, err := transform.TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel, orderGoodModels); err != nil {
... ...
... ... @@ -382,7 +382,7 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str
query.SetWhereByQueryOption("dividends_returned_order.dividends_returned_order_number = ?", "dividendsReturnedOrderNumber")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("分红退货单不存在")
} else {
return nil, err
}
... ... @@ -397,7 +397,7 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str
Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId).
Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).Select(); err != nil {
return nil, err
return nil, fmt.Errorf("分红退货单关联的产品不存在")
}
// 聚合分红退货单
return transform.TransformToDividendsReturnedOrderDomainModelFromPgModels(dividendsReturnedOrderModel, orderGoodModels)
... ... @@ -449,7 +449,10 @@ func (repository *DividendsReturnedOrderRepository) Find(queryOptions map[string
Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).
Select(); err != nil {
return 0, nil, err
log.Logger.Error("分红退货单关联的产品不存在", map[string]interface{}{
"dividendsReturnedOrderModel": dividendsReturnedOrderModel,
})
return 0, nil, fmt.Errorf("分红退货单关联的产品不存在")
}
if dividendsReturnedOrder, err := transform.TransformToDividendsReturnedOrderDomainModelFromPgModels(dividendsReturnedOrderModel, orderGoodModels); err != nil {
return 0, dividendsReturnedOrders, err
... ...
... ... @@ -149,7 +149,7 @@ func (repository *MoneyIncentivesRuleRepository) FindOne(queryOptions map[string
query.SetWhereByQueryOption("money_incentives_rule.money_incentives_rule_id = ?", "moneyIncentivesRuleId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("金额激励规则不存在")
} else {
return nil, err
}
... ...
... ... @@ -150,7 +150,7 @@ func (repository *OrderGoodRepository) FindOne(queryOptions map[string]interface
query.SetWhereByQueryOption("order_good.order_good_id = ?", "orderGoodId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("订单产品不存在")
} else {
return nil, err
}
... ...