From 80b6cbfc9c861469146318d0b3dd5f8b8b525b8a Mon Sep 17 00:00:00 2001 From: xiejun <xiejun@vci-tech.com> Date: 星期五, 01 十一月 2024 15:11:19 +0800 Subject: [PATCH] Revert "集成获取mdm分发通用数据格式接口集成" --- Source/BladeX-Tool/blade-starter-mybatis/src/main/java/org/springblade/core/mp/support/SqlKeyword.java | 130 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 130 insertions(+), 0 deletions(-) diff --git a/Source/BladeX-Tool/blade-starter-mybatis/src/main/java/org/springblade/core/mp/support/SqlKeyword.java b/Source/BladeX-Tool/blade-starter-mybatis/src/main/java/org/springblade/core/mp/support/SqlKeyword.java new file mode 100644 index 0000000..2627533 --- /dev/null +++ b/Source/BladeX-Tool/blade-starter-mybatis/src/main/java/org/springblade/core/mp/support/SqlKeyword.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 搴勯獮 (smallchill@163.com) + */ +package org.springblade.core.mp.support; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringPool; +import org.springblade.core.tool.utils.StringUtil; + +import java.util.Map; + +/** + * 瀹氫箟甯哥敤鐨� sql鍏抽敭瀛� + * + * @author Chill + */ +public class SqlKeyword { + private final static String SQL_REGEX = "'|%|--|insert|delete|select|count|group|union|drop|truncate|alter|grant|execute|exec|xp_cmdshell|call|declare|sql"; + + private static final String EQUAL = "_equal"; + private static final String NOT_EQUAL = "_notequal"; + private static final String LIKE = "_like"; + private static final String LIKE_LEFT = "_likeleft"; + private static final String LIKE_RIGHT = "_likeright"; + private static final String NOT_LIKE = "_notlike"; + private static final String GE = "_ge"; + private static final String LE = "_le"; + private static final String GT = "_gt"; + private static final String LT = "_lt"; + private static final String DATE_GE = "_datege"; + private static final String DATE_GT = "_dategt"; + private static final String DATE_EQUAL = "_dateequal"; + private static final String DATE_LT = "_datelt"; + private static final String DATE_LE = "_datele"; + private static final String IS_NULL = "_null"; + private static final String NOT_NULL = "_notnull"; + private static final String IGNORE = "_ignore"; + + /** + * 鏉′欢鏋勯�犲櫒 + * + * @param query 鏌ヨ瀛楁 + * @param qw 鏌ヨ鍖呰绫� + */ + public static void buildCondition(Map<String, Object> query, QueryWrapper<?> qw) { + if (Func.isEmpty(query)) { + return; + } + query.forEach((k, v) -> { + if (Func.hasEmpty(k, v) || k.endsWith(IGNORE)) { + return; + } + if (k.endsWith(EQUAL)) { + qw.eq(getColumn(k, EQUAL), v); + } else if (k.endsWith(NOT_EQUAL)) { + qw.ne(getColumn(k, NOT_EQUAL), v); + } else if (k.endsWith(LIKE_LEFT)) { + qw.likeLeft(getColumn(k, LIKE_LEFT), v); + } else if (k.endsWith(LIKE_RIGHT)) { + qw.likeRight(getColumn(k, LIKE_RIGHT), v); + } else if (k.endsWith(NOT_LIKE)) { + qw.notLike(getColumn(k, NOT_LIKE), v); + } else if (k.endsWith(GE)) { + qw.ge(getColumn(k, GE), v); + } else if (k.endsWith(LE)) { + qw.le(getColumn(k, LE), v); + } else if (k.endsWith(GT)) { + qw.gt(getColumn(k, GT), v); + } else if (k.endsWith(LT)) { + qw.lt(getColumn(k, LT), v); + } else if (k.endsWith(DATE_GE)) { + qw.ge(getColumn(k, DATE_GE), DateUtil.parse(String.valueOf(v), DateUtil.PATTERN_DATETIME)); + } else if (k.endsWith(DATE_GT)) { + qw.gt(getColumn(k, DATE_GT), DateUtil.parse(String.valueOf(v), DateUtil.PATTERN_DATETIME)); + } else if (k.endsWith(DATE_EQUAL)) { + qw.eq(getColumn(k, DATE_EQUAL), DateUtil.parse(String.valueOf(v), DateUtil.PATTERN_DATETIME)); + } else if (k.endsWith(DATE_LE)) { + qw.le(getColumn(k, DATE_LE), DateUtil.parse(String.valueOf(v), DateUtil.PATTERN_DATETIME)); + } else if (k.endsWith(DATE_LT)) { + qw.lt(getColumn(k, DATE_LT), DateUtil.parse(String.valueOf(v), DateUtil.PATTERN_DATETIME)); + } else if (k.endsWith(IS_NULL)) { + qw.isNull(getColumn(k, IS_NULL)); + } else if (k.endsWith(NOT_NULL)) { + qw.isNotNull(getColumn(k, NOT_NULL)); + } else { + qw.like(getColumn(k, LIKE), v); + } + }); + } + + /** + * 鑾峰彇鏁版嵁搴撳瓧娈� + * + * @param column 瀛楁鍚� + * @param keyword 鍏抽敭瀛� + * @return + */ + private static String getColumn(String column, String keyword) { + return StringUtil.humpToUnderline(StringUtil.removeSuffix(column, keyword)); + } + + /** + * 鎶奡QL鍏抽敭瀛楁浛鎹负绌哄瓧绗︿覆 + * + * @param param 鍏抽敭瀛� + * @return string + */ + public static String filter(String param) { + if (param == null) { + return null; + } + return param.replaceAll("(?i)" + SQL_REGEX, StringPool.EMPTY); + } + +} -- Gitblit v1.9.3