作者 陈志颖

fix:分红订单仓储问题修复

... ... @@ -283,7 +283,6 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
//
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -2,11 +2,9 @@ package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type OrderGoods struct {
... ... @@ -29,14 +27,10 @@ type OrderGoods struct {
type CreateDividendsOrderCommand struct {
// 客户名称
CustomerName string `cname:"客户名称" json:"customerName" valid:"Required"`
// 分红订单金额
DividendsOrderAmount float64 `cname:"分红订单金额" json:"dividendsOrderAmount" valid:"Required"`
// 分红订单号
DividendsOrderNumber string `cname:"分红订单号" json:"dividendsOrderNumber,string" valid:"Required"`
// 分红订单原单号
DividendsOriginalOrderNum string `cname:"分红订单原单号" json:"dividendsOriginalOrderNum" valid:"Required"`
// 订单产生时间
OrderTime time.Time `cname:"订单产生时间" json:"orderTime" valid:"Required"`
DividendsOriginalOrderNum string `cname:"源单号" json:"dividendsOriginalOrderNum" valid:"Required"`
// 订单时间
OrderTime string `cname:"订单时间" json:"orderTime" valid:"Required"`
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
// 订单区域名称
... ...
... ... @@ -10,6 +10,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"strconv"
"time"
)
... ... @@ -100,22 +101,29 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
} else {
dividendsOrderDao = value
}
// 生成分红订单号
dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 校验分红订单编号是否唯一
numberAvailable, _ := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{
numberAvailable, err := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{
"companyId": createDividendsOrderCommand.CompanyId,
"orgId": createDividendsOrderCommand.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 createDividendsOrderCommand.OrderGoods {
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
... ... @@ -126,22 +134,28 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
DividendsOrderNumber: dividendsOrderNumber,
DividendsReturnedOrderNumber: "",
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodExpense: 0,
OrderGoodExpense: orderGood.OrderGoodExpense,
OrgId: organization.OrgId,
CompanyId: company.CompanyId,
CreatedAt: time.Time{},
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
})
// 计算分红订单金额
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
}
// 订单时间转换
orderTimeInt, _ := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
orderTime := utils.TransformTimestampToTime(orderTimeInt)
newDividendsOrder := &domain.DividendsOrder{
DividendsOrderId: 0,
DividendsOrderNumber: dividendsOrderNumber,
DividendsOriginalOrderNum: createDividendsOrderCommand.DividendsOriginalOrderNum,
DividendsOrderAmount: createDividendsOrderCommand.DividendsOrderAmount,
DividendsOrderAmount: dividendsOrderAmount,
OrderSalesman: salesman,
OrderTime: createDividendsOrderCommand.OrderTime,
OrderTime: orderTime,
DividendTime: time.Time{},
DividendStatus: 0,
Region: &domain.RegionInfo{
... ... @@ -159,6 +173,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
Operator: operator,
}
// 分红订单仓储初始化
var dividendsOrderRepository domain.DividendsOrderRepository
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ...
... ... @@ -2,11 +2,9 @@ package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type OrderGoods struct {
... ... @@ -38,7 +36,7 @@ type CreateDividendsReturnedOrderCommand struct {
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
// 退货日期
DividendsReturnedDate time.Time `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"`
DividendsReturnedDate string `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"`
// 退货区域名称
RegionName string `cname:"退货区域名称" json:"regionName,omitempty"`
// 订单产品列表
... ...
... ... @@ -9,6 +9,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"time"
)
... ... @@ -80,6 +81,32 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
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
}
// 生成分红订单号
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 校验分红退货单编号是否唯一
//numberAvailable, _ := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
// "companyId": createDividendsOrderCommand.CompanyId,
// "orgId": createDividendsOrderCommand.OrgId,
// "dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
//})
//if !numberAvailable {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
//}
// 获取分红退货单产品
var orderGoods []*domain.OrderGood
for _, orderGood := range createDividendsReturnedOrderCommand.OrderGoods {
... ... @@ -90,7 +117,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
OrderGoodPrice: orderGood.OrderGoodPrice,
OrderGoodQuantity: orderGood.OrderGoodQuantity,
DividendsOrderNumber: "",
DividendsReturnedOrderNumber: "", // 分红退货单号,规则生成
DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodExpense: 0,
OrgId: organization.OrgId,
... ... @@ -102,7 +129,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
}
newDividendsReturnedOrder := &domain.DividendsReturnedOrder{
DividendsReturnedOrderNumber: "", // 退货单号,生成
DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
DividendsReturnedOrderRefund: 0,
OriginalOrderNum: createDividendsReturnedOrderCommand.OriginalOrderNum,
DividendsOrderNumber: createDividendsReturnedOrderCommand.DividendsOrderNumber,
... ...
... ... @@ -40,6 +40,8 @@ type DividendsOrder struct {
OperateTime time.Time `json:"operateTime"`
// 操作人
Operator *User `json:"operator"`
// 备注
Remarks string `json:"remarks"`
}
type DividendsOrderRepository interface {
... ...
... ... @@ -5,7 +5,7 @@ import "time"
// DividendsReturnedOrder 分红退货单实体
type DividendsReturnedOrder struct {
// 分红退货单记录ID
DividendsReturnedOrderId int64 `json:"dividendsReturnedOrderId"`
DividendsReturnedOrderId int64 `json:"dividendsReturnedOrderId,string"`
// 分红退货单号
DividendsReturnedOrderNumber string `json:"dividendsReturnedOrderNumber"`
// 退货金额
... ...
... ... @@ -44,15 +44,20 @@ func (dao *DividendsOrderDao) CheckDividendsOrderNumberAvailable(queryOptions ma
query = query.Where("dividends_order_number = ?", dividendsOrderNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId)
query = query.Where(`dividends_order.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`cooperation_contract.org @> '{"orgId":"?"}'`, orgId)
query = query.Where(`dividends_order.org @> '{"orgId":"?"}'`, orgId)
}
ok, err := query.Exists()
return !ok, err
}
// CalculateDividendsOrderAmount 计算分红订单金额
func (dao *DividendsOrderDao) CalculateDividendsOrderAmount(queryOptions map[string]interface{}) (float64, error) {
return 0, nil
}
func NewDividendsOrderDao(transactionContext *pgTransaction.TransactionContext) (*DividendsOrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能未")
... ...
... ... @@ -34,11 +34,13 @@ type DividendsOrder struct {
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
DeletedAt time.Time `comment:"删除时间" pg:",soft_delete"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 操作时间
OperateTime time.Time `comment:"操作时间"`
// 操作人
Operator *domain.User `comment:"操作人"`
// 备注
Remarks string `comment:"备注信息"`
}
... ...
... ... @@ -36,7 +36,7 @@ type DividendsReturnedOrder struct {
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
DeletedAt time.Time `comment:"删除时间" pg:",soft_delete"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 操作人
... ...
... ... @@ -45,6 +45,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
"updated_at",
"operate_time",
"operator",
"remarks",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
... ... @@ -78,6 +79,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
&dividendsOrder.UpdatedAt,
&dividendsOrder.OperateTime,
&dividendsOrder.Operator,
&dividendsOrder.Remarks,
),
fmt.Sprintf("INSERT INTO dividends_orders (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
dividendsOrder.DividendsOrderId,
... ... @@ -97,6 +99,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
dividendsOrder.UpdatedAt,
dividendsOrder.OperateTime,
dividendsOrder.Operator,
dividendsOrder.Remarks,
); err != nil {
return dividendsOrder, err
}
... ... @@ -140,6 +143,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
&dividendsOrder.UpdatedAt,
&dividendsOrder.OperateTime,
&dividendsOrder.Operator,
&dividendsOrder.Remarks,
),
fmt.Sprintf("UPDATE dividends_orders SET %s WHERE dividends_order_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
dividendsOrder.DividendsOrderId,
... ... @@ -159,6 +163,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
dividendsOrder.UpdatedAt,
dividendsOrder.OperateTime,
dividendsOrder.Operator,
dividendsOrder.Remarks,
dividendsOrder.Identify(),
); err != nil {
return dividendsOrder, err
... ...
... ... @@ -112,7 +112,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
OrderGoodPrice: good.OrderGoodPrice,
OrderGoodQuantity: good.OrderGoodQuantity,
DividendsOrderNumber: good.DividendsOrderNumber,
DividendsReturnedOrderNumber: good.DividendsReturnedOrderNumber,
DividendsReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
CooperationContractNumber: good.CooperationContractNumber,
OrderGoodExpense: good.OrderGoodExpense,
OrgId: good.OrgId,
... ...
... ... @@ -18,24 +18,24 @@ func GetDayEnd() time.Time {
return nextDay
}
//获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。
// GetFirstDateOfMonth 获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。
func GetFirstDateOfMonth(d time.Time) time.Time {
d = d.AddDate(0, 0, -d.Day()+1)
return GetZeroTime(d)
}
//获取传入的时间所在月份的最后一天,即某月最后一天的23:59:59。如传入time.Now(), 返回当前月份的最后一天的23:59:59。
// GetNextMonthFirstDay 获取传入的时间所在月份的最后一天,即某月最后一天的23:59:59。如传入time.Now(), 返回当前月份的最后一天的23:59:59。
func GetNextMonthFirstDay(d time.Time) time.Time {
d = GetFirstDateOfMonth(d).AddDate(0, 1, 0)
return GetZeroTime(d)
}
//获取某一天的0点时间
// GetZeroTime 获取某一天的0点时间
func GetZeroTime(d time.Time) time.Time {
return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local)
}
//获取某一天的23点59分59秒
// GetNextDayZeroTime 获取某一天的23点59分59秒
func GetNextDayZeroTime(d time.Time) time.Time {
return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, 1)
}
... ...
... ... @@ -14,7 +14,6 @@ func (controller *DividendsReturnedOrderController) CreateDividendsReturnedOrder
dividendsReturnedOrderService := service.NewDividendsReturnedOrderService(nil)
createDividendsReturnedOrderCommand := &command.CreateDividendsReturnedOrderCommand{}
_ = controller.Unmarshal(createDividendsReturnedOrderCommand)
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
createDividendsReturnedOrderCommand.CompanyId = header.CompanyId
createDividendsReturnedOrderCommand.OrgId = header.OrgId
... ... @@ -28,7 +27,6 @@ func (controller *DividendsReturnedOrderController) UpdateDividendsReturnedOrder
dividendsReturnedOrderService := service.NewDividendsReturnedOrderService(nil)
updateDividendsReturnedOrderCommand := &command.UpdateDividendsReturnedOrderCommand{}
_ = controller.Unmarshal(updateDividendsReturnedOrderCommand)
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
updateDividendsReturnedOrderCommand.CompanyId = header.CompanyId
updateDividendsReturnedOrderCommand.OrgId = header.OrgId
... ... @@ -43,7 +41,6 @@ func (controller *DividendsReturnedOrderController) UpdateDividendsReturnedOrder
func (controller *DividendsReturnedOrderController) GetDividendsReturnedOrder() {
dividendsReturnedOrderService := service.NewDividendsReturnedOrderService(nil)
getDividendsReturnedOrderQuery := &query.GetDividendsReturnedOrderQuery{}
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
getDividendsReturnedOrderQuery.CompanyId = header.CompanyId
getDividendsReturnedOrderQuery.OrgId = header.OrgId
... ... @@ -59,7 +56,6 @@ func (controller *DividendsReturnedOrderController) RemoveDividendsReturnedOrder
dividendsReturnedOrderService := service.NewDividendsReturnedOrderService(nil)
removeDividendsReturnedOrderCommand := &command.RemoveDividendsReturnedOrderCommand{}
_ = controller.Unmarshal(removeDividendsReturnedOrderCommand)
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
removeDividendsReturnedOrderCommand.CompanyId = header.CompanyId
removeDividendsReturnedOrderCommand.OrgId = header.OrgId
... ... @@ -74,7 +70,6 @@ func (controller *DividendsReturnedOrderController) RemoveDividendsReturnedOrder
func (controller *DividendsReturnedOrderController) SearchDividendsReturnedOrder() {
dividendsReturnedOrderService := service.NewDividendsReturnedOrderService(nil)
searchDividendsReturnedOrderQuery := &query.SearchDividendsReturnedOrderQuery{}
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
searchDividendsReturnedOrderQuery.CompanyId = header.CompanyId
searchDividendsReturnedOrderQuery.OrgId = header.OrgId
... ... @@ -88,7 +83,6 @@ func (controller *DividendsReturnedOrderController) ImportDividendsReturnedOrder
dividendsReturnedOrderService := service.NewDividendsReturnedOrderService(nil)
importDividendsReturnedOrderCommand := &command.ImportDividendsReturnedOrderCommand{}
_ = controller.Unmarshal(importDividendsReturnedOrderCommand)
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
importDividendsReturnedOrderCommand.CompanyId = header.CompanyId
importDividendsReturnedOrderCommand.OrgId = header.OrgId
... ... @@ -101,7 +95,6 @@ func (controller *DividendsReturnedOrderController) ImportDividendsReturnedOrder
func (controller *DividendsReturnedOrderController) ListDividendsReturnedOrder() {
dividendsReturnedOrderService := service.NewDividendsReturnedOrderService(nil)
listDividendsReturnedOrderQuery := &query.ListDividendsReturnedOrderQuery{}
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
listDividendsReturnedOrderQuery.CompanyId = header.CompanyId
listDividendsReturnedOrderQuery.OrgId = header.OrgId
... ...