增加websocket,增加定时任务管理

This commit is contained in:
liwen
2021-01-14 16:52:47 +08:00
parent 12fd9dc2cb
commit 9c1db9d032
236 changed files with 6453 additions and 1496 deletions

View File

@@ -8,7 +8,7 @@
<version>2.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.epri</groupId>
<groupId>com.fx</groupId>
<artifactId>falsework-sever</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>falsework-sever</name>
@@ -106,11 +106,7 @@
<scope>system</scope>
<systemPath>${basedir}/libs/DmJdbcDriver-1.0.0.jar</systemPath>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>pinyin4j</groupId>
<artifactId>pinyin4j</artifactId>

View File

File diff suppressed because one or more lines are too long

View File

File diff suppressed because one or more lines are too long

View File

@@ -1,41 +0,0 @@
package com.epri.fx.server.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
//@Configuration
//@EnableWebSecurity//开启Spring安全
//@EnableGlobalMethodSecurity(prePostEnabled=true)//开启Spring方法级安全
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
/*
* 配置为从内存中进行加载认证信息.
* 这里配置了两个用户 admin和user
*/
auth.inMemoryAuthentication()
.withUser("admin")
.password(passwordEncoder().encode("123456"))
.roles("admin");
auth.inMemoryAuthentication()
.withUser("user")
.password(passwordEncoder().encode("123456"))
.roles("normal");
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}

View File

@@ -1,23 +0,0 @@
package com.epri.fx.server.util;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtils {
/** 时间格式(yyyy-MM-dd) */
public final static String DATE_PATTERN = "yyyy-MM-dd";
/** 时间格式(yyyy-MM-dd HH:mm:ss) */
public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
public static String format(Date date) {
return format(date, DATE_PATTERN);
}
public static String format(Date date, String pattern) {
if(date != null){
SimpleDateFormat df = new SimpleDateFormat(pattern);
return df.format(date);
}
return null;
}
}

View File

