package com.hollywood.manage.controller; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hollywood.common.basic.ApiResult; import com.hollywood.common.basic.PageInfo; import com.hollywood.common.model.TShortPlay; import com.hollywood.common.model.TShortPlayToType; import com.hollywood.common.model.TShortPlayType; import com.hollywood.common.model.TShortPlayVideo; import com.hollywood.manage.dto.TShortPlayDTO; import com.hollywood.manage.query.TShortPlayQuery; import com.hollywood.manage.service.TShortPlayService; import com.hollywood.manage.service.TShortPlayToTypeService; import com.hollywood.manage.service.TShortPlayTypeService; import com.hollywood.manage.service.TShortPlayVideoService; import com.hollywood.manage.vo.TShortPlayVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; /** *

* 短剧管理 前端控制器 *

* * @author xiaochen * @since 2024-02-29 */ @Api(tags = "短剧管理") @RestController @RequestMapping("/tShortPlay") public class TShortPlayController { private final TShortPlayService shortPlayService; private final TShortPlayVideoService shortPlayVideoService; private final TShortPlayToTypeService shortPlayToTypeService; private final TShortPlayTypeService shortPlayTypeService; @Autowired public TShortPlayController(TShortPlayService shortPlayService, TShortPlayVideoService shortPlayVideoService, TShortPlayToTypeService shortPlayToTypeService, TShortPlayTypeService shortPlayTypeService) { this.shortPlayService = shortPlayService; this.shortPlayVideoService = shortPlayVideoService; this.shortPlayToTypeService = shortPlayToTypeService; this.shortPlayTypeService = shortPlayTypeService; } /** * 获取短剧管理分页列表 */ @ApiOperation(value = "获取短剧管理分页列表") @PostMapping(value = "/pageList") public ApiResult> pageList(@RequestBody TShortPlayQuery query) { return ApiResult.success(shortPlayService.pageList(query)); } /** * 新增短剧管理 */ @ApiOperation(value = "新增短剧管理") @PostMapping(value = "/addTShortPlay") @Transactional(rollbackFor = Exception.class) public ApiResult addTShortPlay(@Validated @RequestBody TShortPlayDTO shortPlayDTO) { // 添加短剧 shortPlayService.save(shortPlayDTO); // 添加短剧视频 List shortPlayVideos = shortPlayDTO.getShortPlayVideos(); for (TShortPlayVideo shortPlayVideo : shortPlayDTO.getShortPlayVideos()) { shortPlayVideo.setShortPlayId(shortPlayDTO.getId()); } shortPlayVideoService.saveBatch(shortPlayVideos); // 添加短剧类型 List shortPlayToTypes = new ArrayList<>(); for (Long typeId : shortPlayDTO.getTypeIds()) { TShortPlayToType shortPlayToType = new TShortPlayToType(); shortPlayToType.setTypeId(typeId); shortPlayToType.setShortPlayId(shortPlayDTO.getId()); shortPlayToTypes.add(shortPlayToType); } shortPlayToTypeService.saveBatch(shortPlayToTypes); return ApiResult.success(); } /** * 修改短剧管理 */ @ApiOperation(value = "修改短剧管理") @PostMapping(value = "/updateTShortPlay") @Transactional(rollbackFor = Exception.class) public ApiResult updateTShortPlay(@Validated @RequestBody TShortPlayDTO shortPlayDTO) { // 添加短剧 shortPlayService.updateById(shortPlayDTO); // 删除已有短视频 shortPlayVideoService.removeByShortPlayId(shortPlayDTO.getId()); // 添加短剧视频 List shortPlayVideos = shortPlayDTO.getShortPlayVideos(); for (TShortPlayVideo shortPlayVideo : shortPlayDTO.getShortPlayVideos()) { shortPlayVideo.setShortPlayId(shortPlayDTO.getId()); } shortPlayVideoService.saveBatch(shortPlayVideos); // 删除已有短剧类型 shortPlayToTypeService.remove(Wrappers.lambdaQuery(TShortPlayToType.class) .eq(TShortPlayToType::getShortPlayId,shortPlayDTO.getId())); // 添加短剧类型 List shortPlayToTypes = new ArrayList<>(); for (Long typeId : shortPlayDTO.getTypeIds()) { TShortPlayToType shortPlayToType = new TShortPlayToType(); shortPlayToType.setTypeId(typeId); shortPlayToType.setShortPlayId(shortPlayDTO.getId()); shortPlayToTypes.add(shortPlayToType); } shortPlayToTypeService.saveBatch(shortPlayToTypes); return ApiResult.success(); } /** * 删除短剧管理 */ @ApiOperation(value = "删除短剧管理") @DeleteMapping(value = "/deleteById") public ApiResult deleteById(@RequestParam Long id) { // 删除短剧 shortPlayVideoService.remove(Wrappers.lambdaQuery(TShortPlayVideo.class) .eq(TShortPlayVideo::getShortPlayId,id)); // 删除已有短剧类型 shortPlayToTypeService.remove(Wrappers.lambdaQuery(TShortPlayToType.class) .eq(TShortPlayToType::getShortPlayId,id)); return ApiResult.success(shortPlayService.removeById(id)); } /** * 查询短剧管理详情 */ @ApiOperation(value = "查询短剧管理详情") @GetMapping(value = "/getDetailById") public ApiResult getDetailById(@RequestParam Long id) { TShortPlay shortPlay = shortPlayService.getById(id); TShortPlayVO shortPlayVO = new TShortPlayVO(); BeanUtils.copyProperties(shortPlay,shortPlayVO); // 查询短剧 List shortPlayVideos = shortPlayVideoService.list(Wrappers.lambdaQuery(TShortPlayVideo.class) .eq(TShortPlayVideo::getShortPlayId, id)); shortPlayVO.setShortPlayVideos(shortPlayVideos); // 查询类型 List tShortPlayToTypes = shortPlayToTypeService.list(Wrappers.lambdaQuery(TShortPlayToType.class) .eq(TShortPlayToType::getShortPlayId,id)); List typeIds = tShortPlayToTypes.stream().map(TShortPlayToType::getTypeId).collect(Collectors.toList()); shortPlayVO.setTypeIds(typeIds); List tShortPlayTypes = shortPlayTypeService.list(Wrappers.lambdaQuery(TShortPlayType.class) .in(TShortPlayType::getId, typeIds)); shortPlayVO.setShortPlayTypes(tShortPlayTypes); return ApiResult.success(shortPlayVO); } /** * 短剧管理上下架 */ @ApiOperation(value = "短剧管理上下架") @GetMapping(value = "/upAndDown") public ApiResult upAndDown(@RequestParam Long id, @RequestParam Integer status) { return ApiResult.success(shortPlayService.upAndDown(id,status)); } }