animeic 1 year ago
parent
commit
bc66457afa
3 changed files with 47 additions and 4 deletions
  1. 1 4
      boxcost/api/plan.go
  2. 45 0
      boxcost/api/print.go
  3. 1 0
      boxcost/api/router.go

+ 1 - 4
boxcost/api/plan.go

@@ -1162,9 +1162,7 @@ func UpdateProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error)
 
 // 删除生产计划
 func DelProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	if apictx.User == nil {
-		return nil, errors.New("用户错误,请重新登录")
-	}
+
 	userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
 	if userId.IsZero() {
 		return nil, errors.New("用户错误,请重新登录")
@@ -1187,7 +1185,6 @@ func DelProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	// 删除计划对应订单
 	if err == nil {
-
 		// 获取所有stages单据id
 		billIds := make([]string, 0)
 		for _, comp := range plan.Pack.Components {

+ 45 - 0
boxcost/api/print.go

@@ -1,9 +1,12 @@
 package api
 
 import (
+	"box-cost/db/model"
 	"box-cost/db/repo"
+	"fmt"
 
 	"github.com/gin-gonic/gin"
+	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
@@ -91,3 +94,45 @@ func Printr(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), "reg-code", "642e2e97243b5c5107d70204", &RegCode{Roles: &roles})
 
 }
+
+func RemovePlanSyncBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	plans := []*model.ProductPlan{}
+	err := repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+		CollectName: repo.CollectionProductPlan,
+		Project:     []string{"_id"},
+	}, &plans)
+	if err != nil {
+		return nil, err
+	}
+
+	planIds := make([]primitive.ObjectID, 0)
+	for _, plan := range plans {
+		fmt.Println(plan.Id.Hex())
+		planIds = append(planIds, plan.Id)
+	}
+	// Purchases := []*model.PurchaseBill{}
+	// repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+	// 	CollectName: repo.CollectionBillPurchase,
+	// 	Query:       repo.Map{"planId": bson.M{"$nin": planIds}},
+	// 	Project:     []string{"planId"},
+	// }, &Purchases)
+
+	produces := []*model.ProduceBill{}
+	repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+		CollectName: repo.CollectionBillProduce,
+		Query:       repo.Map{"planId": bson.M{"$nin": planIds}},
+		Project:     []string{"planId", "serialNumber"},
+	}, &produces)
+	// products := []*model.ProductBill{}
+	// repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+	// 	CollectName: repo.CollectionBillProduct,
+	// 	Query:       repo.Map{"planId": bson.M{"$nin": planIds}},
+	// 	Project:     []string{"planId"},
+	// }, &products)
+
+	// repo.RepoDeleteDocs(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, repo.Map{"planId": bson.M{"$nin": planIds}})
+	// repo.RepoDeleteDocs(apictx.CreateRepoCtx(), repo.CollectionBillProduce, repo.Map{"planId": bson.M{"$nin": planIds}})
+	// repo.RepoDeleteDocs(apictx.CreateRepoCtx(), repo.CollectionBillProduct, repo.Map{"planId": bson.M{"$nin": planIds}})
+
+	return produces, nil
+}

+ 1 - 0
boxcost/api/router.go

@@ -16,6 +16,7 @@ func RegRouters(svc *Service) {
 	//数据存储
 	boxcost.POST("/save/policy", ServiceObsUploadPolicy)
 	boxcost.GET("/printr", Printr)
+	boxcost.GET("/removeSyncBill", RemovePlanSyncBill)
 	boxcost.GET("/callback", callback)
 
 	// 材料管理