diff --git a/luoo_common/src/main/java/constants/ErrorConstants.java b/luoo_common/src/main/java/constants/ErrorConstants.java index bf967f1..fdac576 100644 --- a/luoo_common/src/main/java/constants/ErrorConstants.java +++ b/luoo_common/src/main/java/constants/ErrorConstants.java @@ -9,49 +9,68 @@ package constants; * @Describe: 报错信息,方便国际化 */ public class ErrorConstants { - // 专辑部分 - public final static String USER_IS_NOT_ARTIST = "只有音乐人可以新建专辑"; - public final static String THE_REAL_NAME_AUTHENTICATION_IS_NOT_PASSED = "未通过实名认证"; + // 专辑部分 + public final static String USER_IS_NOT_ARTIST = "只有音乐人可以新建专辑"; - public final static String MUST_APPLY_FOR_REVIEW_IN_THE_NEW_STATE = "必须在新建状态下申请审核"; + public final static String THE_REAL_NAME_AUTHENTICATION_IS_NOT_PASSED = "未通过实名认证"; - public final static String MUST_OPERATE_IN_PERSON = "必须本人操作"; + public final static String MUST_APPLY_FOR_REVIEW_IN_THE_NEW_STATE = "必须在新建状态下申请审核"; - public final static String USER_VERIFICATION_FAILURE = "用户校验失败,请重新登录"; + public final static String MUST_OPERATE_IN_PERSON = "必须本人操作"; - public final static String THE_SONG_DOES_NOT_EXIST = "该专辑不存在此歌曲"; + public final static String USER_VERIFICATION_FAILURE = "用户校验失败,请重新登录"; - public final static String ALBUM_DOES_NOT_EXIST = "专辑不存在,请刷新后重试"; + public final static String THE_SONG_DOES_NOT_EXIST = "该专辑不存在此歌曲"; - public final static String CAUSE_OF_FORCE_MAJEURE = "专辑因不可抗力原因无法显示"; + public final static String ALBUM_DOES_NOT_EXIST = "专辑不存在,请刷新后重试"; - public final static String PRICE_CAN_NOT_BE_EMPTY = "定价不能为空"; + public final static String CAUSE_OF_FORCE_MAJEURE = "专辑因不可抗力原因无法显示"; - public final static String PRICING_MUST_BE_GREATER_THAN_0 = "定价必须大于0"; + public final static String PRICE_CAN_NOT_BE_EMPTY = "定价不能为空"; - public final static String ALBUM_SONG_LIST_IS_EMPTY = "专辑歌曲为空"; + public final static String PRICING_MUST_BE_GREATER_THAN_0 = "定价必须大于0"; - public final static String STATE_ERROR = "状态错误"; + public final static String ALBUM_SONG_LIST_IS_EMPTY = "专辑歌曲为空"; - // 用户部分 - public final static String REAL_NAME_APPROVE_IS_EXISTS = "该用户实名认证已存在"; + public final static String STATE_ERROR = "状态错误"; - public final static String REAL_NAME_IS_CHECKED = "该用户实名认证已审核完成"; + // 用户部分 + public final static String REAL_NAME_APPROVE_IS_EXISTS = "该用户实名认证已存在"; - public final static String REAL_NAME_ERROR = "实名认证错误"; + public final static String REAL_NAME_IS_CHECKED = "该用户实名认证已审核完成"; - public final static String REASONS_FOR_REFUSAL_MUST_BE_GIVEN = "必须填写拒绝理由"; + public final static String REAL_NAME_ERROR = "实名认证错误"; - public final static String THE_BANK_CARD_HAS_BEEN_BOUND = "该银行卡已绑定"; + public final static String REASONS_FOR_REFUSAL_MUST_BE_GIVEN = "必须填写拒绝理由"; - public final static String NO_BANK_CARD = "没有绑定银行卡"; + public final static String THE_BANK_CARD_HAS_BEEN_BOUND = "该银行卡已绑定"; - public final static String AMOUNT_MUST_BE_GREATER_THAN_0 = "金额必须大于0"; + public final static String NO_BANK_CARD = "没有绑定银行卡"; - public final static String USER_ALREADY_EXISTS_ARTIST = "用户已发起过音乐人审核"; + public final static String AMOUNT_MUST_BE_GREATER_THAN_0 = "金额必须大于0"; - public final static String USER_STATUS_ERROR = "用户状态错误"; + public final static String USER_ALREADY_EXISTS_ARTIST = "用户已发起过音乐人审核"; + + public final static String USER_STATUS_ERROR = "用户状态错误"; + + public final static String USER_NAME_ALREADY_EXISTS = "用户名已存在"; + + // 抽奖部分 + public static final String CAN_NOT_EDIT = "不允许修改"; + + public static final String NOT_IN_THE_SIGN_UP_PERIOD = "不是报名中,不允许参与"; + + public static final String NOT_MEMBER = "非会员不能参与"; + + public static final String NOT_PERMANENT_MEMBER = "非永久会员不能参与"; + + public static final String NOT_CONTRIBUTOR = "非贡献者不能参与"; + + public static final String NOT_ARTIST = "非音乐人不能参与"; + + public static final String ALREADY_PARTICIPATED = "已参与抽奖"; + + public static final String NOT_END_OF_SIGN_UP = "报名未结束,不允许抽奖"; - public final static String USER_NAME_ALREADY_EXISTS = "用户名已存在"; } diff --git a/luoo_common/src/main/java/enums/PointEnums.java b/luoo_common/src/main/java/enums/PointEnums.java index f0722ae..5a11378 100644 --- a/luoo_common/src/main/java/enums/PointEnums.java +++ b/luoo_common/src/main/java/enums/PointEnums.java @@ -14,6 +14,26 @@ public enum PointEnums { TASK_POINT_TYPE_ADD(1, "增加"), TASK_POINT_TYPE_REDUCE(2, "减少"), + LOTTERY_ALL(1, "全部"), + LOTTERY_ALL_MEMBER(2, "全部会员"), + LOTTERY_LIFE_MEMBER(3, "永久会员"), + LOTTERY_CONTRIBUTORS(4, "贡献者"), + LOTTERY_ARTIST(5, "音乐人"), + + LOTTERY_STATUS_EDITING(0, "编辑中"), + LOTTERY_STATUS_SIGN(1, "报名中"), + LOTTERY_STATUS_LOTTERY(2, "已抽奖"), + LOTTERY_STATUS_STOP(3, "已停止"), + + LOTTERY_WAY_AUTO(1, "自动抽奖"), + LOTTERY_WAY_MANUAL(2, "手动抽奖"), + + LOTTERY_RESULT_WIN(1, "中奖"), + LOTTERY_RESULT_LOSE(2, "未中奖"), + + MEMBERSHIP_LIFE(1, "永久会员"), + MEMBERSHIP_NOT_LIFE(2, "非永久会员"), + ; private final Integer code; private final String description; diff --git a/luoo_common/src/main/java/enums/UserVipStatusEnum.java b/luoo_common/src/main/java/enums/UserVipStatusEnum.java index d24ee3d..496b5aa 100644 --- a/luoo_common/src/main/java/enums/UserVipStatusEnum.java +++ b/luoo_common/src/main/java/enums/UserVipStatusEnum.java @@ -16,6 +16,7 @@ public enum UserVipStatusEnum { INITIAL(0, "未开通"), ACTIVE(1, "生效中"), EXPIRED(2, "已过期"), + LIFE(3, "永久会员") ; diff --git a/luoo_common/src/main/java/util/RedisLockUtil.java b/luoo_common/src/main/java/util/RedisLockUtil.java index ab144d4..85cf2f7 100644 --- a/luoo_common/src/main/java/util/RedisLockUtil.java +++ b/luoo_common/src/main/java/util/RedisLockUtil.java @@ -28,6 +28,13 @@ public class RedisLockUtil { private static final String KEY_PREFIX = "serial_number:"; private static final String DATE_FORMAT = "yyMMdd"; + private static final String ALL_YEAR_DATE_FORMAT = "yyyyMMdd"; + private static final String LOTTERY_KEY_PREFIX = "lottery"; + + /** + * 音乐人生成编号 + * @return + */ public String generateSerialNumber() { String key = KEY_PREFIX + getCurrentDate(); Long increment = redisTemplate.opsForValue().increment(key, 1); @@ -37,6 +44,24 @@ public class RedisLockUtil { return getCurrentDate() + String.format("%04d", increment); } + /** + * 生成抽奖编号 + * + * @return + */ + public String lotteryGenerateSerialNumber() { + String key = LOTTERY_KEY_PREFIX + getCurrentDate(); + Long increment = redisTemplate.opsForValue().increment(key, 1); + if (increment == 1) { + redisTemplate.expire(key, getSecondsUntilEndOfDay(), TimeUnit.SECONDS); + } + return "CJ" + getAllYearDateFormat() + String.format("%03d", increment); + } + + private String getAllYearDateFormat() { + SimpleDateFormat sdf = new SimpleDateFormat(ALL_YEAR_DATE_FORMAT); + return sdf.format(new Date()); + } private String getCurrentDate() { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); return sdf.format(new Date()); diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MembershipController.java b/luoo_user/src/main/java/com/luoo/user/controller/MembershipController.java index 396f9c4..d2006d5 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MembershipController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MembershipController.java @@ -8,7 +8,9 @@ import com.luoo.user.pojo.MembershipCode; import com.luoo.user.service.MembershipCodeService; import controller.BaseController; import io.swagger.annotations.*; + import java.util.List; + import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -29,60 +31,64 @@ import javax.validation.constraints.NotNull; @Api(tags = "会员模块") public class MembershipController extends BaseController { - @Autowired - private MembershipCodeService membershipCodeService; + @Autowired + private MembershipCodeService membershipCodeService; - @ApiOperation(value = "1.生成会员码", notes = "仅限admin权限用户调用") - @GetMapping("/code/generate") - @GlobalInterceptor(checkAdminLogin = true) - @ApiImplicitParams(value = { - @ApiImplicitParam(name = "duration", value = "会员时长(天)", required = true, dataType = "Integer", paramType = "query") - }) - public Result generateMembershipCode( - @RequestHeader(value = "Authorization", required = true) String authorization, - @NotNull Integer duration) { - return Result.success(membershipCodeService.generateMembershipCode(authorization, duration)); - } + @ApiOperation(value = "1.生成会员码", notes = "仅限admin权限用户调用") + @GetMapping("/code/generate") + @GlobalInterceptor(checkAdminLogin = true) + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "duration", value = "会员时长(天)", required = true, dataType = "Integer", paramType = "query"), + @ApiImplicitParam(name = "life", value = "是否永久会员 1-是 2-否", required = true, dataType = "Integer", paramType = "query") + }) + public Result generateMembershipCode( + @RequestHeader(value = "Authorization", required = true) String authorization, + @NotNull Integer duration, + @NotNull Integer life) { + return Result.success(membershipCodeService.generateMembershipCode(authorization, duration, life)); + } - @ApiOperation(value = "1.1 批量生成会员码", notes = "仅限admin权限用户调用") - @GetMapping("/code/generate/batch") - @GlobalInterceptor(checkAdminLogin = true) - @ApiImplicitParams(value = { - @ApiImplicitParam(name = "duration", value = "会员时长(天)", required = true, dataType = "Integer", paramType = "query"), - @ApiImplicitParam(name = "count", value = "生成数量", required = true, dataType = "Integer", paramType = "query") - }) - public Result> generateMembershipCodeBatch( - @RequestHeader(value = "Authorization", required = true) String authorization, - @NotNull Integer duration, - @NotNull Integer count) { - List list = membershipCodeService.generateMembershipCodeBatch(authorization, - duration, count); - return Result.success(list); - } + @ApiOperation(value = "1.1 批量生成会员码", notes = "仅限admin权限用户调用") + @GetMapping("/code/generate/batch") + @GlobalInterceptor(checkAdminLogin = true) + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "duration", value = "会员时长(天)", required = true, dataType = "Integer", paramType = "query"), + @ApiImplicitParam(name = "count", value = "生成数量", required = true, dataType = "Integer", paramType = "query"), + @ApiImplicitParam(name = "life", value = "是否永久会员 1-是 2-否", required = true, dataType = "Integer", paramType = "query") + }) + public Result> generateMembershipCodeBatch( + @RequestHeader(value = "Authorization", required = true) String authorization, + @NotNull Integer duration, + @NotNull Integer count, + @NotNull Integer life) { + List list = membershipCodeService.generateMembershipCodeBatch(authorization, + duration, count, life); + return Result.success(list); + } - @ApiOperation(value = "2.绑定会员码", notes = "仅限app用户调用") - @PostMapping("/code/bind") - @GlobalInterceptor(checkAppUserLogin = true) - @ApiImplicitParams(value = { - @ApiImplicitParam(name = "code", value = "会员码", required = true, dataType = "String", paramType = "query") - }) - public Result bindMembershipCode( - @RequestHeader(value = "Authorization", required = true) String authorization, - @NotNull String code) { - membershipCodeService.bindMembershipCode(authorization, code); - return Result.success(); - } + @ApiOperation(value = "2.绑定会员码", notes = "仅限app用户调用") + @PostMapping("/code/bind") + @GlobalInterceptor(checkAppUserLogin = true) + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "code", value = "会员码", required = true, dataType = "String", paramType = "query") + }) + public Result bindMembershipCode( + @RequestHeader(value = "Authorization", required = true) String authorization, + @NotNull String code) { + membershipCodeService.bindMembershipCode(authorization, code); + return Result.success(); + } - @ApiOperation(value = "3.查询会员码", notes = "仅限admin权限用户调用") - @GetMapping("/code/list") - @GlobalInterceptor(checkAdminLogin = true) - public Result> queryMembershipCode( - @RequestHeader(value = "Authorization", required = true) String authorization, - @RequestBody @ApiParam(value = "查询参数", required = true) MembershipCodeSearchDto membershipCodeSearchDto, - @ApiParam(value = "页码", required = true) @PathVariable Integer page, - @ApiParam(value = "每页条数", required = true) @PathVariable Integer size) { - return Result.success(membershipCodeService.getMembershipCodeList(authorization, page, size, - membershipCodeSearchDto)); - } + @ApiOperation(value = "3.查询会员码", notes = "仅限admin权限用户调用") + @GetMapping("/code/list{page}/{size}") + @GlobalInterceptor(checkAdminLogin = true) + public Result> queryMembershipCode( + @RequestHeader(value = "Authorization", required = true) String authorization, + @RequestBody @ApiParam(value = "查询参数", required = true) MembershipCodeSearchDto membershipCodeSearchDto, + @ApiParam(value = "页码", required = true) @PathVariable Integer page, + @ApiParam(value = "每页条数", required = true) @PathVariable Integer size) { + return Result.success(membershipCodeService.getMembershipCodeList(authorization, page, size, + membershipCodeSearchDto)); + } } diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index dc0d3bb..2da37b0 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -103,6 +103,9 @@ public class MyController extends BaseController { userRespDTO.setAppleEmail(user.getAppleEmail()); userRespDTO.setEnableNotice(1); userRespDTO.setEnablePush(1); + userRespDTO.setVipStatus(user.getVipStatus()); + userRespDTO.setVipExpireTime(user.getVipExpireTime()); + if (null != user.getEnableNotice()) { userRespDTO.setEnableNotice(user.getEnableNotice()); } 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 fd4191f..cd1a426 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,17 +3,22 @@ package com.luoo.user.controller; import annotation.GlobalInterceptor; import api.PageResult; import api.Result; +import com.luoo.user.dto.point.LotterySearchDto; import com.luoo.user.dto.point.UserPointLogSearchDto; +import com.luoo.user.pojo.Lottery; import com.luoo.user.pojo.TaskPoint; import com.luoo.user.pojo.UserPointLog; +import com.luoo.user.service.LotteryService; import com.luoo.user.service.TaskPointService; import com.luoo.user.service.UserPointLogService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiOperationSort; import io.swagger.annotations.ApiParam; import java.util.List; +import javax.validation.constraints.NotNull; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; @@ -46,6 +51,9 @@ public class PointController { @Autowired private UserPointLogService userPointLogService; + @Autowired + private LotteryService lotteryService; + @ApiOperation(value = "1.1.新增任务积分配置", notes = "仅限admin权限用户调用") @PostMapping("/task/add") @@ -144,7 +152,7 @@ public class PointController { return Result.success(); } - @ApiOperation(value = "2.2. 用户根据新手任务获取积分", notes = "仅限app用户调用") + @ApiOperation(value = "2.2. 用户根据日常任务获取积分", notes = "仅限app用户调用") @PostMapping("/log/earn/task/daily") @GlobalInterceptor(checkAppUserLogin = true) @ApiImplicitParams({ @@ -163,11 +171,101 @@ public class PointController { @GlobalInterceptor(checkAppUserLogin = true) public Result> getUserPointLogList( @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, - @ApiParam(value = "查询对象")@RequestBody UserPointLogSearchDto userPointLogSearchDto, + @ApiParam(value = "查询对象") @RequestBody UserPointLogSearchDto userPointLogSearchDto, @ApiParam(value = "页码", required = true) @PathVariable Integer page, @ApiParam(value = "每页条数", required = true) @PathVariable Integer size) { - return Result.success(userPointLogService.getUserPointLogList(token, userPointLogSearchDto, page, size)); + return Result.success( + userPointLogService.getUserPointLogList(token, userPointLogSearchDto, page, size)); + } + + @ApiOperation(value = "3.1.添加抽奖", notes = "仅限admin权限用户调用") + @PostMapping("/lottery/add") + @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") + }) + public Result addLottery(@RequestHeader("Authorization") String token, + @RequestBody Lottery lottery) { + lotteryService.add(lottery, token); + return Result.success(); + } + + @ApiOperation(value = "3.2.抽奖列表页", notes = "仅限admin权限用户调用") + @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, + @ApiParam(value = "页码", required = true) @PathVariable Integer page, + @ApiParam(value = "每页条数", required = true) @PathVariable Integer size) { + return Result.success(lotteryService.lotteryPageResult(page, size, lotterySearchDto)); + } + + @ApiOperation(value = "3.3.编辑抽奖", 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") + }) + public Result editLottery(@RequestHeader("Authorization") String token, + @RequestBody Lottery lottery) { + lotteryService.edit(lottery, token); + return Result.success(); + } + + @ApiOperation(value = "3.4.发布抽奖", 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") + }) + public Result publishLottery(@RequestHeader("Authorization") String token, + @RequestBody String id) { + lotteryService.publish(id, token); + return Result.success(); } + @ApiOperation(value = "3.5.停止抽奖", notes = "仅限admin权限用户调用") + @PostMapping("/lottery/stop") + @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 = "query"), + @ApiImplicitParam(name = "stopReason", value = "停止原因", required = true, dataType = "String", paramType = "body") + }) + public Result stopLottery(@RequestHeader("Authorization") String token, + @NotNull String id, @RequestBody @NotNull String stopReason) { + lotteryService.stop(id, token, stopReason); + return Result.success(); + } + + @ApiOperation(value = "3.6.参与抽奖") + @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") + }) + 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.自动抽奖结果", notes = "用这个方法主动触发自动抽奖结果") + @PostMapping("/lottery/auto") + @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 = "query") + }) + public Result auto(@RequestHeader("Authorization") String token, @NotNull String id) { + lotteryService.auto(id, token); + return Result.success(); + } + + } diff --git a/luoo_user/src/main/java/com/luoo/user/controller/RegionController.java b/luoo_user/src/main/java/com/luoo/user/controller/RegionController.java index 346543a..a681839 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/RegionController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/RegionController.java @@ -9,6 +9,7 @@ import java.util.List; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -37,7 +38,7 @@ public class RegionController { * @return */ @ApiOperation(value = "获取地区TREE") - @RequestMapping("/tree/{level}") + @GetMapping("/tree/{level}") public Result> getRegionTreeList(@PathVariable Integer level) { return Result.success(regionService.getRegionTreeList(level)); } 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 8be8993..597426c 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 @@ -1,10 +1,21 @@ package com.luoo.user.dao; import com.luoo.user.pojo.LotteryRegion; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; public interface LotteryRegionDao extends JpaRepository, JpaSpecificationExecutor { + @Modifying + @Query(value = "DELETE FROM tb_lottery_region js WHERE js.lottery_id = :lotteryId", nativeQuery = true) + public void deleteByLotteryId(String lotteryId); + + public LotteryRegion findByLotteryIdAndRegionId(String lotteryId, Integer regionId); + + public List findByLotteryId(String lotteryId); + } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/LotteryUserDao.java b/luoo_user/src/main/java/com/luoo/user/dao/LotteryUserDao.java index 30fc8e0..7691f6d 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/LotteryUserDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/LotteryUserDao.java @@ -1,10 +1,20 @@ package com.luoo.user.dao; import com.luoo.user.pojo.LotteryUser; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; public interface LotteryUserDao extends JpaRepository, JpaSpecificationExecutor { + public List findByLotteryId(String lotteryId); + + public List findByLotteryIdAndUserIdAndRegionId(String lotteryId, String userId, + Integer regionId); + + public List findByLotteryIdAndUserId(String lotteryId, String userId); + + public List findByLotteryIdAndRegionId(String lotteryId, Integer regionId); + } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/RegionDao.java b/luoo_user/src/main/java/com/luoo/user/dao/RegionDao.java index 1a3e89e..307b7b4 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/RegionDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/RegionDao.java @@ -5,7 +5,7 @@ import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -public interface RegionDao extends JpaRepository, +public interface RegionDao extends JpaRepository, JpaSpecificationExecutor { List getRegionsByLevel(Integer level); diff --git a/luoo_user/src/main/java/com/luoo/user/dto/point/LotterySearchDto.java b/luoo_user/src/main/java/com/luoo/user/dto/point/LotterySearchDto.java new file mode 100644 index 0000000..1360e73 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/point/LotterySearchDto.java @@ -0,0 +1,30 @@ +package com.luoo.user.dto.point; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @program: luoo_parent + * @description: 抽奖查询参数 + * @author: yawei.huang + * @create: 2024-07-30 14:38 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class LotterySearchDto { + + @ApiModelProperty(value = "抽奖编号/标题") + private String searchStr; + + @ApiModelProperty(value = "城市名称") + private String cityName; + + @ApiModelProperty(value = "抽奖状态 0-编辑中 1-报名中 2-已抽奖 3-已停止") + private Integer status; + + @ApiModelProperty(value = "创建人") + private String createUser; +} 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 7bc8cc9..6807398 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 @@ -1,10 +1,13 @@ package com.luoo.user.dto.response; import java.io.Serializable; +import java.time.LocalDate; import java.util.List; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; @Data public class UserRespDTO implements Serializable { @@ -70,4 +73,18 @@ public class UserRespDTO implements Serializable { */ @ApiModelProperty(value = "是否启用推送,0为关闭,1为启用,默认启用") private Integer enablePush; + + /** + * 会员状态 0-未开通 1-生效中 2-已过期 + */ + @ApiModelProperty(value = "会员状态 0-未开通 1-生效中 2-已过期") + private Integer vipStatus; + + /** + * 会员到期时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd") + @ApiModelProperty(value = "会员到期时间") + private LocalDate vipExpireTime; } diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/Lottery.java b/luoo_user/src/main/java/com/luoo/user/pojo/Lottery.java index 213c87d..253e476 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/Lottery.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/Lottery.java @@ -1,13 +1,17 @@ package com.luoo.user.pojo; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import java.time.Instant; +import java.time.LocalDateTime; +import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EntityListeners; import javax.persistence.Id; import javax.persistence.Lob; import javax.persistence.Table; +import javax.persistence.Transient; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; @@ -16,7 +20,10 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.format.annotation.DateTimeFormat; @Data @NoArgsConstructor @@ -54,13 +61,21 @@ public class Lottery { @ApiModelProperty(value = "积分") private Integer point; + @Column(name = "region_code") + @ApiModelProperty(value = "地区编码") + private String regionCode; + + @Column(name = "region_name") + @ApiModelProperty(value = "地区名称") + private String regionName; + @Column(name = "apply_start_time") @ApiModelProperty(value = "报名开始时间") - private Instant applyStartTime; + private LocalDateTime applyStartTime; @Column(name = "apply_end_time") @ApiModelProperty(value = "报名结束时间") - private Instant applyEndTime; + private LocalDateTime applyEndTime; @Column(name = "way") @ApiModelProperty(value = "抽奖方式 1-自动抽奖 2-手动抽奖") @@ -77,16 +92,20 @@ public class Lottery { private String description; @Column(name = "status") - @ApiModelProperty(value = "抽奖状态 1-报名中 2-已抽奖 3-已停止") + @ApiModelProperty(value = "抽奖状态 0-编辑中 1-报名中 2-已抽奖 3-已停止") private Integer status; - @Column(name = "create_time") - @ApiModelProperty(value = "创建时间") - private Instant createTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty("创建时间") + @CreatedDate + private LocalDateTime createTime; - @Column(name = "update_time") - @ApiModelProperty(value = "修改时间") - private Instant updateTime; + @ApiModelProperty("修改时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @LastModifiedDate + private LocalDateTime updateTime; @Size(max = 20) @Column(name = "create_user", length = 20) @@ -98,4 +117,20 @@ public class Lottery { @ApiModelProperty(value = "更新人") private String updateUser; + @Column(name = "create_user_name") + @ApiModelProperty(value = "创建人姓名") + private String createUserName; + + @Column(name = "update_user_name") + @ApiModelProperty(value = "更新人姓名") + private String updateUserName; + + @Column(name = "stop_reason") + @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/pojo/LotteryRegion.java b/luoo_user/src/main/java/com/luoo/user/pojo/LotteryRegion.java index 56fcf6d..84694e0 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 @@ -1,7 +1,8 @@ package com.luoo.user.pojo; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; -import java.time.Instant; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EntityListeners; @@ -13,12 +14,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.format.annotation.DateTimeFormat; @Data @NoArgsConstructor @@ -53,13 +55,17 @@ public class LotteryRegion { @ApiModelProperty(value = "数量") private Integer num; - @Column(name = "create_time") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty("创建时间") - private Instant createTime; + @CreatedDate + private LocalDateTime createTime; - @Column(name = "update_time") @ApiModelProperty("修改时间") - private Instant updateTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @LastModifiedDate + private LocalDateTime updateTime; @Size(max = 20) @Column(name = "create_user", length = 20) diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/LotteryUser.java b/luoo_user/src/main/java/com/luoo/user/pojo/LotteryUser.java index 299f896..4b22f2d 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/LotteryUser.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/LotteryUser.java @@ -1,7 +1,8 @@ package com.luoo.user.pojo; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; -import java.time.Instant; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EntityListeners; @@ -16,7 +17,10 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.format.annotation.DateTimeFormat; @Data @NoArgsConstructor @@ -57,13 +61,17 @@ public class LotteryUser { @ApiModelProperty(value = "抽奖结果 1-中奖 2-未中奖") private Integer result; - @Column(name = "create_time") - @ApiModelProperty(value = "创建时间") - private Instant createTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty("创建时间") + @CreatedDate + private LocalDateTime createTime; - @Column(name = "update_time") - @ApiModelProperty(value = "修改时间") - private Instant updateTime; + @ApiModelProperty("修改时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @LastModifiedDate + private LocalDateTime updateTime; @Size(max = 20) @Column(name = "create_user", length = 20) diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/MembershipCode.java b/luoo_user/src/main/java/com/luoo/user/pojo/MembershipCode.java index e104b20..92f3422 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/MembershipCode.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/MembershipCode.java @@ -2,6 +2,7 @@ package com.luoo.user.pojo; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; +import java.time.LocalDateTime; import lombok.*; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; @@ -13,7 +14,6 @@ import org.springframework.format.annotation.DateTimeFormat; import javax.persistence.*; import javax.validation.constraints.Size; import java.io.Serializable; -import java.time.Instant; @Data @NoArgsConstructor @@ -45,6 +45,10 @@ public class MembershipCode implements Serializable { @ApiModelProperty(value = "时长") private Integer duration; + @Column(name = "life") + @ApiModelProperty(value = "是否永久会员 1-是 2-否") + private Integer life; + @Size(max = 20) @Column(name = "user_id", length = 20) @ApiModelProperty(value = "用户id") @@ -54,13 +58,13 @@ public class MembershipCode implements Serializable { @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty("创建时间") @CreatedDate - private Instant createTime; + private LocalDateTime createTime; @ApiModelProperty("修改时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @LastModifiedDate - private Instant updateTime; + private LocalDateTime updateTime; @Size(max = 20) @Column(name = "create_user", length = 20) diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/TaskPoint.java b/luoo_user/src/main/java/com/luoo/user/pojo/TaskPoint.java index 1d4c6ff..a04481e 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/TaskPoint.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/TaskPoint.java @@ -2,8 +2,7 @@ package com.luoo.user.pojo; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; -import java.time.Instant; -import java.util.Objects; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EntityListeners; @@ -58,13 +57,13 @@ public class TaskPoint { @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty("创建时间") @CreatedDate - private Instant createTime; + private LocalDateTime createTime; @ApiModelProperty("修改时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @LastModifiedDate - private Instant updateTime; + private LocalDateTime updateTime; @Size(max = 20) @Column(name = "create_user", length = 20) diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserBank.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserBank.java index 6e666e1..784bfba 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserBank.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserBank.java @@ -2,6 +2,7 @@ package com.luoo.user.pojo; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; +import java.time.LocalDateTime; import lombok.*; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -47,13 +48,13 @@ public class UserBank implements Serializable { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @CreatedDate - private Instant createTime; + private LocalDateTime createTime; @ApiModelProperty(value = "修改时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @LastModifiedDate - private Instant updateTime; + private LocalDateTime updateTime; @ApiModelProperty(value = "创建人") private String createUser; diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserPointLog.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserPointLog.java index 3c6fecb..f0dc880 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserPointLog.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserPointLog.java @@ -2,6 +2,7 @@ package com.luoo.user.pojo; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; +import java.time.LocalDateTime; import lombok.*; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; @@ -13,7 +14,6 @@ import org.springframework.format.annotation.DateTimeFormat; import javax.persistence.*; import javax.validation.constraints.Size; import java.io.Serializable; -import java.time.Instant; @Data @NoArgsConstructor @@ -59,13 +59,13 @@ public class UserPointLog implements Serializable { @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty("创建时间") @CreatedDate - private Instant createTime; + private LocalDateTime createTime; @ApiModelProperty("修改时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @LastModifiedDate - private Instant updateTime; + private LocalDateTime updateTime; @Size(max = 20) @Column(name = "create_user", length = 20) diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/Withdraw.java b/luoo_user/src/main/java/com/luoo/user/pojo/Withdraw.java index 7bcd7ea..6970d1a 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/Withdraw.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/Withdraw.java @@ -2,6 +2,7 @@ package com.luoo.user.pojo; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; +import java.time.LocalDateTime; import lombok.*; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -13,7 +14,6 @@ import javax.persistence.Table; import javax.persistence.Transient; import java.io.Serializable; import java.math.BigDecimal; -import java.time.Instant; @Builder @AllArgsConstructor @@ -39,12 +39,12 @@ public class Withdraw implements Serializable { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @CreatedDate - private Instant createTime; + private LocalDateTime createTime; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @LastModifiedDate - private Instant updateTime; + private LocalDateTime updateTime; private String createUser; 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 14693fe..6f259fc 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 @@ -1,7 +1,47 @@ package com.luoo.user.service; +import api.PageResult; +import com.luoo.user.dao.LotteryDao; +import com.luoo.user.dao.LotteryRegionDao; +import com.luoo.user.dao.LotteryUserDao; +import com.luoo.user.dao.UserInfoDao; +import com.luoo.user.dto.point.LotterySearchDto; +import com.luoo.user.pojo.Lottery; +import com.luoo.user.pojo.LotteryRegion; +import com.luoo.user.pojo.LotteryUser; +import com.luoo.user.pojo.Region; +import com.luoo.user.pojo.UserInfo; +import com.luoo.user.pojo.UserPointLog; +import constants.ErrorConstants; +import dto.UserLoginDto; +import enums.PointEnums; +import enums.UserTypeEnum; +import enums.UserVipStatusEnum; +import exception.BizException; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Random; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; +import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import util.IdWorker; +import util.JwtUtil; +import util.RedisLockUtil; /** * @program: luoo_parent @@ -13,4 +53,377 @@ import org.springframework.stereotype.Service; @Slf4j public class LotteryService { + public static final String POINTS_WILL_BE_RETURNED = "抽奖返积分"; + + public static final String LOTTERY_POINTS_TYPE = "积分抽奖"; + + private final LotteryDao lotteryDao; + + private final JwtUtil jwtUtil; + + private final IdWorker idWorker; + + private final RedisLockUtil redisLockUtil; + + private final RegionService regionService; + + private final LotteryRegionDao lotteryRegionDao; + + private final UserInfoDao userInfoDao; + + private final RabbitTemplate rabbitTemplate; + + private final LotteryUserDao lotteryUserDao; + + public LotteryService(LotteryDao lotteryDao, IdWorker idWorker, JwtUtil jwtUtil, + RedisLockUtil redisLockUtil, RegionService regionService, LotteryRegionDao lotteryRegionDao, + UserInfoDao userInfoDao, RabbitTemplate rabbitTemplate, LotteryUserDao lotteryUserDao) { + this.lotteryDao = lotteryDao; + this.idWorker = idWorker; + this.jwtUtil = jwtUtil; + this.redisLockUtil = redisLockUtil; + this.regionService = regionService; + this.lotteryRegionDao = lotteryRegionDao; + this.userInfoDao = userInfoDao; + this.rabbitTemplate = rabbitTemplate; + this.lotteryUserDao = lotteryUserDao; + } + + /** + * 新增一条积分抽奖 + * + * @param lottery 抽奖对象 + * @param token 登录token + */ + @Transactional(rollbackFor = Exception.class) + public void add(Lottery lottery, String token) { + + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + + StringBuilder regionCode = new StringBuilder(); + StringBuilder regionName = new StringBuilder(); + + List lotteryRegionList = lottery.getLotteryRegionList(); + + for (LotteryRegion lotteryRegion : lotteryRegionList) { + Region regionById = regionService.getRegionById(lotteryRegion.getRegionId()); + regionCode.append(regionById.getCode()).append(","); + regionName.append(regionById.getName()).append(","); + } + + lottery.setId(String.valueOf(idWorker.nextId())); + lottery.setCreateUser(userLoginDto.getUserId()); + lottery.setUpdateUser(userLoginDto.getUserId()); + lottery.setCreateUserName(userLoginDto.getNickName()); + lottery.setUpdateUserName(userLoginDto.getNickName()); + lottery.setCode(redisLockUtil.lotteryGenerateSerialNumber()); + lottery.setStatus(PointEnums.LOTTERY_STATUS_EDITING.getCode()); + lottery.setRegionCode(regionCode.toString()); + lottery.setRegionName(regionName.toString()); + + lotteryDao.save(lottery); + + lotteryRegionList.forEach(lotteryRegion -> { + lotteryRegion.setId(String.valueOf(idWorker.nextId())); + lotteryRegion.setLotteryId(lottery.getId()); + lotteryRegion.setCreateUser(userLoginDto.getUserId()); + lotteryRegion.setUpdateUser(userLoginDto.getUserId()); + + lotteryRegionDao.save(lotteryRegion); + }); + } + + /** + * 编辑抽奖 + * + * @param lottery 抽奖内容 + * @param token 登录人 + */ + @Transactional(rollbackFor = Exception.class) + public void edit(Lottery lottery, String token) { + + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + + StringBuilder regionCode = new StringBuilder(); + StringBuilder regionName = new StringBuilder(); + + List lotteryRegionList = lottery.getLotteryRegionList(); + for (LotteryRegion lotteryRegion : lotteryRegionList) { + Region regionById = regionService.getRegionById(lotteryRegion.getRegionId()); + regionCode.append(regionById.getCode()).append(","); + regionName.append(regionById.getName()).append(","); + } + + String id = lottery.getId(); + Lottery lottery1 = lotteryDao.findById(id).orElse(null); + if (!Objects.equals(PointEnums.LOTTERY_STATUS_EDITING.getCode(), lottery1.getStatus())) { + // 不是编辑中,不允许修改 + throw new BizException(ErrorConstants.CAN_NOT_EDIT); + } + + lottery.setRegionCode(regionCode.toString()); + lottery.setRegionName(regionName.toString()); + lottery.setUpdateUser(userLoginDto.getUserId()); + lottery.setUpdateUserName(userLoginDto.getNickName()); + + lotteryDao.save(lottery); + + lotteryRegionDao.deleteByLotteryId(id); + lotteryRegionList.forEach(lotteryRegion -> { + lotteryRegion.setId(String.valueOf(idWorker.nextId())); + lotteryRegion.setLotteryId(id); + lotteryRegion.setCreateUser(userLoginDto.getUserId()); + lotteryRegion.setUpdateUser(userLoginDto.getUserId()); + + lotteryRegionDao.save(lotteryRegion); + }); + + } + + /** + * 发布抽奖 + * + * @param id 抽奖id + * @param token 登录人token + */ + @Transactional(rollbackFor = Exception.class) + public void publish(String id, String token) { + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + + Lottery lottery = lotteryDao.findById(id).orElse(null); + lottery.setUpdateUser(userLoginDto.getUserId()); + lottery.setUpdateUserName(userLoginDto.getNickName()); + + lottery.setStatus(PointEnums.LOTTERY_STATUS_SIGN.getCode()); + + lotteryDao.save(lottery); + + } + + /** + * 停止抽奖 + * + * @param id 抽奖id + * @param token 登录人token + * @param stopReason 停止原因 + */ + @Transactional(rollbackFor = Exception.class) + public void stop(String id, String token, String stopReason) { + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + + Lottery lottery = lotteryDao.findById(id).orElse(null); + lottery.setUpdateUser(userLoginDto.getUserId()); + lottery.setUpdateUserName(userLoginDto.getNickName()); + lottery.setStopReason(stopReason); + lottery.setStatus(PointEnums.LOTTERY_STATUS_SIGN.getCode()); + + lotteryDao.save(lottery); + + // 返还用户积分 放到MQ队列 + lotteryUserDao.findByLotteryId(id).forEach(lotteryUser -> { + + UserPointLog userPointLog = UserPointLog.builder() + .id(String.valueOf(idWorker.nextId())) + .type(PointEnums.TASK_POINT_TYPE_ADD.getCode()) + .createUser(lotteryUser.getUserId()) + .taskPointId(null) + .description(POINTS_WILL_BE_RETURNED) + .userId(lotteryUser.getUserId()) + .score(lottery.getPoint()) + .build(); + + rabbitTemplate.convertAndSend("pointLog", userPointLog); + + }); + + } + + /** + * 参与抽奖 + * + * @param id 抽奖id + * @param token 登录人token + * @param regionId 地区id + */ + @Transactional(rollbackFor = Exception.class) + public void participate(String id, String token, Integer regionId) { + + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + Lottery lottery = lotteryDao.findById(id).get(); + if (!Objects.equals(PointEnums.LOTTERY_STATUS_SIGN.getCode(), lottery.getStatus())) { + // 不是报名中,不允许参与 + throw new BizException(ErrorConstants.NOT_IN_THE_SIGN_UP_PERIOD); + } + + // 校验用户是否可参与 + UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get(); + + Integer participant = lottery.getParticipant(); + if (Objects.equals(participant, PointEnums.LOTTERY_ALL_MEMBER.getCode())) { + // 会员可参与 + if (!Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.INITIAL.getCode()) && + !Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.LIFE.getCode())) { + throw new BizException(ErrorConstants.NOT_MEMBER); + } + } else if (Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.LIFE.getCode())) { + // 永久会员可参与 + if (!Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.LIFE.getCode())) { + throw new BizException(ErrorConstants.NOT_PERMANENT_MEMBER); + } + } else if (Objects.equals(participant, PointEnums.LOTTERY_CONTRIBUTORS.getCode())) { + // 贡献者可参与 + if (StringUtils.isBlank(userInfo.getBadges()) || !userInfo.getBadges().startsWith("1")) { + throw new BizException(ErrorConstants.NOT_CONTRIBUTOR); + } + } else if (Objects.equals(participant, PointEnums.LOTTERY_ARTIST.getCode())) { + // 音乐人可参与 + if (!Objects.equals(String.valueOf(userInfo.getType()), UserTypeEnum.ARTIST_PERSON.getCode()) + && !Objects.equals(String.valueOf(userInfo.getType()), UserTypeEnum.ARTIST_BAND.getCode()) + ) { + throw new BizException(ErrorConstants.NOT_ARTIST); + } + } + + List checkUserList = lotteryUserDao.findByLotteryIdAndUserIdAndRegionId( + id, userLoginDto.getUserId(), regionId); + if(!checkUserList.isEmpty()) { + throw new BizException(ErrorConstants.ALREADY_PARTICIPATED); + } + + LotteryUser lotteryUser = LotteryUser.builder() + .id(String.valueOf(idWorker.nextId())) + .lotteryId(id) + .regionId(regionId) + .userId(userLoginDto.getUserId()) + .createUser(userLoginDto.getUserId()) + .updateUser(userLoginDto.getUserId()) + .build(); + + lotteryUserDao.save(lotteryUser); + + UserPointLog userPointLog = UserPointLog.builder() + .id(String.valueOf(idWorker.nextId())) + .type(PointEnums.TASK_POINT_TYPE_REDUCE.getCode()) + .createUser(lotteryUser.getUserId()) + .taskPointId(null) + .description(LOTTERY_POINTS_TYPE) + .userId(lotteryUser.getUserId()) + .score(lottery.getPoint()) + .build(); + rabbitTemplate.convertAndSend("pointLog", userPointLog); + + } + + /** + * 自动抽奖结果 + * + * @param id 抽奖id + */ + @Transactional(rollbackFor = Exception.class) + public void auto(String id, String token) { + + Lottery lottery = lotteryDao.findById(id).get(); + + LocalDateTime applyEndTime = lottery.getApplyEndTime(); + // 比较当前时间与applyEndTime + if (LocalDateTime.now().isBefore(applyEndTime)) { + throw new BizException(ErrorConstants.NOT_END_OF_SIGN_UP); + } + + if (Objects.equals(lottery.getStatus(), PointEnums.LOTTERY_STATUS_SIGN.getCode())) { + + List lotteryRegionList = lotteryRegionDao.findByLotteryId(id); + + lotteryRegionList.forEach(lotteryRegion -> { + Integer num = lotteryRegion.getNum(); + if (num > 0) { + List lotteryUserList = lotteryUserDao.findByLotteryIdAndRegionId(id, + lotteryRegion.getRegionId()); + + List winnerList = new ArrayList<>(); + if (lotteryUserList.size() > num) { + // 抽奖人数大于设定人数 + // 随机设定人数的数量中奖 + winnerList = drawWinners(lotteryUserList, lotteryRegion.getNum()); + } else { + // 抽奖人数小于设定人数 + // 全部中奖 + winnerList = lotteryUserList; + } + + winnerList.forEach(lotteryUser -> { + lotteryUser.setResult(PointEnums.LOTTERY_RESULT_WIN.getCode()); + if(StringUtils.isNotBlank(token)) { + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + lotteryUser.setUpdateUser(userLoginDto.getUserId()); + } + lotteryUserDao.save(lotteryUser); + }); + + } + }); + // 抽奖状态为报名中,自动抽奖 + lottery.setStatus(PointEnums.LOTTERY_STATUS_LOTTERY.getCode()); + lotteryDao.save(lottery); + } + } + + /** + * 从参与者列表中随机抽取指定数量的中奖者。 + * + * @param participants 参与者列表 + * @param winnersCount 中奖者数量 + * @return 中奖者列表 + */ + private List drawWinners(List participants, int winnersCount) { + List winners = new ArrayList<>(participants); + Collections.shuffle(winners, new Random()); + return winners.subList(0, Math.min(winnersCount, winners.size())); + } + + /** + * 列表页查询 + * + * @param page 页码 + * @param size 每页数量 + * @param lotterySearchDto 查询参数 + * @return 列表页 + */ + public PageResult lotteryPageResult(Integer page, Integer size, + LotterySearchDto lotterySearchDto) { + Sort sort = new Sort(Direction.DESC, "createTime"); + PageRequest pageRequest = PageRequest.of(page - 1, size, sort); + + Specification specification = getSpecification(lotterySearchDto); + Page lotteryPage = lotteryDao.findAll(specification, pageRequest); + + long totalElements = lotteryPage.getTotalElements(); + return new PageResult<>(totalElements, lotteryPage.getContent()); + } + + private Specification getSpecification(LotterySearchDto lotterySearchDto) { + return (Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) -> { + List predicateList = new ArrayList<>(); + + if (StringUtils.isNotBlank(lotterySearchDto.getSearchStr())) { + predicateList.add( + criteriaBuilder.or( + criteriaBuilder.like(root.get("title"), + "%" + lotterySearchDto.getSearchStr() + "%"), + criteriaBuilder.like(root.get("code"), "%" + lotterySearchDto.getSearchStr() + "%") + ) + ); + } + if (lotterySearchDto.getStatus() != null) { + predicateList.add(criteriaBuilder.equal(root.get("status"), lotterySearchDto.getStatus())); + } + if (StringUtils.isNotBlank(lotterySearchDto.getCreateUser())) { + predicateList.add( + criteriaBuilder.equal(root.get("createUser"), lotterySearchDto.getCreateUser())); + } + + return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()])); + }; + } + } diff --git a/luoo_user/src/main/java/com/luoo/user/service/MembershipCodeService.java b/luoo_user/src/main/java/com/luoo/user/service/MembershipCodeService.java index 39b1a31..3fd148f 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/MembershipCodeService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/MembershipCodeService.java @@ -10,14 +10,17 @@ import com.luoo.user.pojo.UserInfo; import com.luoo.user.pojo.UserPointLog; import dto.UserLoginDto; import enums.MembershipEnums; +import enums.PointEnums; import enums.UserVipStatusEnum; import exception.BizException; + import java.util.ArrayList; import java.util.List; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; + import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.data.domain.Page; @@ -47,146 +50,157 @@ import java.util.UUID; @Slf4j public class MembershipCodeService { - private final MembershipCodeDao membershipCodeDao; - - private final IdWorker idWorker; - - private final JwtUtil jwtUtil; - - private final UserInfoDao userInfoDao; - - public MembershipCodeService(JwtUtil jwtUtil, IdWorker idWorker, - MembershipCodeDao membershipCodeDao, UserInfoDao userInfoDao) { - this.jwtUtil = jwtUtil; - this.idWorker = idWorker; - this.membershipCodeDao = membershipCodeDao; - this.userInfoDao = userInfoDao; - } - - /** - * 创建会员码并保存 会员码取UUID - * - * @param token token - * @param duration 会员时长(天) - * @return 会员码 - */ - @Transactional(rollbackFor = Exception.class) - public String generateMembershipCode(String token, Integer duration) { - UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); - - // UUID作为会员码 - String code = UUID.randomUUID().toString(); - MembershipCode build = MembershipCode.builder() - .id(String.valueOf(idWorker.nextId())) - .code(code) - .status(MembershipEnums.CREATED.getCode()) - .duration(duration) - .createUser(userLoginDto.getUserId()) - .build(); - membershipCodeDao.save(build); - return code; - } - - /** - * 批量生成会员码 - * - * @param token token - * @param duration 会员时长(天) - * @param count 生成会员码数量 - * @return 会员码list - */ - @Transactional(rollbackFor = Exception.class) - public List generateMembershipCodeBatch(String token, Integer duration, Integer count) { - List result = new ArrayList<>(); - for (int i = 0; i < count; i++) { - String code = generateMembershipCode(token, duration); - result.add(code); + private final MembershipCodeDao membershipCodeDao; + + private final IdWorker idWorker; + + private final JwtUtil jwtUtil; + + private final UserInfoDao userInfoDao; + + public MembershipCodeService(JwtUtil jwtUtil, IdWorker idWorker, + MembershipCodeDao membershipCodeDao, UserInfoDao userInfoDao) { + this.jwtUtil = jwtUtil; + this.idWorker = idWorker; + this.membershipCodeDao = membershipCodeDao; + this.userInfoDao = userInfoDao; + } + + /** + * 创建会员码并保存 会员码取UUID + * + * @param token token + * @param duration 会员时长(天) + * @param life 是否永久会员 + * @return 会员码 + */ + @Transactional(rollbackFor = Exception.class) + public String generateMembershipCode(String token, Integer duration, Integer life) { + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + + // UUID作为会员码 + String code = UUID.randomUUID().toString(); + MembershipCode build = MembershipCode.builder() + .id(String.valueOf(idWorker.nextId())) + .code(code) + .status(MembershipEnums.CREATED.getCode()) + .duration(duration) + .life(life) + .createUser(userLoginDto.getUserId()) + .build(); + membershipCodeDao.save(build); + return code; + } + + /** + * 批量生成会员码 + * + * @param token token + * @param duration 会员时长(天) + * @param count 生成会员码数量 + * @param life 是否永久会员 + * @return 会员码list + */ + @Transactional(rollbackFor = Exception.class) + public List generateMembershipCodeBatch(String token, Integer duration, Integer count, Integer life) { + List result = new ArrayList<>(); + for (int i = 0; i < count; i++) { + String code = generateMembershipCode(token, duration, life); + result.add(code); + } + return result; } - return result; - } - - /** - * 绑定会员码 - * - * @param token token - * @param code 会员码 - */ - @Transactional(rollbackFor = Exception.class) - public void bindMembershipCode(String token, String code) { - UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); - MembershipCode membershipCode = membershipCodeDao.findMembershipCodeByCodeAndStatus(code, - MembershipEnums.CREATED.getCode()); - if (membershipCode == null) { - throw new BizException("会员码不存在"); + + /** + * 绑定会员码 + * + * @param token token + * @param code 会员码 + */ + @Transactional(rollbackFor = Exception.class) + public void bindMembershipCode(String token, String code) { + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + MembershipCode membershipCode = membershipCodeDao.findMembershipCodeByCodeAndStatus(code, + MembershipEnums.CREATED.getCode()); + if (membershipCode == null) { + throw new BizException("会员码不存在"); + } + // 处理会员码表 + membershipCode.setStatus(MembershipEnums.BIND.getCode()); + membershipCode.setUserId(userLoginDto.getUserId()); + membershipCode.setUpdateUser(userLoginDto.getUserId()); + membershipCodeDao.save(membershipCode); + + // 处理用户表 + UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get(); + + // 永久会员码 + if(Objects.equals(membershipCode.getLife(), PointEnums.MEMBERSHIP_LIFE.getCode())) { + userInfo.setVipStatus(UserVipStatusEnum.LIFE.getCode()); + } else { + // 非永久会员码 + // 计算会员到期时间 + LocalDate vipExpireTime; + if (Objects.equals(UserVipStatusEnum.INITIAL.getCode(), userInfo.getVipStatus())) { + vipExpireTime = userInfo.getVipExpireTime().plusDays(membershipCode.getDuration()); + } else { + // 从今天开始,增加membershipCode的duration天 + userInfo.setVipStatus(UserVipStatusEnum.INITIAL.getCode()); + vipExpireTime = LocalDate.now().plusDays(membershipCode.getDuration()); + } + userInfo.setVipExpireTime(vipExpireTime); + // 无论如何当即设置为会员生效状态 + userInfo.setVipStatus(UserVipStatusEnum.ACTIVE.getCode()); + } + + userInfoDao.save(userInfo); + } - // 处理会员码表 - membershipCode.setStatus(MembershipEnums.BIND.getCode()); - membershipCode.setUserId(userLoginDto.getUserId()); - membershipCode.setUpdateUser(userLoginDto.getUserId()); - membershipCodeDao.save(membershipCode); - - // 处理用户表 - UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get(); - // 计算会员到期时间 - LocalDate vipExpireTime; - if (Objects.equals(UserVipStatusEnum.INITIAL.getCode(), userInfo.getVipStatus())) { - vipExpireTime = userInfo.getVipExpireTime().plusDays(membershipCode.getDuration()); - } else { - // 从今天开始,增加membershipCode的duration天 - userInfo.setVipStatus(UserVipStatusEnum.INITIAL.getCode()); - vipExpireTime = LocalDate.now().plusDays(membershipCode.getDuration()); + + public PageResult getMembershipCodeList(String token, Integer page, Integer size, + MembershipCodeSearchDto membershipCodeSearchDto) { + + Sort sort = new Sort(Direction.DESC, "createTime"); + PageRequest pageRequest = PageRequest.of(page - 1, size, sort); + + Specification specification = buildSearchSpecification(membershipCodeSearchDto); + Page membershipCodePage = membershipCodeDao.findAll(specification, pageRequest); + + long totalElements = membershipCodePage.getTotalElements(); + return new PageResult<>(totalElements, membershipCodePage.getContent()); + } + + private Specification buildSearchSpecification(MembershipCodeSearchDto param) { + return (Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) -> { + List predicateList = new ArrayList(); + + if (StringUtils.isNotBlank(param.getCode())) { + predicateList.add( + criteriaBuilder.and(criteriaBuilder.equal(root.get("code"), param.getCode()))); + } + + if (StringUtils.isNotBlank(param.getCreateUser())) { + predicateList.add( + criteriaBuilder.and( + criteriaBuilder.equal(root.get("createUser"), param.getCreateUser()))); + } + + if (StringUtils.isNotBlank(param.getUserId())) { + predicateList.add( + criteriaBuilder.and(criteriaBuilder.equal(root.get("userId"), param.getUserId()))); + } + + if (param.getStatus() != null) { + predicateList.add( + criteriaBuilder.and(criteriaBuilder.equal(root.get("status"), param.getStatus()))); + } + + if (param.getDuration() != null) { + predicateList.add( + criteriaBuilder.and(criteriaBuilder.equal(root.get("duration"), param.getDuration()))); + } + + return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()])); + }; } - userInfo.setVipExpireTime(vipExpireTime); - // 无论如何当即设置为会员生效状态 - userInfo.setVipStatus(UserVipStatusEnum.ACTIVE.getCode()); - userInfoDao.save(userInfo); - - } - - public PageResult getMembershipCodeList(String token, Integer page, Integer size, - MembershipCodeSearchDto membershipCodeSearchDto) { - - Sort sort = new Sort(Direction.DESC, "createTime"); - PageRequest pageRequest = PageRequest.of(page - 1, size, sort); - - Specification specification = buildSearchSpecification(membershipCodeSearchDto); - Page membershipCodePage = membershipCodeDao.findAll(specification, pageRequest); - - long totalElements = membershipCodePage.getTotalElements(); - return new PageResult<>(totalElements, membershipCodePage.getContent()); - } - - private Specification buildSearchSpecification(MembershipCodeSearchDto param) { - return (Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) -> { - List predicateList = new ArrayList(); - - if (StringUtils.isNotBlank(param.getCode())) { - predicateList.add( - criteriaBuilder.and(criteriaBuilder.equal(root.get("code"), param.getCode()))); - } - - if (StringUtils.isNotBlank(param.getCreateUser())) { - predicateList.add( - criteriaBuilder.and( - criteriaBuilder.equal(root.get("createUser"), param.getCreateUser()))); - } - - if (StringUtils.isNotBlank(param.getUserId())) { - predicateList.add( - criteriaBuilder.and(criteriaBuilder.equal(root.get("userId"), param.getUserId()))); - } - - if (param.getStatus() != null) { - predicateList.add( - criteriaBuilder.and(criteriaBuilder.equal(root.get("status"), param.getStatus()))); - } - - if (param.getDuration() != null) { - predicateList.add( - criteriaBuilder.and(criteriaBuilder.equal(root.get("duration"), param.getDuration()))); - } - - return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()])); - }; - } } diff --git a/luoo_user/src/main/java/com/luoo/user/service/RegionService.java b/luoo_user/src/main/java/com/luoo/user/service/RegionService.java index 056d5da..dcf7313 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/RegionService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/RegionService.java @@ -1,17 +1,15 @@ package com.luoo.user.service; -import cn.hutool.core.util.ObjectUtil; import com.luoo.user.dao.RegionDao; import com.luoo.user.pojo.Region; import com.luoo.user.vo.RegionVo; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -36,14 +34,30 @@ public class RegionService { this.redisTemplate = redisTemplate; } + /** + * 根据id获取地区 + * + * @param id id + * @return + */ + public Region getRegionById(Integer id) { + Region o = (Region) redisTemplate.opsForValue().get("REGION_" + id); + if (o == null) { + o = regionDao.findById(id).get(); + redisTemplate.opsForValue().set("REGION_" + id, o, 10, TimeUnit.MINUTES); + } + return o; + } + /** * 获取2级地区tree + * * @return */ public List getRegionTreeListForTwoLevels() { List o = (List) redisTemplate.opsForValue().get(REGION_TREE_LIST_FOR + 2); - if(o == null) { + if (o == null) { o = getRegionTreeList(2); redisTemplate.opsForValue().set(REGION_TREE_LIST_FOR + 2, o); } @@ -53,12 +67,13 @@ public class RegionService { /** * 获取三级地区tree + * * @return */ public List getRegionTreeListForThreeLevels() { List o = (List) redisTemplate.opsForValue().get(REGION_TREE_LIST_FOR + 3); - if(o == null) { + if (o == null) { o = getRegionTreeList(3); redisTemplate.opsForValue().set(REGION_TREE_LIST_FOR + 3, o); } diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java index 3b3ca67..df0faaa 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java @@ -130,25 +130,32 @@ public class UserPointLogService { // 根据积分任务ID获取积分任务详情 // 保存积分记录 String taskPointId = userPointLog.getTaskPointId(); - TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId); - // 获取积分任务类型 - Integer type = taskPoint.getType(); + if (taskPointId != null) { + TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId); - // 对于新手任务,只允许完成一次,如果用户已经完成过,则直接返回,不重复添加积分 - if (Objects.equals(type, PointEnums.TASK_TYPE_NEW.getCode())) { - // 新手任务,只触发一次 - if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userPointLog.getUserId(), - userPointLog.getTaskPointId()).isEmpty()) { - return; + // 获取积分任务类型 + Integer type = taskPoint.getType(); + + // 对于新手任务,只允许完成一次,如果用户已经完成过,则直接返回,不重复添加积分 + if (Objects.equals(type, PointEnums.TASK_TYPE_NEW.getCode())) { + // 新手任务,只触发一次 + if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userPointLog.getUserId(), + userPointLog.getTaskPointId()).isEmpty()) { + return; + } } + + userPointLog.setScore(taskPoint.getScore()); + userPointLog.setDescription(taskPoint.getDescription()); + + // 保存用户积分记录 + userPointLogDao.save(userPointLog); + log.info("用户 {} 添加积分记录 {} 成功", userPointLog.getUserId(), userPointLog.getId()); } - userPointLog.setScore(taskPoint.getScore()); - userPointLog.setDescription(taskPoint.getDescription()); + // 如果id不存在,按传入的增加积分,如取消抽奖返还用户积分 - // 保存用户积分记录 - userPointLogDao.save(userPointLog); // 更新用户积分,获取用户信息并累加积分得分 // 对用户进行积分计算 @@ -159,6 +166,7 @@ public class UserPointLogService { // 更新用户积分信息 userInfoDao.save(userInfo); + } /** diff --git a/luoo_user/src/main/resources/sql/20240719.sql b/luoo_user/src/main/resources/sql/20240719.sql index 0627155..07706d5 100644 --- a/luoo_user/src/main/resources/sql/20240719.sql +++ b/luoo_user/src/main/resources/sql/20240719.sql @@ -3,14 +3,16 @@ create table tb_membership_code id varchar(20) not null comment 'id' primary key, code varchar(50) null comment '会员码', - status tinyint null comment '状态 1-已生成 2-已绑定 3-已退款 4-已废弃', - duration int null comment '会员时长(天)', + status tinyint null comment '状态 1-已生成 2-已绑定 3-已退款 4-已废弃', + duration int null comment '会员时长(天)', + life tinyint null comment '是否永久会员 1-是 2-否', user_id varchar(20) null comment '使用用户', - create_time datetime null comment '创建时间', - update_time datetime null comment '修改时间', + create_time datetime null comment '创建时间', + update_time datetime null comment '修改时间', create_user varchar(20) null comment '创建人', update_user varchar(20) null comment '修改人' -) comment '会员码'; +) + comment '会员码'; create table tb_user_point_log ( diff --git a/luoo_user/src/main/resources/sql/20240730.sql b/luoo_user/src/main/resources/sql/20240730.sql index f90d85e..0f4bc21 100644 --- a/luoo_user/src/main/resources/sql/20240730.sql +++ b/luoo_user/src/main/resources/sql/20240730.sql @@ -1,23 +1,28 @@ create table tb_lottery ( - id varchar(20) not null comment 'id' + id varchar(20) not null comment 'id' primary key, - code varchar(50) null comment '抽奖码', + code varchar(50) null comment '抽奖码', title varchar(255) null comment '抽奖标题', - participant int null comment '可参加人员 1-全部 2-全部会员 3-永久会员 4-贡献者 5-音乐人', - point int null comment '消耗积分', - apply_start_time datetime null comment '报名开始时间', - apply_end_time datetime null comment '报名结束时间', - way tinyint null comment '抽奖方式 1-自动抽奖 2-手动抽奖', + participant int null comment '可参加人员 1-全部 2-全部会员 3-永久会员 4-贡献者 5-音乐人', + point int null comment '消耗积分', + region_code varchar(255) null comment '抽奖城市code', + region_name varchar(255) null comment '抽奖城市名称', + apply_start_time datetime null comment '报名开始时间', + apply_end_time datetime null comment '报名结束时间', + way tinyint null comment '抽奖方式 1-自动抽奖 2-手动抽奖', image varchar(255) null comment '抽奖封面url', - description longtext null comment '演出详情', - status tinyint null comment '抽奖状态 1-报名中 2-已抽奖 3-已停止', - create_time datetime null comment '创建时间', - update_time datetime null comment '修改时间', - create_user varchar(20) null comment '创建人', - update_user varchar(20) null comment '修改人' -) comment '抽奖表'; - + description longtext null comment '演出详情', + status tinyint null comment '抽奖状态 1-报名中 2-已抽奖 3-已停止', + create_time datetime null comment '创建时间', + update_time datetime null comment '修改时间', + create_user varchar(20) null comment '创建人', + update_user varchar(20) null comment '修改人', + create_user_name varchar(20) null comment '创建人姓名', + update_user_name varchar(20) null comment '更新人姓名', + stop_reason varchar(255) null comment '停止原因' +) + comment '抽奖表'; create table tb_lottery_region ( @@ -32,7 +37,6 @@ create table tb_lottery_region update_user varchar(20) null comment '修改人' ) comment '抽奖地区表'; - create table tb_lottery_user ( id varchar(20) not null comment 'id'