diff --git a/luoo_user/src/main/java/com/luoo/user/Scheduler/DrawLotteryScheduler.java b/luoo_user/src/main/java/com/luoo/user/Scheduler/DrawLotteryScheduler.java index 638f154..1d73a05 100644 --- a/luoo_user/src/main/java/com/luoo/user/Scheduler/DrawLotteryScheduler.java +++ b/luoo_user/src/main/java/com/luoo/user/Scheduler/DrawLotteryScheduler.java @@ -73,21 +73,30 @@ public class DrawLotteryScheduler { scheduledFuture = taskScheduler.schedule(() -> { // 这里执行操作 log.info("抽奖{}", id); - drawLotteryService.auto(id, null); + try { + drawLotteryService.auto(id, null); + } catch (Exception e) { + e.printStackTrace(); + } + }, new Date(System.currentTimeMillis() + delay)); scheduledFutures.put(id, scheduledFuture); - log.info("scheduleDraw--------:{}",scheduledFutures); + log.info("scheduleDraw--------:{}", scheduledFutures); } else { // 处理时间已过的情况 // 立即抽奖 - drawLotteryService.auto(id, null); + try { + drawLotteryService.auto(id, null); + } catch (Exception e) { + e.printStackTrace(); + } } } // 取消任务的方法 public void cancelDraw(String id) { - log.info("cancelDraw--------:{}",scheduledFutures); + log.info("cancelDraw--------:{}", scheduledFutures); // 从映射中获取与 ID 关联的 ScheduledFuture 对象 ScheduledFuture scheduledFuture = scheduledFutures.get(id); // 检查 ScheduledFuture 是否存在 diff --git a/luoo_user/src/main/java/com/luoo/user/controller/PointController.java b/luoo_user/src/main/java/com/luoo/user/controller/PointController.java index 18a5f6d..5da6401 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/PointController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/PointController.java @@ -3,11 +3,9 @@ package com.luoo.user.controller; import annotation.GlobalInterceptor; import api.PageResult; import api.Result; -import com.luoo.user.dto.point.LotteryDto; -import com.luoo.user.dto.point.LotterySearchDto; -import com.luoo.user.dto.point.TaskPointDto; -import com.luoo.user.dto.point.UserPointLogSearchDto; +import com.luoo.user.dto.point.*; import com.luoo.user.pojo.Lottery; +import com.luoo.user.pojo.LotteryRegion; import com.luoo.user.pojo.TaskPoint; import com.luoo.user.pojo.UserPointLog; import com.luoo.user.service.DrawLotteryService; @@ -26,6 +24,7 @@ import javax.validation.constraints.NotNull; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -219,17 +218,19 @@ public class PointController { @GlobalInterceptor(checkAdminLogin = true) @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), - @ApiImplicitParam(name = "lottery", value = "抽奖信息", required = true, dataType = "Lottery", paramType = "body") + @ApiImplicitParam(name = "lotteryAddDto", value = "抽奖信息", required = true, dataType = "LotteryAddDto", paramType = "body") }) public Result addLottery(@RequestHeader("Authorization") String token, - @RequestBody Lottery lottery) { + @Validated @RequestBody LotteryAddDto lotteryAddDto) { + Lottery lottery = new Lottery(); + BeanUtils.copyProperties(lotteryAddDto, lottery); + lotteryService.add(lottery, token); return Result.success(); } - @ApiOperation(value = "3.2.抽奖列表页(PC)", notes = "仅限admin权限用户调用") + @ApiOperation(value = "3.2.抽奖列表页(PC/APP)", notes = "admin/app") @PostMapping("/lottery/list/{page}/{size}") - @GlobalInterceptor(checkAdminLogin = true) public Result> lotteryList( @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "查询对象") @RequestBody LotterySearchDto lotterySearchDto, @@ -238,35 +239,48 @@ public class PointController { return Result.success(lotteryService.lotteryPageResult(page, size, lotterySearchDto)); } - @ApiOperation(value = "3.3.编辑抽奖(PC)", notes = "仅限admin权限用户调用") + @ApiOperation(value = "3.3.根据抽奖id获取地区列表(APP)", notes = "仅限app权限用户调用") + @PostMapping("/lottery/region/list") + @GlobalInterceptor(checkAppUserLogin = true) + @ApiImplicitParams({ + @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), + @ApiImplicitParam(name = "lotteryId", value = "抽奖id", required = true, dataType = "String", paramType = "query") + }) + public Result> getLotteryRegionList( + @RequestHeader("Authorization") String token, + @RequestParam String lotteryId) { + return Result.success(lotteryService.getLotteryRegionList(lotteryId)); + } + + @ApiOperation(value = "3.4.编辑抽奖(PC)", notes = "仅限admin权限用户调用") @PostMapping("/lottery/edit") @GlobalInterceptor(checkAdminLogin = true) @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), - @ApiImplicitParam(name = "lottery", value = "抽奖信息", required = true, dataType = "Lottery", paramType = "body") + @ApiImplicitParam(name = "lotteryUpdateDto", value = "抽奖信息", required = true, dataType = "LotteryUpdateDto", paramType = "body") }) public Result editLottery(@RequestHeader("Authorization") String token, - @RequestBody LotteryDto lotteryDto) { + @Validated @RequestBody LotteryUpdateDto lotteryUpdateDto) { Lottery lottery = new Lottery(); - BeanUtils.copyProperties(lotteryDto, lottery); + BeanUtils.copyProperties(lotteryUpdateDto, lottery); lotteryService.edit(lottery, token); return Result.success(); } - @ApiOperation(value = "3.4.发布抽奖(PC)", notes = "仅限admin权限用户调用") + @ApiOperation(value = "3.5.发布抽奖(PC)", notes = "仅限admin权限用户调用") @PostMapping("/lottery/publish") @GlobalInterceptor(checkAdminLogin = true) @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), - @ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "body") + @ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query") }) public Result publishLottery(@RequestHeader("Authorization") String token, - @RequestBody String id) { + @RequestParam String id) { lotteryService.publish(id, token); return Result.success(); } - @ApiOperation(value = "3.5.停止抽奖(PC)", notes = "仅限admin权限用户调用") + @ApiOperation(value = "3.6.停止抽奖(PC)", notes = "仅限admin权限用户调用") @PostMapping("/lottery/stop") @GlobalInterceptor(checkAdminLogin = true) @ApiImplicitParams({ @@ -280,19 +294,19 @@ public class PointController { return Result.success(); } - @ApiOperation(value = "3.6.参与抽奖(APP)") + @ApiOperation(value = "3.7.参与抽奖(APP)") @PostMapping("/lottery/participate") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), @ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query"), - @ApiImplicitParam(name = "regionId", value = "区域id", required = true, dataType = "String", paramType = "query") + @ApiImplicitParam(name = "regionId", value = "区域id", required = true, dataType = "Integer", paramType = "query") }) public Result participate(@RequestHeader("Authorization") String token, @NotNull String id, @NotNull Integer regionId) { lotteryService.participate(id, token, regionId); return Result.success(); } - @ApiOperation(value = "3.7.自动抽奖结果(PC)", notes = "用这个方法主动触发自动抽奖结果") + @ApiOperation(value = "3.8.自动抽奖结果(PC)", notes = "用这个方法主动触发自动抽奖结果") @PostMapping("/lottery/auto") @GlobalInterceptor(checkAdminLogin = true) @ApiImplicitParams({ diff --git a/luoo_user/src/main/java/com/luoo/user/dao/LotteryRegionDao.java b/luoo_user/src/main/java/com/luoo/user/dao/LotteryRegionDao.java index 597426c..2e0b992 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/LotteryRegionDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/LotteryRegionDao.java @@ -11,7 +11,7 @@ public interface LotteryRegionDao extends JpaRepository, JpaSpecificationExecutor { @Modifying - @Query(value = "DELETE FROM tb_lottery_region js WHERE js.lottery_id = :lotteryId", nativeQuery = true) + @Query(value = "DELETE FROM tb_lottery_region WHERE lottery_id = ?", nativeQuery = true) public void deleteByLotteryId(String lotteryId); public LotteryRegion findByLotteryIdAndRegionId(String lotteryId, Integer regionId); diff --git a/luoo_user/src/main/java/com/luoo/user/dto/point/LotteryAddDto.java b/luoo_user/src/main/java/com/luoo/user/dto/point/LotteryAddDto.java new file mode 100644 index 0000000..077c74e --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/point/LotteryAddDto.java @@ -0,0 +1,85 @@ +package com.luoo.user.dto.point; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.luoo.user.pojo.LotteryRegion; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.Value; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.Transient; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.List; + +/** + * DTO for {@link com.luoo.user.pojo.Lottery} + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class LotteryAddDto implements Serializable { + + @ApiModelProperty(value = "标题") + @NotBlank + private String title; + + @ApiModelProperty(value = "抽奖类型 1-门票抽奖 2-实物抽奖") + @NotNull + private Integer type; + + @ApiModelProperty(value = "奖品总数量") + private Integer num; + + @ApiModelProperty(value = "可参加人员 1-全部 2-全部会员 3-永久会员 4-贡献者") + @NotNull + private Integer participant; + + @ApiModelProperty(value = "积分") + @NotNull + private Integer point; + + @ApiModelProperty(value = "地区编码") + private String regionCode; + + @ApiModelProperty(value = "地区名称") + private String regionName; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "报名开始时间") + @NotNull + private LocalDateTime applyStartTime; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "报名结束时间") + @NotNull + private LocalDateTime applyEndTime; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "抽奖时间") + @NotNull + private LocalDateTime drawTime; + + @ApiModelProperty(value = "抽奖方式 1-自动抽奖 2-手动抽奖") + @NotNull + private Integer way; + + @ApiModelProperty(value = "抽奖封面url") + @NotBlank + private String image; + + @ApiModelProperty(value = "抽奖描述") + @NotBlank + private String description; + + @ApiModelProperty(value = "抽奖地区列表") + private List lotteryRegionList; +} \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/dto/point/LotteryDto.java b/luoo_user/src/main/java/com/luoo/user/dto/point/LotteryUpdateDto.java similarity index 88% rename from luoo_user/src/main/java/com/luoo/user/dto/point/LotteryDto.java rename to luoo_user/src/main/java/com/luoo/user/dto/point/LotteryUpdateDto.java index 1121f40..9432dd8 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/point/LotteryDto.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/point/LotteryUpdateDto.java @@ -9,6 +9,8 @@ import lombok.NoArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; import javax.persistence.Transient; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import java.io.Serializable; import java.time.LocalDateTime; import java.util.List; @@ -19,27 +21,33 @@ import java.util.List; @Data @AllArgsConstructor @NoArgsConstructor -public class LotteryDto implements Serializable { +public class LotteryUpdateDto implements Serializable { @ApiModelProperty(value = "主键") + @NotBlank private String id; @ApiModelProperty(value = "抽奖编码") + @NotBlank private String code; @ApiModelProperty(value = "标题") + @NotBlank private String title; @ApiModelProperty(value = "抽奖类型 1-门票抽奖 2-实物抽奖") + @NotNull private Integer type; @ApiModelProperty(value = "奖品总数量") private Integer num; @ApiModelProperty(value = "可参加人员 1-全部 2-全部会员 3-永久会员 4-贡献者") + @NotNull private Integer participant; @ApiModelProperty(value = "积分") + @NotNull private Integer point; @ApiModelProperty(value = "地区编码") @@ -51,34 +59,40 @@ public class LotteryDto implements Serializable { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "报名开始时间") + @NotNull private LocalDateTime applyStartTime; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "报名结束时间") + @NotNull private LocalDateTime applyEndTime; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "抽奖时间") + @NotNull private LocalDateTime drawTime; @ApiModelProperty(value = "抽奖方式 1-自动抽奖 2-手动抽奖") + @NotNull private Integer way; @ApiModelProperty(value = "抽奖封面url") + @NotBlank private String image; @ApiModelProperty(value = "抽奖描述") + @NotBlank private String description; @ApiModelProperty(value = "抽奖状态 0-编辑中 1-报名中 2-已抽奖 3-已停止") + @NotNull private Integer status; @ApiModelProperty(value = "停止原因") private String stopReason; - @Transient @ApiModelProperty(value = "抽奖地区列表") private List lotteryRegionList; } \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java index 6807398..ec78785 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java @@ -75,9 +75,9 @@ public class UserRespDTO implements Serializable { private Integer enablePush; /** - * 会员状态 0-未开通 1-生效中 2-已过期 + * 会员状态 0-未开通 1-生效中 2-已过期 3-永久会员 */ - @ApiModelProperty(value = "会员状态 0-未开通 1-生效中 2-已过期") + @ApiModelProperty(value = "会员状态 0-未开通 1-生效中 2-已过期 3-永久会员") private Integer vipStatus; /** diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/LotteryRegion.java b/luoo_user/src/main/java/com/luoo/user/pojo/LotteryRegion.java index 84694e0..22dec81 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/LotteryRegion.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/LotteryRegion.java @@ -3,11 +3,7 @@ package com.luoo.user.pojo; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import java.time.LocalDateTime; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.Id; -import javax.persistence.Table; +import javax.persistence.*; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; @@ -77,4 +73,8 @@ public class LotteryRegion { @ApiModelProperty(value = "更新人") private String updateUser; + @Transient + @ApiModelProperty(value = "区域") + private Region region; + } \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/Region.java b/luoo_user/src/main/java/com/luoo/user/pojo/Region.java index 61b066c..30a5046 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/Region.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/Region.java @@ -20,6 +20,8 @@ import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import java.io.Serializable; + @Data @NoArgsConstructor @AllArgsConstructor @@ -30,7 +32,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; @DynamicUpdate @Table(name = "tb_region") @EntityListeners(AuditingEntityListener.class) -public class Region { +public class Region implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java index c781e64..7b6ced6 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java @@ -191,7 +191,7 @@ public class UserInfo implements Serializable { private Integer type; /** - * 会员状态 0-未开通 1-生效中 2-已过期 + * 会员状态 0-未开通 1-生效中 2-已过期 3-永久会员 */ private Integer vipStatus; diff --git a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java index 71acfa9..de45b5b 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java @@ -110,7 +110,7 @@ public class LotteryService { // 门票抽奖,城市必填 List lotteryRegionList = lottery.getLotteryRegionList(); - if (lotteryRegionList.isEmpty()) { + if (lotteryRegionList == null || lotteryRegionList.isEmpty()) { throw new BizException(ErrorConstants.TICKET_CITY_IS_REQUIRED); } @@ -121,8 +121,8 @@ public class LotteryService { regionName.append(regionById.getName()).append(","); num += lotteryRegion.getNum(); - lotteryRegion.setId(id); - lotteryRegion.setLotteryId(lottery.getId()); + lotteryRegion.setId(String.valueOf(idWorker.nextId())); + lotteryRegion.setLotteryId(id); lotteryRegion.setCreateUser(userLoginDto.getUserId()); lotteryRegion.setUpdateUser(userLoginDto.getUserId()); @@ -161,6 +161,10 @@ public class LotteryService { UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + if(lottery.getStatus() != null && !Objects.equals(lottery.getStatus(), PointEnums.LOTTERY_STATUS_EDITING.getCode())) { + throw new BizException(ErrorConstants.CAN_NOT_EDIT); + } + String id = lottery.getId(); StringBuilder regionCode = new StringBuilder(); @@ -170,7 +174,7 @@ public class LotteryService { // 门票抽奖,城市必填 List lotteryRegionList = lottery.getLotteryRegionList(); - if (lotteryRegionList.isEmpty()) { + if (lotteryRegionList == null || lotteryRegionList.isEmpty()) { throw new BizException(ErrorConstants.TICKET_CITY_IS_REQUIRED); } @@ -256,6 +260,7 @@ public class LotteryService { UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); Lottery lottery = lotteryDao.findById(id).orElse(null); + lottery.setStatus(PointEnums.LOTTERY_STATUS_STOP.getCode()); lottery.setUpdateUser(userLoginDto.getUserId()); lottery.setUpdateUserName(userLoginDto.getNickName()); lottery.setStopReason(stopReason); @@ -406,4 +411,20 @@ public class LotteryService { }; } + /** + * 根据抽奖id获取地区列表 + * + * @param lotteryId 抽奖id + * @return 地区列表 + */ + public List getLotteryRegionList(String lotteryId) { + List lotteryRegionList = lotteryRegionDao.findByLotteryId(lotteryId); + lotteryRegionList.forEach(lotteryRegion -> { + Region region = regionService.getRegionById(lotteryRegion.getRegionId()); + lotteryRegion.setRegion(region); + }); + return lotteryRegionList; + } + + } diff --git a/luoo_user/src/main/resources/sql/20240719.sql b/luoo_user/src/main/resources/sql/20240719.sql index 6dbaa4b..fe691d0 100644 --- a/luoo_user/src/main/resources/sql/20240719.sql +++ b/luoo_user/src/main/resources/sql/20240719.sql @@ -36,7 +36,7 @@ create table tb_user_point_log alter table tb_user_info - add vip_status tinyint default 0 not null comment '会员状态 0-未开通 1-生效中 2-已过期'; + add vip_status tinyint default 0 not null comment '会员状态 0-未开通 1-生效中 2-已过期 3-永久会员'; alter table tb_user_info add vip_expire_time date null comment '会员到期时间'; diff --git a/luoo_user/src/main/resources/sql/20240802.sql b/luoo_user/src/main/resources/sql/20240802.sql index cb8d84e..df8c2cc 100644 --- a/luoo_user/src/main/resources/sql/20240802.sql +++ b/luoo_user/src/main/resources/sql/20240802.sql @@ -7,3 +7,11 @@ alter table tb_user_info alter table tb_user_info add invitation_user_id varchar(20) null comment '邀请人'; +create index tb_user_point_log_task_point_id_index + on tb_user_point_log (task_point_id); + +create index tb_user_point_log_user_id_index + on tb_user_point_log (user_id); + + +