askserie_video.go 14 KB

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