sa_label.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package semantic_analysis
  2. import (
  3. "eta_gn/eta_api/global"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "strings"
  7. "time"
  8. )
  9. type SaLabel struct {
  10. SaLabelId int `gorm:"primaryKey;column:sa_label_id;type:int(10) unsigned;not null"` // 语义分析-标签Id
  11. LabelName string `gorm:"column:label_name;type:varchar(128);not null;default:''"` // 标签名称
  12. SysAdminId int `gorm:"column:sys_admin_id;type:int(10) unsigned;not null;default:0"` // 创建人Id
  13. SysAdminName string `gorm:"column:sys_admin_name;type:varchar(128);not null;default:''"` // 创建人姓名
  14. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  15. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间
  16. }
  17. var SaLabelColumns = struct {
  18. SaLabelId string
  19. LabelName string
  20. SysAdminId string
  21. SysAdminName string
  22. CreateTime string
  23. ModifyTime string
  24. }{
  25. SaLabelId: "sa_label_id",
  26. LabelName: "label_name",
  27. SysAdminId: "sys_admin_id",
  28. SysAdminName: "sys_admin_name",
  29. CreateTime: "create_time",
  30. ModifyTime: "modify_time",
  31. }
  32. func (m *SaLabel) TableName() string {
  33. return "sa_label"
  34. }
  35. func (m *SaLabel) Create() (err error) {
  36. err = global.DEFAULT_DmSQL.Create(m).Error
  37. return
  38. }
  39. func (m *SaLabel) Update(cols []string) (err error) {
  40. err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error
  41. return
  42. }
  43. func (m *SaLabel) Del() (err error) {
  44. sql := `DELETE FROM sa_label WHERE sa_label_id = ? LIMIT 1`
  45. err = global.DEFAULT_DmSQL.Exec(sql, m.SaLabelId).Error
  46. return
  47. }
  48. func (m *SaLabel) GetItemById(id int) (err error) {
  49. sql := `SELECT * FROM sa_label WHERE sa_label_id = ? LIMIT 1`
  50. err = global.DEFAULT_DmSQL.Raw(sql, id).First(&m).Error
  51. return
  52. }
  53. func (m *SaLabel) GetItemByCondition(condition string, pars []interface{}) (err error) {
  54. sql := `SELECT * FROM sa_label WHERE 1=1 `
  55. sql += condition
  56. sql += ` LIMIT 1`
  57. err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&m).Error
  58. return
  59. }
  60. func (m *SaLabel) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  61. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  62. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  63. return
  64. }
  65. func (m *SaLabel) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaLabel, err error) {
  66. fields := strings.Join(fieldArr, ",")
  67. if len(fieldArr) == 0 {
  68. fields = `*`
  69. }
  70. order := `ORDER BY create_time DESC`
  71. if orderRule != "" {
  72. order = ` ORDER BY ` + orderRule
  73. }
  74. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  75. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  76. return
  77. }
  78. func (m *SaLabel) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaLabel, err error) {
  79. fields := strings.Join(fieldArr, ",")
  80. if len(fieldArr) == 0 {
  81. fields = `*`
  82. }
  83. order := `ORDER BY create_time DESC`
  84. if orderRule != "" {
  85. order = ` ORDER BY ` + orderRule
  86. }
  87. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  88. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  89. err = global.DEFAULT_DmSQL.Raw(totalSql, pars...).Scan(&total).Error
  90. if err != nil {
  91. return
  92. }
  93. sql += ` LIMIT ?,?`
  94. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  95. return
  96. }
  97. type SaLabelAddReq struct {
  98. LabelName string `description:"标签名称"`
  99. }
  100. type SaLabelEditReq struct {
  101. SaLabelId int `description:"标签ID"`
  102. SaLabelAddReq
  103. }
  104. type SaLabelDelReq struct {
  105. SaLabelId int `description:"标签ID"`
  106. }
  107. type SaLabelPageListResp struct {
  108. List []*SaLabelItem
  109. Paging *paging.PagingItem `description:"分页数据"`
  110. }
  111. type SaLabelItem struct {
  112. SaLabelId int `description:"标签ID"`
  113. LabelName string `description:"标签名称"`
  114. UserNum int `description:"引用数量"`
  115. SysAdminId int `description:"创建人ID"`
  116. SysAdminName string `description:"创建人姓名"`
  117. CreateTime string `description:"创建时间"`
  118. }