report.go 66 KB

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