askserie_video.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "github.com/tealeg/xlsx"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/cygx"
  9. cygxService "hongze/hz_crm_api/services/cygx"
  10. "hongze/hz_crm_api/services/elastic"
  11. "hongze/hz_crm_api/utils"
  12. "os"
  13. "path/filepath"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // 系列问答视频
  19. type AskserieVideoController struct {
  20. controllers.BaseAuthController
  21. }
  22. // @Title 新增
  23. // @Description 新增系列问答接口
  24. // @Param request body cygx.AddProductInteriorReq true "type json string"
  25. // @Success 200 {object} "保存成功"
  26. // @router /askserie_video/preserveAndEdit [post]
  27. func (this *AskserieVideoController) PreserveAndPublish() {
  28. br := new(models.BaseResponse).Init()
  29. defer func() {
  30. this.Data["json"] = br
  31. this.ServeJSON()
  32. }()
  33. sysUser := this.SysUser
  34. if sysUser == nil {
  35. br.Msg = "请登录"
  36. br.ErrMsg = "请登录,SysUser Is Empty"
  37. br.Ret = 408
  38. return
  39. }
  40. var req cygx.AddAskserieVideoReq
  41. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  42. if err != nil {
  43. br.Msg = "参数解析异常!"
  44. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  45. return
  46. }
  47. req.VideoName = utils.RemoveFileSuffixName(req.VideoName) //去掉后缀名称
  48. askserieVideoId := req.AskserieVideoId
  49. videoName := req.VideoName
  50. videoUrl := req.VideoUrl
  51. videoDuration := req.VideoDuration
  52. chartPermissionId := req.ChartPermissionId
  53. chartPermissionName := req.ChartPermissionName
  54. industrialManagementIds := req.IndustrialManagementIds
  55. backgroundImg := req.BackgroundImg
  56. shareImg := req.ShareImg
  57. // 产业ID校验
  58. if industrialManagementIds != "" {
  59. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  60. for _, v := range industrialManagementIdList {
  61. _, err := strconv.Atoi(v)
  62. if err != nil {
  63. br.Msg = "参数解析异常!"
  64. br.ErrMsg = "产业ID不规范,Err:" + err.Error() + industrialManagementIds
  65. return
  66. }
  67. }
  68. }
  69. item := new(cygx.CygxAskserieVideo)
  70. item.AskserieVideoId = askserieVideoId
  71. item.VideoName = videoName
  72. item.VideoUrl = videoUrl
  73. item.VideoDuration = videoDuration
  74. item.ChartPermissionId = chartPermissionId
  75. item.ChartPermissionName = chartPermissionName
  76. item.PublishStatus = 1
  77. item.BackgroundImg = backgroundImg
  78. item.AdminId = sysUser.AdminId
  79. item.ModifyDate = time.Now()
  80. item.PublishDate = time.Now()
  81. item.CreateTime = time.Now()
  82. if askserieVideoId == 0 {
  83. shareImg, _ = cygxService.MakeCygxMp3HtmlImg(videoDuration, 0) //生成分享图片
  84. item.ShareImg = shareImg
  85. //新增
  86. newId, err := cygx.AddCygxAskserieVideo(item, industrialManagementIds)
  87. if err != nil {
  88. br.Msg = "保存失败"
  89. br.ErrMsg = "保存失败,Err:" + err.Error()
  90. return
  91. }
  92. askserieVideoId = int(newId)
  93. } else {
  94. //更新
  95. detail, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  96. if err != nil {
  97. br.Msg = "详情不存在"
  98. br.ErrMsg = "获取失败,Err:" + err.Error()
  99. return
  100. }
  101. //如果时长有变更就更新分享图片
  102. if detail.VideoDuration != videoDuration {
  103. shareImg, _ = cygxService.MakeCygxMp3HtmlImg(videoDuration, 0) //生成分享图片
  104. item.ShareImg = shareImg
  105. }
  106. err = cygx.UpdateCygxAskserieVideo(item, industrialManagementIds)
  107. if err != nil {
  108. br.Msg = "保存失败"
  109. br.ErrMsg = "保存失败,Err:" + err.Error()
  110. return
  111. }
  112. }
  113. go cygxService.UpdateAskserieVideoResourceData(askserieVideoId) //写入首页最新 cygx_resource_data 表
  114. go elastic.EsAddAskserieVideo(askserieVideoId) // 写入es 综合搜索
  115. br.Ret = 200
  116. br.Success = true
  117. br.IsAddLog = true
  118. br.Msg = "操作成功"
  119. }
  120. // @Title 列表
  121. // @Description 列表接口
  122. // @Param PageSize query int true "每页数据条数"
  123. // @Param CurrentIndex query int true "当前页页码,从1开始"
  124. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  125. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  126. // @Param PublishStatus query int true "发布状态: -1-默认全部; 0-未发布; 1-已关注"
  127. // @Param ChartPermissionId query string false "行业Id"
  128. // @Param KeyWord query string false "搜索关键词"
  129. // @Param SortType query string false "排序顺序:asc、desc"
  130. // @Success Ret=200 {object} cygx.GetCygxTacticsTimeLineResp
  131. // @router /askserie_video/list [get]
  132. func (this *AskserieVideoController) List() {
  133. br := new(models.BaseResponse).Init()
  134. defer func() {
  135. this.Data["json"] = br
  136. this.ServeJSON()
  137. }()
  138. sysUser := this.SysUser
  139. if sysUser == nil {
  140. br.Msg = "请登录"
  141. br.ErrMsg = "请登录,SysUser Is Empty"
  142. br.Ret = 408
  143. return
  144. }
  145. resp := new(cygx.GetCygxAskserieVideoRespListResp)
  146. pageSize, _ := this.GetInt("PageSize")
  147. currentIndex, _ := this.GetInt("CurrentIndex")
  148. publishStatus, _ := this.GetInt("PublishStatus", -1)
  149. startDate := this.GetString("StartDate")
  150. endDate := this.GetString("EndDate")
  151. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  152. keyWord := this.GetString("KeyWord")
  153. keyWord = strings.Trim(keyWord, " ")
  154. keyWord = strings.Replace(keyWord, "'", "", -1)
  155. sortType := this.GetString("SortType")
  156. var startSize int
  157. if pageSize <= 0 {
  158. pageSize = utils.PageSize20
  159. }
  160. if currentIndex <= 0 {
  161. currentIndex = 1
  162. }
  163. startSize = utils.StartIndex(currentIndex, pageSize)
  164. var condition string
  165. var pars []interface{}
  166. //发布状态查询
  167. if publishStatus == 0 || publishStatus == 1 || publishStatus == 3 {
  168. condition += ` AND art.publish_status = ? `
  169. pars = append(pars, publishStatus)
  170. }
  171. //起始日期查询
  172. if startDate != "" && endDate != "" {
  173. condition += ` AND art.publish_date BETWEEN ? AND ? `
  174. pars = append(pars, startDate+" 00:00:00", endDate+" 23:59:59")
  175. }
  176. //行业查询
  177. if chartPermissionId > 0 {
  178. condition += ` AND art.chart_permission_id = ?`
  179. pars = append(pars, chartPermissionId)
  180. }
  181. if keyWord != "" {
  182. condition += ` AND ( video_name LIKE '%` + keyWord + `%' ) `
  183. }
  184. total, err := cygx.GetCygxAskserieVideoCount(condition, pars)
  185. if err != nil {
  186. br.Msg = "获取失败"
  187. br.ErrMsg = "获取失败,Err:" + err.Error()
  188. return
  189. }
  190. var conditionOrder string
  191. if sortType == "asc" || sortType == "desc" {
  192. conditionOrder += ` ORDER BY art.video_counts ` + sortType
  193. } else {
  194. conditionOrder += ` ORDER BY art.modify_date DESC `
  195. }
  196. //condition += " ORDER BY art.modify_date DESC "
  197. condition += conditionOrder
  198. list, err := cygx.GetCygxAskserieVideoList(condition, pars, startSize, pageSize)
  199. if err != nil {
  200. br.Msg = "获取失败"
  201. br.ErrMsg = "获取失败,Err:" + err.Error()
  202. return
  203. }
  204. var askserieVideoIds []int
  205. for _, v := range list {
  206. askserieVideoIds = append(askserieVideoIds, v.AskserieVideoId)
  207. }
  208. mapLabel := cygxService.GetCygxAskserieVideoLabelMap(askserieVideoIds) // 标签
  209. for _, v := range list {
  210. v.IndustryName = mapLabel[v.AskserieVideoId]
  211. }
  212. page := paging.GetPaging(currentIndex, pageSize, total)
  213. resp.List = list
  214. resp.Paging = page
  215. br.Ret = 200
  216. br.Success = true
  217. br.Msg = "获取成功"
  218. br.Data = resp
  219. }
  220. // @Title 详情
  221. // @Description 获取详情接口
  222. // @Param AskserieVideoId query int true "ID"
  223. // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
  224. // @router /askserie_video/detail [get]
  225. func (this *AskserieVideoController) Detail() {
  226. br := new(models.BaseResponse).Init()
  227. defer func() {
  228. this.Data["json"] = br
  229. this.ServeJSON()
  230. }()
  231. AdminUser := this.SysUser
  232. if AdminUser == nil {
  233. br.Msg = "请登录"
  234. br.ErrMsg = "请登录,用户信息为空"
  235. br.Ret = 408
  236. return
  237. }
  238. resp := new(cygx.GetCygxAskserieVideoDetailResp)
  239. askserieVideoId, _ := this.GetInt("AskserieVideoId")
  240. if askserieVideoId < 1 {
  241. br.Msg = "请输入详情ID"
  242. return
  243. }
  244. detail, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  245. if err != nil {
  246. br.Msg = "详情不存在"
  247. br.ErrMsg = "获取失败,Err:" + err.Error()
  248. return
  249. }
  250. //产业标签
  251. industrialListMap := cygxService.GetCygxAskserieVideoLabelListMap([]int{askserieVideoId})
  252. detail.ListIndustrial = industrialListMap[askserieVideoId]
  253. resp.Detail = detail
  254. br.Ret = 200
  255. br.Success = true
  256. br.Msg = "获取成功"
  257. br.Data = resp
  258. }
  259. // @Title 播放记录详情
  260. // @Description 播放记录详情接口
  261. // @Param AskserieVideoId query int true "ID"
  262. // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
  263. // @router /askserie_video/history_list [get]
  264. func (this *AskserieVideoController) HistoryList() {
  265. br := new(models.BaseResponse).Init()
  266. defer func() {
  267. this.Data["json"] = br
  268. this.ServeJSON()
  269. }()
  270. AdminUser := this.SysUser
  271. if AdminUser == nil {
  272. br.Msg = "请登录"
  273. br.ErrMsg = "请登录,用户信息为空"
  274. br.Ret = 408
  275. return
  276. }
  277. resp := new(cygx.CygxCygxAskserieVideoHistoryRecordListResp)
  278. askserieVideoId, _ := this.GetInt("AskserieVideoId")
  279. if askserieVideoId < 1 {
  280. br.Msg = "请输入详情ID"
  281. return
  282. }
  283. _, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  284. if err != nil {
  285. br.Msg = "详情不存在"
  286. br.ErrMsg = "获取失败,Err:" + err.Error()
  287. return
  288. }
  289. var condition string
  290. var pars []interface{}
  291. condition = ` AND askserie_video_id = ? ORDER BY id DESC `
  292. pars = append(pars, askserieVideoId)
  293. list, err := cygx.GetCygxAskserieVideoHistoryRecordList(condition, pars)
  294. if err != nil {
  295. br.Msg = "获取失败"
  296. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  297. return
  298. }
  299. for _, v := range list {
  300. v.PlaySeconds = v.VideoDuration
  301. v.RegisterPlatform = utils.CYGX_REGISTER_PLATFORM_MAP[v.RegisterPlatform]
  302. }
  303. resp.List = list
  304. br.Ret = 200
  305. br.Success = true
  306. br.Msg = "获取成功"
  307. br.Data = resp
  308. }
  309. // @Title 留言记录详情
  310. // @Description 留言记录详情接口
  311. // @Param AskserieVideoId query int true "ID"
  312. // @Param IsExport query bool false "是否导出excel,默认是false"
  313. // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
  314. // @router /askserie_video/collection_list [get]
  315. func (this *AskserieVideoController) CollectionList() {
  316. br := new(models.BaseResponse).Init()
  317. defer func() {
  318. this.Data["json"] = br
  319. this.ServeJSON()
  320. }()
  321. AdminUser := this.SysUser
  322. if AdminUser == nil {
  323. br.Msg = "请登录"
  324. br.ErrMsg = "请登录,用户信息为空"
  325. br.Ret = 408
  326. return
  327. }
  328. resp := new(cygx.CygxAskserieVideoCollectionListResp)
  329. askserieVideoId, _ := this.GetInt("AskserieVideoId")
  330. if askserieVideoId < 1 {
  331. br.Msg = "请输入详情ID"
  332. return
  333. }
  334. //是否导出报表
  335. isExport, _ := this.GetBool("IsExport")
  336. _, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  337. if err != nil {
  338. br.Msg = "详情不存在"
  339. br.ErrMsg = "获取失败,Err:" + err.Error()
  340. return
  341. }
  342. var condition string
  343. var pars []interface{}
  344. condition = ` AND askserie_video_id = ? ORDER BY id DESC `
  345. pars = append(pars, askserieVideoId)
  346. list, err := cygx.GetCygxAskserieVideoCollectionList(condition, pars)
  347. if err != nil {
  348. br.Msg = "获取失败"
  349. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  350. return
  351. }
  352. for _, v := range list {
  353. v.RegisterPlatform = utils.CYGX_REGISTER_PLATFORM_MAP[v.RegisterPlatform]
  354. }
  355. resp.List = list
  356. //导出excel
  357. if isExport {
  358. CollectionListExport(this, resp, br)
  359. return
  360. }
  361. br.Ret = 200
  362. br.Success = true
  363. br.Msg = "获取成功"
  364. br.Data = resp
  365. }
  366. // VoiceAndVideoCommentListExport 导出Excel
  367. func CollectionListExport(this *AskserieVideoController, resp *cygx.CygxAskserieVideoCollectionListResp, br *models.BaseResponse) {
  368. //创建excel
  369. dir, err := os.Executable()
  370. exPath := filepath.Dir(dir)
  371. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  372. xlsxFile := xlsx.NewFile()
  373. if err != nil {
  374. br.Msg = "生成文件失败"
  375. br.ErrMsg = "生成文件失败"
  376. return
  377. }
  378. style := xlsx.NewStyle()
  379. alignment := xlsx.Alignment{
  380. Horizontal: "center",
  381. Vertical: "center",
  382. WrapText: true,
  383. }
  384. style.Alignment = alignment
  385. style.ApplyAlignment = true
  386. sheet, err := xlsxFile.AddSheet("阅读明细")
  387. if err != nil {
  388. br.Msg = "新增Sheet失败"
  389. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  390. return
  391. }
  392. //标头
  393. rowTitle := sheet.AddRow()
  394. cellA := rowTitle.AddCell()
  395. cellA.Value = "姓名"
  396. cellB := rowTitle.AddCell()
  397. cellB.Value = "公司名称"
  398. cellC := rowTitle.AddCell()
  399. cellC.Value = "留言"
  400. cellD := rowTitle.AddCell()
  401. cellD.Value = "提交时间"
  402. for _, item := range resp.List {
  403. row := sheet.AddRow()
  404. cellA := row.AddCell()
  405. cellA.Value = item.RealName
  406. cellB := row.AddCell()
  407. cellB.Value = item.CompanyName
  408. cellC := row.AddCell()
  409. cellC.Value = item.Content
  410. cellD := row.AddCell()
  411. cellD.Value = item.CreateTime
  412. }
  413. err = xlsxFile.Save(downLoadnFilePath)
  414. if err != nil {
  415. br.Msg = "保存文件失败"
  416. br.ErrMsg = "保存文件失败"
  417. return
  418. }
  419. downloadFileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  420. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  421. defer func() {
  422. os.Remove(downLoadnFilePath)
  423. }()
  424. br.Ret = 200
  425. br.Success = true
  426. br.Msg = "导出成功"
  427. }
  428. // @Title 发布/取消发布
  429. // @Description 发布/取消发布接口
  430. // @Param request body cygx.ProductInteriorIdReq true "type json string"
  431. // @Success 200 Ret=200 发布成功
  432. // @router /askserie_video/publishAndcancel [post]
  433. func (this *AskserieVideoController) PublishReport() {
  434. br := new(models.BaseResponse).Init()
  435. defer func() {
  436. this.Data["json"] = br
  437. this.ServeJSON()
  438. }()
  439. var req cygx.AskserieVideoIdIdReq
  440. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  441. if err != nil {
  442. br.Msg = "参数解析异常!"
  443. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  444. return
  445. }
  446. askserieVideoId := req.AskserieVideoId
  447. if askserieVideoId == 0 {
  448. br.Msg = "参数错误"
  449. br.ErrMsg = "参数错误,id不可为空"
  450. return
  451. }
  452. detail, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  453. if err != nil {
  454. br.Msg = "详情不存在"
  455. br.ErrMsg = "获取失败,Err:" + err.Error()
  456. return
  457. }
  458. var status int
  459. if detail.PublishStatus != 1 {
  460. status = 1
  461. } else {
  462. status = 3
  463. }
  464. err = cygx.EditCygxAskserieVideoStatus(status, askserieVideoId)
  465. if err != nil {
  466. br.Msg = "操作失败"
  467. br.ErrMsg = "获取失败,Err:" + err.Error()
  468. return
  469. }
  470. go cygxService.UpdateAskserieVideoResourceData(askserieVideoId) //写入首页最新 cygx_resource_data 表
  471. go elastic.EsAddAskserieVideo(askserieVideoId) // 写入es 综合搜索
  472. br.Ret = 200
  473. br.Success = true
  474. br.Msg = "操作成功"
  475. }