english_policy_report.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package models
  2. import (
  3. "eta/eta_mobile/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "strings"
  7. "time"
  8. )
  9. // 英文策略报告
  10. type EnglishPolicyReport struct {
  11. Id int `orm:"column(id);pk;auto" description:"策略报告Id"`
  12. ClassifyIdFirst int `description:"一级分类id"`
  13. ClassifyNameFirst string `description:"一级分类名称"`
  14. ClassifyIdSecond int `description:"二级分类id"`
  15. ClassifyNameSecond string `description:"二级分类名称"`
  16. Title string `description:"标题"`
  17. Abstract string `description:"摘要"`
  18. Author string `description:"作者"`
  19. Frequency string `description:"频度"`
  20. CreateTime time.Time `description:"创建时间"`
  21. ModifyTime time.Time `description:"修改时间"`
  22. State int `description:"1:未同步,2:已同步"`
  23. SyncTime time.Time `description:"同步时间"`
  24. PublishStatus int `description:"1:未发布,2:已发布"`
  25. PublishTime time.Time `description:"发布时间"`
  26. Content string `description:"内容"`
  27. KeyTakeaways string `description:"关键点"`
  28. AuthorMobile string `description:"创建者手机号"`
  29. SyncReportId int `description:"同步后的report_id为english_report的ID"`
  30. SourceReportId int `description:"原始报告ID"`
  31. ReportCoverUrl string `description:"原始报告封面图"`
  32. }
  33. // AddEnglishPolicyReportMulti 批量新增report
  34. func AddEnglishPolicyReportMulti(list []*EnglishPolicyReport) (err error) {
  35. o := orm.NewOrmUsingDB("rddp")
  36. _, err = o.InsertMulti(len(list), list)
  37. return
  38. }
  39. type EnglishPolicyReportDetail struct {
  40. Id int `description:"策略报告Id"`
  41. ClassifyIdFirst int `description:"一级分类id"`
  42. ClassifyNameFirst string `description:"一级分类名称"`
  43. ClassifyIdSecond int `description:"二级分类id"`
  44. ClassifyNameSecond string `description:"二级分类名称"`
  45. Title string `description:"标题"`
  46. Abstract string `description:"摘要"`
  47. Author string `description:"作者"`
  48. Frequency string `description:"频度"`
  49. //CreateTime string `description:"创建时间"`
  50. PublishTime string `description:"发布时间"`
  51. ModifyTime string `description:"修改时间"`
  52. State int `description:"同步状态:1:未同步,2:已同步"`
  53. SyncTime string `description:"同步时间"`
  54. Content string `description:"内容"`
  55. KeyTakeaways string `description:"关键点"`
  56. AuthorMobile string `description:"创建者手机号"`
  57. SyncReportId int `description:"同步后的report_id为english_report的ID"`
  58. //SourceReportId int `description:"原始报告ID"`
  59. ReportCoverUrl string `description:"原始报告封面图"`
  60. }
  61. func GetEnglishPolicyReportById(reportId int) (item *EnglishPolicyReportDetail, err error) {
  62. o := orm.NewOrmUsingDB("rddp")
  63. sql := `SELECT * FROM english_policy_report WHERE id=?`
  64. err = o.Raw(sql, reportId).QueryRow(&item)
  65. return
  66. }
  67. func GetEnglishPolicyReportBySourceReportId(sourceReportId int) (item *EnglishPolicyReport, err error) {
  68. o := orm.NewOrmUsingDB("rddp")
  69. sql := `SELECT * FROM english_policy_report WHERE source_report_id = ? LIMIT 1`
  70. err = o.Raw(sql, sourceReportId).QueryRow(&item)
  71. return
  72. }
  73. type EnglishPolicyReportList struct {
  74. Id int `orm:"column(id);pk;auto" description:"策略报告Id"`
  75. ClassifyIdFirst int `description:"一级分类id"`
  76. ClassifyNameFirst string `description:"一级分类名称"`
  77. ClassifyIdSecond int `description:"二级分类id"`
  78. ClassifyNameSecond string `description:"二级分类名称"`
  79. Title string `description:"标题"`
  80. Abstract string `description:"摘要"`
  81. Author string `description:"作者"`
  82. Frequency string `description:"频度"`
  83. //CreateTime string `description:"创建时间"`
  84. PublishTime string `description:"发布时间"`
  85. ModifyTime string `description:"修改时间"`
  86. State int `description:"1:未同步,2:已同步"`
  87. SyncTime string `description:"同步时间"`
  88. //Content string `description:"内容"`
  89. KeyTakeaways string `description:"关键点"`
  90. AuthorMobile string `description:"创建者手机号"`
  91. SyncReportId int `description:"同步后的report_id为english_report的ID"`
  92. //SourceReportId int `description:"原始报告ID"`
  93. ReportCoverUrl string `description:"原始报告封面图"`
  94. }
  95. type EnglishPolicyReportListResp struct {
  96. List []*EnglishPolicyReportList
  97. Paging *paging.PagingItem `description:"分页数据"`
  98. }
  99. func GetEnglishPolicyReportListCount(condition string, pars []interface{}) (count int, err error) {
  100. oRddp := orm.NewOrmUsingDB("rddp")
  101. sql := `SELECT COUNT(1) AS count FROM english_policy_report WHERE 1=1 `
  102. if condition != "" {
  103. sql += condition
  104. }
  105. err = oRddp.Raw(sql, pars).QueryRow(&count)
  106. return
  107. }
  108. func GetEnglishPolicyReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*EnglishPolicyReportList, err error) {
  109. o := orm.NewOrmUsingDB("rddp")
  110. //产品权限
  111. sql := `SELECT *
  112. FROM english_policy_report WHERE 1=1 `
  113. if condition != "" {
  114. sql += condition
  115. }
  116. sql += `ORDER BY publish_time DESC LIMIT ?,?`
  117. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  118. return
  119. }
  120. func GetEnglishPolicyReportByCondition(condition string, pars []interface{}) (items []*EnglishPolicyReport, err error) {
  121. o := orm.NewOrmUsingDB("rddp")
  122. sql := `SELECT *
  123. FROM english_policy_report WHERE 1=1 `
  124. if condition != "" {
  125. sql += condition
  126. }
  127. _, err = o.Raw(sql, pars).QueryRows(&items)
  128. return
  129. }
  130. type SyncEnglishPolicyReq struct {
  131. Id int `description:"策略报告id"`
  132. }
  133. type PullEnglishPolicyDataResp struct {
  134. Num int `description:"成功获取的记录数"`
  135. }
  136. // 同步报告
  137. func SyncEnglishPolicyReportById(id, newReportId int) (err error) {
  138. o := orm.NewOrmUsingDB("rddp")
  139. sql := `UPDATE english_policy_report SET state=2, sync_time=now(),modify_time=NOW(), sync_report_id=? WHERE id = ? `
  140. _, err = o.Raw(sql, newReportId, id).Exec()
  141. return
  142. }
  143. // 设置策略报告内容
  144. func SetEnglishPolicyReportContentBySourceReportId(sourceReportId int, content string) (err error) {
  145. o := orm.NewOrmUsingDB("rddp")
  146. sql := `UPDATE english_policy_report SET content=?, modify_time=NOW() WHERE source_report_id = ? `
  147. _, err = o.Raw(sql, content, sourceReportId).Exec()
  148. return
  149. }
  150. // 取消发布报告
  151. func SyncCancelEnglishPolicyReport(reportId int) (err error) {
  152. o := orm.NewOrmUsingDB("rddp")
  153. sql := ` UPDATE english_policy_report SET state=1,sync_time=null,modify_time=NOW(), sync_report_id=0 WHERE id =? `
  154. _, err = o.Raw(sql, reportId).Exec()
  155. return
  156. }
  157. // 删除报告
  158. func DeleteEnglishPolicyReport(reportIds int) (err error) {
  159. o := orm.NewOrmUsingDB("rddp")
  160. sql := ` DELETE FROM english_policy_report WHERE id =? `
  161. _, err = o.Raw(sql, reportIds).Exec()
  162. return
  163. }
  164. // Update 更新
  165. func (item *EnglishPolicyReport) Update(cols []string) (err error) {
  166. o := orm.NewOrmUsingDB("rddp")
  167. _, err = o.Update(item, cols...)
  168. return
  169. }
  170. // GetEnglishPolicyReportByIds 根据IDs获取英文报告列表
  171. func GetEnglishPolicyReportByIds(reportIds []int, fieldArr []string) (list []*EnglishPolicyReport, err error) {
  172. listLen := len(reportIds)
  173. if listLen == 0 {
  174. return
  175. }
  176. fields := ` * `
  177. if len(fieldArr) > 0 {
  178. fields = strings.Join(fieldArr, ",")
  179. }
  180. o := orm.NewOrmUsingDB("rddp")
  181. sql := `SELECT ` + fields + ` FROM english_policy_report WHERE id IN (` + utils.GetOrmInReplace(listLen) + `)`
  182. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  183. return
  184. }