release: 批量生成会员码

release-2024-08-08
huangyw 4 months ago
parent 3b570ce16c
commit b9f3b78d8f

@ -5,6 +5,7 @@ import api.Result;
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.*;
@ -34,11 +35,28 @@ public class MembershipController extends BaseController {
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "duration", value = "会员时长(天)", required = true, dataType = "Integer", paramType = "query")
})
public Result<String> generateMembershipCode(@RequestHeader(value = "Authorization", required = true) String authorization,
public Result<String> generateMembershipCode(
@RequestHeader(value = "Authorization", required = true) String authorization,
@NotNull Integer duration) {
return Result.success(membershipCodeService.generateMembershipCode(authorization, duration));
}
@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<List<String>> generateMembershipCodeBatch(
@RequestHeader(value = "Authorization", required = true) String authorization,
@NotNull Integer duration,
@NotNull Integer count) {
List<String> list = membershipCodeService.generateMembershipCodeBatch(authorization,
duration, count);
return Result.success(list);
}
@ApiOperation(value = "2.绑定会员码", notes = "仅限app用户调用")
@PostMapping("/code/bind")
@ -46,7 +64,8 @@ public class MembershipController extends BaseController {
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "code", value = "会员码", required = true, dataType = "String", paramType = "query")
})
public Result<Void> bindMembershipCode(@RequestHeader(value = "Authorization", required = true) String authorization,
public Result<Void> bindMembershipCode(
@RequestHeader(value = "Authorization", required = true) String authorization,
@NotNull String code) {
membershipCodeService.bindMembershipCode(authorization, code);
return Result.success();

@ -8,6 +8,8 @@ import dto.UserLoginDto;
import enums.MembershipEnums;
import enums.UserVipStatusEnum;
import exception.BizException;
import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -39,7 +41,8 @@ public class MembershipCodeService {
private final UserInfoDao userInfoDao;
public MembershipCodeService(JwtUtil jwtUtil, IdWorker idWorker, MembershipCodeDao membershipCodeDao, UserInfoDao userInfoDao) {
public MembershipCodeService(JwtUtil jwtUtil, IdWorker idWorker,
MembershipCodeDao membershipCodeDao, UserInfoDao userInfoDao) {
this.jwtUtil = jwtUtil;
this.idWorker = idWorker;
this.membershipCodeDao = membershipCodeDao;
@ -47,8 +50,7 @@ public class MembershipCodeService {
}
/**
*
* UUID
* UUID
*
* @param token token
* @param duration
@ -71,6 +73,24 @@ public class MembershipCodeService {
return code;
}
/**
*
*
* @param token token
* @param duration
* @param count
* @return list
*/
@Transactional(rollbackFor = Exception.class)
public List<String> generateMembershipCodeBatch(String token, Integer duration, Integer count) {
List<String> result = new ArrayList<>();
for (int i = 0; i < count; i++) {
String code = generateMembershipCode(token, duration);
result.add(code);
}
return result;
}
/**
*
*
@ -80,7 +100,8 @@ public class MembershipCodeService {
@Transactional(rollbackFor = Exception.class)
public void bindMembershipCode(String token, String code) {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
MembershipCode membershipCode = membershipCodeDao.findMembershipCodeByCodeAndStatus(code, MembershipEnums.CREATED.getCode());
MembershipCode membershipCode = membershipCodeDao.findMembershipCodeByCodeAndStatus(code,
MembershipEnums.CREATED.getCode());
if (membershipCode == null) {
throw new BizException("会员码不存在");
}

Loading…
Cancel
Save