作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !37
@@ -336,6 +336,10 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -336,6 +336,10 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
336 } 336 }
337 } 337 }
338 338
  339 + log.Logger.Info("查找合约数据", map[string]interface{}{
  340 + "cooperationContractsMap": cooperationContractsMap,
  341 + })
  342 +
339 // 分红订单DAO初始化 343 // 分红订单DAO初始化
340 var dividendsOrderDao *dao.DividendsOrderDao 344 var dividendsOrderDao *dao.DividendsOrderDao
341 if value, err := factory.CreateDividendsOrderDao(map[string]interface{}{ 345 if value, err := factory.CreateDividendsOrderDao(map[string]interface{}{
@@ -370,12 +374,14 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -370,12 +374,14 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
370 "cooperationContractNumber": "项目合约编号", 374 "cooperationContractNumber": "项目合约编号",
371 } 375 }
372 376
373 - // 空文件校验 377 + /************************************************ 1.空文件校验 ******************************************************/
374 if len(importDividendsOrderCommand.DividendsOrderData) == 0 { 378 if len(importDividendsOrderCommand.DividendsOrderData) == 0 {
375 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "导入的Excel文件为空文件,请上传正确的文件") 379 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "导入的Excel文件为空文件,请上传正确的文件")
376 } 380 }
  381 + /******************************************************************************************************************/
377 382
378 - // 必填项校验 383 + /************************************************ 2.必填项校验 ******************************************************/
  384 + // 空单元格错误
379 nullCellError := make([]*domain.FailInfo, 0) 385 nullCellError := make([]*domain.FailInfo, 0)
380 386
381 // 数据行计数 387 // 数据行计数
@@ -419,15 +425,16 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -419,15 +425,16 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
419 }, 425 },
420 }, nil 426 }, nil
421 } 427 }
  428 + /******************************************************************************************************************/
422 429
423 - // 单元格类型校验  
424 - typeError := make([]interface{}, 0)  
425 - for i, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData { // 行 430 + /***************************************************** 3.单元格类型校验 *********************************************/
  431 + typeError := make([]*domain.FailInfo, 0)
  432 + for _, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData { // 行
426 var myRow []*domain.FailInfo 433 var myRow []*domain.FailInfo
427 t := reflect.TypeOf(dividendsOrder) 434 t := reflect.TypeOf(dividendsOrder)
428 v := reflect.ValueOf(dividendsOrder) 435 v := reflect.ValueOf(dividendsOrder)
429 for k := 0; k < t.NumField(); k++ { // 列 436 for k := 0; k < t.NumField(); k++ { // 列
430 - r := strconv.Itoa(i + 1) 437 + //r := strconv.Itoa(i + 1)
431 switch k { 438 switch k {
432 case 3: // 订单日期校验 439 case 3: // 订单日期校验
433 { 440 {
@@ -439,6 +446,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -439,6 +446,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
439 } 446 }
440 tmpRow.ImportDividendsOrderData = &dividendsOrder 447 tmpRow.ImportDividendsOrderData = &dividendsOrder
441 myRow = append(myRow, tmpRow) 448 myRow = append(myRow, tmpRow)
  449 + continue
442 } 450 }
443 } 451 }
444 case 5: // 产品数量校验 452 case 5: // 产品数量校验
@@ -451,6 +459,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -451,6 +459,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
451 } 459 }
452 tmpRow.ImportDividendsOrderData = &dividendsOrder 460 tmpRow.ImportDividendsOrderData = &dividendsOrder
453 myRow = append(myRow, tmpRow) 461 myRow = append(myRow, tmpRow)
  462 + continue
454 } 463 }
455 // 正负判断 464 // 正负判断
456 if orderGoodQuantity < 0 { 465 if orderGoodQuantity < 0 {
@@ -459,6 +468,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -459,6 +468,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
459 } 468 }
460 tmpRow.ImportDividendsOrderData = &dividendsOrder 469 tmpRow.ImportDividendsOrderData = &dividendsOrder
461 myRow = append(myRow, tmpRow) 470 myRow = append(myRow, tmpRow)
  471 + continue
