report_chapter.go 52 KB

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