作者 陈志颖

feat:增加分红退货单导入功能

... ... @@ -261,8 +261,18 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
dividendsOrderDao = value
}
// 分红订单仓储初始化
var dividendsOrderRepository domain.DividendsOrderRepository
if value, err1 := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err1 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err1.Error())
} else {
dividendsOrderRepository = value
}
var dividendsOrderImportFailed []*domain.DividendsOrder
var dividendsOrderImportSuccesfully []*domain.DividendsOrder
var dividendsOrderImportSuccessfully []*domain.DividendsOrder
for _, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData {
// 生成分红订单号
... ... @@ -272,13 +282,13 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
// 校验分红订单编号是否唯一
numberAvailable, err := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{
numberAvailable, err3 := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{
"companyId": importDividendsOrderCommand.CompanyId,
"orgId": importDividendsOrderCommand.OrgId,
"dividendsOrderNumber": dividendsOrderNumber,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
if err3 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
}
if !numberAvailable {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
... ... @@ -332,25 +342,17 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
Operator: operator,
}
// 分红订单仓储初始化
var dividendsOrderRepository domain.DividendsOrderRepository
if value, err1 := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err1 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err1.Error())
} else {
dividendsOrderRepository = value
}
if dividendsOrderSaved, err2 := dividendsOrderRepository.Save(newDividendsOrder); err2 != nil {
dividendsOrderImportFailed = append(dividendsOrderImportFailed, newDividendsOrder)
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
} else {
dividendsOrderImportSuccesfully = append(dividendsOrderImportSuccesfully, dividendsOrderSaved)
return dividendsOrderSaved, nil
dividendsOrderImportSuccessfully = append(dividendsOrderImportSuccessfully, dividendsOrderSaved)
}
}
if err3 := transactionContext.CommitTransaction(); err3 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
if len(dividendsOrderImportFailed) == 0 {
if err3 := transactionContext.CommitTransaction(); err3 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
}
return dividendsOrderImportSuccessfully, nil
}
return nil, nil
}
... ...
... ... @@ -207,7 +207,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) GetDividends
}
}
// ImportDividendsReturnedOrder TODO 导入分红退货单
// ImportDividendsReturnedOrder 导入分红退货单
func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDividendsReturnedOrder(importDividendsReturnedOrderCommand *command.ImportDividendsReturnedOrderCommand) (interface{}, error) {
if err := importDividendsReturnedOrderCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -222,8 +222,140 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
// 公司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(importDividendsReturnedOrderCommand.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(importDividendsReturnedOrderCommand.CompanyId, importDividendsReturnedOrderCommand.OrgId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
organization = data
}
// 用户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())
} else {
userService = value
}
// 获取操作人
var operator *domain.User
if data, err := userService.OperatorFrom(importDividendsReturnedOrderCommand.CompanyId, importDividendsReturnedOrderCommand.OrgId, importDividendsReturnedOrderCommand.UserId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operator = data
}
// 分红退货单DAO初始化
var dividendsReturnedOrderDao *dao.DividendsReturnedOrderDao
if value, err := factory.CreateDividendsReturnedOrderDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
dividendsReturnedOrderDao = value
}
// 分红退货单仓储初始化
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsReturnedOrderRepository = value
}
var dividendsReturnedOrderImportFailed []*domain.DividendsReturnedOrder
var dividendsReturnedOrderImportSuccessfully []*domain.DividendsReturnedOrder
for _, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData {
// 生成分红订单号
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 获取分红退货单产品
var orderGoods []*domain.OrderGood
for _, orderGood := range dividendsReturnedOrder.OrderGoods {
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
OrderGoodAmount: orderGood.OrderGoodAmount,
OrderGoodName: orderGood.OrderGoodName,
OrderGoodPrice: orderGood.OrderGoodPrice,
OrderGoodQuantity: orderGood.OrderGoodQuantity,
DividendsOrderNumber: "",
DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodExpense: 0,
OrgId: importDividendsReturnedOrderCommand.OrgId,
CompanyId: importDividendsReturnedOrderCommand.CompanyId,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
})
}
newDividendsReturnedOrder := &domain.DividendsReturnedOrder{
DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
DividendsReturnedOrderRefund: dividendsReturnedOrder.DividendsReturnedOrderRefund,
OriginalOrderNum: dividendsReturnedOrder.OriginalOrderNum,
DividendsOrderNumber: "",
DividendsReturnedCustomerName: dividendsReturnedOrder.DividendsReturnedCustomerName,
DividendsReturnedDate: dividendsReturnedOrder.DividendsReturnedDate,
Region: &domain.RegionInfo{
RegionNumber: "",
RegionName: dividendsReturnedOrder.RegionName,
},
Goods: orderGoods,
Remarks: dividendsReturnedOrder.Remarks,
DividendStatus: domain.TO_BE_DIVIDENDED,
DividendTime: time.Time{},
Org: organization,
Company: company,
CreatedAt: time.Now(),
UpdatedAt: time.Time{},
Operator: operator,
OperateTime: time.Now(),
}
if dividendsReturnedOrderSaved, err := dividendsReturnedOrderRepository.Save(newDividendsReturnedOrder); err != nil {
dividendsReturnedOrderImportFailed = append(dividendsReturnedOrderImportFailed, newDividendsReturnedOrder)
} else {
dividendsReturnedOrderImportSuccessfully = append(dividendsReturnedOrderImportSuccessfully, dividendsReturnedOrderSaved)
}
}
if len(dividendsReturnedOrderImportFailed) == 0 {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return dividendsReturnedOrderImportSuccessfully, nil
}
return nil, nil
}
... ...