Commit 62a13034 by xiaolang850403

项目的结构调整

parent 8a0629e2
......@@ -126,6 +126,12 @@
<artifactId>freemarker</artifactId>
<version>2.3.29</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.auth0/java-jwt -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.3</version>
</dependency>
</dependencies>
......
......@@ -3,6 +3,7 @@ package com.asset;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.ComponentScan;
@MapperScan(value = "com.asset.mapper")
@SpringBootApplication
......
......@@ -47,7 +47,7 @@ public class Common {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sf.format(d);
}
//字符串转换成时间戳
//字符串时间日期转换成时间戳
public static long getStringToDate(String time) {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
......
package com.asset.common;
import com.asset.domain.Result;
import com.asset.enums.CodeEnum;
import com.asset.core.enums.CodeEnum;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
......
package com.asset.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/*
* @author xiaol
* @date 2019/12/26
*/
@Configuration
public class DruidConfig {
@ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource druid(){
return new DruidDataSource();
}
//配置Druid的监控
//配置一个管理后台的servlet
@Bean
public ServletRegistrationBean statViewServlet(){
ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*");
Map<String,Object> initParams = new HashMap<>();
initParams.put("loginUsername","admin");
initParams.put("loginPassword","123456");
initParams.put("allow","");
initParams.put("deny","192.168.0.51");
bean.setInitParameters(initParams);
return bean;
}
//配置一份web监控
public FilterRegistrationBean WebStatFilter(){
//通过FilterRegistrationBean实例设置优先级可以生效
//通过@WebFilter无效
FilterRegistrationBean bean = new FilterRegistrationBean<>();
bean.setFilter(new WebStatFilter());//注册自定义过滤器
Map<String,Object> initParams = new HashMap<>();
initParams.put("exclusions","*.js,*.css,/druid/*");
bean.setInitParameters(initParams);
bean.setUrlPatterns(Arrays.asList("/*"));
return bean;
}
}
......@@ -3,13 +3,8 @@ package com.asset.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
/**
* @Author: 落亦-
* @Date: 2019/11/23 19:16
*/
@Configuration
@ConditionalOnClass(value= {PaginationInterceptor.class})
public class MybatisPlusConfig {
......
......@@ -4,16 +4,14 @@ import com.asset.common.*;
import com.asset.domain.Result;
import com.asset.domain.User;
import com.asset.domain.system.*;
import com.asset.mapper.UserMapper;
import com.asset.service.UserService;
import com.asset.service.system.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.asset.enums.CodeEnum;
import com.asset.core.enums.CodeEnum;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......
......@@ -3,7 +3,7 @@ package com.asset.controller.admin;
import com.asset.common.ResultUtil;
import com.asset.domain.Result;
import com.asset.domain.system.FailLog;
import com.asset.enums.CodeEnum;
import com.asset.core.enums.CodeEnum;
import com.asset.service.system.FailLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -3,7 +3,7 @@ package com.asset.controller.admin;
import com.asset.common.ResultUtil;
import com.asset.domain.Result;
import com.asset.domain.system.FailReason;
import com.asset.enums.CodeEnum;
import com.asset.core.enums.CodeEnum;
import com.asset.service.system.FailReasonService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -3,7 +3,7 @@ package com.asset.controller.system;
import com.asset.common.ResultUtil;
import com.asset.domain.Result;
import com.asset.domain.system.Area;
import com.asset.enums.CodeEnum;
import com.asset.core.enums.CodeEnum;
import com.asset.service.system.AreaService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -4,7 +4,7 @@ import com.asset.common.Common;
import com.asset.common.ResultUtil;
import com.asset.domain.Result;
import com.asset.domain.system.Captcha;
import com.asset.enums.CodeEnum;
import com.asset.core.enums.CodeEnum;
import com.asset.service.system.CaptchaService;
import com.wf.captcha.SpecCaptcha;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -3,7 +3,7 @@ package com.asset.controller.system;
import com.asset.common.ResultUtil;
import com.asset.domain.Result;
import com.asset.domain.system.Job;
import com.asset.enums.CodeEnum;
import com.asset.core.enums.CodeEnum;
import com.asset.service.system.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
......
......@@ -5,7 +5,7 @@ import com.asset.common.ResultUtil;
import com.asset.common.Sms;
import com.asset.domain.Result;
import com.asset.domain.system.Code;
import com.asset.enums.CodeEnum;
import com.asset.core.enums.CodeEnum;
import com.asset.service.system.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
......
......@@ -4,7 +4,7 @@ import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.asset.common.ResultUtil;
import com.asset.domain.Result;
import com.asset.enums.CodeEnum;
import com.asset.core.enums.CodeEnum;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
......
package com.asset.enums;
package com.asset.core.enums;
public enum CodeEnum {
......
package com.asset.enums;
package com.asset.core.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;
......
package com.asset.enums;
package com.asset.core.enums;
public enum StatusEnum {
ON(0,"正常"),
......
package com.asset.core.filter;
import com.asset.common.Common;
import com.asset.core.jwt.TokenUtil;
import com.asset.domain.User;
import com.asset.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
@Component
public class TokenInterceptor implements HandlerInterceptor {
@Autowired
UserService userService;
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {
if (request.getMethod().equals("OPTIONS")) {
response.setStatus(HttpServletResponse.SC_OK);
return true;
}
response.setCharacterEncoding("utf-8");
String token = request.getHeader("token");
if (token != null) {
// 拦截验证校验token是否正确,并验证token的有效期
boolean result = TokenUtil.verify(token);
if (result) {
System.out.println("通过拦截器");
return true;
}
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
try {
//JSONObject json = new JSONObject();
//json.put("msg", "token失效");
//json.put("code", "10007");
//response.getWriter().append(json.toJSONString());
System.out.println("认证失败,未通过拦截器,需重新生成token");
//判断用户表记录的token的有效期是否过期
Object mobile = request.getSession().getAttribute("mobile");
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("mobile",mobile);
User user = userService.getOne(queryWrapper);
//比较数据库里token的refexpire的最长期限
if(Common.getStringToDate(user.getLoginTime())+Long.valueOf(user.getRefexpire()) > System.currentTimeMillis()){
System.out.println("刷新token,生成新的token");
token = TokenUtil.sign(mobile.toString());
response.setHeader("token",token);
//手动调用刷新token接口时就需要下面的更新token代码,自动更新就不需要
User user1 = new User();
user1.setToken(token);
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("id",user.getId());
userService.update(user1,userQueryWrapper);
return true;
}else{ //数据表里的长效期的时间过期了,则要重新登录
System.out.println("token超过了最长时效,请重新登录");
JSONObject json = new JSONObject();
json.put("msg", "token超过了最长时效,请重新登录");
json.put("code", "10007");
response.getWriter().append(json.toJSONString());
return false;
}
} catch (Exception e) {
e.printStackTrace();
response.sendError(500);
return false;
}
}
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response,
Object object, ModelAndView mv) throws Exception {
}
}
......@@ -117,7 +117,7 @@ public class User implements Serializable {
private String expertRange;
@JsonFormat(pattern = "yyyy-MM-dd")
private Date loginTime;
private String loginTime;
//@JsonFormat(pattern = "yyyy-MM-dd", timezone="GMT+8")
//private Date yy;
......@@ -133,4 +133,8 @@ public class User implements Serializable {
@TableField(exist = false)
private String reason;
private String token;
private String refexpire;
}
......@@ -29,7 +29,7 @@ pagehelper:
#日志
logging:
file:
path: /Users/langxiao/Code/java/assets/logs
path: /Users/langxiao/Code/java/expert/logs
name: my.log.%d{yyyy-MM-dd}.log
max-history: 30
max-size: 10MB
......
spring.profiles.active = dev
//设置登录过期时间
refexpire=604800000
#图片存储目录
filePath=D:/phpStudy/WWW/images/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment