作者 陈志颖

refactor:优化退货单导入

... ... @@ -372,15 +372,15 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
// 返回信息表头定义
var tableHeader = map[string]interface{}{
"failReason": "失败原因",
"originalOrderNum": "来源单号",
"dividendsCustomerName": "客户名称",
"orderGoodName": "产品名称",
"orderTime": "订单日期",
"regionName": "订单区域",
"orderGoodQuantity": "产品数量",
"orderGoodPrice": "产品价格",
"expense": "费用",
"cooperationContractNumber": "项目合约编号",
"originalOrderNum": "来源单号", // 0
"dividendsCustomerName": "客户名称", // 1
"orderGoodName": "产品名称", // 2
"orderTime": "订单日期", // 3
"regionName": "订单区域", // 4
"orderGoodQuantity": "产品数量", // 5
"orderGoodPrice": "产品价格", // 6
"expense": "费用", // 7
"cooperationContractNumber": "项目合约编号", // 8
}
/************************************************ 1.空文件校验 ******************************************************/
... ... @@ -582,6 +582,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
price, err := strconv.ParseFloat(dividendsOrder.OrderGoodPrice, 64)
if err != nil {
tmpRow := &domain.FailInfo{
... ... @@ -591,6 +592,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
var expense float64
if dividendsOrder.Expense != "" {
if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil {
... ... @@ -643,6 +645,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
price, err := strconv.ParseFloat(dividendsOrder.OrderGoodPrice, 64)
if err != nil {
tmpRow := &domain.FailInfo{
... ... @@ -652,6 +655,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
var expense float64
if dividendsOrder.Expense != "" {
if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil {
... ...
... ... @@ -17,16 +17,16 @@ type (
OrderGoodName string `json:"orderGoodName"`
//退货日期
DividendsReturnedDate string `json:"dividendsReturnedDate"`
//订单日期
OrderTime string `json:"orderTime"`
//退货区域名称
RegionName string `json:"regionName"`
//订单产品单价
OrderGoodPrice string `json:"orderGoodPrice"`
//订单产品数量
OrderGoodQuantity string `json:"orderGoodQuantity"`
//订单产品单价
OrderGoodPrice string `json:"orderGoodPrice"`
//合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
//订单日期
OrderTime string `json:"orderTime"`
}
// ImportDividendsReturnedOrderCommand 请求参数
... ...
... ... @@ -412,15 +412,15 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
// 返回信息表头定义
var tableHeader = map[string]interface{}{
"failReason": "错误详情",
"originalOrderNum": "来源单号",
"dividendsReturnedCustomerName": "客户名称",
"orderGoodName": "产品名称",
"dividendsReturnedDate": "退货日期",
"regionName": "订单日期",
"orderGoodPrice": "订单区域",
"orderGoodQuantity": "退货数量",
"cooperationContractNumber": "退货价格",
"orderTime": "项目合约编号",
"originalOrderNum": "来源单号", // 0
"dividendsReturnedCustomerName": "客户名称", // 1
"orderGoodName": "产品名称", // 2
"dividendsReturnedDate": "退货日期", // 3
"orderTime": "订单日期", // 4
"regionName": "订单区域", // 5
"orderGoodQuantity": "退货数量", // 6
"orderGoodPrice": "退货价格", // 7
"cooperationContractNumber": "项目合约编号", // 8
}
/***************************************************** 空文件校验 ***************************************************/
... ... @@ -446,7 +446,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
v := reflect.ValueOf(dividendsReturnedOrder)
for k := 0; k < t.NumField(); k++ {
fmt.Println("name:", fmt.Sprintf("%+v", t.Field(k).Name), ", value:", fmt.Sprintf("%v", v.Field(k).Interface()))
if t.Field(k).Name != "RegionName" && t.Field(k).Name != "CooperationContractNumber" {
if t.Field(k).Name != "RegionName" {
if v.Field(k).Interface() == "" {
col := strconv.Itoa(k + 1)
nullCell = append(nullCell, col)
... ... @@ -581,10 +581,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
var dividendsReturnedOrderCommands = make(map[string]*command.CreateDividendsReturnedOrderCommand)
for i, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData {
hashValue := md5.Sum([]byte(dividendsReturnedOrder.OriginalOrderNum))
hashValue := md5.Sum([]byte(dividendsReturnedOrder.OriginalOrderNum + dividendsReturnedOrder.OrderTime))
hashString := hex.EncodeToString(hashValue[:])
if _, ok := dividendsReturnedOrderCommands[hashString]; !ok {
// 订单日期时间格式转换
timeValue, err := time.ParseInLocation("2006/01/02", dividendsReturnedOrder.OrderTime, time.Local)
if err != nil {
... ... @@ -600,7 +599,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
timeValue2, err := time.ParseInLocation("2006/01/02", dividendsReturnedOrder.DividendsReturnedDate, time.Local)
if err != nil {
tmpRow := &domain.FailReturnedInfo{
FailReason: "无效的订单日期",
FailReason: "无效的退货日期",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
... ... @@ -617,6 +616,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
price, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodPrice, 64)
if err != nil {
tmpRow := &domain.FailReturnedInfo{
... ... @@ -666,6 +666,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
price, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodPrice, 64)
if err != nil {
tmpRow := &domain.FailReturnedInfo{
... ... @@ -782,14 +783,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
// 批量导入创建退货单
for i, dividendsReturnedOrder := range createDividendsReturnedOrderCommands {
// 生成退货订单号
//dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber(map[string]interface{}{
// "companyId": importDividendsReturnedOrderCommand.CompanyId,
//})
//if err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//}
// 生成分红订单号
dividendsReturnedOrderNumber, err := dividendsReturnedOrder.GenerateSpecificDividendsReturnedOrderNumber(int64(count), time.Time{}, int64(i))
if err != nil {
... ... @@ -831,16 +824,16 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
returnedTime := utils.TransformTimestampToTime(returnedTimeInt)
// 校验退货订单编号是否唯一
numberAvailable, err3 := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
"companyId": importDividendsReturnedOrderCommand.CompanyId,
"dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
})
if err3 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
}
if !numberAvailable {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
}
//numberAvailable, err3 := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
// "companyId": importDividendsReturnedOrderCommand.CompanyId,
// "dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
//})
//if err3 != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
//}
//if !numberAvailable {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
//}
// 新增订单产品
var orderGoods []*domain.OrderGood
... ... @@ -856,7 +849,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
}
}
if !contractNumberExist {
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[j].LineNumber] = "单产品关联的共创合约不存在"
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[j].LineNumber] = "退货单产品关联的共创合约不存在"
continue
}
... ... @@ -909,8 +902,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
UpdatedAt: time.Time{},
})
// 计算分红订单金额
dividendsReturnedOrderAmount = dividendsReturnedOrderAmount + orderGood.OrderGoodAmount
// 计算分红退货单金额
dividendsReturnedOrderAmount, _ = decimal.NewFromFloat(dividendsReturnedOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity))).Float64()
//dividendsReturnedOrderAmount + orderGood.OrderGoodAmount
}
if len(orderGoodErrMap) > 0 {
... ...
... ... @@ -89,8 +89,8 @@ func (dao *DividendsReturnedOrderDao) CountDividendsReturnedOrder(queryOptions m
currentTime := time.Now()
todayZeroTime := utils.GetZeroTime(currentTime)
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("dividends_order.created_at >= ?", todayZeroTime)
query.Where("dividends_order.created_at < ?", nextDayZeroTime)
query.Where("dividends_returned_order.created_at >= ?", todayZeroTime)
query.Where("dividends_returned_order.created_at < ?", nextDayZeroTime)
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return 0, err
} else {
... ...