outside_report.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 OutsideReportResp struct {
  24. OutsideReport
  25. IsCollect int `description:"是否收藏"`
  26. }
  27. type OutsideReportPage struct {
  28. List []OutsideReportResp `description:"报告列表"`
  29. Paging *paging.PagingItem `description:"分页数据"`
  30. }
  31. type OutsideReportBO struct {
  32. OutsideReportId int `orm:"column(outside_report_id);pk" description:"外部报告ID"`
  33. Source int `orm:"column(source)" description:"来源,1:ETA系统录入;2:API接口录入;3:邮件监听录入"`
  34. Title string `orm:"column(title)" description:"报告标题"`
  35. Abstract string `orm:"column(abstract)" description:"摘要"`
  36. ClassifyId int `orm:"column(classify_id)" description:"所属分类id"`
  37. ClassifyName string `orm:"column(classify_name)" description:"所属分类名称(整个分类链条)"`
  38. Content string `orm:"column(content)" description:"报告富文本内容"`
  39. SysUserId int `orm:"column(sys_user_id)" description:"创建人id"`
  40. SysUserName string `orm:"column(sys_user_name)" description:"创建人姓名"`
  41. ModifyTime string `orm:"column(modify_time)" description:"最近一次修改时间"`
  42. CreateTime string `orm:"column(create_time)" description:"创建时间"`
  43. ReportCode string `orm:"column(report_code)" description:"报告唯一编码"`
  44. AttachmentList []*OutsideReportAttachment
  45. }
  46. // 在 init 函数中注册模型
  47. func init() {
  48. orm.RegisterModel(new(OutsideReport))
  49. }
  50. // GetOutsideReportListByConditionCount 根据条件查询列表条数
  51. func GetOutsideReportListByConditionCount(condition string, pars []interface{}) (count int, err error) {
  52. o := orm.NewOrmUsingDB("rddp")
  53. sql := `select count(distinct t1.outside_report_id) from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id where 1 = 1 `
  54. sql += condition
  55. err = o.Raw(sql, pars).QueryRow(&count)
  56. if err != nil {
  57. return 0, err
  58. }
  59. return count, err
  60. }
  61. // GetOutsideReportListByCondition 根据条件查询列表
  62. func GetOutsideReportListByCondition(condition string, pars []interface{}, currentIndex int, pageSize int) (list []OutsideReportResp, err error) {
  63. o := orm.NewOrmUsingDB("rddp")
  64. sql := `select distinct t1.outside_report_id, t1.source, t1.title, t1.abstract, t1.classify_id, t1.classify_name, t1.sys_user_id, t1.sys_user_name, t1.email_message_uid, t1.report_update_time, t1.modify_time, t1.create_time, t1.report_code from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id where 1 = 1 `
  65. sql += condition
  66. sql += ` limit ?, ?`
  67. _, err = o.Raw(sql, pars, (currentIndex-1)*pageSize, pageSize).QueryRows(&list)
  68. if err != nil {
  69. return nil, err
  70. }
  71. return list, err
  72. }
  73. /*// GetOutsideReportListByDocumentTypeCount 根据文档类型查询列表条数
  74. func GetOutsideReportListByDocumentTypeCount(documentType int, condition string, pars []interface{}) (count int, err error) {
  75. o := orm.NewOrmUsingDB("rddp")
  76. var sql string
  77. if documentType == 1 {
  78. sql = `select count(t1.OutsideReportId) from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id where 1 = 1 `
  79. } else if documentType == 2 {
  80. sql = `select count(t1.OutsideReportId) from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id left join user_collect_classify t3 on t1.classify_id = t3.classify_id where 1 = 1 `
  81. }
  82. sql += sql + condition
  83. err = o.Raw(sql, pars).QueryRow(&count)
  84. if err != nil {
  85. return 0, err
  86. }
  87. return 0, err
  88. }
  89. // GetOutsideReportListByDocumentType 根据文档类型查询列表
  90. func GetOutsideReportListByDocumentType(documentType int, condition string, pars []interface{}) (list []OutsideReport, err error) {
  91. o := orm.NewOrmUsingDB("rddp")
  92. var sql string
  93. if documentType == 1 {
  94. sql = `select t1.* from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id where 1 = 1 `
  95. } else if documentType == 2 {
  96. sql = `select t1.* from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id left join user_collect_classify t3 on t1.classify_id = t3.classify_id where 1 = 1 `
  97. }
  98. sql += condition
  99. _, err = o.Raw(sql, pars).QueryRows(&list)
  100. if err != nil {
  101. return nil, err
  102. }
  103. return list, err
  104. }*/
  105. // SaveOutsideReport 保存报告
  106. func SaveOutsideReport(outsideReport OutsideReport) (id int64, err error) {
  107. o := orm.NewOrmUsingDB("rddp")
  108. id, err = o.Insert(&outsideReport)
  109. return
  110. }
  111. // GetOutsideReportById 根据ID获取报告
  112. func GetOutsideReportById(id int) (outsideReport *OutsideReport, err error) {
  113. o := orm.NewOrmUsingDB("rddp")
  114. outsideReport = &OutsideReport{}
  115. err = o.QueryTable("outside_report").Filter("outside_report_id", id).One(outsideReport)
  116. return
  117. }
  118. // UpdateOutsideReport 更新报告
  119. func UpdateOutsideReport(outsideReport *OutsideReport) (err error) {
  120. o := orm.NewOrmUsingDB("rddp")
  121. _, err = o.Update(&outsideReport)
  122. return
  123. }
  124. // DeleteOutsideReport 删除报告
  125. func DeleteOutsideReport(id int) (err error) {
  126. o := orm.NewOrmUsingDB("rddp")
  127. _, err = o.QueryTable("outside_report").Filter("outside_report_id", id).Delete()
  128. return
  129. }