462 } 472 }
463 } 473 }
464 case 6: // 产品价格校验 474 case 6: // 产品价格校验
@@ -471,16 +481,17 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -471,16 +481,17 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
471 } 481 }
472 tmpRow.ImportDividendsOrderData = &dividendsOrder 482 tmpRow.ImportDividendsOrderData = &dividendsOrder
473 myRow = append(myRow, tmpRow) 483 myRow = append(myRow, tmpRow)
  484 + continue
474 } 485 }
475 486
476 // 长度校验 487 // 长度校验
477 if univalent >= 1e16 { 488 if univalent >= 1e16 {
478 tmpRow := &domain.FailInfo{ 489 tmpRow := &domain.FailInfo{
479 - FailReason: "第" + r + "行产品价格超过最大限制,产品价格小数点前面不能超过十六位数字,并保留两位小数", 490 + FailReason: "产品价格超过最大限制,产品价格小数点前面不能超过十六位数字,并保留两位小数",
480 } 491 }
481 tmpRow.ImportDividendsOrderData = &dividendsOrder 492 tmpRow.ImportDividendsOrderData = &dividendsOrder
482 - // 错误行数据  
483 myRow = append(myRow, tmpRow) 493 myRow = append(myRow, tmpRow)
  494 + continue
484 } 495 }
485 } 496 }
486 case 7: // 费用校验 497 case 7: // 费用校验
@@ -490,28 +501,30 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -490,28 +501,30 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
490 univalent, typeErr := strconv.ParseFloat(fmt.Sprintf("%v", v.Field(k).Interface()), 64) 501 univalent, typeErr := strconv.ParseFloat(fmt.Sprintf("%v", v.Field(k).Interface()), 64)
491 if typeErr != nil { 502 if typeErr != nil {
492 tmpRow := &domain.FailInfo{ 503 tmpRow := &domain.FailInfo{
493 - FailReason: "第" + r + "行费用格式错误,费用必须为数字类型", 504 + FailReason: "费用格式错误,费用必须为数字类型",
494 } 505 }
495 tmpRow.ImportDividendsOrderData = &dividendsOrder 506 tmpRow.ImportDividendsOrderData = &dividendsOrder
496 myRow = append(myRow, tmpRow) 507 myRow = append(myRow, tmpRow)
497 log.Logger.Info("费用类型错误", map[string]interface{}{ 508 log.Logger.Info("费用类型错误", map[string]interface{}{
498 "tmpRow": tmpRow, 509 "tmpRow": tmpRow,
499 }) 510 })
  511 + continue
500 } 512 }
501 // 长度校验 513 // 长度校验
502 if univalent >= 1e16 { 514 if univalent >= 1e16 {
503 tmpRow := &domain.FailInfo{ 515 tmpRow := &domain.FailInfo{
504 - FailReason: "第" + r + "行费用超过最大限制,费用小数点前面不能超过十六位数字,并保留两位小数", 516 + FailReason: "费用超过最大限制,费用小数点前面不能超过十六位数字,并保留两位小数",
505 } 517 }
506 tmpRow.ImportDividendsOrderData = &dividendsOrder 518 tmpRow.ImportDividendsOrderData = &dividendsOrder
507 myRow = append(myRow, tmpRow) 519 myRow = append(myRow, tmpRow)
  520 + continue
508 } 521 }
509 } 522 }
510 } 523 }
511 } 524 }
512 } 525 }
513 - if myRow != nil {  
514 - typeError = append(typeError, myRow) 526 + if len(myRow) > 0 {
  527 + typeError = append(typeError, myRow...)
515 } 528 }
516 } 529 }
517 530
@@ -525,11 +538,15 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -525,11 +538,15 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
525 }, 538 },
526 }, nil 539 }, nil
527 } 540 }
  541 + /******************************************************************************************************************/
528 542
529 - // 聚合订单并进行类型校验 543 + /******************************************** 4.聚合订单并进行类型校验 ************************************************/
  544 + // 订单聚合错误
530 aggregateErrorList := make([]interface{}, 0) 545 aggregateErrorList := make([]interface{}, 0)
531 546
  547 + // 新增订单命令集
