report.go 61 KB

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