report.go 57 KB

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