package cn.lili.controller.lmk; import cn.lili.base.Result; import cn.lili.group.Add; import cn.lili.group.Update; import cn.lili.modules.lmk.domain.form.ThumbsUpRecordForm; import cn.lili.modules.lmk.domain.form.VideoFootPrintForm; import cn.lili.modules.lmk.domain.form.VideoHomePageInfoForm; import cn.lili.modules.lmk.domain.form.WxVideoForm; import cn.lili.modules.lmk.domain.query.*; import cn.lili.modules.lmk.domain.vo.WxVideoVO; import cn.lili.modules.lmk.service.VideoService; import cn.lili.utils.COSUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.constraints.NotEmpty; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; /** * 视频内容 前端控制器 * * @author xp * @since 2025-05-16 */ @Validated @RequiredArgsConstructor @Api(value = "视频内容", tags = "视频内容管理") @RestController @RequestMapping("/buyer/lmk/video") public class VideoController { private final VideoService videoService; private COSUtil cOSUtil; @PostMapping("/publish") @ApiOperation(value = "发布视频", notes = "发布视频") public Result publish(@RequestBody @Validated({Add.class}) WxVideoForm form) { return videoService.publish(form); } @PutMapping @ApiOperation(value = "修改视频", notes = "修改视频") public Result update(@RequestBody @Validated(Update.class) WxVideoForm form) { return videoService.updatePublish(form); } @DeleteMapping("/{id}") @ApiOperation(value = "ID删除", notes = "ID删除") public Result removeById(@PathVariable("id") String id) { return videoService.removeById(id); } @PostMapping("/down/{id}") @ApiOperation(value = "用户下架视频", notes = "用户下架视频") public Result downVideo(@PathVariable("id") String id) { return videoService.buyerDownVideo(id); } @DeleteMapping("/batch") @ApiOperation(value = "批量删除", notes = "批量删除") public Result remove(@RequestBody @NotEmpty(message = "请选择数据") List ids) { return videoService.remove(ids); } @GetMapping("/{id}") @ApiOperation(value = "详情", notes = "详情") public Result detail(@PathVariable("id") String id) { return videoService.detail(id); } @GetMapping("/recommend") @ApiOperation(value = "视频推荐", notes = "视频推荐") public Result recommendVideo(VideoQuery query) { return videoService.recommendVideo(query); } @GetMapping("/health/recommend") @ApiOperation(value = "大健康视频推荐", notes = "大健康视频推荐") public Result healthRecommendVideo(WxHealthVideoQuery query) { return videoService.healthRecommendVideo(query); } @GetMapping("/kitchen/type") @ApiOperation(value = "厨神视频类型列表", notes = "厨神视频类型列表") public Result kitchenTypeList() { return videoService.kitchenTypeList(); } @GetMapping("/kitchen/recommend") @ApiOperation(value = "厨神视频推荐", notes = "厨神视频推荐") public Result kitchenRecommendVideo(WxKitchenVideoQuery query) { return videoService.kitchenRecommendVideo(query); } @GetMapping("/goods/detail/{videoId}") @ApiOperation(value = "视频商品查看", notes = "视频商品查看") public Result getGoodsDetail(@PathVariable("videoId") String videoId) { return videoService.getGoodsDetail(videoId); } @PostMapping("/view/record") @ApiOperation(value = "保存观看记录", notes = "保存观看记录") public Result saveViewRecord(@RequestBody VideoFootPrintForm form) { return videoService.saveViewRecord(form); } @GetMapping("/author-info/{authorId}") @ApiOperation(value = "获取视频主页作者信息", notes = "获取视频主页作者信息") public Result getAuthorInfo(@PathVariable("authorId") String authorId) { return videoService.getAuthorInfo(authorId); } @GetMapping("/author-video-page") @ApiOperation(value = "获取视频主页作者视频分页", notes = "获取视频主页作者视频分页") public Result getAuthorVideoPage(AuthorVideoQuery query) { return videoService.getAuthorVideoPage(query); } @GetMapping("/author-collect-video-page") @ApiOperation(value = "获取视频主页作者收藏的视频分页", notes = "获取视频主页作者收藏的视频分页") public Result getAuthorCollectVideoPage(AuthorVideoQuery query) { Result result = videoService.getAuthorCollectVideoPage(query); List list = Optional.ofNullable(result.get("data")) .filter(data -> data instanceof List) .map(data -> (List) data) .orElse(Collections.emptyList()) .stream() .filter(WxVideoVO.class::isInstance) .map(WxVideoVO.class::cast) .collect(Collectors.toList()); for (WxVideoVO wxVideoVO : list){ if (!CollectionUtils.isEmpty(wxVideoVO.getImgs())){ List newImages = wxVideoVO .getImgs().stream().map(item -> cOSUtil.getPreviewUrl(item)).collect(Collectors.toList()); wxVideoVO.setImgs(newImages); } } return result; } @GetMapping("/author-like-video-page") @ApiOperation(value = "获取视频主页作者点赞的视频分页", notes = "获取视频主页作者点赞的视频分页") public Result getAuthorLikeVideoPage(AuthorVideoQuery query) { return videoService.getAuthorLikeVideoPage(query); } @PostMapping("/home-page-info-edit") @ApiOperation(value = "保存视频主页的个人信息修改", notes = "保存视频主页的个人信息修改") public Result homePageInfoEdit(@RequestBody @Validated VideoHomePageInfoForm form) { return videoService.homePageInfoEdit(form); } @GetMapping("/wx/detail/{id}") @ApiOperation(value = "小程序-获取视频详情", notes = "小程序-获取视频详情") public Result wxDetail(@PathVariable("id") String id) { return videoService.wxDetail(id); } @PostMapping("/change/thumbs-up") @ApiOperation(value = "点赞/取消点赞视频", notes = "点赞/取消点赞视频") public Result changeThumbsUp(@RequestBody @Validated(Add.class) ThumbsUpRecordForm form) { return videoService.changeThumbsUp(form); } @GetMapping("/es/search") @ApiOperation(value = "视频搜索", notes = "视频搜索") public Result esSearch(VideoEsQuery query) { return videoService.esSearch(query); } @PostMapping("/goods/similarly") @ApiOperation(value = "挂相同商品的视频", notes = "挂相同商品的视频") public Result goodsSimilarly(@RequestBody VideoQuery query) { return videoService.recommendVideo(query); } @GetMapping("/history") @ApiOperation(value = "获取历史播放记录") public Result getHistoryPage(VideoHistoryQuery query) { return videoService.getHistoryPage(query); } }