Search in sources :

Example 21 with Dict

use of cn.hutool.core.lang.Dict in project RuoYi-Vue-Plus by JavaLionLi.

the class AddressUtils method getRealAddressByIP.

public static String getRealAddressByIP(String ip) {
    String address = UNKNOWN;
    if (StringUtils.isBlank(ip)) {
        return address;
    }
    // 内网不查询
    ip = "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip);
    if (NetUtil.isInnerIP(ip)) {
        return "内网IP";
    }
    if (RuoYiConfig.isAddressEnabled()) {
        try {
            String rspStr = HttpUtil.createGet(IP_URL).body("ip=" + ip + "&json=true", Constants.GBK).execute().body();
            if (StringUtils.isEmpty(rspStr)) {
                log.error("获取地理位置异常 {}", ip);
                return UNKNOWN;
            }
            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);
        }
    }
    return UNKNOWN;
}
Also used : Dict(cn.hutool.core.lang.Dict)

Example 22 with Dict

use of cn.hutool.core.lang.Dict in project RuoYi-Vue-Plus by JavaLionLi.

the class GenTableServiceImpl method validateEdit.

/**
 * 修改保存参数校验
 *
 * @param genTable 业务信息
 */
@Override
public void validateEdit(GenTable genTable) {
    if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
        String options = JsonUtils.toJsonString(genTable.getParams());
        Dict paramsObj = JsonUtils.parseMap(options);
        if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_CODE))) {
            throw new ServiceException("树编码字段不能为空");
        } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_PARENT_CODE))) {
            throw new ServiceException("树父编码字段不能为空");
        } 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())) {
                throw new ServiceException("关联子表的表名不能为空");
            } else if (StringUtils.isEmpty(genTable.getSubTableFkName())) {
                throw new ServiceException("子表关联的外键名不能为空");
            }
        }
    }
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) Dict(cn.hutool.core.lang.Dict)

Example 23 with Dict

use of cn.hutool.core.lang.Dict in project RuoYi-Vue-Plus by JavaLionLi.

the class GenTableServiceImpl method setTableFromOptions.

/**
 * 设置代码生成其他选项值
 *
 * @param genTable 设置后的生成对象
 */
public void setTableFromOptions(GenTable genTable) {
    Dict paramsObj = JsonUtils.parseMap(genTable.getOptions());
    if (ObjectUtil.isNotNull(paramsObj)) {
        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);
        genTable.setTreeName(treeName);
        genTable.setParentMenuId(parentMenuId);
        genTable.setParentMenuName(parentMenuName);
    }
}
Also used : Dict(cn.hutool.core.lang.Dict)

Example 24 with Dict

use of cn.hutool.core.lang.Dict in project RuoYi-Vue-Plus by JavaLionLi.

the class VelocityUtils method getExpandColumn.

/**
 * 获取需要在哪一列上面显示展开按钮
 *
 * @param genTable 业务表对象
 * @return 展开按钮列序号
 */
public static int getExpandColumn(GenTable genTable) {
    String options = genTable.getOptions();
    Dict paramsObj = JsonUtils.parseMap(options);
    String treeName = paramsObj.getStr(GenConstants.TREE_NAME);
    int num = 0;
    for (GenTableColumn column : genTable.getColumns()) {
        if (column.isList()) {
            num++;
            String columnName = column.getColumnName();
            if (columnName.equals(treeName)) {
                break;
            }
        }
    }
    return num;
}
Also used : Dict(cn.hutool.core.lang.Dict) GenTableColumn(com.ruoyi.generator.domain.GenTableColumn)

Example 25 with Dict

use of cn.hutool.core.lang.Dict in project onex-boot by zhangchaoxu.

the class BaseExceptionHandler method saveLog.

/**
 * 保存异常日志
 */
protected void saveLog(HttpServletRequest request, Exception ex) {
    LogBody logEntity = new LogBody();
    logEntity.setStoreType("db");
    logEntity.setType("error");
    logEntity.setState(0);
    // 请求相关信息
    if (request == null) {
        request = HttpContextUtils.getHttpServletRequest();
    }
    if (null != request) {
        logEntity.setUri(request.getRequestURI());
        // 记录内容
        Dict requestParams = Dict.create();
        requestParams.set("ip", HttpContextUtils.getIpAddr(request));
        requestParams.set("ua", request.getHeader(HttpHeaders.USER_AGENT));
        requestParams.set("queryString", request.getQueryString());
        requestParams.set("url", request.getRequestURL());
        requestParams.set("method", request.getMethod());
        requestParams.set("contentType", request.getContentType());
        if (HttpMethod.POST.name().equalsIgnoreCase(request.getMethod())) {
            try {
                requestParams.set("params", IoUtil.read(request.getInputStream()).toString());
            } catch (IOException e) {
                log.error("读取流失败", e);
            }
        }
        logEntity.setRequestParams(requestParams);
    }
    // 异常信息
    logEntity.setContent(ExceptionUtil.stacktraceToString(ex));
    // 保存
    try {
        logService.saveLog(logEntity);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Dict(cn.hutool.core.lang.Dict) LogBody(com.nb6868.onex.common.log.LogBody) IOException(java.io.IOException) UnauthenticatedException(org.apache.shiro.authz.UnauthenticatedException) NoHandlerFoundException(org.springframework.web.servlet.NoHandlerFoundException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) MissingServletRequestParameterException(org.springframework.web.bind.MissingServletRequestParameterException) IOException(java.io.IOException) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) MaxUploadSizeExceededException(org.springframework.web.multipart.MaxUploadSizeExceededException) MethodArgumentTypeMismatchException(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) ConstraintViolationException(javax.validation.ConstraintViolationException) HttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException)

Aggregations

Dict (cn.hutool.core.lang.Dict)43 Test (org.junit.Test)25 File (java.io.File)4 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 ArrayList (java.util.ArrayList)3 BaseTest (cn.e3mall.common.freemarker.BaseTest)2 JexlEngine (cn.hutool.extra.expression.engine.jexl.JexlEngine)2 JfireELEngine (cn.hutool.extra.expression.engine.jfireel.JfireELEngine)2 MvelEngine (cn.hutool.extra.expression.engine.mvel.MvelEngine)2 RhinoEngine (cn.hutool.extra.expression.engine.rhino.RhinoEngine)2 SpELEngine (cn.hutool.extra.expression.engine.spel.SpELEngine)2 LogBody (com.nb6868.onex.common.log.LogBody)2 Configuration (freemarker.template.Configuration)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2