
125 changed files with 1942 additions and 1596 deletions
@ -1,60 +0,0 @@ |
|||
package com.yxt.demo.common.utils; |
|||
|
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import javax.validation.ConstraintViolation; |
|||
import javax.validation.Validation; |
|||
import javax.validation.Validator; |
|||
import java.util.List; |
|||
import java.util.Set; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2022/6/21 0:03 |
|||
* @Description 校验参数工具 |
|||
*/ |
|||
public class ValidationUtil { |
|||
|
|||
public final static Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); |
|||
|
|||
|
|||
/** |
|||
* 验证单个实体 |
|||
* |
|||
* @param t 参数 |
|||
* @param <T> 类型 |
|||
* @return 验证结果 |
|||
*/ |
|||
public static <T> String validateOne(T t) { |
|||
Set<ConstraintViolation<T>> validateResult = validator.validate(t); |
|||
if (validateResult != null && validateResult.size() != 0) { |
|||
StringBuilder sb = new StringBuilder(); |
|||
for (ConstraintViolation<T> valid : validateResult) { |
|||
sb.append(valid.getPropertyPath().toString()).append(StringUtils.SPACE).append(valid.getMessage()) |
|||
.append(","); |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
|
|||
return StringUtils.EMPTY; |
|||
} |
|||
|
|||
/** |
|||
* 验证多个实体 |
|||
* |
|||
* @param ts 参数 |
|||
* @param <T> 类型 |
|||
* @return 验证结果 |
|||
*/ |
|||
public static <T> String validateMutil(List<T> ts) { |
|||
StringBuilder sb = new StringBuilder(); |
|||
for (int index = 0; index < ts.size(); ++index) { |
|||
String validateOneResult = validateOne(ts.get(index)); |
|||
if (!StringUtils.isBlank(validateOneResult)) { |
|||
sb.append("index[" + index + "]:").append(validateOneResult).append(";"); |
|||
} |
|||
} |
|||
|
|||
return sb.toString(); |
|||
} |
|||
} |
@ -1,189 +0,0 @@ |
|||
package com.yxt.demo.common.utils.allutils; |
|||
|
|||
import org.apache.commons.codec.DecoderException; |
|||
import org.apache.commons.codec.binary.Hex; |
|||
import org.apache.commons.lang3.StringEscapeUtils; |
|||
import org.apache.tomcat.util.codec.binary.Base64; |
|||
|
|||
import java.io.UnsupportedEncodingException; |
|||
import java.net.URLDecoder; |
|||
import java.net.URLEncoder; |
|||
import java.security.MessageDigest; |
|||
import java.security.NoSuchAlgorithmException; |
|||
|
|||
/** |
|||
* 封装各种格式的编码解码工具类. 1.Commons-Codec的 hex/base64 编码 2.自制的base62 编码 |
|||
* 3.Commons-Lang的xml/html escape 4.JDK提供的URLEncoder |
|||
* |
|||
* @author dimengzhe |
|||
* @date 2020/9/11 13:38 |
|||
* @description 编码解码工具类 |
|||
*/ |
|||
|
|||
public class Encodes { |
|||
|
|||
private static final String DEFAULT_URL_ENCODING = "UTF-8"; |
|||
private static final char[] BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray(); |
|||
private static final String SALT = "jlzx@yxt?"; |
|||
|
|||
/** |
|||
* Hex编码. |
|||
*/ |
|||
public static String encodeHex(byte[] input) { |
|||
return new String(Hex.encodeHex(input)); |
|||
} |
|||
|
|||
/** |
|||
* Hex解码. |
|||
*/ |
|||
public static byte[] decodeHex(String input) { |
|||
try { |
|||
return Hex.decodeHex(input.toCharArray()); |
|||
} catch (DecoderException e) { |
|||
throw Exceptions.unchecked(e); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Base64编码. |
|||
*/ |
|||
public static String encodeBase64(byte[] input) { |
|||
return new String(Base64.encodeBase64(input)); |
|||
} |
|||
|
|||
/** |
|||
* Base64编码. |
|||
*/ |
|||
public static String encodeBase64(String input) { |
|||
try { |
|||
return new String(Base64.encodeBase64(input.getBytes(DEFAULT_URL_ENCODING))); |
|||
} catch (UnsupportedEncodingException e) { |
|||
return ""; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Base64解码. |
|||
*/ |
|||
public static byte[] decodeBase64(String input) { |
|||
return Base64.decodeBase64(input.getBytes()); |
|||
} |
|||
|
|||
/** |
|||
* Base64解码. |
|||
*/ |
|||
public static String decodeBase64String(String input) { |
|||
try { |
|||
return new String(Base64.decodeBase64(input.getBytes()), DEFAULT_URL_ENCODING); |
|||
} catch (UnsupportedEncodingException e) { |
|||
return ""; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Base62编码。 |
|||
*/ |
|||
public static String encodeBase62(byte[] input) { |
|||
char[] chars = new char[input.length]; |
|||
for (int i = 0; i < input.length; i++) { |
|||
chars[i] = BASE62[((input[i] & 0xFF) % BASE62.length)]; |
|||
} |
|||
return new String(chars); |
|||
} |
|||
|
|||
/** |
|||
* Html 转码. |
|||
*/ |
|||
public static String escapeHtml(String html) { |
|||
return StringEscapeUtils.escapeHtml4(html); |
|||
} |
|||
|
|||
/** |
|||
* Html 解码. |
|||
*/ |
|||
public static String unescapeHtml(String htmlEscaped) { |
|||
return StringEscapeUtils.unescapeHtml4(htmlEscaped); |
|||
} |
|||
|
|||
/** |
|||
* Xml 转码. |
|||
*/ |
|||
public static String escapeXml(String xml) { |
|||
return StringEscapeUtils.escapeXml10(xml); |
|||
} |
|||
|
|||
/** |
|||
* Xml 解码. |
|||
*/ |
|||
public static String unescapeXml(String xmlEscaped) { |
|||
return StringEscapeUtils.unescapeXml(xmlEscaped); |
|||
} |
|||
|
|||
/** |
|||
* URL 编码, Encode默认为UTF-8. |
|||
*/ |
|||
public static String urlEncode(String part) { |
|||
try { |
|||
return URLEncoder.encode(part, DEFAULT_URL_ENCODING); |
|||
} catch (UnsupportedEncodingException e) { |
|||
throw Exceptions.unchecked(e); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* URL 解码, Encode默认为UTF-8. |
|||
*/ |
|||
public static String urlDecode(String part) { |
|||
|
|||
try { |
|||
return URLDecoder.decode(part, DEFAULT_URL_ENCODING); |
|||
} catch (UnsupportedEncodingException e) { |
|||
throw Exceptions.unchecked(e); |
|||
} |
|||
} |
|||
|
|||
public static String md5(String str) { |
|||
return digest("MD5", str + SALT); |
|||
} |
|||
|
|||
public static String sha1(CharSequence cs) { |
|||
return digest("SHA1", cs); |
|||
} |
|||
|
|||
public static String digest(String algorithm, CharSequence cs) { |
|||
return digest(algorithm, StringUtils.getBytesUTF8(null == cs ? "" : cs), null, 1); |
|||
} |
|||
|
|||
public static String digest(String algorithm, byte[] bytes, byte[] salt, int iterations) { |
|||
try { |
|||
MessageDigest md = MessageDigest.getInstance(algorithm); |
|||
if (salt != null) { |
|||
md.update(salt); |
|||
} |
|||
byte[] hashBytes = md.digest(bytes); |
|||
for (int i = 1; i < iterations; i++) { |
|||
md.reset(); |
|||
hashBytes = md.digest(hashBytes); |
|||
} |
|||
return fixedHexString(hashBytes); |
|||
} catch (NoSuchAlgorithmException e) { |
|||
throw Exceptions.unchecked(e); |
|||
} |
|||
} |
|||
|
|||
public static String fixedHexString(byte[] hashBytes) { |
|||
StringBuffer sb = new StringBuffer(); |
|||
for (int i = 0; i < hashBytes.length; i++) { |
|||
sb.append(Integer.toString((hashBytes[i] & 0xFF) + 256, 16).substring(1)); |
|||
} |
|||
|
|||
return sb.toString(); |
|||
} |
|||
|
|||
public static String md5(String str, boolean isShort) { |
|||
if (isShort) { |
|||
return md5(str).substring(8, 24); |
|||
} |
|||
return md5(str); |
|||
} |
|||
} |
@ -1,395 +0,0 @@ |
|||
package com.yxt.demo.common.utils.allutils; |
|||
|
|||
import org.apache.commons.lang3.StringEscapeUtils; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.io.UnsupportedEncodingException; |
|||
import java.math.BigDecimal; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
/** |
|||
* @author dimengzhe |
|||
* @date 2020/9/18 9:35 |
|||
* @description |
|||
*/ |
|||
|
|||
public class StringUtils extends org.apache.commons.lang3.StringUtils { |
|||
|
|||
private static final char SEPARATOR = '_'; |
|||
private static final String CHARSET_NAME = "UTF-8"; |
|||
|
|||
public static boolean isNull(Object obj) { |
|||
return obj == null; |
|||
} |
|||
|
|||
public static boolean isNotNull(Object obj) { |
|||
return !isNull(obj); |
|||
} |
|||
|
|||
/** |
|||
* 转换为字节数组 |
|||
* |
|||
* @param str 字符串 |
|||
* @return |
|||
*/ |
|||
public static byte[] getBytes(String str) { |
|||
if (str != null) { |
|||
try { |
|||
return str.getBytes(CHARSET_NAME); |
|||
} catch (UnsupportedEncodingException e) { |
|||
return null; |
|||
} |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 转换为字节数组 |
|||
* |
|||
* @param bytes |
|||
* @return |
|||
*/ |
|||
public static String toString(byte[] bytes) { |
|||
try { |
|||
return new String(bytes, CHARSET_NAME); |
|||
} catch (UnsupportedEncodingException e) { |
|||
return EMPTY; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 是否包含字符串 |
|||
* |
|||
* @param str 验证字符串 |
|||
* @param strs 字符串组 |
|||
* @return 包含返回true |
|||
*/ |
|||
public static boolean inString(String str, String... strs) { |
|||
if (str != null) { |
|||
for (String s : strs) { |
|||
if (str.equals(trim(s))) { |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* 替换掉HTML标签方法 |
|||
*/ |
|||
public static String replaceHtml(String html) { |
|||
if (isBlank(html)) { |
|||
return ""; |
|||
} |
|||
String regEx = "<.+?>"; |
|||
Pattern p = Pattern.compile(regEx); |
|||
Matcher m = p.matcher(html); |
|||
String s = m.replaceAll(""); |
|||
return s; |
|||
} |
|||
|
|||
/** |
|||
* 替换为手机识别的HTML,去掉样式及属性,保留回车。 |
|||
* |
|||
* @param html |
|||
* @return |
|||
*/ |
|||
public static String replaceMobileHtml(String html) { |
|||
if (html == null) { |
|||
return ""; |
|||
} |
|||
return html.replaceAll("<([a-z]+?)\\s+?.*?>", "<$1>"); |
|||
} |
|||
|
|||
/** |
|||
* 替换为手机识别的HTML,去掉样式及属性,保留回车。 |
|||
* |
|||
* @param txt |
|||
* @return |
|||
*/ |
|||
public static String toHtml(String txt) { |
|||
if (txt == null) { |
|||
return ""; |
|||
} |
|||
return replace(replace(Encodes.escapeHtml(txt), "\n", "<br/>"), "\t", " "); |
|||
} |
|||
|
|||
/** |
|||
* 缩略字符串(不区分中英文字符) |
|||
* |
|||
* @param str 目标字符串 |
|||
* @param length 截取长度 |
|||
* @return |
|||
*/ |
|||
public static String abbr(String str, int length) { |
|||
if (str == null) { |
|||
return ""; |
|||
} |
|||
try { |
|||
StringBuilder sb = new StringBuilder(); |
|||
int currentLength = 0; |
|||
for (char c : replaceHtml(StringEscapeUtils.unescapeHtml4(str)).toCharArray()) { |
|||
currentLength += String.valueOf(c).getBytes("GBK").length; |
|||
if (currentLength <= length - 3) { |
|||
sb.append(c); |
|||
} else { |
|||
sb.append("..."); |
|||
break; |
|||
} |
|||
} |
|||
return sb.toString(); |
|||
} catch (UnsupportedEncodingException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return ""; |
|||
} |
|||
|
|||
public static String abbr2(String param, int length) { |
|||
if (param == null) { |
|||
return ""; |
|||
} |
|||
StringBuffer result = new StringBuffer(); |
|||
int n = 0; |
|||
char temp; |
|||
boolean isCode = false; // 是不是HTML代码
|
|||
boolean isHTML = false; // 是不是HTML特殊字符,如
|
|||
for (int i = 0; i < param.length(); i++) { |
|||
temp = param.charAt(i); |
|||
if (temp == '<') { |
|||
isCode = true; |
|||
} else if (temp == '&') { |
|||
isHTML = true; |
|||
} else if (temp == '>' && isCode) { |
|||
n = n - 1; |
|||
isCode = false; |
|||
} else if (temp == ';' && isHTML) { |
|||
isHTML = false; |
|||
} |
|||
try { |
|||
if (!isCode && !isHTML) { |
|||
n += String.valueOf(temp).getBytes("GBK").length; |
|||
} |
|||
} catch (UnsupportedEncodingException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
if (n <= length - 3) { |
|||
result.append(temp); |
|||
} else { |
|||
result.append("..."); |
|||
break; |
|||
} |
|||
} |
|||
// 取出截取字符串中的HTML标记
|
|||
String temp_result = result.toString().replaceAll("(>)[^<>]*(<?)", "$1$2"); |
|||
// 去掉不需要结素标记的HTML标记
|
|||
temp_result = temp_result.replaceAll( |
|||
"</?(AREA|BASE|BASEFONT|BODY|BR|COL|COLGROUP|DD|DT|FRAME|HEAD|HR|HTML|IMG|INPUT|ISINDEX|LI|LINK|META|OPTION|P|PARAM|TBODY|TD|TFOOT|TH|THEAD|TR|area|base|basefont|body|br|col|colgroup|dd|dt|frame|head|hr|html|img|input|isindex|li|link|meta|option|p|param|tbody|td|tfoot|th|thead|tr)[^<>]*/?>", |
|||
""); |
|||
// 去掉成对的HTML标记
|
|||
temp_result = temp_result.replaceAll("<([a-zA-Z]+)[^<>]*>(.*?)</\\1>", "$2"); |
|||
// 用正则表达式取出标记
|
|||
Pattern p = Pattern.compile("<([a-zA-Z]+)[^<>]*>"); |
|||
Matcher m = p.matcher(temp_result); |
|||
List<String> endHTML = new ArrayList<String>(); |
|||
while (m.find()) { |
|||
endHTML.add(m.group(1)); |
|||
} |
|||
// 补全不成对的HTML标记
|
|||
for (int i = endHTML.size() - 1; i >= 0; i--) { |
|||
result.append("</"); |
|||
result.append(endHTML.get(i)); |
|||
result.append(">"); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
/** |
|||
* 转换为Double类型 |
|||
*/ |
|||
public static Double toDouble(Object val) { |
|||
if (val == null) { |
|||
return 0D; |
|||
} |
|||
try { |
|||
return Double.valueOf(trim(val.toString())); |
|||
} catch (Exception e) { |
|||
return 0D; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 转换为Float类型 |
|||
*/ |
|||
public static Float toFloat(Object val) { |
|||
return toDouble(val).floatValue(); |
|||
} |
|||
|
|||
/** |
|||
* 转换为Long类型 |
|||
*/ |
|||
public static Long toLong(Object val) { |
|||
return toDouble(val).longValue(); |
|||
} |
|||
|
|||
/** |
|||
* 转换为Integer类型 |
|||
*/ |
|||
public static Integer toInteger(Object val) { |
|||
return toLong(val).intValue(); |
|||
} |
|||
|
|||
/** |
|||
* 转换为BigDecimal类型 |
|||
*/ |
|||
public static BigDecimal toBigDecimal(String val) { |
|||
if (StringUtils.isBlank(val)) { |
|||
return null; |
|||
} |
|||
BigDecimal bd = new BigDecimal(val); |
|||
return bd; |
|||
} |
|||
|
|||
/** |
|||
* 获得用户远程地址 |
|||
*/ |
|||
public static String getRemoteAddr(HttpServletRequest request) { |
|||
String remoteAddr = request.getHeader("X-Real-IP"); |
|||
if (isNotBlank(remoteAddr)) { |
|||
remoteAddr = request.getHeader("X-Forwarded-For"); |
|||
} else if (isNotBlank(remoteAddr)) { |
|||
remoteAddr = request.getHeader("Proxy-Client-IP"); |
|||
} else if (isNotBlank(remoteAddr)) { |
|||
remoteAddr = request.getHeader("WL-Proxy-Client-IP"); |
|||
} |
|||
return remoteAddr != null ? remoteAddr : request.getRemoteAddr(); |
|||
} |
|||
|
|||
/** |
|||
* 驼峰命名法工具 |
|||
* |
|||
* @return toCamelCase(" hello_world ") == "helloWorld" |
|||
* toCapitalizeCamelCase("hello_world") == "HelloWorld" |
|||
* toUnderScoreCase("helloWorld") = "hello_world" |
|||
*/ |
|||
public static String toCamelCase(String s) { |
|||
if (s == null) { |
|||
return null; |
|||
} |
|||
|
|||
s = s.toLowerCase(); |
|||
|
|||
StringBuilder sb = new StringBuilder(s.length()); |
|||
boolean upperCase = false; |
|||
for (int i = 0; i < s.length(); i++) { |
|||
char c = s.charAt(i); |
|||
|
|||
if (c == SEPARATOR) { |
|||
upperCase = true; |
|||
} else if (upperCase) { |
|||
sb.append(Character.toUpperCase(c)); |
|||
upperCase = false; |
|||
} else { |
|||
sb.append(c); |
|||
} |
|||
} |
|||
|
|||
return sb.toString(); |
|||
} |
|||
|
|||
/** |
|||
* 驼峰命名法工具 |
|||
* |
|||
* @return toCamelCase(" hello_world ") == "helloWorld" |
|||
* toCapitalizeCamelCase("hello_world") == "HelloWorld" |
|||
* toUnderScoreCase("helloWorld") = "hello_world" |
|||
*/ |
|||
public static String toCapitalizeCamelCase(String s) { |
|||
if (s == null) { |
|||
return null; |
|||
} |
|||
s = toCamelCase(s); |
|||
return s.substring(0, 1).toUpperCase() + s.substring(1); |
|||
} |
|||
|
|||
/** |
|||
* 驼峰命名法工具 |
|||
* |
|||
* @return toCamelCase(" hello_world ") == "helloWorld" |
|||
* toCapitalizeCamelCase("hello_world") == "HelloWorld" |
|||
* toUnderScoreCase("helloWorld") = "hello_world" |
|||
*/ |
|||
public static String toUnderScoreCase(String s) { |
|||
if (s == null) { |
|||
return null; |
|||
} |
|||
|
|||
StringBuilder sb = new StringBuilder(); |
|||
boolean upperCase = false; |
|||
for (int i = 0; i < s.length(); i++) { |
|||
char c = s.charAt(i); |
|||
|
|||
boolean nextUpperCase = true; |
|||
|
|||
if (i < (s.length() - 1)) { |
|||
nextUpperCase = Character.isUpperCase(s.charAt(i + 1)); |
|||
} |
|||
|
|||
if ((i > 0) && Character.isUpperCase(c)) { |
|||
if (!upperCase || !nextUpperCase) { |
|||
sb.append(SEPARATOR); |
|||
} |
|||
upperCase = true; |
|||
} else { |
|||
upperCase = false; |
|||
} |
|||
|
|||
sb.append(Character.toLowerCase(c)); |
|||
} |
|||
|
|||
return sb.toString(); |
|||
} |
|||
|
|||
/** |
|||
* 如果不为空,则设置值 |
|||
* |
|||
* @param target |
|||
* @param source |
|||
*/ |
|||
public static void setValueIfNotBlank(String target, String source) { |
|||
if (isNotBlank(source)) { |
|||
target = source; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 转换为JS获取对象值,生成三目运算返回结果 |
|||
* |
|||
* @param objectString 对象串 例如:row.user.id |
|||
* 返回:!row?'':!row.user?'':!row.user.id?'':row.user.id |
|||
*/ |
|||
public static String jsGetVal(String objectString) { |
|||
StringBuilder result = new StringBuilder(); |
|||
StringBuilder val = new StringBuilder(); |
|||
String[] vals = split(objectString, "."); |
|||
for (int i = 0; i < vals.length; i++) { |
|||
val.append("." + vals[i]); |
|||
result.append("!" + (val.substring(1)) + "?'':"); |
|||
} |
|||
result.append(val.substring(1)); |
|||
return result.toString(); |
|||
} |
|||
|
|||
public static byte[] getBytesUTF8(CharSequence cs) { |
|||
try { |
|||
return cs.toString().getBytes("UTF-8"); |
|||
} catch (UnsupportedEncodingException e) { |
|||
throw Exceptions.unchecked(e); |
|||
} |
|||
} |
|||
} |
@ -1,197 +0,0 @@ |
|||
package com.yxt.demo.common.utils.convert; |
|||
|
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import java.util.Collection; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2022/7/23 23:38 |
|||
* @Description |
|||
*/ |
|||
public class StringUtil extends StringUtils { |
|||
|
|||
/** |
|||
* 空字符串 |
|||
*/ |
|||
private static final String NULLSTR = ""; |
|||
|
|||
/** |
|||
* 下划线 |
|||
*/ |
|||
private static final char SEPARATOR = '_'; |
|||
|
|||
/** |
|||
* 星号 |
|||
*/ |
|||
private static final String START = "*"; |
|||
|
|||
/** |
|||
* * 判断一个Collection是否为空, 包含List,Set,Queue |
|||
* |
|||
* @param coll 要判断的Collection |
|||
* @return true:为空 false:非空 |
|||
*/ |
|||
public static boolean isEmpty(Collection<?> coll) { |
|||
return isNull(coll) || coll.isEmpty(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* * 判断一个对象是否为空 |
|||
* |
|||
* @param object Object |
|||
* @return true:为空 false:非空 |
|||
*/ |
|||
public static boolean isNull(Object object) { |
|||
return object == null; |
|||
} |
|||
|
|||
/** |
|||
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串 |
|||
* |
|||
* @param str 指定字符串 |
|||
* @param strs 需要检查的字符串数组 |
|||
* @return 是否匹配 |
|||
*/ |
|||
public static boolean matchesTwo(String str, List<String> strs) { |
|||
if (isEmpty(str) || isEmpty(strs)) { |
|||
return false; |
|||
} |
|||
for (String testStr : strs) { |
|||
if (matchesTwo(str, testStr)) { |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public static boolean matches(String str, List<String> strs) { |
|||
if (isEmpty(str) || isEmpty(strs)) { |
|||
return false; |
|||
} |
|||
for (String testStr : strs) { |
|||
if (matches(str, testStr)) { |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public static boolean matches(String str, String pattern) { |
|||
if (isEmpty(pattern) || isEmpty(str)) { |
|||
return false; |
|||
} |
|||
|
|||
pattern = pattern.replaceAll("\\s*", ""); // 替换空格
|
|||
int beginOffset = 0; // pattern截取开始位置
|
|||
int formerStarOffset = -1; // 前星号的偏移位置
|
|||
int latterStarOffset = -1; // 后星号的偏移位置
|
|||
|
|||
String remainingURI = str; |
|||
String prefixPattern = ""; |
|||
String suffixPattern = ""; |
|||
|
|||
boolean result = false; |
|||
do { |
|||
formerStarOffset = indexOf(pattern, START, beginOffset); |
|||
prefixPattern = substring(pattern, beginOffset, formerStarOffset > -1 ? formerStarOffset : pattern.length()); |
|||
|
|||
// 匹配前缀Pattern
|
|||
result = remainingURI.equals(prefixPattern); |
|||
// 已经没有星号,直接返回
|
|||
if (formerStarOffset == -1) { |
|||
return result; |
|||
} |
|||
|
|||
// 匹配失败,直接返回
|
|||
if (!result) { |
|||
return false; |
|||
} |
|||
if (!isEmpty(prefixPattern)) { |
|||
remainingURI = substringAfter(str, prefixPattern); |
|||
} |
|||
|
|||
// 匹配后缀Pattern
|
|||
latterStarOffset = indexOf(pattern, START, formerStarOffset + 1); |
|||
suffixPattern = substring(pattern, formerStarOffset + 1, latterStarOffset > -1 ? latterStarOffset : pattern.length()); |
|||
|
|||
result = remainingURI.equals(suffixPattern); |
|||
// 匹配失败,直接返回
|
|||
if (!result) { |
|||
return false; |
|||
} |
|||
if (!isEmpty(suffixPattern)) { |
|||
remainingURI = substringAfter(str, suffixPattern); |
|||
} |
|||
|
|||
// 移动指针
|
|||
beginOffset = latterStarOffset + 1; |
|||
|
|||
} |
|||
while (!isEmpty(suffixPattern) && !isEmpty(remainingURI)); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* 查找指定字符串是否匹配 |
|||
* |
|||
* @param str 指定字符串 |
|||
* @param pattern 需要检查的字符串 |
|||
* @return 是否匹配 |
|||
*/ |
|||
public static boolean matchesTwo(String str, String pattern) { |
|||
if (isEmpty(pattern) || isEmpty(str)) { |
|||
return false; |
|||
} |
|||
pattern = pattern.replaceAll("\\s*", ""); // 替换空格
|
|||
int beginOffset = 0; // pattern截取开始位置
|
|||
int formerStarOffset = -1; // 前星号的偏移位置
|
|||
int latterStarOffset = -1; // 后星号的偏移位置
|
|||
|
|||
String remainingURI = str; |
|||
String prefixPattern = ""; |
|||
String suffixPattern = ""; |
|||
|
|||
boolean result = false; |
|||
do { |
|||
formerStarOffset = indexOf(pattern, START, beginOffset); |
|||
prefixPattern = substring(pattern, beginOffset, formerStarOffset > -1 ? formerStarOffset : pattern.length()); |
|||
|
|||
// 匹配前缀Pattern
|
|||
result = remainingURI.contains(prefixPattern); |
|||
// 已经没有星号,直接返回
|
|||
if (formerStarOffset == -1) { |
|||
return result; |
|||
} |
|||
|
|||
// 匹配失败,直接返回
|
|||
if (!result) { |
|||
return false; |
|||
} |
|||
if (!isEmpty(prefixPattern)) { |
|||
remainingURI = substringAfter(str, prefixPattern); |
|||
} |
|||
|
|||
// 匹配后缀Pattern
|
|||
latterStarOffset = indexOf(pattern, START, formerStarOffset + 1); |
|||
suffixPattern = substring(pattern, formerStarOffset + 1, latterStarOffset > -1 ? latterStarOffset : pattern.length()); |
|||
|
|||
result = remainingURI.contains(suffixPattern); |
|||
// 匹配失败,直接返回
|
|||
if (!result) { |
|||
return false; |
|||
} |
|||
if (!isEmpty(suffixPattern)) { |
|||
remainingURI = substringAfter(str, suffixPattern); |
|||
} |
|||
|
|||
// 移动指针
|
|||
beginOffset = latterStarOffset + 1; |
|||
} |
|||
while (!isEmpty(suffixPattern) && !isEmpty(remainingURI)); |
|||
return true; |
|||
} |
|||
} |
@ -1,345 +0,0 @@ |
|||
package com.yxt.demo.common.utils.http; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import okhttp3.*; |
|||
|
|||
import javax.net.ssl.SSLContext; |
|||
import javax.net.ssl.SSLSocketFactory; |
|||
import javax.net.ssl.TrustManager; |
|||
import javax.net.ssl.X509TrustManager; |
|||
import java.io.IOException; |
|||
import java.net.URLEncoder; |
|||
import java.security.SecureRandom; |
|||
import java.security.cert.X509Certificate; |
|||
import java.util.LinkedHashMap; |
|||
import java.util.Map; |
|||
import java.util.concurrent.Semaphore; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2021/11/5 20:57 |
|||
* @Description 封装OkHttp3工具类 |
|||
*/ |
|||
public class OkHttpUtils { |
|||
|
|||
private static volatile OkHttpClient okHttpClient = null; |
|||
private static volatile Semaphore semaphore = null; |
|||
private Map<String, String> headerMap; |
|||
private Map<String, String> paramMap; |
|||
private String url; |
|||
private Request.Builder request; |
|||
|
|||
/** |
|||
* 初始化okHttpClient,并且允许https访问 |
|||
*/ |
|||
private OkHttpUtils() { |
|||
if (okHttpClient == null) { |
|||
synchronized (OkHttpUtils.class) { |
|||
if (okHttpClient == null) { |
|||
TrustManager[] trustManagers = buildTrustManagers(); |
|||
okHttpClient = new OkHttpClient.Builder() |
|||
.connectTimeout(15, TimeUnit.SECONDS) |
|||
.writeTimeout(20, TimeUnit.SECONDS) |
|||
.readTimeout(20, TimeUnit.SECONDS) |
|||
.sslSocketFactory(createSSLSocketFactory(trustManagers), (X509TrustManager) trustManagers[0]) |
|||
.hostnameVerifier((hostName, session) -> true) |
|||
.retryOnConnectionFailure(true) |
|||
.build(); |
|||
addHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 用于异步请求时,控制访问线程数,返回结果 |
|||
* |
|||
* @return |
|||
*/ |
|||
private static Semaphore getSemaphoreInstance() { |
|||
//只能1个线程同时访问
|
|||
synchronized (OkHttpUtils.class) { |
|||
if (semaphore == null) { |
|||
semaphore = new Semaphore(0); |
|||
} |
|||
} |
|||
return semaphore; |
|||
} |
|||
|
|||
/** |
|||
* 创建OkHttpUtils |
|||
* |
|||
* @return |
|||
*/ |
|||
public static OkHttpUtils builder() { |
|||
return new OkHttpUtils(); |
|||
} |
|||
|
|||
/** |
|||
* 添加url |
|||
* |
|||
* @param url |
|||
* @return |
|||
*/ |
|||
public OkHttpUtils url(String url) { |
|||
this.url = url; |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 添加参数 |
|||
* |
|||
* @param key 参数名 |
|||
* @param value 参数值 |
|||
* @return |
|||
*/ |
|||
public OkHttpUtils addParam(String key, String value) { |
|||
if (paramMap == null) { |
|||
paramMap = new LinkedHashMap<>(16); |
|||
} |
|||
paramMap.put(key, value); |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 添加请求头 |
|||
* |
|||
* @param key 参数名 |
|||
* @param value 参数值 |
|||
* @return |
|||
*/ |
|||
public OkHttpUtils addHeader(String key, String value) { |
|||
if (headerMap == null) { |
|||
headerMap = new LinkedHashMap<>(16); |
|||
} |
|||
headerMap.put(key, value); |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 初始化get方法 |
|||
* |
|||
* @return |
|||
*/ |
|||
public OkHttpUtils get() { |
|||
request = new Request.Builder().get(); |
|||
StringBuilder urlBuilder = new StringBuilder(url); |
|||
if (paramMap != null) { |
|||
urlBuilder.append("?"); |
|||
try { |
|||
for (Map.Entry<String, String> entry : paramMap.entrySet()) { |
|||
urlBuilder.append(URLEncoder.encode(entry.getKey(), "utf-8")). |
|||
append("="). |
|||
append(URLEncoder.encode(entry.getValue(), "utf-8")). |
|||
append("&"); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
urlBuilder.deleteCharAt(urlBuilder.length() - 1); |
|||
} |
|||
request.url(urlBuilder.toString()); |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 初始化post方法 |
|||
* |
|||
* @param isJsonPost true等于json的方式提交数据,类似postman里post方法的raw |
|||
* false等于普通的表单提交 |
|||
* @return |
|||
*/ |
|||
public OkHttpUtils post(boolean isJsonPost) { |
|||
RequestBody requestBody; |
|||
if (isJsonPost) { |
|||
String json = ""; |
|||
if (paramMap != null) { |
|||
json = JSON.toJSONString(paramMap); |
|||
} |
|||
requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json); |
|||
} else { |
|||
FormBody.Builder formBody = new FormBody.Builder(); |
|||
if (paramMap != null) { |
|||
paramMap.forEach(formBody::add); |
|||
} |
|||
requestBody = formBody.build(); |
|||
} |
|||
request = new Request.Builder().post(requestBody).url(url); |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 同步请求 |
|||
* |
|||
* @return |
|||
*/ |
|||
public String sync() { |
|||
setHeader(request); |
|||
try { |
|||
Response response = okHttpClient.newCall(request.build()).execute(); |
|||
assert response.body() != null; |
|||
return response.body().string(); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
return "请求失败:" + e.getMessage(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 异步请求,有返回值 |
|||
*/ |
|||
public String async() { |
|||
StringBuilder buffer = new StringBuilder(""); |
|||
setHeader(request); |
|||
okHttpClient.newCall(request.build()).enqueue(new Callback() { |
|||
@Override |
|||
public void onFailure(Call call, IOException e) { |
|||
buffer.append("请求出错:").append(e.getMessage()); |
|||
} |
|||
|
|||
@Override |
|||
public void onResponse(Call call, Response response) throws IOException { |
|||
assert response.body() != null; |
|||
buffer.append(response.body().string()); |
|||
getSemaphoreInstance().release(); |
|||
} |
|||
}); |
|||
try { |
|||
getSemaphoreInstance().acquire(); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return buffer.toString(); |
|||
} |
|||
|
|||
/** |
|||
* 异步请求,带有接口回调 |
|||
* |
|||
* @param callBack |
|||
*/ |
|||
public void async(ICallBack callBack) { |
|||
setHeader(request); |
|||
okHttpClient.newCall(request.build()).enqueue(new Callback() { |
|||
@Override |
|||
public void onFailure(Call call, IOException e) { |
|||
callBack.onFailure(call, e.getMessage()); |
|||
} |
|||
|
|||
@Override |
|||
public void onResponse(Call call, Response response) throws IOException { |
|||
assert response.body() != null; |
|||
callBack.onSuccessful(call, response.body().string()); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* 为request添加请求头 |
|||
* |
|||
* @param request |
|||
*/ |
|||
private void setHeader(Request.Builder request) { |
|||
if (headerMap != null) { |
|||
try { |
|||
for (Map.Entry<String, String> entry : headerMap.entrySet()) { |
|||
request.addHeader(entry.getKey(), entry.getValue()); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 生成安全套接字工厂,用于https请求的证书跳过 |
|||
* |
|||
* @return |
|||
*/ |
|||
private static SSLSocketFactory createSSLSocketFactory(TrustManager[] trustAllCerts) { |
|||
SSLSocketFactory ssfFactory = null; |
|||
try { |
|||
SSLContext sc = SSLContext.getInstance("SSL"); |
|||
sc.init(null, trustAllCerts, new SecureRandom()); |
|||
ssfFactory = sc.getSocketFactory(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return ssfFactory; |
|||
} |
|||
|
|||
private static TrustManager[] buildTrustManagers() { |
|||
return new TrustManager[]{ |
|||
new X509TrustManager() { |
|||
@Override |
|||
public void checkClientTrusted(X509Certificate[] chain, String authType) { |
|||
} |
|||
|
|||
@Override |
|||
public void checkServerTrusted(X509Certificate[] chain, String authType) { |
|||
} |
|||
|
|||
@Override |
|||
public X509Certificate[] getAcceptedIssuers() { |
|||
return new X509Certificate[]{}; |
|||
} |
|||
} |
|||
}; |
|||
} |
|||
|
|||
/** |
|||
* 自定义一个接口回调 |
|||
*/ |
|||
public interface ICallBack { |
|||
void onSuccessful(Call call, String data); |
|||
|
|||
void onFailure(Call call, String errorMsg); |
|||
} |
|||
|
|||
/*****************************使用教程************************************************************/ |
|||
|
|||
public static void main(String[] args) { |
|||
// get请求,方法顺序按照这种方式,切记选择post/get一定要放在倒数第二,同步或者异步倒数第一,才会正确执行
|
|||
OkHttpUtils.builder().url("请求地址,http/https都可以") |
|||
// 有参数的话添加参数,可多个
|
|||
.addParam("参数名", "参数值") |
|||
.addParam("参数名", "参数值") |
|||
// 也可以添加多个
|
|||
.addHeader("Content-Type", "application/json; charset=utf-8") |
|||
.get() |
|||
// 可选择是同步请求还是异步请求
|
|||
//.async();
|
|||
.sync(); |
|||
|
|||
// post请求,分为两种,一种是普通表单提交,一种是json提交
|
|||
OkHttpUtils.builder().url("请求地址,http/https都可以") |
|||
// 有参数的话添加参数,可多个
|
|||
.addParam("参数名", "参数值") |
|||
.addParam("参数名", "参数值") |
|||
// 也可以添加多个
|
|||
.addHeader("Content-Type", "application/json; charset=utf-8") |
|||
// 如果是true的话,会类似于postman中post提交方式的raw,用json的方式提交,不是表单
|
|||
// 如果是false的话传统的表单提交
|
|||
.post(true) |
|||
.sync(); |
|||
|
|||
// 选择异步有两个方法,一个是带回调接口,一个是直接返回结果
|
|||
OkHttpUtils.builder().url("") |
|||
.post(false) |
|||
.async(); |
|||
|
|||
OkHttpUtils.builder().url("").post(false).async(new ICallBack() { |
|||
@Override |
|||
public void onSuccessful(Call call, String data) { |
|||
// 请求成功后的处理
|
|||
} |
|||
|
|||
@Override |
|||
public void onFailure(Call call, String errorMsg) { |
|||
// 请求失败后的处理
|
|||
} |
|||
}); |
|||
} |
|||
|
|||
} |
@ -1,85 +0,0 @@ |
|||
package com.yxt.demo.common.utils.jwt; |
|||
|
|||
import io.jsonwebtoken.Jwts; |
|||
import io.jsonwebtoken.SignatureAlgorithm; |
|||
|
|||
import java.util.Date; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2021/11/6 22:55 |
|||
* @Description |
|||
*/ |
|||
public class JwtUtils { |
|||
|
|||
/** |
|||
* 签名密钥(高度保密) |
|||
*/ |
|||
private static final String SECRET = "qYYjXt7s1C*nEC%9RCwQGFA$YwPr$Jrj"; |
|||
/** |
|||
* 签名算法 |
|||
*/ |
|||
private static final SignatureAlgorithm SIGNATURE_ALGORITHM = SignatureAlgorithm.HS512; |
|||
/** |
|||
* token前缀 |
|||
*/ |
|||
private static final String TOKEN_PREFIX = "Bearer "; |
|||
/** |
|||
* 有效期:1天 |
|||
*/ |
|||
private static final Long TIME = 24 * 3600 * 1000L; |
|||
|
|||
/** |
|||
* 生成JWT token |
|||
* |
|||
* @param map 传入数据 |
|||
* @return |
|||
*/ |
|||
public static String sign(Map<String, Object> map) { |
|||
Date now = new Date(System.currentTimeMillis()); |
|||
String jwt = Jwts.builder() |
|||
// 设置自定义数据
|
|||
.setClaims(map) |
|||
// 设置签发时间
|
|||
.setIssuedAt(now) |
|||
// 设置过期时间
|
|||
.setExpiration(new Date(now.getTime() + TIME)) |
|||
.signWith(SIGNATURE_ALGORITHM, SECRET) |
|||
.compact(); |
|||
return TOKEN_PREFIX + jwt; |
|||
} |
|||
|
|||
/** |
|||
* 验证JWT token并返回数据。当验证失败时,抛出异常 |
|||
* |
|||
* @param token token |
|||
* @return |
|||
*/ |
|||
public static Map unSign(String token) { |
|||
try { |
|||
return Jwts.parser() |
|||
.setSigningKey(SECRET) |
|||
.parseClaimsJws(token.replace(TOKEN_PREFIX, "")) |
|||
.getBody(); |
|||
} catch (Exception e) { |
|||
throw new IllegalStateException("Token验证失败:" + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
public static void main(String[] args) { |
|||
/* Map<String, Object> map = new HashMap<>(); |
|||
map.put("userName", "admin"); |
|||
map.put("userId", "001"); |
|||
String token = JwtUtils.sign(map, 3600_000); |
|||
System.out.println(JwtUtils.unSign(token));*/ |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("userSid", "123456788"); |
|||
map.put("userName", "你好"); |
|||
// sign(map);
|
|||
// System.out.println(sign(map));
|
|||
Map<String,Object> map1 = unSign("Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyU2lkIjoiMTIzNDU2Nzg4IiwidXNlck5hbWUiOiLkvaDlpb0iLCJleHAiOjE2MzYyOTk0NTgsImlhdCI6MTYzNjIxMzA1OH0.iuyZznSCm0QYneqfck_zc3fpg57YsAdG8k2aLrDY_4NZJwJdVxE7supqLtfEvTC5O0EhG590ShhRsVoU-rbSrA"); |
|||
System.out.println(map1); |
|||
} |
|||
} |
@ -1,21 +0,0 @@ |
|||
package com.yxt.demo.system.api.sys_forum; |
|||
|
|||
import com.yxt.demo.system.api.dict_type.DictTypeFeignFallback; |
|||
import io.swagger.annotations.Api; |
|||
import org.springframework.cloud.openfeign.FeignClient; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 14:21 |
|||
* @Description |
|||
*/ |
|||
@Api(tags = "论坛") |
|||
@FeignClient( |
|||
contextId = "demo-system-SysForum", |
|||
name = "demo-system", |
|||
path = "v1/sysforum", |
|||
fallback = SysForumFeignFallback.class) |
|||
public interface SysForumFeign { |
|||
|
|||
|
|||
} |
@ -1,19 +0,0 @@ |
|||
package com.yxt.demo.system.api.sys_forum_comment; |
|||
|
|||
import com.yxt.demo.system.api.sys_forum.SysForumFeignFallback; |
|||
import io.swagger.annotations.Api; |
|||
import org.springframework.cloud.openfeign.FeignClient; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 14:22 |
|||
* @Description |
|||
*/ |
|||
@Api(tags = "论坛评论") |
|||
@FeignClient( |
|||
contextId = "demo-system-SysForumComment", |
|||
name = "demo-system", |
|||
path = "v1/SysForumComment", |
|||
fallback = SysForumCommentFeignFallback.class) |
|||
public interface SysForumCommentFeign { |
|||
} |
@ -1,19 +0,0 @@ |
|||
package com.yxt.demo.system.api.sys_info; |
|||
|
|||
import com.yxt.demo.system.api.sys_user.SysUserFeignFallback; |
|||
import io.swagger.annotations.Api; |
|||
import org.springframework.cloud.openfeign.FeignClient; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 11:50 |
|||
* @Description |
|||
*/ |
|||
@Api(tags = "基础信息") |
|||
@FeignClient( |
|||
contextId = "demo-system-SysInfo", |
|||
name = "demo-system", |
|||
path = "v1/sysinfo", |
|||
fallback = SysInfoFeignFallback.class) |
|||
public interface SysInfoFeign { |
|||
} |
@ -1,19 +0,0 @@ |
|||
package com.yxt.demo.system.api.sys_notice; |
|||
|
|||
import com.yxt.demo.system.api.dict_type.DictTypeFeignFallback; |
|||
import io.swagger.annotations.Api; |
|||
import org.springframework.cloud.openfeign.FeignClient; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 14:23 |
|||
* @Description |
|||
*/ |
|||
@Api(tags = "公告") |
|||
@FeignClient( |
|||
contextId = "demo-system-SysNotice", |
|||
name = "demo-system", |
|||
path = "v1/SysNotice", |
|||
fallback = SysNoticeFeignFallback.class) |
|||
public interface SysNoticeFeign { |
|||
} |
@ -1,28 +0,0 @@ |
|||
package com.yxt.demo.system.api.sys_role; |
|||
|
|||
import com.yxt.demo.common.core.result.ResultBean; |
|||
import com.yxt.demo.system.api.sys_user.SysUserDto; |
|||
import com.yxt.demo.system.api.sys_user.SysUserFeignFallback; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.springframework.cloud.openfeign.FeignClient; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 14:27 |
|||
* @Description |
|||
*/ |
|||
@Api(tags = "角色表") |
|||
@FeignClient( |
|||
contextId = "demo-system-SysRole", |
|||
name = "demo-system", |
|||
path = "v1/sysrole", |
|||
fallback = SysRoleFeignFallback.class) |
|||
public interface SysRoleFeign { |
|||
|
|||
@ApiOperation(value = "添加角色") |
|||
@PostMapping("/addRole") |
|||
ResultBean addRole(@RequestBody SysRole sysRole); |
|||
} |
@ -1,7 +1,7 @@ |
|||
package com.yxt.demo.system.api.dict_common; |
|||
|
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.dict_type; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_forum; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -0,0 +1,14 @@ |
|||
package com.yxt.demo.system.api.sys_forum; |
|||
|
|||
import io.swagger.annotations.Api; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 14:21 |
|||
* @Description |
|||
*/ |
|||
@Api(tags = "论坛") |
|||
public interface SysForumFeign { |
|||
|
|||
|
|||
} |
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_forum_comment; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -0,0 +1,12 @@ |
|||
package com.yxt.demo.system.api.sys_forum_comment; |
|||
|
|||
import io.swagger.annotations.Api; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 14:22 |
|||
* @Description |
|||
*/ |
|||
@Api(tags = "论坛评论") |
|||
public interface SysForumCommentFeign { |
|||
} |
@ -0,0 +1,40 @@ |
|||
package com.yxt.demo.system.api.sys_info; |
|||
|
|||
import com.yxt.demo.common.core.query.PagerQuery; |
|||
import com.yxt.demo.common.core.vo.PagerVo; |
|||
import com.yxt.demo.system.api.dict_type.DictTypeQuery; |
|||
import com.yxt.demo.system.api.dict_type.DictTypeVo; |
|||
import com.yxt.demo.system.api.sys_user.SysUserDto; |
|||
import com.yxt.demo.system.utils.ResultBean; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import org.springframework.web.bind.annotation.PathVariable; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 11:50 |
|||
* @Description |
|||
*/ |
|||
@Api(tags = "基础信息表") |
|||
public interface SysInfoFeign { |
|||
|
|||
@ApiOperation(value = "修改基础信息") |
|||
@PostMapping("/alterInfo") |
|||
ResultBean alterInfo(@RequestBody SysInfo sysInfo); |
|||
|
|||
@ApiOperation(value = "查询基本信息") |
|||
@RequestMapping("/selectInfo") |
|||
ResultBean selectInfoOne(@RequestBody SysInfoPageCount sysInfoPageCount); |
|||
|
|||
@ApiOperation(value = "删除基本信息") |
|||
@RequestMapping("/deleteInfo") |
|||
ResultBean deleteInfo(@ApiParam(value = "sid", required = true) @PathVariable("sid") String sid); |
|||
|
|||
@ApiOperation(value = "添加基本信息") |
|||
@RequestMapping("/saveInfo") |
|||
ResultBean saveInfo(@RequestBody SysInfo sysInfo); |
|||
} |
@ -0,0 +1,18 @@ |
|||
package com.yxt.demo.system.api.sys_info; |
|||
|
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author shkstart |
|||
* @create 2023-04-26-15:54 |
|||
*/ |
|||
@Data |
|||
public class SysInfoPageCount { |
|||
@ApiModelProperty(value = "基础信息sid") |
|||
private String sid; |
|||
@ApiModelProperty(value = "开始条数") |
|||
private Integer from; |
|||
@ApiModelProperty(value = "显示条数") |
|||
private Integer to; |
|||
} |
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_info_ship; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_menu; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_menu_role; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_notice; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -0,0 +1,12 @@ |
|||
package com.yxt.demo.system.api.sys_notice; |
|||
|
|||
import io.swagger.annotations.Api; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 14:23 |
|||
* @Description |
|||
*/ |
|||
@Api(tags = "公告") |
|||
public interface SysNoticeFeign { |
|||
} |
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_plan; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_plan_schedule; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_resources; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import lombok.Data; |
|||
|
|||
/** |
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_role; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -0,0 +1,38 @@ |
|||
package com.yxt.demo.system.api.sys_role; |
|||
import com.yxt.demo.system.utils.ResultBean; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import org.springframework.web.bind.annotation.PathVariable; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 14:27 |
|||
* @Description |
|||
*/ |
|||
@Api(tags = "角色表") |
|||
public interface SysRoleFeign { |
|||
|
|||
@ApiOperation(value = "添加角色") |
|||
@PostMapping("/addRole") |
|||
ResultBean addRole(@RequestBody SysRole sysRole); |
|||
|
|||
@ApiOperation(value = "删除角色") |
|||
@PostMapping("/deleteRole/{sid}") |
|||
ResultBean deleteRole(@ApiParam(value = "sid", required = true) @PathVariable("sid") String sid); |
|||
|
|||
@ApiOperation(value = "查询角色") |
|||
@PostMapping("/RoleOne/{sid}") |
|||
ResultBean RoleOne(@ApiParam(value = "sid", required = true) @PathVariable("sid") String sid); |
|||
|
|||
@ApiOperation(value = "查询多角色") |
|||
@PostMapping("/RoleOne") |
|||
ResultBean RoleList(); |
|||
|
|||
@ApiOperation(value = "修改角色") |
|||
@RequestMapping("/alterRole") |
|||
ResultBean alterRole(@RequestBody SysRole sysRole); |
|||
} |
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_score; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_student_score; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -1,6 +1,7 @@ |
|||
package com.yxt.demo.system.api.sys_user; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
|
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -1,6 +1,6 @@ |
|||
package com.yxt.demo.system.api.sys_user_role; |
|||
|
|||
import com.yxt.demo.common.core.domain.BaseEntity; |
|||
import com.yxt.demo.system.utils.BaseEntity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
@ -0,0 +1,29 @@ |
|||
package com.yxt.demo.system.api.sys_user_role; |
|||
|
|||
import com.yxt.demo.system.utils.ResultBean; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import org.springframework.web.bind.annotation.PathVariable; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
|
|||
/** |
|||
* @author shkstart |
|||
* @create 2023-04-26-14:31 |
|||
*/ |
|||
@Api(tags = "用户角色关联表") |
|||
public interface SysUserRoleFeign { |
|||
|
|||
@ApiOperation(value = "给用户分配角色") |
|||
@RequestMapping("/addUserRole") |
|||
ResultBean addUserRole(@RequestBody SysUserRole sysUserRole); |
|||
|
|||
@ApiOperation(value = "修改用户角色") |
|||
@RequestMapping("/alterUserRole") |
|||
ResultBean alterUserRole(@RequestBody SysUserRole sysUserRole); |
|||
|
|||
@ApiOperation(value = "删除该用户角色") |
|||
@RequestMapping("/deleteUserRoleById") |
|||
ResultBean deleteUserRoleById(@ApiParam(value = "sid", required = true) @PathVariable("sid") String sid); |
|||
} |
@ -1,9 +1,12 @@ |
|||
package com.yxt.demo.system.biz.sys_forum; |
|||
|
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 14:21 |
|||
* @Description |
|||
*/ |
|||
@Mapper |
|||
public interface SysForumMapper { |
|||
} |
|||
|
@ -1,4 +1,4 @@ |
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
|||
<mapper namespace=""> |
|||
<mapper namespace="com.yxt.demo.system.biz.sys_forum.SysForumMapper"> |
|||
</mapper> |
@ -1,4 +1,4 @@ |
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
|||
<mapper namespace=""> |
|||
<mapper namespace="com.yxt.demo.system.biz.sys_plan.SysPlanMapper"> |
|||
</mapper> |
@ -1,7 +1,11 @@ |
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
|||
<mapper namespace="com.yxt.demo.system.biz.sys_role.SysRoleMapper"> |
|||
<select id="selectRole" resultType="com.yxt.demo.system.biz.sys_role.SysRoleMapper"> |
|||
select count(*) from sys_role where name == #{name} |
|||
<select id="selectRole" resultType="com.yxt.demo.system.api.sys_role.SysRoleDto"> |
|||
select * from sys_role where name == #{name} |
|||
</select> |
|||
|
|||
<select id="selectRoleList" resultType="com.yxt.demo.system.api.sys_role.SysRoleDto"> |
|||
select * from sys_role |
|||
</select> |
|||
</mapper> |
@ -1,28 +1,83 @@ |
|||
package com.yxt.demo.system.biz.sys_role; |
|||
|
|||
import com.yxt.demo.common.core.result.ResultBean; |
|||
import com.yxt.demo.system.api.sys_role.SysRole; |
|||
import com.yxt.demo.system.api.sys_role.SysRoleFeign; |
|||
import com.yxt.demo.system.api.sys_user.SysUser; |
|||
import com.yxt.demo.system.api.sys_user_role.SysUserRole; |
|||
import com.yxt.demo.system.biz.sys_user_role.SysUserRoleSerrvice; |
|||
import com.yxt.demo.system.utils.Const; |
|||
import com.yxt.demo.system.utils.ResultBean; |
|||
import io.swagger.annotations.Api; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 14:27 |
|||
* @Description |
|||
*/ |
|||
@Api(tags = "成绩表") |
|||
@Api(tags = "角色表") |
|||
@RestController |
|||
@RequestMapping("v1/sysrole") |
|||
public class SysRoleRest implements SysRoleFeign { |
|||
@Autowired |
|||
private SysRoleService sysRoleService; |
|||
|
|||
@Autowired |
|||
private SysUserRoleSerrvice sysUserRoleSerrvice; |
|||
//
|
|||
@Override |
|||
public ResultBean addRole(SysRole sysRole) { |
|||
return sysRoleService.addRole(sysRole); |
|||
} |
|||
|
|||
@Override |
|||
public ResultBean deleteRole(String sid){ |
|||
SysUser user = Const.getUser(); |
|||
ResultBean rb = ResultBean.fireFail(); |
|||
if (user.getType() == 2){ |
|||
SysRole sysRole = sysRoleService.fetchBySid(sid); |
|||
if (sysRole == null){ |
|||
return rb.setMsg("该角色不存在"); |
|||
} |
|||
List<SysUserRole> sysUserRoles = sysUserRoleSerrvice.selectSysUserRole(sid); |
|||
if (sysUserRoles.size() != 0){ |
|||
return rb.setMsg("该角色已有用户使用,不可删除"); |
|||
} |
|||
if (0 == sysRoleService.deleteBySid(sid)){ |
|||
return rb.setMsg("删除失败"); |
|||
} |
|||
return rb.success().setMsg("删除成功"); |
|||
}else { |
|||
return rb.setMsg("无权操作"); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public ResultBean RoleOne(String sid){ |
|||
ResultBean rb = ResultBean.fireFail(); |
|||
SysRole sysRole = sysRoleService.fetchBySid(sid); |
|||
if (sysRole != null){ |
|||
return rb.setData(sysRole); |
|||
}else { |
|||
return rb.setData("查询角色失败"); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public ResultBean RoleList(){ |
|||
ResultBean rb = ResultBean.fireFail(); |
|||
sysRoleService.selectRoleList(); |
|||
return rb.setMsg("查询角色失败"); |
|||
} |
|||
|
|||
@Override |
|||
public ResultBean alterRole(SysRole sysRole) { |
|||
return sysRoleService.alterRole(sysRole); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
@ -1,9 +1,18 @@ |
|||
package com.yxt.demo.system.biz.sys_user_role; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.yxt.demo.system.api.sys_user_role.SysUserRole; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author dimengzhe |
|||
* @Date 2023/4/24 14:31 |
|||
* @Description |
|||
*/ |
|||
public interface SysUserRoleMapper { |
|||
@Mapper |
|||
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> { |
|||
|
|||
List<SysUserRole> selectSysUserRole(String sid); |
|||
} |
|||
|
@ -1,4 +1,7 @@ |
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
|||
<mapper namespace="com.yxt.demo.system.biz.sys_user_role.SysUserRoleMapper"> |
|||
<select id="selectSysUserRole" resultType="com.yxt.demo.system.api.sys_user_role.SysUserRole"> |
|||
select * from sys_user_role |
|||
</select> |
|||
</mapper> |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue