sun-pc-linux vor 7 Monaten
Ursprung
Commit
65de74e2b0
5 geänderte Dateien mit 180 neuen und 143 gelöschten Zeilen
  1. 43 35
      boxcost/api/bill-produce.go
  2. 33 53
      boxcost/api/bill-product.go
  3. 37 53
      boxcost/api/bill.go
  4. 64 0
      boxcost/api/plan.go
  5. 3 2
      boxcost/db/model/plan-track.go

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

@@ -6,6 +6,8 @@ import (
 	"box-cost/log"
 	"errors"
 	"fmt"
+	"strconv"
+	"strings"
 	"time"
 
 	"github.com/gin-gonic/gin"
@@ -228,49 +230,55 @@ func UpdateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 		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 {
-		idCounts := map[string]int{}
+		// 获取当前订单供应商id
+		// 对比供应商是否变化,变化了就同步计划中的供应商
+		currProduce := &model.ProduceBill{}
+		repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+			CollectName: repo.CollectionBillProduce,
+			Query:       repo.Map{"_id": bill.Id},
+			Project:     []string{"supplierId"},
+		}, currProduce)
+		var supplierInfo *model.Supplier
+		if currProduce.SupplierId != bill.SupplierId {
+			// 查询更改后的supplierInfo
+			supplierInfo = &model.Supplier{}
+			repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+				CollectName: repo.CollectionSupplier,
+			}, supplierInfo)
+		}
+		idStatges := make(map[string]*UpdateBilltoStageReq)
 		for _, produce := range bill.Produces {
 			if len(produce.Id) == 0 {
 				continue
 			}
-			// 对比提交数量不一致时
-			if v, ok := currConfirmCountMap[produce.Id]; ok {
-				if v != produce.ConfirmCount {
-					isSyncConfirm = true
-					idCounts[produce.Id] = produce.ConfirmCount
-				}
+			ps := strings.Split(produce.PrintSize, "*")
+			width := 0
+			height := 0
+			if len(ps) == 2 {
+				height, _ = strconv.Atoi(ps[0])
+				width, _ = strconv.Atoi(ps[1])
 			}
-
-		}
-		fmt.Println("单据变化的提交数量:", idCounts)
-
-		if isSyncConfirm {
-			result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
-			if err != nil {
-				fmt.Println(err)
-				log.Error(err)
+			idStatges[produce.Id] = &UpdateBilltoStageReq{
+				BillType:     "produce",
+				SupplierInfo: supplierInfo,
+				Norm:         produce.Norm,
+				Price2:       produce.Price2,
+				OrderCount:   produce.OrderCount,
+				OrderPrice:   produce.OrderPrice,
+				ConfirmCount: produce.ConfirmCount,
+				Remark:       produce.Remark,
+				Width:        width,
+				Height:       height,
+				DeliveryTime: produce.DeliveryTime,
 			}
-			fmt.Println(result)
-
 		}
+		_, err := updateBilltoStage(c, bill.PlanId, idStatges, apictx)
+		if err != nil {
+			return nil, errors.New("该单据改动同步到产品失败")
+		}
+		fmt.Println("单据同步到产品,planId:", bill.PlanId)
 	}
 
 	bill.UpdateTime = time.Now()

+ 33 - 53
boxcost/api/bill-product.go

@@ -230,69 +230,49 @@ func UpdateProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 		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 {
-		idCounts := map[string]int{}
+		// 获取当前订单供应商id
+		// 对比供应商是否变化,变化了就同步计划中的供应商
+		currProduct := &model.ProductBill{}
+		repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+			CollectName: repo.CollectionBillProduct,
+			Query:       repo.Map{"_id": bill.Id},
+			Project:     []string{"supplierId"},
+		}, currProduct)
+		var supplierInfo *model.Supplier
+		if currProduct.SupplierId != bill.SupplierId {
+			// 查询更改后的supplierInfo
+			supplierInfo = &model.Supplier{}
+			repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+				CollectName: repo.CollectionSupplier,
+			}, supplierInfo)
+		}
+		idStatges := make(map[string]*UpdateBilltoStageReq)
 		for _, product := range bill.Products {
 			if len(product.Id) == 0 {
 				continue
 			}
-			// 对比提交数量不一致时
-			if v, ok := currConfirmCountMap[product.Id]; ok {
-				if v != product.ConfirmCount {
-					isSyncConfirm = true
-					idCounts[product.Id] = product.ConfirmCount
-				}
-			}
 
-		}
-		fmt.Println("单据变化的提交数量:", idCounts)
-
-		if isSyncConfirm {
-			result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
-			if err != nil {
-				fmt.Println(err)
-				log.Error(err)
+			idStatges[product.Id] = &UpdateBilltoStageReq{
+				BillType:     "product",
+				SupplierInfo: supplierInfo,
+				Norm:         product.Norm,
+				Size:         product.Size,
+				OrderCount:   product.OrderCount,
+				OrderPrice:   product.OrderPrice,
+				ConfirmCount: product.ConfirmCount,
+				Remark:       product.Remark,
+				DeliveryTime: product.DeliveryTime,
 			}
-			fmt.Println(result)
-
 		}
+		_, err := updateBilltoStage(c, bill.PlanId, idStatges, apictx)
+		if err != nil {
+			return nil, errors.New("该单据改动同步到产品失败")
+		}
+		fmt.Println("单据同步到产品,planId:", bill.PlanId)
 	}
 
-	// 更新供应商确定数量与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()
 	// return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduct, bill.Id.Hex(), &bill)
 	return repo.RepoUpdateSetDoc1(apictx.CreateRepoCtx(), repo.CollectionBillProduct, bill.Id.Hex(), &bill, &repo.RecordLogReq{

+ 37 - 53
boxcost/api/bill.go

@@ -6,6 +6,7 @@ import (
 	"box-cost/log"
 	"errors"
 	"fmt"
+	"strconv"
 	"time"
 
 	"github.com/gin-gonic/gin"
@@ -365,69 +366,52 @@ func UpdateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		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 {
-		idCounts := map[string]int{}
+		// 获取当前订单供应商id
+		// 对比供应商是否变化,变化了就同步计划中的供应商
+		currPurchase := &model.PurchaseBill{}
+		repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+			CollectName: repo.CollectionBillPurchase,
+			Query:       repo.Map{"_id": bill.Id},
+			Project:     []string{"supplierId"},
+		}, currPurchase)
+		var supplierInfo *model.Supplier
+		if currPurchase.SupplierId != bill.SupplierId {
+			// 查询更改后的supplierInfo
+			supplierInfo = &model.Supplier{}
+			repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+				CollectName: repo.CollectionSupplier,
+			}, supplierInfo)
+		}
+		idStatges := make(map[string]*UpdateBilltoStageReq)
 		for _, paper := range bill.Paper {
 			if len(paper.Id) == 0 {
 				continue
 			}
-			// 对比提交数量不一致时
-			if v, ok := currConfirmCountMap[paper.Id]; ok {
-				if v != paper.ConfirmCount {
-					isSyncConfirm = true
-					idCounts[paper.Id] = paper.ConfirmCount
-				}
+			width, _ := strconv.Atoi(paper.Width)
+			Height, _ := strconv.Atoi(paper.Height)
+			idStatges[paper.Id] = &UpdateBilltoStageReq{
+				BillType:     "purchase",
+				SupplierInfo: supplierInfo,
+				Norm:         paper.Norm,
+				Width:        width,
+				Height:       Height,
+				Price2:       paper.Price2,
+				OrderCount:   paper.OrderCount,
+				OrderPrice:   paper.OrderPrice,
+				Remark:       paper.Remark,
+				ConfirmCount: paper.ConfirmCount,
+				DeliveryTime: paper.DeliveryTime,
 			}
-
 		}
-		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)
-
+		_, err := updateBilltoStage(c, bill.PlanId, idStatges, apictx)
+		if err != nil {
+			return nil, errors.New("该单据改动同步到产品失败")
 		}
