report_chapter.go 39 KB

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