message.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package data_manage_permission
  2. import (
  3. "eta/eta_api/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. OpUniqueCode string `json:"op_unique_code"` // 操作编码
  19. IsRead int32 `json:"is_read"` // 是否已读:0-未读;1-已读
  20. CreateTime time.Time `json:"create_time"` // 创建时间
  21. ModifyTime time.Time `json:"modify_time"` // 修改时间
  22. }
  23. var DataPermissionMessageCols = struct {
  24. DataPermissionMessageId string
  25. SendUserId string
  26. ReceiveUserId string
  27. Content string
  28. Remark string
  29. OpType string
  30. OpUniqueCode string
  31. IsRead string
  32. CreateTime string
  33. ModifyTime string
  34. }{
  35. DataPermissionMessageId: "data_permission_message_id",
  36. SendUserId: "send_user_id",
  37. ReceiveUserId: "receive_user_id",
  38. Content: "content",
  39. Remark: "remark",
  40. OpType: "op_type",
  41. OpUniqueCode: "op_unique_code",
  42. IsRead: "is_read",
  43. CreateTime: "create_time",
  44. ModifyTime: "modify_time",
  45. }
  46. func (m *DataPermissionMessage) TableName() string {
  47. return "data_permission_message"
  48. }
  49. func (m *DataPermissionMessage) PrimaryId() string {
  50. return DataPermissionMessageCols.DataPermissionMessageId
  51. }
  52. func (m *DataPermissionMessage) Create() (err error) {
  53. o := orm.NewOrmUsingDB("data")
  54. id, err := o.Insert(m)
  55. if err != nil {
  56. return
  57. }
  58. m.DataPermissionMessageId = id
  59. return
  60. }
  61. func (m *DataPermissionMessage) CreateMulti(items []*DataPermissionMessage) (err error) {
  62. if len(items) == 0 {
  63. return
  64. }
  65. o := orm.NewOrmUsingDB("data")
  66. _, err = o.InsertMulti(500, items)
  67. return
  68. }
  69. func (m *DataPermissionMessage) Update(cols []string) (err error) {
  70. o := orm.NewOrmUsingDB("data")
  71. _, err = o.Update(m, cols...)
  72. return
  73. }
  74. func (m *DataPermissionMessage) Del() (err error) {
  75. o := orm.NewOrmUsingDB("data")
  76. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  77. _, err = o.Raw(sql, m.DataPermissionMessageId).Exec()
  78. return
  79. }
  80. func (m *DataPermissionMessage) MultiDel(menuIds []int) (err error) {
  81. if len(menuIds) == 0 {
  82. return
  83. }
  84. o := orm.NewOrmUsingDB("data")
  85. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  86. _, err = o.Raw(sql, menuIds).Exec()
  87. return
  88. }
  89. func (m *DataPermissionMessage) GetItemById(id int) (item *DataPermissionMessage, err error) {
  90. o := orm.NewOrmUsingDB("data")
  91. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  92. err = o.Raw(sql, id).QueryRow(&item)
  93. return
  94. }
  95. func (m *DataPermissionMessage) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  96. o := orm.NewOrmUsingDB("data")
  97. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  98. err = o.Raw(sql, pars).QueryRow(&count)
  99. return
  100. }
  101. func (m *DataPermissionMessage) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*DataPermissionMessage, err error) {
  102. o := orm.NewOrmUsingDB("data")
  103. fields := strings.Join(fieldArr, ",")
  104. if len(fieldArr) == 0 {
  105. fields = `*`
  106. }
  107. order := `ORDER BY create_time DESC`
  108. if orderRule != "" {
  109. order = ` ORDER BY ` + orderRule
  110. }
  111. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  112. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  113. return
  114. }
  115. // FormatDataPermissionMessage2Item 格式化消息
  116. func FormatDataPermissionMessage2Item(origin *DataPermissionMessage) (item *DataPermissionMessageItem) {
  117. item = &DataPermissionMessageItem{
  118. DataPermissionMessageId: origin.DataPermissionMessageId,
  119. SendUserId: origin.SendUserId,
  120. ReceiveUserId: origin.ReceiveUserId,
  121. Content: origin.Content,
  122. Remark: origin.Remark,
  123. OpType: origin.OpType,
  124. OpUniqueCode: origin.OpUniqueCode,
  125. IsRead: origin.IsRead,
  126. CreateTime: utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime),
  127. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime),
  128. }
  129. return
  130. }