report_chapter.go 45 KB

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