report_chapter.go 47 KB

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