@@ -1,6 +1,6 @@
package com.epri.fx.server;
package com.fx.server;
import com.epri.fx.server.util.DBLog;
import com.fx.server.util.DBLog;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement
@MapperScan("com.epri.fx.server.mapper")
@MapperScan("com.fx.server.mapper")
@SpringBootApplication(exclude=SecurityAutoConfiguration.class)
public class ServerApplication {

View File

@@ -1,6 +1,6 @@
package com.epri.fx.server.config;
package com.fx.server.config;
import com.epri.fx.server.filter.ReplaceStreamFilter;
import com.fx.server.filter.ReplaceStreamFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.config;
package com.fx.server.config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.config;
package com.fx.server.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.config;
package com.fx.server.config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;

View File

@@ -1,9 +1,9 @@
package com.epri.fx.server.config;
package com.fx.server.config;
import com.epri.fx.server.handler.GlobalExceptionHandler;
import com.epri.fx.server.interceptor.LogInterceptor;
import com.epri.fx.server.interceptor.UserAuthRestInterceptor;
import com.fx.server.handler.GlobalExceptionHandler;
import com.fx.server.interceptor.LogInterceptor;
import com.fx.server.interceptor.UserAuthRestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
@@ -19,7 +19,7 @@ import java.util.Collections;
*/
@Configuration("admimWebConfig")
@Primary
public class WebConfiguration implements WebMvcConfigurer {
public class WebConfiguration implements WebMvcConfigurer {
@Bean
GlobalExceptionHandler getGlobalExceptionHandler() {
return new GlobalExceptionHandler();
@@ -36,14 +36,17 @@ public class WebConfiguration implements WebMvcConfigurer {
UserAuthRestInterceptor getUserAuthRestInterceptor() {
return new UserAuthRestInterceptor();
}
@Bean
LogInterceptor getLogInterceptor() {
return new LogInterceptor();
}
/**
* 需要用户和服务认证判断的路径
*
* @return
*/
private ArrayList<String> getIncludePathPatterns() {

View File

@@ -0,0 +1,27 @@
package com.fx.server.config;
import com.fx.server.interceptor.WebcocketInterceptor;
import com.fx.server.websocket.WebSocketMessageHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
@Autowired
private WebSocketMessageHandler webSocketMessageHandler;
@Autowired
private WebcocketInterceptor myInterceptor;
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry
.addHandler(webSocketMessageHandler, "/websocket/*")
.addInterceptors(myInterceptor)
.setAllowedOrigins("*");
}
}

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.constant;
package com.fx.server.constant;
/**
*

View File

@@ -1,9 +1,7 @@
package com.epri.fx.server.constant;
package com.fx.server.constant;
/**
*
* @Description:
*
* @param:
* @return:
* @auther: liwen
@@ -25,4 +23,19 @@ public class CommonConstants {
public static final String CONTEXT_KEY_USER_TOKEN = "currentUserToken";
public static final String JWT_KEY_USER_ID = "userId";
public static final String JWT_KEY_NAME = "name";
public static final String FAIL = "1";
public static final String SUCCESS = "0";
/**
* 执行目标key
*/
public static final String TASK_PROPERTIES = "TASK_PROPERTIES";
/**
* 执行目标参数
*/
public static final String TASK_PARAMETERS = "TASK_PARAMETERS";
public static final String WEB_SOCKET_USER_LIST = "web_socket_user_list";
public static final String WEB_SOCKET_USER_ID = "web_socket_user_id";
public static final String WEB_SOCKET_TOKEN = "WEB_SOCKET_TOKEN";
}

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.constant;
package com.fx.server.constant;
/**
*

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.constant;
package com.fx.server.constant;
/**
* ${DESCRIPTION}

View File

@@ -1,10 +1,8 @@
package com.epri.fx.server.context;
package com.fx.server.context;
import com.epri.fx.server.constant.CommonConstants;
import com.epri.fx.server.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fx.server.constant.CommonConstants;
import com.fx.server.util.StringHelper;
import java.util.HashMap;
import java.util.Map;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.entity;
package com.fx.server.entity;
import lombok.Data;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.entity;
package com.fx.server.entity;
import java.io.Serializable;
import java.util.Date;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.entity;
package com.fx.server.entity;
import java.io.Serializable;
import java.util.Date;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.entity;
package com.fx.server.entity;
import lombok.Data;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.entity;
package com.fx.server.entity;
import java.io.Serializable;
import java.util.Date;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.entity;
package com.fx.server.entity;
import lombok.Data;

View File

@@ -0,0 +1,57 @@
package com.fx.server.entity;
import lombok.Data;
import org.quartz.Job;
import org.springframework.scheduling.quartz.QuartzJobBean;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* @description:
* @className: SysJob
* @author: liwen
* @date: 2020/12/25 09:06
*/
@Data
public class SysJob implements Serializable {
/**
* 任务实现类
*/
private String jobClass;
/**
* 任务名称(建议唯一)
*/
private String jobName;
/**
* 任务组名
*/
private String jobGroupName;
/**
* 时间表达式 0/5 * * * * ?
*/
private String jobTime;
/**
* 参数
*/
private String parames;
private String description;
private String jobStatus;
public SysJob(String jobClass, String jobName, String jobGroupName, String jobTime, String parames) {
this.jobClass = jobClass;
this.jobName = jobName;
this.jobGroupName = jobGroupName;
this.jobTime = jobTime;
this.parames = parames;
}
public SysJob() {
}
}

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.entity;
package com.fx.server.entity;
import lombok.Data;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.entity;
package com.fx.server.entity;
import java.io.Serializable;
import java.util.Date;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.entity.log;
package com.fx.server.entity.log;
import java.io.Serializable;
import java.util.Date;

View File

@@ -1,13 +1,16 @@
package com.epri.fx.server.entity.log;
package com.fx.server.entity.log;
import java.io.Serializable;
import java.util.Date;
/**
* ${DESCRIPTION}
*
* @author wanghaobin
* @create 2017-07-01 11:18
* @Description:
*
* @param:
* @return:
* @auther: liwen
* @date: 2021/1/4 1:03 下午
*/
public class LogInfo implements Serializable{
private String id;

View File

@@ -0,0 +1,61 @@
package com.fx.server.entity.log;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* sys_job_log
* @author
*/
@Data
public class SysJobLog implements Serializable {
/**
* 任务日志ID
*/
private Long jobLogId;
/**
* 任务名称
*/
private String jobName;
/**
* 任务组名
*/
private String jobGroup;
/**
* 调用目标字符串
*/
private String invokeTarget;
/**
* 日志信息
*/
private String jobMessage;
/**
* 执行状态0正常 1失败
*/
private String status;
/**
* 异常信息
*/
private String exceptionInfo;
/**
* 创建时间
*/
private Date createTime;
/** 开始时间 */
private Date startTime;
/** 结束时间 */
private Date endTime;
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,59 @@
package com.fx.server.entity.log;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* sys_logininfor
* @author
*/
@Data
public class SysLoginInfor implements Serializable {
/**
* 访问ID
*/
private Long infoId;
/**
* 登录账号
*/
private String loginName;
/**
* 登录IP地址
*/
private String ipaddr;
/**
* 登录地点
*/
private String loginLocation;
/**
* 浏览器类型
*/
private String browser;
/**
* 操作系统
*/
private String os;
/**
* 登录状态0成功 1失败
*/
private String status;
/**
* 提示消息
*/
private String msg;
/**
* 访问时间
*/
private Date loginTime;
private static final long serialVersionUID = 1L;
}

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.exception;
package com.fx.server.exception;
/**
*

View File

@@ -1,8 +1,8 @@
package com.epri.fx.server.exception.auth;
package com.fx.server.exception.auth;
import com.epri.fx.server.constant.CommonConstants;
import com.epri.fx.server.exception.BaseException;
import com.fx.server.constant.CommonConstants;
import com.fx.server.exception.BaseException;
/**
*

View File

@@ -1,8 +1,8 @@
package com.epri.fx.server.exception.auth;
package com.fx.server.exception.auth;
import com.epri.fx.server.constant.CommonConstants;
import com.epri.fx.server.exception.BaseException;
import com.fx.server.constant.CommonConstants;
import com.fx.server.exception.BaseException;
/**
*

View File

@@ -1,8 +1,8 @@
package com.epri.fx.server.exception.auth;
package com.fx.server.exception.auth;
import com.epri.fx.server.constant.CommonConstants;
import com.epri.fx.server.exception.BaseException;
import com.fx.server.constant.CommonConstants;
import com.fx.server.exception.BaseException;
/**
*

View File

@@ -1,8 +1,8 @@
package com.epri.fx.server.exception.auth;
package com.fx.server.exception.auth;
import com.epri.fx.server.constant.CommonConstants;
import com.epri.fx.server.exception.BaseException;
import com.fx.server.constant.CommonConstants;
import com.fx.server.exception.BaseException;
/**
*

View File

@@ -1,8 +1,8 @@
package com.epri.fx.server.exception.auth;
package com.fx.server.exception.auth;
import com.epri.fx.server.constant.CommonConstants;
import com.epri.fx.server.exception.BaseException;
import com.fx.server.constant.CommonConstants;
import com.fx.server.exception.BaseException;
/**
*

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.filter;
package com.fx.server.filter;
import lombok.extern.slf4j.Slf4j;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.filter;
package com.fx.server.filter;
import lombok.extern.slf4j.Slf4j;

View File

@@ -0,0 +1,52 @@
package com.fx.server.handler;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;
import java.util.Map;
/**
* WebSocket握手请求的拦截器. 检查握手请求和响应, 对WebSocketHandler传递属性
*/
public class ChatHandshakeInterceptor extends HttpSessionHandshakeInterceptor {
/**
* 在握手之前执行该方法, 继续握手返回true, 中断握手返回false. 通过attributes参数设置WebSocketSession的属性
*
* @param request
* @param response
* @param wsHandler
* @param attributes
* @return
* @throws Exception
*/
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler,
Map<String, Object> attributes) throws Exception {
//为了方便区分来源,在此以用户的名字来区分,名字我们通过要求用输入进行传递,所以在这里先从请求中获取到用户输入的名字,因为是使用的rest 风格,所以规定路径的最后一个字符串是名字
System.out.println("握手之前");
String s = request.getURI().toString();
String s1 = s.substring(s.lastIndexOf("/") + 1);
return super.beforeHandshake(request, response, wsHandler, attributes);
}
/**
* 在握手之后执行该方法. 无论是否握手成功都指明了响应状态码和相应头.
*
* @param request
* @param response
* @param wsHandler
* @param ex
*/
@Override
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler,
Exception ex) {
System.out.println("After Handshake");
super.afterHandshake(request, response, wsHandler, ex);
}
}

View File

@@ -1,12 +1,12 @@
package com.epri.fx.server.handler;
package com.fx.server.handler;
import com.epri.fx.server.constant.CommonConstants;
import com.epri.fx.server.exception.BaseException;
import com.epri.fx.server.exception.auth.ClientTokenException;
import com.epri.fx.server.exception.auth.UserInvalidException;
import com.epri.fx.server.exception.auth.UserTokenException;
import com.epri.fx.server.msg.BaseResponse;
import com.fx.server.constant.CommonConstants;
import com.fx.server.exception.BaseException;
import com.fx.server.exception.auth.ClientTokenException;
import com.fx.server.exception.auth.UserInvalidException;
import com.fx.server.exception.auth.UserTokenException;
import com.fx.server.msg.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
@@ -18,7 +18,7 @@ import javax.servlet.http.HttpServletResponse;
/**
* Created by ace on 2017/9/8.
*/
@ControllerAdvice("com.epri.fx.server")
@ControllerAdvice("com.fx.server")
@ResponseBody
public class GlobalExceptionHandler {
private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

View File

@@ -1,16 +1,16 @@
package com.epri.fx.server.interceptor;
package com.fx.server.interceptor;
import com.epri.fx.server.config.UserConfiguration;
import com.epri.fx.server.context.BaseContextHandler;
import com.epri.fx.server.entity.log.LogInfo;
import com.epri.fx.server.filter.RequestWrapper;
import com.epri.fx.server.jwt.IJWTInfo;
import com.epri.fx.server.service.PermissionService;
import com.epri.fx.server.service.log.GateLogService;
import com.epri.fx.server.util.DBLog;
import com.epri.fx.server.util.user.JwtTokenUtil;
import com.epri.fx.server.vo.PermissionInfo;
import com.fx.server.config.UserConfiguration;
import com.fx.server.context.BaseContextHandler;
import com.fx.server.entity.log.LogInfo;
import com.fx.server.filter.RequestWrapper;
import com.fx.server.jwt.IJWTInfo;
import com.fx.server.service.PermissionService;
import com.fx.server.service.log.GateLogService;
import com.fx.server.util.DBLog;
import com.fx.server.util.user.JwtTokenUtil;
import com.fx.server.vo.PermissionInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -1,12 +1,12 @@
package com.epri.fx.server.interceptor;
package com.fx.server.interceptor;
import com.epri.fx.server.config.UserConfiguration;
import com.epri.fx.server.context.BaseContextHandler;
import com.epri.fx.server.jwt.IJWTInfo;
import com.epri.fx.server.service.PermissionService;
import com.epri.fx.server.service.log.GateLogService;
import com.epri.fx.server.util.user.JwtTokenUtil;
import com.fx.server.config.UserConfiguration;
import com.fx.server.context.BaseContextHandler;
import com.fx.server.jwt.IJWTInfo;
import com.fx.server.service.PermissionService;
import com.fx.server.service.log.GateLogService;
import com.fx.server.util.user.JwtTokenUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -0,0 +1,93 @@
package com.fx.server.interceptor;
import com.fx.server.config.UserConfiguration;
import com.fx.server.entity.log.SysLoginInfor;
import com.fx.server.jwt.IJWTInfo;
import com.fx.server.service.log.SysLoginInfoService;
import com.fx.server.util.user.JwtTokenUtil;
import com.fx.server.constant.CommonConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;
import java.util.Date;
import java.util.Map;
import static java.util.UUID.*;
/**
* @author buhao
* @version MyInterceptor.java, v 0.1 2019-10-17 19:21 buhao
*/
@Slf4j
@Component
public class WebcocketInterceptor implements HandshakeInterceptor {
@Autowired
private JwtTokenUtil jwtTokenUtil;
@Autowired
private UserConfiguration userConfiguration;
@Autowired
private SysLoginInfoService sysLoginInfoService;
/**
* 握手前
*
* @param request
* @param response
* @param wsHandler
* @param attributes
* @return
* @throws Exception
*/
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
log.info("握手开始");
// 获得请求参数
String token = request.getHeaders().getFirst(userConfiguration.getUserTokenHeader());
String userName = request.getHeaders().getFirst("userName");
IJWTInfo ijwtInfo = jwtTokenUtil.getInfoFromToken(token);
SysLoginInfor sysLoginInfor = new SysLoginInfor();
sysLoginInfor.setInfoId(randomUUID().getMostSignificantBits());
sysLoginInfor.setLoginName(userName);
sysLoginInfor.setIpaddr(request.getRemoteAddress().toString());
sysLoginInfor.setLoginTime(new Date());
if (ijwtInfo != null) {
sysLoginInfor.setStatus("0");
sysLoginInfor.setMsg("登录成功!");
// 放入属性域
attributes.put(CommonConstants.WEB_SOCKET_USER_LIST, sysLoginInfor);
attributes.put(CommonConstants.WEB_SOCKET_USER_ID, sysLoginInfor.getLoginName());
sysLoginInfoService.addSysJobLog(sysLoginInfor);
return true;
} else {
log.error("用户登录已失效");
sysLoginInfor.setStatus("1");
sysLoginInfor.setMsg("登录失败!");
sysLoginInfoService.addSysJobLog(sysLoginInfor);
return false;
}
}
/**
* 握手后
*
* @param request
* @param response
* @param wsHandler
* @param exception
*/
@Override
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
log.info("握手完成.");
}
}

View File

@@ -0,0 +1,102 @@
package com.fx.server.job;
import com.fx.server.constant.CommonConstants;
import com.fx.server.entity.SysJob;
import com.fx.server.entity.log.SysJobLog;
import com.fx.server.service.log.SysJobLogService;
import com.fx.server.util.SpringUtils;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import java.util.Date;
/**
* 抽象quartz调用
*
* @author ruoyi
*/
public abstract class AbstractQuartzJob implements Job {
private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class);
/**
* 线程本地变量
*/
private static ThreadLocal<Date> threadLocal = new ThreadLocal<>();
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
SysJob sysJob = new SysJob();
Object obj = context.getMergedJobDataMap().get(CommonConstants.TASK_PROPERTIES);
if (obj != null) {
BeanUtils.copyProperties(obj, sysJob);
}
try {
before(context, sysJob);
if (sysJob != null) {
doExecute(context, sysJob);
}
after(context, sysJob, null);
} catch (Exception e) {
log.error("任务执行异常 - ", e);
after(context, sysJob, e);
}
}
/**
* 执行前
*
* @param context 工作执行上下文对象
* @param sysJob 系统计划任务
*/
protected void before(JobExecutionContext context, SysJob sysJob) {
threadLocal.set(new Date());
}
/**
* 执行后
*
* @param context 工作执行上下文对象
* @param sysScheduleJob 系统计划任务
*/
protected void after(JobExecutionContext context, SysJob sysJob, Exception e) {
Date startTime = threadLocal.get();
threadLocal.remove();
final SysJobLog sysJobLog = new SysJobLog();
sysJobLog.setCreateTime(startTime);
sysJobLog.setJobName(sysJob.getJobName());
sysJobLog.setJobGroup(sysJob.getJobGroupName());
sysJobLog.setInvokeTarget(sysJob.getJobClass());
sysJobLog.setStartTime(startTime);
sysJobLog.setEndTime(new Date());
long runMs = sysJobLog.getEndTime().getTime() - sysJobLog.getStartTime().getTime();
sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
if (e != null) {
sysJobLog.setStatus(CommonConstants.FAIL);
String errorMsg = StringUtils.substring(e.getMessage(), 0, 2000);
sysJobLog.setExceptionInfo(errorMsg);
} else {
sysJobLog.setStatus(CommonConstants.SUCCESS);
}
// 写入数据库当中
SpringUtils.getBean(SysJobLogService.class).addSysJobLog(sysJobLog);
}
/**
* 执行方法,由子类重载
*
* @param context 工作执行上下文对象
* @param sysJob 系统计划任务
* @throws Exception 执行过程中的异常
*/
protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception;
}

