Java Code Examples for cn.hutool.core.convert.Convert#toLong()

The following examples show how to use cn.hutool.core.convert.Convert#toLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserServiceImpl.java    From v-mock with MIT License 6 votes vote down vote up
/**
 * 根据条件分页查询用户列表
 *
 * @param user 用户信息
 * @return 用户信息集合信息
 */
@Override
public List<User> selectUserList(User user) {
    Long beginTime = Convert.toLong(user.getParams().get("beginTime"));
    Long endTime = Convert.toLong(user.getParams().get("endTime"));
    return this.list(Wrappers.<User>lambdaQuery()
            // like login nameF
            .like(StrUtil.isNotBlank(user.getLoginName()), User::getLoginName, user.getLoginName())
            // equals status
            .eq(user.getStatus() != null, User::getStatus, user.getStatus())
            // like phone
            .like(StrUtil.isNotBlank(user.getPhonenumber()), User::getPhonenumber, user.getPhonenumber())
            // beginTime
            .ge(beginTime != null, User::getCreateTime, beginTime)
            // endTime 加入当日的时间戳
            .le(endTime != null, User::getCreateTime, endTime));
}
 
Example 2
Source File: MockLogServiceImpl.java    From v-mock with MIT License 6 votes vote down vote up
/**
 * 获取过滤数据的wrapper
 *
 * @param mockLog  参数实体
 * @param isExport 是否excel导出的过滤,excel导出查询全部字段。
 */
private LambdaQueryWrapper<MockLog> getFilterWrapper(MockLog mockLog, boolean isExport) {
    Long beginTime = Convert.toLong(mockLog.getParams().get("beginTime"));
    Long endTime = Convert.toLong(mockLog.getParams().get("endTime"));
    String from = Convert.toStr(mockLog.getParams().get("from"));
    LambdaQueryWrapper<MockLog> mockLogWrapper = Wrappers.<MockLog>lambdaQuery()
            // like ip
            .like(StrUtil.isNotBlank(mockLog.getRequestIp()), MockLog::getRequestIp, mockLog.getRequestIp())
            // like hit url
            .like(StrUtil.isNotBlank(mockLog.getHitUrl()) && !FROM_URL.equals(from), MockLog::getHitUrl, mockLog.getHitUrl())
            // equals hit url, in url log page
            .eq(StrUtil.isNotBlank(mockLog.getHitUrl()) && FROM_URL.equals(from), MockLog::getHitUrl, mockLog.getHitUrl())
            // equals method
            .eq(StrUtil.isNotBlank(mockLog.getRequestMethod()), MockLog::getRequestMethod, mockLog.getRequestMethod())
            // beginTime
            .ge(beginTime != null, MockLog::getCreateTime, beginTime)
            // endTime 加入当日的时间戳
            .le(endTime != null, MockLog::getCreateTime, endTime);
    // 非导出场景
    if (!isExport) {
        // 只查询需要字段,排除大json字段
        mockLogWrapper.select(MockLog::getLogId, MockLog::getHitUrl, MockLog::getRequestMethod, MockLog::getCreateTime, MockLog::getRequestIp);
    }
    return mockLogWrapper;
}
 
Example 3
Source File: ServerExtConfigBean.java    From Jpom with MIT License 5 votes vote down vote up
public long getIpErrorLockTime() {
    if (this.ipErrorLockTimeValue == -1) {
        String str = StrUtil.emptyToDefault(this.ipErrorLockTime, "60*60*5*1000");
        this.ipErrorLockTimeValue = Convert.toLong(ScriptUtil.eval(str), TimeUnit.HOURS.toMillis(5));
    }
    return this.ipErrorLockTimeValue;
}
 
Example 4
Source File: TimeUtils.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
public static LocalDateTime getPasswordErrorLockTime(String time) {
    if (time == null || "".equals(time)) {
        return LocalDateTime.MAX;
    }
    if ("0".equals(time)) {
        return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
    }
    char unit = Character.toLowerCase(time.charAt(time.length() - 1));

    if (time.length() == 1) {
        unit = 'd';
    }
    Long lastTime = Convert.toLong(time.substring(0, time.length() - 1));

    LocalDateTime passwordErrorLastTime = LocalDateTime.MAX;
    switch (unit) {
        //时
        case 'h':
            passwordErrorLastTime = LocalDateTime.now().plusHours(lastTime);
            break;
        //天
        case 'd':
            passwordErrorLastTime = LocalDateTime.now().plusDays(lastTime);
            break;
        //周
        case 'w':
            passwordErrorLastTime = LocalDateTime.now().plusWeeks(lastTime);
            break;
        //月
        case 'm':
            passwordErrorLastTime = LocalDateTime.now().plusMonths(lastTime);
            break;
        default:
            passwordErrorLastTime = LocalDateTime.now().plusDays(lastTime);
            break;
    }

    return passwordErrorLastTime;
}
 
