luodangjia
2024-12-10 ee7ce5d1cbf80bee0a15c1e5bc5eaa30858d812b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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;
 
/**
 * <p>
 * 短剧管理 前端控制器
 * </p>
 *
 * @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<PageInfo<TShortPlayVO>> pageList(@RequestBody TShortPlayQuery query) {
        return ApiResult.success(shortPlayService.pageList(query));
    }
 
    /**
     * 新增短剧管理
     */
    @ApiOperation(value = "新增短剧管理")
    @PostMapping(value = "/addTShortPlay")
    @Transactional(rollbackFor = Exception.class)
    public ApiResult<String> addTShortPlay(@Validated @RequestBody TShortPlayDTO shortPlayDTO) {
        // 添加短剧
        shortPlayService.save(shortPlayDTO);
        // 添加短剧视频
        List<TShortPlayVideo> shortPlayVideos = shortPlayDTO.getShortPlayVideos();
        for (TShortPlayVideo shortPlayVideo : shortPlayDTO.getShortPlayVideos()) {
            shortPlayVideo.setShortPlayId(shortPlayDTO.getId());
        }
        shortPlayVideoService.saveBatch(shortPlayVideos);
        // 添加短剧类型
        List<TShortPlayToType> 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<String> updateTShortPlay(@Validated @RequestBody TShortPlayDTO shortPlayDTO) {
        // 添加短剧
        shortPlayService.updateById(shortPlayDTO);
        // 删除已有短视频
        shortPlayVideoService.removeByShortPlayId(shortPlayDTO.getId());
        // 添加短剧视频
        List<TShortPlayVideo> 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<TShortPlayToType> 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<Boolean> 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<TShortPlayVO> getDetailById(@RequestParam Long id) {
        TShortPlay shortPlay = shortPlayService.getById(id);
        TShortPlayVO shortPlayVO = new TShortPlayVO();
        BeanUtils.copyProperties(shortPlay,shortPlayVO);
        // 查询短剧
        List<TShortPlayVideo> shortPlayVideos = shortPlayVideoService.list(Wrappers.lambdaQuery(TShortPlayVideo.class)
                .eq(TShortPlayVideo::getShortPlayId, id));
        shortPlayVO.setShortPlayVideos(shortPlayVideos);
        // 查询类型
        List<TShortPlayToType> tShortPlayToTypes = shortPlayToTypeService.list(Wrappers.lambdaQuery(TShortPlayToType.class)
                .eq(TShortPlayToType::getShortPlayId,id));
        List<Long> typeIds = tShortPlayToTypes.stream().map(TShortPlayToType::getTypeId).collect(Collectors.toList());
        shortPlayVO.setTypeIds(typeIds);
        List<TShortPlayType> 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));
    }
 
}