532 var dividendsOrderCommands = make(map[string]*command.CreateDividendsOrderCommand) 548 var dividendsOrderCommands = make(map[string]*command.CreateDividendsOrderCommand)
  549 +
533 for i, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData { 550 for i, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData {
534 hashValue := md5.Sum([]byte(dividendsOrder.OriginalOrderNum)) 551 hashValue := md5.Sum([]byte(dividendsOrder.OriginalOrderNum))
535 hashString := hex.EncodeToString(hashValue[:]) 552 hashString := hex.EncodeToString(hashValue[:])
@@ -542,22 +559,37 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -542,22 +559,37 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
542 } 559 }
543 tmpRow.ImportDividendsOrderData = &dividendsOrder 560 tmpRow.ImportDividendsOrderData = &dividendsOrder
544 aggregateErrorList = append(aggregateErrorList, tmpRow) 561 aggregateErrorList = append(aggregateErrorList, tmpRow)
545 - break 562 + continue
546 } 563 }
547 564
548 // 产品相关:产品名称,产品数量、产品价格、费用 565 // 产品相关:产品名称,产品数量、产品价格、费用
549 quantity, err := strconv.ParseFloat(dividendsOrder.OrderGoodQuantity, 64) 566 quantity, err := strconv.ParseFloat(dividendsOrder.OrderGoodQuantity, 64)
550 if err != nil { 567 if err != nil {
551 - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 568 + tmpRow := &domain.FailInfo{
  569 + FailReason: "产品数量类型错误",
  570 + }
  571 + tmpRow.ImportDividendsOrderData = &dividendsOrder
  572 + aggregateErrorList = append(aggregateErrorList, tmpRow)
  573 + continue
552 } 574 }
553 price, err := strconv.ParseFloat(dividendsOrder.OrderGoodPrice, 64) 575 price, err := strconv.ParseFloat(dividendsOrder.OrderGoodPrice, 64)
554 if err != nil { 576 if err != nil {
555 - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 577 + tmpRow := &domain.FailInfo{
  578 + FailReason: "产品价格类型错误",
  579 + }
  580 + tmpRow.ImportDividendsOrderData = &dividendsOrder
  581 + aggregateErrorList = append(aggregateErrorList, tmpRow)
  582 + continue
556 } 583 }
557 var expense float64 584 var expense float64
558 if dividendsOrder.Expense != "" { 585 if dividendsOrder.Expense != "" {
559 if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil { 586 if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil {
560 - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 587 + tmpRow := &domain.FailInfo{
  588 + FailReason: "费用类型错误",
  589 + }
  590 + tmpRow.ImportDividendsOrderData = &dividendsOrder
  591 + aggregateErrorList = append(aggregateErrorList, tmpRow)
  592 + continue
561 } else { 593 } else {
562 expense = expenseParse 594 expense = expenseParse
563 } 595 }
@@ -581,6 +613,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -581,6 +613,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
581 DividendsOrderNumber: "", 613 DividendsOrderNumber: "",
582 CooperationContractNumber: dividendsOrder.CooperationContractNumber, 614 CooperationContractNumber: dividendsOrder.CooperationContractNumber,
583 OrderGoodExpense: expense, 615 OrderGoodExpense: expense,
  616 + LineNumber: i,
584 }, 617 },
585 }, 618 },
586 CompanyId: importDividendsOrderCommand.CompanyId, 619 CompanyId: importDividendsOrderCommand.CompanyId,
@@ -593,16 +626,31 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -593,16 +626,31 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
593 // 产品相关:产品名称,产品数量、产品价格、费用 626 // 产品相关:产品名称,产品数量、产品价格、费用
594 quantity, err := strconv.ParseFloat(dividendsOrder.OrderGoodQuantity, 64) 627 quantity, err := strconv.ParseFloat(dividendsOrder.OrderGoodQuantity, 64)
595 if err != nil { 628 if err != nil {
596 - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 629 + tmpRow := &domain.FailInfo{
  630 + FailReason: "产品数量类型错误",
  631 + }
  632 + tmpRow.ImportDividendsOrderData = &dividendsOrder
  633 + aggregateErrorList = append(aggregateErrorList, tmpRow)
  634 + continue
597 } 635 }
598 price, err := strconv.ParseFloat(dividendsOrder.OrderGoodPrice, 64) 636 price, err := strconv.ParseFloat(dividendsOrder.OrderGoodPrice, 64)
599 if err != nil { 637 if err != nil {
600 - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 638 + tmpRow := &domain.FailInfo{
  639 + FailReason: "产品价格类型错误",
  640 + }
  641 + tmpRow.ImportDividendsOrderData = &dividendsOrder
  642 + aggregateErrorList = append(aggregateErrorList, tmpRow)
  643 + continue
601 } 644 }
602 var expense float64 645 var expense float64
603 if dividendsOrder.Expense != "" { 646 if dividendsOrder.Expense != "" {
604 if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil { 647 if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil {
605 - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 648 + tmpRow := &domain.FailInfo{
  649 + FailReason: "费用类型错误",
  650 + }
  651 + tmpRow.ImportDividendsOrderData = &dividendsOrder
  652 + aggregateErrorList = append(aggregateErrorList, tmpRow)
  653 + continue
606 } else { 654 } else {
607 expense = expenseParse 655 expense = expenseParse
608 } 656 }
@@ -617,6 +665,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -617,6 +665,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
617 DividendsOrderNumber: "", 665 DividendsOrderNumber: "",
618 CooperationContractNumber: dividendsOrder.CooperationContractNumber, 666 CooperationContractNumber: dividendsOrder.CooperationContractNumber,
619 OrderGoodExpense: expense, 667 OrderGoodExpense: expense,
  668 + LineNumber: i, // 记录订单产品行号
620 }) 669 })
621 670
622 // 记录聚合行号 671 // 记录聚合行号
@@ -624,6 +673,10 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -624,6 +673,10 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
624 } 673 }
625 } 674 }
626 675
  676 + log.Logger.Info("聚合订单", map[string]interface{}{
  677 + "dividendsOrderCommands": dividendsOrderCommands,
  678 + })
  679 +
