|
@@ -11,6 +11,7 @@ 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"
|
|
|
)
|
|
|
|
|
|
// 供应商管理
|
|
@@ -110,6 +111,7 @@ func GetSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
return repo.RepoPageSearch(apictx.CreateRepoCtx(), option)
|
|
|
}
|
|
|
|
|
|
+// !暂时弃用
|
|
|
func GetPlanSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
page, size, query := UtilQueryPageSize(c)
|
|
|
|
|
@@ -169,79 +171,79 @@ func GetPlanSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
}
|
|
|
|
|
|
if query["craftId"] != nil {
|
|
|
- // cratf := &model.Craft{}
|
|
|
+ cratf := &model.Craft{}
|
|
|
|
|
|
- // ok, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
- // Query: repo.Map{"_id": query["craftId"].(string)},
|
|
|
- // CollectName: repo.CollectionCraft,
|
|
|
- // }, cratf)
|
|
|
+ ok, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
+ Query: repo.Map{"_id": query["craftId"].(string)},
|
|
|
+ CollectName: repo.CollectionCraft,
|
|
|
+ }, cratf)
|
|
|
|
|
|
- // if !ok {
|
|
|
- // return nil, fmt.Errorf("没有对应的工艺信息")
|
|
|
- // }
|
|
|
+ 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()
|
|
|
+ //查询工艺分类
|
|
|
+ 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)
|
|
|
+ colls := ctx.Client.GetCollection(repo.CollectionSupplierCraftprice)
|
|
|
|
|
|
- // findoptions := &options.AggregateOptions{}
|
|
|
+ findoptions := &options.AggregateOptions{}
|
|
|
|
|
|
- // cur, err := colls.Aggregate(ctx.Ctx, pipleLine, findoptions)
|
|
|
- // if err != nil {
|
|
|
- // return nil, err
|
|
|
- // }
|
|
|
+ cur, err := colls.Aggregate(ctx.Ctx, pipleLine, findoptions)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
|
|
|
- // defer cur.Close(ctx.Ctx)
|
|
|
+ defer cur.Close(ctx.Ctx)
|
|
|
|
|
|
- // err = cur.All(ctx.Ctx, &listOut)
|
|
|
+ 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)为空")
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
}
|
|
|
- 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 {
|
|
|
+ if len(listOut) < 1 {
|
|
|
return emtyPage, nil
|
|
|
}
|
|
|
+ return listOut, nil
|
|
|
+ // cratfId := query["craftId"].(string)
|
|
|
+ // if len(cratfId) < 1 {
|
|
|
+ // return nil, fmt.Errorf("cratfId(string)为空")
|
|
|
+ // }
|
|
|
+ // id, _ := primitive.ObjectIDFromHex(cratfId)
|
|
|
+ // ok, list := repo.RepoSeachDocsMap(apictx.CreateRepoCtx(), &repo.DocsSearchOptions{
|
|
|
+ // CollectName: repo.CollectionSupplierCraftprice,
|
|
|
+ // Query: repo.Map{"craftId": id},
|
|
|
+ // Project: []string{"supplierId"},
|
|
|
+ // })
|
|
|
+ // if !ok {
|
|
|
+ // return emtyPage, nil
|
|
|
+ // }
|
|
|
|
|
|
- listOut = list
|
|
|
+ // listOut = list
|
|
|
}
|
|
|
|
|
|
if query["productId"] != nil {
|