Example 5
Source File: TimeUtils.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
public static LocalDateTime getPasswordErrorLockTime(String time) {
    if (time == null || "".equals(time)) {
        return LocalDateTime.MAX;
    }
    if ("0".equals(time)) {
        return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
    }
    char unit = Character.toLowerCase(time.charAt(time.length() - 1));

    if (time.length() == 1) {
        unit = 'd';
    }
    Long lastTime = Convert.toLong(time.substring(0, time.length() - 1));

    LocalDateTime passwordErrorLastTime = LocalDateTime.MAX;
    switch (unit) {
        //时
        case 'h':
            passwordErrorLastTime = LocalDateTime.now().plusHours(lastTime);
            break;
        //天
        case 'd':
            passwordErrorLastTime = LocalDateTime.now().plusDays(lastTime);
            break;
        //周
        case 'w':
            passwordErrorLastTime = LocalDateTime.now().plusWeeks(lastTime);
            break;
        //月
        case 'm':
            passwordErrorLastTime = LocalDateTime.now().plusMonths(lastTime);
            break;
        default:
            passwordErrorLastTime = LocalDateTime.now().plusDays(lastTime);
            break;
    }

    return passwordErrorLastTime;
}
 
Example 6
Source File: TimeUtils.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
public static LocalDateTime getPasswordErrorLockTime(String time) {
    if (time == null || "".equals(time)) {
        return LocalDateTime.MAX;
    }
    if ("0".equals(time)) {
        return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
    }
    char unit = Character.toLowerCase(time.charAt(time.length() - 1));

    if (time.length() == 1) {
        unit = 'd';
    }
    Long lastTime = Convert.toLong(time.substring(0, time.length() - 1));

    LocalDateTime passwordErrorLastTime = LocalDateTime.MAX;
    switch (unit) {
        //时
        case 'h':
            passwordErrorLastTime = LocalDateTime.now().plusHours(lastTime);
            break;
        //天
        case 'd':
            passwordErrorLastTime = LocalDateTime.now().plusDays(lastTime);
            break;
        //周
        case 'w':
            passwordErrorLastTime = LocalDateTime.now().plusWeeks(lastTime);
            break;
        //月
        case 'm':
            passwordErrorLastTime = LocalDateTime.now().plusMonths(lastTime);
            break;
        default:
            passwordErrorLastTime = LocalDateTime.now().plusDays(lastTime);
            break;
    }

    return passwordErrorLastTime;
}
 
Example 7
Source File: SignAuthFilter.java    From spring-boot-demo with MIT License 4 votes vote down vote up
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    // 防止流读取一次后就没有了, 所以需要将流继续写出去
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletRequest requestWrapper = new RequestWrapper(httpRequest);

    Set<String> uriSet = new HashSet<>(securityProperties.getIgnoreSignUri());
    String requestUri = httpRequest.getRequestURI();
    boolean isMatch = false;
    for (String uri : uriSet) {
        isMatch = requestUri.contains(uri);
        if (isMatch) {
            break;
        }
    }
    log.info("当前请求的URI是==>{},isMatch==>{}", httpRequest.getRequestURI(), isMatch);
    if (isMatch) {
        filterChain.doFilter(requestWrapper, response);
        return;
    }

    String sign = requestWrapper.getHeader("Sign");
    Long timestamp = Convert.toLong(requestWrapper.getHeader("Timestamp"));

    if (StrUtil.isEmpty(sign)) {
        returnFail("签名不允许为空", response);
        return;
    }

    if (timestamp == null) {
        returnFail("时间戳不允许为空", response);
        return;
    }

    //重放时间限制(单位分)
    Long difference = DateUtil.between(DateUtil.date(), DateUtil.date(timestamp * 1000), DateUnit.MINUTE);
    if (difference > securityProperties.getSignTimeout()) {
        returnFail("已过期的签名", response);
        log.info("前端时间戳:{},服务端时间戳:{}", DateUtil.date(timestamp * 1000), DateUtil.date());
        return;
    }

    boolean accept = true;
    SortedMap<String, String> paramMap;
    switch (requestWrapper.getMethod()) {
        case "GET":
            paramMap = HttpUtil.getUrlParams(requestWrapper);
            accept = SignUtil.verifySign(paramMap, sign, timestamp);
            break;
        case "POST":
        case "PUT":
        case "DELETE":
            paramMap = HttpUtil.getBodyParams(requestWrapper);
            accept = SignUtil.verifySign(paramMap, sign, timestamp);
            break;
        default:
            accept = true;
            break;
    }
    if (accept) {
        filterChain.doFilter(requestWrapper, response);
    } else {
        returnFail("签名验证不通过", response);
    }
}
 
