report.go 61 KB

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