Java Code Examples for com.ruoyi.common.constant.Constants

The following examples show how to use com.ruoyi.common.constant.Constants. These examples are extracted from open source projects. 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 Project: supplierShop   Source File: GenTableServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 预览代码
 * 
 * @param tableId 表编号
 * @return 预览数据列表
 */
public Map<String, String> previewCode(Long tableId)
{
    Map<String, String> dataMap = new LinkedHashMap<>();
    // 查询表信息
    GenTable table = genTableMapper.selectGenTableById(tableId);
    // 查询列信息
    List<GenTableColumn> columns = table.getColumns();
    setPkColumn(table, columns);
    VelocityInitializer.initVelocity();

    VelocityContext context = VelocityUtils.prepareContext(table);

    // 获取模板列表
    List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
    for (String template : templates)
    {
        // 渲染模板
        StringWriter sw = new StringWriter();
        Template tpl = Velocity.getTemplate(template, Constants.UTF8);
        tpl.merge(context, sw);
        dataMap.put(template, sw.toString());
    }
    return dataMap;
}
 
Example 2
Source Project: supplierShop   Source File: VelocityInitializer.java    License: MIT License 6 votes vote down vote up
/**
 * 初始化vm方法
 */
public static void initVelocity()
{
    Properties p = new Properties();
    try
    {
        // 加载classpath目录下的vm文件
        p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        // 定义字符集
        p.setProperty(Velocity.ENCODING_DEFAULT, Constants.UTF8);
        p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8);
        // 初始化Velocity引擎,指定配置Properties
        Velocity.init(p);
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source Project: RuoYi-Vue   Source File: GenTableServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 预览代码
 * 
 * @param tableId 表编号
 * @return 预览数据列表
 */
@Override
public Map<String, String> previewCode(Long tableId)
{
    Map<String, String> dataMap = new LinkedHashMap<>();
    // 查询表信息
    GenTable table = genTableMapper.selectGenTableById(tableId);
    // 查询列信息
    List<GenTableColumn> columns = table.getColumns();
    setPkColumn(table, columns);
    VelocityInitializer.initVelocity();

    VelocityContext context = VelocityUtils.prepareContext(table);

    // 获取模板列表
    List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
    for (String template : templates)
    {
        // 渲染模板
        StringWriter sw = new StringWriter();
        Template tpl = Velocity.getTemplate(template, Constants.UTF8);
        tpl.merge(context, sw);
        dataMap.put(template, sw.toString());
    }
    return dataMap;
}
 
Example 4
Source Project: RuoYi-Vue   Source File: VelocityInitializer.java    License: MIT License 6 votes vote down vote up
/**
 * 初始化vm方法
 */
public static void initVelocity()
{
    Properties p = new Properties();
    try
    {
        // 加载classpath目录下的vm文件
        p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        // 定义字符集
        p.setProperty(Velocity.ENCODING_DEFAULT, Constants.UTF8);
        p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8);
        // 初始化Velocity引擎,指定配置Properties
        Velocity.init(p);
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
Example 5
Source Project: RuoYi-Vue   Source File: CommonController.java    License: MIT License 6 votes vote down vote up
/**
 * 本地资源通用下载
 */
@GetMapping("/common/download/resource")
public void resourceDownload(String name, HttpServletRequest request, HttpServletResponse response) throws Exception
{
    // 本地资源路径
    String localPath = RuoYiConfig.getProfile();
    // 数据库资源地址
    String downloadPath = localPath + StringUtils.substringAfter(name, Constants.RESOURCE_PREFIX);
    // 下载名称
    String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
    response.setCharacterEncoding("utf-8");
    response.setContentType("multipart/form-data");
    response.setHeader("Content-Disposition",
            "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName));
    FileUtils.writeBytes(downloadPath, response.getOutputStream());
}
 
Example 6
Source Project: RuoYi-Vue   Source File: SysMenuController.java    License: MIT License 6 votes vote down vote up
/**
 * 新增菜单
 */
@PreAuthorize("@ss.hasPermi('system:menu:add')")
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysMenu menu)
{
    if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
    {
        return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
    }
    else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
            && !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS))
    {
        return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
    }
    menu.setCreateBy(SecurityUtils.getUsername());
    return toAjax(menuService.insertMenu(menu));
}
 
Example 7
Source Project: RuoYi-Vue   Source File: SysMenuController.java    License: MIT License 6 votes vote down vote up
/**
 * 修改菜单
 */
