Java Code Examples for com.ruoyi.common.utils.StringUtils

The following examples show how to use com.ruoyi.common.utils.StringUtils. 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: ruoyiplus   Source File: XssFilter.java    License: MIT License 6 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
    String tempExcludes = filterConfig.getInitParameter("excludes");
    String tempEnabled = filterConfig.getInitParameter("enabled");
    if (StringUtils.isNotEmpty(tempExcludes))
    {
        String[] url = tempExcludes.split(",");
        for (int i = 0; url != null && i < url.length; i++)
        {
            excludes.add(url[i]);
        }
    }
    if (StringUtils.isNotEmpty(tempEnabled))
    {
        enabled = Boolean.valueOf(tempEnabled);
    }
}
 
Example 2
Source Project: supplierShop   Source File: SysProfileController.java    License: MIT License 6 votes vote down vote up
@Log(title = "重置密码", businessType = BusinessType.UPDATE)
@PostMapping("/resetPwd")
@ResponseBody
public AjaxResult resetPwd(String oldPassword, String newPassword)
{
    SysUser user = ShiroUtils.getSysUser();
    if (StringUtils.isNotEmpty(newPassword) && passwordService.matches(user, oldPassword))
    {
        user.setSalt(ShiroUtils.randomSalt());
        user.setPassword(passwordService.encryptPassword(user.getLoginName(), newPassword, user.getSalt()));
        if (userService.resetUserPwd(user) > 0)
        {
            ShiroUtils.setSysUser(userService.selectUserById(user.getUserId()));
            return success();
        }
        return error();
    }
    else
    {
        return error("修改密码失败,旧密码错误");
    }
}
 
Example 3
Source Project: supplierShop   Source File: DataSourceAspect.java    License: MIT License 6 votes vote down vote up
/**
 * 获取需要切换的数据源
 */
public DataSource getDataSource(ProceedingJoinPoint point)
{
    MethodSignature signature = (MethodSignature) point.getSignature();
    Class<? extends Object> targetClass = point.getTarget().getClass();
    DataSource targetDataSource = targetClass.getAnnotation(DataSource.class);
    if (StringUtils.isNotNull(targetDataSource))
    {
        return targetDataSource;
    }
    else
    {
        Method method = signature.getMethod();
        DataSource dataSource = method.getAnnotation(DataSource.class);
        return dataSource;
    }
}
 
Example 4
Source Project: RuoYi-Vue   Source File: GenTableServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 修改保存参数校验
 * 
 * @param genTable 业务信息
 */
@Override
public void validateEdit(GenTable genTable)
{
    if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
    {
        String options = JSON.toJSONString(genTable.getParams());
        JSONObject paramsObj = JSONObject.parseObject(options);
        if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
        {
            throw new CustomException("树编码字段不能为空");
        }
        else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
        {
            throw new CustomException("树父编码字段不能为空");
        }
        else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME)))
        {
            throw new CustomException("树名称字段不能为空");
        }
    }
}
 
Example 5
Source Project: supplierShop   Source File: SysShiroService.java    License: MIT License 6 votes vote down vote up
public Session createSession(SysUserOnline userOnline)
{
    OnlineSession onlineSession = new OnlineSession();
    if (StringUtils.isNotNull(userOnline))
    {
        onlineSession.setId(userOnline.getSessionId());
        onlineSession.setHost(userOnline.getIpaddr());
        onlineSession.setBrowser(userOnline.getBrowser());
        onlineSession.setOs(userOnline.getOs());
        onlineSession.setDeptName(userOnline.getDeptName());
        onlineSession.setLoginName(userOnline.getLoginName());
        onlineSession.setStartTimestamp(userOnline.getStartTimestamp());
        onlineSession.setLastAccessTime(userOnline.getLastAccessTime());
        onlineSession.setTimeout(userOnline.getExpireTime());
    }
    return onlineSession;
}
 
Example 6
Source Project: supplierShop   Source File: FilterConfig.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
public FilterRegistrationBean xssFilterRegistration()
{
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setDispatcherTypes(DispatcherType.REQUEST);
    registration.setFilter(new XssFilter());
    registration.addUrlPatterns(StringUtils.split(urlPatterns, ","));
    registration.setName("xssFilter");
    registration.setOrder(Integer.MAX_VALUE);
    Map<String, String> initParameters = new HashMap<String, String>();
    initParameters.put("excludes", excludes);
    initParameters.put("enabled", enabled);
    registration.setInitParameters(initParameters);
    return registration;
}
 
