GAAS GFrame项目web后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.6 KiB

3 years ago
3 years ago
  1. package implments
  2. import (
  3. "LAPP_GAAS_GFrame_BACKEND/conf"
  4. "LAPP_GAAS_GFrame_BACKEND/db"
  5. model "LAPP_GAAS_GFrame_BACKEND/models/cache"
  6. "LAPP_GAAS_GFrame_BACKEND/web/middleware/glog"
  7. "context"
  8. "go.mongodb.org/mongo-driver/bson"
  9. "go.mongodb.org/mongo-driver/bson/primitive"
  10. )
  11. /******************************************************************************
  12. *
  13. * @Struct Name : SchedulerCache
  14. *-----------------------------------------------------------------------------
  15. *
  16. * @Description : SchedulerCache的数据访问对象实现
  17. *
  18. * @Author : 娄文智
  19. *
  20. * @Date : 2021-05-20 14:37:20
  21. *
  22. ******************************************************************************/
  23. type SchedulerCache struct {
  24. TaskId string `bson:"taskId" json:"taskId"` //任务Id
  25. WorkLineId string `bson:"workLineId" json:"workLineId"` //产线ID
  26. Data string `bson:"data" json:"data"` //保存的数据
  27. CreateBy string `bson:"createBy" json:"createBy"` //创建人
  28. CreateTime string `bson:"createTime" json:"createTime"` //创建时间
  29. }
  30. /******************************************************************************
  31. *
  32. * @Function Name : NewSchedulerCacheDAOImplement
  33. *-----------------------------------------------------------------------------
  34. *
  35. * @Description : 创建一个SchedulerCache实例
  36. *
  37. * @Function Parameters : xorm会话
  38. *
  39. * @Function Parameters : 基本主键
  40. *
  41. * @Return Value : SchedulerCache实例
  42. *
  43. * @Author : 代码生成器创建
  44. *
  45. * @Date : 2021-05-20 14:37:20
  46. *
  47. ******************************************************************************/
  48. func NewSchedulerCacheDAOImplement() *SchedulerCache {
  49. return &SchedulerCache{}
  50. }
  51. /******************************************************************************
  52. *
  53. * @Reference LAPP_GAAS_GFrame_BACKEND/dao/om/SchedulerCache.InsertOne
  54. *
  55. ******************************************************************************/
  56. func (impl *SchedulerCache) InsertOne(entity *model.SchedulerCache) (insertID primitive.ObjectID, err error) {
  57. //1.初始化链接
  58. client := db.MgoDb()
  59. //2.选择数据库,数据表
  60. collect := client.Database(conf.DbConfig.Mongdbname).Collection("SchedulerCache")
  61. insertRest, err := collect.InsertOne(context.TODO(), entity)
  62. if err != nil {
  63. glog.InfoExtln("buffer 数据导入", "err", err)
  64. return
  65. }
  66. insertID = insertRest.InsertedID.(primitive.ObjectID)
  67. return insertID, err
  68. }
  69. /******************************************************************************
  70. *
  71. * @Reference LAPP_GAAS_GFrame_BACKEND/dao/om/SchedulerCache.DeleteOne
  72. *
  73. ******************************************************************************/
  74. func (impl *SchedulerCache) DeleteOne(entity *model.SchedulerCache) error {
  75. //1.初始化链接
  76. client := db.MgoDb()
  77. //2.选择数据库,数据表
  78. collect := client.Database(conf.DbConfig.Mongdbname).Collection("SchedulerCache")
  79. _, err := collect.DeleteOne(context.Background(), bson.M{"taskId": entity.TaskId})
  80. if err != nil {
  81. return err
  82. }
  83. return nil
  84. }
  85. /******************************************************************************
  86. *
  87. * @Reference LAPP_GAAS_GFrame_BACKEND/dao/om/SchedulerCache.SelectOne
  88. *
  89. ******************************************************************************/
  90. func (impl *SchedulerCache) SelectOne(entity *model.SchedulerCache) (model.SchedulerCache, error) {
  91. //1.初始化链接
  92. client := db.MgoDb()
  93. //2.选择数据库,数据表
  94. collect := client.Database(conf.DbConfig.Mongdbname).Collection("SchedulerCache")
  95. record := model.SchedulerCache{}
  96. err := collect.FindOne(context.Background(), bson.M{"taskId": entity.TaskId}).Decode(&record)
  97. if err != nil {
  98. return record, err
  99. }
  100. return record, nil
  101. }
  102. /******************************************************************************
  103. *
  104. * @Reference LAPP_GAAS_GFrame_BACKEND/dao/om/SchedulerCache.UpdateOne
  105. *
  106. ******************************************************************************/
  107. func (impl *SchedulerCache) UpdateOne(entity *model.SchedulerCache) error {
  108. //1.初始化链接
  109. client := db.MgoDb()
  110. //2.选择数据库,数据表
  111. collect := client.Database(conf.DbConfig.Mongdbname).Collection("SchedulerCache")
  112. new := &model.SchedulerCache{
  113. TaskId: entity.TaskId,
  114. WorkLineId: entity.WorkLineId,
  115. Data: entity.Data,
  116. CreateBy: entity.CreateBy,
  117. CreateTime: entity.CreateTime,
  118. }
  119. update := bson.M{"$set": new}
  120. _, err := collect.UpdateOne(context.Background(), bson.M{"taskId": new.TaskId}, update)
  121. if err != nil {
  122. return err
  123. }
  124. return nil
  125. }