report_chapter.go 48 KB

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