@PreAuthorize("@ss.hasPermi('system:menu:edit')")
@Log(title = "菜单管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysMenu menu)
{
    if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
    {
        return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
    }
    else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
            && !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS))
    {
        return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
    }
    menu.setUpdateBy(SecurityUtils.getUsername());
    return toAjax(menuService.updateMenu(menu));
}
 
Example 8
Source Project: RuoYi-Vue   Source File: LogoutSuccessHandlerImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 退出处理
 * 
 * @return
 */
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
        throws IOException, ServletException
{
    LoginUser loginUser = tokenService.getLoginUser(request);
    if (StringUtils.isNotNull(loginUser))
    {
        String userName = loginUser.getUsername();
        // 删除用户缓存记录
        tokenService.delLoginUser(loginUser.getToken());
        // 记录用户退出日志
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功"));
    }
    ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(HttpStatus.SUCCESS, "退出成功")));
}
 
Example 9
Source Project: RuoYi-Vue   Source File: TokenService.java    License: MIT License 6 votes vote down vote up
/**
 * 获取用户身份信息
 * 
 * @return 用户信息
 */
public LoginUser getLoginUser(HttpServletRequest request)
{
    // 获取请求携带的令牌
    String token = getToken(request);
    if (StringUtils.isNotEmpty(token))
    {
        Claims claims = parseToken(token);
        // 解析对应的权限以及用户信息
        String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
        String userKey = getTokenKey(uuid);
        LoginUser user = redisCache.getCacheObject(userKey);
        return user;
    }
    return null;
}
 
Example 10
Source Project: ruoyiplus   Source File: GenServiceImpl.java    License: MIT License 6 votes vote down vote up
private void generatorAdvCodeOnlyWeb(
        String tmplName,
        TableInfo table,
        List<ColumnInfo> columns,
        Map<String, String[]> params,
        ZipOutputStream zip) {
    Map<String, String> swMap = generatorAdvCodeOnlyWeb(tmplName, table, columns, params);
    for (Map.Entry<String, String> entry : swMap.entrySet()) {
        String fileName = Convert.toStr(entry.getKey());
        fileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
        fileName = StrUtil.replace(fileName, ".vm", "");
        try {
            // 添加到zip
            zip.putNextEntry(new ZipEntry(fileName));
            IOUtils.write(Convert.toStr(entry.getValue()), zip, Constants.UTF8);
            zip.closeEntry();
        } catch (IOException e) {
            log.error("渲染模板失败,表名:" + table.getTableName(), e);
        }
    }
}
 
Example 11
Source Project: ruoyiplus   Source File: GenUtils.java    License: MIT License 6 votes vote down vote up
/**
 * 表名转换成Java类名
 */
public static String tableToJava(String tableName)
{
    String autoRemovePre = Global.getAutoRemovePre();
    String tablePrefix = Global.getTablePrefix();
    //多种前缀
    if(tablePrefix.indexOf(",")>0){
        String[] prefixes = StrUtil.splitToArray(tablePrefix,',');
        for(String _prefix : prefixes){
            if(!StrUtil.isEmpty(_prefix)){
                tableName = tableName.replaceFirst(_prefix, "");
            }
        }
    }else {
        if (Constants.AUTO_REOMVE_PRE.equals(autoRemovePre) && StringUtils.isNotEmpty(tablePrefix)) {
            tableName = tableName.replaceFirst(tablePrefix, "");
        }
    }
    return StringUtils.convertToCamelCase(tableName);
}
 
Example 12
Source Project: ruoyiplus   Source File: VelocityInitializer.java    License: MIT License 6 votes vote down vote up
/**
 * 初始化vm方法
 */
