report_chapter.go 45 KB

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