report_chapter.go 48 KB

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