View File

@@ -0,0 +1,23 @@
package com.fx.server.job;
import com.fx.server.entity.SysJob;
import com.fx.server.util.SpringUtils;
import com.fx.server.websocket.WebSocketMessageHandler;
import org.quartz.JobExecutionContext;
import org.springframework.web.socket.TextMessage;
/**
* @description:
* @className: TestJob
* @author: liwen
* @date: 2020/12/24 16:23
*/
public class TestJob extends AbstractQuartzJob {
@Override
protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception {
System.err.println("aafdsafdsa");
// 写入数据库当中
SpringUtils.getBean(WebSocketMessageHandler.class).sendMessageToUsers(new TextMessage("999999999999999999999999999999"));
}
}

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.jwt;
package com.fx.server.jwt;
/**
*

View File

@@ -1,8 +1,8 @@
package com.epri.fx.server.jwt;
package com.fx.server.jwt;
import com.epri.fx.server.constant.CommonConstants;
import com.epri.fx.server.util.StringHelper;
import com.fx.server.constant.CommonConstants;
import com.fx.server.util.StringHelper;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.jwt;
package com.fx.server.jwt;
import java.io.Serializable;

View File

@@ -1,9 +1,7 @@
package com.epri.fx.server.jwt;
package com.fx.server.jwt;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.io.DataInputStream;
import java.io.FileOutputStream;
@@ -155,11 +153,11 @@ public class RsaKeyHelper {
}
public static String toHexString(byte[] b) {
return Base64.encodeBase64String(b);
return (new BASE64Encoder()).encodeBuffer(b);
}
public static final byte[] toBytes(String s) throws IOException {
return Base64.decodeBase64(s);
return (new BASE64Decoder()).decodeBuffer(s);
}
public static void main(String[] args) throws NoSuchAlgorithmException {

View File

@@ -1,7 +1,7 @@
package com.epri.fx.server.jwt;
package com.fx.server.jwt;
import com.epri.fx.server.config.UserAuthConfig;
import com.epri.fx.server.exception.auth.UserTokenException;
import com.fx.server.config.UserAuthConfig;
import com.fx.server.exception.auth.UserTokenException;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.SignatureException;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -1,6 +1,6 @@
package com.epri.fx.server.mapper;
package com.fx.server.mapper;
import com.epri.fx.server.entity.Element;
import com.fx.server.entity.Element;
import org.apache.ibatis.annotations.Param;
import java.util.List;

View File

@@ -1,7 +1,6 @@
package com.epri.fx.server.mapper;
package com.fx.server.mapper;
import com.epri.fx.server.entity.User;
import com.epri.fx.server.entity.log.GateLog;
import com.fx.server.entity.log.GateLog;
import java.util.List;

View File

@@ -1,6 +1,6 @@
package com.epri.fx.server.mapper;
package com.fx.server.mapper;
import com.epri.fx.server.entity.Group;
import com.fx.server.entity.Group;
import org.apache.ibatis.annotations.Param;
import java.util.List;

View File

@@ -1,6 +1,6 @@
package com.epri.fx.server.mapper;
package com.fx.server.mapper;
import com.epri.fx.server.entity.GroupType;
import com.fx.server.entity.GroupType;
import java.util.List;

View File

@@ -1,7 +1,7 @@
package com.epri.fx.server.mapper;
package com.fx.server.mapper;
import com.epri.fx.server.entity.Menu;
import com.fx.server.entity.Menu;
import org.apache.ibatis.annotations.Param;
import java.util.List;

View File

@@ -1,6 +1,6 @@
package com.epri.fx.server.mapper;
package com.fx.server.mapper;
import com.epri.fx.server.entity.ResourceAuthority;
import com.fx.server.entity.ResourceAuthority;
import org.apache.ibatis.annotations.Param;
import java.util.List;

View File

@@ -1,6 +1,6 @@
package com.epri.fx.server.mapper;
package com.fx.server.mapper;
import com.epri.fx.server.entity.RsaKey;
import com.fx.server.entity.RsaKey;
public interface RsaKeyMapper {
int deleteByPrimaryKey(String key);

View File

@@ -0,0 +1,22 @@
package com.fx.server.mapper;
import com.fx.server.entity.log.SysJobLog;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface SysJobLogMapper {
int deleteByPrimaryKey(Long jobLogId);
int insert(SysJobLog record);
int insertSelective(SysJobLog record);
SysJobLog selectByPrimaryKey(Long jobLogId);
int updateByPrimaryKeySelective(SysJobLog record);
int updateByPrimaryKey(SysJobLog record);
List<SysJobLog> selectPage(@Param("params") Map<String, Object> params);
}

View File

@@ -0,0 +1,22 @@
package com.fx.server.mapper;
import com.fx.server.entity.log.SysLoginInfor;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface SysLoginInforMapper {
int deleteByPrimaryKey(Long infoId);
int insert(SysLoginInfor record);
int insertSelective(SysLoginInfor record);
SysLoginInfor selectByPrimaryKey(Long infoId);
int updateByPrimaryKeySelective(SysLoginInfor record);
int updateByPrimaryKey(SysLoginInfor record);
List<SysLoginInfor> selectPage(@Param("params")Map<String,Object> params);
}

View File

@@ -1,6 +1,6 @@
package com.epri.fx.server.mapper;
package com.fx.server.mapper;
import com.epri.fx.server.entity.User;
import com.fx.server.entity.User;
import org.apache.ibatis.annotations.Param;
import java.util.List;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.msg;
package com.fx.server.msg;
/**
*

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.msg;
package com.fx.server.msg;
/**
* ${DESCRIPTION}

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.msg;
package com.fx.server.msg;
/**
*

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.msg;
package com.fx.server.msg;
import java.util.List;

View File

@@ -1,8 +1,8 @@
package com.epri.fx.server.msg.auth;
package com.fx.server.msg.auth;
import com.epri.fx.server.constant.RestCodeConstants;
import com.epri.fx.server.msg.BaseResponse;
import com.fx.server.constant.RestCodeConstants;
import com.fx.server.msg.BaseResponse;
/**
*

View File

@@ -1,8 +1,8 @@
package com.epri.fx.server.msg.auth;
package com.fx.server.msg.auth;
import com.epri.fx.server.constant.RestCodeConstants;
import com.epri.fx.server.msg.BaseResponse;
import com.fx.server.constant.RestCodeConstants;
import com.fx.server.msg.BaseResponse;
/**
*

View File

@@ -1,8 +1,8 @@
package com.epri.fx.server.rest;
package com.fx.server.rest;
import com.epri.fx.server.msg.ObjectRestResponse;
import com.epri.fx.server.service.security.auth.AuthService;
import com.epri.fx.server.util.user.JwtAuthenticationRequest;
import com.fx.server.msg.ObjectRestResponse;
import com.fx.server.service.security.auth.AuthService;
import com.fx.server.util.user.JwtAuthenticationRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

View File

@@ -1,8 +1,8 @@
package com.epri.fx.server.rest;
package com.fx.server.rest;
import com.epri.fx.server.entity.Element;
import com.epri.fx.server.msg.TableResultResponse;
import com.epri.fx.server.service.ElementService;
import com.fx.server.entity.Element;
import com.fx.server.msg.TableResultResponse;
import com.fx.server.service.ElementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

View File

@@ -1,10 +1,10 @@
package com.epri.fx.server.rest;
package com.fx.server.rest;
import com.epri.fx.server.service.GroupService;
import com.epri.fx.server.vo.GroupUsers;
import com.epri.fx.server.vo.GroupVO;
import com.epri.fx.server.vo.MenuVO;
import com.fx.server.service.GroupService;
import com.fx.server.vo.GroupUsers;
import com.fx.server.vo.GroupVO;
import com.fx.server.vo.MenuVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

View File

@@ -1,10 +1,9 @@
package com.epri.fx.server.rest;
package com.fx.server.rest;
import com.epri.fx.server.service.GroupTypeService;
import com.epri.fx.server.vo.GroupTypeVO;
import com.fx.server.service.GroupTypeService;
import com.fx.server.vo.GroupTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;

View File

@@ -1,6 +1,6 @@
package com.epri.fx.server.rest;
package com.fx.server.rest;
import com.epri.fx.server.service.MenuService;
import com.fx.server.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

View File

@@ -1,22 +1,13 @@
package com.epri.fx.server.rest;
package com.fx.server.rest;
import com.epri.fx.server.entity.User;
import com.epri.fx.server.entity.UserInfo;
import com.epri.fx.server.entity.log.GateLog;
import com.epri.fx.server.entity.log.LogInfo;
import com.epri.fx.server.msg.ObjectRestResponse;
import com.epri.fx.server.msg.TableResultResponse;
import com.epri.fx.server.service.PermissionService;
import com.epri.fx.server.service.UserService;
import com.epri.fx.server.service.log.GateLogService;
import com.epri.fx.server.vo.FrontUser;
import com.epri.fx.server.vo.MenuVO;
import com.epri.fx.server.vo.PermissionInfo;
import com.fx.server.entity.log.GateLog;
import com.fx.server.msg.ObjectRestResponse;
import com.fx.server.msg.TableResultResponse;
import com.fx.server.service.log.GateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.rest;
package com.fx.server.rest;
import org.springframework.web.bind.annotation.RestController;

View File

@@ -1,9 +1,8 @@
package com.epri.fx.server.rest;
package com.fx.server.rest;
import com.epri.fx.server.entity.Menu;
import com.epri.fx.server.service.MenuService;
import com.epri.fx.server.vo.MenuVO;
import com.fx.server.service.MenuService;
import com.fx.server.vo.MenuVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

View File

@@ -0,0 +1,86 @@
package com.fx.server.rest;
import com.fx.server.entity.SysJob;
import com.fx.server.entity.log.SysJobLog;
import com.fx.server.msg.TableResultResponse;
import com.fx.server.service.log.SysJobLogService;
import com.fx.server.service.quartz.SysJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @description:
* @className: QuartzController
* @author: liwen
* @date: 2020/12/25 08:53
*/
@RestController
@RequestMapping("job")
public class SysJobController {
@Autowired
private SysJobService sysJobService;
@Autowired
private SysJobLogService sysJobLogService;
@GetMapping("/list")
@ResponseBody
public List<SysJob> getAllJob(String jobName, String jobGroup, String jobStatus) {
SysJob queryJob = new SysJob();
queryJob.setJobName(jobName);
queryJob.setJobGroupName(jobGroup);
queryJob.setJobStatus(jobStatus);
return sysJobService.queryAllJob(jobName, jobGroup, jobStatus);
}
@GetMapping("/log/list")
@ResponseBody
public TableResultResponse<SysJobLog> getAllJob(@RequestParam Map<String, Object> params) {
return sysJobLogService.getPageList(params);
}
@PostMapping("")
@ResponseBody
public Integer addJob(@RequestBody SysJob sysJob) {
return sysJobService.addJob(sysJob);
}
@PutMapping("")
@ResponseBody
public Integer updateJob(@RequestBody SysJob sysJob) {
return sysJobService.updateJob(sysJob);
}
@DeleteMapping("/{jobName}/{jobGroupName}")
@ResponseBody
public Integer deleteJob(@PathVariable("jobName") String jobName, @PathVariable("jobGroupName") String jobGroupName) {
return sysJobService.deleteJob(jobName, jobGroupName);
}
@PutMapping("pause/{jobName}/{jobGroupName}")
@ResponseBody
public Integer pauseJob(@PathVariable("jobName") String jobName, @PathVariable("jobGroupName") String jobGroupName) {
return sysJobService.pauseJob(jobName, jobGroupName);
}
@PutMapping("resume/{jobName}/{jobGroupName}")
@ResponseBody
public Integer resumeJob(@PathVariable("jobName") String jobName, @PathVariable("jobGroupName") String jobGroupName) {
return sysJobService.resumeJob(jobName, jobGroupName);
}
@PutMapping("run/{jobName}/{jobGroupName}")
@ResponseBody
public Integer runAJobNow(@PathVariable("jobName") String jobName, @PathVariable("jobGroupName") String jobGroupName) {
return sysJobService.runAJobNow(jobName, jobGroupName);
}
}

