print.go 4.8 KB

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