|
|
package service
|
|
|
|
|
|
import (
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/dividendsOrder/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/dividendsOrder/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
|
|
|
)
|
|
|
|
|
|
// 分红订单实体对象
|
|
|
type DividendsOrderService struct {
|
|
|
}
|
|
|
|
|
|
// 创建分红订单实体对象
|
|
|
func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createDividendsOrderCommand *command.CreateDividendsOrderCommand) (interface{}, error) {
|
|
|
if err := createDividendsOrderCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
orderGoods := []allied_creation_cooperation.DividendsOrderGoods{}
|
|
|
for _, v := range createDividendsOrderCommand.OrderGoods {
|
|
|
good := allied_creation_cooperation.DividendsOrderGoods{
|
|
|
CooperationContractNumber: v.CooperationContractNumber,
|
|
|
DividendsOrderNumber: v.DividendsOrderNumber,
|
|
|
OrderGoodAmount: v.OrderGoodAmount,
|
|
|
OrderGoodExpense: v.OrderGoodExpense,
|
|
|
OrderGoodName: v.OrderGoodName,
|
|
|
OrderGoodPrice: v.OrderGoodPrice,
|
|
|
OrderGoodQuantity: v.OrderGoodQuantity,
|
|
|
}
|
|
|
orderGoods = append(orderGoods, good)
|
|
|
}
|
|
|
t := time.Unix(createDividendsOrderCommand.OrderTime, 0)
|
|
|
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(createDividendsOrderCommand.Operator)
|
|
|
result, err := creationCooperationGateway.DividendsOrderAdd(allied_creation_cooperation.ReqDividendsOrderAdd{
|
|
|
CompanyId: int(createDividendsOrderCommand.Operator.CompanyId),
|
|
|
CustomerName: createDividendsOrderCommand.CustomerName,
|
|
|
DividendsOrderAmount: createDividendsOrderCommand.DividendsOrderAmount,
|
|
|
DividendsOrderNumber: createDividendsOrderCommand.DividendsOrderNumber,
|
|
|
DividendsOriginalOrderNum: createDividendsOrderCommand.DividendsOriginalOrderNum,
|
|
|
OperatorUid: int(createDividendsOrderCommand.Operator.UserId),
|
|
|
OrderTime: t,
|
|
|
Remarks: createDividendsOrderCommand.Remarks,
|
|
|
SalesmanUid: createDividendsOrderCommand.SalesmanUid,
|
|
|
RegionName: createDividendsOrderCommand.RegionName,
|
|
|
OrderGoods: orderGoods,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
data := struct {
|
|
|
DividendsOrderId int
|
|
|
command.CreateDividendsOrderCommand
|
|
|
}{
|
|
|
DividendsOrderId: result.DividendsOrderID,
|
|
|
CreateDividendsOrderCommand: *createDividendsOrderCommand,
|
|
|
}
|
|
|
return data, nil
|
|
|
}
|
|
|
|
|
|
// 返回分红订单实体对象
|
|
|
func (dividendsOrderService *DividendsOrderService) GetDividendsOrder(getDividendsOrderQuery *query.GetDividendsOrderQuery) (interface{}, error) {
|
|
|
if err := getDividendsOrderQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(getDividendsOrderQuery.Operator)
|
|
|
result, err := creationCooperationGateway.DividendsOrderGet(allied_creation_cooperation.ReqDividendsOrderGet{
|
|
|
DividendsOrderId: getDividendsOrderQuery.DividendsOrderId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
// 返回分红订单实体对象列表
|
|
|
// func (dividendsOrderService *DividendsOrderService) ListDividendsOrders(listDividendsOrdersQuery *query.ListDividendsOrdersQuery) (int, interface{}, error) {
|
|
|
// if err := listDividendsOrdersQuery.ValidateQuery(); err != nil {
|
|
|
// return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
// }
|
|
|
|
|
|
// return 0, nil, nil
|
|
|
// }
|
|
|
|
|
|
// 移除分红订单实体对象
|
|
|
func (dividendsOrderService *DividendsOrderService) RemoveDividendsOrder(removeDividendsOrderCommand *command.RemoveDividendsOrderCommand) (interface{}, error) {
|
|
|
if err := removeDividendsOrderCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
dividendsOrderId := []int{}
|
|
|
for _, v := range removeDividendsOrderCommand.DividendsOrderId {
|
|
|
id, _ := strconv.Atoi(v)
|
|
|
dividendsOrderId = append(dividendsOrderId, id)
|
|
|
}
|
|
|
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(removeDividendsOrderCommand.Operator)
|
|
|
creationCooperationGateway.DividendsOrderRemove(allied_creation_cooperation.ReqDividendsOrderRemove{
|
|
|
DividendsOrderId: 0, ///TODO 改换为批量删除
|
|
|
})
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// 查询分红订单方法
|
|
|
func (dividendsOrderService *DividendsOrderService) SearchDividendsOrder(searchDividendsOrderQuery *query.SearchDividendsOrderQuery) (int, interface{}, error) {
|
|
|
if err := searchDividendsOrderQuery.ValidateQuery(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(searchDividendsOrderQuery.Operator)
|
|
|
result, err := creationCooperationGateway.DividendsOrderSearch(allied_creation_cooperation.ReqDividendsOrderSearch{
|
|
|
PageNumber: searchDividendsOrderQuery.PageNumber,
|
|
|
PageSize: searchDividendsOrderQuery.PageSize,
|
|
|
CustomerName: searchDividendsOrderQuery.CustomerName,
|
|
|
DividendsOrderNumber: searchDividendsOrderQuery.DividendsOrderNumber,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
return result.Gride.Total, result.Gride.List, nil
|
|
|
}
|
|
|
|
|
|
// 更新分红订单实体对象
|
|
|
func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateDividendsOrderCommand *command.UpdateDividendsOrderCommand) (interface{}, error) {
|
|
|
if err := updateDividendsOrderCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
orderGoods := []allied_creation_cooperation.DividendsOrderGoods{}
|
|
|
for _, v := range updateDividendsOrderCommand.OrderGoods {
|
|
|
good := allied_creation_cooperation.DividendsOrderGoods{
|
|
|
CooperationContractNumber: v.CooperationContractNumber,
|
|
|
DividendsOrderNumber: v.DividendsOrderNumber,
|
|
|
OrderGoodAmount: v.OrderGoodAmount,
|
|
|
OrderGoodExpense: v.OrderGoodExpense,
|
|
|
OrderGoodName: v.OrderGoodName,
|
|
|
OrderGoodPrice: v.OrderGoodPrice,
|
|
|
OrderGoodQuantity: v.OrderGoodQuantity,
|
|
|
}
|
|
|
orderGoods = append(orderGoods, good)
|
|
|
}
|
|
|
t := time.Unix(updateDividendsOrderCommand.OrderTime, 0)
|
|
|
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(updateDividendsOrderCommand.Operator)
|
|
|
_, err := creationCooperationGateway.DividendsOrderUpdate(allied_creation_cooperation.ReqDividendsOrderUpdate{
|
|
|
DividendsOrderId: updateDividendsOrderCommand.DividendsOrderID,
|
|
|
CompanyId: int(updateDividendsOrderCommand.Operator.CompanyId),
|
|
|
CustomerName: updateDividendsOrderCommand.CustomerName,
|
|
|
DividendsOrderAmount: updateDividendsOrderCommand.DividendsOrderAmount,
|
|
|
DividendsOrderNumber: updateDividendsOrderCommand.DividendsOrderNumber,
|
|
|
DividendsOriginalOrderNum: updateDividendsOrderCommand.DividendsOriginalOrderNum,
|
|
|
OperatorUid: int(updateDividendsOrderCommand.Operator.UserId),
|
|
|
OrderTime: t,
|
|
|
Remarks: updateDividendsOrderCommand.Remarks,
|
|
|
SalesmanUid: updateDividendsOrderCommand.SalesmanUid,
|
|
|
RegionName: updateDividendsOrderCommand.RegionName,
|
|
|
OrderGoods: orderGoods,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return updateDividendsOrderCommand, nil
|
|
|
}
|
|
|
|
|
|
func NewDividendsOrderService(options map[string]interface{}) *DividendsOrderService {
|
|
|
newDividendsOrderService := &DividendsOrderService{}
|
|
|
return newDividendsOrderService
|
|
|
} |
...
|
...
|
|