report_chapter.go 51 KB

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