report.go 63 KB

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