Example 7
Source Project: ruoyiplus   Source File: Convert.java    License: MIT License 6 votes vote down vote up
/**
 * 转换为Integer数组<br>
 * 
 * @param split 分隔符
 * @param split 被转换的值
 * @return 结果
 */
public static Integer[] toIntArray(String split, String str)
{
    if (StringUtils.isEmpty(str))
    {
        return new Integer[] {};
    }
    String[] arr = str.split(split);
    final Integer[] ints = new Integer[arr.length];
    for (int i = 0; i < arr.length; i++)
    {
        final Integer v = toInt(arr[i], 0);
        ints[i] = v;
    }
    return ints;
}
 
Example 8
Source Project: supplierShop   Source File: TestController.java    License: MIT License 6 votes vote down vote up
@ApiOperation("更新用户")
@ApiImplicitParam(name = "userEntity", value = "新增用户信息", dataType = "UserEntity")
@PutMapping("/update")
public AjaxResult update(UserEntity user)
{
    if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
    {
        return error("用户ID不能为空");
    }
    if (users.isEmpty() || !users.containsKey(user.getUserId()))
    {
        return error("用户不存在");
    }
    users.remove(user.getUserId());
    return AjaxResult.success(users.put(user.getUserId(), user));
}
 
Example 9
Source Project: RuoYi-Vue   Source File: RepeatableFilter.java    License: MIT License 6 votes vote down vote up
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException
{
    ServletRequest requestWrapper = null;
    if (request instanceof HttpServletRequest && StringUtils.equalsAnyIgnoreCase(request.getContentType(),
            MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_JSON_UTF8_VALUE))
    {
        requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response);
    }
    if (null == requestWrapper)
    {
        chain.doFilter(request, response);
    }
    else
    {
        chain.doFilter(requestWrapper, response);
    }
}
 
Example 10
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 11
Source Project: RuoYi-Vue   Source File: EscapeUtil.java    License: MIT License 6 votes vote down vote up
/**
 * Escape编码
 * 
 * @param text 被编码的文本
 * @return 编码后的字符
 */
private static String encode(String text)
{
    int len;
    if ((text == null) || ((len = text.length()) == 0))
    {
        return StringUtils.EMPTY;
    }
    StringBuilder buffer = new StringBuilder(len + (len >> 2));
    char c;
    for (int i = 0; i < len; i++)
    {
        c = text.charAt(i);
        if (c < 64)
        {
            buffer.append(TEXT[c]);
        }
        else
        {
            buffer.append(c);
        }
    }
    return buffer.toString();
}
 
Example 12
Source Project: supplierShop   Source File: SysDeptServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 根据角色ID查询部门(数据权限)
 *
 * @param role 角色对象
 * @return 部门列表(数据权限)
 */
@Override
public List<Ztree> roleDeptTreeData(SysRole role)
{
    Long roleId = role.getRoleId();
    List<Ztree> ztrees = new ArrayList<Ztree>();
    List<SysDept> deptList = selectDeptList(new SysDept());
    if (StringUtils.isNotNull(roleId))
    {
        List<String> roleDeptList = deptMapper.selectRoleDeptTree(roleId);
        ztrees = initZtree(deptList, roleDeptList);
    }
    else
    {
        ztrees = initZtree(deptList);
    }
    return ztrees;
}
 
Example 13
Source Project: supplierShop   Source File: Convert.java    License: MIT License 6 votes vote down vote up
/**
 * 转换为Long数组<br>
 * 
 * @param split 分隔符
 * @param str 被转换的值
 * @return 结果
 */
public static Long[] toLongArray(String split, String str)
{
    if (StringUtils.isEmpty(str))
    {
        return new Long[] {};
    }
    String[] arr = str.split(split);
    final Long[] longs = new Long[arr.length];
    for (int i = 0; i < arr.length; i++)
    {
        final Long v = toLong(arr[i], null);
        longs[i] = v;
    }
    return longs;
}
 
