release: 会员码分页查询

release-2024-08-08
huangyw 4 months ago
parent b9f3b78d8f
commit cd6ac9a0ac

@ -1,7 +1,10 @@
package com.luoo.user.controller; package com.luoo.user.controller;
import annotation.GlobalInterceptor; import annotation.GlobalInterceptor;
import api.PageResult;
import api.Result; import api.Result;
import com.luoo.user.dto.memberShip.MembershipCodeSearchDto;
import com.luoo.user.pojo.MembershipCode;
import com.luoo.user.service.MembershipCodeService; import com.luoo.user.service.MembershipCodeService;
import controller.BaseController; import controller.BaseController;
import io.swagger.annotations.*; import io.swagger.annotations.*;
@ -70,4 +73,16 @@ public class MembershipController extends BaseController {
membershipCodeService.bindMembershipCode(authorization, code); membershipCodeService.bindMembershipCode(authorization, code);
return Result.success(); return Result.success();
} }
@ApiOperation(value = "3.查询会员码", notes = "仅限admin权限用户调用")
@GetMapping("/code/list")
@GlobalInterceptor(checkAdminLogin = true)
public Result<PageResult<MembershipCode>> 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));
}
} }

@ -0,0 +1,34 @@
package com.luoo.user.dto.memberShip;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* DTO for {@link com.luoo.user.pojo.MembershipCode}
*/
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
public class MembershipCodeSearchDto implements Serializable {
@ApiModelProperty(value = "会员码")
private String code;
@ApiModelProperty(value = "状态 1-已生成 2-已绑定 3-已退款 4-已废弃")
private Integer status;
@ApiModelProperty(value = "时长")
private Integer duration;
@ApiModelProperty(value = "用户id")
private String userId;
@ApiModelProperty(value = "创建人")
private String createUser;
}

@ -1,16 +1,30 @@
package com.luoo.user.service; package com.luoo.user.service;
import api.PageResult;
import com.luoo.user.dao.MembershipCodeDao; import com.luoo.user.dao.MembershipCodeDao;
import com.luoo.user.dao.UserInfoDao; import com.luoo.user.dao.UserInfoDao;
import com.luoo.user.dto.memberShip.MembershipCodeSearchDto;
import com.luoo.user.dto.point.UserPointLogSearchDto;
import com.luoo.user.pojo.MembershipCode; import com.luoo.user.pojo.MembershipCode;
import com.luoo.user.pojo.UserInfo; import com.luoo.user.pojo.UserInfo;
import com.luoo.user.pojo.UserPointLog;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.MembershipEnums; import enums.MembershipEnums;
import enums.UserVipStatusEnum; import enums.UserVipStatusEnum;
import exception.BizException; import exception.BizException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
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 org.springframework.transaction.annotation.Transactional;
import util.IdWorker; import util.IdWorker;
@ -128,4 +142,51 @@ public class MembershipCodeService {
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
} }
public PageResult<MembershipCode> 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<MembershipCode> specification = buildSearchSpecification(membershipCodeSearchDto);
Page<MembershipCode> membershipCodePage = membershipCodeDao.findAll(specification, pageRequest);
long totalElements = membershipCodePage.getTotalElements();
return new PageResult<>(totalElements, membershipCodePage.getContent());
}
private Specification<MembershipCode> buildSearchSpecification(MembershipCodeSearchDto param) {
return (Root<MembershipCode> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<Predicate>();
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()]));
};
}
} }

Loading…
Cancel
Save