作者 唐旭辉

Merge branch 'dev' into test

... ... @@ -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
}
... ...
... ... @@ -709,7 +709,7 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
// c.ResponseError(errors.New("json数据解析失败"))
//}
if typeCode != "PARTNER_ORDER_IMPORT" {
if typeCode != "PARTNER_ORDER_FILE" {
c.ResponseError(errors.New("类型编码错误"))
}
... ... @@ -987,6 +987,9 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
// 创建订单服务
orderSrv := orderService.NewOrderInfoService(nil)
// 合伙人检索错误
partnerDataList := make([]interface{}, 0)
// 聚合订单产品
var orderCommands = make(map[string]*orderCmd.CreateOrderCommand, 0)
for i, row := range rows {
... ... @@ -1028,27 +1031,35 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
// 获取partnerId
var partnerInfo *domain.PartnerInfo
partnerInfo, err = orderSrv.GetPartnerIdByCodeAndCategory(orderQuery.GetPartnerIdQuery{
orderQueryData := orderQuery.GetPartnerIdQuery{
Code: row[4],
PartnerCategory: 0,
CompanyId: companyId,
})
if err != nil {
}
// 1: 事业合伙、2: 业务合伙、3: 研发合伙、4: 业务-产品应用合伙
switch row[6] {
case "事业合伙":
orderQueryData.PartnerCategory = 1
case "业务合伙":
orderQueryData.PartnerCategory = 2
case "研发合伙":
orderQueryData.PartnerCategory = 3
case "业务-产品应用合伙":
orderQueryData.PartnerCategory = 4
default:
orderQueryData.PartnerCategory = 0
}
partnerInfo, err = orderSrv.GetPartnerIdByCodeAndCategory(orderQueryData)
if err != nil || partnerInfo == nil { // 检索合伙人错误
var tmpRow []string
tmpRow = append(tmpRow, err.Error()) // 错误信息
s := strconv.Itoa(i + 1)
tmpRow = append(tmpRow, s) // 行号
tmpRow = append(tmpRow, row...) // 错误行数据
partnerDataList = append(partnerDataList, tmpRow)
}
if partnerInfo != nil {
orderCommands[hashString].PartnerId = partnerInfo.Partner.Id
// 1: 事业合伙、2: 业务合伙、3: 研发合伙、4: 业务-产品应用合伙
switch row[6] {
case "事业合伙":
partnerInfo.PartnerCategory = 1
case "业务合伙":
partnerInfo.PartnerCategory = 2
case "研发合伙":
partnerInfo.PartnerCategory = 3
case "业务-产品应用合伙":
partnerInfo.PartnerCategory = 4
}
}
} else {
//产品相关,8: 产品名称, 9: 数量, 10: 单价, 11: 合伙人分红比例
... ... @@ -1070,6 +1081,17 @@ func (c *OrderInfoController) ImportOrderFromExcel() {
}
}
}
if len(partnerDataList) > 0 {
ret = map[string]interface{}{
"successCount": 0,
"fail": map[string]interface{}{
"tableHeader": tableHeader,
"tableData": partnerDataList,
},
}
c.ResponseData(ret)
return
}
// 产品数量校验
productNumberError := make([]interface{}, 0)
... ...