message.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package data_manage_permission
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  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" gorm:"primaryKey" `
  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. err = global.DmSQL["data"].Create(m).Error
  60. return
  61. }
  62. func (m *DataPermissionMessage) CreateMulti(items []*DataPermissionMessage) (err error) {
  63. if len(items) == 0 {
  64. return
  65. }
  66. err = global.DmSQL["data"].CreateInBatches(items, utils.MultiAddNum).Error
  67. return
  68. }
  69. func (m *DataPermissionMessage) Update(cols []string) (err error) {
  70. err = global.DmSQL["data"].Select(cols).Updates(m).Error
  71. return
  72. }
  73. func (m *DataPermissionMessage) Del() (err error) {
  74. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  75. err = global.DmSQL["data"].Exec(sql, m.DataPermissionMessageId).Error
  76. return
  77. }
  78. func (m *DataPermissionMessage) MultiDel(menuIds []int) (err error) {
  79. if len(menuIds) == 0 {
  80. return
  81. }
  82. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  83. err = global.DmSQL["data"].Exec(sql, menuIds).Error
  84. return
  85. }
  86. func (m *DataPermissionMessage) GetItemById(id int) (item *DataPermissionMessage, err error) {
  87. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  88. err = global.DmSQL["data"].Raw(sql, id).First(&item).Error
  89. return
  90. }
  91. func (m *DataPermissionMessage) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  92. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  93. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
  94. return
  95. }
  96. func (m *DataPermissionMessage) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*DataPermissionMessage, err error) {
  97. fields := strings.Join(fieldArr, ",")
  98. if len(fieldArr) == 0 {
  99. fields = `*`
  100. }
  101. order := `ORDER BY create_time DESC`
  102. if orderRule != "" {
  103. order = ` ORDER BY ` + orderRule
  104. }
  105. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  106. pars = append(pars, startSize)
  107. pars = append(pars, pageSize)
  108. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&items).Error
  109. return
  110. }
  111. // FormatDataPermissionMessage2Item 格式化消息
  112. func FormatDataPermissionMessage2Item(origin *DataPermissionMessage) (item *DataPermissionMessageItem) {
  113. item = &DataPermissionMessageItem{
  114. DataPermissionMessageId: origin.DataPermissionMessageId,
  115. SendUserId: origin.SendUserId,
  116. ReceiveUserId: origin.ReceiveUserId,
  117. Content: origin.Content,
  118. Remark: origin.Remark,
  119. OpType: origin.OpType,
  120. Source: origin.Source,
  121. SubSource: origin.SubSource,
  122. OpUniqueCode: origin.OpUniqueCode,
  123. IsRead: origin.IsRead,
  124. CreateTime: utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime),
  125. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime),
  126. }
  127. return
  128. }