Merge remote-tracking branch 'origin/master'

master
rong.liu 2 years ago
commit cd11e047e2
  1. 13
      src/main/java/com/huoran/iasf/common/exception/UnauthorizedException.java
  2. 14
      src/main/java/com/huoran/iasf/common/exception/handler/RestExceptionHandler.java
  3. 16
      src/main/java/com/huoran/iasf/common/filter/AuthFilter.java
  4. 5
      src/main/java/com/huoran/iasf/common/shiro/CustomAccessControlFilter.java
  5. 6
      src/main/java/com/huoran/iasf/controller/SysFilesController.java
  6. 2
      src/main/java/com/huoran/iasf/mapper/SysDeptMapper.java
  7. 6
      src/main/java/com/huoran/iasf/mapper/SysFilesMapper.java
  8. 49
      src/main/java/com/huoran/iasf/mapper/xml/SysFilesMapper.xml
  9. 3
      src/main/java/com/huoran/iasf/service/SysFilesService.java
  10. 5
      src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java
  11. 16
      src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java
  12. 8
      src/main/resources/application-dev.yml

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

@ -3,6 +3,7 @@ package com.huoran.iasf.common.exception.handler;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.NotFoundException; 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.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.R; import com.huoran.iasf.common.utils.R;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -63,13 +64,24 @@ public class RestExceptionHandler {
* 自定义全局异常处理 * 自定义全局异常处理
*/ */
@ExceptionHandler(value = BusinessException.class) @ExceptionHandler(value = BusinessException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED) @ResponseStatus(HttpStatus.OK)
public R businessExceptionHandler(BusinessException e) { public R businessExceptionHandler(BusinessException e) {
log.error("Exception,exception:{}", e, e); log.error("Exception,exception:{}", e, e);
BaseResponseCode em = e.getBaseResponseCode(); BaseResponseCode em = e.getBaseResponseCode();
return new R(em.getCode(), em.getMsg()); 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) @ExceptionHandler(value = NotFoundException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R businessExceptionHandler(NotFoundException e) { public R businessExceptionHandler(NotFoundException e) {

@ -2,6 +2,7 @@ package com.huoran.iasf.common.filter;
import com.huoran.iasf.common.exception.BusinessException; 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.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.Constant; import com.huoran.iasf.common.utils.Constant;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
@ -9,20 +10,16 @@ import io.jsonwebtoken.Jwts;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import javax.servlet.*; import javax.servlet.*;
import javax.servlet.annotation.WebFilter; import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import static com.huoran.iasf.service.HttpApiSessionService.*; import static com.huoran.iasf.service.HttpApiSessionService.*;
import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
/** /**
* shiro过滤器 登录用户权限认证授权 * shiro过滤器 登录用户权限认证授权
@ -47,13 +44,6 @@ public class AuthFilter implements Filter {
@SneakyThrows @SneakyThrows
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
//每一次的请求先校验cookie //每一次的请求先校验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; HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response; HttpServletResponse resp = (HttpServletResponse) response;
@ -79,7 +69,7 @@ public class AuthFilter implements Filter {
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
resp.setCharacterEncoding("utf-8"); resp.setCharacterEncoding("utf-8");
resp.setContentType(MediaType.APPLICATION_JSON_VALUE); 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); request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, resp);
} }
@ -89,7 +79,7 @@ public class AuthFilter implements Filter {
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
resp.setCharacterEncoding("utf-8"); resp.setCharacterEncoding("utf-8");
resp.setContentType(MediaType.APPLICATION_JSON_VALUE); 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); request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, resp);
}else { }else {

@ -2,6 +2,7 @@ package com.huoran.iasf.common.shiro;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.huoran.iasf.common.exception.BusinessException; 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.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.Constant; import com.huoran.iasf.common.utils.Constant;
import com.huoran.iasf.common.utils.R; import com.huoran.iasf.common.utils.R;
@ -83,7 +84,7 @@ public class CustomAccessControlFilter extends AccessControlFilter {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
response.setContentType(MediaType.APPLICATION_JSON_VALUE); 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); request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, response);
} }
@ -93,7 +94,7 @@ public class CustomAccessControlFilter extends AccessControlFilter {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
response.setContentType(MediaType.APPLICATION_JSON_VALUE); 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); request.getRequestDispatcher(Constant.ERROR_CONTROLLER_PATH).forward(request, response);
}else { }else {

@ -124,7 +124,9 @@ public class SysFilesController {
@PostMapping("/listByPage") @PostMapping("/listByPage")
@RequiresPermissions("sysFiles:list") @RequiresPermissions("sysFiles:list")
public R findListByPage(@RequestBody SysFilesEntity sysFiles) { public R findListByPage(@RequestBody SysFilesEntity sysFiles) {
LambdaQueryWrapper<SysFilesEntity> queryWrapper = Wrappers.lambdaQuery(); return sysFilesService.getPage(sysFiles);
/*LambdaQueryWrapper<SysFilesEntity> queryWrapper = Wrappers.lambdaQuery();
if (!StringUtils.isEmpty(sysFiles.getFileName())) { if (!StringUtils.isEmpty(sysFiles.getFileName())) {
queryWrapper.like(SysFilesEntity::getFileName, sysFiles.getFileName()); queryWrapper.like(SysFilesEntity::getFileName, sysFiles.getFileName());
} }
@ -155,7 +157,7 @@ public class SysFilesController {
} }
} }
}); });
return R.success(iPage); return R.success(iPage);*/
} }
} }

@ -2,6 +2,7 @@ package com.huoran.iasf.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huoran.iasf.entity.SysDept; import com.huoran.iasf.entity.SysDept;
import org.apache.ibatis.annotations.Mapper;
/** /**
* 部门 Mapper * 部门 Mapper
@ -10,5 +11,6 @@ import com.huoran.iasf.entity.SysDept;
* @version V1.0 * @version V1.0
* @date 2022年7月28日 * @date 2022年7月28日
*/ */
@Mapper
public interface SysDeptMapper extends BaseMapper<SysDept> { public interface SysDeptMapper extends BaseMapper<SysDept> {
} }

@ -1,7 +1,11 @@
package com.huoran.iasf.mapper; package com.huoran.iasf.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; 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 com.huoran.iasf.entity.SysFilesEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/** /**
* 文件上传 Mapper * 文件上传 Mapper
@ -10,6 +14,8 @@ import com.huoran.iasf.entity.SysFilesEntity;
* @version V1.0 * @version V1.0
* @date 2022年7月28日 * @date 2022年7月28日
*/ */
@Mapper
public interface SysFilesMapper extends BaseMapper<SysFilesEntity> { public interface SysFilesMapper extends BaseMapper<SysFilesEntity> {
IPage<SysFilesEntity> fileList(Page<SysFilesEntity> page, @Param("req")SysFilesEntity sysFiles);
} }

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.huoran.iasf.mapper.SysFilesMapper">
<select id="fileList" resultType="com.huoran.iasf.entity.SysFilesEntity"
parameterType="com.huoran.iasf.entity.SysFilesEntity">
SELECT
f.id,
f.url,
f.file_name,
f.format,
f.file_path,
f.file_size,
f.type,
f.deleted,
f.quote,
f.site,
f.is_release,
f.is_del,
f.quote_id,
f.quote_type,
f.create_date,
u.real_name AS uploader
FROM
sys_files f
LEFT JOIN sys_user u ON f.uploader = u.id
WHERE
AND f.site = 1
AND f.deleted = 1
AND f.is_release = 1
AND f.is_del = 0
and f.quote is not null
<if test="req.type != '' and req.type != null">
AND f.type = #{req.type}
</if>
<if test="req.fileName != '' and req.fileName != null">
AND f.file_name LIKE '%' #{req.fileName} '%'
</if>
<if test="req.uploader != '' and req.uploader != null">
AND u.real_name LIKE '%' #{req.uploader} '%'
</if>
<if test="req.quote != '' and req.quote != null">
AND f.quote LIKE '%' #{req.quote} '%'
</if>
ORDER BY
f.create_date DESC
</select>
</mapper>

@ -1,6 +1,7 @@
package com.huoran.iasf.service; package com.huoran.iasf.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysFilesEntity; import com.huoran.iasf.entity.SysFilesEntity;
import com.huoran.iasf.vo.UEditorResultVO; import com.huoran.iasf.vo.UEditorResultVO;
import com.huoran.iasf.vo.req.FileParameters; import com.huoran.iasf.vo.req.FileParameters;
@ -29,5 +30,7 @@ public interface SysFilesService extends IService<SysFilesEntity> {
void preview(String id, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException; void preview(String id, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException;
void download(String id, HttpServletRequest req, HttpServletResponse res); void download(String id, HttpServletRequest req, HttpServletResponse res);
R getPage(SysFilesEntity sysFiles);
} }

@ -123,10 +123,7 @@ public class DeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impleme
throw new BusinessException(BaseResponseCode.DATA_ERROR); throw new BusinessException(BaseResponseCode.DATA_ERROR);
} }
List<Object> deptIds = sysDeptMapper.selectObjs(Wrappers.<SysDept>lambdaQuery().select(SysDept::getId).likeRight(SysDept::getRelationCode, sysDept.getRelationCode())); List<Object> deptIds = sysDeptMapper.selectObjs(Wrappers.<SysDept>lambdaQuery().select(SysDept::getId).likeRight(SysDept::getRelationCode, sysDept.getRelationCode()));
/*List<SysUser> list = sysUserMapper.selectList(Wrappers.<SysUser>lambdaQuery().in(SysUser::getDeptId, deptIds));
if (!CollectionUtils.isEmpty(list)) {
throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT);
}*/
List<UserDept> list = userDeptMapper.selectList(Wrappers.<UserDept>lambdaQuery().in(UserDept::getDeptId, deptIds)); List<UserDept> list = userDeptMapper.selectList(Wrappers.<UserDept>lambdaQuery().in(UserDept::getDeptId, deptIds));
if (!CollectionUtils.isEmpty(list)) { if (!CollectionUtils.isEmpty(list)) {
throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT); throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT);

@ -4,12 +4,15 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huoran.iasf.common.config.FileUploadProperties; import com.huoran.iasf.common.config.FileUploadProperties;
import com.huoran.iasf.common.config.NonStaticResourceHttpRequestConfig; import com.huoran.iasf.common.config.NonStaticResourceHttpRequestConfig;
import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.DateUtils; import com.huoran.iasf.common.utils.DateUtils;
import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysFilesEntity; import com.huoran.iasf.entity.SysFilesEntity;
import com.huoran.iasf.mapper.SysFilesMapper; import com.huoran.iasf.mapper.SysFilesMapper;
import com.huoran.iasf.service.SysFilesService; import com.huoran.iasf.service.SysFilesService;
@ -37,10 +40,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Date; import java.util.*;
import java.util.Enumeration;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
@ -310,4 +310,12 @@ public class SysFilesServiceImpl extends ServiceImpl<SysFilesMapper, SysFilesEnt
} }
return ""; return "";
} }
@Override
public R getPage(SysFilesEntity sysFiles) {
Page<SysFilesEntity> page = new Page<>(1, 10);
IPage<SysFilesEntity> fileList = baseMapper.fileList(page, sysFiles);
return R.success(fileList);
}
} }

@ -6,11 +6,11 @@ spring:
datasource: datasource:
master: master:
username: root username: root
# password: 123456 password: 123456
password: iasf#2022 # password: iasf#2022
driver-class-name: com.mysql.cj.jdbc.Driver 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://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://192.168.31.136:3306/iasf?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2b8
cache: cache:
type: redis type: redis
redis: redis:

Loading…
Cancel
Save