作者 唐旭辉

修复bug:订单唯一性校验

... ... @@ -235,9 +235,12 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
}); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
goodNames := []string{}
for _, v := range cmd.Goods {
goodNames = append(goodNames, v.GoodName)
}
if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode,
cmd.PartnerCategory, cmd.PartnerId, 0); err != nil {
cmd.PartnerCategory, cmd.PartnerId, 0, goodNames); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在")
... ... @@ -447,8 +450,13 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
// return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
// }
// }
goodNames := []string{}
for _, v := range cmd.Goods {
goodNames = append(goodNames, v.GoodName)
}
//检查delivery_code是否重复
if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode, cmd.PartnerCategory, cmd.PartnerId, cmd.Id); err != nil {
if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode,
cmd.PartnerCategory, cmd.PartnerId, cmd.Id, goodNames); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在")
... ... @@ -1056,10 +1064,13 @@ func (service OrderInfoService) CreateNewOrderByImport(createOrderCommands []*co
errorDataList = append(errorDataList, row)
continue
}
goodNames := []string{}
for _, v := range cmd.Goods {
goodNames = append(goodNames, v.GoodName)
}
// 批量校验订单
if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode,
cmd.PartnerCategory, cmd.PartnerId, 0); err != nil {
cmd.PartnerCategory, cmd.PartnerId, 0, goodNames); err != nil {
row := &domain.ImportInfo{
Error: lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()),
LineNumbers: cmd.LineNumbers, // 错误影响的行
... ...
... ... @@ -28,16 +28,19 @@ func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*Order
//@orderCode 订单号
//@deliveryCode 发货单号
//@partnerCategoryCode 合伙人类型编号
//@goodNames 货品名称列表
func (dao OrderBaseDao) CheckOrderExist(companyId int64, orderCode string,
deliveryCode string, partnerCategory int64, partnerId int64, notId int64) (bool, error) {
deliveryCode string, partnerCategory int64, partnerId int64, notId int64, goodNames []string) (bool, error) {
tx := dao.transactionContext.GetDB()
query := tx.Model(&models.OrderBase{}).
Join("JOIN order_good ON order_base.id=order_good.order_id").
Where("company_id=?", companyId).
Where("order_code=?", orderCode).
Where("delivery_code=?", deliveryCode).
Where("partner_id=?", partnerId).
Where(`partner_category @>'{"id":?}'`, partnerCategory).
Where("id<>?", notId)
Where("id<>?", notId).
WhereIn("order_good.good_name in(?)", goodNames)
ok, err := query.Exists()
return ok, err
}
... ...