report_chapter.go 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/models/report"
  6. "eta/eta_mobile/models/system"
  7. "eta/eta_mobile/services"
  8. "eta/eta_mobile/services/data"
  9. "eta/eta_mobile/utils"
  10. "fmt"
  11. "github.com/kgiannakakis/mp3duration/src/mp3duration"
  12. "html"
  13. "os"
  14. "path"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // AddChapter
  20. // @Title 新增晨周报章节内容
  21. // @Description 新增晨周报章节内容
  22. // @Param request body models.AddReportChapterReq true "type json string"
  23. // @Success 200 Ret=200 保存成功
  24. // @router /chapter/add [post]
  25. func (this *ReportController) AddChapter() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. sysUser := this.SysUser
  32. if sysUser == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,SysUser Is Empty"
  35. br.Ret = 408
  36. return
  37. }
  38. var req models.AddReportChapterReq
  39. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  40. if err != nil {
  41. br.Msg = "参数解析异常!"
  42. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  43. return
  44. }
  45. if req.ReportId <= 0 {
  46. br.Msg = "报告ID有误"
  47. return
  48. }
  49. req.Title = strings.TrimSpace(req.Title)
  50. if req.Title == `` {
  51. br.Msg = "章节名称不能为空"
  52. return
  53. }
  54. // 获取报告详情
  55. reportInfo, err := models.GetReportByReportId(req.ReportId)
  56. if err != nil {
  57. br.Msg = "报告信息有误"
  58. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  59. return
  60. }
  61. if reportInfo.State == 2 {
  62. br.Msg = "该报告已发布,不允许新增"
  63. br.ErrMsg = "该报告已发布,不允许新增"
  64. return
  65. }
  66. //newContent := req.Content
  67. //// 更新章节及指标
  68. //contentSub := ""
  69. //if req.Content != "" {
  70. // e := utils.ContentXssCheck(req.Content)
  71. // if e != nil {
  72. // br.Msg = "存在非法标签"
  73. // br.ErrMsg = "存在非法标签, Err: " + e.Error()
  74. // return
  75. // }
  76. // contentClean, e := services.FilterReportContentBr(req.Content)
  77. // if e != nil {
  78. // br.Msg = "内容去除前后空格失败"
  79. // br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  80. // return
  81. // }
  82. // req.Content = contentClean
  83. //
  84. // contentSub, err = services.GetReportContentSub(req.Content)
  85. // if err != nil {
  86. // br.Msg = "内容分段解析失败"
  87. // br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
  88. // return
  89. // }
  90. //}
  91. //if req.Content == "" {
  92. // req.Content = newContent
  93. //}
  94. // 最小单元的分类
  95. var minClassifyId int
  96. var minClassifyName string
  97. if reportInfo.ClassifyIdThird > 0 {
  98. minClassifyId = reportInfo.ClassifyIdThird
  99. minClassifyName = reportInfo.ClassifyNameThird
  100. } else if reportInfo.ClassifyIdSecond > 0 {
  101. minClassifyId = reportInfo.ClassifyIdSecond
  102. minClassifyName = reportInfo.ClassifyNameSecond
  103. } else {
  104. minClassifyId = reportInfo.ClassifyIdFirst
  105. minClassifyName = reportInfo.ClassifyNameFirst
  106. }
  107. // 判断名称是否重复
  108. {
  109. var condition string
  110. var pars []interface{}
  111. condition += " AND report_id = ? AND title=? "
  112. pars = append(pars, req.ReportId, req.Title)
  113. count, err := models.GetCountReportChapterByCondition(condition, pars)
  114. if err != nil {
  115. br.Msg = "新增失败"
  116. br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
  117. return
  118. }
  119. if count > 0 {
  120. br.Msg = "章节名称不允许重复"
  121. br.ErrMsg = "章节名称不允许重复"
  122. br.IsSendEmail = false
  123. return
  124. }
  125. }
  126. reportChapterInfo := new(models.ReportChapter)
  127. reportChapterInfo.ReportId = reportInfo.Id
  128. reportChapterInfo.ClassifyIdFirst = minClassifyId
  129. reportChapterInfo.ClassifyNameFirst = minClassifyName
  130. reportChapterInfo.Title = req.Title
  131. reportChapterInfo.AddType = 1
  132. reportChapterInfo.PublishState = 1
  133. //reportChapterInfo.Author = req.Author
  134. //reportChapterInfo.Content = html.EscapeString(req.Content)
  135. //reportChapterInfo.ContentSub = html.EscapeString(contentSub)
  136. reportChapterInfo.IsEdit = 1
  137. //reportChapterInfo.CreateTime = req.CreateTime
  138. reportChapterInfo.CreateTime = reportInfo.CreateTime
  139. reportChapterInfo.ModifyTime = time.Now()
  140. reportChapterInfo.ReportCreateTime = time.Now()
  141. reportChapterInfo.VideoKind = 2
  142. reportChapterInfo.Stage = reportInfo.Stage
  143. reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  144. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  145. reportChapterInfo.ContentModifyTime = time.Now()
  146. //reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  147. //reportChapterInfo.CanvasColor = req.CanvasColor
  148. //reportChapterInfo.HeadResourceId = req.HeadResourceId
  149. //reportChapterInfo.EndResourceId = req.EndResourceId
  150. err, errMsg := services.AddChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.PermissionIdList, req.AdminIdList)
  151. if err != nil {
  152. br.Msg = "保存失败"
  153. if errMsg != "" {
  154. br.Msg = errMsg
  155. }
  156. br.ErrMsg = "保存失败,Err:" + err.Error()
  157. return
  158. }
  159. br.Ret = 200
  160. br.Success = true
  161. br.Msg = "保存成功"
  162. }
  163. // EditChapterBaseInfoAndPermission
  164. // @Title 修改报告章节的基础信息、授权用户权限、品种权限
  165. // @Description 修改报告章节的基础信息、授权用户权限、品种权限
  166. // @Param request body models.EditReportChapterReq true "type json string"
  167. // @Success 200 Ret=200 保存成功
  168. // @router /chapter/base_info/edit [post]
  169. func (this *ReportController) EditChapterBaseInfoAndPermission() {
  170. br := new(models.BaseResponse).Init()
  171. defer func() {
  172. this.Data["json"] = br
  173. this.ServeJSON()
  174. }()
  175. sysUser := this.SysUser
  176. if sysUser == nil {
  177. br.Msg = "请登录"
  178. br.ErrMsg = "请登录,SysUser Is Empty"
  179. br.Ret = 408
  180. return
  181. }
  182. var req models.EditReportChapterBaseInfoAndPermissionReq
  183. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  184. if err != nil {
  185. br.Msg = "参数解析异常!"
  186. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  187. return
  188. }
  189. reportChapterId := req.ReportChapterId
  190. if reportChapterId <= 0 {
  191. br.Msg = "报告章节ID有误"
  192. return
  193. }
  194. req.Title = strings.TrimSpace(req.Title)
  195. if req.Title == `` {
  196. br.Msg = "章节名称不能为空"
  197. return
  198. }
  199. // 获取章节详情
  200. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  201. if err != nil {
  202. br.Msg = "报告章节信息有误"
  203. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  204. return
  205. }
  206. // 判断名称是否重复
  207. {
  208. var condition string
  209. var pars []interface{}
  210. condition += " AND report_id = ? AND title=? AND report_chapter_id != ? "
  211. pars = append(pars, reportChapterInfo.ReportId, req.Title, reportChapterId)
  212. count, err := models.GetCountReportChapterByCondition(condition, pars)
  213. if err != nil {
  214. br.Msg = "新增失败"
  215. br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
  216. return
  217. }
  218. if count > 0 {
  219. br.Msg = "章节名称不允许重复"
  220. br.ErrMsg = "章节名称不允许重复"
  221. br.IsSendEmail = false
  222. return
  223. }
  224. }
  225. // 获取报告详情
  226. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  227. if err != nil {
  228. br.Msg = "报告信息有误"
  229. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  230. return
  231. }
  232. if reportInfo.State == 2 {
  233. br.Msg = "该报告已发布,不允许编辑"
  234. br.ErrMsg = "该报告已发布,不允许编辑"
  235. return
  236. }
  237. // 报告的最后编辑人
  238. reportInfo.LastModifyAdminId = sysUser.AdminId
  239. reportInfo.LastModifyAdminName = sysUser.RealName
  240. reportInfo.ModifyTime = time.Now()
  241. err, errMsg := services.EditChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.Title, req.PermissionIdList, req.AdminIdList)
  242. if err != nil {
  243. br.Msg = "保存失败"
  244. if errMsg != "" {
  245. br.Msg = errMsg
  246. }
  247. br.ErrMsg = "保存失败,Err:" + err.Error()
  248. return
  249. }
  250. br.Ret = 200
  251. br.Success = true
  252. br.Msg = "保存成功"
  253. }
  254. // EditDayWeekChapter
  255. // @Title 编辑晨周报章节内容
  256. // @Description 编辑晨周报章节内容
  257. // @Param request body models.EditReportChapterReq true "type json string"
  258. // @Success 200 Ret=200 保存成功
  259. // @router /editDayWeekChapter [post]
  260. func (this *ReportController) EditDayWeekChapter() {
  261. br := new(models.BaseResponse).Init()
  262. defer func() {
  263. this.Data["json"] = br
  264. this.ServeJSON()
  265. }()
  266. sysUser := this.SysUser
  267. if sysUser == nil {
  268. br.Msg = "请登录"
  269. br.ErrMsg = "请登录,SysUser Is Empty"
  270. br.Ret = 408
  271. return
  272. }
  273. var req models.EditReportChapterReq
  274. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  275. if err != nil {
  276. br.Msg = "参数解析异常!"
  277. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  278. return
  279. }
  280. reportChapterId := req.ReportChapterId
  281. if reportChapterId <= 0 {
  282. br.Msg = "报告章节ID有误"
  283. return
  284. }
  285. if req.Content == "" {
  286. br.Msg = "请输入内容"
  287. return
  288. }
  289. // 获取章节详情
  290. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  291. if err != nil {
  292. br.Msg = "报告章节信息有误"
  293. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  294. return
  295. }
  296. // 获取报告详情
  297. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  298. if err != nil {
  299. br.Msg = "报告信息有误"
  300. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  301. return
  302. }
  303. // 操作权限校验
  304. hasAuth, msg, errMsg, isSendEmail := checkOpPermission(sysUser, reportInfo, reportChapterInfo, true, this.Lang)
  305. if !hasAuth {
  306. br.Msg = msg
  307. br.ErrMsg = errMsg
  308. br.IsSendEmail = isSendEmail
  309. return
  310. }
  311. if reportInfo.State == 2 {
  312. br.Msg = "该报告已发布,不允许编辑"
  313. br.ErrMsg = "该报告已发布,不允许编辑"
  314. return
  315. }
  316. if reportChapterInfo.PublishState == 2 {
  317. br.Msg = "该报告章节已发布,不允许编辑"
  318. br.ErrMsg = "该报告章节已发布,不允许编辑"
  319. br.IsSendEmail = false
  320. return
  321. }
  322. updateCols := make([]string, 0)
  323. // 报告的最后编辑人
  324. reportInfo.LastModifyAdminId = sysUser.AdminId
  325. reportInfo.LastModifyAdminName = sysUser.RealName
  326. reportInfo.ModifyTime = time.Now()
  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. // 担心外部没有传入时间,如果没有传入,那么就不修改
  362. if req.CreateTime != `` {
  363. reportChapterInfo.CreateTime = req.CreateTime
  364. updateCols = append(updateCols, "CreateTime")
  365. }
  366. reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  367. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  368. reportChapterInfo.ContentModifyTime = time.Now()
  369. reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  370. updateCols = append(updateCols, "Author", "Content", "ContentSub", "IsEdit", "ModifyTime")
  371. updateCols = append(updateCols, "LastModifyAdminId", "LastModifyAdminName", "ContentModifyTime", "ContentStruct")
  372. // 章节报告更新指标
  373. tickerList := make([]*models.ReportChapterTicker, 0)
  374. if len(reqTickerList) > 0 {
  375. nowTime := time.Now()
  376. for i := 0; i < len(reqTickerList); i++ {
  377. tickerList = append(tickerList, &models.ReportChapterTicker{
  378. ReportChapterId: reportChapterInfo.ReportChapterId,
  379. Sort: reqTickerList[i].Sort,
  380. Ticker: reqTickerList[i].Ticker,
  381. CreateTime: nowTime,
  382. UpdateTime: nowTime,
  383. })
  384. }
  385. }
  386. err = models.UpdateChapterAndTicker(reportInfo, reportChapterInfo, updateCols, tickerList)
  387. if err != nil {
  388. br.Msg = "保存失败"
  389. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  390. return
  391. }
  392. // 标记更新中
  393. {
  394. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  395. if err != nil {
  396. br.Msg = err.Error()
  397. return
  398. }
  399. if markStatus.Status == 1 {
  400. br.Msg = markStatus.Msg
  401. return
  402. }
  403. }
  404. // 备份关键数据
  405. chapters := make([]*models.ReportChapter, 0)
  406. chapters = append(chapters, reportChapterInfo)
  407. go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
  408. br.Ret = 200
  409. br.Success = true
  410. br.Msg = "保存成功"
  411. }
  412. // DelChapter
  413. // @Title 编辑晨周报章节内容
  414. // @Description 编辑晨周报章节内容
  415. // @Param request body models.EditReportChapterReq true "type json string"
  416. // @Success 200 Ret=200 保存成功
  417. // @router /chapter/del [post]
  418. func (this *ReportController) DelChapter() {
  419. br := new(models.BaseResponse).Init()
  420. defer func() {
  421. this.Data["json"] = br
  422. this.ServeJSON()
  423. }()
  424. sysUser := this.SysUser
  425. if sysUser == nil {
  426. br.Msg = "请登录"
  427. br.ErrMsg = "请登录,SysUser Is Empty"
  428. br.Ret = 408
  429. return
  430. }
  431. var req models.DelReportChapterReq
  432. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  433. if err != nil {
  434. br.Msg = "参数解析异常!"
  435. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  436. return
  437. }
  438. reportChapterId := req.ReportChapterId
  439. if reportChapterId <= 0 {
  440. br.Msg = "报告章节ID有误"
  441. return
  442. }
  443. // 获取章节详情
  444. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  445. if err != nil {
  446. br.Msg = "报告章节信息有误"
  447. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  448. return
  449. }
  450. // 获取报告详情
  451. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  452. if err != nil {
  453. br.Msg = "报告信息有误"
  454. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  455. return
  456. }
  457. // 操作权限校验
  458. hasAuth, msg, errMsg, isSendEmail := checkOpPermission(sysUser, reportInfo, reportChapterInfo, true, this.Lang)
  459. if !hasAuth {
  460. br.Msg = msg
  461. br.ErrMsg = errMsg
  462. br.IsSendEmail = isSendEmail
  463. return
  464. }
  465. if reportInfo.State == 2 {
  466. br.Msg = "该报告已发布,不允许编辑"
  467. br.ErrMsg = "该报告已发布,不允许编辑"
  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. fileBody, err := os.ReadFile(fPath)
  1044. videoSize := len(fileBody)
  1045. sizeFloat := (float64(videoSize) / float64(1024)) / float64(1024)
  1046. sizeStr := utils.SubFloatToFloatStr(sizeFloat, 2)
  1047. {
  1048. reportChapterCreateTime, err := time.Parse(utils.FormatDateTime, reportChapterInfo.CreateTime)
  1049. if err != nil {
  1050. br.Msg = "上传失败"
  1051. br.ErrMsg = "上传失败,Err:" + err.Error()
  1052. return
  1053. }
  1054. createTimeStr := reportChapterCreateTime.Format("0102")
  1055. videoName := reportChapterInfo.Title + "(" + createTimeStr + ")"
  1056. reportChapterInfo.VideoUrl = resourceUrl
  1057. reportChapterInfo.VideoName = videoName
  1058. reportChapterInfo.VideoPlaySeconds = fmt.Sprint(playSeconds)
  1059. reportChapterInfo.VideoSize = sizeStr
  1060. reportChapterInfo.VideoKind = 1
  1061. reportChapterInfo.LastModifyAdminId = this.SysUser.AdminId
  1062. reportChapterInfo.LastModifyAdminName = this.SysUser.RealName
  1063. reportInfo.VoiceGenerateType = 1
  1064. reportChapterInfo.ModifyTime = time.Now()
  1065. err = reportChapterInfo.UpdateChapter([]string{"VideoUrl", "VideoName", "VideoPlaySeconds", "VideoSize", "VideoKind", "LastModifyAdminId", "LastModifyAdminName", "VoiceGenerateType", "ModifyTime"})
  1066. if err != nil {
  1067. br.Msg = "上传失败"
  1068. br.ErrMsg = "修改报告章节的音频信息失败,Err:" + err.Error()
  1069. return
  1070. }
  1071. // 修改报告的最近更新人信息
  1072. reportInfo.LastModifyAdminId = this.SysUser.AdminId
  1073. reportInfo.LastModifyAdminName = this.SysUser.RealName
  1074. reportInfo.ModifyTime = time.Now()
  1075. err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1076. if err != nil {
  1077. br.Msg = "上传失败"
  1078. br.ErrMsg = "修改报告最后更新人信息失败,Err:" + err.Error()
  1079. return
  1080. }
  1081. }
  1082. // 处理报告中的音频文件分贝
  1083. go services.HandleVideoDecibel(reportChapterInfo)
  1084. resp := new(models.ResourceResp)
  1085. resp.Id = newId
  1086. resp.ResourceUrl = resourceUrl
  1087. br.Msg = "上传成功"
  1088. br.Ret = 200
  1089. br.Success = true
  1090. br.Data = resp
  1091. return
  1092. }
  1093. // PublishDayWeekReportChapter
  1094. // @Title 发布章节
  1095. // @Description 发布章节
  1096. // @Param request body models.PublishReportChapterReq true "type json string"
  1097. // @Success 200 Ret=200 操作成功
  1098. // @router /publishDayWeekReportChapter [post]
  1099. func (this *ReportController) PublishDayWeekReportChapter() {
  1100. br := new(models.BaseResponse).Init()
  1101. defer func() {
  1102. this.Data["json"] = br
  1103. this.ServeJSON()
  1104. }()
  1105. sysUser := this.SysUser
  1106. if sysUser == nil {
  1107. br.Msg = "请登录"
  1108. br.ErrMsg = "请登录,SysUser Is Empty"
  1109. br.Ret = 408
  1110. return
  1111. }
  1112. var req models.PublishReportChapterReq
  1113. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1114. if err != nil {
  1115. br.Msg = "参数解析异常!"
  1116. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1117. return
  1118. }
  1119. if req.ReportChapterId <= 0 {
  1120. br.Msg = "参数有误"
  1121. return
  1122. }
  1123. // 获取报告详情
  1124. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  1125. if err != nil {
  1126. br.Msg = "章节信息有误"
  1127. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  1128. return
  1129. }
  1130. reportInfo, err := models.GetReportByReportId(chapterInfo.ReportId)
  1131. if err != nil {
  1132. br.Msg = "查询报告有误"
  1133. br.ErrMsg = "查询报告信息失败, Err: " + err.Error()
  1134. return
  1135. }
  1136. if reportInfo.State == 2 {
  1137. br.Msg = "该报告已发布,不允许编辑"
  1138. br.ErrMsg = "该报告已发布,不允许编辑"
  1139. return
  1140. }
  1141. // 图表刷新状态
  1142. refreshResult := data.CheckBatchChartRefreshResult("report", chapterInfo.ReportId, chapterInfo.ReportChapterId)
  1143. if !refreshResult {
  1144. br.Msg = "图表刷新未完成,请稍后操作"
  1145. br.ErrMsg = "图表刷新未完成,请稍后操作"
  1146. br.IsSendEmail = false
  1147. return
  1148. }
  1149. // 如果是系统章节,那么需要校验下是否已经停更
  1150. if chapterInfo.TypeId > 0 {
  1151. // 获取规则配置
  1152. reportChapterTypeRule, err := models.GetReportChapterTypeById(chapterInfo.TypeId)
  1153. if err != nil {
  1154. br.Msg = "获取配置信息异常"
  1155. br.ErrMsg = "获取配置信息异常, Err: " + err.Error()
  1156. return
  1157. }
  1158. if reportChapterTypeRule.Enabled == 0 {
  1159. br.Msg = "该章节已永久停更"
  1160. br.ErrMsg = "该章节已永久停更 "
  1161. br.IsSendEmail = false
  1162. return
  1163. }
  1164. }
  1165. var publishTime time.Time
  1166. if reportInfo.MsgIsSend == 1 && reportInfo.PublishTime.IsZero() { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
  1167. publishTime = reportInfo.PublishTime
  1168. } else {
  1169. publishTime = time.Now()
  1170. }
  1171. // 更新报告的最后编辑人
  1172. reportInfo.LastModifyAdminId = sysUser.AdminId
  1173. reportInfo.LastModifyAdminName = sysUser.RealName
  1174. reportInfo.ModifyTime = time.Now()
  1175. err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1176. if err != nil {
  1177. br.Msg = "发布失败"
  1178. br.ErrMsg = "报告最后编辑人保存失败, Err: " + err.Error()
  1179. return
  1180. }
  1181. // 更新章节信息
  1182. chapterInfo.IsEdit = 1
  1183. chapterInfo.PublishState = 2
  1184. chapterInfo.PublishTime = publishTime
  1185. chapterInfo.LastModifyAdminId = this.SysUser.AdminId
  1186. chapterInfo.LastModifyAdminName = this.SysUser.RealName
  1187. chapterInfo.ModifyTime = time.Now()
  1188. updateCols := make([]string, 0)
  1189. updateCols = append(updateCols, "IsEdit", "PublishState", "PublishTime", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
  1190. err = chapterInfo.UpdateChapter(updateCols)
  1191. if err != nil {
  1192. br.Msg = "发布失败"
  1193. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1194. return
  1195. }
  1196. // 修改报告的最近更新人信息
  1197. go func() {
  1198. reportInfo.LastModifyAdminId = this.SysUser.AdminId
  1199. reportInfo.LastModifyAdminName = this.SysUser.RealName
  1200. reportInfo.ModifyTime = time.Now()
  1201. err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1202. if err != nil {
  1203. br.Msg = "上传失败"
  1204. br.ErrMsg = "修改报告最后更新人信息失败,Err:" + err.Error()
  1205. return
  1206. }
  1207. }()
  1208. // 更新章节ES
  1209. {
  1210. go services.UpdateReportChapterEs(chapterInfo.ReportChapterId)
  1211. }
  1212. // 同时发布报告
  1213. //if req.PublishReport == 1 {
  1214. // if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
  1215. // br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
  1216. // br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
  1217. // return
  1218. // }
  1219. //}
  1220. br.Ret = 200
  1221. br.Success = true
  1222. br.Msg = "操作成功"
  1223. }
  1224. // GetUnPublishReportChapterList
  1225. // @Title 获取报告中未发布的章节数
  1226. // @Description 获取报告中未发布的章节数
  1227. // @Param ReportId query int true "报告ID"
  1228. // @Success 200 Ret=200 获取成功
  1229. // @router /chapter/un_publish/list [get]
  1230. func (this *ReportController) GetUnPublishReportChapterList() {
  1231. br := new(models.BaseResponse).Init()
  1232. defer func() {
  1233. this.Data["json"] = br
  1234. this.ServeJSON()
  1235. }()
  1236. sysUser := this.SysUser
  1237. if sysUser == nil {
  1238. br.Msg = "请登录"
  1239. br.ErrMsg = "请登录,SysUser Is Empty"
  1240. br.Ret = 408
  1241. return
  1242. }
  1243. reportId, _ := this.GetInt("ReportId")
  1244. if reportId <= 0 {
  1245. br.Msg = "参数有误"
  1246. br.IsSendEmail = false
  1247. return
  1248. }
  1249. reportInfo, err := models.GetReportById(reportId)
  1250. if err != nil {
  1251. br.Msg = "报告有误"
  1252. br.ErrMsg = "报告有误, Err: " + err.Error()
  1253. return
  1254. }
  1255. if reportInfo.HasChapter == 0 {
  1256. br.Msg = "报告未包含章节"
  1257. br.IsSendEmail = false
  1258. return
  1259. }
  1260. // 获取未发布的章节列表
  1261. unPublishedList, err := models.GetUnPublishedChapterList(reportInfo.Id)
  1262. if err != nil {
  1263. br.Msg = "获取未发布的章节数失败"
  1264. br.ErrMsg = "获取未发布的章节数失败, Err: " + err.Error()
  1265. return
  1266. }
  1267. br.Ret = 200
  1268. br.Success = true
  1269. br.Msg = "获取成功"
  1270. br.Data = unPublishedList
  1271. }
  1272. // EditChapterTitle
  1273. // @Title 编辑章节标题
  1274. // @Description 编辑章节标题
  1275. // @Param request body models.EditReportChapterReq true "type json string"
  1276. // @Success 200 Ret=200 保存成功
  1277. // @router /chapter/title/edit [post]
  1278. func (this *ReportController) EditChapterTitle() {
  1279. br := new(models.BaseResponse).Init()
  1280. defer func() {
  1281. this.Data["json"] = br
  1282. this.ServeJSON()
  1283. }()
  1284. sysUser := this.SysUser
  1285. if sysUser == nil {
  1286. br.Msg = "请登录"
  1287. br.ErrMsg = "请登录,SysUser Is Empty"
  1288. br.Ret = 408
  1289. return
  1290. }
  1291. var req models.EditReportChapterReq
  1292. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1293. if err != nil {
  1294. br.Msg = "参数解析异常!"
  1295. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1296. return
  1297. }
  1298. reportChapterId := req.ReportChapterId
  1299. if reportChapterId <= 0 {
  1300. br.Msg = "报告章节ID有误"
  1301. return
  1302. }
  1303. req.Title = strings.TrimSpace(req.Title)
  1304. if req.Title == `` {
  1305. br.Msg = "章节名称不能为空"
  1306. return
  1307. }
  1308. // 获取章节详情
  1309. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  1310. if err != nil {
  1311. br.Msg = "报告章节信息有误"
  1312. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  1313. return
  1314. }
  1315. // 判断名称是否重复
  1316. {
  1317. var condition string
  1318. var pars []interface{}
  1319. condition += " AND report_id = ? AND title=? AND report_chapter_id != ? "
  1320. pars = append(pars, reportChapterInfo.ReportId, req.Title, reportChapterId)
  1321. count, err := models.GetCountReportChapterByCondition(condition, pars)
  1322. if err != nil {
  1323. br.Msg = "新增失败"
  1324. br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
  1325. return
  1326. }
  1327. if count > 0 {
  1328. br.Msg = "章节名称不允许重复"
  1329. br.ErrMsg = "章节名称不允许重复"
  1330. br.IsSendEmail = false
  1331. return
  1332. }
  1333. }
  1334. // 获取报告详情
  1335. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  1336. if err != nil {
  1337. br.Msg = "报告信息有误"
  1338. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  1339. return
  1340. }
  1341. // 操作权限校验
  1342. hasAuth, msg, errMsg, isSendEmail := checkOpPermission(sysUser, reportInfo, reportChapterInfo, true, this.Lang)
  1343. if !hasAuth {
  1344. br.Msg = msg
  1345. br.ErrMsg = errMsg
  1346. br.IsSendEmail = isSendEmail
  1347. return
  1348. }
  1349. if reportInfo.State == 2 {
  1350. br.Msg = "该报告已发布,不允许编辑"
  1351. br.ErrMsg = "该报告已发布,不允许编辑"
  1352. return
  1353. }
  1354. // 报告的最后编辑人
  1355. reportInfo.LastModifyAdminId = sysUser.AdminId
  1356. reportInfo.LastModifyAdminName = sysUser.RealName
  1357. reportInfo.ModifyTime = time.Now()
  1358. reportChapterInfo.Title = req.Title
  1359. reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  1360. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  1361. reportChapterInfo.ModifyTime = time.Now()
  1362. updateCols := make([]string, 0)
  1363. updateCols = append(updateCols, "Title", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
  1364. // 更新报告的最近编辑人信息
  1365. if err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"}); err != nil {
  1366. br.Msg = "保存失败"
  1367. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1368. return
  1369. }
  1370. // 更新章节
  1371. if err = reportChapterInfo.UpdateChapter(updateCols); err != nil {
  1372. br.Msg = "保存失败"
  1373. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1374. return
  1375. }
  1376. // 标记更新中
  1377. {
  1378. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  1379. if err != nil {
  1380. br.Msg = err.Error()
  1381. return
  1382. }
  1383. if markStatus.Status == 1 {
  1384. br.Msg = markStatus.Msg
  1385. return
  1386. }
  1387. }
  1388. br.Ret = 200
  1389. br.Success = true
  1390. br.Msg = "保存成功"
  1391. }
  1392. // CancelPublishReportChapter
  1393. // @Title 取消发布章节
  1394. // @Description 取消发布章节
  1395. // @Param request body models.PublishReportChapterReq true "type json string"
  1396. // @Success 200 Ret=200 操作成功
  1397. // @router /chapter/publish/cancel [post]
  1398. func (this *ReportController) CancelPublishReportChapter() {
  1399. br := new(models.BaseResponse).Init()
  1400. defer func() {
  1401. this.Data["json"] = br
  1402. this.ServeJSON()
  1403. }()
  1404. sysUser := this.SysUser
  1405. if sysUser == nil {
  1406. br.Msg = "请登录"
  1407. br.ErrMsg = "请登录,SysUser Is Empty"
  1408. br.Ret = 408
  1409. return
  1410. }
  1411. var req models.PublishReportChapterReq
  1412. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1413. if err != nil {
  1414. br.Msg = "参数解析异常!"
  1415. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1416. return
  1417. }
  1418. if req.ReportChapterId <= 0 {
  1419. br.Msg = "参数有误"
  1420. return
  1421. }
  1422. // 获取章节详情
  1423. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  1424. if err != nil {
  1425. br.Msg = "章节信息有误"
  1426. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  1427. return
  1428. }
  1429. // 章节发布状态校验
  1430. if chapterInfo.PublishState == 1 {
  1431. br.Msg = "该章节未发布,不能重复撤销"
  1432. br.ErrMsg = "该章节未发布,不能重复撤销"
  1433. br.IsSendEmail = false
  1434. return
  1435. }
  1436. // 获取报告详情
  1437. reportInfo, err := models.GetReportByReportId(chapterInfo.ReportId)
  1438. if err != nil {
  1439. br.Msg = "查询报告有误"
  1440. br.ErrMsg = "查询报告信息失败, Err: " + err.Error()
  1441. return
  1442. }
  1443. if reportInfo.State == 2 {
  1444. br.Msg = "该报告已发布,不允许撤销章节"
  1445. br.ErrMsg = "该报告已发布,不允许撤销章节"
  1446. br.IsSendEmail = false
  1447. return
  1448. }
  1449. // 更新章节信息
  1450. chapterInfo.PublishState = 1
  1451. chapterInfo.PublishTime = time.Time{}
  1452. chapterInfo.LastModifyAdminId = this.SysUser.AdminId
  1453. chapterInfo.LastModifyAdminName = this.SysUser.RealName
  1454. chapterInfo.ModifyTime = time.Now()
  1455. updateCols := make([]string, 0)
  1456. updateCols = append(updateCols, "PublishState", "PublishTime", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
  1457. err = chapterInfo.UpdateChapter(updateCols)
  1458. if err != nil {
  1459. br.Msg = "发布失败"
  1460. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1461. return
  1462. }
  1463. // 更新章节ES
  1464. {
  1465. go services.UpdateReportChapterEs(chapterInfo.ReportChapterId)
  1466. }
  1467. br.Ret = 200
  1468. br.Success = true
  1469. br.Msg = "撤销成功"
  1470. }
  1471. // checkOpPermission
  1472. // @Description: 操作权限校验
  1473. // @author: Roc
  1474. // @datetime 2024-11-12 09:58:34
  1475. // @param sysUser *system.Admin
  1476. // @param reportInfo *models.Report
  1477. // @param reportChapterInfo *models.ReportChapter
  1478. // @param isMarkStatus bool
  1479. // @param lang string
  1480. // @return hasAuth bool
  1481. // @return msg string
  1482. // @return errMsg string
  1483. // @return isSendEmail bool
  1484. func checkOpPermission(sysUser *system.Admin, reportInfo *models.Report, reportChapterInfo *models.ReportChapter, isMarkStatus bool, lang string) (hasAuth bool, msg, errMsg string, isSendEmail bool) {
  1485. isSendEmail = true
  1486. // 权限校验
  1487. isAuth, err := services.CheckChapterAuthByReportChapterInfo(sysUser, reportInfo.AdminId, reportChapterInfo)
  1488. if err != nil {
  1489. msg = "获取报告权限失败"
  1490. errMsg = "获取报告权限失败,Err:" + err.Error()
  1491. return
  1492. }
  1493. if !isAuth {
  1494. msg = "没有权限"
  1495. errMsg = "没有权限"
  1496. isSendEmail = false
  1497. return
  1498. }
  1499. // 如果不是创建人,那么就要去查看是否授权
  1500. //if reportInfo.AdminId != sysUser.AdminId && !utils.IsAdminRole(sysUser.RoleTypeCode) {
  1501. // // 授权用户权限校验
  1502. // chapterGrantObj := report.ReportChapterGrant{}
  1503. // _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, sysUser.AdminId)
  1504. // if tmpErr != nil {
  1505. // if tmpErr.Error() == utils.ErrNoRow() {
  1506. // msg = "没有权限"
  1507. // errMsg = "没有权限"
  1508. // isSendEmail = false
  1509. // return
  1510. // }
  1511. // msg = "获取章节id授权用户失败"
  1512. // errMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
  1513. // return
  1514. // }
  1515. //}
  1516. // 标记更新中
  1517. if isMarkStatus {
  1518. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, lang)
  1519. if err != nil {
  1520. msg = err.Error()
  1521. errMsg = err.Error()
  1522. return
  1523. }
  1524. if markStatus.Status == 1 {
  1525. msg = markStatus.Msg
  1526. errMsg = markStatus.Msg
  1527. isSendEmail = false
  1528. return
  1529. }
  1530. }
  1531. // 有权限
  1532. hasAuth = true
  1533. return
  1534. }