outside_report.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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{}, chartPermissionIdList []string) (count int, err error) {
  52. o := orm.NewOrmUsingDB("rddp")
  53. var sql string
  54. if len(chartPermissionIdList) > 0 {
  55. sql = `select count(1) from (`
  56. }
  57. sql += `SELECT COUNT( DISTINCT t1.outside_report_id )
  58. FROM outside_report t1
  59. LEFT JOIN chart_permission_search_key_word_mapping t2 ON t1.classify_id = t2.classify_id
  60. WHERE 1 = 1 `
  61. sql += condition
  62. if len(chartPermissionIdList) > 0 {
  63. sql += ` ) t`
  64. }
  65. err = o.Raw(sql, pars).QueryRow(&count)
  66. if err != nil && err != orm.ErrNoRows {
  67. return 0, err
  68. }
  69. return count, err
  70. }
  71. // GetOutsideReportListByCondition 根据条件查询列表
  72. func GetOutsideReportListByCondition(condition string, pars []interface{}, currentIndex int, pageSize int) (list []OutsideReportResp, err error) {
  73. o := orm.NewOrmUsingDB("rddp")
  74. 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 `
  75. sql += condition
  76. sql += ` limit ?, ?`
  77. _, err = o.Raw(sql, pars, (currentIndex-1)*pageSize, pageSize).QueryRows(&list)
  78. if err != nil && err != orm.ErrNoRows {
  79. return nil, err
  80. }
  81. return list, err
  82. }
  83. /*// GetOutsideReportListByDocumentTypeCount 根据文档类型查询列表条数
  84. func GetOutsideReportListByDocumentTypeCount(documentType int, condition string, pars []interface{}) (count int, err error) {
  85. o := orm.NewOrmUsingDB("rddp")
  86. var sql string
  87. if documentType == 1 {
  88. 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 `
  89. } else if documentType == 2 {
  90. 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 `
  91. }
  92. sql += sql + condition
  93. err = o.Raw(sql, pars).QueryRow(&count)
  94. if err != nil {
  95. return 0, err
  96. }
  97. return 0, err
  98. }
  99. // GetOutsideReportListByDocumentType 根据文档类型查询列表
  100. func GetOutsideReportListByDocumentType(documentType int, condition string, pars []interface{}) (list []OutsideReport, err error) {
  101. o := orm.NewOrmUsingDB("rddp")
  102. var sql string
  103. if documentType == 1 {
  104. 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 `
  105. } else if documentType == 2 {
  106. 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 `
  107. }
  108. sql += condition
  109. _, err = o.Raw(sql, pars).QueryRows(&list)
  110. if err != nil {
  111. return nil, err
  112. }
  113. return list, err
  114. }*/
  115. // SaveOutsideReport 保存报告
  116. func SaveOutsideReport(outsideReport OutsideReport) (id int64, err error) {
  117. o := orm.NewOrmUsingDB("rddp")
  118. id, err = o.Insert(&outsideReport)
  119. return
  120. }
  121. // GetOutsideReportById 根据ID获取报告
  122. func GetOutsideReportById(id int) (outsideReport *OutsideReport, err error) {
  123. o := orm.NewOrmUsingDB("rddp")
  124. outsideReport = &OutsideReport{}
  125. err = o.QueryTable("outside_report").Filter("outside_report_id", id).One(outsideReport)
  126. return
  127. }
  128. // UpdateOutsideReport 更新报告
  129. func UpdateOutsideReport(outsideReport *OutsideReport) (err error) {
  130. o := orm.NewOrmUsingDB("rddp")
  131. _, err = o.Update(&outsideReport)
  132. return
  133. }
  134. // DeleteOutsideReport 删除报告
  135. func DeleteOutsideReport(id int) (err error) {
  136. o := orm.NewOrmUsingDB("rddp")
  137. _, err = o.QueryTable("outside_report").Filter("outside_report_id", id).Delete()
  138. return
  139. }