Example 14
Source Project: ruoyiplus   Source File: DataSourceAspect.java    License: MIT License 6 votes vote down vote up
@Around("dsPointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable
{
    MethodSignature signature = (MethodSignature) point.getSignature();

    Method method = signature.getMethod();

    DataSource dataSource = method.getAnnotation(DataSource.class);

    if (StringUtils.isNotNull(dataSource))
    {
        DynamicDataSourceContextHolder.setDateSoureType(dataSource.value().name());
    }

    try
    {
        return point.proceed();
    }
    finally
    {
        // 销毁数据源 在执行方法之后
        DynamicDataSourceContextHolder.clearDateSoureType();
    }
}
 
Example 15
Source Project: supplierShop   Source File: SysUserServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 查询用户所属岗位组
 * 
 * @param userId 用户ID
 * @return 结果
 */
@Override
public String selectUserPostGroup(Long userId)
{
    List<SysPost> list = postMapper.selectPostsByUserId(userId);
    StringBuffer idsStr = new StringBuffer();
    for (SysPost post : list)
    {
        idsStr.append(post.getPostName()).append(",");
    }
    if (StringUtils.isNotEmpty(idsStr.toString()))
    {
        return idsStr.substring(0, idsStr.length() - 1);
    }
    return idsStr.toString();
}
 
Example 16
Source Project: RuoYi-Vue   Source File: GenTableColumn.java    License: MIT License 6 votes vote down vote up
public String readConverterExp()
{
    String remarks = StringUtils.substringBetween(this.columnComment, "(", ")");
    StringBuffer sb = new StringBuffer();
    if (StringUtils.isNotEmpty(remarks))
    {
        for (String value : remarks.split(" "))
        {
            if (StringUtils.isNotEmpty(value))
            {
                Object startStr = value.subSequence(0, 1);
                String endStr = value.substring(1);
                sb.append("").append(startStr).append("=").append(endStr).append(",");
            }
        }
        return sb.deleteCharAt(sb.length() - 1).toString();
    }
    else
    {
        return this.columnComment;
    }
}
 
Example 17
Source Project: ruoyiplus   Source File: SysDeptServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 修改保存部门信息
 * 
 * @param dept 部门信息
 * @return 结果
 */
@Override
public int updateDept(SysDept dept)
{
    SysDept info = deptMapper.selectDeptById(dept.getParentId());
    if (StringUtils.isNotNull(info))
    {
        String ancestors = info.getAncestors() + "," + info.getDeptId();
        dept.setAncestors(ancestors);
        updateDeptChildren(dept.getDeptId(), ancestors);
    }
    int result = deptMapper.updateDept(dept);
    if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
    {
        // 如果该部门是启用状态,则启用该部门的所有上级部门
        updateParentDeptStatus(dept);
    }
    return result;
}
 
Example 18
Source Project: RuoYi-Vue   Source File: SysPostServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 校验岗位编码是否唯一
 * 
 * @param post 岗位信息
 * @return 结果
 */
@Override
public String checkPostCodeUnique(SysPost post)
{
    Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
    SysPost info = postMapper.checkPostCodeUnique(post.getPostCode());
    if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue())
    {
        return UserConstants.NOT_UNIQUE;
    }
    return UserConstants.UNIQUE;
}
 
Example 19
Source Project: supplierShop   Source File: SysUserServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 校验用户名称是否唯一
 *
 * @param user 用户信息
 * @return
 */
@Override
public String checkPhoneUnique(SysUser user)
{
    Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
    SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber());
    if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
    {
        return UserConstants.USER_PHONE_NOT_UNIQUE;
    }
    return UserConstants.USER_PHONE_UNIQUE;
}
 
Example 20
Source Project: supplierShop   Source File: GenUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 初始化表信息
 */
public static void initTable(GenTable genTable, String operName)
{
    genTable.setClassName(StringUtils.convertToCamelCase(genTable.getTableName()));
    genTable.setPackageName(GenConfig.getPackageName());
    genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
    genTable.setBusinessName(getBusinessName(genTable.getTableName()));
    genTable.setFunctionName(replaceText(genTable.getTableComment()));
    genTable.setFunctionAuthor(GenConfig.getAuthor());
    genTable.setCreateBy(operName);
}
 
Example 21
Source Project: RuoYi-Vue   Source File: TokenService.java    License: MIT License 5 votes vote down vote up
/**
 * 设置用户身份信息
 */
