report_chapter.go 47 KB

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