627 // 聚合订单错误返回 680 // 聚合订单错误返回
628 if len(aggregateErrorList) > 0 { 681 if len(aggregateErrorList) > 0 {
629 return map[string]interface{}{ 682 return map[string]interface{}{
@@ -634,22 +687,20 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -634,22 +687,20 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
634 }, 687 },
635 }, nil 688 }, nil
636 } 689 }
  690 + /******************************************************************************************************************/
  691 +
  692 + // 错误数据返回
  693 + errorDataList := make([]*domain.ImportInfo, 0)
637 694
638 - // 批量创建分红订单命令集 695 + /******************************************** 批量创建分红订单命令集 **************************************************/
639 var createDividendsOrderCommands []*command.CreateDividendsOrderCommand 696 var createDividendsOrderCommands []*command.CreateDividendsOrderCommand
640 for _, dividendsOrderCommand := range dividendsOrderCommands { 697 for _, dividendsOrderCommand := range dividendsOrderCommands {
641 createDividendsOrderCommands = append(createDividendsOrderCommands, dividendsOrderCommand) 698 createDividendsOrderCommands = append(createDividendsOrderCommands, dividendsOrderCommand)
642 } 699 }
643 700
644 - // 新增失败记录  
645 - failureDataList := make([]interface{}, 0)  
646 -  
647 // 新增成功记录计数 701 // 新增成功记录计数
648 var successDataCount int64 702 var successDataCount int64
649 703
650 - // 错误数据返回  
651 - var errorDataList []*domain.ImportInfo  
652 -  
653 // 循环校验命令 704 // 循环校验命令
654 for _, cmd := range createDividendsOrderCommands { 705 for _, cmd := range createDividendsOrderCommands {
655 if err = cmd.ValidateCommand(); err != nil { 706 if err = cmd.ValidateCommand(); err != nil {
@@ -657,13 +708,16 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -657,13 +708,16 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
657 row := &domain.ImportInfo{ 708 row := &domain.ImportInfo{
658 Error: application.ThrowError(application.BUSINESS_ERROR, err.Error()), // 错误信息 709 Error: application.ThrowError(application.BUSINESS_ERROR, err.Error()), // 错误信息
659 LineNumbers: cmd.LineNumbers, // 错误影响的行 710 LineNumbers: cmd.LineNumbers, // 错误影响的行
660 - GoodLine: map[int]interface{}{}, 711 + GoodLine: map[int]string{},
661 } 712 }
662 errorDataList = append(errorDataList, row) 713 errorDataList = append(errorDataList, row)
663 continue 714 continue
664 } 715 }
665 } 716 }
666 717
  718 + // 新增失败记录
  719 + failureDataList := make([]interface{}, 0)
  720 +
