release- 音乐人注册审核

release-2024-08-08
pikaqiudeshujia 6 months ago
parent 520bcd8320
commit a6ee47947c

@ -29,5 +29,17 @@
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.7.0</version>
</dependency>
</dependencies>
</project>

@ -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<String, String> 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();
}
}

@ -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();
}
}

@ -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("拒绝理由")

@ -49,4 +49,7 @@ public class ArtistInfo implements Serializable {
@ApiModelProperty(name = "播放器音乐人管理后台实时截图")
private String screenshot;
@ApiModelProperty("编号")
private String serialNo;
}

@ -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;
}

@ -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<ArtistRegister> 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());

@ -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 '修改人';

Loading…
Cancel
Save