修改查询

master
sugy 4 months ago
parent 1ac546abd9
commit b34345b0a4
  1. 5
      src/main/java/com/nov/KgLowDurable/controller/MenuController.java
  2. 11
      src/main/java/com/nov/KgLowDurable/controller/RoleController.java
  3. 2
      src/main/java/com/nov/KgLowDurable/service/IRoleService.java
  4. 15
      src/main/java/com/nov/KgLowDurable/service/Impl/LdDictServiceImpl.java
  5. 4
      src/main/java/com/nov/KgLowDurable/service/Impl/RoleServiceImpl.java
  6. 64
      src/main/java/com/nov/KgLowDurable/util/ConcurrentDateFormat.java
  7. 2
      src/main/java/com/nov/KgLowDurable/util/Condition.java
  8. 25
      src/main/java/com/nov/KgLowDurable/util/DateUtil.java
  9. 20
      src/main/java/com/nov/KgLowDurable/util/Func.java
  10. 14
      src/main/java/com/nov/KgLowDurable/util/ObjectUtil.java
  11. 109
      src/main/java/com/nov/KgLowDurable/util/SqlKeyword.java
  12. 53
      src/main/java/com/nov/KgLowDurable/util/StringUtil.java
  13. 1
      src/main/java/com/nov/KgLowDurable/wrapper/LdDictWrapper.java

@ -27,6 +27,7 @@ package com.nov.KgLowDurable.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.nov.KgLowDurable.common.TreeNode;
import com.nov.KgLowDurable.pojo.entity.Kv;
import com.nov.KgLowDurable.pojo.entity.Menu;
import com.nov.KgLowDurable.pojo.vo.MenuVO;
import com.nov.KgLowDurable.service.IMenuService;
@ -128,7 +129,9 @@ public class MenuController {
@ApiOperation(value = "新增或修改", notes = "传入menu")
public Result submit( @RequestBody Menu menu) {
if (menuService.submit(menu)) {
return Result.OK();
// 返回懒加载树更新节点所需字段
Kv kv = Kv.create().set("id", String.valueOf(menu.getId()));
return Result.OK(kv);
}
return Result.error("操作失败");
}

@ -147,11 +147,10 @@ public class RoleController {
/**
* 获取现有角色别名列表
*/
// @GetMapping("/alias")
// @ApiOperationSupport(order = 9)
// @Operation(summary = "获取角色别名", description = "获取角色别名")
// public R<List<Role>> alias() {
// return R.data(roleService.alias(AuthUtil.getTenantId()));
// }
@GetMapping("/alias")
@ApiOperation(value = "获取角色别名", notes = "获取角色别名")
public Result<List<Role>> alias() {
return Result.OK(roleService.alias());
}
}

@ -124,7 +124,7 @@ public interface IRoleService extends IService<Role> {
* @param tenantId 租户id
* @return 别名列表
*/
List<Role> alias(String tenantId);
List<Role> alias();
}

@ -36,10 +36,7 @@ import com.nov.KgLowDurable.mapper.LdDictMapper;
import com.nov.KgLowDurable.pojo.entity.LdDict;
import com.nov.KgLowDurable.pojo.vo.LdDictVO;
import com.nov.KgLowDurable.service.ILdDictService;
import com.nov.KgLowDurable.util.CommonConstant;
import com.nov.KgLowDurable.util.Condition;
import com.nov.KgLowDurable.util.ForestNodeMerger;
import com.nov.KgLowDurable.util.Query;
import com.nov.KgLowDurable.util.*;
import com.nov.KgLowDurable.wrapper.LdDictWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@ -89,7 +86,15 @@ public class LdDictServiceImpl extends ServiceImpl<LdDictMapper, LdDict> impleme
throw new MybatisPlusException("当前字典键值已存在!");
}
}
dict.setIsDeleted(0);
// 修改顶级字典后同步更新下属字典的编号
if (Func.isNotEmpty(dict.getId()) && dict.getParentId().longValue() == BladeConstant.TOP_PARENT_ID) {
LdDict parent = baseMapper.selectById(dict.getId());
this.update(Wrappers.<LdDict>update().lambda().set(LdDict::getCode, dict.getCode()).eq(LdDict::getCode, parent.getCode()).ne(LdDict::getParentId, BladeConstant.TOP_PARENT_ID));
}
if (Func.isEmpty(dict.getParentId())) {
dict.setParentId(BladeConstant.TOP_PARENT_ID);
}
dict.setIsDeleted(BladeConstant.DB_NOT_DELETED);
//CacheUtil.clear(DICT_CACHE, Boolean.FALSE);
return saveOrUpdate(dict);
}