View File

@@ -0,0 +1,29 @@
package com.fx.server.rest;
import com.fx.server.entity.log.SysLoginInfor;
import com.fx.server.msg.TableResultResponse;
import com.fx.server.service.log.SysLoginInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* @description:
* @className: SysLoginInfoController
* @author: liwen
* @date: 2021/1/4 13:21
*/
@RestController()
@RequestMapping("log/login")
public class SysLoginInfoController {
@Autowired
private SysLoginInfoService sysLoginInfoService;
@GetMapping("/list")
@ResponseBody
private TableResultResponse<SysLoginInfor> getSysloginInforList(@RequestParam Map<String, Object> params) {
return sysLoginInfoService.getPageList(params);
}
}

View File

@@ -1,18 +1,18 @@
package com.epri.fx.server.rest;
package com.fx.server.rest;
import com.epri.fx.server.entity.User;
import com.epri.fx.server.entity.UserInfo;
import com.epri.fx.server.msg.ObjectRestResponse;
import com.epri.fx.server.msg.TableResultResponse;
import com.epri.fx.server.service.PermissionService;
import com.epri.fx.server.service.UserService;
import com.epri.fx.server.vo.FrontUser;
import com.epri.fx.server.vo.MenuVO;
import com.epri.fx.server.vo.PermissionInfo;
import com.epri.fx.server.vo.UserVO;
import com.fx.server.entity.User;
import com.fx.server.entity.UserInfo;
import com.fx.server.entity.log.SysLoginInfor;
import com.fx.server.msg.ObjectRestResponse;
import com.fx.server.msg.TableResultResponse;
import com.fx.server.service.PermissionService;
import com.fx.server.service.UserService;
import com.fx.server.vo.FrontUser;
import com.fx.server.vo.MenuVO;
import com.fx.server.vo.PermissionInfo;
import com.fx.server.websocket.WebSocketMessageHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -20,9 +20,7 @@ import java.util.Map;
/**
*
* @Description:
*
* @param:
* @return:
* @auther: liwen
@@ -36,6 +34,8 @@ public class UserController {
@Autowired
private PermissionService permissionService;
@Autowired
private WebSocketMessageHandler webSocketMessageHandler;
@GetMapping(value = "/page")
@ResponseBody
@@ -44,12 +44,20 @@ public class UserController {
return userService.getPageList(params);
}
@GetMapping(value = "/online/list")
@ResponseBody
public List<SysLoginInfor> getOnlineUsers() {
return webSocketMessageHandler.getOnlineUsers();
}
@PutMapping("/{id}")
@ResponseBody
public ObjectRestResponse<Integer> update(@PathVariable int id, @RequestBody User entity) {
return userService.update(entity);
}
@PutMapping("/password/{id}")
@ResponseBody
public ObjectRestResponse<Integer> restPasswrod(@PathVariable Integer id) {
@@ -65,6 +73,14 @@ public class UserController {
return userService.add(entity);
}
@PostMapping("/retreat/{userId}")
@ResponseBody
public ObjectRestResponse<Boolean> retreat(@PathVariable("userId") String userId) {
return new ObjectRestResponse<Boolean>().rel(webSocketMessageHandler.retreat(userId));
}
@DeleteMapping("/{id}")
@ResponseBody
@@ -107,4 +123,5 @@ public class UserController {
return permissionService.getMenusByUsername(token);
}
}

View File

@@ -1,10 +1,9 @@
package com.epri.fx.server.runner;
package com.fx.server.runner;
import com.epri.fx.server.config.KeyConfiguration;
import com.epri.fx.server.config.UserAuthConfig;
import com.epri.fx.server.entity.RsaKey;
import com.epri.fx.server.jwt.RsaKeyHelper;
import com.epri.fx.server.service.RsaKeyService;
import com.fx.server.config.KeyConfiguration;
import com.fx.server.config.UserAuthConfig;
import com.fx.server.jwt.RsaKeyHelper;
import com.fx.server.service.RsaKeyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;

View File

@@ -1,9 +1,9 @@
package com.epri.fx.server.service;
package com.fx.server.service;
import com.epri.fx.server.entity.Element;
import com.epri.fx.server.mapper.ElementMapper;
import com.epri.fx.server.msg.TableResultResponse;
import com.epri.fx.server.util.EntityUtils;
import com.fx.server.entity.Element;
import com.fx.server.mapper.ElementMapper;
import com.fx.server.msg.TableResultResponse;
import com.fx.server.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@@ -1,16 +1,16 @@
package com.epri.fx.server.service;
package com.fx.server.service;
import com.epri.fx.server.constant.AdminCommonConstant;
import com.epri.fx.server.entity.Element;
import com.epri.fx.server.entity.Group;
import com.epri.fx.server.entity.Menu;
import com.epri.fx.server.entity.ResourceAuthority;
import com.epri.fx.server.mapper.*;
import com.epri.fx.server.util.EntityUtils;
import com.epri.fx.server.vo.ElementVO;
import com.epri.fx.server.vo.GroupUsers;
import com.epri.fx.server.vo.GroupVO;
import com.epri.fx.server.vo.MenuVO;
import com.fx.server.constant.AdminCommonConstant;
import com.fx.server.entity.Element;
import com.fx.server.entity.Group;
import com.fx.server.entity.Menu;
import com.fx.server.entity.ResourceAuthority;
import com.fx.server.mapper.*;
import com.fx.server.util.EntityUtils;
import com.fx.server.vo.ElementVO;
import com.fx.server.vo.GroupUsers;
import com.fx.server.vo.GroupVO;
import com.fx.server.vo.MenuVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -19,7 +19,6 @@ import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**

View File

@@ -1,9 +1,9 @@
package com.epri.fx.server.service;
package com.fx.server.service;
import com.epri.fx.server.entity.GroupType;
import com.epri.fx.server.mapper.GroupTypeMapper;
import com.epri.fx.server.util.EntityUtils;
import com.epri.fx.server.vo.GroupTypeVO;
import com.fx.server.entity.GroupType;
import com.fx.server.mapper.GroupTypeMapper;
import com.fx.server.util.EntityUtils;
import com.fx.server.vo.GroupTypeVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@@ -1,24 +1,19 @@
package com.epri.fx.server.service;
package com.fx.server.service;
import com.epri.fx.server.constant.AdminCommonConstant;
import com.epri.fx.server.entity.Element;
import com.epri.fx.server.entity.Menu;
import com.epri.fx.server.entity.ResourceAuthority;
import com.epri.fx.server.mapper.ElementMapper;
import com.epri.fx.server.mapper.MenuMapper;
import com.epri.fx.server.mapper.ResourceAuthorityMapper;
import com.epri.fx.server.util.EntityUtils;
import com.epri.fx.server.vo.ElementVO;
import com.epri.fx.server.vo.GroupVO;
import com.epri.fx.server.vo.MenuVO;
import com.fx.server.constant.AdminCommonConstant;
import com.fx.server.entity.Menu;
import com.fx.server.mapper.ElementMapper;
import com.fx.server.mapper.MenuMapper;
import com.fx.server.mapper.ResourceAuthorityMapper;
import com.fx.server.util.EntityUtils;
import com.fx.server.vo.ElementVO;
import com.fx.server.vo.MenuVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @description:

View File

@@ -1,17 +1,17 @@
package com.epri.fx.server.service;
package com.fx.server.service;
import com.epri.fx.server.constant.AdminCommonConstant;
import com.epri.fx.server.constant.CommonConstants;
import com.epri.fx.server.entity.Element;
import com.epri.fx.server.entity.Menu;
import com.epri.fx.server.entity.User;
import com.epri.fx.server.entity.UserInfo;
import com.epri.fx.server.jwt.UserAuthUtil;
import com.epri.fx.server.util.EncryptUtil;
import com.epri.fx.server.vo.FrontUser;
import com.epri.fx.server.vo.GroupVO;
import com.epri.fx.server.vo.MenuVO;
import com.epri.fx.server.vo.PermissionInfo;
import com.fx.server.constant.AdminCommonConstant;
import com.fx.server.constant.CommonConstants;
import com.fx.server.entity.Element;
import com.fx.server.entity.Menu;
import com.fx.server.entity.User;
import com.fx.server.entity.UserInfo;
import com.fx.server.jwt.UserAuthUtil;
import com.fx.server.util.EncryptUtil;
import com.fx.server.vo.FrontUser;
import com.fx.server.vo.GroupVO;
import com.fx.server.vo.MenuVO;
import com.fx.server.vo.PermissionInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -1,7 +1,7 @@
package com.epri.fx.server.service;
package com.fx.server.service;
import com.epri.fx.server.entity.RsaKey;
import com.epri.fx.server.mapper.RsaKeyMapper;
import com.fx.server.entity.RsaKey;
import com.fx.server.mapper.RsaKeyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@@ -1,26 +1,20 @@
package com.epri.fx.server.service;
package com.fx.server.service;
import com.alibaba.druid.util.StringUtils;
import com.epri.fx.server.constant.UserConstant;
import com.epri.fx.server.entity.Menu;
import com.epri.fx.server.entity.User;
import com.epri.fx.server.entity.UserInfo;
import com.epri.fx.server.mapper.MenuMapper;
import com.epri.fx.server.mapper.UserMapper;
import com.epri.fx.server.msg.ObjectRestResponse;
import com.epri.fx.server.msg.TableResultResponse;
import com.epri.fx.server.util.EntityUtils;
import com.epri.fx.server.util.Query;
import com.epri.fx.server.util.user.JwtAuthenticationRequest;
import com.epri.fx.server.vo.UserVO;
import com.fx.server.constant.UserConstant;
import com.fx.server.entity.User;
import com.fx.server.entity.UserInfo;
import com.fx.server.mapper.UserMapper;
import com.fx.server.msg.ObjectRestResponse;
import com.fx.server.msg.TableResultResponse;
import com.fx.server.util.EntityUtils;
import com.fx.server.util.Query;
import com.fx.server.util.user.JwtAuthenticationRequest;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;

View File

@@ -1,12 +1,12 @@
package com.epri.fx.server.service.log;
package com.fx.server.service.log;
import com.alibaba.druid.util.StringUtils;
import com.epri.fx.server.entity.log.GateLog;
import com.epri.fx.server.entity.log.LogInfo;
import com.epri.fx.server.mapper.GateLogMapper;
import com.epri.fx.server.msg.ObjectRestResponse;
import com.epri.fx.server.msg.TableResultResponse;
import com.epri.fx.server.util.Query;
import com.fx.server.entity.log.GateLog;
import com.fx.server.entity.log.LogInfo;
import com.fx.server.mapper.GateLogMapper;
import com.fx.server.msg.ObjectRestResponse;
import com.fx.server.msg.TableResultResponse;
import com.fx.server.util.Query;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;

View File

@@ -0,0 +1,38 @@
package com.fx.server.service.log;
import com.fx.server.entity.log.SysJobLog;
import com.fx.server.mapper.SysJobLogMapper;
import com.fx.server.msg.TableResultResponse;
import com.fx.server.util.Query;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* @description:
* @className: SysJobLogServer
* @author: liwen
* @date: 2020/12/28 16:37
*/
@Service
public class SysJobLogService {
@Autowired
private SysJobLogMapper sysJobLogMapper;
public void addSysJobLog(SysJobLog sysJobLog) {
sysJobLogMapper.insert(sysJobLog);
}
public TableResultResponse<SysJobLog> getPageList(Map<String, Object> params) {
Query query = new Query(params);
Page<Object> page = PageHelper.startPage(query.getPage(), query.getLimit());
List<SysJobLog> list = sysJobLogMapper.selectPage(params);
int total = (int) Math.ceil(page.getTotal() / (float) query.getLimit());
return new TableResultResponse<SysJobLog>(total == 0 ? 1 : total, list);
}
}

