report_chapter.go 38 KB

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