report.go 62 KB

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