askserie_video.go 14 KB

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