From 98e5db30cc4fab8bc242ec5c3b96547c2f484614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E8=B6=85?= <1162714483@qq.com> Date: Thu, 22 Apr 2021 00:17:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/FileConstant.java | 1 + .../com/qiwenshare/common/util/PathUtil.java | 10 +- .../file/component/FileDealComp.java | 127 +++++++++--------- .../file/component/UserDealComp.java | 58 ++++++++ .../qiwenshare/file/config/WebMvcConfig.java | 52 +++++++ .../file/controller/FileController.java | 65 +-------- .../controller/FiletransferController.java | 13 +- .../file/controller/UserController.java | 12 +- .../AuthenticationInterceptor.java | 22 +-- .../file/service/UserFileService.java | 12 +- .../qiwenshare/file/service/UserService.java | 59 ++------ .../resources/mybatis/mapper/ShareMapper.xml | 37 ----- pom.xml | 1 - 13 files changed, 215 insertions(+), 254 deletions(-) create mode 100644 file-web/src/main/java/com/qiwenshare/file/component/UserDealComp.java create mode 100644 file-web/src/main/java/com/qiwenshare/file/config/WebMvcConfig.java diff --git a/file-common/src/main/java/com/qiwenshare/common/constant/FileConstant.java b/file-common/src/main/java/com/qiwenshare/common/constant/FileConstant.java index a6051e9..73cdec0 100644 --- a/file-common/src/main/java/com/qiwenshare/common/constant/FileConstant.java +++ b/file-common/src/main/java/com/qiwenshare/common/constant/FileConstant.java @@ -5,5 +5,6 @@ public class FileConstant { * 路径分隔符 */ public static final String pathSeparator = "/"; + public static final int deleteFileRandomSize = 999999; } diff --git a/file-common/src/main/java/com/qiwenshare/common/util/PathUtil.java b/file-common/src/main/java/com/qiwenshare/common/util/PathUtil.java index f870382..8e58685 100644 --- a/file-common/src/main/java/com/qiwenshare/common/util/PathUtil.java +++ b/file-common/src/main/java/com/qiwenshare/common/util/PathUtil.java @@ -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); } } diff --git a/file-web/src/main/java/com/qiwenshare/file/component/FileDealComp.java b/file-web/src/main/java/com/qiwenshare/file/component/FileDealComp.java index 691420e..9949ad4 100644 --- a/file-web/src/main/java/com/qiwenshare/file/component/FileDealComp.java +++ b/file-web/src/main/java/com/qiwenshare/file/component/FileDealComp.java @@ -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 nodeNameQueue){ -// -// List childrenTreeNodes = treeNode.getChildren(); -// String currentNodeName = nodeNameQueue.peek(); -// if (currentNodeName == null){ -// return treeNode; -// } -// -// Map 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 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 nodeNameQueue){ + + List 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 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; + } } diff --git a/file-web/src/main/java/com/qiwenshare/file/component/UserDealComp.java b/file-web/src/main/java/com/qiwenshare/file/component/UserDealComp.java new file mode 100644 index 0000000..89c461a --- /dev/null +++ b/file-web/src/main/java/com/qiwenshare/file/component/UserDealComp.java @@ -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 lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(UserBean::getUsername, userBean.getUsername()); + List list = userMapper.selectList(lambdaQueryWrapper); + if (list != null && !list.isEmpty()) { + return true; + } else { + return false; + } + } + + /** + * 检测手机号是否存在 + * + * @param userBean + * @return + */ + public Boolean isPhoneExit(UserBean userBean) { + + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(UserBean::getTelephone, userBean.getTelephone()); + List 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; + } +} diff --git a/file-web/src/main/java/com/qiwenshare/file/config/WebMvcConfig.java b/file-web/src/main/java/com/qiwenshare/file/config/WebMvcConfig.java new file mode 100644 index 0000000..29c13e8 --- /dev/null +++ b/file-web/src/main/java/com/qiwenshare/file/config/WebMvcConfig.java @@ -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 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"); + + } +} \ No newline at end of file diff --git a/file-web/src/main/java/com/qiwenshare/file/controller/FileController.java b/file-web/src/main/java/com/qiwenshare/file/controller/FileController.java index 3b1f54f..384a990 100644 --- a/file-web/src/main/java/com/qiwenshare/file/controller/FileController.java +++ b/file-web/src/main/java/com/qiwenshare/file/controller/FileController.java @@ -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 nodeNameQueue){ - List 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 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; - } } diff --git a/file-web/src/main/java/com/qiwenshare/file/controller/FiletransferController.java b/file-web/src/main/java/com/qiwenshare/file/controller/FiletransferController.java index c182b35..36aefef 100644 --- a/file-web/src/main/java/com/qiwenshare/file/controller/FiletransferController.java +++ b/file-web/src/main/java/com/qiwenshare/file/controller/FiletransferController.java @@ -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)) { diff --git a/file-web/src/main/java/com/qiwenshare/file/controller/UserController.java b/file-web/src/main/java/com/qiwenshare/file/controller/UserController.java index 58ebcfd..c2fe1f2 100644 --- a/file-web/src/main/java/com/qiwenshare/file/controller/UserController.java +++ b/file-web/src/main/java/com/qiwenshare/file/controller/UserController.java @@ -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 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 { diff --git a/file-web/src/main/java/com/qiwenshare/file/interceptor/AuthenticationInterceptor.java b/file-web/src/main/java/com/qiwenshare/file/interceptor/AuthenticationInterceptor.java index 5f2c2ce..92dcd1a 100644 --- a/file-web/src/main/java/com/qiwenshare/file/interceptor/AuthenticationInterceptor.java +++ b/file-web/src/main/java/com/qiwenshare/file/interceptor/AuthenticationInterceptor.java @@ -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; diff --git a/file-web/src/main/java/com/qiwenshare/file/service/UserFileService.java b/file-web/src/main/java/com/qiwenshare/file/service/UserFileService.java index 393d661..2bf6a30 100644 --- a/file-web/src/main/java/com/qiwenshare/file/service/UserFileService.java +++ b/file-web/src/main/java/com/qiwenshare/file/service/UserFileService.java @@ -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 impl String uuid = UUID.randomUUID().toString(); if (userFile.getIsDir() == 1) { LambdaUpdateWrapper userFileLambdaUpdateWrapper = new LambdaUpdateWrapper(); - 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 impl updateFileDeleteStateByFilePath(filePath, userFile.getDeleteBatchNum(), sessionUserId); }else{ - UserFile userFileTemp = userFileMapper.selectById(userFileId); - FileBean fileBean = fileMapper.selectById(userFileTemp.getFileId()); - LambdaUpdateWrapper 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 impl public void run() { //标记删除标志 LambdaUpdateWrapper 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()) diff --git a/file-web/src/main/java/com/qiwenshare/file/service/UserService.java b/file-web/src/main/java/com/qiwenshare/file/service/UserService.java index 385d62c..69d1e90 100644 --- a/file-web/src/main/java/com/qiwenshare/file/service/UserService.java +++ b/file-web/src/main/java/com/qiwenshare/file/service/UserService.java @@ -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 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 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 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 implements IU - /** - * 检测用户名是否存在 - * - * @param userBean - */ - private Boolean isUserNameExit(UserBean userBean) { - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(UserBean::getUsername, userBean.getUsername()); - List list = userMapper.selectList(lambdaQueryWrapper); - if (list != null && !list.isEmpty()) { - return true; - } else { - return false; - } - } - - /** - * 检测手机号是否存在 - * - * @param userBean - * @return - */ - private Boolean isPhoneExit(UserBean userBean) { - - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(UserBean::getTelephone, userBean.getTelephone()); - List 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; - } /** diff --git a/file-web/src/main/resources/mybatis/mapper/ShareMapper.xml b/file-web/src/main/resources/mybatis/mapper/ShareMapper.xml index 3ce7065..1f5f71a 100644 --- a/file-web/src/main/resources/mybatis/mapper/ShareMapper.xml +++ b/file-web/src/main/resources/mybatis/mapper/ShareMapper.xml @@ -33,41 +33,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index fa44a75..d432196 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,6 @@ file-common file-web -