diff --git a/src/main/java/com/huoran/iasf/common/exception/UnauthorizedException.java b/src/main/java/com/huoran/iasf/common/exception/UnauthorizedException.java new file mode 100644 index 0000000..50d03a4 --- /dev/null +++ b/src/main/java/com/huoran/iasf/common/exception/UnauthorizedException.java @@ -0,0 +1,13 @@ +package com.huoran.iasf.common.exception; + +import com.huoran.iasf.common.exception.code.BaseResponseCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class UnauthorizedException extends RuntimeException { + private BaseResponseCode baseResponseCode; +} diff --git a/src/main/java/com/huoran/iasf/common/exception/handler/RestExceptionHandler.java b/src/main/java/com/huoran/iasf/common/exception/handler/RestExceptionHandler.java index 6a95f10..aec72d8 100644 --- a/src/main/java/com/huoran/iasf/common/exception/handler/RestExceptionHandler.java +++ b/src/main/java/com/huoran/iasf/common/exception/handler/RestExceptionHandler.java @@ -3,6 +3,7 @@ package com.huoran.iasf.common.exception.handler; import com.google.common.collect.Maps; import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.NotFoundException; +import com.huoran.iasf.common.exception.UnauthorizedException; import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.utils.R; import lombok.extern.slf4j.Slf4j; @@ -63,13 +64,24 @@ public class RestExceptionHandler { * 自定义全局异常处理 */ @ExceptionHandler(value = BusinessException.class) - @ResponseStatus(HttpStatus.UNAUTHORIZED) + @ResponseStatus(HttpStatus.OK) public R businessExceptionHandler(BusinessException e) { log.error("Exception,exception:{}", e, e); BaseResponseCode em = e.getBaseResponseCode(); return new R(em.getCode(), em.getMsg()); } + /** + * 权限全局异常处理 + */ + @ExceptionHandler(value = UnauthorizedException.class) + @ResponseStatus(HttpStatus.UNAUTHORIZED) + public R businessExceptionHandler(UnauthorizedException e) { + log.error("Exception,exception:{}", e, e); + BaseResponseCode em = e.getBaseResponseCode(); + return new R(em.getCode(), em.getMsg()); + } + @ExceptionHandler(value = NotFoundException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public R businessExceptionHandler(NotFoundException e) { diff --git a/src/main/java/com/huoran/iasf/common/filter/AuthFilter.java b/src/main/java/com/huoran/iasf/common/filter/AuthFilter.java index da1c07c..e69a49a 100644 --- a/src/main/java/com/huoran/iasf/common/filter/AuthFilter.java +++ b/src/main/java/com/huoran/iasf/common/filter/AuthFilter.java @@ -2,6 +2,7 @@ package com.huoran.iasf.common.filter; import com.huoran.iasf.common.exception.BusinessException; +import com.huoran.iasf.common.exception.UnauthorizedException; import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.utils.Constant; import io.jsonwebtoken.Claims; @@ -9,20 +10,16 @@ import io.jsonwebtoken.Jwts; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; -import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; import javax.servlet.*; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; import java.util.Arrays; import static com.huoran.iasf.service.HttpApiSessionService.*; -import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; /** * shiro过滤器 登录用户权限认证授权 @@ -47,13 +44,6 @@ public class AuthFilter implements Filter { @SneakyThrows public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { //每一次的请求先校验cookie -// HttpServletResponse httpResponse = (HttpServletResponse) response; -// HttpServletRequest httpRequest = (HttpServletRequest) request; -// httpResponse.setHeader("Access-Control-Allow-Origin", httpRequest.getHeader("Origin")); -// httpResponse.setHeader("Access-Control-Allow-Methods", httpRequest.getMethod()); -// httpResponse.setHeader("Access-Control-Max-Age", "3600"); -// httpResponse.setHeader("Access-Control-Allow-Headers", httpRequest.getHeader("Access-Control-Request-Headers")); -// chain.doFilter(request, response); HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; @@ -79,7 +69,7 @@ public class AuthFilter implements Filter { resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); resp.setCharacterEncoding("utf-8"); resp.setContentType(MediaType.APPLICATION_JSON_VALUE); - request.setAttribute("filterError", new BusinessException(BaseResponseCode.TOKEN_ERROR)); + request.setAttribute("filterError", new UnauthorizedException(BaseResponseCode.TOKEN_ERROR)); // 指定处理该请求的处理器 request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, resp); } @@ -89,7 +79,7 @@ public class AuthFilter implements Filter { resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); resp.setCharacterEncoding("utf-8"); resp.setContentType(MediaType.APPLICATION_JSON_VALUE); - request.setAttribute("filterError", new BusinessException(BaseResponseCode.TOKEN_ERROR)); + request.setAttribute("filterError", new UnauthorizedException(BaseResponseCode.TOKEN_ERROR)); // 指定处理该请求的处理器 request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, resp); }else { diff --git a/src/main/java/com/huoran/iasf/common/shiro/CustomAccessControlFilter.java b/src/main/java/com/huoran/iasf/common/shiro/CustomAccessControlFilter.java index 4e8fa7c..4c8d8a3 100644 --- a/src/main/java/com/huoran/iasf/common/shiro/CustomAccessControlFilter.java +++ b/src/main/java/com/huoran/iasf/common/shiro/CustomAccessControlFilter.java @@ -2,6 +2,7 @@ package com.huoran.iasf.common.shiro; import com.alibaba.fastjson.JSON; import com.huoran.iasf.common.exception.BusinessException; +import com.huoran.iasf.common.exception.UnauthorizedException; import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.utils.Constant; import com.huoran.iasf.common.utils.R; @@ -83,7 +84,7 @@ public class CustomAccessControlFilter extends AccessControlFilter { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setCharacterEncoding("utf-8"); response.setContentType(MediaType.APPLICATION_JSON_VALUE); - request.setAttribute("filterError", new BusinessException(BaseResponseCode.TOKEN_ERROR)); + request.setAttribute("filterError", new UnauthorizedException(BaseResponseCode.TOKEN_ERROR)); // 指定处理该请求的处理器 request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, response); } @@ -93,7 +94,7 @@ public class CustomAccessControlFilter extends AccessControlFilter { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setCharacterEncoding("utf-8"); response.setContentType(MediaType.APPLICATION_JSON_VALUE); - request.setAttribute("filterError", new BusinessException(BaseResponseCode.TOKEN_ERROR)); + request.setAttribute("filterError", new UnauthorizedException(BaseResponseCode.TOKEN_ERROR)); // 指定处理该请求的处理器 request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, response); }else { diff --git a/src/main/java/com/huoran/iasf/controller/SysFilesController.java b/src/main/java/com/huoran/iasf/controller/SysFilesController.java index a7e9210..c470442 100644 --- a/src/main/java/com/huoran/iasf/controller/SysFilesController.java +++ b/src/main/java/com/huoran/iasf/controller/SysFilesController.java @@ -124,7 +124,9 @@ public class SysFilesController { @PostMapping("/listByPage") @RequiresPermissions("sysFiles:list") public R findListByPage(@RequestBody SysFilesEntity sysFiles) { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + return sysFilesService.getPage(sysFiles); + + /*LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); if (!StringUtils.isEmpty(sysFiles.getFileName())) { queryWrapper.like(SysFilesEntity::getFileName, sysFiles.getFileName()); } @@ -155,7 +157,7 @@ public class SysFilesController { } } }); - return R.success(iPage); + return R.success(iPage);*/ } } diff --git a/src/main/java/com/huoran/iasf/mapper/SysDeptMapper.java b/src/main/java/com/huoran/iasf/mapper/SysDeptMapper.java index 4b98776..47c0cc5 100644 --- a/src/main/java/com/huoran/iasf/mapper/SysDeptMapper.java +++ b/src/main/java/com/huoran/iasf/mapper/SysDeptMapper.java @@ -2,6 +2,7 @@ package com.huoran.iasf.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.huoran.iasf.entity.SysDept; +import org.apache.ibatis.annotations.Mapper; /** * 部门 Mapper @@ -10,5 +11,6 @@ import com.huoran.iasf.entity.SysDept; * @version V1.0 * @date 2022年7月28日 */ +@Mapper public interface SysDeptMapper extends BaseMapper { } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/mapper/SysFilesMapper.java b/src/main/java/com/huoran/iasf/mapper/SysFilesMapper.java index cdff573..38e19bb 100644 --- a/src/main/java/com/huoran/iasf/mapper/SysFilesMapper.java +++ b/src/main/java/com/huoran/iasf/mapper/SysFilesMapper.java @@ -1,7 +1,11 @@ package com.huoran.iasf.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.huoran.iasf.entity.SysFilesEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 文件上传 Mapper @@ -10,6 +14,8 @@ import com.huoran.iasf.entity.SysFilesEntity; * @version V1.0 * @date 2022年7月28日 */ +@Mapper public interface SysFilesMapper extends BaseMapper { + IPage fileList(Page page, @Param("req")SysFilesEntity sysFiles); } diff --git a/src/main/java/com/huoran/iasf/mapper/xml/SysFilesMapper.xml b/src/main/java/com/huoran/iasf/mapper/xml/SysFilesMapper.xml new file mode 100644 index 0000000..12e4792 --- /dev/null +++ b/src/main/java/com/huoran/iasf/mapper/xml/SysFilesMapper.xml @@ -0,0 +1,49 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/service/SysFilesService.java b/src/main/java/com/huoran/iasf/service/SysFilesService.java index 399ceb2..3880148 100644 --- a/src/main/java/com/huoran/iasf/service/SysFilesService.java +++ b/src/main/java/com/huoran/iasf/service/SysFilesService.java @@ -1,6 +1,7 @@ package com.huoran.iasf.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.huoran.iasf.common.utils.R; import com.huoran.iasf.entity.SysFilesEntity; import com.huoran.iasf.vo.UEditorResultVO; import com.huoran.iasf.vo.req.FileParameters; @@ -29,5 +30,7 @@ public interface SysFilesService extends IService { void preview(String id, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException; void download(String id, HttpServletRequest req, HttpServletResponse res); + + R getPage(SysFilesEntity sysFiles); } diff --git a/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java index 3a3e9bf..29bd997 100644 --- a/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java @@ -123,10 +123,7 @@ public class DeptServiceImpl extends ServiceImpl impleme throw new BusinessException(BaseResponseCode.DATA_ERROR); } List deptIds = sysDeptMapper.selectObjs(Wrappers.lambdaQuery().select(SysDept::getId).likeRight(SysDept::getRelationCode, sysDept.getRelationCode())); - /*List list = sysUserMapper.selectList(Wrappers.lambdaQuery().in(SysUser::getDeptId, deptIds)); - if (!CollectionUtils.isEmpty(list)) { - throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT); - }*/ + List list = userDeptMapper.selectList(Wrappers.lambdaQuery().in(UserDept::getDeptId, deptIds)); if (!CollectionUtils.isEmpty(list)) { throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT); diff --git a/src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java index 68f2665..1574384 100644 --- a/src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java @@ -4,12 +4,15 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.huoran.iasf.common.config.FileUploadProperties; import com.huoran.iasf.common.config.NonStaticResourceHttpRequestConfig; import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.utils.DateUtils; +import com.huoran.iasf.common.utils.R; import com.huoran.iasf.entity.SysFilesEntity; import com.huoran.iasf.mapper.SysFilesMapper; import com.huoran.iasf.service.SysFilesService; @@ -37,10 +40,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Date; -import java.util.Enumeration; -import java.util.List; -import java.util.UUID; +import java.util.*; import java.util.regex.Pattern; /** @@ -310,4 +310,12 @@ public class SysFilesServiceImpl extends ServiceImpl page = new Page<>(1, 10); + + IPage fileList = baseMapper.fileList(page, sysFiles); + return R.success(fileList); + } } \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 32b1191..3ba0eee 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -6,11 +6,11 @@ spring: datasource: master: username: root -# password: 123456 - password: iasf#2022 + password: 123456 +# password: iasf#2022 driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://127.0.0.1:3306/iasf?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2b8 -# url: jdbc:mysql://192.168.31.136:3306/iasf?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2b8 +# url: jdbc:mysql://127.0.0.1:3306/iasf?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2b8 + url: jdbc:mysql://192.168.31.136:3306/iasf?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2b8 cache: type: redis redis: