Explorar o código

优化提交数量变更引起的计划同步

sun-pc-linux hai 7 meses
pai
achega
8bb4ad33e2
Modificáronse 3 ficheiros con 140 adicións e 22 borrados
  1. 35 8
      boxcost/api/bill-produce.go
  2. 52 7
      boxcost/api/bill-product.go
  3. 53 7
      boxcost/api/bill.go

+ 35 - 8
boxcost/api/bill-produce.go

@@ -195,7 +195,7 @@ func UpdateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 		return nil, errors.New("id的为空")
 		return nil, errors.New("id的为空")
 	}
 	}
 
 
-	// 如果更改类型
+	// 如果更改类型 重新生成订单号
 	if len(bill.Type) > 0 {
 	if len(bill.Type) > 0 {
 		billType, err := searchBillTypeById(apictx, repo.CollectionBillProduce, bill.Id)
 		billType, err := searchBillTypeById(apictx, repo.CollectionBillProduce, bill.Id)
 		if err != nil {
 		if err != nil {
@@ -228,6 +228,22 @@ func UpdateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 		bill.SupplierRemark = " "
 		bill.SupplierRemark = " "
 	}
 	}
 
 
+	// 获取当前订单提交数
+	// 对比提交数量是否变化,变化了就同步计划中的提交数
+	currProduce := &model.ProduceBill{}
+	currConfirmCountMap := map[string]int{}
+	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionBillProduce,
+		Query:       repo.Map{"_id": bill.Id},
+		Project:     []string{"produces"},
+	}, currProduce)
+	if len(currProduce.Produces) > 0 {
+		for _, cp := range currProduce.Produces {
+			currConfirmCountMap[cp.Id] = cp.ConfirmCount
+		}
+	}
+	isSyncConfirm := false
+
 	// 更新供应商确定数量与plan中stage项的同步
 	// 更新供应商确定数量与plan中stage项的同步
 	if len(bill.Produces) > 0 {
 	if len(bill.Produces) > 0 {
 		idCounts := map[string]int{}
 		idCounts := map[string]int{}
@@ -235,15 +251,26 @@ func UpdateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 			if len(produce.Id) == 0 {
 			if len(produce.Id) == 0 {
 				continue
 				continue
 			}
 			}
-			idCounts[produce.Id] = produce.ConfirmCount
+			// 对比提交数量不一致时
+			if v, ok := currConfirmCountMap[produce.Id]; ok {
+				if v != produce.ConfirmCount {
+					isSyncConfirm = true
+					idCounts[produce.Id] = produce.ConfirmCount
+				}
+			}
+
 		}
 		}
-		fmt.Println(idCounts)
-		result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
-		if err != nil {
-			fmt.Println(err)
-			log.Error(err)
+		fmt.Println("单据变化的提交数量:", idCounts)
+
+		if isSyncConfirm {
+			result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
+			if err != nil {
+				fmt.Println(err)
+				log.Error(err)
+			}
+			fmt.Println(result)
+
 		}
 		}
-		fmt.Println(result)
 	}
 	}
 
 
 	bill.UpdateTime = time.Now()
 	bill.UpdateTime = time.Now()

+ 52 - 7
boxcost/api/bill-product.go

@@ -230,6 +230,22 @@ func UpdateProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 		bill.SupplierRemark = " "
 		bill.SupplierRemark = " "
 	}
 	}
 
 
+	// 获取当前订单提交数
+	// 对比提交数量是否变化,变化了就同步计划中的提交数
+	currProduct := &model.ProductBill{}
+	currConfirmCountMap := map[string]int{}
+	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionBillProduct,
+		Query:       repo.Map{"_id": bill.Id},
+		Project:     []string{"products"},
+	}, currProduct)
+	if len(currProduct.Products) > 0 {
+		for _, cp := range currProduct.Products {
+			currConfirmCountMap[cp.Id] = cp.ConfirmCount
+		}
+	}
+	isSyncConfirm := false
+
 	// 更新供应商确定数量与plan中stage项的同步
 	// 更新供应商确定数量与plan中stage项的同步
 	if len(bill.Products) > 0 {
 	if len(bill.Products) > 0 {
 		idCounts := map[string]int{}
 		idCounts := map[string]int{}
@@ -237,17 +253,46 @@ func UpdateProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 			if len(product.Id) == 0 {
 			if len(product.Id) == 0 {
 				continue
 				continue
 			}
 			}
-			idCounts[product.Id] = product.ConfirmCount
+			// 对比提交数量不一致时
+			if v, ok := currConfirmCountMap[product.Id]; ok {
+				if v != product.ConfirmCount {
+					isSyncConfirm = true
+					idCounts[product.Id] = product.ConfirmCount
+				}
+			}
+
 		}
 		}
