report_chapter.go 45 KB

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