From cd6ac9a0ac8216177d955b52f5fedfb80108bab5 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Fri, 26 Jul 2024 08:27:37 +0800 Subject: [PATCH] =?UTF-8?q?release:=20=E4=BC=9A=E5=91=98=E7=A0=81=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/MembershipController.java | 15 +++++ .../memberShip/MembershipCodeSearchDto.java | 34 +++++++++++ .../user/service/MembershipCodeService.java | 61 +++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 luoo_user/src/main/java/com/luoo/user/dto/memberShip/MembershipCodeSearchDto.java 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 0a86a54..396f9c4 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 @@ -1,7 +1,10 @@ package com.luoo.user.controller; import annotation.GlobalInterceptor; +import api.PageResult; import api.Result; +import com.luoo.user.dto.memberShip.MembershipCodeSearchDto; +import com.luoo.user.pojo.MembershipCode; import com.luoo.user.service.MembershipCodeService; import controller.BaseController; import io.swagger.annotations.*; @@ -70,4 +73,16 @@ public class MembershipController extends BaseController { 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)); + } } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/memberShip/MembershipCodeSearchDto.java b/luoo_user/src/main/java/com/luoo/user/dto/memberShip/MembershipCodeSearchDto.java new file mode 100644 index 0000000..a2c3f03 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/memberShip/MembershipCodeSearchDto.java @@ -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; + +} \ No newline at end of file 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 6c5ca37..39b1a31 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 @@ -1,16 +1,30 @@ package com.luoo.user.service; +import api.PageResult; import com.luoo.user.dao.MembershipCodeDao; 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.UserInfo; +import com.luoo.user.pojo.UserPointLog; import dto.UserLoginDto; import enums.MembershipEnums; 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; +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; @@ -128,4 +142,51 @@ public class MembershipCodeService { 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()])); + }; + } }