1.move common annotation/constants/enums to common module, 2.enable journal

main
Gary 10 months ago
parent 7034207125
commit 6c4df54f35

@ -1,21 +1,24 @@
package com.luoo.user.annotation;
package annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.luoo.user.enums.RequestFrequencyTypeEnum;
import enums.RequestFrequencyTypeEnum;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface GlobalInterceptor {
boolean checkLogin() default false;
boolean checkAppUserLogin() default false;
boolean checkAdminLogin() default false;
boolean checkParam() default true;
int requestFrequencyThreshold() default 0;
RequestFrequencyTypeEnum frequencyType() default RequestFrequencyTypeEnum.NO_LIMIT;
boolean checkParam() default true;
int requestFrequencyThreshold() default 0;
RequestFrequencyTypeEnum frequencyType() default RequestFrequencyTypeEnum.NO_LIMIT;
}

@ -0,0 +1,21 @@
package annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import enums.VerifyRegexEnum;
@Target({ ElementType.PARAMETER, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface VerifyParam {
VerifyRegexEnum regex() default VerifyRegexEnum.NO;
int min() default -1;
int max() default -1;
boolean required() default false;
}

@ -1,4 +1,4 @@
package com.luoo.user.constants;
package constants;
public class Constants {
public static final String IMAGE_CHECK_CODE_KEY="image_check_code_key";
@ -14,4 +14,6 @@ public class Constants {
public static final String FOLDER_AVATAR = "avatar/";
public static final String MUSIC_RESOURCE_PREFIX="http://wx.gisocn.com:18599/music/";
}

@ -1,4 +1,4 @@
package com.luoo.user.enums;
package enums;
public enum RequestFrequencyTypeEnum {
DAY(60 * 60 * 24, "一天"), HOUR(60 * 60, "一小时"), MINUTE(60, "一分钟"), SECONDS(1, "一秒"), NO_LIMIT(0, "不限制");

@ -1,4 +1,4 @@
package com.luoo.user.enums;
package enums;
public enum VerifyRegexEnum {
NO("", "不校验"),

@ -0,0 +1,21 @@
package util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import enums.VerifyRegexEnum;
public class VerifyUtils {
public static boolean verify(String regex, String value) {
if (StringTools.isEmpty(value)) {
return false;
}
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(value);
return matcher.matches();
}
public static boolean verify(VerifyRegexEnum regexEnum, String value) {
return verify(regexEnum.getRegex(), value);
}
}

@ -15,6 +15,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import util.IdWorker;
import util.JwtUtil;
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@ -44,4 +45,8 @@ public class MusicApplication {
return new IdWorker(1, 1);
}
@Bean
public JwtUtil jwtUtil(){
return new JwtUtil();
}
}

@ -0,0 +1,221 @@
package com.luoo.music.aspect;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.ArrayUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.luoo.music.util.RedisUtils;
import constants.Constants;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.StatusCode;
import dto.UserLoginDto;
import enums.RequestFrequencyTypeEnum;
import exception.BizException;
import util.JwtUtil;
import util.StringTools;
import util.VerifyUtils;
@Aspect
@Component("operationAspect")
public class OperationAspect {
static Logger logger = LoggerFactory.getLogger(OperationAspect.class);
private static final String[] BASE_TYPE_ARRAY = new String[] { "java.lang.String", "java.lang.Integer",
"java.lang.Long" };
@Autowired
private JwtUtil jwtUtil;
@Autowired
private RedisUtils redisUtils;
@Before("@annotation(annotation.GlobalInterceptor)")
public void interceptorDo(JoinPoint point) {
Object[] arguments = point.getArgs();
Object target = point.getTarget();
Method method = ((MethodSignature) point.getSignature()).getMethod();
GlobalInterceptor interceptor = method.getAnnotation(GlobalInterceptor.class);
if (null == interceptor) {
return;
}
/**
*
*/
if (interceptor.checkLogin()) {
checkLogin();
}
/**
*
*/
if (interceptor.checkAdminLogin()) {
checkAdminLogin();
}
/**
* app
*/
if (interceptor.checkAppUserLogin()) {
checkAppUserLogin();
}
/**
*
*/
if (interceptor.checkParam()) {
validateParams(method, arguments);
}
/**
*
*/
if (interceptor.frequencyType() != RequestFrequencyTypeEnum.NO_LIMIT && interceptor.requestFrequencyThreshold() != 0) {
String fullMethodName = target.getClass().getName() + "." + method.getName();
checkRequestFrequency(fullMethodName, interceptor.frequencyType(), interceptor.requestFrequencyThreshold());
}
}
private void checkRequestFrequency(String fullMethodName, RequestFrequencyTypeEnum frequencyTyp, Integer threshold) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String ip = getIpAddr(request);
ip = ip.replace(":", "");
String redisKey = fullMethodName + ip;
Object count=redisUtils.get(redisKey);
Integer cuCount= null==count?0:Integer.valueOf((String)count);
if (cuCount != null && cuCount > threshold - 1) {
throw new BizException(StatusCode.REQUEST_TOO_FREQUENCY);
}
redisUtils.increment(redisKey, 1, frequencyTyp.getSeconds());
}
private void checkAppUserLogin() {
UserLoginDto userLoginDto = getUserLoginDtoFromToken();
if (userLoginDto == null) {
throw new BizException(StatusCode.UNAUTHORIZED);
}
if (!Constants.TOKEN_ROLE_APP_USER.equals(userLoginDto.getRoles())) {
throw new BizException(StatusCode.FORBIDDEN);
}
}
private void checkAdminLogin() {
UserLoginDto userLoginDto = getUserLoginDtoFromToken();
if (userLoginDto == null) {
throw new BizException(StatusCode.UNAUTHORIZED);
}
if (!Constants.TOKEN_ROLE_ADMIN_USER.equals(userLoginDto.getRoles())) {
throw new BizException(StatusCode.FORBIDDEN);
}
}
private void checkLogin() {
UserLoginDto userLoginDto = getUserLoginDtoFromToken();
if (userLoginDto == null) {
throw new BizException(StatusCode.UNAUTHORIZED);
}
}
private UserLoginDto getUserLoginDtoFromToken() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getRequest();
String token = request.getHeader("token");
return jwtUtil.getUserLoginDto(token);
}
private void validateParams(Method method, Object[] arguments) {
Parameter[] parameters = method.getParameters();
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
Object value = arguments[i];
VerifyParam verifyParam = parameter.getAnnotation(VerifyParam.class);
if (null == verifyParam) {
continue;
}
String paramTypeName = parameter.getParameterizedType().getTypeName();
if (ArrayUtils.contains(BASE_TYPE_ARRAY, paramTypeName)) {
checkValue(value, verifyParam);
} else {
checkObjValue(parameter, value);
}
}
}
private void checkObjValue(Parameter parameter, Object value) {
try {
String typeName = parameter.getParameterizedType().getTypeName();
Class<?> clazz = Class.forName(typeName);
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
VerifyParam fieldVerifyParam = field.getAnnotation(VerifyParam.class);
if (null == fieldVerifyParam) {
continue;
}
field.setAccessible(true);
Object resultValue = field.get(value);
checkValue(resultValue, fieldVerifyParam);
}
} catch (Exception e) {
logger.error(StatusCode.VALIDATE_FAILED.getMessage(), e.getMessage());
throw new BizException(StatusCode.VALIDATE_FAILED);
}
}
private void checkValue(Object value, VerifyParam verifyParam) {
boolean isEmpty = null == value || StringTools.isEmpty(value.toString());
int length = null == value ? 0 : value.toString().length();
if (isEmpty && verifyParam.required()) {
throw new BizException(StatusCode.VALIDATE_FAILED);
}
if (!isEmpty && (-1 != verifyParam.max() && verifyParam.max() < length
|| -1 != verifyParam.min() && verifyParam.min() > length)) {
throw new BizException(StatusCode.VALIDATE_FAILED);
}
if (!isEmpty && !StringTools.isEmpty(verifyParam.regex().getRegex())
&& !VerifyUtils.verify(verifyParam.regex(), String.valueOf(value))) {
throw new BizException(StatusCode.VALIDATE_FAILED);
}
}
private String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
// 多次反向代理后会有多个ip值第一个ip才是真实ip
if (ip.indexOf(",") != -1) {
ip = ip.split(",")[0];
}
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Real-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
}

