1、拦截器增加请求地址、参数的日志输出

2、wps在线编辑增加文件下载(只做到文件保存到文件这一步骤,还需要存库、前端实现下载、预览功能)
This commit is contained in:
1378012178@qq.com 2025-01-06 08:53:22 +08:00
parent 36057f3126
commit 703000d3e3
14 changed files with 1781 additions and 1082 deletions

View File

@ -1,6 +1,7 @@
package org.jeecg.common.exception;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.jeecg.common.api.vo.Result;
@ -15,19 +16,18 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.NoHandlerFoundException;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.sql.SQLNonTransientException;
import java.sql.SQLSyntaxErrorException;
import java.util.Iterator;
/**
* 异常处理器
*
* @Author scott
* @Date 2019
*/
@RestControllerAdvice
@Slf4j
@ -37,8 +37,9 @@ public class JeecgBootExceptionHandler {
* 处理自定义异常
*/
@ExceptionHandler(JeecgBootException.class)
public Result<?> handleJeecgBootException(JeecgBootException e){
log.error(e.getMessage(), e);
public Result<?> handleJeecgBootException(JeecgBootException e, HttpServletRequest request) {
log.error("Intercepted exception for request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap(), e);
return Result.error(e.getMessage());
}
@ -46,110 +47,126 @@ public class JeecgBootExceptionHandler {
* 处理自定义微服务异常
*/
@ExceptionHandler(JeecgCloudException.class)
public Result<?> handleJeecgCloudException(JeecgCloudException e){
log.error(e.getMessage(), e);
public Result<?> handleJeecgCloudException(JeecgCloudException e, HttpServletRequest request) {
log.error("Intercepted exception for request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap(), e);
return Result.error(e.getMessage());
}
/**
* 处理自定义异常
* 处理自定义401异常
*/
@ExceptionHandler(JeecgBoot401Exception.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public Result<?> handleJeecgBoot401Exception(JeecgBoot401Exception e){
log.error(e.getMessage(), e);
return new Result(401,e.getMessage());
public Result<?> handleJeecgBoot401Exception(JeecgBoot401Exception e, HttpServletRequest request) {
log.error("Intercepted exception for request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap(), e);
return new Result<>(401, e.getMessage());
}
@ExceptionHandler(NoHandlerFoundException.class)
public Result<?> handlerNoFoundException(Exception e) {
log.error(e.getMessage(), e);
public Result<?> handlerNoFoundException(Exception e, HttpServletRequest request) {
log.error("Intercepted exception for request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap(), e);
return Result.error(404, "路径不存在,请检查路径是否正确");
}
@ExceptionHandler(DuplicateKeyException.class)
public Result<?> handleDuplicateKeyException(DuplicateKeyException e){
log.error(e.getMessage(), e);
public Result<?> handleDuplicateKeyException(DuplicateKeyException e, HttpServletRequest request) {
log.error("Intercepted exception for request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap(), e);
return Result.error("数据库中已存在该记录");
}
@ExceptionHandler({UnauthorizedException.class, AuthorizationException.class})
public Result<?> handleAuthorizationException(AuthorizationException e){
log.error(e.getMessage(), e);
public Result<?> handleAuthorizationException(AuthorizationException e, HttpServletRequest request) {
log.error("Intercepted exception for request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap(), e);
return Result.noauth("没有权限,请联系管理员授权");
}
@ExceptionHandler(Exception.class)
public Result<?> handleException(Exception e){
log.error(e.getMessage(), e);
//update-begin---author:zyf ---date:20220411 for处理Sentinel限流自定义异常
Throwable throwable = e.getCause();
SentinelErrorInfoEnum errorInfoEnum = SentinelErrorInfoEnum.getErrorByException(throwable);
if (ObjectUtil.isNotEmpty(errorInfoEnum)) {
return Result.error(errorInfoEnum.getError());
}
//update-end---author:zyf ---date:20220411 for处理Sentinel限流自定义异常
// return Result.error("操作失败"+e.getMessage());
return Result.error("操作失败");
}
/**
* @Author 政辉
* @param e
* @return
*/
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public Result<?> httpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e){
public Result<?> httpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e, HttpServletRequest request) {
StringBuffer sb = new StringBuffer();
sb.append("不支持");
sb.append(e.getMethod());
sb.append("请求方法,");
sb.append("支持以下");
String [] methods = e.getSupportedMethods();
if(methods!=null){
for(String str:methods){
String[] methods = e.getSupportedMethods();
if (methods != null) {
for (String str : methods) {
sb.append(str);
sb.append("");
}
}
log.error("Intercepted unsupported HTTP method request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), e.getMethod(), request.getParameterMap());
log.error(sb.toString(), e);
//return Result.error("没有权限,请联系管理员授权");
return Result.error(405,sb.toString());
return Result.error(405, sb.toString());
}
/**
* spring默认上传大小100MB 超出大小捕获异常MaxUploadSizeExceededException
*/
@ExceptionHandler(MaxUploadSizeExceededException.class)
public Result<?> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) {
log.error(e.getMessage(), e);
return Result.error("文件大小超出10MB限制, 请压缩或降低文件质量! ");
}
@ExceptionHandler(DataIntegrityViolationException.class)
public Result<?> handleDataIntegrityViolationException(DataIntegrityViolationException e) {
log.error(e.getMessage(), e);
//issues/3624数据库执行异常handleDataIntegrityViolationException提示有误 #3624
return Result.error("执行数据库异常,违反了完整性例如:违反惟一约束、违反非空限制、字段内容超出长度等");
}
@ExceptionHandler(MaxUploadSizeExceededException.class)
public Result<?> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e, HttpServletRequest request) {
if (request instanceof MultipartHttpServletRequest) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Iterator<String> fileNames = multipartRequest.getFileNames();
@ExceptionHandler(PoolException.class)
public Result<?> handlePoolException(PoolException e) {
log.error(e.getMessage(), e);
return Result.error("Redis 连接异常!");
}
while (fileNames.hasNext()) {
String fileName = fileNames.next();
MultipartFile file = multipartRequest.getFile(fileName);
log.error("File upload exceeded max size: File name={}, Size={} bytes, Content type={}",
file.getOriginalFilename(), file.getSize(), file.getContentType());
}
}
@ExceptionHandler({ SQLSyntaxErrorException.class, SQLNonTransientException.class, SQLException.class })
public Result<?> handleSQLSyntaxErrorException(SQLException e) {
log.error(e.getMessage(), e);
return Result.error("文件大小超出10MB限制, 请压缩或降低文件质量!");
}
@ExceptionHandler(DataIntegrityViolationException.class)
public Result<?> handleDataIntegrityViolationException(DataIntegrityViolationException e, HttpServletRequest request) {
log.error("Intercepted exception for request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap(), e);
//issues/3624数据库执行异常handleDataIntegrityViolationException提示有误 #3624
return Result.error("执行数据库异常,违反了完整性例如:违反惟一约束、违反非空限制、字段内容超出长度等");
}
@ExceptionHandler(PoolException.class)
public Result<?> handlePoolException(PoolException e, HttpServletRequest request) {
log.error("Intercepted exception for request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap(), e);
return Result.error("Redis 连接异常!");
}
@ExceptionHandler({SQLSyntaxErrorException.class, SQLNonTransientException.class, SQLException.class})
public Result<?> handleSQLSyntaxErrorException(SQLException e, HttpServletRequest request) {
log.error("Intercepted exception for request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap(), e);
return Result.error("SQL语法错误");
}
@ExceptionHandler({ BadSqlGrammarException.class, InvalidDataAccessResourceUsageException.class, NonTransientDataAccessException.class, DataAccessException.class })
public Result<?> handleBadSqlGrammarException(DataAccessException e) {
log.error(e.getMessage(), e);
@ExceptionHandler({BadSqlGrammarException.class, InvalidDataAccessResourceUsageException.class, NonTransientDataAccessException.class, DataAccessException.class})
public Result<?> handleBadSqlGrammarException(DataAccessException e, HttpServletRequest request) {
log.error("Intercepted exception for request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap(), e);
return Result.error("SQL语法错误");
}
@ExceptionHandler(Exception.class)
public Result<?> handleException(Exception e, HttpServletRequest request) {
log.error("Intercepted an exception for request: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap(), e);
// 处理Sentinel限流自定义异常
Throwable throwable = e.getCause();
SentinelErrorInfoEnum errorInfoEnum = SentinelErrorInfoEnum.getErrorByException(throwable);
if (ObjectUtil.isNotEmpty(errorInfoEnum)) {
return Result.error(errorInfoEnum.getError());
}
return Result.error("操作失败");
}
}

View File

@ -0,0 +1,153 @@
package org.jeecg.common.exception;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.enums.SentinelErrorInfoEnum;
import org.springframework.dao.*;
import org.springframework.data.redis.connection.PoolException;
import org.springframework.http.HttpStatus;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.NoHandlerFoundException;
import java.sql.SQLException;
import java.sql.SQLNonTransientException;
import java.sql.SQLSyntaxErrorException;
/**
* 异常处理器
*
* @Author scott
* @Date 2019
*/
@RestControllerAdvice
@Slf4j
public class JeecgBootExceptionHandlerbk {
/**
* 处理自定义异常
*/
@ExceptionHandler(JeecgBootException.class)
public Result<?> handleJeecgBootException(JeecgBootException e){
log.error(e.getMessage(), e);
return Result.error(e.getMessage());
}
/**
* 处理自定义微服务异常
*/
@ExceptionHandler(JeecgCloudException.class)
public Result<?> handleJeecgCloudException(JeecgCloudException e){
log.error(e.getMessage(), e);
return Result.error(e.getMessage());
}
/**
* 处理自定义异常
*/
@ExceptionHandler(JeecgBoot401Exception.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public Result<?> handleJeecgBoot401Exception(JeecgBoot401Exception e){
log.error(e.getMessage(), e);
return new Result(401,e.getMessage());
}
@ExceptionHandler(NoHandlerFoundException.class)
public Result<?> handlerNoFoundException(Exception e) {
log.error(e.getMessage(), e);
return Result.error(404, "路径不存在,请检查路径是否正确");
}
@ExceptionHandler(DuplicateKeyException.class)
public Result<?> handleDuplicateKeyException(DuplicateKeyException e){
log.error(e.getMessage(), e);
return Result.error("数据库中已存在该记录");
}
@ExceptionHandler({UnauthorizedException.class, AuthorizationException.class})
public Result<?> handleAuthorizationException(AuthorizationException e){
log.error(e.getMessage(), e);
return Result.noauth("没有权限,请联系管理员授权");
}
@ExceptionHandler(Exception.class)
public Result<?> handleException(Exception e){
log.error(e.getMessage(), e);
//update-begin---author:zyf ---date:20220411 for处理Sentinel限流自定义异常
Throwable throwable = e.getCause();
SentinelErrorInfoEnum errorInfoEnum = SentinelErrorInfoEnum.getErrorByException(throwable);
if (ObjectUtil.isNotEmpty(errorInfoEnum)) {
return Result.error(errorInfoEnum.getError());
}
//update-end---author:zyf ---date:20220411 for处理Sentinel限流自定义异常
// return Result.error("操作失败"+e.getMessage());
return Result.error("操作失败");
}
/**
* @Author 政辉
* @param e
* @return
*/
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public Result<?> httpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e){
StringBuffer sb = new StringBuffer();
sb.append("不支持");
sb.append(e.getMethod());
sb.append("请求方法,");
sb.append("支持以下");
String [] methods = e.getSupportedMethods();
if(methods!=null){
for(String str:methods){
sb.append(str);
sb.append("");
}
}
log.error(sb.toString(), e);
//return Result.error("没有权限,请联系管理员授权");
return Result.error(405,sb.toString());
}
/**
* spring默认上传大小100MB 超出大小捕获异常MaxUploadSizeExceededException
*/
@ExceptionHandler(MaxUploadSizeExceededException.class)
public Result<?> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) {
log.error(e.getMessage(), e);
return Result.error("文件大小超出10MB限制, 请压缩或降低文件质量! ");
}
@ExceptionHandler(DataIntegrityViolationException.class)
public Result<?> handleDataIntegrityViolationException(DataIntegrityViolationException e) {
log.error(e.getMessage(), e);
//issues/3624数据库执行异常handleDataIntegrityViolationException提示有误 #3624
return Result.error("执行数据库异常,违反了完整性例如:违反惟一约束、违反非空限制、字段内容超出长度等");
}
@ExceptionHandler(PoolException.class)
public Result<?> handlePoolException(PoolException e) {
log.error(e.getMessage(), e);
return Result.error("Redis 连接异常!");
}
@ExceptionHandler({ SQLSyntaxErrorException.class, SQLNonTransientException.class, SQLException.class })
public Result<?> handleSQLSyntaxErrorException(SQLException e) {
log.error(e.getMessage(), e);
return Result.error("SQL语法错误");
}
@ExceptionHandler({ BadSqlGrammarException.class, InvalidDataAccessResourceUsageException.class, NonTransientDataAccessException.class, DataAccessException.class })
public Result<?> handleBadSqlGrammarException(DataAccessException e) {
log.error(e.getMessage(), e);
return Result.error("SQL语法错误");
}
}

View File

@ -0,0 +1,50 @@
package org.jeecg.common.exception;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Iterator;
@Component
@Slf4j
public class LoggingInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 记录普通请求信息
log.info("Request intercepted: URL={}, Method={}, Parameters={}",
request.getRequestURI(), request.getMethod(), request.getParameterMap());
// 如果是多部分请求文件上传记录文件元数据
if (request instanceof MultipartHttpServletRequest) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Iterator<String> fileNames = multipartRequest.getFileNames();
while (fileNames.hasNext()) {
String fileName = fileNames.next();
MultipartFile file = multipartRequest.getFile(fileName);
log.info("Intercepted file upload: URL={}, File name={}, Size={} bytes, Content type={}",
request.getRequestURI(), file.getOriginalFilename(), file.getSize(), file.getContentType());
}
}
return true; // 继续处理链
}
// 可选实现postHandle和afterCompletion方法...
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
// 可以在这里添加处理后的行为
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
// 可以在这里添加请求完成后的行为
}
}

View File

@ -0,0 +1,19 @@
package org.jeecg.common.exception;
import org.jeecg.common.exception.LoggingInterceptor;
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.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Autowired
private LoggingInterceptor loggingInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loggingInterceptor).addPathPatterns("/**");
}
}

View File

@ -26,6 +26,7 @@ public class ZyInfoSys implements Serializable {
private String xqxn;
@Excel(name = "学院", width = 15)
private String kkdw;
private String dwh;//学院号
@Excel(name = "课程名称", width = 15)
private String kcmc;
@Excel(name = "课程性质", width = 15)

View File

@ -36,10 +36,26 @@ public interface ZyInfoMapper extends BaseMapper<ZyInfo> {
List<ZyInfoSys> getZyStaticNo(@Param("zyInfoSys") ZyInfoSys zyInfoSys);
List<ZyInfoSys> getXyZyList(@Param("zyInfoSys") ZyInfoSys zyInfoSys);
List<ZyInfoSys> getZyTopList(@Param("zyInfoSys") ZyInfoSys zyInfoSys);
List<ZyInfoSys> getZyList(@Param("zyInfoSys") ZyInfoSys zyInfoSys);
List<ZyInfoSys> getCyTopList(@Param("zyInfoSys") ZyInfoSys zyInfoSys);
List<ZyInfoSys> getCyList(@Param("zyInfoSys") ZyInfoSys zyInfoSys);
List<ZyInfoSys> getXYCyList(@Param("zyInfoSys") ZyInfoSys zyInfoSys);
List<ZyInfoSys> getKcTopList(@Param("zyInfoSys") ZyInfoSys zyInfoSys);
List<ZyInfoSys> getXnKcList(@Param("zyInfoSys") ZyInfoSys zyInfoSys);
List<ZyInfoSys> getJsTopList(@Param("zyInfoSys") ZyInfoSys zyInfoSys);
List<ZyInfoSys> getXnJsList(@Param("zyInfoSys") ZyInfoSys zyInfoSys);
IPage<ZyInfoSys> sysStaticZyList(Page<ZyInfoSys> page,@Param("zyInfoSys") ZyInfoSys zyInfoSys);
IPage<CyInfoSys> sysStaticCyList(Page<CyInfoSys> page, @Param("zyInfoSys") CyInfoSys cyInfoSys);

View File

@ -244,6 +244,26 @@
select count(distinct ww.id) as count,'10' as type from wjx_wjxx ww join kc_kechengbiao kk on kk.jgh = ww.create_by AND kk.rwbh = ww.rwbh AND kk.xqxn = ww.xqxn where (ww.update_time = DATE_FORMAT(NOW(),'%Y-%m-%d') or ww.create_time = DATE_FORMAT(NOW(),'%Y-%m-%d') ) and ww.qpublish in (2)
union all
select count(distinct zi.id) as count,'11' as type from zy_info zi join kc_kechengbiao kk on kk.jgh = zi.create_by AND kk.rwbh = zi.rwbh AND kk.xqxn = zi.xnxq where zi.zy_status in ('1','2') and zi.xnxq = #{zyInfoSys.xqxn} and zi.sfcc in ('1','2') and kk.flag = 0
union all
select count(*) as count,'12' as type from zy_info where file_path is not null and xnxq = #{zyInfoSys.xqxn}
union all
select count(*) as count,'13' as type from zy_info where file_path is not null and xnxq = #{zyInfoSys.xqxn} and xshpkg = '1'
union all
select count(*) as count,'14' as type from zy_info where file_path is not null and xnxq = #{zyInfoSys.xqxn} and sfcc = '1'
union all
SELECT COUNT(*) as count,'16' as type FROM wjx_djxx WHERE create_time BETWEEN (SELECT bxqkssj FROM kc_sys_config WHERE flag1=#{zyInfoSys.xqxn} LIMIT 1) AND (SELECT bxqjssj FROM kc_sys_config WHERE flag1=#{zyInfoSys.xqxn} LIMIT 1);
</select>
<select id="getXyZyList" resultType="org.jeecg.modules.kc.zyInfo.entity.ZyInfoSys">
select (@rownum:=@rownum + 1) AS rownum,t.* from (
select count(*) as count,b.dwmc as kkdw from zy_info a,xxhbuser b where a.create_by = b.gh and xnxq = #{zyInfoSys.xqxn} and zy_status in (1,2) GROUP BY b.dwmc
) t , (SELECT @rownum:=0) AS r ORDER BY count-0 desc
</select>
<select id="getZyList" resultType="org.jeecg.modules.kc.zyInfo.entity.ZyInfoSys">
select (@rownum:=@rownum + 1) AS rownum,t.* from (
select a.create_by,count(*) as count,b.xm as skjs,b.dwmc as kkdw from zy_info a,xxhbuser b where a.create_by = b.gh and xnxq = #{zyInfoSys.xqxn} and zy_status in (1,2) GROUP BY a.create_by ,b.xm,b.dwmc
) t , (SELECT @rownum:=0) AS r ORDER BY count-0 desc
</select>
<select id="getZyTopList" resultType="org.jeecg.modules.kc.zyInfo.entity.ZyInfoSys">
@ -252,13 +272,169 @@
) t , (SELECT @rownum:=0) AS r ORDER BY count-0 desc limit 10
</select>
<select id="getCyList" resultType="org.jeecg.modules.kc.zyInfo.entity.ZyInfoSys">
select (@rownum:=@rownum + 1) AS rownum,t.* from (
select a.create_by,count(*) as count,b.xm as skjs,b.dwmc as kkdw from wjx_wjxx a,xxhbuser b where a.create_by = b.gh and xqxn = #{zyInfoSys.xqxn} and qpublish in (1,2) GROUP BY a.create_by ,b.xm,b.dwmc
) t , (SELECT @rownum:=0) AS r ORDER BY count-0 desc
</select>
<select id="getCyTopList" resultType="org.jeecg.modules.kc.zyInfo.entity.ZyInfoSys">
select (@rownum:=@rownum + 1) AS rownum,t.* from (
select a.create_by,count(*) as count,b.xm as skjs,b.dwmc as kkdw from wjx_wjxx a,xxhbuser b where a.create_by = b.gh and xqxn = #{zyInfoSys.xqxn} and qpublish in (1,2) GROUP BY a.create_by ,b.xm,b.dwmc
) t , (SELECT @rownum:=0) AS r ORDER BY count-0 desc limit 10
</select>
<select id="getXYCyList" resultType="org.jeecg.modules.kc.zyInfo.entity.ZyInfoSys">
select (@rownum:=@rownum + 1) AS rownum,t.* from (
select count(*) as count,b.dwmc as kkdw from wjx_wjxx a,xxhbuser b where a.create_by = b.gh and xqxn = #{zyInfoSys.xqxn} and qpublish in (1,2) GROUP BY b.dwmc
) t , (SELECT @rownum:=0) AS r ORDER BY count-0 desc
</select>
<select id="getKcTopList" resultType="org.jeecg.modules.kc.zyInfo.entity.ZyInfoSys">
SELECT
( @rownum := @rownum + 1 ) AS rownum,
t.*
FROM
(
SELECT
b.kcmc,
count(*) AS count,
b.kkdw
FROM
zy_info a,
kc_kechengbiao b
WHERE
a.rwbh = b.rwbh
AND a.xnxq = #{zyInfoSys.xqxn} GROUP BY b.kcmc,b.kkdw
union all
SELECT
b.kcmc,
count(*) AS count,
b.kkdw
FROM
wjx_wjxx a,
kc_kechengbiao b
WHERE
a.rwbh = b.rwbh
AND a.xqxn = #{zyInfoSys.xqxn} GROUP BY b.kcmc,b.kkdw
) t,
( SELECT @rownum := 0 ) AS r
ORDER BY
count - 0 DESC
LIMIT 10
</select>
<select id="getXnKcList" resultType="org.jeecg.modules.kc.zyInfo.entity.ZyInfoSys">
SELECT
( @rownum := @rownum + 1 ) AS rownum,
t.*
FROM
(
SELECT
b.kcmc,
count(*) AS count,
b.kkdw
FROM
zy_info a,
kc_kechengbiao b
WHERE
a.rwbh = b.rwbh
AND a.xnxq = #{zyInfoSys.xqxn} GROUP BY b.kcmc,b.kkdw
union all
SELECT
b.kcmc,
count(*) AS count,
b.kkdw
FROM
wjx_wjxx a,
kc_kechengbiao b
WHERE
a.rwbh = b.rwbh
AND a.xqxn = #{zyInfoSys.xqxn} GROUP BY b.kcmc,b.kkdw
) t,
( SELECT @rownum := 0 ) AS r
ORDER BY
count - 0 DESC
</select>
<select id="getJsTopList" resultType="org.jeecg.modules.kc.zyInfo.entity.ZyInfoSys">
SELECT
( @rownum := @rownum + 1 ) AS rownum,
t.*
FROM
(
SELECT
a.create_by,
count(*) AS count,
b.xm AS skjs,
b.dwmc AS kkdw
FROM
zy_info a,
xxhbuser b
WHERE
a.create_by = b.gh
AND xnxq = #{zyInfoSys.xqxn} and zy_status in (1,2) GROUP BY a.create_by ,b.xm,b.dwmc
union all
SELECT
a.create_by,
count(*) AS count,
b.xm AS skjs,
b.dwmc AS kkdw
FROM
wjx_wjxx a,
xxhbuser b
WHERE
a.create_by = b.gh
AND xqxn = #{zyInfoSys.xqxn} and qpublish in (1,2) GROUP BY a.create_by ,b.xm,b.dwmc
) t,
( SELECT @rownum := 0 ) AS r
ORDER BY
count - 0 DESC
LIMIT 10
</select>
<select id="getXnJsList" resultType="org.jeecg.modules.kc.zyInfo.entity.ZyInfoSys">
SELECT
( @rownum := @rownum + 1 ) AS rownum,
t.*
FROM
(
SELECT
a.create_by,
count(*) AS count,
b.xm AS skjs,
b.dwmc AS kkdw
FROM
zy_info a,
xxhbuser b
WHERE
a.create_by = b.gh
AND xnxq = #{zyInfoSys.xqxn} and zy_status in (1,2) GROUP BY a.create_by ,b.xm,b.dwmc
union all
SELECT
a.create_by,
count(*) AS count,
b.xm AS skjs,
b.dwmc AS kkdw
FROM
wjx_wjxx a,
xxhbuser b
WHERE
a.create_by = b.gh
AND xqxn = #{zyInfoSys.xqxn} and qpublish in (1,2) GROUP BY a.create_by ,b.xm,b.dwmc
) t,
( SELECT @rownum := 0 ) AS r
ORDER BY
count - 0 DESC
</select>
<select id="sysStaticZyList" resultType="org.jeecg.modules.kc.zyInfo.entity.ZyInfoSys">
select a.*,b.skjs,b.jgh,b.kcmc,b.kcbh,b.xkrs,b.kkdw,b.kcxz,b.zc,a.xnxq as xqxn,

View File

@ -0,0 +1,28 @@
package org.jeecg.modules.kc.zyInfo.pojo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import java.io.Serializable;
/**
* @Description: 导出用
* @Author: zmy
*/
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class ExportEntity1 implements Serializable {
private static final long serialVersionUID = 1L;
@Excel(name = "序号", width = 10)
private String rownum;
@Excel(name = "姓名", width = 15)
private String skjs;
@Excel(name = "次数", width = 15)
private String count;
@Excel(name = "学院", width = 40)
private String kkdw;
}

View File

@ -0,0 +1,28 @@
package org.jeecg.modules.kc.zyInfo.pojo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import java.io.Serializable;
/**
* @Description: 导出用
* @Author: zmy
*/
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class ExportEntity2 implements Serializable {
private static final long serialVersionUID = 1L;
@Excel(name = "序号", width = 10)
private String rownum;
@Excel(name = "课程", width = 40)
private String kcmc;
@Excel(name = "次数", width = 15)
private String count;
@Excel(name = "学院", width = 40)
private String kkdw;
}

View File

@ -37,6 +37,8 @@ public interface IZyInfoService extends IService<ZyInfo> {
Map<String,Object> sysStaticNo(ZyInfoSys zyInfoSys);
List<ZyInfoSys> getPHData(ZyInfoSys zyInfoSys,String tag);
IPage<ZyInfoSys> sysStaticZyList(Page<ZyInfoSys> page, ZyInfoSys zyInfoSys);
IPage<CyInfoSys> sysStaticCyList(Page<CyInfoSys> page, CyInfoSys cyInfoSys);

View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.xkcoding.http.HttpUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
@ -180,6 +181,12 @@ public class ZyInfoServiceImpl extends ServiceImpl<ZyInfoMapper, ZyInfo> impleme
String jr_cy_syzcs = "0";
String jr_cy_ywczcs = "0";
String xn_zy_cccs = "0"; //查重次数
String xn_kc_zyzxsrc = "0";//使用课程作业总学生人次
String xn_kc_zyhp = "0";//使用课程作业互评总学生人次
String xn_kc_zycc = "0";//使用课程作业查重总学生人次
String xn_kc_zywczxsrc = "0";//完成课程作业总学生人次
String xn_kc_ktcy = "0";//使用课堂测验总学生人次
String xn_kc_wccy = "0";//完成课堂测验总学生人次
List<ZyInfoSys> list = baseMapper.getZyStaticNo(zyInfoSys);
for (ZyInfoSys par : list) {
@ -205,13 +212,36 @@ public class ZyInfoServiceImpl extends ServiceImpl<ZyInfoMapper, ZyInfo> impleme
jr_cy_ywczcs = par.getCount();
} else if (StringUtils.equals("11", par.getType())) {
xn_zy_cccs = par.getCount();
} else if (StringUtils.equals("12", par.getType())) {
xn_kc_zyzxsrc = par.getCount();
} else if (StringUtils.equals("13", par.getType())) {
xn_kc_zyhp = par.getCount();
} else if (StringUtils.equals("14", par.getType())) {
xn_kc_zycc = par.getCount();
} else if (StringUtils.equals("15", par.getType())) {
xn_kc_zywczxsrc = par.getCount();
} else if (StringUtils.equals("16", par.getType())) {
xn_kc_ktcy = par.getCount();
} else if (StringUtils.equals("17", par.getType())) {
xn_kc_wccy = par.getCount();
}
}
//本学年作业使用排行TOP10
List<ZyInfoSys> list1 = baseMapper.getZyTopList(zyInfoSys);
//本学年测验使用排行TOP10
List<ZyInfoSys> list2 = baseMapper.getCyTopList(zyInfoSys);
//本学年课程使用排行TOP10
List<ZyInfoSys> list3 = baseMapper.getKcTopList(zyInfoSys);
//本学年教师使用排行TOP10
List<ZyInfoSys> list4 = baseMapper.getJsTopList(zyInfoSys);
list.add(zyInfoSys);
//本学年各个学院作业数
List<ZyInfoSys> list5 = baseMapper.getXyZyList(zyInfoSys);
//本学年各个学院测验数
List<ZyInfoSys> list6 = baseMapper.getXYCyList(zyInfoSys);
map.put("xn_zy_syzcs", xn_zy_syzcs);//本学年作业使用总次数
map.put("xn_zy_hpzcs", xn_zy_hpzcs);//本学年作业互评总次数
map.put("xn_zy_ywczcs", xn_zy_ywczcs);//本学年作业已完成总次数
@ -223,12 +253,39 @@ public class ZyInfoServiceImpl extends ServiceImpl<ZyInfoMapper, ZyInfo> impleme
map.put("jr_zy_ywczcs", jr_zy_ywczcs);//今日作业已完成总次数
map.put("jr_cy_syzcs", jr_cy_syzcs);//今日测验使用总次数
map.put("jr_cy_ywczcs", jr_cy_ywczcs);//今日测验已完成总次数
map.put("xn_kc_zyzxsrc",xn_kc_zyzxsrc );//使用课程作业总学生人次
map.put("xn_kc_zyhp",xn_kc_zyhp );//使用课程作业互评总学生人次
map.put("xn_kc_zycc",xn_kc_zycc );//使用课程作业查重总学生人次
map.put("xn_kc_zywczxsrc",xn_kc_zywczxsrc );//完成课程作业总学生人次
map.put("xn_kc_ktcy",xn_kc_ktcy );//使用课堂测验总学生人次
map.put("xn_kc_wccy",xn_kc_wccy );//完成课堂测验总学生人次
map.put("xntop10", list1);//本学年作业使用排行TOP10
map.put("jrtop10", list2);//本学年测验使用排行TOP10
map.put("kctop10", list3);//本学年课程使用排行TOP10
map.put("jstop10", list4);//本学年教师使用排行TOP10
map.put("xnxyzycs", list5);//本学年各个学院作业数
map.put("xnxycycs", list6);//本学年各个学院测验数
return map;
}
@Override
public List<ZyInfoSys> getPHData(ZyInfoSys zyInfoSys,String tag) {
List<ZyInfoSys> list = Lists.newArrayList();
if("xntop10".equals(tag)){
list = baseMapper.getZyList(zyInfoSys);
}
if("jrtop10".equals(tag)){
list = baseMapper.getCyList(zyInfoSys);
}
if("kctop10".equals(tag)){
list = baseMapper.getXnKcList(zyInfoSys);
}
if("jstop10".equals(tag)){
list = baseMapper.getXnJsList(zyInfoSys);
}
return list;
}
@Override
public IPage<ZyInfoSys> sysStaticZyList(Page<ZyInfoSys> page, ZyInfoSys zyInfoSys) {
return baseMapper.sysStaticZyList(page, zyInfoSys);

View File

@ -18,16 +18,26 @@ import org.jeecg.modules.kc.kcCasusers.service.IKcCasusersService;
import org.jeecg.modules.kc.zyInfoStudent.entity.ZyInfoStudent;
import org.jeecg.modules.kc.zyInfoStudent.service.IZyInfoStudentService;
import org.jeecg.modules.kc.zyZyxx.entity.ZyZyxx;
import org.jeecg.modules.system.controller.CommonController;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.wps.entity.WpsEnti;
import org.jeecg.modules.wps.entity.WpsUploadEnti;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.*;
/**
@ -46,6 +56,9 @@ public class WpsController extends JeecgController<KcCasusers, IKcCasusersServic
@Autowired
private ISysUserService sysUserService;
@Autowired
private CommonController commonController;
/**
* 文档预览
*
@ -82,11 +95,14 @@ public class WpsController extends JeecgController<KcCasusers, IKcCasusersServic
*/
@RequestMapping(value = "/files/{fileId}/download", method = {RequestMethod.GET})
public Map<String, Object> download(@PathVariable("fileId") String fileId) {
log.info("~~~~~~~~~~~~>>>>>>>>>>>");
log.info("download--fileId=" + fileId);
log.info("~~~~~~~~~~~~<<<<<<<<<<<");
ZyInfoStudent zyInfoStudent = zyInfoStudentService.getById(fileId);
Map<String, Object> mapRet = new HashMap<>();
Map<String, Object> mapRet2 = new HashMap<>();
// https://kczxcs.nenu.edu.cn/jeecg-boot/sys/common/static/temp/QA%E4%BD%9C%E4%B8%9A%E7%B3%BB%E7%BB%9F%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98_1733101749150.docx
mapRet2.put("url", "https://kczxcs.nenu.edu.cn/jeecg-boot/sys/common/static/" + zyInfoStudent.getFilePath());
Map<String, String> headers = new HashMap<>();
mapRet.put("code", 0);
mapRet.put("data", mapRet2);
return mapRet;
@ -197,7 +213,7 @@ public class WpsController extends JeecgController<KcCasusers, IKcCasusersServic
Map<String, Object> mapRet = new HashMap<>();
mapRet.put("code", 0);
Map<String, Object> mapRet2 = new HashMap<>();
mapRet2.put("url", "https://kczxcs.nenu.edu.cn/jeecg-boot/sys/common/static/" + zyInfoStudent.getFilePath());
mapRet2.put("url", "https://kczxcs.nenu.edu.cn/jeecg-boot/v3/3rd/static/" + zyInfoStudent.getFilePath());
mapRet2.put("method", "POST");
mapRet.put("data", mapRet2);
mapRet.put("message", "");
@ -226,5 +242,18 @@ public class WpsController extends JeecgController<KcCasusers, IKcCasusersServic
return mapRet;
}
@PostMapping("/static/temp/{fileName}")
public ResponseEntity<String> downloadFile(@PathVariable String fileName
, @RequestParam(value = "file", required = false) MultipartFile file) {
log.info(">>>>>>>>>");
log.info("fileName=" + fileName);
String newFileName = fileName.substring(0, fileName.indexOf("_")) + "_" + System.currentTimeMillis() + fileName.substring(fileName.indexOf("."));
log.info("fileName222处理后=", newFileName);
String savePath = commonController.uploadLocal(file, newFileName, "temp");
log.info("savePath=" + savePath);
log.info("<<<<<<<<<");
//TODO 存数据库 不能旧的不删除然后每次都新存 前端关闭弹窗时调用保存方法来触发这个接口
return null;
}
}

View File

@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
@ -34,6 +35,11 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@ -50,7 +56,7 @@ import java.util.stream.Collectors;
@RequestMapping("/sys/common")
public class CommonController {
private final static Logger logger= LoggerFactory.getLogger(CommonController.class);
private final static Logger logger = LoggerFactory.getLogger(CommonController.class);
@Value(value = "${jeecg.path.upload}")
private String uploadpath;
@ -61,23 +67,24 @@ public class CommonController {
/**
* 本地local miniominio 阿里alioss
*/
@Value(value="${jeecg.uploadType}")
@Value(value = "${jeecg.uploadType}")
private String uploadType;
@Autowired
SftpConfig sftpConfig;
/**
* @Author 政辉
* @return
* @Author 政辉
*/
@GetMapping("/403")
public Result<?> noauth() {
public Result<?> noauth() {
return Result.error("没有权限,请联系管理员授权");
}
/**
* 文件上传统一方法
*
* @param request
* @param response
* @return
@ -100,40 +107,42 @@ public class CommonController {
MultipartFile file = multipartRequest.getFile("file");
savePath = upload(bizPath, file);
if(oConvertUtils.isNotEmpty(savePath)){
if (oConvertUtils.isNotEmpty(savePath)) {
result.setMessage(savePath);
result.setSuccess(true);
}else {
} else {
result.setMessage("上传失败!");
result.setSuccess(false);
}
return result;
}
/**
* 文件上传统一方法
*
* @param bizPath
* @param file
* @return
*/
public String upload(String bizPath, MultipartFile file) throws Exception {
String savePath = "";
if(oConvertUtils.isEmpty(bizPath)){
if(CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)){
if (oConvertUtils.isEmpty(bizPath)) {
if (CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)) {
//未指定目录则用阿里云默认目录 upload
bizPath = "upload";
//result.setMessage("使用阿里云文件上传时,必须添加目录!");
//result.setSuccess(false);
//return result;
}else{
} else {
bizPath = "";
}
}
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) {
//update-begin-author:liusq date:20221102 for: 过滤上传文件类型
FileTypeFilter.fileTypeFilter(file);
//update-end-author:liusq date:20221102 for: 过滤上传文件类型
//update-begin-author:lvdandan date:20200928 for:修改JEditor编辑器本地上传
savePath = this.uploadLocal(file,bizPath);
savePath = this.uploadLocal(file, bizPath);
//update-begin-author:lvdandan date:20200928 for:修改JEditor编辑器本地上传
/** 富文本编辑器及markdown本地上传时采用返回链接方式
//针对jeditor编辑器如何使 lcaol模式采用 base64格式存储
@ -146,10 +155,10 @@ public class CommonController {
savePath = this.uploadLocal(file,bizPath);
}
*/
}else if(CommonConstant.UPLOAD_TYPE_SFTP.equals(uploadType)) {
} else if (CommonConstant.UPLOAD_TYPE_SFTP.equals(uploadType)) {
FileTypeFilter.fileTypeFilter(file);
savePath = this.uploadSftp(file,bizPath);
}else{
savePath = this.uploadSftp(file, bizPath);
} else {
//update-begin-author:taoyan date:20200814 for:文件上传改造
savePath = CommonUtils.upload(file, bizPath, uploadType);
//update-end-author:taoyan date:20200814 for:文件上传改造
@ -159,38 +168,40 @@ public class CommonController {
/**
* 本地文件上传
* @param mf 文件
* @param bizPath 自定义路径
*
* @param mf 文件
* @param bizPath 自定义路径
* @return
*/
private String uploadLocal(MultipartFile mf,String bizPath){
return uploadLocal(mf,null,bizPath);
private String uploadLocal(MultipartFile mf, String bizPath) {
return uploadLocal(mf, null, bizPath);
}
/**
* 本地文件上传
* @param mf 文件
* @param bizPath 自定义路径
*
* @param mf 文件
* @param bizPath 自定义路径
* @return
*/
private String uploadLocal(MultipartFile mf,String _fileName,String bizPath){
public String uploadLocal(MultipartFile mf, String _fileName, String bizPath) {
try {
String ctxPath = uploadpath;
String fileName = _fileName;
File file = new File(ctxPath + File.separator + bizPath + File.separator );
File file = new File(ctxPath + File.separator + bizPath + File.separator);
if (!file.exists()) {
// 创建文件根目录
file.mkdirs();
}
// 获取文件名
if(fileName == null){
if (fileName == null) {
String orgName = StrAttackFilter.filter2(mf.getOriginalFilename());
if (orgName != null) {
orgName = CommonUtils.getFileName(orgName);
if(orgName.contains(SymbolConstant.SPOT)){
if (orgName.contains(SymbolConstant.SPOT)) {
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf("."));
}else{
fileName = orgName+ "_" + System.currentTimeMillis();
} else {
fileName = orgName + "_" + System.currentTimeMillis();
}
}
}
@ -198,9 +209,9 @@ public class CommonController {
File savefile = new File(savePath);
FileCopyUtils.copy(mf.getBytes(), savefile);
String dbpath = null;
if(oConvertUtils.isNotEmpty(bizPath)){
if (oConvertUtils.isNotEmpty(bizPath)) {
dbpath = bizPath + File.separator + fileName;
}else{
} else {
dbpath = fileName;
}
if (dbpath.contains(SymbolConstant.DOUBLE_BACKSLASH)) {
@ -213,17 +224,17 @@ public class CommonController {
return "";
}
private String uploadSftp(MultipartFile mf,String bizPath){
private String uploadSftp(MultipartFile mf, String bizPath) {
try {
Map<String,String> uploadMap = SFTPUtil.upload(sftpConfig,mf,bizPath);
Map<String, String> uploadMap = SFTPUtil.upload(sftpConfig, mf, bizPath);
SFTPUtil.disChannel();
SFTPUtil.disSession();
if(uploadMap.get("code").equals("0")){
if (uploadMap.get("code").equals("0")) {
return uploadMap.get("data");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}finally {
} finally {
SFTPUtil.disChannel();
SFTPUtil.disSession();
}
@ -268,7 +279,7 @@ public class CommonController {
// }
@Data
public static class SectionUploadData{
public static class SectionUploadData {
private Integer chunkCount;
private String fileMd5;
private String biz;
@ -285,21 +296,21 @@ public class CommonController {
String fileName = sectionUploadData.getFileName();
String bizPath = sectionUploadData.getBiz();
if (oConvertUtils.isNotEmpty(bizPath)) {
if(bizPath.contains(SymbolConstant.SPOT_SINGLE_SLASH) || bizPath.contains(SymbolConstant.SPOT_DOUBLE_BACKSLASH)){
if (bizPath.contains(SymbolConstant.SPOT_SINGLE_SLASH) || bizPath.contains(SymbolConstant.SPOT_DOUBLE_BACKSLASH)) {
throw new JeecgBootException("上传目录bizPath格式非法");
}
}
//创建一个空文件夹,里面有个文件信息
String ctxPath = uploadpath;
File file = new File(ctxPath + File.separator + bizPath + File.separator + fileMd5 );
File file = new File(ctxPath + File.separator + bizPath + File.separator + fileMd5);
if (!file.exists()) {
// 创建文件根目录
file.mkdirs();
}
File fileInfo = new File(ctxPath + File.separator + bizPath + File.separator + fileMd5 + File.separator + "file.info" );
FileUtil.writeUtf8String("fileMd5:" + fileMd5 + "\nchunkCount:" + chunkCount + "\nfileName:" + fileName,fileInfo);
File fileInfo = new File(ctxPath + File.separator + bizPath + File.separator + fileMd5 + File.separator + "file.info");
FileUtil.writeUtf8String("fileMd5:" + fileMd5 + "\nchunkCount:" + chunkCount + "\nfileName:" + fileName, fileInfo);
return Result.OK("init ok");
}
@ -312,7 +323,7 @@ public class CommonController {
//LOWCOD-2580 sys/common/upload接口存在任意文件上传漏洞
if (oConvertUtils.isNotEmpty(bizPath)) {
if(bizPath.contains(SymbolConstant.SPOT_SINGLE_SLASH) || bizPath.contains(SymbolConstant.SPOT_DOUBLE_BACKSLASH)){
if (bizPath.contains(SymbolConstant.SPOT_SINGLE_SLASH) || bizPath.contains(SymbolConstant.SPOT_DOUBLE_BACKSLASH)) {
throw new JeecgBootException("上传目录bizPath格式非法");
}
}
@ -323,14 +334,15 @@ public class CommonController {
String savePath = this.uploadLocal(file, partNumber, bizPath + File.separator + fileMd5);
if(StringUtils.isBlank(savePath)){
if (StringUtils.isBlank(savePath)) {
return Result.error("upload error");
}
return Result.OK("upload ok");
}
@PostMapping(value = "/sectionUpload/end")
public Result<?> sectionUploadEnd(@RequestBody SectionUploadData sectionUploadData){
public Result<?> sectionUploadEnd(@RequestBody SectionUploadData sectionUploadData) {
log.info("合并文件!");
Result<?> result = new Result<>();
Integer chunkCount = sectionUploadData.getChunkCount();
@ -340,7 +352,7 @@ public class CommonController {
String bizPath = sectionUploadData.getBiz();
if (oConvertUtils.isNotEmpty(bizPath)) {
if(bizPath.contains(SymbolConstant.SPOT_SINGLE_SLASH) || bizPath.contains(SymbolConstant.SPOT_DOUBLE_BACKSLASH)){
if (bizPath.contains(SymbolConstant.SPOT_SINGLE_SLASH) || bizPath.contains(SymbolConstant.SPOT_DOUBLE_BACKSLASH)) {
throw new JeecgBootException("上传目录bizPath格式非法");
}
}
@ -354,16 +366,16 @@ public class CommonController {
//savePath = this.uploadLocal(file,bizPath)
List<String> allFileNameList = FileUtil.listFileNames(fileFolder.getPath());
List<String> fileNameList = allFileNameList.stream().filter(x -> !StringUtils.equals("file.info",x))
List<String> fileNameList = allFileNameList.stream().filter(x -> !StringUtils.equals("file.info", x))
.sorted(Comparator.comparing(Integer::parseInt))
.collect(Collectors.toList());
if (orgName != null) {
orgName = CommonUtils.getFileName(orgName);
if(orgName.contains(SymbolConstant.SPOT)){
if (orgName.contains(SymbolConstant.SPOT)) {
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf("."));
}else{
fileName = orgName+ "_" + System.currentTimeMillis();
} else {
fileName = orgName + "_" + System.currentTimeMillis();
}
}
@ -383,7 +395,7 @@ public class CommonController {
BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(outFile.toPath()));
byte[] bys = new byte[1024];
int len = 0;
while((len = sis.read(bys)) != -1){
while ((len = sis.read(bys)) != -1) {
bos.write(bys, 0, len);
}
IoUtil.close(sis);
@ -394,28 +406,28 @@ public class CommonController {
FileUtil.del(fileFolder);
//本地上传不做处理
if(!CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
if (!CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) {
String savePath = upload(bizPath, getMultipartFile(outFile));
if(oConvertUtils.isNotEmpty(savePath)){
if (oConvertUtils.isNotEmpty(savePath)) {
//删除本地文件
if(!StringUtils.equals(bizPath, "temp")){
if (!StringUtils.equals(bizPath, "temp")) {
//不等于这个的删除
FileUtil.del(outFile);
}
result.setMessage(savePath);
result.setSuccess(true);
}else {
} else {
result.setMessage("上传失败!");
result.setSuccess(false);
}
}else {
} else {
//本地上传不做处理直接返回地址即可
result.setSuccess(true);
result.setMessage(bizPath + "/" + fileName);//地址
}
return result;
}catch (Exception e){
} catch (Exception e) {
log.error(e.getMessage(), e);
result.setSuccess(false);
result.setMessage(e.getMessage());//地址
@ -426,6 +438,7 @@ public class CommonController {
/**
* file转MultipartFile
*
* @param file File对象
* @return MultipartFile 对象
*/
@ -458,41 +471,41 @@ public class CommonController {
public void view(HttpServletRequest request, HttpServletResponse response) {
// ISO-8859-1 ==> UTF-8 进行编码转换
String imgPath = extractPathFromPattern(request);
if(oConvertUtils.isEmpty(imgPath) || CommonConstant.STRING_NULL.equals(imgPath)){
if (oConvertUtils.isEmpty(imgPath) || CommonConstant.STRING_NULL.equals(imgPath)) {
return;
}
// 其余处理略
InputStream inputStream = null;
OutputStream outputStream = null;
try {
imgPath = imgPath.replace("..", "").replace("../","");
imgPath = imgPath.replace("..", "").replace("../", "");
if (imgPath.endsWith(SymbolConstant.COMMA)) {
imgPath = imgPath.substring(0, imgPath.length() - 1);
}
if(CommonConstant.UPLOAD_TYPE_SFTP.equals(uploadType)) {
try{
logger.info("/sys/common/static/SFTP下载 ..."+new Date());
if (CommonConstant.UPLOAD_TYPE_SFTP.equals(uploadType)) {
try {
logger.info("/sys/common/static/SFTP下载 ..." + new Date());
// SFTPUtil.writeFileToRes(sftpConfig,imgPath,response);
int index = imgPath.lastIndexOf("/");
String path = "temp";
if(index != -1){
path = imgPath.substring(0,index);
if (index != -1) {
path = imgPath.substring(0, index);
}
//TODO 不确定是否有问题
Map<String,String> map = SFTPUtil.download(sftpConfig,imgPath,getDownloadPath(path));
if(!map.get("code").equals("0")){
Map<String, String> map = SFTPUtil.download(sftpConfig, imgPath, getDownloadPath(path));
if (!map.get("code").equals("0")) {
response.setStatus(404);
throw new RuntimeException(map.get("msg"));
}
String localFilePath = map.get("fileName");
File file = new File(localFilePath);
if(!file.exists()){
if (!file.exists()) {
response.setStatus(404);
throw new RuntimeException("文件["+imgPath+"]不存在..");
throw new RuntimeException("文件[" + imgPath + "]不存在..");
}
// 设置强制下载不打开
// response.setContentType("application/force-download");
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1"));
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"), "iso-8859-1"));
inputStream = new BufferedInputStream(new FileInputStream(localFilePath));
outputStream = response.getOutputStream();
byte[] buf = new byte[1024];
@ -501,13 +514,13 @@ public class CommonController {
outputStream.write(buf, 0, len);
}
response.flushBuffer();
}catch (Exception e){
} catch (Exception e) {
// e.printStackTrace();
}finally {
} finally {
SFTPUtil.disChannel();
SFTPUtil.disSession();
}
}else {
} else {
String filePath = uploadpath + File.separator + imgPath;
File file = new File(filePath);
if (!file.exists()) {
@ -608,9 +621,9 @@ public class CommonController {
// }
/**
* @功能pdf预览Iframe
* @param modelAndView
* @return
* @功能pdf预览Iframe
*/
@RequestMapping("/pdf/pdfPreviewIframe")
public ModelAndView pdfPreviewIframe(ModelAndView modelAndView) {
@ -619,8 +632,9 @@ public class CommonController {
}
/**
* 把指定URL后的字符串全部截断当成参数
* 这么做是为了防止URL中包含中文或者特殊字符/匹配不了的问题
* 把指定URL后的字符串全部截断当成参数
* 这么做是为了防止URL中包含中文或者特殊字符/匹配不了的问题
*
* @param request
* @return
*/
@ -632,18 +646,19 @@ public class CommonController {
/**
* 获取文件真实路径
*
* @param path
* @return
*/
private String getDownloadPath(String path){
private String getDownloadPath(String path) {
String filePath = "";
if(org.jeecg.common.util.text.StringUtils.isEmpty(path)){
if (org.jeecg.common.util.text.StringUtils.isEmpty(path)) {
return "";
}
int idx = path.indexOf(downloadpath);
if(idx==-1){
if (idx == -1) {
filePath = downloadpath + File.separator + path;
}else{
} else {
filePath = path;
}
return filePath;