report_chapter.go 47 KB

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