667 // 循环校验命令失败返回 721 // 循环校验命令失败返回
668 if len(errorDataList) > 0 { 722 if len(errorDataList) > 0 {
669 successDataCount = 0 723 successDataCount = 0
@@ -695,8 +749,9 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -695,8 +749,9 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
695 }, 749 },
696 }, nil 750 }, nil
697 } 751 }
  752 + /******************************************************************************************************************/
698 753
699 - // 创建分红订单领域模型 754 + /********************************************** 创建分红订单领域模型 *************************************************/
700 var creatDividendsOrder []*domain.DividendsOrder 755 var creatDividendsOrder []*domain.DividendsOrder
701 756
702 // 统计当前分红订单数 757 // 统计当前分红订单数
@@ -710,7 +765,13 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -710,7 +765,13 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
710 // 生成分红订单号 765 // 生成分红订单号
711 dividendsOrderNumber, err := dividendsOrder.GenerateSpecificDividendsOrderNumber(int64(count), time.Time{}, int64(i)) 766 dividendsOrderNumber, err := dividendsOrder.GenerateSpecificDividendsOrderNumber(int64(count), time.Time{}, int64(i))
712 if err != nil { 767 if err != nil {
713 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 768 + row := &domain.ImportInfo{
  769 + Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单号生成错误:%s", err)),
  770 + LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
  771 + GoodLine: map[int]string{},
  772 + }
  773 + errorDataList = append(errorDataList, row)
  774 + continue
714 } 775 }
715 776
716 // 订单时间转换 777 // 订单时间转换
@@ -719,18 +780,19 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -719,18 +780,19 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
719 row := &domain.ImportInfo{ 780 row := &domain.ImportInfo{
720 Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("订单日期转换错误:%s", err)), 781 Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("订单日期转换错误:%s", err)),
721 LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行 782 LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
722 - GoodLine: map[int]interface{}{}, 783 + GoodLine: map[int]string{},
723 } 784 }
724 errorDataList = append(errorDataList, row) 785 errorDataList = append(errorDataList, row)
725 continue 786 continue
726 } 787 }
  788 +
