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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
package com.hollywood.applet.controller;
 
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hollywood.applet.dto.PerformanceJoinDto;
import com.hollywood.applet.dto.TrueOrFalse;
import com.hollywood.applet.query.TPerformerActivityQuery;
import com.hollywood.applet.query.TPerformerActivityUserQuery;
import com.hollywood.applet.query.TUserQuery;
import com.hollywood.applet.service.TPerformerActivityService;
import com.hollywood.applet.service.TPerformerActivityUserService;
import com.hollywood.applet.service.TUserService;
import com.hollywood.applet.utils.LoginInfoUtil;
import com.hollywood.common.basic.ApiResult;
import com.hollywood.common.basic.PageInfo;
import com.hollywood.common.exception.ServiceException;
import com.hollywood.common.model.TPerformerActivity;
import com.hollywood.common.model.TPerformerActivityUser;
 
import com.hollywood.common.model.TPopularActivityUser;
import com.hollywood.common.model.TUser;
import com.hollywood.common.redis.RedisAutoTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 演员活动 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2024-02-29
 */
@Api(tags = "演员活动")
@RestController
@RequestMapping("/tPerformerActivity")
public class TPerformerActivityController {
 
    private final TPerformerActivityService performerActivityService;
    private final TPerformerActivityUserService performerActivityUserService;
 
    @Autowired
    private LoginInfoUtil loginInfoUtil;
    @Autowired
    private RedisAutoTemplate redisAutoTemplate;
    @Autowired
    private TUserService userService;
 
 
    @Autowired
    public TPerformerActivityController(TPerformerActivityService performerActivityService, TPerformerActivityUserService performerActivityUserService) {
        this.performerActivityService = performerActivityService;
        this.performerActivityUserService = performerActivityUserService;
    }
 
    /**
     * 获取演员活动列表
     */
    @ApiOperation(value = "获取演员活动分页列表")
    @PostMapping(value = "/pageList")
    public ApiResult<PageInfo<TPerformerActivity>> pageList(@RequestBody TPerformerActivityQuery query) {
        Long userId = loginInfoUtil.getUserId();
        List<Long> ids = new ArrayList<>();
        if (query.getMine()!=null&&query.getMine()==1){
            List<TPerformerActivityUser> list = performerActivityUserService.list(Wrappers.lambdaQuery(TPerformerActivityUser.class)
                    .eq(TPerformerActivityUser::getUserId, userId).eq(TPerformerActivityUser::getIsPay,2));
 
            ids = list.stream()
                    .map(TPerformerActivityUser::getActivityId)
                    .collect(Collectors.toList());
            if (ids.isEmpty()){
                return ApiResult.success(new PageInfo<>());
            }
        }
 
        return ApiResult.success(performerActivityService.pageList(query,ids));
    }
    @ApiOperation(value = "演员活动-立即投票前获取可投票数")
    @GetMapping(value = "/vote-get/{acId}")
    public ApiResult voteGet(@PathVariable Long acId) {
        Long userId = loginInfoUtil.getUserId();
        TPerformerActivity byId = performerActivityService.getById(acId);
        if (byId.getVoteType()==1){
            String str = redisAutoTemplate.getStr(byId.getId() + ":" + userId + ":vote");
            if (str==null){
                redisAutoTemplate.setStr(byId.getId() + ":" + userId + ":vote", String.valueOf(byId.getVoteCount()));
                str= String.valueOf(byId.getVoteCount());
                return ApiResult.success(str);
            }else {
                return ApiResult.success(redisAutoTemplate.getStr(byId.getId() + ":" + userId + ":vote"));
            }
        }else{
            String str = redisAutoTemplate.getStr(byId.getId() + ":" + userId + ":vote");
            if (str==null){
                LocalTime currentTime = LocalTime.now();
                // 获取凌晨12点时间
                LocalTime midnight = LocalTime.of(0, 0);
                // 计算当前时间到凌晨12点的秒数差
                long secondsUntilMidnight = getSecondsUntilEndOfDay();
                redisAutoTemplate.setStr(byId.getId() + ":" + userId + ":vote", String.valueOf(byId.getVoteCount()),secondsUntilMidnight);
                str= String.valueOf(byId.getVoteCount());
                return ApiResult.success(str);
            }else {
                return ApiResult.success(redisAutoTemplate.getStr(byId.getId() + ":" + userId + ":vote"));
            }
        }
 
    }
 
 
    @ApiOperation(value = "演员推荐-立即投票前获取可投票数")
    @GetMapping(value = "/vote")
    public ApiResult vote() {
        Long userId = loginInfoUtil.getUserId();
            String str = redisAutoTemplate.getStr( userId + ":vote");
        if (str==null) {
            LocalTime currentTime = LocalTime.now();
            // 获取凌晨12点时间
            LocalTime midnight = LocalTime.of(0, 0);
            // 计算当前时间到凌晨12点的秒数差
            long secondsUntilMidnight = getSecondsUntilEndOfDay();
            redisAutoTemplate.setStr( userId + ":vote","10" , secondsUntilMidnight);
            str = String.valueOf(10);
        }
            return ApiResult.success(str);
    }
    public static long getSecondsUntilEndOfDay() {
        LocalDateTime currentTime = LocalDateTime.now();
        LocalDateTime endOfDay = LocalDateTime.of(currentTime.toLocalDate(), LocalTime.MAX);
 
        long remainingSeconds = currentTime.until(endOfDay, ChronoUnit.SECONDS);
 
        return remainingSeconds;
    }
 
