report.go 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  1. package models
  2. import (
  3. "errors"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "github.com/beego/beego/v2/client/orm"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. )
  11. // 报告状态
  12. const (
  13. ReportStateUnpublished = 1 // 未发布
  14. ReportStatePublished = 2 // 已发布
  15. ReportStateWaitSubmit = 3 // 待提交
  16. ReportStateWaitApprove = 4 // 审批中
  17. ReportStateRefused = 5 // 已驳回
  18. ReportStatePass = 6 // 已通过
  19. )
  20. // 报告操作
  21. const (
  22. ReportOperateAdd = 1 // 新增报告
  23. ReportOperateEdit = 2 // 编辑报告
  24. ReportOperatePublish = 3 // 发布报告
  25. ReportOperateCancelPublish = 4 // 取消发布报告
  26. ReportOperateSubmitApprove = 5 // 提交审批
  27. ReportOperateCancelApprove = 6 // 撤回审批
  28. )
  29. type Report struct {
  30. Id int `orm:"column(id)" description:"报告Id"`
  31. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  32. ClassifyIdFirst int `description:"一级分类id"`
  33. ClassifyNameFirst string `description:"一级分类名称"`
  34. ClassifyIdSecond int `description:"二级分类id"`
  35. ClassifyNameSecond string `description:"二级分类名称"`
  36. Title string `description:"标题"`
  37. Abstract string `description:"摘要"`
  38. Author string `description:"作者"`
  39. Frequency string `description:"频度"`
  40. CreateTime string `description:"创建时间"`
  41. ModifyTime time.Time `description:"修改时间"`
  42. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  43. PublishTime time.Time `description:"发布时间"`
  44. Stage int `description:"期数"`
  45. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  46. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  47. Content string `description:"内容"`
  48. VideoUrl string `description:"音频文件URL"`
  49. VideoName string `description:"音频文件名称"`
  50. VideoPlaySeconds string `description:"音频播放时长"`
  51. VideoSize string `description:"音频文件大小,单位M"`
  52. ContentSub string `description:"内容前两个章节"`
  53. ReportCode string `description:"报告唯一编码"`
  54. ReportVersion int `description:"1:旧版,2:新版"`
  55. HasChapter int `description:"是否有章节 0-否 1-是"`
  56. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  57. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  58. MsgSendTime time.Time `description:"模版消息发送时间"`
  59. AdminId int `description:"创建者账号"`
  60. AdminRealName string `description:"创建者姓名"`
  61. ApproveTime time.Time `description:"审批时间"`
  62. ApproveId int `description:"审批ID"`
  63. DetailImgUrl string `description:"报告详情长图地址"`
  64. DetailPdfUrl string `description:"报告详情PDF地址"`
  65. ContentStruct string `description:"内容组件"`
  66. LastModifyAdminId int `description:"最后更新人ID"`
  67. LastModifyAdminName string `description:"最后更新人姓名"`
  68. ContentModifyTime time.Time `description:"内容更新时间"`
  69. Pv int `description:"pv"`
  70. Uv int `description:"uv"`
  71. HeadImg string `description:"报告头图地址"`
  72. EndImg string `description:"报告尾图地址"`
  73. CanvasColor string `description:"画布颜色"`
  74. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  75. HeadResourceId int `description:"版头资源ID"`
  76. EndResourceId int `description:"版尾资源ID"`
  77. ClassifyIdThird int `description:"三级分类id"`
  78. ClassifyNameThird string `description:"三级分类名称"`
  79. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  80. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  81. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  82. ReportCreateTime time.Time `description:"报告时间创建时间"`
  83. InheritReportId int `description:"待继承的报告ID"`
  84. VoiceGenerateType int `description:"音频生成方式,0:系统生成,1:人工上传"`
  85. }
  86. type ReportList struct {
  87. Id int `description:"报告Id"`
  88. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  89. ClassifyIdFirst int `description:"一级分类id"`
  90. ClassifyNameFirst string `description:"一级分类名称"`
  91. ClassifyIdSecond int `description:"二级分类id"`
  92. ClassifyNameSecond string `description:"二级分类名称"`
  93. Title string `description:"标题"`
  94. Abstract string `description:"摘要"`
  95. Author string `description:"作者"`
  96. Frequency string `description:"频度"`
  97. CreateTime string `description:"创建时间"`
  98. ModifyTime string `description:"修改时间"`
  99. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  100. PublishTime string `description:"发布时间"`
  101. PrePublishTime string `description:"预发布时间"`
  102. Stage int `description:"期数"`
  103. MsgIsSend int `description:"模板消息是否已发送,0:否,1:是"`
  104. Content string `description:"内容"`
  105. VideoUrl string `description:"音频文件URL"`
  106. VideoName string `description:"音频文件名称"`
  107. VideoPlaySeconds string `description:"音频播放时长"`
  108. ContentSub string `description:"内容前两个章节"`
  109. Pv int `description:"Pv"`
  110. Uv int `description:"Uv"`
  111. ReportCode string `description:"报告唯一编码"`
  112. ReportVersion int `description:"1:旧版,2:新版"`
  113. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  114. NeedThsMsg int `description:"是否需要推送客群消息 0-否 1-是"`
  115. HasChapter int `description:"是否有章节 0-否 1-是"`
  116. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  117. ChapterVideoList []*ReportChapterVideoList `description:"章节音频列表"`
  118. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  119. MsgSendTime string `description:"模版消息发送时间"`
  120. CanEdit bool `description:"是否可编辑"`
  121. HasAuth bool `description:"是否可操作"`
  122. Editor string `description:"编辑人"`
  123. AdminId int `description:"创建者账号"`
  124. AdminRealName string `description:"创建者姓名"`
  125. ApproveTime string `description:"审批时间"`
  126. DetailImgUrl string `description:"报告详情长图地址"`
  127. DetailPdfUrl string `description:"报告详情PDF地址"`
  128. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  129. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  130. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  131. ReportCreateTime time.Time `description:"报告时间创建时间"`
  132. ContentStruct string `description:"内容组件"`
  133. LastModifyAdminId int `description:"最后更新人ID"`
  134. LastModifyAdminName string `description:"最后更新人姓名"`
  135. ContentModifyTime time.Time `description:"内容更新时间"`
  136. HeadImg string `description:"报告头图地址"`
  137. EndImg string `description:"报告尾图地址"`
  138. CanvasColor string `description:"画布颜色"`
  139. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  140. HeadResourceId int `description:"版头资源ID"`
  141. EndResourceId int `description:"版尾资源ID"`
  142. ClassifyIdThird int `description:"三级分类id"`
  143. ClassifyNameThird string `description:"三级分类名称"`
  144. InheritReportId int `description:"待继承的报告ID"`
  145. }
  146. type ReportListResp struct {
  147. List []*ReportList
  148. Paging *paging.PagingItem `description:"分页数据"`
  149. }
  150. // GetReportListCountV1
  151. // @Description: 获取普通报告列表的报告数量
  152. // @author: Roc
  153. // @datetime 2024-05-30 15:14:43
  154. // @param condition string
  155. // @param pars []interface{}
  156. // @return count int
  157. // @return err error
  158. func GetReportListCountV1(condition string, pars []interface{}) (count int, err error) {
  159. o := orm.NewOrmUsingDB("rddp")
  160. sql := `SELECT COUNT(1) AS count FROM report as a left join chart_permission_search_key_word_mapping b on
  161. a.classify_id_first = b.classify_id WHERE 1=1 `
  162. if condition != "" {
  163. sql += condition
  164. }
  165. err = o.Raw(sql, pars).QueryRow(&count)
  166. return
  167. }
  168. // GetReportListV1
  169. // @Description: 获取普通报告列表的数据
  170. // @author: Roc
  171. // @datetime 2024-05-30 15:14:25
  172. // @param condition string
  173. // @param pars []interface{}
  174. // @param startSize int
  175. // @param pageSize int
  176. // @return items []*ReportList
  177. // @return err error
  178. func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  179. o := orm.NewOrmUsingDB("rddp")
  180. sql := `SELECT * FROM report as a WHERE 1=1 `
  181. if condition != "" {
  182. sql += condition
  183. }
  184. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  185. sql += ` ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  186. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  187. return
  188. }
  189. // GetReportListByCondition 获取报告列表
  190. func GetReportListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  191. o := orm.NewOrmUsingDB("rddp")
  192. sql := `SELECT a.id, a.title, a.author, a.modify_time, a.publish_time,a.classify_id_first,
  193. a.classify_name_first,a.classify_id_second,a.classify_name_second,a.classify_id_third,
  194. a.classify_name_third FROM report as a left join chart_permission_search_key_word_mapping b on
  195. a.classify_id_first = b.classify_id WHERE 1=1 `
  196. if condition != "" {
  197. sql += condition
  198. }
  199. sql += ` LIMIT ?,?`
  200. _, err = o.Raw(sql, pars, (startSize-1)*pageSize, pageSize).QueryRows(&items)
  201. return
  202. }
  203. type ReportPvUv struct {
  204. ReportId int
  205. PvTotal int
  206. UvTotal int
  207. }
  208. func GetReportPvUvByReportIdList(reportIdList []int) (items []ReportPvUv, err error) {
  209. num := len(reportIdList)
  210. if num <= 0 {
  211. return
  212. }
  213. o := orm.NewOrmUsingDB("rddp")
  214. sql := `SELECT report_id, COUNT(1) as pv_total,COUNT(DISTINCT user_id) as uv_total FROM report_view_record WHERE report_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY report_id`
  215. _, err = o.Raw(sql, reportIdList).QueryRows(&items)
  216. return
  217. }
  218. // GetReportListCountByGrant
  219. // @Description: 获取共享报告列表的报告数量
  220. // @author: Roc
  221. // @datetime 2024-05-30 15:14:01
  222. // @param condition string
  223. // @param pars []interface{}
  224. // @return count int
  225. // @return err error
  226. func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
  227. o := orm.NewOrmUsingDB("rddp")
  228. sql := `SELECT a.id FROM report as a
  229. JOIN report_grant b on a.id=b.report_id
  230. WHERE 1=1 `
  231. if condition != "" {
  232. sql += condition
  233. }
  234. sql += " GROUP BY a.id "
  235. sql = `SELECT COUNT(1) AS count FROM (` + sql + `) d`
  236. err = o.Raw(sql, pars).QueryRow(&count)
  237. return
  238. }
  239. // GetReportListByGrant
  240. // @Description: 获取共享报告列表的数据
  241. // @author: Roc
  242. // @datetime 2024-05-30 15:15:07
  243. // @param condition string
  244. // @param pars []interface{}
  245. // @param startSize int
  246. // @param pageSize int
  247. // @return items []*ReportList
  248. // @return err error
  249. func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  250. o := orm.NewOrmUsingDB("rddp")
  251. sql := `SELECT a.* FROM report as a JOIN report_grant b on a.id = b.report_id WHERE 1=1 `
  252. if condition != "" {
  253. sql += condition
  254. }
  255. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  256. sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), a.modify_time DESC LIMIT ?,?`
  257. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  258. return
  259. }
  260. func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
  261. oRddp := orm.NewOrmUsingDB("rddp")
  262. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 `
  263. if condition != "" {
  264. sql += condition
  265. }
  266. err = oRddp.Raw(sql, pars).QueryRow(&count)
  267. return
  268. }
  269. func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  270. o := orm.NewOrmUsingDB("rddp")
  271. sql := `SELECT *,
  272. (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
  273. (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
  274. FROM report WHERE 1=1 `
  275. if condition != "" {
  276. sql += condition
  277. }
  278. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  279. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  280. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  281. return
  282. }
  283. // PublishReport 发布报告
  284. func PublishReport(reportIds []int) (err error) {
  285. if len(reportIds) == 0 {
  286. return
  287. }
  288. o := orm.NewOrmUsingDB("rddp")
  289. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  290. _, err = o.Raw(sql).Exec()
  291. return
  292. }
  293. // PublishCancelReport 取消发布报告
  294. func PublishCancelReport(reportId, state int, publishTimeNullFlag bool, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  295. o := orm.NewOrmUsingDB("rddp")
  296. var sql string
  297. if publishTimeNullFlag {
  298. sql = ` UPDATE report SET state=?, publish_time=null, pre_publish_time=null, pre_msg_send=0,last_modify_admin_id=?,last_modify_admin_name=?,modify_time = NOW() WHERE id =?`
  299. } else {
  300. sql = ` UPDATE report SET state=?, pre_publish_time=null, pre_msg_send=0,last_modify_admin_id=?,last_modify_admin_name=?,modify_time = NOW() WHERE id =?`
  301. }
  302. _, err = o.Raw(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  303. return
  304. }
  305. // 删除报告
  306. func DeleteReport(reportIds int) (err error) {
  307. o := orm.NewOrmUsingDB("rddp")
  308. sql := ` DELETE FROM report WHERE id =? `
  309. _, err = o.Raw(sql, reportIds).Exec()
  310. return
  311. }
  312. type ReportDetail struct {
  313. Id int `orm:"column(id)" description:"报告Id"`
  314. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  315. ClassifyIdFirst int `description:"一级分类id"`
  316. ClassifyNameFirst string `description:"一级分类名称"`
  317. ClassifyIdSecond int `description:"二级分类id"`
  318. ClassifyNameSecond string `description:"二级分类名称"`
  319. Title string `description:"标题"`
  320. Abstract string `description:"摘要"`
  321. Author string `description:"作者"`
  322. Frequency string `description:"频度"`
  323. CreateTime string `description:"创建时间"`
  324. ModifyTime string `description:"修改时间"`
  325. State int `description:"1:未发布,2:已发布"`
  326. PublishTime string `description:"发布时间"`
  327. PrePublishTime string `description:"预发布时间"`
  328. Stage int `description:"期数"`
  329. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  330. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  331. Content string `description:"内容"`
  332. VideoUrl string `description:"音频文件URL"`
  333. VideoName string `description:"音频文件名称"`
  334. VideoPlaySeconds string `description:"音频播放时长"`
  335. ContentSub string `description:"内容前两个章节"`
  336. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  337. HasChapter int `description:"是否有章节 0-否 1-是"`
  338. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  339. AdminId int `description:"创建者账号"`
  340. AdminRealName string `description:"创建者姓名"`
  341. ReportCode string `description:"报告唯一编码"`
  342. // eta1.8.3(研报改版)相关内容
  343. ContentStruct string `description:"内容组件"`
  344. LastModifyAdminId int `description:"最后更新人ID"`
  345. LastModifyAdminName string `description:"最后更新人姓名"`
  346. ContentModifyTime time.Time `description:"内容更新时间"`
  347. Pv int `description:"pv"`
  348. Uv int `description:"uv"`
  349. HeadImg string `description:"报告头图地址"`
  350. EndImg string `description:"报告尾图地址"`
  351. HeadStyle string `description:"版头样式"`
  352. EndStyle string `description:"版尾样式"`
  353. CanvasColor string `description:"画布颜色"`
  354. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  355. HeadResourceId int `description:"版头资源ID"`
  356. EndResourceId int `description:"版尾资源ID"`
  357. ClassifyIdThird int `description:"三级分类id"`
  358. ClassifyNameThird string `description:"三级分类名称"`
  359. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  360. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  361. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  362. ReportCreateTime time.Time `description:"报告时间创建时间"`
  363. }
  364. func GetReportById(reportId int) (item *ReportDetail, err error) {
  365. o := orm.NewOrmUsingDB("rddp")
  366. sql := `SELECT * FROM report WHERE id=?`
  367. err = o.Raw(sql, reportId).QueryRow(&item)
  368. return
  369. }
  370. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  371. o := orm.NewOrmUsingDB("rddp")
  372. sql := `SELECT * FROM report WHERE id in ` + reportIds
  373. _, err = o.Raw(sql).QueryRows(&list)
  374. return
  375. }
  376. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  377. func GetSimpleReportByIds(reportIds []int) (list []*Report, err error) {
  378. if len(reportIds) == 0 {
  379. return
  380. }
  381. o := orm.NewOrmUsingDB("rddp")
  382. sql := `SELECT id, title, report_code FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  383. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  384. return
  385. }
  386. // GetReportStage
  387. // @Description: 获取报告的最大期数(每一年的最大期数)
  388. // @author: Roc
  389. // @datetime 2024-06-03 17:44:14
  390. // @param classifyIdFirst int
  391. // @param classifyIdSecond int
  392. // @param classifyIdThird int
  393. // @return count int
  394. // @return err error
  395. func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (count int, err error) {
  396. o := orm.NewOrmUsingDB("rddp")
  397. classifyId := classifyIdThird
  398. if classifyId <= 0 {
  399. classifyId = classifyIdSecond
  400. }
  401. if classifyId <= 0 {
  402. classifyId = classifyIdFirst
  403. }
  404. if classifyId <= 0 {
  405. err = errors.New("错误的分类id")
  406. return
  407. }
  408. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  409. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? `
  410. if classifyIdThird > 0 {
  411. sql += " AND classify_id_third = ? "
  412. } else if classifyIdSecond > 0 {
  413. sql += " AND classify_id_second = ? "
  414. } else {
  415. sql += " AND classify_id_first = ? "
  416. }
  417. o.Raw(sql, yearStart, classifyId).QueryRow(&count)
  418. return
  419. }
  420. // GetReportStageEdit
  421. // @Description: 获取报告的最大期数(每一年的最大期数)
  422. // @author: Roc
  423. // @datetime 2024-06-04 13:50:34
  424. // @param classifyIdFirst int
  425. // @param classifyIdSecond int
  426. // @param classifyIdThird int
  427. // @param reportId int
  428. // @return count int
  429. // @return err error
  430. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, classifyIdThird, reportId int) (count int, err error) {
  431. classifyId := classifyIdThird
  432. if classifyId <= 0 {
  433. classifyId = classifyIdSecond
  434. }
  435. if classifyId <= 0 {
  436. classifyId = classifyIdFirst
  437. }
  438. if classifyId <= 0 {
  439. err = errors.New("错误的分类id")
  440. return
  441. }
  442. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  443. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? AND id<>? `
  444. if classifyIdThird > 0 {
  445. sql += " AND classify_id_third = ? "
  446. } else if classifyIdSecond > 0 {
  447. sql += " AND classify_id_second = ? "
  448. } else {
  449. sql = " AND classify_id_first = ? "
  450. }
  451. o := orm.NewOrmUsingDB("rddp")
  452. o.Raw(sql, yearStart, reportId, classifyId).QueryRow(&count)
  453. return
  454. }
  455. type PublishReq struct {
  456. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  457. ReportUrl string `description:"报告Url"`
  458. }
  459. type PublishCancelReq struct {
  460. ReportIds int `description:"报告id"`
  461. }
  462. type DeleteReq struct {
  463. ReportIds int `description:"报告id"`
  464. }
  465. type AddReq struct {
  466. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  467. ClassifyIdFirst int `description:"一级分类id"`
  468. ClassifyNameFirst string `description:"一级分类名称"`
  469. ClassifyIdSecond int `description:"二级分类id"`
  470. ClassifyNameSecond string `description:"二级分类名称"`
  471. ClassifyIdThird int `description:"三级分类id"`
  472. ClassifyNameThird string `description:"三级分类名称"`
  473. Title string `description:"标题"`
  474. Abstract string `description:"摘要"`
  475. Author string `description:"作者"`
  476. Frequency string `description:"频度"`
  477. State int `description:"状态:1:未发布,2:已发布"`
  478. Content string `description:"内容"`
  479. CreateTime string `description:"创建时间"`
  480. ReportVersion int `description:"1:旧版,2:新版"`
  481. ContentStruct string `description:"内容组件"`
  482. HeadImg string `description:"报告头图地址"`
  483. EndImg string `description:"报告尾图地址"`
  484. CanvasColor string `description:"画布颜色"`
  485. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  486. HeadResourceId int `description:"版头资源ID"`
  487. EndResourceId int `description:"版尾资源ID"`
  488. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  489. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  490. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  491. InheritReportId int `description:"待继承的报告ID"`
  492. GrantAdminIdList []int `description:"授权用户id列表"`
  493. }
  494. type PrePublishReq struct {
  495. ReportId int `description:"报告id"`
  496. PrePublishTime string `description:"预发布时间"`
  497. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  498. ReportUrl string `description:"报告Url"`
  499. }
  500. type AddResp struct {
  501. ReportId int64 `description:"报告id"`
  502. ReportCode string `description:"报告code"`
  503. }
  504. func AddReport(item *Report) (lastId int64, err error) {
  505. o := orm.NewOrmUsingDB("rddp")
  506. lastId, err = o.Insert(item)
  507. return
  508. }
  509. type EditReq struct {
  510. ReportId int64 `description:"报告id"`
  511. ClassifyIdFirst int `description:"一级分类id"`
  512. ClassifyNameFirst string `description:"一级分类名称"`
  513. ClassifyIdSecond int `description:"二级分类id"`
  514. ClassifyNameSecond string `description:"二级分类名称"`
  515. ClassifyIdThird int `description:"三级分类id"`
  516. ClassifyNameThird string `description:"三级分类名称"`
  517. Title string `description:"标题"`
  518. Abstract string `description:"摘要"`
  519. Author string `description:"作者"`
  520. Frequency string `description:"频度"`
  521. State int `description:"状态:1:未发布,2:已发布"`
  522. Content string `description:"内容"`
  523. CreateTime string `description:"创建时间"`
  524. ContentStruct string `description:"内容组件"`
  525. HeadImg string `description:"报告头图地址"`
  526. EndImg string `description:"报告尾图地址"`
  527. CanvasColor string `description:"画布颜色"`
  528. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  529. HeadResourceId int `description:"版头资源ID"`
  530. EndResourceId int `description:"版尾资源ID"`
  531. //CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  532. //ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  533. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  534. GrantAdminIdList []int `description:"授权用户id列表"`
  535. }
  536. type EditResp struct {
  537. ReportId int64 `description:"报告id"`
  538. ReportCode string `description:"报告code"`
  539. }
  540. func EditReport(item *Report, reportId int64) (err error) {
  541. o := orm.NewOrmUsingDB("rddp")
  542. sql := `UPDATE report
  543. SET
  544. classify_id_first =?,
  545. classify_name_first = ?,
  546. classify_id_second = ?,
  547. classify_name_second = ?,
  548. title = ?,
  549. abstract = ?,
  550. author = ?,
  551. frequency = ?,
  552. state = ?,
  553. content = ?,
  554. content_sub = ?,
  555. stage =?,
  556. create_time = ?,
  557. modify_time = ?
  558. WHERE id = ? `
  559. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  560. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  561. return
  562. }
  563. func (m *Report) Update(cols []string) (err error) {
  564. o := orm.NewOrmUsingDB("rddp")
  565. _, err = o.Update(m, cols...)
  566. return
  567. }
  568. type ReportDetailReq struct {
  569. ReportId int `description:"报告id"`
  570. }
  571. type ClassifyIdDetailReq struct {
  572. ClassifyIdFirst int `description:"报告一级分类id"`
  573. ClassifyIdSecond int `description:"报告二级分类id"`
  574. }
  575. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  576. o := orm.NewOrmUsingDB("rddp")
  577. sql := ` SELECT * FROM report WHERE 1=1 `
  578. if classifyIdSecond > 0 {
  579. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  580. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  581. } else {
  582. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  583. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  584. }
  585. return
  586. }
  587. type SendTemplateMsgReq struct {
  588. ReportId int `description:"报告id"`
  589. }
  590. // SendTemplateMsgResp
  591. // @Description: 报告推送返回结构体
  592. type SendTemplateMsgResp struct {
  593. ReportId int `description:"报告id"`
  594. MsgSendTime string `description:"报告推送时间"`
  595. }
  596. func ModifyReportMsgIsSend(reportId int) (err error) {
  597. o := orm.NewOrmUsingDB("rddp")
  598. report, err := GetReportById(reportId)
  599. if err != nil {
  600. return
  601. }
  602. if report.MsgIsSend == 0 {
  603. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  604. _, err = o.Raw(sql, reportId).Exec()
  605. }
  606. return
  607. }
  608. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  609. o := orm.NewOrmUsingDB("rddp")
  610. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  611. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  612. return
  613. }
  614. // ModifyReportVideoByNoVideo
  615. // @Description: 修改无音频的报告音频信息
  616. // @author: Roc
  617. // @datetime 2024-07-25 18:03:05
  618. // @param reportId int
  619. // @param videoUrl string
  620. // @param videoName string
  621. // @param videoSize string
  622. // @param playSeconds float64
  623. // @return err error
  624. func ModifyReportVideoByNoVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  625. o := orm.NewOrmUsingDB("rddp")
  626. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? AND video_url=""`
  627. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  628. return
  629. }
  630. type ReportItem struct {
  631. Id int `orm:"column(id)" description:"报告Id"`
  632. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  633. ClassifyIdFirst int `description:"一级分类id"`
  634. ClassifyNameFirst string `description:"一级分类名称"`
  635. ClassifyIdSecond int `description:"二级分类id"`
  636. ClassifyNameSecond string `description:"二级分类名称"`
  637. Title string `description:"标题"`
  638. Abstract string `description:"摘要"`
  639. Author string `description:"作者"`
  640. Frequency string `description:"频度"`
  641. CreateTime time.Time `description:"创建时间"`
  642. ModifyTime time.Time `description:"修改时间"`
  643. State int `description:"1:未发布,2:已发布"`
  644. PublishTime time.Time `description:"发布时间"`
  645. Stage int `description:"期数"`
  646. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  647. Content string `description:"内容"`
  648. VideoUrl string `description:"音频文件URL"`
  649. VideoName string `description:"音频文件名称"`
  650. VideoPlaySeconds string `description:"音频播放时长"`
  651. ContentSub string `description:"内容前两个章节"`
  652. }
  653. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  654. o := orm.NewOrmUsingDB("rddp")
  655. sql := `SELECT * FROM report WHERE id=?`
  656. err = o.Raw(sql, reportId).QueryRow(&item)
  657. return
  658. }
  659. type SaveReportContent struct {
  660. Content string `description:"内容"`
  661. ReportId int `description:"报告id"`
  662. NoChange int `description:"内容是否未改变:1:内容未改变"`
  663. // 以下是智能研报相关
  664. ContentStruct string `description:"内容组件"`
  665. HeadImg string `description:"报告头图地址"`
  666. EndImg string `description:"报告尾图地址"`
  667. CanvasColor string `description:"画布颜色"`
  668. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  669. HeadResourceId int `description:"版头资源ID"`
  670. EndResourceId int `description:"版尾资源ID"`
  671. }
  672. func EditReportContent(reportId int, content, contentSub string) (err error) {
  673. o := orm.NewOrmUsingDB("rddp")
  674. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  675. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  676. return
  677. }
  678. func AddReportSaveLog(reportId, adminId int, content, contentSub, contentStruct, canvasColor, adminName string, headResourceId, endResourceId int) (err error) {
  679. o := orm.NewOrmUsingDB("rddp")
  680. sql := ` INSERT INTO report_save_log(report_id, content,content_sub,content_struct,canvas_color,head_resource_id,end_resource_id,admin_id,admin_name) VALUES (?,?,?,?,?,?,?,?,?) `
  681. _, err = o.Raw(sql, reportId, content, contentSub, contentStruct, canvasColor, headResourceId, endResourceId, adminId, adminName).Exec()
  682. return
  683. }
  684. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  685. o := orm.NewOrmUsingDB("rddp")
  686. p, err := o.Raw(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub,content_struct,admin_id, admin_name) VALUES (?,?,?,?,?,?,?)`).Prepare()
  687. if err != nil {
  688. return
  689. }
  690. defer func() {
  691. _ = p.Close()
  692. }()
  693. for _, v := range items {
  694. _, err = p.Exec(v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, v.ContentStruct, adminId, adminRealName)
  695. if err != nil {
  696. return
  697. }
  698. }
  699. return
  700. }
  701. type SaveReportContentResp struct {
  702. ReportId int `description:"报告id"`
  703. }
  704. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  705. o := orm.NewOrmUsingDB("rddp")
  706. sql := `UPDATE report SET report_code=? WHERE id=? `
  707. _, err = o.Raw(sql, reportCode, reportId).Exec()
  708. return
  709. }
  710. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  711. o := orm.NewOrmUsingDB("rddp")
  712. if item.ThsMsgIsSend == 0 {
  713. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  714. _, err = o.Raw(sql, item.Id).Exec()
  715. }
  716. return
  717. }
  718. type ThsSendTemplateMsgReq struct {
  719. ReportId []int `description:"报告id"`
  720. }
  721. type PublishDayWeekReportReq struct {
  722. ReportId int `description:"报告ID"`
  723. }
  724. // SaveDayWeekReportReq 新增晨报周报请求体
  725. type SaveDayWeekReportReq struct {
  726. ReportId int `description:"报告ID"`
  727. Title string `description:"标题"`
  728. ReportType string `description:"一级分类ID"`
  729. Author string `description:"作者"`
  730. CreateTime string `description:"创建时间"`
  731. }
  732. // GetDayWeekReportStage 获取晨报周报期数
  733. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  734. o := orm.NewOrmUsingDB("rddp")
  735. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  736. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  737. return
  738. }
  739. // GetReportByReportId 主键获取报告
  740. func GetReportByReportId(reportId int) (item *Report, err error) {
  741. o := orm.NewOrmUsingDB("rddp")
  742. sql := `SELECT * FROM report WHERE id = ?`
  743. err = o.Raw(sql, reportId).QueryRow(&item)
  744. return
  745. }
  746. // GetReportByOldReportId 根据老报告id主键获取报告
  747. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  748. o := orm.NewOrmUsingDB("rddp")
  749. sql := `SELECT * FROM report WHERE old_report_id = ?`
  750. err = o.Raw(sql, reportId).QueryRow(&item)
  751. return
  752. }
  753. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  754. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  755. o := orm.NewOrmUsingDB("rddp")
  756. to, err := o.Begin()
  757. if err != nil {
  758. return
  759. }
  760. defer func() {
  761. if err != nil {
  762. _ = to.Rollback()
  763. } else {
  764. _ = to.Commit()
  765. }
  766. }()
  767. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  768. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  769. return
  770. }
  771. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  772. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  773. return
  774. }
  775. return
  776. }
  777. // UpdateReport 更新报告
  778. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  779. o := orm.NewOrmUsingDB("rddp")
  780. _, err = o.Update(reportInfo, cols...)
  781. return
  782. }
  783. // ReportDetailView
  784. // @Description: 晨周报详情
  785. type ReportDetailView struct {
  786. *ReportDetail
  787. ChapterList []*ReportChapter
  788. GrandAdminList []ReportDetailViewAdmin
  789. PermissionList []ReportDetailViewPermission
  790. }
  791. // ReportDetailViewAdmin
  792. // @Description: 报告里面的授权人
  793. type ReportDetailViewAdmin struct {
  794. AdminId int
  795. AdminName string
  796. }
  797. // ReportDetailViewPermission
  798. // @Description: 报告分类关联的品种权限
  799. type ReportDetailViewPermission struct {
  800. PermissionId int
  801. PermissionName string
  802. }
  803. func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  804. o := orm.NewOrmUsingDB("rddp")
  805. sql := ` SELECT
  806. *
  807. FROM
  808. report AS a
  809. WHERE
  810. a.has_chapter = 1
  811. AND a.chapter_type = "day"
  812. AND a.state = 1
  813. AND (
  814. a.create_time BETWEEN ? AND ?
  815. )
  816. ORDER BY
  817. a.create_time DESC
  818. LIMIT 1 `
  819. err = o.Raw(sql, startTime, endTime).QueryRow(&item)
  820. return
  821. }
  822. type ElasticReportDetail struct {
  823. ReportId int `description:"报告ID"`
  824. ReportChapterId int `description:"报告章节ID"`
  825. Title string `description:"标题"`
  826. Abstract string `description:"摘要"`
  827. BodyContent string `description:"内容"`
  828. PublishTime string `description:"发布时间"`
  829. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  830. Author string `description:"作者"`
  831. ClassifyIdFirst int `description:"一级分类ID"`
  832. ClassifyNameFirst string `description:"一级分类名称"`
  833. ClassifyIdSecond int `description:"二级分类ID"`
  834. ClassifyNameSecond string `description:"二级分类名称"`
  835. ClassifyId int `description:"最小单元的分类ID"`
  836. ClassifyName string `description:"最小单元的分类名称"`
  837. Categories string `description:"关联的品种名称(包括品种别名)"`
  838. StageStr string `description:"报告期数"`
  839. }
  840. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  841. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  842. o := orm.NewOrmUsingDB("rddp")
  843. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  844. err = o.Raw(sql, chapterType).QueryRow(&item)
  845. return
  846. }
  847. // GetNewReportExist
  848. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  849. o := orm.NewOrmUsingDB("rddp")
  850. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  851. err = o.Raw(sql, oldReportId).QueryRow(&item)
  852. return
  853. }
  854. // PublishReportAndChapter 发布报告及章节
  855. func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
  856. o := orm.NewOrmUsingDB("rddp")
  857. to, err := o.Begin()
  858. if err != nil {
  859. return
  860. }
  861. defer func() {
  862. if err != nil {
  863. _ = to.Rollback()
  864. } else {
  865. _ = to.Commit()
  866. }
  867. }()
  868. // 更新报告
  869. if isPublishReport {
  870. _, err = to.Update(reportInfo, cols...)
  871. if err != nil {
  872. return
  873. }
  874. }
  875. // 发布该报告的所有章节
  876. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  877. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
  878. // 发布章节
  879. //if len(publishIds) > 0 {
  880. // sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  881. // _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  882. //}
  883. //if len(unPublishIds) > 0 {
  884. // sql := ` UPDATE report_chapter SET publish_state = 1, publish_time = NULL, is_edit = 0 WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(unPublishIds)) + `) `
  885. // _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  886. //}
  887. return
  888. }
  889. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  890. o := orm.NewOrmUsingDB("rddp")
  891. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  892. UNION ALL
  893. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  894. _, err = o.Raw(sql).QueryRows(&list)
  895. return
  896. }
  897. // PublishReportById 发布报告
  898. func PublishReportById(reportId int, publishTime time.Time, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  899. o := orm.NewOrmUsingDB("rddp")
  900. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW(),last_modify_admin_id=?,last_modify_admin_name=? WHERE id = ? `
  901. _, err = o.Raw(sql, publishTime, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  902. return
  903. }
  904. // ResetReportById 重置报告状态
  905. func ResetReportById(reportId, state int, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  906. o := orm.NewOrmUsingDB("rddp")
  907. sql := `UPDATE report SET state = ?, pre_publish_time = null, pre_msg_send = 0, modify_time = NOW(),last_modify_admin_id=?,last_modify_admin_name=? WHERE id = ?`
  908. _, err = o.Raw(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  909. return
  910. }
  911. // GetCommentReportByReportId 查询有留言的报告列表
  912. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  913. o := orm.NewOrmUsingDB("rddp")
  914. sql := `SELECT
  915. id,
  916. create_time,
  917. title,
  918. classify_name_first,
  919. classify_id_first,
  920. classify_name_second,
  921. classify_id_second,
  922. state,
  923. IF
  924. ( publish_time, publish_time, create_time ) AS publish_time
  925. FROM
  926. report
  927. WHERE
  928. 1=1
  929. `
  930. if condition != "" {
  931. sql += condition
  932. }
  933. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  934. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  935. return
  936. }
  937. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  938. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  939. o := orm.NewOrmUsingDB("rddp")
  940. sql := `SELECT
  941. id,
  942. create_time,
  943. title,
  944. classify_name_first,
  945. classify_id_first,
  946. classify_name_second,
  947. classify_id_second,
  948. state,
  949. IF
  950. ( publish_time, publish_time, create_time ) AS publish_time
  951. FROM
  952. report
  953. WHERE
  954. 1=1
  955. `
  956. if condition != "" {
  957. sql += condition
  958. }
  959. if orderBy == `` {
  960. sql += ` ORDER BY publish_time DESC , title ASC `
  961. } else {
  962. sql += orderBy
  963. }
  964. sql += ` LIMIT ?,? `
  965. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  966. return
  967. }
  968. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  969. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  970. o := orm.NewOrmUsingDB("rddp")
  971. sql := `SELECT count(*)
  972. FROM report WHERE 1=1`
  973. if condition != "" {
  974. sql += condition
  975. }
  976. err = o.Raw(sql, pars).QueryRow(&total)
  977. return
  978. }
  979. // 点赞相关的报告列表
  980. type LikeReportItem struct {
  981. ReportId int `description:"报告Id"`
  982. ReportChapterId int `description:"报告章节Id"`
  983. ClassifyIdFirst int `description:"一级分类id"`
  984. ClassifyNameFirst string `description:"一级分类名称"`
  985. ClassifyIdSecond int `description:"二级分类id"`
  986. ClassifyNameSecond string `description:"二级分类名称"`
  987. ReportChapterTypeId int `description:"章节类型"`
  988. ReportChapterTypeName string `description:"品种名称"`
  989. PublishTime time.Time `description:"发布时间" `
  990. Title string `description:"标题"`
  991. }
  992. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  993. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  994. o := orm.NewOrmUsingDB("rddp")
  995. sql := `( SELECT
  996. id AS report_id,
  997. 0 AS report_chapter_id,
  998. classify_id_first,
  999. classify_id_second,
  1000. classify_name_first,
  1001. classify_name_second,
  1002. 0 as report_chapter_type_id,
  1003. "" as report_chapter_type_name,
  1004. publish_time,
  1005. title
  1006. FROM
  1007. report
  1008. WHERE
  1009. classify_name_first != "晨报"
  1010. AND classify_name_first != "周报"
  1011. AND id in (` + reportIds + `)
  1012. )
  1013. UNION
  1014. ( SELECT
  1015. report_id,
  1016. report_chapter_id,
  1017. classify_id_first,
  1018. 0 as classify_id_second,
  1019. classify_name_first,
  1020. null as classify_name_second,
  1021. type_id as report_chapter_type_id,
  1022. type_name as report_chapter_type_name,
  1023. publish_time,
  1024. title
  1025. FROM
  1026. report_chapter
  1027. WHERE
  1028. report_chapter_id in (` + chapterIds + `)
  1029. )`
  1030. if orderStr != "" {
  1031. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  1032. } else {
  1033. sql += ` ORDER BY publish_time DESC, report_id Desc`
  1034. }
  1035. sql += ` LIMIT ?,?`
  1036. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  1037. return
  1038. }
  1039. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  1040. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  1041. o := orm.NewOrmUsingDB("rddp")
  1042. sql := `select count(*) from (( SELECT
  1043. id AS report_id,
  1044. 0 AS report_chapter_id,
  1045. classify_id_first,
  1046. classify_id_second,
  1047. classify_name_first,
  1048. classify_name_second,
  1049. 0 as report_chapter_type_id,
  1050. publish_time,
  1051. title
  1052. FROM
  1053. report
  1054. WHERE
  1055. classify_name_first != "晨报"
  1056. AND classify_name_first != "周报"
  1057. AND id in (` + reportIds + `)
  1058. )
  1059. UNION
  1060. ( SELECT
  1061. report_id,
  1062. report_chapter_id,
  1063. classify_id_first,
  1064. 0 as classify_id_second,
  1065. classify_name_first,
  1066. null as classify_name_second,
  1067. type_id as report_chapter_type_id,
  1068. publish_time,
  1069. title
  1070. FROM
  1071. report_chapter
  1072. WHERE
  1073. report_chapter_id in (` + chapterIds + `)
  1074. )) r`
  1075. err = o.Raw(sql).QueryRow(&total)
  1076. return
  1077. }
  1078. // GetPageReportList 分页获取报告列表
  1079. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  1080. o := orm.NewOrmUsingDB("rddp")
  1081. sql := `SELECT * FROM report WHERE 1=1 `
  1082. sql += condition
  1083. sql += ` ORDER BY modify_time DESC`
  1084. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1085. err = o.Raw(totalSql, pars).QueryRow(&total)
  1086. if err != nil {
  1087. return
  1088. }
  1089. sql += ` LIMIT ?,? `
  1090. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1091. return
  1092. }
  1093. // SunCodeReq 获取太阳码请求体
  1094. type SunCodeReq struct {
  1095. CodePage string `json:"CodePage" description:"太阳码page"`
  1096. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  1097. }
  1098. // YbPcSuncode 活动海报表
  1099. type YbPcSuncode struct {
  1100. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  1101. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  1102. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  1103. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  1104. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  1105. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  1106. }
  1107. // GetYbPcSunCode 获取太阳码
  1108. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  1109. o := orm.NewOrmUsingDB("weekly")
  1110. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  1111. err = o.Raw(sql, scene, page).QueryRow(&item)
  1112. return
  1113. }
  1114. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  1115. o := orm.NewOrmUsingDB("weekly")
  1116. _, err = o.Insert(item)
  1117. return
  1118. }
  1119. // YbSuncodePars 小程序太阳码scene参数
  1120. type YbSuncodePars struct {
  1121. ID uint32 `orm:"column(id);pk" `
  1122. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  1123. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  1124. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  1125. }
  1126. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  1127. o := orm.NewOrmUsingDB("weekly")
  1128. _, err = o.Insert(item)
  1129. return
  1130. }
  1131. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  1132. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1133. o := orm.NewOrmUsingDB("rddp")
  1134. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  1135. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1136. return
  1137. }
  1138. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  1139. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1140. o := orm.NewOrmUsingDB("rddp")
  1141. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  1142. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1143. return
  1144. }
  1145. // UpdateReportThirdClassifyNameByClassifyId 更新报告的三级分类名称字段
  1146. func UpdateReportThirdClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1147. o := orm.NewOrmUsingDB("rddp")
  1148. sql := " UPDATE report SET classify_name_third = ? WHERE classify_id_third = ? "
  1149. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1150. return
  1151. }
  1152. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  1153. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  1154. o := orm.NewOrmUsingDB("rddp")
  1155. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  1156. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  1157. return
  1158. }
  1159. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  1160. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  1161. sql := `SELECT
  1162. r.id,
  1163. r.content,
  1164. r.content_sub
  1165. FROM
  1166. report AS r
  1167. JOIN ppt_v2 AS p ON r.id = p.report_id
  1168. WHERE
  1169. p.report_id > 0 AND r.content_sub = ""`
  1170. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  1171. return
  1172. }
  1173. // ModifyReportAuthor 更改报告作者
  1174. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  1175. //产品权限
  1176. oRddp := orm.NewOrmUsingDB("rddp")
  1177. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  1178. if condition != "" {
  1179. sql += condition
  1180. }
  1181. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  1182. return
  1183. }
  1184. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  1185. o := orm.NewOrmUsingDB("rddp")
  1186. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  1187. _, err = o.Raw(sql1, reportId).Exec()
  1188. if err != nil {
  1189. return
  1190. }
  1191. //修改音频标题
  1192. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  1193. _, err = o.Raw(sql2, reportId).Exec()
  1194. return
  1195. }
  1196. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  1197. o := orm.NewOrmUsingDB("rddp")
  1198. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  1199. _, err = o.Raw(sql1, reportId).Exec()
  1200. if err != nil {
  1201. return
  1202. }
  1203. //修改音频标题
  1204. sql2 := ` UPDATE report_chapter SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE report_id = ? and (video_name !="" and video_name is not null)`
  1205. _, err = o.Raw(sql2, reportId).Exec()
  1206. return
  1207. }
  1208. // MarkEditReport 标记编辑英文研报的请求数据
  1209. type MarkEditReport struct {
  1210. ReportId int `description:"研报id"`
  1211. ReportChapterId int `description:"研报章节id"`
  1212. Status int `description:"标记状态,1:编辑中,2:查询状态,3:编辑完成"`
  1213. }
  1214. type MarkReportResp struct {
  1215. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  1216. Msg string `description:"提示信息"`
  1217. Editor string `description:"编辑者姓名"`
  1218. }
  1219. type MarkReportItem struct {
  1220. AdminId int `description:"编辑者ID"`
  1221. Editor string `description:"编辑者姓名"`
  1222. ReportClassifyNameFirst string
  1223. }
  1224. // GetReportByCondition 获取报告
  1225. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  1226. o := orm.NewOrmUsingDB("rddp")
  1227. fields := `*`
  1228. if len(fieldArr) > 0 {
  1229. fields = strings.Join(fieldArr, ",")
  1230. }
  1231. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  1232. sql += condition
  1233. order := ` ORDER BY modify_time DESC`
  1234. if orderRule != `` {
  1235. order = orderRule
  1236. }
  1237. sql += order
  1238. if isPage {
  1239. sql += ` LIMIT ?,?`
  1240. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1241. } else {
  1242. _, err = o.Raw(sql, pars).QueryRows(&items)
  1243. }
  1244. return
  1245. }
  1246. // ModifyReportMsgIsSendV2 更新报告消息状态
  1247. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  1248. o := orm.NewOrmUsingDB("rddp")
  1249. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  1250. _, err = o.Raw(sql, reportId).Exec()
  1251. return
  1252. }
  1253. // SetPrePublishReportById 设置定时发布
  1254. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1255. o := orm.NewOrmUsingDB("rddp")
  1256. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1257. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  1258. return
  1259. }
  1260. // ReportSubmitApproveReq 提交审批请求体
  1261. type ReportSubmitApproveReq struct {
  1262. ReportId int `description:"报告ID"`
  1263. }
  1264. // ReportCancelApproveReq 撤回审批请求体
  1265. type ReportCancelApproveReq struct {
  1266. ReportId int `description:"报告ID"`
  1267. }
  1268. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1269. o := orm.NewOrmUsingDB("rddp")
  1270. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1271. err = o.Raw(sql, id).QueryRow(&item)
  1272. return
  1273. }
  1274. // GetReportStateCount 获取指定状态的报告数量
  1275. func GetReportStateCount(state int) (count int, err error) {
  1276. o := orm.NewOrmUsingDB("rddp")
  1277. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1278. err = o.Raw(sql, state).QueryRow(&count)
  1279. return
  1280. }
  1281. // UpdateReportsStateByCond 批量更新报告状态
  1282. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, classifyThirdId, oldState, newState int) (err error) {
  1283. o := orm.NewOrmUsingDB("rddp")
  1284. cond := ``
  1285. if classifyFirstId > 0 {
  1286. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1287. }
  1288. if classifySecondId > 0 {
  1289. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1290. }
  1291. if classifyThirdId > 0 {
  1292. cond += fmt.Sprintf(` AND classify_id_third = %d`, classifyThirdId)
  1293. }
  1294. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1295. _, err = o.Raw(sql, newState, oldState).Exec()
  1296. return
  1297. }
  1298. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1299. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1300. if len(secondIds) <= 0 {
  1301. return
  1302. }
  1303. o := orm.NewOrmUsingDB("rddp")
  1304. // (有审批流的)未发布->待提交
  1305. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1306. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1307. if err != nil {
  1308. return
  1309. }
  1310. // (无审批流的)待提交->未发布
  1311. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1312. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1313. return
  1314. }
  1315. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1316. type GetReportPdfUrlReq struct {
  1317. ReportUrl string `description:"报告Url"`
  1318. ReportCode string `description:"报告Code"`
  1319. Type int `description:"类型 1-pdf 2-图片"`
  1320. }
  1321. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1322. o := orm.NewOrmUsingDB("rddp")
  1323. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1324. _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  1325. return
  1326. }
  1327. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1328. o := orm.NewOrmUsingDB("rddp")
  1329. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1330. _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  1331. return
  1332. }
  1333. // UpdatePdfUrlReportById 清空pdf相关字段
  1334. func UpdatePdfUrlReportById(reportId int) (err error) {
  1335. o := orm.NewOrmUsingDB("rddp")
  1336. sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  1337. _, err = o.Raw(sql, reportId).Exec()
  1338. return
  1339. }
  1340. // InsertMultiReport
  1341. // @Description: 批量新增报告
  1342. // @author: Roc
  1343. // @datetime 2024-06-27 15:55:25
  1344. // @param items []*Report
  1345. // @return err error
  1346. func InsertMultiReport(items []*Report) (err error) {
  1347. o := orm.NewOrmUsingDB("rddp")
  1348. _, err = o.InsertMulti(500, items)
  1349. return
  1350. }
  1351. // ReportLayout
  1352. // @Description: 报告布局
  1353. type ReportLayout struct {
  1354. Id int
  1355. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  1356. }
  1357. // GetReportLayoutByReportId
  1358. // @Description: 根据报告id获取报告的布局
  1359. // @author: Roc
  1360. // @datetime 2024-07-15 15:27:05
  1361. // @param reportId int
  1362. // @return item ReportLayout
  1363. // @return err error
  1364. func GetReportLayoutByReportId(reportId int) (item ReportLayout, err error) {
  1365. o := orm.NewOrmUsingDB("rddp")
  1366. sql := `SELECT id, report_layout FROM report WHERE id = ? `
  1367. err = o.Raw(sql, reportId).QueryRow(&item)
  1368. return
  1369. }
  1370. func GetReportFieldsByIds(ids []int, fields []string) (items []*Report, err error) {
  1371. if len(ids) == 0 {
  1372. return
  1373. }
  1374. o := orm.NewOrmUsingDB("rddp")
  1375. field := " * "
  1376. if len(fields) > 0 {
  1377. field = fmt.Sprintf(" %s ", strings.Join(fields, ","))
  1378. }
  1379. sql := fmt.Sprintf(`SELECT %s FROM report WHERE id IN (%s)`, field, utils.GetOrmInReplace(len(ids)))
  1380. _, err = o.Raw(sql, ids).QueryRows(&items)
  1381. return
  1382. }
  1383. // GetReportListByClassifyId 根据分类id 获取报告列表
  1384. func GetReportListByClassifyId(classifyId int) (items []*Report, err error) {
  1385. o := orm.NewOrmUsingDB("rddp")
  1386. sql := `SELECT * FROM report WHERE classify_id_first = ? or classify_id_second = ? or classify_id_third = ?`
  1387. _, err = o.Raw(sql, classifyId, classifyId, classifyId).QueryRows(&items)
  1388. return items, err
  1389. }
  1390. func GetExistReportClassifyIdByClassifyIds(classifyIds []int) (existClassifyIds []*Report, err error) {
  1391. if len(classifyIds) == 0 {
  1392. return
  1393. }
  1394. o := orm.NewOrmUsingDB("rddp")
  1395. sql := `SELECT classify_id_first, classify_id_second, classify_id_third FROM report WHERE 1=1 `
  1396. sql += fmt.Sprintf(` AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s))`, utils.GetOrmInReplace(len(classifyIds)), utils.GetOrmInReplace(len(classifyIds)), utils.GetOrmInReplace(len(classifyIds)))
  1397. _, err = o.Raw(sql, classifyIds, classifyIds, classifyIds).QueryRows(&existClassifyIds)
  1398. return
  1399. }
  1400. // UpdateReportInfo 修改报告
  1401. func UpdateReportInfo(reports *Report) (err error) {
  1402. o := orm.NewOrmUsingDB("rddp")
  1403. _, err = o.Update(reports)
  1404. if err != nil {
  1405. return err
  1406. }
  1407. return
  1408. }
  1409. func FindReportListByCondition(condition string, pars []interface{}) (items []*Report, err error) {
  1410. o := orm.NewOrmUsingDB("rddp")
  1411. sql := `SELECT * FROM report WHERE 1=1 `
  1412. if condition != "" {
  1413. sql += condition
  1414. }
  1415. _, err = o.Raw(sql, pars).QueryRows(&items)
  1416. if err != nil {
  1417. return nil, err
  1418. }
  1419. return
  1420. }