作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-cooperation into dev
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type CooperationContractByUndertakerDto struct {
}
func (dto *CooperationContractByUndertakerDto) LoadDto(contract *domain.CooperationContract) error {
return nil
}
... ...
... ... @@ -791,7 +791,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC
}
}
// SearchCooperationContractByUndertaker 根据承接人返回共创项目合约
// SearchCooperationContractByUndertaker TODO 根据承接人返回共创项目合约
func (cooperationContractService *CooperationContractService) SearchCooperationContractByUndertaker(searchCooperationContractByUndertakerQuery *query.SearchCooperationContractByUndertakerQuery) (interface{}, error) {
if err := searchCooperationContractByUndertakerQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ...
... ... @@ -5,7 +5,6 @@ import (
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
"time"
)
type OrderGoods struct {
... ... @@ -31,7 +30,7 @@ type CreateDividendsOrderCommand struct {
// 分红订单原单号
DividendsOriginalOrderNum string `cname:"源单号" json:"dividendsOriginalOrderNum" valid:"Required"`
// 订单时间
OrderTime time.Time `cname:"订单时间" json:"orderTime" valid:"Required"`
OrderTime string `cname:"订单时间" json:"orderTime" valid:"Required"`
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
// 订单区域名称
... ...
... ... @@ -136,9 +136,12 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
}
//// 订单时间转换
//orderTimeInt, _ := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
//orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 新增分红订单
newDividendsOrder := &domain.DividendsOrder{
... ... @@ -146,7 +149,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
DividendsOrderNumber: dividendsOrderNumber,
DividendsOriginalOrderNum: createDividendsOrderCommand.DividendsOriginalOrderNum,
DividendsOrderAmount: dividendsOrderAmount,
OrderTime: createDividendsOrderCommand.OrderTime,
OrderTime: orderTime,
DividendTime: time.Time{},
DividendStatus: domain.TO_BE_DIVIDEND,
Region: &domain.RegionInfo{
... ... @@ -258,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 {
// 生成分红订单号
... ... @@ -269,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, "新增分红订单异常")
... ... @@ -329,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
}
... ...
... ... @@ -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,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
}
... ... @@ -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, "分红退货单号错误")
... ...
... ... @@ -191,7 +191,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil {
return nil, err
}
dividendsEstimatesSaved := []*domain.DividendsEstimate{}
var dividendsEstimatesSaved []*domain.DividendsEstimate
for _, dividendsEstimateModel := range dividendsEstimateModels {
if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
return dividendsEstimates, err
... ...