report_author.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. func GetReportAuthorList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportAuthor, err error) {
  17. baseSql := ` report_author WHERE is_delete=0 `
  18. if condition != "" {
  19. baseSql += condition
  20. }
  21. totalSql := ` SELECT count(1) total FROM ` + baseSql
  22. err = global.DmSQL["rddp"].Raw(totalSql, pars...).Scan(&total).Error
  23. if err != nil {
  24. return
  25. }
  26. sql := ` SELECT * FROM ` + baseSql + ` ORDER BY id desc LIMIT ?,? `
  27. pars = append(pars, startSize)
  28. pars = append(pars, pageSize)
  29. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  30. return
  31. }
  32. func GetReportAuthorCount(condition string, pars []interface{}) (total int, err error) {
  33. totalSql := ` SELECT count(1) total FROM report_author WHERE 1=1 `
  34. if condition != "" {
  35. totalSql += condition
  36. }
  37. err = global.DmSQL["rddp"].Raw(totalSql, pars...).Scan(&total).Error
  38. return
  39. }
  40. type ReportAuthorResp struct {
  41. List []*ReportAuthor
  42. Paging *paging.PagingItem `description:"分页数据"`
  43. }
  44. type AddReportAuthorReq struct {
  45. Id int `description:"作者id"`
  46. AuthorType int `description:"类型,1:中文;2:英文"`
  47. Author string `description:"报告作者名称"`
  48. }
  49. func GetReportAuthorById(authorId int) (item *ReportAuthor, err error) {
  50. sql := `SELECT * FROM report_author WHERE is_delete=0 AND id = ? `
  51. err = global.DmSQL["rddp"].Raw(sql, authorId).First(&item).Error
  52. return
  53. }
  54. func GetReportAuthorByAuthor(title string, authorType int) (item *ReportAuthor, err error) {
  55. sql := `SELECT * FROM report_author WHERE is_delete=0 AND report_author=? AND author_type = ? `
  56. err = global.DmSQL["rddp"].Raw(sql, title, authorType).First(&item).Error
  57. return
  58. }
  59. func GetReportAuthorByAuthorAndId(title string, authorType, authorId int) (item *ReportAuthor, err error) {
  60. sql := `SELECT * FROM report_author WHERE is_delete=0 AND report_author=? AND author_type = ? AND id != ? `
  61. err = global.DmSQL["rddp"].Raw(sql, title, authorType, authorId).First(&item).Error
  62. return
  63. }
  64. func AddReportAuthor(item *ReportAuthor) (lastId int64, err error) {
  65. err = global.DmSQL["rddp"].Create(item).Error
  66. lastId = int64(item.Id)
  67. return
  68. }
  69. func (item *ReportAuthor) Update(cols []string) (err error) {
  70. err = global.DmSQL["rddp"].Select(cols).Updates(item).Error
  71. return
  72. }
  73. type EnableReportAuthorReq struct {
  74. Id int `description:"作者id"`
  75. EnableType int `description:"是否启用,0:禁用,1:启用"`
  76. }
  77. type DeleteReportAuthorReq struct {
  78. Id int `description:"作者id"`
  79. }