-		fmt.Println(idCounts)
-		result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
-		if err != nil {
-			fmt.Println(err)
-			log.Error(err)
+		fmt.Println("单据变化的提交数量:", idCounts)
+
+		if isSyncConfirm {
+			result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
+			if err != nil {
+				fmt.Println(err)
+				log.Error(err)
+			}
+			fmt.Println(result)
+
 		}
 		}
-		fmt.Println(result)
 	}
 	}
 
 
+	// 更新供应商确定数量与plan中stage项的同步
+	// if len(bill.Products) > 0 {
+	// 	idCounts := map[string]int{}
+	// 	for _, product := range bill.Products {
+	// 		if len(product.Id) == 0 {
+	// 			continue
+	// 		}
+	// 		idCounts[product.Id] = product.ConfirmCount
+	// 	}
+	// 	fmt.Println(idCounts)
+	// 	result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
+	// 	if err != nil {
+	// 		fmt.Println(err)
+	// 		log.Error(err)
+	// 	}
+	// 	fmt.Println(result)
+	// }
+
 	bill.UpdateTime = time.Now()
 	bill.UpdateTime = time.Now()
 	// return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduct, bill.Id.Hex(), &bill)
 	// return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduct, bill.Id.Hex(), &bill)
 	return repo.RepoUpdateSetDoc1(apictx.CreateRepoCtx(), repo.CollectionBillProduct, bill.Id.Hex(), &bill, &repo.RecordLogReq{
 	return repo.RepoUpdateSetDoc1(apictx.CreateRepoCtx(), repo.CollectionBillProduct, bill.Id.Hex(), &bill, &repo.RecordLogReq{

+ 53 - 7
boxcost/api/bill.go

@@ -364,6 +364,23 @@ func UpdateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	if bill.SupplierRemark == "" {
 	if bill.SupplierRemark == "" {
 		bill.SupplierRemark = " "
 		bill.SupplierRemark = " "
 	}
 	}
+
+	// 获取当前订单提交数
+	// 对比提交数量是否变化,变化了就同步计划中的提交数
+	currPurchase := &model.PurchaseBill{}
+	currConfirmCountMap := map[string]int{}
+	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionBillPurchase,
+		Query:       repo.Map{"_id": bill.Id},
+		Project:     []string{"papers"},
+	}, currPurchase)
+	if len(currPurchase.Paper) > 0 {
+		for _, cp := range currPurchase.Paper {
+			currConfirmCountMap[cp.Id] = cp.ConfirmCount
+		}
+	}
+	isSyncConfirm := false
+
 	// 更新供应商确定数量与plan中stage项的同步
 	// 更新供应商确定数量与plan中stage项的同步
 	if len(bill.Paper) > 0 {
 	if len(bill.Paper) > 0 {
 		idCounts := map[string]int{}
 		idCounts := map[string]int{}
@@ -371,17 +388,46 @@ func UpdateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			if len(paper.Id) == 0 {
 			if len(paper.Id) == 0 {
 				continue
 				continue
 			}
 			}
-			idCounts[paper.Id] = paper.ConfirmCount
+			// 对比提交数量不一致时
+			if v, ok := currConfirmCountMap[paper.Id]; ok {
+				if v != paper.ConfirmCount {
+					isSyncConfirm = true
+					idCounts[paper.Id] = paper.ConfirmCount
+				}
+			}
+
 		}
 		}
-		fmt.Println(idCounts)
-		result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
-		if err != nil {
-			fmt.Println(err)
-			log.Error(err)
+		fmt.Println("单据变化的提交数量:", idCounts)
+
+		if isSyncConfirm {
+			result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
+			if err != nil {
+				fmt.Println(err)
+				log.Error(err)
+			}
+			fmt.Println(result)
+
 		}
 		}
-		fmt.Println(result)
 	}
 	}
 
 
+	// // 更新供应商确定数量与plan中stage项的同步
+	// if len(bill.Paper) > 0 {
+	// 	idCounts := map[string]int{}
+	// 	for _, paper := range bill.Paper {
+	// 		if len(paper.Id) == 0 {
+	// 			continue
+	// 		}
+	// 		idCounts[paper.Id] = paper.ConfirmCount
+	// 	}
+	// 	fmt.Println(idCounts)
+	// 	result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
+	// 	if err != nil {
+	// 		fmt.Println(err)
+	// 		log.Error(err)
+	// 	}
+	// 	fmt.Println(result)
+	// }
+
 	bill.UpdateTime = time.Now()
 	bill.UpdateTime = time.Now()
 	// return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, bill.Id.Hex(), &bill)
 	// return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, bill.Id.Hex(), &bill)
 	return repo.RepoUpdateSetDoc1(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, bill.Id.Hex(), &bill, &repo.RecordLogReq{
 	return repo.RepoUpdateSetDoc1(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, bill.Id.Hex(), &bill, &repo.RecordLogReq{