value = new ArrayList<>();
- map.keySet().forEach(key -> {
- name.add(key);
- value.add(map.get(key).toString());
- });
- FormBody formBody = new FormBody(name, value);
- return post(url, formBody);
- }
-
-// /**
-// * @param url 请求地址
-// * @param json 上报内容
-// * @return 返回值
-// */
-// public String okHttpPostMethod(String url, String json) {
-// MediaType JSON = MediaType.parse("application/json; charset=utf-8");
-// OkHttpClient client = new OkHttpClient();
-// RequestBody body = RequestBody.create(JSON, json);
-//
-// Request request = new Request.Builder()
-// .url(url)
-// .build();
-// try (Response response = client.newCall(request).execute()) {
-// return response.body().string();
-// } catch (IOException e) {
-// e.printStackTrace();
-// }
-// return null;
-// }
-//
-// public static String get(String url, JSONObject jsonObject) {
-// MediaType JSON = MediaType.parse("application/json; charset=utf-8");
-// //1 . 拿到OkHttpClient对象
-// OkHttpClient client = new OkHttpClient();
-// //创建一个RequestBody(参数1:数据类型 参数2传递的json串)
-// RequestBody requestBody = RequestBody.create(JSON, String.valueOf(jsonObject));
-// //3 . 构建Request,将FormBody作为Post方法的参数传入
-// Request request = new Request.Builder()
-// .url(url).post(requestBody)
-// .build();
-//
-// try {
-// Response response = client.newCall(request).execute();
-// return response.body().string();
-// } catch (IOException e) {
-// e.printStackTrace();
-// }
-// return "";
-// }
-}
\ No newline at end of file
diff --git a/src/main/java/cn/sric/util/PictureFileUtil.java b/src/main/java/cn/sric/util/PictureFileUtil.java
deleted file mode 100644
index 03b2f20..0000000
--- a/src/main/java/cn/sric/util/PictureFileUtil.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package cn.sric.util;
-
-
-import lombok.extern.slf4j.Slf4j;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Response;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Objects;
-
-/**
- * @author sric
- *
- * 由于某些文件使用RestTemplate会出现异常,所以这里使用了OkHttp
- * 首先导入okhttp的依赖
- *
- *
- * com.squareup.okhttp3
- * okhttp
- * 4.6.0
- *
- * @version V1.0
- * @date 2020/11/18
- * @package cn.sric.util
- * @description
- **/
-@Slf4j
-public class PictureFileUtil {
-
-
- /**
- * 下载网络图片
- *
- * @param url 文件URL
- * @param localUrl 下载到本地的路径 (加文件名
- * @return 返回下载的路径
- */
- public static String download(String url, String localUrl) {
- InputStream inputStream = null;
- FileOutputStream out = null;
- try {
- //将网络URL转换为流
- inputStream = sendGetForFile(url);
- if (inputStream != null) {
- out = new FileOutputStream(localUrl);
- int j;
- while ((j = inputStream.read()) != -1) {
- out.write(j);
- }
- out.flush();
- return localUrl;
- }
- } catch (Exception e) {
- return "";
- } finally {
- try {
- if (inputStream != null) {
- inputStream.close();
- }
- if (out != null) {
- out.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return "";
- }
-
- /**
- * 网络文件 由URL转换为流的形式
- *
- * @param url
- * @return
- */
- public static InputStream sendGetForFile(String url) {
- InputStream inputStream;
- Request req = (new Request.Builder()).url(url).get().build();
- Response response;
- try {
- response = new OkHttpClient().newCall(req).execute();
- if (!response.isSuccessful()) {
- log.error("【调用HTTP请求异常】 code:{},message:{},url:{}", response.code(), response.message(), url);
- return null;
- }
- inputStream = Objects.requireNonNull(response.body()).byteStream();
- return inputStream;
- } catch (IOException e) {
- return null;
- }
- }
-}
diff --git a/src/main/java/cn/sric/util/RedisUtil.java b/src/main/java/cn/sric/util/RedisUtil.java
deleted file mode 100644
index 96fa698..0000000
--- a/src/main/java/cn/sric/util/RedisUtil.java
+++ /dev/null
@@ -1,147 +0,0 @@
-package cn.sric.util;
-
-import org.springframework.data.redis.connection.RedisConnection;
-import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
-import org.springframework.data.redis.core.StringRedisTemplate;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.annotation.Resource;
-import java.util.Calendar;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-/**
- * 使用前加入 redis 依赖
- *
- *
- * org.springframework.boot
- * spring-boot-starter-data-redis
- *
- *
- * @author sric
- */
-@Component(value = "redisUtil")
-public class RedisUtil {
-
- @Resource
- private StringRedisTemplate stringRedisTemplate;
-
- public boolean set(String key, String value) {
- boolean flag = false;
- try {
- stringRedisTemplate.opsForValue().set(key, value);
- flag = true;
- } catch (Exception e) {
- flag = false;
- }
- return flag;
- }
-
-
- public boolean set(String key, String value, long timeout) {
- boolean flag = false;
- try {
- stringRedisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
- flag = true;
- } catch (Exception e) {
- flag = false;
- }
- return flag;
- }
-
-
- public boolean set(String key, String value, long timeout, TimeUnit timeUnit) {
- boolean flag = false;
- try {
- stringRedisTemplate.opsForValue().set(key, value, timeout, timeUnit);
- flag = true;
- } catch (Exception e) {
- flag = false;
- }
- return flag;
- }
-
- public String get(String key) {
- return stringRedisTemplate.opsForValue().get(key);
- }
-
-
- public boolean setNX(String key, String value) {
- RedisConnection redisConnection = stringRedisTemplate.getConnectionFactory().getConnection();
- return redisConnection.setNX(key.getBytes(), new byte[]{1});
- }
-
-
- /**
- * 设置过期时间是凌晨0点0分0秒
- * 如果存在不进行设置
- *
- * @param key
- * @param value
- */
- @Transactional(rollbackFor = Exception.class)
- public boolean putTime(String key, String value) {
- //获取剩余时间
- long seconds = (RedisUtil.getMiol() - System.currentTimeMillis()) / 1000;
-// boolean b = setNX(key, value);
-
-// if (b) {
-// try {
-// if (expire(key, seconds, TimeUnit.SECONDS)) {
-// return true;
-// }
-// } catch (Exception e) {
-// del(key);
-// e.printStackTrace();
-// }
-// }
- return set(key, value, seconds, TimeUnit.SECONDS);
- }
-
-
- public boolean del(String key) {
- return stringRedisTemplate.delete(key);
- }
-
- public boolean expire(String key, long time, TimeUnit timeUnit) {
- return stringRedisTemplate.expire(key, time, timeUnit);
- }
-
- public Set keys(String keyPatterns) {
- return stringRedisTemplate.keys(keyPatterns);
- }
-
-
- public boolean exists(String key) {
- RedisConnection redisConnection = stringRedisTemplate.getConnectionFactory().getConnection();
- return redisConnection.exists(key.getBytes());
- }
-
- public void setDatabase(int index) {
- LettuceConnectionFactory connectionFactory = (LettuceConnectionFactory) stringRedisTemplate.getConnectionFactory();
- connectionFactory.setDatabase(index);
- }
-
-
- public static Long getMiol() {
- Calendar ca = Calendar.getInstance();
- //失效的时间
- ca.set(Calendar.HOUR_OF_DAY, 24);
- ca.set(Calendar.MINUTE, 0);
- ca.set(Calendar.SECOND, 0);
- long fl = ca.getTimeInMillis();
- return fl;
- }
-
- public static void main(String[] args) {
- Calendar ca = Calendar.getInstance();
- //失效的时间
- ca.set(Calendar.HOUR_OF_DAY, 24);
- ca.set(Calendar.MINUTE, 0);
- ca.set(Calendar.SECOND, 0);
- long fl = ca.getTimeInMillis();
- System.out.println(fl / 1000);
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/cn/sric/util/ThreadPoolExecutorUtil.java b/src/main/java/cn/sric/util/ThreadPoolExecutorUtil.java
deleted file mode 100644
index fc1288d..0000000
--- a/src/main/java/cn/sric/util/ThreadPoolExecutorUtil.java
+++ /dev/null
@@ -1,152 +0,0 @@
-package cn.sric.util;
-
-
-import java.util.concurrent.*;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * 创建线程池的帮助类
- * 可以使线程池状态为暂停,继续运行
- *
- * @author sunchuanchuan
- * @version V1.0
- * @date 2020/12/22
- * @package cn.sric.config
- * @description
- **/
-public class ThreadPoolExecutorUtil extends ThreadPoolExecutor {
-
-
- /**
- * @param corePoolSize 核心线程池数量 不会被回收
- * @param maximumPoolSize 最大线程数量 当核心线程到达最大值,并且队列中也到最大值,就会创建新的线程
- * @param keepAliveTime 设置线程最多保持多长时间默认 0 超过这个时间会回收不是核心的线程 也就是 maximumPoolSize - corePoolSize
- * @param unit keepAliveTime 时间类型
- * @param workQueue 创建队列的方式 (当新的任务来临后并且核心线程满了之后会创建队列来进行排队等待
- * @param handler 拒绝策略 当队列达到最大值并且 最大线程池( maximumPoolSize)也是最大值,这时新来的任务没有地方储存,则会使用拒绝策略
- */
- public ThreadPoolExecutorUtil(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue, RejectedExecutionHandler handler) {
- super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
- }
-
-
- /**
- * @param threadFactory 创建线程的方式
- * 这个构造方法对比上面的多了一个 threadFactory 参数
- * 表示线程的创建工厂,此参数一般用的比较少,我们通常在创建线程池时不指定此参数,它会使用默认的线程创建工厂的方法来创建线程,
- *
- * 其余参数看上面的构造方法注释
- */
-
- public ThreadPoolExecutorUtil(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue,
- ThreadFactory threadFactory, RejectedExecutionHandler handler) {
- super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
- }
-
-
- boolean isPause = false;
- ReentrantLock lock = new ReentrantLock();
- Condition condition = lock.newCondition();
-
-
- @Override
- protected void beforeExecute(Thread t, Runnable r) {
- super.beforeExecute(t, r);
- lock.lock();
- try {
- while (isPause) {
- long ms = 10L;
- System.out.printf("pausing, %s\n", t.getName());
- Thread.sleep(ms);
- condition.await();
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- } finally {
- lock.unlock();
- }
- }
-
- @Override
- protected void afterExecute(Runnable r, Throwable t) {
- super.afterExecute(r, t);
- }
-
- /**
- * 暂停
- */
- public void pause() {
- lock.lock();
- try {
- System.out.println("exe pause");
- isPause = true;
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- lock.unlock();
- }
- }
-
- /**
- * 继续执行
- */
- public void resume() {
- lock.lock();
- try {
- System.out.println("un pause");
- isPause = false;
- condition.signalAll();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- lock.unlock();
- }
- }
-
- public static void main(String[] args) throws InterruptedException {
- /**
- * new LinkedBlockingQueue<>(100) 队列 括号填写参数为队列的最大值,不填写参数为无界队列
- * new ThreadPoolExecutor.CallerRunsPolicy() 拒绝策略,如果添加到线程池失败,那么主线程会自己去执行该任务,不会等待线程池中的线程去执行。
- */
- ThreadPoolExecutorUtil threadPoolExecutorUtil = new ThreadPoolExecutorUtil(5, 10,
- 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(100), new ThreadPoolExecutor.CallerRunsPolicy());
-
- for (int i = 1; i <= 150; i++) {
-
- System.out.println("i:" + i + "---->>>当前活动的线程数量:" + threadPoolExecutorUtil.getActiveCount() + "队列中的数量为:" + threadPoolExecutorUtil.getQueue().size() +
- "-----》》》》最大线程数" + threadPoolExecutorUtil.getPoolSize());
-
- int finalI = i;
- threadPoolExecutorUtil.execute(() -> {
- try {
- System.err.println(Thread.currentThread().getName() + "---->>>i:" + finalI);
- TimeUnit.SECONDS.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- });
-
-
- if (i == 100) {
- System.out.println("100当前活动的线程数量:" + threadPoolExecutorUtil.getActiveCount() + "队列中的数量为:" + threadPoolExecutorUtil.getQueue().size() +
- "最大线程数" + threadPoolExecutorUtil.getPoolSize());
- } else if (i == 110) {
- System.out.println("110当前活动的线程数量:" + threadPoolExecutorUtil.getActiveCount() + "队列中的数量为:" + threadPoolExecutorUtil.getQueue().size() +
- "最大线程数" + threadPoolExecutorUtil.getPoolSize());
- } else if (i == 120) {
- System.out.println("120当前活动的线程数量:" + threadPoolExecutorUtil.getActiveCount() + "队列中的数量为:" + threadPoolExecutorUtil.getQueue().size() +
- "最大线程数" + threadPoolExecutorUtil.getPoolSize());
- } else if (i == 130) {
- System.out.println("120当前活动的线程数量:" + threadPoolExecutorUtil.getActiveCount() + "队列中的数量为:" + threadPoolExecutorUtil.getQueue().size() +
- "最大线程数" + threadPoolExecutorUtil.getPoolSize());
- } else if (i == 150) {
- System.out.println("150当前活动的线程数量:" + threadPoolExecutorUtil.getActiveCount() + "队列中的数量为:" + threadPoolExecutorUtil.getQueue().size() +
- "最大线程数" + threadPoolExecutorUtil.getPoolSize());
- }
- }
- TimeUnit.SECONDS.sleep(5);
- System.out.println("当前活动的线程数量:" + threadPoolExecutorUtil.getActiveCount() + "队列中的数量为:" + threadPoolExecutorUtil.getQueue().size() +
- "最大线程数" + threadPoolExecutorUtil.getPoolSize());
- }
-}
diff --git a/src/main/java/cn/sric/util/TimeCountUtil.java b/src/main/java/cn/sric/util/TimeCountUtil.java
deleted file mode 100644
index ef4765d..0000000
--- a/src/main/java/cn/sric/util/TimeCountUtil.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package cn.sric.util;
-
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-public class TimeCountUtil {
- public static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss";
-
-
- private static final long ONE_MINUTE = 60000L;
- private static final long ONE_HOUR = 3600000L;
- private static final long ONE_DAY = 86400000L;
- private static final long ONE_WEEK = 604800000L;
-
- private static final String ONE_SECOND_AGO = "秒前";
- private static final String ONE_MINUTE_AGO = "分钟前";
- private static final String ONE_HOUR_AGO = "小时前";
- private static final String ONE_DAY_AGO = "天前";
- private static final String ONE_MONTH_AGO = "月前";
- private static final String ONE_YEAR_AGO = "年前";
-
- // 实际调用方法
- public static String timeCount(Date dateTime) {
- return format(dateTime);
- }
-
- // 实际调用方法
- public static String timeCount(String dateTime) {
- SimpleDateFormat format = new SimpleDateFormat(DEFAULT_PATTERN);
- try {
- return format(format.parse(dateTime));
- } catch (ParseException e) {
- return null;
- }
- }
-
- // 时间转换
- public static String format(Date date) {
- Date currDate = new Date();
- long delta = currDate.getTime() - date.getTime();
- if (delta < 1L * ONE_MINUTE) {
- long seconds = toSeconds(delta);
- return (seconds <= 0 ? 1 : seconds) + ONE_SECOND_AGO;
- }
- if (delta < 45L * ONE_MINUTE) {
- long minutes = toMinutes(delta);
- return (minutes <= 0 ? 1 : minutes) + ONE_MINUTE_AGO;
- }
-
- if (delta < 24L * ONE_HOUR) {
- long hours = toHours(delta);
- return (hours <= 0 ? 1 : hours) + ONE_HOUR_AGO;
- }
-// String currDateStr = DateUtil.parseDateToStr(currDate, DateUtil.DATE_TIME_FORMAT_YYYY年MM月DD日);
-// delta = DateUtil.parseStrToDate(currDateStr,DateUtil.DATE_TIME_FORMAT_YYYY年MM月DD日).getTime() - date.getTime();
-// if (delta < 24L * ONE_HOUR) {
-// return "昨天";
-// }
- if (delta < 30L * ONE_DAY) {
- long days = toDays(delta);
- return (days <= 0 ? 1 : days) + ONE_DAY_AGO;
- }
- if (delta < 12L * 4L * ONE_WEEK) {
- long months = toMonths(delta);
- return (months <= 0 ? 1 : months) + ONE_MONTH_AGO;
- } else {
- long years = toYears(delta);
- return (years <= 0 ? 1 : years) + ONE_YEAR_AGO;
- }
- }
-
- private static long toSeconds(long date) {
- return date / 1000L;
- }
-
- private static long toMinutes(long date) {
- return toSeconds(date) / 60L;
- }
-
- private static long toHours(long date) {
- return toMinutes(date) / 60L;
- }
-
- private static long toDays(long date) {
- return toHours(date) / 24L;
- }
-
- private static long toMonths(long date) {
- return toDays(date) / 30L;
- }
-
- private static long toYears(long date) {
- return toMonths(date) / 365L;
- }
-
-
- public static void main(String[] args) {
- System.out.println(timeCount(new Date()));
- }
-}