outside_report.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // @Author gmy 2024/9/19 14:53:00
  2. package document_manage_model
  3. import (
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. )
  7. type OutsideReport struct {
  8. OutsideReportId int `orm:"column(outside_report_id);pk" description:"外部报告ID"`
  9. Source int `orm:"column(source)" description:"来源,1:ETA系统录入;2:API接口录入;3:邮件监听录入"`
  10. Title string `orm:"column(title)" description:"报告标题"`
  11. Abstract string `orm:"column(abstract)" description:"摘要"`
  12. ClassifyId int `orm:"column(classify_id)" description:"所属分类id"`
  13. ClassifyName string `orm:"column(classify_name)" description:"所属分类名称(整个分类链条)"`
  14. Content string `orm:"column(content)" description:"报告富文本内容"`
  15. SysUserId int `orm:"column(sys_user_id)" description:"创建人id"`
  16. SysUserName string `orm:"column(sys_user_name)" description:"创建人姓名"`
  17. EmailMessageUid int `orm:"column(email_message_uid)" description:"该邮件在邮箱中的唯一id"`
  18. ReportUpdateTime string `orm:"column(report_update_time)" description:"报告更新时间,如果来源于邮件,那么取邮件的收件时间"`
  19. ModifyTime string `orm:"column(modify_time)" description:"最近一次修改时间"`
  20. CreateTime string `orm:"column(create_time)" description:"创建时间"`
  21. ReportCode string `orm:"column(report_code)" description:"报告唯一编码"`
  22. }
  23. type OutsideReportPage struct {
  24. List []OutsideReport `description:"报告列表"`
  25. Paging *paging.PagingItem `description:"分页数据"`
  26. }
  27. type OutsideReportBO struct {
  28. OutsideReportId int `orm:"column(outside_report_id);pk" description:"外部报告ID"`
  29. Source int `orm:"column(source)" description:"来源,1:ETA系统录入;2:API接口录入;3:邮件监听录入"`
  30. Title string `orm:"column(title)" description:"报告标题"`
  31. Abstract string `orm:"column(abstract)" description:"摘要"`
  32. ClassifyId int `orm:"column(classify_id)" description:"所属分类id"`
  33. ClassifyName string `orm:"column(classify_name)" description:"所属分类名称(整个分类链条)"`
  34. Content string `orm:"column(content)" description:"报告富文本内容"`
  35. SysUserId int `orm:"column(sys_user_id)" description:"创建人id"`
  36. SysUserName string `orm:"column(sys_user_name)" description:"创建人姓名"`
  37. ReportCode string `orm:"column(report_code)" description:"报告唯一编码"`
  38. ModifyTime string `orm:"column(modify_time)" description:"最近一次修改时间"`
  39. CreateTime string `orm:"column(create_time)" description:"创建时间"`
  40. AttachmentList []*OutsideReportAttachment
  41. }
  42. // 在 init 函数中注册模型
  43. func init() {
  44. orm.RegisterModel(new(OutsideReport))
  45. }
  46. // GetOutsideReportListByConditionCount 根据条件查询列表条数
  47. func GetOutsideReportListByConditionCount(condition string, pars []interface{}) (count int, err error) {
  48. o := orm.NewOrmUsingDB("rddp")
  49. sql := `select count(1) from (
  50. SELECT COUNT( DISTINCT t1.outside_report_id )
  51. FROM outside_report t1
  52. LEFT JOIN chart_permission_search_key_word_mapping t2 ON t1.classify_id = t2.classify_id
  53. WHERE 1 = 1 `
  54. sql += condition
  55. sql += ` ) t`
  56. err = o.Raw(sql, pars).QueryRow(&count)
  57. if err != nil {
  58. return 0, err
  59. }
  60. return count, err
  61. }
  62. // GetOutsideReportListByCondition 根据条件查询列表
  63. func GetOutsideReportListByCondition(condition string, pars []interface{}) (list []OutsideReport, err error) {
  64. o := orm.NewOrmUsingDB("rddp")
  65. sql := `select DISTINCT t1.outside_report_id, t1.source, t1.title, t1.abstract, t1.classify_id,
  66. t1.classify_name, t1.sys_user_id, t1.sys_user_name, t1.email_message_uid, t1.report_update_time,
  67. t1.modify_time, t1.create_time, t1.report_code from outside_report t1
  68. left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id where 1 = 1 `
  69. sql += condition
  70. _, err = o.Raw(sql, pars).QueryRows(&list)
  71. if err != nil {
  72. return nil, err
  73. }
  74. return list, err
  75. }
  76. // SaveOutsideReport 保存报告
  77. func SaveOutsideReport(outsideReport OutsideReport) (id int64, err error) {
  78. o := orm.NewOrmUsingDB("rddp")
  79. id, err = o.Insert(&outsideReport)
  80. return
  81. }
  82. // GetOutsideReportById 根据ID获取报告
  83. func GetOutsideReportById(id int) (outsideReport *OutsideReport, err error) {
  84. o := orm.NewOrmUsingDB("rddp")
  85. outsideReport = &OutsideReport{}
  86. err = o.QueryTable("outside_report").Filter("outside_report_id", id).One(outsideReport)
  87. return
  88. }
  89. // UpdateOutsideReport 更新报告
  90. func UpdateOutsideReport(outsideReport *OutsideReport) (err error) {
  91. o := orm.NewOrmUsingDB("rddp")
  92. _, err = o.Update(outsideReport)
  93. return
  94. }
  95. // DeleteOutsideReport 删除报告
  96. func DeleteOutsideReport(id int) (err error) {
  97. o := orm.NewOrmUsingDB("rddp")
  98. _, err = o.QueryTable("outside_report").Filter("outside_report_id", id).Delete()
  99. return
  100. }
  101. // GetOutsideReportListByClassifyId 根据分类id查询报告列表
  102. func GetOutsideReportListByClassifyId(classifyId int) (list []OutsideReport, err error) {
  103. o := orm.NewOrmUsingDB("rddp")
  104. sql := `select * from outside_report where classify_id = ?`
  105. _, err = o.Raw(sql, classifyId).QueryRows(&list)
  106. if err != nil {
  107. return nil, err
  108. }
  109. return list, err
  110. }