report_chapter.go 38 KB

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