Example 8
Source File: WindowsSystemCommander.java    From Jpom with MIT License 4 votes vote down vote up
/**
     * 将windows的tasklist转为集合
     *
     * @param header 是否包含投信息
     * @param result 进程信息
     * @return jsonArray
     */
    private static List<ProcessModel> formatWindowsProcess(String result, boolean header) {
        List<String> list = StrSpliter.splitTrim(result, StrUtil.LF, true);
        if (list.isEmpty()) {
            return null;
        }
        List<ProcessModel> processModels = new ArrayList<>();
        ProcessModel processModel;
        for (int i = header ? 2 : 0, len = list.size(); i < len; i++) {
            String param = list.get(i);
            List<String> memList = StrSpliter.splitTrim(param, StrUtil.SPACE, true);
            processModel = new ProcessModel();
            int pid = Convert.toInt(memList.get(1), 0);
            processModel.setPid(pid);
            //
            String name = memList.get(0);
            processModel.setCommand(name);
            //使用内存 kb
            String mem = memList.get(4).replace(",", "");
            long aLong = Convert.toLong(mem, 0L);
//            FileUtil.readableFileSize()
            processModel.setRes(aLong / 1024 + " MB");
            String status = memList.get(6);
            processModel.setStatus(formatStatus(status));
            //
            processModel.setUser(memList.get(7));
            processModel.setTime(memList.get(8));

            try {
                OperatingSystemMXBean operatingSystemMXBean = JvmUtil.getOperatingSystemMXBean(memList.get(1));
                if (operatingSystemMXBean != null) {
                    //最近jvm cpu使用率
                    double processCpuLoad = operatingSystemMXBean.getProcessCpuLoad() * 100;
                    if (processCpuLoad <= 0) {
                        processCpuLoad = 0;
                    }
                    processModel.setCpu(String.format("%.2f", processCpuLoad) + "%");
                    //服务器总内存
                    long totalMemorySize = operatingSystemMXBean.getTotalPhysicalMemorySize();
                    BigDecimal total = new BigDecimal(totalMemorySize / 1024);
                    // 进程
                    double v = new BigDecimal(aLong).divide(total, 4, BigDecimal.ROUND_HALF_UP).doubleValue() * 100;
                    processModel.setMem(String.format("%.2f", v) + "%");
                }
            } catch (Exception ignored) {

            }
            processModels.add(processModel);
        }
        return processModels;
    }
 
Example 9
Source File: ExecutorRegistryThread.java    From zuihou-admin-boot with Apache License 2.0 4 votes vote down vote up
public void start(final String appName, final String address, final String registryLazy) {

        // valid
        if (appName == null || appName.trim().length() == 0) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, appName is null.");
            return;
        }
        if (XxlJobExecutor.getAdminBizList() == null) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, adminAddresses is null.");
            return;
        }

        REGISTRY_LAZY = Convert.toLong(registryLazy, 10000L);

        registryThread = new Thread(new Runnable() {
            @Override
            public void run() {

                // 首次主次延迟 REGISTRY_LAZY 毫秒, 防止尚未启动完成时,注册失败
                if (REGISTRY_LAZY > 0) {
                    try {
                        Thread.sleep(REGISTRY_LAZY);
                    } catch (InterruptedException e) {
                        logger.error(">>>>>>>>>>> xxl-job 首次注册延迟失败, appName:{}, address:{}", new Object[]{appName, address});
                    } finally {
                        REGISTRY_LAZY = 0;
                    }
                }

                // registry
                while (!toStop) {
                    try {
                        RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, address);
                        for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
                            try {
                                ReturnT<String> registryResult = adminBiz.registry(registryParam);
                                if (registryResult != null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                    registryResult = ReturnT.SUCCESS;
                                    logger.info(">>>>>>>>>>> xxl-job registry success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                    break;
                                } else {
                                    logger.info(">>>>>>>>>>> xxl-job registry fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                }
                            } catch (Exception e) {
                                logger.info(">>>>>>>>>>> xxl-job registry error, registryParam:{}", registryParam, e);
                            }

                        }
                    } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                    }

                    try {
                        TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
                    } catch (InterruptedException e) {
                        logger.warn(">>>>>>>>>>> xxl-job, executor registry thread interrupted, error msg:{}", e.getMessage());
                    }
                }

                // registry remove
                try {
                    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, address);
                    for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
                        try {
                            ReturnT<String> registryResult = adminBiz.registryRemove(registryParam);
                            if (registryResult != null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                registryResult = ReturnT.SUCCESS;
                                logger.info(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                break;
                            } else {
                                logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                            }
                        } catch (Exception e) {
                            logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e);
                        }

                    }
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }
                logger.info(">>>>>>>>>>> xxl-job, executor registry thread destory.");

            }
        });
        registryThread.setDaemon(true);
        registryThread.start();
    }
 
