report.go 62 KB

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