@ -237,9 +237,9 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
}
@Override
public List<Role> alias(String tenantId) {
public List<Role> alias() {
// 获取所有角色数据
List<Role> roles = baseMapper.selectList(Wrappers.<Role>lambdaQuery().eq(Role::getTenantId, tenantId));
List<Role> roles = baseMapper.selectList(Wrappers.<Role>lambdaQuery());
// 根据 roleAlias 对角色进行分组
Map<String, List<String>> aliasToNamesMap = roles.stream()

@ -0,0 +1,64 @@
package com.nov.KgLowDurable.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Queue;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentLinkedQueue;
public class ConcurrentDateFormat {
private final String format;
private final Locale locale;
private final TimeZone timezone;
private final Queue<SimpleDateFormat> queue = new ConcurrentLinkedQueue();
private ConcurrentDateFormat(String format, Locale locale, TimeZone timezone) {
this.format = format;
this.locale = locale;
this.timezone = timezone;
SimpleDateFormat initial = this.createInstance();
this.queue.add(initial);
}
public static ConcurrentDateFormat of(String format) {
return new ConcurrentDateFormat(format, Locale.getDefault(), TimeZone.getDefault());
}
public static ConcurrentDateFormat of(String format, TimeZone timezone) {
return new ConcurrentDateFormat(format, Locale.getDefault(), timezone);
}
public static ConcurrentDateFormat of(String format, Locale locale, TimeZone timezone) {
return new ConcurrentDateFormat(format, locale, timezone);
}
public String format(Date date) {
SimpleDateFormat sdf = (SimpleDateFormat)this.queue.poll();
if (sdf == null) {
sdf = this.createInstance();
}
String result = sdf.format(date);
this.queue.add(sdf);
return result;
}
public Date parse(String source) throws ParseException {
SimpleDateFormat sdf = (SimpleDateFormat)this.queue.poll();
if (sdf == null) {
sdf = this.createInstance();
}
Date result = sdf.parse(source);
this.queue.add(sdf);
return result;
}
private SimpleDateFormat createInstance() {
SimpleDateFormat sdf = new SimpleDateFormat(this.format, this.locale);
sdf.setTimeZone(this.timezone);
return sdf;
}
}

@ -63,7 +63,7 @@ public class Condition {
});
QueryWrapper<T> qw = new QueryWrapper();
qw.setEntity(BeanUtil.newInstance(clazz));
buildCondition(query, qw);
SqlKeyword.buildCondition(query, qw);
return qw;
}
public static <T> Set<String> getClassFieldNames(Class<T> clazz) {

@ -0,0 +1,25 @@
package com.nov.KgLowDurable.util;
import com.nov.KgLowDurable.exception.CustomerException;
import java.text.ParseException;
import java.time.format.DateTimeFormatter;
import java.util.Date;
public class DateUtil {
public static final ConcurrentDateFormat DATETIME_FORMAT = ConcurrentDateFormat.of("yyyy-MM-dd HH:mm:ss");
public static final ConcurrentDateFormat DATETIME_MINI_FORMAT = ConcurrentDateFormat.of("yyyyMMddHHmmss");
public static final ConcurrentDateFormat DATE_FORMAT = ConcurrentDateFormat.of("yyyy-MM-dd");
public static final ConcurrentDateFormat TIME_FORMAT = ConcurrentDateFormat.of("HH:mm:ss");
public static Date parse(String dateStr, String pattern) {
ConcurrentDateFormat format = ConcurrentDateFormat.of(pattern);
try {
return format.parse(dateStr);
} catch (ParseException var4) {
throw new CustomerException("系统错误");
}
}
}

@ -70,4 +70,24 @@ public class Func {
public static List<String> toStrList(String str) {
return Arrays.asList(toStrArray(str));
}
public static boolean isEmpty(@Nullable Object obj) {
return ObjectUtil.isEmpty(obj);
}
public static boolean hasEmpty(Object... os) {
Object[] var1 = os;
int var2 = os.length;
for(int var3 = 0; var3 < var2; ++var3) {
Object o = var1[var3];
if (isEmpty(o)) {
return true;
}
}
return false;
}
public static boolean isNotEmpty(@Nullable Object obj) {
return !ObjectUtil.isEmpty(obj);
}
}

@ -0,0 +1,14 @@
package com.nov.KgLowDurable.util;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
public class ObjectUtil extends ObjectUtils {
public ObjectUtil() {
}
public static boolean isNotEmpty(@Nullable Object obj) {
return !isEmpty(obj);
}
}

@ -0,0 +1,109 @@
package com.nov.KgLowDurable.util;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nov.KgLowDurable.exception.CustomerException;
import java.sql.SQLException;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.regex.Pattern;
public class SqlKeyword {
private static final String SQL_REGEX = "(?i)(?<![a-z])('|%|--|insert|delete|select|sleep|count|update|updatexml|group|union|drop|truncate|alter|grant|execute|exec|xp_cmdshell|call|declare|sql)(?![a-z])";
private static final Pattern PATTERN = Pattern.compile("(?:--|[\"';%]|\\binsert\\b|\\bdelete\\b|\\bselect\\b|\\bcount\\b|\\bupdate\\b|\\bupdatexml\\b|\\bsleep\\b|group\\s+by|\\bunion\\b|\\bdrop\\b|\\btruncate\\b|\\balter\\b|\\bgrant\\b|\\bexecute\\b|\\bxp_cmdshell\\b|\\bcall\\b|\\bdeclare\\b|\\bsql\\b)");
private static final String SQL_INJECTION_MESSAGE = "SQL keyword injection prevention processing!";
private static final String SQL_EMPTY_MESSAGE = "SQL keyword is empty!";
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";
public SqlKeyword() {
}
public static void buildCondition(Map<String, Object> query, QueryWrapper<?> qw) {
if (!Func.isEmpty(query)) {
query.forEach((k, v) -> {
if (!Func.hasEmpty(new Object[]{k, v}) && !k.endsWith("_ignore")) {
k = filter(k);
if (k.endsWith("_equal")) {
qw.eq(getColumn(k, "_equal"), v);
} else if (k.endsWith("_notequal")) {
qw.ne(getColumn(k, "_notequal"), v);
} else if (k.endsWith("_likeleft")) {
qw.likeLeft(getColumn(k, "_likeleft"), v);
} else if (k.endsWith("_likeright")) {
qw.likeRight(getColumn(k, "_likeright"), v);
} else if (k.endsWith("_notlike")) {
qw.notLike(getColumn(k, "_notlike"), 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("_datege")) {
qw.ge(getColumn(k, "_datege"), DateUtil.parse(String.valueOf(v), "yyyy-MM-dd HH:mm:ss"));
} else if (k.endsWith("_dategt")) {
qw.gt(getColumn(k, "_dategt"), DateUtil.parse(String.valueOf(v), "yyyy-MM-dd HH:mm:ss"));
} else if (k.endsWith("_dateequal")) {
qw.eq(getColumn(k, "_dateequal"), DateUtil.parse(String.valueOf(v), "yyyy-MM-dd HH:mm:ss"));
} else if (k.endsWith("_datele")) {
qw.le(getColumn(k, "_datele"), DateUtil.parse(String.valueOf(v), "yyyy-MM-dd HH:mm:ss"));
} else if (k.endsWith("_datelt")) {
qw.lt(getColumn(k, "_datelt"), DateUtil.parse(String.valueOf(v), "yyyy-MM-dd HH:mm:ss"));
} else if (k.endsWith("_null")) {
qw.isNull(getColumn(k, "_null"));
} else if (k.endsWith("_notnull")) {
qw.isNotNull(getColumn(k, "_notnull"));
} else {
qw.like(getColumn(k, "_like"), v);
}
}
});
}
}
private static String getColumn(String column, String keyword) {
return StringUtil.humpToUnderline(StringUtil.removeSuffix(column, keyword));
}
public static String filter(String param) {
try {
String cleaned = StringUtil.cleanIdentifier(param);
if (cleaned == null) {
throw new SQLException("SQL keyword is empty!");
} else {
String sql = cleaned.replaceAll("(?i)(?<![a-z])('|%|--|insert|delete|select|sleep|count|update|updatexml|group|union|drop|truncate|alter|grant|execute|exec|xp_cmdshell|call|declare|sql)(?![a-z])", "");
if (match(sql)) {
throw new SQLException("SQL keyword injection prevention processing!");
} else {
return sql;
}
}
} catch (SQLException var3) {
throw new CustomerException("系统错误");
}
}
public static Boolean match(String param) {
return Func.isNotEmpty(param) && PATTERN.matcher(param).find();
}
}

@ -0,0 +1,53 @@
package com.nov.KgLowDurable.util;
import org.springframework.lang.Nullable;
import static com.baomidou.mybatisplus.core.toolkit.StringUtils.firstCharToLower;
import static com.nov.KgLowDurable.util.Condition.subPre;
import static com.nov.KgLowDurable.util.StringUtils.isBlank;
public class StringUtil {
public static String humpToUnderline(String para) {
if (isBlank(para)) {
return "";
} else {
para = firstCharToLower(para);
StringBuilder sb = new StringBuilder(para);
int temp = 0;
for(int i = 0; i < para.length(); ++i) {
if (Character.isUpperCase(para.charAt(i))) {
sb.insert(i + temp, "_");
++temp;
}
}
return sb.toString().toLowerCase();
}
}
public static String removeSuffix(CharSequence str, CharSequence suffix) {
if (!ObjectUtil.isEmpty(str) && !ObjectUtil.isEmpty(suffix)) {
String str2 = str.toString();
return str2.endsWith(suffix.toString()) ? subPre(str2, str2.length() - suffix.length()) : str2;
} else {
return "";
}
}
@Nullable
public static String cleanIdentifier(@Nullable String param) {
if (param == null) {
return null;
} else {
StringBuilder paramBuilder = new StringBuilder();
for(int i = 0; i < param.length(); ++i) {
char c = param.charAt(i);
if (Character.isJavaIdentifierPart(c)) {
paramBuilder.append(c);
}
}
return paramBuilder.toString();
}
}
}

@ -67,7 +67,6 @@ public class LdDictWrapper extends BaseEntityWrapper<LdDict, LdDictVO> {
public List listNodeVO(List<LdDict> list) {
List<LdDictVO> collect = list.stream().map(LdDict -> BeanUtil.copyProperties(LdDict, LdDictVO.class)).collect(Collectors.toList());
return ForestNodeMerger.mergeDict(collect);
//return collect;
}
}

Loading…
Cancel
Save