report.go 63 KB

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