askserie_video.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/controllers"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/cygx"
  8. cygxService "hongze/hz_crm_api/services/cygx"
  9. "hongze/hz_crm_api/services/elastic"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. // 系列问答视频
  16. type AskserieVideoController struct {
  17. controllers.BaseAuthController
  18. }
  19. // @Title 新增
  20. // @Description 新增系列问答接口
  21. // @Param request body cygx.AddProductInteriorReq true "type json string"
  22. // @Success 200 {object} "保存成功"
  23. // @router /askserie_video/preserveAndEdit [post]
  24. func (this *AskserieVideoController) PreserveAndPublish() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. sysUser := this.SysUser
  31. if sysUser == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,SysUser Is Empty"
  34. br.Ret = 408
  35. return
  36. }
  37. var req cygx.AddAskserieVideoReq
  38. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  39. if err != nil {
  40. br.Msg = "参数解析异常!"
  41. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  42. return
  43. }
  44. askserieVideoId := req.AskserieVideoId
  45. videoName := req.VideoName
  46. videoUrl := req.VideoUrl
  47. videoDuration := req.VideoDuration
  48. chartPermissionId := req.ChartPermissionId
  49. chartPermissionName := req.ChartPermissionName
  50. industrialManagementIds := req.IndustrialManagementIds
  51. backgroundImg := req.BackgroundImg
  52. shareImg := req.ShareImg
  53. // 产业ID校验
  54. if industrialManagementIds != "" {
  55. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  56. for _, v := range industrialManagementIdList {
  57. _, err := strconv.Atoi(v)
  58. if err != nil {
  59. br.Msg = "参数解析异常!"
  60. br.ErrMsg = "产业ID不规范,Err:" + err.Error() + industrialManagementIds
  61. return
  62. }
  63. }
  64. }
  65. item := new(cygx.CygxAskserieVideo)
  66. item.AskserieVideoId = askserieVideoId
  67. item.VideoName = videoName
  68. item.VideoUrl = videoUrl
  69. item.VideoDuration = videoDuration
  70. item.ChartPermissionId = chartPermissionId
  71. item.ChartPermissionName = chartPermissionName
  72. item.PublishStatus = 1
  73. item.BackgroundImg = backgroundImg
  74. item.ShareImg = shareImg
  75. item.AdminId = sysUser.AdminId
  76. item.ModifyDate = time.Now()
  77. item.PublishDate = time.Now()
  78. item.CreateTime = time.Now()
  79. if askserieVideoId == 0 {
  80. //新增
  81. newId, err := cygx.AddCygxAskserieVideo(item, industrialManagementIds)
  82. if err != nil {
  83. br.Msg = "保存失败"
  84. br.ErrMsg = "保存失败,Err:" + err.Error()
  85. return
  86. }
  87. askserieVideoId = int(newId)
  88. } else {
  89. //更新
  90. _, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  91. if err != nil {
  92. br.Msg = "详情不存在"
  93. br.ErrMsg = "获取失败,Err:" + err.Error()
  94. return
  95. }
  96. err = cygx.UpdateCygxAskserieVideo(item, industrialManagementIds)
  97. if err != nil {
  98. br.Msg = "保存失败"
  99. br.ErrMsg = "保存失败,Err:" + err.Error()
  100. return
  101. }
  102. }
  103. go cygxService.UpdateAskserieVideoResourceData(askserieVideoId) //写入首页最新 cygx_resource_data 表
  104. go elastic.EsAddAskserieVideo(askserieVideoId) // 写入es 综合搜索
  105. br.Ret = 200
  106. br.Success = true
  107. br.IsAddLog = true
  108. br.Msg = "操作成功"
  109. }
  110. // @Title 列表
  111. // @Description 列表接口
  112. // @Param PageSize query int true "每页数据条数"
  113. // @Param CurrentIndex query int true "当前页页码,从1开始"
  114. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  115. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  116. // @Param PublishStatus query int true "发布状态: -1-默认全部; 0-未发布; 1-已关注"
  117. // @Param ChartPermissionId query string false "行业Id"
  118. // @Success Ret=200 {object} cygx.GetCygxTacticsTimeLineResp
  119. // @router /askserie_video/list [get]
  120. func (this *AskserieVideoController) List() {
  121. br := new(models.BaseResponse).Init()
  122. defer func() {
  123. this.Data["json"] = br
  124. this.ServeJSON()
  125. }()
  126. sysUser := this.SysUser
  127. if sysUser == nil {
  128. br.Msg = "请登录"
  129. br.ErrMsg = "请登录,SysUser Is Empty"
  130. br.Ret = 408
  131. return
  132. }
  133. resp := new(cygx.GetCygxAskserieVideoRespListResp)
  134. pageSize, _ := this.GetInt("PageSize")
  135. currentIndex, _ := this.GetInt("CurrentIndex")
  136. publishStatus, _ := this.GetInt("PublishStatus", -1)
  137. startDate := this.GetString("StartDate")
  138. endDate := this.GetString("EndDate")
  139. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  140. var startSize int
  141. if pageSize <= 0 {
  142. pageSize = utils.PageSize20
  143. }
  144. if currentIndex <= 0 {
  145. currentIndex = 1
  146. }
  147. startSize = utils.StartIndex(currentIndex, pageSize)
  148. var condition string
  149. var pars []interface{}
  150. //发布状态查询
  151. if publishStatus == 0 || publishStatus == 1 {
  152. condition += ` AND art.publish_status = ? `
  153. pars = append(pars, publishStatus)
  154. }
  155. //起始日期查询
  156. if startDate != "" && endDate != "" {
  157. condition += ` AND art.publish_time BETWEEN ? AND ? `
  158. pars = append(pars, startDate, endDate)
  159. }
  160. //行业查询
  161. if chartPermissionId > 0 {
  162. condition += ` AND art.chart_permission_id = ?`
  163. pars = append(pars, chartPermissionId)
  164. }
  165. total, err := cygx.GetCygxAskserieVideoCount(condition, pars)
  166. if err != nil {
  167. br.Msg = "获取失败"
  168. br.ErrMsg = "获取失败,Err:" + err.Error()
  169. return
  170. }
  171. condition += " ORDER BY art.modify_date DESC "
  172. list, err := cygx.GetCygxAskserieVideoList(condition, pars, startSize, pageSize)
  173. if err != nil {
  174. br.Msg = "获取失败"
  175. br.ErrMsg = "获取失败,Err:" + err.Error()
  176. return
  177. }
  178. var askserieVideoIds []int
  179. for _, v := range list {
  180. askserieVideoIds = append(askserieVideoIds, v.AskserieVideoId)
  181. }
  182. mapLabel := cygxService.GetCygxAskserieVideoLabelMap(askserieVideoIds) // 标签
  183. for _, v := range list {
  184. v.IndustryName = mapLabel[v.AskserieVideoId]
  185. }
  186. page := paging.GetPaging(currentIndex, pageSize, total)
  187. resp.List = list
  188. resp.Paging = page
  189. br.Ret = 200
  190. br.Success = true
  191. br.Msg = "获取成功"
  192. br.Data = resp
  193. }
  194. // @Title 详情
  195. // @Description 获取详情接口
  196. // @Param AskserieVideoId query int true "ID"
  197. // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
  198. // @router /askserie_video/detail [get]
  199. func (this *AskserieVideoController) Detail() {
  200. br := new(models.BaseResponse).Init()
  201. defer func() {
  202. this.Data["json"] = br
  203. this.ServeJSON()
  204. }()
  205. AdminUser := this.SysUser
  206. if AdminUser == nil {
  207. br.Msg = "请登录"
  208. br.ErrMsg = "请登录,用户信息为空"
  209. br.Ret = 408
  210. return
  211. }
  212. resp := new(cygx.GetCygxAskserieVideoDetailResp)
  213. askserieVideoId, _ := this.GetInt("AskserieVideoId")
  214. if askserieVideoId < 1 {
  215. br.Msg = "请输入详情ID"
  216. return
  217. }
  218. detail, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  219. if err != nil {
  220. br.Msg = "详情不存在"
  221. br.ErrMsg = "获取失败,Err:" + err.Error()
  222. return
  223. }
  224. //产业标签
  225. industrialListMap := cygxService.GetCygxAskserieVideoLabelListMap([]int{askserieVideoId})
  226. detail.ListIndustrial = industrialListMap[askserieVideoId]
  227. resp.Detail = detail
  228. br.Ret = 200
  229. br.Success = true
  230. br.Msg = "获取成功"
  231. br.Data = resp
  232. }
  233. // @Title 播放记录详情
  234. // @Description 播放记录详情接口
  235. // @Param AskserieVideoId query int true "ID"
  236. // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
  237. // @router /askserie_video/history_list [get]
  238. func (this *AskserieVideoController) HistoryList() {
  239. br := new(models.BaseResponse).Init()
  240. defer func() {
  241. this.Data["json"] = br
  242. this.ServeJSON()
  243. }()
  244. AdminUser := this.SysUser
  245. if AdminUser == nil {
  246. br.Msg = "请登录"
  247. br.ErrMsg = "请登录,用户信息为空"
  248. br.Ret = 408
  249. return
  250. }
  251. resp := new(cygx.CygxCygxAskserieVideoHistoryRecordListResp)
  252. askserieVideoId, _ := this.GetInt("AskserieVideoId")
  253. if askserieVideoId < 1 {
  254. br.Msg = "请输入详情ID"
  255. return
  256. }
  257. _, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  258. if err != nil {
  259. br.Msg = "详情不存在"
  260. br.ErrMsg = "获取失败,Err:" + err.Error()
  261. return
  262. }
  263. var condition string
  264. var pars []interface{}
  265. condition = ` AND askserie_video_id = ? ORDER BY id DESC `
  266. pars = append(pars, askserieVideoId)
  267. list, err := cygx.GetCygxAskserieVideoHistoryRecordList(condition, pars)
  268. if err != nil {
  269. br.Msg = "获取失败"
  270. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  271. return
  272. }
  273. resp.List = list
  274. br.Ret = 200
  275. br.Success = true
  276. br.Msg = "获取成功"
  277. br.Data = resp
  278. }
  279. // @Title 留言记录详情
  280. // @Description 留言记录详情接口
  281. // @Param AskserieVideoId query int true "ID"
  282. // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
  283. // @router /askserie_video/collection_list [get]
  284. func (this *AskserieVideoController) CollectionList() {
  285. br := new(models.BaseResponse).Init()
  286. defer func() {
  287. this.Data["json"] = br
  288. this.ServeJSON()
  289. }()
  290. AdminUser := this.SysUser
  291. if AdminUser == nil {
  292. br.Msg = "请登录"
  293. br.ErrMsg = "请登录,用户信息为空"
  294. br.Ret = 408
  295. return
  296. }
  297. resp := new(cygx.CygxAskserieVideoCollectionListResp)
  298. askserieVideoId, _ := this.GetInt("AskserieVideoId")
  299. if askserieVideoId < 1 {
  300. br.Msg = "请输入详情ID"
  301. return
  302. }
  303. _, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  304. if err != nil {
  305. br.Msg = "详情不存在"
  306. br.ErrMsg = "获取失败,Err:" + err.Error()
  307. return
  308. }
  309. var condition string
  310. var pars []interface{}
  311. condition = ` AND askserie_video_id = ? ORDER BY id DESC `
  312. pars = append(pars, askserieVideoId)
  313. list, err := cygx.GetCygxAskserieVideoCollectionList(condition, pars)
  314. if err != nil {
  315. br.Msg = "获取失败"
  316. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  317. return
  318. }
  319. resp.List = list
  320. br.Ret = 200
  321. br.Success = true
  322. br.Msg = "获取成功"
  323. br.Data = resp
  324. }
  325. // @Title 发布/取消发布
  326. // @Description 发布/取消发布接口
  327. // @Param request body cygx.ProductInteriorIdReq true "type json string"
  328. // @Success 200 Ret=200 发布成功
  329. // @router /askserie_video/publishAndcancel [post]
  330. func (this *AskserieVideoController) PublishReport() {
  331. br := new(models.BaseResponse).Init()
  332. defer func() {
  333. this.Data["json"] = br
  334. this.ServeJSON()
  335. }()
  336. var req cygx.AskserieVideoIdIdReq
  337. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  338. if err != nil {
  339. br.Msg = "参数解析异常!"
  340. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  341. return
  342. }
  343. askserieVideoId := req.AskserieVideoId
  344. if askserieVideoId == 0 {
  345. br.Msg = "参数错误"
  346. br.ErrMsg = "参数错误,id不可为空"
  347. return
  348. }
  349. detail, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
  350. if err != nil {
  351. br.Msg = "详情不存在"
  352. br.ErrMsg = "获取失败,Err:" + err.Error()
  353. return
  354. }
  355. var status int
  356. if detail.PublishStatus == 0 {
  357. status = 1
  358. } else {
  359. status = 0
  360. }
  361. err = cygx.EditCygxAskserieVideoStatus(status, askserieVideoId)
  362. if err != nil {
  363. br.Msg = "操作失败"
  364. br.ErrMsg = "获取失败,Err:" + err.Error()
  365. return
  366. }
  367. go cygxService.UpdateAskserieVideoResourceData(askserieVideoId) //写入首页最新 cygx_resource_data 表
  368. go elastic.EsAddAskserieVideo(askserieVideoId) // 写入es 综合搜索
  369. br.Ret = 200
  370. br.Success = true
  371. br.Msg = "操作成功"
  372. }