public static void initVelocity()
{
    Properties p = new Properties();
    try
    {
        // 加载classpath目录下的vm文件
        p.setProperty("file.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        // 定义字符集
        p.setProperty(Velocity.ENCODING_DEFAULT, Constants.UTF8);
        p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8);
        // 初始化Velocity引擎,指定配置Properties
        Velocity.init(p);
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
Example 13
Source Project: RuoYi   Source File: LogoutFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response){
    try {
        Subject subject = getSubject(request, response);
        String redirectUrl = getRedirectUrl(request, response, subject);
        SysUser user = ShiroUtils.getSysUser();
        if (ObjectUtil.isNotNull(user)) {
            String loginName = user.getLoginName();
            // 记录用户退出日志
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success")));
            // 清理缓存
            cache.remove(loginName);
        }
        // 退出登录
        subject.logout();
        issueRedirect(request, response, redirectUrl);
    } catch (Exception e) {
        log.error("Encountered session exception during logout.  This can generally safely be ignored." , e);
    }
    return false;
}
 
Example 14
Source Project: RuoYi   Source File: AbstractQuartzJob.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 执行后
 *
 * @param context        工作执行上下文对象
 */
protected void after(JobExecutionContext context, SysJob sysJob, Exception e) {
    Date startTime = threadLocal.get();
    threadLocal.remove();

    final SysJobLog sysJobLog = new SysJobLog();
    sysJobLog.setJobName(sysJob.getJobName());
    sysJobLog.setJobGroup(sysJob.getJobGroup());
    sysJobLog.setMethodName(sysJob.getMethodName());
    sysJobLog.setMethodParams(sysJob.getMethodParams());
    sysJobLog.setStartTime(startTime);
    sysJobLog.setEndTime(new Date());
    long runMs = sysJobLog.getEndTime().getTime() - sysJobLog.getStartTime().getTime();
    sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
    if (e != null) {
        sysJobLog.setStatus(Constants.FAIL);
        String errorMsg = StrUtil.sub(ExceptionUtil.getExceptionMessage(e), 0, 2000);
        sysJobLog.setExceptionInfo(errorMsg);
    } else {
        sysJobLog.setStatus(Constants.SUCCESS);
    }

    // 写入数据库当中
    SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog);
}
 
Example 15
Source Project: supplierShop   Source File: GenTableServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 查询表信息并生成代码
 */
private void generatorCode(String tableName, ZipOutputStream zip)
{
    // 查询表信息
    GenTable table = genTableMapper.selectGenTableByName(tableName);
    // 查询列信息
    List<GenTableColumn> columns = table.getColumns();
    setPkColumn(table, columns);

    VelocityInitializer.initVelocity();

    VelocityContext context = VelocityUtils.prepareContext(table);

    // 获取模板列表
    List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
    for (String template : templates)
    {
        // 渲染模板
        StringWriter sw = new StringWriter();
        Template tpl = Velocity.getTemplate(template, Constants.UTF8);
        tpl.merge(context, sw);
        try
        {
            // 添加到zip
            zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
            IOUtils.write(sw.toString(), zip, Constants.UTF8);
            IOUtils.closeQuietly(sw);
            zip.closeEntry();
        }
        catch (IOException e)
        {
            log.error("渲染模板失败,表名:" + table.getTableName(), e);
        }
    }
}
 
Example 16
Source Project: supplierShop   Source File: LogoutFilter.java    License: MIT License 5 votes vote down vote up
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception
{
    try
    {
        Subject subject = getSubject(request, response);
        String redirectUrl = getRedirectUrl(request, response, subject);
        try
        {
            SysUser user = ShiroUtils.getSysUser();
            if (StringUtils.isNotNull(user))
            {
                String loginName = user.getLoginName();
                // 记录用户退出日志
                AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success")));
                // 清理缓存
                cache.remove(loginName);
            }
            // 退出登录
            subject.logout();
        }
        catch (SessionException ise)
        {
            log.error("logout fail.", ise);
        }
        issueRedirect(request, response, redirectUrl);
    }
    catch (Exception e)
    {
        log.error("Encountered session exception during logout.  This can generally safely be ignored.", e);
    }
    return false;
}
 
Example 17
Source Project: supplierShop   Source File: TableSupport.java    License: MIT License 5 votes vote down vote up
/**
 * 封装分页对象
 */
public static PageDomain getPageDomain()
{
    PageDomain pageDomain = new PageDomain();
    pageDomain.setPageNum(ServletUtils.getParameterToInt(Constants.PAGE_NUM));
    pageDomain.setPageSize(ServletUtils.getParameterToInt(Constants.PAGE_SIZE));
    pageDomain.setOrderByColumn(ServletUtils.getParameter(Constants.ORDER_BY_COLUMN));
    pageDomain.setIsAsc(ServletUtils.getParameter(Constants.IS_ASC));
    return pageDomain;
}
 
Example 18
Source Project: supplierShop   Source File: AbstractQuartzJob.java    License: MIT License 5 votes vote down vote up
/**
 * 执行后
 *
 * @param context 工作执行上下文对象
 * @param sysScheduleJob 系统计划任务
 */