Example 10
Source File: ExecutorRegistryThread.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
public void start(final String appName, final String address, final String registryLazy) {

        // valid
        if (appName == null || appName.trim().length() == 0) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, appName is null.");
            return;
        }
        if (XxlJobExecutor.getAdminBizList() == null) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, adminAddresses is null.");
            return;
        }

        REGISTRY_LAZY = Convert.toLong(registryLazy, 10000L);

        registryThread = new Thread(new Runnable() {
            @Override
            public void run() {

                // 首次主次延迟 REGISTRY_LAZY 毫秒, 防止尚未启动完成时,注册失败
                if (REGISTRY_LAZY > 0) {
                    try {
                        Thread.sleep(REGISTRY_LAZY);
                    } catch (InterruptedException e) {
                        logger.error(">>>>>>>>>>> xxl-job 首次注册延迟失败, appName:{}, address:{}", new Object[]{appName, address});
                    } finally {
                        REGISTRY_LAZY = 0;
                    }
                }

                // registry
                while (!toStop) {
                    try {
                        RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, address);
                        for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
                            try {
                                ReturnT<String> registryResult = adminBiz.registry(registryParam);
                                if (registryResult != null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                    registryResult = ReturnT.SUCCESS;
                                    logger.info(">>>>>>>>>>> xxl-job registry success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                    break;
                                } else {
                                    logger.info(">>>>>>>>>>> xxl-job registry fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                }
                            } catch (Exception e) {
                                logger.info(">>>>>>>>>>> xxl-job registry error, registryParam:{}", registryParam, e);
                            }

                        }
                    } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                    }

                    try {
                        TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
                    } catch (InterruptedException e) {
                        logger.warn(">>>>>>>>>>> xxl-job, executor registry thread interrupted, error msg:{}", e.getMessage());
                    }
                }

                // registry remove
                try {
                    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, address);
                    for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
                        try {
                            ReturnT<String> registryResult = adminBiz.registryRemove(registryParam);
                            if (registryResult != null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                registryResult = ReturnT.SUCCESS;
                                logger.info(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                break;
                            } else {
                                logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                            }
                        } catch (Exception e) {
                            logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e);
                        }

                    }
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }
                logger.info(">>>>>>>>>>> xxl-job, executor registry thread destory.");

            }
        });
        registryThread.setDaemon(true);
        registryThread.start();
    }
 
Example 11
Source File: Kv.java    From magic-starter with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 获得特定类型值
 *
 * @param attr 字段名
 * @return 字段值
 */
public Long getLong(String attr) {
	return Convert.toLong(get(attr), -1L);
}
 
Example 12
Source File: JSONObject.java    From RuoYi with Apache License 2.0 2 votes vote down vote up
/**
 * 获取指定字段的长整数值。如果字段不存在,或者无法转换为长整数,返回defaultValue。
 *
 * @param name         字段名,支持多级。
 * @param defaultValue 查询失败时,返回的值。
 * @return 返回指定的长整数值,或者defaultValue。
 */
public Long longValue(final String name, final Long defaultValue) {
    return Convert.toLong(longValue(name), defaultValue);
}
 
Example 13
Source File: JSONObject.java    From RuoYi with Apache License 2.0 2 votes vote down vote up
/**
 * 返回字段长整数值。如果不存在,返回defaultValue。
 *
 * @param name         字段名。
 * @param defaultValue 字段不存在时,返回的值。
 * @return 返回指定字段长整数值。
 */
public Long getLong(final String name, Long defaultValue) {
    return Convert.toLong(getLong(name), defaultValue);
}