print.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. return nil, nil
  68. // type RegCode struct {
  69. // Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  70. // Roles *[]string `bson:"roles,omitempty" json:"roles"`
  71. // Key string `bson:"key,omitempty" json:"key"`
  72. // }
  73. // roles := []string{}
  74. // ?接收客户端传参数,更新
  75. // {"_id":"642e2e97243b5c5107d70204","roles":false}
  76. // form := RegCode{}
  77. // err := c.ShouldBindJSON(&form)
  78. // if err != nil {
  79. // return nil, err
  80. // }
  81. // return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), "reg-code", form.Id.Hex(), &RegCode{Roles: form.Roles})
  82. // return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), "reg-code", "642e2e97243b5c5107d70204", &RegCode{Roles: &roles})
  83. }
  84. func RemovePlanSyncBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  85. plans := []*model.ProductPlan{}
  86. err := repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  87. CollectName: repo.CollectionProductPlan,
  88. Project: []string{"_id"},
  89. }, &plans)
  90. if err != nil {
  91. return nil, err
  92. }
  93. planIds := make([]primitive.ObjectID, 0)
  94. for _, plan := range plans {
  95. fmt.Println(plan.Id.Hex())
  96. planIds = append(planIds, plan.Id)
  97. }
  98. // Purchases := []*model.PurchaseBill{}
  99. // repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  100. // CollectName: repo.CollectionBillPurchase,
  101. // Query: repo.Map{"planId": bson.M{"$nin": planIds}},
  102. // Project: []string{"planId"},
  103. // }, &Purchases)
  104. produces := []*model.ProduceBill{}
  105. repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  106. CollectName: repo.CollectionBillProduce,
  107. Query: repo.Map{"planId": bson.M{"$nin": planIds}},
  108. Project: []string{"planId", "serialNumber"},
  109. }, &produces)
  110. // products := []*model.ProductBill{}
  111. // repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  112. // CollectName: repo.CollectionBillProduct,
  113. // Query: repo.Map{"planId": bson.M{"$nin": planIds}},
  114. // Project: []string{"planId"},
  115. // }, &products)
  116. // repo.RepoDeleteDocs(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, repo.Map{"planId": bson.M{"$nin": planIds}})
  117. // repo.RepoDeleteDocs(apictx.CreateRepoCtx(), repo.CollectionBillProduce, repo.Map{"planId": bson.M{"$nin": planIds}})
  118. // repo.RepoDeleteDocs(apictx.CreateRepoCtx(), repo.CollectionBillProduct, repo.Map{"planId": bson.M{"$nin": planIds}})
  119. return produces, nil
  120. }