report_chapter.go 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/report"
  6. "eta/eta_api/models/system"
  7. "eta/eta_api/services"
  8. "eta/eta_api/services/data"
  9. "eta/eta_api/utils"
  10. "html"
  11. "os"
  12. "path"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // AddChapter
  18. // @Title 新增晨周报章节内容
  19. // @Description 新增晨周报章节内容
  20. // @Param request body models.AddReportChapterReq true "type json string"
  21. // @Success 200 Ret=200 保存成功
  22. // @router /chapter/add [post]
  23. func (this *ReportController) AddChapter() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sysUser := this.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. br.Ret = 408
  34. return
  35. }
  36. var req models.AddReportChapterReq
  37. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  38. if err != nil {
  39. br.Msg = "参数解析异常!"
  40. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  41. return
  42. }
  43. if req.ReportId <= 0 {
  44. br.Msg = "报告ID有误"
  45. return
  46. }
  47. req.Title = strings.TrimSpace(req.Title)
  48. if req.Title == `` {
  49. br.Msg = "章节名称不能为空"
  50. return
  51. }
  52. // 获取报告详情
  53. reportInfo, err := models.GetReportByReportId(req.ReportId)
  54. if err != nil {
  55. br.Msg = "报告信息有误"
  56. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  57. return
  58. }
  59. if reportInfo.State == 2 {
  60. br.Msg = "该报告已发布,不允许新增"
  61. br.ErrMsg = "该报告已发布,不允许新增"
  62. return
  63. }
  64. //newContent := req.Content
  65. //// 更新章节及指标
  66. //contentSub := ""
  67. //if req.Content != "" {
  68. // e := utils.ContentXssCheck(req.Content)
  69. // if e != nil {
  70. // br.Msg = "存在非法标签"
  71. // br.ErrMsg = "存在非法标签, Err: " + e.Error()
  72. // return
  73. // }
  74. // contentClean, e := services.FilterReportContentBr(req.Content)
  75. // if e != nil {
  76. // br.Msg = "内容去除前后空格失败"
  77. // br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  78. // return
  79. // }
  80. // req.Content = contentClean
  81. //
  82. // contentSub, err = services.GetReportContentSub(req.Content)
  83. // if err != nil {
  84. // br.Msg = "内容分段解析失败"
  85. // br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
  86. // return
  87. // }
  88. //}
  89. //if req.Content == "" {
  90. // req.Content = newContent
  91. //}
  92. // 最小单元的分类
  93. var minClassifyId int
  94. var minClassifyName string
  95. if reportInfo.ClassifyIdThird > 0 {
  96. minClassifyId = reportInfo.ClassifyIdThird
  97. minClassifyName = reportInfo.ClassifyNameThird
  98. } else if reportInfo.ClassifyIdSecond > 0 {
  99. minClassifyId = reportInfo.ClassifyIdSecond
  100. minClassifyName = reportInfo.ClassifyNameSecond
  101. } else {
  102. minClassifyId = reportInfo.ClassifyIdFirst
  103. minClassifyName = reportInfo.ClassifyNameFirst
  104. }
  105. // 判断名称是否重复
  106. {
  107. var condition string
  108. var pars []interface{}
  109. condition += " AND report_id = ? AND title=? "
  110. pars = append(pars, req.ReportId, req.Title)
  111. count, err := models.GetCountReportChapterByCondition(condition, pars)
  112. if err != nil {
  113. br.Msg = "新增失败"
  114. br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
  115. return
  116. }
  117. if count > 0 {
  118. br.Msg = "章节名称不允许重复"
  119. br.ErrMsg = "章节名称不允许重复"
  120. br.IsSendEmail = false
  121. return
  122. }
  123. }
  124. reportChapterInfo := new(models.ReportChapter)
  125. reportChapterInfo.ReportId = reportInfo.Id
  126. reportChapterInfo.ClassifyIdFirst = minClassifyId
  127. reportChapterInfo.ClassifyNameFirst = minClassifyName
  128. reportChapterInfo.Title = req.Title
  129. reportChapterInfo.AddType = 1
  130. reportChapterInfo.PublishState = 1
  131. //reportChapterInfo.Author = req.Author
  132. //reportChapterInfo.Content = html.EscapeString(req.Content)
  133. //reportChapterInfo.ContentSub = html.EscapeString(contentSub)
  134. reportChapterInfo.IsEdit = 1
  135. //reportChapterInfo.CreateTime = req.CreateTime
  136. reportChapterInfo.CreateTime = reportInfo.CreateTime
  137. reportChapterInfo.ModifyTime = time.Now()
  138. reportChapterInfo.ReportCreateTime = time.Now()
  139. reportChapterInfo.VideoKind = 2
  140. reportChapterInfo.Stage = reportInfo.Stage
  141. reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  142. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  143. reportChapterInfo.ContentModifyTime = time.Now()
  144. //reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  145. //reportChapterInfo.CanvasColor = req.CanvasColor
  146. //reportChapterInfo.HeadResourceId = req.HeadResourceId
  147. //reportChapterInfo.EndResourceId = req.EndResourceId
  148. err, errMsg := services.AddChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.PermissionIdList, req.AdminIdList)
  149. if err != nil {
  150. br.Msg = "保存失败"
  151. if errMsg != "" {
  152. br.Msg = errMsg
  153. }
  154. br.ErrMsg = "保存失败,Err:" + err.Error()
  155. return
  156. }
  157. br.Ret = 200
  158. br.Success = true
  159. br.Msg = "保存成功"
  160. }
  161. // EditChapterBaseInfoAndPermission
  162. // @Title 修改报告章节的基础信息、授权用户权限、品种权限
  163. // @Description 修改报告章节的基础信息、授权用户权限、品种权限
  164. // @Param request body models.EditReportChapterReq true "type json string"
  165. // @Success 200 Ret=200 保存成功
  166. // @router /chapter/base_info/edit [post]
  167. func (this *ReportController) EditChapterBaseInfoAndPermission() {
  168. br := new(models.BaseResponse).Init()
  169. defer func() {
  170. this.Data["json"] = br
  171. this.ServeJSON()
  172. }()
  173. sysUser := this.SysUser
  174. if sysUser == nil {
  175. br.Msg = "请登录"
  176. br.ErrMsg = "请登录,SysUser Is Empty"
  177. br.Ret = 408
  178. return
  179. }
  180. var req models.EditReportChapterBaseInfoAndPermissionReq
  181. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  182. if err != nil {
  183. br.Msg = "参数解析异常!"
  184. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  185. return
  186. }
  187. reportChapterId := req.ReportChapterId
  188. if reportChapterId <= 0 {
  189. br.Msg = "报告章节ID有误"
  190. return
  191. }
  192. req.Title = strings.TrimSpace(req.Title)
  193. if req.Title == `` {
  194. br.Msg = "章节名称不能为空"
  195. return
  196. }
  197. // 获取章节详情
  198. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  199. if err != nil {
  200. br.Msg = "报告章节信息有误"
  201. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  202. return
  203. }
  204. // 判断名称是否重复
  205. {
  206. var condition string
  207. var pars []interface{}
  208. condition += " AND report_id = ? AND title=? AND report_chapter_id != ? "
  209. pars = append(pars, reportChapterInfo.ReportId, req.Title, reportChapterId)
  210. count, err := models.GetCountReportChapterByCondition(condition, pars)
  211. if err != nil {
  212. br.Msg = "新增失败"
  213. br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
  214. return
  215. }
  216. if count > 0 {
  217. br.Msg = "章节名称不允许重复"
  218. br.ErrMsg = "章节名称不允许重复"
  219. br.IsSendEmail = false
  220. return
  221. }
  222. }
  223. // 获取报告详情
  224. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  225. if err != nil {
  226. br.Msg = "报告信息有误"
  227. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  228. return
  229. }
  230. if reportInfo.State == 2 {
  231. br.Msg = "该报告已发布,不允许编辑"
  232. br.ErrMsg = "该报告已发布,不允许编辑"
  233. br.IsSendEmail = false
  234. return
  235. }
  236. // 报告的最后编辑人
  237. reportInfo.LastModifyAdminId = sysUser.AdminId
  238. reportInfo.LastModifyAdminName = sysUser.RealName
  239. reportInfo.ModifyTime = time.Now()
  240. err, errMsg := services.EditChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.Title, req.PermissionIdList, req.AdminIdList)
  241. if err != nil {
  242. br.Msg = "保存失败"
  243. if errMsg != "" {
  244. br.Msg = errMsg
  245. }
  246. br.ErrMsg = "保存失败,Err:" + err.Error()
  247. return
  248. }
  249. br.Ret = 200
  250. br.Success = true
  251. br.Msg = "保存成功"
  252. }
  253. // EditDayWeekChapter
  254. // @Title 编辑晨周报章节内容
  255. // @Description 编辑晨周报章节内容
  256. // @Param request body models.EditReportChapterReq true "type json string"
  257. // @Success 200 Ret=200 保存成功
  258. // @router /editDayWeekChapter [post]
  259. func (this *ReportController) EditDayWeekChapter() {
  260. br := new(models.BaseResponse).Init()
  261. defer func() {
  262. this.Data["json"] = br
  263. this.ServeJSON()
  264. }()
  265. sysUser := this.SysUser
  266. if sysUser == nil {
  267. br.Msg = "请登录"
  268. br.ErrMsg = "请登录,SysUser Is Empty"
  269. br.Ret = 408
  270. return
  271. }
  272. var req models.EditReportChapterReq
  273. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  274. if err != nil {
  275. br.Msg = "参数解析异常!"
  276. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  277. return
  278. }
  279. reportChapterId := req.ReportChapterId
  280. if reportChapterId <= 0 {
  281. br.Msg = "报告章节ID有误"
  282. return
  283. }
  284. if req.Content == "" {
  285. br.Msg = "请输入内容"
  286. return
  287. }
  288. // 获取章节详情
  289. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  290. if err != nil {
  291. br.Msg = "报告章节信息有误"
  292. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  293. return
  294. }
  295. // 获取报告详情
  296. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  297. if err != nil {
  298. br.Msg = "报告信息有误"
  299. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  300. return
  301. }
  302. // 操作权限校验
  303. hasAuth, msg, errMsg, isSendEmail := checkOpPermission(sysUser, reportInfo, reportChapterInfo, true, this.Lang)
  304. if !hasAuth {
  305. br.Msg = msg
  306. br.ErrMsg = errMsg
  307. br.IsSendEmail = isSendEmail
  308. return
  309. }
  310. if reportInfo.State == 2 {
  311. br.Msg = "该报告已发布,不允许编辑"
  312. br.ErrMsg = "该报告已发布,不允许编辑"
  313. br.IsSendEmail = false
  314. return
  315. }
  316. if reportChapterInfo.PublishState == 2 {
  317. br.Msg = "该报告章节已发布,不允许编辑"
  318. br.ErrMsg = "该报告章节已发布,不允许编辑"
  319. br.IsSendEmail = false
  320. return
  321. }
  322. // 报告的最后编辑人
  323. reportInfo.LastModifyAdminId = sysUser.AdminId
  324. reportInfo.LastModifyAdminName = sysUser.RealName
  325. reportInfo.ModifyTime = time.Now()
  326. updateCols := make([]string, 0)
  327. reqTickerList := req.TickerList
  328. // 更新章节及指标
  329. contentSub := ""
  330. if req.Content != "" {
  331. e := utils.ContentXssCheck(req.Content)
  332. if e != nil {
  333. br.Msg = "存在非法标签"
  334. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  335. return
  336. }
  337. contentClean, e := services.FilterReportContentBr(req.Content)
  338. if e != nil {
  339. br.Msg = "内容去除前后空格失败"
  340. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  341. return
  342. }
  343. req.Content = contentClean
  344. contentSub, err = services.GetReportContentSub(req.Content)
  345. if err != nil {
  346. br.Msg = "内容分段解析失败"
  347. br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
  348. return
  349. }
  350. }
  351. if req.Title != "" {
  352. reportChapterInfo.Title = req.Title
  353. updateCols = append(updateCols, "Title")
  354. }
  355. //reportChapterInfo.AddType = req.AddType
  356. reportChapterInfo.Author = req.Author
  357. reportChapterInfo.Content = html.EscapeString(req.Content)
  358. reportChapterInfo.ContentSub = html.EscapeString(contentSub)
  359. reportChapterInfo.IsEdit = 1
  360. reportChapterInfo.ModifyTime = time.Now()
  361. if req.CreateTime != `` {
  362. reportChapterInfo.CreateTime = req.CreateTime
  363. updateCols = append(updateCols, "CreateTime")
  364. }
  365. reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  366. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  367. reportChapterInfo.ContentModifyTime = time.Now()
  368. reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  369. updateCols = append(updateCols, "Author", "Content", "ContentSub", "IsEdit", "ModifyTime")
  370. updateCols = append(updateCols, "LastModifyAdminId", "LastModifyAdminName", "ContentModifyTime", "ContentStruct")
  371. // 章节报告更新指标
  372. tickerList := make([]*models.ReportChapterTicker, 0)
  373. if len(reqTickerList) > 0 {
  374. nowTime := time.Now()
  375. for i := 0; i < len(reqTickerList); i++ {
  376. tickerList = append(tickerList, &models.ReportChapterTicker{
  377. ReportChapterId: reportChapterInfo.ReportChapterId,
  378. Sort: reqTickerList[i].Sort,
  379. Ticker: reqTickerList[i].Ticker,
  380. CreateTime: nowTime,
  381. UpdateTime: nowTime,
  382. })
  383. }
  384. }
  385. err = models.UpdateChapterAndTicker(reportInfo, reportChapterInfo, updateCols, tickerList)
  386. if err != nil {
  387. br.Msg = "保存失败"
  388. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  389. return
  390. }
  391. // 标记更新中
  392. {
  393. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  394. if err != nil {
  395. br.Msg = err.Error()
  396. return
  397. }
  398. if markStatus.Status == 1 {
  399. br.Msg = markStatus.Msg
  400. return
  401. }
  402. }
  403. // 备份关键数据
  404. chapters := make([]*models.ReportChapter, 0)
  405. chapters = append(chapters, reportChapterInfo)
  406. go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
  407. br.Ret = 200
  408. br.Success = true
  409. br.Msg = "保存成功"
  410. }
  411. // DelChapter
  412. // @Title 编辑晨周报章节内容
  413. // @Description 编辑晨周报章节内容
  414. // @Param request body models.EditReportChapterReq true "type json string"
  415. // @Success 200 Ret=200 保存成功
  416. // @router /chapter/del [post]
  417. func (this *ReportController) DelChapter() {
  418. br := new(models.BaseResponse).Init()
  419. defer func() {
  420. this.Data["json"] = br
  421. this.ServeJSON()
  422. }()
  423. sysUser := this.SysUser
  424. if sysUser == nil {
  425. br.Msg = "请登录"
  426. br.ErrMsg = "请登录,SysUser Is Empty"
  427. br.Ret = 408
  428. return
  429. }
  430. var req models.DelReportChapterReq
  431. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  432. if err != nil {
  433. br.Msg = "参数解析异常!"
  434. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  435. return
  436. }
  437. reportChapterId := req.ReportChapterId
  438. if reportChapterId <= 0 {
  439. br.Msg = "报告章节ID有误"
  440. return
  441. }
  442. // 获取章节详情
  443. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  444. if err != nil {
  445. br.Msg = "报告章节信息有误"
  446. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  447. return
  448. }
  449. // 获取报告详情
  450. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  451. if err != nil {
  452. br.Msg = "报告信息有误"
  453. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  454. return
  455. }
  456. // 操作权限校验
  457. hasAuth, msg, errMsg, isSendEmail := checkOpPermission(sysUser, reportInfo, reportChapterInfo, true, this.Lang)
  458. if !hasAuth {
  459. br.Msg = msg
  460. br.ErrMsg = errMsg
  461. br.IsSendEmail = isSendEmail
  462. return
  463. }
  464. if reportInfo.State == 2 {
  465. br.Msg = "该报告已发布,不允许编辑"
  466. br.ErrMsg = "该报告已发布,不允许编辑"
  467. br.IsSendEmail = false
  468. return
  469. }
  470. // 删除章节
  471. err, errMsg = services.DelChapter(reportInfo, reportChapterInfo, sysUser)
  472. if err != nil {
  473. br.Msg = "删除失败"
  474. if errMsg != "" {
  475. br.Msg = errMsg
  476. }
  477. br.ErrMsg = "删除失败,Err:" + err.Error()
  478. return
  479. }
  480. // 备份关键数据
  481. chapters := make([]*models.ReportChapter, 0)
  482. chapters = append(chapters, reportChapterInfo)
  483. go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
  484. br.Ret = 200
  485. br.Success = true
  486. br.Msg = "删除成功"
  487. }
  488. // GetReportChapterList
  489. // @Title 获取报告章节列表
  490. // @Description 获取报告章节列表
  491. // @Param ReportId query string true "报告ID"
  492. // @Success 200 {object} company.CompanyListResp
  493. // @router /getReportChapterList [get]
  494. func (this *ReportController) GetReportChapterList() {
  495. br := new(models.BaseResponse).Init()
  496. defer func() {
  497. this.Data["json"] = br
  498. this.ServeJSON()
  499. }()
  500. sysUser := this.SysUser
  501. if sysUser == nil {
  502. br.Msg = "请登录"
  503. br.ErrMsg = "请登录,SysUser Is Empty"
  504. br.Ret = 408
  505. return
  506. }
  507. reqReportId := this.GetString("ReportId")
  508. reportId, _ := strconv.Atoi(reqReportId)
  509. if reportId <= 0 {
  510. br.Msg = "报告ID有误"
  511. return
  512. }
  513. // 获取报告信息
  514. reportInfo, err := models.GetReportByReportId(reportId)
  515. if err != nil {
  516. br.Msg = "获取报告信息失败"
  517. br.ErrMsg = "获取报告信息失败, Err: " + err.Error()
  518. return
  519. }
  520. // 权限校验
  521. isAuth, err := services.CheckReportAuthByReportId(sysUser, reportInfo.AdminId, reportId)
  522. if err != nil {
  523. br.Msg = "获取报告权限失败"
  524. br.ErrMsg = "获取报告权限失败,Err:" + err.Error()
  525. return
  526. }
  527. if !isAuth {
  528. br.Msg = "无操作权限"
  529. br.ErrMsg = "无操作权限"
  530. return
  531. }
  532. // 获取章节列表
  533. chapterList, err := models.GetChapterListByReportId(reportId)
  534. if err != nil {
  535. br.Msg = "获取章节列表失败"
  536. br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
  537. return
  538. }
  539. typeList, err := models.GetReportChapterTypeList()
  540. if err != nil {
  541. br.Msg = "获取章节类型列表失败"
  542. br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
  543. return
  544. }
  545. typeIdImg := make(map[int]string)
  546. for i := 0; i < len(typeList); i++ {
  547. typeIdImg[typeList[i].ReportChapterTypeId] = typeList[i].EditImgUrl
  548. }
  549. resp := make([]models.ReportChapterResp, 0)
  550. if len(chapterList) > 0 {
  551. chapterIdList := make([]int, 0)
  552. // 章节id授权用户列表map
  553. chapterIdGrandListMap := make(map[int][]int)
  554. // 章节id关联品种id列表map
  555. chapterIdPermissionListMap := make(map[int][]int)
  556. for _, v := range chapterList {
  557. chapterIdList = append(chapterIdList, v.ReportChapterId)
  558. }
  559. // 处理章节id授权用户列表
  560. {
  561. chapterGrantObj := report.ReportChapterGrant{}
  562. chapterGrantList, tmpErr := chapterGrantObj.GetGrantListByIdList(chapterIdList)
  563. if tmpErr != nil {
  564. br.Msg = "获取章节id授权用户列表失败"
  565. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  566. return
  567. }
  568. for _, v := range chapterGrantList {
  569. tmpChapterIdGrandList, ok := chapterIdGrandListMap[v.ReportChapterId]
  570. if !ok {
  571. tmpChapterIdGrandList = make([]int, 0)
  572. }
  573. chapterIdGrandListMap[v.ReportChapterId] = append(tmpChapterIdGrandList, v.AdminId)
  574. }
  575. }
  576. // 处理章节id关联品种id列表
  577. {
  578. obj := report.ReportChapterPermissionMapping{}
  579. chapterPermissionList, tmpErr := obj.GetPermissionListByIdList(chapterIdList)
  580. if tmpErr != nil {
  581. br.Msg = "获取章节id关联品种列表失败"
  582. br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
  583. return
  584. }
  585. for _, v := range chapterPermissionList {
  586. tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[v.ReportChapterId]
  587. if !ok {
  588. tmpChapterIdPermissionList = make([]int, 0)
  589. }
  590. chapterIdPermissionListMap[v.ReportChapterId] = append(tmpChapterIdPermissionList, v.ChartPermissionId)
  591. }
  592. }
  593. // 章节类型的字段
  594. for _, item := range chapterList {
  595. // 授权的用户列表
  596. tmpChapterIdGrandList, ok := chapterIdGrandListMap[item.ReportChapterId]
  597. if !ok {
  598. tmpChapterIdGrandList = make([]int, 0)
  599. }
  600. // 关联的品种列表
  601. tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[item.ReportChapterId]
  602. if !ok {
  603. tmpChapterIdPermissionList = make([]int, 0)
  604. }
  605. tmpChapterItem := models.ReportChapterResp{
  606. ReportChapterId: item.ReportChapterId,
  607. ReportId: item.ReportId,
  608. ReportType: item.ReportType,
  609. TypeId: item.TypeId,
  610. TypeName: item.TypeName,
  611. TypeEditImg: typeIdImg[item.TypeId],
  612. Title: item.Title,
  613. IsEdit: item.IsEdit,
  614. Trend: item.Trend,
  615. Sort: item.Sort,
  616. PublishState: item.PublishState,
  617. VideoUrl: item.VideoUrl,
  618. VideoName: item.VideoName,
  619. VideoPlaySeconds: item.VideoPlaySeconds,
  620. VideoSize: item.VideoSize,
  621. VideoKind: item.VideoKind,
  622. ModifyTime: item.ModifyTime.Format(utils.FormatDate),
  623. GrandAdminIdList: tmpChapterIdGrandList,
  624. PermissionIdList: tmpChapterIdPermissionList,
  625. }
  626. markStatus, err := services.UpdateReportEditMark(item.ReportId, item.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  627. if err != nil {
  628. br.Msg = "查询标记状态失败"
  629. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  630. return
  631. }
  632. if markStatus.Status == 0 {
  633. tmpChapterItem.CanEdit = true
  634. } else {
  635. tmpChapterItem.Editor = markStatus.Editor
  636. }
  637. // 报告章节的操作权限
  638. tmpChapterItem.IsAuth = services.CheckChapterAuthByAdminIdList(sysUser, reportInfo.AdminId, tmpChapterIdGrandList)
  639. resp = append(resp, tmpChapterItem)
  640. }
  641. }
  642. br.Ret = 200
  643. br.Success = true
  644. br.Msg = "获取成功"
  645. br.Data = resp
  646. }
  647. // GetDayWeekChapter
  648. // @Title 获取晨周报章节信息
  649. // @Description 获取晨周报章节信息
  650. // @Param ReportChapterId query int true "报告章节ID"
  651. // @Success 200 Ret=200 保存成功
  652. // @router /getDayWeekChapter [get]
  653. func (this *ReportController) GetDayWeekChapter() {
  654. br := new(models.BaseResponse).Init()
  655. defer func() {
  656. this.Data["json"] = br
  657. this.ServeJSON()
  658. }()
  659. sysUser := this.SysUser
  660. if sysUser == nil {
  661. br.Msg = "请登录"
  662. br.ErrMsg = "请登录,SysUser Is Empty"
  663. br.Ret = 408
  664. return
  665. }
  666. reportChapterId, _ := this.GetInt("ReportChapterId")
  667. if reportChapterId <= 0 {
  668. br.Msg = "参数有误"
  669. return
  670. }
  671. chapterItem, err := models.GetReportChapterItemById(reportChapterId)
  672. if err != nil {
  673. br.Msg = "获取章节信息失败"
  674. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  675. return
  676. }
  677. // 获取报告详情
  678. reportInfo, err := models.GetReportById(chapterItem.ReportId)
  679. if err != nil {
  680. br.Msg = "获取报告信息失败"
  681. br.ErrMsg = "获取报告信息失败, Err: " + err.Error()
  682. return
  683. }
  684. // 权限校验
  685. isAuth, err := services.CheckReportAuthByReportId(sysUser, reportInfo.AdminId, reportInfo.Id)
  686. if err != nil {
  687. br.Msg = "获取报告权限失败"
  688. br.ErrMsg = "获取报告权限失败,Err:" + err.Error()
  689. return
  690. }
  691. if !isAuth {
  692. br.Msg = "无操作权限"
  693. br.ErrMsg = "无操作权限"
  694. return
  695. }
  696. chapterItem.Content = html.UnescapeString(chapterItem.Content)
  697. chapterItem.ContentSub = html.UnescapeString(chapterItem.ContentSub)
  698. chapterItem.ContentStruct = html.UnescapeString(chapterItem.ContentStruct)
  699. // 授权用户列表map
  700. chapterGrantIdList := make([]int, 0)
  701. // 关联品种id列表map
  702. chapterPermissionIdList := make([]int, 0)
  703. // 处理章节id授权用户列表
  704. {
  705. chapterGrantObj := report.ReportChapterGrant{}
  706. chapterGrantList, tmpErr := chapterGrantObj.GetGrantListById(chapterItem.ReportChapterId)
  707. if tmpErr != nil {
  708. br.Msg = "获取章节id授权用户列表失败"
  709. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  710. return
  711. }
  712. for _, v := range chapterGrantList {
  713. chapterGrantIdList = append(chapterGrantIdList, v.AdminId)
  714. }
  715. }
  716. // 处理章节id关联品种id列表
  717. {
  718. obj := report.ReportChapterPermissionMapping{}
  719. chapterPermissionList, tmpErr := obj.GetPermissionListById(chapterItem.ReportChapterId)
  720. if tmpErr != nil {
  721. br.Msg = "获取章节id关联品种列表失败"
  722. br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
  723. return
  724. }
  725. for _, v := range chapterPermissionList {
  726. chapterPermissionIdList = append(chapterPermissionIdList, v.ChartPermissionId)
  727. }
  728. }
  729. resp := models.ReportChapterItemResp{
  730. ReportChapterItem: *chapterItem,
  731. GrandAdminIdList: chapterGrantIdList,
  732. PermissionIdList: chapterPermissionIdList,
  733. }
  734. // 获取当前编辑状态
  735. {
  736. markStatus, err := services.UpdateReportEditMark(chapterItem.ReportId, chapterItem.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  737. if err != nil {
  738. br.Msg = "查询标记状态失败"
  739. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  740. return
  741. }
  742. if markStatus.Status == 0 {
  743. resp.CanEdit = true
  744. } else {
  745. resp.Editor = markStatus.Editor
  746. }
  747. }
  748. br.Ret = 200
  749. br.Success = true
  750. br.Msg = "获取成功"
  751. br.Data = resp
  752. }
  753. // ChapterMove
  754. // @Title 移动章节类型
  755. // @Description 移动章节类型
  756. // @Param request body models.PermissionMoveReq true "type json string"
  757. // @Success 200 Ret=200 操作成功
  758. // @router /chapter/move [post]
  759. func (this *ReportController) ChapterMove() {
  760. br := new(models.BaseResponse).Init()
  761. defer func() {
  762. if br.ErrMsg == "" {
  763. br.IsSendEmail = false
  764. }
  765. this.Data["json"] = br
  766. this.ServeJSON()
  767. }()
  768. sysUser := this.SysUser
  769. if sysUser == nil {
  770. br.Msg = "请登录"
  771. br.ErrMsg = "请登录,SysUser Is Empty"
  772. br.Ret = 408
  773. return
  774. }
  775. var req models.ReportChapterMoveReq
  776. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  777. br.Msg = "参数解析异常!"
  778. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  779. return
  780. }
  781. if req.ReportChapterId == 0 {
  782. br.Msg = "请选择要移动的章节"
  783. return
  784. }
  785. e, msg := services.MoveReportChapter(&req)
  786. if e != nil {
  787. br.Msg = msg
  788. br.ErrMsg = "移动品种失败, Err: " + e.Error()
  789. return
  790. }
  791. br.Ret = 200
  792. br.Success = true
  793. br.Msg = "操作成功"
  794. }
  795. // EditChapterTrendTag
  796. // @Title 编辑章节趋势标签
  797. // @Description 编辑章节趋势标签
  798. // @Param request body models.EditReportChapterReq true "type json string"
  799. // @Success 200 Ret=200 保存成功
  800. // @router /editChapterTrendTag [post]
  801. func (this *ReportController) EditChapterTrendTag() {
  802. br := new(models.BaseResponse).Init()
  803. defer func() {
  804. this.Data["json"] = br
  805. this.ServeJSON()
  806. }()
  807. sysUser := this.SysUser
  808. if sysUser == nil {
  809. br.Msg = "请登录"
  810. br.ErrMsg = "请登录,SysUser Is Empty"
  811. br.Ret = 408
  812. return
  813. }
  814. var req models.EditChapterTrendTagReq
  815. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  816. if err != nil {
  817. br.Msg = "参数解析异常!"
  818. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  819. return
  820. }
  821. if req.ReportChapterId <= 0 {
  822. br.Msg = "章节ID有误"
  823. return
  824. }
  825. if req.Trend == "" {
  826. br.Msg = "请输入标签"
  827. return
  828. }
  829. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  830. if err != nil {
  831. br.Msg = "获取章节信息失败"
  832. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  833. return
  834. }
  835. // 获取报告详情
  836. reportInfo, err := models.GetReportByReportId(chapterInfo.ReportId)
  837. if err != nil {
  838. br.Msg = "报告信息有误"
  839. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  840. return
  841. }
  842. // 操作权限校验
  843. hasAuth, msg, errMsg, isSendEmail := checkOpPermission(sysUser, reportInfo, chapterInfo, false, this.Lang)
  844. if !hasAuth {
  845. br.Msg = msg
  846. br.ErrMsg = errMsg
  847. br.IsSendEmail = isSendEmail
  848. return
  849. }
  850. // 更新章节标签
  851. chapterInfo.Trend = req.Trend
  852. updateCols := make([]string, 0)
  853. updateCols = append(updateCols, "Trend")
  854. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  855. br.Msg = "更新标签失败"
  856. br.ErrMsg = "更新标签失败, Err: " + err.Error()
  857. return
  858. }
  859. // 添加关键词
  860. if err = models.AddTrendTagKeyWord(req.Trend); err != nil {
  861. br.Msg = "添加标签关键词失败"
  862. br.ErrMsg = "添加标签关键词失败, Err: " + err.Error()
  863. return
  864. }
  865. br.Ret = 200
  866. br.Success = true
  867. br.Msg = "保存成功"
  868. }
  869. // GetSunCode 获取太阳码
  870. // @Title 公共模块
  871. // @Description 获取分享海报
  872. // @Param request body models.SunCodeReq true "type json string"
  873. // @Success 200 {object} string "获取成功"
  874. // @failure 400 {string} string "获取失败"
  875. // @router /getSunCode [post]
  876. func (this *ReportController) GetSunCode() {
  877. br := new(models.BaseResponse).Init()
  878. defer func() {
  879. this.Data["json"] = br
  880. this.ServeJSON()
  881. }()
  882. sysUser := this.SysUser
  883. if sysUser == nil {
  884. br.Msg = "请登录"
  885. br.ErrMsg = "请登录,SysUser Is Empty"
  886. br.Ret = 408
  887. return
  888. }
  889. var req models.SunCodeReq
  890. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  891. if err != nil {
  892. br.Msg = "参数解析异常!"
  893. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  894. return
  895. }
  896. var sunCodeUrl string
  897. //先查,查不到再去生成上传
  898. item, err := models.GetYbPcSunCode(req.CodeScene, req.CodePage)
  899. if err != nil && err.Error() != utils.ErrNoRow() {
  900. br.Msg = "查询太阳码失败!"
  901. br.ErrMsg = "查询太阳码失败,Err:" + err.Error()
  902. return
  903. }
  904. if item != nil {
  905. sunCodeUrl = item.SuncodeUrl
  906. }
  907. if sunCodeUrl == "" {
  908. sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
  909. if err != nil {
  910. br.Msg = "生成太阳码失败!"
  911. br.ErrMsg = "生成太阳码失败,Err:" + err.Error()
  912. return
  913. }
  914. }
  915. br.Data = sunCodeUrl
  916. br.Ret = 200
  917. br.Success = true
  918. br.Msg = "操作成功"
  919. }
  920. // VoiceUpload
  921. // @Title 音频上传
  922. // @Description 音频上传接口
  923. // @Param file query file true "文件"
  924. // @Param ReportChapterId query int true "报告章节ID"
  925. // @Success Ret=200 上传成功
  926. // @router /chapter/voice/upload [post]
  927. func (this *ReportController) VoiceUpload() {
  928. br := new(models.BaseResponse).Init()
  929. defer func() {
  930. this.Data["json"] = br
  931. this.ServeJSON()
  932. }()
  933. f, h, err := this.GetFile("file")
  934. if err != nil {
  935. br.Msg = "获取资源信息失败"
  936. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  937. return
  938. }
  939. // 报告章节id
  940. reportChapterId, err := this.GetInt("ReportChapterId", 0)
  941. if err != nil {
  942. br.Msg = "报告章节ID异常"
  943. br.ErrMsg = "报告章节ID异常,Err:" + err.Error()
  944. return
  945. }
  946. // 报告章节信息
  947. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  948. if err != nil {
  949. br.Msg = "获取报告章节信息失败"
  950. br.ErrMsg = "获取报告章节信息失败,Err:" + err.Error()
  951. return
  952. }
  953. // 报告信息
  954. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  955. if err != nil {
  956. br.Msg = "获取报告信息失败"
  957. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  958. return
  959. }
  960. // 权限校验
  961. isAuth, err := services.CheckChapterAuthByReportChapterInfo(this.SysUser, reportInfo.AdminId, reportChapterInfo)
  962. if err != nil {
  963. br.Msg = "获取报告权限失败"
  964. br.ErrMsg = "获取报告权限失败,Err:" + err.Error()
  965. return
  966. }
  967. if !isAuth {
  968. br.Msg = "无操作权限"
  969. br.ErrMsg = "无操作权限"
  970. return
  971. }
  972. ext := path.Ext(h.Filename)
  973. dateDir := time.Now().Format("20060102")
  974. uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
  975. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  976. if err != nil {
  977. br.Msg = "存储目录创建失败"
  978. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  979. return
  980. }
  981. randStr := utils.GetRandStringNoSpecialChar(28)
  982. fileName := randStr + ext
  983. fPath := uploadDir + "/" + fileName
  984. defer f.Close() //关闭上传文件
  985. err = this.SaveToFile("file", fPath)
  986. if err != nil {
  987. br.Msg = "文件上传失败"
  988. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  989. return
  990. }
  991. resourceUrl := ``
  992. //上传到阿里云 和 minio
  993. //if utils.ObjectStorageClient == "minio" {
  994. // resourceUrl, err = services.UploadAudioToMinIo(fileName, fPath)
  995. // if err != nil {
  996. // br.Msg = "文件上传失败"
  997. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  998. // return
  999. // }
  1000. //} else {
  1001. // resourceUrl, err = services.UploadAudioAliyun(fileName, fPath)
  1002. // if err != nil {
  1003. // br.Msg = "文件上传失败"
  1004. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1005. // return
  1006. // }
  1007. //}
  1008. ossClient := services.NewOssClient()
  1009. if ossClient == nil {
  1010. br.Msg = "上传失败"
  1011. br.ErrMsg = "初始化OSS服务失败"
  1012. return
  1013. }
  1014. resourceUrl, err = ossClient.UploadFile(fileName, fPath, "")
  1015. if err != nil {
  1016. br.Msg = "文件上传失败"
  1017. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1018. return
  1019. }
  1020. defer func() {
  1021. os.Remove(fPath)
  1022. }()
  1023. item := new(models.Resource)
  1024. item.ResourceUrl = resourceUrl
  1025. item.ResourceType = 2
  1026. item.CreateTime = time.Now()
  1027. newId, err := models.AddResource(item)
  1028. if err != nil {
  1029. br.Msg = "资源上传失败"
  1030. br.ErrMsg = "资源上传失败,Err:" + err.Error()
  1031. return
  1032. }
  1033. //var playSeconds float64
  1034. //playSeconds, err = mp3duration.Calculate(fPath)
  1035. //if playSeconds <= 0 {
  1036. // playSeconds, err = utils.GetVideoPlaySeconds(fPath)
  1037. // if err != nil {
  1038. // br.Msg = "获取音频时间失败"
  1039. // br.ErrMsg = "获取音频时间失败,Err:" + err.Error()
  1040. // return
  1041. // }
  1042. //}
  1043. playSecondsStr, err := utils.GetDuration(fPath) //mp3duration.Calculate(fPath)
  1044. if err != nil {
  1045. utils.FileLog.Info("获取音频时间失败,Err:" + err.Error())
  1046. }
  1047. fileBody, err := os.ReadFile(fPath)
  1048. videoSize := len(fileBody)
  1049. sizeFloat := (float64(videoSize) / float64(1024)) / float64(1024)
  1050. sizeStr := utils.SubFloatToFloatStr(sizeFloat, 2)
  1051. {
  1052. reportChapterCreateTime, err := time.Parse(utils.FormatDateTime, reportChapterInfo.CreateTime)
  1053. if err != nil {
  1054. br.Msg = "上传失败"
  1055. br.ErrMsg = "上传失败,Err:" + err.Error()
  1056. return
  1057. }
  1058. createTimeStr := reportChapterCreateTime.Format("0102")
  1059. videoName := reportChapterInfo.Title + "(" + createTimeStr + ")"
  1060. reportChapterInfo.VideoUrl = resourceUrl
  1061. reportChapterInfo.VideoName = videoName
  1062. reportChapterInfo.VideoPlaySeconds = playSecondsStr //fmt.Sprint(playSeconds)
  1063. reportChapterInfo.VideoSize = sizeStr
  1064. reportChapterInfo.VideoKind = 1
  1065. reportChapterInfo.LastModifyAdminId = this.SysUser.AdminId
  1066. reportChapterInfo.LastModifyAdminName = this.SysUser.RealName
  1067. reportInfo.VoiceGenerateType = 1
  1068. reportChapterInfo.ModifyTime = time.Now()
  1069. err = reportChapterInfo.UpdateChapter([]string{"VideoUrl", "VideoName", "VideoPlaySeconds", "VideoSize", "VideoKind", "LastModifyAdminId", "LastModifyAdminName", "VoiceGenerateType", "ModifyTime"})
  1070. if err != nil {
  1071. br.Msg = "上传失败"
  1072. br.ErrMsg = "修改报告章节的音频信息失败,Err:" + err.Error()
  1073. return
  1074. }
  1075. // 修改报告的最近更新人信息
  1076. reportInfo.LastModifyAdminId = this.SysUser.AdminId
  1077. reportInfo.LastModifyAdminName = this.SysUser.RealName
  1078. reportInfo.ModifyTime = time.Now()
  1079. err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1080. if err != nil {
  1081. br.Msg = "上传失败"
  1082. br.ErrMsg = "修改报告最后更新人信息失败,Err:" + err.Error()
  1083. return
  1084. }
  1085. }
  1086. // 处理报告中的音频文件分贝
  1087. go services.HandleVideoDecibel(reportChapterInfo)
  1088. resp := new(models.ResourceResp)
  1089. resp.Id = newId
  1090. resp.ResourceUrl = resourceUrl
  1091. br.Msg = "上传成功"
  1092. br.Ret = 200
  1093. br.Success = true
  1094. br.Data = resp
  1095. return
  1096. }
  1097. // PublishDayWeekReportChapter
  1098. // @Title 发布章节
  1099. // @Description 发布章节
  1100. // @Param request body models.PublishReportChapterReq true "type json string"
  1101. // @Success 200 Ret=200 操作成功
  1102. // @router /publishDayWeekReportChapter [post]
  1103. func (this *ReportController) PublishDayWeekReportChapter() {
  1104. br := new(models.BaseResponse).Init()
  1105. defer func() {
  1106. this.Data["json"] = br
  1107. this.ServeJSON()
  1108. }()
  1109. sysUser := this.SysUser
  1110. if sysUser == nil {
  1111. br.Msg = "请登录"
  1112. br.ErrMsg = "请登录,SysUser Is Empty"
  1113. br.Ret = 408
  1114. return
  1115. }
  1116. var req models.PublishReportChapterReq
  1117. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1118. if err != nil {
  1119. br.Msg = "参数解析异常!"
  1120. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1121. return
  1122. }
  1123. if req.ReportChapterId <= 0 {
  1124. br.Msg = "参数有误"
  1125. return
  1126. }
  1127. // 获取报告详情
  1128. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  1129. if err != nil {
  1130. br.Msg = "章节信息有误"
  1131. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  1132. return
  1133. }
  1134. reportInfo, err := models.GetReportByReportId(chapterInfo.ReportId)
  1135. if err != nil {
  1136. br.Msg = "查询报告有误"
  1137. br.ErrMsg = "查询报告信息失败, Err: " + err.Error()
  1138. return
  1139. }
  1140. if reportInfo.State == 2 {
  1141. br.Msg = "该报告已发布,不允许编辑"
  1142. br.ErrMsg = "该报告已发布,不允许编辑"
  1143. br.IsSendEmail = false
  1144. return
  1145. }
  1146. // 图表刷新状态
  1147. refreshResult := data.CheckBatchChartRefreshResult("report", chapterInfo.ReportId, chapterInfo.ReportChapterId)
  1148. if !refreshResult {
  1149. br.Msg = "图表刷新未完成,请稍后操作"
  1150. br.ErrMsg = "图表刷新未完成,请稍后操作"
  1151. br.IsSendEmail = false
  1152. return
  1153. }
  1154. // 如果是系统章节,那么需要校验下是否已经停更
  1155. if chapterInfo.TypeId > 0 {
  1156. // 获取规则配置
  1157. reportChapterTypeRule, err := models.GetReportChapterTypeById(chapterInfo.TypeId)
  1158. if err != nil {
  1159. br.Msg = "获取配置信息异常"
  1160. br.ErrMsg = "获取配置信息异常, Err: " + err.Error()
  1161. return
  1162. }
  1163. if reportChapterTypeRule.Enabled == 0 {
  1164. br.Msg = "该章节已永久停更"
  1165. br.ErrMsg = "该章节已永久停更 "
  1166. br.IsSendEmail = false
  1167. return
  1168. }
  1169. }
  1170. var publishTime time.Time
  1171. if reportInfo.MsgIsSend == 1 && !reportInfo.PublishTime.IsZero() { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
  1172. publishTime = reportInfo.PublishTime
  1173. } else {
  1174. publishTime = time.Now()
  1175. }
  1176. // 更新报告的最后编辑人
  1177. reportInfo.LastModifyAdminId = sysUser.AdminId
  1178. reportInfo.LastModifyAdminName = sysUser.RealName
  1179. reportInfo.ModifyTime = time.Now()
  1180. err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1181. if err != nil {
  1182. br.Msg = "发布失败"
  1183. br.ErrMsg = "报告最后编辑人保存失败, Err: " + err.Error()
  1184. return
  1185. }
  1186. // 更新章节信息
  1187. chapterInfo.IsEdit = 1
  1188. chapterInfo.PublishState = 2
  1189. chapterInfo.PublishTime = publishTime
  1190. chapterInfo.LastModifyAdminId = this.SysUser.AdminId
  1191. chapterInfo.LastModifyAdminName = this.SysUser.RealName
  1192. chapterInfo.ModifyTime = time.Now()
  1193. updateCols := make([]string, 0)
  1194. updateCols = append(updateCols, "IsEdit", "PublishState", "PublishTime", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
  1195. err = chapterInfo.UpdateChapter(updateCols)
  1196. if err != nil {
  1197. br.Msg = "发布失败"
  1198. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1199. return
  1200. }
  1201. // 修改报告的最近更新人信息
  1202. go func() {
  1203. reportInfo.LastModifyAdminId = this.SysUser.AdminId
  1204. reportInfo.LastModifyAdminName = this.SysUser.RealName
  1205. reportInfo.ModifyTime = time.Now()
  1206. err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1207. if err != nil {
  1208. br.Msg = "上传失败"
  1209. br.ErrMsg = "修改报告最后更新人信息失败,Err:" + err.Error()
  1210. return
  1211. }
  1212. }()
  1213. // 生成音频
  1214. go services.UpdateChaptersVideo([]int{chapterInfo.ReportChapterId})
  1215. // 更新章节ES
  1216. {
  1217. go services.UpdateReportChapterEs(chapterInfo.ReportChapterId, reportInfo.IsPublicPublish)
  1218. }
  1219. // 同时发布报告
  1220. //if req.PublishReport == 1 {
  1221. // if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
  1222. // br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
  1223. // br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
  1224. // return
  1225. // }
  1226. //}
  1227. br.Ret = 200
  1228. br.Success = true
  1229. br.Msg = "操作成功"
  1230. }
  1231. // GetUnPublishReportChapterList
  1232. // @Title 获取报告中未发布的章节数
  1233. // @Description 获取报告中未发布的章节数
  1234. // @Param ReportId query int true "报告ID"
  1235. // @Success 200 Ret=200 获取成功
  1236. // @router /chapter/un_publish/list [get]
  1237. func (this *ReportController) GetUnPublishReportChapterList() {
  1238. br := new(models.BaseResponse).Init()
  1239. defer func() {
  1240. this.Data["json"] = br
  1241. this.ServeJSON()
  1242. }()
  1243. sysUser := this.SysUser
  1244. if sysUser == nil {
  1245. br.Msg = "请登录"
  1246. br.ErrMsg = "请登录,SysUser Is Empty"
  1247. br.Ret = 408
  1248. return
  1249. }
  1250. reportId, _ := this.GetInt("ReportId")
  1251. if reportId <= 0 {
  1252. br.Msg = "参数有误"
  1253. br.IsSendEmail = false
  1254. return
  1255. }
  1256. reportInfo, err := models.GetReportById(reportId)
  1257. if err != nil {
  1258. br.Msg = "报告有误"
  1259. br.ErrMsg = "报告有误, Err: " + err.Error()
  1260. return
  1261. }
  1262. if reportInfo.HasChapter == 0 {
  1263. br.Msg = "报告未包含章节"
  1264. br.IsSendEmail = false
  1265. return
  1266. }
  1267. // 获取未发布的章节列表
  1268. unPublishedList, err := models.GetUnPublishedChapterList(reportInfo.Id)
  1269. if err != nil {
  1270. br.Msg = "获取未发布的章节数失败"
  1271. br.ErrMsg = "获取未发布的章节数失败, Err: " + err.Error()
  1272. return
  1273. }
  1274. br.Ret = 200
  1275. br.Success = true
  1276. br.Msg = "获取成功"
  1277. br.Data = unPublishedList
  1278. }
  1279. // EditChapterTitle
  1280. // @Title 编辑章节标题
  1281. // @Description 编辑章节标题
  1282. // @Param request body models.EditReportChapterReq true "type json string"
  1283. // @Success 200 Ret=200 保存成功
  1284. // @router /chapter/title/edit [post]
  1285. func (this *ReportController) EditChapterTitle() {
  1286. br := new(models.BaseResponse).Init()
  1287. defer func() {
  1288. this.Data["json"] = br
  1289. this.ServeJSON()
  1290. }()
  1291. sysUser := this.SysUser
  1292. if sysUser == nil {
  1293. br.Msg = "请登录"
  1294. br.ErrMsg = "请登录,SysUser Is Empty"
  1295. br.Ret = 408
  1296. return
  1297. }
  1298. var req models.EditReportChapterReq
  1299. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1300. if err != nil {
  1301. br.Msg = "参数解析异常!"
  1302. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1303. return
  1304. }
  1305. reportChapterId := req.ReportChapterId
  1306. if reportChapterId <= 0 {
  1307. br.Msg = "报告章节ID有误"
  1308. return
  1309. }
  1310. req.Title = strings.TrimSpace(req.Title)
  1311. if req.Title == `` {
  1312. br.Msg = "章节名称不能为空"
  1313. return
  1314. }
  1315. // 获取章节详情
  1316. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  1317. if err != nil {
  1318. br.Msg = "报告章节信息有误"
  1319. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  1320. return
  1321. }
  1322. // 判断名称是否重复
  1323. {
  1324. var condition string
  1325. var pars []interface{}
  1326. condition += " AND report_id = ? AND title=? AND report_chapter_id != ? "
  1327. pars = append(pars, reportChapterInfo.ReportId, req.Title, reportChapterId)
  1328. count, err := models.GetCountReportChapterByCondition(condition, pars)
  1329. if err != nil {
  1330. br.Msg = "新增失败"
  1331. br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
  1332. return
  1333. }
  1334. if count > 0 {
  1335. br.Msg = "章节名称不允许重复"
  1336. br.ErrMsg = "章节名称不允许重复"
  1337. br.IsSendEmail = false
  1338. return
  1339. }
  1340. }
  1341. // 获取报告详情
  1342. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  1343. if err != nil {
  1344. br.Msg = "报告信息有误"
  1345. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  1346. return
  1347. }
  1348. // 操作权限校验
  1349. hasAuth, msg, errMsg, isSendEmail := checkOpPermission(sysUser, reportInfo, reportChapterInfo, true, this.Lang)
  1350. if !hasAuth {
  1351. br.Msg = msg
  1352. br.ErrMsg = errMsg
  1353. br.IsSendEmail = isSendEmail
  1354. return
  1355. }
  1356. if reportInfo.State == 2 {
  1357. br.Msg = "该报告已发布,不允许编辑"
  1358. br.ErrMsg = "该报告已发布,不允许编辑"
  1359. br.IsSendEmail = false
  1360. return
  1361. }
  1362. // 报告的最后编辑人
  1363. reportInfo.LastModifyAdminId = sysUser.AdminId
  1364. reportInfo.LastModifyAdminName = sysUser.RealName
  1365. reportInfo.ModifyTime = time.Now()
  1366. reportChapterInfo.Title = req.Title
  1367. reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  1368. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  1369. reportChapterInfo.ModifyTime = time.Now()
  1370. updateCols := make([]string, 0)
  1371. updateCols = append(updateCols, "Title", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
  1372. // 更新报告的最近编辑人信息
  1373. if err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"}); err != nil {
  1374. br.Msg = "保存失败"
  1375. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1376. return
  1377. }
  1378. // 更新章节
  1379. if err = reportChapterInfo.UpdateChapter(updateCols); err != nil {
  1380. br.Msg = "保存失败"
  1381. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1382. return
  1383. }
  1384. // 标记更新中
  1385. {
  1386. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  1387. if err != nil {
  1388. br.Msg = err.Error()
  1389. return
  1390. }
  1391. if markStatus.Status == 1 {
  1392. br.Msg = markStatus.Msg
  1393. return
  1394. }
  1395. }
  1396. br.Ret = 200
  1397. br.Success = true
  1398. br.Msg = "保存成功"
  1399. }
  1400. // CancelPublishReportChapter
  1401. // @Title 取消发布章节
  1402. // @Description 取消发布章节
  1403. // @Param request body models.PublishReportChapterReq true "type json string"
  1404. // @Success 200 Ret=200 操作成功
  1405. // @router /chapter/publish/cancel [post]
  1406. func (this *ReportController) CancelPublishReportChapter() {
  1407. br := new(models.BaseResponse).Init()
  1408. defer func() {
  1409. this.Data["json"] = br
  1410. this.ServeJSON()
  1411. }()
  1412. sysUser := this.SysUser
  1413. if sysUser == nil {
  1414. br.Msg = "请登录"
  1415. br.ErrMsg = "请登录,SysUser Is Empty"
  1416. br.Ret = 408
  1417. return
  1418. }
  1419. var req models.PublishReportChapterReq
  1420. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1421. if err != nil {
  1422. br.Msg = "参数解析异常!"
  1423. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1424. return
  1425. }
  1426. if req.ReportChapterId <= 0 {
  1427. br.Msg = "参数有误"
  1428. return
  1429. }
  1430. // 获取章节详情
  1431. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  1432. if err != nil {
  1433. br.Msg = "章节信息有误"
  1434. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  1435. return
  1436. }
  1437. // 章节发布状态校验
  1438. if chapterInfo.PublishState == 1 {
  1439. br.Msg = "该章节未发布,不能重复撤销"
  1440. br.ErrMsg = "该章节未发布,不能重复撤销"
  1441. br.IsSendEmail = false
  1442. return
  1443. }
  1444. // 获取报告详情
  1445. reportInfo, err := models.GetReportByReportId(chapterInfo.ReportId)
  1446. if err != nil {
  1447. br.Msg = "查询报告有误"
  1448. br.ErrMsg = "查询报告信息失败, Err: " + err.Error()
  1449. return
  1450. }
  1451. if reportInfo.State == 2 {
  1452. br.Msg = "该报告已发布,不允许撤销章节"
  1453. br.ErrMsg = "该报告已发布,不允许撤销章节"
  1454. br.IsSendEmail = false
  1455. return
  1456. }
  1457. // 更新章节信息
  1458. chapterInfo.PublishState = 1
  1459. chapterInfo.PublishTime = time.Time{}
  1460. chapterInfo.LastModifyAdminId = this.SysUser.AdminId
  1461. chapterInfo.LastModifyAdminName = this.SysUser.RealName
  1462. chapterInfo.ModifyTime = time.Now()
  1463. updateCols := make([]string, 0)
  1464. updateCols = append(updateCols, "PublishState", "PublishTime", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
  1465. err = chapterInfo.UpdateChapter(updateCols)
  1466. if err != nil {
  1467. br.Msg = "发布失败"
  1468. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1469. return
  1470. }
  1471. // 更新章节ES
  1472. {
  1473. go services.UpdateReportChapterEs(chapterInfo.ReportChapterId, reportInfo.IsPublicPublish)
  1474. }
  1475. br.Ret = 200
  1476. br.Success = true
  1477. br.Msg = "撤销成功"
  1478. }
  1479. // checkOpPermission
  1480. // @Description: 操作权限校验
  1481. // @author: Roc
  1482. // @datetime 2024-11-12 09:58:34
  1483. // @param sysUser *system.Admin
  1484. // @param reportInfo *models.Report
  1485. // @param reportChapterInfo *models.ReportChapter
  1486. // @param isMarkStatus bool
  1487. // @param lang string
  1488. // @return hasAuth bool
  1489. // @return msg string
  1490. // @return errMsg string
  1491. // @return isSendEmail bool
  1492. func checkOpPermission(sysUser *system.Admin, reportInfo *models.Report, reportChapterInfo *models.ReportChapter, isMarkStatus bool, lang string) (hasAuth bool, msg, errMsg string, isSendEmail bool) {
  1493. isSendEmail = true
  1494. // 权限校验
  1495. isAuth, err := services.CheckChapterAuthByReportChapterInfo(sysUser, reportInfo.AdminId, reportChapterInfo)
  1496. if err != nil {
  1497. msg = "获取报告权限失败"
  1498. errMsg = "获取报告权限失败,Err:" + err.Error()
  1499. return
  1500. }
  1501. if !isAuth {
  1502. msg = "没有权限"
  1503. errMsg = "没有权限"
  1504. isSendEmail = false
  1505. return
  1506. }
  1507. // 如果不是创建人,那么就要去查看是否授权
  1508. //if reportInfo.AdminId != sysUser.AdminId && !utils.IsAdminRole(sysUser.RoleTypeCode) {
  1509. // // 授权用户权限校验
  1510. // chapterGrantObj := report.ReportChapterGrant{}
  1511. // _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, sysUser.AdminId)
  1512. // if tmpErr != nil {
  1513. // if tmpErr.Error() == utils.ErrNoRow() {
  1514. // msg = "没有权限"
  1515. // errMsg = "没有权限"
  1516. // isSendEmail = false
  1517. // return
  1518. // }
  1519. // msg = "获取章节id授权用户失败"
  1520. // errMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
  1521. // return
  1522. // }
  1523. //}
  1524. // 标记更新中
  1525. if isMarkStatus {
  1526. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, lang)
  1527. if err != nil {
  1528. msg = err.Error()
  1529. errMsg = err.Error()
  1530. return
  1531. }
  1532. if markStatus.Status == 1 {
  1533. msg = markStatus.Msg
  1534. errMsg = markStatus.Msg
  1535. isSendEmail = false
  1536. return
  1537. }
  1538. }
  1539. // 有权限
  1540. hasAuth = true
  1541. return
  1542. }