From 0ba6c3dc4417b3a2178fbbc902b230d193512368 Mon Sep 17 00:00:00 2001 From: huangyawei Date: Wed, 29 May 2024 19:23:56 +0800 Subject: [PATCH] =?UTF-8?q?release-=20=E6=96=B0=E5=A2=9E=E8=A1=A8tb=5Farti?= =?UTF-8?q?st=5Fregister=EF=BC=8C=E4=B8=8D=E5=86=8D=E5=81=9A=E5=A4=8D?= =?UTF-8?q?=E6=9D=82=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/constants/ErrorConstants.java | 2 + .../user/controller/ArtistController.java | 11 +- .../com/luoo/user/dao/ArtistRegisterDao.java | 27 ++ .../user/dto/artist/ArtistRegisterDto.java | 4 +- .../luoo/user/dto/artist/ArtistSearchDto.java | 17 + .../com/luoo/user/pojo/ArtistRegister.java | 109 ++++++ .../com/luoo/user/service/ArtistService.java | 310 ++++++++---------- luoo_user/src/main/resources/sql/20240529.sql | 21 ++ 8 files changed, 321 insertions(+), 180 deletions(-) create mode 100644 luoo_user/src/main/java/com/luoo/user/dao/ArtistRegisterDao.java create mode 100644 luoo_user/src/main/java/com/luoo/user/pojo/ArtistRegister.java create mode 100644 luoo_user/src/main/resources/sql/20240529.sql diff --git a/luoo_common/src/main/java/constants/ErrorConstants.java b/luoo_common/src/main/java/constants/ErrorConstants.java index bc41f6f..bf967f1 100644 --- a/luoo_common/src/main/java/constants/ErrorConstants.java +++ b/luoo_common/src/main/java/constants/ErrorConstants.java @@ -52,4 +52,6 @@ public class ErrorConstants { public final static String USER_ALREADY_EXISTS_ARTIST = "用户已发起过音乐人审核"; public final static String USER_STATUS_ERROR = "用户状态错误"; + + public final static String USER_NAME_ALREADY_EXISTS = "用户名已存在"; } diff --git a/luoo_user/src/main/java/com/luoo/user/controller/ArtistController.java b/luoo_user/src/main/java/com/luoo/user/controller/ArtistController.java index 3278725..73dcd6c 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/ArtistController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/ArtistController.java @@ -7,6 +7,7 @@ import com.luoo.user.dto.artist.ArtistRegisterDto; import com.luoo.user.dto.artist.ArtistSearchDto; import com.luoo.user.dto.artist.ArtistUserBindDto; import com.luoo.user.pojo.ArtistInfo; +import com.luoo.user.pojo.ArtistRegister; import com.luoo.user.pojo.UserProcess; import com.luoo.user.service.ArtistService; import io.swagger.annotations.Api; @@ -84,15 +85,9 @@ public class ArtistController { return Result.success(artistService.getList(artistSearchDto, page, size)); } - @ApiOperation(value = "上一次申请的记录", notes = "上一次申请的记录-音乐人注册审批失败后可以自动带出上一次审批填写的数据") + @ApiOperation(value = "上一次申请的记录", notes = "上一次申请的记录:申请状态 0-待审批 1-审批通过 2-审批不通过") @GetMapping("/last/apply/record") - public Result lastApplyRecord(@ApiParam(value = "Header中的token信息", required = true) String token) { - return Result.success(artistService.lastApplyRecord(token)); - } - - @ApiOperation(value = "当前申请的状态", notes = "当前申请的状态-申请状态 0-待审批 1-审批通过 2-审批失败") - @GetMapping("/last/apply/result") - public Result lastApplyResult(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token) { + public Result lastApplyRecord(@ApiParam(value = "Header中的token信息", required = true) String token) { return Result.success(artistService.lastApplyResult(token)); } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/ArtistRegisterDao.java b/luoo_user/src/main/java/com/luoo/user/dao/ArtistRegisterDao.java new file mode 100644 index 0000000..248e331 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dao/ArtistRegisterDao.java @@ -0,0 +1,27 @@ +package com.luoo.user.dao; + +import com.luoo.user.pojo.ArtistRegister; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +import java.util.List; + +/** + * @Author: yawei.huang + * @Package: com.luoo.user.dao + * @Project: luoo_parent + * @Date: 2024/5/29 18:47 + * @Filename: ArtistRegisterDao + * @Describe: + */ +public interface ArtistRegisterDao extends JpaRepository, JpaSpecificationExecutor { + + List findAllByCreateUser(String createUser); + + List findAllByUserName(String userName); + + List findAllByUserNameAndIdNot(String userName, String id); + + ArtistRegister findArtistRegisterByCreateUserOrderByCreateTime(String createUser); + +} diff --git a/luoo_user/src/main/java/com/luoo/user/dto/artist/ArtistRegisterDto.java b/luoo_user/src/main/java/com/luoo/user/dto/artist/ArtistRegisterDto.java index 9966caa..05a1c4e 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/artist/ArtistRegisterDto.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/artist/ArtistRegisterDto.java @@ -24,8 +24,8 @@ import java.io.Serializable; @Data public class ArtistRegisterDto implements Serializable { - @ApiModelProperty("用户表id,如果是再次发起审批必填") - private String userId; + @ApiModelProperty("id,如果是再次发起审批必填") + private String id; @ApiModelProperty("歌手名") @NotBlank(message = "歌手名必填") diff --git a/luoo_user/src/main/java/com/luoo/user/dto/artist/ArtistSearchDto.java b/luoo_user/src/main/java/com/luoo/user/dto/artist/ArtistSearchDto.java index 29a43fa..e0c3879 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/artist/ArtistSearchDto.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/artist/ArtistSearchDto.java @@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; +import java.time.LocalDate; +import java.time.LocalDateTime; /** * @Author: yawei.huang @@ -18,4 +20,19 @@ public class ArtistSearchDto implements Serializable { @ApiModelProperty(value = "申请状态 0-待审批 1-审批通过 2-审批失败") private Integer status; + + @ApiModelProperty(value = "搜索内容") + private String searchStr; + + @ApiModelProperty(value = "音乐人类型") + private Integer type; + + @ApiModelProperty(value = "流派风格-tag表id") + private String style; + + @ApiModelProperty(value = "申请开始时间") + private LocalDateTime startTime; + + @ApiModelProperty(value = "申请结束时间") + private LocalDateTime endTime; } diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/ArtistRegister.java b/luoo_user/src/main/java/com/luoo/user/pojo/ArtistRegister.java new file mode 100644 index 0000000..0d2a99a --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/pojo/ArtistRegister.java @@ -0,0 +1,109 @@ +package com.luoo.user.pojo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Date; + +/** + * @Author: yawei.huang + * @Package: com.luoo.user.pojo + * @Project: luoo_parent + * @Date: 2024/5/29 18:38 + * @Filename: ArtistRegister + * @Describe: + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode +@Builder +@Entity +@Table(name="tb_artist_register") +public class ArtistRegister implements Serializable { + @Id + @ApiModelProperty("id") + private String id; + + @ApiModelProperty("歌手名") + @NotBlank(message = "歌手名必填") + private String nickName; + + @ApiModelProperty("艺人头像") + @NotBlank(message = "艺人头像必填") + private String avatar; + + @ApiModelProperty("主页背景") + private String backgroundImage; + + @ApiModelProperty("播放器音乐人管理后台实时截图") + @NotBlank(message = "后台截图必填") + private String screenshot; + + @ApiModelProperty("所在地区") + @NotBlank(message = "所在地区必填") + private String address; + + @ApiModelProperty("流派风格") + @NotBlank(message = "流派风格必填") + private String style; + + @ApiModelProperty("艺人类型") + @NotNull(message = "艺人类型必填") + private Integer type; + + @ApiModelProperty("艺人简介") + @NotBlank(message = "艺人简介必填") + private String description; + + @ApiModelProperty("所属公司/厂牌") + private String bandUserId; + + @ApiModelProperty("登录用户名") + @NotBlank(message = "用户名必填") + private String userName; + + @ApiModelProperty("密码") + @NotBlank(message = "密码必填") + private String password; + + @ApiModelProperty("用户表id") + private String userId; + + @ApiModelProperty("音乐人表id") + private String artistId; + + @ApiModelProperty("申请状态 0-待审批 1-审批通过 2-审批不通过") + private Integer status; + + @ApiModelProperty("拒绝理由") + private String content; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty("创建时间") + @CreatedDate + private Date createTime; + + @ApiModelProperty("修改时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @LastModifiedDate + private Date modifyTime; + + @ApiModelProperty("创建人") + private String createUser; + + @ApiModelProperty("修改人") + private String updateUser; +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/ArtistService.java b/luoo_user/src/main/java/com/luoo/user/service/ArtistService.java index 7da499c..3cfe175 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/ArtistService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/ArtistService.java @@ -1,18 +1,12 @@ package com.luoo.user.service; import api.PageResult; -import com.luoo.user.dao.ArtistInfoDao; -import com.luoo.user.dao.ArtistUserDao; -import com.luoo.user.dao.UserInfoDao; -import com.luoo.user.dao.UserProcessDao; +import com.luoo.user.dao.*; import com.luoo.user.dto.UserProcessApproveDto; import com.luoo.user.dto.artist.ArtistRegisterDto; import com.luoo.user.dto.artist.ArtistSearchDto; import com.luoo.user.dto.artist.ArtistUserBindDto; -import com.luoo.user.pojo.ArtistInfo; -import com.luoo.user.pojo.ArtistUser; -import com.luoo.user.pojo.UserInfo; -import com.luoo.user.pojo.UserProcess; +import com.luoo.user.pojo.*; import constants.Constants; import constants.ErrorConstants; import dto.UserLoginDto; @@ -25,16 +19,24 @@ import exception.BizException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.domain.Specification; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import util.IdWorker; import util.JwtUtil; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -65,136 +67,69 @@ public class ArtistService { @Autowired private ArtistUserDao artistUserDao; - @Autowired - private UserProcessDao userProcessDao; - @Autowired private UserMessageService userMessageService; @Autowired private JwtUtil jwtUtil; + @Autowired + private ArtistRegisterDao artistRegisterDao; + /** * 音乐人注册 - * */ @Transactional(rollbackFor = Exception.class) public void artistRegister(String token, ArtistRegisterDto artistRegisterDto) { UserLoginDto currentUser = jwtUtil.getUserLoginDto(token); - UserInfo userInfo; - if (currentUser == null) { - // 用户校验失败,请重新登录 - throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE); - } - - if(StringUtils.isNotBlank(artistRegisterDto.getUserId())) { - // 重新发起音乐人账号审批 - UserInfo info = userInfoDao.findById(artistRegisterDto.getUserId()).get(); - if(ObjectUtils.notEqual(artistRegisterDto.getUserName(), info.getUserName())) { - throw new BizException("用户名不允许修改"); - } - Integer count = userInfoDao.countByUserNameAndUserNameNotNullAndIdNot(artistRegisterDto.getUserName(), artistRegisterDto.getUserId()); - if (count > 0) { - throw new BizException("该用户名已存在,请重新输入!"); - } - userInfo = UserInfo.builder() - .id(info.getId()) - .nickName(artistRegisterDto.getNickName()) - .avatar(artistRegisterDto.getAvatar()) - .joinTime(new Date()) - .status(UserStatusEnum.UNAPPROVED.getStatus()) - .thumbnail(Constants.DEFAULT_USER_THUMBNAIL) - .signature(Constants.DEFAULT_USER_SIGNATURE) - .userName(artistRegisterDto.getUserName()) - .type(artistRegisterDto.getType()) - .password(encoder.encode(artistRegisterDto.getPassword())) - .build(); - userInfoDao.save(userInfo); - - ArtistInfo artistInfoByUserId = artistInfoDao.findArtistInfoByUserId(artistRegisterDto.getUserId()); - - // 新增音乐人基本信息 - ArtistInfo artistInfo = ArtistInfo.builder() - .id(artistInfoByUserId != null ? artistInfoByUserId.getId() : String.valueOf(idWorker.nextId())) - .userId(userInfo.getId()) - .backgroundImage(artistRegisterDto.getBackgroundImage()) - .address(artistRegisterDto.getAddress()) - .style(artistRegisterDto.getStyle()) - .bandUserId(artistRegisterDto.getBandUserId()) - .build(); - artistInfoDao.save(artistInfo); - - } else { + String id = artistRegisterDto.getId(); + if (StringUtils.isNotBlank(id)) { // 新增音乐人账号 - // 目前一个用户只能新增一个音乐人账号 - UserProcess currentUserProcess = userProcessDao.findUserProcessByCreateUserAndTypeOrderByCreateTime(currentUser.getUserId(), UserProcessTypeEnum.ARTIST.getCode()); - if(currentUserProcess != null) { + // 一个用户只能新增一个音乐人账号 + List list = artistRegisterDao.findAllByCreateUser(currentUser.getUserId()); + if (!list.isEmpty()) { // 用户已存在音乐人账号 throw new BizException(ErrorConstants.USER_ALREADY_EXISTS_ARTIST); } - Integer count = userInfoDao.countByUserNameAndUserNameNotNull(artistRegisterDto.getUserName()); - if (count > 0) { - throw new BizException("该用户名已存在,请重新输入!"); - } - // 新增用户基本信息 - userInfo = UserInfo.builder() - .id(String.valueOf(idWorker.nextId())) - .nickName(artistRegisterDto.getNickName()) - .avatar(artistRegisterDto.getAvatar()) - .joinTime(new Date()) - .status(UserStatusEnum.UNAPPROVED.getStatus()) - .thumbnail(Constants.DEFAULT_USER_THUMBNAIL) - .signature(Constants.DEFAULT_USER_SIGNATURE) - .userName(artistRegisterDto.getUserName()) - .type(artistRegisterDto.getType()) - .password(encoder.encode(artistRegisterDto.getPassword())) - .build(); - userInfoDao.save(userInfo); - // 新增音乐人基本信息 - ArtistInfo artistInfo = ArtistInfo.builder() - .id(String.valueOf(idWorker.nextId())) - .userId(userInfo.getId()) - .backgroundImage(artistRegisterDto.getBackgroundImage()) - .address(artistRegisterDto.getAddress()) - .style(artistRegisterDto.getStyle()) - .bandUserId(artistRegisterDto.getBandUserId()) - .build(); - artistInfoDao.save(artistInfo); + List allByUserName = artistRegisterDao.findAllByUserName(artistRegisterDto.getUserName()); + if (!allByUserName.isEmpty()) { + // 用户名已存在 + throw new BizException(ErrorConstants.USER_NAME_ALREADY_EXISTS); + } + ArtistRegister artistRegister = new ArtistRegister(); + BeanUtils.copyProperties(artistRegisterDto, artistRegister); + // 未审核状态 + artistRegister.setStatus(UserProcessStatusEnum.UNAPPROVED.getCode()); + // 创建人 + artistRegister.setCreateUser(currentUser.getUserId()); + // 密码加密 + artistRegister.setPassword(encoder.encode(artistRegisterDto.getPassword())); + artistRegisterDao.save(artistRegister); + } else { + // 拒绝后重新发起音乐人账号审批 + // 判断当前是否是拒绝状态 + ArtistRegister artistRegister = artistRegisterDao.findById(id).get(); + if (ObjectUtils.notEqual(UserProcessStatusEnum.FAIL.getCode(), artistRegister.getStatus())) { + throw new BizException(ErrorConstants.STATE_ERROR); + } - } + List allByUserName = artistRegisterDao.findAllByUserNameAndIdNot(artistRegisterDto.getUserName(), id); + if (!allByUserName.isEmpty()) { + // 用户名已存在 + throw new BizException(ErrorConstants.USER_NAME_ALREADY_EXISTS); + } - // 新增音乐人负责人信息 -// ArtistResponsible artistResponsible = ArtistResponsible.builder() -// .id(String.valueOf(idWorker.nextId())) -// .userId(userInfo.getId()) -// .sex(artistRegisterDto.getSex()) -// .name(artistRegisterDto.getNickName()) -// .mobile(artistRegisterDto.getMobile()) -// .build(); -// artistResponsibleDao.save(artistResponsible); - - // 审核记录 - List successList = userProcessDao.findUserProcessByUserIdAndTypeAndStatus(userInfo.getId(), UserProcessTypeEnum.ARTIST.getCode(), UserProcessStatusEnum.SUCCESS.getCode()); - if (!successList.isEmpty()) { - throw new BizException("该账号已审核通过,请勿重复申请"); + BeanUtils.copyProperties(artistRegisterDto, artistRegister); + // 未审核状态 + artistRegister.setStatus(UserProcessStatusEnum.UNAPPROVED.getCode()); + // 创建人 + artistRegister.setCreateUser(currentUser.getUserId()); + // 密码加密 + artistRegister.setPassword(encoder.encode(artistRegisterDto.getPassword())); + artistRegisterDao.save(artistRegister); } - List upApprovedList = userProcessDao.findUserProcessByUserIdAndTypeAndStatus(userInfo.getId(), UserProcessTypeEnum.ARTIST.getCode(), UserProcessStatusEnum.UNAPPROVED.getCode()); - if (!upApprovedList.isEmpty()) { - throw new BizException("该账号正在审核中,请勿重复申请"); - } - - UserProcess userProcess = UserProcess.builder() - .id(String.valueOf(idWorker.nextId())) - .userId(userInfo.getId()) - .type(UserProcessTypeEnum.ARTIST.getCode()) - .status(UserProcessStatusEnum.UNAPPROVED.getCode()) - .createTime(new Date()) - .createUser(currentUser.getUserId()) - .build(); - - userProcessDao.save(userProcess); } @@ -227,27 +162,50 @@ public class ArtistService { throw new BizException("请填写拒绝理由!"); } - UserProcess userProcessById = userProcessDao.findUserProcessById(userProcessApproveDto.getId()); - userProcessById.setContent(userProcessApproveDto.getContent()); - userProcessById.setModifyTime(new Date()); - userProcessById.setStatus(userProcessApproveDto.getStatus()); + ArtistRegister artistRegister = artistRegisterDao.findById(userProcessApproveDto.getId()).get(); + artistRegister.setStatus(userProcessApproveDto.getStatus()); + artistRegister.setContent(userProcessApproveDto.getContent()); + artistRegister.setModifyTime(new Date()); + artistRegisterDao.save(artistRegister); - userProcessDao.save(userProcessById); + if (ObjectUtils.equals(UserProcessStatusEnum.SUCCESS.getCode(), userProcessApproveDto.getStatus())) { + // 审核通过 + // 新增用户基本信息,直接是启用状态 + UserInfo userInfo = UserInfo.builder() + .id(String.valueOf(idWorker.nextId())) + .nickName(artistRegister.getNickName()) + .avatar(artistRegister.getAvatar()) + .joinTime(new Date()) + .status(UserStatusEnum.ENABLE.getStatus()) + .thumbnail(Constants.DEFAULT_USER_THUMBNAIL) + .signature(Constants.DEFAULT_USER_SIGNATURE) + .userName(artistRegister.getUserName()) + .type(artistRegister.getType()) + .password(artistRegister.getPassword()) + .build(); + userInfoDao.save(userInfo); - UserInfo userInfo = userInfoDao.findById(userProcessById.getUserId()).get(); - userInfo.setStatus(ObjectUtils.equals(UserProcessStatusEnum.FAIL.getCode(), userProcessApproveDto.getStatus()) ? - UserStatusEnum.DISABLE.getStatus() : UserStatusEnum.ENABLE.getStatus()); - userInfo.setModifyTime(new Date()); - userInfoDao.save(userInfo); + // 新增音乐人基本信息 + ArtistInfo artistInfo = ArtistInfo.builder() + .id(String.valueOf(idWorker.nextId())) + .userId(userInfo.getId()) + .backgroundImage(artistRegister.getBackgroundImage()) + .address(artistRegister.getAddress()) + .style(artistRegister.getStyle()) + .bandUserId(artistRegister.getBandUserId()) + .build(); + artistInfoDao.save(artistInfo); + } + UserInfo sendUser = userInfoDao.findById(artistRegister.getCreateUser()).get(); UserMessageDto userMessageDto = new UserMessageDto(); userMessageDto.setType(MessageTypeEnum.PRIVATE_MESSAGE.getType()); - userMessageDto.setSendUserId(userInfo.getId()); + userMessageDto.setSendUserId(sendUser.getId()); userMessageDto.setTitle(title); userMessageDto.setContent(content); - userMessageDto.setUserId(userProcessById.getCreateUser()); - userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar()); - userMessageDto.setSendUserNickName(userInfo.getNickName()); + userMessageDto.setUserId(artistRegister.getCreateUser()); + userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX + sendUser.getAvatar()); + userMessageDto.setSendUserNickName(sendUser.getNickName()); userMessageService.sendUserMessage(userMessageDto); } @@ -288,60 +246,72 @@ public class ArtistService { /** * 分页显示音乐人列表 - * */ - public PageResult getList(ArtistSearchDto artistSearchDto, Integer page, Integer size) { - Pageable pageable = PageRequest.of(page - 1, size); - Page artistInfoPage; - if(artistSearchDto.getStatus() == null) { - artistInfoPage = artistInfoDao.findAllNoStatus(pageable); - } else { - artistInfoPage = artistInfoDao.findAllByStatus(artistSearchDto.getStatus(), pageable); - } - long totalElements = artistInfoPage.getTotalElements(); - return new PageResult<>(totalElements, artistInfoPage.getContent()); + public PageResult getList(ArtistSearchDto artistSearchDto, Integer page, Integer size) { + Sort sort = new Sort(Sort.Direction.DESC, "createTime"); + PageRequest pageRequest = PageRequest.of(page - 1, size, sort); + + Specification artistRegisterDtoSpecification = buildSearchSpecification(artistSearchDto); + Page artistRegisterPage = artistRegisterDao.findAll(artistRegisterDtoSpecification, pageRequest); + + long totalElements = artistRegisterPage.getTotalElements(); + return new PageResult<>(totalElements, artistRegisterPage.getContent()); } /** - * 获取上一次申请的审批状态 + * 检索条件 * + * @param param 查询对象 + * @return 检索条件 */ - public UserProcess lastApplyResult(String token) { - UserLoginDto user = jwtUtil.getUserLoginDto(token); - if (user == null) { - throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE); - } + private Specification buildSearchSpecification(ArtistSearchDto param) { + return (Root root, CriteriaQuery query, CriteriaBuilder builder) -> { + List predicateList = new ArrayList(); + + if (param.getType() != null) { + predicateList.add(builder.and(builder.equal(root.get("type"), param.getType()))); + } + + if (param.getStatus() != null) { + predicateList.add(builder.and(builder.equal(root.get("status"), param.getStatus()))); + } + + if (StringUtils.isNotBlank(param.getSearchStr())) { + // 专辑名称 + String likeExpression = "%" + param.getSearchStr() + "%"; + predicateList.add(builder.and(builder.like(root.get("nickName"), likeExpression))); + } - return userProcessDao.findUserProcessByCreateUserAndTypeOrderByCreateTime(user.getUserId(), UserProcessTypeEnum.ARTIST.getCode()); + if (StringUtils.isNotBlank(param.getStyle())) { + // 专辑名称 + String likeExpression = "%" + param.getStyle() + "%"; + predicateList.add(builder.and(builder.like(root.get("style"), likeExpression))); + } + + if (param.getStartTime() != null) { + predicateList.add(builder.greaterThanOrEqualTo(root.get("createTime"), param.getStartTime())); + } + + if (param.getEndTime() != null) { + predicateList.add(builder.lessThanOrEqualTo(root.get("createTime"), param.getEndTime())); + + } + + return builder.and(predicateList.toArray(new Predicate[predicateList.size()])); + }; } + /** - * 返回给前端上一次申请的对象 - * + * 获取上一次申请的审批状态 */ - public ArtistRegisterDto lastApplyRecord(String token) { + public ArtistRegister lastApplyResult(String token) { UserLoginDto user = jwtUtil.getUserLoginDto(token); if (user == null) { throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE); } - UserProcess userprocess = userProcessDao.findUserProcessByCreateUserAndTypeOrderByCreateTime(user.getUserId(), UserProcessTypeEnum.ARTIST.getCode()); - String userId = userprocess.getUserId(); - UserInfo userInfo = userInfoDao.findById(userId).get(); - ArtistInfo artistInfoByUserId = artistInfoDao.findArtistInfoByUserId(userId); - - return ArtistRegisterDto.builder() - .userId(userInfo.getId()) - .nickName(userInfo.getNickName()) - .avatar(userInfo.getAvatar()) - .userName(userInfo.getUserName()) - .type(userInfo.getType()) - .password("") - .backgroundImage(artistInfoByUserId.getBackgroundImage()) - .address(artistInfoByUserId.getAddress()) - .style(artistInfoByUserId.getStyle()) - .bandUserId(artistInfoByUserId.getBandUserId()) - .screenshot(artistInfoByUserId.getScreenshot()) - .build(); + + return artistRegisterDao.findArtistRegisterByCreateUserOrderByCreateTime(user.getUserId()); } diff --git a/luoo_user/src/main/resources/sql/20240529.sql b/luoo_user/src/main/resources/sql/20240529.sql new file mode 100644 index 0000000..b8d08b4 --- /dev/null +++ b/luoo_user/src/main/resources/sql/20240529.sql @@ -0,0 +1,21 @@ +create table tb_artist_register +( + id varchar(20) not null + primary key, + nick_name varchar(255) null comment '歌手名', + avatar varchar(255) null comment '艺人头像', + background_image varchar(255) null comment '主页背景', + screenshot varchar(255) null comment '播放器音乐人管理后台实时截图', + address varchar(255) null comment '所在地区', + style varchar(500) null comment '流派风格', + type int null comment '艺人类型 2- 音乐人个人 3-音乐人乐队', + description longtext null comment '艺人简介', + band_user_id varchar(20) null comment 'tb_user_info表中厂牌类型用户的id', + user_name varchar(255) null comment '用户名', + password varchar(255) null comment '密码', + user_id varchar(20) null comment '用户id,审核后创建账号的id', + artist_id varchar(20) null comment '音乐人id,审核后新建的id', + status int null comment '申请状态 0-待审批 1-审批通过 2-审批不通过' +) + comment '音乐人注册信息'; +