report_chapter.go 51 KB

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