作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

... ... @@ -44,6 +44,7 @@ type DividendsOrder struct {
type DividendsOrderRepository interface {
Save(dividendsOrder *DividendsOrder) (*DividendsOrder, error)
UpdateMany(dividendsOrders []*DividendsOrder) ([]*DividendsOrder, error)
Remove(dividendsOrder *DividendsOrder) (*DividendsOrder, error)
BatchRemove(dividendsOrders []*DividendsOrder) ([]*DividendsOrder, error)
FindOne(queryOptions map[string]interface{}) (*DividendsOrder, error)
... ...
... ... @@ -48,6 +48,7 @@ type DividendsReturnedOrder struct {
type DividendsReturnedOrderRepository interface {
Save(dividendsReturnedOrder *DividendsReturnedOrder) (*DividendsReturnedOrder, error)
UpdateMany(dividendsReturnedOrder []*DividendsReturnedOrder) ([]*DividendsReturnedOrder, error)
Remove(dividendsReturnedOrder *DividendsReturnedOrder) (*DividendsReturnedOrder, error)
BatchRemove(dividendsReturnedOrders []*DividendsReturnedOrder) ([]*DividendsReturnedOrder, error)
FindOne(queryOptions map[string]interface{}) (*DividendsReturnedOrder, error)
... ...
... ... @@ -7,5 +7,5 @@ import (
type CancelDividendsEstimate interface {
coreDomain.DomainEventPublisher
CancelEstimate(dividendsEstimateId int64, operatorId int64) ([]*domain.DividendsEstimate, error)
CancelEstimate(dividendsEstimateIds []int64, operatorId int64) ([]*domain.DividendsEstimate, error)
}
... ...
... ... @@ -2,9 +2,13 @@ package domain_service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"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/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
)
type CancelDividendsEstimateService struct {
... ... @@ -12,7 +16,126 @@ type CancelDividendsEstimateService struct {
transactionContext *pgTransaction.TransactionContext
}
func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEstimateId int64, operatorId int64) ([]*domain.DividendsEstimate, error) {
func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEstimateIds []int64, operatorId int64) ([]*domain.DividendsEstimate, error) {
var dividendsEstimateRepository domain.DividendsEstimateRepository // 分红预算单仓储
var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
var userService service.UserService // 用户服务
// 分红预算单仓储初始化
if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
dividendsEstimateRepository = repo
}
// 分红订单仓储初始化
if repo, err := repository.NewDividendsOrderRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
dividendsOrderRepository = repo
}
// 分红退后单仓储初始化
if repo, err := repository.NewDividendsReturnedOrderRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
dividendsReturnedOrderRepository = repo
}
// 用户服务初始化
if value, err := NewUserService(); err != nil {
userService = value
}
// 获取操作人
var operator *domain.User
if data, err := userService.OperatorFrom(0, 0, operatorId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operator = data
}
// 获取分红预算单
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
"dividendsEstimateIds": dividendsEstimateIds,
}); err != nil {
return nil, err
} else {
if count > 0 {
var dividendsEstimatesCanceled []*domain.DividendsEstimate
var orderOrReturnOrderNums []string
for _, dividendsEstimate := range dividendsEstimates {
// 根据当前分红预算单的分红订单号或退货单号获取分红预算单
if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
}); err2 != nil {
return nil, err2
} else {
if countRelative > 0 {
for i, _ := range dividendsEstimatesRelative {
dividendsEstimatesRelative[i].IsCanceled = true
dividendsEstimatesRelative[i].Operator = operator
// 获取相关订单/退货单号
orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
}
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
if err3 != nil {
return nil, err3
}
dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)
}
}
}
// 分红订单或分红退货单状态变更
var orderNums []string
var returnedOrderNums []string
// 订单/退货单号数组去重
orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums)
for _, orderNullNum := range orderOrReturnOrderNumsWithoutDup {
if orderNullNum[0:2] == "RE" { // 分红退后单
returnedOrderNums = append(returnedOrderNums, orderNullNum)
} else if orderNullNum[0:2] == "FH" { // 分红订单
orderNums = append(orderNums, orderNullNum)
}
}
// 获取分红订单
if countDividendsOrder, orders, err4 := dividendsOrderRepository.Find(map[string]interface{}{
"dividendsOrderNumbers": orderNums,
}); err4 != nil {
return nil, err4
} else {
if countDividendsOrder > 0 {
for i, _ := range orders {
orders[i].DividendStatus = 1
}
// 保存订单状态
if _, err6 := dividendsOrderRepository.UpdateMany(orders); err6 != nil {
return nil, err6
}
}
}
// 获取分红退货单
if countDividendsReturnedOrder, returnedOrders, err5 := dividendsReturnedOrderRepository.Find(map[string]interface{}{
"dividendsReturnedOrderNumbers": returnedOrderNums,
}); err5 != nil {
return nil, err5
} else {
if countDividendsReturnedOrder > 0 {
for i, _ := range returnedOrders {
returnedOrders[i].DividendStatus = 1
}
// 保存退货单状态
if _, err7 := dividendsReturnedOrderRepository.UpdateMany(returnedOrders); err7 != nil {
return nil, err7
}
}
}
return dividendsEstimatesCanceled, nil
}
}
return nil, nil
}
... ...
... ... @@ -32,12 +32,13 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
} else {
dividendsOrderRepository = repo
}
// 分红退单仓储初始化
// 分红退单仓储初始化
if repo, err := repository.NewDividendsReturnedOrderRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
dividendsReturnedOrderRepository = repo
}
// 确认业绩分红预算
var dividendsEstimateDetails []*service.DividendsEstimateDetail
for _, orderGood := range orderGoods {
// 获取合约
... ...
... ... @@ -251,6 +251,10 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
return dividendsOrder, nil
}
func (repository *DividendsOrderRepository) UpdateMany(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) {
panic("implement me")
}
func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.DividendsOrder) (*domain.DividendsOrder, error) {
tx := repository.transactionContext.PgTx
dividendsOrderModel := new(models.DividendsOrder)
... ...
... ... @@ -263,6 +263,10 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
return dividendsReturnedOrder, nil
}
func (repository *DividendsReturnedOrderRepository) UpdateMany(dividendsReturnedOrder []*domain.DividendsReturnedOrder) ([]*domain.DividendsReturnedOrder, error) {
panic("implement me")
}
func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrder *domain.DividendsReturnedOrder) (*domain.DividendsReturnedOrder, error) {
tx := repository.transactionContext.PgTx
dividendsReturnedOrderModel := new(models.DividendsReturnedOrder)
... ...
... ... @@ -96,7 +96,21 @@ func NumberToCNNumber(num int) string {
chinese = copyChinese
}
}
return "第" + chinese + "阶段"
}
// RemoveDuplication 数组去重
func RemoveDuplication(arr []string) []string {
set := make(map[string]struct{}, len(arr))
j := 0
for _, v := range arr {
_, ok := set[v]
if ok {
continue
}
set[v] = struct{}{}
arr[j] = v
j++
}
return arr[:j]
}
... ...