From a6ee47947c5d53d60a3ee754ad661695fe5945bb Mon Sep 17 00:00:00 2001 From: pikaqiudeshujia Date: Thu, 30 May 2024 10:24:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?release-=20=E9=9F=B3=E4=B9=90=E4=BA=BA?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=AE=A1=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- luoo_common/pom.xml | 12 +++++ .../src/main/java/util/RedisLockUtil.java | 52 +++++++++++++++++++ .../java/com/luoo/user/UserApplication.java | 13 +++-- .../luoo/user/dto/UserProcessApproveDto.java | 3 +- .../java/com/luoo/user/pojo/ArtistInfo.java | 3 ++ .../com/luoo/user/pojo/ArtistRegister.java | 16 ++++-- .../com/luoo/user/service/ArtistService.java | 37 ++++++++++--- luoo_user/src/main/resources/sql/20240529.sql | 22 ++++++++ 8 files changed, 144 insertions(+), 14 deletions(-) create mode 100644 luoo_common/src/main/java/util/RedisLockUtil.java diff --git a/luoo_common/pom.xml b/luoo_common/pom.xml index c4a4784..29f00aa 100644 --- a/luoo_common/pom.xml +++ b/luoo_common/pom.xml @@ -29,5 +29,17 @@ com.github.xiaoymin swagger-bootstrap-ui + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + redis.clients + jedis + 3.7.0 + diff --git a/luoo_common/src/main/java/util/RedisLockUtil.java b/luoo_common/src/main/java/util/RedisLockUtil.java new file mode 100644 index 0000000..ab144d4 --- /dev/null +++ b/luoo_common/src/main/java/util/RedisLockUtil.java @@ -0,0 +1,52 @@ +package util; + +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.Date; +import java.util.concurrent.TimeUnit; + +/** + * @Author: yawei.huang + * @Package: util + * @Project: luoo_parent + * @Date: 2024/5/30 8:34 + * @Filename: RedisLockUtil + * @Describe: + */ +@Component +public class RedisLockUtil { + + @Resource + private RedisTemplate redisTemplate; + + private static final String KEY_PREFIX = "serial_number:"; + private static final String DATE_FORMAT = "yyMMdd"; + + public String generateSerialNumber() { + String key = KEY_PREFIX + getCurrentDate(); + Long increment = redisTemplate.opsForValue().increment(key, 1); + if (increment == 1) { + redisTemplate.expire(key, getSecondsUntilEndOfDay(), TimeUnit.SECONDS); + } + return getCurrentDate() + String.format("%04d", increment); + } + + private String getCurrentDate() { + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); + return sdf.format(new Date()); + } + + private long getSecondsUntilEndOfDay() { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime endOfDay = now.with(LocalTime.MAX); + Duration duration = Duration.between(now, endOfDay); + return duration.getSeconds(); + } + +} diff --git a/luoo_user/src/main/java/com/luoo/user/UserApplication.java b/luoo_user/src/main/java/com/luoo/user/UserApplication.java index bd5b3c0..caf5e89 100644 --- a/luoo_user/src/main/java/com/luoo/user/UserApplication.java +++ b/luoo_user/src/main/java/com/luoo/user/UserApplication.java @@ -1,6 +1,4 @@ package com.luoo.user; -import java.net.InetAddress; -import java.net.UnknownHostException; import com.spring4all.mongodb.EnableMongoPlus; import org.slf4j.Logger; @@ -9,13 +7,17 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.env.Environment; import org.springframework.context.annotation.Bean; +import org.springframework.core.env.Environment; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import util.IdWorker; import util.JwtUtil; +import util.RedisLockUtil; + +import java.net.InetAddress; +import java.net.UnknownHostException; @EnableMongoPlus @SpringBootApplication @@ -55,4 +57,9 @@ public class UserApplication { public JwtUtil jwtUtil(){ return new JwtUtil(); } + + @Bean + public RedisLockUtil redisLockUtil() { + return new RedisLockUtil(); + } } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/UserProcessApproveDto.java b/luoo_user/src/main/java/com/luoo/user/dto/UserProcessApproveDto.java index 591f6a7..d21d137 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/UserProcessApproveDto.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/UserProcessApproveDto.java @@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import java.io.Serializable; /** @@ -22,7 +23,7 @@ public class UserProcessApproveDto implements Serializable { private String id; @ApiModelProperty("审核结果 1-通过 2-拒绝") - @NotBlank(message = "审核结果必填") + @NotNull(message = "审核结果必填") private Integer status; @ApiModelProperty("拒绝理由") diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/ArtistInfo.java b/luoo_user/src/main/java/com/luoo/user/pojo/ArtistInfo.java index 897496d..e6791f4 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/ArtistInfo.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/ArtistInfo.java @@ -49,4 +49,7 @@ public class ArtistInfo implements Serializable { @ApiModelProperty(name = "播放器音乐人管理后台实时截图") private String screenshot; + + @ApiModelProperty("编号") + private String serialNo; } 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 index 0d2a99a..c527b3f 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/ArtistRegister.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/ArtistRegister.java @@ -3,17 +3,21 @@ package com.luoo.user.pojo; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.*; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.format.annotation.DateTimeFormat; import javax.persistence.Entity; +import javax.persistence.EntityListeners; 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; +import java.time.LocalDateTime; /** * @Author: yawei.huang @@ -29,7 +33,10 @@ import java.util.Date; @EqualsAndHashCode @Builder @Entity +@DynamicInsert +@DynamicUpdate @Table(name="tb_artist_register") +@EntityListeners(AuditingEntityListener.class) public class ArtistRegister implements Serializable { @Id @ApiModelProperty("id") @@ -93,17 +100,20 @@ public class ArtistRegister implements Serializable { @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty("创建时间") @CreatedDate - private Date createTime; + private LocalDateTime 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; + private LocalDateTime modifyTime; @ApiModelProperty("创建人") private String createUser; @ApiModelProperty("修改人") private String updateUser; + + @ApiModelProperty("编号") + private String serialNo; } 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 aea121b..eee8fcc 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,19 +1,24 @@ package com.luoo.user.service; import api.PageResult; -import com.luoo.user.dao.*; +import com.luoo.user.dao.ArtistInfoDao; +import com.luoo.user.dao.ArtistRegisterDao; +import com.luoo.user.dao.ArtistUserDao; +import com.luoo.user.dao.UserInfoDao; 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.*; +import com.luoo.user.pojo.ArtistInfo; +import com.luoo.user.pojo.ArtistRegister; +import com.luoo.user.pojo.ArtistUser; +import com.luoo.user.pojo.UserInfo; import constants.Constants; import constants.ErrorConstants; import dto.UserLoginDto; import dto.UserMessageDto; import enums.MessageTypeEnum; import enums.UserProcessStatusEnum; -import enums.UserProcessTypeEnum; import enums.UserStatusEnum; import exception.BizException; import lombok.extern.slf4j.Slf4j; @@ -31,6 +36,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import util.IdWorker; import util.JwtUtil; +import util.RedisLockUtil; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; @@ -76,6 +82,8 @@ public class ArtistService { @Autowired private ArtistRegisterDao artistRegisterDao; + @Autowired + private RedisLockUtil redisLockUtil; /** * 音乐人注册 */ @@ -84,7 +92,7 @@ public class ArtistService { UserLoginDto currentUser = jwtUtil.getUserLoginDto(token); String id = artistRegisterDto.getId(); - if (StringUtils.isNotBlank(id)) { + if (StringUtils.isBlank(id)) { // 新增音乐人账号 // 一个用户只能新增一个音乐人账号 List list = artistRegisterDao.findAllByCreateUser(currentUser.getUserId()); @@ -106,6 +114,11 @@ public class ArtistService { artistRegister.setCreateUser(currentUser.getUserId()); // 密码加密 artistRegister.setPassword(encoder.encode(artistRegisterDto.getPassword())); + + String serialNo = redisLockUtil.generateSerialNumber(); + artistRegister.setSerialNo(serialNo); + + artistRegister.setId(String.valueOf(idWorker.nextId())); artistRegisterDao.save(artistRegister); } else { // 拒绝后重新发起音乐人账号审批 @@ -154,6 +167,8 @@ public class ArtistService { @Transactional(rollbackFor = Exception.class) public void approve(String token, UserProcessApproveDto userProcessApproveDto) { + UserLoginDto currentUser = jwtUtil.getUserLoginDto(token); + String title = ObjectUtils.equals(UserProcessStatusEnum.SUCCESS.getCode(), userProcessApproveDto.getStatus()) ? "音乐人审核通过" : "音乐人审核失败"; String content = userProcessApproveDto.getContent(); @@ -164,10 +179,9 @@ public class ArtistService { } ArtistRegister artistRegister = artistRegisterDao.findById(userProcessApproveDto.getId()).get(); + artistRegister.setUserId(currentUser.getUserId()); artistRegister.setStatus(userProcessApproveDto.getStatus()); artistRegister.setContent(userProcessApproveDto.getContent()); - artistRegister.setModifyTime(new Date()); - artistRegisterDao.save(artistRegister); if (ObjectUtils.equals(UserProcessStatusEnum.SUCCESS.getCode(), userProcessApproveDto.getStatus())) { // 审核通过 @@ -190,18 +204,27 @@ public class ArtistService { ArtistInfo artistInfo = ArtistInfo.builder() .id(String.valueOf(idWorker.nextId())) .userId(userInfo.getId()) + .description(artistRegister.getDescription()) + .screenshot(artistRegister.getScreenshot()) .backgroundImage(artistRegister.getBackgroundImage()) .address(artistRegister.getAddress()) .style(artistRegister.getStyle()) .bandUserId(artistRegister.getBandUserId()) + .serialNo(artistRegister.getSerialNo()) .build(); artistInfoDao.save(artistInfo); + + artistRegister.setArtistId(artistInfo.getId()); + artistRegister.setUserId(userInfo.getId()); + + artistRegister.setUpdateUser(currentUser.getUserId()); } + artistRegisterDao.save(artistRegister); + // 发送审核成功、失败的站内信 // 发送人是当前登录用户 // 接收人是音乐人注册人 - UserLoginDto currentUser = jwtUtil.getUserLoginDto(token); UserMessageDto userMessageDto = new UserMessageDto(); userMessageDto.setType(MessageTypeEnum.PRIVATE_MESSAGE.getType()); userMessageDto.setSendUserId(currentUser.getUserId()); diff --git a/luoo_user/src/main/resources/sql/20240529.sql b/luoo_user/src/main/resources/sql/20240529.sql index b8d08b4..caa4700 100644 --- a/luoo_user/src/main/resources/sql/20240529.sql +++ b/luoo_user/src/main/resources/sql/20240529.sql @@ -19,3 +19,25 @@ create table tb_artist_register ) comment '音乐人注册信息'; +alter table tb_artist_register + add serial_no varchar(20) null comment '编号'; + +alter table tb_artist_register + add content longtext null comment '拒绝理由'; + +alter table tb_artist_info + add serial_no varchar(20) null comment '编号'; + +alter table tb_artist_register + add create_time datetime null comment '创建时间'; + +alter table tb_artist_register + add modify_time datetime null comment '修改时间'; + +alter table tb_artist_register + add create_user varchar(20) null comment '创建人'; + +alter table tb_artist_register + add update_user varchar(20) null comment '修改人'; + + From b27a9935c69fd79d5e806c226cf38346151dc40e Mon Sep 17 00:00:00 2001 From: pikaqiudeshujia Date: Thu, 30 May 2024 10:38:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?release-=20=E9=9F=B3=E4=B9=90=E4=BA=BA?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=AE=A1=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/luoo/user/controller/ArtistController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bb8d63e..4d39269 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 @@ -86,7 +86,7 @@ public class ArtistController { @ApiOperation(value = "上一次申请的记录", notes = "上一次申请的记录:申请状态 0-待审批 1-审批通过 2-审批不通过") @GetMapping("/last/apply/record") - public Result lastApplyRecord(@ApiParam(value = "Header中的token信息", required = true) String token) { + public Result lastApplyRecord(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token) { return Result.success(artistService.lastApplyResult(token)); }