report_chapter.go 48 KB

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