作者 陈志颖

合并分支 'dev' 到 'test'

refactor:分红退货单导入调整、优化



查看合并请求 !46
... ... @@ -824,6 +824,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
log.Logger.Info("订单产品匹配的合约", map[string]interface{}{
"contractMatched": cooperationContractsMap[orderGood.CooperationContractNumber],
})
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
orderGoodErrMap[dividendsOrder.OrderGoods[j].LineNumber] = "分红订单不能关联金额激励规则"
continue
... ...
... ... @@ -5,6 +5,7 @@ import (
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
"time"
)
type OrderGoods struct {
... ... @@ -61,6 +62,28 @@ type CreateDividendsReturnedOrderCommand struct {
LineNumbers []int `cname:"记录行号" json:"lineNumbers"`
}
// GenerateSpecificDividendsReturnedOrderNumber 生成自定义退货单号
func (createDividendsReturnedOrderCommand *CreateDividendsReturnedOrderCommand) GenerateSpecificDividendsReturnedOrderNumber(count int64, orderTime time.Time, index int64) (string, error) {
currentTime := time.Now()
if count+index < 1000 {
countStr := fmt.Sprintf("%03d", count+index+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "RE" + timeString + "#" + countStr
return dividendsOrderNumber, nil
} else {
countStr := fmt.Sprintf("%d", count+index+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "RE" + timeString + "#" + countStr
return dividendsOrderNumber, nil
}
}
func (createDividendsReturnedOrderCommand *CreateDividendsReturnedOrderCommand) Valid(validation *validation.Validation) {
}
... ...
... ... @@ -14,6 +14,7 @@ import (
"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"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"reflect"
"regexp"
"strconv"
... ... @@ -422,13 +423,15 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
"orderTime": "项目合约编号",
}
// 空文件校验
/***************************************************** 空文件校验 ***************************************************/
if len(importDividendsReturnedOrderCommand.DividendsReturnedOrderData) == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "导入的Excel文件为空文件,请上传正确的文件")
}
/******************************************************************************************************************/
// 必填项校验
nullCellError := make([]interface{}, 0)
/************************************************ 2.必填项校验 ******************************************************/
// 空单元格错误
nullCellError := make([]*domain.FailReturnedInfo, 0)
// 数据行计数
rowCnt := 0
... ... @@ -439,11 +442,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
for i, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData {
rowCnt++
nullCell := make([]interface{}, 0)
var myRow *domain.FailReturnedInfo
t := reflect.TypeOf(dividendsReturnedOrder)
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()), ", yaml:", t.Field(k).Tag.Get("yaml"))
if k != 5 && k != 8 {
if v.Field(k).Interface() == "" {
col := strconv.Itoa(k + 1)
... ... @@ -453,9 +454,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
}
}
if nullFlag {
//s := strconv.Itoa(i + 1)
//b := strings.Replace(strings.Trim(fmt.Sprint(nullCell), "[]"), " ", ",", -1)
myRow = &domain.FailReturnedInfo{
myRow := &domain.FailReturnedInfo{
FailReason: "必填项为空",
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[i],
}
... ... @@ -474,11 +473,12 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
},
}, nil
}
/******************************************************************************************************************/
// 单元格类型校验
typeError := make([]interface{}, 0)
/***************************************************** 3.单元格类型校验 *********************************************/
typeError := make([]*domain.FailReturnedInfo, 0)
for _, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData { // 行
var myRow *domain.FailReturnedInfo
var myRow []*domain.FailReturnedInfo
t := reflect.TypeOf(dividendsReturnedOrder)
v := reflect.ValueOf(dividendsReturnedOrder)
for k := 0; k < t.NumField(); k++ { // 列
... ... @@ -488,12 +488,12 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
regexpStr := `(\d{4})/(\d{2})/(\d{2})`
ok := regexp.MustCompile(regexpStr).MatchString(fmt.Sprintf("%v", v.Field(k).Interface()))
if !ok {
var tmpRow *domain.FailReturnedInfo
tmpRow = &domain.FailReturnedInfo{
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货日期格式错误,请输入正确的退货日期",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
myRow = tmpRow
myRow = append(myRow, tmpRow)
continue
}
}
case 4: // 订单日期校验
... ... @@ -501,12 +501,12 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
regexpStr := `(\d{4})/(\d{2})/(\d{2})`
ok := regexp.MustCompile(regexpStr).MatchString(fmt.Sprintf("%v", v.Field(k).Interface()))
if !ok {
var tmpRow *domain.FailReturnedInfo
tmpRow = &domain.FailReturnedInfo{
tmpRow := &domain.FailReturnedInfo{
FailReason: "订单日期格式错误,请输入正确的订单日期",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
myRow = tmpRow
myRow = append(myRow, tmpRow)
continue
}
}
case 6: // 退货数量校验
... ... @@ -514,21 +514,21 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
//参数类型转换
orderGoodQuantity, err := strconv.ParseInt(fmt.Sprintf("%v", v.Field(k).Interface()), 10, 64)
if err != nil {
var tmpRow *domain.FailReturnedInfo
tmpRow = &domain.FailReturnedInfo{
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货数量格式错误,退货数量必须整数",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
myRow = tmpRow
myRow = append(myRow, tmpRow)
continue
}
// 正负判断
if orderGoodQuantity < 0 {
var tmpRow *domain.FailReturnedInfo
tmpRow = &domain.FailReturnedInfo{
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货数量必须大于0,请重新填写",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
myRow = tmpRow
myRow = append(myRow, tmpRow)
continue
}
}
case 7: // 退货价格校验
... ... @@ -536,28 +536,28 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
// 参数类型转换
univalent, typeErr := strconv.ParseFloat(fmt.Sprintf("%v", v.Field(k).Interface()), 64)
if typeErr != nil {
var tmpRow *domain.FailReturnedInfo
tmpRow = &domain.FailReturnedInfo{
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货价格格式错误,退货价格必须为数字类型",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
myRow = tmpRow
myRow = append(myRow, tmpRow)
continue
}
// 长度校验
if univalent >= 1e16 {
var tmpRow *domain.FailReturnedInfo
tmpRow = &domain.FailReturnedInfo{
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货价格超过最大限制,退货价格小数点前面不能超过十六位数字,并保留两位小数",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
myRow = tmpRow
myRow = append(myRow, tmpRow)
continue
}
}
}
}
if myRow != nil {
typeError = append(typeError, myRow)
if len(myRow) > 0 {
typeError = append(typeError, myRow...)
}
}
... ... @@ -571,53 +571,59 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
},
}, nil
}
/******************************************************************************************************************/
/******************************************** 4.聚合订单并进行类型校验 ************************************************/
// 聚合订单并进行类型校验
aggregateErrorList := make([]interface{}, 0)
var dividendsReturnedOrderCommands = make(map[string]*command.CreateDividendsReturnedOrderCommand)
for i, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData {
hashValue := md5.Sum([]byte(dividendsReturnedOrder.OriginalOrderNum))
hashString := hex.EncodeToString(hashValue[:])
if _, ok := dividendsReturnedOrderCommands[hashString]; !ok {
// 来源单号
dividendsReturnedOrderCommands[hashString].OriginalOrderNum = dividendsReturnedOrder.OriginalOrderNum
// 客户名称
dividendsReturnedOrderCommands[hashString].DividendsReturnedCustomerName = dividendsReturnedOrder.DividendsReturnedCustomerName
// 订单日期时间格式转换
timeValue, err := time.ParseInLocation("2006/01/02", dividendsReturnedOrder.OrderTime, time.Local)
if err != nil {
var tmpRow []string
tmpRow = append(tmpRow, "无效的订单日期") // 错误信息
s := strconv.Itoa(i + 1)
tmpRow = append(tmpRow, s) // 行号
//tmpRow = append(tmpRow, dividendsReturnedOrder.OriginalOrderNum) // TODO 错误行数据
tmpRow := &domain.FailReturnedInfo{
FailReason: "无效的订单日期",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
break
continue
}
// 退货日期格式转换
timeValue2, err := time.ParseInLocation("2006/01/02", dividendsReturnedOrder.DividendsReturnedDate, time.Local)
if err != nil {
var tmpRow []string
tmpRow = append(tmpRow, "无效的订单日期") // 错误信息
s := strconv.Itoa(i + 1)
tmpRow = append(tmpRow, s) // 行号
//tmpRow = append(tmpRow, dividendsReturnedOrder.OriginalOrderNum) // TODO 错误行数据
tmpRow := &domain.FailReturnedInfo{
FailReason: "无效的订单日期",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
break
continue
}
// 产品相关:产品名称,退货数量、退货价格
quantity, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodQuantity, 64)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
tmpRow := &domain.FailReturnedInfo{
FailReason: "产品数量类型错误",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
price, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodPrice, 64)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
tmpRow := &domain.FailReturnedInfo{
FailReason: "产品价格类型错误",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
// 初始化新建分红订单命令集
... ... @@ -639,6 +645,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
DividendsOrderNumber: "",
CooperationContractNumber: dividendsReturnedOrder.CooperationContractNumber,
OrderGoodExpense: 0,
LineNumber: i,
},
},
CompanyId: importDividendsReturnedOrderCommand.CompanyId,
... ... @@ -651,11 +658,21 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
// 产品相关:产品名称,退货数量、退货价格
quantity, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodQuantity, 64)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
tmpRow := &domain.FailReturnedInfo{
FailReason: "产品数量类型错误",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
price, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodPrice, 64)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
tmpRow := &domain.FailReturnedInfo{
FailReason: "产品价格类型错误",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
dividendsReturnedOrderCommands[hashString].OrderGoods = append(dividendsReturnedOrderCommands[hashString].OrderGoods, command.OrderGoods{
... ... @@ -667,6 +684,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
DividendsOrderNumber: "",
CooperationContractNumber: dividendsReturnedOrder.CooperationContractNumber,
OrderGoodExpense: 0,
LineNumber: i,
})
// 记录聚合行号
... ... @@ -674,6 +692,10 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
}
}
log.Logger.Info("聚合退货单", map[string]interface{}{
"dividendsReturnedOrderCommands": dividendsReturnedOrderCommands,
})
// 聚合订单错误返回
if len(aggregateErrorList) > 0 {
return map[string]interface{}{
... ... @@ -684,22 +706,20 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
},
}, nil
}
/******************************************************************************************************************/
// 错误数据返回
var errorDataList []*domain.ImportInfo
// 批量创建分红订单命令集
/******************************************** 批量创建分红订单命令集 **************************************************/
var createDividendsReturnedOrderCommands []*command.CreateDividendsReturnedOrderCommand
for _, dividendsReturnedOrderCommand := range dividendsReturnedOrderCommands {
createDividendsReturnedOrderCommands = append(createDividendsReturnedOrderCommands, dividendsReturnedOrderCommand)
}
// 新增失败记录
failureDataList := make([]interface{}, 0)
// 新增成功记录计数
var successDataCount int64
// 错误数据返回
var errorDataList []*domain.ImportInfo
// 循环校验命令
for _, cmd := range createDividendsReturnedOrderCommands {
if err = cmd.ValidateCommand(); err != nil {
... ... @@ -714,6 +734,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
}
}
// 新增失败记录
failureDataList := make([]interface{}, 0)
// 循环校验命令失败返回
if len(errorDataList) > 0 {
successDataCount = 0
... ... @@ -721,20 +744,18 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
for _, errorData := range errorDataList {
if len(errorData.GoodLine) == 0 { // 订单错误
for _, line := range errorData.LineNumbers {
var tmpRow []string
tmpRow = append(tmpRow, errorData.Error.Error()) // 错误信息
s := strconv.Itoa(line + 1)
tmpRow = append(tmpRow, s) // 行号
//tmpRow = append(tmpRow, importDividendsOrderCommand.DividendsOrderData[line]...) // 错误行数据
tmpRow := &domain.FailReturnedInfo{
FailReason: "数据校验错误:" + errorData.Error.Error(),
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[line],
}
failureDataList = append(failureDataList, tmpRow)
}
} else if len(errorData.GoodLine) > 0 { // 订单产品错误
for line := range errorData.GoodLine {
var tmpRow []string
tmpRow = append(tmpRow, errorData.Error.Error()) // 错误信息
s := strconv.Itoa(line + 1)
tmpRow = append(tmpRow, s) // 行号
//tmpRow = append(tmpRow, importDividendsOrderCommand.DividendsOrderData[line]...) // 错误行数据
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货单产品信息错误:" + errorData.Error.Error(),
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[line],
}
failureDataList = append(failureDataList, tmpRow)
}
}
... ... @@ -747,17 +768,67 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
},
}, nil
}
/******************************************************************************************************************/
/********************************************** 创建分红退货单领域模型 *************************************************/
var createDividendsReturnedOrders []*domain.DividendsReturnedOrder
// 统计当前分红退货单数
count, err := dividendsReturnedOrderDao.CountDividendsReturnedOrder(map[string]interface{}{})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 批量导入创建退货单
for _, dividendsReturnedOrder := range createDividendsReturnedOrderCommands {
for i, dividendsReturnedOrder := range createDividendsReturnedOrderCommands {
// 生成退货订单号
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber(map[string]interface{}{
"companyId": importDividendsReturnedOrderCommand.CompanyId,
})
//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 {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
row := &domain.ImportInfo{
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红退货单号生成错误:%s", err)),
LineNumbers: dividendsReturnedOrder.LineNumbers, // 错误影响的行
GoodLine: map[int]string{},
}
errorDataList = append(errorDataList, row)
continue
}
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(dividendsReturnedOrder.OrderTime, 10, 64)
if err != nil {
row := &domain.ImportInfo{
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("订单日期转换错误:%s", err)),
LineNumbers: dividendsReturnedOrder.LineNumbers, // 错误影响的行
GoodLine: map[int]string{},
}
errorDataList = append(errorDataList, row)
continue
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 退货时间转换
returnedTimeInt, err := strconv.ParseInt(dividendsReturnedOrder.DividendsReturnedDate, 10, 64)
if err != nil {
row := &domain.ImportInfo{
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("退货时间错误:%s", err)),
LineNumbers: dividendsReturnedOrder.LineNumbers, // 错误影响的行
GoodLine: map[int]string{},
}
errorDataList = append(errorDataList, row)
continue
}
returnedTime := utils.TransformTimestampToTime(returnedTimeInt)
// 校验退货订单编号是否唯一
numberAvailable, err3 := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
"companyId": importDividendsReturnedOrderCommand.CompanyId,
... ... @@ -773,8 +844,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
// 新增订单产品
var orderGoods []*domain.OrderGood
var dividendsReturnedOrderAmount float64
orderGoodErrMap := make(map[int]interface{}, 0)
for i, orderGood := range dividendsReturnedOrder.OrderGoods {
orderGoodErrMap := make(map[int]string, 0)
for j, orderGood := range dividendsReturnedOrder.OrderGoods {
// 校验共创合约是否合法
contractNumberExist := false
for _, cooperationContract := range cooperationContracts {
... ... @@ -784,16 +855,39 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
}
}
if !contractNumberExist {
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("共创合约编号不存在:%s", err))
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[j].LineNumber] = "订单产品关联的共创合约不存在"
continue
}
// 计算产品金额
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
// 校验合约激励类型是否正确
ruleMatchedFlag := false
if orderGood.CooperationContractNumber != "" {
// 校验共创合约激励类型是否正确
log.Logger.Info("退货单产品匹配的合约", map[string]interface{}{
"contractMatched": cooperationContractsMap[orderGood.CooperationContractNumber],
})
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[j].LineNumber] = "退货单产品不能关联金额激励规则"
continue
}
// 检验产品关联合约的激励规则是否匹配订单时间
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
if (orderTime.After(incentivesRule.DividendsIncentivesStageStart) || orderTime.Equal(incentivesRule.DividendsIncentivesStageStart)) &&
(orderTime.Before(incentivesRule.DividendsIncentivesStageEnd) || orderTime.Equal(incentivesRule.DividendsIncentivesStageEnd)) {
ruleMatchedFlag = true
break
}
}
}
if !ruleMatchedFlag {
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[j].LineNumber] = "订单时间无法匹配分红激励规则"
continue
}
}
... ... @@ -813,23 +907,23 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
})
// 计算分红订单金额
dividendsReturnedOrderAmount = dividendsReturnedOrderAmount + orderGood.OrderGoodAmount
}
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(dividendsReturnedOrder.OrderTime, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 退货时间转换
returnedTimeInt, err := strconv.ParseInt(dividendsReturnedOrder.DividendsReturnedDate, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货时间错误")
if len(orderGoodErrMap) > 0 {
log.Logger.Info("校验退货单产品", map[string]interface{}{
"orderGoodErrMap": orderGoodErrMap,
})
row := &domain.ImportInfo{
Error: nil,
LineNumbers: dividendsReturnedOrder.LineNumbers, // 错误影响的行
GoodLine: orderGoodErrMap, // 错误产品行号记录
}
errorDataList = append(errorDataList, row)
continue
}
returnedTime := utils.TransformTimestampToTime(returnedTimeInt)
// 新增退货单
newDividendsReturnedOrder := &domain.DividendsReturnedOrder{
... ... @@ -858,17 +952,15 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
OperateTime: time.Now(),
}
if _, err2 := dividendsReturnedOrderRepository.Save(newDividendsReturnedOrder); err2 != nil {
row := &domain.ImportInfo{
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存退货单数据失败:%s", err)),
LineNumbers: dividendsReturnedOrder.LineNumbers, // 错误影响的行
GoodLine: map[int]string{},
}
errorDataList = append(errorDataList, row)
continue
}
createDividendsReturnedOrders = append(createDividendsReturnedOrders, newDividendsReturnedOrder)
}
/******************************************************************************************************************/
/*********************************************** 错误报告处理 *******************************************************/
if len(errorDataList) <= 0 {
if _, err4 := dividendsReturnedOrderRepository.SaveMany(createDividendsReturnedOrders); err4 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
}
if err3 := transactionContext.CommitTransaction(); err3 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
}
... ... @@ -876,7 +968,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if successDataCount == int64(rowCnt) {
return map[string]interface{}{
"successCount": successDataCount,
"fail": nil,
"fail": make(map[string]interface{}),
}, nil
}
} else {
... ... @@ -885,20 +977,18 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
for _, errorData := range errorDataList {
if len(errorData.GoodLine) == 0 { // 订单错误
for _, line := range errorData.LineNumbers {
var tmpRow []string
tmpRow = append(tmpRow, errorData.Error.Error()) // 错误信息
s := strconv.Itoa(line + 1)
tmpRow = append(tmpRow, s) // 行号
//tmpRow = append(tmpRow, importDividendsOrderCommand.DividendsOrderData[line]...) // 错误行数据
tmpRow := &domain.FailReturnedInfo{
FailReason: errorData.Error.Error(),
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[line],
}
failureDataList = append(failureDataList, tmpRow)
}
} else if len(errorData.GoodLine) > 0 { // 订单产品错误
for line := range errorData.GoodLine {
var tmpRow []string
tmpRow = append(tmpRow, errorData.Error.Error()) // 错误信息
s := strconv.Itoa(line + 1)
tmpRow = append(tmpRow, s) // 行号
//tmpRow = append(tmpRow, importDividendsOrderCommand.DividendsOrderData[line]...) // 错误行数据
tmpRow := &domain.FailReturnedInfo{
FailReason: errorData.GoodLine[line],
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[line],
}
failureDataList = append(failureDataList, tmpRow)
}
}
... ...
... ... @@ -81,6 +81,23 @@ func (dao *DividendsReturnedOrderDao) CalculateDividendsReturnedOrderAmount(quer
return dividendsOrderModel.DividendsReturnedOrderRefund, nil
}
// CountDividendsReturnedOrder 统计当前退货单总数
func (dao *DividendsReturnedOrderDao) CountDividendsReturnedOrder(queryOptions map[string]interface{}) (int, error) {
tx := dao.transactionContext.PgTx
var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
query := tx.Model(&dividendsReturnedOrderModels)
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)
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return 0, err
} else {
return count, nil
}
}
func NewDividendsReturnedOrderDao(transactionContext *pgTransaction.TransactionContext) (*DividendsReturnedOrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能未")
... ...