report.go 65 KB

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