askserie_video.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. v.RegisterPlatform = utils.CYGX_REGISTER_PLATFORM_MAP[v.RegisterPlatform]
  279. }
  280. resp.List = list
  281. br.Ret = 200
  282. br.Success = true
  283. br.Msg = "获取成功"
  284. br.Data = resp
  285. }
  286. // @Title 留言记录详情
  287. // @Description 留言记录详情接口
  288. // @Param AskserieVideoId query int true "ID"
  289. // @Param IsExport query bool false "是否导出excel,默认是false"
  290. // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
  291. // @router /askserie_video/collection_list [get]
  292. func (this *AskserieVideoController) CollectionList() {
  293. br := new(models.BaseResponse).Init()
  294. defer func() {
  295. this.Data["json"] = br
  296. this.ServeJSON()
  297. }()
  298. AdminUser := this.SysUser
  299. if AdminUser == nil {
  300. br.Msg = "请登录"
  301. br.ErrMsg = "请登录,用户信息为空"
  302. br.Ret = 408
  303. return
  304. }
  305. resp := new(cygx.CygxAskserieVideoCollectionListResp)
  306. askserieVideoId, _ := this.GetInt("AskserieVideoId")
  307. if askserieVideoId < 1 {
  308. br.Msg = "请输入详情ID"
  309. return
  310. }
  311. //是否导出报表
  312. isExport, _ := this.GetBool("IsExport")
  313. _, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  314. if err != nil {
  315. br.Msg = "详情不存在"
  316. br.ErrMsg = "获取失败,Err:" + err.Error()
  317. return
  318. }
  319. var condition string
  320. var pars []interface{}
  321. condition = ` AND askserie_video_id = ? ORDER BY id DESC `
  322. pars = append(pars, askserieVideoId)
  323. list, err := cygx.GetCygxAskserieVideoCollectionList(condition, pars)
  324. if err != nil {
  325. br.Msg = "获取失败"
  326. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  327. return
  328. }
  329. for _, v := range list {
  330. v.RegisterPlatform = utils.CYGX_REGISTER_PLATFORM_MAP[v.RegisterPlatform]
  331. }
  332. resp.List = list
  333. //导出excel
  334. if isExport {
  335. CollectionListExport(this, resp, br)
  336. return
  337. }
  338. br.Ret = 200
  339. br.Success = true
  340. br.Msg = "获取成功"
  341. br.Data = resp
  342. }
  343. // VoiceAndVideoCommentListExport 导出Excel
  344. func CollectionListExport(this *AskserieVideoController, resp *cygx.CygxAskserieVideoCollectionListResp, br *models.BaseResponse) {
  345. //创建excel
  346. dir, err := os.Executable()
  347. exPath := filepath.Dir(dir)
  348. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  349. xlsxFile := xlsx.NewFile()
  350. if err != nil {
  351. br.Msg = "生成文件失败"
  352. br.ErrMsg = "生成文件失败"
  353. return
  354. }
  355. style := xlsx.NewStyle()
  356. alignment := xlsx.Alignment{
  357. Horizontal: "center",
  358. Vertical: "center",
  359. WrapText: true,
  360. }
  361. style.Alignment = alignment
  362. style.ApplyAlignment = true
  363. sheet, err := xlsxFile.AddSheet("阅读明细")
  364. if err != nil {
  365. br.Msg = "新增Sheet失败"
  366. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  367. return
  368. }
  369. //标头
  370. rowTitle := sheet.AddRow()
  371. cellA := rowTitle.AddCell()
  372. cellA.Value = "姓名"
  373. cellB := rowTitle.AddCell()
  374. cellB.Value = "公司名称"
  375. cellC := rowTitle.AddCell()
  376. cellC.Value = "留言"
  377. cellD := rowTitle.AddCell()
  378. cellD.Value = "提交时间"
  379. for _, item := range resp.List {
  380. row := sheet.AddRow()
  381. cellA := row.AddCell()
  382. cellA.Value = item.RealName
  383. cellB := row.AddCell()
  384. cellB.Value = item.CompanyName
  385. cellC := row.AddCell()
  386. cellC.Value = item.Content
  387. cellD := row.AddCell()
  388. cellD.Value = item.CreateTime
  389. }
  390. err = xlsxFile.Save(downLoadnFilePath)
  391. if err != nil {
  392. br.Msg = "保存文件失败"
  393. br.ErrMsg = "保存文件失败"
  394. return
  395. }
  396. downloadFileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  397. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  398. defer func() {
  399. os.Remove(downLoadnFilePath)
  400. }()
  401. br.Ret = 200
  402. br.Success = true
  403. br.Msg = "导出成功"
  404. }
  405. // @Title 发布/取消发布
  406. // @Description 发布/取消发布接口
  407. // @Param request body cygx.ProductInteriorIdReq true "type json string"
  408. // @Success 200 Ret=200 发布成功
  409. // @router /askserie_video/publishAndcancel [post]
  410. func (this *AskserieVideoController) PublishReport() {
  411. br := new(models.BaseResponse).Init()
  412. defer func() {
  413. this.Data["json"] = br
  414. this.ServeJSON()
  415. }()
  416. var req cygx.AskserieVideoIdIdReq
  417. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  418. if err != nil {
  419. br.Msg = "参数解析异常!"
  420. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  421. return
  422. }
  423. askserieVideoId := req.AskserieVideoId
  424. if askserieVideoId == 0 {
  425. br.Msg = "参数错误"
  426. br.ErrMsg = "参数错误,id不可为空"
  427. return
  428. }
  429. detail, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  430. if err != nil {
  431. br.Msg = "详情不存在"
  432. br.ErrMsg = "获取失败,Err:" + err.Error()
  433. return
  434. }
  435. var status int
  436. if detail.PublishStatus == 0 {
  437. status = 1
  438. } else {
  439. status = 0
  440. }
  441. err = cygx.EditCygxAskserieVideoStatus(status, askserieVideoId)
  442. if err != nil {
  443. br.Msg = "操作失败"
  444. br.ErrMsg = "获取失败,Err:" + err.Error()
  445. return
  446. }
  447. go cygxService.UpdateAskserieVideoResourceData(askserieVideoId) //写入首页最新 cygx_resource_data 表
  448. go elastic.EsAddAskserieVideo(askserieVideoId) // 写入es 综合搜索
  449. br.Ret = 200
  450. br.Success = true
  451. br.Msg = "操作成功"
  452. }