+		fmt.Println("单据同步到产品,planId:", bill.PlanId)
 	}
 
-	// // 更新供应商确定数量与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()
 	// return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, bill.Id.Hex(), &bill)
 	return repo.RepoUpdateSetDoc1(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, bill.Id.Hex(), &bill, &repo.RecordLogReq{

+ 64 - 0
boxcost/api/plan.go

@@ -164,6 +164,70 @@ func PlanAllocBatch(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 }
 
+type UpdateBilltoStageReq struct {
+	BillType     string
+	SupplierInfo *model.Supplier
+	Norm         string
+	Width        int
+	Height       int
+	Price2       float64
+	OrderCount   int
+	OrderPrice   float64
+	Remark       string
+	ConfirmCount int
+	DeliveryTime time.Time
+	PrintSize    string
+	Size         string
+}
+
+// 更新供应商确定数量与plan中stage项的同步
+func updateBilltoStage(c *gin.Context, planId primitive.ObjectID, idStatges map[string]*UpdateBilltoStageReq, apictx *ApiSession) (interface{}, error) {
+	if len(idStatges) == 0 {
+		return true, nil
+	}
+
+	plan := model.ProductPlan{}
+	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionProductPlan,
+		Query:       repo.Map{"_id": planId},
+	}, &plan)
+	if !found || err != nil {
+		return nil, errors.New("数据未找到")
+	}
+	for _, comp := range plan.Pack.Components {
+		if comp.Id == "" || len(comp.Stages) == 0 {
+			continue
+		}
+		for _, stage := range comp.Stages {
+
+			if idStatge, ok := idStatges[stage.Id]; ok {
+				stage.SupplierInfo = idStatge.SupplierInfo
+				stage.Norm = idStatge.Norm
+				stage.BatchSizeWidth = idStatge.Width
+				stage.BatchSizeHeight = idStatge.Height
+				stage.Price = idStatge.Price2
+				stage.OrderCount = idStatge.OrderCount
+				stage.OrderPrice = idStatge.OrderPrice
+				stage.Remark = idStatge.Remark
+				stage.ConfirmCount = idStatge.ConfirmCount
+				stage.DeliveryTime = idStatge.DeliveryTime
+				stage.Size = idStatge.Size
+				fmt.Printf("stage更新信息:\nplanId:%s\nstage:%v\n", planId, stage)
+			}
+		}
+	}
+	plan.UpdateTime = time.Now()
+	userId, _ := primitive.ObjectIDFromHex(apictx.User.ID)
+	user, _ := getUserById(apictx, userId)
+	// return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionProductPlan, planId.Hex(), &plan)
+	return repo.RepoUpdateSetDoc1(apictx.CreateRepoCtx(), repo.CollectionProductPlan, planId.Hex(), &plan, &repo.RecordLogReq{
+		Path:     c.Request.URL.Path,
+		UserInfo: user,
+		TargetId: planId.Hex(),
+		Type:     "sync",
+	})
+}
+
 // 更新供应商确定数量与plan中stage项的同步
 func updateStageCount(c *gin.Context, planId primitive.ObjectID, idCounts map[string]int, apictx *ApiSession) (interface{}, error) {
 	if len(idCounts) == 0 {

+ 3 - 2
boxcost/db/model/plan-track.go

@@ -7,8 +7,9 @@ import (
 )
 
 type PlanTrack struct {
-	Id     primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId"`
+	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	UserId     primitive.ObjectID `bson:"userId,omitempty" json:"userId"`
+	SupplierId primitive.ObjectID `bson:"supplierId,omitempty" json:"supplierId"`
 	//名字
 	Name string `bson:"name,omitempty" json:"name"`
 	//规格