report_chapter.go 45 KB

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