outside_report.go 5.8 KB

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