message.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package data_manage_permission
  2. import (
  3. "eta/eta_mobile/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. // DataPermissionMessage
  10. // @Description: 数据权限变更消息表
  11. type DataPermissionMessage struct {
  12. DataPermissionMessageId int64 `json:"data_permission_message_id" orm:"column(data_permission_message_id);pk"`
  13. SendUserId int32 `json:"send_user_id"` // 发送人ID
  14. ReceiveUserId int32 `json:"receive_user_id"` // 接收者ID
  15. Content string `json:"content"` // 消息内容
  16. Remark string `json:"remark"` // 备注信息
  17. OpType int32 `json:"op_type"` // 操作类型,1:单个资产转移,2:资产模块转移,3:资产授权,4:资产分类授权
  18. Source int32 `description:"来源id"`
  19. SubSource int32 `description:"子来源id"`
  20. OpUniqueCode string `json:"op_unique_code"` // 操作编码
  21. IsRead int32 `json:"is_read"` // 是否已读:0-未读;1-已读
  22. CreateTime time.Time `json:"create_time"` // 创建时间
  23. ModifyTime time.Time `json:"modify_time"` // 修改时间
  24. }
  25. var DataPermissionMessageCols = struct {
  26. DataPermissionMessageId string
  27. SendUserId string
  28. ReceiveUserId string
  29. Content string
  30. Remark string
  31. OpType string
  32. Source string
  33. SubSource string
  34. OpUniqueCode string
  35. IsRead string
  36. CreateTime string
  37. ModifyTime string
  38. }{
  39. DataPermissionMessageId: "data_permission_message_id",
  40. SendUserId: "send_user_id",
  41. ReceiveUserId: "receive_user_id",
  42. Content: "content",
  43. Remark: "remark",
  44. OpType: "op_type",
  45. Source: "source",
  46. SubSource: "sub_source",
  47. OpUniqueCode: "op_unique_code",
  48. IsRead: "is_read",
  49. CreateTime: "create_time",
  50. ModifyTime: "modify_time",
  51. }
  52. func (m *DataPermissionMessage) TableName() string {
  53. return "data_permission_message"
  54. }
  55. func (m *DataPermissionMessage) PrimaryId() string {
  56. return DataPermissionMessageCols.DataPermissionMessageId
  57. }
  58. func (m *DataPermissionMessage) Create() (err error) {
  59. o := orm.NewOrmUsingDB("data")
  60. id, err := o.Insert(m)
  61. if err != nil {
  62. return
  63. }
  64. m.DataPermissionMessageId = id
  65. return
  66. }
  67. func (m *DataPermissionMessage) CreateMulti(items []*DataPermissionMessage) (err error) {
  68. if len(items) == 0 {
  69. return
  70. }
  71. o := orm.NewOrmUsingDB("data")
  72. _, err = o.InsertMulti(500, items)
  73. return
  74. }
  75. func (m *DataPermissionMessage) Update(cols []string) (err error) {
  76. o := orm.NewOrmUsingDB("data")
  77. _, err = o.Update(m, cols...)
  78. return
  79. }
  80. func (m *DataPermissionMessage) Del() (err error) {
  81. o := orm.NewOrmUsingDB("data")
  82. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  83. _, err = o.Raw(sql, m.DataPermissionMessageId).Exec()
  84. return
  85. }
  86. func (m *DataPermissionMessage) MultiDel(menuIds []int) (err error) {
  87. if len(menuIds) == 0 {
  88. return
  89. }
  90. o := orm.NewOrmUsingDB("data")
  91. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  92. _, err = o.Raw(sql, menuIds).Exec()
  93. return
  94. }
  95. func (m *DataPermissionMessage) GetItemById(id int) (item *DataPermissionMessage, err error) {
  96. o := orm.NewOrmUsingDB("data")
  97. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  98. err = o.Raw(sql, id).QueryRow(&item)
  99. return
  100. }
  101. func (m *DataPermissionMessage) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  102. o := orm.NewOrmUsingDB("data")
  103. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  104. err = o.Raw(sql, pars).QueryRow(&count)
  105. return
  106. }
  107. func (m *DataPermissionMessage) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*DataPermissionMessage, err error) {
  108. o := orm.NewOrmUsingDB("data")
  109. fields := strings.Join(fieldArr, ",")
  110. if len(fieldArr) == 0 {
  111. fields = `*`
  112. }
  113. order := `ORDER BY create_time DESC`
  114. if orderRule != "" {
  115. order = ` ORDER BY ` + orderRule
  116. }
  117. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  118. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  119. return
  120. }
  121. // FormatDataPermissionMessage2Item 格式化消息
  122. func FormatDataPermissionMessage2Item(origin *DataPermissionMessage) (item *DataPermissionMessageItem) {
  123. item = &DataPermissionMessageItem{
  124. DataPermissionMessageId: origin.DataPermissionMessageId,
  125. SendUserId: origin.SendUserId,
  126. ReceiveUserId: origin.ReceiveUserId,
  127. Content: origin.Content,
  128. Remark: origin.Remark,
  129. OpType: origin.OpType,
  130. Source: origin.Source,
  131. SubSource: origin.SubSource,
  132. OpUniqueCode: origin.OpUniqueCode,
  133. IsRead: origin.IsRead,
  134. CreateTime: utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime),
  135. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime),
  136. }
  137. return
  138. }