View File

@@ -0,0 +1,38 @@
package com.fx.server.service.log;
import com.fx.server.entity.log.SysLoginInfor;
import com.fx.server.mapper.SysLoginInforMapper;
import com.fx.server.msg.TableResultResponse;
import com.fx.server.util.Query;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* @description:
* @className: SysJobLogServer
* @author: liwen
* @date: 2020/12/28 16:37
*/
@Service
public class SysLoginInfoService {
@Autowired
private SysLoginInforMapper sysLoginInforMapper;
public int addSysJobLog(SysLoginInfor sysLoginInfor) {
return sysLoginInforMapper.insertSelective(sysLoginInfor);
}
public TableResultResponse<SysLoginInfor> getPageList(Map<String, Object> params) {
Query query = new Query(params);
Page<Object> page = PageHelper.startPage(query.getPage(), query.getLimit());
List<SysLoginInfor> list = sysLoginInforMapper.selectPage(params);
int total = (int) Math.ceil(page.getTotal() / (float) query.getLimit());
return new TableResultResponse<SysLoginInfor>(total == 0 ? 1 : total, list);
}
}

View File

@@ -0,0 +1,287 @@
package com.fx.server.service.quartz;
import com.fx.server.constant.CommonConstants;
import com.fx.server.entity.SysJob;
import org.apache.commons.lang3.StringUtils;
import org.quartz.*;
import org.quartz.impl.matchers.GroupMatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.*;
@Service
public class SysJobService {
@Autowired
private Scheduler scheduler;
@PostConstruct
public void startScheduler() {
try {
scheduler.start();
} catch (SchedulerException e) {
e.printStackTrace();
}
}
/**
* 增加一个job
*
* @param jobClass 任务实现类
* @param jobName 任务名称
* @param jobGroupName 任务组名
* @param jobTime 时间表达式 (这是每隔多少秒为一次任务)
* @param jobTimes 运行的次数 <0:表示不限次数)
* @param jobData 参数
*/
public void addJob(Class<? extends Job> jobClass, String jobName, String jobGroupName, int jobTime,
int jobTimes, Map jobData) {
try {
// 任务名称和组构成任务key
JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(jobName, jobGroupName)
.build();
// 设置job参数
if (jobData != null && jobData.size() > 0) {
jobDetail.getJobDataMap().putAll(jobData);
}
// 使用simpleTrigger规则
Trigger trigger = null;
if (jobTimes < 0) {
trigger = TriggerBuilder.newTrigger().withIdentity(jobName, jobGroupName)
.withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(1).withIntervalInSeconds(jobTime))
.startNow().build();
} else {
trigger = TriggerBuilder
.newTrigger().withIdentity(jobName, jobGroupName).withSchedule(SimpleScheduleBuilder
.repeatSecondlyForever(1).withIntervalInSeconds(jobTime).withRepeatCount(jobTimes))
.startNow().build();
}
scheduler.scheduleJob(jobDetail, trigger);
} catch (SchedulerException e) {
e.printStackTrace();
}
}
/**
* 增加一个job
*/
public Integer addJob(SysJob sysJob) {
try {
// 创建jobDetail实例绑定Job实现类
// 指明job的名称所在组的名称以及绑定job类
// 任务名称和组构成任务key
JobDetail jobDetail = JobBuilder.newJob((Class<? extends Job>) Class.forName(sysJob.getJobClass())).withIdentity(sysJob.getJobName(), sysJob.getJobGroupName())
.build();
jobDetail.getJobDataMap().put(CommonConstants.TASK_PROPERTIES, sysJob);
// 设置job参数
if (StringUtils.isNotBlank(sysJob.getParames())) {
jobDetail.getJobDataMap().put(CommonConstants.TASK_PARAMETERS, sysJob.getParames());
}
// 定义调度触发规则
// 使用cornTrigger规则
// 触发器key
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(sysJob.getJobName(), sysJob.getJobGroupName()).withDescription(sysJob.getDescription())
.startAt(DateBuilder.futureDate(1, DateBuilder.IntervalUnit.SECOND))
.withSchedule(CronScheduleBuilder.cronSchedule(sysJob.getJobTime())).startNow().build();
// 把作业和触发器注册到任务调度中
scheduler.scheduleJob(jobDetail, trigger);
return 0;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* 修改 一个job的 时间表达式
*/
public Integer updateJob(SysJob sysJob) {
try {
TriggerKey triggerKey = TriggerKey.triggerKey(sysJob.getJobName(), sysJob.getJobGroupName());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey)
.withSchedule(CronScheduleBuilder.cronSchedule(sysJob.getJobTime())).withDescription(sysJob.getDescription()).build();
JobKey jobKey = JobKey.jobKey(sysJob.getJobName(), sysJob.getJobGroupName());
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
// 设置job参数
if (StringUtils.isNotBlank(sysJob.getParames())) {
jobDetail.getJobDataMap().put(CommonConstants.TASK_PARAMETERS, sysJob.getParames());
}
// 重启触发器
scheduler.rescheduleJob(triggerKey, trigger);
return 0;
} catch (SchedulerException e) {
e.printStackTrace();
return -1;
}
}
/**
* 删除任务一个job
*
* @param jobName 任务名称
* @param jobGroupName 任务组名
*/
public Integer deleteJob(String jobName, String jobGroupName) {
try {
scheduler.deleteJob(new JobKey(jobName, jobGroupName));
return 0;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* 暂停一个job
*
* @param jobName
* @param jobGroupName
*/
public Integer pauseJob(String jobName, String jobGroupName) {
try {
JobKey jobKey = JobKey.jobKey(jobName, jobGroupName);
scheduler.pauseJob(jobKey);
return 0;
} catch (SchedulerException e) {
e.printStackTrace();
return -1;
}
}
/**
* 恢复一个job
*
* @param jobName
* @param jobGroupName
*/
public Integer resumeJob(String jobName, String jobGroupName) {
try {
JobKey jobKey = JobKey.jobKey(jobName, jobGroupName);
scheduler.resumeJob(jobKey);
return 0;
} catch (SchedulerException e) {
e.printStackTrace();
return -1;
}
}
/**
* 立即执行一个job
*
* @param jobName
* @param jobGroupName
*/
public Integer runAJobNow(String jobName, String jobGroupName) {
try {
JobKey jobKey = JobKey.jobKey(jobName, jobGroupName);
scheduler.triggerJob(jobKey);
return 0;
} catch (SchedulerException e) {
e.printStackTrace();
return -1;
}
}
/**
* 获取所有计划中的任务列表
*
* @return
*/
public List<SysJob> queryAllJob(String jobName,String jobGroup,String jobStatus) {
List<SysJob> jobList = null;
try {
GroupMatcher<JobKey> matcher = GroupMatcher.anyJobGroup();
Set<JobKey> jobKeys = scheduler.getJobKeys(matcher);
jobList = new ArrayList<>();
for (JobKey jobKey : jobKeys) {
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
for (Trigger trigger : triggers) {
SysJob sysJob = new SysJob();
sysJob.setJobName(jobKey.getName());
sysJob.setJobClass(scheduler.getJobDetail(trigger.getJobKey()).getJobClass().getName());
sysJob.setJobGroupName(jobKey.getGroup());
sysJob.setDescription(trigger.getDescription());
sysJob.setParames(scheduler.getJobDetail(trigger.getJobKey()).getJobDataMap().getString(CommonConstants.TASK_PARAMETERS));
Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
sysJob.setJobStatus(triggerState.name());
if (trigger instanceof CronTrigger) {
CronTrigger cronTrigger = (CronTrigger) trigger;
String cronExpression = cronTrigger.getCronExpression();
sysJob.setJobTime(cronExpression);
}
boolean a = false;
boolean b = false;
boolean c = false;
if (StringUtils.isBlank(jobName)) {
a = true;
} else {
a = jobKey.getName().toLowerCase().contains(jobName);
}
if (StringUtils.isBlank(jobGroup)) {
b = true;
} else {
b = jobKey.getGroup().equalsIgnoreCase(jobGroup);
}
if (StringUtils.isBlank(jobStatus)) {
c = true;
} else {
c = triggerState.name().equalsIgnoreCase(jobStatus);
}
if (a && b && c) {
jobList.add(sysJob);
}
}
}
} catch (SchedulerException e) {
e.printStackTrace();
}
return jobList;
}
/**
* 获取所有正在运行的job
*
* @return
*/
public List<SysJob> queryRunJob() {
List<SysJob> jobList = null;
try {
List<JobExecutionContext> executingJobs = scheduler.getCurrentlyExecutingJobs();
jobList = new ArrayList<>(executingJobs.size());
for (JobExecutionContext executingJob : executingJobs) {
SysJob sysJob = new SysJob();
JobDetail jobDetail = executingJob.getJobDetail();
JobKey jobKey = jobDetail.getKey();
Trigger trigger = executingJob.getTrigger();
sysJob.setJobName(jobKey.getName());
sysJob.setJobGroupName(jobKey.getGroup());
sysJob.setDescription("触发器:" + trigger.getKey());
sysJob.setJobClass(scheduler.getJobDetail(trigger.getJobKey()).getJobClass().toString());
sysJob.setParames(scheduler.getJobDetail(trigger.getJobKey()).getJobDataMap().getString(CommonConstants.TASK_PARAMETERS));
Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
sysJob.setJobStatus(triggerState.name());
if (trigger instanceof CronTrigger) {
CronTrigger cronTrigger = (CronTrigger) trigger;
String cronExpression = cronTrigger.getCronExpression();
sysJob.setJobTime(cronExpression);
}
jobList.add(sysJob);
}
} catch (SchedulerException e) {
e.printStackTrace();
}
return jobList;
}
}

View File

@@ -1,7 +1,7 @@
package com.epri.fx.server.service.security.auth;
package com.fx.server.service.security.auth;
import com.epri.fx.server.util.user.JwtAuthenticationRequest;
import com.fx.server.util.user.JwtAuthenticationRequest;
public interface AuthService {
String login(JwtAuthenticationRequest authenticationRequest) throws Exception;

View File

@@ -1,12 +1,12 @@
package com.epri.fx.server.service.security.auth.impl;
package com.fx.server.service.security.auth.impl;
import com.epri.fx.server.entity.UserInfo;
import com.epri.fx.server.exception.auth.UserInvalidException;
import com.epri.fx.server.jwt.JWTInfo;
import com.epri.fx.server.service.security.auth.AuthService;
import com.epri.fx.server.service.UserService;
import com.epri.fx.server.util.user.JwtAuthenticationRequest;
import com.epri.fx.server.util.user.JwtTokenUtil;
import com.fx.server.entity.UserInfo;
import com.fx.server.exception.auth.UserInvalidException;
import com.fx.server.jwt.JWTInfo;
import com.fx.server.service.security.auth.AuthService;
import com.fx.server.service.UserService;
import com.fx.server.util.user.JwtAuthenticationRequest;
import com.fx.server.util.user.JwtTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.util;
package com.fx.server.util;
import javax.servlet.http.HttpServletRequest;

View File

@@ -1,8 +1,8 @@
package com.epri.fx.server.util;
package com.fx.server.util;
import com.epri.fx.server.entity.log.LogInfo;
import com.epri.fx.server.service.log.GateLogService;
import com.fx.server.entity.log.LogInfo;
import com.fx.server.service.log.GateLogService;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;

View File

@@ -0,0 +1,514 @@
package com.fx.server.util;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.apache.commons.lang3.time.DateFormatUtils;
public class DateUtils {
/**
* 仅显示年月日,例如 2015-08-11.
*/
public static final String DATE_FORMAT = "yyyy-MM-dd";
/**
* 显示年月日时分秒,例如 2015-08-11 09:51:53.
*/
public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
/**
* 仅显示时分秒,例如 09:51:53.
*/
public static final String TIME_FORMAT = "HH:mm:ss";
/**
* 每天的毫秒数 8640000.
*/
public static final long MILLISECONDS_PER_DAY = 86400000L;
/**
* 每周的天数.
*/
public static final long DAYS_PER_WEEK = 7L;
/**
* 每小时毫秒数.
*/
public static final long MILLISECONDS_PER_HOUR = 3600000L;
/**
* 每分钟秒数.
*/
public static final long SECONDS_PER_MINUTE = 60L;
/**
* 每小时秒数.
*/
public static final long SECONDS_PER_HOUR = 3600L;
/**
* 每天秒数.
*/
public static final long SECONDS_PER_DAY = 86400L;
/**
* 每个月秒数默认每月30天.
*/
public static final long SECONDS_PER_MONTH = 2592000L;
/**
* 每年秒数默认每年365天.
*/
public static final long SECONDS_PER_YEAR = 31536000L;
/**
* 常用的时间格式.
*/
private static String[] parsePatterns = {"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd",
"yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm"};
/**
* 得到当前日期字符串.
*
* @return String 日期字符串例如2015-08-11
* @since 1.0
*/
public static String getDate() {
return getDate(DateUtils.DATE_FORMAT);
}
/**
* 得到当前时间字符串.
*
* @return String 时间字符串,例如 09:51:53
* @since 1.0
*/
public static String getTime() {
return formatDate(new Date(), DateUtils.TIME_FORMAT);
}
/**
* 得到当前日期和时间字符串.
*
* @return String 日期和时间字符串,例如 2015-08-11 09:51:53
* @since 1.0
*/
public static String getDateTime() {
return formatDate(new Date(), DateUtils.DATETIME_FORMAT);
}
/**
* 获取当前时间指定格式下的字符串.
*
* @param pattern 转化后时间展示的格式,例如"yyyy-MM-dd""yyyy-MM-dd HH:mm:ss"等
* @return String 格式转换之后的时间字符串.
* @since 1.0
*/
public static String getDate(String pattern) {
return DateFormatUtils.format(new Date(), pattern);
}
/**
* 获取指定日期的字符串格式.
*
* @param date 需要格式化的时间,不能为空
* @param pattern 时间格式,例如"yyyy-MM-dd""yyyy-MM-dd HH:mm:ss"等
* @return String 格式转换之后的时间字符串.
* @since 1.0
*/
public static String getDate(Date date, String pattern) {
return DateFormatUtils.format(date, pattern);
}
/**
* 获取日期时间字符串默认格式为yyyy-MM-dd.
*
* @param date 需要转化的日期时间
* @param pattern 时间格式,例如"yyyy-MM-dd" "HH:mm:ss" "E"等
* @return String 格式转换后的时间字符串
* @since 1.0
*/
public static String formatDate(Date date, Object... pattern) {
String formatDate = null;
if (pattern != null && pattern.length > 0) {
formatDate = DateFormatUtils.format(date, pattern[0].toString());
} else {
formatDate = DateFormatUtils.format(date, DateUtils.DATE_FORMAT);
}
return formatDate;
}
/**
* 获取当前年份字符串.
*
* @return String 当前年份字符串,例如 2015
* @since 1.0
*/
public static String getYear() {
return formatDate(new Date(), "yyyy");
}
/**
* 获取当前月份字符串.
*
* @return String 当前月份字符串,例如 08
* @since 1.0
*/
public static String getMonth() {
return formatDate(new Date(), "MM");
}
/**
* 获取当前天数字符串.
*
* @return String 当前天数字符串,例如 11
* @since 1.0
*/
public static String getDay() {
return formatDate(new Date(), "dd");
}
/**
* 获取当前星期字符串.
*
* @return String 当前星期字符串,例如星期二
* @since 1.0
*/
public static String getWeek() {
return formatDate(new Date(), "E");
}
/**
* 将日期型字符串转换为日期格式.
* 支持的日期字符串格式包括"yyyy-MM-dd","yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
* "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm"
*
* @param str
* @return Date
* @since 1.0
*/
public static Date parseDate(Object str) {
if (str == null) {
return null;
}
try {
return org.apache.commons.lang3.time.DateUtils.parseDate(str.toString(), parsePatterns);
} catch (ParseException e) {
return null;
}
}
/**
* 获取当前日期与指定日期相隔的天数.
*
* @param date 给定的日期
* @return long 日期间隔天数,正数表示给定日期在当前日期之前,负数表示在当前日期之后
* @since 1.0
*/
public static long pastDays(Date date) {
// 将指定日期转换为yyyy-MM-dd格式
date = DateUtils.parseDate(DateUtils.formatDate(date, DateUtils.DATE_FORMAT));
// 当前日期转换为yyyy-MM-dd格式
Date currentDate = DateUtils.parseDate(DateUtils.formatDate(new Date(), DateUtils.DATE_FORMAT));
long t = 0;
if (date != null && currentDate != null) {
t = (currentDate.getTime() - date.getTime()) / DateUtils.MILLISECONDS_PER_DAY;
}
return t;
}
/**
* 获取当前日期指定天数之后的日期.
*
* @param num 相隔天数
* @return Date 日期
* @since 1.0
*/
public static Date nextDay(int num) {
Calendar curr = Calendar.getInstance();
curr.set(Calendar.DAY_OF_MONTH, curr.get(Calendar.DAY_OF_MONTH) + num);
return curr.getTime();
}
/**
* 获取当前日期指定月数之后的日期.
*
* @param num 间隔月数
* @return Date 日期
* @since 1.0
*/
public static Date nextMonth(int num) {
Calendar curr = Calendar.getInstance();
curr.set(Calendar.MONTH, curr.get(Calendar.MONTH) + num);
return curr.getTime();
}
/**
* 获取当前日期指定年数之后的日期.
*
* @param num 间隔年数
* @return Date 日期
* @since 1.0
*/
public static Date nextYear(int num) {
Calendar curr = Calendar.getInstance();
curr.set(Calendar.YEAR, curr.get(Calendar.YEAR) + num);
return curr.getTime();
}
/**
* 将 Date 日期转化为 Calendar 类型日期.
*
* @param date 给定的时间若为null则默认为当前时间
* @return Calendar Calendar对象
* @since 1.0
*/
public static Calendar getCalendar(Date date) {
Calendar calendar = Calendar.getInstance();
// calendar.setFirstDayOfWeek(Calendar.SUNDAY);//每周从周日开始
// calendar.setMinimalDaysInFirstWeek(1); // 设置每周最少为1天
if (date != null) {
calendar.setTime(date);
}
return calendar;
}
/**
* 计算两个日期之间相差天数.
*
* @param start 计算开始日期
* @param end 计算结束日期
* @return long 相隔天数
* @since 1.0
*/
public static long getDaysBetween(Date start, Date end) {
// 将指定日期转换为yyyy-MM-dd格式
start = DateUtils.parseDate(DateUtils.formatDate(start, DateUtils.DATE_FORMAT));
// 当前日期转换为yyyy-MM-dd格式
end = DateUtils.parseDate(DateUtils.formatDate(end, DateUtils.DATE_FORMAT));
long diff = 0;
if (start != null && end != null) {
diff = (end.getTime() - start.getTime()) / DateUtils.MILLISECONDS_PER_DAY;
}
return diff;
}
/**
* 计算两个日期之前相隔多少周.
*
* @param start 计算开始时间
* @param end 计算结束时间
* @return long 相隔周数,向下取整
* @since 1.0
*/
public static long getWeeksBetween(Date start, Date end) {
return getDaysBetween(start, end) / DateUtils.DAYS_PER_WEEK;
}
/**
* 获取与指定日期间隔给定天数的日期.
*
* @param specifiedDay 给定的字符串格式日期,支持的日期字符串格式包括"yyyy-MM-dd","yyyy-MM-dd HH:mm:ss",
* "yyyy-MM-dd HH:mm", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss",
* "yyyy/MM/dd HH:mm"
* @param num 间隔天数
* @return String 间隔指定天数之后的日期
* @since 1.0
*/
public static String getSpecifiedDayAfter(String specifiedDay, int num) {
Date specifiedDate = parseDate(specifiedDay);
Calendar c = Calendar.getInstance();
c.setTime(specifiedDate);
int day = c.get(Calendar.DATE);
c.set(Calendar.DATE, day + num);
String dayAfter = formatDate(c.getTime(), DateUtils.DATE_FORMAT);
return dayAfter;
}
/**
* 计算两个日期之前间隔的小时数.
*
* @param date1 结束时间
* @param date2 开始时间
* @return String 相差的小时数,保留一位小数
* @since 1.0
*/
public static String dateMinus(Date date1, Date date2) {
if (date1 == null || date2 == null) {
return "0";
}
Long r = date1.getTime() - date2.getTime();
DecimalFormat df = new DecimalFormat("#.0");
double result = r * 1.0 / DateUtils.MILLISECONDS_PER_HOUR;
return df.format(result);
}
/**
* 获取当前季度 .
*
* @return Integer 当前季度数
* @since 1.0
*/
public static Integer getCurrentSeason() {
Calendar calendar = Calendar.getInstance();
Integer month = calendar.get(Calendar.MONTH) + 1;
int season = 0;
if (month >= 1 && month <= 3) {
season = 1;
} else if (month >= 4 && month <= 6) {
season = 2;
} else if (month >= 7 && month <= 9) {
season = 3;
} else if (month >= 10 && month <= 12) {
season = 4;
}
return season;
}
/**
* 将以秒为单位的时间转换为其他单位.
*
* @param seconds 秒数
* @return String 例如 16分钟前、2小时前、3天前、4月前、5年前等
* @since 1.0
*/
public static String getIntervalBySeconds(long seconds) {
StringBuffer buffer = new StringBuffer();
if (seconds < SECONDS_PER_MINUTE) {
buffer.append(seconds).append("秒前");
} else if (seconds < SECONDS_PER_HOUR) {
buffer.append(seconds / SECONDS_PER_MINUTE).append("分钟前");
} else if (seconds < SECONDS_PER_DAY) {
buffer.append(seconds / SECONDS_PER_HOUR).append("小时前");
} else if (seconds < SECONDS_PER_MONTH) {
buffer.append(seconds / SECONDS_PER_DAY).append("天前");
} else if (seconds < SECONDS_PER_YEAR) {
buffer.append(seconds / SECONDS_PER_MONTH).append("月前");
} else {
buffer.append(seconds / DateUtils.SECONDS_PER_YEAR).append("年前");
}
return buffer.toString();
}
/**
* getNowTimeBefore(记录时间相当于目前多久之前)
*
* @param seconds 秒
* @return
* @throws @since 1.0
* @author rlliu
*/
public static String getNowTimeBefore(long seconds) {
StringBuffer buffer = new StringBuffer();
buffer.append("上传于");
if (seconds < 3600) {
buffer.append((long) Math.floor(seconds / 60.0)).append("分钟前");
} else if (seconds < 86400) {
buffer.append((long) Math.floor(seconds / 3600.0)).append("小时前");
} else if (seconds < 604800) {
buffer.append((long) Math.floor(seconds / 86400.0)).append("天前");
} else if (seconds < 2592000) {
buffer.append((long) Math.floor(seconds / 604800.0)).append("周前");
} else if (seconds < 31104000) {
buffer.append((long) Math.floor(seconds / 2592000.0)).append("月前");
} else {
buffer.append((long) Math.floor(seconds / 31104000.0)).append("年前");
}
return buffer.toString();
}
/**
* getMonthsBetween(查询两个日期相隔的月份)
*
* @param startDate 开始日期1 (格式yyyy-MM-dd)
* @param endDate 截止日期2 (格式yyyy-MM-dd)
* @return
*/
public static int getMonthsBetween(String startDate, String endDate) {
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(DateUtils.parseDate(startDate));
c2.setTime(DateUtils.parseDate(endDate));
int year = c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR);
int month = c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH);
return Math.abs(year * 12 + month);
}
/**
* getDayOfWeek(获取当前日期是星期几)
*
* @param dateStr 日期
* @return 星期几
*/
public static String getDayOfWeek(String dateStr) {
String[] weekOfDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
Date date = parseDate(dateStr);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int num = calendar.get(Calendar.DAY_OF_WEEK) - 1;
return weekOfDays[num];
}
/**
* sns 格式 如几秒前,几分钟前,几小时前,几天前,几个月前,几年后, ... 精细,类如某个明星几秒钟之前发表了一篇微博
*
* @param createTime
* @return
*/
public static String snsFormat(long createTime) {
long now = System.currentTimeMillis() / 1000;
long differ = now - createTime / 1000;
String dateStr = "";
if (differ <= 60) {
dateStr = "刚刚";
} else if (differ <= 3600) {
dateStr = (differ / 60) + "分钟前";
} else if (differ <= 3600 * 24) {
dateStr = (differ / 3600) + "小时前";
} else if (differ <= 3600 * 24 * 30) {
dateStr = (differ / (3600 * 24)) + "天前";
} else {
Date date = new Date(createTime);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
dateStr = sdf.format(date);
}
return dateStr;
}
/**
* 得到UTC时间类型为字符串格式为"yyyy-MM-dd HH:mm"
* 如果获取失败返回null
*
* @return
*/
public static String getUTCTimeStr() {
StringBuffer UTCTimeBuffer = new StringBuffer();
// 1、取得本地时间
Calendar cal = Calendar.getInstance();
// 2、取得时间偏移量
int zoneOffset = cal.get(java.util.Calendar.ZONE_OFFSET);
// 3、取得夏令时差
int dstOffset = cal.get(java.util.Calendar.DST_OFFSET);
// 4、从本地时间里扣除这些差量即可以取得UTC时间
cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset));
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
UTCTimeBuffer.append(year).append("-").append(month).append("-").append(day);
UTCTimeBuffer.append(" ").append(hour).append(":").append(minute);
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
sdf.parse(UTCTimeBuffer.toString());
return UTCTimeBuffer.toString();
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}

