作者 唐旭辉

修复bug:订单唯一性校验

@@ -235,9 +235,12 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( @@ -235,9 +235,12 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
235 }); err != nil { 235 }); err != nil {
236 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 236 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
237 } 237 }
238 - 238 + goodNames := []string{}
  239 + for _, v := range cmd.Goods {
  240 + goodNames = append(goodNames, v.GoodName)
  241 + }
239 if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode, 242 if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode,
240 - cmd.PartnerCategory, cmd.PartnerId, 0); err != nil { 243 + cmd.PartnerCategory, cmd.PartnerId, 0, goodNames); err != nil {
241 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 244 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
242 } else if ok { 245 } else if ok {
243 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在") 246 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在")
@@ -447,8 +450,13 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) @@ -447,8 +450,13 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
447 // return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在") 450 // return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
448 // } 451 // }
449 // } 452 // }
  453 + goodNames := []string{}
  454 + for _, v := range cmd.Goods {
  455 + goodNames = append(goodNames, v.GoodName)
  456 + }
450 //检查delivery_code是否重复 457 //检查delivery_code是否重复
451 - if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode, cmd.PartnerCategory, cmd.PartnerId, cmd.Id); err != nil { 458 + if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode,
  459 + cmd.PartnerCategory, cmd.PartnerId, cmd.Id, goodNames); err != nil {
452 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 460 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
453 } else if ok { 461 } else if ok {
454 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在") 462 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在")
@@ -1056,10 +1064,13 @@ func (service OrderInfoService) CreateNewOrderByImport(createOrderCommands []*co @@ -1056,10 +1064,13 @@ func (service OrderInfoService) CreateNewOrderByImport(createOrderCommands []*co
1056 errorDataList = append(errorDataList, row) 1064 errorDataList = append(errorDataList, row)
1057 continue 1065 continue
1058 } 1066 }
1059 - 1067 + goodNames := []string{}
  1068 + for _, v := range cmd.Goods {
  1069 + goodNames = append(goodNames, v.GoodName)
  1070 + }
1060 // 批量校验订单 1071 // 批量校验订单
1061 if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode, 1072 if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode,
1062 - cmd.PartnerCategory, cmd.PartnerId, 0); err != nil { 1073 + cmd.PartnerCategory, cmd.PartnerId, 0, goodNames); err != nil {
1063 row := &domain.ImportInfo{ 1074 row := &domain.ImportInfo{
1064 Error: lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()), 1075 Error: lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()),
1065 LineNumbers: cmd.LineNumbers, // 错误影响的行 1076 LineNumbers: cmd.LineNumbers, // 错误影响的行
@@ -28,16 +28,19 @@ func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*Order @@ -28,16 +28,19 @@ func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*Order
28 //@orderCode 订单号 28 //@orderCode 订单号
29 //@deliveryCode 发货单号 29 //@deliveryCode 发货单号
30 //@partnerCategoryCode 合伙人类型编号 30 //@partnerCategoryCode 合伙人类型编号
  31 +//@goodNames 货品名称列表
31 func (dao OrderBaseDao) CheckOrderExist(companyId int64, orderCode string, 32 func (dao OrderBaseDao) CheckOrderExist(companyId int64, orderCode string,
32 - deliveryCode string, partnerCategory int64, partnerId int64, notId int64) (bool, error) { 33 + deliveryCode string, partnerCategory int64, partnerId int64, notId int64, goodNames []string) (bool, error) {
33 tx := dao.transactionContext.GetDB() 34 tx := dao.transactionContext.GetDB()
34 query := tx.Model(&models.OrderBase{}). 35 query := tx.Model(&models.OrderBase{}).
  36 + Join("JOIN order_good ON order_base.id=order_good.order_id").
35 Where("company_id=?", companyId). 37 Where("company_id=?", companyId).
36 Where("order_code=?", orderCode). 38 Where("order_code=?", orderCode).
37 Where("delivery_code=?", deliveryCode). 39 Where("delivery_code=?", deliveryCode).
38 Where("partner_id=?", partnerId). 40 Where("partner_id=?", partnerId).
39 Where(`partner_category @>'{"id":?}'`, partnerCategory). 41 Where(`partner_category @>'{"id":?}'`, partnerCategory).
40 - Where("id<>?", notId) 42 + Where("id<>?", notId).
  43 + WhereIn("order_good.good_name in(?)", goodNames)
41 ok, err := query.Exists() 44 ok, err := query.Exists()
42 return ok, err 45 return ok, err
43 } 46 }