    @ApiOperation(value = "演员推荐-投票操作")
    @GetMapping(value = "/vote-num")
    public ApiResult voteUser(Integer num,Long acId) {
        Long userId = loginInfoUtil.getUserId();
        TUser byId = userService.getById(userId);
        TrueOrFalse trueOrFalse = new TrueOrFalse();
        LocalDateTime currentTime = LocalDateTime.now();
        Date date = new Date();
        if (byId.getVipType()==3|| byId.getEndTime().isBefore(currentTime)){
           throw new ServiceException("当前活动仅限会员参与");
        }
 
 
 
//
//        Long userId = loginInfoUtil.getUserId();
//
//        TUser byId = userService.getById(acId);
 
        String str = redisAutoTemplate.getStr(userId + ":vote");
        Integer i = Integer.valueOf(str);
        int i1 = i - num;
        // 计算当前时间到凌晨12点的秒数差
        long secondsUntilMidnight = getSecondsUntilEndOfDay();
        redisAutoTemplate.setStr( userId + ":vote", String.valueOf(i1),secondsUntilMidnight);
        //改变演员的投票数量
        TUser byId1 = userService.getById(acId);
        Integer voteCount1 = byId1.getHot();
        if (voteCount1==null){
            voteCount1=1;
        }else {
            voteCount1 = voteCount1+num;
        }
        byId1.setHot(voteCount1);
        userService.updateById(byId1);
        return ApiResult.success();
    }
 
 
 
 
 
    @ApiOperation(value = "活动列表-投票操作")
    @GetMapping(value = "/vote-list")
    public ApiResult vote( Long peId, Integer num) {
        Long userId = loginInfoUtil.getUserId();
        TUser byId2 = userService.getById(userId);
        TrueOrFalse trueOrFalse = new TrueOrFalse();
        LocalDateTime currentTime = LocalDateTime.now();
        Date date = new Date();
        if (byId2.getVipType()==3|| byId2.getEndTime().isBefore(currentTime)){
            throw new ServiceException("当前活动仅限会员参与");
        }
 
 
 
 
 
 
 
 
//        Long userId = loginInfoUtil.getUserId();
        TPerformerActivityUser byId1 = performerActivityUserService.getById(peId);
 
        TPerformerActivity byId = performerActivityService.getById(byId1.getActivityId());
        redisAutoTemplate.addSet("performer:hot:"+byId.getId(), userId);
//        LocalDateTime currentTime = LocalDateTime.now();
        if (byId.getStatus()==2){
            throw new ServiceException("当前活动已下架");
        }
        if (byId.getEndTime().isBefore(currentTime)){
            throw new ServiceException("当前活动已结束");
        }
 
        long secondsUntilMidnight = getSecondsUntilEndOfDay();
 
        String str = redisAutoTemplate.getStr(byId.getId() + ":" + userId + ":vote");
        Integer i = Integer.valueOf(str);
        int i1 = i - num;
        if (i1<0){
            return ApiResult.failed("票数不足,请重试");
        }
        if (byId.getVoteType()==1) {
            redisAutoTemplate.setStr(byId.getId() + ":" + userId + ":vote", String.valueOf(i1));
        }else {
            redisAutoTemplate.setStr(byId.getId() + ":" + userId + ":vote", String.valueOf(i1),secondsUntilMidnight);
 
        }
        //改变活动投票数量
//        Integer voteCount = byId.getVoteCount();
//        if (voteCount==null){
//            voteCount=num;
//        }else {
//            voteCount = voteCount+num;
//        }
//        byId.setVoteCount(voteCount);
//        performerActivityService.updateById(byId);
        //改变演员的投票数量
        Integer voteCount1 = byId1.getGainVotesCount();
        if (voteCount1==null){
            voteCount1=num;
        }else {
            voteCount1 = voteCount1+num;
        }
        byId1.setGainVotesCount(voteCount1);
        performerActivityUserService.updateById(byId1);
        return ApiResult.success();
    }
 
 
 
 
    /**
     * 获取演员活动参与人员列表
     */
    @ApiOperation(value = "获取演员活动参与人员列表")
    @PostMapping(value = "/userJoin")
    public ApiResult<PageInfo<TPerformerActivityUser>> userPageList(@Validated @RequestBody TPerformerActivityUserQuery query) {
        return ApiResult.success(performerActivityUserService.userPageList(query));
    }
 
 
    /**
     * 查看演员活动详情
     */
    @ApiOperation(value = "查看演员活动详情")
    @GetMapping(value = "/getDetailById")
    public ApiResult<TPerformerActivity> getDetailById(@RequestParam Long id) {
        Long userId = loginInfoUtil.getUserId();
        TPerformerActivity byId = performerActivityService.getById(id);
        List<TPerformerActivityUser> list = performerActivityUserService.list(Wrappers.lambdaQuery(TPerformerActivityUser.class).eq(TPerformerActivityUser::getIsPay,2).eq(TPerformerActivityUser::getUserId, userId).eq(TPerformerActivityUser::getActivityId,byId.getId()));
        if (!list.isEmpty()){
            byId.setIsJoin(1);
        }
        List<TPerformerActivityUser> count = performerActivityUserService.list(Wrappers.lambdaQuery(TPerformerActivityUser.class).eq(TPerformerActivityUser::getActivityId,byId.getId()));
        byId.setHot(redisAutoTemplate.getSet("performer:hot:"+byId.getId()).size());
        return ApiResult.success(byId);
    }
    @ApiOperation(value = "查看演员详情")
    @GetMapping(value = "/getPerformById")
    public ApiResult<TPerformerActivityUser> getPerformById(@RequestParam Long id) {
        return ApiResult.success(performerActivityUserService.getById(id));
    }
 