public void setLoginUser(LoginUser loginUser)
{
    if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken()))
    {
        refreshToken(loginUser);
    }
}
 
Example 22
Source Project: ruoyiplus   Source File: Convert.java    License: MIT License 5 votes vote down vote up
/**
 * 转换为字符<br>
 * 如果给定的值为null,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static Character toChar(Object value, Character defaultValue)
{
    if (null == value)
    {
        return defaultValue;
    }
    if (value instanceof Character)
    {
        return (Character) value;
    }

    final String valueStr = toStr(value, null);
    return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0);
}
 
Example 23
Source Project: RuoYi-Vue   Source File: SysMenuServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 校验菜单名称是否唯一
 * 
 * @param menu 菜单信息
 * @return 结果
 */
@Override
public String checkMenuNameUnique(SysMenu menu)
{
    Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId();
    SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId());
    if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue())
    {
        return UserConstants.NOT_UNIQUE;
    }
    return UserConstants.UNIQUE;
}
 
Example 24
Source Project: supplierShop   Source File: GenUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 获取数据库类型字段
 * 
 * @param columnType 列类型
 * @return 截取后的列类型
 */
public static String getDbType(String columnType)
{
    if (StringUtils.indexOf(columnType, "(") > 0)
    {
        return StringUtils.substringBefore(columnType, "(");
    }
    else
    {
        return columnType;
    }
}
 
Example 25
Source Project: supplierShop   Source File: GenUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 获取字段长度
 * 
 * @param columnType 列类型
 * @return 截取后的列类型
 */
public static Integer getColumnLength(String columnType)
{
    if (StringUtils.indexOf(columnType, "(") > 0)
    {
        String length = StringUtils.substringBetween(columnType, "(", ")");
        return Integer.valueOf(length);
    }
    else
    {
        return 0;
    }
}
 
Example 26
Source Project: RuoYi-Vue   Source File: GenTable.java    License: MIT License 5 votes vote down vote up
public static boolean isSuperColumn(String tplCategory, String javaField)
{
    if (isTree(tplCategory))
    {
        return StringUtils.equalsAnyIgnoreCase(javaField,
                ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY));
    }
    return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
}
 
Example 27
Source Project: RuoYi-Vue   Source File: JwtAuthenticationTokenFilter.java    License: MIT License 5 votes vote down vote up
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws ServletException, IOException
{
    LoginUser loginUser = tokenService.getLoginUser(request);
    if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication()))
    {
        tokenService.verifyToken(loginUser);
        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
        authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
        SecurityContextHolder.getContext().setAuthentication(authenticationToken);
    }
    chain.doFilter(request, response);
}
 
Example 28
Source Project: RuoYi-Vue   Source File: SysUserOnlineServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 通过用户名称查询信息
 * 
 * @param userName 用户名称
 * @param user 用户信息
 * @return 在线用户信息
 */
@Override
public SysUserOnline selectOnlineByUserName(String userName, LoginUser user)
{
    if (StringUtils.equals(userName, user.getUsername()))
    {
        return loginUserToUserOnline(user);
    }
    return null;
}
 
Example 29
Source Project: ruoyiplus   Source File: Convert.java    License: MIT License 5 votes vote down vote up
/**
 * 转换为double<br>
 * 如果给定的值为空,或者转换失败,返回默认值<br>
 * 转换失败不会报错
 * 
 * @param value 被转换的值
 * @param defaultValue 转换错误时的默认值
 * @return 结果
 */
public static Double toDouble(Object value, Double defaultValue)
{
    if (value == null)
    {
        return defaultValue;
    }
    if (value instanceof Double)
    {
        return (Double) value;
    }
    if (value instanceof Number)
    {
        return ((Number) value).doubleValue();
    }
    final String valueStr = toStr(value, null);
    if (StringUtils.isEmpty(valueStr))
    {
        return defaultValue;
    }
    try
    {
        // 支持科学计数法
        return new BigDecimal(valueStr.trim()).doubleValue();
    }
    catch (Exception e)
    {
        return defaultValue;
    }
}
 
Example 30
Source Project: RuoYi-Vue   Source File: AuthenticationEntryPointImpl.java    License: MIT License 5 votes vote down vote up
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
        throws IOException
{
    int code = HttpStatus.UNAUTHORIZED;
    String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
    ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
}