report_author.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type ReportAuthor struct {
  8. Id int `orm:"column(id)" description:"报告作者ID"`
  9. ReportAuthor string `description:"报告作者名称"`
  10. AuthorType int `description:"类型,1:中文;2:英文"`
  11. Enable int `description:"是否启用,0:禁用,1:启用"`
  12. IsDelete int `description:"是否删除,0:未删除,1:已删除"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ModifyTime time.Time `description:"更新时间"`
  15. }
  16. // GetReportAuthorList 获取报告作者列表
  17. func GetReportAuthorList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportAuthor, err error) {
  18. o := orm.NewOrmUsingDB("rddp")
  19. baseSql := ` report_author WHERE is_delete=0 `
  20. if condition != "" {
  21. baseSql += condition
  22. }
  23. totalSql := ` SELECT count(1) total FROM ` + baseSql
  24. err = o.Raw(totalSql, pars).QueryRow(&total)
  25. if err != nil {
  26. return
  27. }
  28. sql := ` SELECT * FROM ` + baseSql + ` ORDER BY id desc LIMIT ?,? `
  29. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  30. return
  31. }
  32. // GetReportAuthorCount 获取报告作者列表数
  33. func GetReportAuthorCount(condition string, pars []interface{}) (total int, err error) {
  34. o := orm.NewOrmUsingDB("rddp")
  35. totalSql := ` SELECT count(1) total FROM report_author WHERE 1=1 `
  36. if condition != "" {
  37. totalSql += condition
  38. }
  39. err = o.Raw(totalSql, pars).QueryRow(&total)
  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. o := orm.NewOrmUsingDB("rddp")
  55. sql := `SELECT * FROM report_author WHERE is_delete=0 AND id = ? `
  56. err = o.Raw(sql, authorId).QueryRow(&item)
  57. return
  58. }
  59. // GetReportAuthorByAuthor 根据作者名称获取数据
  60. func GetReportAuthorByAuthor(title string, authorType int) (item *ReportAuthor, err error) {
  61. o := orm.NewOrmUsingDB("rddp")
  62. sql := `SELECT * FROM report_author WHERE is_delete=0 AND report_author=? AND author_type = ? `
  63. err = o.Raw(sql, title, authorType).QueryRow(&item)
  64. return
  65. }
  66. // GetReportAuthorByAuthorAndId 根据作者名称和作者id获取数据
  67. func GetReportAuthorByAuthorAndId(title string, authorType, authorId int) (item *ReportAuthor, err error) {
  68. o := orm.NewOrmUsingDB("rddp")
  69. sql := `SELECT * FROM report_author WHERE is_delete=0 AND report_author=? AND author_type = ? AND id != ? `
  70. err = o.Raw(sql, title, authorType, authorId).QueryRow(&item)
  71. return
  72. }
  73. // AddReportAuthor 新增作者
  74. func AddReportAuthor(item *ReportAuthor) (lastId int64, err error) {
  75. o := orm.NewOrmUsingDB("rddp")
  76. lastId, err = o.Insert(item)
  77. return
  78. }
  79. // Update 更新作者基础信息
  80. func (item *ReportAuthor) Update(cols []string) (err error) {
  81. o := orm.NewOrmUsingDB("rddp")
  82. _, err = o.Update(item, cols...)
  83. return
  84. }
  85. // EnableReportAuthorReq 启用/禁用报告作者请求体
  86. type EnableReportAuthorReq struct {
  87. Id int `description:"作者id"`
  88. EnableType int `description:"是否启用,0:禁用,1:启用"`
  89. }
  90. // DeleteReportAuthorReq 删除报告作者请求体
  91. type DeleteReportAuthorReq struct {
  92. Id int `description:"作者id"`
  93. }