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
174
175
176
177
178
179
180
181
182
183
184
185
186
package com.hollywood.applet.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hollywood.applet.dto.AdverDto;
import com.hollywood.applet.dto.ScriptPayDto;
import com.hollywood.applet.dto.ShortPayDto;
import com.hollywood.applet.dto.TShortPlayDTO;
import com.hollywood.applet.query.TShortPlayQuery;
import com.hollywood.applet.service.*;
import com.hollywood.applet.utils.LoginInfoUtil;
import com.hollywood.applet.vo.TShortPlayVO;
import com.hollywood.common.basic.ApiResult;
import com.hollywood.common.basic.PageInfo;
import com.hollywood.common.model.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
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.Random;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 短剧管理 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2024-02-29
 */
@RestController
@RequestMapping("/tShortPlay")
@Api(tags = "短剧")
public class TShortPlayController {
    @Autowired
    private TShortPlayService shortPlayService;
    @Autowired
    private TAdvertisementService tAdvertisementService;
    @Autowired
    private LoginInfoUtil loginInfoUtil;
    @Autowired
    private TOrderService orderService;
    @Autowired
    private TAdvertisementConfigService advertisementConfigService;
    @Autowired
    private TShortPlayVideoService videoService;
 
    private final TShortPlayVideoService shortPlayVideoService;
    private final TShortPlayToTypeService shortPlayToTypeService;
    private final TShortPlayTypeService shortPlayTypeService;
 
 
    @Autowired
    public TShortPlayController( TShortPlayVideoService shortPlayVideoService, TShortPlayToTypeService shortPlayToTypeService, TShortPlayTypeService shortPlayTypeService) {
        this.shortPlayVideoService = shortPlayVideoService;
        this.shortPlayToTypeService = shortPlayToTypeService;
        this.shortPlayTypeService = shortPlayTypeService;
    }
 
 
    @ApiOperation(value = "首页获取短剧排名")
    @GetMapping("/get-home")
    public ApiResult<List<TShortPlayVO>> getHome()
    {
        List<TShortPlayVO> list = shortPlayService.getHotTwo(new QueryWrapper<TShortPlay>().eq("status", 1).orderByDesc("playNum").last("limit 4"));
        return ApiResult.success(list);
    }
 
 
    /**
     * 获取短剧管理分页列表
     */
    @ApiOperation(value = "获取短剧管理分页列表")
    @PostMapping(value = "/pageList")
    public ApiResult<PageInfo<TShortPlayVO>> pageList(@RequestBody TShortPlayQuery query) {
        Long userId = loginInfoUtil.getUserId();
        List<Long> ids = new ArrayList<>();
        if (query.getMine()!=null&&query.getMine()==1){
            List<TOrder> list = orderService.list(Wrappers.lambdaQuery(TOrder.class).eq(TOrder::getProductType, 2)
                    .eq(TOrder::getUserId, userId)
                    .eq(TOrder::getIsPay, 1));
 
            ids = list.stream()
                    .map(TOrder::getProductId)
                    .collect(Collectors.toList());
            if (ids.size()==0){
                return ApiResult.success(new PageInfo<>());
            }
        }
        return ApiResult.success(shortPlayService.pageList(query,ids));
    }
 
    @ApiOperation(value = "播放接口")
    @PostMapping(value = "/playNum/{id}")
    public ApiResult playNum(@PathVariable Long id) {
        TShortPlay byId1 = shortPlayService.getById(id);
        byId1.setPlayNum(byId1.getPlayNum()==null ? 0: byId1.getPlayNum()+1);
        shortPlayService.updateById(byId1);
        return ApiResult.success();
    }
 
    @ApiOperation(value = "播放前播放广告")
    @PostMapping(value = "/adver")
    public ApiResult<AdverDto> adver() {
        List<TAdvertisement> list = tAdvertisementService.list(Wrappers.lambdaQuery(TAdvertisement.class).eq(TAdvertisement::getStatus, 1));
        if (list.isEmpty()){
            ApiResult.success();
        }
        Random random = new Random();
        int listSize = list.size();
        int randomIndex = random.nextInt(listSize);
        TAdvertisement randomElement = list.get(randomIndex);
        AdverDto adverDto = new AdverDto();
        adverDto.setTAdvertisement(randomElement);
        if (advertisementConfigService.getOne(null).getAdvertisementConfig()!=null){
            adverDto.setSeconds(advertisementConfigService.getOne(null).getAdvertisementConfig());
        }
        return ApiResult.success(adverDto);
 
    }
 
 
 
    @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).orderByAsc(TShortPlayVideo::getSortBy));
        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);
 
 
        StringBuilder sb = new StringBuilder();
        for (TShortPlayType type : tShortPlayTypes) {
            sb.append(type.getTypeName()).append(" | ");
        }
 
        // 移除末尾多余的分隔符和空格
        if (sb.length() > 0) {
            sb.setLength(sb.length() - 3);
        }
 
        String result = sb.toString();
        shortPlayVO.setShortPlayTypesNames(result);
        return ApiResult.success(shortPlayVO);
    }
 
    @ApiOperation(value = "购买短剧操作")
    @PostMapping(value = "/pay")
    public ApiResult pay(@RequestBody ShortPayDto shortPayDto) throws Exception {
        try {
            Long userId = loginInfoUtil.getUserId();
           return    shortPlayService.pay(shortPayDto,userId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ApiResult.success();
    }
 
 
 
 
 
 
}