重构项目结构

This commit is contained in:
启航 2024-02-26 19:15:34 +08:00
parent 70828cc922
commit cf04d44196
159 changed files with 12328 additions and 4148 deletions

View File

@ -15,7 +15,7 @@ public class Api
{
public static void main( String[] args )
{
System.out.println( "Hello World! Api" );
System.out.println( "Hello api! " );
SpringApplication.run(Api.class, args);
}

View File

@ -20,7 +20,7 @@ public class TokenFilter implements GlobalFilter, Ordered {
System.out.println("Token:"+token);
String url = exchange.getRequest().getURI().getPath();
System.out.println("intercept " + url);
if(url.equals("/api/oms-api/login")){
if(url.equals("/api/sys-api/login")){
// 登录页面 放行
return chain.filter(exchange);
}

View File

@ -26,10 +26,10 @@ spring:
- Path=/api/tao-api/**
filters:
- StripPrefix=2
- id: oms_api_route
uri: lb://oms-api
- id: sys_api_route
uri: lb://sys-api
predicates:
- Path=/api/oms-api/**
- Path=/api/sys-api/**
filters:
- StripPrefix=2
# - TokenFilter

38
core/common/.gitignore vendored Normal file
View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

73
core/common/pom.xml Normal file
View File

@ -0,0 +1,73 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.qihang</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.qihang</groupId>
<artifactId>common</artifactId>
<packaging>jar</packaging>
<name>common</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>3.0.2</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- Token生成与解析-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>${jwt.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>${jwt.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>${jwt.version}</version>
<scope>runtime</scope>
</dependency>
<!-- 解析客户端操作系统、浏览器等 -->
<dependency>
<groupId>eu.bitwalker</groupId>
<artifactId>UserAgentUtils</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>9.1.0</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-tomcat</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- <version>3.0.2</version>-->
<!-- </dependency>-->
</dependencies>
</project>

View File

@ -0,0 +1,13 @@
package com.qihang.common;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

View File

@ -1,6 +1,8 @@
package com.qihang.oms.api.common;
package com.qihang.common.common;
import com.qihang.common.enums.HttpStatus;
import java.util.HashMap;
import java.util.Objects;

View File

@ -1,7 +1,6 @@
package com.qihang.oms.api.common;
package com.qihang.common.common;
import com.qihang.oms.api.utils.StringUtils;
import com.qihang.common.utils.StringUtils;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.common;
package com.qihang.common.common;
import java.util.HashMap;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.common;
package com.qihang.common.common;
/**
* 业务异常

View File

@ -0,0 +1,220 @@
//package com.qihang.common.common;
//
//import com.qihang.common.constant.Convert;
//import com.qihang.common.constant.Constants;
//import com.qihang.common.utils.StringUtils;
//import jakarta.servlet.ServletRequest;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import jakarta.servlet.http.HttpSession;
//import org.springframework.web.context.request.RequestAttributes;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import java.io.IOException;
//import java.io.UnsupportedEncodingException;
//import java.net.URLDecoder;
//import java.net.URLEncoder;
//import java.util.Collections;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 客户端工具类
// *
// * @author qihang
// */
//public class ServletUtils
//{
// /**
// * 获取String参数
// */
// public static String getParameter(String name)
// {
// return getRequest().getParameter(name);
// }
//
// /**
// * 获取String参数
// */
// public static String getParameter(String name, String defaultValue)
// {
// return Convert.toStr(getRequest().getParameter(name), defaultValue);
// }
//
// /**
// * 获取Integer参数
// */
// public static Integer getParameterToInt(String name)
// {
// return Convert.toInt(getRequest().getParameter(name));
// }
//
// /**
// * 获取Integer参数
// */
// public static Integer getParameterToInt(String name, Integer defaultValue)
// {
// return Convert.toInt(getRequest().getParameter(name), defaultValue);
// }
//
// /**
// * 获取Boolean参数
// */
// public static Boolean getParameterToBool(String name)
// {
// return Convert.toBool(getRequest().getParameter(name));
// }
//
// /**
// * 获取Boolean参数
// */
// public static Boolean getParameterToBool(String name, Boolean defaultValue)
// {
// return Convert.toBool(getRequest().getParameter(name), defaultValue);
// }
//
// /**
// * 获得所有请求参数
// *
// * @param request 请求对象{@link ServletRequest}
// * @return Map
// */
// public static Map<String, String[]> getParams(ServletRequest request)
// {
// final Map<String, String[]> map = request.getParameterMap();
// return Collections.unmodifiableMap(map);
// }
//
// /**
// * 获得所有请求参数
// *
// * @param request 请求对象{@link ServletRequest}
// * @return Map
// */
// public static Map<String, String> getParamMap(ServletRequest request)
// {
// Map<String, String> params = new HashMap<>();
// for (Map.Entry<String, String[]> entry : getParams(request).entrySet())
// {
// params.put(entry.getKey(), StringUtils.join(entry.getValue(), ","));
// }
// return params;
// }
//
// /**
// * 获取request
// */
// public static HttpServletRequest getRequest()
// {
// return getRequestAttributes().getRequest();
// }
//
// /**
// * 获取response
// */
// public static HttpServletResponse getResponse()
// {
// return getRequestAttributes().getResponse();
// }
//
// /**
// * 获取session
// */
// public static HttpSession getSession()
// {
// return getRequest().getSession();
// }
//
// public static ServletRequestAttributes getRequestAttributes()
// {
// RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
// return (ServletRequestAttributes) attributes;
// }
//
// /**
// * 将字符串渲染到客户端
// *
// * @param response 渲染对象
// * @param string 待渲染的字符串
// */
// public static void renderString(HttpServletResponse response, String string)
// {
// try
// {
// response.setStatus(200);
// response.setContentType("application/json");
// response.setCharacterEncoding("utf-8");
// response.getWriter().print(string);
// }
// catch (IOException e)
// {
// e.printStackTrace();
// }
// }
//
// /**
// * 是否是Ajax异步请求
// *
// * @param request
// */
// public static boolean isAjaxRequest(HttpServletRequest request)
// {
// String accept = request.getHeader("accept");
// if (accept != null && accept.contains("application/json"))
// {
// return true;
// }
//
// String xRequestedWith = request.getHeader("X-Requested-With");
// if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
// {
// return true;
// }
//
// String uri = request.getRequestURI();
// if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml"))
// {
// return true;
// }
//
// String ajax = request.getParameter("__ajax");
// return StringUtils.inStringIgnoreCase(ajax, "json", "xml");
// }
//
// /**
// * 内容编码
// *
// * @param str 内容
// * @return 编码后的内容
// */
// public static String urlEncode(String str)
// {
// try
// {
// return URLEncoder.encode(str, Constants.UTF8);
// }
// catch (UnsupportedEncodingException e)
// {
// return StringUtils.EMPTY;
// }
// }
//
// /**
// * 内容解码
// *
// * @param str 内容
// * @return 解码后的内容
// */
// public static String urlDecode(String str)
// {
// try
// {
// return URLDecoder.decode(str, Constants.UTF8);
// }
// catch (UnsupportedEncodingException e)
// {
// return StringUtils.EMPTY;
// }
// }
//}

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.utils;
package com.qihang.common.config;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.config;
package com.qihang.common.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundSetOperations;

View File

@ -1,7 +1,6 @@
package com.qihang.oms.api.config;
package com.qihang.common.config;
import com.qihang.oms.api.utils.FastJson2JsonRedisSerializer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.constant;
package com.qihang.common.constant;
/**
* 缓存的key 常量

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.constant;
package com.qihang.common.constant;
import io.jsonwebtoken.Claims;

View File

@ -1,6 +1,7 @@
package com.qihang.oms.api.common;
package com.qihang.common.constant;
import com.qihang.oms.api.utils.StringUtils;
import com.qihang.common.common.CharsetKit;
import com.qihang.common.utils.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import java.math.BigDecimal;

View File

@ -1,7 +1,7 @@
package com.qihang.oms.api.common;
package com.qihang.common.constant;
import com.qihang.oms.api.utils.StringUtils;
import com.qihang.common.utils.StringUtils;
/**
* 字符串格式化

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.common;
package com.qihang.common.constant;
/**
* 用户常量信息

View File

@ -1,8 +1,8 @@
package com.qihang.oms.api.common;
package com.qihang.common.enums;//package com.qihang.oms.api.common;
/**
* 返回状态码
*
*
* @author qihang
*/
public class HttpStatus

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.enums;
package com.qihang.common.enums;
/**
* 用户状态

View File

@ -1,12 +1,12 @@
package com.qihang.oms.api.common;
package com.qihang.common.exception;
import com.qihang.oms.api.utils.MessageUtils;
import com.qihang.oms.api.utils.StringUtils;
import com.qihang.common.utils.MessageUtils;
import com.qihang.common.utils.StringUtils;
/**
* 基础异常
*
*
* @author qihang
*/
public class BaseException extends RuntimeException

View File

@ -1,10 +1,10 @@
package com.qihang.oms.api.common;
package com.qihang.common.exception;
/**
* 用户信息异常类
*
*
* @author qihang
*/
public class UserException extends BaseException

View File

@ -1,8 +1,8 @@
package com.qihang.oms.api.common;
package com.qihang.common.exception;
/**
* 用户不存在异常类
*
*
* @author qihang
*/
public class UserNotExistsException extends UserException

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.utils;
package com.qihang.common.utils;
import org.apache.commons.lang3.time.DateFormatUtils;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.utils;
package com.qihang.common.utils;
/**
* ID生成器工具类

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.utils;
package com.qihang.common.utils;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.utils;
package com.qihang.common.utils;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeansException;

View File

@ -1,9 +1,7 @@
package com.qihang.oms.api.utils;
package com.qihang.common.utils;
import com.qihang.oms.api.constant.Constants;
import com.qihang.oms.api.common.StrFormatter;
import org.springframework.util.AntPathMatcher;
import com.qihang.common.constant.Constants;
import com.qihang.common.constant.StrFormatter;
import java.util.*;
@ -522,21 +520,21 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param strs 需要检查的字符串数组
* @return 是否匹配
*/
public static boolean matches(String str, List<String> strs)
{
if (isEmpty(str) || isEmpty(strs))
{
return false;
}
for (String pattern : strs)
{
if (isMatch(pattern, str))
{
return true;
}
}
return false;
}
// public static boolean matches(String str, List<String> strs)
// {
// if (isEmpty(str) || isEmpty(strs))
// {
// return false;
// }
// for (String pattern : strs)
// {
// if (isMatch(pattern, str))
// {
// return true;
// }
// }
// return false;
// }
/**
* 判断url是否与规则配置:
@ -548,11 +546,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param url 需要匹配的url
* @return
*/
public static boolean isMatch(String pattern, String url)
{
AntPathMatcher matcher = new AntPathMatcher();
return matcher.match(pattern, url);
}
// public static boolean isMatch(String pattern, String url)
// {
// AntPathMatcher matcher = new AntPathMatcher();
// return matcher.match(pattern, url);
// }
@SuppressWarnings("unchecked")
public static <T> T cast(Object obj)

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.utils;
package com.qihang.common.utils;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.utils.http;
package com.qihang.common.utils.http;
import jakarta.servlet.ServletRequest;
import org.apache.commons.lang3.exception.ExceptionUtils;

View File

@ -1,7 +1,7 @@
package com.qihang.oms.api.utils.http;
package com.qihang.common.utils.http;
import com.qihang.oms.api.constant.Constants;
import com.qihang.oms.api.utils.StringUtils;
import com.qihang.common.constant.Constants;
import com.qihang.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -0,0 +1,54 @@
//package com.qihang.common.utils.ip;
//
//import com.alibaba.fastjson2.JSON;
//import com.alibaba.fastjson2.JSONObject;
//import com.qihang.common.constant.Constants;
//import com.qihang.common.utils.http.HttpUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.util.StringUtils;
//
///**
// * 获取地址类
// *
// * @author qihang
// */
//public class AddressUtils
//{
// private static final Logger log = LoggerFactory.getLogger(AddressUtils.class);
//
// // IP地址查询
// public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp";
//
// // 未知地址
// public static final String UNKNOWN = "XX XX";
//
// public static String getRealAddressByIP(String ip)
// {
// // 内网不查询
// if (IpUtils.internalIp(ip))
// {
// return "内网IP";
// }
//
// try
// {
// String rspStr = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK);
// if (StringUtils.isEmpty(rspStr))
// {
// log.error("获取地理位置异常 {}", ip);
// return UNKNOWN;
// }
// JSONObject obj = JSON.parseObject(rspStr);
// String region = obj.getString("pro");
// String city = obj.getString("city");
// return String.format("%s %s", region, city);
// }
// catch (Exception e)
// {
// log.error("获取地理位置异常 {}", ip);
// }
//
// return UNKNOWN;
// }
//}

View File

@ -0,0 +1,384 @@
//package com.qihang.common.utils.ip;
//
//
//import com.qihang.common.common.ServletUtils;
//import com.qihang.common.utils.StringUtils;
//import jakarta.servlet.http.HttpServletRequest;
//
//import java.net.InetAddress;
//import java.net.UnknownHostException;
//
///**
// * 获取IP方法
// *
// * @author qihang
// */
//public class IpUtils
//{
// public final static String REGX_0_255 = "(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)";
// // 匹配 ip
// public final static String REGX_IP = "((" + REGX_0_255 + "\\.){3}" + REGX_0_255 + ")";
// public final static String REGX_IP_WILDCARD = "(((\\*\\.){3}\\*)|(" + REGX_0_255 + "(\\.\\*){3})|(" + REGX_0_255 + "\\." + REGX_0_255 + ")(\\.\\*){2}" + "|((" + REGX_0_255 + "\\.){3}\\*))";
// // 匹配网段
// public final static String REGX_IP_SEG = "(" + REGX_IP + "\\-" + REGX_IP + ")";
//
// /**
// * 获取客户端IP
// *
// * @return IP地址
// */
// public static String getIpAddr()
// {
// return getIpAddr(ServletUtils.getRequest());
// }
//
// /**
// * 获取客户端IP
// *
// * @param request 请求对象
// * @return IP地址
// */
// public static String getIpAddr(HttpServletRequest request)
// {
// if (request == null)
// {
// return "unknown";
// }
// String ip = request.getHeader("x-forwarded-for");
// if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
// {
// ip = request.getHeader("Proxy-Client-IP");
// }
// if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
// {
// ip = request.getHeader("X-Forwarded-For");
// }
// if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
// {
// ip = request.getHeader("WL-Proxy-Client-IP");
// }
// if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
// {
// ip = request.getHeader("X-Real-IP");
// }
//
// if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
// {
// ip = request.getRemoteAddr();
// }
//
// return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : getMultistageReverseProxyIp(ip);
// }
//
// /**
// * 检查是否为内部IP地址
// *
// * @param ip IP地址
// * @return 结果
// */
// public static boolean internalIp(String ip)
// {
// byte[] addr = textToNumericFormatV4(ip);
// return internalIp(addr) || "127.0.0.1".equals(ip);
// }
//
// /**
// * 检查是否为内部IP地址
// *
// * @param addr byte地址
// * @return 结果
// */
// private static boolean internalIp(byte[] addr)
// {
// if (StringUtils.isNull(addr) || addr.length < 2)
// {
// return true;
// }
// final byte b0 = addr[0];
// final byte b1 = addr[1];
// // 10.x.x.x/8
// final byte SECTION_1 = 0x0A;
// // 172.16.x.x/12
// final byte SECTION_2 = (byte) 0xAC;
// final byte SECTION_3 = (byte) 0x10;
// final byte SECTION_4 = (byte) 0x1F;
// // 192.168.x.x/16
// final byte SECTION_5 = (byte) 0xC0;
// final byte SECTION_6 = (byte) 0xA8;
// switch (b0)
// {
// case SECTION_1:
// return true;
// case SECTION_2:
// if (b1 >= SECTION_3 && b1 <= SECTION_4)
// {
// return true;
// }
// case SECTION_5:
// switch (b1)
// {
// case SECTION_6:
// return true;
// }
// default:
// return false;
// }
// }
//
// /**
// * 将IPv4地址转换成字节
// *
// * @param text IPv4地址
// * @return byte 字节
// */
// public static byte[] textToNumericFormatV4(String text)
// {
// if (text.length() == 0)
// {
// return null;
// }
//
// byte[] bytes = new byte[4];
// String[] elements = text.split("\\.", -1);
// try
// {
// long l;
// int i;
// switch (elements.length)
// {
// case 1:
// l = Long.parseLong(elements[0]);
// if ((l < 0L) || (l > 4294967295L))
// {
// return null;
// }
// bytes[0] = (byte) (int) (l >> 24 & 0xFF);
// bytes[1] = (byte) (int) ((l & 0xFFFFFF) >> 16 & 0xFF);
// bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
// bytes[3] = (byte) (int) (l & 0xFF);
// break;
// case 2:
// l = Integer.parseInt(elements[0]);
// if ((l < 0L) || (l > 255L))
// {
// return null;
// }
// bytes[0] = (byte) (int) (l & 0xFF);
// l = Integer.parseInt(elements[1]);
// if ((l < 0L) || (l > 16777215L))
// {
// return null;
// }
// bytes[1] = (byte) (int) (l >> 16 & 0xFF);
// bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
// bytes[3] = (byte) (int) (l & 0xFF);
// break;
// case 3:
// for (i = 0; i < 2; ++i)
// {
// l = Integer.parseInt(elements[i]);
// if ((l < 0L) || (l > 255L))
// {
// return null;
// }
// bytes[i] = (byte) (int) (l & 0xFF);
// }
// l = Integer.parseInt(elements[2]);
// if ((l < 0L) || (l > 65535L))
// {
// return null;
// }
// bytes[2] = (byte) (int) (l >> 8 & 0xFF);
// bytes[3] = (byte) (int) (l & 0xFF);
// break;
// case 4:
// for (i = 0; i < 4; ++i)
// {
// l = Integer.parseInt(elements[i]);
// if ((l < 0L) || (l > 255L))
// {
// return null;
// }
// bytes[i] = (byte) (int) (l & 0xFF);
// }
// break;
// default:
// return null;
// }
// }
// catch (NumberFormatException e)
// {
// return null;
// }
// return bytes;
// }
//
// /**
// * 获取IP地址
// *
// * @return 本地IP地址
// */
// public static String getHostIp()
// {
// try
// {
// return InetAddress.getLocalHost().getHostAddress();
// }
// catch (UnknownHostException e)
// {
// }
// return "127.0.0.1";
// }
//
// /**
// * 获取主机名
// *
// * @return 本地主机名
// */
// public static String getHostName()
// {
// try
// {
// return InetAddress.getLocalHost().getHostName();
// }
// catch (UnknownHostException e)
// {
// }
// return "未知";
// }
//
// /**
// * 从多级反向代理中获得第一个非unknown IP地址
// *
// * @param ip 获得的IP地址
// * @return 第一个非unknown IP地址
// */
// public static String getMultistageReverseProxyIp(String ip)
// {
// // 多级反向代理检测
// if (ip != null && ip.indexOf(",") > 0)
// {
// final String[] ips = ip.trim().split(",");
// for (String subIp : ips)
// {
// if (false == isUnknown(subIp))
// {
// ip = subIp;
// break;
// }
// }
// }
// return StringUtils.substring(ip, 0, 255);
// }
//
// /**
// * 检测给定字符串是否为未知多用于检测HTTP请求相关
// *
// * @param checkString 被检测的字符串
// * @return 是否未知
// */
// public static boolean isUnknown(String checkString)
// {
// return StringUtils.isBlank(checkString) || "unknown".equalsIgnoreCase(checkString);
// }
//
// /**
// * 是否为IP
// */
// public static boolean isIP(String ip)
// {
// return StringUtils.isNotBlank(ip) && ip.matches(REGX_IP);
// }
//
// /**
// * 是否为IP *为间隔的通配符地址
// */
// public static boolean isIpWildCard(String ip)
// {
// return StringUtils.isNotBlank(ip) && ip.matches(REGX_IP_WILDCARD);
// }
//
// /**
// * 检测参数是否在ip通配符里
// */
// public static boolean ipIsInWildCardNoCheck(String ipWildCard, String ip)
// {
// String[] s1 = ipWildCard.split("\\.");
// String[] s2 = ip.split("\\.");
// boolean isMatchedSeg = true;
// for (int i = 0; i < s1.length && !s1[i].equals("*"); i++)
// {
// if (!s1[i].equals(s2[i]))
// {
// isMatchedSeg = false;
// break;
// }
// }
// return isMatchedSeg;
// }
//
// /**
// * 是否为特定格式如:10.10.10.1-10.10.10.99的ip段字符串
// */
// public static boolean isIPSegment(String ipSeg)
// {
// return StringUtils.isNotBlank(ipSeg) && ipSeg.matches(REGX_IP_SEG);
// }
//
// /**
// * 判断ip是否在指定网段中
// */
// public static boolean ipIsInNetNoCheck(String iparea, String ip)
// {
// int idx = iparea.indexOf('-');
// String[] sips = iparea.substring(0, idx).split("\\.");
// String[] sipe = iparea.substring(idx + 1).split("\\.");
// String[] sipt = ip.split("\\.");
// long ips = 0L, ipe = 0L, ipt = 0L;
// for (int i = 0; i < 4; ++i)
// {
// ips = ips << 8 | Integer.parseInt(sips[i]);
// ipe = ipe << 8 | Integer.parseInt(sipe[i]);
// ipt = ipt << 8 | Integer.parseInt(sipt[i]);
// }
// if (ips > ipe)
// {
// long t = ips;
// ips = ipe;
// ipe = t;
// }
// return ips <= ipt && ipt <= ipe;
// }
//
// /**
// * 校验ip是否符合过滤串规则
// *
// * @param filter 过滤IP列表,支持后缀'*'通配,支持网段如:`10.10.10.1-10.10.10.99`
// * @param ip 校验IP地址
// * @return boolean 结果
// */
// public static boolean isMatchedIp(String filter, String ip)
// {
// if (StringUtils.isEmpty(filter) || StringUtils.isEmpty(ip))
// {
// return false;
// }
// String[] ips = filter.split(";");
// for (String iStr : ips)
// {
// if (isIP(iStr) && iStr.equals(ip))
// {
// return true;
// }
// else if (isIpWildCard(iStr) && ipIsInWildCardNoCheck(iStr, ip))
// {
// return true;
// }
// else if (isIPSegment(iStr) && ipIsInNetNoCheck(iStr, ip))
// {
// return true;
// }
// }
// return false;
// }
//}

27
core/pom.xml Normal file
View File

@ -0,0 +1,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.qihang</groupId>
<artifactId>qihang-oms</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.qihang</groupId>
<artifactId>core</artifactId>
<packaging>pom</packaging>
<name>core</name>
<url>http://maven.apache.org</url>
<modules>
<module>security</module>
<module>common</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
</dependencies>
</project>

38
core/security/.gitignore vendored Normal file
View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

78
core/security/pom.xml Normal file
View File

@ -0,0 +1,78 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.qihang</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.qihang</groupId>
<artifactId>security</artifactId>
<packaging>jar</packaging>
<name>security</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>3.0.2</spring-boot.version>
<jwt.version>0.11.5</jwt.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- Token生成与解析-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>${jwt.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>${jwt.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>${jwt.version}</version>
<scope>runtime</scope>
</dependency>
<!-- 解析客户端操作系统、浏览器等 -->
<dependency>
<groupId>eu.bitwalker</groupId>
<artifactId>UserAgentUtils</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>9.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.qihang</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,8 @@
package com.qihang.security;
public class App {
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

View File

@ -1,10 +1,10 @@
package com.qihang.oms.api.security;
package com.qihang.security;
import org.springframework.security.core.Authentication;
/**
* 身份验证信息
*
*
* @author qihang
*/
public class AuthenticationContextHolder

View File

@ -1,6 +1,8 @@
package com.qihang.oms.api.security;
package com.qihang.security;
import com.alibaba.fastjson2.JSON;
import com.qihang.common.common.R;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@ -10,7 +12,7 @@ import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import com.qihang.oms.api.common.R;
import java.io.IOException;
import java.io.PrintWriter;

View File

@ -1,10 +1,8 @@
package com.qihang.oms.api.security;
package com.qihang.security;
import com.alibaba.fastjson2.JSON;
import com.qihang.oms.api.common.R;
import com.qihang.oms.api.domain.LoginUser;
import com.qihang.oms.api.service.TokenService;
import com.qihang.common.common.R;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;

View File

@ -1,7 +1,7 @@
package com.qihang.oms.api.domain;
package com.qihang.security;
import com.alibaba.fastjson2.annotation.JSONField;
import com.qihang.oms.api.domain.SysUser;
import com.qihang.security.entity.SysUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.security;
package com.qihang.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

View File

@ -1,14 +1,13 @@
package com.qihang.oms.api.service;
package com.qihang.security;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.qihang.oms.api.config.RedisCache;
import com.qihang.oms.api.constant.CacheConstants;
import com.qihang.oms.api.constant.Constants;
import com.qihang.oms.api.domain.LoginUser;
import com.qihang.oms.api.utils.IdUtils;
import com.qihang.oms.api.utils.ServletUtils;
import com.qihang.oms.api.utils.ip.AddressUtils;
import com.qihang.oms.api.utils.ip.IpUtils;
import com.qihang.common.config.RedisCache;
import com.qihang.common.constant.CacheConstants;
import com.qihang.common.constant.Constants;
import com.qihang.common.utils.IdUtils;
import com.qihang.common.utils.StringUtils;
import com.qihang.security.utils.AddressUtils;
import com.qihang.security.utils.IpUtils;
import com.qihang.security.utils.ServletUtils;
import eu.bitwalker.useragentutils.UserAgent;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

View File

@ -1,13 +1,13 @@
package com.qihang.oms.api.security;
package com.qihang.security;
import com.qihang.oms.api.common.ServiceException;
import com.qihang.oms.api.domain.LoginUser;
import com.qihang.oms.api.domain.SysUser;
import com.qihang.oms.api.enums.UserStatus;
import com.qihang.oms.api.service.ISysUserService;
import com.qihang.oms.api.utils.MessageUtils;
import com.qihang.oms.api.utils.StringUtils;
import com.qihang.common.common.ServiceException;
import com.qihang.common.enums.UserStatus;
import com.qihang.common.utils.MessageUtils;
import com.qihang.common.utils.StringUtils;
import com.qihang.security.entity.SysUser;
import com.qihang.security.service.ISysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,8 +1,10 @@
package com.qihang.oms.api.common;
package com.qihang.security;
import com.qihang.common.exception.UserException;
/**
* 用户密码不正确或不符合规范异常类
*
*
* @author qihang
*/
public class UserPasswordNotMatchException extends UserException

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.domain;
package com.qihang.security.entity;
import java.util.Date;
@ -8,7 +8,7 @@ import java.util.Date;
*
* @author qihang
*/
public class SysUser extends BaseEntity
public class SysUser
{
private static final long serialVersionUID = 1L;
@ -60,7 +60,18 @@ public class SysUser extends BaseEntity
/** 角色ID */
private Long roleId;
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 更新者 */
private String updateBy;
/** 更新时间 */
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
/** 创建者 */
private String createBy;
private String remark;
public SysUser()
{
@ -246,4 +257,43 @@ public class SysUser extends BaseEntity
this.roleId = roleId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}

View File

@ -0,0 +1,130 @@
//package com.qihang.security.mapper;
//
//import com.qihang.security.entity.SysUser;
//import org.apache.ibatis.annotations.Mapper;
//import org.apache.ibatis.annotations.Param;
//
//import java.util.List;
//
///**
// * 用户表 数据层
// *
// * @author qihang
// */
//@Mapper
//public interface SysUserMapper
//{
// /**
// * 根据条件分页查询用户列表
// *
// * @param sysUser 用户信息
// * @return 用户信息集合信息
// */
// public List<SysUser> selectUserList(SysUser sysUser);
//
// /**
// * 根据条件分页查询已配用户角色列表
// *
// * @param user 用户信息
// * @return 用户信息集合信息
// */
// public List<SysUser> selectAllocatedList(SysUser user);
//
// /**
// * 根据条件分页查询未分配用户角色列表
// *
// * @param user 用户信息
// * @return 用户信息集合信息
// */
// public List<SysUser> selectUnallocatedList(SysUser user);
//
// /**
// * 通过用户名查询用户
// *
// * @param userName 用户名
// * @return 用户对象信息
// */
// public SysUser selectUserByUserName(String userName);
//
// /**
// * 通过用户ID查询用户
// *
// * @param userId 用户ID
// * @return 用户对象信息
// */
// public SysUser selectUserById(Long userId);
//
// /**
// * 新增用户信息
// *
// * @param user 用户信息
// * @return 结果
// */
// public int insertUser(SysUser user);
//
// /**
// * 修改用户信息
// *
// * @param user 用户信息
// * @return 结果
// */
// public int updateUser(SysUser user);
//
// /**
// * 修改用户头像
// *
// * @param userName 用户名
// * @param avatar 头像地址
// * @return 结果
// */
// public int updateUserAvatar(@Param("userName") String userName, @Param("avatar") String avatar);
//
// /**
// * 重置用户密码
// *
// * @param userName 用户名
// * @param password 密码
// * @return 结果
// */
// public int resetUserPwd(@Param("userName") String userName, @Param("password") String password);
//
// /**
// * 通过用户ID删除用户
// *
// * @param userId 用户ID
// * @return 结果
// */
// public int deleteUserById(Long userId);
//
// /**
// * 批量删除用户信息
// *
// * @param userIds 需要删除的用户ID
// * @return 结果
// */
// public int deleteUserByIds(Long[] userIds);
//
// /**
// * 校验用户名称是否唯一
// *
// * @param userName 用户名称
// * @return 结果
// */
// public SysUser checkUserNameUnique(String userName);
//
// /**
// * 校验手机号码是否唯一
// *
// * @param phonenumber 手机号码
// * @return 结果
// */
// public SysUser checkPhoneUnique(String phonenumber);
//
// /**
// * 校验email是否唯一
// *
// * @param email 用户邮箱
// * @return 结果
// */
// public SysUser checkEmailUnique(String email);
//}

View File

@ -1,19 +1,20 @@
package com.qihang.oms.api.service;
package com.qihang.security.service;
import com.qihang.oms.api.domain.SysUser;
import com.qihang.security.entity.SysUser;
import java.util.List;
/**
* 用户 业务层
*
*
* @author qihang
*/
public interface ISysUserService
{
/**
* 根据条件分页查询用户列表
*
*
* @param user 用户信息
* @return 用户信息集合信息
*/
@ -21,7 +22,7 @@ public interface ISysUserService
/**
* 根据条件分页查询已分配用户角色列表
*
*
* @param user 用户信息
* @return 用户信息集合信息
*/
@ -29,7 +30,7 @@ public interface ISysUserService
/**
* 根据条件分页查询未分配用户角色列表
*
*
* @param user 用户信息
* @return 用户信息集合信息
*/
@ -37,7 +38,7 @@ public interface ISysUserService
/**
* 通过用户名查询用户
*
*
* @param userName 用户名
* @return 用户对象信息
*/
@ -45,7 +46,7 @@ public interface ISysUserService
/**
* 通过用户ID查询用户
*
*
* @param userId 用户ID
* @return 用户对象信息
*/
@ -53,7 +54,7 @@ public interface ISysUserService
/**
* 校验用户名称是否唯一
*
*
* @param user 用户信息
* @return 结果
*/
@ -77,7 +78,7 @@ public interface ISysUserService
/**
* 校验用户是否允许操作
*
*
* @param user 用户信息
*/
public void checkUserAllowed(SysUser user);
@ -85,7 +86,7 @@ public interface ISysUserService
/**
* 新增用户信息
*
*
* @param user 用户信息
* @return 结果
*/
@ -93,7 +94,7 @@ public interface ISysUserService
/**
* 注册用户信息
*
*
* @param user 用户信息
* @return 结果
*/
@ -101,7 +102,7 @@ public interface ISysUserService
/**
* 修改用户信息
*
*
* @param user 用户信息
* @return 结果
*/
@ -109,7 +110,7 @@ public interface ISysUserService
/**
* 修改用户状态
*
*
* @param user 用户信息
* @return 结果
*/
@ -117,7 +118,7 @@ public interface ISysUserService
/**
* 修改用户基本信息
*
*
* @param user 用户信息
* @return 结果
*/
@ -125,7 +126,7 @@ public interface ISysUserService
/**
* 修改用户头像
*
*
* @param userName 用户名
* @param avatar 头像地址
* @return 结果
@ -134,7 +135,7 @@ public interface ISysUserService
/**
* 重置用户密码
*
*
* @param user 用户信息
* @return 结果
*/
@ -142,7 +143,7 @@ public interface ISysUserService
/**
* 重置用户密码
*
*
* @param userName 用户名
* @param password 密码
* @return 结果
@ -151,7 +152,7 @@ public interface ISysUserService
/**
* 通过用户ID删除用户
*
*
* @param userId 用户ID
* @return 结果
*/

View File

@ -1,15 +1,17 @@
package com.qihang.oms.api.service;
package com.qihang.security.service;
import com.qihang.oms.api.common.UserConstants;
import com.qihang.oms.api.common.UserNotExistsException;
import com.qihang.oms.api.common.UserPasswordNotMatchException;
import com.qihang.oms.api.config.RedisCache;
import com.qihang.oms.api.domain.LoginUser;
import com.qihang.oms.api.domain.SysUser;
import com.qihang.oms.api.security.AuthenticationContextHolder;
import com.qihang.oms.api.utils.DateUtils;
import com.qihang.oms.api.utils.StringUtils;
import com.qihang.oms.api.utils.ip.IpUtils;
import com.qihang.common.config.RedisCache;
import com.qihang.common.constant.UserConstants;
import com.qihang.common.exception.UserNotExistsException;
import com.qihang.common.utils.DateUtils;
import com.qihang.common.utils.StringUtils;
import com.qihang.security.AuthenticationContextHolder;
import com.qihang.security.LoginUser;
import com.qihang.security.TokenService;
import com.qihang.security.UserPasswordNotMatchException;
import com.qihang.security.entity.SysUser;
import com.qihang.security.utils.IpUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
@ -21,7 +23,7 @@ import org.springframework.stereotype.Component;
/**
* 登录校验方法
*
*
* @author qihang
*/
@Component
@ -35,7 +37,7 @@ public class SysLoginService
@Autowired
private RedisCache redisCache;
@Autowired
private ISysUserService userService;
@ -44,7 +46,7 @@ public class SysLoginService
/**
* 登录验证
*
*
* @param username 用户名
* @param password 密码
* @param code 验证码

View File

@ -0,0 +1,294 @@
//package com.qihang.security.service.impl;
//
//
//import com.qihang.common.common.ServiceException;
//import com.qihang.common.constant.UserConstants;
//import com.qihang.common.utils.StringUtils;
//import com.qihang.security.entity.SysUser;
//import com.qihang.security.mapper.SysUserMapper;
//import com.qihang.security.service.ISysUserService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.util.List;
//
///**
// * 用户 业务层处理
// *
// * @author qihang
// */
//@Service
//public class SysUserServiceImpl implements ISysUserService
//{
// private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
//
// @Autowired
// private SysUserMapper userMapper;
//
// /**
// * 根据条件分页查询用户列表
// *
// * @param user 用户信息
// * @return 用户信息集合信息
// */
// @Override
// public List<SysUser> selectUserList(SysUser user)
// {
// return userMapper.selectUserList(user);
// }
//
// /**
// * 根据条件分页查询已分配用户角色列表
// *
// * @param user 用户信息
// * @return 用户信息集合信息
// */
// @Override
// public List<SysUser> selectAllocatedList(SysUser user)
// {
// return userMapper.selectAllocatedList(user);
// }
//
// /**
// * 根据条件分页查询未分配用户角色列表
// *
// * @param user 用户信息
// * @return 用户信息集合信息
// */
// @Override
// public List<SysUser> selectUnallocatedList(SysUser user)
// {
// return userMapper.selectUnallocatedList(user);
// }
//
// /**
// * 通过用户名查询用户
// *
// * @param userName 用户名
// * @return 用户对象信息
// */
// @Override
// public SysUser selectUserByUserName(String userName)
// {
// return userMapper.selectUserByUserName(userName);
// }
//
// /**
// * 通过用户ID查询用户
// *
// * @param userId 用户ID
// * @return 用户对象信息
// */
// @Override
// public SysUser selectUserById(Long userId)
// {
// return userMapper.selectUserById(userId);
// }
//
// /**
// * 校验用户名称是否唯一
// *
// * @param user 用户信息
// * @return 结果
// */
// @Override
// public boolean checkUserNameUnique(SysUser user)
// {
// Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
// SysUser info = userMapper.checkUserNameUnique(user.getUserName());
// if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
// {
// return UserConstants.NOT_UNIQUE;
// }
// return UserConstants.UNIQUE;
// }
//
// /**
// * 校验手机号码是否唯一
// *
// * @param user 用户信息
// * @return
// */
// @Override
// public boolean checkPhoneUnique(SysUser user)
// {
// Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
// SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber());
// if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
// {
// return UserConstants.NOT_UNIQUE;
// }
// return UserConstants.UNIQUE;
// }
//
// /**
// * 校验email是否唯一
// *
// * @param user 用户信息
// * @return
// */
// @Override
// public boolean checkEmailUnique(SysUser user)
// {
// Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
// SysUser info = userMapper.checkEmailUnique(user.getEmail());
// if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
// {
// return UserConstants.NOT_UNIQUE;
// }
// return UserConstants.UNIQUE;
// }
//
// /**
// * 校验用户是否允许操作
// *
// * @param user 用户信息
// */
// @Override
// public void checkUserAllowed(SysUser user)
// {
// if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin())
// {
// throw new ServiceException("不允许操作超级管理员用户");
// }
// }
//
// /**
// * 新增保存用户信息
// *
// * @param user 用户信息
// * @return 结果
// */
// @Override
// @Transactional
// public int insertUser(SysUser user)
// {
// // 新增用户信息
// int rows = userMapper.insertUser(user);
//// // 新增用户岗位关联
//// insertUserPost(user);
//// // 新增用户与角色管理
//// insertUserRole(user);
// return rows;
// }
//
// /**
// * 注册用户信息
// *
// * @param user 用户信息
// * @return 结果
// */
// @Override
// public boolean registerUser(SysUser user)
// {
// return userMapper.insertUser(user) > 0;
// }
//
// /**
// * 修改保存用户信息
// *
// * @param user 用户信息
// * @return 结果
// */
// @Override
// @Transactional
// public int updateUser(SysUser user)
// {
// Long userId = user.getUserId();
//// // 删除用户与角色关联
//// userRoleMapper.deleteUserRoleByUserId(userId);
//// // 新增用户与角色管理
//// insertUserRole(user);
//// // 删除用户与岗位关联
//// userPostMapper.deleteUserPostByUserId(userId);
// // 新增用户与岗位管理
//// insertUserPost(user);
// return userMapper.updateUser(user);
// }
//
//
// /**
// * 修改用户状态
// *
// * @param user 用户信息
// * @return 结果
// */
// @Override
// public int updateUserStatus(SysUser user)
// {
// return userMapper.updateUser(user);
// }
//
// /**
// * 修改用户基本信息
// *
// * @param user 用户信息
// * @return 结果
// */
// @Override
// public int updateUserProfile(SysUser user)
// {
// return userMapper.updateUser(user);
// }
//
// /**
// * 修改用户头像
// *
// * @param userName 用户名
// * @param avatar 头像地址
// * @return 结果
// */
// @Override
// public boolean updateUserAvatar(String userName, String avatar)
// {
// return userMapper.updateUserAvatar(userName, avatar) > 0;
// }
//
// /**
// * 重置用户密码
// *
// * @param user 用户信息
// * @return 结果
// */
// @Override
// public int resetPwd(SysUser user)
// {
// return userMapper.updateUser(user);
// }
//
// /**
// * 重置用户密码
// *
// * @param userName 用户名
// * @param password 密码
// * @return 结果
// */
// @Override
// public int resetUserPwd(String userName, String password)
// {
// return userMapper.resetUserPwd(userName, password);
// }
//
//
//
// /**
// * 通过用户ID删除用户
// *
// * @param userId 用户ID
// * @return 结果
// */
// @Override
// @Transactional
// public int deleteUserById(Long userId)
// {
//// // 删除用户与角色关联
//// userRoleMapper.deleteUserRoleByUserId(userId);
//// // 删除用户与岗位表
//// userPostMapper.deleteUserPostByUserId(userId);
// return userMapper.deleteUserById(userId);
// }
//
//}

View File

@ -1,16 +1,16 @@
package com.qihang.oms.api.utils.ip;
package com.qihang.security.utils;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.qihang.oms.api.constant.Constants;
import com.qihang.oms.api.utils.http.HttpUtils;
import com.qihang.common.constant.Constants;
import com.qihang.common.utils.http.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
/**
* 获取地址类
*
*
* @author qihang
*/
public class AddressUtils

View File

@ -1,8 +1,6 @@
package com.qihang.oms.api.utils.ip;
package com.qihang.security.utils;
import com.qihang.oms.api.utils.ServletUtils;
import com.qihang.oms.api.utils.StringUtils;
import com.qihang.common.utils.StringUtils;
import jakarta.servlet.http.HttpServletRequest;
import java.net.InetAddress;
@ -10,7 +8,7 @@ import java.net.UnknownHostException;
/**
* 获取IP方法
*
*
* @author qihang
*/
public class IpUtils
@ -24,7 +22,7 @@ public class IpUtils
/**
* 获取客户端IP
*
*
* @return IP地址
*/
public static String getIpAddr()
@ -34,7 +32,7 @@ public class IpUtils
/**
* 获取客户端IP
*
*
* @param request 请求对象
* @return IP地址
*/
@ -72,7 +70,7 @@ public class IpUtils
/**
* 检查是否为内部IP地址
*
*
* @param ip IP地址
* @return 结果
*/
@ -84,7 +82,7 @@ public class IpUtils
/**
* 检查是否为内部IP地址
*
*
* @param addr byte地址
* @return 结果
*/
@ -127,7 +125,7 @@ public class IpUtils
/**
* 将IPv4地址转换成字节
*
*
* @param text IPv4地址
* @return byte 字节
*/
@ -215,7 +213,7 @@ public class IpUtils
/**
* 获取IP地址
*
*
* @return 本地IP地址
*/
public static String getHostIp()
@ -232,7 +230,7 @@ public class IpUtils
/**
* 获取主机名
*
*
* @return 本地主机名
*/
public static String getHostName()
@ -352,7 +350,7 @@ public class IpUtils
/**
* 校验ip是否符合过滤串规则
*
*
* @param filter 过滤IP列表,支持后缀'*'通配,支持网段如:`10.10.10.1-10.10.10.99`
* @param ip 校验IP地址
* @return boolean 结果

View File

@ -1,8 +1,8 @@
package com.qihang.oms.api.utils;
package com.qihang.security.utils;
import com.qihang.oms.api.constant.Constants;
import com.qihang.oms.api.common.Convert;
import com.qihang.common.constant.Convert;
import com.qihang.common.constant.Constants;
import com.qihang.common.utils.StringUtils;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@ -10,6 +10,7 @@ import jakarta.servlet.http.HttpSession;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
@ -20,7 +21,7 @@ import java.util.Map;
/**
* 客户端工具类
*
*
* @author qihang
*/
public class ServletUtils
@ -133,7 +134,7 @@ public class ServletUtils
/**
* 将字符串渲染到客户端
*
*
* @param response 渲染对象
* @param string 待渲染的字符串
*/
@ -154,7 +155,7 @@ public class ServletUtils
/**
* 是否是Ajax异步请求
*
*
* @param request
*/
public static boolean isAjaxRequest(HttpServletRequest request)
@ -183,7 +184,7 @@ public class ServletUtils
/**
* 内容编码
*
*
* @param str 内容
* @return 编码后的内容
*/
@ -201,7 +202,7 @@ public class ServletUtils
/**
* 内容解码
*
*
* @param str 内容
* @return 解码后的内容
*/

View File

@ -1,4 +0,0 @@
package com.qihang.oms.api.domain.vo;
public class MenuMetaVo {
}

24
pom.xml
View File

@ -11,15 +11,37 @@
<url>http://maven.apache.org</url>
<modules>
<module>tao-api</module>
<module>oms-api</module>
<module>sys-api</module>
<module>api</module>
<module>core</module>
<!-- <module>core/common</module>-->
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>3.0.2</spring-boot.version>
<jwt.version>0.11.5</jwt.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.43</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>
</project>

38
sys-api/.gitignore vendored Normal file
View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -13,11 +13,11 @@
<!-- <version>1.0-SNAPSHOT</version>-->
<!-- </parent>-->
<artifactId>oms-api</artifactId>
<artifactId>sys-api</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>oms-api</name>
<name>sys-api</name>
<url>http://maven.apache.org</url>
<properties>
@ -177,6 +177,11 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>com.qihang</groupId>
<artifactId>security</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api;
package com.qihang.sys.api;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
@ -14,22 +14,22 @@ import org.springframework.web.client.RestTemplate;
* Hello world!
*
*/
@EnableFeignClients(basePackages = "com.qihang.oms.api")
@EnableFeignClients(basePackages = "com.qihang.sys.api")
@EnableDiscoveryClient
//@ComponentScan(basePackages={"com.qihang"})
@MapperScan("com.qihang.oms.api.mapper")
@ComponentScan(basePackages={"com.qihang"})
@MapperScan("com.qihang.sys.api.mapper")
@SpringBootApplication
public class OmsApi
public class SysApi
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
SpringApplication.run(OmsApi.class, args);
System.out.println( "Hello sys-api!" );
SpringApplication.run(SysApi.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
// @Bean
// @LoadBalanced
// public RestTemplate restTemplate() {
// return new RestTemplate();
// }
}

View File

@ -0,0 +1,214 @@
//package com.qihang.oms.api.common;
//
//
//import java.util.HashMap;
//import java.util.Objects;
//
///**
// * 操作消息提醒
// *
// * @author qihang
// */
//public class AjaxResult extends HashMap<String, Object>
//{
// private static final long serialVersionUID = 1L;
//
// /** 状态码 */
// public static final String CODE_TAG = "code";
//
// /** 返回内容 */
// public static final String MSG_TAG = "msg";
//
// /** 数据对象 */
// public static final String DATA_TAG = "data";
//
// /**
// * 初始化一个新创建的 AjaxResult 对象使其表示一个空消息
// */
// public AjaxResult()
// {
// }
//
// /**
// * 初始化一个新创建的 AjaxResult 对象
// *
// * @param code 状态码
// * @param msg 返回内容
// */
// public AjaxResult(int code, String msg)
// {
// super.put(CODE_TAG, code);
// super.put(MSG_TAG, msg);
// }
//
// /**
// * 初始化一个新创建的 AjaxResult 对象
// *
// * @param code 状态码
// * @param msg 返回内容
// * @param data 数据对象
// */
// public AjaxResult(int code, String msg, Object data)
// {
// super.put(CODE_TAG, code);
// super.put(MSG_TAG, msg);
// if (data!=null)
// {
// super.put(DATA_TAG, data);
// }
// }
//
// /**
// * 返回成功消息
// *
// * @return 成功消息
// */
// public static AjaxResult success()
// {
// return AjaxResult.success("操作成功");
// }
//
// /**
// * 返回成功数据
// *
// * @return 成功消息
// */
// public static AjaxResult success(Object data)
// {
// return AjaxResult.success("操作成功", data);
// }
//
// /**
// * 返回成功消息
// *
// * @param msg 返回内容
// * @return 成功消息
// */
// public static AjaxResult success(String msg)
// {
// return AjaxResult.success(msg, null);
// }
//
// /**
// * 返回成功消息
// *
// * @param msg 返回内容
// * @param data 数据对象
// * @return 成功消息
// */
// public static AjaxResult success(String msg, Object data)
// {
// return new AjaxResult(HttpStatus.SUCCESS, msg, data);
// }
//
// /**
// * 返回警告消息
// *
// * @param msg 返回内容
// * @return 警告消息
// */
// public static AjaxResult warn(String msg)
// {
// return AjaxResult.warn(msg, null);
// }
//
// /**
// * 返回警告消息
// *
// * @param msg 返回内容
// * @param data 数据对象
// * @return 警告消息
// */
// public static AjaxResult warn(String msg, Object data)
// {
// return new AjaxResult(HttpStatus.WARN, msg, data);
// }
//
// /**
// * 返回错误消息
// *
// * @return 错误消息
// */
// public static AjaxResult error()
// {
// return AjaxResult.error("操作失败");
// }
// /**
// * 返回错误消息
// *
// * @param msg 返回内容
// * @return 错误消息
// */
// public static AjaxResult error(String msg)
// {
// return AjaxResult.error(msg, null);
// }
//
// /**
// * 返回错误消息
// *
// * @param msg 返回内容
// * @param data 数据对象
// * @return 错误消息
// */
// public static AjaxResult error(String msg, Object data)
// {
// return new AjaxResult(HttpStatus.ERROR, msg, data);
// }
//
// /**
// * 返回错误消息
// *
// * @param code 状态码
// * @param msg 返回内容
// * @return 错误消息
// */
// public static AjaxResult error(int code, String msg)
// {
// return new AjaxResult(code, msg, null);
// }
//
// /**
// * 是否为成功消息
// *
// * @return 结果
// */
// public boolean isSuccess()
// {
// return Objects.equals(HttpStatus.SUCCESS, this.get(CODE_TAG));
// }
//
// /**
// * 是否为警告消息
// *
// * @return 结果
// */
// public boolean isWarn()
// {
// return Objects.equals(HttpStatus.WARN, this.get(CODE_TAG));
// }
//
// /**
// * 是否为错误消息
// *
// * @return 结果
// */
// public boolean isError()
// {
// return Objects.equals(HttpStatus.ERROR, this.get(CODE_TAG));
// }
//
// /**
// * 方便链式调用
// *
// * @param key
// * @param value
// * @return 数据对象
// */
// @Override
// public AjaxResult put(String key, Object value)
// {
// super.put(key, value);
// return this;
// }
//}

View File

@ -0,0 +1,98 @@
//package com.qihang.oms.api.common;
//
//
//import com.qihang.oms.api.utils.MessageUtils;
//import com.qihang.oms.api.utils.StringUtils;
//
///**
// * 基础异常
// *
// * @author qihang
// */
//public class BaseException extends RuntimeException
//{
// private static final long serialVersionUID = 1L;
//
// /**
// * 所属模块
// */
// private String module;
//
// /**
// * 错误码
// */
// private String code;
//
// /**
// * 错误码对应的参数
// */
// private Object[] args;
//
// /**
// * 错误消息
// */
// private String defaultMessage;
//
// public BaseException(String module, String code, Object[] args, String defaultMessage)
// {
// this.module = module;
// this.code = code;
// this.args = args;
// this.defaultMessage = defaultMessage;
// }
//
// public BaseException(String module, String code, Object[] args)
// {
// this(module, code, args, null);
// }
//
// public BaseException(String module, String defaultMessage)
// {
// this(module, null, null, defaultMessage);
// }
//
// public BaseException(String code, Object[] args)
// {
// this(null, code, args, null);
// }
//
// public BaseException(String defaultMessage)
// {
// this(null, null, null, defaultMessage);
// }
//
// @Override
// public String getMessage()
// {
// String message = null;
// if (!StringUtils.isEmpty(code))
// {
// message = MessageUtils.message(code, args);
// }
// if (message == null)
// {
// message = defaultMessage;
// }
// return message;
// }
//
// public String getModule()
// {
// return module;
// }
//
// public String getCode()
// {
// return code;
// }
//
// public Object[] getArgs()
// {
// return args;
// }
//
// public String getDefaultMessage()
// {
// return defaultMessage;
// }
//}

View File

@ -0,0 +1,88 @@
//package com.qihang.oms.api.common;
//
//
//import com.qihang.oms.api.utils.StringUtils;
//
//import java.nio.charset.Charset;
//import java.nio.charset.StandardCharsets;
//
///**
// * 字符集工具类
// *
// * @author qihang
// */
//public class CharsetKit
//{
// /** ISO-8859-1 */
// public static final String ISO_8859_1 = "ISO-8859-1";
// /** UTF-8 */
// public static final String UTF_8 = "UTF-8";
// /** GBK */
// public static final String GBK = "GBK";
//
// /** ISO-8859-1 */
// public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1);
// /** UTF-8 */
// public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8);
// /** GBK */
// public static final Charset CHARSET_GBK = Charset.forName(GBK);
//
// /**
// * 转换为Charset对象
// *
// * @param charset 字符集为空则返回默认字符集
// * @return Charset
// */
// public static Charset charset(String charset)
// {
// return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset);
// }
//
// /**
// * 转换字符串的字符集编码
// *
// * @param source 字符串
// * @param srcCharset 源字符集默认ISO-8859-1
// * @param destCharset 目标字符集默认UTF-8
// * @return 转换后的字符集
// */
// public static String convert(String source, String srcCharset, String destCharset)
// {
// return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset));
// }
//
// /**
// * 转换字符串的字符集编码
// *
// * @param source 字符串
// * @param srcCharset 源字符集默认ISO-8859-1
// * @param destCharset 目标字符集默认UTF-8
// * @return 转换后的字符集
// */
// public static String convert(String source, Charset srcCharset, Charset destCharset)
// {
// if (null == srcCharset)
// {
// srcCharset = StandardCharsets.ISO_8859_1;
// }
//
// if (null == destCharset)
// {
// destCharset = StandardCharsets.UTF_8;
// }
//
// if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset))
// {
// return source;
// }
// return new String(source.getBytes(srcCharset), destCharset);
// }
//
// /**
// * @return 系统字符集编码
// */
// public static String systemCharset()
// {
// return Charset.defaultCharset().name();
// }
//}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,94 @@
//package com.qihang.oms.api.common;
//
///**
// * 返回状态码
// *
// * @author qihang
// */
//public class HttpStatus
//{
// /**
// * 操作成功
// */
// public static final int SUCCESS = 200;
//
// /**
// * 对象创建成功
// */
// public static final int CREATED = 201;
//
// /**
// * 请求已经被接受
// */
// public static final int ACCEPTED = 202;
//
// /**
// * 操作已经执行成功但是没有返回数据
// */
// public static final int NO_CONTENT = 204;
//
// /**
// * 资源已被移除
// */
// public static final int MOVED_PERM = 301;
//
// /**
// * 重定向
// */
// public static final int SEE_OTHER = 303;
//
// /**
// * 资源没有被修改
// */
// public static final int NOT_MODIFIED = 304;
//
// /**
// * 参数列表错误缺少格式不匹配
// */
// public static final int BAD_REQUEST = 400;
//
// /**
// * 未授权
// */
// public static final int UNAUTHORIZED = 401;
//
// /**
// * 访问受限授权过期
// */
// public static final int FORBIDDEN = 403;
//
// /**
// * 资源服务未找到
// */
// public static final int NOT_FOUND = 404;
//
// /**
// * 不允许的http方法
// */
// public static final int BAD_METHOD = 405;
//
// /**
// * 资源冲突或者资源被锁
// */
// public static final int CONFLICT = 409;
//
// /**
// * 不支持的数据媒体类型
// */
// public static final int UNSUPPORTED_TYPE = 415;
//
// /**
// * 系统内部错误
// */
// public static final int ERROR = 500;
//
// /**
// * 接口未实现
// */
// public static final int NOT_IMPLEMENTED = 501;
//
// /**
// * 系统警告消息
// */
// public static final int WARN = 601;
//}

View File

@ -0,0 +1,62 @@
//package com.qihang.oms.api.common;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// *
// *
// * @Description 统一返回类封装
// **/
//public class R extends HashMap<String, Object> {
//
// private static final long serialVersionUID = 563554414843661955L;
//
// public R() {
// put("code", 0);
// put("msg", "success");
// }
//
// public static R error(int code, String msg) {
// R r = new R();
// r.put("code", code);
// r.put("msg", msg);
// r.put("success", false);
// return r;
// }
//
// public static R success(Object data, String msg) {
// R r = new R();
// r.put("code", 200);
// r.put("data", data);
// r.put("msg", msg);
// r.put("success", true);
// return r;
// }
//
// public static R success(Object data) {
// return success(data, "success");
// }
//
// public static R ok(String msg) {
// R r = new R();
// r.put("msg", msg);
// return r;
// }
//
// public static R ok(Map<String, Object> map) {
// R r = new R();
// r.putAll(map);
// return r;
// }
//
// public static R ok() {
// return new R();
// }
//
// public R put(String key, Object value) {
// super.put(key, value);
// return this;
// }
//}
//

View File

@ -0,0 +1,74 @@
//package com.qihang.oms.api.common;
//
///**
// * 业务异常
// *
// * @author qihang
// */
//public final class ServiceException extends RuntimeException
//{
// private static final long serialVersionUID = 1L;
//
// /**
// * 错误码
// */
// private Integer code;
//
// /**
// * 错误提示
// */
// private String message;
//
// /**
// * 错误明细内部调试错误
// *
// * {@link CommonResult#getDetailMessage()} 一致的设计
// */
// private String detailMessage;
//
// /**
// * 空构造方法避免反序列化问题
// */
// public ServiceException()
// {
// }
//
// public ServiceException(String message)
// {
// this.message = message;
// }
//
// public ServiceException(String message, Integer code)
// {
// this.message = message;
// this.code = code;
// }
//
// public String getDetailMessage()
// {
// return detailMessage;
// }
//
// @Override
// public String getMessage()
// {
// return message;
// }
//
// public Integer getCode()
// {
// return code;
// }
//
// public ServiceException setMessage(String message)
// {
// this.message = message;
// return this;
// }
//
// public ServiceException setDetailMessage(String detailMessage)
// {
// this.detailMessage = detailMessage;
// return this;
// }
//}

View File

@ -0,0 +1,93 @@
//package com.qihang.oms.api.common;
//
//
//import com.qihang.oms.api.utils.StringUtils;
//
///**
// * 字符串格式化
// *
// * @author qihang
// */
//public class StrFormatter
//{
// public static final String EMPTY_JSON = "{}";
// public static final char C_BACKSLASH = '\\';
// public static final char C_DELIM_START = '{';
// public static final char C_DELIM_END = '}';
//
// /**
// * 格式化字符串<br>
// * 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
// * 如果想输出 {} 使用 \\转义 { 即可如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br>
// * <br>
// * 通常使用format("this is {} for {}", "a", "b") -> this is a for b<br>
// * 转义{} format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
// * 转义\ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
// *
// * @param strPattern 字符串模板
// * @param argArray 参数列表
// * @return 结果
// */
// public static String format(final String strPattern, final Object... argArray)
// {
// if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray))
// {
// return strPattern;
// }
// final int strPatternLength = strPattern.length();
//
// // 初始化定义好的长度以获得更好的性能
// StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
//
// int handledPosition = 0;
// int delimIndex;// 占位符所在位置
// for (int argIndex = 0; argIndex < argArray.length; argIndex++)
// {
// delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition);
// if (delimIndex == -1)
// {
// if (handledPosition == 0)
// {
// return strPattern;
// }
// else
// { // 字符串模板剩余部分不再包含占位符加入剩余部分后返回结果
// sbuf.append(strPattern, handledPosition, strPatternLength);
// return sbuf.toString();
// }
// }
// else
// {
// if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH)
// {
// if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH)
// {
// // 转义符之前还有一个转义符占位符依旧有效
// sbuf.append(strPattern, handledPosition, delimIndex - 1);
// sbuf.append(Convert.utf8Str(argArray[argIndex]));
// handledPosition = delimIndex + 2;
// }
// else
// {
// // 占位符被转义
// argIndex--;
// sbuf.append(strPattern, handledPosition, delimIndex - 1);
// sbuf.append(C_DELIM_START);
// handledPosition = delimIndex + 1;
// }
// }
// else
// {
// // 正常占位符
// sbuf.append(strPattern, handledPosition, delimIndex);
// sbuf.append(Convert.utf8Str(argArray[argIndex]));
// handledPosition = delimIndex + 2;
// }
// }
// }
// // 加入最后一个占位符后所有的字符
// sbuf.append(strPattern, handledPosition, strPattern.length());
//
// return sbuf.toString();
// }
//}

View File

@ -0,0 +1,78 @@
//package com.qihang.oms.api.common;
//
///**
// * 用户常量信息
// *
// * @author qihang
// */
//public class UserConstants
//{
// /**
// * 平台内系统用户的唯一标志
// */
// public static final String SYS_USER = "SYS_USER";
//
// /** 正常状态 */
// public static final String NORMAL = "0";
//
// /** 异常状态 */
// public static final String EXCEPTION = "1";
//
// /** 用户封禁状态 */
// public static final String USER_DISABLE = "1";
//
// /** 角色封禁状态 */
// public static final String ROLE_DISABLE = "1";
//
// /** 部门正常状态 */
// public static final String DEPT_NORMAL = "0";
//
// /** 部门停用状态 */
// public static final String DEPT_DISABLE = "1";
//
// /** 字典正常状态 */
// public static final String DICT_NORMAL = "0";
//
// /** 是否为系统默认(是) */
// public static final String YES = "Y";
//
// /** 是否菜单外链(是) */
// public static final String YES_FRAME = "0";
//
// /** 是否菜单外链(否) */
// public static final String NO_FRAME = "1";
//
// /** 菜单类型(目录) */
// public static final String TYPE_DIR = "M";
//
// /** 菜单类型(菜单) */
// public static final String TYPE_MENU = "C";
//
// /** 菜单类型(按钮) */
// public static final String TYPE_BUTTON = "F";
//
// /** Layout组件标识 */
// public final static String LAYOUT = "Layout";
//
// /** ParentView组件标识 */
// public final static String PARENT_VIEW = "ParentView";
//
// /** InnerLink组件标识 */
// public final static String INNER_LINK = "InnerLink";
//
// /** 校验是否唯一的返回标识 */
// public final static boolean UNIQUE = true;
// public final static boolean NOT_UNIQUE = false;
//
// /**
// * 用户名长度限制
// */
// public static final int USERNAME_MIN_LENGTH = 2;
// public static final int USERNAME_MAX_LENGTH = 20;
//
// /**
// * 密码长度限制
// */
// public static final int PASSWORD_MIN_LENGTH = 5;
// public static final int PASSWORD_MAX_LENGTH = 20;
//}

View File

@ -0,0 +1,18 @@
//package com.qihang.oms.api.common;
//
//
//
///**
// * 用户信息异常类
// *
// * @author qihang
// */
//public class UserException extends BaseException
//{
// private static final long serialVersionUID = 1L;
//
// public UserException(String code, Object[] args)
// {
// super("user", code, args, null);
// }
//}

View File

@ -0,0 +1,16 @@
//package com.qihang.oms.api.common;
//
///**
// * 用户不存在异常类
// *
// * @author qihang
// */
//public class UserNotExistsException extends UserException
//{
// private static final long serialVersionUID = 1L;
//
// public UserNotExistsException()
// {
// super("user.not.exists", null);
// }
//}

View File

@ -0,0 +1,16 @@
//package com.qihang.oms.api.common;
//
///**
// * 用户密码不正确或不符合规范异常类
// *
// * @author qihang
// */
//public class UserPasswordNotMatchException extends UserException
//{
// private static final long serialVersionUID = 1L;
//
// public UserPasswordNotMatchException()
// {
// super("user.password.not.match", null);
// }
//}

View File

@ -0,0 +1,265 @@
//package com.qihang.oms.api.config;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.BoundSetOperations;
//import org.springframework.data.redis.core.HashOperations;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.core.ValueOperations;
//import org.springframework.stereotype.Component;
//
//import java.util.*;
//import java.util.concurrent.TimeUnit;
//
///**
// * spring redis 工具类
// *
// * @author qihang
// **/
//@SuppressWarnings(value = { "unchecked", "rawtypes" })
//@Component
//public class RedisCache
//{
// @Autowired
// public RedisTemplate redisTemplate;
//
// /**
// * 缓存基本的对象IntegerString实体类等
// *
// * @param key 缓存的键值
// * @param value 缓存的值
// */
// public <T> void setCacheObject(final String key, final T value)
// {
// redisTemplate.opsForValue().set(key, value);
// }
//
// /**
// * 缓存基本的对象IntegerString实体类等
// *
// * @param key 缓存的键值
// * @param value 缓存的值
// * @param timeout 时间
// * @param timeUnit 时间颗粒度
// */
// public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit)
// {
// redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
// }
//
// /**
// * 设置有效时间
// *
// * @param key Redis键
// * @param timeout 超时时间
// * @return true=设置成功false=设置失败
// */
// public boolean expire(final String key, final long timeout)
// {
// return expire(key, timeout, TimeUnit.SECONDS);
// }
//
// /**
// * 设置有效时间
// *
// * @param key Redis键
// * @param timeout 超时时间
// * @param unit 时间单位
// * @return true=设置成功false=设置失败
// */
// public boolean expire(final String key, final long timeout, final TimeUnit unit)
// {
// return redisTemplate.expire(key, timeout, unit);
// }
//
// /**
// * 获取有效时间
// *
// * @param key Redis键
// * @return 有效时间
// */
// public long getExpire(final String key)
// {
// return redisTemplate.getExpire(key);
// }
//
// /**
// * 判断 key是否存在
// *
// * @param key
// * @return true 存在 false不存在
// */
// public Boolean hasKey(String key)
// {
// return redisTemplate.hasKey(key);
// }
//
// /**
// * 获得缓存的基本对象
// *
// * @param key 缓存键值
// * @return 缓存键值对应的数据
// */
// public <T> T getCacheObject(final String key)
// {
// ValueOperations<String, T> operation = redisTemplate.opsForValue();
// return operation.get(key);
// }
//
// /**
// * 删除单个对象
// *
// * @param key
// */
// public boolean deleteObject(final String key)
// {
// return redisTemplate.delete(key);
// }
//
// /**
// * 删除集合对象
// *
// * @param collection 多个对象
// * @return
// */
// public boolean deleteObject(final Collection collection)
// {
// return redisTemplate.delete(collection) > 0;
// }
//
// /**
// * 缓存List数据
// *
// * @param key 缓存的键值
// * @param dataList 待缓存的List数据
// * @return 缓存的对象
// */
// public <T> long setCacheList(final String key, final List<T> dataList)
// {
// Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
// return count == null ? 0 : count;
// }
//
// /**
// * 获得缓存的list对象
// *
// * @param key 缓存的键值
// * @return 缓存键值对应的数据
// */
// public <T> List<T> getCacheList(final String key)
// {
// return redisTemplate.opsForList().range(key, 0, -1);
// }
//
// /**
// * 缓存Set
// *
// * @param key 缓存键值
// * @param dataSet 缓存的数据
// * @return 缓存数据的对象
// */
// public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet)
// {
// BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
// Iterator<T> it = dataSet.iterator();
// while (it.hasNext())
// {
// setOperation.add(it.next());
// }
// return setOperation;
// }
//
// /**
// * 获得缓存的set
// *
// * @param key
// * @return
// */
// public <T> Set<T> getCacheSet(final String key)
// {
// return redisTemplate.opsForSet().members(key);
// }
//
// /**
// * 缓存Map
// *
// * @param key
// * @param dataMap
// */
// public <T> void setCacheMap(final String key, final Map<String, T> dataMap)
// {
// if (dataMap != null) {
// redisTemplate.opsForHash().putAll(key, dataMap);
// }
// }
//
// /**
// * 获得缓存的Map
// *
// * @param key
// * @return
// */
// public <T> Map<String, T> getCacheMap(final String key)
// {
// return redisTemplate.opsForHash().entries(key);
// }
//
// /**
// * 往Hash中存入数据
// *
// * @param key Redis键
// * @param hKey Hash键
// * @param value
// */
// public <T> void setCacheMapValue(final String key, final String hKey, final T value)
// {
// redisTemplate.opsForHash().put(key, hKey, value);
// }
//
// /**
// * 获取Hash中的数据
// *
// * @param key Redis键
// * @param hKey Hash键
// * @return Hash中的对象
// */
// public <T> T getCacheMapValue(final String key, final String hKey)
// {
// HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
// return opsForHash.get(key, hKey);
// }
//
// /**
// * 获取多个Hash中的数据
// *
// * @param key Redis键
// * @param hKeys Hash键集合
// * @return Hash对象集合
// */
// public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys)
// {
// return redisTemplate.opsForHash().multiGet(key, hKeys);
// }
//
// /**
// * 删除Hash中的某条数据
// *
// * @param key Redis键
// * @param hKey Hash键
// * @return 是否成功
// */
// public boolean deleteCacheMapValue(final String key, final String hKey)
// {
// return redisTemplate.opsForHash().delete(key, hKey) > 0;
// }
//
// /**
// * 获得缓存的基本对象列表
// *
// * @param pattern 字符串前缀
// * @return 对象列表
// */
// public Collection<String> keys(final String pattern)
// {
// return redisTemplate.keys(pattern);
// }
//}

View File

@ -0,0 +1,71 @@
//package com.qihang.oms.api.config;
//
//
//import com.qihang.oms.api.utils.FastJson2JsonRedisSerializer;
//import org.springframework.cache.annotation.CachingConfigurerSupport;
//import org.springframework.cache.annotation.EnableCaching;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.core.script.DefaultRedisScript;
//import org.springframework.data.redis.serializer.StringRedisSerializer;
//
///**
// * redis配置
// *
// * @author qihang
// */
//@Configuration
//@EnableCaching
//public class RedisConfig extends CachingConfigurerSupport
//{
// @Bean
// @SuppressWarnings(value = { "unchecked", "rawtypes" })
// public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory)
// {
// RedisTemplate<Object, Object> template = new RedisTemplate<>();
// template.setConnectionFactory(connectionFactory);
//
// FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
//
// // 使用StringRedisSerializer来序列化和反序列化redis的key值
// template.setKeySerializer(new StringRedisSerializer());
// template.setValueSerializer(serializer);
//
// // Hash的key也采用StringRedisSerializer的序列化方式
// template.setHashKeySerializer(new StringRedisSerializer());
// template.setHashValueSerializer(serializer);
//
// template.afterPropertiesSet();
// return template;
// }
//
// @Bean
// public DefaultRedisScript<Long> limitScript()
// {
// DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
// redisScript.setScriptText(limitScriptText());
// redisScript.setResultType(Long.class);
// return redisScript;
// }
//
// /**
// * 限流脚本
// */
// private String limitScriptText()
// {
// return "local key = KEYS[1]\n" +
// "local count = tonumber(ARGV[1])\n" +
// "local time = tonumber(ARGV[2])\n" +
// "local current = redis.call('get', key);\n" +
// "if current and tonumber(current) > count then\n" +
// " return tonumber(current);\n" +
// "end\n" +
// "current = redis.call('incr', key)\n" +
// "if tonumber(current) == 1 then\n" +
// " redis.call('expire', key, time)\n" +
// "end\n" +
// "return tonumber(current);";
// }
//}

View File

@ -0,0 +1,44 @@
package com.qihang.sys.api.constant;
/**
* 缓存的key 常量
*
* @author qihang
*/
public class CacheConstants
{
/**
* 登录用户 redis key
*/
public static final String LOGIN_TOKEN_KEY = "login_tokens:";
/**
* 验证码 redis key
*/
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
/**
* 参数管理 cache key
*/
public static final String SYS_CONFIG_KEY = "sys_config:";
/**
* 字典管理 cache key
*/
public static final String SYS_DICT_KEY = "sys_dict:";
/**
* 防重提交 redis key
*/
public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";
/**
* 限流 redis key
*/
public static final String RATE_LIMIT_KEY = "rate_limit:";
/**
* 登录账户密码错误次数 redis key
*/
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
}

View File

@ -0,0 +1,142 @@
package com.qihang.sys.api.constant;
import io.jsonwebtoken.Claims;
/**
* 通用常量信息
*
* @author qihang
*/
public class Constants
{
/**
* UTF-8 字符集
*/
public static final String UTF8 = "UTF-8";
/**
* GBK 字符集
*/
public static final String GBK = "GBK";
/**
* www主域
*/
public static final String WWW = "www.";
/**
* http请求
*/
public static final String HTTP = "http://";
/**
* https请求
*/
public static final String HTTPS = "https://";
/**
* 通用成功标识
*/
public static final String SUCCESS = "0";
/**
* 通用失败标识
*/
public static final String FAIL = "1";
/**
* 登录成功
*/
public static final String LOGIN_SUCCESS = "Success";
/**
* 注销
*/
public static final String LOGOUT = "Logout";
/**
* 注册
*/
public static final String REGISTER = "Register";
/**
* 登录失败
*/
public static final String LOGIN_FAIL = "Error";
/**
* 验证码有效期分钟
*/
public static final Integer CAPTCHA_EXPIRATION = 2;
/**
* 令牌
*/
public static final String TOKEN = "token";
/**
* 令牌前缀
*/
public static final String TOKEN_PREFIX = "Bearer ";
/**
* 令牌前缀
*/
public static final String LOGIN_USER_KEY = "login_user_key";
/**
* 用户ID
*/
public static final String JWT_USERID = "userid";
/**
* 用户名称
*/
public static final String JWT_USERNAME = Claims.SUBJECT;
/**
* 用户头像
*/
public static final String JWT_AVATAR = "avatar";
/**
* 创建时间
*/
public static final String JWT_CREATED = "created";
/**
* 用户权限
*/
public static final String JWT_AUTHORITIES = "authorities";
/**
* 资源映射路径 前缀
*/
public static final String RESOURCE_PREFIX = "/profile";
/**
* RMI 远程方法调用
*/
public static final String LOOKUP_RMI = "rmi:";
/**
* LDAP 远程方法调用
*/
public static final String LOOKUP_LDAP = "ldap:";
/**
* LDAPS 远程方法调用
*/
public static final String LOOKUP_LDAPS = "ldaps:";
/**
* 定时任务白名单配置仅允许访问的包名如其他需要可以自行添加
*/
public static final String[] JOB_WHITELIST_STR = { "com.zhijian" };
/**
* 定时任务违规的字符
*/
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
"org.springframework", "org.apache", "com.zhijian.common.utils.file", "com.zhijian.common.config" };
}

View File

@ -1,10 +1,8 @@
package com.qihang.oms.api.controller;
package com.qihang.sys.api.controller;
import com.qihang.oms.api.service.EchoService;
import com.qihang.sys.api.service.EchoService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

View File

@ -1,11 +1,9 @@
package com.qihang.oms.api.controller;
package com.qihang.sys.api.controller;
import com.alibaba.nacos.api.common.Constants;
import com.qihang.oms.api.common.AjaxResult;
import com.qihang.oms.api.domain.LoginBody;
import com.qihang.oms.api.domain.SysUser;
import com.qihang.oms.api.service.ISysUserService;
import com.qihang.oms.api.service.SysLoginService;
import com.qihang.common.common.AjaxResult;
import com.qihang.sys.api.domain.LoginBody;
import com.qihang.security.service.ISysUserService;
import com.qihang.security.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

View File

@ -1,13 +1,13 @@
package com.qihang.oms.api.controller;
package com.qihang.sys.api.controller;
import com.alibaba.fastjson2.JSONArray;
import com.qihang.oms.api.common.AjaxResult;
import com.qihang.oms.api.domain.LoginUser;
import com.qihang.oms.api.domain.SysMenu;
import com.qihang.oms.api.domain.vo.MenusDetailVo;
import com.qihang.oms.api.domain.vo.MenusVo;
import com.qihang.oms.api.service.ISysMenuService;
import com.qihang.oms.api.service.TokenService;
import com.qihang.common.common.AjaxResult;
import com.qihang.sys.api.domain.SysMenu;
import com.qihang.sys.api.domain.vo.MenusDetailVo;
import com.qihang.sys.api.domain.vo.MenusVo;
import com.qihang.sys.api.service.ISysMenuService;
import com.qihang.security.LoginUser;
import com.qihang.security.TokenService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@RequestMapping("/menus")
@RestController

View File

@ -1,9 +1,8 @@
package com.qihang.oms.api.controller;
package com.qihang.sys.api.controller;
import com.qihang.oms.api.common.AjaxResult;
import com.qihang.oms.api.domain.vo.UserInfoVo;
import com.qihang.common.common.AjaxResult;
import com.qihang.sys.api.domain.vo.UserInfoVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.domain;
package com.qihang.sys.api.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.domain;
package com.qihang.sys.api.domain;
/**
* 用户登录对象

View File

@ -0,0 +1,268 @@
//package com.qihang.oms.api.domain;
//
//import com.alibaba.fastjson2.annotation.JSONField;
//
//import com.qihang.security.entity.SysUser;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.userdetails.UserDetails;
//
//import java.util.Collection;
//import java.util.Set;
//
///**
// * 登录用户身份权限
// *
// * @author qihang
// */
//public class LoginUser implements UserDetails
//{
// private static final long serialVersionUID = 1L;
//
// /**
// * 用户ID
// */
// private Long userId;
//
// /**
// * 部门ID
// */
// private Long deptId;
//
// /**
// * 用户唯一标识
// */
// private String token;
//
// /**
// * 登录时间
// */
// private Long loginTime;
//
// /**
// * 过期时间
// */
// private Long expireTime;
//
// /**
// * 登录IP地址
// */
// private String ipaddr;
//
// /**
// * 登录地点
// */
// private String loginLocation;
//
// /**
// * 浏览器类型
// */
// private String browser;
//
// /**
// * 操作系统
// */
// private String os;
//
// /**
// * 权限列表
// */
// private Set<String> permissions;
//
// /**
// * 用户信息
// */
// private SysUser user;
//
// public LoginUser()
// {
// }
//
// public LoginUser(SysUser user, Set<String> permissions)
// {
// this.user = user;
// this.permissions = permissions;
// }
//
// public LoginUser(Long userId, Long deptId, SysUser user, Set<String> permissions)
// {
// this.userId = userId;
// this.deptId = deptId;
// this.user = user;
// this.permissions = permissions;
// }
//
// public Long getUserId()
// {
// return userId;
// }
//
// public void setUserId(Long userId)
// {
// this.userId = userId;
// }
//
// public Long getDeptId()
// {
// return deptId;
// }
//
// public void setDeptId(Long deptId)
// {
// this.deptId = deptId;
// }
//
// public String getToken()
// {
// return token;
// }
//
// public void setToken(String token)
// {
// this.token = token;
// }
//
// @JSONField(serialize = false)
// @Override
// public String getPassword()
// {
// return user.getPassword();
// }
//
// @Override
// public String getUsername()
// {
// return user.getUserName();
// }
//
// /**
// * 账户是否未过期,过期无法验证
// */
// @JSONField(serialize = false)
// @Override
// public boolean isAccountNonExpired()
// {
// return true;
// }
//
// /**
// * 指定用户是否解锁,锁定的用户无法进行身份验证
// *
// * @return
// */
// @JSONField(serialize = false)
// @Override
// public boolean isAccountNonLocked()
// {
// return true;
// }
//
// /**
// * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
// *
// * @return
// */
// @JSONField(serialize = false)
// @Override
// public boolean isCredentialsNonExpired()
// {
// return true;
// }
//
// /**
// * 是否可用 ,禁用的用户不能身份验证
// *
// * @return
// */
// @JSONField(serialize = false)
// @Override
// public boolean isEnabled()
// {
// return true;
// }
//
// public Long getLoginTime()
// {
// return loginTime;
// }
//
// public void setLoginTime(Long loginTime)
// {
// this.loginTime = loginTime;
// }
//
// public String getIpaddr()
// {
// return ipaddr;
// }
//
// public void setIpaddr(String ipaddr)
// {
// this.ipaddr = ipaddr;
// }
//
// public String getLoginLocation()
// {
// return loginLocation;
// }
//
// public void setLoginLocation(String loginLocation)
// {
// this.loginLocation = loginLocation;
// }
//
// public String getBrowser()
// {
// return browser;
// }
//
// public void setBrowser(String browser)
// {
// this.browser = browser;
// }
//
// public String getOs()
// {
// return os;
// }
//
// public void setOs(String os)
// {
// this.os = os;
// }
//
// public Long getExpireTime()
// {
// return expireTime;
// }
//
// public void setExpireTime(Long expireTime)
// {
// this.expireTime = expireTime;
// }
//
// public Set<String> getPermissions()
// {
// return permissions;
// }
//
// public void setPermissions(Set<String> permissions)
// {
// this.permissions = permissions;
// }
//
// public SysUser getUser()
// {
// return user;
// }
//
// public void setUser(SysUser user)
// {
// this.user = user;
// }
//
// @Override
// public Collection<? extends GrantedAuthority> getAuthorities()
// {
// return null;
// }
//}

View File

@ -1,8 +1,7 @@
package com.qihang.oms.api.domain;
package com.qihang.sys.api.domain;
import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.qihang.oms.api.domain.vo.MenusDetailVo;
import com.qihang.sys.api.domain.vo.MenusDetailVo;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

View File

@ -0,0 +1,249 @@
//package com.qihang.oms.api.domain;
//
//
//import java.util.Date;
//
///**
// * 用户对象 sys_user
// *
// * @author qihang
// */
//public class SysUser extends BaseEntity
//{
// private static final long serialVersionUID = 1L;
//
// /** 用户ID */
// private Long userId;
//
// /** 部门ID */
// private Long deptId;
//
// /** 用户账号 */
//
// private String userName;
//
// /** 用户昵称 */
// private String nickName;
//
// /** 用户邮箱 */
// private String email;
//
// /** 手机号码 */
// private String phonenumber;
//
// /** 用户性别 */
// private String sex;
//
// /** 用户头像 */
// private String avatar;
//
// /** 密码 */
// private String password;
//
// /** 帐号状态0正常 1停用 */
// private String status;
//
// /** 删除标志0代表存在 2代表删除 */
// private String delFlag;
//
// /** 最后登录IP */
// private String loginIp;
//
// /** 最后登录时间 */
// private Date loginDate;
//
// /** 角色组 */
// private Long[] roleIds;
//
// /** 岗位组 */
// private Long[] postIds;
//
// /** 角色ID */
// private Long roleId;
//
// public SysUser()
// {
//
// }
//
// public SysUser(Long userId)
// {
// this.userId = userId;
// }
//
// public Long getUserId()
// {
// return userId;
// }
//
// public void setUserId(Long userId)
// {
// this.userId = userId;
// }
//
// public boolean isAdmin()
// {
// return isAdmin(this.userId);
// }
//
// public static boolean isAdmin(Long userId)
// {
// return userId != null && 1L == userId;
// }
//
// public Long getDeptId()
// {
// return deptId;
// }
//
// public void setDeptId(Long deptId)
// {
// this.deptId = deptId;
// }
//
//
// public String getNickName()
// {
// return nickName;
// }
//
// public void setNickName(String nickName)
// {
// this.nickName = nickName;
// }
//
//
// public String getUserName()
// {
// return userName;
// }
//
// public void setUserName(String userName)
// {
// this.userName = userName;
// }
//
//
// public String getEmail()
// {
// return email;
// }
//
// public void setEmail(String email)
// {
// this.email = email;
// }
//
//
// public String getPhonenumber()
// {
// return phonenumber;
// }
//
// public void setPhonenumber(String phonenumber)
// {
// this.phonenumber = phonenumber;
// }
//
// public String getSex()
// {
// return sex;
// }
//
// public void setSex(String sex)
// {
// this.sex = sex;
// }
//
// public String getAvatar()
// {
// return avatar;
// }
//
// public void setAvatar(String avatar)
// {
// this.avatar = avatar;
// }
//
// public String getPassword()
// {
// return password;
// }
//
// public void setPassword(String password)
// {
// this.password = password;
// }
//
// public String getStatus()
// {
// return status;
// }
//
// public void setStatus(String status)
// {
// this.status = status;
// }
//
// public String getDelFlag()
// {
// return delFlag;
// }
//
// public void setDelFlag(String delFlag)
// {
// this.delFlag = delFlag;
// }
//
// public String getLoginIp()
// {
// return loginIp;
// }
//
// public void setLoginIp(String loginIp)
// {
// this.loginIp = loginIp;
// }
//
// public Date getLoginDate()
// {
// return loginDate;
// }
//
// public void setLoginDate(Date loginDate)
// {
// this.loginDate = loginDate;
// }
//
//
// public Long[] getRoleIds()
// {
// return roleIds;
// }
//
// public void setRoleIds(Long[] roleIds)
// {
// this.roleIds = roleIds;
// }
//
// public Long[] getPostIds()
// {
// return postIds;
// }
//
// public void setPostIds(Long[] postIds)
// {
// this.postIds = postIds;
// }
//
// public Long getRoleId()
// {
// return roleId;
// }
//
// public void setRoleId(Long roleId)
// {
// this.roleId = roleId;
// }
//
//}

View File

@ -0,0 +1,4 @@
package com.qihang.sys.api.domain.vo;
public class MenuMetaVo {
}

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.domain.vo;
package com.qihang.sys.api.domain.vo;
import java.util.List;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.domain.vo;
package com.qihang.sys.api.domain.vo;
import java.util.List;

View File

@ -1,4 +1,4 @@
package com.qihang.oms.api.domain.vo;
package com.qihang.sys.api.domain.vo;
import java.util.List;

View File

@ -0,0 +1,30 @@
package com.qihang.sys.api.enums;
/**
* 用户状态
*
* @author qihang
*/
public enum UserStatus
{
OK("0", "正常"), DISABLE("1", "停用"), DELETED("2", "删除");
private final String code;
private final String info;
UserStatus(String code, String info)
{
this.code = code;
this.info = info;
}
public String getCode()
{
return code;
}
public String getInfo()
{
return info;
}
}

View File

@ -1,7 +1,7 @@
package com.qihang.oms.api.mapper;
package com.qihang.sys.api.mapper;
import com.qihang.oms.api.domain.SysMenu;
import com.qihang.sys.api.domain.SysMenu;
import org.apache.ibatis.annotations.Param;
import java.util.List;

View File

@ -1,7 +1,6 @@
package com.qihang.oms.api.mapper;
package com.qihang.sys.api.mapper;
import com.qihang.oms.api.domain.SysUser;
import com.qihang.security.entity.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -9,7 +8,7 @@ import java.util.List;
/**
* 用户表 数据层
*
*
* @author qihang
*/
@Mapper
@ -17,7 +16,7 @@ public interface SysUserMapper
{
/**
* 根据条件分页查询用户列表
*
*
* @param sysUser 用户信息
* @return 用户信息集合信息
*/
@ -25,7 +24,7 @@ public interface SysUserMapper
/**
* 根据条件分页查询已配用户角色列表
*
*
* @param user 用户信息
* @return 用户信息集合信息
*/
@ -33,7 +32,7 @@ public interface SysUserMapper
/**
* 根据条件分页查询未分配用户角色列表
*
*
* @param user 用户信息
* @return 用户信息集合信息
*/
@ -41,7 +40,7 @@ public interface SysUserMapper
/**
* 通过用户名查询用户
*
*
* @param userName 用户名
* @return 用户对象信息
*/
@ -49,7 +48,7 @@ public interface SysUserMapper
/**
* 通过用户ID查询用户
*
*
* @param userId 用户ID
* @return 用户对象信息
*/
@ -57,7 +56,7 @@ public interface SysUserMapper
/**
* 新增用户信息
*
*
* @param user 用户信息
* @return 结果
*/
@ -65,7 +64,7 @@ public interface SysUserMapper
/**
* 修改用户信息
*
*
* @param user 用户信息
* @return 结果
*/
@ -73,7 +72,7 @@ public interface SysUserMapper
/**
* 修改用户头像
*
*
* @param userName 用户名
* @param avatar 头像地址
* @return 结果
@ -82,7 +81,7 @@ public interface SysUserMapper
/**
* 重置用户密码
*
*
* @param userName 用户名
* @param password 密码
* @return 结果
@ -91,7 +90,7 @@ public interface SysUserMapper
/**
* 通过用户ID删除用户
*
*
* @param userId 用户ID
* @return 结果
*/
@ -99,7 +98,7 @@ public interface SysUserMapper
/**
* 批量删除用户信息
*
*
* @param userIds 需要删除的用户ID
* @return 结果
*/
@ -107,7 +106,7 @@ public interface SysUserMapper
/**
* 校验用户名称是否唯一
*
*
* @param userName 用户名称
* @return 结果
*/

View File

@ -0,0 +1,28 @@
//package com.qihang.oms.api.security;
//
//import org.springframework.security.core.Authentication;
//
///**
// * 身份验证信息
// *
// * @author qihang
// */
//public class AuthenticationContextHolder
//{
// private static final ThreadLocal<Authentication> contextHolder = new ThreadLocal<>();
//
// public static Authentication getContext()
// {
// return contextHolder.get();
// }
//
// public static void setContext(Authentication context)
// {
// contextHolder.set(context);
// }
//
// public static void clearContext()
// {
// contextHolder.remove();
// }
//}

View File

@ -0,0 +1,44 @@
//package com.qihang.oms.api.security;
//
//import com.alibaba.fastjson2.JSON;
//import jakarta.servlet.ServletException;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.http.MediaType;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.web.AuthenticationEntryPoint;
//import org.springframework.stereotype.Component;
//import com.qihang.oms.api.common.R;
//import java.io.IOException;
//import java.io.PrintWriter;
//
//@Component
//public class AuthenticationExceptionHandler implements AuthenticationEntryPoint {
// Logger log = LoggerFactory.getLogger(getClass());
// @Override
// public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
// fallback(authException.getMessage(), response);
// }
//
// private void fallback(String message, HttpServletResponse response) {
// response.setCharacterEncoding("UTF-8");
// response.setContentType(MediaType.APPLICATION_JSON_VALUE);
// PrintWriter writer = null;
// try {
// if (message == null) {
// message = "认证失败!";
// }
// R res = R.error(500, message);
// writer = response.getWriter();
// writer.append(JSON.toJSONString(res));
// } catch (IOException e) {
// log.error(e.getMessage());
// } finally {
// if (writer != null) {
// writer.close();
// }
// }
// }
//}

View File

@ -0,0 +1,89 @@
//package com.qihang.oms.api.security;
//
//
//import com.alibaba.fastjson2.JSON;
//import com.qihang.oms.api.common.R;
//import com.qihang.oms.api.domain.LoginUser;
//import com.qihang.oms.api.service.TokenService;
//import jakarta.servlet.FilterChain;
//import jakarta.servlet.ServletException;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import org.slf4j.Logger;
//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.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
//import org.springframework.stereotype.Component;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import java.io.IOException;
//import java.io.PrintWriter;
//
///**
// * token过滤器 验证token有效性
// *
// * @author qihang
// */
//@Component
//public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
//{
// @Autowired
// private TokenService tokenService;
// /**
// * 需要拦截的请求头信息
// */
// @Value("${token.header:'Authorization'}")
// public String TOKEN_HEADER = "Authorization";
// private Logger log = LoggerFactory.getLogger(getClass());
// @Override
// protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
// throws ServletException, IOException
// {
//// String token = exchange.getRequest().getHeaders().getFirst(TOKEN_HEADER);
// String token = request.getHeader("Authorization");
// String url =request.getRequestURI();
// log.info("intercept " + url);
// log.info("token: " + token);
// if(request.getRequestURI().equals("/login")){
// // 登录页面放行
// chain.doFilter(request, response);
// return;
// }
// LoginUser loginUser = tokenService.getLoginUser(request);
// if (loginUser !=null )
// {
// tokenService.verifyToken(loginUser);
// UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
// authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
// SecurityContextHolder.getContext().setAuthentication(authenticationToken);
// }else {
// fallback(" 授权过期!",response);
// return;
// }
// chain.doFilter(request, response);
// }
//
// private void fallback(String message, HttpServletResponse response) {
// response.setCharacterEncoding("UTF-8");
// response.setContentType(MediaType.APPLICATION_JSON_VALUE);
// PrintWriter writer = null;
// try {
// if (message == null) {
// message = "403 Forbidden";
// }
// R res = R.error(403, message);
// writer = response.getWriter();
// writer.append(JSON.toJSONString(res));
// } catch (IOException e) {
// log.error(e.getMessage());
// } finally {
// if (writer != null) {
// writer.close();
// }
// }
// }
//}

View File

@ -0,0 +1,109 @@
//package com.qihang.oms.api.security;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.HttpMethod;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.authentication.AuthenticationProvider;
//import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
//import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.http.SessionCreationPolicy;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.security.web.SecurityFilterChain;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//
//@Configuration
//@EnableWebSecurity
//public class SecurityConfig {
//
// @Autowired
// private UserDetailsServiceImpl userDetailsService;
//
// @Autowired
// private AuthenticationExceptionHandler invalidAuthenticationEntryPoint;
//
// @Bean
// public PasswordEncoder passwordEncoder() {
// return new BCryptPasswordEncoder();
// }
//
// @Bean
// public JwtAuthenticationTokenFilter authenticationJwtTokenFilter() {
// return new JwtAuthenticationTokenFilter();
// }
//
// @Bean
// public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
//
// http
// // 禁用basic明文验证
// .httpBasic().disable()
// // 前后端分离架构不需要csrf保护
// .csrf().disable()
// // 禁用默认登录页
// .formLogin().disable()
// // 禁用默认登出页
// .logout().disable()
// // 设置异常的EntryPoint如果不设置默认使用Http403ForbiddenEntryPoint
// .exceptionHandling(exceptions -> exceptions.authenticationEntryPoint(invalidAuthenticationEntryPoint))
// // 前后端分离是无状态的不需要session了直接禁用
// .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
// .authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests
// // 允许所有OPTIONS请求
// .requestMatchers("/home").permitAll()
// .requestMatchers(HttpMethod.GET, "/favicon.ico").permitAll()
// // 允许直接访问授权登录接口
// .requestMatchers(HttpMethod.POST, "/login").permitAll()
// // 允许 SpringMVC 的默认错误地址匿名访问
// .requestMatchers("/error").permitAll()
// // 其他所有接口必须有Authority信息Authority在登录成功后的UserDetailsImpl对象中默认设置ROLE_USER
// //.requestMatchers("/**").hasAnyAuthority("ROLE_USER")
// // 允许任意请求被已登录用户访问不检查Authority
// .anyRequest().authenticated())
// .authenticationProvider(authenticationProvider())
// // 加我们自定义的过滤器替代UsernamePasswordAuthenticationFilter
// .addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
//
// return http.build();
// }
//
// @Bean
// public UserDetailsService userDetailsService() {
// // 调用 JwtUserDetailService实例执行实际校验
// return username -> userDetailsService.loadUserByUsername(username);
// }
//
// /**
// * 调用loadUserByUsername获得UserDetail信息在AbstractUserDetailsAuthenticationProvider里执行用户状态检查
// *
// * @return
// */
// @Bean
// public AuthenticationProvider authenticationProvider() {
// DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
// // DaoAuthenticationProvider 从自定义的 userDetailsService.loadUserByUsername 方法获取UserDetails
// authProvider.setUserDetailsService(userDetailsService());
// // 设置密码编辑器
// authProvider.setPasswordEncoder(passwordEncoder());
// return authProvider;
// }
//
// /**
// * 登录时需要调用AuthenticationManager.authenticate执行一次校验
// *
// * @param config
// * @return
// * @throws Exception
// */
// @Bean
// public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
// return config.getAuthenticationManager();
// }
//
//
//}

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