update 日常字符串校验 统一重构到 StringUtils 便于维护扩展
| | |
| | | import cn.hutool.captcha.generator.RandomGenerator; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | |
| | | |
| | | private String getCodeResult(String capStr) { |
| | | int numberLength = captchaProperties.getNumberLength(); |
| | | int a = Convert.toInt(StrUtil.sub(capStr, 0, numberLength).trim()); |
| | | int a = Convert.toInt(StringUtils.sub(capStr, 0, numberLength).trim()); |
| | | char operator = capStr.charAt(numberLength); |
| | | int b = Convert.toInt(StrUtil.sub(capStr, numberLength + 1, numberLength + 1 + numberLength).trim()); |
| | | int b = Convert.toInt(StringUtils.sub(capStr, numberLength + 1, numberLength + 1 + numberLength).trim()); |
| | | switch (operator) { |
| | | case '*': |
| | | return a * b + ""; |
| | |
| | | package com.ruoyi.web.controller.common; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | |
| | | { |
| | | if (!FileUtils.checkAllowDownload(fileName)) |
| | | { |
| | | throw new Exception(StrUtil.format("æä»¶åç§°({})éæ³ï¼ä¸å
许ä¸è½½ã ", fileName)); |
| | | throw new Exception(StringUtils.format("æä»¶åç§°({})éæ³ï¼ä¸å
许ä¸è½½ã ", fileName)); |
| | | } |
| | | String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); |
| | | String filePath = RuoYiConfig.getDownloadPath() + fileName; |
| | |
| | | { |
| | | if (!FileUtils.checkAllowDownload(resource)) |
| | | { |
| | | throw new Exception(StrUtil.format("èµæºæä»¶({})éæ³ï¼ä¸å
许ä¸è½½ã ", resource)); |
| | | throw new Exception(StringUtils.format("èµæºæä»¶({})éæ³ï¼ä¸å
许ä¸è½½ã ", resource)); |
| | | } |
| | | // æ¬å°èµæºè·¯å¾ |
| | | String localPath = RuoYiConfig.getProfile(); |
| | | // æ°æ®åºèµæºå°å |
| | | String downloadPath = localPath + StrUtil.subAfter(resource, Constants.RESOURCE_PREFIX,false); |
| | | String downloadPath = localPath + StringUtils.subAfter(resource, Constants.RESOURCE_PREFIX,false); |
| | | // ä¸è½½åç§° |
| | | String downloadName = StrUtil.subAfter(downloadPath, "/",true); |
| | | String downloadName = StringUtils.subAfter(downloadPath, "/",true); |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
| | | File file = new File(downloadPath); |
| | | FileUtils.setAttachmentResponseHeader(response, downloadName); |
| | |
| | | package com.ruoyi.web.controller.monitor;
|
| | |
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.data.redis.core.RedisCallback;
|
| | | import org.springframework.data.redis.core.RedisTemplate;
|
| | | import org.springframework.security.access.prepost.PreAuthorize;
|
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | |
|
| | | import java.util.*;
|
| | |
|
| | | /**
|
| | | * ç¼åçæ§
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @RestController
|
| | | @RequestMapping("/monitor/cache")
|
| | | public class CacheController
|
| | | {
|
| | | @Autowired
|
| | | private RedisTemplate<String, String> redisTemplate;
|
| | |
|
| | | @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
|
| | | @GetMapping()
|
| | | public AjaxResult getInfo() throws Exception
|
| | | {
|
| | | Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info());
|
| | | Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats"));
|
| | | Object dbSize = redisTemplate.execute((RedisCallback<Object>) connection -> connection.dbSize());
|
| | |
|
| | | Map<String, Object> result = new HashMap<>(3);
|
| | | result.put("info", info);
|
| | | result.put("dbSize", dbSize);
|
| | |
|
| | | List<Map<String, String>> pieList = new ArrayList<>();
|
| | | commandStats.stringPropertyNames().forEach(key -> {
|
| | | Map<String, String> data = new HashMap<>(2);
|
| | | String property = commandStats.getProperty(key);
|
| | | data.put("name", StrUtil.removePrefix(key, "cmdstat_"));
|
| | | data.put("value", StrUtil.subBetween(property, "calls=", ",usec"));
|
| | | pieList.add(data);
|
| | | });
|
| | | result.put("commandStats", pieList);
|
| | | return AjaxResult.success(result);
|
| | | }
|
| | | }
|
| | | package com.ruoyi.web.controller.monitor; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisCallback; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * ç¼åçæ§ |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/monitor/cache") |
| | | public class CacheController |
| | | { |
| | | @Autowired |
| | | private RedisTemplate<String, String> redisTemplate; |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:cache:list')") |
| | | @GetMapping() |
| | | public AjaxResult getInfo() throws Exception |
| | | { |
| | | Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info()); |
| | | Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats")); |
| | | Object dbSize = redisTemplate.execute((RedisCallback<Object>) connection -> connection.dbSize()); |
| | | |
| | | Map<String, Object> result = new HashMap<>(3); |
| | | result.put("info", info); |
| | | result.put("dbSize", dbSize); |
| | | |
| | | List<Map<String, String>> pieList = new ArrayList<>(); |
| | | commandStats.stringPropertyNames().forEach(key -> { |
| | | Map<String, String> data = new HashMap<>(2); |
| | | String property = commandStats.getProperty(key); |
| | | data.put("name", StringUtils.removePrefix(key, "cmdstat_")); |
| | | data.put("value", StringUtils.subBetween(property, "calls=", ",usec")); |
| | | pieList.add(data); |
| | | }); |
| | | result.put("commandStats", pieList); |
| | | return AjaxResult.success(result); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.web.controller.monitor; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | |
| | | /** |
| | | * å¨çº¿ç¨æ·çæ§ |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @RestController |
| | |
| | | LoginUser user = redisCache.getCacheObject(key); |
| | | if (Validator.isNotEmpty(ipaddr) && Validator.isNotEmpty(userName)) |
| | | { |
| | | if (StrUtil.equals(ipaddr, user.getIpaddr()) && StrUtil.equals(userName, user.getUsername())) |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) |
| | | { |
| | | userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user)); |
| | | } |
| | | } |
| | | else if (Validator.isNotEmpty(ipaddr)) |
| | | { |
| | | if (StrUtil.equals(ipaddr, user.getIpaddr())) |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr())) |
| | | { |
| | | userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user)); |
| | | } |
| | | } |
| | | else if (Validator.isNotEmpty(userName) && Validator.isNotNull(user.getUser())) |
| | | { |
| | | if (StrUtil.equals(userName, user.getUsername())) |
| | | if (StringUtils.equals(userName, user.getUsername())) |
| | | { |
| | | userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user)); |
| | | } |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | { |
| | | SysDept d = (SysDept) it.next(); |
| | | if (d.getDeptId().intValue() == deptId |
| | | || ArrayUtils.contains(StrUtil.splitToArray(d.getAncestors(), ","), deptId + "")) |
| | | || ArrayUtils.contains(StringUtils.splitToArray(d.getAncestors(), ","), deptId + "")) |
| | | { |
| | | it.remove(); |
| | | } |
| | |
| | | { |
| | | return AjaxResult.error("ä¿®æ¹é¨é¨'" + dept.getDeptName() + "'失败ï¼ä¸çº§é¨é¨ä¸è½æ¯èªå·±"); |
| | | } |
| | | else if (StrUtil.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) |
| | | else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) |
| | | && deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0) |
| | | { |
| | | return AjaxResult.error("该é¨é¨å
嫿ªåç¨çåé¨é¨ï¼"); |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | @RequestMapping("/") |
| | | public String index() |
| | | { |
| | | return StrUtil.format("欢è¿ä½¿ç¨{}åå°ç®¡çæ¡æ¶ï¼å½åçæ¬ï¼v{}ï¼è¯·éè¿å端å°å访é®ã", ruoyiConfig.getName(), ruoyiConfig.getVersion()); |
| | | return StringUtils.format("欢è¿ä½¿ç¨{}åå°ç®¡çæ¡æ¶ï¼å½åçæ¬ï¼v{}ï¼è¯·éè¿å端å°å访é®ã", ruoyiConfig.getName(), ruoyiConfig.getVersion()); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | { |
| | | return AjaxResult.error("æ°å¢èå'" + menu.getMenuName() + "'失败ï¼èååç§°å·²åå¨"); |
| | | } |
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !Validator.isUrl(menu.getPath())) |
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) |
| | | { |
| | | return AjaxResult.error("æ°å¢èå'" + menu.getMenuName() + "'失败ï¼å°åå¿
须以http(s)://å¼å¤´"); |
| | | } |
| | |
| | | { |
| | | return AjaxResult.error("ä¿®æ¹èå'" + menu.getMenuName() + "'失败ï¼èååç§°å·²åå¨"); |
| | | } |
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !Validator.isUrl(menu.getPath())) |
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) |
| | | { |
| | | return AjaxResult.error("ä¿®æ¹èå'" + menu.getMenuName() + "'失败ï¼å°åå¿
须以http(s)://å¼å¤´"); |
| | | } |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | |
| | | @PutMapping |
| | | public AjaxResult updateProfile(@RequestBody SysUser user) |
| | | { |
| | | if (StrUtil.isNotEmpty(user.getPhonenumber()) |
| | | if (StringUtils.isNotEmpty(user.getPhonenumber()) |
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) |
| | | { |
| | | return AjaxResult.error("ä¿®æ¹ç¨æ·'" + user.getUserName() + "'å¤±è´¥ï¼ææºå·ç å·²åå¨"); |
| | | } |
| | | if (StrUtil.isNotEmpty(user.getEmail()) |
| | | if (StringUtils.isNotEmpty(user.getEmail()) |
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) |
| | | { |
| | | return AjaxResult.error("ä¿®æ¹ç¨æ·'" + user.getUserName() + "'失败ï¼é®ç®±è´¦å·å·²åå¨"); |
| | |
| | | package com.ruoyi.web.controller.system;
|
| | |
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.util.StringUtils;
|
| | | import org.springframework.web.bind.annotation.PostMapping;
|
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.core.controller.BaseController;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.model.RegisterBody;
|
| | | import com.ruoyi.framework.web.service.SysRegisterService;
|
| | | import com.ruoyi.system.service.ISysConfigService;
|
| | |
|
| | | /**
|
| | | * 注åéªè¯
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @RestController
|
| | | public class SysRegisterController extends BaseController
|
| | | {
|
| | | @Autowired
|
| | | private SysRegisterService registerService;
|
| | |
|
| | | @Autowired
|
| | | private ISysConfigService configService;
|
| | |
|
| | | @PostMapping("/register")
|
| | | public AjaxResult register(@RequestBody RegisterBody user)
|
| | | {
|
| | | if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
|
| | | {
|
| | | return error("å½åç³»ç»æ²¡æå¼å¯æ³¨ååè½ï¼");
|
| | | }
|
| | | String msg = registerService.register(user);
|
| | | return StringUtils.isEmpty(msg) ? success() : error(msg);
|
| | | }
|
| | | }
|
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.model.RegisterBody; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.web.service.SysRegisterService; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | /** |
| | | * 注åéªè¯ |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @RestController |
| | | public class SysRegisterController extends BaseController |
| | | { |
| | | @Autowired |
| | | private SysRegisterService registerService; |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | @PostMapping("/register") |
| | | public AjaxResult register(@RequestBody RegisterBody user) |
| | | { |
| | | if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) |
| | | { |
| | | return error("å½åç³»ç»æ²¡æå¼å¯æ³¨ååè½ï¼"); |
| | | } |
| | | String msg = registerService.register(user); |
| | | return StringUtils.isEmpty(msg) ? success() : error(msg); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.common.core.controller; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | */ |
| | | public String redirect(String url) |
| | | { |
| | | return StrUtil.format("redirect:{}", url); |
| | | return StringUtils.format("redirect:{}", url); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.common.core.mybatisplus.methods; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.core.injector.AbstractMethod; |
| | | import com.baomidou.mybatisplus.core.metadata.TableInfo; |
| | | import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; |
| | | import org.apache.ibatis.executor.keygen.KeyGenerator; |
| | | import org.apache.ibatis.executor.keygen.NoKeyGenerator; |
| | |
| | | String keyProperty = null; |
| | | String keyColumn = null; |
| | | // 表å
å«ä¸»é®å¤çé»è¾,妿ä¸å
å«ä¸»é®å½æ®éåæ®µå¤ç |
| | | if (StrUtil.isNotBlank(tableInfo.getKeyProperty())) { |
| | | if (StringUtils.isNotBlank(tableInfo.getKeyProperty())) { |
| | | if (tableInfo.getIdType() == IdType.AUTO) { |
| | | /** èªå¢ä¸»é® */ |
| | | keyGenerator = new Jdbc3KeyGenerator(); |
| | |
| | | |
| | | private String prepareFieldSql(TableInfo tableInfo) { |
| | | StringBuilder fieldSql = new StringBuilder(); |
| | | if (StrUtil.isNotBlank(tableInfo.getKeyColumn())) { |
| | | if (StringUtils.isNotBlank(tableInfo.getKeyColumn())) { |
| | | fieldSql.append(tableInfo.getKeyColumn()).append(","); |
| | | } |
| | | tableInfo.getFieldList().forEach(x -> fieldSql.append(x.getColumn()).append(",")); |
| | |
| | | private String prepareValuesSqlForMysqlBatch(TableInfo tableInfo) { |
| | | final StringBuilder valueSql = new StringBuilder(); |
| | | valueSql.append("<foreach collection=\"list\" item=\"item\" index=\"index\" open=\"(\" separator=\"),(\" close=\")\">"); |
| | | if (StrUtil.isNotBlank(tableInfo.getKeyColumn())) { |
| | | if (StringUtils.isNotBlank(tableInfo.getKeyColumn())) { |
| | | valueSql.append("#{item.").append(tableInfo.getKeyProperty()).append("},"); |
| | | } |
| | | tableInfo.getFieldList().forEach(x -> valueSql.append("#{item.").append(x.getProperty()).append("},")); |
| | |
| | | package com.ruoyi.common.exception; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.utils.MessageUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * åºç¡å¼å¸¸ |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class BaseException extends RuntimeException |
| | |
| | | public String getMessage() |
| | | { |
| | | String message = null; |
| | | if (!Validator.isEmpty(code)) |
| | | if (!StringUtils.isEmpty(code)) |
| | | { |
| | | message = MessageUtils.message(code, args); |
| | | } |
| | |
| | | package com.ruoyi.common.filter;
|
| | |
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import org.springframework.http.MediaType;
|
| | |
|
| | | import javax.servlet.*;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import java.io.IOException;
|
| | |
|
| | | /**
|
| | | * Repeatable è¿æ»¤å¨
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class RepeatableFilter implements Filter
|
| | | {
|
| | | @Override
|
| | | public void init(FilterConfig filterConfig) throws ServletException
|
| | | {
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
| | | throws IOException, ServletException
|
| | | {
|
| | | ServletRequest requestWrapper = null;
|
| | | if (request instanceof HttpServletRequest
|
| | | && StrUtil.startWithIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE))
|
| | | {
|
| | | requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response);
|
| | | }
|
| | | if (null == requestWrapper)
|
| | | {
|
| | | chain.doFilter(request, response);
|
| | | }
|
| | | else
|
| | | {
|
| | | chain.doFilter(requestWrapper, response);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void destroy()
|
| | | {
|
| | |
|
| | | }
|
| | | }
|
| | | package com.ruoyi.common.filter; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.springframework.http.MediaType; |
| | | |
| | | import javax.servlet.*; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * Repeatable è¿æ»¤å¨ |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class RepeatableFilter implements Filter |
| | | { |
| | | @Override |
| | | public void init(FilterConfig filterConfig) throws ServletException |
| | | { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |
| | | throws IOException, ServletException |
| | | { |
| | | ServletRequest requestWrapper = null; |
| | | if (request instanceof HttpServletRequest |
| | | && StringUtils.startWithIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE)) |
| | | { |
| | | requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response); |
| | | } |
| | | if (null == requestWrapper) |
| | | { |
| | | chain.doFilter(request, response); |
| | | } |
| | | else |
| | | { |
| | | chain.doFilter(requestWrapper, response); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void destroy() |
| | | { |
| | | |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.common.filter; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | import javax.servlet.*; |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * 鲿¢XSSæ»å»çè¿æ»¤å¨ |
| | |
| | | public void init(FilterConfig filterConfig) throws ServletException |
| | | { |
| | | String tempExcludes = filterConfig.getInitParameter("excludes"); |
| | | if (StrUtil.isNotEmpty(tempExcludes)) |
| | | if (StringUtils.isNotEmpty(tempExcludes)) |
| | | { |
| | | String[] url = tempExcludes.split(","); |
| | | for (int i = 0; url != null && i < url.length; i++) |
| | |
| | | { |
| | | return true; |
| | | } |
| | | return StrUtil.matches(url, excludes); |
| | | return StringUtils.matches(url, excludes); |
| | | } |
| | | |
| | | @Override |
| | |
| | | package com.ruoyi.common.filter; |
| | | |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HtmlUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | |
| | |
| | | |
| | | // 为空ï¼ç´æ¥è¿å |
| | | String json = IoUtil.read(super.getInputStream(), StandardCharsets.UTF_8); |
| | | if (Validator.isEmpty(json)) |
| | | if (StringUtils.isEmpty(json)) |
| | | { |
| | | return super.getInputStream(); |
| | | } |
| | |
| | | public boolean isJsonRequest() |
| | | { |
| | | String header = super.getHeader(HttpHeaders.CONTENT_TYPE); |
| | | return StrUtil.startWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE); |
| | | return StringUtils.startWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.common.utils;
|
| | |
|
| | | import cn.hutool.core.collection.CollUtil;
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.core.domain.entity.SysDictData;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | |
|
| | | import java.util.Collection;
|
| | | import java.util.List;
|
| | |
|
| | | /**
|
| | | * åå
¸å·¥å
·ç±»
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | public class DictUtils
|
| | | {
|
| | | /**
|
| | | * åé符
|
| | | */
|
| | | public static final String SEPARATOR = ",";
|
| | |
|
| | | /**
|
| | | * 设置åå
¸ç¼å
|
| | | * |
| | | * @param key åæ°é®
|
| | | * @param dictDatas åå
¸æ°æ®å表
|
| | | */
|
| | | public static void setDictCache(String key, List<SysDictData> dictDatas)
|
| | | {
|
| | | SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas);
|
| | | }
|
| | |
|
| | | /**
|
| | | * è·ååå
¸ç¼å
|
| | | * |
| | | * @param key åæ°é®
|
| | | * @return dictDatas åå
¸æ°æ®å表
|
| | | */
|
| | | public static List<SysDictData> getDictCache(String key)
|
| | | {
|
| | | Object cacheObj = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
|
| | | if (Validator.isNotNull(cacheObj))
|
| | | {
|
| | | List<SysDictData> dictDatas = (List<SysDictData>)cacheObj;
|
| | | return dictDatas;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ ¹æ®åå
¸ç±»åååå
¸å¼è·ååå
¸æ ç¾
|
| | | * |
| | | * @param dictType åå
¸ç±»å
|
| | | * @param dictValue åå
¸å¼
|
| | | * @return åå
¸æ ç¾
|
| | | */
|
| | | public static String getDictLabel(String dictType, String dictValue)
|
| | | {
|
| | | return getDictLabel(dictType, dictValue, SEPARATOR);
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ ¹æ®åå
¸ç±»åååå
¸æ ç¾è·ååå
¸å¼
|
| | | * |
| | | * @param dictType åå
¸ç±»å
|
| | | * @param dictLabel åå
¸æ ç¾
|
| | | * @return åå
¸å¼
|
| | | */
|
| | | public static String getDictValue(String dictType, String dictLabel)
|
| | | {
|
| | | return getDictValue(dictType, dictLabel, SEPARATOR);
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ ¹æ®åå
¸ç±»åååå
¸å¼è·ååå
¸æ ç¾
|
| | | * |
| | | * @param dictType åå
¸ç±»å
|
| | | * @param dictValue åå
¸å¼
|
| | | * @param separator åé符
|
| | | * @return åå
¸æ ç¾
|
| | | */
|
| | | public static String getDictLabel(String dictType, String dictValue, String separator)
|
| | | {
|
| | | StringBuilder propertyString = new StringBuilder();
|
| | | List<SysDictData> datas = getDictCache(dictType);
|
| | |
|
| | | if (StrUtil.containsAny(dictValue, separator) && CollUtil.isNotEmpty(datas))
|
| | | {
|
| | | for (SysDictData dict : datas)
|
| | | {
|
| | | for (String value : dictValue.split(separator))
|
| | | {
|
| | | if (value.equals(dict.getDictValue()))
|
| | | {
|
| | | propertyString.append(dict.getDictLabel() + separator);
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | for (SysDictData dict : datas)
|
| | | {
|
| | | if (dictValue.equals(dict.getDictValue()))
|
| | | {
|
| | | return dict.getDictLabel();
|
| | | }
|
| | | }
|
| | | }
|
| | | return StrUtil.strip(propertyString.toString(), null, separator);
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ ¹æ®åå
¸ç±»åååå
¸æ ç¾è·ååå
¸å¼
|
| | | * |
| | | * @param dictType åå
¸ç±»å
|
| | | * @param dictLabel åå
¸æ ç¾
|
| | | * @param separator åé符
|
| | | * @return åå
¸å¼
|
| | | */
|
| | | public static String getDictValue(String dictType, String dictLabel, String separator)
|
| | | {
|
| | | StringBuilder propertyString = new StringBuilder();
|
| | | List<SysDictData> datas = getDictCache(dictType);
|
| | |
|
| | | if (StrUtil.containsAny(dictLabel, separator) && CollUtil.isNotEmpty(datas))
|
| | | {
|
| | | for (SysDictData dict : datas)
|
| | | {
|
| | | for (String label : dictLabel.split(separator))
|
| | | {
|
| | | if (label.equals(dict.getDictLabel()))
|
| | | {
|
| | | propertyString.append(dict.getDictValue() + separator);
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | for (SysDictData dict : datas)
|
| | | {
|
| | | if (dictLabel.equals(dict.getDictLabel()))
|
| | | {
|
| | | return dict.getDictValue();
|
| | | }
|
| | | }
|
| | | }
|
| | | return StrUtil.strip(propertyString.toString(), null, separator);
|
| | | }
|
| | |
|
| | | /**
|
| | | * å 餿å®åå
¸ç¼å
|
| | | * |
| | | * @param key åå
¸é®
|
| | | */
|
| | | public static void removeDictCache(String key)
|
| | | {
|
| | | SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key));
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ¸
空åå
¸ç¼å
|
| | | */
|
| | | public static void clearDictCache()
|
| | | {
|
| | | Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(Constants.SYS_DICT_KEY + "*");
|
| | | SpringUtils.getBean(RedisCache.class).deleteObject(keys);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置cache key
|
| | | * |
| | | * @param configKey åæ°é®
|
| | | * @return ç¼åé®key
|
| | | */
|
| | | public static String getCacheKey(String configKey)
|
| | | {
|
| | | return Constants.SYS_DICT_KEY + configKey;
|
| | | }
|
| | | }
|
| | | package com.ruoyi.common.utils; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * åå
¸å·¥å
·ç±» |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class DictUtils |
| | | { |
| | | /** |
| | | * åé符 |
| | | */ |
| | | public static final String SEPARATOR = ","; |
| | | |
| | | /** |
| | | * 设置åå
¸ç¼å |
| | | * |
| | | * @param key åæ°é® |
| | | * @param dictDatas åå
¸æ°æ®å表 |
| | | */ |
| | | public static void setDictCache(String key, List<SysDictData> dictDatas) |
| | | { |
| | | SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas); |
| | | } |
| | | |
| | | /** |
| | | * è·ååå
¸ç¼å |
| | | * |
| | | * @param key åæ°é® |
| | | * @return dictDatas åå
¸æ°æ®å表 |
| | | */ |
| | | public static List<SysDictData> getDictCache(String key) |
| | | { |
| | | Object cacheObj = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key)); |
| | | if (StringUtils.isNotNull(cacheObj)) |
| | | { |
| | | List<SysDictData> dictDatas = (List<SysDictData>)cacheObj; |
| | | return dictDatas; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åååå
¸å¼è·ååå
¸æ ç¾ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @param dictValue åå
¸å¼ |
| | | * @return åå
¸æ ç¾ |
| | | */ |
| | | public static String getDictLabel(String dictType, String dictValue) |
| | | { |
| | | return getDictLabel(dictType, dictValue, SEPARATOR); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åååå
¸æ ç¾è·ååå
¸å¼ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @param dictLabel åå
¸æ ç¾ |
| | | * @return åå
¸å¼ |
| | | */ |
| | | public static String getDictValue(String dictType, String dictLabel) |
| | | { |
| | | return getDictValue(dictType, dictLabel, SEPARATOR); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åååå
¸å¼è·ååå
¸æ ç¾ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @param dictValue åå
¸å¼ |
| | | * @param separator åé符 |
| | | * @return åå
¸æ ç¾ |
| | | */ |
| | | public static String getDictLabel(String dictType, String dictValue, String separator) |
| | | { |
| | | StringBuilder propertyString = new StringBuilder(); |
| | | List<SysDictData> datas = getDictCache(dictType); |
| | | |
| | | if (StringUtils.containsAny(dictValue, separator) && CollUtil.isNotEmpty(datas)) |
| | | { |
| | | for (SysDictData dict : datas) |
| | | { |
| | | for (String value : dictValue.split(separator)) |
| | | { |
| | | if (value.equals(dict.getDictValue())) |
| | | { |
| | | propertyString.append(dict.getDictLabel() + separator); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (SysDictData dict : datas) |
| | | { |
| | | if (dictValue.equals(dict.getDictValue())) |
| | | { |
| | | return dict.getDictLabel(); |
| | | } |
| | | } |
| | | } |
| | | return StringUtils.strip(propertyString.toString(), null, separator); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®åå
¸ç±»åååå
¸æ ç¾è·ååå
¸å¼ |
| | | * |
| | | * @param dictType åå
¸ç±»å |
| | | * @param dictLabel åå
¸æ ç¾ |
| | | * @param separator åé符 |
| | | * @return åå
¸å¼ |
| | | */ |
| | | public static String getDictValue(String dictType, String dictLabel, String separator) |
| | | { |
| | | StringBuilder propertyString = new StringBuilder(); |
| | | List<SysDictData> datas = getDictCache(dictType); |
| | | |
| | | if (StringUtils.containsAny(dictLabel, separator) && CollUtil.isNotEmpty(datas)) |
| | | { |
| | | for (SysDictData dict : datas) |
| | | { |
| | | for (String label : dictLabel.split(separator)) |
| | | { |
| | | if (label.equals(dict.getDictLabel())) |
| | | { |
| | | propertyString.append(dict.getDictValue() + separator); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (SysDictData dict : datas) |
| | | { |
| | | if (dictLabel.equals(dict.getDictLabel())) |
| | | { |
| | | return dict.getDictValue(); |
| | | } |
| | | } |
| | | } |
| | | return StringUtils.strip(propertyString.toString(), null, separator); |
| | | } |
| | | |
| | | /** |
| | | * å 餿å®åå
¸ç¼å |
| | | * |
| | | * @param key åå
¸é® |
| | | */ |
| | | public static void removeDictCache(String key) |
| | | { |
| | | SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key)); |
| | | } |
| | | |
| | | /** |
| | | * æ¸
空åå
¸ç¼å |
| | | */ |
| | | public static void clearDictCache() |
| | | { |
| | | Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(Constants.SYS_DICT_KEY + "*"); |
| | | SpringUtils.getBean(RedisCache.class).deleteObject(keys); |
| | | } |
| | | |
| | | /** |
| | | * 设置cache key |
| | | * |
| | | * @param configKey åæ°é® |
| | | * @return ç¼åé®key |
| | | */ |
| | | public static String getCacheKey(String configKey) |
| | | { |
| | | return Constants.SYS_DICT_KEY + configKey; |
| | | } |
| | | } |
| | |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | |
| | | } |
| | | |
| | | public static String toJsonString(Object object) { |
| | | if (Validator.isEmpty(object)) { |
| | | if (StringUtils.isNull(object)) { |
| | | return null; |
| | | } |
| | | try { |
| | |
| | | } |
| | | |
| | | public static <T> T parseObject(String text, Class<T> clazz) { |
| | | if (StrUtil.isEmpty(text)) { |
| | | if (StringUtils.isEmpty(text)) { |
| | | return null; |
| | | } |
| | | try { |
| | |
| | | } |
| | | |
| | | public static <T> T parseObject(String text, TypeReference<T> typeReference) { |
| | | if (StrUtil.isBlank(text)) { |
| | | if (StringUtils.isBlank(text)) { |
| | | return null; |
| | | } |
| | | try { |
| | |
| | | } |
| | | |
| | | public static <T> Map<String, T> parseMap(String text) { |
| | | if (StrUtil.isBlank(text)) { |
| | | if (StringUtils.isBlank(text)) { |
| | | return null; |
| | | } |
| | | try { |
| | |
| | | } |
| | | |
| | | public static <T> List<T> parseArray(String text, Class<T> clazz) { |
| | | if (StrUtil.isEmpty(text)) { |
| | | if (StringUtils.isEmpty(text)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | try { |
| | |
| | | package com.ruoyi.common.utils; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpStatus; |
| | | import com.baomidou.mybatisplus.core.metadata.OrderItem; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | String orderByColumn = ServletUtils.getParameter(ORDER_BY_COLUMN); |
| | | String isAsc = ServletUtils.getParameter(IS_ASC); |
| | | PagePlus<T, K> page = new PagePlus<>(pageNum, pageSize); |
| | | if (StrUtil.isNotBlank(orderByColumn)) { |
| | | if (StringUtils.isNotBlank(orderByColumn)) { |
| | | String orderBy = SqlUtil.escapeOrderBySql(orderByColumn); |
| | | if ("asc".equals(isAsc)) { |
| | | page.addOrder(OrderItem.asc(orderBy)); |
| | |
| | | isAsc = "desc"; |
| | | } |
| | | Page<T> page = new Page<>(pageNum, pageSize); |
| | | if (StrUtil.isNotBlank(orderByColumn)) { |
| | | if (StringUtils.isNotBlank(orderByColumn)) { |
| | | String orderBy = SqlUtil.escapeOrderBySql(orderByColumn); |
| | | orderBy = StrUtil.toUnderlineCase(orderBy); |
| | | orderBy = StringUtils.toUnderlineCase(orderBy); |
| | | if ("asc".equals(isAsc)) { |
| | | page.addOrder(OrderItem.asc(orderBy)); |
| | | } else if ("desc".equals(isAsc)) { |
| | |
| | | package com.ruoyi.common.utils; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.extra.servlet.ServletUtil; |
| | | import cn.hutool.http.HttpStatus; |
| | | import org.springframework.http.MediaType; |
| | |
| | | } |
| | | |
| | | String uri = request.getRequestURI(); |
| | | if (StrUtil.equalsAnyIgnoreCase(uri, ".json", ".xml")) { |
| | | if (StringUtils.equalsAnyIgnoreCase(uri, ".json", ".xml")) { |
| | | return true; |
| | | } |
| | | |
| | | String ajax = request.getParameter("__ajax"); |
| | | if (StrUtil.equalsAnyIgnoreCase(ajax, "json", "xml")) { |
| | | if (StringUtils.equalsAnyIgnoreCase(ajax, "json", "xml")) { |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | package com.ruoyi.common.utils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.HashSet; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.ReUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import org.springframework.util.AntPathMatcher; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.text.StrFormatter; |
| | | |
| | | /** |
| | | * å符串工å
·ç±» |
| | | * |
| | | * @author ruoyi |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | public class StringUtils extends org.apache.commons.lang3.StringUtils |
| | | { |
| | | /** 空å符串 */ |
| | | private static final String NULLSTR = ""; |
| | | public class StringUtils extends StrUtil { |
| | | |
| | | /** ä¸å线 */ |
| | | private static final char SEPARATOR = '_'; |
| | | /** |
| | | * * 夿ä¸ä¸ªå¯¹è±¡æ¯å¦ä¸ºç©º |
| | | * |
| | | * @param object Object |
| | | * @return trueï¼ä¸ºç©º falseï¼é空 |
| | | */ |
| | | public static boolean isNull(Object object) { |
| | | return Validator.isNull(object); |
| | | } |
| | | |
| | | /** |
| | | * è·ååæ°ä¸ä¸ºç©ºå¼ |
| | | * |
| | | * @param value defaultValue è¦å¤æçvalue |
| | | * @return value è¿åå¼ |
| | | */ |
| | | public static <T> T nvl(T value, T defaultValue) |
| | | { |
| | | return value != null ? value : defaultValue; |
| | | } |
| | | /** |
| | | * * 夿ä¸ä¸ªå¯¹è±¡æ¯å¦é空 |
| | | * |
| | | * @param object Object |
| | | * @return trueï¼é空 falseï¼ç©º |
| | | */ |
| | | public static boolean isNotNull(Object object) { |
| | | return Validator.isNotNull(object); |
| | | } |
| | | |
| | | /** |
| | | * * 夿ä¸ä¸ªCollectionæ¯å¦ä¸ºç©ºï¼ å
å«Listï¼Setï¼Queue |
| | | * |
| | | * @param coll è¦å¤æçCollection |
| | | * @return trueï¼ä¸ºç©º falseï¼é空 |
| | | */ |
| | | public static boolean isEmpty(Collection<?> coll) |
| | | { |
| | | return isNull(coll) || coll.isEmpty(); |
| | | } |
| | | /** |
| | | * æ¿æ¢ææ |
| | | */ |
| | | public static String replaceEach(String text, String[] searchList, String[] replacementList) { |
| | | return org.apache.commons.lang3.StringUtils.replaceEach(text, searchList, replacementList); |
| | | } |
| | | |
| | | /** |
| | | * * 夿ä¸ä¸ªCollectionæ¯å¦é空ï¼å
å«Listï¼Setï¼Queue |
| | | * |
| | | * @param coll è¦å¤æçCollection |
| | | * @return trueï¼é空 falseï¼ç©º |
| | | */ |
| | | public static boolean isNotEmpty(Collection<?> coll) |
| | | { |
| | | return !isEmpty(coll); |
| | | } |
| | | /** |
| | | * éªè¯è¯¥å符串æ¯å¦æ¯æ°å |
| | | * |
| | | * @param value å符串å
容 |
| | | * @return æ¯å¦æ¯æ°å |
| | | */ |
| | | public static boolean isNumeric(CharSequence value) { |
| | | return Validator.isNumber(value); |
| | | } |
| | | |
| | | /** |
| | | * * 夿ä¸ä¸ªå¯¹è±¡æ°ç»æ¯å¦ä¸ºç©º |
| | | * |
| | | * @param objects è¦å¤æç对象æ°ç» |
| | | ** @return trueï¼ä¸ºç©º falseï¼é空 |
| | | */ |
| | | public static boolean isEmpty(Object[] objects) |
| | | { |
| | | return isNull(objects) || (objects.length == 0); |
| | | } |
| | | /** |
| | | * æ¯å¦ä¸ºhttp(s)://å¼å¤´ |
| | | * |
| | | * @param link 龿¥ |
| | | * @return ç»æ |
| | | */ |
| | | public static boolean ishttp(String link) { |
| | | return Validator.isUrl(link); |
| | | } |
| | | |
| | | /** |
| | | * * 夿ä¸ä¸ªå¯¹è±¡æ°ç»æ¯å¦é空 |
| | | * |
| | | * @param objects è¦å¤æç对象æ°ç» |
| | | * @return trueï¼é空 falseï¼ç©º |
| | | */ |
| | | public static boolean isNotEmpty(Object[] objects) |
| | | { |
| | | return !isEmpty(objects); |
| | | } |
| | | |
| | | /** |
| | | * * 夿ä¸ä¸ªMapæ¯å¦ä¸ºç©º |
| | | * |
| | | * @param map è¦å¤æçMap |
| | | * @return trueï¼ä¸ºç©º falseï¼é空 |
| | | */ |
| | | public static boolean isEmpty(Map<?, ?> map) |
| | | { |
| | | return isNull(map) || map.isEmpty(); |
| | | } |
| | | |
| | | /** |
| | | * * 夿ä¸ä¸ªMapæ¯å¦ä¸ºç©º |
| | | * |
| | | * @param map è¦å¤æçMap |
| | | * @return trueï¼é空 falseï¼ç©º |
| | | */ |
| | | public static boolean isNotEmpty(Map<?, ?> map) |
| | | { |
| | | return !isEmpty(map); |
| | | } |
| | | |
| | | /** |
| | | * * 夿ä¸ä¸ªå符串æ¯å¦ä¸ºç©ºä¸² |
| | | * |
| | | * @param str String |
| | | * @return trueï¼ä¸ºç©º falseï¼é空 |
| | | */ |
| | | public static boolean isEmpty(String str) |
| | | { |
| | | return isNull(str) || NULLSTR.equals(str.trim()); |
| | | } |
| | | |
| | | /** |
| | | * * 夿ä¸ä¸ªå符串æ¯å¦ä¸ºé空串 |
| | | * |
| | | * @param str String |
| | | * @return trueï¼é空串 falseï¼ç©ºä¸² |
| | | */ |
| | | public static boolean isNotEmpty(String str) |
| | | { |
| | | return !isEmpty(str); |
| | | } |
| | | |
| | | /** |
| | | * * 夿ä¸ä¸ªå¯¹è±¡æ¯å¦ä¸ºç©º |
| | | * |
| | | * @param object Object |
| | | * @return trueï¼ä¸ºç©º falseï¼é空 |
| | | */ |
| | | public static boolean isNull(Object object) |
| | | { |
| | | return object == null; |
| | | } |
| | | |
| | | /** |
| | | * * 夿ä¸ä¸ªå¯¹è±¡æ¯å¦é空 |
| | | * |
| | | * @param object Object |
| | | * @return trueï¼é空 falseï¼ç©º |
| | | */ |
| | | public static boolean isNotNull(Object object) |
| | | { |
| | | return !isNull(object); |
| | | } |
| | | |
| | | /** |
| | | * * 夿ä¸ä¸ªå¯¹è±¡æ¯å¦æ¯æ°ç»ç±»åï¼Javaåºæ¬åå«çæ°ç»ï¼ |
| | | * |
| | | * @param object 对象 |
| | | * @return trueï¼æ¯æ°ç» falseï¼ä¸æ¯æ°ç» |
| | | */ |
| | | public static boolean isArray(Object object) |
| | | { |
| | | return isNotNull(object) && object.getClass().isArray(); |
| | | } |
| | | |
| | | /** |
| | | * å»ç©ºæ ¼ |
| | | */ |
| | | public static String trim(String str) |
| | | { |
| | | return (str == null ? "" : str.trim()); |
| | | } |
| | | |
| | | /** |
| | | * æªåå符串 |
| | | * |
| | | * @param str å符串 |
| | | * @param start å¼å§ |
| | | * @return ç»æ |
| | | */ |
| | | public static String substring(final String str, int start) |
| | | { |
| | | if (str == null) |
| | | { |
| | | return NULLSTR; |
| | | } |
| | | |
| | | if (start < 0) |
| | | { |
| | | start = str.length() + start; |
| | | } |
| | | |
| | | if (start < 0) |
| | | { |
| | | start = 0; |
| | | } |
| | | if (start > str.length()) |
| | | { |
| | | return NULLSTR; |
| | | } |
| | | |
| | | return str.substring(start); |
| | | } |
| | | |
| | | /** |
| | | * æªåå符串 |
| | | * |
| | | * @param str å符串 |
| | | * @param start å¼å§ |
| | | * @param end ç»æ |
| | | * @return ç»æ |
| | | */ |
| | | public static String substring(final String str, int start, int end) |
| | | { |
| | | if (str == null) |
| | | { |
| | | return NULLSTR; |
| | | } |
| | | |
| | | if (end < 0) |
| | | { |
| | | end = str.length() + end; |
| | | } |
| | | if (start < 0) |
| | | { |
| | | start = str.length() + start; |
| | | } |
| | | |
| | | if (end > str.length()) |
| | | { |
| | | end = str.length(); |
| | | } |
| | | |
| | | if (start > end) |
| | | { |
| | | return NULLSTR; |
| | | } |
| | | |
| | | if (start < 0) |
| | | { |
| | | start = 0; |
| | | } |
| | | if (end < 0) |
| | | { |
| | | end = 0; |
| | | } |
| | | |
| | | return str.substring(start, end); |
| | | } |
| | | |
| | | /** |
| | | * æ ¼å¼åææ¬, {} 表示å ä½ç¬¦<br> |
| | | * æ¤æ¹æ³åªæ¯ç®åå°å ä½ç¬¦ {} æç
§é¡ºåºæ¿æ¢ä¸ºåæ°<br> |
| | | * 妿æ³è¾åº {} ä½¿ç¨ \\è½¬ä¹ { å³å¯ï¼å¦ææ³è¾åº {} ä¹åç \ 使ç¨å转ä¹ç¬¦ \\\\ å³å¯<br> |
| | | * ä¾ï¼<br> |
| | | * é常使ç¨ï¼format("this is {} for {}", "a", "b") -> this is a for b<br> |
| | | * 转ä¹{}ï¼ format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> |
| | | * 转ä¹\ï¼ format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> |
| | | * |
| | | * @param template ææ¬æ¨¡æ¿ï¼è¢«æ¿æ¢çé¨åç¨ {} 表示 |
| | | * @param params åæ°å¼ |
| | | * @return æ ¼å¼ååçææ¬ |
| | | */ |
| | | public static String format(String template, Object... params) |
| | | { |
| | | if (isEmpty(params) || isEmpty(template)) |
| | | { |
| | | return template; |
| | | } |
| | | return StrFormatter.format(template, params); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºhttp(s)://å¼å¤´ |
| | | * |
| | | * @param link 龿¥ |
| | | * @return ç»æ |
| | | */ |
| | | public static boolean ishttp(String link) |
| | | { |
| | | return StringUtils.startsWithAny(link, Constants.HTTP, Constants.HTTPS); |
| | | } |
| | | |
| | | /** |
| | | * å符串转set |
| | | * |
| | | * @param str å符串 |
| | | * @param sep åé符 |
| | | * @return setéå |
| | | */ |
| | | public static final Set<String> str2Set(String str, String sep) |
| | | { |
| | | return new HashSet<String>(str2List(str, sep, true, false)); |
| | | } |
| | | |
| | | /** |
| | | * å符串转list |
| | | * |
| | | * @param str å符串 |
| | | * @param sep åé符 |
| | | * @param filterBlank è¿æ»¤çº¯ç©ºç½ |
| | | * @param trim 廿é¦å°¾ç©ºç½ |
| | | * @return listéå |
| | | */ |
| | | public static final List<String> str2List(String str, String sep, boolean filterBlank, boolean trim) |
| | | { |
| | | List<String> list = new ArrayList<String>(); |
| | | if (StringUtils.isEmpty(str)) |
| | | { |
| | | return list; |
| | | } |
| | | |
| | | // è¿æ»¤ç©ºç½å符串 |
| | | if (filterBlank && StringUtils.isBlank(str)) |
| | | { |
| | | return list; |
| | | } |
| | | String[] split = str.split(sep); |
| | | for (String string : split) |
| | | { |
| | | if (filterBlank && StringUtils.isBlank(string)) |
| | | { |
| | | continue; |
| | | } |
| | | if (trim) |
| | | { |
| | | string = string.trim(); |
| | | } |
| | | list.add(string); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¾æå®å符串æ¯å¦å
嫿å®å符串å表ä¸çä»»æä¸ä¸ªåç¬¦ä¸²åæ¶ä¸²å¿½ç¥å¤§å°å |
| | | * |
| | | * @param cs æå®å符串 |
| | | * @param searchCharSequences éè¦æ£æ¥çå符串æ°ç» |
| | | * @return æ¯å¦å
å«ä»»æä¸ä¸ªå符串 |
| | | */ |
| | | public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) |
| | | { |
| | | if (isEmpty(cs) || isEmpty(searchCharSequences)) |
| | | { |
| | | return false; |
| | | } |
| | | for (CharSequence testStr : searchCharSequences) |
| | | { |
| | | if (containsIgnoreCase(cs, testStr)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 驼峰转ä¸å线å½å |
| | | */ |
| | | public static String toUnderScoreCase(String str) |
| | | { |
| | | if (str == null) |
| | | { |
| | | return null; |
| | | } |
| | | StringBuilder sb = new StringBuilder(); |
| | | // åç½®å符æ¯å¦å¤§å |
| | | boolean preCharIsUpperCase = true; |
| | | // å½åå符æ¯å¦å¤§å |
| | | boolean curreCharIsUpperCase = true; |
| | | // ä¸ä¸å符æ¯å¦å¤§å |
| | | boolean nexteCharIsUpperCase = true; |
| | | for (int i = 0; i < str.length(); i++) |
| | | { |
| | | char c = str.charAt(i); |
| | | if (i > 0) |
| | | { |
| | | preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1)); |
| | | } |
| | | else |
| | | { |
| | | preCharIsUpperCase = false; |
| | | } |
| | | |
| | | curreCharIsUpperCase = Character.isUpperCase(c); |
| | | |
| | | if (i < (str.length() - 1)) |
| | | { |
| | | nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1)); |
| | | } |
| | | |
| | | if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) |
| | | { |
| | | sb.append(SEPARATOR); |
| | | } |
| | | else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) |
| | | { |
| | | sb.append(SEPARATOR); |
| | | } |
| | | sb.append(Character.toLowerCase(c)); |
| | | } |
| | | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦å
å«å符串 |
| | | * |
| | | * @param str éªè¯å符串 |
| | | * @param strs åç¬¦ä¸²ç» |
| | | * @return å
å«è¿åtrue |
| | | */ |
| | | public static boolean inStringIgnoreCase(String str, String... strs) |
| | | { |
| | | if (str != null && strs != null) |
| | | { |
| | | for (String s : strs) |
| | | { |
| | | if (str.equalsIgnoreCase(trim(s))) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * å°ä¸åçº¿å¤§åæ¹å¼å½åçå符串转æ¢ä¸ºé©¼å³°å¼ãå¦æè½¬æ¢åçä¸åçº¿å¤§åæ¹å¼å½åçå符串为空ï¼åè¿å空å符串ã ä¾å¦ï¼HELLO_WORLD->HelloWorld |
| | | * |
| | | * @param name 转æ¢åçä¸åçº¿å¤§åæ¹å¼å½åçå符串 |
| | | * @return 转æ¢åç驼峰å¼å½åçå符串 |
| | | */ |
| | | public static String convertToCamelCase(String name) |
| | | { |
| | | StringBuilder result = new StringBuilder(); |
| | | // å¿«éæ£æ¥ |
| | | if (name == null || name.isEmpty()) |
| | | { |
| | | // 没å¿
è¦è½¬æ¢ |
| | | return ""; |
| | | } |
| | | else if (!name.contains("_")) |
| | | { |
| | | // ä¸å«ä¸å线ï¼ä»
å°é¦åæ¯å¤§å |
| | | return name.substring(0, 1).toUpperCase() + name.substring(1); |
| | | } |
| | | // ç¨ä¸å线å°åå§å符串åå² |
| | | String[] camels = name.split("_"); |
| | | for (String camel : camels) |
| | | { |
| | | // è·³è¿åå§å符串ä¸å¼å¤´ãç»å°¾ç䏿¢çº¿æåéä¸å线 |
| | | if (camel.isEmpty()) |
| | | { |
| | | continue; |
| | | } |
| | | // é¦åæ¯å¤§å |
| | | result.append(camel.substring(0, 1).toUpperCase()); |
| | | result.append(camel.substring(1).toLowerCase()); |
| | | } |
| | | return result.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 驼峰å¼å½åæ³ ä¾å¦ï¼user_name->userName |
| | | */ |
| | | public static String toCamelCase(String s) |
| | | { |
| | | if (s == null) |
| | | { |
| | | return null; |
| | | } |
| | | s = s.toLowerCase(); |
| | | StringBuilder sb = new StringBuilder(s.length()); |
| | | boolean upperCase = false; |
| | | for (int i = 0; i < s.length(); i++) |
| | | { |
| | | char c = s.charAt(i); |
| | | |
| | | if (c == SEPARATOR) |
| | | { |
| | | upperCase = true; |
| | | } |
| | | else if (upperCase) |
| | | { |
| | | sb.append(Character.toUpperCase(c)); |
| | | upperCase = false; |
| | | } |
| | | else |
| | | { |
| | | sb.append(c); |
| | | } |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¾æå®å符串æ¯å¦å¹é
æå®å符串å表ä¸çä»»æä¸ä¸ªå符串 |
| | | * |
| | | * @param str æå®å符串 |
| | | * @param strs éè¦æ£æ¥çå符串æ°ç» |
| | | * @return æ¯å¦å¹é
|
| | | */ |
| | | public static boolean matches(String str, List<String> strs) |
| | | { |
| | | if (isEmpty(str) || isEmpty(strs)) |
| | | { |
| | | return false; |
| | | } |
| | | for (String pattern : strs) |
| | | { |
| | | if (isMatch(pattern, str)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 夿urlæ¯å¦ä¸è§åé
ç½®: |
| | | * ? 表示å个å符; |
| | | * * 表示ä¸å±è·¯å¾å
çä»»æå符串ï¼ä¸å¯è·¨å±çº§; |
| | | * ** 表示任æå±è·¯å¾; |
| | | * |
| | | * @param pattern å¹é
è§å |
| | | * @param url éè¦å¹é
çurl |
| | | * @return |
| | | */ |
| | | public static boolean isMatch(String pattern, String url) |
| | | { |
| | | AntPathMatcher matcher = new AntPathMatcher(); |
| | | return matcher.match(pattern, url); |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public static <T> T cast(Object obj) |
| | | { |
| | | return (T) obj; |
| | | } |
| | | } |
| | | /** |
| | | * æ¥æ¾æå®å符串æ¯å¦å¹é
æå®å符串å表ä¸çä»»æä¸ä¸ªå符串 |
| | | * |
| | | * @param str æå®å符串 |
| | | * @param strs éè¦æ£æ¥çå符串æ°ç» |
| | | * @return æ¯å¦å¹é
|
| | | */ |
| | | public static boolean matches(String str, List<String> strs) { |
| | | if (isEmpty(str) || CollUtil.isEmpty(strs)) { |
| | | return false; |
| | | } |
| | | for (String pattern : strs) { |
| | | if (ReUtil.isMatch(pattern, str)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.common.utils.file; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.exception.file.FileNameLengthLimitExceededException; |
| | | import com.ruoyi.common.exception.file.FileSizeLimitExceededException; |
| | | import com.ruoyi.common.exception.file.InvalidExtensionException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | |
| | | private static final String getPathFileName(String uploadDir, String fileName) throws IOException |
| | | { |
| | | int dirLastIndex = RuoYiConfig.getProfile().length() + 1; |
| | | String currentDir = StrUtil.subSuf(uploadDir, dirLastIndex); |
| | | String currentDir = StringUtils.subSuf(uploadDir, dirLastIndex); |
| | | String pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; |
| | | return pathFileName; |
| | | } |
| | |
| | | public static final String getExtension(MultipartFile file) |
| | | { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | if (Validator.isEmpty(extension)) |
| | | if (StringUtils.isEmpty(extension)) |
| | | { |
| | | extension = MimeTypeUtils.getExtension(file.getContentType()); |
| | | } |
| | |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | |
| | | public static boolean checkAllowDownload(String resource) |
| | | { |
| | | // ç¦æ¢ç®å½ä¸è·³çº§å« |
| | | if (StrUtil.contains(resource, "..")) |
| | | if (StringUtils.contains(resource, "..")) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | package com.ruoyi.common.utils.file;
|
| | |
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.config.RuoYiConfig;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import org.apache.poi.util.IOUtils;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import java.io.ByteArrayInputStream;
|
| | | import java.io.ByteArrayOutputStream;
|
| | | import java.io.FileInputStream;
|
| | | import java.io.InputStream;
|
| | | import java.net.URL;
|
| | | import java.net.URLConnection;
|
| | | import java.util.Arrays;
|
| | |
|
| | | /**
|
| | | * å¾çå¤çå·¥å
·ç±»
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public class ImageUtils
|
| | | {
|
| | | private static final Logger log = LoggerFactory.getLogger(ImageUtils.class);
|
| | |
|
| | | public static byte[] getImage(String imagePath)
|
| | | {
|
| | | InputStream is = getFile(imagePath);
|
| | | try
|
| | | {
|
| | | return IOUtils.toByteArray(is);
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | log.error("å¾çå è½½å¼å¸¸ {}", e);
|
| | | return null;
|
| | | }
|
| | | finally
|
| | | {
|
| | | IOUtils.closeQuietly(is);
|
| | | }
|
| | | }
|
| | |
|
| | | public static InputStream getFile(String imagePath)
|
| | | {
|
| | | try
|
| | | {
|
| | | byte[] result = readFile(imagePath);
|
| | | result = Arrays.copyOf(result, result.length);
|
| | | return new ByteArrayInputStream(result);
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | log.error("è·åå¾çå¼å¸¸ {}", e);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 读åæä»¶ä¸ºåèæ°æ®
|
| | | * |
| | | * @param key å°å
|
| | | * @return åèæ°æ®
|
| | | */
|
| | | public static byte[] readFile(String url)
|
| | | {
|
| | | InputStream in = null;
|
| | | ByteArrayOutputStream baos = null;
|
| | | try
|
| | | {
|
| | | if (url.startsWith("http"))
|
| | | {
|
| | | // ç½ç»å°å
|
| | | URL urlObj = new URL(url);
|
| | | URLConnection urlConnection = urlObj.openConnection();
|
| | | urlConnection.setConnectTimeout(30 * 1000);
|
| | | urlConnection.setReadTimeout(60 * 1000);
|
| | | urlConnection.setDoInput(true);
|
| | | in = urlConnection.getInputStream();
|
| | | }
|
| | | else
|
| | | {
|
| | | // æ¬æºå°å
|
| | | String localPath = RuoYiConfig.getProfile();
|
| | | String downloadPath = localPath + StrUtil.subAfter(url, Constants.RESOURCE_PREFIX,false);
|
| | | in = new FileInputStream(downloadPath);
|
| | | }
|
| | | return IOUtils.toByteArray(in);
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | log.error("è·åæä»¶è·¯å¾å¼å¸¸ {}", e);
|
| | | return null;
|
| | | }
|
| | | finally
|
| | | {
|
| | | IOUtils.closeQuietly(in);
|
| | | IOUtils.closeQuietly(baos);
|
| | | }
|
| | | }
|
| | | }
|
| | | package com.ruoyi.common.utils.file; |
| | | |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.apache.poi.util.IOUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.FileInputStream; |
| | | import java.io.InputStream; |
| | | import java.net.URL; |
| | | import java.net.URLConnection; |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * å¾çå¤çå·¥å
·ç±» |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class ImageUtils |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(ImageUtils.class); |
| | | |
| | | public static byte[] getImage(String imagePath) |
| | | { |
| | | InputStream is = getFile(imagePath); |
| | | try |
| | | { |
| | | return IOUtils.toByteArray(is); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("å¾çå è½½å¼å¸¸ {}", e); |
| | | return null; |
| | | } |
| | | finally |
| | | { |
| | | IOUtils.closeQuietly(is); |
| | | } |
| | | } |
| | | |
| | | public static InputStream getFile(String imagePath) |
| | | { |
| | | try |
| | | { |
| | | byte[] result = readFile(imagePath); |
| | | result = Arrays.copyOf(result, result.length); |
| | | return new ByteArrayInputStream(result); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("è·åå¾çå¼å¸¸ {}", e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 读åæä»¶ä¸ºåèæ°æ® |
| | | * |
| | | * @param key å°å |
| | | * @return åèæ°æ® |
| | | */ |
| | | public static byte[] readFile(String url) |
| | | { |
| | | InputStream in = null; |
| | | ByteArrayOutputStream baos = null; |
| | | try |
| | | { |
| | | if (url.startsWith("http")) |
| | | { |
| | | // ç½ç»å°å |
| | | URL urlObj = new URL(url); |
| | | URLConnection urlConnection = urlObj.openConnection(); |
| | | urlConnection.setConnectTimeout(30 * 1000); |
| | | urlConnection.setReadTimeout(60 * 1000); |
| | | urlConnection.setDoInput(true); |
| | | in = urlConnection.getInputStream(); |
| | | } |
| | | else |
| | | { |
| | | // æ¬æºå°å |
| | | String localPath = RuoYiConfig.getProfile(); |
| | | String downloadPath = localPath + StringUtils.subAfter(url, Constants.RESOURCE_PREFIX,false); |
| | | in = new FileInputStream(downloadPath); |
| | | } |
| | | return IOUtils.toByteArray(in); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("è·åæä»¶è·¯å¾å¼å¸¸ {}", e); |
| | | return null; |
| | | } |
| | | finally |
| | | { |
| | | IOUtils.closeQuietly(in); |
| | | IOUtils.closeQuietly(baos); |
| | | } |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.common.utils.ip; |
| | | |
| | | import cn.hutool.core.net.NetUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HtmlUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.Map; |
| | |
| | | .body("ip=" + ip + "&json=true", Constants.GBK) |
| | | .execute() |
| | | .body(); |
| | | if (StrUtil.isEmpty(rspStr)) { |
| | | if (StringUtils.isEmpty(rspStr)) { |
| | | log.error("è·åå°çä½ç½®å¼å¸¸ {}", ip); |
| | | return UNKNOWN; |
| | | } |
| | |
| | | package com.ruoyi.common.utils.poi; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.annotation.Excel; |
| | | import com.ruoyi.common.annotation.Excel.ColumnType; |
| | | import com.ruoyi.common.annotation.Excel.Type; |
| | |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DictUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.file.FileTypeUtils; |
| | | import com.ruoyi.common.utils.file.ImageUtils; |
| | | import com.ruoyi.common.utils.reflect.ReflectUtils; |
| | |
| | | */ |
| | | public List<T> importExcel(InputStream is) throws Exception |
| | | { |
| | | return importExcel(StrUtil.EMPTY, is); |
| | | return importExcel(StringUtils.EMPTY, is); |
| | | } |
| | | |
| | | /** |
| | |
| | | this.wb = WorkbookFactory.create(is); |
| | | List<T> list = new ArrayList<T>(); |
| | | Sheet sheet = null; |
| | | if (Validator.isNotEmpty(sheetName)) |
| | | if (StringUtils.isNotEmpty(sheetName)) |
| | | { |
| | | // 妿æå®sheetå,ååæå®sheetä¸çå
容. |
| | | sheet = wb.getSheet(sheetName); |
| | |
| | | for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) |
| | | { |
| | | Cell cell = heard.getCell(i); |
| | | if (Validator.isNotNull(cell)) |
| | | if (StringUtils.isNotNull(cell)) |
| | | { |
| | | String value = this.getCellValue(heard, i).toString(); |
| | | cellMap.put(value, i); |
| | |
| | | if (String.class == fieldType) |
| | | { |
| | | String s = Convert.toStr(val); |
| | | if (StrUtil.endWith(s, ".0")) |
| | | if (StringUtils.endWith(s, ".0")) |
| | | { |
| | | val = StrUtil.subBefore(s, ".0",false); |
| | | val = StringUtils.subBefore(s, ".0",false); |
| | | } |
| | | else |
| | | { |
| | | String dateFormat = field.getAnnotation(Excel.class).dateFormat(); |
| | | if (Validator.isNotEmpty(dateFormat)) |
| | | if (StringUtils.isNotEmpty(dateFormat)) |
| | | { |
| | | val = DateUtils.parseDateToStr(dateFormat, (Date) val); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && Validator.isNumber(Convert.toStr(val))) |
| | | else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) |
| | | { |
| | | val = Convert.toInt(val); |
| | | } |
| | |
| | | { |
| | | val = Convert.toBool(val, false); |
| | | } |
| | | if (Validator.isNotNull(fieldType)) |
| | | if (StringUtils.isNotNull(fieldType)) |
| | | { |
| | | Excel attr = field.getAnnotation(Excel.class); |
| | | String propertyName = field.getName(); |
| | | if (Validator.isNotEmpty(attr.targetAttr())) |
| | | if (StringUtils.isNotEmpty(attr.targetAttr())) |
| | | { |
| | | propertyName = field.getName() + "." + attr.targetAttr(); |
| | | } |
| | | else if (Validator.isNotEmpty(attr.readConverterExp())) |
| | | else if (StringUtils.isNotEmpty(attr.readConverterExp())) |
| | | { |
| | | val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator()); |
| | | } |
| | | else if (Validator.isNotEmpty(attr.dictType())) |
| | | else if (StringUtils.isNotEmpty(attr.dictType())) |
| | | { |
| | | val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator()); |
| | | } |
| | |
| | | { |
| | | if (ColumnType.STRING == attr.cellType()) |
| | | { |
| | | cell.setCellValue(Validator.isNull(value) ? attr.defaultValue() : value + attr.suffix()); |
| | | cell.setCellValue(StringUtils.isNull(value) ? attr.defaultValue() : value + attr.suffix()); |
| | | } |
| | | else if (ColumnType.NUMERIC == attr.cellType()) |
| | | { |
| | | if (Validator.isNotNull(value)) |
| | | if (StringUtils.isNotNull(value)) |
| | | { |
| | | cell.setCellValue(StrUtil.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)); |
| | | cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)); |
| | | } |
| | | } |
| | | else if (ColumnType.IMAGE == attr.cellType()) |
| | |
| | | ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), |
| | | cell.getRow().getRowNum() + 1); |
| | | String imagePath = Convert.toStr(value); |
| | | if (Validator.isNotEmpty(imagePath)) |
| | | if (StringUtils.isNotEmpty(imagePath)) |
| | | { |
| | | byte[] data = ImageUtils.getImage(imagePath); |
| | | getDrawingPatriarch(cell.getSheet()).createPicture(anchor, |
| | |
| | | sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256)); |
| | | } |
| | | // å¦æè®¾ç½®äºæç¤ºä¿¡æ¯åé¼ æ æ¾ä¸å»æç¤º. |
| | | if (Validator.isNotEmpty(attr.prompt())) |
| | | if (StringUtils.isNotEmpty(attr.prompt())) |
| | | { |
| | | // è¿éé»è®¤è®¾äº2-101åæç¤º. |
| | | setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column); |
| | |
| | | String readConverterExp = attr.readConverterExp(); |
| | | String separator = attr.separator(); |
| | | String dictType = attr.dictType(); |
| | | if (Validator.isNotEmpty(dateFormat) && Validator.isNotNull(value)) |
| | | if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) |
| | | { |
| | | cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value)); |
| | | } |
| | | else if (Validator.isNotEmpty(readConverterExp) && Validator.isNotNull(value)) |
| | | else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) |
| | | { |
| | | cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator)); |
| | | } |
| | | else if (Validator.isNotEmpty(dictType) && Validator.isNotNull(value)) |
| | | else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value)) |
| | | { |
| | | cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator)); |
| | | } |
| | |
| | | for (String item : convertSource) |
| | | { |
| | | String[] itemArray = item.split("="); |
| | | if (StrUtil.containsAny(propertyValue, separator)) |
| | | if (StringUtils.containsAny(propertyValue, separator)) |
| | | { |
| | | for (String value : propertyValue.split(separator)) |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | return StrUtil.strip(propertyString.toString(), null,separator); |
| | | return StringUtils.strip(propertyString.toString(), null,separator); |
| | | } |
| | | |
| | | /** |
| | |
| | | for (String item : convertSource) |
| | | { |
| | | String[] itemArray = item.split("="); |
| | | if (StrUtil.containsAny(propertyValue, separator)) |
| | | if (StringUtils.containsAny(propertyValue, separator)) |
| | | { |
| | | for (String value : propertyValue.split(separator)) |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | return StrUtil.strip(propertyString.toString(), null,separator); |
| | | return StringUtils.strip(propertyString.toString(), null,separator); |
| | | } |
| | | |
| | | /** |
| | |
| | | private Object getTargetValue(T vo, Field field, Excel excel) throws Exception |
| | | { |
| | | Object o = field.get(vo); |
| | | if (Validator.isNotEmpty(excel.targetAttr())) |
| | | if (StringUtils.isNotEmpty(excel.targetAttr())) |
| | | { |
| | | String target = excel.targetAttr(); |
| | | if (target.contains(".")) |
| | |
| | | */ |
| | | private Object getValue(Object o, String name) throws Exception |
| | | { |
| | | if (Validator.isNotNull(o) && Validator.isNotEmpty(name)) |
| | | if (StringUtils.isNotNull(o) && StringUtils.isNotEmpty(name)) |
| | | { |
| | | Class<?> clazz = o.getClass(); |
| | | Field field = clazz.getDeclaredField(name); |
| | |
| | | try |
| | | { |
| | | Cell cell = row.getCell(column); |
| | | if (Validator.isNotNull(cell)) |
| | | if (StringUtils.isNotNull(cell)) |
| | | { |
| | | if (cell.getCellType() == CellType.NUMERIC || cell.getCellType() == CellType.FORMULA) |
| | | { |
| | |
| | | package com.ruoyi.common.utils.reflect; |
| | | |
| | | import cn.hutool.core.util.ReflectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.util.List; |
| | |
| | | @SuppressWarnings("unchecked") |
| | | public static <E> E invokeGetter(Object obj, String propertyName) { |
| | | Object object = obj; |
| | | for (String name : StrUtil.split(propertyName, ".")) { |
| | | String getterMethodName = GETTER_PREFIX + StrUtil.upperFirst(name); |
| | | for (String name : StringUtils.split(propertyName, ".")) { |
| | | String getterMethodName = GETTER_PREFIX + StringUtils.upperFirst(name); |
| | | object = invoke(object, getterMethodName); |
| | | } |
| | | return (E) object; |
| | |
| | | */ |
| | | public static <E> void invokeSetter(Object obj, String propertyName, E value) { |
| | | Object object = obj; |
| | | List<String> names = StrUtil.split(propertyName, "."); |
| | | List<String> names = StringUtils.split(propertyName, "."); |
| | | for (int i = 0; i < names.size(); i++) { |
| | | if (i < names.size() - 1) { |
| | | String getterMethodName = GETTER_PREFIX + StrUtil.upperFirst(names.get(i)); |
| | | String getterMethodName = GETTER_PREFIX + StringUtils.upperFirst(names.get(i)); |
| | | object = invoke(object, getterMethodName); |
| | | } else { |
| | | String setterMethodName = SETTER_PREFIX + StrUtil.upperFirst(names.get(i)); |
| | | String setterMethodName = SETTER_PREFIX + StringUtils.upperFirst(names.get(i)); |
| | | Method method = getMethodByName(object.getClass(), setterMethodName); |
| | | invoke(object, method, value); |
| | | } |
| | |
| | | package com.ruoyi.common.utils.sql; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.exception.BaseException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * sqlæä½å·¥å
·ç±» |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class SqlUtil |
| | |
| | | */ |
| | | public static String escapeOrderBySql(String value) |
| | | { |
| | | if (Validator.isNotEmpty(value) && !isValidOrderBySql(value)) |
| | | if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value)) |
| | | { |
| | | throw new BaseException("åæ°ä¸ç¬¦åè§èï¼ä¸è½è¿è¡æ¥è¯¢"); |
| | | } |
| | |
| | | package com.ruoyi.demo.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | Map<String, Object> params = bo.getParams(); |
| | | Object dataScope = params.get("dataScope"); |
| | | LambdaQueryWrapper<TestDemo> lqw = Wrappers.lambdaQuery(); |
| | | lqw.like(StrUtil.isNotBlank(bo.getTestKey()), TestDemo::getTestKey, bo.getTestKey()); |
| | | lqw.eq(StrUtil.isNotBlank(bo.getValue()), TestDemo::getValue, bo.getValue()); |
| | | lqw.like(StringUtils.isNotBlank(bo.getTestKey()), TestDemo::getTestKey, bo.getTestKey()); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getValue()), TestDemo::getValue, bo.getValue()); |
| | | lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null, |
| | | TestDemo::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime")); |
| | | lqw.apply(dataScope != null && StrUtil.isNotBlank(dataScope.toString()), |
| | | lqw.apply(dataScope != null && StringUtils.isNotBlank(dataScope.toString()), |
| | | dataScope != null ? dataScope.toString() : null); |
| | | return lqw; |
| | | } |
| | |
| | | package com.ruoyi.demo.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | |
| | | Map<String, Object> params = bo.getParams(); |
| | | Object dataScope = params.get("dataScope"); |
| | | LambdaQueryWrapper<TestTree> lqw = Wrappers.lambdaQuery(); |
| | | lqw.like(StrUtil.isNotBlank(bo.getTreeName()), TestTree::getTreeName, bo.getTreeName()); |
| | | lqw.like(StringUtils.isNotBlank(bo.getTreeName()), TestTree::getTreeName, bo.getTreeName()); |
| | | lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null, |
| | | TestTree::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime")); |
| | | lqw.apply(dataScope != null && StrUtil.isNotBlank(dataScope.toString()), |
| | | lqw.apply(dataScope != null && StringUtils.isNotBlank(dataScope.toString()), |
| | | dataScope != null ? dataScope.toString() : null); |
| | | return lqw; |
| | | } |
| | |
| | | package com.ruoyi.framework.aspectj; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | |
| | | StringBuilder sqlString = new StringBuilder(); |
| | | |
| | | // å° "." æååº,ä¸åå«å为å表æ¥è¯¢,åå«å为å¤è¡¨æ¥è¯¢ |
| | | deptAlias = StrUtil.isNotBlank(deptAlias) ? deptAlias + "." : ""; |
| | | userAlias = StrUtil.isNotBlank(userAlias) ? userAlias + "." : ""; |
| | | deptAlias = StringUtils.isNotBlank(deptAlias) ? deptAlias + "." : ""; |
| | | userAlias = StringUtils.isNotBlank(userAlias) ? userAlias + "." : ""; |
| | | |
| | | for (SysRole role : user.getRoles()) { |
| | | String dataScope = role.getDataScope(); |
| | |
| | | sqlString = new StringBuilder(); |
| | | break; |
| | | } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) { |
| | | sqlString.append(StrUtil.format( |
| | | sqlString.append(StringUtils.format( |
| | | " OR {}dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", |
| | | deptAlias, role.getRoleId())); |
| | | } else if (DATA_SCOPE_DEPT.equals(dataScope)) { |
| | | sqlString.append(StrUtil.format(" OR {}dept_id = {} ", |
| | | sqlString.append(StringUtils.format(" OR {}dept_id = {} ", |
| | | deptAlias, user.getDeptId())); |
| | | } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) { |
| | | sqlString.append(StrUtil.format( |
| | | sqlString.append(StringUtils.format( |
| | | " OR {}dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", |
| | | deptAlias, user.getDeptId(), user.getDeptId())); |
| | | } else if (DATA_SCOPE_SELF.equals(dataScope)) { |
| | | if (isUser) { |
| | | sqlString.append(StrUtil.format(" OR {}user_id = {} ", |
| | | sqlString.append(StringUtils.format(" OR {}user_id = {} ", |
| | | userAlias, user.getUserId())); |
| | | } else { |
| | | // æ°æ®æé为ä»
æ¬äººä¸æ²¡æuserAliaså«å䏿¥è¯¢ä»»ä½æ°æ® |
| | |
| | | } |
| | | } |
| | | |
| | | if (StrUtil.isNotBlank(sqlString.toString())) { |
| | | if (StringUtils.isNotBlank(sqlString.toString())) { |
| | | putDataScope(joinPoint, sqlString.substring(4)); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.framework.aspectj; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.enums.BusinessStatus; |
| | |
| | | if (e != null) |
| | | { |
| | | operLog.setStatus(BusinessStatus.FAIL.ordinal()); |
| | | operLog.setErrorMsg(StrUtil.sub(e.getMessage(), 0, 2000)); |
| | | operLog.setErrorMsg(StringUtils.sub(e.getMessage(), 0, 2000)); |
| | | } |
| | | // è®¾ç½®æ¹æ³åç§° |
| | | String className = joinPoint.getTarget().getClass().getName(); |
| | |
| | | if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) |
| | | { |
| | | String params = argsArrayToString(joinPoint.getArgs()); |
| | | operLog.setOperParam(StrUtil.sub(params, 0, 2000)); |
| | | operLog.setOperParam(StringUtils.sub(params, 0, 2000)); |
| | | } |
| | | else |
| | | { |
| | | Map<?, ?> paramsMap = (Map<?, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); |
| | | operLog.setOperParam(StrUtil.sub(paramsMap.toString(), 0, 2000)); |
| | | operLog.setOperParam(StringUtils.sub(paramsMap.toString(), 0, 2000)); |
| | | } |
| | | } |
| | | |
| | |
| | | import cn.hutool.core.math.Calculator; |
| | | import cn.hutool.core.util.CharUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | | * æ 符å·è®¡ç®çæå¨ |
| | |
| | | int max = RandomUtil.randomInt(min, limit); |
| | | String number1 = Integer.toString(max); |
| | | String number2 = Integer.toString(min); |
| | | number1 = StrUtil.padAfter(number1, this.numberLength, CharUtil.SPACE); |
| | | number2 = StrUtil.padAfter(number2, this.numberLength, CharUtil.SPACE); |
| | | number1 = StringUtils.padAfter(number1, this.numberLength, CharUtil.SPACE); |
| | | number2 = StringUtils.padAfter(number2, this.numberLength, CharUtil.SPACE); |
| | | |
| | | return number1 + RandomUtil.randomChar(operators) + number2 + '='; |
| | | } |
| | |
| | | * @return æå¤§å¼ |
| | | */ |
| | | private int getLimit() { |
| | | return Integer.parseInt("1" + StrUtil.repeat('0', this.numberLength)); |
| | | return Integer.parseInt("1" + StringUtils.repeat('0', this.numberLength)); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.framework.config; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.filter.RepeatableFilter; |
| | | import com.ruoyi.common.filter.XssFilter; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.config.properties.XssProperties; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | |
| | | FilterRegistrationBean registration = new FilterRegistrationBean(); |
| | | registration.setDispatcherTypes(DispatcherType.REQUEST); |
| | | registration.setFilter(new XssFilter()); |
| | | registration.addUrlPatterns(StrUtil.splitToArray(xssProperties.getUrlPatterns(), ",")); |
| | | registration.addUrlPatterns(StringUtils.splitToArray(xssProperties.getUrlPatterns(), ",")); |
| | | registration.setName("xssFilter"); |
| | | registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE); |
| | | Map<String, String> initParameters = new HashMap<String, String>(); |
| | | initParameters.put("excludes", excludes); |
| | | initParameters.put("excludes", xssProperties.getExcludes()); |
| | | registration.setInitParameters(initParameters); |
| | | return registration; |
| | | } |
| | |
| | | package com.ruoyi.framework.config; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.config.properties.RedissonProperties; |
| | | import org.redisson.Redisson; |
| | | import org.redisson.api.RedissonClient; |
| | |
| | | .setAddress(prefix + redisProperties.getHost() + ":" + redisProperties.getPort()) |
| | | .setConnectTimeout(((Long) redisProperties.getTimeout().toMillis()).intValue()) |
| | | .setDatabase(redisProperties.getDatabase()) |
| | | .setPassword(StrUtil.isNotBlank(redisProperties.getPassword()) ? redisProperties.getPassword() : null) |
| | | .setPassword(StringUtils.isNotBlank(redisProperties.getPassword()) ? redisProperties.getPassword() : null) |
| | | .setTimeout(singleServerConfig.getTimeout()) |
| | | .setRetryAttempts(singleServerConfig.getRetryAttempts()) |
| | | .setRetryInterval(singleServerConfig.getRetryInterval()) |
| | |
| | | package com.ruoyi.framework.security.handle; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import cn.hutool.http.HttpStatus; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | |
| | | throws IOException |
| | | { |
| | | int code = HttpStatus.HTTP_UNAUTHORIZED; |
| | | String msg = StrUtil.format("请æ±è®¿é®ï¼{}ï¼è®¤è¯å¤±è´¥ï¼æ æ³è®¿é®ç³»ç»èµæº", request.getRequestURI()); |
| | | String msg = StringUtils.format("请æ±è®¿é®ï¼{}ï¼è®¤è¯å¤±è´¥ï¼æ æ³è®¿é®ç³»ç»èµæº", request.getRequestURI()); |
| | | ServletUtils.renderString(response, JsonUtils.toJsonString(AjaxResult.error(code, msg))); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.framework.web.service; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import cn.hutool.http.useragent.UserAgent; |
| | | import cn.hutool.http.useragent.UserAgentUtil; |
| | | import com.ruoyi.common.constant.Constants; |
| | |
| | | logininfor.setOs(os); |
| | | logininfor.setMsg(message); |
| | | // æ¥å¿ç¶æ |
| | | if (Constants.LOGIN_SUCCESS.equals(status) || Constants.LOGOUT.equals(status)) { |
| | | if (StringUtils.equalsAny(status, Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER)) { |
| | | logininfor.setStatus(Constants.SUCCESS); |
| | | } else if (Constants.LOGIN_FAIL.equals(status)) { |
| | | logininfor.setStatus(Constants.FAIL); |
| | |
| | | package com.ruoyi.framework.web.service; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | |
| | | |
| | | /** |
| | | * RuoYié¦å èªå®ä¹æéå®ç°ï¼ssåèªSpringSecurityé¦åæ¯ |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Service("ss") |
| | |
| | | |
| | | /** |
| | | * éªè¯ç¨æ·æ¯å¦å
·å¤ææé |
| | | * |
| | | * |
| | | * @param permission æéå符串 |
| | | * @return ç¨æ·æ¯å¦å
·å¤ææé |
| | | */ |
| | |
| | | |
| | | /** |
| | | * å¤æç¨æ·æ¯å¦æ¥ææä¸ªè§è² |
| | | * |
| | | * |
| | | * @param role è§è²å符串 |
| | | * @return ç¨æ·æ¯å¦å
·å¤æè§è² |
| | | */ |
| | |
| | | for (SysRole sysRole : loginUser.getUser().getRoles()) |
| | | { |
| | | String roleKey = sysRole.getRoleKey(); |
| | | if (SUPER_ADMIN.equals(roleKey) || roleKey.equals(StrUtil.trim(role))) |
| | | if (SUPER_ADMIN.equals(roleKey) || roleKey.equals(StringUtils.trim(role))) |
| | | { |
| | | return true; |
| | | } |
| | |
| | | |
| | | /** |
| | | * 夿æ¯å¦å
嫿é |
| | | * |
| | | * |
| | | * @param permissions æéå表 |
| | | * @param permission æéå符串 |
| | | * @return ç¨æ·æ¯å¦å
·å¤ææé |
| | | */ |
| | | private boolean hasPermissions(Set<String> permissions, String permission) |
| | | { |
| | | return permissions.contains(ALL_PERMISSION) || permissions.contains(StrUtil.trim(permission)); |
| | | return permissions.contains(ALL_PERMISSION) || permissions.contains(StringUtils.trim(permission)); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.framework.web.service;
|
| | |
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.springframework.util.StringUtils;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | | import com.ruoyi.common.core.domain.model.RegisterBody;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.exception.user.CaptchaException;
|
| | | import com.ruoyi.common.exception.user.CaptchaExpireException;
|
| | | import com.ruoyi.common.utils.MessageUtils;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.framework.manager.AsyncManager;
|
| | | import com.ruoyi.framework.manager.factory.AsyncFactory;
|
| | | import com.ruoyi.system.service.ISysConfigService;
|
| | | import com.ruoyi.system.service.ISysUserService;
|
| | |
|
| | | /**
|
| | | * æ³¨åæ ¡éªæ¹æ³
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @Component
|
| | | public class SysRegisterService
|
| | | {
|
| | | @Autowired
|
| | | private ISysUserService userService;
|
| | |
|
| | | @Autowired
|
| | | private ISysConfigService configService;
|
| | |
|
| | | @Autowired
|
| | | private RedisCache redisCache;
|
| | |
|
| | | /**
|
| | | * 注å
|
| | | */
|
| | | public String register(RegisterBody registerBody)
|
| | | {
|
| | | String msg = "", username = registerBody.getUsername(), password = registerBody.getPassword();
|
| | |
|
| | | boolean captchaOnOff = configService.selectCaptchaOnOff();
|
| | | // éªè¯ç å¼å
³
|
| | | if (captchaOnOff)
|
| | | {
|
| | | validateCaptcha(username, registerBody.getCode(), registerBody.getUuid());
|
| | | }
|
| | |
|
| | | if (StringUtils.isEmpty(username))
|
| | | {
|
| | | msg = "ç¨æ·åä¸è½ä¸ºç©º";
|
| | | }
|
| | | else if (StringUtils.isEmpty(password))
|
| | | {
|
| | | msg = "ç¨æ·å¯ç ä¸è½ä¸ºç©º";
|
| | | }
|
| | | else if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
| | | || username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
| | | {
|
| | | msg = "è´¦æ·é¿åº¦å¿
é¡»å¨2å°20个å符ä¹é´";
|
| | | }
|
| | | else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
| | | || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
| | | {
|
| | | msg = "å¯ç é¿åº¦å¿
é¡»å¨5å°20个å符ä¹é´";
|
| | | }
|
| | | else if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username)))
|
| | | {
|
| | | msg = "ä¿åç¨æ·'" + username + "'å¤±è´¥ï¼æ³¨åè´¦å·å·²åå¨";
|
| | | }
|
| | | else
|
| | | {
|
| | | SysUser sysUser = new SysUser();
|
| | | sysUser.setUserName(username);
|
| | | sysUser.setNickName(username);
|
| | | sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword()));
|
| | | boolean regFlag = userService.registerUser(sysUser);
|
| | | if (!regFlag)
|
| | | {
|
| | | msg = "注å失败,请è系系ç»ç®¡ç人å";
|
| | | }
|
| | | else
|
| | | {
|
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.REGISTER,
|
| | | MessageUtils.message("user.register.success")));
|
| | | }
|
| | | }
|
| | | return msg;
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ ¡éªéªè¯ç
|
| | | * |
| | | * @param username ç¨æ·å
|
| | | * @param code éªè¯ç
|
| | | * @param uuid å¯ä¸æ è¯
|
| | | * @return ç»æ
|
| | | */
|
| | | public void validateCaptcha(String username, String code, String uuid)
|
| | | {
|
| | | String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
|
| | | String captcha = redisCache.getCacheObject(verifyKey);
|
| | | redisCache.deleteObject(verifyKey);
|
| | | if (captcha == null)
|
| | | {
|
| | | throw new CaptchaExpireException();
|
| | | }
|
| | | if (!code.equalsIgnoreCase(captcha))
|
| | | {
|
| | | throw new CaptchaException();
|
| | | }
|
| | | }
|
| | | }
|
| | | package com.ruoyi.framework.web.service; |
| | | |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.RegisterBody; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.exception.user.CaptchaException; |
| | | import com.ruoyi.common.exception.user.CaptchaExpireException; |
| | | import com.ruoyi.common.utils.MessageUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * æ³¨åæ ¡éªæ¹æ³ |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Component |
| | | public class SysRegisterService |
| | | { |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @Autowired |
| | | private AsyncService asyncService; |
| | | |
| | | /** |
| | | * 注å |
| | | */ |
| | | public String register(RegisterBody registerBody) |
| | | { |
| | | String msg = "", username = registerBody.getUsername(), password = registerBody.getPassword(); |
| | | |
| | | boolean captchaOnOff = configService.selectCaptchaOnOff(); |
| | | // éªè¯ç å¼å
³ |
| | | if (captchaOnOff) |
| | | { |
| | | validateCaptcha(username, registerBody.getCode(), registerBody.getUuid()); |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(username)) |
| | | { |
| | | msg = "ç¨æ·åä¸è½ä¸ºç©º"; |
| | | } |
| | | else if (StringUtils.isEmpty(password)) |
| | | { |
| | | msg = "ç¨æ·å¯ç ä¸è½ä¸ºç©º"; |
| | | } |
| | | else if (username.length() < UserConstants.USERNAME_MIN_LENGTH |
| | | || username.length() > UserConstants.USERNAME_MAX_LENGTH) |
| | | { |
| | | msg = "è´¦æ·é¿åº¦å¿
é¡»å¨2å°20个å符ä¹é´"; |
| | | } |
| | | else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH |
| | | || password.length() > UserConstants.PASSWORD_MAX_LENGTH) |
| | | { |
| | | msg = "å¯ç é¿åº¦å¿
é¡»å¨5å°20个å符ä¹é´"; |
| | | } |
| | | else if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username))) |
| | | { |
| | | msg = "ä¿åç¨æ·'" + username + "'å¤±è´¥ï¼æ³¨åè´¦å·å·²åå¨"; |
| | | } |
| | | else |
| | | { |
| | | SysUser sysUser = new SysUser(); |
| | | sysUser.setUserName(username); |
| | | sysUser.setNickName(username); |
| | | sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword())); |
| | | boolean regFlag = userService.registerUser(sysUser); |
| | | if (!regFlag) |
| | | { |
| | | msg = "注å失败,请è系系ç»ç®¡ç人å"; |
| | | } |
| | | else |
| | | { |
| | | asyncService.recordLogininfor(username, Constants.REGISTER, |
| | | MessageUtils.message("user.register.success"), ServletUtils.getRequest()); |
| | | } |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªéªè¯ç |
| | | * |
| | | * @param username ç¨æ·å |
| | | * @param code éªè¯ç |
| | | * @param uuid å¯ä¸æ è¯ |
| | | * @return ç»æ |
| | | */ |
| | | public void validateCaptcha(String username, String code, String uuid) |
| | | { |
| | | String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; |
| | | String captcha = redisCache.getCacheObject(verifyKey); |
| | | redisCache.deleteObject(verifyKey); |
| | | if (captcha == null) |
| | | { |
| | | throw new CaptchaExpireException(); |
| | | } |
| | | if (!code.equalsIgnoreCase(captcha)) |
| | | { |
| | | throw new CaptchaException(); |
| | | } |
| | | } |
| | | } |
| | |
| | | String userKey = getTokenKey(uuid); |
| | | LoginUser user = redisCache.getCacheObject(userKey); |
| | | return user; |
| | | catch (Exception e) { |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | return null; |
| | |
| | | package com.ruoyi.generator.domain; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.annotation.*; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | |
| | | } |
| | | |
| | | public static boolean isSub(String tplCategory) { |
| | | return tplCategory != null && StrUtil.equals(GenConstants.TPL_SUB, tplCategory); |
| | | return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory); |
| | | } |
| | | |
| | | public boolean isTree() { |
| | |
| | | } |
| | | |
| | | public static boolean isTree(String tplCategory) { |
| | | return tplCategory != null && StrUtil.equals(GenConstants.TPL_TREE, tplCategory); |
| | | return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory); |
| | | } |
| | | |
| | | public boolean isCrud() { |
| | |
| | | } |
| | | |
| | | public static boolean isCrud(String tplCategory) { |
| | | return tplCategory != null && StrUtil.equals(GenConstants.TPL_CRUD, tplCategory); |
| | | return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory); |
| | | } |
| | | |
| | | public boolean isSuperColumn(String javaField) { |
| | |
| | | |
| | | public static boolean isSuperColumn(String tplCategory, String javaField) { |
| | | if (isTree(tplCategory)) { |
| | | return StrUtil.equalsAnyIgnoreCase(javaField, |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, |
| | | ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY)); |
| | | } |
| | | return StrUtil.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); |
| | | } |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.generator.domain; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.annotation.*; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.*; |
| | |
| | | private Map<String, Object> params = new HashMap<>(); |
| | | |
| | | public String getCapJavaField() { |
| | | return StrUtil.upperFirst(javaField); |
| | | return StringUtils.upperFirst(javaField); |
| | | } |
| | | |
| | | public boolean isPk() { |
| | |
| | | } |
| | | |
| | | public boolean isPk(String isPk) { |
| | | return isPk != null && StrUtil.equals("1", isPk); |
| | | return isPk != null && StringUtils.equals("1", isPk); |
| | | } |
| | | |
| | | public boolean isIncrement() { |
| | |
| | | } |
| | | |
| | | public boolean isIncrement(String isIncrement) { |
| | | return isIncrement != null && StrUtil.equals("1", isIncrement); |
| | | return isIncrement != null && StringUtils.equals("1", isIncrement); |
| | | } |
| | | |
| | | public boolean isRequired() { |
| | |
| | | } |
| | | |
| | | public boolean isRequired(String isRequired) { |
| | | return isRequired != null && StrUtil.equals("1", isRequired); |
| | | return isRequired != null && StringUtils.equals("1", isRequired); |
| | | } |
| | | |
| | | public boolean isInsert() { |
| | |
| | | } |
| | | |
| | | public boolean isInsert(String isInsert) { |
| | | return isInsert != null && StrUtil.equals("1", isInsert); |
| | | return isInsert != null && StringUtils.equals("1", isInsert); |
| | | } |
| | | |
| | | public boolean isEdit() { |
| | |
| | | } |
| | | |
| | | public boolean isEdit(String isEdit) { |
| | | return isEdit != null && StrUtil.equals("1", isEdit); |
| | | return isEdit != null && StringUtils.equals("1", isEdit); |
| | | } |
| | | |
| | | public boolean isList() { |
| | |
| | | } |
| | | |
| | | public boolean isList(String isList) { |
| | | return isList != null && StrUtil.equals("1", isList); |
| | | return isList != null && StringUtils.equals("1", isList); |
| | | } |
| | | |
| | | public boolean isQuery() { |
| | |
| | | } |
| | | |
| | | public boolean isQuery(String isQuery) { |
| | | return isQuery != null && StrUtil.equals("1", isQuery); |
| | | return isQuery != null && StringUtils.equals("1", isQuery); |
| | | } |
| | | |
| | | public boolean isSuperColumn() { |
| | |
| | | } |
| | | |
| | | public static boolean isSuperColumn(String javaField) { |
| | | return StrUtil.equalsAnyIgnoreCase(javaField, |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, |
| | | // BaseEntity |
| | | "createBy", "createTime", "updateBy", "updateTime", "remark", |
| | | // TreeEntity |
| | |
| | | |
| | | public static boolean isUsableColumn(String javaField) { |
| | | // isSuperColumn()ä¸çååç¨äºé¿å
çæå¤ä½Domain屿§ï¼è¥æäºå±æ§å¨çæé¡µé¢æ¶éè¦ç¨å°ä¸è½å¿½ç¥ï¼åæ¾å¨æ¤å¤ç½åå |
| | | return StrUtil.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); |
| | | return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); |
| | | } |
| | | |
| | | public String readConverterExp() { |
| | | String remarks = StrUtil.subBetween(this.columnComment, "ï¼", "ï¼"); |
| | | String remarks = StringUtils.subBetween(this.columnComment, "ï¼", "ï¼"); |
| | | StringBuffer sb = new StringBuffer(); |
| | | if (StrUtil.isNotEmpty(remarks)) { |
| | | if (StringUtils.isNotEmpty(remarks)) { |
| | | for (String value : remarks.split(" ")) { |
| | | if (StrUtil.isNotEmpty(value)) { |
| | | if (StringUtils.isNotEmpty(value)) { |
| | | Object startStr = value.subSequence(0, 1); |
| | | String endStr = value.substring(1); |
| | | sb.append("").append(startStr).append("=").append(endStr).append(","); |
| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.ruoyi.common.constant.Constants; |
| | |
| | | for (GenTableColumn cenTableColumn : genTable.getColumns()) { |
| | | genTableColumnMapper.update(cenTableColumn, |
| | | new LambdaUpdateWrapper<GenTableColumn>() |
| | | .set(StrUtil.isBlank(cenTableColumn.getColumnComment()), GenTableColumn::getColumnComment, null) |
| | | .set(StrUtil.isBlank(cenTableColumn.getIsPk()), GenTableColumn::getIsPk, null) |
| | | .set(StrUtil.isBlank(cenTableColumn.getIsIncrement()), GenTableColumn::getIsIncrement, null) |
| | | .set(StrUtil.isBlank(cenTableColumn.getIsInsert()), GenTableColumn::getIsInsert, null) |
| | | .set(StrUtil.isBlank(cenTableColumn.getIsEdit()), GenTableColumn::getIsEdit, null) |
| | | .set(StrUtil.isBlank(cenTableColumn.getIsList()), GenTableColumn::getIsList, null) |
| | | .set(StrUtil.isBlank(cenTableColumn.getIsQuery()), GenTableColumn::getIsQuery, null) |
| | | .set(StrUtil.isBlank(cenTableColumn.getIsRequired()), GenTableColumn::getIsRequired, null) |
| | | .set(StrUtil.isBlank(cenTableColumn.getDictType()), GenTableColumn::getDictType, "") |
| | | .set(StringUtils.isBlank(cenTableColumn.getColumnComment()), GenTableColumn::getColumnComment, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsPk()), GenTableColumn::getIsPk, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsIncrement()), GenTableColumn::getIsIncrement, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsInsert()), GenTableColumn::getIsInsert, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsEdit()), GenTableColumn::getIsEdit, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsList()), GenTableColumn::getIsList, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsQuery()), GenTableColumn::getIsQuery, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsRequired()), GenTableColumn::getIsRequired, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getDictType()), GenTableColumn::getDictType, "") |
| | | .eq(GenTableColumn::getColumnId,cenTableColumn.getColumnId())); |
| | | } |
| | | } |
| | |
| | | // è·å模æ¿å表 |
| | | List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); |
| | | for (String template : templates) { |
| | | if (!StrUtil.containsAny("sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm", template)) { |
| | | if (!StringUtils.containsAny("sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm", template)) { |
| | | // æ¸²ææ¨¡æ¿ |
| | | StringWriter sw = new StringWriter(); |
| | | Template tpl = Velocity.getTemplate(template, Constants.UTF8); |
| | |
| | | */ |
| | | public static String getGenPath(GenTable table, String template) { |
| | | String genPath = table.getGenPath(); |
| | | if (StrUtil.equals(genPath, "/")) { |
| | | if (StringUtils.equals(genPath, "/")) { |
| | | return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); |
| | | } |
| | | return genPath + File.separator + VelocityUtils.getFileName(template, table); |
| | |
| | | package com.ruoyi.generator.util; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import com.ruoyi.generator.config.GenConfig; |
| | | import com.ruoyi.generator.domain.GenTable; |
| | |
| | | column.setTableId(table.getTableId()); |
| | | column.setCreateBy(table.getCreateBy()); |
| | | // 设置javaåæ®µå |
| | | column.setJavaField(StrUtil.toCamelCase(columnName)); |
| | | column.setJavaField(StringUtils.toCamelCase(columnName)); |
| | | // 设置é»è®¤ç±»å |
| | | column.setJavaType(GenConstants.TYPE_STRING); |
| | | |
| | |
| | | column.setHtmlType(GenConstants.HTML_INPUT); |
| | | |
| | | // å¦ææ¯æµ®ç¹å ç»ä¸ç¨BigDecimal |
| | | String[] str = StrUtil.splitToArray(StrUtil.subBetween(column.getColumnType(), "(", ")"), ","); |
| | | String[] str = StringUtils.splitToArray(StringUtils.subBetween(column.getColumnType(), "(", ")"), ","); |
| | | if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) |
| | | { |
| | | column.setJavaType(GenConstants.TYPE_BIGDECIMAL); |
| | |
| | | } |
| | | |
| | | // æ¥è¯¢å段类å |
| | | if (StrUtil.endWithIgnoreCase(columnName, "name")) |
| | | if (StringUtils.endWithIgnoreCase(columnName, "name")) |
| | | { |
| | | column.setQueryType(GenConstants.QUERY_LIKE); |
| | | } |
| | | // ç¶æåæ®µè®¾ç½®åéæ¡ |
| | | if (StrUtil.endWithIgnoreCase(columnName, "status")) |
| | | if (StringUtils.endWithIgnoreCase(columnName, "status")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_RADIO); |
| | | } |
| | | // ç±»å&æ§å«åæ®µè®¾ç½®ä¸ææ¡ |
| | | else if (StrUtil.endWithIgnoreCase(columnName, "type") |
| | | || StrUtil.endWithIgnoreCase(columnName, "sex")) |
| | | else if (StringUtils.endWithIgnoreCase(columnName, "type") |
| | | || StringUtils.endWithIgnoreCase(columnName, "sex")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_SELECT); |
| | | } |
| | | // å¾çåæ®µè®¾ç½®å¾çä¸ä¼ æ§ä»¶ |
| | | else if (StrUtil.endWithIgnoreCase(columnName, "image")) |
| | | else if (StringUtils.endWithIgnoreCase(columnName, "image")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD); |
| | | } |
| | | // æä»¶å段设置æä»¶ä¸ä¼ æ§ä»¶ |
| | | else if (StrUtil.endWithIgnoreCase(columnName, "file")) |
| | | else if (StringUtils.endWithIgnoreCase(columnName, "file")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_FILE_UPLOAD); |
| | | } |
| | | // å
容忮µè®¾ç½®å¯ææ¬æ§ä»¶ |
| | | else if (StrUtil.endWithIgnoreCase(columnName, "content")) |
| | | else if (StringUtils.endWithIgnoreCase(columnName, "content")) |
| | | { |
| | | column.setHtmlType(GenConstants.HTML_EDITOR); |
| | | } |
| | |
| | | { |
| | | int lastIndex = packageName.lastIndexOf("."); |
| | | int nameLength = packageName.length(); |
| | | String moduleName = StrUtil.sub(packageName, lastIndex + 1, nameLength); |
| | | String moduleName = StringUtils.sub(packageName, lastIndex + 1, nameLength); |
| | | return moduleName; |
| | | } |
| | | |
| | |
| | | { |
| | | int lastIndex = tableName.lastIndexOf("_"); |
| | | int nameLength = tableName.length(); |
| | | String businessName = StrUtil.sub(tableName, lastIndex + 1, nameLength); |
| | | String businessName = StringUtils.sub(tableName, lastIndex + 1, nameLength); |
| | | return businessName; |
| | | } |
| | | |
| | |
| | | { |
| | | boolean autoRemovePre = GenConfig.getAutoRemovePre(); |
| | | String tablePrefix = GenConfig.getTablePrefix(); |
| | | if (autoRemovePre && StrUtil.isNotEmpty(tablePrefix)) |
| | | if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) |
| | | { |
| | | String[] searchList = StrUtil.splitToArray(tablePrefix, ","); |
| | | String[] searchList = StringUtils.splitToArray(tablePrefix, ","); |
| | | tableName = replaceFirst(tableName, searchList); |
| | | } |
| | | return StrUtil.upperFirst(StrUtil.toCamelCase(tableName)); |
| | | return StringUtils.upperFirst(StringUtils.toCamelCase(tableName)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static String getDbType(String columnType) |
| | | { |
| | | if (StrUtil.indexOf(columnType, '(') > 0) |
| | | if (StringUtils.indexOf(columnType, '(') > 0) |
| | | { |
| | | return StrUtil.subBefore(columnType, "(",false); |
| | | return StringUtils.subBefore(columnType, "(",false); |
| | | } |
| | | else |
| | | { |
| | |
| | | */ |
| | | public static Integer getColumnLength(String columnType) |
| | | { |
| | | if (StrUtil.indexOf(columnType, '(') > 0) |
| | | if (StringUtils.indexOf(columnType, '(') > 0) |
| | | { |
| | | String length = StrUtil.subBetween(columnType, "(", ")"); |
| | | String length = StringUtils.subBetween(columnType, "(", ")"); |
| | | return Integer.valueOf(length); |
| | | } |
| | | else |
| | |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | |
| | | VelocityContext velocityContext = new VelocityContext(); |
| | | velocityContext.put("tplCategory", genTable.getTplCategory()); |
| | | velocityContext.put("tableName", genTable.getTableName()); |
| | | velocityContext.put("functionName", StrUtil.isNotEmpty(functionName) ? functionName : "ã请填ååè½åç§°ã"); |
| | | velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "ã请填ååè½åç§°ã"); |
| | | velocityContext.put("ClassName", genTable.getClassName()); |
| | | velocityContext.put("className", StrUtil.lowerFirst(genTable.getClassName())); |
| | | velocityContext.put("className", StringUtils.lowerFirst(genTable.getClassName())); |
| | | velocityContext.put("moduleName", genTable.getModuleName()); |
| | | velocityContext.put("BusinessName", StrUtil.upperFirst(genTable.getBusinessName())); |
| | | velocityContext.put("BusinessName", StringUtils.upperFirst(genTable.getBusinessName())); |
| | | velocityContext.put("businessName", genTable.getBusinessName()); |
| | | velocityContext.put("basePackage", getPackagePrefix(packageName)); |
| | | velocityContext.put("packageName", packageName); |
| | |
| | | String subTableName = genTable.getSubTableName(); |
| | | String subTableFkName = genTable.getSubTableFkName(); |
| | | String subClassName = genTable.getSubTable().getClassName(); |
| | | String subTableFkClassName = StrUtil.toCamelCase(subTableFkName); |
| | | String subTableFkClassName = StringUtils.toCamelCase(subTableFkName); |
| | | |
| | | context.put("subTable", subTable); |
| | | context.put("subTableName", subTableName); |
| | | context.put("subTableFkName", subTableFkName); |
| | | context.put("subTableFkClassName", subTableFkClassName); |
| | | context.put("subTableFkclassName", StrUtil.lowerFirst(subTableFkClassName)); |
| | | context.put("subTableFkclassName", StringUtils.lowerFirst(subTableFkClassName)); |
| | | context.put("subClassName", subClassName); |
| | | context.put("subclassName", StrUtil.lowerFirst(subClassName)); |
| | | context.put("subclassName", StringUtils.lowerFirst(subClassName)); |
| | | context.put("subImportList", getImportList(genTable.getSubTable())); |
| | | } |
| | | |
| | |
| | | // ä¸å¡åç§° |
| | | String businessName = genTable.getBusinessName(); |
| | | |
| | | String javaPath = PROJECT_PATH + "/" + StrUtil.replace(packageName, ".", "/"); |
| | | String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); |
| | | String mybatisPath = MYBATIS_PATH + "/" + moduleName; |
| | | String vuePath = "vue"; |
| | | |
| | | if (template.contains("domain.java.vm")) |
| | | { |
| | | fileName = StrUtil.format("{}/domain/{}.java", javaPath, className); |
| | | fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); |
| | | } |
| | | if (template.contains("vo.java.vm")) |
| | | { |
| | | fileName = StrUtil.format("{}/domain/vo/{}Vo.java", javaPath, className); |
| | | fileName = StringUtils.format("{}/domain/vo/{}Vo.java", javaPath, className); |
| | | } |
| | | if (template.contains("bo.java.vm")) |
| | | { |
| | | fileName = StrUtil.format("{}/domain/bo/{}Bo.java", javaPath, className); |
| | | fileName = StringUtils.format("{}/domain/bo/{}Bo.java", javaPath, className); |
| | | } |
| | | if (template.contains("sub-domain.java.vm") && StrUtil.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) |
| | | if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) |
| | | { |
| | | fileName = StrUtil.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); |
| | | fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); |
| | | } |
| | | else if (template.contains("mapper.java.vm")) |
| | | { |
| | | fileName = StrUtil.format("{}/mapper/{}Mapper.java", javaPath, className); |
| | | fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); |
| | | } |
| | | else if (template.contains("service.java.vm")) |
| | | { |
| | | fileName = StrUtil.format("{}/service/I{}Service.java", javaPath, className); |
| | | fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); |
| | | } |
| | | else if (template.contains("serviceImpl.java.vm")) |
| | | { |
| | | fileName = StrUtil.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); |
| | | fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); |
| | | } |
| | | else if (template.contains("controller.java.vm")) |
| | | { |
| | | fileName = StrUtil.format("{}/controller/{}Controller.java", javaPath, className); |
| | | fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); |
| | | } |
| | | else if (template.contains("mapper.xml.vm")) |
| | | { |
| | | fileName = StrUtil.format("{}/{}Mapper.xml", mybatisPath, className); |
| | | fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); |
| | | } |
| | | else if (template.contains("sql.vm")) |
| | | { |
| | |
| | | } |
| | | else if (template.contains("api.js.vm")) |
| | | { |
| | | fileName = StrUtil.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); |
| | | fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); |
| | | } |
| | | else if (template.contains("index.vue.vm")) |
| | | { |
| | | fileName = StrUtil.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); |
| | | fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); |
| | | } |
| | | else if (template.contains("index-tree.vue.vm")) |
| | | { |
| | | fileName = StrUtil.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); |
| | | fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); |
| | | } |
| | | return fileName; |
| | | } |
| | |
| | | public static String getPackagePrefix(String packageName) |
| | | { |
| | | int lastIndex = packageName.lastIndexOf("."); |
| | | String basePackage = StrUtil.sub(packageName, 0, lastIndex); |
| | | String basePackage = StringUtils.sub(packageName, 0, lastIndex); |
| | | return basePackage; |
| | | } |
| | | |
| | |
| | | */ |
| | | public static String getPermissionPrefix(String moduleName, String businessName) |
| | | { |
| | | return StrUtil.format("{}:{}", moduleName, businessName); |
| | | return StringUtils.format("{}:{}", moduleName, businessName); |
| | | } |
| | | |
| | | /** |
| | |
| | | public static String getParentMenuId(Map<String, Object> paramsObj) |
| | | { |
| | | if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID) |
| | | && StrUtil.isNotEmpty(paramsObj.getString(GenConstants.PARENT_MENU_ID))) |
| | | && StringUtils.isNotEmpty(Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID)))) |
| | | { |
| | | return Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID)); |
| | | } |
| | |
| | | { |
| | | if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_CODE)) |
| | | { |
| | | return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_CODE))); |
| | | return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_CODE))); |
| | | } |
| | | return StrUtil.EMPTY; |
| | | return StringUtils.EMPTY; |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) |
| | | { |
| | | return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE))); |
| | | return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE))); |
| | | } |
| | | return StrUtil.EMPTY; |
| | | return StringUtils.EMPTY; |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) |
| | | { |
| | | return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_NAME))); |
| | | return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_NAME))); |
| | | } |
| | | return StrUtil.EMPTY; |
| | | return StringUtils.EMPTY; |
| | | } |
| | | |
| | | /** |
| | |
| | | package ${packageName}.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | #if($table.crud || $table.sub) |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.core.page.PagePlus; |
| | |
| | | #set($mpMethod=$column.queryType.toLowerCase()) |
| | | #if($queryType != 'BETWEEN') |
| | | #if($javaType == 'String') |
| | | #set($condition='StrUtil.isNotBlank(bo.get'+$AttrName+'())') |
| | | #set($condition='StringUtils.isNotBlank(bo.get'+$AttrName+'())') |
| | | #else |
| | | #set($condition='bo.get'+$AttrName+'() != null') |
| | | #end |
| | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.service.ICloudStorageService; |
| | | import org.springframework.beans.factory.InitializingBean; |
| | |
| | | String uuid = IdUtil.fastSimpleUUID(); |
| | | // æä»¶è·¯å¾ |
| | | String path = DateUtil.format(new Date(), "yyyyMMdd") + "/" + uuid; |
| | | if (StrUtil.isNotBlank(prefix)) { |
| | | if (StringUtils.isNotBlank(prefix)) { |
| | | path = prefix + "/" + path; |
| | | } |
| | | return path + suffix; |
| | |
| | | package com.ruoyi.oss.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.aliyun.oss.ClientConfiguration; |
| | | import com.aliyun.oss.OSSClient; |
| | | import com.aliyun.oss.common.auth.DefaultCredentialProvider; |
| | |
| | | public String getEndpointLink() { |
| | | String endpoint = properties.getEndpoint(); |
| | | StringBuilder sb = new StringBuilder(endpoint); |
| | | if (StrUtil.containsAnyIgnoreCase(endpoint, "http://")) { |
| | | if (StringUtils.containsAnyIgnoreCase(endpoint, "http://")) { |
| | | sb.insert(7, properties.getBucketName() + "."); |
| | | } else if (StrUtil.containsAnyIgnoreCase(endpoint, "https://")) { |
| | | } else if (StringUtils.containsAnyIgnoreCase(endpoint, "https://")) { |
| | | sb.insert(8, properties.getBucketName() + "."); |
| | | } else { |
| | | throw new OssException("Endpointé
ç½®é误"); |
| | |
| | | package com.ruoyi.oss.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.enumd.CloudServiceEnumd; |
| | | import com.ruoyi.oss.enumd.PolicyType; |
| | |
| | | minioClient.putObject(PutObjectArgs.builder() |
| | | .bucket(properties.getBucketName()) |
| | | .object(path) |
| | | .contentType(StrUtil.blankToDefault(contentType, MediaType.APPLICATION_OCTET_STREAM_VALUE)) |
| | | .contentType(StringUtils.blankToDefault(contentType, MediaType.APPLICATION_OCTET_STREAM_VALUE)) |
| | | .stream(inputStream, inputStream.available(), -1) |
| | | .build()); |
| | | } catch (Exception e) { |
| | |
| | | package com.ruoyi.oss.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.qcloud.cos.COSClient; |
| | | import com.qcloud.cos.ClientConfig; |
| | | import com.qcloud.cos.auth.BasicCOSCredentials; |
| | |
| | | public String getEndpointLink() { |
| | | String endpoint = properties.getEndpoint(); |
| | | StringBuilder sb = new StringBuilder(endpoint); |
| | | if (StrUtil.containsAnyIgnoreCase(endpoint, "http://")) { |
| | | if (StringUtils.containsAnyIgnoreCase(endpoint, "http://")) { |
| | | sb.insert(7, properties.getBucketName() + "."); |
| | | } else if (StrUtil.containsAnyIgnoreCase(endpoint, "https://")) { |
| | | } else if (StringUtils.containsAnyIgnoreCase(endpoint, "https://")) { |
| | | sb.insert(8, properties.getBucketName() + "."); |
| | | } else { |
| | | throw new OssException("Endpointé
ç½®é误"); |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | |
| | | private LambdaQueryWrapper<SysOss> buildQueryWrapper(SysOssBo bo) { |
| | | Map<String, Object> params = bo.getParams(); |
| | | LambdaQueryWrapper<SysOss> lqw = Wrappers.lambdaQuery(); |
| | | lqw.like(StrUtil.isNotBlank(bo.getFileName()), SysOss::getFileName, bo.getFileName()); |
| | | lqw.like(StrUtil.isNotBlank(bo.getOriginalName()), SysOss::getOriginalName, bo.getOriginalName()); |
| | | lqw.eq(StrUtil.isNotBlank(bo.getFileSuffix()), SysOss::getFileSuffix, bo.getFileSuffix()); |
| | | lqw.eq(StrUtil.isNotBlank(bo.getUrl()), SysOss::getUrl, bo.getUrl()); |
| | | lqw.like(StringUtils.isNotBlank(bo.getFileName()), SysOss::getFileName, bo.getFileName()); |
| | | lqw.like(StringUtils.isNotBlank(bo.getOriginalName()), SysOss::getOriginalName, bo.getOriginalName()); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getFileSuffix()), SysOss::getFileSuffix, bo.getFileSuffix()); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getUrl()), SysOss::getUrl, bo.getUrl()); |
| | | lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null, |
| | | SysOss::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime")); |
| | | lqw.eq(StrUtil.isNotBlank(bo.getCreateBy()), SysOss::getCreateBy, bo.getCreateBy()); |
| | | lqw.eq(StrUtil.isNotBlank(bo.getService()), SysOss::getService, bo.getService()); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getCreateBy()), SysOss::getCreateBy, bo.getCreateBy()); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getService()), SysOss::getService, bo.getService()); |
| | | return lqw; |
| | | } |
| | | |
| | | @Override |
| | | public SysOss upload(MultipartFile file) { |
| | | String originalfileName = file.getOriginalFilename(); |
| | | String suffix = StrUtil.sub(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length()); |
| | | String suffix = StringUtils.sub(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length()); |
| | | ICloudStorageService storage = OssFactory.instance(); |
| | | UploadResult uploadResult; |
| | | try { |
| | |
| | | package com.ruoyi.quartz.controller; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | { |
| | | return error("æ°å¢ä»»å¡'" + job.getJobName() + "'失败ï¼Cron表达å¼ä¸æ£ç¡®"); |
| | | } |
| | | else if (StrUtil.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI)) |
| | | else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI)) |
| | | { |
| | | return error("æ°å¢ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'rmi://'è°ç¨"); |
| | | } |
| | | else if (StrUtil.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS })) |
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS })) |
| | | { |
| | | return error("æ°å¢ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'http(s)//'è°ç¨"); |
| | | } |
| | |
| | | { |
| | | return error("ä¿®æ¹ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'rmi://'è°ç¨"); |
| | | } |
| | | else if (StrUtil.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS })) |
| | | else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS })) |
| | | { |
| | | return error("ä¿®æ¹ä»»å¡'" + job.getJobName() + "'失败ï¼ç®æ å符串ä¸å
许'http(s)//'è°ç¨"); |
| | | } |
| | |
| | | package com.ruoyi.quartz.domain; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.annotation.*; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.common.annotation.Excel; |
| | |
| | | |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | public Date getNextValidTime() { |
| | | if (StrUtil.isNotEmpty(cronExpression)) { |
| | | if (StringUtils.isNotEmpty(cronExpression)) { |
| | | return CronUtils.getNextExecution(cronExpression); |
| | | } |
| | | return null; |
| | |
| | | package com.ruoyi.quartz.service.impl; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | |
| | | public TableDataInfo<SysJobLog> selectPageJobLogList(SysJobLog jobLog) { |
| | | Map<String, Object> params = jobLog.getParams(); |
| | | LambdaQueryWrapper<SysJobLog> lqw = new LambdaQueryWrapper<SysJobLog>() |
| | | .like(StrUtil.isNotBlank(jobLog.getJobName()), SysJobLog::getJobName, jobLog.getJobName()) |
| | | .eq(StrUtil.isNotBlank(jobLog.getJobGroup()), SysJobLog::getJobGroup, jobLog.getJobGroup()) |
| | | .eq(StrUtil.isNotBlank(jobLog.getStatus()), SysJobLog::getStatus, jobLog.getStatus()) |
| | | .like(StrUtil.isNotBlank(jobLog.getInvokeTarget()), SysJobLog::getInvokeTarget, jobLog.getInvokeTarget()) |
| | | .like(StringUtils.isNotBlank(jobLog.getJobName()), SysJobLog::getJobName, jobLog.getJobName()) |
| | | .eq(StringUtils.isNotBlank(jobLog.getJobGroup()), SysJobLog::getJobGroup, jobLog.getJobGroup()) |
| | | .eq(StringUtils.isNotBlank(jobLog.getStatus()), SysJobLog::getStatus, jobLog.getStatus()) |
| | | .like(StringUtils.isNotBlank(jobLog.getInvokeTarget()), SysJobLog::getInvokeTarget, jobLog.getInvokeTarget()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | |
| | | public List<SysJobLog> selectJobLogList(SysJobLog jobLog) { |
| | | Map<String, Object> params = jobLog.getParams(); |
| | | return list(new LambdaQueryWrapper<SysJobLog>() |
| | | .like(StrUtil.isNotBlank(jobLog.getJobName()), SysJobLog::getJobName, jobLog.getJobName()) |
| | | .eq(StrUtil.isNotBlank(jobLog.getJobGroup()), SysJobLog::getJobGroup, jobLog.getJobGroup()) |
| | | .eq(StrUtil.isNotBlank(jobLog.getStatus()), SysJobLog::getStatus, jobLog.getStatus()) |
| | | .like(StrUtil.isNotBlank(jobLog.getInvokeTarget()), SysJobLog::getInvokeTarget, jobLog.getInvokeTarget()) |
| | | .like(StringUtils.isNotBlank(jobLog.getJobName()), SysJobLog::getJobName, jobLog.getJobName()) |
| | | .eq(StringUtils.isNotBlank(jobLog.getJobGroup()), SysJobLog::getJobGroup, jobLog.getJobGroup()) |
| | | .eq(StringUtils.isNotBlank(jobLog.getStatus()), SysJobLog::getStatus, jobLog.getStatus()) |
| | | .like(StringUtils.isNotBlank(jobLog.getInvokeTarget()), SysJobLog::getInvokeTarget, jobLog.getInvokeTarget()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | |
| | | package com.ruoyi.quartz.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.constant.ScheduleConstants; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | |
| | | @Override |
| | | public TableDataInfo<SysJob> selectPageJobList(SysJob job) { |
| | | LambdaQueryWrapper<SysJob> lqw = new LambdaQueryWrapper<SysJob>() |
| | | .like(StrUtil.isNotBlank(job.getJobName()), SysJob::getJobName, job.getJobName()) |
| | | .eq(StrUtil.isNotBlank(job.getJobGroup()), SysJob::getJobGroup, job.getJobGroup()) |
| | | .eq(StrUtil.isNotBlank(job.getStatus()), SysJob::getStatus, job.getStatus()) |
| | | .like(StrUtil.isNotBlank(job.getInvokeTarget()), SysJob::getInvokeTarget, job.getInvokeTarget()); |
| | | .like(StringUtils.isNotBlank(job.getJobName()), SysJob::getJobName, job.getJobName()) |
| | | .eq(StringUtils.isNotBlank(job.getJobGroup()), SysJob::getJobGroup, job.getJobGroup()) |
| | | .eq(StringUtils.isNotBlank(job.getStatus()), SysJob::getStatus, job.getStatus()) |
| | | .like(StringUtils.isNotBlank(job.getInvokeTarget()), SysJob::getInvokeTarget, job.getInvokeTarget()); |
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw)); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public List<SysJob> selectJobList(SysJob job) { |
| | | return list(new LambdaQueryWrapper<SysJob>() |
| | | .like(StrUtil.isNotBlank(job.getJobName()), SysJob::getJobName, job.getJobName()) |
| | | .eq(StrUtil.isNotBlank(job.getJobGroup()), SysJob::getJobGroup, job.getJobGroup()) |
| | | .eq(StrUtil.isNotBlank(job.getStatus()), SysJob::getStatus, job.getStatus()) |
| | | .like(StrUtil.isNotBlank(job.getInvokeTarget()), SysJob::getInvokeTarget, job.getInvokeTarget())); |
| | | .like(StringUtils.isNotBlank(job.getJobName()), SysJob::getJobName, job.getJobName()) |
| | | .eq(StringUtils.isNotBlank(job.getJobGroup()), SysJob::getJobGroup, job.getJobGroup()) |
| | | .eq(StringUtils.isNotBlank(job.getStatus()), SysJob::getStatus, job.getStatus()) |
| | | .like(StringUtils.isNotBlank(job.getInvokeTarget()), SysJob::getInvokeTarget, job.getInvokeTarget())); |
| | | } |
| | | |
| | | /** |
| | |
| | | package com.ruoyi.quartz.task;
|
| | |
|
| | | import cn.hutool.core.lang.Console;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | /**
|
| | | * 宿¶ä»»å¡è°åº¦æµè¯
|
| | | * |
| | | * @author ruoyi
|
| | | */
|
| | | @Component("ryTask")
|
| | | public class RyTask
|
| | | {
|
| | | public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
|
| | | {
|
| | | Console.log(StrUtil.format("æ§è¡å¤åæ¹æ³ï¼ å符串类å{}ï¼å¸å°ç±»å{}ï¼é¿æ´å{}ï¼æµ®ç¹å{}ï¼æ´å½¢{}", s, b, l, d, i));
|
| | | }
|
| | |
|
| | | public void ryParams(String params)
|
| | | {
|
| | | Console.log("æ§è¡æåæ¹æ³ï¼" + params);
|
| | | }
|
| | |
|
| | | public void ryNoParams()
|
| | | {
|
| | | Console.log("æ§è¡æ åæ¹æ³");
|
| | | }
|
| | | }
|
| | | package com.ruoyi.quartz.task; |
| | | |
| | | import cn.hutool.core.lang.Console; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡è°åº¦æµè¯ |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Component("ryTask") |
| | | public class RyTask |
| | | { |
| | | public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) |
| | | { |
| | | Console.log(StringUtils.format("æ§è¡å¤åæ¹æ³ï¼ å符串类å{}ï¼å¸å°ç±»å{}ï¼é¿æ´å{}ï¼æµ®ç¹å{}ï¼æ´å½¢{}", s, b, l, d, i)); |
| | | } |
| | | |
| | | public void ryParams(String params) |
| | | { |
| | | Console.log("æ§è¡æåæ¹æ³ï¼" + params); |
| | | } |
| | | |
| | | public void ryNoParams() |
| | | { |
| | | Console.log("æ§è¡æ åæ¹æ³"); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.quartz.util;
|
| | |
|
| | | import cn.hutool.core.bean.BeanUtil;
|
| | | import cn.hutool.core.exceptions.ExceptionUtil;
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.constant.ScheduleConstants;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | | import com.ruoyi.quartz.domain.SysJobLog;
|
| | | import com.ruoyi.quartz.service.ISysJobLogService;
|
| | | import org.quartz.Job;
|
| | | import org.quartz.JobExecutionContext;
|
| | | import org.quartz.JobExecutionException;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | /**
|
| | | * æ½è±¡quartzè°ç¨
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public abstract class AbstractQuartzJob implements Job
|
| | | {
|
| | | private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class);
|
| | |
|
| | | /**
|
| | | * çº¿ç¨æ¬å°åé
|
| | | */
|
| | | private static ThreadLocal<Date> threadLocal = new ThreadLocal<>();
|
| | |
|
| | | @Override
|
| | | public void execute(JobExecutionContext context) throws JobExecutionException
|
| | | {
|
| | | SysJob sysJob = new SysJob();
|
| | | BeanUtil.copyProperties(context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES),sysJob);
|
| | | try
|
| | | {
|
| | | before(context, sysJob);
|
| | | if (Validator.isNotNull(sysJob))
|
| | | {
|
| | | doExecute(context, sysJob);
|
| | | }
|
| | | after(context, sysJob, null);
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | log.error("任塿§è¡å¼å¸¸ - ï¼", e);
|
| | | after(context, sysJob, e);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ§è¡å
|
| | | *
|
| | | * @param context 工使§è¡ä¸ä¸æå¯¹è±¡
|
| | | * @param sysJob ç³»ç»è®¡åä»»å¡
|
| | | */
|
| | | protected void before(JobExecutionContext context, SysJob sysJob)
|
| | | {
|
| | | threadLocal.set(new Date());
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ§è¡å
|
| | | *
|
| | | * @param context 工使§è¡ä¸ä¸æå¯¹è±¡
|
| | | * @param sysJob ç³»ç»è®¡åä»»å¡
|
| | | */
|
| | | 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 = StrUtil.sub(ExceptionUtil.stacktraceToString(e), 0, 2000);
|
| | | sysJobLog.setExceptionInfo(errorMsg);
|
| | | }
|
| | | else
|
| | | {
|
| | | sysJobLog.setStatus(Constants.SUCCESS);
|
| | | }
|
| | |
|
| | | // åå
¥æ°æ®åºå½ä¸
|
| | | SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog);
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ§è¡æ¹æ³ï¼ç±åç±»éè½½
|
| | | *
|
| | | * @param context 工使§è¡ä¸ä¸æå¯¹è±¡
|
| | | * @param sysJob ç³»ç»è®¡åä»»å¡
|
| | | * @throws Exception æ§è¡è¿ç¨ä¸çå¼å¸¸
|
| | | */
|
| | | protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception;
|
| | | }
|
| | | package com.ruoyi.quartz.util; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.exceptions.ExceptionUtil; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.ScheduleConstants; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.quartz.domain.SysJob; |
| | | import com.ruoyi.quartz.domain.SysJobLog; |
| | | import com.ruoyi.quartz.service.ISysJobLogService; |
| | | import org.quartz.Job; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * æ½è±¡quartzè°ç¨ |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public abstract class AbstractQuartzJob implements Job |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class); |
| | | |
| | | /** |
| | | * çº¿ç¨æ¬å°åé |
| | | */ |
| | | private static ThreadLocal<Date> threadLocal = new ThreadLocal<>(); |
| | | |
| | | @Override |
| | | public void execute(JobExecutionContext context) throws JobExecutionException |
| | | { |
| | | SysJob sysJob = new SysJob(); |
| | | BeanUtil.copyProperties(context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES),sysJob); |
| | | try |
| | | { |
| | | before(context, sysJob); |
| | | if (Validator.isNotNull(sysJob)) |
| | | { |
| | | doExecute(context, sysJob); |
| | | } |
| | | after(context, sysJob, null); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("任塿§è¡å¼å¸¸ - ï¼", e); |
| | | after(context, sysJob, e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡å |
| | | * |
| | | * @param context 工使§è¡ä¸ä¸æå¯¹è±¡ |
| | | * @param sysJob ç³»ç»è®¡åä»»å¡ |
| | | */ |
| | | protected void before(JobExecutionContext context, SysJob sysJob) |
| | | { |
| | | threadLocal.set(new Date()); |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡å |
| | | * |
| | | * @param context 工使§è¡ä¸ä¸æå¯¹è±¡ |
| | | * @param sysJob ç³»ç»è®¡åä»»å¡ |
| | | */ |
| | | 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.sub(ExceptionUtil.stacktraceToString(e), 0, 2000); |
| | | sysJobLog.setExceptionInfo(errorMsg); |
| | | } |
| | | else |
| | | { |
| | | sysJobLog.setStatus(Constants.SUCCESS); |
| | | } |
| | | |
| | | // åå
¥æ°æ®åºå½ä¸ |
| | | SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡æ¹æ³ï¼ç±åç±»éè½½ |
| | | * |
| | | * @param context 工使§è¡ä¸ä¸æå¯¹è±¡ |
| | | * @param sysJob ç³»ç»è®¡åä»»å¡ |
| | | * @throws Exception æ§è¡è¿ç¨ä¸çå¼å¸¸ |
| | | */ |
| | | protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception; |
| | | } |
| | |
| | | package com.ruoyi.quartz.util;
|
| | |
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | import java.lang.reflect.InvocationTargetException;
|
| | | import java.lang.reflect.Method;
|
| | | import java.util.LinkedList;
|
| | | import java.util.List;
|
| | |
|
| | | /**
|
| | | * 任塿§è¡å·¥å
·
|
| | | *
|
| | | * @author ruoyi
|
| | | */
|
| | | public class JobInvokeUtil
|
| | | {
|
| | | /**
|
| | | * æ§è¡æ¹æ³
|
| | | *
|
| | | * @param sysJob ç³»ç»ä»»å¡
|
| | | */
|
| | | public static void invokeMethod(SysJob sysJob) throws Exception
|
| | | {
|
| | | String invokeTarget = sysJob.getInvokeTarget();
|
| | | String beanName = getBeanName(invokeTarget);
|
| | | String methodName = getMethodName(invokeTarget);
|
| | | List<Object[]> methodParams = getMethodParams(invokeTarget);
|
| | |
|
| | | if (!isValidClassName(beanName))
|
| | | {
|
| | | Object bean = SpringUtils.getBean(beanName);
|
| | | invokeMethod(bean, methodName, methodParams);
|
| | | }
|
| | | else
|
| | | {
|
| | | Object bean = Class.forName(beanName).newInstance();
|
| | | invokeMethod(bean, methodName, methodParams);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * è°ç¨ä»»å¡æ¹æ³
|
| | | *
|
| | | * @param bean ç®æ 对象
|
| | | * @param methodName æ¹æ³åç§°
|
| | | * @param methodParams æ¹æ³åæ°
|
| | | */
|
| | | private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams)
|
| | | throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
|
| | | InvocationTargetException
|
| | | {
|
| | | if (Validator.isNotNull(methodParams) && methodParams.size() > 0)
|
| | | {
|
| | | Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams));
|
| | | method.invoke(bean, getMethodParamsValue(methodParams));
|
| | | }
|
| | | else
|
| | | {
|
| | | Method method = bean.getClass().getDeclaredMethod(methodName);
|
| | | method.invoke(bean);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * æ ¡éªæ¯å¦ä¸ºä¸ºclasså
å
|
| | | * |
| | | * @param str åç§°
|
| | | * @return trueæ¯ falseå¦
|
| | | */
|
| | | public static boolean isValidClassName(String invokeTarget)
|
| | | {
|
| | | return StrUtil.count(invokeTarget, ".") > 1;
|
| | | }
|
| | |
|
| | | /**
|
| | | * è·åbeanåç§°
|
| | | * |
| | | * @param invokeTarget ç®æ å符串
|
| | | * @return beanåç§°
|
| | | */
|
| | | public static String getBeanName(String invokeTarget)
|
| | | {
|
| | | String beanName = StrUtil.subBefore(invokeTarget, "(",false);
|
| | | return StrUtil.subBefore(beanName, ".",true);
|
| | | }
|
| | |
|
| | | /**
|
| | | * è·åbeanæ¹æ³
|
| | | * |
| | | * @param invokeTarget ç®æ å符串
|
| | | * @return methodæ¹æ³
|
| | | */
|
| | | public static String getMethodName(String invokeTarget)
|
| | | {
|
| | | String methodName = StrUtil.subBefore(invokeTarget, "(",false);
|
| | | return StrUtil.subAfter(methodName, ".",true);
|
| | | }
|
| | |
|
| | | /**
|
| | | * è·åmethodæ¹æ³åæ°ç¸å
³å表
|
| | | * |
| | | * @param invokeTarget ç®æ å符串
|
| | | * @return methodæ¹æ³ç¸å
³åæ°å表
|
| | | */
|
| | | public static List<Object[]> getMethodParams(String invokeTarget)
|
| | | {
|
| | | String methodStr = StrUtil.subBetween(invokeTarget, "(", ")");
|
| | | if (StrUtil.isEmpty(methodStr))
|
| | | {
|
| | | return null;
|
| | | }
|
| | | String[] methodParams = methodStr.split(",");
|
| | | List<Object[]> classs = new LinkedList<>();
|
| | | for (int i = 0; i < methodParams.length; i++)
|
| | | {
|
| | | String str = StrUtil.trimToEmpty(methodParams[i]);
|
| | | // Stringå符串类åï¼å
å«'
|
| | | if (StrUtil.contains(str, "'"))
|
| | | {
|
| | | classs.add(new Object[] { StrUtil.replace(str, "'", ""), String.class });
|
| | | }
|
| | | // booleanå¸å°ç±»åï¼çäºtrueæè
false
|
| | | else if (StrUtil.equals(str, "true") || StrUtil.equalsIgnoreCase(str, "false"))
|
| | | {
|
| | | classs.add(new Object[] { Boolean.valueOf(str), Boolean.class });
|
| | | }
|
| | | // longé¿æ´å½¢ï¼å
å«L
|
| | | else if (StrUtil.containsIgnoreCase(str, "L"))
|
| | | {
|
| | | classs.add(new Object[] { Long.valueOf(StrUtil.replaceIgnoreCase(str, "L", "")), Long.class });
|
| | | }
|
| | | // doubleæµ®ç¹ç±»åï¼å
å«D
|
| | | else if (StrUtil.containsIgnoreCase(str, "D"))
|
| | | {
|
| | | classs.add(new Object[] { Double.valueOf(StrUtil.replaceIgnoreCase(str, "D", "")), Double.class });
|
| | | }
|
| | | // å
¶ä»ç±»åå½ç±»ä¸ºæ´å½¢
|
| | | else
|
| | | {
|
| | | classs.add(new Object[] { Integer.valueOf(str), Integer.class });
|
| | | }
|
| | | }
|
| | | return classs;
|
| | | }
|
| | |
|
| | | /**
|
| | | * è·ååæ°ç±»å
|
| | | * |
| | | * @param methodParams åæ°ç¸å
³å表
|
| | | * @return åæ°ç±»åå表
|
| | | */
|
| | | public static Class<?>[] getMethodParamsType(List<Object[]> methodParams)
|
| | | {
|
| | | Class<?>[] classs = new Class<?>[methodParams.size()];
|
| | | int index = 0;
|
| | | for (Object[] os : methodParams)
|
| | | {
|
| | | classs[index] = (Class<?>) os[1];
|
| | | index++;
|
| | | }
|
| | | return classs;
|
| | | }
|
| | |
|
| | | /**
|
| | | * è·ååæ°å¼
|
| | | * |
| | | * @param methodParams åæ°ç¸å
³å表
|
| | | * @return åæ°å¼å表
|
| | | */
|
| | | public static Object[] getMethodParamsValue(List<Object[]> methodParams)
|
| | | {
|
| | | Object[] classs = new Object[methodParams.size()];
|
| | | int index = 0;
|
| | | for (Object[] os : methodParams)
|
| | | {
|
| | | classs[index] = (Object) os[0];
|
| | | index++;
|
| | | }
|
| | | return classs;
|
| | | }
|
| | | }
|
| | | package com.ruoyi.quartz.util; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.quartz.domain.SysJob; |
| | | |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.lang.reflect.Method; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 任塿§è¡å·¥å
· |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class JobInvokeUtil |
| | | { |
| | | /** |
| | | * æ§è¡æ¹æ³ |
| | | * |
| | | * @param sysJob ç³»ç»ä»»å¡ |
| | | */ |
| | | public static void invokeMethod(SysJob sysJob) throws Exception |
| | | { |
| | | String invokeTarget = sysJob.getInvokeTarget(); |
| | | String beanName = getBeanName(invokeTarget); |
| | | String methodName = getMethodName(invokeTarget); |
| | | List<Object[]> methodParams = getMethodParams(invokeTarget); |
| | | |
| | | if (!isValidClassName(beanName)) |
| | | { |
| | | Object bean = SpringUtils.getBean(beanName); |
| | | invokeMethod(bean, methodName, methodParams); |
| | | } |
| | | else |
| | | { |
| | | Object bean = Class.forName(beanName).newInstance(); |
| | | invokeMethod(bean, methodName, methodParams); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è°ç¨ä»»å¡æ¹æ³ |
| | | * |
| | | * @param bean ç®æ 对象 |
| | | * @param methodName æ¹æ³åç§° |
| | | * @param methodParams æ¹æ³åæ° |
| | | */ |
| | | private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams) |
| | | throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, |
| | | InvocationTargetException |
| | | { |
| | | if (Validator.isNotNull(methodParams) && methodParams.size() > 0) |
| | | { |
| | | Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams)); |
| | | method.invoke(bean, getMethodParamsValue(methodParams)); |
| | | } |
| | | else |
| | | { |
| | | Method method = bean.getClass().getDeclaredMethod(methodName); |
| | | method.invoke(bean); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªæ¯å¦ä¸ºä¸ºclasså
å |
| | | * |
| | | * @param str åç§° |
| | | * @return trueæ¯ falseå¦ |
| | | */ |
| | | public static boolean isValidClassName(String invokeTarget) |
| | | { |
| | | return StringUtils.count(invokeTarget, ".") > 1; |
| | | } |
| | | |
| | | /** |
| | | * è·åbeanåç§° |
| | | * |
| | | * @param invokeTarget ç®æ å符串 |
| | | * @return beanåç§° |
| | | */ |
| | | public static String getBeanName(String invokeTarget) |
| | | { |
| | | String beanName = StringUtils.subBefore(invokeTarget, "(",false); |
| | | return StringUtils.subBefore(beanName, ".",true); |
| | | } |
| | | |
| | | /** |
| | | * è·åbeanæ¹æ³ |
| | | * |
| | | * @param invokeTarget ç®æ å符串 |
| | | * @return methodæ¹æ³ |
| | | */ |
| | | public static String getMethodName(String invokeTarget) |
| | | { |
| | | String methodName = StringUtils.subBefore(invokeTarget, "(",false); |
| | | return StringUtils.subAfter(methodName, ".",true); |
| | | } |
| | | |
| | | /** |
| | | * è·åmethodæ¹æ³åæ°ç¸å
³å表 |
| | | * |
| | | * @param invokeTarget ç®æ å符串 |
| | | * @return methodæ¹æ³ç¸å
³åæ°å表 |
| | | */ |
| | | public static List<Object[]> getMethodParams(String invokeTarget) |
| | | { |
| | | String methodStr = StringUtils.subBetween(invokeTarget, "(", ")"); |
| | | if (StringUtils.isEmpty(methodStr)) |
| | | { |
| | | return null; |
| | | } |
| | | String[] methodParams = methodStr.split(","); |
| | | List<Object[]> classs = new LinkedList<>(); |
| | | for (int i = 0; i < methodParams.length; i++) |
| | | { |
| | | String str = StringUtils.trimToEmpty(methodParams[i]); |
| | | // Stringå符串类åï¼å
å«' |
| | | if (StringUtils.contains(str, "'")) |
| | | { |
| | | classs.add(new Object[] { StringUtils.replace(str, "'", ""), String.class }); |
| | | } |
| | | // booleanå¸å°ç±»åï¼çäºtrueæè
false |
| | | else if (StringUtils.equals(str, "true") || StringUtils.equalsIgnoreCase(str, "false")) |
| | | { |
| | | classs.add(new Object[] { Boolean.valueOf(str), Boolean.class }); |
| | | } |
| | | // longé¿æ´å½¢ï¼å
å«L |
| | | else if (StringUtils.containsIgnoreCase(str, "L")) |
| | | { |
| | | classs.add(new Object[] { Long.valueOf(StringUtils.replaceIgnoreCase(str, "L", "")), Long.class }); |
| | | } |
| | | // doubleæµ®ç¹ç±»åï¼å
å«D |
| | | else if (StringUtils.containsIgnoreCase(str, "D")) |
| | | { |
| | | classs.add(new Object[] { Double.valueOf(StringUtils.replaceIgnoreCase(str, "D", "")), Double.class }); |
| | | } |
| | | // å
¶ä»ç±»åå½ç±»ä¸ºæ´å½¢ |
| | | else |
| | | { |
| | | classs.add(new Object[] { Integer.valueOf(str), Integer.class }); |
| | | } |
| | | } |
| | | return classs; |
| | | } |
| | | |
| | | /** |
| | | * è·ååæ°ç±»å |
| | | * |
| | | * @param methodParams åæ°ç¸å
³å表 |
| | | * @return åæ°ç±»åå表 |
| | | */ |
| | | public static Class<?>[] getMethodParamsType(List<Object[]> methodParams) |
| | | { |
| | | Class<?>[] classs = new Class<?>[methodParams.size()]; |
| | | int index = 0; |
| | | for (Object[] os : methodParams) |
| | | { |
| | | classs[index] = (Class<?>) os[1]; |
| | | index++; |
| | | } |
| | | return classs; |
| | | } |
| | | |
| | | /** |
| | | * è·ååæ°å¼ |
| | | * |
| | | * @param methodParams åæ°ç¸å
³å表 |
| | | * @return åæ°å¼å表 |
| | | */ |
| | | public static Object[] getMethodParamsValue(List<Object[]> methodParams) |
| | | { |
| | | Object[] classs = new Object[methodParams.size()]; |
| | | int index = 0; |
| | | for (Object[] os : methodParams) |
| | | { |
| | | classs[index] = (Object) os[0]; |
| | | index++; |
| | | } |
| | | return classs; |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.system.domain.vo; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import lombok.experimental.Accessors; |
| | |
| | | this.title = title; |
| | | this.icon = icon; |
| | | this.noCache = noCache; |
| | | if (Validator.isUrl(link)) { |
| | | if (StringUtils.ishttp(link)) { |
| | | this.link = link; |
| | | } |
| | | } |
| | |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.annotation.DataSource; |
| | | import com.ruoyi.common.constant.Constants; |
| | |
| | | public TableDataInfo<SysConfig> selectPageConfigList(SysConfig config) { |
| | | Map<String, Object> params = config.getParams(); |
| | | LambdaQueryWrapper<SysConfig> lqw = new LambdaQueryWrapper<SysConfig>() |
| | | .like(StrUtil.isNotBlank(config.getConfigName()), SysConfig::getConfigName, config.getConfigName()) |
| | | .eq(StrUtil.isNotBlank(config.getConfigType()), SysConfig::getConfigType, config.getConfigType()) |
| | | .like(StrUtil.isNotBlank(config.getConfigKey()), SysConfig::getConfigKey, config.getConfigKey()) |
| | | .like(StringUtils.isNotBlank(config.getConfigName()), SysConfig::getConfigName, config.getConfigName()) |
| | | .eq(StringUtils.isNotBlank(config.getConfigType()), SysConfig::getConfigType, config.getConfigType()) |
| | | .like(StringUtils.isNotBlank(config.getConfigKey()), SysConfig::getConfigKey, config.getConfigKey()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | |
| | | redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue()); |
| | | return retConfig.getConfigValue(); |
| | | } |
| | | return StrUtil.EMPTY; |
| | | return StringUtils.EMPTY; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public boolean selectCaptchaOnOff() { |
| | | String captchaOnOff = selectConfigByKey("sys.account.captchaOnOff"); |
| | | if (StrUtil.isEmpty(captchaOnOff)) { |
| | | if (StringUtils.isEmpty(captchaOnOff)) { |
| | | return true; |
| | | } |
| | | return Convert.toBool(captchaOnOff); |
| | |
| | | public List<SysConfig> selectConfigList(SysConfig config) { |
| | | Map<String, Object> params = config.getParams(); |
| | | LambdaQueryWrapper<SysConfig> lqw = new LambdaQueryWrapper<SysConfig>() |
| | | .like(StrUtil.isNotBlank(config.getConfigName()), SysConfig::getConfigName, config.getConfigName()) |
| | | .eq(StrUtil.isNotBlank(config.getConfigType()), SysConfig::getConfigType, config.getConfigType()) |
| | | .like(StrUtil.isNotBlank(config.getConfigKey()), SysConfig::getConfigKey, config.getConfigKey()) |
| | | .like(StringUtils.isNotBlank(config.getConfigName()), SysConfig::getConfigName, config.getConfigName()) |
| | | .eq(StringUtils.isNotBlank(config.getConfigType()), SysConfig::getConfigType, config.getConfigType()) |
| | | .like(StringUtils.isNotBlank(config.getConfigKey()), SysConfig::getConfigKey, config.getConfigKey()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | |
| | | public void deleteConfigByIds(Long[] configIds) { |
| | | for (Long configId : configIds) { |
| | | SysConfig config = selectConfigById(configId); |
| | | if (StrUtil.equals(UserConstants.YES, config.getConfigType())) { |
| | | if (StringUtils.equals(UserConstants.YES, config.getConfigType())) { |
| | | throw new CustomException(String.format("å
ç½®åæ°ã%1$sãä¸è½å é¤ ", config.getConfigKey())); |
| | | } |
| | | redisCache.deleteObject(getCacheKey(config.getConfigKey())); |
| | |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | |
| | | updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); |
| | | } |
| | | int result = baseMapper.updateById(dept); |
| | | if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StrUtil.isNotEmpty(dept.getAncestors()) |
| | | && !StrUtil.equals("0", dept.getAncestors())) { |
| | | if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) |
| | | && !StringUtils.equals("0", dept.getAncestors())) { |
| | | // å¦æè¯¥é¨é¨æ¯å¯ç¨ç¶æï¼åå¯ç¨è¯¥é¨é¨çææä¸çº§é¨é¨ |
| | | updateParentDeptStatusNormal(dept); |
| | | } |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | |
| | | @Override |
| | | public TableDataInfo<SysDictData> selectPageDictDataList(SysDictData dictData) { |
| | | LambdaQueryWrapper<SysDictData> lqw = new LambdaQueryWrapper<SysDictData>() |
| | | .eq(StrUtil.isNotBlank(dictData.getDictType()), SysDictData::getDictType, dictData.getDictType()) |
| | | .like(StrUtil.isNotBlank(dictData.getDictLabel()), SysDictData::getDictLabel, dictData.getDictLabel()) |
| | | .eq(StrUtil.isNotBlank(dictData.getStatus()), SysDictData::getStatus, dictData.getStatus()) |
| | | .eq(StringUtils.isNotBlank(dictData.getDictType()), SysDictData::getDictType, dictData.getDictType()) |
| | | .like(StringUtils.isNotBlank(dictData.getDictLabel()), SysDictData::getDictLabel, dictData.getDictLabel()) |
| | | .eq(StringUtils.isNotBlank(dictData.getStatus()), SysDictData::getStatus, dictData.getStatus()) |
| | | .orderByAsc(SysDictData::getDictSort); |
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw)); |
| | | } |
| | |
| | | @Override |
| | | public List<SysDictData> selectDictDataList(SysDictData dictData) { |
| | | return list(new LambdaQueryWrapper<SysDictData>() |
| | | .eq(StrUtil.isNotBlank(dictData.getDictType()), SysDictData::getDictType, dictData.getDictType()) |
| | | .like(StrUtil.isNotBlank(dictData.getDictLabel()), SysDictData::getDictLabel, dictData.getDictLabel()) |
| | | .eq(StrUtil.isNotBlank(dictData.getStatus()), SysDictData::getStatus, dictData.getStatus()) |
| | | .eq(StringUtils.isNotBlank(dictData.getDictType()), SysDictData::getDictType, dictData.getDictType()) |
| | | .like(StringUtils.isNotBlank(dictData.getDictLabel()), SysDictData::getDictLabel, dictData.getDictLabel()) |
| | | .eq(StringUtils.isNotBlank(dictData.getStatus()), SysDictData::getStatus, dictData.getStatus()) |
| | | .orderByAsc(SysDictData::getDictSort)); |
| | | } |
| | | |
| | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | |
| | | public TableDataInfo<SysDictType> selectPageDictTypeList(SysDictType dictType) { |
| | | Map<String, Object> params = dictType.getParams(); |
| | | LambdaQueryWrapper<SysDictType> lqw = new LambdaQueryWrapper<SysDictType>() |
| | | .like(StrUtil.isNotBlank(dictType.getDictName()), SysDictType::getDictName, dictType.getDictName()) |
| | | .eq(StrUtil.isNotBlank(dictType.getStatus()), SysDictType::getStatus, dictType.getStatus()) |
| | | .like(StrUtil.isNotBlank(dictType.getDictType()), SysDictType::getDictType, dictType.getDictType()) |
| | | .like(StringUtils.isNotBlank(dictType.getDictName()), SysDictType::getDictName, dictType.getDictName()) |
| | | .eq(StringUtils.isNotBlank(dictType.getStatus()), SysDictType::getStatus, dictType.getStatus()) |
| | | .like(StringUtils.isNotBlank(dictType.getDictType()), SysDictType::getDictType, dictType.getDictType()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | |
| | | public List<SysDictType> selectDictTypeList(SysDictType dictType) { |
| | | Map<String, Object> params = dictType.getParams(); |
| | | return list(new LambdaQueryWrapper<SysDictType>() |
| | | .like(StrUtil.isNotBlank(dictType.getDictName()), SysDictType::getDictName, dictType.getDictName()) |
| | | .eq(StrUtil.isNotBlank(dictType.getStatus()), SysDictType::getStatus, dictType.getStatus()) |
| | | .like(StrUtil.isNotBlank(dictType.getDictType()), SysDictType::getDictType, dictType.getDictType()) |
| | | .like(StringUtils.isNotBlank(dictType.getDictName()), SysDictType::getDictName, dictType.getDictName()) |
| | | .eq(StringUtils.isNotBlank(dictType.getStatus()), SysDictType::getStatus, dictType.getStatus()) |
| | | .like(StringUtils.isNotBlank(dictType.getDictType()), SysDictType::getDictType, dictType.getDictType()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.SysLogininfor; |
| | | import com.ruoyi.system.mapper.SysLogininforMapper; |
| | | import com.ruoyi.system.service.ISysLogininforService; |
| | |
| | | public TableDataInfo<SysLogininfor> selectPageLogininforList(SysLogininfor logininfor) { |
| | | Map<String, Object> params = logininfor.getParams(); |
| | | LambdaQueryWrapper<SysLogininfor> lqw = new LambdaQueryWrapper<SysLogininfor>() |
| | | .like(StrUtil.isNotBlank(logininfor.getIpaddr()), SysLogininfor::getIpaddr, logininfor.getIpaddr()) |
| | | .eq(StrUtil.isNotBlank(logininfor.getStatus()), SysLogininfor::getStatus, logininfor.getStatus()) |
| | | .like(StrUtil.isNotBlank(logininfor.getUserName()), SysLogininfor::getUserName, logininfor.getUserName()) |
| | | .like(StringUtils.isNotBlank(logininfor.getIpaddr()), SysLogininfor::getIpaddr, logininfor.getIpaddr()) |
| | | .eq(StringUtils.isNotBlank(logininfor.getStatus()), SysLogininfor::getStatus, logininfor.getStatus()) |
| | | .like(StringUtils.isNotBlank(logininfor.getUserName()), SysLogininfor::getUserName, logininfor.getUserName()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(login_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | |
| | | public List<SysLogininfor> selectLogininforList(SysLogininfor logininfor) { |
| | | Map<String, Object> params = logininfor.getParams(); |
| | | return list(new LambdaQueryWrapper<SysLogininfor>() |
| | | .like(StrUtil.isNotBlank(logininfor.getIpaddr()),SysLogininfor::getIpaddr,logininfor.getIpaddr()) |
| | | .eq(StrUtil.isNotBlank(logininfor.getStatus()),SysLogininfor::getStatus,logininfor.getStatus()) |
| | | .like(StrUtil.isNotBlank(logininfor.getUserName()),SysLogininfor::getUserName,logininfor.getUserName()) |
| | | .like(StringUtils.isNotBlank(logininfor.getIpaddr()),SysLogininfor::getIpaddr,logininfor.getIpaddr()) |
| | | .eq(StringUtils.isNotBlank(logininfor.getStatus()),SysLogininfor::getStatus,logininfor.getStatus()) |
| | | .like(StringUtils.isNotBlank(logininfor.getUserName()),SysLogininfor::getUserName,logininfor.getUserName()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(login_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | |
| | | import com.ruoyi.system.mapper.SysRoleMapper; |
| | | import com.ruoyi.system.mapper.SysRoleMenuMapper; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | // 管çåæ¾ç¤ºææèåä¿¡æ¯ |
| | | if (SysUser.isAdmin(userId)) { |
| | | menuList = list(new LambdaQueryWrapper<SysMenu>() |
| | | .like(StrUtil.isNotBlank(menu.getMenuName()),SysMenu::getMenuName,menu.getMenuName()) |
| | | .eq(StrUtil.isNotBlank(menu.getVisible()),SysMenu::getVisible,menu.getVisible()) |
| | | .eq(StrUtil.isNotBlank(menu.getStatus()),SysMenu::getStatus,menu.getStatus()) |
| | | .like(StringUtils.isNotBlank(menu.getMenuName()),SysMenu::getMenuName,menu.getMenuName()) |
| | | .eq(StringUtils.isNotBlank(menu.getVisible()),SysMenu::getVisible,menu.getVisible()) |
| | | .eq(StringUtils.isNotBlank(menu.getStatus()),SysMenu::getStatus,menu.getStatus()) |
| | | .orderByAsc(SysMenu::getParentId) |
| | | .orderByAsc(SysMenu::getOrderNum)); |
| | | } else { |
| | |
| | | router.setName(getRouteName(menu)); |
| | | router.setPath(getRouterPath(menu)); |
| | | router.setComponent(getComponent(menu)); |
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StrUtil.equals("1", menu.getIsCache()), menu.getPath())); |
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); |
| | | List<SysMenu> cMenus = menu.getChildren(); |
| | | if (!cMenus.isEmpty() && UserConstants.TYPE_DIR.equals(menu.getMenuType())) { |
| | | router.setAlwaysShow(true); |
| | |
| | | RouterVo children = new RouterVo(); |
| | | children.setPath(menu.getPath()); |
| | | children.setComponent(menu.getComponent()); |
| | | children.setName(StrUtil.upperFirst(menu.getPath())); |
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StrUtil.equals("1", menu.getIsCache()), menu.getPath())); |
| | | children.setName(StringUtils.upperFirst(menu.getPath())); |
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); |
| | | childrenList.add(children); |
| | | router.setChildren(childrenList); |
| | | } else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) { |
| | |
| | | String routerPath = StringUtils.replaceEach(menu.getPath(), new String[] { Constants.HTTP, Constants.HTTPS }, new String[] { "", "" }); |
| | | children.setPath(routerPath); |
| | | children.setComponent(UserConstants.INNER_LINK); |
| | | children.setName(StrUtil.upperFirst(routerPath)); |
| | | children.setName(StringUtils.upperFirst(routerPath)); |
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath())); |
| | | childrenList.add(children); |
| | | router.setChildren(childrenList); |
| | |
| | | * @return è·¯ç±åç§° |
| | | */ |
| | | public String getRouteName(SysMenu menu) { |
| | | String routerName = StrUtil.upperFirst(menu.getPath()); |
| | | String routerName = StringUtils.upperFirst(menu.getPath()); |
| | | // éå¤é¾å¹¶ä¸æ¯ä¸çº§ç®å½ï¼ç±»å为ç®å½ï¼ |
| | | if (isMenuFrame(menu)) { |
| | | routerName = StrUtil.EMPTY; |
| | | routerName = StringUtils.EMPTY; |
| | | } |
| | | return routerName; |
| | | } |
| | |
| | | */ |
| | | public String getComponent(SysMenu menu) { |
| | | String component = UserConstants.LAYOUT; |
| | | if (StrUtil.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) { |
| | | if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) { |
| | | component = menu.getComponent(); |
| | | } else if (StrUtil.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) { |
| | | } else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) { |
| | | component = UserConstants.INNER_LINK; |
| | | } else if (StrUtil.isEmpty(menu.getComponent()) && isParentView(menu)) { |
| | | } else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) { |
| | | component = UserConstants.PARENT_VIEW; |
| | | } |
| | | return component; |
| | |
| | | * @return ç»æ |
| | | */ |
| | | public boolean isInnerLink(SysMenu menu) { |
| | | return menu.getIsFrame().equals(UserConstants.NO_FRAME) && Validator.isUrl(menu.getPath()); |
| | | return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.ishttp(menu.getPath()); |
| | | } |
| | | |
| | | /** |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | |
| | | @Override |
| | | public TableDataInfo<SysNotice> selectPageNoticeList(SysNotice notice) { |
| | | LambdaQueryWrapper<SysNotice> lqw = new LambdaQueryWrapper<SysNotice>() |
| | | .like(StrUtil.isNotBlank(notice.getNoticeTitle()), SysNotice::getNoticeTitle, notice.getNoticeTitle()) |
| | | .eq(StrUtil.isNotBlank(notice.getNoticeType()), SysNotice::getNoticeType, notice.getNoticeType()) |
| | | .like(StrUtil.isNotBlank(notice.getCreateBy()), SysNotice::getCreateBy, notice.getCreateBy()); |
| | | .like(StringUtils.isNotBlank(notice.getNoticeTitle()), SysNotice::getNoticeTitle, notice.getNoticeTitle()) |
| | | .eq(StringUtils.isNotBlank(notice.getNoticeType()), SysNotice::getNoticeType, notice.getNoticeType()) |
| | | .like(StringUtils.isNotBlank(notice.getCreateBy()), SysNotice::getCreateBy, notice.getCreateBy()); |
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage(),lqw)); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public List<SysNotice> selectNoticeList(SysNotice notice) { |
| | | return list(new LambdaQueryWrapper<SysNotice>() |
| | | .like(StrUtil.isNotBlank(notice.getNoticeTitle()),SysNotice::getNoticeTitle,notice.getNoticeTitle()) |
| | | .eq(StrUtil.isNotBlank(notice.getNoticeType()),SysNotice::getNoticeType,notice.getNoticeType()) |
| | | .like(StrUtil.isNotBlank(notice.getCreateBy()),SysNotice::getCreateBy,notice.getCreateBy())); |
| | | .like(StringUtils.isNotBlank(notice.getNoticeTitle()),SysNotice::getNoticeTitle,notice.getNoticeTitle()) |
| | | .eq(StringUtils.isNotBlank(notice.getNoticeType()),SysNotice::getNoticeType,notice.getNoticeType()) |
| | | .like(StringUtils.isNotBlank(notice.getCreateBy()),SysNotice::getCreateBy,notice.getCreateBy())); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | |
| | | public TableDataInfo<SysOperLog> selectPageOperLogList(SysOperLog operLog) { |
| | | Map<String, Object> params = operLog.getParams(); |
| | | LambdaQueryWrapper<SysOperLog> lqw = new LambdaQueryWrapper<SysOperLog>() |
| | | .like(StrUtil.isNotBlank(operLog.getTitle()), SysOperLog::getTitle, operLog.getTitle()) |
| | | .like(StringUtils.isNotBlank(operLog.getTitle()), SysOperLog::getTitle, operLog.getTitle()) |
| | | .eq(operLog.getBusinessType() != null && operLog.getBusinessType() > 0, |
| | | SysOperLog::getBusinessType, operLog.getBusinessType()) |
| | | .func(f -> { |
| | |
| | | }) |
| | | .eq(operLog.getStatus() != null && operLog.getStatus() > 0, |
| | | SysOperLog::getStatus, operLog.getStatus()) |
| | | .like(StrUtil.isNotBlank(operLog.getOperName()), SysOperLog::getOperName, operLog.getOperName()) |
| | | .like(StringUtils.isNotBlank(operLog.getOperName()), SysOperLog::getOperName, operLog.getOperName()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(oper_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | |
| | | public List<SysOperLog> selectOperLogList(SysOperLog operLog) { |
| | | Map<String, Object> params = operLog.getParams(); |
| | | return list(new LambdaQueryWrapper<SysOperLog>() |
| | | .like(StrUtil.isNotBlank(operLog.getTitle()),SysOperLog::getTitle,operLog.getTitle()) |
| | | .like(StringUtils.isNotBlank(operLog.getTitle()),SysOperLog::getTitle,operLog.getTitle()) |
| | | .eq(operLog.getBusinessType() != null && operLog.getBusinessType() > 0, |
| | | SysOperLog::getBusinessType,operLog.getBusinessType()) |
| | | .func(f -> { |
| | |
| | | }) |
| | | .eq(operLog.getStatus() != null && operLog.getStatus() > 0, |
| | | SysOperLog::getStatus,operLog.getStatus()) |
| | | .like(StrUtil.isNotBlank(operLog.getOperName()),SysOperLog::getOperName,operLog.getOperName()) |
| | | .like(StringUtils.isNotBlank(operLog.getOperName()),SysOperLog::getOperName,operLog.getOperName()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(oper_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.SysPost; |
| | | import com.ruoyi.system.domain.SysUserPost; |
| | | import com.ruoyi.system.mapper.SysPostMapper; |
| | |
| | | @Override |
| | | public TableDataInfo<SysPost> selectPagePostList(SysPost post) { |
| | | LambdaQueryWrapper<SysPost> lqw = new LambdaQueryWrapper<SysPost>() |
| | | .like(StrUtil.isNotBlank(post.getPostCode()), SysPost::getPostCode, post.getPostCode()) |
| | | .eq(StrUtil.isNotBlank(post.getStatus()), SysPost::getStatus, post.getStatus()) |
| | | .like(StrUtil.isNotBlank(post.getPostName()), SysPost::getPostName, post.getPostName()); |
| | | .like(StringUtils.isNotBlank(post.getPostCode()), SysPost::getPostCode, post.getPostCode()) |
| | | .eq(StringUtils.isNotBlank(post.getStatus()), SysPost::getStatus, post.getStatus()) |
| | | .like(StringUtils.isNotBlank(post.getPostName()), SysPost::getPostName, post.getPostName()); |
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage(),lqw)); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public List<SysPost> selectPostList(SysPost post) { |
| | | return list(new LambdaQueryWrapper<SysPost>() |
| | | .like(StrUtil.isNotBlank(post.getPostCode()), SysPost::getPostCode, post.getPostCode()) |
| | | .eq(StrUtil.isNotBlank(post.getStatus()), SysPost::getStatus, post.getStatus()) |
| | | .like(StrUtil.isNotBlank(post.getPostName()), SysPost::getPostName, post.getPostName())); |
| | | .like(StringUtils.isNotBlank(post.getPostCode()), SysPost::getPostCode, post.getPostCode()) |
| | | .eq(StringUtils.isNotBlank(post.getStatus()), SysPost::getStatus, post.getStatus()) |
| | | .like(StringUtils.isNotBlank(post.getPostName()), SysPost::getPostName, post.getPostName())); |
| | | } |
| | | |
| | | /** |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.system.domain.SysUserOnline; |
| | | import com.ruoyi.system.service.ISysUserOnlineService; |
| | |
| | | */ |
| | | @Override |
| | | public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user) { |
| | | if (StrUtil.equals(ipaddr, user.getIpaddr())) { |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr())) { |
| | | return loginUserToUserOnline(user); |
| | | } |
| | | return null; |
| | |
| | | */ |
| | | @Override |
| | | public SysUserOnline selectOnlineByUserName(String userName, LoginUser user) { |
| | | if (StrUtil.equals(userName, user.getUsername())) { |
| | | if (StringUtils.equals(userName, user.getUsername())) { |
| | | return loginUserToUserOnline(user); |
| | | } |
| | | return null; |
| | |
| | | */ |
| | | @Override |
| | | public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user) { |
| | | if (StrUtil.equals(ipaddr, user.getIpaddr()) && StrUtil.equals(userName, user.getUsername())) { |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) { |
| | | return loginUserToUserOnline(user); |
| | | } |
| | | return null; |
| | |
| | | var result = patt.exec(contentDisposition) |
| | | var fileName = result[1] |
| | | fileName = fileName.replace(/\"/g, '') |
| | | aLink.style.display = 'none' |
| | | aLink.href = URL.createObjectURL(blob) |
| | | aLink.setAttribute('download', decodeURI(fileName)) // 设置ä¸è½½æä»¶åç§° |
| | | document.body.appendChild(aLink) |
| | | aLink.click() |
| | | URL.revokeObjectURL(aLink.href);//æ¸
é¤å¼ç¨ |
| | | document.body.removeChild(aLink); |
| | | } |