print.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package api
  2. import (
  3. "box-cost/db/model"
  4. "box-cost/db/repo"
  5. "fmt"
  6. "github.com/gin-gonic/gin"
  7. "go.mongodb.org/mongo-driver/bson"
  8. "go.mongodb.org/mongo-driver/bson/primitive"
  9. )
  10. // func UpdateIsAckStatus(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  11. // products := []*model.ProductBill{}
  12. // repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  13. // CollectName: repo.CollectionBillProduct,
  14. // Query: repo.Map{"isAck": nil},
  15. // Project: []string{"isAck"},
  16. // }, &products)
  17. // fmt.Println(len(products))
  18. // for _, product := range products {
  19. // fmt.Println(product.Id.Hex())
  20. // fmt.Println(product.IsAck)
  21. // notAck := false
  22. // repo.RepoUpdateSetDocsProps(apictx.CreateRepoCtx(), &repo.DocFilterOptions{
  23. // CollectName: repo.CollectionBillProduct,
  24. // Query: repo.Map{"isAck": nil},
  25. // }, &model.ProductBill{IsAck: &notAck})
  26. // }
  27. // return products, nil
  28. // produces := []*model.ProduceBill{}
  29. // repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  30. // CollectName: repo.CollectionBillProduce,
  31. // Query: repo.Map{"isAck": nil},
  32. // Project: []string{"isAck"},
  33. // }, &produces)
  34. // for _, produce := range produces {
  35. // fmt.Println(produce.Id.Hex())
  36. // fmt.Println(produce.IsAck)
  37. // notAck := false
  38. // repo.RepoUpdateSetDocsProps(apictx.CreateRepoCtx(), &repo.DocFilterOptions{
  39. // CollectName: repo.CollectionBillProduce,
  40. // Query: repo.Map{"isAck": nil},
  41. // }, &model.ProduceBill{IsAck: &notAck})
  42. // }
  43. // return produces, nil
  44. // purchases := []*model.PurchaseBill{}
  45. // repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  46. // CollectName: repo.CollectionBillPurchase,
  47. // Query: repo.Map{"isAck": nil},
  48. // Project: []string{"isAck"},
  49. // }, &purchases)
  50. // for _, purchase := range purchases {
  51. // fmt.Println(purchase.Id.Hex())
  52. // fmt.Println(purchase.IsAck)
  53. // notAck := false
  54. // repo.RepoUpdateSetDocsProps(apictx.CreateRepoCtx(), &repo.DocFilterOptions{
  55. // CollectName: repo.CollectionBillPurchase,
  56. // Query: repo.Map{"isAck": nil},
  57. // }, &model.PurchaseBill{IsAck: &notAck})
  58. // }
  59. // return purchases, nil
  60. // return nil, nil
  61. // }
  62. func Printr(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  63. // !如果数据模型tag omitempty存在 对某个字段设置零值的方法
  64. // !如果有omitempty存在,对应字段零值将被忽略
  65. // !该字段设置为引用类型
  66. // !创建该字段时设置默认值
  67. type RegCode struct {
  68. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  69. Roles *[]string `bson:"roles,omitempty" json:"roles"`
  70. Key string `bson:"key,omitempty" json:"key"`
  71. }
  72. roles := []string{}
  73. // ?接收客户端传参数,更新
  74. // {"_id":"642e2e97243b5c5107d70204","roles":false}
  75. // form := RegCode{}
  76. // err := c.ShouldBindJSON(&form)
  77. // if err != nil {
  78. // return nil, err
  79. // }
  80. // return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), "reg-code", form.Id.Hex(), &RegCode{Roles: form.Roles})
  81. return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), "reg-code", "642e2e97243b5c5107d70204", &RegCode{Roles: &roles})
  82. }
  83. func RemovePlanSyncBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  84. plans := []*model.ProductPlan{}
  85. err := repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  86. CollectName: repo.CollectionProductPlan,
  87. Project: []string{"_id"},
  88. }, &plans)
  89. if err != nil {
  90. return nil, err
  91. }
  92. planIds := make([]primitive.ObjectID, 0)
  93. for _, plan := range plans {
  94. fmt.Println(plan.Id.Hex())
  95. planIds = append(planIds, plan.Id)
  96. }
  97. // Purchases := []*model.PurchaseBill{}
  98. // repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  99. // CollectName: repo.CollectionBillPurchase,
  100. // Query: repo.Map{"planId": bson.M{"$nin": planIds}},
  101. // Project: []string{"planId"},
  102. // }, &Purchases)
  103. produces := []*model.ProduceBill{}
  104. repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  105. CollectName: repo.CollectionBillProduce,
  106. Query: repo.Map{"planId": bson.M{"$nin": planIds}},
  107. Project: []string{"planId", "serialNumber"},
  108. }, &produces)
  109. // products := []*model.ProductBill{}
  110. // repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  111. // CollectName: repo.CollectionBillProduct,
  112. // Query: repo.Map{"planId": bson.M{"$nin": planIds}},
  113. // Project: []string{"planId"},
  114. // }, &products)
  115. // repo.RepoDeleteDocs(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, repo.Map{"planId": bson.M{"$nin": planIds}})
  116. // repo.RepoDeleteDocs(apictx.CreateRepoCtx(), repo.CollectionBillProduce, repo.Map{"planId": bson.M{"$nin": planIds}})
  117. // repo.RepoDeleteDocs(apictx.CreateRepoCtx(), repo.CollectionBillProduct, repo.Map{"planId": bson.M{"$nin": planIds}})
  118. return produces, nil
  119. }