    @ApiOperation(value = "参加演员活动")
    @PostMapping(value = "/join")
    public ApiResult join(@RequestBody PerformanceJoinDto performanceJoinDto) throws Exception {
 
        Long userId = loginInfoUtil.getUserId();
        TUser byId = userService.getById(userId);
        TrueOrFalse trueOrFalse = new TrueOrFalse();
        LocalDateTime currentTime = LocalDateTime.now();
        Date date = new Date();
        if (byId.getVipType() == 3 || byId.getEndTime().isBefore(currentTime)) {
            return ApiResult.failed("仅限会员报名");
        }
 
        TPerformerActivity byId1 = performerActivityService.getById(performanceJoinDto.getAcId());
 
        if (byId1.getStatus() == 2) {
            return ApiResult.failed("当前活动已下架");
        }
        if (byId1.getRegistrationDeadlineTime() != null && byId1.getRegistrationDeadlineTime().isBefore(currentTime)) {
            return ApiResult.failed("当前活动已到截至报名时间");
//                throw new ServiceException("当前活动已到截至报名时间");
        }
        if (byId1.getEndTime().isBefore(currentTime)) {
            return ApiResult.failed("当前活动已结束");
//                throw new ServiceException("当前活动已结束");
        }
 
 
        List<TPerformerActivityUser> list = performerActivityUserService.list(Wrappers.lambdaQuery(TPerformerActivityUser.class).eq(TPerformerActivityUser::getIsPay, 2).eq(TPerformerActivityUser::getUserId, userId).eq(TPerformerActivityUser::getActivityId, performanceJoinDto.getAcId()));
        if (!list.isEmpty()) {
            return ApiResult.failed("当前用户已报名");
        }
      return   performerActivityService.join(performanceJoinDto, userId);
 
 
}
 
    @ApiOperation(value = "获取演员推荐列表")
    @PostMapping(value = "/userPageList")
    public ApiResult<PageInfo<TUser>> userPageList(@RequestBody TUserQuery query) {
        return ApiResult.success(userService.userPageList(query));
    }
    @ApiOperation(value = "成为演员")
    @PostMapping(value = "/toBeAC")
    public ApiResult toBeAC(@RequestBody TUser user) {
        user.setId(loginInfoUtil.getUserId());
        user.setAuditStatus(1);
        userService.updateById(user);
        return ApiResult.success();
    }
 
    @ApiOperation(value = "编辑演员")
    @PostMapping(value = "/editAC")
    public ApiResult editAC(@RequestBody TUser user) {
        userService.updateById(user);
        return ApiResult.success();
    }
 
 
    @ApiOperation(value = "获取用户详情(演员管理详情,演员审核详情通用)")
    @GetMapping(value = "/getUserDetailById")
    public ApiResult<TUser> getUserDetailById(@RequestParam Long id) {
        TUser byId = userService.getById(id);
 
        return ApiResult.success(byId);
 
    }
 
 
 
 
}