@ -0,0 +1,55 @@
package com.luoo.music.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.luoo.music.client.UserClient;
import com.luoo.music.dto.request.JournalQueryReq;
import com.luoo.music.dto.response.JournalRespDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Article;
import com.luoo.music.service.ArticleService;
import annotation.GlobalInterceptor;
import api.PageResult;
import api.Result;
import constants.Constants;
import io.swagger.annotations.ApiOperation;
/**
*
* @author Administrator
*
*/
@RestController
@CrossOrigin
@RequestMapping("/journal")
public class JournalController {
@Autowired
private ArticleService articleService;
@ApiOperation(value = "1.查询期刊信息")
@GetMapping("/list")
//@GlobalInterceptor(checkLogin = true)
public Result<PageResult<JournalRespDTO>> page(@RequestHeader(value = "token", required = false) String token,
JournalQueryReq queryReq){
Page<Article> pageList = articleService.queryPage(queryReq);
List<JournalRespDTO> list=pageList.stream().map(a->getArticleRespDTO(a)).collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list) );
}
private JournalRespDTO getArticleRespDTO(Article article) {
JournalRespDTO journalRespDTO=new JournalRespDTO();
journalRespDTO.setId(article.getId());
journalRespDTO.setJournalNo(article.getVolid());
journalRespDTO.setTitle(article.getTitle());
journalRespDTO.setImage(Constants.MUSIC_RESOURCE_PREFIX+article.getImage());
return journalRespDTO;
}
}

