report_chapter.go 48 KB

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