...
|
...
|
@@ -112,7 +112,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
|
|
|
}
|
|
|
|
|
|
// 获取订单产品
|
|
|
// 新增订单产品
|
|
|
var orderGoods []*domain.OrderGood
|
|
|
var dividendsOrderAmount float64
|
|
|
for _, orderGood := range createDividendsOrderCommand.OrderGoods {
|
...
|
...
|
@@ -136,9 +136,9 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD |
|
|
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
|
|
|
}
|
|
|
|
|
|
// 订单时间转换
|
|
|
orderTimeInt, _ := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
|
|
|
orderTime := utils.TransformTimestampToTime(orderTimeInt)
|
|
|
//// 订单时间转换
|
|
|
//orderTimeInt, _ := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
|
|
|
//orderTime := utils.TransformTimestampToTime(orderTimeInt)
|
|
|
|
|
|
// 新增分红订单
|
|
|
newDividendsOrder := &domain.DividendsOrder{
|
...
|
...
|
@@ -146,7 +146,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD |
|
|
DividendsOrderNumber: dividendsOrderNumber,
|
|
|
DividendsOriginalOrderNum: createDividendsOrderCommand.DividendsOriginalOrderNum,
|
|
|
DividendsOrderAmount: dividendsOrderAmount,
|
|
|
OrderTime: orderTime,
|
|
|
OrderTime: createDividendsOrderCommand.OrderTime,
|
|
|
DividendTime: time.Time{},
|
|
|
DividendStatus: domain.TO_BE_DIVIDEND,
|
|
|
Region: &domain.RegionInfo{
|
...
|
...
|
@@ -162,6 +162,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD |
|
|
UpdatedAt: time.Time{},
|
|
|
OperateTime: time.Now(),
|
|
|
Operator: operator,
|
|
|
Remarks: createDividendsOrderCommand.Remarks,
|
|
|
}
|
|
|
|
|
|
// 分红订单仓储初始化
|
...
|
...
|
@@ -183,6 +184,174 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD |
|
|
}
|
|
|
}
|
|
|
|
|
|
// ImportDividendsOrder 导入分红订单实体对象
|
|
|
func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importDividendsOrderCommand *command.ImportDividendsOrderCommand) (interface{}, error) {
|
|
|
if err := importDividendsOrderCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
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(importDividendsOrderCommand.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(importDividendsOrderCommand.CompanyId, importDividendsOrderCommand.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(importDividendsOrderCommand.CompanyId, importDividendsOrderCommand.OrgId, importDividendsOrderCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
operator = data
|
|
|
}
|
|
|
|
|
|
// 分红订单DAO初始化
|
|
|
var dividendsOrderDao *dao.DividendsOrderDao
|
|
|
if value, err := factory.CreateDividendsOrderDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsOrderDao = value
|
|
|
}
|
|
|
|
|
|
var dividendsOrderImportFailed []*domain.DividendsOrder
|
|
|
var dividendsOrderImportSuccesfully []*domain.DividendsOrder
|
|
|
|
|
|
for _, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData {
|
|
|
// 生成分红订单号
|
|
|
dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber()
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 校验分红订单编号是否唯一
|
|
|
numberAvailable, err := 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 !numberAvailable {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
|
|
|
}
|
|
|
|
|
|
// 新增订单产品
|
|
|
var orderGoods []*domain.OrderGood
|
|
|
var dividendsOrderAmount float64
|
|
|
for _, orderGood := range dividendsOrder.OrderGoods {
|
|
|
orderGoods = append(orderGoods, &domain.OrderGood{
|
|
|
OrderGoodId: 0,
|
|
|
OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
OrderGoodName: orderGood.OrderGoodName,
|
|
|
OrderGoodPrice: orderGood.OrderGoodPrice,
|
|
|
OrderGoodQuantity: orderGood.OrderGoodQuantity,
|
|
|
DividendsOrderNumber: dividendsOrderNumber,
|
|
|
DividendsReturnedOrderNumber: "",
|
|
|
CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
OrderGoodExpense: orderGood.OrderGoodExpense,
|
|
|
OrgId: importDividendsOrderCommand.OrgId,
|
|
|
CompanyId: importDividendsOrderCommand.CompanyId,
|
|
|
CreatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
})
|
|
|
// 计算分红订单金额
|
|
|
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
|
|
|
}
|
|
|
|
|
|
// 新增分红订单
|
|
|
newDividendsOrder := &domain.DividendsOrder{
|
|
|
DividendsOrderId: 0,
|
|
|
DividendsOrderNumber: dividendsOrderNumber,
|
|
|
DividendsOriginalOrderNum: dividendsOrder.DividendsOriginalOrderNum,
|
|
|
DividendsOrderAmount: dividendsOrderAmount,
|
|
|
OrderTime: dividendsOrder.OrderTime,
|
|
|
DividendTime: time.Time{},
|
|
|
DividendStatus: domain.TO_BE_DIVIDEND,
|
|
|
Region: &domain.RegionInfo{
|
|
|
RegionNumber: "",
|
|
|
RegionName: dividendsOrder.RegionName,
|
|
|
},
|
|
|
CustomerName: dividendsOrder.CustomerName,
|
|
|
Goods: orderGoods,
|
|
|
Org: organization,
|
|
|
Company: company,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
OperateTime: time.Now(),
|
|
|
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
|
|
|
}
|
|
|
}
|
|
|
if err3 := transactionContext.CommitTransaction(); err3 != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// GetDividendsOrder 返回分红订单实体对象
|
|
|
func (dividendsOrderService *DividendsOrderService) GetDividendsOrder(getDividendsOrderQuery *query.GetDividendsOrderQuery) (interface{}, error) {
|
|
|
if err := getDividendsOrderQuery.ValidateQuery(); err != nil {
|
...
|
...
|
|