com.ruoyi.common.constant.Constants Java Examples
The following examples show how to use
com.ruoyi.common.constant.Constants.
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: GenTableServiceImpl.java From supplierShop with MIT License | 6 votes |
/** * 预览代码 * * @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 File: LogoutSuccessHandlerImpl.java From RuoYi-Vue with MIT License | 6 votes |
/** * 退出处理 * * @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 #3
Source File: TokenService.java From RuoYi-Vue with MIT License | 6 votes |
/** * 获取用户身份信息 * * @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 #4
Source File: GenServiceImpl.java From ruoyiplus with MIT License | 6 votes |
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 #5
Source File: SysMenuController.java From RuoYi-Vue with MIT License | 6 votes |
/** * 修改菜单 */ @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 #6
Source File: SysMenuController.java From RuoYi-Vue with MIT License | 6 votes |
/** * 新增菜单 */ @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 File: GenUtils.java From ruoyiplus with MIT License | 6 votes |
/** * 表名转换成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 #8
Source File: VelocityInitializer.java From ruoyiplus with MIT License | 6 votes |
/** * 初始化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 #9
Source File: CommonController.java From RuoYi-Vue with MIT License | 6 votes |
/** * 本地资源通用下载 */ @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 #10
Source File: VelocityInitializer.java From RuoYi-Vue with MIT License | 6 votes |
/** * 初始化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 #11
Source File: GenTableServiceImpl.java From RuoYi-Vue with MIT License | 6 votes |
/** * 预览代码 * * @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 #12
Source File: LogoutFilter.java From RuoYi with Apache License 2.0 | 6 votes |
@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 #13
Source File: AbstractQuartzJob.java From RuoYi with Apache License 2.0 | 6 votes |
/** * 执行后 * * @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 #14
Source File: VelocityInitializer.java From supplierShop with MIT License | 6 votes |
/** * 初始化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 #15
Source File: LogoutFilter.java From ruoyiplus with MIT License | 5 votes |
@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"))); } // 退出登录 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 #16
Source File: TableSupport.java From ruoyiplus with MIT License | 5 votes |
/** * 封装分页对象 */ 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 #17
Source File: GenUtils.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 表名转换成Java类名 */ public static String tableToJava(String tableName) { if (Constants.AUTO_REOMVE_PRE.equals(Global.getAutoRemovePre())) { tableName = tableName.substring(tableName.indexOf('_') + 1); } if (StrUtil.isNotEmpty(Global.getTablePrefix())) { tableName = tableName.replace(Global.getTablePrefix(), ""); } return StrUtil.upperFirst(StrUtil.toUnderlineCase(tableName)); }
Example #18
Source File: TableSupport.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 封装分页对象 */ 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 #19
Source File: AsyncFactory.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 记录登陆信息 * * @param username 用户名 * @param status 状态 * @param message 消息 * @param args 列表 * @return 任务task */ public static TimerTask recordLogininfor(final String username, final String status, final String message, final Object... args) { final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); final String ip = ShiroUtils.getIp(); return new TimerTask() { @Override public void run() { // 打印信息到日志 String address = AddressUtils.getRealAddressByIp(ip); String s = LogUtils.getBlock(ip) + address + LogUtils.getBlock(username) + LogUtils.getBlock(status) + LogUtils.getBlock(message); sys_user_logger.info(s, args); // 获取客户端操作系统 String os = userAgent.getOperatingSystem().getName(); // 获取客户端浏览器 String browser = userAgent.getBrowser().getName(); // 封装对象 SysLogininfor logininfor = new SysLogininfor(); logininfor.setLoginName(username); logininfor.setIpaddr(ip); logininfor.setLoginLocation(address); logininfor.setBrowser(browser); logininfor.setOs(os); logininfor.setMsg(message); // 日志状态 if (Constants.LOGIN_SUCCESS.equals(status) || Constants.LOGOUT.equals(status)) { logininfor.setStatus(Constants.SUCCESS); } else if (Constants.LOGIN_FAIL.equals(status)) { logininfor.setStatus(Constants.FAIL); } // 插入数据 SpringUtils.getBean(SysLogininforServiceImpl.class).insertLogininfor(logininfor); } }; }
Example #20
Source File: GenServiceImpl.java From ruoyiplus with MIT License | 5 votes |
private Map putIntoMap(Map retMap, VelocityContext context, List<String> templates) { for (String template : templates) { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); tpl.merge(context, sw); retMap.put(template, sw.toString()); } return retMap; }
Example #21
Source File: GenServiceImpl.java From ruoyiplus with MIT License | 5 votes |
/** * 生成代码 */ private void generatorCode(TableInfo table, ZipOutputStream zip) { // 设置主键 table.setPrimaryKey(table.getColumnsLast()); VelocityInitializer.initVelocity(); String packageName = Global.getPackageName(); String moduleName = GenUtils.getModuleName(packageName); VelocityContext context = GenUtils.getVelocityContext(table); // 获取模板列表 List<String> templates = GenUtils.getTemplates(); 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(GenUtils.getFileName(template, table, moduleName))); IOUtils.write(sw.toString(), zip, Constants.UTF8); IOUtils.closeQuietly(sw); zip.closeEntry(); } catch (IOException e) { log.error("渲染模板失败,表名:" + table.getTableName(), e); } } }
Example #22
Source File: ResourcesConfig.java From RuoYi-Vue with MIT License | 5 votes |
@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { /** 本地文件上传路径 */ registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + RuoYiConfig.getProfile() + "/"); /** swagger配置 */ registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); }
Example #23
Source File: TokenService.java From RuoYi-Vue with MIT License | 5 votes |
/** * 获取请求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; }
Example #24
Source File: TokenService.java From RuoYi-Vue with MIT License | 5 votes |
/** * 创建令牌 * * @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 #25
Source File: GenTableServiceImpl.java From supplierShop with MIT License | 5 votes |
/** * 查询表信息并生成代码 */ 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 #26
Source File: FileUploadUtils.java From RuoYi-Vue with MIT License | 5 votes |
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 #27
Source File: AddressUtils.java From RuoYi-Vue with MIT License | 5 votes |
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 File: LogoutFilter.java From supplierShop with MIT License | 5 votes |
@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 #29
Source File: TableSupport.java From supplierShop with MIT License | 5 votes |
/** * 封装分页对象 */ 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 #30
Source File: AbstractQuartzJob.java From supplierShop with MIT License | 5 votes |
/** * 执行后 * * @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); }