From f1c3e5d1ea16187504065a764c7ff06ff6a36e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Tue, 15 Feb 2022 12:16:29 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=20=E4=BD=BF=E7=94=A8=E6=96=B0=20JsonUtils.pa?= =?UTF-8?q?rseMap=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/utils/ip/AddressUtils.java | 9 +++--- .../gen/service/GenTableServiceImpl.java | 21 +++++++------- .../com/ruoyi/gen/util/VelocityUtils.java | 28 ++++++++++--------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ip/AddressUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ip/AddressUtils.java index 8bf6ffdf..9317e78e 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ip/AddressUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ip/AddressUtils.java @@ -1,5 +1,6 @@ package com.ruoyi.common.core.utils.ip; +import cn.hutool.core.lang.Dict; import cn.hutool.core.net.NetUtil; import cn.hutool.http.HtmlUtil; import cn.hutool.http.HttpUtil; @@ -10,8 +11,6 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import java.util.Map; - /** * 获取地址类 * @@ -47,9 +46,9 @@ public class AddressUtils { log.error("获取地理位置异常 {}", ip); return UNKNOWN; } - Map obj = JsonUtils.parseMap(rspStr); - String region = obj.get("pro"); - String city = obj.get("city"); + Dict obj = JsonUtils.parseMap(rspStr); + String region = obj.getStr("pro"); + String city = obj.getStr("city"); return String.format("%s %s", region, city); } catch (Exception e) { log.error("获取地理位置异常 {}", ip); diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java index 6e08bb0f..f16c77e9 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java @@ -2,6 +2,7 @@ package com.ruoyi.gen.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.IoUtil; +import cn.hutool.core.lang.Dict; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -382,12 +383,12 @@ public class GenTableServiceImpl implements IGenTableService { public void validateEdit(GenTable genTable) { if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { String options = JsonUtils.toJsonString(genTable.getParams()); - Map paramsObj = JsonUtils.parseMap(options); - if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_CODE))) { + Dict paramsObj = JsonUtils.parseMap(options); + if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_CODE))) { throw new ServiceException("树编码字段不能为空"); - } else if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_PARENT_CODE))) { + } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_PARENT_CODE))) { throw new ServiceException("树父编码字段不能为空"); - } else if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_NAME))) { + } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_NAME))) { throw new ServiceException("树名称字段不能为空"); } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) { if (StringUtils.isEmpty(genTable.getSubTableName())) { @@ -445,13 +446,13 @@ public class GenTableServiceImpl implements IGenTableService { * @param genTable 设置后的生成对象 */ public void setTableFromOptions(GenTable genTable) { - Map paramsObj = JsonUtils.parseMap(genTable.getOptions()); + Dict paramsObj = JsonUtils.parseMap(genTable.getOptions()); if (ObjectUtil.isNotNull(paramsObj)) { - String treeCode = paramsObj.get(GenConstants.TREE_CODE); - String treeParentCode = paramsObj.get(GenConstants.TREE_PARENT_CODE); - String treeName = paramsObj.get(GenConstants.TREE_NAME); - String parentMenuId = paramsObj.get(GenConstants.PARENT_MENU_ID); - String parentMenuName = paramsObj.get(GenConstants.PARENT_MENU_NAME); + String treeCode = paramsObj.getStr(GenConstants.TREE_CODE); + String treeParentCode = paramsObj.getStr(GenConstants.TREE_PARENT_CODE); + String treeName = paramsObj.getStr(GenConstants.TREE_NAME); + String parentMenuId = paramsObj.getStr(GenConstants.PARENT_MENU_ID); + String parentMenuName = paramsObj.getStr(GenConstants.PARENT_MENU_NAME); genTable.setTreeCode(treeCode); genTable.setTreeParentCode(treeParentCode); diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java index 2fbeb9cf..844357c0 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java @@ -2,6 +2,7 @@ package com.ruoyi.gen.util; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.lang.Dict; import cn.hutool.core.util.ObjectUtil; import com.ruoyi.common.core.constant.GenConstants; import com.ruoyi.common.core.utils.DateUtils; @@ -19,6 +20,7 @@ import java.util.*; * @author ruoyi */ public class VelocityUtils { + /** * 项目空间路径 */ @@ -77,14 +79,14 @@ public class VelocityUtils { public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { String options = genTable.getOptions(); - Map paramsObj = JsonUtils.parseMap(options); + Dict paramsObj = JsonUtils.parseMap(options); String parentMenuId = getParentMenuId(paramsObj); context.put("parentMenuId", parentMenuId); } public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) { String options = genTable.getOptions(); - Map paramsObj = JsonUtils.parseMap(options); + Dict paramsObj = JsonUtils.parseMap(options); String treeCode = getTreecode(paramsObj); String treeParentCode = getTreeParentCode(paramsObj); String treeName = getTreeName(paramsObj); @@ -243,8 +245,8 @@ public class VelocityUtils { Set dicts = new HashSet(); for (GenTableColumn column : columns) { if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny( - column.getHtmlType(), - new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) { + column.getHtmlType(), + new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) { dicts.add("'" + column.getDictType() + "'"); } } @@ -268,10 +270,10 @@ public class VelocityUtils { * @param paramsObj 生成其他选项 * @return 上级菜单ID字段 */ - public static String getParentMenuId(Map paramsObj) { + public static String getParentMenuId(Dict paramsObj) { if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID) - && StringUtils.isNotEmpty(Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID)))) { - return Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID)); + && StringUtils.isNotEmpty(paramsObj.getStr(GenConstants.PARENT_MENU_ID))) { + return paramsObj.getStr(GenConstants.PARENT_MENU_ID); } return DEFAULT_PARENT_MENU_ID; } @@ -295,9 +297,9 @@ public class VelocityUtils { * @param paramsObj 生成其他选项 * @return 树父编码 */ - public static String getTreeParentCode(Map paramsObj) { + public static String getTreeParentCode(Dict paramsObj) { if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { - return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE))); + return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_PARENT_CODE)); } return StringUtils.EMPTY; } @@ -308,9 +310,9 @@ public class VelocityUtils { * @param paramsObj 生成其他选项 * @return 树名称 */ - public static String getTreeName(Map paramsObj) { + public static String getTreeName(Dict paramsObj) { if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) { - return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_NAME))); + return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_NAME)); } return StringUtils.EMPTY; } @@ -323,8 +325,8 @@ public class VelocityUtils { */ public static int getExpandColumn(GenTable genTable) { String options = genTable.getOptions(); - Map paramsObj = JsonUtils.parseMap(options); - String treeName = Convert.toStr(paramsObj.get(GenConstants.TREE_NAME)); + Dict paramsObj = JsonUtils.parseMap(options); + String treeName = paramsObj.getStr(GenConstants.TREE_NAME); int num = 0; for (GenTableColumn column : genTable.getColumns()) { if (column.isList()) {