animeic 2 年之前
父節點
當前提交
f8949a1930
共有 1 個文件被更改,包括 70 次插入55 次删除
  1. 70 55
      boxcost/api/supplier.go

+ 70 - 55
boxcost/api/supplier.go

@@ -11,7 +11,6 @@ import (
 	"github.com/gin-gonic/gin"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson/primitive"
-	"go.mongodb.org/mongo-driver/mongo/options"
 )
 
 // 供应商管理
@@ -170,63 +169,79 @@ func GetPlanSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 
 	if query["craftId"] != nil {
-		cratf := &model.Craft{}
-
-		ok, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-			Query:       repo.Map{"_id": query["craftId"].(string)},
-			CollectName: repo.CollectionCraft,
-		}, cratf)
-
-		if !ok {
-			return nil, fmt.Errorf("没有对应的工艺信息")
-		}
-
-		//查询工艺分类
-		pipleLine := []bson.M{
-			{
-				"$lookup": bson.M{
-					"from":         repo.CollectionCraft,
-					"localField":   "productId",
-					"foreignField": "_id",
-					"as":           "craft_docs",
-				},
-			},
-			{
-				"$match": bson.M{
-					"craft_docs.0.category": cratf.Category,
-				},
-			},
-			{
-				"$project": bson.M{
-					"craft_docs": 0,
-					"createTime": 0,
-					"price":      0,
-					"productId":  0,
-					"updateTime": 0,
-				},
-			},
+		// cratf := &model.Craft{}
+
+		// ok, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		// 	Query:       repo.Map{"_id": query["craftId"].(string)},
+		// 	CollectName: repo.CollectionCraft,
+		// }, cratf)
+
+		// if !ok {
+		// 	return nil, fmt.Errorf("没有对应的工艺信息")
+		// }
+
+		// //查询工艺分类
+		// pipleLine := []bson.M{
+		// 	{
+		// 		"$lookup": bson.M{
+		// 			"from":         repo.CollectionCraft,
+		// 			"localField":   "productId",
+		// 			"foreignField": "_id",
+		// 			"as":           "craft_docs",
+		// 		},
+		// 	},
+		// 	{
+		// 		"$match": bson.M{
+		// 			"craft_docs.0.category": cratf.Category,
+		// 		},
+		// 	},
+		// 	{
+		// 		"$project": bson.M{
+		// 			"craft_docs": 0,
+		// 			"createTime": 0,
+		// 			"price":      0,
+		// 			"productId":  0,
+		// 			"updateTime": 0,
+		// 		},
+		// 	},
+		// }
+		// ctx := apictx.CreateRepoCtx()
+
+		// colls := ctx.Client.GetCollection(repo.CollectionSupplierCraftprice)
+
+		// findoptions := &options.AggregateOptions{}
+
+		// cur, err := colls.Aggregate(ctx.Ctx, pipleLine, findoptions)
+		// if err != nil {
+		// 	return nil, err
+		// }
+
+		// defer cur.Close(ctx.Ctx)
+
+		// err = cur.All(ctx.Ctx, &listOut)
+
+		// if err != nil {
+		// 	return nil, err
+		// }
+		// if len(listOut) < 1 {
+		// 	return emtyPage, nil
+		// }
+		// return listOut, nil
+		cratfId := query["cratfId"].(string)
+		if len(cratfId) < 1 {
+			return nil, fmt.Errorf("cratfId(string)为空")
 		}
-		ctx := apictx.CreateRepoCtx()
-
-		colls := ctx.Client.GetCollection(repo.CollectionSupplierCraftprice)
-
-		findoptions := &options.AggregateOptions{}
-
-		cur, err := colls.Aggregate(ctx.Ctx, pipleLine, findoptions)
-		if err != nil {
-			return nil, err
-		}
-
-		defer cur.Close(ctx.Ctx)
-
-		err = cur.All(ctx.Ctx, &listOut)
-
-		if err != nil {
-			return nil, err
-		}
-		if len(listOut) < 1 {
+		id, _ := primitive.ObjectIDFromHex(cratfId)
+		ok, list := repo.RepoSeachDocsMap(apictx.CreateRepoCtx(), &repo.DocsSearchOptions{
+			CollectName: repo.CollectionSupplierCraftprice,
+			Query:       repo.Map{"cratfId": id},
+			Project:     []string{"supplierId"},
+		})
+		if !ok {
 			return emtyPage, nil
 		}
+
+		listOut = list
 	}
 
 	if query["productId"] != nil {