From c4483ebb11dd1c1baed961530424d5360141d599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Thu, 28 Mar 2024 14:17:04 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20Improving=20structure=20/=20format=20of?= =?UTF-8?q?=20the=20code.=20=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pig/common/core/util/RedisUtils.java | 1166 ++++++++--------- .../feign/PigFeignAutoConfiguration.java | 52 +- .../core/PigFeignRequestCloseInterceptor.java | 18 +- .../resolver/SqlFilterArgumentResolver.java | 91 +- .../gateway/config/GatewayConfiguration.java | 102 +- .../service/impl/SysUserServiceImpl.java | 2 +- .../quartz/controller/SysJobController.java | 81 +- 7 files changed, 728 insertions(+), 784 deletions(-) diff --git a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/RedisUtils.java b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/RedisUtils.java index 3a96c712..62856f15 100644 --- a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/RedisUtils.java +++ b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/RedisUtils.java @@ -20,661 +20,619 @@ import java.util.concurrent.TimeUnit; @UtilityClass public class RedisUtils { - private static final Long SUCCESS = 1L; + private static final Long SUCCESS = 1L; - /** - * 指定缓存失效时间 - * - * @param key 键 - * @param time 时间(秒) - */ - public boolean expire(String key, long time) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - Optional.ofNullable(redisTemplate) - .filter(template -> time > 0) - .ifPresent(template -> template.expire(key, time, TimeUnit.SECONDS)); - return true; - } + /** + * 指定缓存失效时间 + * @param key 键 + * @param time 时间(秒) + */ + public boolean expire(String key, long time) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + Optional.ofNullable(redisTemplate) + .filter(template -> time > 0) + .ifPresent(template -> template.expire(key, time, TimeUnit.SECONDS)); + return true; + } - /** - * 根据 key 获取过期时间 - * - * @param key 键 不能为null - * @return 时间(秒) 返回0代表为永久有效 - */ - public long getExpire(Object key) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return Optional.ofNullable(redisTemplate) - .map(template -> template.getExpire(key, TimeUnit.SECONDS)) - .orElse(-1L); - } + /** + * 根据 key 获取过期时间 + * @param key 键 不能为null + * @return 时间(秒) 返回0代表为永久有效 + */ + public long getExpire(Object key) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return Optional.ofNullable(redisTemplate) + .map(template -> template.getExpire(key, TimeUnit.SECONDS)) + .orElse(-1L); + } - /** - * 查找匹配key - * - * @param pattern key - * @return / - */ - public List scan(String pattern) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - ScanOptions options = ScanOptions.scanOptions().match(pattern).build(); - return Optional.ofNullable(redisTemplate).map(template -> { - RedisConnectionFactory factory = template.getConnectionFactory(); - RedisConnection rc = Objects.requireNonNull(factory).getConnection(); - Cursor cursor = rc.scan(options); - List result = new ArrayList<>(); - while (cursor.hasNext()) { - result.add(new String(cursor.next())); - } - RedisConnectionUtils.releaseConnection(rc, factory); - return result; - }).orElse(Collections.emptyList()); - } + /** + * 查找匹配key + * @param pattern key + * @return / + */ + public List scan(String pattern) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + ScanOptions options = ScanOptions.scanOptions().match(pattern).build(); + return Optional.ofNullable(redisTemplate).map(template -> { + RedisConnectionFactory factory = template.getConnectionFactory(); + RedisConnection rc = Objects.requireNonNull(factory).getConnection(); + Cursor cursor = rc.scan(options); + List result = new ArrayList<>(); + while (cursor.hasNext()) { + result.add(new String(cursor.next())); + } + RedisConnectionUtils.releaseConnection(rc, factory); + return result; + }).orElse(Collections.emptyList()); + } - /** - * 分页查询 key - * - * @param patternKey key - * @param page 页码 - * @param size 每页数目 - * @return / - */ - public List findKeysForPage(String patternKey, int page, int size) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - ScanOptions options = ScanOptions.scanOptions().match(patternKey).build(); - RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); - RedisConnection rc = Objects.requireNonNull(factory).getConnection(); - Cursor cursor = rc.scan(options); - List result = new ArrayList<>(size); - int tmpIndex = 0; - int fromIndex = page * size; - int toIndex = page * size + size; - while (cursor.hasNext()) { - if (tmpIndex >= fromIndex && tmpIndex < toIndex) { - result.add(new String(cursor.next())); - tmpIndex++; - continue; - } - // 获取到满足条件的数据后,就可以退出了 - if (tmpIndex >= toIndex) { - break; - } - tmpIndex++; - cursor.next(); - } - RedisConnectionUtils.releaseConnection(rc, factory); - return result; - } + /** + * 分页查询 key + * @param patternKey key + * @param page 页码 + * @param size 每页数目 + * @return / + */ + public List findKeysForPage(String patternKey, int page, int size) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + ScanOptions options = ScanOptions.scanOptions().match(patternKey).build(); + RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); + RedisConnection rc = Objects.requireNonNull(factory).getConnection(); + Cursor cursor = rc.scan(options); + List result = new ArrayList<>(size); + int tmpIndex = 0; + int fromIndex = page * size; + int toIndex = page * size + size; + while (cursor.hasNext()) { + if (tmpIndex >= fromIndex && tmpIndex < toIndex) { + result.add(new String(cursor.next())); + tmpIndex++; + continue; + } + // 获取到满足条件的数据后,就可以退出了 + if (tmpIndex >= toIndex) { + break; + } + tmpIndex++; + cursor.next(); + } + RedisConnectionUtils.releaseConnection(rc, factory); + return result; + } - /** - * 判断key是否存在 - * - * @param key 键 - * @return true 存在 false不存在 - */ - public boolean hasKey(String key) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return Optional.ofNullable(redisTemplate).map(template -> template.hasKey(key)).orElse(false); - } + /** + * 判断key是否存在 + * @param key 键 + * @return true 存在 false不存在 + */ + public boolean hasKey(String key) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return Optional.ofNullable(redisTemplate).map(template -> template.hasKey(key)).orElse(false); + } - /** - * 删除缓存 - * - * @param keys 可以传一个值 或多个 - */ - public void del(String... keys) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - if (keys != null) { - Arrays.stream(keys).forEach(redisTemplate::delete); - } - } + /** + * 删除缓存 + * @param keys 可以传一个值 或多个 + */ + public void del(String... keys) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + if (keys != null) { + Arrays.stream(keys).forEach(redisTemplate::delete); + } + } - /** - * 获取锁 - * - * @param lockKey 锁key - * @param value value - * @param expireTime:单位-秒 - * @return boolean - */ - public boolean getLock(String lockKey, String value, int expireTime) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return Optional.ofNullable(redisTemplate) - .map(template -> template.opsForValue().setIfAbsent(lockKey, value, expireTime, TimeUnit.SECONDS)) - .orElse(false); - } + /** + * 获取锁 + * @param lockKey 锁key + * @param value value + * @param expireTime:单位-秒 + * @return boolean + */ + public boolean getLock(String lockKey, String value, int expireTime) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return Optional.ofNullable(redisTemplate) + .map(template -> template.opsForValue().setIfAbsent(lockKey, value, expireTime, TimeUnit.SECONDS)) + .orElse(false); + } - /** - * 释放锁 - * - * @param lockKey 锁key - * @param value value - * @return boolean - */ - public boolean releaseLock(String lockKey, String value) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"; - RedisScript redisScript = new DefaultRedisScript<>(script, Long.class); - return Optional.ofNullable(redisTemplate.execute(redisScript, Collections.singletonList(lockKey), value)) - .map(Convert::toLong) - .filter(SUCCESS::equals) - .isPresent(); - } + /** + * 释放锁 + * @param lockKey 锁key + * @param value value + * @return boolean + */ + public boolean releaseLock(String lockKey, String value) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"; + RedisScript redisScript = new DefaultRedisScript<>(script, Long.class); + return Optional.ofNullable(redisTemplate.execute(redisScript, Collections.singletonList(lockKey), value)) + .map(Convert::toLong) + .filter(SUCCESS::equals) + .isPresent(); + } - // ============================String============================= + // ============================String============================= - /** - * 普通缓存获取 - * - * @param key 键 - * @return 值 - */ - public T get(String key) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForValue().get(key); - } + /** + * 普通缓存获取 + * @param key 键 + * @return 值 + */ + public T get(String key) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForValue().get(key); + } - /** - * 批量获取 - * - * @param keys - * @return - */ - public List multiGet(List keys) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForValue().multiGet(keys); - } + /** + * 批量获取 + * @param keys + * @return + */ + public List multiGet(List keys) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForValue().multiGet(keys); + } - /** - * 普通缓存放入 - * - * @param key 键 - * @param value 值 - * @return true成功 false失败 - */ - public boolean set(String key, Object value) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - Optional.ofNullable(redisTemplate).map(template -> { - template.opsForValue().set(key, value); - return true; - }); - return true; - } + /** + * 普通缓存放入 + * @param key 键 + * @param value 值 + * @return true成功 false失败 + */ + public boolean set(String key, Object value) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + Optional.ofNullable(redisTemplate).map(template -> { + template.opsForValue().set(key, value); + return true; + }); + return true; + } - /** - * 普通缓存放入并设置时间 - * - * @param key 键 - * @param value 值 - * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 - * @return true成功 false 失败 - */ - public boolean set(String key, Object value, long time) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return Optional.ofNullable(redisTemplate).map(template -> { - if (time > 0) { - template.opsForValue().set(key, value, time, TimeUnit.SECONDS); - } else { - template.opsForValue().set(key, value); - } - return true; - }).orElse(false); - } + /** + * 普通缓存放入并设置时间 + * @param key 键 + * @param value 值 + * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 + * @return true成功 false 失败 + */ + public boolean set(String key, Object value, long time) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return Optional.ofNullable(redisTemplate).map(template -> { + if (time > 0) { + template.opsForValue().set(key, value, time, TimeUnit.SECONDS); + } + else { + template.opsForValue().set(key, value); + } + return true; + }).orElse(false); + } - /** - * 普通缓存放入并设置时间 - * - * @param key 键 - * @param value 值 - * @param time 时间 - * @param timeUnit 类型 - * @return true成功 false 失败 - */ - public boolean set(String key, T value, long time, TimeUnit timeUnit) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - Optional.ofNullable(redisTemplate).map(template -> { - if (time > 0) { - template.opsForValue().set(key, value, time, timeUnit); - } else { - template.opsForValue().set(key, value); - } - return true; - }); - return true; - } + /** + * 普通缓存放入并设置时间 + * @param key 键 + * @param value 值 + * @param time 时间 + * @param timeUnit 类型 + * @return true成功 false 失败 + */ + public boolean set(String key, T value, long time, TimeUnit timeUnit) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + Optional.ofNullable(redisTemplate).map(template -> { + if (time > 0) { + template.opsForValue().set(key, value, time, timeUnit); + } + else { + template.opsForValue().set(key, value); + } + return true; + }); + return true; + } - // ================================Map================================= + // ================================Map================================= - /** - * HashGet - * - * @param key 键 不能为null - * @param hashKey 项 不能为null - * @return 值 - */ - public HV hget(String key, HK hashKey) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForHash().get(key, hashKey); - } + /** + * HashGet + * @param key 键 不能为null + * @param hashKey 项 不能为null + * @return 值 + */ + public HV hget(String key, HK hashKey) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForHash().get(key, hashKey); + } - /** - * 获取hashKey对应的所有键值 - * - * @param key 键 - * @return 对应的多个键值 - */ - public Map hmget(String key) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForHash().entries(key); - } + /** + * 获取hashKey对应的所有键值 + * @param key 键 + * @return 对应的多个键值 + */ + public Map hmget(String key) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForHash().entries(key); + } - /** - * HashSet - * - * @param key 键 - * @param map 对应多个键值 - * @return true 成功 false 失败 - */ - public boolean hmset(String key, Map map) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - Optional.ofNullable(redisTemplate).map(template -> { - template.opsForHash().putAll(key, map); - return true; - }); - return true; - } + /** + * HashSet + * @param key 键 + * @param map 对应多个键值 + * @return true 成功 false 失败 + */ + public boolean hmset(String key, Map map) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + Optional.ofNullable(redisTemplate).map(template -> { + template.opsForHash().putAll(key, map); + return true; + }); + return true; + } - /** - * HashSet 并设置时间 - * - * @param key 键 - * @param map 对应多个键值 - * @param time 时间(秒) - * @return true成功 false失败 - */ - public boolean hmset(String key, Map map, long time) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - Optional.ofNullable(redisTemplate).map(template -> { - template.opsForHash().putAll(key, map); - if (time > 0) { - template.expire(key, time, TimeUnit.SECONDS); - } - return true; - }); - return true; - } + /** + * HashSet 并设置时间 + * @param key 键 + * @param map 对应多个键值 + * @param time 时间(秒) + * @return true成功 false失败 + */ + public boolean hmset(String key, Map map, long time) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + Optional.ofNullable(redisTemplate).map(template -> { + template.opsForHash().putAll(key, map); + if (time > 0) { + template.expire(key, time, TimeUnit.SECONDS); + } + return true; + }); + return true; + } - /** - * 向一张hash表中放入数据,如果不存在将创建 - * - * @param key 键 - * @param item 项 - * @param value 值 - * @return true 成功 false失败 - */ - public boolean hset(String key, String item, Object value) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return Optional.ofNullable(redisTemplate).map(template -> { - template.opsForHash().put(key, item, value); - return true; - }).orElse(false); - } + /** + * 向一张hash表中放入数据,如果不存在将创建 + * @param key 键 + * @param item 项 + * @param value 值 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return Optional.ofNullable(redisTemplate).map(template -> { + template.opsForHash().put(key, item, value); + return true; + }).orElse(false); + } - /** - * 向一张hash表中放入数据,如果不存在将创建 - * - * @param key 键 - * @param item 项 - * @param value 值 - * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 - * @return true 成功 false失败 - */ - public boolean hset(String key, String item, Object value, long time) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return Optional.ofNullable(redisTemplate).map(template -> { - template.opsForHash().put(key, item, value); - if (time > 0) { - template.expire(key, time, TimeUnit.SECONDS); - } - return true; - }).orElse(false); - } + /** + * 向一张hash表中放入数据,如果不存在将创建 + * @param key 键 + * @param item 项 + * @param value 值 + * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value, long time) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return Optional.ofNullable(redisTemplate).map(template -> { + template.opsForHash().put(key, item, value); + if (time > 0) { + template.expire(key, time, TimeUnit.SECONDS); + } + return true; + }).orElse(false); + } - /** - * 删除hash表中的值 - * - * @param key 键 不能为null - * @param item 项 可以使多个 不能为null - */ - public void hdel(String key, Object... item) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - redisTemplate.opsForHash().delete(key, item); - } + /** + * 删除hash表中的值 + * @param key 键 不能为null + * @param item 项 可以使多个 不能为null + */ + public void hdel(String key, Object... item) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + redisTemplate.opsForHash().delete(key, item); + } - /** - * 判断hash表中是否有该项的值 - * - * @param key 键 不能为null - * @param item 项 不能为null - * @return true 存在 false不存在 - */ - public boolean hHasKey(String key, String item) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForHash().hasKey(key, item); - } + /** + * 判断hash表中是否有该项的值 + * @param key 键 不能为null + * @param item 项 不能为null + * @return true 存在 false不存在 + */ + public boolean hHasKey(String key, String item) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForHash().hasKey(key, item); + } - /** - * hash递增 如果不存在,就会创建一个 并把新增后的值返回 - * - * @param key 键 - * @param item 项 - * @param by 要增加几(大于0) - * @return - */ - public double hincr(String key, String item, double by) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForHash().increment(key, item, by); - } + /** + * hash递增 如果不存在,就会创建一个 并把新增后的值返回 + * @param key 键 + * @param item 项 + * @param by 要增加几(大于0) + * @return + */ + public double hincr(String key, String item, double by) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForHash().increment(key, item, by); + } - /** - * hash递减 - * - * @param key 键 - * @param item 项 - * @param by 要减少记(小于0) - * @return - */ - public double hdecr(String key, String item, double by) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForHash().increment(key, item, -by); - } + /** + * hash递减 + * @param key 键 + * @param item 项 + * @param by 要减少记(小于0) + * @return + */ + public double hdecr(String key, String item, double by) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForHash().increment(key, item, -by); + } - // ============================set============================= + // ============================set============================= - /** - * 根据key获取Set中的所有值 - * - * @param key 键 - * @return - */ - public Set sGet(String key) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForSet().members(key); - } + /** + * 根据key获取Set中的所有值 + * @param key 键 + * @return + */ + public Set sGet(String key) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForSet().members(key); + } - /** - * 根据value从一个set中查询,是否存在 - * - * @param key 键 - * @param value 值 - * @return true 存在 false不存在 - */ - public boolean sHasKey(String key, Object value) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForSet().isMember(key, value); - } + /** + * 根据value从一个set中查询,是否存在 + * @param key 键 + * @param value 值 + * @return true 存在 false不存在 + */ + public boolean sHasKey(String key, Object value) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForSet().isMember(key, value); + } - /** - * 将数据放入set缓存 - * - * @param key 键 - * @param values 值 可以是多个 - * @return 成功个数 - */ - public long sSet(String key, Object... values) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForSet().add(key, values); - } + /** + * 将数据放入set缓存 + * @param key 键 + * @param values 值 可以是多个 + * @return 成功个数 + */ + public long sSet(String key, Object... values) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForSet().add(key, values); + } - /** - * 将set数据放入缓存 - * - * @param key 键 - * @param time 时间(秒) - * @param values 值 可以是多个 - * @return 成功个数 - */ - public long sSetAndTime(String key, long time, Object... values) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - Long count = redisTemplate.opsForSet().add(key, values); - if (time > 0) { - expire(key, time); - } - return count; - } + /** + * 将set数据放入缓存 + * @param key 键 + * @param time 时间(秒) + * @param values 值 可以是多个 + * @return 成功个数 + */ + public long sSetAndTime(String key, long time, Object... values) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + Long count = redisTemplate.opsForSet().add(key, values); + if (time > 0) { + expire(key, time); + } + return count; + } - /** - * 获取set缓存的长度 - * - * @param key 键 - * @return - */ - public long sGetSetSize(String key) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForSet().size(key); - } + /** + * 获取set缓存的长度 + * @param key 键 + * @return + */ + public long sGetSetSize(String key) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForSet().size(key); + } - /** - * 移除值为value的 - * - * @param key 键 - * @param values 值 可以是多个 - * @return 移除的个数 - */ - public long setRemove(String key, Object... values) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - Long count = redisTemplate.opsForSet().remove(key, values); - return count; - } + /** + * 移除值为value的 + * @param key 键 + * @param values 值 可以是多个 + * @return 移除的个数 + */ + public long setRemove(String key, Object... values) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + Long count = redisTemplate.opsForSet().remove(key, values); + return count; + } - /** - * 获集合key1和集合key2的差集元素 - * - * @param key 键 - * @return - */ - public Set sDifference(String key, String otherKey) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForSet().difference(key, otherKey); - } + /** + * 获集合key1和集合key2的差集元素 + * @param key 键 + * @return + */ + public Set sDifference(String key, String otherKey) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForSet().difference(key, otherKey); + } - // ===============================list================================= + // ===============================list================================= - /** - * 获取list缓存的内容 - * - * @param key 键 - * @param start 开始 - * @param end 结束 0 到 -1代表所有值 - * @return - */ - public List lGet(String key, long start, long end) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForList().range(key, start, end); - } + /** + * 获取list缓存的内容 + * @param key 键 + * @param start 开始 + * @param end 结束 0 到 -1代表所有值 + * @return + */ + public List lGet(String key, long start, long end) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForList().range(key, start, end); + } - /** - * 获取list缓存的长度 - * - * @param key 键 - * @return - */ - public long lGetListSize(String key) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForList().size(key); - } + /** + * 获取list缓存的长度 + * @param key 键 + * @return + */ + public long lGetListSize(String key) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForList().size(key); + } - /** - * 通过索引 获取list中的值 - * - * @param key 键 - * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 - * @return - */ - public Object lGetIndex(String key, long index) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForList().index(key, index); - } + /** + * 通过索引 获取list中的值 + * @param key 键 + * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 + * @return + */ + public Object lGetIndex(String key, long index) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForList().index(key, index); + } - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @return - */ - public boolean lSet(String key, Object value) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - redisTemplate.opsForList().rightPush(key, value); - return true; - } + /** + * 将list放入缓存 + * @param key 键 + * @param value 值 + * @return + */ + public boolean lSet(String key, Object value) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + redisTemplate.opsForList().rightPush(key, value); + return true; + } - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @param time 时间(秒) - * @return - */ - public boolean lSet(String key, Object value, long time) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - redisTemplate.opsForList().rightPush(key, value); - if (time > 0) { - Optional.ofNullable(redisTemplate).ifPresent(template -> template.expire(key, time, TimeUnit.SECONDS)); - } - return true; - } + /** + * 将list放入缓存 + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return + */ + public boolean lSet(String key, Object value, long time) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + redisTemplate.opsForList().rightPush(key, value); + if (time > 0) { + Optional.ofNullable(redisTemplate).ifPresent(template -> template.expire(key, time, TimeUnit.SECONDS)); + } + return true; + } - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @return - */ - public boolean lSet(String key, List value) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - redisTemplate.opsForList().rightPushAll(key, value); - return true; - } + /** + * 将list放入缓存 + * @param key 键 + * @param value 值 + * @return + */ + public boolean lSet(String key, List value) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + redisTemplate.opsForList().rightPushAll(key, value); + return true; + } - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @param time 时间(秒) - * @return - */ - public boolean lSet(String key, List value, long time) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - redisTemplate.opsForList().rightPushAll(key, value); - if (time > 0) { - expire(key, time); - } - return true; - } + /** + * 将list放入缓存 + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return + */ + public boolean lSet(String key, List value, long time) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + redisTemplate.opsForList().rightPushAll(key, value); + if (time > 0) { + expire(key, time); + } + return true; + } - /** - * 根据索引修改list中的某条数据 - * - * @param key 键 - * @param index 索引 - * @param value 值 - * @return / - */ - public boolean lUpdateIndex(String key, long index, Object value) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - redisTemplate.opsForList().set(key, index, value); - return true; - } + /** + * 根据索引修改list中的某条数据 + * @param key 键 + * @param index 索引 + * @param value 值 + * @return / + */ + public boolean lUpdateIndex(String key, long index, Object value) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + redisTemplate.opsForList().set(key, index, value); + return true; + } - /** - * 移除N个值为value - * - * @param key 键 - * @param count 移除多少个 - * @param value 值 - * @return 移除的个数 - */ - public long lRemove(String key, long count, Object value) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForList().remove(key, count, value); - } + /** + * 移除N个值为value + * @param key 键 + * @param count 移除多少个 + * @param value 值 + * @return 移除的个数 + */ + public long lRemove(String key, long count, Object value) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForList().remove(key, count, value); + } - /** - * 将zSet数据放入缓存 - * - * @param key - * @param time - * @param tuples - * @return - */ - public long zSetAndTime(String key, long time, Set> tuples) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - Long count = redisTemplate.opsForZSet().add(key, tuples); - if (time > 0) { - expire(key, time); - } - return count; + /** + * 将zSet数据放入缓存 + * @param key + * @param time + * @param tuples + * @return + */ + public long zSetAndTime(String key, long time, Set> tuples) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + Long count = redisTemplate.opsForZSet().add(key, tuples); + if (time > 0) { + expire(key, time); + } + return count; - } + } - /** - * Sorted set:有序集合获取 - * - * @param key - * @param min - * @param max - * @return - */ - public Set zRangeByScore(String key, double min, double max) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - ZSetOperations zset = redisTemplate.opsForZSet(); - return zset.rangeByScore(key, min, max); + /** + * Sorted set:有序集合获取 + * @param key + * @param min + * @param max + * @return + */ + public Set zRangeByScore(String key, double min, double max) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + ZSetOperations zset = redisTemplate.opsForZSet(); + return zset.rangeByScore(key, min, max); - } + } - /** - * Sorted set:有序集合获取 正序 - * - * @param key - * @param start - * @param end - * @return - */ - public Set zRange(String key, long start, long end) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - ZSetOperations zset = redisTemplate.opsForZSet(); - return zset.range(key, start, end); + /** + * Sorted set:有序集合获取 正序 + * @param key + * @param start + * @param end + * @return + */ + public Set zRange(String key, long start, long end) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + ZSetOperations zset = redisTemplate.opsForZSet(); + return zset.range(key, start, end); - } + } - /** - * Sorted set:有序集合获取 倒叙 - * - * @param key - * @param start - * @param end - * @return - */ - public Set zReverseRange(String key, long start, long end) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - ZSetOperations zset = redisTemplate.opsForZSet(); - return zset.reverseRange(key, start, end); + /** + * Sorted set:有序集合获取 倒叙 + * @param key + * @param start + * @param end + * @return + */ + public Set zReverseRange(String key, long start, long end) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + ZSetOperations zset = redisTemplate.opsForZSet(); + return zset.reverseRange(key, start, end); - } + } - /** - * 获取zSet缓存的长度 - * - * @param key 键 - * @return - */ - public long zGetSetSize(String key) { - RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); - return redisTemplate.opsForZSet().size(key); - } + /** + * 获取zSet缓存的长度 + * @param key 键 + * @return + */ + public long zGetSetSize(String key) { + RedisTemplate redisTemplate = SpringContextHolder.getBean(RedisTemplate.class); + return redisTemplate.opsForZSet().size(key); + } } diff --git a/pig-common/pig-common-feign/src/main/java/com/pig4cloud/pig/common/feign/PigFeignAutoConfiguration.java b/pig-common/pig-common-feign/src/main/java/com/pig4cloud/pig/common/feign/PigFeignAutoConfiguration.java index f8f558a3..82d3fa39 100755 --- a/pig-common/pig-common-feign/src/main/java/com/pig4cloud/pig/common/feign/PigFeignAutoConfiguration.java +++ b/pig-common/pig-common-feign/src/main/java/com/pig4cloud/pig/common/feign/PigFeignAutoConfiguration.java @@ -45,33 +45,33 @@ import org.springframework.context.annotation.Scope; @AutoConfigureBefore(SentinelFeignAutoConfiguration.class) public class PigFeignAutoConfiguration { - @Bean - @Scope("prototype") - @ConditionalOnMissingBean - @ConditionalOnProperty(name = "feign.sentinel.enabled") - public Feign.Builder feignSentinelBuilder() { - return PigSentinelFeign.builder(); - } + @Bean + @Scope("prototype") + @ConditionalOnMissingBean + @ConditionalOnProperty(name = "feign.sentinel.enabled") + public Feign.Builder feignSentinelBuilder() { + return PigSentinelFeign.builder(); + } - @Bean - @ConditionalOnMissingBean - public BlockExceptionHandler blockExceptionHandler(ObjectMapper objectMapper) { - return new PigUrlBlockHandler(objectMapper); - } + @Bean + @ConditionalOnMissingBean + public BlockExceptionHandler blockExceptionHandler(ObjectMapper objectMapper) { + return new PigUrlBlockHandler(objectMapper); + } - @Bean - @ConditionalOnMissingBean - public RequestOriginParser requestOriginParser() { - return new PigHeaderRequestOriginParser(); - } + @Bean + @ConditionalOnMissingBean + public RequestOriginParser requestOriginParser() { + return new PigHeaderRequestOriginParser(); + } + + /** + * add http connection close header + * @return + */ + @Bean + public PigFeignRequestCloseInterceptor pigFeignRequestCloseInterceptor() { + return new PigFeignRequestCloseInterceptor(); + } - /** - * add http connection close header - * - * @return - */ - @Bean - public PigFeignRequestCloseInterceptor pigFeignRequestCloseInterceptor() { - return new PigFeignRequestCloseInterceptor(); - } } diff --git a/pig-common/pig-common-feign/src/main/java/com/pig4cloud/pig/common/feign/core/PigFeignRequestCloseInterceptor.java b/pig-common/pig-common-feign/src/main/java/com/pig4cloud/pig/common/feign/core/PigFeignRequestCloseInterceptor.java index 83a8b512..c2851035 100644 --- a/pig-common/pig-common-feign/src/main/java/com/pig4cloud/pig/common/feign/core/PigFeignRequestCloseInterceptor.java +++ b/pig-common/pig-common-feign/src/main/java/com/pig4cloud/pig/common/feign/core/PigFeignRequestCloseInterceptor.java @@ -11,13 +11,13 @@ import org.springframework.http.HttpHeaders; */ public class PigFeignRequestCloseInterceptor implements RequestInterceptor { - /** - * set connection close - * - * @param template - */ - @Override - public void apply(feign.RequestTemplate template) { - template.header(HttpHeaders.CONNECTION, "close"); - } + /** + * set connection close + * @param template + */ + @Override + public void apply(feign.RequestTemplate template) { + template.header(HttpHeaders.CONNECTION, "close"); + } + } diff --git a/pig-common/pig-common-mybatis/src/main/java/com/pig4cloud/pig/common/mybatis/resolver/SqlFilterArgumentResolver.java b/pig-common/pig-common-mybatis/src/main/java/com/pig4cloud/pig/common/mybatis/resolver/SqlFilterArgumentResolver.java index fe0953a9..90e34f33 100644 --- a/pig-common/pig-common-mybatis/src/main/java/com/pig4cloud/pig/common/mybatis/resolver/SqlFilterArgumentResolver.java +++ b/pig-common/pig-common-mybatis/src/main/java/com/pig4cloud/pig/common/mybatis/resolver/SqlFilterArgumentResolver.java @@ -46,56 +46,59 @@ import java.util.stream.Collectors; @Slf4j public class SqlFilterArgumentResolver implements HandlerMethodArgumentResolver { - /** - * 判断Controller是否包含page 参数 - * - * @param parameter 参数 - * @return 是否过滤 - */ - @Override - public boolean supportsParameter(MethodParameter parameter) { - return parameter.getParameterType().equals(Page.class); - } + /** + * 判断Controller是否包含page 参数 + * @param parameter 参数 + * @return 是否过滤 + */ + @Override + public boolean supportsParameter(MethodParameter parameter) { + return parameter.getParameterType().equals(Page.class); + } - /** - * @param parameter 入参集合 - * @param mavContainer model 和 view - * @param webRequest web相关 - * @param binderFactory 入参解析 - * @return 检查后新的page对象 - *

- * page 只支持查询 GET .如需解析POST获取请求报文体处理 - */ - @Override - public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { + /** + * @param parameter 入参集合 + * @param mavContainer model 和 view + * @param webRequest web相关 + * @param binderFactory 入参解析 + * @return 检查后新的page对象 + *

+ * page 只支持查询 GET .如需解析POST获取请求报文体处理 + */ + @Override + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { - HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); + HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); - String[] ascs = request.getParameterValues("ascs"); - String[] descs = request.getParameterValues("descs"); - String current = request.getParameter("current"); - String size = request.getParameter("size"); + String[] ascs = request.getParameterValues("ascs"); + String[] descs = request.getParameterValues("descs"); + String current = request.getParameter("current"); + String size = request.getParameter("size"); - Page page = new Page<>(); - if (StrUtil.isNotBlank(current)) { - page.setCurrent(Long.parseLong(current)); - } + Page page = new Page<>(); + if (StrUtil.isNotBlank(current)) { + page.setCurrent(Long.parseLong(current)); + } - if (StrUtil.isNotBlank(size)) { - page.setSize(Long.parseLong(size)); - } + if (StrUtil.isNotBlank(size)) { + page.setSize(Long.parseLong(size)); + } - List orderItemList = new ArrayList<>(); - Optional.ofNullable(ascs) - .ifPresent(s -> orderItemList.addAll( - Arrays.stream(s).filter(asc -> !SqlInjectionUtils.check(asc)).map(OrderItem::asc).collect(Collectors.toList()))); - Optional.ofNullable(descs) - .ifPresent(s -> orderItemList.addAll( - Arrays.stream(s).filter(desc -> !SqlInjectionUtils.check(desc)).map(OrderItem::desc).collect(Collectors.toList()))); - page.addOrder(orderItemList); + List orderItemList = new ArrayList<>(); + Optional.ofNullable(ascs) + .ifPresent(s -> orderItemList.addAll(Arrays.stream(s) + .filter(asc -> !SqlInjectionUtils.check(asc)) + .map(OrderItem::asc) + .collect(Collectors.toList()))); + Optional.ofNullable(descs) + .ifPresent(s -> orderItemList.addAll(Arrays.stream(s) + .filter(desc -> !SqlInjectionUtils.check(desc)) + .map(OrderItem::desc) + .collect(Collectors.toList()))); + page.addOrder(orderItemList); - return page; - } + return page; + } } diff --git a/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/config/GatewayConfiguration.java b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/config/GatewayConfiguration.java index 11ad9ee9..42c3b7bf 100644 --- a/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/config/GatewayConfiguration.java +++ b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/config/GatewayConfiguration.java @@ -21,62 +21,58 @@ import org.springframework.data.redis.core.RedisTemplate; @EnableConfigurationProperties(GatewayConfigProperties.class) public class GatewayConfiguration { - /** - * 创建密码解码器过滤器 - * - * @param modifyRequestBodyGatewayFilterFactory 修改请求体网关过滤器工厂 - * @param configProperties 配置属性 - * @return 密码解码器过滤器 - */ - @Bean - public PasswordDecoderFilter passwordDecoderFilter( - ModifyRequestBodyGatewayFilterFactory modifyRequestBodyGatewayFilterFactory, - GatewayConfigProperties configProperties) { - return new PasswordDecoderFilter(modifyRequestBodyGatewayFilterFactory, configProperties); - } + /** + * 创建密码解码器过滤器 + * @param modifyRequestBodyGatewayFilterFactory 修改请求体网关过滤器工厂 + * @param configProperties 配置属性 + * @return 密码解码器过滤器 + */ + @Bean + public PasswordDecoderFilter passwordDecoderFilter( + ModifyRequestBodyGatewayFilterFactory modifyRequestBodyGatewayFilterFactory, + GatewayConfigProperties configProperties) { + return new PasswordDecoderFilter(modifyRequestBodyGatewayFilterFactory, configProperties); + } - /** - * 创建PigRequest全局过滤器 - * - * @return PigRequest全局过滤器 - */ - @Bean - public PigRequestGlobalFilter pigRequestGlobalFilter() { - return new PigRequestGlobalFilter(); - } + /** + * 创建PigRequest全局过滤器 + * @return PigRequest全局过滤器 + */ + @Bean + public PigRequestGlobalFilter pigRequestGlobalFilter() { + return new PigRequestGlobalFilter(); + } - /** - * 创建验证码网关过滤器 - * - * @param configProperties 配置属性 - * @param redisTemplate Redis模板 - * @return 验证码网关过滤器 - */ - @Bean - public ValidateCodeGatewayFilter validateCodeGatewayFilter(GatewayConfigProperties configProperties, RedisTemplate redisTemplate) { - return new ValidateCodeGatewayFilter(configProperties, redisTemplate); - } + /** + * 创建验证码网关过滤器 + * @param configProperties 配置属性 + * @param redisTemplate Redis模板 + * @return 验证码网关过滤器 + */ + @Bean + public ValidateCodeGatewayFilter validateCodeGatewayFilter(GatewayConfigProperties configProperties, + RedisTemplate redisTemplate) { + return new ValidateCodeGatewayFilter(configProperties, redisTemplate); + } - /** - * 创建全局异常处理程序 - * - * @param objectMapper 对象映射器 - * @return 全局异常处理程序 - */ - @Bean - public GlobalExceptionHandler globalExceptionHandler(ObjectMapper objectMapper) { - return new GlobalExceptionHandler(objectMapper); - } + /** + * 创建全局异常处理程序 + * @param objectMapper 对象映射器 + * @return 全局异常处理程序 + */ + @Bean + public GlobalExceptionHandler globalExceptionHandler(ObjectMapper objectMapper) { + return new GlobalExceptionHandler(objectMapper); + } - /** - * 创建图片验证码处理器 - * - * @param redisTemplate Redis模板 - * @return 图片验证码处理器 - */ - @Bean - public ImageCodeHandler imageCodeHandler(RedisTemplate redisTemplate) { - return new ImageCodeHandler(redisTemplate); - } + /** + * 创建图片验证码处理器 + * @param redisTemplate Redis模板 + * @return 图片验证码处理器 + */ + @Bean + public ImageCodeHandler imageCodeHandler(RedisTemplate redisTemplate) { + return new ImageCodeHandler(redisTemplate); + } } diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java index 8590a0ed..42525864 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java @@ -257,7 +257,7 @@ public class SysUserServiceImpl extends ServiceImpl impl // 根据数据权限查询全部的用户信息 List voList = baseMapper.selectVoList(userDTO); // 转换成execl 对象输出 - return voList.stream().map(userVO -> { + return voList.stream().map(userVO -> { UserExcelVO excelVO = new UserExcelVO(); BeanUtils.copyProperties(userVO, excelVO); String roleNameList = userVO.getRoleList() diff --git a/pig-visual/pig-quartz/src/main/java/com/pig4cloud/pig/daemon/quartz/controller/SysJobController.java b/pig-visual/pig-quartz/src/main/java/com/pig4cloud/pig/daemon/quartz/controller/SysJobController.java index f78e1e1f..cdb0bb8d 100644 --- a/pig-visual/pig-quartz/src/main/java/com/pig4cloud/pig/daemon/quartz/controller/SysJobController.java +++ b/pig-visual/pig-quartz/src/main/java/com/pig4cloud/pig/daemon/quartz/controller/SysJobController.java @@ -69,8 +69,7 @@ public class SysJobController { /** * 定时任务分页查询 - * - * @param page 分页对象 + * @param page 分页对象 * @param sysJob 定时任务调度表 * @return R */ @@ -78,17 +77,16 @@ public class SysJobController { @Operation(description = "分页定时业务查询") public R getSysJobPage(Page page, SysJob sysJob) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery() - .like(StrUtil.isNotBlank(sysJob.getJobName()), SysJob::getJobName, sysJob.getJobName()) - .like(StrUtil.isNotBlank(sysJob.getJobGroup()), SysJob::getJobGroup, sysJob.getJobGroup()) - .eq(StrUtil.isNotBlank(sysJob.getJobStatus()), SysJob::getJobStatus, sysJob.getJobGroup()) - .eq(StrUtil.isNotBlank(sysJob.getJobExecuteStatus()), SysJob::getJobExecuteStatus, - sysJob.getJobExecuteStatus()); + .like(StrUtil.isNotBlank(sysJob.getJobName()), SysJob::getJobName, sysJob.getJobName()) + .like(StrUtil.isNotBlank(sysJob.getJobGroup()), SysJob::getJobGroup, sysJob.getJobGroup()) + .eq(StrUtil.isNotBlank(sysJob.getJobStatus()), SysJob::getJobStatus, sysJob.getJobGroup()) + .eq(StrUtil.isNotBlank(sysJob.getJobExecuteStatus()), SysJob::getJobExecuteStatus, + sysJob.getJobExecuteStatus()); return R.ok(sysJobService.page(page, wrapper)); } /** * 通过id查询定时任务 - * * @param id id * @return R */ @@ -100,7 +98,6 @@ public class SysJobController { /** * 新增定时任务,默认新增状态为1已发布 - * * @param sysJob 定时任务调度表 * @return R */ @@ -109,13 +106,8 @@ public class SysJobController { @PreAuthorize("@pms.hasPermission('job_sys_job_add')") @Operation(description = "新增定时任务") public R save(@RequestBody SysJob sysJob) { - long count = sysJobService - .count(Wrappers.query( - SysJob.builder() - .jobName(sysJob.getJobName()) - .jobGroup(sysJob.getJobGroup()) - .build() - )); + long count = sysJobService.count( + Wrappers.query(SysJob.builder().jobName(sysJob.getJobName()).jobGroup(sysJob.getJobGroup()).build())); if (count > 0) { return R.failed("任务重复,请检查此组内是否已包含同名任务"); @@ -127,7 +119,6 @@ public class SysJobController { /** * 修改定时任务 - * * @param sysJob 定时任务调度表 * @return R */ @@ -139,10 +130,11 @@ public class SysJobController { sysJob.setUpdateBy(SecurityUtils.getUser().getUsername()); SysJob querySysJob = this.sysJobService.getById(sysJob.getJobId()); if (PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType().equals(querySysJob.getJobStatus())) { - //如修改暂停的需更新调度器 + // 如修改暂停的需更新调度器 this.taskUtil.addOrUpateJob(sysJob, scheduler); sysJobService.updateById(sysJob); - } else if (PigQuartzEnum.JOB_STATUS_RELEASE.getType().equals(querySysJob.getJobStatus())) { + } + else if (PigQuartzEnum.JOB_STATUS_RELEASE.getType().equals(querySysJob.getJobStatus())) { sysJobService.updateById(sysJob); } return R.ok(); @@ -150,7 +142,6 @@ public class SysJobController { /** * 通过id删除定时任务 - * * @param id id * @return R */ @@ -163,7 +154,8 @@ public class SysJobController { if (PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType().equals(querySysJob.getJobStatus())) { this.taskUtil.removeJob(querySysJob, scheduler); this.sysJobService.removeById(id); - } else if (PigQuartzEnum.JOB_STATUS_RELEASE.getType().equals(querySysJob.getJobStatus())) { + } + else if (PigQuartzEnum.JOB_STATUS_RELEASE.getType().equals(querySysJob.getJobStatus())) { this.sysJobService.removeById(id); } return R.ok(); @@ -171,7 +163,6 @@ public class SysJobController { /** * 暂停全部定时任务 - * * @return R */ @SysLog("暂停全部定时任务") @@ -184,19 +175,19 @@ public class SysJobController { new LambdaQueryWrapper().eq(SysJob::getJobStatus, PigQuartzEnum.JOB_STATUS_RUNNING.getType())); if (count <= 0) { return R.ok("无正在运行定时任务"); - } else { + } + else { // 更新定时任务状态条件,运行状态2更新为暂停状态3 this.sysJobService.update( SysJob.builder().jobStatus(PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType()).build(), - new UpdateWrapper().lambda().eq(SysJob::getJobStatus, - PigQuartzEnum.JOB_STATUS_RUNNING.getType())); + new UpdateWrapper().lambda() + .eq(SysJob::getJobStatus, PigQuartzEnum.JOB_STATUS_RUNNING.getType())); return R.ok("暂停成功"); } } /** * 启动全部定时任务 - * * @return */ @SysLog("启动全部暂停的定时任务") @@ -206,16 +197,14 @@ public class SysJobController { public R startJobs() { // 更新定时任务状态条件,暂停状态3更新为运行状态2 this.sysJobService.update(SysJob.builder().jobStatus(PigQuartzEnum.JOB_STATUS_RUNNING.getType()).build(), - new UpdateWrapper().lambda().eq(SysJob::getJobStatus, - PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType())); + new UpdateWrapper().lambda() + .eq(SysJob::getJobStatus, PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType())); taskUtil.startJobs(scheduler); return R.ok(); } /** - * 刷新全部定时任务 - * 暂停和运行的添加到调度器其他状态从调度器移除 - * + * 刷新全部定时任务 暂停和运行的添加到调度器其他状态从调度器移除 * @return R */ @SysLog("刷新全部定时任务") @@ -227,7 +216,8 @@ public class SysJobController { if (PigQuartzEnum.JOB_STATUS_RUNNING.getType().equals(sysjob.getJobStatus()) || PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType().equals(sysjob.getJobStatus())) { taskUtil.addOrUpateJob(sysjob, scheduler); - } else { + } + else { taskUtil.removeJob(sysjob, scheduler); } }); @@ -236,7 +226,6 @@ public class SysJobController { /** * 启动定时任务 - * * @param jobId 任务id * @return R */ @@ -250,7 +239,7 @@ public class SysJobController { return R.failed("无此定时任务,请确认"); } - //如果定时任务不存在,强制状态为1已发布 + // 如果定时任务不存在,强制状态为1已发布 if (!scheduler.checkExists(TaskUtil.getJobKey(querySysJob))) { querySysJob.setJobStatus(PigQuartzEnum.JOB_STATUS_RELEASE.getType()); log.warn("定时任务不在quartz中,任务id:{},强制状态为已发布并加入调度器", jobId); @@ -258,18 +247,18 @@ public class SysJobController { if (PigQuartzEnum.JOB_STATUS_RELEASE.getType().equals(querySysJob.getJobStatus())) { taskUtil.addOrUpateJob(querySysJob, scheduler); - } else { + } + else { taskUtil.resumeJob(querySysJob, scheduler); } // 更新定时任务状态为运行状态2 - this.sysJobService.updateById( - SysJob.builder().jobId(jobId).jobStatus(PigQuartzEnum.JOB_STATUS_RUNNING.getType()).build()); + this.sysJobService + .updateById(SysJob.builder().jobId(jobId).jobStatus(PigQuartzEnum.JOB_STATUS_RUNNING.getType()).build()); return R.ok(); } /** * 启动定时任务 - * * @param jobId 任务id * @return R */ @@ -280,7 +269,7 @@ public class SysJobController { public R runJob(@PathVariable("id") Long jobId) throws SchedulerException { SysJob querySysJob = this.sysJobService.getById(jobId); - //执行定时任务前判定任务是否在quartz中 + // 执行定时任务前判定任务是否在quartz中 if (!scheduler.checkExists(TaskUtil.getJobKey(querySysJob))) { querySysJob.setJobStatus(PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType()); log.warn("立刻执行定时任务-定时任务不在quartz中,任务id:{},强制状态为暂停并加入调度器", jobId); @@ -292,7 +281,6 @@ public class SysJobController { /** * 暂停定时任务 - * * @return */ @SysLog("暂停定时任务") @@ -302,15 +290,16 @@ public class SysJobController { public R shutdownJob(@PathVariable("id") Long id) { SysJob querySysJob = this.sysJobService.getById(id); // 更新定时任务状态条件,运行状态2更新为暂停状态3 - this.sysJobService.updateById(SysJob.builder().jobId(querySysJob.getJobId()) - .jobStatus(PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType()).build()); + this.sysJobService.updateById(SysJob.builder() + .jobId(querySysJob.getJobId()) + .jobStatus(PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType()) + .build()); taskUtil.pauseJob(querySysJob, scheduler); return R.ok(); } /** * 唯一标识查询定时执行日志 - * * @return */ @GetMapping("/job-log") @@ -321,20 +310,18 @@ public class SysJobController { /** * 检验任务名称和任务组联合是否唯一 - * * @return */ @GetMapping("/is-valid-task-name") @Operation(description = "检验任务名称和任务组联合是否唯一") public R isValidTaskName(@RequestParam String jobName, @RequestParam String jobGroup) { return this.sysJobService - .count(Wrappers.query(SysJob.builder().jobName(jobName).jobGroup(jobGroup).build())) > 0 - ? R.failed("任务重复,请检查此组内是否已包含同名任务") : R.ok(); + .count(Wrappers.query(SysJob.builder().jobName(jobName).jobGroup(jobGroup).build())) > 0 + ? R.failed("任务重复,请检查此组内是否已包含同名任务") : R.ok(); } /** * 导出任务 - * * @param sysJob * @return */