release: 积分抽奖部分

release-2024-08-08
huangyw 6 months ago
parent d546a4574c
commit f2618e152d

@ -9,49 +9,68 @@ package constants;
* @Describe: 便 * @Describe: 便
*/ */
public class ErrorConstants { 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 STATE_ERROR = "状态错误";
public final static String REAL_NAME_APPROVE_IS_EXISTS = "该用户实名认证已存在";
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 = "用户名已存在";
} }

@ -14,6 +14,23 @@ public enum PointEnums {
TASK_POINT_TYPE_ADD(1, "增加"), TASK_POINT_TYPE_ADD(1, "增加"),
TASK_POINT_TYPE_REDUCE(2, "减少"), 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, "未中奖"),
; ;
private final Integer code; private final Integer code;
private final String description; private final String description;

@ -16,6 +16,7 @@ public enum UserVipStatusEnum {
INITIAL(0, "未开通"), INITIAL(0, "未开通"),
ACTIVE(1, "生效中"), ACTIVE(1, "生效中"),
EXPIRED(2, "已过期"), EXPIRED(2, "已过期"),
LIFE(3, "永久会员")
; ;

@ -28,6 +28,13 @@ public class RedisLockUtil {
private static final String KEY_PREFIX = "serial_number:"; private static final String KEY_PREFIX = "serial_number:";
private static final String DATE_FORMAT = "yyMMdd"; 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() { public String generateSerialNumber() {
String key = KEY_PREFIX + getCurrentDate(); String key = KEY_PREFIX + getCurrentDate();
Long increment = redisTemplate.opsForValue().increment(key, 1); Long increment = redisTemplate.opsForValue().increment(key, 1);
@ -37,6 +44,24 @@ public class RedisLockUtil {
return getCurrentDate() + String.format("%04d", increment); 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() { private String getCurrentDate() {
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
return sdf.format(new Date()); return sdf.format(new Date());

@ -3,17 +3,22 @@ package com.luoo.user.controller;
import annotation.GlobalInterceptor; import annotation.GlobalInterceptor;
import api.PageResult; import api.PageResult;
import api.Result; import api.Result;
import com.luoo.user.dto.point.LotterySearchDto;
import com.luoo.user.dto.point.UserPointLogSearchDto; import com.luoo.user.dto.point.UserPointLogSearchDto;
import com.luoo.user.pojo.Lottery;
import com.luoo.user.pojo.TaskPoint; import com.luoo.user.pojo.TaskPoint;
import com.luoo.user.pojo.UserPointLog; import com.luoo.user.pojo.UserPointLog;
import com.luoo.user.service.LotteryService;
import com.luoo.user.service.TaskPointService; import com.luoo.user.service.TaskPointService;
import com.luoo.user.service.UserPointLogService; import com.luoo.user.service.UserPointLogService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import java.util.List; import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.CrossOrigin;
@ -46,6 +51,9 @@ public class PointController {
@Autowired @Autowired
private UserPointLogService userPointLogService; private UserPointLogService userPointLogService;
@Autowired
private LotteryService lotteryService;
@ApiOperation(value = "1.1.新增任务积分配置", notes = "仅限admin权限用户调用") @ApiOperation(value = "1.1.新增任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/add") @PostMapping("/task/add")
@ -163,11 +171,101 @@ public class PointController {
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<UserPointLog>> getUserPointLogList( public Result<PageResult<UserPointLog>> getUserPointLogList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @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 page,
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) { @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<Void> 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<PageResult<Lottery>> 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<Void> 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<Void> 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<Void> 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<Void> 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<Void> auto(@RequestHeader("Authorization") String token, @NotNull String id) {
lotteryService.auto(id, token);
return Result.success();
}
} }

@ -9,6 +9,7 @@ import java.util.List;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin; 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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -37,7 +38,7 @@ public class RegionController {
* @return * @return
*/ */
@ApiOperation(value = "获取地区TREE") @ApiOperation(value = "获取地区TREE")
@RequestMapping("/tree/{level}") @GetMapping("/tree/{level}")
public Result<List<RegionVo>> getRegionTreeList(@PathVariable Integer level) { public Result<List<RegionVo>> getRegionTreeList(@PathVariable Integer level) {
return Result.success(regionService.getRegionTreeList(level)); return Result.success(regionService.getRegionTreeList(level));
} }

@ -1,10 +1,21 @@
package com.luoo.user.dao; package com.luoo.user.dao;
import com.luoo.user.pojo.LotteryRegion; import com.luoo.user.pojo.LotteryRegion;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 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<LotteryRegion, String>, public interface LotteryRegionDao extends JpaRepository<LotteryRegion, String>,
JpaSpecificationExecutor<LotteryRegion> { JpaSpecificationExecutor<LotteryRegion> {
@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<LotteryRegion> findByLotteryId(String lotteryId);
} }

@ -1,10 +1,20 @@
package com.luoo.user.dao; package com.luoo.user.dao;
import com.luoo.user.pojo.LotteryUser; import com.luoo.user.pojo.LotteryUser;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface LotteryUserDao extends JpaRepository<LotteryUser, String>, public interface LotteryUserDao extends JpaRepository<LotteryUser, String>,
JpaSpecificationExecutor<LotteryUser> { JpaSpecificationExecutor<LotteryUser> {
public List<LotteryUser> findByLotteryId(String lotteryId);
public List<LotteryUser> findByLotteryIdAndUserIdAndRegionId(String lotteryId, String userId,
Integer regionId);
public List<LotteryUser> findByLotteryIdAndUserId(String lotteryId, String userId);
public List<LotteryUser> findByLotteryIdAndRegionId(String lotteryId, Integer regionId);
} }

@ -5,7 +5,7 @@ import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface RegionDao extends JpaRepository<Region, String>, public interface RegionDao extends JpaRepository<Region, Integer>,
JpaSpecificationExecutor<Region> { JpaSpecificationExecutor<Region> {
List<Region> getRegionsByLevel(Integer level); List<Region> getRegionsByLevel(Integer level);

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

@ -1,13 +1,17 @@
package com.luoo.user.pojo; package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EntityListeners; import javax.persistence.EntityListeners;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@ -16,7 +20,10 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate; 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.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@ -54,13 +61,21 @@ public class Lottery {
@ApiModelProperty(value = "积分") @ApiModelProperty(value = "积分")
private Integer point; 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") @Column(name = "apply_start_time")
@ApiModelProperty(value = "报名开始时间") @ApiModelProperty(value = "报名开始时间")
private Instant applyStartTime; private LocalDateTime applyStartTime;
@Column(name = "apply_end_time") @Column(name = "apply_end_time")
@ApiModelProperty(value = "报名结束时间") @ApiModelProperty(value = "报名结束时间")
private Instant applyEndTime; private LocalDateTime applyEndTime;
@Column(name = "way") @Column(name = "way")
@ApiModelProperty(value = "抽奖方式 1-自动抽奖 2-手动抽奖") @ApiModelProperty(value = "抽奖方式 1-自动抽奖 2-手动抽奖")
@ -77,16 +92,20 @@ public class Lottery {
private String description; private String description;
@Column(name = "status") @Column(name = "status")
@ApiModelProperty(value = "抽奖状态 1-报名中 2-已抽奖 3-已停止") @ApiModelProperty(value = "抽奖状态 0-编辑中 1-报名中 2-已抽奖 3-已停止")
private Integer status; private Integer status;
@Column(name = "create_time") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "创建时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Instant createTime; @ApiModelProperty("创建时间")
@CreatedDate
private LocalDateTime createTime;
@Column(name = "update_time") @ApiModelProperty("修改时间")
@ApiModelProperty(value = "修改时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Instant updateTime; @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@LastModifiedDate
private LocalDateTime updateTime;
@Size(max = 20) @Size(max = 20)
@Column(name = "create_user", length = 20) @Column(name = "create_user", length = 20)
@ -98,4 +117,20 @@ public class Lottery {
@ApiModelProperty(value = "更新人") @ApiModelProperty(value = "更新人")
private String updateUser; 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<LotteryRegion> lotteryRegionList;
} }

@ -1,7 +1,8 @@
package com.luoo.user.pojo; package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.time.Instant; import java.time.LocalDateTime;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EntityListeners; import javax.persistence.EntityListeners;
@ -13,12 +14,13 @@ import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate; 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.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@ -53,13 +55,17 @@ public class LotteryRegion {
@ApiModelProperty(value = "数量") @ApiModelProperty(value = "数量")
private Integer num; 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("创建时间") @ApiModelProperty("创建时间")
private Instant createTime; @CreatedDate
private LocalDateTime createTime;
@Column(name = "update_time")
@ApiModelProperty("修改时间") @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) @Size(max = 20)
@Column(name = "create_user", length = 20) @Column(name = "create_user", length = 20)

@ -1,7 +1,8 @@
package com.luoo.user.pojo; package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.time.Instant; import java.time.LocalDateTime;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EntityListeners; import javax.persistence.EntityListeners;
@ -16,7 +17,10 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate; 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.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@ -57,13 +61,17 @@ public class LotteryUser {
@ApiModelProperty(value = "抽奖结果 1-中奖 2-未中奖") @ApiModelProperty(value = "抽奖结果 1-中奖 2-未中奖")
private Integer result; private Integer result;
@Column(name = "create_time") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "创建时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Instant createTime; @ApiModelProperty("创建时间")
@CreatedDate
private LocalDateTime createTime;
@Column(name = "update_time") @ApiModelProperty("修改时间")
@ApiModelProperty(value = "修改时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Instant updateTime; @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@LastModifiedDate
private LocalDateTime updateTime;
@Size(max = 20) @Size(max = 20)
@Column(name = "create_user", length = 20) @Column(name = "create_user", length = 20)

@ -2,6 +2,7 @@ package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import lombok.*; import lombok.*;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
@ -13,7 +14,6 @@ import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
import java.time.Instant;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@ -54,13 +54,13 @@ public class MembershipCode implements Serializable {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间") @ApiModelProperty("创建时间")
@CreatedDate @CreatedDate
private Instant createTime; private LocalDateTime createTime;
@ApiModelProperty("修改时间") @ApiModelProperty("修改时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@LastModifiedDate @LastModifiedDate
private Instant updateTime; private LocalDateTime updateTime;
@Size(max = 20) @Size(max = 20)
@Column(name = "create_user", length = 20) @Column(name = "create_user", length = 20)

@ -2,8 +2,7 @@ package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.time.Instant; import java.time.LocalDateTime;
import java.util.Objects;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EntityListeners; import javax.persistence.EntityListeners;
@ -58,13 +57,13 @@ public class TaskPoint {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间") @ApiModelProperty("创建时间")
@CreatedDate @CreatedDate
private Instant createTime; private LocalDateTime createTime;
@ApiModelProperty("修改时间") @ApiModelProperty("修改时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@LastModifiedDate @LastModifiedDate
private Instant updateTime; private LocalDateTime updateTime;
@Size(max = 20) @Size(max = 20)
@Column(name = "create_user", length = 20) @Column(name = "create_user", length = 20)

@ -2,6 +2,7 @@ package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import lombok.*; import lombok.*;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate; 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") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@CreatedDate @CreatedDate
private Instant createTime; private LocalDateTime createTime;
@ApiModelProperty(value = "修改时间") @ApiModelProperty(value = "修改时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@LastModifiedDate @LastModifiedDate
private Instant updateTime; private LocalDateTime updateTime;
@ApiModelProperty(value = "创建人") @ApiModelProperty(value = "创建人")
private String createUser; private String createUser;

@ -2,6 +2,7 @@ package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import lombok.*; import lombok.*;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
@ -13,7 +14,6 @@ import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
import java.time.Instant;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@ -59,13 +59,13 @@ public class UserPointLog implements Serializable {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间") @ApiModelProperty("创建时间")
@CreatedDate @CreatedDate
private Instant createTime; private LocalDateTime createTime;
@ApiModelProperty("修改时间") @ApiModelProperty("修改时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@LastModifiedDate @LastModifiedDate
private Instant updateTime; private LocalDateTime updateTime;
@Size(max = 20) @Size(max = 20)
@Column(name = "create_user", length = 20) @Column(name = "create_user", length = 20)

@ -2,6 +2,7 @@ package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import lombok.*; import lombok.*;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.annotation.LastModifiedDate;
@ -13,7 +14,6 @@ import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.Instant;
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor
@ -39,12 +39,12 @@ public class Withdraw implements Serializable {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@CreatedDate @CreatedDate
private Instant createTime; private LocalDateTime createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@LastModifiedDate @LastModifiedDate
private Instant updateTime; private LocalDateTime updateTime;
private String createUser; private String createUser;

@ -1,7 +1,47 @@
package com.luoo.user.service; 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 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.IdWorker;
import util.JwtUtil;
import util.RedisLockUtil;
/** /**
* @program: luoo_parent * @program: luoo_parent
@ -13,4 +53,364 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
public class LotteryService { public class LotteryService {
public static final String POINTS_WILL_BE_RETURNED = "抽奖返积分";
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<LotteryRegion> 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<LotteryRegion> 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<LotteryUser> 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);
}
/**
*
*
* @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<LotteryRegion> lotteryRegionList = lotteryRegionDao.findByLotteryId(id);
lotteryRegionList.forEach(lotteryRegion -> {
Integer num = lotteryRegion.getNum();
if (num > 0) {
List<LotteryUser> lotteryUserList = lotteryUserDao.findByLotteryIdAndRegionId(id,
lotteryRegion.getRegionId());
List<LotteryUser> 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<LotteryUser> drawWinners(List<LotteryUser> participants, int winnersCount) {
List<LotteryUser> 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<Lottery> lotteryPageResult(Integer page, Integer size,
LotterySearchDto lotterySearchDto) {
Sort sort = new Sort(Direction.DESC, "createTime");
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
Specification<Lottery> specification = getSpecification(lotterySearchDto);
Page<Lottery> lotteryPage = lotteryDao.findAll(specification, pageRequest);
long totalElements = lotteryPage.getTotalElements();
return new PageResult<>(totalElements, lotteryPage.getContent());
}
private Specification<Lottery> getSpecification(LotterySearchDto lotterySearchDto) {
return (Root<Lottery> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
List<Predicate> 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()]));
};
}
} }

@ -1,17 +1,15 @@
package com.luoo.user.service; package com.luoo.user.service;
import cn.hutool.core.util.ObjectUtil;
import com.luoo.user.dao.RegionDao; import com.luoo.user.dao.RegionDao;
import com.luoo.user.pojo.Region; import com.luoo.user.pojo.Region;
import com.luoo.user.vo.RegionVo; import com.luoo.user.vo.RegionVo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -36,14 +34,30 @@ public class RegionService {
this.redisTemplate = redisTemplate; 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;
}
/** /**
* 2tree * 2tree
*
* @return * @return
*/ */
public List<RegionVo> getRegionTreeListForTwoLevels() { public List<RegionVo> getRegionTreeListForTwoLevels() {
List<RegionVo> o = (List<RegionVo>) redisTemplate.opsForValue().get(REGION_TREE_LIST_FOR + 2); List<RegionVo> o = (List<RegionVo>) redisTemplate.opsForValue().get(REGION_TREE_LIST_FOR + 2);
if(o == null) { if (o == null) {
o = getRegionTreeList(2); o = getRegionTreeList(2);
redisTemplate.opsForValue().set(REGION_TREE_LIST_FOR + 2, o); redisTemplate.opsForValue().set(REGION_TREE_LIST_FOR + 2, o);
} }
@ -53,12 +67,13 @@ public class RegionService {
/** /**
* tree * tree
*
* @return * @return
*/ */
public List<RegionVo> getRegionTreeListForThreeLevels() { public List<RegionVo> getRegionTreeListForThreeLevels() {
List<RegionVo> o = (List<RegionVo>) redisTemplate.opsForValue().get(REGION_TREE_LIST_FOR + 3); List<RegionVo> o = (List<RegionVo>) redisTemplate.opsForValue().get(REGION_TREE_LIST_FOR + 3);
if(o == null) { if (o == null) {
o = getRegionTreeList(3); o = getRegionTreeList(3);
redisTemplate.opsForValue().set(REGION_TREE_LIST_FOR + 3, o); redisTemplate.opsForValue().set(REGION_TREE_LIST_FOR + 3, o);
} }

@ -130,25 +130,32 @@ public class UserPointLogService {
// 根据积分任务ID获取积分任务详情 // 根据积分任务ID获取积分任务详情
// 保存积分记录 // 保存积分记录
String taskPointId = userPointLog.getTaskPointId(); String taskPointId = userPointLog.getTaskPointId();
TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId);
// 获取积分任务类型 if (taskPointId != null) {
Integer type = taskPoint.getType(); TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId);
// 对于新手任务,只允许完成一次,如果用户已经完成过,则直接返回,不重复添加积分 // 获取积分任务类型
if (Objects.equals(type, PointEnums.TASK_TYPE_NEW.getCode())) { Integer type = taskPoint.getType();
// 新手任务,只触发一次
if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userPointLog.getUserId(), // 对于新手任务,只允许完成一次,如果用户已经完成过,则直接返回,不重复添加积分
userPointLog.getTaskPointId()).isEmpty()) { if (Objects.equals(type, PointEnums.TASK_TYPE_NEW.getCode())) {
return; // 新手任务,只触发一次
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()); // 如果id不存在按传入的增加积分如取消抽奖返还用户积分
userPointLog.setDescription(taskPoint.getDescription());
// 保存用户积分记录
userPointLogDao.save(userPointLog);
// 更新用户积分,获取用户信息并累加积分得分 // 更新用户积分,获取用户信息并累加积分得分
// 对用户进行积分计算 // 对用户进行积分计算
@ -159,6 +166,7 @@ public class UserPointLogService {
// 更新用户积分信息 // 更新用户积分信息
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
} }
/** /**

@ -1,23 +1,28 @@
create table tb_lottery create table tb_lottery
( (
id varchar(20) not null comment 'id' id varchar(20) not null comment 'id'
primary key, primary key,
code varchar(50) null comment '抽奖码', code varchar(50) null comment '抽奖码',
title varchar(255) null comment '抽奖标题', title varchar(255) null comment '抽奖标题',
participant int null comment '可参加人员 1-全部 2-全部会员 3-永久会员 4-贡献者 5-音乐人', participant int null comment '可参加人员 1-全部 2-全部会员 3-永久会员 4-贡献者 5-音乐人',
point int null comment '消耗积分', point int null comment '消耗积分',
apply_start_time datetime null comment '报名开始时间', region_code varchar(255) null comment '抽奖城市code',
apply_end_time datetime null comment '报名结束时间', region_name varchar(255) null comment '抽奖城市名称',
way tinyint null comment '抽奖方式 1-自动抽奖 2-手动抽奖', apply_start_time datetime null comment '报名开始时间',
apply_end_time datetime null comment '报名结束时间',
way tinyint null comment '抽奖方式 1-自动抽奖 2-手动抽奖',
image varchar(255) null comment '抽奖封面url', image varchar(255) null comment '抽奖封面url',
description longtext null comment '演出详情', description longtext null comment '演出详情',
status tinyint null comment '抽奖状态 1-报名中 2-已抽奖 3-已停止', status tinyint null comment '抽奖状态 1-报名中 2-已抽奖 3-已停止',
create_time datetime null comment '创建时间', create_time datetime null comment '创建时间',
update_time datetime null comment '修改时间', update_time datetime null comment '修改时间',
create_user varchar(20) null comment '创建人', create_user varchar(20) null comment '创建人',
update_user varchar(20) null comment '修改人' update_user varchar(20) null comment '修改人',
) 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 create table tb_lottery_region
( (
@ -32,7 +37,6 @@ create table tb_lottery_region
update_user varchar(20) null comment '修改人' update_user varchar(20) null comment '修改人'
) comment '抽奖地区表'; ) comment '抽奖地区表';
create table tb_lottery_user create table tb_lottery_user
( (
id varchar(20) not null comment 'id' id varchar(20) not null comment 'id'

Loading…
Cancel
Save