report_author.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. //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. err = global.DmSQL["rddp"].Raw(totalSql, pars...).Scan(&total).Error
  26. if err != nil {
  27. return
  28. }
  29. sql := ` SELECT * FROM ` + baseSql + ` ORDER BY id desc LIMIT ?,? `
  30. // _, err = o.Raw(sql, pars...).QueryRows(&items)
  31. pars = append(pars, startSize)
  32. pars = append(pars, pageSize)
  33. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  34. return
  35. }
  36. // GetReportAuthorCount 获取报告作者列表数
  37. func GetReportAuthorCount(condition string, pars []interface{}) (total int, err error) {
  38. //o := orm.NewOrmUsingDB("rddp")
  39. totalSql := ` SELECT count(1) total FROM report_author WHERE 1=1 `
  40. if condition != "" {
  41. totalSql += condition
  42. }
  43. //err = o.Raw(totalSql, pars).QueryRow(&total)
  44. err = global.DmSQL["rddp"].Raw(totalSql, pars...).Scan(&total).Error
  45. return
  46. }
  47. type ReportAuthorResp struct {
  48. List []*ReportAuthor
  49. Paging *paging.PagingItem `description:"分页数据"`
  50. }
  51. // AddReportAuthorReq 新增报告作者请求体
  52. type AddReportAuthorReq struct {
  53. Id int `description:"作者id"`
  54. AuthorType int `description:"类型,1:中文;2:英文"`
  55. Author string `description:"报告作者名称"`
  56. }
  57. // GetReportAuthorById 根据作者id获取数据
  58. func GetReportAuthorById(authorId int) (item *ReportAuthor, err error) {
  59. //o := orm.NewOrmUsingDB("rddp")
  60. sql := `SELECT * FROM report_author WHERE is_delete=0 AND id = ? `
  61. //err = o.Raw(sql, authorId).QueryRow(&item)
  62. err = global.DmSQL["rddp"].Raw(sql, authorId).First(&item).Error
  63. return
  64. }
  65. // GetReportAuthorByAuthor 根据作者名称获取数据
  66. func GetReportAuthorByAuthor(title string, authorType int) (item *ReportAuthor, err error) {
  67. //o := orm.NewOrmUsingDB("rddp")
  68. sql := `SELECT * FROM report_author WHERE is_delete=0 AND report_author=? AND author_type = ? `
  69. //err = o.Raw(sql, title, authorType).QueryRow(&item)
  70. err = global.DmSQL["rddp"].Raw(sql, title, authorType).First(&item).Error
  71. return
  72. }
  73. // GetReportAuthorByAuthorAndId 根据作者名称和作者id获取数据
  74. func GetReportAuthorByAuthorAndId(title string, authorType, authorId int) (item *ReportAuthor, err error) {
  75. //o := orm.NewOrmUsingDB("rddp")
  76. sql := `SELECT * FROM report_author WHERE is_delete=0 AND report_author=? AND author_type = ? AND id != ? `
  77. //err = o.Raw(sql, title, authorType, authorId).QueryRow(&item)
  78. err = global.DmSQL["rddp"].Raw(sql, title, authorType, authorId).First(&item).Error
  79. return
  80. }
  81. // AddReportAuthor 新增作者
  82. func AddReportAuthor(item *ReportAuthor) (lastId int64, err error) {
  83. //o := orm.NewOrmUsingDB("rddp")
  84. //lastId, err = o.Insert(item)
  85. err = global.DmSQL["rddp"].Create(item).Error
  86. lastId = int64(item.Id)
  87. return
  88. }
  89. // Update 更新作者基础信息
  90. func (item *ReportAuthor) Update(cols []string) (err error) {
  91. //o := orm.NewOrmUsingDB("rddp")
  92. //_, err = o.Update(item, cols...)
  93. err = global.DmSQL["rddp"].Select(cols).Updates(item).Error
  94. return
  95. }
  96. // EnableReportAuthorReq 启用/禁用报告作者请求体
  97. type EnableReportAuthorReq struct {
  98. Id int `description:"作者id"`
  99. EnableType int `description:"是否启用,0:禁用,1:启用"`
  100. }
  101. // DeleteReportAuthorReq 删除报告作者请求体
  102. type DeleteReportAuthorReq struct {
  103. Id int `description:"作者id"`
  104. }