View File

@@ -0,0 +1,122 @@
package com.fx.server.util;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import sun.reflect.ConstructorAccessor;
import sun.reflect.FieldAccessor;
import sun.reflect.ReflectionFactory;
public class DynamicEnumUtils {
private static ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory();
private static void setFailsafeFieldValue(Field field, Object target, Object value) throws NoSuchFieldException,
IllegalAccessException {
// let's make the field accessible
field.setAccessible(true);
// next we change the modifier in the Field instance to
// not be final anymore, thus tricking reflection into
// letting us modify the static final field
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
int modifiers = modifiersField.getInt(field);
// blank out the final bit in the modifiers int
modifiers &= ~Modifier.FINAL;
modifiersField.setInt(field, modifiers);
FieldAccessor fa = reflectionFactory.newFieldAccessor(field, false);
fa.set(target, value);
}
private static void blankField(Class<?> enumClass, String fieldName) throws NoSuchFieldException,
IllegalAccessException {
for (Field field : Class.class.getDeclaredFields()) {
if (field.getName().contains(fieldName)) {
AccessibleObject.setAccessible(new Field[]{field}, true);
setFailsafeFieldValue(field, enumClass, null);
break;
}
}
}
private static void cleanEnumCache(Class<?> enumClass) throws NoSuchFieldException, IllegalAccessException {
blankField(enumClass, "enumConstantDirectory"); // Sun (Oracle?!?) JDK 1.5/6
blankField(enumClass, "enumConstants"); // IBM JDK
}
private static ConstructorAccessor getConstructorAccessor(Class<?> enumClass, Class<?>[] additionalParameterTypes)
throws NoSuchMethodException {
Class<?>[] parameterTypes = new Class[additionalParameterTypes.length + 2];
parameterTypes[0] = String.class;
parameterTypes[1] = int.class;
System.arraycopy(additionalParameterTypes, 0, parameterTypes, 2, additionalParameterTypes.length);
return reflectionFactory.newConstructorAccessor(enumClass.getDeclaredConstructor(parameterTypes));
}
private static Object makeEnum(Class<?> enumClass, String value, int ordinal, Class<?>[] additionalTypes,
Object[] additionalValues) throws Exception {
Object[] parms = new Object[additionalValues.length + 2];
parms[0] = value;
parms[1] = Integer.valueOf(ordinal);
System.arraycopy(additionalValues, 0, parms, 2, additionalValues.length);
return enumClass.cast(getConstructorAccessor(enumClass, additionalTypes).newInstance(parms));
}
/**
* Add an enum instance to the enum class given as argument
*
* @param <T> the type of the enum (implicit)
* @param enumType the class of the enum to be modified
* @param enumName the name of the new enum instance to be added to the class.
*/
@SuppressWarnings("unchecked")
public static <T extends Enum<?>> void addEnum(Class<T> enumType, String enumName, Class<?>[] additionalTypes, Object[] additionalValues) {
// 0. Sanity checks
if (!Enum.class.isAssignableFrom(enumType)) {
throw new RuntimeException("class " + enumType + " is not an instance of Enum");
}
// 1. Lookup "$VALUES" holder in enum class and get previous enum instances
Field valuesField = null;
Field[] fields = enumType.getDeclaredFields();
for (Field field : fields) {
if (field.getName().contains("$VALUES")) {
valuesField = field;
break;
}
}
AccessibleObject.setAccessible(new Field[]{valuesField}, true);
try {
// 2. Copy it
T[] previousValues = (T[]) valuesField.get(enumType);
List<T> values = new ArrayList<T>(Arrays.asList(previousValues));
// 3. build new enum
T newValue = (T) makeEnum(enumType, enumName, values.size(), additionalTypes, additionalValues);
// 4. add new value
values.add(newValue);
// 5. Set new values field
setFailsafeFieldValue(valuesField, null, values.toArray((T[]) Array.newInstance(enumType, 0)));
// 6. Clean enum cache
cleanEnumCache(enumType);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.util;
package com.fx.server.util;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

View File

@@ -1,6 +1,6 @@
package com.epri.fx.server.util;
package com.fx.server.util;
import com.epri.fx.server.context.BaseContextHandler;
import com.fx.server.context.BaseContextHandler;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.util;
package com.fx.server.util;
import java.util.LinkedHashMap;

View File

@@ -1,4 +1,4 @@
package com.epri.fx.server.util;
package com.fx.server.util;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;

View File

@@ -0,0 +1,149 @@
package com.fx.server.util;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
*
* @Description:spring工具类 方便在非spring管理环境中获取bean
*
* @param:
* @return:
* @auther: liwen
* @date: 2020/12/28 4:36 下午
*/
@Component
public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware
{
/** Spring应用上下文环境 */
private static ConfigurableListableBeanFactory beanFactory;
private static ApplicationContext applicationContext;
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
{
SpringUtils.beanFactory = beanFactory;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
SpringUtils.applicationContext = applicationContext;
}
/**
* 获取对象
*
* @param name
* @return Object 一个以所给名字注册的bean的实例
* @throws org.springframework.beans.BeansException
*
*/
@SuppressWarnings("unchecked")
public static <T> T getBean(String name) throws BeansException
{
return (T) beanFactory.getBean(name);
}
/**
* 获取类型为requiredType的对象
*
* @param clz
* @return
* @throws org.springframework.beans.BeansException
*
*/
public static <T> T getBean(Class<T> clz) throws BeansException
{
T result = (T) beanFactory.getBean(clz);
return result;
}
/**
* 如果BeanFactory包含一个与所给名称匹配的bean定义则返回true
*
* @param name
* @return boolean
*/
public static boolean containsBean(String name)
{
return beanFactory.containsBean(name);
}
/**
* 判断以给定名字注册的bean定义是一个singleton还是一个prototype。 如果与给定名字相应的bean定义没有被找到将会抛出一个异常NoSuchBeanDefinitionException
*
* @param name
* @return boolean
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException
{
return beanFactory.isSingleton(name);
}
/**
* @param name
* @return Class 注册对象的类型
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public static Class<?> getType(String name) throws NoSuchBeanDefinitionException
{
return beanFactory.getType(name);
}
/**
* 如果给定的bean名字在bean定义中有别名则返回这些别名
*
* @param name
* @return
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public static String[] getAliases(String name) throws NoSuchBeanDefinitionException
{
return beanFactory.getAliases(name);
}
/**
* 获取aop代理对象
*
* @param invoker
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T getAopProxy(T invoker)
{
return (T) AopContext.currentProxy();
}
/**
* 获取当前的环境配置无配置返回null
*
* @return 当前的环境配置
*/
public static String[] getActiveProfiles()
{
return applicationContext.getEnvironment().getActiveProfiles();
}
// /**
// * 获取当前的环境配置,当有多个环境配置时,只获取第一个
// *
// * @return 当前的环境配置
// */
// public static String getActiveProfile()
// {
// final String[] activeProfiles = getActiveProfiles();
// return StringUtils.isNotEmpty(activeProfiles) ? activeProfiles[0] : null;
// }
}

Some files were not shown because too many files have changed in this diff Show More