release: 完善积分逻辑

release-2024-08-08
huangyw 4 months ago
parent 8ba3025ddf
commit b9c84e8840

@ -73,7 +73,12 @@ public class DrawLotteryScheduler {
scheduledFuture = taskScheduler.schedule(() -> {
// 这里执行操作
log.info("抽奖{}", id);
try {
drawLotteryService.auto(id, null);
} catch (Exception e) {
e.printStackTrace();
}
}, new Date(System.currentTimeMillis() + delay));
scheduledFutures.put(id, scheduledFuture);
@ -81,7 +86,11 @@ public class DrawLotteryScheduler {
} else {
// 处理时间已过的情况
// 立即抽奖
try {
drawLotteryService.auto(id, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -3,11 +3,9 @@ package com.luoo.user.controller;
import annotation.GlobalInterceptor;
import api.PageResult;
import api.Result;
import com.luoo.user.dto.point.LotteryDto;
import com.luoo.user.dto.point.LotterySearchDto;
import com.luoo.user.dto.point.TaskPointDto;
import com.luoo.user.dto.point.UserPointLogSearchDto;
import com.luoo.user.dto.point.*;
import com.luoo.user.pojo.Lottery;
import com.luoo.user.pojo.LotteryRegion;
import com.luoo.user.pojo.TaskPoint;
import com.luoo.user.pojo.UserPointLog;
import com.luoo.user.service.DrawLotteryService;
@ -26,6 +24,7 @@ import javax.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -219,17 +218,19 @@ public class PointController {
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "lottery", value = "抽奖信息", required = true, dataType = "Lottery", paramType = "body")
@ApiImplicitParam(name = "lotteryAddDto", value = "抽奖信息", required = true, dataType = "LotteryAddDto", paramType = "body")
})
public Result<Void> addLottery(@RequestHeader("Authorization") String token,
@RequestBody Lottery lottery) {
@Validated @RequestBody LotteryAddDto lotteryAddDto) {
Lottery lottery = new Lottery();
BeanUtils.copyProperties(lotteryAddDto, lottery);
lotteryService.add(lottery, token);
return Result.success();
}
@ApiOperation(value = "3.2.抽奖列表页(PC)", notes = "仅限admin权限用户调用")
@ApiOperation(value = "3.2.抽奖列表页(PC/APP)", notes = "admin/app")
@PostMapping("/lottery/list/{page}/{size}")
@GlobalInterceptor(checkAdminLogin = true)
public Result<PageResult<Lottery>> lotteryList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "查询对象") @RequestBody LotterySearchDto lotterySearchDto,
@ -238,35 +239,48 @@ public class PointController {
return Result.success(lotteryService.lotteryPageResult(page, size, lotterySearchDto));
}
@ApiOperation(value = "3.3.编辑抽奖(PC)", notes = "仅限admin权限用户调用")
@ApiOperation(value = "3.3.根据抽奖id获取地区列表(APP)", notes = "仅限app权限用户调用")
@PostMapping("/lottery/region/list")
@GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "lotteryId", value = "抽奖id", required = true, dataType = "String", paramType = "query")
})
public Result<List<LotteryRegion>> getLotteryRegionList(
@RequestHeader("Authorization") String token,
@RequestParam String lotteryId) {
return Result.success(lotteryService.getLotteryRegionList(lotteryId));
}
@ApiOperation(value = "3.4.编辑抽奖(PC)", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/edit")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "lottery", value = "抽奖信息", required = true, dataType = "Lottery", paramType = "body")
@ApiImplicitParam(name = "lotteryUpdateDto", value = "抽奖信息", required = true, dataType = "LotteryUpdateDto", paramType = "body")
})
public Result<Void> editLottery(@RequestHeader("Authorization") String token,
@RequestBody LotteryDto lotteryDto) {
@Validated @RequestBody LotteryUpdateDto lotteryUpdateDto) {
Lottery lottery = new Lottery();
BeanUtils.copyProperties(lotteryDto, lottery);
BeanUtils.copyProperties(lotteryUpdateDto, lottery);
lotteryService.edit(lottery, token);
return Result.success();
}
@ApiOperation(value = "3.4.发布抽奖(PC)", notes = "仅限admin权限用户调用")
@ApiOperation(value = "3.5.发布抽奖(PC)", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/publish")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "body")
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query")
})
public Result<Void> publishLottery(@RequestHeader("Authorization") String token,
@RequestBody String id) {
@RequestParam String id) {
lotteryService.publish(id, token);
return Result.success();
}
@ApiOperation(value = "3.5.停止抽奖(PC)", notes = "仅限admin权限用户调用")
@ApiOperation(value = "3.6.停止抽奖(PC)", notes = "仅限admin权限用户调用")
@PostMapping("/lottery/stop")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({
@ -280,19 +294,19 @@ public class PointController {
return Result.success();
}
@ApiOperation(value = "3.6.参与抽奖(APP)")
@ApiOperation(value = "3.7.参与抽奖(APP)")
@PostMapping("/lottery/participate")
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "id", value = "抽奖id", required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "regionId", value = "区域id", required = true, dataType = "String", paramType = "query")
@ApiImplicitParam(name = "regionId", value = "区域id", required = true, dataType = "Integer", paramType = "query")
})
public Result<Void> participate(@RequestHeader("Authorization") String token, @NotNull String id, @NotNull Integer regionId) {
lotteryService.participate(id, token, regionId);
return Result.success();
}
@ApiOperation(value = "3.7.自动抽奖结果(PC)", notes = "用这个方法主动触发自动抽奖结果")
@ApiOperation(value = "3.8.自动抽奖结果(PC)", notes = "用这个方法主动触发自动抽奖结果")
@PostMapping("/lottery/auto")
@GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({

@ -11,7 +11,7 @@ public interface LotteryRegionDao extends JpaRepository<LotteryRegion, String>,
JpaSpecificationExecutor<LotteryRegion> {
@Modifying
@Query(value = "DELETE FROM tb_lottery_region js WHERE js.lottery_id = :lotteryId", nativeQuery = true)
@Query(value = "DELETE FROM tb_lottery_region WHERE lottery_id = ?", nativeQuery = true)
public void deleteByLotteryId(String lotteryId);
public LotteryRegion findByLotteryIdAndRegionId(String lotteryId, Integer regionId);

@ -0,0 +1,85 @@
package com.luoo.user.dto.point;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.luoo.user.pojo.LotteryRegion;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/**
* DTO for {@link com.luoo.user.pojo.Lottery}
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class LotteryAddDto implements Serializable {
@ApiModelProperty(value = "标题")
@NotBlank
private String title;
@ApiModelProperty(value = "抽奖类型 1-门票抽奖 2-实物抽奖")
@NotNull
private Integer type;
@ApiModelProperty(value = "奖品总数量")
private Integer num;
@ApiModelProperty(value = "可参加人员 1-全部 2-全部会员 3-永久会员 4-贡献者")
@NotNull
private Integer participant;
@ApiModelProperty(value = "积分")
@NotNull
private Integer point;
@ApiModelProperty(value = "地区编码")
private String regionCode;
@ApiModelProperty(value = "地区名称")
private String regionName;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "报名开始时间")
@NotNull
private LocalDateTime applyStartTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "报名结束时间")
@NotNull
private LocalDateTime applyEndTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "抽奖时间")
@NotNull
private LocalDateTime drawTime;
@ApiModelProperty(value = "抽奖方式 1-自动抽奖 2-手动抽奖")
@NotNull
private Integer way;
@ApiModelProperty(value = "抽奖封面url")
@NotBlank
private String image;
@ApiModelProperty(value = "抽奖描述")
@NotBlank
private String description;
@ApiModelProperty(value = "抽奖地区列表")
private List<LotteryRegion> lotteryRegionList;
}

@ -9,6 +9,8 @@ import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
@ -19,27 +21,33 @@ import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LotteryDto implements Serializable {
public class LotteryUpdateDto implements Serializable {
@ApiModelProperty(value = "主键")
@NotBlank
private String id;
@ApiModelProperty(value = "抽奖编码")
@NotBlank
private String code;
@ApiModelProperty(value = "标题")
@NotBlank
private String title;
@ApiModelProperty(value = "抽奖类型 1-门票抽奖 2-实物抽奖")
@NotNull
private Integer type;
@ApiModelProperty(value = "奖品总数量")
private Integer num;
@ApiModelProperty(value = "可参加人员 1-全部 2-全部会员 3-永久会员 4-贡献者")
@NotNull
private Integer participant;
@ApiModelProperty(value = "积分")
@NotNull
private Integer point;
@ApiModelProperty(value = "地区编码")
@ -51,34 +59,40 @@ public class LotteryDto implements Serializable {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "报名开始时间")
@NotNull
private LocalDateTime applyStartTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "报名结束时间")
@NotNull
private LocalDateTime applyEndTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "抽奖时间")
@NotNull
private LocalDateTime drawTime;
@ApiModelProperty(value = "抽奖方式 1-自动抽奖 2-手动抽奖")
@NotNull
private Integer way;
@ApiModelProperty(value = "抽奖封面url")
@NotBlank
private String image;
@ApiModelProperty(value = "抽奖描述")
@NotBlank
private String description;
@ApiModelProperty(value = "抽奖状态 0-编辑中 1-报名中 2-已抽奖 3-已停止")
@NotNull
private Integer status;
@ApiModelProperty(value = "停止原因")
private String stopReason;
@Transient
@ApiModelProperty(value = "抽奖地区列表")
private List<LotteryRegion> lotteryRegionList;
}

@ -75,9 +75,9 @@ public class UserRespDTO implements Serializable {
private Integer enablePush;
/**
* 0- 1- 2-
* 0- 1- 2- 3-
*/
@ApiModelProperty(value = "会员状态 0-未开通 1-生效中 2-已过期")
@ApiModelProperty(value = "会员状态 0-未开通 1-生效中 2-已过期 3-永久会员")
private Integer vipStatus;
/**

@ -3,11 +3,7 @@ package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.AllArgsConstructor;
@ -77,4 +73,8 @@ public class LotteryRegion {
@ApiModelProperty(value = "更新人")
private String updateUser;
@Transient
@ApiModelProperty(value = "区域")
private Region region;
}

@ -20,6 +20,8 @@ import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
@ -30,7 +32,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@DynamicUpdate
@Table(name = "tb_region")
@EntityListeners(AuditingEntityListener.class)
public class Region {
public class Region implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)

@ -191,7 +191,7 @@ public class UserInfo implements Serializable {
private Integer type;
/**
* 0- 1- 2-
* 0- 1- 2- 3-
*/
private Integer vipStatus;

@ -110,7 +110,7 @@ public class LotteryService {
// 门票抽奖,城市必填
List<LotteryRegion> lotteryRegionList = lottery.getLotteryRegionList();
if (lotteryRegionList.isEmpty()) {
if (lotteryRegionList == null || lotteryRegionList.isEmpty()) {
throw new BizException(ErrorConstants.TICKET_CITY_IS_REQUIRED);
}
@ -121,8 +121,8 @@ public class LotteryService {
regionName.append(regionById.getName()).append(",");
num += lotteryRegion.getNum();
lotteryRegion.setId(id);
lotteryRegion.setLotteryId(lottery.getId());
lotteryRegion.setId(String.valueOf(idWorker.nextId()));
lotteryRegion.setLotteryId(id);
lotteryRegion.setCreateUser(userLoginDto.getUserId());
lotteryRegion.setUpdateUser(userLoginDto.getUserId());
@ -161,6 +161,10 @@ public class LotteryService {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
if(lottery.getStatus() != null && !Objects.equals(lottery.getStatus(), PointEnums.LOTTERY_STATUS_EDITING.getCode())) {
throw new BizException(ErrorConstants.CAN_NOT_EDIT);
}
String id = lottery.getId();
StringBuilder regionCode = new StringBuilder();
@ -170,7 +174,7 @@ public class LotteryService {
// 门票抽奖,城市必填
List<LotteryRegion> lotteryRegionList = lottery.getLotteryRegionList();
if (lotteryRegionList.isEmpty()) {
if (lotteryRegionList == null || lotteryRegionList.isEmpty()) {
throw new BizException(ErrorConstants.TICKET_CITY_IS_REQUIRED);
}
@ -256,6 +260,7 @@ public class LotteryService {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
Lottery lottery = lotteryDao.findById(id).orElse(null);
lottery.setStatus(PointEnums.LOTTERY_STATUS_STOP.getCode());
lottery.setUpdateUser(userLoginDto.getUserId());
lottery.setUpdateUserName(userLoginDto.getNickName());
lottery.setStopReason(stopReason);
@ -406,4 +411,20 @@ public class LotteryService {
};
}
/**
* id
*
* @param lotteryId id
* @return
*/
public List<LotteryRegion> getLotteryRegionList(String lotteryId) {
List<LotteryRegion> lotteryRegionList = lotteryRegionDao.findByLotteryId(lotteryId);
lotteryRegionList.forEach(lotteryRegion -> {
Region region = regionService.getRegionById(lotteryRegion.getRegionId());
lotteryRegion.setRegion(region);
});
return lotteryRegionList;
}
}

@ -36,7 +36,7 @@ create table tb_user_point_log
alter table tb_user_info
add vip_status tinyint default 0 not null comment '会员状态 0-未开通 1-生效中 2-已过期';
add vip_status tinyint default 0 not null comment '会员状态 0-未开通 1-生效中 2-已过期 3-永久会员';
alter table tb_user_info
add vip_expire_time date null comment '会员到期时间';

@ -7,3 +7,11 @@ alter table tb_user_info
alter table tb_user_info
add invitation_user_id varchar(20) null comment '邀请人';
create index tb_user_point_log_task_point_id_index
on tb_user_point_log (task_point_id);
create index tb_user_point_log_user_id_index
on tb_user_point_log (user_id);

Loading…
Cancel
Save