report_author.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package models
  2. import (
  3. sql2 "database/sql"
  4. "eta/eta_api/global"
  5. "eta/eta_api/utils"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "time"
  8. )
  9. type ReportAuthor struct {
  10. Id int `gorm:"column:id;primaryKey;autoIncrement" description:"报告作者ID"`
  11. ReportAuthor string `description:"报告作者名称"`
  12. AuthorType int `description:"类型,1:中文;2:英文"`
  13. Enable int `description:"是否启用,0:禁用,1:启用"`
  14. IsDelete int `description:"是否删除,0:未删除,1:已删除"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"更新时间"`
  17. }
  18. // GetReportAuthorList 获取报告作者列表
  19. func GetReportAuthorList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportAuthor, err error) {
  20. o := global.DbMap[utils.DbNameReport]
  21. baseSql := ` report_author WHERE is_delete=0 `
  22. if condition != "" {
  23. baseSql += condition
  24. }
  25. totalSql := ` SELECT count(1) total FROM ` + baseSql
  26. var totalNull sql2.NullInt64
  27. err = global.DbMap[utils.DbNameReport].Raw(totalSql, pars...).Scan(&totalNull).Error
  28. if err != nil {
  29. return
  30. }
  31. if totalNull.Valid {
  32. total = int(totalNull.Int64)
  33. }
  34. sql := ` SELECT * FROM ` + baseSql + ` ORDER BY id desc LIMIT ?,? `
  35. pars = append(pars, startSize, pageSize)
  36. err = o.Raw(sql, pars...).Find(&items).Error
  37. return
  38. }
  39. // GetReportAuthorCount 获取报告作者列表数
  40. func GetReportAuthorCount(condition string, pars []interface{}) (total int, err error) {
  41. o := global.DbMap[utils.DbNameReport]
  42. totalSql := ` SELECT count(1) total FROM report_author WHERE 1=1 `
  43. if condition != "" {
  44. totalSql += condition
  45. }
  46. var totalNull sql2.NullInt64
  47. err = o.Raw(totalSql, pars...).Scan(&totalNull).Error
  48. if err != nil {
  49. return
  50. }
  51. if totalNull.Valid {
  52. total = int(totalNull.Int64)
  53. }
  54. return
  55. }
  56. type ReportAuthorResp struct {
  57. List []*ReportAuthor
  58. Paging *paging.PagingItem `description:"分页数据"`
  59. }
  60. // AddReportAuthorReq 新增报告作者请求体
  61. type AddReportAuthorReq struct {
  62. Id int `description:"作者id"`
  63. AuthorType int `description:"类型,1:中文;2:英文"`
  64. Author string `description:"报告作者名称"`
  65. }
  66. // GetReportAuthorById 根据作者id获取数据
  67. func GetReportAuthorById(authorId int) (item *ReportAuthor, err error) {
  68. o := global.DbMap[utils.DbNameReport]
  69. sql := `SELECT * FROM report_author WHERE is_delete=0 AND id = ? `
  70. err = o.Raw(sql, authorId).First(&item).Error
  71. return
  72. }
  73. // GetReportAuthorByAuthor 根据作者名称获取数据
  74. func GetReportAuthorByAuthor(title string, authorType int) (item *ReportAuthor, err error) {
  75. o := global.DbMap[utils.DbNameReport]
  76. sql := `SELECT * FROM report_author WHERE is_delete=0 AND report_author=? AND author_type = ? `
  77. err = o.Raw(sql, title, authorType).First(&item).Error
  78. return
  79. }
  80. // GetReportAuthorByAuthorAndId 根据作者名称和作者id获取数据
  81. func GetReportAuthorByAuthorAndId(title string, authorType, authorId int) (item *ReportAuthor, err error) {
  82. o := global.DbMap[utils.DbNameReport]
  83. sql := `SELECT * FROM report_author WHERE is_delete=0 AND report_author=? AND author_type = ? AND id != ? `
  84. err = o.Raw(sql, title, authorType, authorId).First(&item).Error
  85. return
  86. }
  87. // AddReportAuthor 新增作者
  88. func AddReportAuthor(item *ReportAuthor) (lastId int64, err error) {
  89. o := global.DbMap[utils.DbNameReport]
  90. err = o.Create(item).Error
  91. if err != nil {
  92. return
  93. }
  94. lastId = int64(item.Id)
  95. return
  96. }
  97. // Update 更新作者基础信息
  98. func (item *ReportAuthor) Update(cols []string) (err error) {
  99. err = global.DbMap[utils.DbNameReport].Select(cols).Updates(item).Error
  100. return
  101. }
  102. // EnableReportAuthorReq 启用/禁用报告作者请求体
  103. type EnableReportAuthorReq struct {
  104. Id int `description:"作者id"`
  105. EnableType int `description:"是否启用,0:禁用,1:启用"`
  106. }
  107. // DeleteReportAuthorReq 删除报告作者请求体
  108. type DeleteReportAuthorReq struct {
  109. Id int `description:"作者id"`
  110. }