report_author.go 3.8 KB

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