report_chapter.go 45 KB

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