作者 陈志颖

fix:修复共创合约编辑必填项问题

... ... @@ -12,9 +12,9 @@ type UpdateCooperationContractCommand struct {
// 共创合约id
CooperationContractId string `cname:"共创合约id" json:"cooperationContractId" valid:"Required"`
// 共创合约描述
CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription" valid:"Required"`
CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription"`
// 共创项目编号
CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber" valid:"Required"`
CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber"`
// 部门ID
DepartmentId string `cname:"部门ID" json:"departmentId" valid:"Required"`
// 共创合约承接对象,1员工,2共创用户,3公开
... ...
... ... @@ -24,6 +24,8 @@ type OrderGoods struct {
CooperationContractNumber string `json:"cooperationContractNumber"`
// 订单产品费用
OrderGoodExpense float64 `json:"orderGoodExpense"`
//行号-错误信息返回
LineNumber int `json:"lineNumber"`
}
type CreateDividendsOrderCommand struct {
... ...
... ... @@ -13,6 +13,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"
... ... @@ -308,7 +309,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
rowCnt++
nullCell := make([]interface{}, 0)
//var myRow []string
var myRow interface{}
t := reflect.TypeOf(dividendsOrder)
v := reflect.ValueOf(dividendsOrder)
for k := 0; k < t.NumField(); k++ {
... ... @@ -322,19 +322,10 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
}
if nullFlag {
s := strconv.Itoa(i + 1)
myRow = map[string]interface{}{
"failReason": "第" + s + "行订单日期格式错误,请输入正确的订单日期",
"originalOrderNum": dividendsOrder.OriginalOrderNum,
"dividendsCustomerName": dividendsOrder.DividendsCustomerName,
"orderGoodName": dividendsOrder.OrderGoodName,
"orderTime": dividendsOrder.OrderTime,
"regionName": dividendsOrder.RegionName,
"orderGoodQuantity": dividendsOrder.OrderGoodQuantity,
"orderGoodPrice": dividendsOrder.OrderGoodPrice,
"expense": dividendsOrder.Expense,
"cooperationContractNumber": dividendsOrder.CooperationContractNumber,
myRow := &domain.FailInfo{
FailReason: "订单日期格式错误,请输入正确的订单日期",
}
myRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[i]
nullCellError = append(nullCellError, myRow)
nullFlag = false
}
... ... @@ -354,32 +345,22 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
// 单元格类型校验
typeError := make([]interface{}, 0)
for i, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData { // 行
var myRow interface{}
//var myRow []string
var myRow []*domain.FailInfo
t := reflect.TypeOf(dividendsOrder)
v := reflect.ValueOf(dividendsOrder)
for k := 0; k < t.NumField(); k++ { // 列
r := strconv.Itoa(i + 1)
//col := strconv.Itoa(k + 1)
switch k {
case 3: // 订单日期校验
{
regexpStr := `(\d{4})/(\d{2})/(\d{2})`
ok := regexp.MustCompile(regexpStr).MatchString(fmt.Sprintf("%v", v.Field(k).Interface()))
if !ok {
tmpRow := map[string]interface{}{
"failReason": "第" + r + "行订单日期格式错误,请输入正确的订单日期",
"originalOrderNum": dividendsOrder.OriginalOrderNum,
"dividendsCustomerName": dividendsOrder.DividendsCustomerName,
"orderGoodName": dividendsOrder.OrderGoodName,
"orderTime": dividendsOrder.OrderTime,
"regionName": dividendsOrder.RegionName,
"orderGoodQuantity": dividendsOrder.OrderGoodQuantity,
"orderGoodPrice": dividendsOrder.OrderGoodPrice,
"expense": dividendsOrder.Expense,
"cooperationContractNumber": dividendsOrder.CooperationContractNumber,
tmpRow := &domain.FailInfo{
FailReason: "订单日期格式错误,请输入正确的订单日期",
}
myRow = tmpRow
tmpRow.ImportDividendsOrderData = &dividendsOrder
myRow = append(myRow, tmpRow)
}
}
case 5: // 产品数量校验
... ... @@ -387,35 +368,19 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
//参数类型转换
orderGoodQuantity, err := strconv.ParseInt(fmt.Sprintf("%v", v.Field(k).Interface()), 10, 64)
if err != nil {
tmpRow := map[string]interface{}{
"failReason": "第" + r + "行产品数量格式错误,产品数量必须整数",
"originalOrderNum": dividendsOrder.OriginalOrderNum,
"dividendsCustomerName": dividendsOrder.DividendsCustomerName,
"orderGoodName": dividendsOrder.OrderGoodName,
"orderTime": dividendsOrder.OrderTime,
"regionName": dividendsOrder.RegionName,
"orderGoodQuantity": dividendsOrder.OrderGoodQuantity,
"orderGoodPrice": dividendsOrder.OrderGoodPrice,
"expense": dividendsOrder.Expense,
"cooperationContractNumber": dividendsOrder.CooperationContractNumber,
tmpRow := &domain.FailInfo{
FailReason: "行产品数量格式错误,产品数量必须整数",
}
myRow = tmpRow
tmpRow.ImportDividendsOrderData = &dividendsOrder
myRow = append(myRow, tmpRow)
}
// 正负判断
if orderGoodQuantity < 0 {
tmpRow := map[string]interface{}{
"failReason": "第" + r + "行产品数量必须大于0,请重新填写",
"originalOrderNum": dividendsOrder.OriginalOrderNum,
"dividendsCustomerName": dividendsOrder.DividendsCustomerName,
"orderGoodName": dividendsOrder.OrderGoodName,
"orderTime": dividendsOrder.OrderTime,
"regionName": dividendsOrder.RegionName,
"orderGoodQuantity": dividendsOrder.OrderGoodQuantity,
"orderGoodPrice": dividendsOrder.OrderGoodPrice,
"expense": dividendsOrder.Expense,
"cooperationContractNumber": dividendsOrder.CooperationContractNumber,
tmpRow := &domain.FailInfo{
FailReason: "产品数量必须大于0,请重新填写",
}
myRow = tmpRow
tmpRow.ImportDividendsOrderData = &dividendsOrder
myRow = append(myRow, tmpRow)
}
}
case 6: // 产品价格校验
... ... @@ -423,37 +388,21 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
// 参数类型转换
univalent, typeErr := strconv.ParseFloat(fmt.Sprintf("%v", v.Field(k).Interface()), 64)
if typeErr != nil {
tmpRow := map[string]interface{}{
"failReason": "第" + r + "行产品价格格式错误,产品价格必须为数字类型",
"originalOrderNum": dividendsOrder.OriginalOrderNum,
"dividendsCustomerName": dividendsOrder.DividendsCustomerName,
"orderGoodName": dividendsOrder.OrderGoodName,
"orderTime": dividendsOrder.OrderTime,
"regionName": dividendsOrder.RegionName,
"orderGoodQuantity": dividendsOrder.OrderGoodQuantity,
"orderGoodPrice": dividendsOrder.OrderGoodPrice,
"expense": dividendsOrder.Expense,
"cooperationContractNumber": dividendsOrder.CooperationContractNumber,
tmpRow := &domain.FailInfo{
FailReason: "产品价格格式错误,产品价格必须为数字类型",
}
myRow = tmpRow
tmpRow.ImportDividendsOrderData = &dividendsOrder
myRow = append(myRow, tmpRow)
}
// 长度校验
if univalent >= 1e16 {
tmpRow := map[string]interface{}{
"failReason": "第" + r + "行产品价格超过最大限制,产品价格小数点前面不能超过十六位数字,并保留两位小数",
"originalOrderNum": dividendsOrder.OriginalOrderNum,
"dividendsCustomerName": dividendsOrder.DividendsCustomerName,
"orderGoodName": dividendsOrder.OrderGoodName,
"orderTime": dividendsOrder.OrderTime,
"regionName": dividendsOrder.RegionName,
"orderGoodQuantity": dividendsOrder.OrderGoodQuantity,
"orderGoodPrice": dividendsOrder.OrderGoodPrice,
"expense": dividendsOrder.Expense,
"cooperationContractNumber": dividendsOrder.CooperationContractNumber,
tmpRow := &domain.FailInfo{
FailReason: "第" + r + "行产品价格超过最大限制,产品价格小数点前面不能超过十六位数字,并保留两位小数",
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
// 错误行数据
myRow = tmpRow
myRow = append(myRow, tmpRow)
}
}
case 7: // 费用校验
... ... @@ -462,36 +411,22 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
// 参数类型转换
univalent, typeErr := strconv.ParseFloat(fmt.Sprintf("%v", v.Field(k).Interface()), 64)
if typeErr != nil {
tmpRow := map[string]interface{}{
"failReason": "第" + r + "行费用格式错误,费用必须为数字类型",
"originalOrderNum": dividendsOrder.OriginalOrderNum,
"dividendsCustomerName": dividendsOrder.DividendsCustomerName,
"orderGoodName": dividendsOrder.OrderGoodName,
"orderTime": dividendsOrder.OrderTime,
"regionName": dividendsOrder.RegionName,
"orderGoodQuantity": dividendsOrder.OrderGoodQuantity,
"orderGoodPrice": dividendsOrder.OrderGoodPrice,
"expense": dividendsOrder.Expense,
"cooperationContractNumber": dividendsOrder.CooperationContractNumber,
tmpRow := &domain.FailInfo{
FailReason: "第" + r + "行费用格式错误,费用必须为数字类型",
}
myRow = tmpRow
tmpRow.ImportDividendsOrderData = &dividendsOrder
myRow = append(myRow, tmpRow)
log.Logger.Info("费用类型错误", map[string]interface{}{
"tmpRow": tmpRow,
})
}
// 长度校验
if univalent >= 1e16 {
tmpRow := map[string]interface{}{
"failReason": "第" + r + "行费用超过最大限制,费用小数点前面不能超过十六位数字,并保留两位小数",
"originalOrderNum": dividendsOrder.OriginalOrderNum,
"dividendsCustomerName": dividendsOrder.DividendsCustomerName,
"orderGoodName": dividendsOrder.OrderGoodName,
"orderTime": dividendsOrder.OrderTime,
"regionName": dividendsOrder.RegionName,
"orderGoodQuantity": dividendsOrder.OrderGoodQuantity,
"orderGoodPrice": dividendsOrder.OrderGoodPrice,
"expense": dividendsOrder.Expense,
"cooperationContractNumber": dividendsOrder.CooperationContractNumber,
tmpRow := &domain.FailInfo{
FailReason: "第" + r + "行费用超过最大限制,费用小数点前面不能超过十六位数字,并保留两位小数",
}
myRow = tmpRow
tmpRow.ImportDividendsOrderData = &dividendsOrder
myRow = append(myRow, tmpRow)
}
}
}
... ... @@ -524,19 +459,11 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
// 订单日期时间格式转换
timeValue, err := time.ParseInLocation("2006/01/02", dividendsOrder.OrderTime, time.Local)
if err != nil {
s := strconv.Itoa(i + 1)
tmpRow := map[string]interface{}{
"failReason": "第" + s + "行无效的订单日期",
"originalOrderNum": dividendsOrder.OriginalOrderNum,
"dividendsCustomerName": dividendsOrder.DividendsCustomerName,
"orderGoodName": dividendsOrder.OrderGoodName,
"orderTime": dividendsOrder.OrderTime,
"regionName": dividendsOrder.RegionName,
"orderGoodQuantity": dividendsOrder.OrderGoodQuantity,
"orderGoodPrice": dividendsOrder.OrderGoodPrice,
"expense": dividendsOrder.Expense,
"cooperationContractNumber": dividendsOrder.CooperationContractNumber,
//s := strconv.Itoa(i + 1)
tmpRow := &domain.FailInfo{
FailReason: "无效的订单日期",
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
aggregateErrorList = append(aggregateErrorList, tmpRow)
break
}
... ... @@ -659,36 +586,20 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
for _, errorData := range errorDataList {
if len(errorData.GoodLine) == 0 { // 订单错误
for _, line := range errorData.LineNumbers {
s := strconv.Itoa(line + 1)
tmpRow := map[string]interface{}{
"failReason": "第" + s + "行数据校验错误:" + errorData.Error.Error(),
"originalOrderNum": importDividendsOrderCommand.DividendsOrderData[line].OriginalOrderNum,
"dividendsCustomerName": importDividendsOrderCommand.DividendsOrderData[line].DividendsCustomerName,
"orderGoodName": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodName,
"orderTime": importDividendsOrderCommand.DividendsOrderData[line].OrderTime,
"regionName": importDividendsOrderCommand.DividendsOrderData[line].RegionName,
"orderGoodQuantity": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodQuantity,
"orderGoodPrice": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodPrice,
"expense": importDividendsOrderCommand.DividendsOrderData[line].Expense,
"cooperationContractNumber": importDividendsOrderCommand.DividendsOrderData[line].CooperationContractNumber,
//s := strconv.Itoa(line + 1)
tmpRow := &domain.FailInfo{
FailReason: "数据校验错误:" + errorData.Error.Error(),
}
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[line]
failureDataList = append(failureDataList, tmpRow)
}
} else if len(errorData.GoodLine) > 0 { // 订单产品错误
for line := range errorData.GoodLine {
s := strconv.Itoa(line + 1)
tmpRow := map[string]interface{}{
"failReason": "第" + s + "行订单产品信息错误:" + errorData.Error.Error(),
"originalOrderNum": importDividendsOrderCommand.DividendsOrderData[line].OriginalOrderNum,
"dividendsCustomerName": importDividendsOrderCommand.DividendsOrderData[line].DividendsCustomerName,
"orderGoodName": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodName,
"orderTime": importDividendsOrderCommand.DividendsOrderData[line].OrderTime,
"regionName": importDividendsOrderCommand.DividendsOrderData[line].RegionName,
"orderGoodQuantity": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodQuantity,
"orderGoodPrice": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodPrice,
"expense": importDividendsOrderCommand.DividendsOrderData[line].Expense,
"cooperationContractNumber": importDividendsOrderCommand.DividendsOrderData[line].CooperationContractNumber,
//s := strconv.Itoa(line + 1)
tmpRow := &domain.FailInfo{
FailReason: "订单产品信息错误:" + errorData.Error.Error(),
}
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[line]
failureDataList = append(failureDataList, tmpRow)
}
}
... ... @@ -736,15 +647,18 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
// 新增订单产品
var orderGoods []*domain.OrderGood
var dividendsOrderAmount float64
for _, orderGood := range dividendsOrder.OrderGoods {
orderGoodErrMap := make(map[int]interface{}, 0)
for i, orderGood := range dividendsOrder.OrderGoods {
// 校验共创合约是否合法
contractNumberExist, _ := cooperationContractDao.CheckContractNumberExist(map[string]interface{}{
"companyId": importDividendsOrderCommand.CompanyId,
"orgId": importDividendsOrderCommand.OrgId,
"cooperationContractNumber": orderGood.CooperationContractNumber,
})
if !contractNumberExist {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "共创合约编号不存在")
if orderGood.CooperationContractNumber != "" {
contractNumberExist, _ := cooperationContractDao.CheckContractNumberExist(map[string]interface{}{
"companyId": importDividendsOrderCommand.CompanyId,
"orgId": importDividendsOrderCommand.OrgId,
"cooperationContractNumber": orderGood.CooperationContractNumber,
})
if !contractNumberExist {
orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("共创合约编号不存在:%s", err))
}
}
orderGoods = append(orderGoods, &domain.OrderGood{
... ... @@ -767,6 +681,15 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
// 计算分红订单金额
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
}
if len(orderGoodErrMap) > 0 {
row := &domain.ImportInfo{
Error: application.ThrowError(application.BUSINESS_ERROR, "共创合约不存在"),
LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
GoodLine: orderGoodErrMap, // 错误产品行号记录
}
errorDataList = append(errorDataList, row)
continue
}
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(dividendsOrder.OrderTime, 10, 64)
... ... @@ -817,7 +740,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
// 错误报告处理
if len(errorDataList) <= 0 {
if len(errorDataList) <= 0 { // 成功返回
if err3 := transactionContext.CommitTransaction(); err3 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
}
... ... @@ -825,45 +748,29 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
if successDataCount == int64(rowCnt) {
return map[string]interface{}{
"successCount": successDataCount,
"fail": nil,
"fail": map[string]interface{}{},
}, nil
}
} else {
} else { // 失败返回
successDataCount = 0
// 错误记录处理
for _, errorData := range errorDataList {
if len(errorData.GoodLine) == 0 { // 订单错误
for _, line := range errorData.LineNumbers {
s := strconv.Itoa(line + 1)
tmpRow := map[string]interface{}{
"failReason": "第" + s + "行订单数据新增错误:" + errorData.Error.Error(),
"originalOrderNum": importDividendsOrderCommand.DividendsOrderData[line].OriginalOrderNum,
"dividendsCustomerName": importDividendsOrderCommand.DividendsOrderData[line].DividendsCustomerName,
"orderGoodName": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodName,
"orderTime": importDividendsOrderCommand.DividendsOrderData[line].OrderTime,
"regionName": importDividendsOrderCommand.DividendsOrderData[line].RegionName,
"orderGoodQuantity": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodQuantity,
"orderGoodPrice": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodPrice,
"expense": importDividendsOrderCommand.DividendsOrderData[line].Expense,
"cooperationContractNumber": importDividendsOrderCommand.DividendsOrderData[line].CooperationContractNumber,
//s := strconv.Itoa(line + 1)
tmpRow := &domain.FailInfo{
FailReason: "订单数据新增错误:" + errorData.Error.Error(),
}
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[line]
failureDataList = append(failureDataList, tmpRow)
}
} else if len(errorData.GoodLine) > 0 { // 订单产品错误
for line := range errorData.GoodLine {
s := strconv.Itoa(line + 1)
tmpRow := map[string]interface{}{
"failReason": "第" + s + "行订单数据新增错误:" + errorData.Error.Error(),
"originalOrderNum": importDividendsOrderCommand.DividendsOrderData[line].OriginalOrderNum,
"dividendsCustomerName": importDividendsOrderCommand.DividendsOrderData[line].DividendsCustomerName,
"orderGoodName": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodName,
"orderTime": importDividendsOrderCommand.DividendsOrderData[line].OrderTime,
"regionName": importDividendsOrderCommand.DividendsOrderData[line].RegionName,
"orderGoodQuantity": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodQuantity,
"orderGoodPrice": importDividendsOrderCommand.DividendsOrderData[line].OrderGoodPrice,
"expense": importDividendsOrderCommand.DividendsOrderData[line].Expense,
"cooperationContractNumber": importDividendsOrderCommand.DividendsOrderData[line].CooperationContractNumber,
//s := strconv.Itoa(line + 1)
tmpRow := &domain.FailInfo{
FailReason: "订单数据新增错误:" + errorData.Error.Error(),
}
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[line]
failureDataList = append(failureDataList, tmpRow)
}
}
... ...
package domain
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/command"
"time"
)
... ... @@ -52,9 +53,24 @@ type DividendsOrder struct {
// ImportInfo 导入错误信息
type ImportInfo struct {
Error error
LineNumbers []int
GoodLine map[int]interface{}
Error error `json:"error"`
LineNumbers []int `json:"lineNumbers"`
GoodLine map[int]interface{} `json:"goodLine"`
}
// FailInfo 返回的失败信息
type FailInfo struct {
FailReason string `json:"failReason"`
//OriginalOrderNum string `json:"originalOrderNum"`
//DividendsCustomerName string `json:"dividendsCustomerName"`
//OrderGoodName string `json:"orderGoodName"`
//OrderTime string `json:"orderTime"`
//RegionName string `json:"regionName"`
//OrderGoodQuantity string `json:"orderGoodQuantity"`
//OrderGoodPrice string `json:"orderGoodPrice"`
//Expense string `json:"expense"`
//CooperationContractNumber string `json:"cooperationContractNumber"`
*command.ImportDividendsOrderData
}
type DividendsOrderRepository interface {
... ...
... ... @@ -255,6 +255,7 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.Where("is_canceled = ?", false)
query.SetOrderDirect("cooperation_application_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationApplications, err
... ...