askserie_video.go 11 KB

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