727 orderTime := utils.TransformTimestampToTime(orderTimeInt) 789 orderTime := utils.TransformTimestampToTime(orderTimeInt)
728 790
729 // 新增订单产品 791 // 新增订单产品
730 var orderGoods []*domain.OrderGood 792 var orderGoods []*domain.OrderGood
731 var dividendsOrderAmount float64 793 var dividendsOrderAmount float64
732 - orderGoodErrMap := make(map[int]interface{}, 0)  
733 - for i, orderGood := range dividendsOrder.OrderGoods { 794 + orderGoodErrMap := make(map[int]string, 0)
  795 + for j, orderGood := range dividendsOrder.OrderGoods {
734 // 校验共创合约是否合法 796 // 校验共创合约是否合法
735 contractNumberExist := false 797 contractNumberExist := false
736 for _, cooperationContract := range cooperationContracts { 798 for _, cooperationContract := range cooperationContracts {
@@ -740,18 +802,24 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -740,18 +802,24 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
740 } 802 }
741 } 803 }
742 if !contractNumberExist { 804 if !contractNumberExist {
743 - orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("共创合约编号不存在:%s", err)) 805 + orderGoodErrMap[dividendsOrder.OrderGoods[j].LineNumber] = "订单产品关联的共创合约不存在"
  806 + continue
744 } 807 }
745 808
746 // 计算产品金额 809 // 计算产品金额
747 orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)).Float64() 810 orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)).Float64()
748 811
749 - // 校验共创合约激励类型是否正确  
750 ruleMatchedFlag := false 812 ruleMatchedFlag := false
751 if orderGood.CooperationContractNumber != "" { 813 if orderGood.CooperationContractNumber != "" {
  814 + // 校验共创合约激励类型是否正确
  815 + log.Logger.Info("订单产品匹配的合约", map[string]interface{}{
  816 + "contractMatched": cooperationContractsMap[orderGood.CooperationContractNumber],
  817 + })
752 if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 { 818 if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
753 - orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则") 819 + orderGoodErrMap[dividendsOrder.OrderGoods[j].LineNumber] = "分红订单不能关联金额激励规则"
  820 + continue
754 } 821 }
  822 +
755 // 校验产品关联合约的激励规则是否匹配订单时间 823 // 校验产品关联合约的激励规则是否匹配订单时间
756 if cooperationContractsMap[orderGood.CooperationContractNumber] != nil { 824 if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
757 for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules { 825 for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
@@ -763,7 +831,8 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -763,7 +831,8 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
763 } 831 }
764 } 832 }
765 if !ruleMatchedFlag { 833 if !ruleMatchedFlag {
766 - orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间无法匹配分红激励规则,请重新选择") 834 + orderGoodErrMap[dividendsOrder.OrderGoods[j].LineNumber] = "订单时间无法匹配分红激励规则"
  835 + continue
767 } 836 }
768 } 837 }
769 838
@@ -787,9 +856,13 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -787,9 +856,13 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
787 // 计算分红订单金额 856 // 计算分红订单金额
788 dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)))).Float64() 857 dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)))).Float64()
789 } 858 }
  859 +
790 if len(orderGoodErrMap) > 0 { 860 if len(orderGoodErrMap) > 0 {
  861 + log.Logger.Info("校验订单产品", map[string]interface{}{
  862 + "orderGoodErrMap": orderGoodErrMap,
  863 + })
791 row := &domain.ImportInfo{ 864 row := &domain.ImportInfo{
792 - Error: application.ThrowError(application.BUSINESS_ERROR, "共创合约不存在"), 865 + Error: nil,
793 LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行 866 LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
794 GoodLine: orderGoodErrMap, // 错误产品行号记录 867 GoodLine: orderGoodErrMap, // 错误产品行号记录
795 } 868 }
@@ -823,8 +896,9 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -823,8 +896,9 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
823 896
824 creatDividendsOrder = append(creatDividendsOrder, newDividendsOrder) 897 creatDividendsOrder = append(creatDividendsOrder, newDividendsOrder)
825 } 898 }
  899 + /******************************************************************************************************************/
