report.go 65 KB

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