report_chapter.go 46 KB

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