protected void after(JobExecutionContext context, SysJob sysJob, Exception e)
{
    Date startTime = threadLocal.get();
    threadLocal.remove();

    final SysJobLog sysJobLog = new SysJobLog();
    sysJobLog.setJobName(sysJob.getJobName());
    sysJobLog.setJobGroup(sysJob.getJobGroup());
    sysJobLog.setInvokeTarget(sysJob.getInvokeTarget());
    sysJobLog.setStartTime(startTime);
    sysJobLog.setEndTime(new Date());
    long runMs = sysJobLog.getEndTime().getTime() - sysJobLog.getStartTime().getTime();
    sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
    if (e != null)
    {
        sysJobLog.setStatus(Constants.FAIL);
        String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
        sysJobLog.setExceptionInfo(errorMsg);
    }
    else
    {
        sysJobLog.setStatus(Constants.SUCCESS);
    }

    // 写入数据库当中
    SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog);
}
 
Example 19
Source Project: RuoYi-Vue   Source File: GenTableServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 查询表信息并生成代码
 */
private void generatorCode(String tableName, ZipOutputStream zip)
{
    // 查询表信息
    GenTable table = genTableMapper.selectGenTableByName(tableName);
    // 查询列信息
    List<GenTableColumn> columns = table.getColumns();
    setPkColumn(table, columns);

    VelocityInitializer.initVelocity();

    VelocityContext context = VelocityUtils.prepareContext(table);

    // 获取模板列表
    List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
    for (String template : templates)
    {
        // 渲染模板
        StringWriter sw = new StringWriter();
        Template tpl = Velocity.getTemplate(template, Constants.UTF8);
        tpl.merge(context, sw);
        try
        {
            // 添加到zip
            zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
            IOUtils.write(sw.toString(), zip, Constants.UTF8);
            IOUtils.closeQuietly(sw);
zip.flush();
            zip.closeEntry();
        }
        catch (IOException e)
        {
            log.error("渲染模板失败,表名:" + table.getTableName(), e);
        }
    }
}
 
Example 20
Source Project: RuoYi-Vue   Source File: CaptchaController.java    License: MIT License 5 votes vote down vote up
/**
 * 生成验证码
 */
@GetMapping("/captchaImage")
public AjaxResult getCode(HttpServletResponse response) throws IOException
{
    // 生成随机字串
    String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
    // 唯一标识
    String uuid = IdUtils.simpleUUID();
    String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;

    redisCache.setCacheObject(verifyKey, verifyCode, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
    // 生成图片
    int w = 111, h = 36;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    VerifyCodeUtils.outputImage(w, h, stream, verifyCode);
    try
    {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("uuid", uuid);
        ajax.put("img", Base64.encode(stream.toByteArray()));
        return ajax;
    }
    catch (Exception e)
    {
        e.printStackTrace();
        return AjaxResult.error(e.getMessage());
    }
    finally
    {
        stream.close();
    }
}
 
Example 21
Source Project: RuoYi-Vue   Source File: SysUserOnlineController.java    License: MIT License 5 votes vote down vote up
@PreAuthorize("@ss.hasPermi('monitor:online:list')")
@GetMapping("/list")
public TableDataInfo list(String ipaddr, String userName)
{
    Collection<String> keys = redisCache.keys(Constants.LOGIN_TOKEN_KEY + "*");
    List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
    for (String key : keys)
    {
        LoginUser user = redisCache.getCacheObject(key);
        if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName))
        {
            if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername()))
            {
                userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
            }
        }
        else if (StringUtils.isNotEmpty(ipaddr))
        {
            if (StringUtils.equals(ipaddr, user.getIpaddr()))
            {
                userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user));
            }
        }
        else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser()))
        {
            if (StringUtils.equals(userName, user.getUsername()))
            {
                userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
            }
        }
        else
        {
            userOnlineList.add(userOnlineService.loginUserToUserOnline(user));
        }
    }
    Collections.reverse(userOnlineList);
    userOnlineList.removeAll(Collections.singleton(null));
    return getDataTable(userOnlineList);
}
 
Example 22
Source Project: RuoYi-Vue   Source File: SysUserOnlineController.java    License: MIT License 5 votes vote down vote up
/**
 * 强退用户
 */
@PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')")
@Log(title = "在线用户", businessType = BusinessType.DELETE)
@DeleteMapping("/{tokenId}")
public AjaxResult forceLogout(@PathVariable String tokenId)
{
    redisCache.deleteObject(Constants.LOGIN_TOKEN_KEY + tokenId);
    return AjaxResult.success();
}
 
