report.go 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. package models
  2. import (
  3. "eta/eta_mobile/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "strings"
  8. "time"
  9. )
  10. // 报告状态
  11. const (
  12. ReportStateUnpublished = 1 // 未发布
  13. ReportStatePublished = 2 // 已发布
  14. ReportStateWaitSubmit = 3 // 待提交
  15. ReportStateWaitApprove = 4 // 审批中
  16. ReportStateRefused = 5 // 已驳回
  17. ReportStatePass = 6 // 已通过
  18. )
  19. // 报告操作
  20. const (
  21. ReportOperateAdd = 1 // 新增报告
  22. ReportOperateEdit = 2 // 编辑报告
  23. ReportOperatePublish = 3 // 发布报告
  24. ReportOperateCancelPublish = 4 // 取消发布报告
  25. ReportOperateSubmitApprove = 5 // 提交审批
  26. ReportOperateCancelApprove = 6 // 撤回审批
  27. )
  28. type Report struct {
  29. Id int `orm:"column(id)" description:"报告Id"`
  30. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  31. ClassifyIdFirst int `description:"一级分类id"`
  32. ClassifyNameFirst string `description:"一级分类名称"`
  33. ClassifyIdSecond int `description:"二级分类id"`
  34. ClassifyNameSecond string `description:"二级分类名称"`
  35. Title string `description:"标题"`
  36. Abstract string `description:"摘要"`
  37. Author string `description:"作者"`
  38. Frequency string `description:"频度"`
  39. CreateTime string `description:"创建时间"`
  40. ModifyTime time.Time `description:"修改时间"`
  41. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  42. PublishTime time.Time `description:"发布时间"`
  43. Stage int `description:"期数"`
  44. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  45. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  46. Content string `description:"内容"`
  47. VideoUrl string `description:"音频文件URL"`
  48. VideoName string `description:"音频文件名称"`
  49. VideoPlaySeconds string `description:"音频播放时长"`
  50. VideoSize string `description:"音频文件大小,单位M"`
  51. ContentSub string `description:"内容前两个章节"`
  52. ReportCode string `description:"报告唯一编码"`
  53. ReportVersion int `description:"1:旧版,2:新版"`
  54. HasChapter int `description:"是否有章节 0-否 1-是"`
  55. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  56. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  57. MsgSendTime time.Time `description:"模版消息发送时间"`
  58. AdminId int `description:"创建者账号"`
  59. AdminRealName string `description:"创建者姓名"`
  60. ApproveTime time.Time `description:"审批时间"`
  61. ApproveId int `description:"审批ID"`
  62. }
  63. type ReportList struct {
  64. Id int `description:"报告Id"`
  65. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  66. ClassifyIdFirst int `description:"一级分类id"`
  67. ClassifyNameFirst string `description:"一级分类名称"`
  68. ClassifyIdSecond int `description:"二级分类id"`
  69. ClassifyNameSecond string `description:"二级分类名称"`
  70. Title string `description:"标题"`
  71. Abstract string `description:"摘要"`
  72. Author string `description:"作者"`
  73. Frequency string `description:"频度"`
  74. CreateTime string `description:"创建时间"`
  75. ModifyTime time.Time `description:"修改时间"`
  76. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  77. PublishTime string `description:"发布时间"`
  78. PrePublishTime string `description:"预发布时间"`
  79. Stage int `description:"期数"`
  80. MsgIsSend int `description:"模板消息是否已发送,0:否,1:是"`
  81. Content string `description:"内容"`
  82. VideoUrl string `description:"音频文件URL"`
  83. VideoName string `description:"音频文件名称"`
  84. VideoPlaySeconds string `description:"音频播放时长"`
  85. ContentSub string `description:"内容前两个章节"`
  86. Pv int `description:"Pv"`
  87. Uv int `description:"Uv"`
  88. ReportCode string `description:"报告唯一编码"`
  89. ReportVersion int `description:"1:旧版,2:新版"`
  90. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  91. NeedThsMsg int `description:"是否需要推送客群消息 0-否 1-是"`
  92. HasChapter int `description:"是否有章节 0-否 1-是"`
  93. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  94. ChapterVideoList []*ReportChapterVideoList `description:"章节音频列表"`
  95. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  96. MsgSendTime string `description:"模版消息发送时间"`
  97. CanEdit bool `description:"是否可编辑"`
  98. Editor string `description:"编辑人"`
  99. AdminId int `description:"创建者账号"`
  100. AdminRealName string `description:"创建者姓名"`
  101. ApproveTime string `description:"审批时间"`
  102. DetailImgUrl string `description:"报告详情长图地址"`
  103. DetailPdfUrl string `description:"报告详情PDF地址"`
  104. }
  105. type ReportListResp struct {
  106. List []*ReportList
  107. Paging *paging.PagingItem `description:"分页数据"`
  108. }
  109. func GetReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) {
  110. //产品权限
  111. companyTypeSqlStr := ``
  112. if companyType == "ficc" {
  113. companyTypeSqlStr = " AND classify_id_first != 40 "
  114. } else if companyType == "权益" {
  115. companyTypeSqlStr = " AND classify_id_first = 40 "
  116. }
  117. oRddp := orm.NewOrmUsingDB("rddp")
  118. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 ` + companyTypeSqlStr
  119. if condition != "" {
  120. sql += condition
  121. }
  122. err = oRddp.Raw(sql, pars).QueryRow(&count)
  123. return
  124. }
  125. func GetReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int) (items []*ReportList, err error) {
  126. o := orm.NewOrmUsingDB("rddp")
  127. //产品权限
  128. companyTypeSqlStr := ``
  129. if companyType == "ficc" {
  130. companyTypeSqlStr = " AND classify_id_first != 40 "
  131. } else if companyType == "权益" {
  132. companyTypeSqlStr = " AND classify_id_first = 40 "
  133. }
  134. sql := `SELECT *,
  135. (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
  136. (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
  137. FROM report WHERE 1=1 ` + companyTypeSqlStr
  138. if condition != "" {
  139. sql += condition
  140. }
  141. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  142. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  143. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  144. return
  145. }
  146. // PublishReport 发布报告
  147. func PublishReport(reportIds []int) (err error) {
  148. if len(reportIds) == 0 {
  149. return
  150. }
  151. o := orm.NewOrmUsingDB("rddp")
  152. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  153. _, err = o.Raw(sql).Exec()
  154. return
  155. }
  156. // PublishCancelReport 取消发布报告
  157. func PublishCancelReport(reportId, state int, publishTimeNullFlag bool) (err error) {
  158. o := orm.NewOrmUsingDB("rddp")
  159. var sql string
  160. if publishTimeNullFlag {
  161. sql = ` UPDATE report SET state=?, publish_time=null, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  162. } else {
  163. sql = ` UPDATE report SET state=?, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  164. }
  165. _, err = o.Raw(sql, state, reportId).Exec()
  166. return
  167. }
  168. // 取消发布报告
  169. func PublishCancleReport(reportIds int, publishTimeNullFlag bool) (err error) {
  170. o := orm.NewOrmUsingDB("rddp")
  171. var sql string
  172. if publishTimeNullFlag {
  173. sql = ` UPDATE report SET state=1, publish_time=null, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  174. } else {
  175. sql = ` UPDATE report SET state=1, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  176. }
  177. _, err = o.Raw(sql, reportIds).Exec()
  178. return
  179. }
  180. // 删除报告
  181. func DeleteReport(reportIds int) (err error) {
  182. o := orm.NewOrmUsingDB("rddp")
  183. sql := ` DELETE FROM report WHERE id =? `
  184. _, err = o.Raw(sql, reportIds).Exec()
  185. return
  186. }
  187. type ReportDetail struct {
  188. Id int `orm:"column(id)" description:"报告Id"`
  189. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  190. ClassifyIdFirst int `description:"一级分类id"`
  191. ClassifyNameFirst string `description:"一级分类名称"`
  192. ClassifyIdSecond int `description:"二级分类id"`
  193. ClassifyNameSecond string `description:"二级分类名称"`
  194. Title string `description:"标题"`
  195. Abstract string `description:"摘要"`
  196. Author string `description:"作者"`
  197. Frequency string `description:"频度"`
  198. CreateTime string `description:"创建时间"`
  199. ModifyTime string `description:"修改时间"`
  200. State int `description:"1:未发布,2:已发布"`
  201. PublishTime string `description:"发布时间"`
  202. PrePublishTime string `description:"预发布时间"`
  203. Stage int `description:"期数"`
  204. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  205. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  206. Content string `description:"内容"`
  207. VideoUrl string `description:"音频文件URL"`
  208. VideoName string `description:"音频文件名称"`
  209. VideoPlaySeconds string `description:"音频播放时长"`
  210. ContentSub string `description:"内容前两个章节"`
  211. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  212. HasChapter int `description:"是否有章节 0-否 1-是"`
  213. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  214. ReportCode string `description:"报告code"`
  215. }
  216. func GetReportById(reportId int) (item *ReportDetail, err error) {
  217. o := orm.NewOrmUsingDB("rddp")
  218. sql := `SELECT * FROM report WHERE id=?`
  219. err = o.Raw(sql, reportId).QueryRow(&item)
  220. return
  221. }
  222. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  223. o := orm.NewOrmUsingDB("rddp")
  224. sql := `SELECT * FROM report WHERE id in ` + reportIds
  225. _, err = o.Raw(sql).QueryRows(&list)
  226. return
  227. }
  228. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  229. func GetSimpleReportByIds(reportIds []int) (list []*ReportDetail, err error) {
  230. if len(reportIds) == 0 {
  231. return
  232. }
  233. o := orm.NewOrmUsingDB("rddp")
  234. sql := `SELECT id, title FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  235. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  236. return
  237. }
  238. func GetReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) {
  239. o := orm.NewOrmUsingDB("rddp")
  240. sql := ``
  241. if classifyIdSecond > 0 {
  242. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? "
  243. o.Raw(sql, classifyIdSecond).QueryRow(&count)
  244. } else {
  245. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? "
  246. o.Raw(sql, classifyIdFirst).QueryRow(&count)
  247. }
  248. return
  249. }
  250. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, reportId int) (count int, err error) {
  251. o := orm.NewOrmUsingDB("rddp")
  252. sql := ``
  253. if classifyIdSecond > 0 {
  254. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? AND id<>? "
  255. o.Raw(sql, classifyIdSecond, reportId).QueryRow(&count)
  256. } else {
  257. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? AND id<>? "
  258. o.Raw(sql, classifyIdFirst, reportId).QueryRow(&count)
  259. }
  260. return
  261. }
  262. type PublishReq struct {
  263. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  264. ReportUrl string `description:"报告Url"`
  265. }
  266. type PublishCancelReq struct {
  267. ReportIds int `description:"报告id"`
  268. }
  269. type DeleteReq struct {
  270. ReportIds int `description:"报告id"`
  271. }
  272. type AddReq struct {
  273. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  274. ClassifyIdFirst int `description:"一级分类id"`
  275. ClassifyNameFirst string `description:"一级分类名称"`
  276. ClassifyIdSecond int `description:"二级分类id"`
  277. ClassifyNameSecond string `description:"二级分类名称"`
  278. Title string `description:"标题"`
  279. Abstract string `description:"摘要"`
  280. Author string `description:"作者"`
  281. Frequency string `description:"频度"`
  282. State int `description:"状态:1:未发布,2:已发布"`
  283. Content string `description:"内容"`
  284. CreateTime string `description:"创建时间"`
  285. ReportVersion int `description:"1:旧版,2:新版"`
  286. }
  287. type PrePublishReq struct {
  288. ReportId int `description:"报告id"`
  289. PrePublishTime string `description:"预发布时间"`
  290. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  291. ReportUrl string `description:"报告Url"`
  292. }
  293. type AddResp struct {
  294. ReportId int64 `description:"报告id"`
  295. ReportCode string `description:"报告code"`
  296. }
  297. func AddReport(item *Report) (lastId int64, err error) {
  298. o := orm.NewOrmUsingDB("rddp")
  299. lastId, err = o.Insert(item)
  300. return
  301. }
  302. type EditReq struct {
  303. ReportId int64 `description:"报告id"`
  304. ClassifyIdFirst int `description:"一级分类id"`
  305. ClassifyNameFirst string `description:"一级分类名称"`
  306. ClassifyIdSecond int `description:"二级分类id"`
  307. ClassifyNameSecond string `description:"二级分类名称"`
  308. Title string `description:"标题"`
  309. Abstract string `description:"摘要"`
  310. Author string `description:"作者"`
  311. Frequency string `description:"频度"`
  312. State int `description:"状态:1:未发布,2:已发布"`
  313. Content string `description:"内容"`
  314. CreateTime string `description:"创建时间"`
  315. }
  316. type EditResp struct {
  317. ReportId int64 `description:"报告id"`
  318. ReportCode string `description:"报告code"`
  319. }
  320. func EditReport(item *Report, reportId int64) (err error) {
  321. o := orm.NewOrmUsingDB("rddp")
  322. sql := `UPDATE report
  323. SET
  324. classify_id_first =?,
  325. classify_name_first = ?,
  326. classify_id_second = ?,
  327. classify_name_second = ?,
  328. title = ?,
  329. abstract = ?,
  330. author = ?,
  331. frequency = ?,
  332. state = ?,
  333. content = ?,
  334. content_sub = ?,
  335. stage =?,
  336. create_time = ?,
  337. modify_time = ?
  338. WHERE id = ? `
  339. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  340. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  341. return
  342. }
  343. type ReportDetailReq struct {
  344. ReportId int `description:"报告id"`
  345. }
  346. type ClassifyIdDetailReq struct {
  347. ClassifyIdFirst int `description:"报告一级分类id"`
  348. ClassifyIdSecond int `description:"报告二级分类id"`
  349. }
  350. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  351. o := orm.NewOrmUsingDB("rddp")
  352. sql := ` SELECT * FROM report WHERE 1=1 `
  353. if classifyIdSecond > 0 {
  354. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  355. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  356. } else {
  357. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  358. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  359. }
  360. return
  361. }
  362. type SendTemplateMsgReq struct {
  363. ReportId int `description:"报告id"`
  364. }
  365. func ModifyReportMsgIsSend(reportId int) (err error) {
  366. o := orm.NewOrmUsingDB("rddp")
  367. report, err := GetReportById(reportId)
  368. if err != nil {
  369. return
  370. }
  371. if report.MsgIsSend == 0 {
  372. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  373. _, err = o.Raw(sql, reportId).Exec()
  374. }
  375. return
  376. }
  377. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  378. o := orm.NewOrmUsingDB("rddp")
  379. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  380. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  381. return
  382. }
  383. type ReportItem struct {
  384. Id int `orm:"column(id)" description:"报告Id"`
  385. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  386. ClassifyIdFirst int `description:"一级分类id"`
  387. ClassifyNameFirst string `description:"一级分类名称"`
  388. ClassifyIdSecond int `description:"二级分类id"`
  389. ClassifyNameSecond string `description:"二级分类名称"`
  390. Title string `description:"标题"`
  391. Abstract string `description:"摘要"`
  392. Author string `description:"作者"`
  393. Frequency string `description:"频度"`
  394. CreateTime time.Time `description:"创建时间"`
  395. ModifyTime time.Time `description:"修改时间"`
  396. State int `description:"1:未发布,2:已发布"`
  397. PublishTime time.Time `description:"发布时间"`
  398. Stage int `description:"期数"`
  399. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  400. Content string `description:"内容"`
  401. VideoUrl string `description:"音频文件URL"`
  402. VideoName string `description:"音频文件名称"`
  403. VideoPlaySeconds string `description:"音频播放时长"`
  404. ContentSub string `description:"内容前两个章节"`
  405. }
  406. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  407. o := orm.NewOrmUsingDB("rddp")
  408. sql := `SELECT * FROM report WHERE id=?`
  409. err = o.Raw(sql, reportId).QueryRow(&item)
  410. return
  411. }
  412. type SaveReportContent struct {
  413. Content string `description:"内容"`
  414. ReportId int `description:"报告id"`
  415. NoChange int `description:"内容是否未改变:1:内容未改变"`
  416. }
  417. func EditReportContent(reportId int, content, contentSub string) (err error) {
  418. o := orm.NewOrmUsingDB("rddp")
  419. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  420. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  421. return
  422. }
  423. func AddReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
  424. o := orm.NewOrmUsingDB("rddp")
  425. sql := ` INSERT INTO report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
  426. _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
  427. return
  428. }
  429. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  430. o := orm.NewOrmUsingDB("rddp")
  431. p, err := o.Raw(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub, admin_id, admin_name) VALUES (?,?,?,?,?,?)`).Prepare()
  432. if err != nil {
  433. return
  434. }
  435. defer func() {
  436. _ = p.Close()
  437. }()
  438. for _, v := range items {
  439. _, err = p.Exec(v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, adminId, adminRealName)
  440. if err != nil {
  441. return
  442. }
  443. }
  444. return
  445. }
  446. type SaveReportContentResp struct {
  447. ReportId int `description:"报告id"`
  448. }
  449. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  450. o := orm.NewOrmUsingDB("rddp")
  451. sql := `UPDATE report SET report_code=? WHERE id=? `
  452. _, err = o.Raw(sql, reportCode, reportId).Exec()
  453. return
  454. }
  455. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  456. o := orm.NewOrmUsingDB("rddp")
  457. if item.ThsMsgIsSend == 0 {
  458. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  459. _, err = o.Raw(sql, item.Id).Exec()
  460. }
  461. return
  462. }
  463. type ThsSendTemplateMsgReq struct {
  464. ReportId []int `description:"报告id"`
  465. }
  466. type PublishDayWeekReportReq struct {
  467. ReportId int `description:"报告ID"`
  468. }
  469. // SaveDayWeekReportReq 新增晨报周报请求体
  470. type SaveDayWeekReportReq struct {
  471. ReportId int `description:"报告ID"`
  472. Title string `description:"标题"`
  473. ReportType string `description:"一级分类ID"`
  474. Author string `description:"作者"`
  475. CreateTime string `description:"创建时间"`
  476. }
  477. // GetDayWeekReportStage 获取晨报周报期数
  478. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  479. o := orm.NewOrmUsingDB("rddp")
  480. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  481. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  482. return
  483. }
  484. // AddReportAndChapter 新增报告及章节
  485. func AddReportAndChapter(reportItem *Report, chapterItemList []*ReportChapter) (reportId int64, err error) {
  486. o := orm.NewOrmUsingDB("rddp")
  487. to, err := o.Begin()
  488. if err != nil {
  489. return
  490. }
  491. defer func() {
  492. if err != nil {
  493. _ = to.Rollback()
  494. } else {
  495. _ = to.Commit()
  496. }
  497. }()
  498. if reportId, err = to.Insert(reportItem); err != nil {
  499. return
  500. }
  501. if len(chapterItemList) > 0 {
  502. for _, chapterItem := range chapterItemList {
  503. chapterItem.ReportId = int(reportId)
  504. cpId, tmpErr := to.Insert(chapterItem)
  505. if tmpErr != nil {
  506. return
  507. }
  508. chapterItem.ReportChapterId = int(cpId)
  509. }
  510. }
  511. return
  512. }
  513. // GetReportByReportId 主键获取报告
  514. func GetReportByReportId(reportId int) (item *Report, err error) {
  515. o := orm.NewOrmUsingDB("rddp")
  516. sql := `SELECT * FROM report WHERE id = ?`
  517. err = o.Raw(sql, reportId).QueryRow(&item)
  518. return
  519. }
  520. // GetReportByOldReportId 根据老报告id主键获取报告
  521. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  522. o := orm.NewOrmUsingDB("rddp")
  523. sql := `SELECT * FROM report WHERE old_report_id = ?`
  524. err = o.Raw(sql, reportId).QueryRow(&item)
  525. return
  526. }
  527. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  528. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  529. o := orm.NewOrmUsingDB("rddp")
  530. to, err := o.Begin()
  531. if err != nil {
  532. return
  533. }
  534. defer func() {
  535. if err != nil {
  536. _ = to.Rollback()
  537. } else {
  538. _ = to.Commit()
  539. }
  540. }()
  541. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  542. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  543. return
  544. }
  545. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  546. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  547. return
  548. }
  549. return
  550. }
  551. // UpdateReport 更新报告
  552. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  553. o := orm.NewOrmUsingDB("rddp")
  554. _, err = o.Update(reportInfo, cols...)
  555. return
  556. }
  557. // 晨周报详情
  558. type ReportDetailView struct {
  559. *ReportDetail
  560. ChapterList []*ReportChapter
  561. }
  562. func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  563. o := orm.NewOrmUsingDB("rddp")
  564. sql := ` SELECT
  565. *
  566. FROM
  567. report AS a
  568. WHERE
  569. a.has_chapter = 1
  570. AND a.chapter_type = "day"
  571. AND a.state = 1
  572. AND (
  573. a.create_time BETWEEN ? AND ?
  574. )
  575. ORDER BY
  576. a.create_time DESC
  577. LIMIT 1 `
  578. err = o.Raw(sql, startTime, endTime).QueryRow(&item)
  579. return
  580. }
  581. type ElasticReportDetail struct {
  582. ReportId int `description:"报告ID"`
  583. ReportChapterId int `description:"报告章节ID"`
  584. Title string `description:"标题"`
  585. Abstract string `description:"摘要"`
  586. BodyContent string `description:"内容"`
  587. PublishTime string `description:"发布时间"`
  588. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  589. Author string `description:"作者"`
  590. ClassifyIdFirst int `description:"一级分类ID"`
  591. ClassifyNameFirst string `description:"一级分类名称"`
  592. ClassifyIdSecond int `description:"二级分类ID"`
  593. ClassifyNameSecond string `description:"二级分类名称"`
  594. Categories string `description:"关联的品种名称(包括品种别名)"`
  595. StageStr string `description:"报告期数"`
  596. }
  597. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  598. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  599. o := orm.NewOrmUsingDB("rddp")
  600. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  601. err = o.Raw(sql, chapterType).QueryRow(&item)
  602. return
  603. }
  604. // GetNewReportExist
  605. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  606. o := orm.NewOrmUsingDB("rddp")
  607. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  608. err = o.Raw(sql, oldReportId).QueryRow(&item)
  609. return
  610. }
  611. // PublishReportAndChapter 发布报告及章节
  612. func PublishReportAndChapter(reportInfo *Report, publishIds, unPublishIds []int, isPublishReport bool, cols []string) (err error) {
  613. o := orm.NewOrmUsingDB("rddp")
  614. to, err := o.Begin()
  615. if err != nil {
  616. return
  617. }
  618. defer func() {
  619. if err != nil {
  620. _ = to.Rollback()
  621. } else {
  622. _ = to.Commit()
  623. }
  624. }()
  625. // 更新报告
  626. if isPublishReport {
  627. if _, err = to.Update(reportInfo, cols...); err != nil {
  628. return
  629. }
  630. }
  631. // 发布章节
  632. if len(publishIds) > 0 {
  633. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  634. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  635. }
  636. if len(unPublishIds) > 0 {
  637. 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)) + `) `
  638. _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  639. }
  640. return
  641. }
  642. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  643. o := orm.NewOrmUsingDB("rddp")
  644. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  645. UNION ALL
  646. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  647. _, err = o.Raw(sql).QueryRows(&list)
  648. return
  649. }
  650. // PublishReportById 发布报告
  651. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  652. o := orm.NewOrmUsingDB("rddp")
  653. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  654. _, err = o.Raw(sql, publishTime, reportId).Exec()
  655. return
  656. }
  657. // ResetReportById 重置报告状态
  658. func ResetReportById(reportId, state int) (err error) {
  659. o := orm.NewOrmUsingDB("rddp")
  660. sql := `UPDATE report SET state = ?, pre_publish_time = null, pre_msg_send = 0, modify_time = NOW() WHERE id = ?`
  661. _, err = o.Raw(sql, state, reportId).Exec()
  662. return
  663. }
  664. // GetCommentReportByReportId 查询有留言的报告列表
  665. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  666. o := orm.NewOrmUsingDB("rddp")
  667. sql := `SELECT
  668. id,
  669. create_time,
  670. title,
  671. classify_name_first,
  672. classify_id_first,
  673. classify_name_second,
  674. classify_id_second,
  675. state,
  676. IF
  677. ( publish_time, publish_time, create_time ) AS publish_time
  678. FROM
  679. report
  680. WHERE
  681. 1=1
  682. `
  683. if condition != "" {
  684. sql += condition
  685. }
  686. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  687. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  688. return
  689. }
  690. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  691. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  692. o := orm.NewOrmUsingDB("rddp")
  693. sql := `SELECT
  694. id,
  695. create_time,
  696. title,
  697. classify_name_first,
  698. classify_id_first,
  699. classify_name_second,
  700. classify_id_second,
  701. state,
  702. IF
  703. ( publish_time, publish_time, create_time ) AS publish_time
  704. FROM
  705. report
  706. WHERE
  707. 1=1
  708. `
  709. if condition != "" {
  710. sql += condition
  711. }
  712. if orderBy == `` {
  713. sql += ` ORDER BY publish_time DESC , title ASC `
  714. } else {
  715. sql += orderBy
  716. }
  717. sql += ` LIMIT ?,? `
  718. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  719. return
  720. }
  721. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  722. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  723. o := orm.NewOrmUsingDB("rddp")
  724. sql := `SELECT count(*)
  725. FROM report WHERE 1=1`
  726. if condition != "" {
  727. sql += condition
  728. }
  729. err = o.Raw(sql, pars).QueryRow(&total)
  730. return
  731. }
  732. // 点赞相关的报告列表
  733. type LikeReportItem struct {
  734. ReportId int `description:"报告Id"`
  735. ReportChapterId int `description:"报告章节Id"`
  736. ClassifyIdFirst int `description:"一级分类id"`
  737. ClassifyNameFirst string `description:"一级分类名称"`
  738. ClassifyIdSecond int `description:"二级分类id"`
  739. ClassifyNameSecond string `description:"二级分类名称"`
  740. ReportChapterTypeId int `description:"章节类型"`
  741. ReportChapterTypeName string `description:"品种名称"`
  742. PublishTime time.Time `description:"发布时间" `
  743. Title string `description:"标题"`
  744. }
  745. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  746. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  747. o := orm.NewOrmUsingDB("rddp")
  748. sql := `( SELECT
  749. id AS report_id,
  750. 0 AS report_chapter_id,
  751. classify_id_first,
  752. classify_id_second,
  753. classify_name_first,
  754. classify_name_second,
  755. 0 as report_chapter_type_id,
  756. "" as report_chapter_type_name,
  757. publish_time,
  758. title
  759. FROM
  760. report
  761. WHERE
  762. classify_name_first != "晨报"
  763. AND classify_name_first != "周报"
  764. AND id in (` + reportIds + `)
  765. )
  766. UNION
  767. ( SELECT
  768. report_id,
  769. report_chapter_id,
  770. classify_id_first,
  771. 0 as classify_id_second,
  772. classify_name_first,
  773. null as classify_name_second,
  774. type_id as report_chapter_type_id,
  775. type_name as report_chapter_type_name,
  776. publish_time,
  777. title
  778. FROM
  779. report_chapter
  780. WHERE
  781. report_chapter_id in (` + chapterIds + `)
  782. )`
  783. if orderStr != "" {
  784. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  785. } else {
  786. sql += ` ORDER BY publish_time DESC, report_id Desc`
  787. }
  788. sql += ` LIMIT ?,?`
  789. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  790. return
  791. }
  792. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  793. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  794. o := orm.NewOrmUsingDB("rddp")
  795. sql := `select count(*) from (( SELECT
  796. id AS report_id,
  797. 0 AS report_chapter_id,
  798. classify_id_first,
  799. classify_id_second,
  800. classify_name_first,
  801. classify_name_second,
  802. 0 as report_chapter_type_id,
  803. publish_time,
  804. title
  805. FROM
  806. report
  807. WHERE
  808. classify_name_first != "晨报"
  809. AND classify_name_first != "周报"
  810. AND id in (` + reportIds + `)
  811. )
  812. UNION
  813. ( SELECT
  814. report_id,
  815. report_chapter_id,
  816. classify_id_first,
  817. 0 as classify_id_second,
  818. classify_name_first,
  819. null as classify_name_second,
  820. type_id as report_chapter_type_id,
  821. publish_time,
  822. title
  823. FROM
  824. report_chapter
  825. WHERE
  826. report_chapter_id in (` + chapterIds + `)
  827. )) r`
  828. err = o.Raw(sql).QueryRow(&total)
  829. return
  830. }
  831. // GetPageReportList 分页获取报告列表
  832. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  833. o := orm.NewOrmUsingDB("rddp")
  834. sql := `SELECT * FROM report WHERE 1=1 `
  835. sql += condition
  836. sql += ` ORDER BY modify_time DESC`
  837. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  838. err = o.Raw(totalSql, pars).QueryRow(&total)
  839. if err != nil {
  840. return
  841. }
  842. sql += ` LIMIT ?,? `
  843. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  844. return
  845. }
  846. // SunCodeReq 获取太阳码请求体
  847. type SunCodeReq struct {
  848. CodePage string `json:"CodePage" description:"太阳码page"`
  849. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  850. }
  851. // YbPcSuncode 活动海报表
  852. type YbPcSuncode struct {
  853. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  854. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  855. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  856. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  857. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  858. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  859. }
  860. // GetYbPcSunCode 获取太阳码
  861. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  862. o := orm.NewOrmUsingDB("weekly")
  863. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  864. err = o.Raw(sql, scene, page).QueryRow(&item)
  865. return
  866. }
  867. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  868. o := orm.NewOrmUsingDB("weekly")
  869. _, err = o.Insert(item)
  870. return
  871. }
  872. // YbSuncodePars 小程序太阳码scene参数
  873. type YbSuncodePars struct {
  874. ID uint32 `orm:"column(id);pk" `
  875. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  876. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  877. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  878. }
  879. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  880. o := orm.NewOrmUsingDB("weekly")
  881. _, err = o.Insert(item)
  882. return
  883. }
  884. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  885. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  886. o := orm.NewOrmUsingDB("rddp")
  887. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  888. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  889. return
  890. }
  891. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  892. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  893. o := orm.NewOrmUsingDB("rddp")
  894. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  895. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  896. return
  897. }
  898. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  899. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  900. o := orm.NewOrmUsingDB("rddp")
  901. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  902. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  903. return
  904. }
  905. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  906. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  907. sql := `SELECT
  908. r.id,
  909. r.content,
  910. r.content_sub
  911. FROM
  912. report AS r
  913. JOIN ppt_v2 AS p ON r.id = p.report_id
  914. WHERE
  915. p.report_id > 0 AND r.content_sub = ""`
  916. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  917. return
  918. }
  919. // ModifyReportAuthor 更改报告作者
  920. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  921. //产品权限
  922. oRddp := orm.NewOrmUsingDB("rddp")
  923. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  924. if condition != "" {
  925. sql += condition
  926. }
  927. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  928. return
  929. }
  930. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  931. o := orm.NewOrmUsingDB("rddp")
  932. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  933. _, err = o.Raw(sql1, reportId).Exec()
  934. if err != nil {
  935. return
  936. }
  937. //修改音频标题
  938. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  939. _, err = o.Raw(sql2, reportId).Exec()
  940. return
  941. }
  942. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  943. o := orm.NewOrmUsingDB("rddp")
  944. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  945. _, err = o.Raw(sql1, reportId).Exec()
  946. if err != nil {
  947. return
  948. }
  949. //修改音频标题
  950. 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)`
  951. _, err = o.Raw(sql2, reportId).Exec()
  952. return
  953. }
  954. // MarkEditReport 标记编辑英文研报的请求数据
  955. type MarkEditReport struct {
  956. ReportId int `description:"研报id"`
  957. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  958. }
  959. type MarkReportResp struct {
  960. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  961. Msg string `description:"提示信息"`
  962. Editor string `description:"编辑者姓名"`
  963. }
  964. type MarkReportItem struct {
  965. AdminId int `description:"编辑者ID"`
  966. Editor string `description:"编辑者姓名"`
  967. ReportClassifyNameFirst string
  968. }
  969. // GetReportByCondition 获取报告
  970. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  971. o := orm.NewOrmUsingDB("rddp")
  972. fields := `*`
  973. if len(fieldArr) > 0 {
  974. fields = strings.Join(fieldArr, ",")
  975. }
  976. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  977. sql += condition
  978. order := ` ORDER BY modify_time DESC`
  979. if orderRule != `` {
  980. order = orderRule
  981. }
  982. sql += order
  983. if isPage {
  984. sql += ` LIMIT ?,?`
  985. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  986. } else {
  987. _, err = o.Raw(sql, pars).QueryRows(&items)
  988. }
  989. return
  990. }
  991. // ModifyReportMsgIsSendV2 更新报告消息状态
  992. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  993. o := orm.NewOrmUsingDB("rddp")
  994. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  995. _, err = o.Raw(sql, reportId).Exec()
  996. return
  997. }
  998. // SetPrePublishReportById 设置定时发布
  999. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1000. o := orm.NewOrmUsingDB("rddp")
  1001. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1002. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  1003. return
  1004. }
  1005. // ReportSubmitApproveReq 提交审批请求体
  1006. type ReportSubmitApproveReq struct {
  1007. ReportId int `description:"报告ID"`
  1008. }
  1009. // ReportCancelApproveReq 撤回审批请求体
  1010. type ReportCancelApproveReq struct {
  1011. ReportId int `description:"报告ID"`
  1012. }
  1013. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1014. o := orm.NewOrmUsingDB("rddp")
  1015. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1016. err = o.Raw(sql, id).QueryRow(&item)
  1017. return
  1018. }
  1019. // GetReportStateCount 获取指定状态的报告数量
  1020. func GetReportStateCount(state int) (count int, err error) {
  1021. o := orm.NewOrmUsingDB("rddp")
  1022. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1023. err = o.Raw(sql, state).QueryRow(&count)
  1024. return
  1025. }
  1026. // UpdateReportsStateByCond 批量更新报告状态
  1027. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
  1028. o := orm.NewOrmUsingDB("rddp")
  1029. cond := ``
  1030. if classifyFirstId > 0 {
  1031. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1032. }
  1033. if classifySecondId > 0 {
  1034. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1035. }
  1036. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1037. _, err = o.Raw(sql, newState, oldState).Exec()
  1038. return
  1039. }
  1040. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1041. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1042. if len(secondIds) <= 0 {
  1043. return
  1044. }
  1045. o := orm.NewOrmUsingDB("rddp")
  1046. // (有审批流的)未发布->待提交
  1047. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1048. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1049. if err != nil {
  1050. return
  1051. }
  1052. // (无审批流的)待提交->未发布
  1053. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1054. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1055. return
  1056. }
  1057. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1058. o := orm.NewOrmUsingDB("rddp")
  1059. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1060. _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  1061. return
  1062. }
  1063. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1064. o := orm.NewOrmUsingDB("rddp")
  1065. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1066. _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  1067. return
  1068. }
  1069. // UpdatePdfUrlReportById 清空pdf相关字段
  1070. func UpdatePdfUrlReportById(reportId int) (err error) {
  1071. o := orm.NewOrmUsingDB("rddp")
  1072. sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  1073. _, err = o.Raw(sql, reportId).Exec()
  1074. return
  1075. }