826 900
827 - // 错误报告处理 901 + /*********************************************** 错误报告处理 *******************************************************/
828 if len(errorDataList) <= 0 { // 成功返回 902 if len(errorDataList) <= 0 { // 成功返回
829 if _, err2 := dividendsOrderRepository.SaveMany(creatDividendsOrder); err2 != nil { 903 if _, err2 := dividendsOrderRepository.SaveMany(creatDividendsOrder); err2 != nil {
830 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error()) 904 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
@@ -836,7 +910,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -836,7 +910,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
836 if successDataCount == int64(rowCnt) { 910 if successDataCount == int64(rowCnt) {
837 return map[string]interface{}{ 911 return map[string]interface{}{
838 "successCount": successDataCount, 912 "successCount": successDataCount,
839 - "fail": map[string]interface{}{}, 913 + "fail": make(map[string]interface{}),
840 }, nil 914 }, nil
841 } 915 }
842 } else { // 失败返回 916 } else { // 失败返回
@@ -846,7 +920,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -846,7 +920,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
846 if len(errorData.GoodLine) == 0 { // 订单错误 920 if len(errorData.GoodLine) == 0 { // 订单错误
847 for _, line := range errorData.LineNumbers { 921 for _, line := range errorData.LineNumbers {
848 tmpRow := &domain.FailInfo{ 922 tmpRow := &domain.FailInfo{
849 - FailReason: "订单数据新增错误:" + errorData.Error.Error(), 923 + FailReason: errorData.Error.Error(),
850 } 924 }
851 tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[line] 925 tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[line]
852 failureDataList = append(failureDataList, tmpRow) 926 failureDataList = append(failureDataList, tmpRow)
@@ -854,7 +928,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -854,7 +928,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
854 } else if len(errorData.GoodLine) > 0 { // 订单产品错误 928 } else if len(errorData.GoodLine) > 0 { // 订单产品错误
855 for line := range errorData.GoodLine { 929 for line := range errorData.GoodLine {
856 tmpRow := &domain.FailInfo{ 930 tmpRow := &domain.FailInfo{
857 - FailReason: "订单数据新增错误:" + errorData.Error.Error(), 931 + FailReason: errorData.GoodLine[line],
858 } 932 }
859 tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[line] 933 tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[line]
860 failureDataList = append(failureDataList, tmpRow) 934 failureDataList = append(failureDataList, tmpRow)
@@ -1048,6 +1122,8 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba @@ -1048,6 +1122,8 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
1048 } 1122 }
1049 } 1123 }
1050 1124
  1125 + // TODO 校验分红订单是否有分红预算
  1126 +
1051 dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders) 1127 dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders)
1052 if err != nil { 1128 if err != nil {
1053 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1129 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -707,7 +707,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -707,7 +707,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
707 row := &domain.ImportInfo{ 707 row := &domain.ImportInfo{
708 Error: application.ThrowError(application.BUSINESS_ERROR, err.Error()), // 错误信息 708 Error: application.ThrowError(application.BUSINESS_ERROR, err.Error()), // 错误信息
709 LineNumbers: cmd.LineNumbers, // 错误影响的行 709 LineNumbers: cmd.LineNumbers, // 错误影响的行
710 - GoodLine: map[int]interface{}{}, 710 + GoodLine: map[int]string{},
711 } 711 }
712 errorDataList = append(errorDataList, row) 712 errorDataList = append(errorDataList, row)
713 continue 713 continue
@@ -862,7 +862,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -862,7 +862,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
862 row := &domain.ImportInfo{ 862 row := &domain.ImportInfo{
863 Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存退货单数据失败:%s", err)), 863 Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存退货单数据失败:%s", err)),
864 LineNumbers: dividendsReturnedOrder.LineNumbers, // 错误影响的行 864 LineNumbers: dividendsReturnedOrder.LineNumbers, // 错误影响的行
865 - GoodLine: map[int]interface{}{}, 865 + GoodLine: map[int]string{},
866 } 866 }
867 errorDataList = append(errorDataList, row) 867 errorDataList = append(errorDataList, row)
868 continue 868 continue
@@ -53,9 +53,9 @@ type DividendsOrder struct { @@ -53,9 +53,9 @@ type DividendsOrder struct {
53 53
54 // ImportInfo 导入错误信息 54 // ImportInfo 导入错误信息
55 type ImportInfo struct { 55 type ImportInfo struct {
56 - Error error `json:"error"`  
57 - LineNumbers []int `json:"lineNumbers"`  
58 - GoodLine map[int]interface{} `json:"goodLine"` 56 + Error error `json:"error"`
  57 + LineNumbers []int `json:"lineNumbers"`
  58 + GoodLine map[int]string `json:"goodLine"`
59 } 59 }
60 60
61 // FailInfo 返回的失败信息 61 // FailInfo 返回的失败信息
@@ -31,7 +31,7 @@ type OrderGood struct { @@ -31,7 +31,7 @@ type OrderGood struct {
31 // 创建时间 31 // 创建时间
32 CreatedAt time.Time `comment:"创建时间"` 32 CreatedAt time.Time `comment:"创建时间"`
33 // 删除时间 33 // 删除时间
34 - DeletedAt time.Time `comment:"删除时间"` 34 + DeletedAt time.Time `comment:"删除时间" pg:",soft_delete"`
35 // 更新时间 35 // 更新时间
36 UpdatedAt time.Time `comment:"更新时间"` 36 UpdatedAt time.Time `comment:"更新时间"`
37 } 37 }