report_chapter.go 46 KB

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