askserie_video.go 13 KB

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