代码优化
This commit is contained in:
parent
5217cc32fa
commit
98e5db30cc
@ -5,5 +5,6 @@ public class FileConstant {
|
||||
* 路径分隔符
|
||||
*/
|
||||
public static final String pathSeparator = "/";
|
||||
public static final int deleteFileRandomSize = 999999;
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.qiwenshare.common.util;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.qiwenshare.common.config.PropertiesUtil;
|
||||
import com.qiwenshare.common.constant.FileConstant;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -73,9 +74,10 @@ public class PathUtil {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String path = "aaa/bbb/ccc/";
|
||||
System.out.println(getParentPath(path));
|
||||
String fileName = path.substring(path.lastIndexOf("/"));
|
||||
System.out.println(fileName);
|
||||
System.out.println(RandomUtil.randomLong(999999));
|
||||
// String path = "aaa/bbb/ccc/";
|
||||
// System.out.println(getParentPath(path));
|
||||
// String fileName = path.substring(path.lastIndexOf("/"));
|
||||
// System.out.println(fileName);
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,7 @@ import com.qiwenshare.file.mapper.UserFileMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
|
||||
@Component
|
||||
@ -109,68 +107,65 @@ public class FileDealComp {
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// public TreeNode insertTreeNode(TreeNode treeNode, String filePath, Queue<String> nodeNameQueue){
|
||||
//
|
||||
// List<TreeNode> childrenTreeNodes = treeNode.getChildren();
|
||||
// String currentNodeName = nodeNameQueue.peek();
|
||||
// if (currentNodeName == null){
|
||||
// return treeNode;
|
||||
// }
|
||||
//
|
||||
// Map<String, String> map = new HashMap<>();
|
||||
// filePath = filePath + currentNodeName + "/";
|
||||
// map.put("filePath", filePath);
|
||||
//
|
||||
// if (!isExistPath(childrenTreeNodes, currentNodeName)){ //1、判断有没有该子节点,如果没有则插入
|
||||
// //插入
|
||||
// TreeNode resultTreeNode = new TreeNode();
|
||||
//
|
||||
//
|
||||
// resultTreeNode.setAttributes(map);
|
||||
// resultTreeNode.setLabel(nodeNameQueue.poll());
|
||||
// resultTreeNode.setId(treeid++);
|
||||
//
|
||||
// childrenTreeNodes.add(resultTreeNode);
|
||||
//
|
||||
// }else{ //2、如果有,则跳过
|
||||
// nodeNameQueue.poll();
|
||||
// }
|
||||
//
|
||||
// if (nodeNameQueue.size() != 0) {
|
||||
// for (int i = 0; i < childrenTreeNodes.size(); i++) {
|
||||
//
|
||||
// TreeNode childrenTreeNode = childrenTreeNodes.get(i);
|
||||
// if (currentNodeName.equals(childrenTreeNode.getLabel())){
|
||||
// childrenTreeNode = insertTreeNode(childrenTreeNode, filePath, nodeNameQueue);
|
||||
// childrenTreeNodes.remove(i);
|
||||
// childrenTreeNodes.add(childrenTreeNode);
|
||||
// treeNode.setChildren(childrenTreeNodes);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }else{
|
||||
// treeNode.setChildren(childrenTreeNodes);
|
||||
// }
|
||||
//
|
||||
// return treeNode;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public boolean isExistPath(List<TreeNode> childrenTreeNodes, String path){
|
||||
// boolean isExistPath = false;
|
||||
//
|
||||
// try {
|
||||
// for (int i = 0; i < childrenTreeNodes.size(); i++){
|
||||
// if (path.equals(childrenTreeNodes.get(i).getLabel())){
|
||||
// isExistPath = true;
|
||||
// }
|
||||
// }
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// return isExistPath;
|
||||
// }
|
||||
|
||||
public TreeNode insertTreeNode(TreeNode treeNode, long id, String filePath, Queue<String> nodeNameQueue){
|
||||
|
||||
List<TreeNode> childrenTreeNodes = treeNode.getChildren();
|
||||
String currentNodeName = nodeNameQueue.peek();
|
||||
if (currentNodeName == null){
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
filePath = filePath + currentNodeName + "/";
|
||||
|
||||
if (!isExistPath(childrenTreeNodes, currentNodeName)){ //1、判断有没有该子节点,如果没有则插入
|
||||
//插入
|
||||
TreeNode resultTreeNode = new TreeNode();
|
||||
|
||||
resultTreeNode.setFilePath(filePath);
|
||||
resultTreeNode.setLabel(nodeNameQueue.poll());
|
||||
resultTreeNode.setId(++id);
|
||||
|
||||
childrenTreeNodes.add(resultTreeNode);
|
||||
|
||||
}else{ //2、如果有,则跳过
|
||||
nodeNameQueue.poll();
|
||||
}
|
||||
|
||||
if (nodeNameQueue.size() != 0) {
|
||||
for (int i = 0; i < childrenTreeNodes.size(); i++) {
|
||||
|
||||
TreeNode childrenTreeNode = childrenTreeNodes.get(i);
|
||||
if (currentNodeName.equals(childrenTreeNode.getLabel())){
|
||||
childrenTreeNode = insertTreeNode(childrenTreeNode, id * 10, filePath, nodeNameQueue);
|
||||
childrenTreeNodes.remove(i);
|
||||
childrenTreeNodes.add(childrenTreeNode);
|
||||
treeNode.setChildren(childrenTreeNodes);
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
treeNode.setChildren(childrenTreeNodes);
|
||||
}
|
||||
|
||||
return treeNode;
|
||||
|
||||
}
|
||||
|
||||
public boolean isExistPath(List<TreeNode> childrenTreeNodes, String path){
|
||||
boolean isExistPath = false;
|
||||
|
||||
try {
|
||||
for (int i = 0; i < childrenTreeNodes.size(); i++){
|
||||
if (path.equals(childrenTreeNodes.get(i).getLabel())){
|
||||
isExistPath = true;
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return isExistPath;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.qiwenshare.file.component;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.qiwenshare.file.domain.UserBean;
|
||||
import com.qiwenshare.file.mapper.UserMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Component
|
||||
public class UserDealComp {
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 检测用户名是否存在
|
||||
*
|
||||
* @param userBean
|
||||
*/
|
||||
public Boolean isUserNameExit(UserBean userBean) {
|
||||
LambdaQueryWrapper<UserBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserBean::getUsername, userBean.getUsername());
|
||||
List<UserBean> list = userMapper.selectList(lambdaQueryWrapper);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机号是否存在
|
||||
*
|
||||
* @param userBean
|
||||
* @return
|
||||
*/
|
||||
public Boolean isPhoneExit(UserBean userBean) {
|
||||
|
||||
LambdaQueryWrapper<UserBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserBean::getTelephone, userBean.getTelephone());
|
||||
List<UserBean> list = userMapper.selectList(lambdaQueryWrapper);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Boolean isPhoneFormatRight(String phone){
|
||||
String regex = "^1\\d{10}";
|
||||
boolean isRight = Pattern.matches(regex, phone);
|
||||
return isRight;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.qiwenshare.file.config;
|
||||
|
||||
|
||||
import com.qiwenshare.file.interceptor.AuthenticationInterceptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
@Autowired
|
||||
private AuthenticationInterceptor authenticationInterceptor;
|
||||
|
||||
// @Override
|
||||
// public void addCorsMappings(CorsRegistry registry) {
|
||||
// registry.addMapping("/**").allowedOriginPatterns("*").allowCredentials(true).maxAge(3600).allowedMethods("GET", "POST","OPTIONS");
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
// //默认的资源映射需要填写,不然不能正常访问
|
||||
// registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
|
||||
// //配置外部资源目录的映射,/image目录为前端访问的路径,后面配置静态资源的绝对路径
|
||||
// registry.addResourceHandler("/image/**").addResourceLocations("file:"+uploadFolder);
|
||||
// //调用基类的方法
|
||||
// super.addResourceHandlers(registry);
|
||||
// }
|
||||
|
||||
/**
|
||||
* app拦截器
|
||||
*/
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("/file/**");
|
||||
list.add("/filetransfer/**");
|
||||
list.add("/recoveryfile/**");
|
||||
list.add("/share/**");
|
||||
registry.addInterceptor(authenticationInterceptor)
|
||||
.addPathPatterns(list)
|
||||
.excludePathPatterns("/filetransfer/downloadfile", "/filetransfer/preview");
|
||||
// //登录、登出
|
||||
// .excludePathPatterns("/user/checkuserlogininfo", "/user/login", "/user/register");
|
||||
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ import com.qiwenshare.common.util.PathUtil;
|
||||
import com.qiwenshare.file.anno.MyLog;
|
||||
import com.qiwenshare.file.api.*;
|
||||
import com.qiwenshare.common.config.QiwenFileConfig;
|
||||
import com.qiwenshare.file.component.FileDealComp;
|
||||
import com.qiwenshare.file.config.es.FileSearch;
|
||||
import com.qiwenshare.file.domain.*;
|
||||
import com.qiwenshare.file.dto.*;
|
||||
@ -59,6 +60,8 @@ public class FileController {
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchRestTemplate elasticsearchRestTemplate;
|
||||
@Resource
|
||||
FileDealComp fileDealComp;
|
||||
|
||||
@Resource
|
||||
QiwenFileConfig qiwenFileConfig;
|
||||
@ -379,6 +382,7 @@ public class FileController {
|
||||
tempFileBean.setTimeStampName(FileUtil.getFileNameNotExtend(currentFile.getName()));
|
||||
tempFileBean.setFileUrl(File.separator + (currentFile.getPath()).replace(PathUtil.getStaticPath(), ""));
|
||||
tempFileBean.setPointCount(1);
|
||||
tempFileBean.setStorageType(0);
|
||||
fileService.save(tempFileBean);
|
||||
}
|
||||
|
||||
@ -540,7 +544,7 @@ public class FileController {
|
||||
continue;
|
||||
}
|
||||
|
||||
resultTreeNode = insertTreeNode(resultTreeNode, id++, "/" , queue);
|
||||
resultTreeNode = fileDealComp.insertTreeNode(resultTreeNode, id++, "/" , queue);
|
||||
|
||||
|
||||
}
|
||||
@ -558,65 +562,6 @@ public class FileController {
|
||||
|
||||
}
|
||||
|
||||
public TreeNode insertTreeNode(TreeNode treeNode, long id, String filePath, Queue<String> nodeNameQueue){
|
||||
|
||||
List<TreeNode> childrenTreeNodes = treeNode.getChildren();
|
||||
String currentNodeName = nodeNameQueue.peek();
|
||||
if (currentNodeName == null){
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
filePath = filePath + currentNodeName + "/";
|
||||
|
||||
if (!isExistPath(childrenTreeNodes, currentNodeName)){ //1、判断有没有该子节点,如果没有则插入
|
||||
//插入
|
||||
TreeNode resultTreeNode = new TreeNode();
|
||||
|
||||
resultTreeNode.setFilePath(filePath);
|
||||
resultTreeNode.setLabel(nodeNameQueue.poll());
|
||||
resultTreeNode.setId(++id);
|
||||
|
||||
childrenTreeNodes.add(resultTreeNode);
|
||||
|
||||
}else{ //2、如果有,则跳过
|
||||
nodeNameQueue.poll();
|
||||
}
|
||||
|
||||
if (nodeNameQueue.size() != 0) {
|
||||
for (int i = 0; i < childrenTreeNodes.size(); i++) {
|
||||
|
||||
TreeNode childrenTreeNode = childrenTreeNodes.get(i);
|
||||
if (currentNodeName.equals(childrenTreeNode.getLabel())){
|
||||
childrenTreeNode = insertTreeNode(childrenTreeNode, id * 10, filePath, nodeNameQueue);
|
||||
childrenTreeNodes.remove(i);
|
||||
childrenTreeNodes.add(childrenTreeNode);
|
||||
treeNode.setChildren(childrenTreeNodes);
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
treeNode.setChildren(childrenTreeNodes);
|
||||
}
|
||||
|
||||
return treeNode;
|
||||
|
||||
}
|
||||
|
||||
public boolean isExistPath(List<TreeNode> childrenTreeNodes, String path){
|
||||
boolean isExistPath = false;
|
||||
|
||||
try {
|
||||
for (int i = 0; i < childrenTreeNodes.size(); i++){
|
||||
if (path.equals(childrenTreeNodes.get(i).getLabel())){
|
||||
isExistPath = true;
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return isExistPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -105,12 +105,6 @@ public class FiletransferController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "上传文件", description = "真正的上传文件接口", tags = {"filetransfer"})
|
||||
@RequestMapping(value = "/uploadfile", method = RequestMethod.POST)
|
||||
@MyLog(operation = "上传文件", module = CURRENT_MODULE)
|
||||
@ -132,11 +126,7 @@ public class FiletransferController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Operation(summary = "下载文件", description = "下载文件接口", tags = {"filetransfer"})
|
||||
@MyLog(operation = "下载文件", module = CURRENT_MODULE)
|
||||
@RequestMapping(value = "/downloadfile", method = RequestMethod.GET)
|
||||
@ -167,7 +157,6 @@ public class FiletransferController {
|
||||
UserFile userFile = userFileService.getById(previewDTO.getUserFileId());
|
||||
FileBean fileBean = fileService.getById(userFile.getFileId());
|
||||
String mime= MimeUtils.getMime(userFile.getExtendName());
|
||||
// httpServletResponse.setContentType(mime);
|
||||
httpServletResponse.setHeader("Content-Type", mime);
|
||||
String rangeString = httpServletRequest.getHeader("Range");//如果是video标签发起的请求就不会为null
|
||||
if (StringUtils.isNotEmpty(rangeString)) {
|
||||
|
@ -24,11 +24,7 @@ import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户控制类
|
||||
*
|
||||
* @author ma116
|
||||
*/
|
||||
|
||||
@Tag(name = "user", description = "该接口为用户接口,主要做用户登录,注册和校验token")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@ -44,11 +40,7 @@ public class UserController {
|
||||
|
||||
public static Map<String, String> verificationCodeMap = new HashMap<>();
|
||||
|
||||
public static final int TEXT = 4;
|
||||
|
||||
/**
|
||||
* 当前模块
|
||||
*/
|
||||
public static final String CURRENT_MODULE = "用户管理";
|
||||
|
||||
|
||||
@ -93,7 +85,7 @@ public class UserController {
|
||||
|
||||
UserLoginVo userLoginVo = new UserLoginVo();
|
||||
BeanUtil.copyProperties(saveUserBean, userLoginVo);
|
||||
userLoginVo.setToken(jwt);
|
||||
userLoginVo.setToken("Bearer " + jwt);
|
||||
restResult.setData(userLoginVo);
|
||||
restResult.setSuccess(true);
|
||||
} else {
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.qiwenshare.file.interceptor;
|
||||
|
||||
import com.qiwenshare.common.exception.NotLoginException;
|
||||
import com.qiwenshare.file.api.IUserService;
|
||||
import com.qiwenshare.file.domain.UserBean;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@ -15,25 +18,28 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* token验证拦截
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
log.info("---------------------------------------------------------");
|
||||
// 取得token
|
||||
String tokenHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
|
||||
if (tokenHeader == null || "".equals(tokenHeader)) {
|
||||
throw new Exception("token不存在");
|
||||
String token = request.getHeader("token");//HttpHeaders.AUTHORIZATION
|
||||
if("undefined".equals(token) || StringUtils.isEmpty(token)){
|
||||
token=request.getParameter("token不存在");
|
||||
}
|
||||
if (!tokenHeader.startsWith("Bearer")) {
|
||||
throw new Exception("token格式错误");
|
||||
if ("undefined".equals(token) || StringUtils.isEmpty(token)) {
|
||||
throw new NotLoginException("token不存在");
|
||||
}
|
||||
String token = tokenHeader.replace("Bearer", "");
|
||||
if (!token.startsWith("Bearer ")) {
|
||||
throw new NotLoginException("token格式错误");
|
||||
}
|
||||
token = token.replace("Bearer ", "");
|
||||
UserBean userBean = userService.getUserBeanByToken(token);
|
||||
if (userBean == null) {
|
||||
return false;
|
||||
throw new NotLoginException();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.qiwenshare.common.constant.FileConstant;
|
||||
import com.qiwenshare.common.util.DateUtil;
|
||||
import com.qiwenshare.file.api.IUserFileService;
|
||||
import com.qiwenshare.common.config.QiwenFileConfig;
|
||||
@ -183,7 +184,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
if (userFile.getIsDir() == 1) {
|
||||
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<UserFile>();
|
||||
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(10))
|
||||
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(FileConstant.deleteFileRandomSize))
|
||||
.set(UserFile::getDeleteBatchNum, uuid)
|
||||
.set(UserFile::getDeleteTime, DateUtil.getCurrentTime())
|
||||
.eq(UserFile::getUserFileId, userFileId);
|
||||
@ -193,20 +194,15 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
updateFileDeleteStateByFilePath(filePath, userFile.getDeleteBatchNum(), sessionUserId);
|
||||
|
||||
}else{
|
||||
|
||||
UserFile userFileTemp = userFileMapper.selectById(userFileId);
|
||||
FileBean fileBean = fileMapper.selectById(userFileTemp.getFileId());
|
||||
|
||||
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(10))
|
||||
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(FileConstant.deleteFileRandomSize))
|
||||
.set(UserFile::getDeleteTime, DateUtil.getCurrentTime())
|
||||
.set(UserFile::getDeleteBatchNum, uuid)
|
||||
.eq(UserFile::getUserFileId, userFileTemp.getUserFileId());
|
||||
userFileMapper.update(null, userFileLambdaUpdateWrapper);
|
||||
|
||||
}
|
||||
|
||||
|
||||
RecoveryFile recoveryFile = new RecoveryFile();
|
||||
recoveryFile.setUserFileId(userFileId);
|
||||
recoveryFile.setDeleteTime(DateUtil.getCurrentTime());
|
||||
@ -226,7 +222,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
public void run() {
|
||||
//标记删除标志
|
||||
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper1 = new LambdaUpdateWrapper<>();
|
||||
userFileLambdaUpdateWrapper1.set(UserFile::getDeleteFlag, RandomUtil.randomInt(10))
|
||||
userFileLambdaUpdateWrapper1.set(UserFile::getDeleteFlag, RandomUtil.randomInt(FileConstant.deleteFileRandomSize))
|
||||
.set(UserFile::getDeleteTime, DateUtil.getCurrentTime())
|
||||
.set(UserFile::getDeleteBatchNum, deleteBatchNum)
|
||||
.eq(UserFile::getUserFileId, userFileTemp.getUserFileId())
|
||||
|
@ -8,6 +8,7 @@ import com.qiwenshare.common.result.RestResult;
|
||||
import com.qiwenshare.common.util.JjwtUtil;
|
||||
import com.qiwenshare.common.util.PasswordUtil;
|
||||
import com.qiwenshare.file.api.IUserService;
|
||||
import com.qiwenshare.file.component.UserDealComp;
|
||||
import com.qiwenshare.file.controller.UserController;
|
||||
import com.qiwenshare.file.domain.UserBean;
|
||||
import com.qiwenshare.file.mapper.UserMapper;
|
||||
@ -29,15 +30,20 @@ public class UserService extends ServiceImpl<UserMapper, UserBean> implements IU
|
||||
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
@Resource
|
||||
UserDealComp userDealComp;
|
||||
|
||||
@Override
|
||||
public UserBean getUserBeanByToken(String token){
|
||||
Claims c = null;
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
return null;
|
||||
}
|
||||
token = token.replace("Bearer ", "");
|
||||
try {
|
||||
log.debug("token:" + token);
|
||||
c = JjwtUtil.parseJWT(token);
|
||||
} catch (Exception e) {
|
||||
log.error("解码异常");
|
||||
log.error("解码异常:" + e);
|
||||
return null;
|
||||
}
|
||||
if (c == null) {
|
||||
@ -111,13 +117,13 @@ public class UserService extends ServiceImpl<UserMapper, UserBean> implements IU
|
||||
if (userBean.getUsername() == null || "".equals(userBean.getUsername())){
|
||||
return RestResult.fail().message("用户名不能为空!");
|
||||
}
|
||||
if (isUserNameExit(userBean)) {
|
||||
if (userDealComp.isUserNameExit(userBean)) {
|
||||
return RestResult.fail().message("用户名已存在!");
|
||||
}
|
||||
if (!isPhoneFormatRight(userBean.getTelephone())){
|
||||
if (!userDealComp.isPhoneFormatRight(userBean.getTelephone())){
|
||||
return RestResult.fail().message("手机号格式不正确!");
|
||||
}
|
||||
if (isPhoneExit(userBean)) {
|
||||
if (userDealComp.isPhoneExit(userBean)) {
|
||||
return RestResult.fail().message("手机号已存在!");
|
||||
}
|
||||
|
||||
@ -131,9 +137,6 @@ public class UserService extends ServiceImpl<UserMapper, UserBean> implements IU
|
||||
userBean.setRegisterTime(DateUtil.getCurrentTime());
|
||||
int result = userMapper.insertUser(userBean);
|
||||
userMapper.insertUserRole(userBean.getUserId(), 2);
|
||||
// UserImageBean userImageBean = new UserImageBean();
|
||||
// userImageBean.setImageUrl("");
|
||||
// userImageBean.setUserId(userBean.getUserId());
|
||||
if (result == 1) {
|
||||
return RestResult.success();
|
||||
} else {
|
||||
@ -143,46 +146,6 @@ public class UserService extends ServiceImpl<UserMapper, UserBean> implements IU
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 检测用户名是否存在
|
||||
*
|
||||
* @param userBean
|
||||
*/
|
||||
private Boolean isUserNameExit(UserBean userBean) {
|
||||
LambdaQueryWrapper<UserBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserBean::getUsername, userBean.getUsername());
|
||||
List<UserBean> list = userMapper.selectList(lambdaQueryWrapper);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机号是否存在
|
||||
*
|
||||
* @param userBean
|
||||
* @return
|
||||
*/
|
||||
private Boolean isPhoneExit(UserBean userBean) {
|
||||
|
||||
LambdaQueryWrapper<UserBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserBean::getTelephone, userBean.getTelephone());
|
||||
List<UserBean> list = userMapper.selectList(lambdaQueryWrapper);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Boolean isPhoneFormatRight(String phone){
|
||||
String regex = "^1\\d{10}";
|
||||
boolean isRight = Pattern.matches(regex, phone);
|
||||
return isRight;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -33,41 +33,4 @@
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- <update id="updateFile" parameterType="java">-->
|
||||
<!-- <choose>-->
|
||||
<!-- <when test="isDir == 1">-->
|
||||
<!-- UPDATE file SET filename=#{fileName}, uploadTime = #{uploadTime}-->
|
||||
<!-- where fileId = #{fileId};-->
|
||||
<!-- UPDATE file SET filepath=REPLACE(filepath, #{oldFilePath}, #{filePath}) WHERE filepath LIKE N'${oldFilePath}%';-->
|
||||
<!-- </when>-->
|
||||
<!-- <otherwise>-->
|
||||
<!-- update file-->
|
||||
<!-- <set>-->
|
||||
<!-- <if test="fileName != null">-->
|
||||
<!-- fileName = #{fileName},-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="uploadTime != null">-->
|
||||
<!-- uploadTime = #{uploadTime},-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="fileUrl != null">-->
|
||||
<!-- fileUrl = #{fileUrl},-->
|
||||
<!-- </if>-->
|
||||
<!-- </set>-->
|
||||
<!-- where fileId = #{fileId}-->
|
||||
<!-- </otherwise>-->
|
||||
<!-- </choose>-->
|
||||
|
||||
<!-- </update>-->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user