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);
|
|
}
|
|
|
|
|
}
|