report_chapter.go 39 KB

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