print.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package api
  2. import (
  3. "box-cost/db/repo"
  4. "github.com/gin-gonic/gin"
  5. "go.mongodb.org/mongo-driver/bson/primitive"
  6. )
  7. // func UpdateIsAckStatus(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  8. // products := []*model.ProductBill{}
  9. // repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  10. // CollectName: repo.CollectionBillProduct,
  11. // Query: repo.Map{"isAck": nil},
  12. // Project: []string{"isAck"},
  13. // }, &products)
  14. // fmt.Println(len(products))
  15. // for _, product := range products {
  16. // fmt.Println(product.Id.Hex())
  17. // fmt.Println(product.IsAck)
  18. // notAck := false
  19. // repo.RepoUpdateSetDocsProps(apictx.CreateRepoCtx(), &repo.DocFilterOptions{
  20. // CollectName: repo.CollectionBillProduct,
  21. // Query: repo.Map{"isAck": nil},
  22. // }, &model.ProductBill{IsAck: &notAck})
  23. // }
  24. // return products, nil
  25. // produces := []*model.ProduceBill{}
  26. // repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  27. // CollectName: repo.CollectionBillProduce,
  28. // Query: repo.Map{"isAck": nil},
  29. // Project: []string{"isAck"},
  30. // }, &produces)
  31. // for _, produce := range produces {
  32. // fmt.Println(produce.Id.Hex())
  33. // fmt.Println(produce.IsAck)
  34. // notAck := false
  35. // repo.RepoUpdateSetDocsProps(apictx.CreateRepoCtx(), &repo.DocFilterOptions{
  36. // CollectName: repo.CollectionBillProduce,
  37. // Query: repo.Map{"isAck": nil},
  38. // }, &model.ProduceBill{IsAck: &notAck})
  39. // }
  40. // return produces, nil
  41. // purchases := []*model.PurchaseBill{}
  42. // repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  43. // CollectName: repo.CollectionBillPurchase,
  44. // Query: repo.Map{"isAck": nil},
  45. // Project: []string{"isAck"},
  46. // }, &purchases)
  47. // for _, purchase := range purchases {
  48. // fmt.Println(purchase.Id.Hex())
  49. // fmt.Println(purchase.IsAck)
  50. // notAck := false
  51. // repo.RepoUpdateSetDocsProps(apictx.CreateRepoCtx(), &repo.DocFilterOptions{
  52. // CollectName: repo.CollectionBillPurchase,
  53. // Query: repo.Map{"isAck": nil},
  54. // }, &model.PurchaseBill{IsAck: &notAck})
  55. // }
  56. // return purchases, nil
  57. // return nil, nil
  58. // }
  59. func Printr(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  60. // !如果数据模型tag omitempty存在 对某个字段设置零值的方法
  61. // !如果有omitempty存在,对应字段零值将被忽略
  62. // !该字段设置为引用类型
  63. // !创建该字段时设置默认值
  64. type RegCode struct {
  65. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  66. Roles *[]string `bson:"roles,omitempty" json:"roles"`
  67. Key string `bson:"key,omitempty" json:"key"`
  68. }
  69. roles := []string{}
  70. // ?接收客户端传参数,更新
  71. // {"_id":"642e2e97243b5c5107d70204","roles":false}
  72. // form := RegCode{}
  73. // err := c.ShouldBindJSON(&form)
  74. // if err != nil {
  75. // return nil, err
  76. // }
  77. // return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), "reg-code", form.Id.Hex(), &RegCode{Roles: form.Roles})
  78. return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), "reg-code", "642e2e97243b5c5107d70204", &RegCode{Roles: &roles})
  79. }