report_chapter.go 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/report"
  6. "eta/eta_api/services"
  7. "eta/eta_api/services/data"
  8. "eta/eta_api/utils"
  9. "fmt"
  10. "github.com/kgiannakakis/mp3duration/src/mp3duration"
  11. "html"
  12. "os"
  13. "path"
  14. "strconv"
  15. "strings"
  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. req.Title = strings.TrimSpace(req.Title)
  49. if req.Title == `` {
  50. br.Msg = "章节名称不能为空"
  51. return
  52. }
  53. // 获取报告详情
  54. reportInfo, err := models.GetReportByReportId(req.ReportId)
  55. if err != nil {
  56. br.Msg = "报告信息有误"
  57. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  58. return
  59. }
  60. if reportInfo.State == 2 {
  61. br.Msg = "该报告已发布,不允许新增"
  62. br.ErrMsg = "该报告已发布,不允许新增"
  63. return
  64. }
  65. //newContent := req.Content
  66. //// 更新章节及指标
  67. //contentSub := ""
  68. //if req.Content != "" {
  69. // e := utils.ContentXssCheck(req.Content)
  70. // if e != nil {
  71. // br.Msg = "存在非法标签"
  72. // br.ErrMsg = "存在非法标签, Err: " + e.Error()
  73. // return
  74. // }
  75. // contentClean, e := services.FilterReportContentBr(req.Content)
  76. // if e != nil {
  77. // br.Msg = "内容去除前后空格失败"
  78. // br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  79. // return
  80. // }
  81. // req.Content = contentClean
  82. //
  83. // contentSub, err = services.GetReportContentSub(req.Content)
  84. // if err != nil {
  85. // br.Msg = "内容分段解析失败"
  86. // br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
  87. // return
  88. // }
  89. //}
  90. //if req.Content == "" {
  91. // req.Content = newContent
  92. //}
  93. // 最小单元的分类
  94. var minClassifyId int
  95. var minClassifyName string
  96. if reportInfo.ClassifyIdThird > 0 {
  97. minClassifyId = reportInfo.ClassifyIdThird
  98. minClassifyName = reportInfo.ClassifyNameThird
  99. } else if reportInfo.ClassifyIdSecond > 0 {
  100. minClassifyId = reportInfo.ClassifyIdSecond
  101. minClassifyName = reportInfo.ClassifyNameSecond
  102. } else {
  103. minClassifyId = reportInfo.ClassifyIdFirst
  104. minClassifyName = reportInfo.ClassifyNameFirst
  105. }
  106. // 判断名称是否重复
  107. {
  108. var condition string
  109. var pars []interface{}
  110. condition += " AND report_id = ? AND title=? "
  111. pars = append(pars, req.ReportId, req.Title)
  112. count, err := models.GetCountReportChapterByCondition(condition, pars)
  113. if err != nil {
  114. br.Msg = "新增失败"
  115. br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
  116. return
  117. }
  118. if count > 0 {
  119. br.Msg = "章节名称不允许重复"
  120. br.ErrMsg = "章节名称不允许重复"
  121. br.IsSendEmail = false
  122. return
  123. }
  124. }
  125. reportChapterInfo := new(models.ReportChapter)
  126. reportChapterInfo.ReportId = reportInfo.Id
  127. reportChapterInfo.ClassifyIdFirst = minClassifyId
  128. reportChapterInfo.ClassifyNameFirst = minClassifyName
  129. reportChapterInfo.Title = req.Title
  130. reportChapterInfo.AddType = 1
  131. reportChapterInfo.PublishState = 1
  132. //reportChapterInfo.Author = req.Author
  133. //reportChapterInfo.Content = html.EscapeString(req.Content)
  134. //reportChapterInfo.ContentSub = html.EscapeString(contentSub)
  135. reportChapterInfo.IsEdit = 1
  136. //reportChapterInfo.CreateTime = req.CreateTime
  137. reportChapterInfo.CreateTime = reportInfo.CreateTime
  138. reportChapterInfo.ModifyTime = time.Now()
  139. reportChapterInfo.ReportCreateTime = time.Now()
  140. reportChapterInfo.VideoKind = 2
  141. reportChapterInfo.Stage = reportInfo.Stage
  142. reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  143. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  144. reportChapterInfo.ContentModifyTime = time.Now()
  145. //reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  146. //reportChapterInfo.CanvasColor = req.CanvasColor
  147. //reportChapterInfo.HeadResourceId = req.HeadResourceId
  148. //reportChapterInfo.EndResourceId = req.EndResourceId
  149. err, errMsg := services.AddChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.PermissionIdList, req.AdminIdList)
  150. if err != nil {
  151. br.Msg = "保存失败"
  152. if errMsg != "" {
  153. br.Msg = errMsg
  154. }
  155. br.ErrMsg = "保存失败,Err:" + err.Error()
  156. return
  157. }
  158. br.Ret = 200
  159. br.Success = true
  160. br.Msg = "保存成功"
  161. }
  162. // EditChapterBaseInfoAndPermission
  163. // @Title 修改报告章节的基础信息、授权用户权限、品种权限
  164. // @Description 修改报告章节的基础信息、授权用户权限、品种权限
  165. // @Param request body models.EditReportChapterReq true "type json string"
  166. // @Success 200 Ret=200 保存成功
  167. // @router /chapter/base_info/edit [post]
  168. func (this *ReportController) EditChapterBaseInfoAndPermission() {
  169. br := new(models.BaseResponse).Init()
  170. defer func() {
  171. this.Data["json"] = br
  172. this.ServeJSON()
  173. }()
  174. sysUser := this.SysUser
  175. if sysUser == nil {
  176. br.Msg = "请登录"
  177. br.ErrMsg = "请登录,SysUser Is Empty"
  178. br.Ret = 408
  179. return
  180. }
  181. var req models.EditReportChapterBaseInfoAndPermissionReq
  182. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  183. if err != nil {
  184. br.Msg = "参数解析异常!"
  185. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  186. return
  187. }
  188. reportChapterId := req.ReportChapterId
  189. if reportChapterId <= 0 {
  190. br.Msg = "报告章节ID有误"
  191. return
  192. }
  193. req.Title = strings.TrimSpace(req.Title)
  194. if req.Title == `` {
  195. br.Msg = "章节名称不能为空"
  196. return
  197. }
  198. // 获取章节详情
  199. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  200. if err != nil {
  201. br.Msg = "报告章节信息有误"
  202. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  203. return
  204. }
  205. // 判断名称是否重复
  206. {
  207. var condition string
  208. var pars []interface{}
  209. condition += " AND report_id = ? AND title=? AND report_chapter_id != ? "
  210. pars = append(pars, reportChapterInfo.ReportId, req.Title, reportChapterId)
  211. count, err := models.GetCountReportChapterByCondition(condition, pars)
  212. if err != nil {
  213. br.Msg = "新增失败"
  214. br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
  215. return
  216. }
  217. if count > 0 {
  218. br.Msg = "章节名称不允许重复"
  219. br.ErrMsg = "章节名称不允许重复"
  220. br.IsSendEmail = false
  221. return
  222. }
  223. }
  224. // 获取报告详情
  225. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  226. if err != nil {
  227. br.Msg = "报告信息有误"
  228. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  229. return
  230. }
  231. if reportInfo.State == 2 {
  232. br.Msg = "该报告已发布,不允许编辑"
  233. br.ErrMsg = "该报告已发布,不允许编辑"
  234. br.IsSendEmail = false
  235. return
  236. }
  237. // 报告的最后编辑人
  238. reportInfo.LastModifyAdminId = sysUser.AdminId
  239. reportInfo.LastModifyAdminName = sysUser.RealName
  240. reportInfo.ModifyTime = time.Now()
  241. err, errMsg := services.EditChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.Title, req.PermissionIdList, req.AdminIdList)
  242. if err != nil {
  243. br.Msg = "保存失败"
  244. if errMsg != "" {
  245. br.Msg = errMsg
  246. }
  247. br.ErrMsg = "保存失败,Err:" + err.Error()
  248. return
  249. }
  250. br.Ret = 200
  251. br.Success = true
  252. br.Msg = "保存成功"
  253. }
  254. // EditDayWeekChapter
  255. // @Title 编辑晨周报章节内容
  256. // @Description 编辑晨周报章节内容
  257. // @Param request body models.EditReportChapterReq true "type json string"
  258. // @Success 200 Ret=200 保存成功
  259. // @router /editDayWeekChapter [post]
  260. func (this *ReportController) EditDayWeekChapter() {
  261. br := new(models.BaseResponse).Init()
  262. defer func() {
  263. this.Data["json"] = br
  264. this.ServeJSON()
  265. }()
  266. sysUser := this.SysUser
  267. if sysUser == nil {
  268. br.Msg = "请登录"
  269. br.ErrMsg = "请登录,SysUser Is Empty"
  270. br.Ret = 408
  271. return
  272. }
  273. var req models.EditReportChapterReq
  274. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  275. if err != nil {
  276. br.Msg = "参数解析异常!"
  277. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  278. return
  279. }
  280. reportChapterId := req.ReportChapterId
  281. if reportChapterId <= 0 {
  282. br.Msg = "报告章节ID有误"
  283. return
  284. }
  285. if req.Content == "" {
  286. br.Msg = "请输入内容"
  287. return
  288. }
  289. // 获取章节详情
  290. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  291. if err != nil {
  292. br.Msg = "报告章节信息有误"
  293. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  294. return
  295. }
  296. // 获取报告详情
  297. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  298. if err != nil {
  299. br.Msg = "报告信息有误"
  300. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  301. return
  302. }
  303. // 操作权限校验
  304. {
  305. // 如果不是创建人,那么就要去查看是否授权
  306. if reportInfo.AdminId != sysUser.AdminId {
  307. // 授权用户权限校验
  308. chapterGrantObj := report.ReportChapterGrant{}
  309. _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, sysUser.AdminId)
  310. if tmpErr != nil {
  311. if tmpErr.Error() == utils.ErrNoRow() {
  312. br.Msg = "没有权限"
  313. br.ErrMsg = "没有权限"
  314. br.IsSendEmail = false
  315. return
  316. }
  317. br.Msg = "获取章节id授权用户失败"
  318. br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
  319. return
  320. }
  321. }
  322. // 标记更新中
  323. {
  324. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  325. if err != nil {
  326. br.Msg = err.Error()
  327. return
  328. }
  329. if markStatus.Status == 1 {
  330. br.Msg = markStatus.Msg
  331. br.IsSendEmail = false
  332. return
  333. }
  334. }
  335. }
  336. if reportInfo.State == 2 {
  337. br.Msg = "该报告已发布,不允许编辑"
  338. br.ErrMsg = "该报告已发布,不允许编辑"
  339. br.IsSendEmail = false
  340. return
  341. }
  342. // 报告的最后编辑人
  343. reportInfo.LastModifyAdminId = sysUser.AdminId
  344. reportInfo.LastModifyAdminName = sysUser.RealName
  345. reportInfo.ModifyTime = time.Now()
  346. reqTickerList := req.TickerList
  347. // 更新章节及指标
  348. contentSub := ""
  349. if req.Content != "" {
  350. e := utils.ContentXssCheck(req.Content)
  351. if e != nil {
  352. br.Msg = "存在非法标签"
  353. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  354. return
  355. }
  356. contentClean, e := services.FilterReportContentBr(req.Content)
  357. if e != nil {
  358. br.Msg = "内容去除前后空格失败"
  359. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  360. return
  361. }
  362. req.Content = contentClean
  363. contentSub, err = services.GetReportContentSub(req.Content)
  364. if err != nil {
  365. br.Msg = "内容分段解析失败"
  366. br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
  367. return
  368. }
  369. }
  370. if req.Title != "" {
  371. reportChapterInfo.Title = req.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. }
  382. reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  383. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  384. reportChapterInfo.ContentModifyTime = time.Now()
  385. reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  386. updateCols := make([]string, 0)
  387. updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime", "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. fileBody, err := os.ReadFile(fPath)
  1099. videoSize := len(fileBody)
  1100. sizeFloat := (float64(videoSize) / float64(1024)) / float64(1024)
  1101. sizeStr := utils.SubFloatToFloatStr(sizeFloat, 2)
  1102. {
  1103. reportChapterCreateTime, err := time.Parse(utils.FormatDateTime, reportChapterInfo.CreateTime)
  1104. if err != nil {
  1105. br.Msg = "上传失败"
  1106. br.ErrMsg = "上传失败,Err:" + err.Error()
  1107. return
  1108. }
  1109. createTimeStr := reportChapterCreateTime.Format("0102")
  1110. videoName := reportChapterInfo.Title + "(" + createTimeStr + ")"
  1111. reportChapterInfo.VideoUrl = resourceUrl
  1112. reportChapterInfo.VideoName = videoName
  1113. reportChapterInfo.VideoPlaySeconds = fmt.Sprint(playSeconds)
  1114. reportChapterInfo.VideoSize = sizeStr
  1115. reportChapterInfo.VideoKind = 1
  1116. reportChapterInfo.LastModifyAdminId = this.SysUser.AdminId
  1117. reportChapterInfo.LastModifyAdminName = this.SysUser.RealName
  1118. reportChapterInfo.ModifyTime = time.Now()
  1119. err = reportChapterInfo.UpdateChapter([]string{"VideoUrl", "VideoName", "VideoPlaySeconds", "VideoSize", "VideoKind", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1120. if err != nil {
  1121. br.Msg = "上传失败"
  1122. br.ErrMsg = "修改报告章节的音频信息失败,Err:" + err.Error()
  1123. return
  1124. }
  1125. // 修改报告的最近更新人信息
  1126. reportInfo.LastModifyAdminId = this.SysUser.AdminId
  1127. reportInfo.LastModifyAdminName = this.SysUser.RealName
  1128. reportInfo.ModifyTime = time.Now()
  1129. err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1130. if err != nil {
  1131. br.Msg = "上传失败"
  1132. br.ErrMsg = "修改报告最后更新人信息失败,Err:" + err.Error()
  1133. return
  1134. }
  1135. }
  1136. // 处理报告中的音频文件分贝
  1137. go services.HandleVideoDecibel(reportChapterInfo)
  1138. resp := new(models.ResourceResp)
  1139. resp.Id = newId
  1140. resp.ResourceUrl = resourceUrl
  1141. br.Msg = "上传成功"
  1142. br.Ret = 200
  1143. br.Success = true
  1144. br.Data = resp
  1145. return
  1146. }
  1147. // PublishDayWeekReportChapter
  1148. // @Title 发布章节
  1149. // @Description 发布章节
  1150. // @Param request body models.PublishReportChapterReq true "type json string"
  1151. // @Success 200 Ret=200 操作成功
  1152. // @router /publishDayWeekReportChapter [post]
  1153. func (this *ReportController) PublishDayWeekReportChapter() {
  1154. br := new(models.BaseResponse).Init()
  1155. defer func() {
  1156. this.Data["json"] = br
  1157. this.ServeJSON()
  1158. }()
  1159. sysUser := this.SysUser
  1160. if sysUser == nil {
  1161. br.Msg = "请登录"
  1162. br.ErrMsg = "请登录,SysUser Is Empty"
  1163. br.Ret = 408
  1164. return
  1165. }
  1166. var req models.PublishReportChapterReq
  1167. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1168. if err != nil {
  1169. br.Msg = "参数解析异常!"
  1170. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1171. return
  1172. }
  1173. if req.ReportChapterId <= 0 {
  1174. br.Msg = "参数有误"
  1175. return
  1176. }
  1177. // 获取报告详情
  1178. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  1179. if err != nil {
  1180. br.Msg = "章节信息有误"
  1181. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  1182. return
  1183. }
  1184. reportInfo, err := models.GetReportByReportId(chapterInfo.ReportId)
  1185. if err != nil {
  1186. br.Msg = "查询报告有误"
  1187. br.ErrMsg = "查询报告信息失败, Err: " + err.Error()
  1188. return
  1189. }
  1190. if reportInfo.State == 2 {
  1191. br.Msg = "该报告已发布,不允许编辑"
  1192. br.ErrMsg = "该报告已发布,不允许编辑"
  1193. br.IsSendEmail = false
  1194. return
  1195. }
  1196. // 图表刷新状态
  1197. refreshResult := data.CheckBatchChartRefreshResult("report", chapterInfo.ReportId, chapterInfo.ReportChapterId)
  1198. if !refreshResult {
  1199. br.Msg = "图表刷新未完成,请稍后操作"
  1200. br.ErrMsg = "图表刷新未完成,请稍后操作"
  1201. br.IsSendEmail = false
  1202. return
  1203. }
  1204. // 如果是系统章节,那么需要校验下是否已经停更
  1205. if chapterInfo.TypeId > 0 {
  1206. // 获取规则配置
  1207. reportChapterTypeRule, err := models.GetReportChapterTypeById(chapterInfo.TypeId)
  1208. if err != nil {
  1209. br.Msg = "获取配置信息异常"
  1210. br.ErrMsg = "获取配置信息异常, Err: " + err.Error()
  1211. return
  1212. }
  1213. if reportChapterTypeRule.Enabled == 0 {
  1214. br.Msg = "该章节已永久停更"
  1215. br.ErrMsg = "该章节已永久停更 "
  1216. br.IsSendEmail = false
  1217. return
  1218. }
  1219. }
  1220. var publishTime time.Time
  1221. if reportInfo.MsgIsSend == 1 && reportInfo.PublishTime.IsZero() { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
  1222. publishTime = reportInfo.PublishTime
  1223. } else {
  1224. publishTime = time.Now()
  1225. }
  1226. // 更新报告的最后编辑人
  1227. reportInfo.LastModifyAdminId = sysUser.AdminId
  1228. reportInfo.LastModifyAdminName = sysUser.RealName
  1229. reportInfo.ModifyTime = time.Now()
  1230. err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1231. if err != nil {
  1232. br.Msg = "发布失败"
  1233. br.ErrMsg = "报告最后编辑人保存失败, Err: " + err.Error()
  1234. return
  1235. }
  1236. // 更新章节信息
  1237. chapterInfo.IsEdit = 1
  1238. chapterInfo.PublishState = 2
  1239. chapterInfo.PublishTime = publishTime
  1240. chapterInfo.LastModifyAdminId = this.SysUser.AdminId
  1241. chapterInfo.LastModifyAdminName = this.SysUser.RealName
  1242. chapterInfo.ModifyTime = time.Now()
  1243. updateCols := make([]string, 0)
  1244. updateCols = append(updateCols, "IsEdit", "PublishState", "PublishTime", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
  1245. err = chapterInfo.UpdateChapter(updateCols)
  1246. if err != nil {
  1247. br.Msg = "发布失败"
  1248. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1249. return
  1250. }
  1251. // 修改报告的最近更新人信息
  1252. go func() {
  1253. reportInfo.LastModifyAdminId = this.SysUser.AdminId
  1254. reportInfo.LastModifyAdminName = this.SysUser.RealName
  1255. reportInfo.ModifyTime = time.Now()
  1256. err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1257. if err != nil {
  1258. br.Msg = "上传失败"
  1259. br.ErrMsg = "修改报告最后更新人信息失败,Err:" + err.Error()
  1260. return
  1261. }
  1262. }()
  1263. // 生成音频
  1264. go services.UpdateChaptersVideo([]int{chapterInfo.ReportChapterId})
  1265. // 更新章节ES
  1266. {
  1267. go services.UpdateReportChapterEs(chapterInfo.ReportChapterId)
  1268. }
  1269. // 同时发布报告
  1270. //if req.PublishReport == 1 {
  1271. // if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
  1272. // br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
  1273. // br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
  1274. // return
  1275. // }
  1276. //}
  1277. br.Ret = 200
  1278. br.Success = true
  1279. br.Msg = "操作成功"
  1280. }
  1281. // GetUnPublishReportChapterList
  1282. // @Title 获取报告中未发布的章节数
  1283. // @Description 获取报告中未发布的章节数
  1284. // @Param ReportId query int true "报告ID"
  1285. // @Success 200 Ret=200 获取成功
  1286. // @router /chapter/un_publish/list [get]
  1287. func (this *ReportController) GetUnPublishReportChapterList() {
  1288. br := new(models.BaseResponse).Init()
  1289. defer func() {
  1290. this.Data["json"] = br
  1291. this.ServeJSON()
  1292. }()
  1293. sysUser := this.SysUser
  1294. if sysUser == nil {
  1295. br.Msg = "请登录"
  1296. br.ErrMsg = "请登录,SysUser Is Empty"
  1297. br.Ret = 408
  1298. return
  1299. }
  1300. reportId, _ := this.GetInt("ReportId")
  1301. if reportId <= 0 {
  1302. br.Msg = "参数有误"
  1303. br.IsSendEmail = false
  1304. return
  1305. }
  1306. reportInfo, err := models.GetReportById(reportId)
  1307. if err != nil {
  1308. br.Msg = "报告有误"
  1309. br.ErrMsg = "报告有误, Err: " + err.Error()
  1310. return
  1311. }
  1312. if reportInfo.HasChapter == 0 {
  1313. br.Msg = "报告未包含章节"
  1314. br.IsSendEmail = false
  1315. return
  1316. }
  1317. // 获取未发布的章节列表
  1318. unPublishedList, err := models.GetUnPublishedChapterList(reportInfo.Id)
  1319. if err != nil {
  1320. br.Msg = "获取未发布的章节数失败"
  1321. br.ErrMsg = "获取未发布的章节数失败, Err: " + err.Error()
  1322. return
  1323. }
  1324. br.Ret = 200
  1325. br.Success = true
  1326. br.Msg = "获取成功"
  1327. br.Data = unPublishedList
  1328. }
  1329. // EditChapterTitle
  1330. // @Title 编辑章节标题
  1331. // @Description 编辑章节标题
  1332. // @Param request body models.EditReportChapterReq true "type json string"
  1333. // @Success 200 Ret=200 保存成功
  1334. // @router /chapter/title/edit [post]
  1335. func (this *ReportController) EditChapterTitle() {
  1336. br := new(models.BaseResponse).Init()
  1337. defer func() {
  1338. this.Data["json"] = br
  1339. this.ServeJSON()
  1340. }()
  1341. sysUser := this.SysUser
  1342. if sysUser == nil {
  1343. br.Msg = "请登录"
  1344. br.ErrMsg = "请登录,SysUser Is Empty"
  1345. br.Ret = 408
  1346. return
  1347. }
  1348. var req models.EditReportChapterReq
  1349. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1350. if err != nil {
  1351. br.Msg = "参数解析异常!"
  1352. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1353. return
  1354. }
  1355. reportChapterId := req.ReportChapterId
  1356. if reportChapterId <= 0 {
  1357. br.Msg = "报告章节ID有误"
  1358. return
  1359. }
  1360. req.Title = strings.TrimSpace(req.Title)
  1361. if req.Title == `` {
  1362. br.Msg = "章节名称不能为空"
  1363. return
  1364. }
  1365. // 获取章节详情
  1366. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  1367. if err != nil {
  1368. br.Msg = "报告章节信息有误"
  1369. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  1370. return
  1371. }
  1372. // 判断名称是否重复
  1373. {
  1374. var condition string
  1375. var pars []interface{}
  1376. condition += " AND report_id = ? AND title=? AND report_chapter_id != ? "
  1377. pars = append(pars, reportChapterInfo.ReportId, req.Title, reportChapterId)
  1378. count, err := models.GetCountReportChapterByCondition(condition, pars)
  1379. if err != nil {
  1380. br.Msg = "新增失败"
  1381. br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
  1382. return
  1383. }
  1384. if count > 0 {
  1385. br.Msg = "章节名称不允许重复"
  1386. br.ErrMsg = "章节名称不允许重复"
  1387. br.IsSendEmail = false
  1388. return
  1389. }
  1390. }
  1391. // 获取报告详情
  1392. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  1393. if err != nil {
  1394. br.Msg = "报告信息有误"
  1395. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  1396. return
  1397. }
  1398. // 操作权限校验
  1399. {
  1400. // 如果不是创建人,那么就要去查看是否授权
  1401. if reportInfo.AdminId != sysUser.AdminId {
  1402. // 授权用户权限校验
  1403. chapterGrantObj := report.ReportChapterGrant{}
  1404. _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, sysUser.AdminId)
  1405. if tmpErr != nil {
  1406. if tmpErr.Error() == utils.ErrNoRow() {
  1407. br.Msg = "没有权限"
  1408. br.ErrMsg = "没有权限"
  1409. br.IsSendEmail = false
  1410. return
  1411. }
  1412. br.Msg = "获取章节id授权用户失败"
  1413. br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
  1414. return
  1415. }
  1416. }
  1417. // 标记更新中
  1418. {
  1419. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  1420. if err != nil {
  1421. br.Msg = err.Error()
  1422. return
  1423. }
  1424. if markStatus.Status == 1 {
  1425. br.Msg = markStatus.Msg
  1426. br.IsSendEmail = false
  1427. return
  1428. }
  1429. }
  1430. }
  1431. if reportInfo.State == 2 {
  1432. br.Msg = "该报告已发布,不允许编辑"
  1433. br.ErrMsg = "该报告已发布,不允许编辑"
  1434. br.IsSendEmail = false
  1435. return
  1436. }
  1437. // 报告的最后编辑人
  1438. reportInfo.LastModifyAdminId = sysUser.AdminId
  1439. reportInfo.LastModifyAdminName = sysUser.RealName
  1440. reportInfo.ModifyTime = time.Now()
  1441. reportChapterInfo.Title = req.Title
  1442. reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  1443. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  1444. reportChapterInfo.ModifyTime = time.Now()
  1445. updateCols := make([]string, 0)
  1446. updateCols = append(updateCols, "Title", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
  1447. // 更新报告的最近编辑人信息
  1448. if err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"}); err != nil {
  1449. br.Msg = "保存失败"
  1450. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1451. return
  1452. }
  1453. // 更新章节
  1454. if err = reportChapterInfo.UpdateChapter(updateCols); err != nil {
  1455. br.Msg = "保存失败"
  1456. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1457. return
  1458. }
  1459. // 标记更新中
  1460. {
  1461. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  1462. if err != nil {
  1463. br.Msg = err.Error()
  1464. return
  1465. }
  1466. if markStatus.Status == 1 {
  1467. br.Msg = markStatus.Msg
  1468. return
  1469. }
  1470. }
  1471. br.Ret = 200
  1472. br.Success = true
  1473. br.Msg = "保存成功"
  1474. }