report.go 66 KB

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