report_chapter.go 48 KB

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