report_chapter.go 48 KB

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