@ -1,12 +1,15 @@
package com.luoo.music.controller;
import com.luoo.music.dto.response.SongRespDTO;
import com.luoo.music.pojo.Article;
import com.luoo.music.pojo.Song;
import com.luoo.music.pojo.SongVO;
import com.luoo.music.service.SongService;
import api.PageResult;
import api.Result;
import constants.Constants;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
@ -15,6 +18,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@RestController
@CrossOrigin
@ -32,12 +36,27 @@ public class SongController {
public Result<List<Song>> findAll(){
return Result.success(songService.findAll());
}
@GetMapping("/findByVolid/{volid}")
public Result<List<SongVO>> findByVolid(@PathVariable String volid){
return Result.success(songService.findByVolid(volid));
@ApiOperation(value = "1.根据期刊号查询歌曲信息")
@GetMapping("/getByJournalNo/{journalNo}")
public Result<List<SongRespDTO>> getByJournalNo(@PathVariable String journalNo){
List<Song> songs=songService.findByVolid(journalNo);
List<SongRespDTO> results=songs.stream().map(s->getSongRespDTO(s)).collect(Collectors.toList());
return Result.success(results);
}
private SongRespDTO getSongRespDTO(Song song) {
SongRespDTO songRespDTO = new SongRespDTO();
songRespDTO.setJournalNo(song.getVolid());
songRespDTO.setAlbum(song.getAlbum());
songRespDTO.setArtist(song.getArtist());
songRespDTO.setId(song.getId());
songRespDTO.setTitle(song.getName());
songRespDTO.setSrc(Constants.MUSIC_RESOURCE_PREFIX+song.getUrl());
songRespDTO.setPic(Constants.MUSIC_RESOURCE_PREFIX+song.getUrl().replace(".mp3",".jpg"));
songRespDTO.setLrc(Constants.MUSIC_RESOURCE_PREFIX+song.getUrl().replace(".mp3",".lyric"));
songRespDTO.setSongNo(song.getSongno());
return songRespDTO;
}
/**
* ID
* @param id ID

@ -0,0 +1,28 @@
package com.luoo.music.dto.request;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
*
*/
@Data
@ApiModel
public class JournalQueryReq implements Serializable {
private static final long serialVersionUID = -1198060864891902188L;
@ApiModelProperty(value = "风格")
private String style;
@ApiModelProperty(value = "语言")
private String language;
@ApiModelProperty(value = "分页: 页码", example = "1")
private int pageNum = 1;
@ApiModelProperty(value = "分页: 每页数量", example = "10")
private int pageSize = 10;
}

@ -0,0 +1,18 @@
package com.luoo.music.dto.response;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class JournalRespDTO {
@ApiModelProperty(value = "ID")
private String id;
@ApiModelProperty(value = "剘刊号")
private String journalNo;
@ApiModelProperty(value = "期刊名")
private String title;
@ApiModelProperty(value = "文案")
private String content;
@ApiModelProperty(value = "期刊封面")
private String image;
}

@ -0,0 +1,22 @@
package com.luoo.music.dto.response;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class SongRespDTO {
private String id;
private String title;
private String artist;
@ApiModelProperty(value = "专辑")
private String album;
private String src;
private String pic;
private String lrc;
@ApiModelProperty(value = "剘刊号")
private String journalNo;
@ApiModelProperty(value = "歌曲号")
private Integer songNo;
}

@ -1,88 +0,0 @@
package com.luoo.music.pojo;
public class SongVO {
private String id;
private String title;
private String artist;
private String album;
private String src;
private String pic;
private String lrc;
private String volid;
private Integer songno;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String getAlbum() {
return album;
}
public void setAlbum(String album) {
this.album = album;
}
public String getSrc() {
return src;
}
public void setSrc(String src) {
this.src = src;
}
public String getPic() {
return pic;
}
public void setPic(String pic) {
this.pic = pic;
}
public String getLrc() {
return lrc;
}
public void setLrc(String lrc) {
this.lrc = lrc;
}
public String getVolid() {
return volid;
}
public void setVolid(String volid) {
this.volid = volid;
}
public Integer getSongno() {
return songno;
}
public void setSongno(Integer songno) {
this.songno = songno;
}
}

@ -9,6 +9,7 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@ -20,6 +21,7 @@ import org.springframework.stereotype.Service;
import util.IdWorker;
import com.luoo.music.dao.ArticleDao;
import com.luoo.music.dto.request.JournalQueryReq;
import com.luoo.music.pojo.Article;
/**
@ -209,4 +211,28 @@ public class ArticleService {
public Article findByVolid(String volid) {
return articleDao.findArticleByVolid(volid);
}
public Page<Article> queryPage(JournalQueryReq queryReq) {
Specification<Article> specification = createArticleSpecification(queryReq);
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum()-1, queryReq.getPageSize());
return articleDao.findAll(specification, pageRequest);
}
/**
*
* as article do not support style and langauge, only sort the result
*/
private Specification<Article> createArticleSpecification(JournalQueryReq queryReq) {
return new Specification<Article>() {
private static final long serialVersionUID = 1L;
@Override
public Predicate toPredicate(Root<Article> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicateList = new ArrayList<Predicate>();
query.orderBy(cb.desc(root.get("volid").as(Integer.class)));
return cb.and( predicateList.toArray(new Predicate[predicateList.size()]));
}
};
}
}

@ -1,8 +1,9 @@
package com.luoo.music.service;
import com.luoo.music.dao.SongDao;
import com.luoo.music.dto.response.SongRespDTO;
import com.luoo.music.pojo.Song;
import com.luoo.music.pojo.SongVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
@ -141,24 +142,7 @@ public class SongService {
};
}
public List<SongVO> findByVolid(String volid) {
List<Song> songList = songDao.findSongsByVolid(volid);
List<SongVO> songVOList = new ArrayList<>();
for (Song song: songList) {
SongVO songVO = new SongVO();
songVO.setVolid(song.getVolid());
songVO.setAlbum(song.getAlbum());
songVO.setArtist(song.getArtist());
songVO.setId(song.getId());
songVO.setTitle(song.getName());
songVO.setSrc("http://wx.gisocn.com:18599/music/"+song.getUrl());
songVO.setPic("http://wx.gisocn.com:18599/music/"+song.getUrl().replace(".mp3",".jpg"));
songVO.setLrc("http://wx.gisocn.com:18599/music/"+song.getUrl().replace(".mp3",".lyric"));
songVOList.add(songVO);
}
return songVOList;
public List<Song> findByVolid(String volid){
return songDao.findSongsByVolid(volid);
}
}

