update 优化代码生成 使用新 JsonUtils.parseMap 方法

2.X
疯狂的狮子li 3 years ago
parent c994e2c97b
commit f1c3e5d1ea

@ -1,5 +1,6 @@
package com.ruoyi.common.core.utils.ip; package com.ruoyi.common.core.utils.ip;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.net.NetUtil; import cn.hutool.core.net.NetUtil;
import cn.hutool.http.HtmlUtil; import cn.hutool.http.HtmlUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
@ -10,8 +11,6 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.Map;
/** /**
* *
* *
@ -47,9 +46,9 @@ public class AddressUtils {
log.error("获取地理位置异常 {}", ip); log.error("获取地理位置异常 {}", ip);
return UNKNOWN; return UNKNOWN;
} }
Map<String, String> obj = JsonUtils.parseMap(rspStr); Dict obj = JsonUtils.parseMap(rspStr);
String region = obj.get("pro"); String region = obj.getStr("pro");
String city = obj.get("city"); String city = obj.getStr("city");
return String.format("%s %s", region, city); return String.format("%s %s", region, city);
} catch (Exception e) { } catch (Exception e) {
log.error("获取地理位置异常 {}", ip); log.error("获取地理位置异常 {}", ip);

@ -2,6 +2,7 @@ package com.ruoyi.gen.service;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -382,12 +383,12 @@ public class GenTableServiceImpl implements IGenTableService {
public void validateEdit(GenTable genTable) { public void validateEdit(GenTable genTable) {
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
String options = JsonUtils.toJsonString(genTable.getParams()); String options = JsonUtils.toJsonString(genTable.getParams());
Map<String, String> paramsObj = JsonUtils.parseMap(options); Dict paramsObj = JsonUtils.parseMap(options);
if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_CODE))) { if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_CODE))) {
throw new ServiceException("树编码字段不能为空"); 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("树父编码字段不能为空"); throw new ServiceException("树父编码字段不能为空");
} else if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_NAME))) { } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_NAME))) {
throw new ServiceException("树名称字段不能为空"); throw new ServiceException("树名称字段不能为空");
} else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) { } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) {
if (StringUtils.isEmpty(genTable.getSubTableName())) { if (StringUtils.isEmpty(genTable.getSubTableName())) {
@ -445,13 +446,13 @@ public class GenTableServiceImpl implements IGenTableService {
* @param genTable * @param genTable
*/ */
public void setTableFromOptions(GenTable genTable) { public void setTableFromOptions(GenTable genTable) {
Map<String, String> paramsObj = JsonUtils.parseMap(genTable.getOptions()); Dict paramsObj = JsonUtils.parseMap(genTable.getOptions());
if (ObjectUtil.isNotNull(paramsObj)) { if (ObjectUtil.isNotNull(paramsObj)) {
String treeCode = paramsObj.get(GenConstants.TREE_CODE); String treeCode = paramsObj.getStr(GenConstants.TREE_CODE);
String treeParentCode = paramsObj.get(GenConstants.TREE_PARENT_CODE); String treeParentCode = paramsObj.getStr(GenConstants.TREE_PARENT_CODE);
String treeName = paramsObj.get(GenConstants.TREE_NAME); String treeName = paramsObj.getStr(GenConstants.TREE_NAME);
String parentMenuId = paramsObj.get(GenConstants.PARENT_MENU_ID); String parentMenuId = paramsObj.getStr(GenConstants.PARENT_MENU_ID);
String parentMenuName = paramsObj.get(GenConstants.PARENT_MENU_NAME); String parentMenuName = paramsObj.getStr(GenConstants.PARENT_MENU_NAME);
genTable.setTreeCode(treeCode); genTable.setTreeCode(treeCode);
genTable.setTreeParentCode(treeParentCode); genTable.setTreeParentCode(treeParentCode);

@ -2,6 +2,7 @@ package com.ruoyi.gen.util;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.constant.GenConstants; import com.ruoyi.common.core.constant.GenConstants;
import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.DateUtils;
@ -19,6 +20,7 @@ import java.util.*;
* @author ruoyi * @author ruoyi
*/ */
public class VelocityUtils { public class VelocityUtils {
/** /**
* *
*/ */
@ -77,14 +79,14 @@ public class VelocityUtils {
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions(); String options = genTable.getOptions();
Map<String, Object> paramsObj = JsonUtils.parseMap(options); Dict paramsObj = JsonUtils.parseMap(options);
String parentMenuId = getParentMenuId(paramsObj); String parentMenuId = getParentMenuId(paramsObj);
context.put("parentMenuId", parentMenuId); context.put("parentMenuId", parentMenuId);
} }
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) { public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions(); String options = genTable.getOptions();
Map<String, Object> paramsObj = JsonUtils.parseMap(options); Dict paramsObj = JsonUtils.parseMap(options);
String treeCode = getTreecode(paramsObj); String treeCode = getTreecode(paramsObj);
String treeParentCode = getTreeParentCode(paramsObj); String treeParentCode = getTreeParentCode(paramsObj);
String treeName = getTreeName(paramsObj); String treeName = getTreeName(paramsObj);
@ -243,8 +245,8 @@ public class VelocityUtils {
Set<String> dicts = new HashSet<String>(); Set<String> dicts = new HashSet<String>();
for (GenTableColumn column : columns) { for (GenTableColumn column : columns) {
if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny( if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny(
column.getHtmlType(), column.getHtmlType(),
new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) { new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) {
dicts.add("'" + column.getDictType() + "'"); dicts.add("'" + column.getDictType() + "'");
} }
} }
@ -268,10 +270,10 @@ public class VelocityUtils {
* @param paramsObj * @param paramsObj
* @return ID * @return ID
*/ */
public static String getParentMenuId(Map<String, Object> paramsObj) { public static String getParentMenuId(Dict paramsObj) {
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID) if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)
&& StringUtils.isNotEmpty(Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID)))) { && StringUtils.isNotEmpty(paramsObj.getStr(GenConstants.PARENT_MENU_ID))) {
return Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID)); return paramsObj.getStr(GenConstants.PARENT_MENU_ID);
} }
return DEFAULT_PARENT_MENU_ID; return DEFAULT_PARENT_MENU_ID;
} }
@ -295,9 +297,9 @@ public class VelocityUtils {
* @param paramsObj * @param paramsObj
* @return * @return
*/ */
public static String getTreeParentCode(Map<String, Object> paramsObj) { public static String getTreeParentCode(Dict paramsObj) {
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { 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; return StringUtils.EMPTY;
} }
@ -308,9 +310,9 @@ public class VelocityUtils {
* @param paramsObj * @param paramsObj
* @return * @return
*/ */
public static String getTreeName(Map<String, Object> paramsObj) { public static String getTreeName(Dict paramsObj) {
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) { 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; return StringUtils.EMPTY;
} }
@ -323,8 +325,8 @@ public class VelocityUtils {
*/ */
public static int getExpandColumn(GenTable genTable) { public static int getExpandColumn(GenTable genTable) {
String options = genTable.getOptions(); String options = genTable.getOptions();
Map<String, Object> paramsObj = JsonUtils.parseMap(options); Dict paramsObj = JsonUtils.parseMap(options);
String treeName = Convert.toStr(paramsObj.get(GenConstants.TREE_NAME)); String treeName = paramsObj.getStr(GenConstants.TREE_NAME);
int num = 0; int num = 0;
for (GenTableColumn column : genTable.getColumns()) { for (GenTableColumn column : genTable.getColumns()) {
if (column.isList()) { if (column.isList()) {

Loading…
Cancel
Save