report_chapter.go 45 KB

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