@ -0,0 +1,101 @@
package com.luoo.music.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
@Component("redisUtils")
public class RedisUtils<V> {
@Autowired
private RedisTemplate<String, V> redisTemplate;
private static final Logger logger = LoggerFactory.getLogger(RedisUtils.class);
/**
*
*
* @param key
*/
public void delete(String... key) {
if (key != null && key.length > 0) {
if (key.length == 1) {
redisTemplate.delete(key[0]);
} else {
redisTemplate.delete((Collection<String>) CollectionUtils.arrayToList(key));
}
}
}
public V get(String key) {
return key == null ? null : redisTemplate.opsForValue().get(key);
}
/**
*
*
* @param key
* @param value
* @return true false
*/
public boolean set(String key, V value) {
try {
redisTemplate.opsForValue().set(key, value);
return true;
} catch (Exception e) {
logger.error("设置redisKey:{},value:{}失败", key, value);
return false;
}
}
/**
*
*
* @param key
* @param value
* @param time () time0 time0
* @return true false
*/
public boolean setex(String key, V value, long time) {
try {
if (time > 0) {
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
} else {
set(key, value);
}
return true;
} catch (Exception e) {
logger.error("设置redisKey:{},value:{}失败", key, value);
return false;
}
}
public long increment(String key, long delta, long time) {
if (delta < 0) {
throw new RuntimeException("递增因子必须大于0");
}
long result = redisTemplate.opsForValue().increment(key, delta);
if (result == 1) {
expire(key, time);
}
return result;
}
public boolean expire(String key, long time) {
try {
if (time > 0) {
redisTemplate.expire(key, time, TimeUnit.SECONDS);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}

@ -1,17 +0,0 @@
package com.luoo.user.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.luoo.user.enums.VerifyRegexEnum;
@Target({ElementType.PARAMETER,ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface VerifyParam {
VerifyRegexEnum regex() default VerifyRegexEnum.NO;
int min() default -1;
int max() default -1;
boolean required() default false;
}

@ -4,7 +4,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.ArrayUtils;
@ -15,23 +14,22 @@ import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.luoo.user.annotation.GlobalInterceptor;
import com.luoo.user.annotation.VerifyParam;
import com.luoo.user.constants.Constants;
import com.luoo.user.enums.RequestFrequencyTypeEnum;
import com.luoo.user.util.RedisUtils;
import com.luoo.user.util.VerifyUtils;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.StatusCode;
import constants.Constants;
import dto.UserLoginDto;
import enums.RequestFrequencyTypeEnum;
import exception.BizException;
import util.JwtUtil;
import util.StringTools;
import util.VerifyUtils;
@Aspect
@Component("operationAspect")
@ -46,7 +44,7 @@ public class OperationAspect {
@Autowired
private RedisUtils redisUtils;
@Before("@annotation(com.luoo.user.annotation.GlobalInterceptor)")
@Before("@annotation(annotation.GlobalInterceptor)")
public void interceptorDo(JoinPoint point) {
Object[] arguments = point.getArgs();
Object target = point.getTarget();

@ -6,11 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import com.luoo.user.annotation.GlobalInterceptor;
import com.luoo.user.annotation.VerifyParam;
import com.luoo.user.pojo.Admin;
import com.luoo.user.service.AdminService;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import api.StatusCode;

@ -18,14 +18,13 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.luoo.user.annotation.GlobalInterceptor;
import com.luoo.user.annotation.VerifyParam;
import com.luoo.user.constants.Constants;
import constants.Constants;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.enums.VerifyRegexEnum;
import com.luoo.user.pojo.User;
import com.luoo.user.service.UserService;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.Result;
import api.StatusCode;
import dto.UserLoginDto;

@ -8,27 +8,24 @@ import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import com.luoo.user.annotation.GlobalInterceptor;
import com.luoo.user.annotation.VerifyParam;
import com.luoo.user.constants.Constants;
import constants.Constants;
import com.luoo.user.dto.response.CreateImageCode;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.enums.RequestFrequencyTypeEnum;
import com.luoo.user.enums.VerifyRegexEnum;
import com.luoo.user.pojo.User;
import com.luoo.user.service.UserService;
import com.luoo.user.util.NickNameUtil;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import api.StatusCode;
import io.jsonwebtoken.Claims;
import enums.RequestFrequencyTypeEnum;
import enums.VerifyRegexEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import util.IdWorker;

@ -1,14 +0,0 @@
package com.luoo.user.enumerate;
public enum Gender {
Male("0"), Female("1");
private String code;
private Gender(String code) {
this.code = code;
}
public String getCode() {
return code;
}
}

@ -11,7 +11,6 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@ -23,18 +22,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.IdWorker;
import com.apifan.common.random.RandomSource;
import com.luoo.user.constants.Constants;
import constants.Constants;
import com.luoo.user.dao.UserDao;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.enumerate.Gender;
import com.luoo.user.pojo.User;
import com.luoo.user.util.NickNameUtil;
import api.Result;
import api.StatusCode;
import dto.UserLoginDto;
import io.jsonwebtoken.Claims;
import util.JwtUtil;
/**

@ -1,31 +0,0 @@
package com.luoo.user.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.luoo.user.enums.VerifyRegexEnum;
import util.StringTools;
/**
* @ClassName VerifyUtils
* @Description TODO
* @Author Administrator
* @Date 2023/8/30 21:59
*/
public class VerifyUtils {
public static boolean verify(String regex,String value){
if(StringTools.isEmpty(value)){
return false;
}
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(value);
return matcher.matches();
}
public static boolean verify(VerifyRegexEnum regexEnum,String value){
return verify(regexEnum.getRegex(),value);
}
}
Loading…
Cancel
Save