Example 23
Source Project: RuoYi-Vue   Source File: SysLoginController.java    License: MIT License 5 votes vote down vote up
/**
 * 登录方法
 * 
 * @param loginBody 登陆信息
 * @return 结果
 */
@PostMapping("/login")
public AjaxResult login(@RequestBody LoginBody loginBody)
{
    AjaxResult ajax = AjaxResult.success();
    // 生成令牌
    String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
            loginBody.getUuid());
    ajax.put(Constants.TOKEN, token);
    return ajax;
}
 
Example 24
Source Project: RuoYi-Vue   Source File: SysConfigServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 批量删除参数信息
 * 
 * @param configIds 需要删除的参数ID
 * @return 结果
 */
@Override
public int deleteConfigByIds(Long[] configIds)
{
    int count = configMapper.deleteConfigByIds(configIds);
    if (count > 0)
    {
        Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
        redisCache.deleteObject(keys);
    }
    return count;
}
 
Example 25
Source Project: RuoYi-Vue   Source File: SysConfigServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 清空缓存数据
 */
@Override
public void clearCache()
{
    Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
    redisCache.deleteObject(keys);
}
 
Example 26
Source Project: RuoYi-Vue   Source File: AbstractQuartzJob.java    License: MIT License 5 votes vote down vote up
/**
 * 执行后
 *
 * @param context 工作执行上下文对象
 * @param sysScheduleJob 系统计划任务
 */
protected void after(JobExecutionContext context, SysJob sysJob, Exception e)
{
    Date startTime = threadLocal.get();
    threadLocal.remove();

    final SysJobLog sysJobLog = new SysJobLog();
    sysJobLog.setJobName(sysJob.getJobName());
    sysJobLog.setJobGroup(sysJob.getJobGroup());
    sysJobLog.setInvokeTarget(sysJob.getInvokeTarget());
    sysJobLog.setStartTime(startTime);
    sysJobLog.setStopTime(new Date());
    long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime();
    sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
    if (e != null)
    {
        sysJobLog.setStatus(Constants.FAIL);
        String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
        sysJobLog.setExceptionInfo(errorMsg);
    }
    else
    {
        sysJobLog.setStatus(Constants.SUCCESS);
    }

    // 写入数据库当中
    SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog);
}
 
Example 27
Source Project: RuoYi-Vue   Source File: AddressUtils.java    License: MIT License 5 votes vote down vote up
public static String getRealAddressByIP(String ip)
{
    String address = UNKNOWN;
    // 内网不查询
    if (IpUtils.internalIp(ip))
    {
        return "内网IP";
    }
    if (RuoYiConfig.isAddressEnabled())
    {
        try
        {
            String rspStr = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK);
            if (StringUtils.isEmpty(rspStr))
            {
                log.error("获取地理位置异常 {}", ip);
                return UNKNOWN;
            }
            JSONObject obj = JSONObject.parseObject(rspStr);
            String region = obj.getString("pro");
            String city = obj.getString("city");
            return String.format("%s %s", region, city);
        }
        catch (Exception e)
        {
            log.error("获取地理位置异常 {}", ip);
        }
    }
    return address;
}
 
Example 28
Source Project: RuoYi-Vue   Source File: FileUploadUtils.java    License: MIT License 5 votes vote down vote up
private static final String getPathFileName(String uploadDir, String fileName) throws IOException
{
    int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
    String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
    String pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
    return pathFileName;
}
 
Example 29
Source Project: RuoYi-Vue   Source File: TokenService.java    License: MIT License 5 votes vote down vote up
/**
 * 创建令牌
 * 
 * @param loginUser 用户信息
 * @return 令牌
 */
public String createToken(LoginUser loginUser)
{
    String token = IdUtils.fastUUID();
    loginUser.setToken(token);
    setUserAgent(loginUser);
    refreshToken(loginUser);

    Map<String, Object> claims = new HashMap<>();
    claims.put(Constants.LOGIN_USER_KEY, token);
    return createToken(claims);
}
 
Example 30
Source Project: RuoYi-Vue   Source File: TokenService.java    License: MIT License 5 votes vote down vote up
/**
 * 获取请求token
 *
 * @param request
 * @return token
 */
private String getToken(HttpServletRequest request)
{
    String token = request.getHeader(header);
    if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX))
    {
        token = token.replace(Constants.TOKEN_PREFIX, "");
    }
    return token;
}