...
|
...
|
@@ -34,7 +34,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide |
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 公司REST服务初始化
|
|
|
// 公司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())
|
...
|
...
|
@@ -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,9 +222,141 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide |
|
|
defer func() {
|
|
|
_ = 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(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
|
|
|
}
|
|
|
|
...
|
...
|
@@ -330,6 +462,10 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) BatchRemoveD |
|
|
dividendsReturnedOrderRepository = value
|
|
|
}
|
|
|
|
|
|
if len(batchRemoveDividendsOrderCommand.DividendsReturnedOrderIds) == 0 {
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
dividendsReturnedOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsReturnedOrderIds)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号错误")
|
...
|
...
|
|