From 15cbce2cc25aebf9d1c561ab0dc8f8f144d8281c Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Wed, 6 Jul 2022 11:55:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/FirePointServiceImpl.java | 3 - .../java/com/xkrs/utils/AddressUtils.java | 195 ------------------ src/main/java/com/xkrs/utils/BeanUtils.java | 73 ------- .../java/com/xkrs/utils/BroadcastUtils.java | 12 -- .../java/com/xkrs/utils/CommonConstant.java | 166 --------------- .../com/xkrs/utils/CopyPropertiesUtil.java | 54 ----- .../java/com/xkrs/utils/DateTimeUtils.java | 1 - .../com/xkrs/utils/EntityManagerUtil.java | 36 ---- src/main/java/com/xkrs/utils/FileFastDfs.java | 39 ++-- .../java/com/xkrs/utils/GaoDeApiUtil.java | 1 + src/main/java/com/xkrs/utils/HashUtil.java | 40 ---- .../java/com/xkrs/utils/HttpClientUtils.java | 47 ++--- src/main/java/com/xkrs/utils/IpUtil.java | 3 +- src/main/java/com/xkrs/utils/JdbcUtils.java | 40 ---- src/main/java/com/xkrs/utils/NumberUtil.java | 21 -- .../com/xkrs/utils/ObjectToBeanUtils.java | 68 +----- src/main/java/com/xkrs/utils/OpenGeoUtil.java | 37 ---- src/main/java/com/xkrs/utils/PhotoUtil.java | 36 ++-- src/main/java/com/xkrs/utils/RandomUtil.java | 54 +---- .../java/com/xkrs/utils/SnowFlakeUtil.java | 124 ----------- 20 files changed, 58 insertions(+), 992 deletions(-) delete mode 100644 src/main/java/com/xkrs/utils/AddressUtils.java delete mode 100644 src/main/java/com/xkrs/utils/BeanUtils.java delete mode 100644 src/main/java/com/xkrs/utils/BroadcastUtils.java delete mode 100644 src/main/java/com/xkrs/utils/CopyPropertiesUtil.java delete mode 100644 src/main/java/com/xkrs/utils/EntityManagerUtil.java delete mode 100644 src/main/java/com/xkrs/utils/HashUtil.java delete mode 100644 src/main/java/com/xkrs/utils/JdbcUtils.java delete mode 100644 src/main/java/com/xkrs/utils/NumberUtil.java delete mode 100644 src/main/java/com/xkrs/utils/OpenGeoUtil.java delete mode 100644 src/main/java/com/xkrs/utils/SnowFlakeUtil.java diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 95d8fe8..10e4855 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -68,9 +68,6 @@ public class FirePointServiceImpl implements FirePointService { @Resource private FireTaskDao fireTaskDao; - @Resource - private JdbcUtils jdbcUtils; - @Resource private FireTaskPhotoDao fireTaskPhotoDao; diff --git a/src/main/java/com/xkrs/utils/AddressUtils.java b/src/main/java/com/xkrs/utils/AddressUtils.java deleted file mode 100644 index 02736d7..0000000 --- a/src/main/java/com/xkrs/utils/AddressUtils.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.xkrs.utils; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.http.HttpEntity; -import org.apache.http.HttpStatus; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - -public class AddressUtils { - - private static final Logger log = LoggerFactory.getLogger(AddressUtils.class); - private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"; - - /** - * 获取指定经纬度的地理位置 - * - * @param latitude 纬度 - * @param longitude 经度 - * @return - */ - public static String getLocal(String latitude, String longitude) { - String ok = "ok"; - String msg = "msg"; - String info = getAdd(latitude, longitude); - ObjectMapper mapper = new ObjectMapper(); - JsonNode node = null; - try { - node = mapper.readTree(info); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - assert node != null; - String province = null; - String city = null; - String county = null; - String road = null; - String address = null; - if (ok.equals(node.path(msg).asText())) { - province = node.path("result").path("addressComponent").path("province").asText(); - city = node.path("result").path("addressComponent").path("city").asText(); - county = node.path("result").path("addressComponent").path("county").asText(); - road = node.path("result").path("addressComponent").path("road").asText(); - address = node.path("result").path("addressComponent").path("address").asText(); - } - String fireAddress = province + city + county + road + address; - return fireAddress; - } - - /** - * 根据经纬度获取位置信息 - * - * @param latitude 纬度 - * @param longitude 经度 - * @return - */ - public static String getAdd(String latitude, String longitude) { - // 读取成功标志 - boolean isSuccess = false; - // 重复次数 - int count = 10; - ObjectMapper mapper = new ObjectMapper(); - Map paramMap = new HashMap<>(3); - paramMap.put("lon", longitude); - paramMap.put("lat", latitude); - paramMap.put("ver", "1"); - String paramStr = null; - try { - paramStr = mapper.writeValueAsString(paramMap); - } catch (JsonProcessingException e) { - log.error("转json失败,{}", (Object) e.getStackTrace()); - } - String url = String.format("http://api.tianditu.gov.cn/geocoder?type=geocode&tk=5a1d34815475f88e6d8802da6be832ae&postStr=%s", paramStr); - // 创建http对象 - RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).setConnectionRequestTimeout(60000).build(); - CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build(); - - // 创建并设置URI - URIBuilder uri = null; - // 创建Get请求 - HttpGet get = null; - - try { - URL url1 = new URL(url); - URI uri1 = new URI(url1.getProtocol(), url1.getHost(), url1.getPath(), url1.getQuery(), null); - uri = new URIBuilder(uri1); - get = new HttpGet(uri.build()); - // 设置请求头 - setGet(get); - } catch (URISyntaxException | MalformedURLException e) { - log.info("错误{}", (Object) e.getStackTrace()); - } - //发送请求 - HttpEntity entity = null; - InputStream is = null; - BufferedReader br = null; - // 创建响应对象 - CloseableHttpResponse response = null; - String line; - String sLine = null; - - String json = null; - while (!isSuccess && count > 0) { - try { - response = client.execute(get); - // 获取请求结果 - if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { - log.info("实时定位数据未请求成功"); - count--; - //close(is, br, response, client); - continue; - } - entity = response.getEntity(); - is = entity.getContent(); - br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); - StringBuilder sb = new StringBuilder(); - while ((line = br.readLine()) != null) { - sb.append(line); - } - sLine = sb.toString(); - sLine = sLine.substring(sLine.indexOf("{")); - //使用ObjectMapper对象对 User对象进行转换 - try { - json = mapper.writeValueAsString(sLine); - } catch (JsonProcessingException e) { - log.info("json字符串转化异常{}", (Object) e.getStackTrace()); - } - isSuccess = true; - - } catch (ClientProtocolException e) { - log.info("请求超时等问题:{}", (Object) e.getStackTrace()); - } catch (IOException e) { - log.info("I/O问题:{}", (Object) e.getStackTrace()); - } finally { - close(is, br, response, client); - } - } - return sLine; - } - - private static void close(InputStream is, BufferedReader br, CloseableHttpResponse response, CloseableHttpClient client) { - try { - if (null != is) { - is.close(); - } - if (null != br) { - br.close(); - } - if (null != response) { - response.close(); - } - if (null != client) { - client.close(); - } - } catch (IOException e) { - log.info("IO错误{}", (Object) e.getStackTrace()); - } - } - - private static HttpGet setGet(HttpGet get) { - get.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); - get.setHeader("Accept-Encoding", "gzip, deflate"); - get.setHeader("Accept-Language", "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6"); - get.setHeader("Connection", "keep-alive"); - get.setHeader("Cache-Control", "no-cache"); - get.setHeader("Upgrade-Insecure-Requests", "1"); - get.setHeader("User-Agent", USER_AGENT); - return get; - } - - public static void main(String[] args) { - String latAndLng = getLocal("36.89", "115.90"); - System.out.println(latAndLng); - } -} diff --git a/src/main/java/com/xkrs/utils/BeanUtils.java b/src/main/java/com/xkrs/utils/BeanUtils.java deleted file mode 100644 index 67c5ba2..0000000 --- a/src/main/java/com/xkrs/utils/BeanUtils.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.xkrs.utils; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Supplier; - -/** - * @author xkrs - */ -public class BeanUtils { - - /** - * 缓存BeanCopier 对象 提升性能 - */ - private static final ConcurrentHashMap BEAN_COPIER_MAP = new ConcurrentHashMap<>(); - - - /** - * Bean属性复制工具方法。 - * @param sources 原始集合 - * @param supplier: 目标类::new(eg: UserVO::new) - */ - public static List cgLibCopyList(List sources, Supplier supplier) { - List list = new ArrayList<>(sources.size()); - org.springframework.cglib.beans.BeanCopier beanCopier = null; - for (S source : sources) { - T t = supplier.get(); - if (beanCopier == null) { - beanCopier = getBeanCopier(source.getClass(), t.getClass()); - } - beanCopier.copy(source, t, null); - list.add(t); - } - return list; - } - - /** - * Bean属性复制工具方法。 - * @param source 目标对象 - * @param supplier: 目标类::new(eg: UserVO::new) - */ - public static T cgLibCopyBean(Object source, Supplier supplier) { - T t = supplier.get(); - getBeanCopier(source.getClass(), t.getClass()).copy(source, t, null); - return t; - } - - - /** - * 获取BeanCopier对象 如果缓存中有从缓存中获取 如果没有则新创建对象并加入缓存 - * @param sourceClass - * @param targetClass - * @return - */ - private static org.springframework.cglib.beans.BeanCopier getBeanCopier(Class sourceClass, Class targetClass) { - String key = getKey(sourceClass.getName(), targetClass.getName()); - org.springframework.cglib.beans.BeanCopier beanCopier; - beanCopier = BEAN_COPIER_MAP.get(key); - if (beanCopier == null) { - beanCopier = org.springframework.cglib.beans.BeanCopier.create(sourceClass, targetClass, false); - BEAN_COPIER_MAP.put(key, beanCopier); - } - return beanCopier; - } - - /** - * 生成缓存key - */ - private static String getKey(String sourceClassName, String targetClassName) { - return sourceClassName + targetClassName; - } -} diff --git a/src/main/java/com/xkrs/utils/BroadcastUtils.java b/src/main/java/com/xkrs/utils/BroadcastUtils.java deleted file mode 100644 index 644b218..0000000 --- a/src/main/java/com/xkrs/utils/BroadcastUtils.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkrs.utils; - -public class BroadcastUtils { - - private BroadcastUtils() { - } - -// public static void send(String firePointStreetCode, String firePointAddress) { -// -// } - -} diff --git a/src/main/java/com/xkrs/utils/CommonConstant.java b/src/main/java/com/xkrs/utils/CommonConstant.java index 9573695..21278b3 100644 --- a/src/main/java/com/xkrs/utils/CommonConstant.java +++ b/src/main/java/com/xkrs/utils/CommonConstant.java @@ -5,172 +5,6 @@ package com.xkrs.utils; */ public interface CommonConstant { - /** - * 正常状态 - */ - public static final String STATUS_NORMAL = "0"; - - /** - * 禁用状态 - */ - public static final String STATUS_DISABLE = "1"; - - /** - * 删除标志 - */ - public static final String DEL_FLAG_1 = "1"; - - /** - * 未删除 - */ - public static final String DEL_FLAG_0 = "0"; - - /** - * 系统日志类型: 登录 - */ - public static final int LOG_TYPE_1 = 1; - - /** - * 系统日志类型: 操作 - */ - public static final int LOG_TYPE_2 = 2; - - /** - * 操作日志类型: 查询 - */ - public static final int OPERATE_TYPE_1 = 1; - - /** - * 操作日志类型: 添加 - */ - public static final int OPERATE_TYPE_2 = 2; - - /** - * 操作日志类型: 更新 - */ - public static final int OPERATE_TYPE_3 = 3; - - /** - * 操作日志类型: 删除 - */ - public static final int OPERATE_TYPE_4 = 4; - - /** - * 操作日志类型: 倒入 - */ - public static final int OPERATE_TYPE_5 = 5; - - /** - * 操作日志类型: 导出 - */ - public static final int OPERATE_TYPE_6 = 6; - - - /** {@code 500 Server Error} (HTTP/1.0 - RFC 1945) */ - public static final Integer SC_INTERNAL_SERVER_ERROR_500 = 500; - public static final Integer SC_INTERNAL_SERVER_ERROR_501 = 501; - public static final Integer SC_INTERNAL_SERVER_ERROR_502 = 502; - /** {@code 200 OK} (HTTP/1.0 - RFC 1945) */ - public static final Integer SC_OK_200 = 200; - public static final Integer SC_OK_201 = 201; - public static final Integer SC_OK_202 = 202; - - public static final Integer SC_OK_300 = 300; - public static final Integer SC_OK_301 = 301; - /**访问权限认证未通过 510*/ - public static final Integer SC_JEECG_NO_AUTHZ=510; - - /** 登录用户Shiro权限缓存KEY前缀 */ - public static String PREFIX_USER_SHIRO_CACHE = "shiro:cache:org.jeecg.modules.shiro.authc.ShiroRealm.authorizationCache:"; - /** 登录用户Token令牌缓存KEY前缀 */ - public static final String PREFIX_USER_TOKEN = "prefix_user_token_"; - /** Token缓存时间:3600秒即一小时 */ - public static final int TOKEN_EXPIRE_TIME = 3600; - - - /** - * 0:一级菜单 - */ - public static final Integer MENU_TYPE_0 = 0; - /** - * 1:子菜单 - */ - public static final Integer MENU_TYPE_1 = 1; - /** - * 2:按钮权限 - */ - public static final Integer MENU_TYPE_2 = 2; - - /**通告对象类型(USER:指定用户,ALL:全体用户)*/ - public static final String MSG_TYPE_UESR = "USER"; - public static final String MSG_TYPE_ALL = "ALL"; - - /**发布状态(0未发布,1已发布,2已撤销)*/ - public static final String NO_SEND = "0"; - public static final String HAS_SEND = "1"; - public static final String HAS_CANCLE = "2"; - - /**阅读状态(0未读,1已读)*/ - public static final String HAS_READ_FLAG = "1"; - public static final String NO_READ_FLAG = "0"; - - /**优先级(L低,M中,H高)*/ - public static final String PRIORITY_L = "L"; - public static final String PRIORITY_M = "M"; - public static final String PRIORITY_H = "H"; - - /** - * 短信模板方式 0 .登录模板、1.注册模板、2.忘记密码模板 - * 3 信息变更 - */ - public static final String SMS_TPL_TYPE_0 = "0"; - public static final String SMS_TPL_TYPE_1 = "1"; - public static final String SMS_TPL_TYPE_2 = "2"; - public static final String SMS_TPL_TYPE_3 = "3"; - /** - * 状态(0无效1有效) - */ - public static final String STATUS_0 = "0"; - public static final String STATUS_1 = "1"; - - /** - * 同步工作流引擎1同步0不同步 - */ - public static final Integer ACT_SYNC_1 = 1; - public static final Integer ACT_SYNC_0 = 0; - - /** - * 消息类型1:通知公告2:系统消息 - */ - public static final String MSG_CATEGORY_1 = "1"; - public static final String MSG_CATEGORY_2 = "2"; - - /** - * 是否配置菜单的数据权限 1是0否 - */ - public static final Integer RULE_FLAG_0 = 0; - public static final Integer RULE_FLAG_1 = 1; - - /** - * 是否用户已被冻结 1正常(解冻) 2冻结 - */ - public static final String USER_UNFREEZE = "1"; - public static final String USER_FREEZE = "2"; - - /** - * 文件上传类型(本地:local,Minio:minio,阿里云:alioss) - */ - public static final String UPLOAD_TYPE_LOCAL = "local"; - public static final String UPLOAD_TYPE_MINIO = "minio"; - public static final String UPLOAD_TYPE_OSS = "alioss"; - - - /** - * 收入明细 (1:收入 2:支出) - */ - public static final Integer USER_IDENTITY_1 = 1; - public static final Integer USER_IDENTITY_2 = 2; - /** * 高德天气URL、key */ diff --git a/src/main/java/com/xkrs/utils/CopyPropertiesUtil.java b/src/main/java/com/xkrs/utils/CopyPropertiesUtil.java deleted file mode 100644 index 03155f8..0000000 --- a/src/main/java/com/xkrs/utils/CopyPropertiesUtil.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.xkrs.utils; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -/** - * 复制源对象的属性值 - * @Author tajochen - */ -public class CopyPropertiesUtil { - - /** - * 复制源对象和目标对象的属性值 - * @param source 源对象 - * @param target 目标对象 - * @throws SecurityException - * @throws IllegalArgumentException - */ - public static void copy(Object source, Object target) { - //得到对象的Class - Class sourceClass = source.getClass(); - Class targetClass = target.getClass(); - //得到Class对象的所有属性 - Field[] sourceFields = sourceClass.getDeclaredFields(); - Field[] targetFields = targetClass.getDeclaredFields(); - - for(Field sourceField : sourceFields){ - //属性名 - String name = sourceField.getName(); - //属性类型 - Class type = sourceField.getType(); - String methodName = name.substring(0, 1).toUpperCase() + name.substring(1); - try{ - //得到属性对应get方法 - Method getMethod = sourceClass.getMethod("get" + methodName); - //执行源对象的get方法得到属性值 - Object value = getMethod.invoke(source); - //目标对象的属性名 - for(Field targetField : targetFields){ - String targetName = targetField.getName(); - if(targetName.equals(name)){ - //属性对应的set方法 - Method setMethod = targetClass.getMethod("set" + methodName, type); - //执行目标对象的set方法 - setMethod.invoke(target, value); - } - } - } - catch (Exception e){ - e.printStackTrace(); - } - } - } -} diff --git a/src/main/java/com/xkrs/utils/DateTimeUtils.java b/src/main/java/com/xkrs/utils/DateTimeUtils.java index e3978ce..6dcae15 100644 --- a/src/main/java/com/xkrs/utils/DateTimeUtils.java +++ b/src/main/java/com/xkrs/utils/DateTimeUtils.java @@ -9,7 +9,6 @@ public class DateTimeUtils { public final static DateTimeFormatter DATE_TIME_FORMATTER_1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); public final static DateTimeFormatter DATE_TIME_FORMATTER_2 = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - public static String localDateTimeToString(LocalDateTime localDateTime) { return DATE_TIME_FORMATTER_1.format(localDateTime); } diff --git a/src/main/java/com/xkrs/utils/EntityManagerUtil.java b/src/main/java/com/xkrs/utils/EntityManagerUtil.java deleted file mode 100644 index ac1ede1..0000000 --- a/src/main/java/com/xkrs/utils/EntityManagerUtil.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.xkrs.utils; - -import java.lang.reflect.Constructor; -import java.util.ArrayList; -import java.util.List; - -/** - * @author XinYi Song - */ -public class EntityManagerUtil { - /** - * 把List转换成List - */ - public static List objectToBean(List objList, Class clz) throws Exception{ - if (objList==null || objList.size()==0) { - return null; - } - - Class[] cz = null; - Constructor[] cons = clz.getConstructors(); - for (Constructor ct : cons) { - Class[] clazz = ct.getParameterTypes(); - if (objList.get(0).length == clazz.length) { - cz = clazz; - break; - } - } - - List list = new ArrayList(); - for (Object[] obj : objList) { - Constructor cr = clz.getConstructor(cz); - list.add(cr.newInstance(obj)); - } - return list; - } -} diff --git a/src/main/java/com/xkrs/utils/FileFastDfs.java b/src/main/java/com/xkrs/utils/FileFastDfs.java index 2ec28d9..8eb184a 100644 --- a/src/main/java/com/xkrs/utils/FileFastDfs.java +++ b/src/main/java/com/xkrs/utils/FileFastDfs.java @@ -37,12 +37,6 @@ public class FileFastDfs { @Value("${dfs.port}") public String port; -// @Value("${dfs.upload}") -// public String upload; -// -// @Value("${dfs.delete}") -// public String delete; - @Resource private KafkaTemplate kafkaTemplate; private static final Logger log = LoggerFactory.getLogger(FileFastDfs.class); @@ -52,6 +46,7 @@ public class FileFastDfs { /** * 文件上传到dfs服务器 + * * @param file * @param dir * @return @@ -61,8 +56,7 @@ public class FileFastDfs { InputStreamResource isr = null; try { file1 = multipartFileToFile(file); - isr=new InputStreamResource(file.getInputStream(), - file.getOriginalFilename()); + isr = new InputStreamResource(file.getInputStream(), file.getOriginalFilename()); } catch (IOException e) { log.info("IO错误{}", (Object) e.getStackTrace()); } catch (Exception e) { @@ -84,9 +78,7 @@ public class FileFastDfs { String name = file1.getName(); System.err.println("file:" + file1.getName()); paramMap.put("scene", name.substring(name.lastIndexOf(".") + 1)); - paramMap.put("fileName", System.currentTimeMillis() + "" - + Objects.requireNonNull(file.getOriginalFilename()) - .substring(file.getOriginalFilename().lastIndexOf("."))); + paramMap.put("fileName", System.currentTimeMillis() + "" + Objects.requireNonNull(file.getOriginalFilename()).substring(file.getOriginalFilename().lastIndexOf("."))); System.err.println(paramMap); // String result = HttpUtil.post("http://" + ip + ":" + port + "/group1/upload", paramMap); @@ -111,7 +103,7 @@ public class FileFastDfs { /** * @description: 文件上传到dfs服务器 - * @params [file:File 文件, dir 文件存放路径] + * @params [file:File 文件, dir 文件存放路径] * @author: wd * @time: 2020/3/31 2020/3/31 */ @@ -154,7 +146,7 @@ public class FileFastDfs { /** * @description: 文件上传到dfs服务器 - * @params [file:File 文件, dir 文件存放路径] + * @params [file:File 文件, dir 文件存放路径] * @author: wd * @time: 2020/3/31 2020/3/31 */ @@ -251,12 +243,12 @@ public class FileFastDfs { /** * @description: 文件base64流获取 - * @params [fileName : 文件路径] + * @params [fileName : 文件路径] * @return: java.lang.String * @author: chqf * @time: 2020/3/31 2020/3/31 */ - public String getBase64(String fileName) { + public String getBase64(String fileName) { if (fileName == null || "".equals(fileName)) { return null; } @@ -284,7 +276,7 @@ public class FileFastDfs { imgStr = encoder.encodeToString(data.toByteArray()); } catch (IOException e) { log.info("IO错误{}", (Object) e.getStackTrace()); - }finally { + } finally { try { if (null != fis) { fis.close(); @@ -300,7 +292,7 @@ public class FileFastDfs { /** * @description: 文件格式转换multipartFil 转为 File 格式 - * @params [file] + * @params [file] * @return: java.io.File * @author: dong * @time: 2020/3/31 2020/3/31 @@ -331,7 +323,7 @@ public class FileFastDfs { } } catch (IOException e) { log.info("IO错误{}", (Object) e.getStackTrace()); - }finally { + } finally { try { if (null != os) { os.close(); @@ -347,7 +339,7 @@ public class FileFastDfs { /** * @description: 文件base64流获取 - * @params [fileName : 文件路径] + * @params [fileName : 文件路径] * @return: java.lang.String * @author: dong * @time: 2020/3/31 2020/3/31 @@ -373,12 +365,12 @@ public class FileFastDfs { int len; try { assert fis != null; - while ((len = fis.read(b)) > 0){ + while ((len = fis.read(b)) > 0) { response.getOutputStream().write(b, 0, len); } } catch (IOException e) { log.info("IO错误{}", (Object) e.getStackTrace()); - }finally { + } finally { try { if (null != fis) { fis.close(); @@ -392,6 +384,7 @@ public class FileFastDfs { /** * 删除文件 path + * * @param filePath 文件路径 上传返回的path * @return */ @@ -429,6 +422,7 @@ public class FileFastDfs { /** * 删除文件 path + * * @param md5 上传返回的md5 * @return */ @@ -465,9 +459,6 @@ public class FileFastDfs { } - - - public static void main(String[] args) { File file = new File("C:\\Users\\dong\\Desktop\\遥感影像\\遥感影像\\GF1\\GF1_PMS1_E116.8_N36.6_20190528_L1A0004026837-MSS1_ORTHO_MS.tif"); FileFastDfs fileFastDfs = new FileFastDfs(); diff --git a/src/main/java/com/xkrs/utils/GaoDeApiUtil.java b/src/main/java/com/xkrs/utils/GaoDeApiUtil.java index 3b9e663..34a78d9 100644 --- a/src/main/java/com/xkrs/utils/GaoDeApiUtil.java +++ b/src/main/java/com/xkrs/utils/GaoDeApiUtil.java @@ -20,6 +20,7 @@ import static com.xkrs.utils.HttpClientUtils.sendHttpsGet; * @description */ public class GaoDeApiUtil { + private static final Logger log = LoggerFactory.getLogger(GaoDeApiUtil.class); /** diff --git a/src/main/java/com/xkrs/utils/HashUtil.java b/src/main/java/com/xkrs/utils/HashUtil.java deleted file mode 100644 index 2aa3a99..0000000 --- a/src/main/java/com/xkrs/utils/HashUtil.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.xkrs.utils; - -import java.security.MessageDigest; - -/** - * md5加密解密工具 - * @author tajochen - */ -public class HashUtil { - - /** - * MD5加密 - * - * @param password - * @return - */ - public static String md5Encode(String password) { - MessageDigest md5 = null; - try { - md5 = MessageDigest.getInstance("MD5"); - } catch (Exception e) { - throw new RuntimeException(e); - } - char[] charArray = password.toCharArray(); - byte[] byteArray = new byte[charArray.length]; - for (int i = 0; i < charArray.length; i++){ - byteArray[i] = (byte) charArray[i]; - } - byte[] md5Bytes = md5.digest(byteArray); - StringBuilder hexValue = new StringBuilder(); - for (byte md5Byte : md5Bytes) { - int val = ((int) md5Byte) & 0xff; - if (val < 16) { - hexValue.append("0"); - } - hexValue.append(Integer.toHexString(val)); - } - return hexValue.toString(); - } -} diff --git a/src/main/java/com/xkrs/utils/HttpClientUtils.java b/src/main/java/com/xkrs/utils/HttpClientUtils.java index 2129b97..2d5ac2b 100644 --- a/src/main/java/com/xkrs/utils/HttpClientUtils.java +++ b/src/main/java/com/xkrs/utils/HttpClientUtils.java @@ -37,17 +37,19 @@ public class HttpClientUtils { /** * 发送http+get请求 + * * @param url * @return 返回结果 * @throws Exception */ public static String sendHttpGet(String url) throws Exception { CloseableHttpClient httpClient = HttpClients.createDefault(); - return doGet(url,httpClient); + return doGet(url, httpClient); } /** * 发送https+get请求,绕过证书 + * * @param url 请求地址 * @return 返回结果 * @throws Exception @@ -55,19 +57,15 @@ public class HttpClientUtils { public static String sendHttpsGet(String url) throws Exception { // CloseableHttpClient httpClient = createIgnoreVerifyHttpClient(); //CloseableHttpClient httpClient = HttpClients.createDefault(); - SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory( - SSLContexts.custom() - .loadTrustMaterial(null, new TrustSelfSignedStrategy()) - .build(), - NoopHostnameVerifier.INSTANCE - ); + SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(), NoopHostnameVerifier.INSTANCE); CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(scsf).build(); - return doGet(url,httpClient); + return doGet(url, httpClient); } /** * 发送http+post请求 - * @param url 请求地址 + * + * @param url 请求地址 * @param params 请求参数 json字符串 * @return 返回结果 * @throws Exception @@ -79,7 +77,8 @@ public class HttpClientUtils { /** * 发送https+post请求 - * @param url 请求地址 + * + * @param url 请求地址 * @param params 请求参数 json字符串 * @return 返回结果 * @throws Exception @@ -87,12 +86,7 @@ public class HttpClientUtils { public static String sendHttpsPost(String url, String params) throws Exception { // CloseableHttpClient httpClient = createIgnoreVerifyHttpClient(); // CloseableHttpClient httpClient = null; - SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory( - SSLContexts.custom() - .loadTrustMaterial(null, new TrustSelfSignedStrategy()) - .build(), - NoopHostnameVerifier.INSTANCE - ); + SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(), NoopHostnameVerifier.INSTANCE); CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(scsf).build(); // CloseableHttpClient httpClient = HttpClients.createDefault(); return doPost(httpClient, url, params); @@ -102,10 +96,10 @@ public class HttpClientUtils { /** * 封装get请求方式的处理 */ - private static String doGet(String url,CloseableHttpClient httpClient) throws Exception { + private static String doGet(String url, CloseableHttpClient httpClient) throws Exception { log.info("HGet请求url={}", url); HttpGet httpGet = new HttpGet(url); - return execute(httpClient,httpGet); + return execute(httpClient, httpGet); } /** @@ -117,7 +111,7 @@ public class HttpClientUtils { HttpPost httpPost = new HttpPost(url); httpPost.addHeader("Content-Type", "application/json; charset=utf-8"); httpPost.setEntity(new StringEntity(params)); - return execute(httpClient,httpPost); + return execute(httpClient, httpPost); } /** @@ -132,7 +126,7 @@ public class HttpClientUtils { log.info("HttpClient响应码={}", statusCode); final int success = 200; if (statusCode == success) { - result = EntityUtils.toString(response.getEntity(),"utf-8"); + result = EntityUtils.toString(response.getEntity(), "utf-8"); } else { log.error("HttpClient请求失败,错误码={}", statusCode); } @@ -162,15 +156,11 @@ public class HttpClientUtils { // 实现一个X509TrustManager接口 X509TrustManager trustManager = new X509TrustManager() { @Override - public void checkClientTrusted( - X509Certificate[] paramArrayOfX509Certificate, - String paramString) throws CertificateException { + public void checkClientTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException { } @Override - public void checkServerTrusted( - X509Certificate[] paramArrayOfX509Certificate, - String paramString) throws CertificateException { + public void checkServerTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException { } @Override @@ -179,10 +169,7 @@ public class HttpClientUtils { } }; sslContext.init(null, new TrustManager[]{trustManager}, null); - Registry socketFactoryRegistry = - RegistryBuilder.create() - .register("http", PlainConnectionSocketFactory.INSTANCE) - .register("https", new SSLConnectionSocketFactory(sslContext)).build(); + Registry socketFactoryRegistry = RegistryBuilder.create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", new SSLConnectionSocketFactory(sslContext)).build(); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry); CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connManager).build(); return httpClient; diff --git a/src/main/java/com/xkrs/utils/IpUtil.java b/src/main/java/com/xkrs/utils/IpUtil.java index ae88933..ef5bd73 100644 --- a/src/main/java/com/xkrs/utils/IpUtil.java +++ b/src/main/java/com/xkrs/utils/IpUtil.java @@ -4,6 +4,7 @@ import javax.servlet.http.HttpServletRequest; /** * IP地址处理工具 + * * @author tajochen */ public class IpUtil { @@ -14,7 +15,7 @@ public class IpUtil { final char splitChar = ','; if (ip != null && ip.length() != 0 && !unkonwMsg.equalsIgnoreCase(ip)) { // 多次反向代理后会有多个ip值,第一个ip才是真实ip - if( ip.indexOf(splitChar)!=-1 ){ + if (ip.indexOf(splitChar) != -1) { ip = ip.split(",")[0]; } } diff --git a/src/main/java/com/xkrs/utils/JdbcUtils.java b/src/main/java/com/xkrs/utils/JdbcUtils.java deleted file mode 100644 index bae62fa..0000000 --- a/src/main/java/com/xkrs/utils/JdbcUtils.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.xkrs.utils; - -import com.xkrs.model.entity.FireTaskPhoto; -import org.springframework.jdbc.core.BatchPreparedStatementSetter; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.List; - -/** - * @author XinYi Song - */ -@Component -public class JdbcUtils { - @Resource - private JdbcTemplate jdbcTemplate; - - /** - * jdbcTemplate,batchUpdate增加,需自己定义sql,需要配置 - * @param list - */ - public List batchWithJdbcTemplate(List list){ - String sql = "Insert into fire_task_photo(photo_fire_code,task_photo) values(?,?)"; - jdbcTemplate.batchUpdate(sql,new BatchPreparedStatementSetter() { - @Override - public void setValues(PreparedStatement ps, int i) throws SQLException { - ps.setString(1,list.get(i).getPhotoFireCode()); - ps.setString(2,list.get(i).getTaskPhoto()); - } - @Override - public int getBatchSize() { - return list.size(); - } - }); - return list; - } -} diff --git a/src/main/java/com/xkrs/utils/NumberUtil.java b/src/main/java/com/xkrs/utils/NumberUtil.java deleted file mode 100644 index 2ead0c3..0000000 --- a/src/main/java/com/xkrs/utils/NumberUtil.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.xkrs.utils; - -/** - * 数字工具 - * @author tajochen - */ -public class NumberUtil { - - public static boolean isStrNumeric(String str) { - if(str==null||str.length()==0){ - return false; - } - for (int i = 0; i < str.length(); i++) { - System.out.println(str.charAt(i)); - if (!Character.isDigit(str.charAt(i))) { - return false; - } - } - return true; - } -} diff --git a/src/main/java/com/xkrs/utils/ObjectToBeanUtils.java b/src/main/java/com/xkrs/utils/ObjectToBeanUtils.java index 1caf481..ceb0381 100644 --- a/src/main/java/com/xkrs/utils/ObjectToBeanUtils.java +++ b/src/main/java/com/xkrs/utils/ObjectToBeanUtils.java @@ -22,8 +22,8 @@ public class ObjectToBeanUtils { /** * 把List转换成List */ - public static List objectToBean(List objList, Class clz) throws Exception{ - if (objList==null || objList.size()==0) { + public static List objectToBean(List objList, Class clz) throws Exception { + if (objList == null || objList.size() == 0) { return null; } @@ -45,70 +45,6 @@ public class ObjectToBeanUtils { return list; } - - - - - - public static List objectToBeans(List objList, Class clz) throws Exception{ - if (objList==null || objList.size()==0) { - return null; - } - - int length = objList.get(0).length; - log.info("*************>"+length); - - Class[] cz = null; - Constructor[] cons = clz.getConstructors(); - for (Constructor ct : cons) { - Class[] clazz = ct.getParameterTypes(); - if (objList.get(0).length == clazz.length) { - cz = clazz; - break; - } - } - - List list = new ArrayList(); - log.info("---------->"+objList.get(0)); - Constructor cr = clz.getConstructor(cz); - T newInstance = cr.newInstance((Object) objList.get(0)); - list.add(newInstance); - return list; - } - - - public static List castEntity(List list, Class clazz, Object model) { - List returnList = new ArrayList(); - if (list.isEmpty()) { - return returnList; - } - //获取每个数组集合的元素个数 - Object[] co = list.get(0); - - //获取当前实体类的属性名、属性值、属性类别 - List attributeInfoList = getFiledsInfo(model); - //创建属性类别数组 - Class[] c2 = new Class[attributeInfoList.size()]; - //如果数组集合元素个数与实体类属性个数不一致则发生错误 - if (attributeInfoList.size() != co.length) { - return returnList; - } - //确定构造方法 - for (int i = 0; i < attributeInfoList.size(); i++) { - c2[i] = (Class) attributeInfoList.get(i).get("type"); - } - try { - for (Object[] o : list) { - Constructor constructor = clazz.getConstructor(c2); - returnList.add(constructor.newInstance(o)); - } - } catch (Exception ex) { - log.info("实体数据转化为实体类发生异常:异常信息:{}", ex.getMessage()); - return returnList; - } - return returnList; - } - /** * 根据属性名获取属性值 * diff --git a/src/main/java/com/xkrs/utils/OpenGeoUtil.java b/src/main/java/com/xkrs/utils/OpenGeoUtil.java deleted file mode 100644 index cc1b03a..0000000 --- a/src/main/java/com/xkrs/utils/OpenGeoUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.xkrs.utils; - -import org.geolatte.geom.Geometry; -import org.geolatte.geom.Point; -import org.geolatte.geom.codec.Wkt; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * 开源Gis工具集 - * @author tajochen - */ -public class OpenGeoUtil { - - Logger logger = LoggerFactory.getLogger(OpenGeoUtil.class); - - /** - * wkt文本转为点数据 - * @param wkt - * @return - */ - public static Point wktStrToPoint(String wkt) { - Point point = (Point) Wkt.fromWkt(wkt); - return point; - } - - /** - * wkt文本转geometry - * @param wkt - * @return - */ - public static Geometry wktStrToGeom(String wkt) { - Geometry geom = Wkt.fromWkt(wkt); - return geom; - } - -} diff --git a/src/main/java/com/xkrs/utils/PhotoUtil.java b/src/main/java/com/xkrs/utils/PhotoUtil.java index 10ff940..d58c665 100644 --- a/src/main/java/com/xkrs/utils/PhotoUtil.java +++ b/src/main/java/com/xkrs/utils/PhotoUtil.java @@ -24,11 +24,12 @@ public class PhotoUtil { /** * 上传单张图片 + * * @param imgFile * @return * @throws IOException */ - public static String memoryPhoto(MultipartFile imgFile,String distributedTime,String distributedType) throws IOException { + public static String memoryPhoto(MultipartFile imgFile, String distributedTime, String distributedType) throws IOException { //String uploadPath = "http://139.199.98.175:2088/wfTaskImage/"; String uploadPath = "http://192.168.2.172/"; //获取原始文件名 @@ -52,13 +53,14 @@ public class PhotoUtil { imgFile.transferTo(new File(path)); - return "video/"+newName; + return "video/" + newName; } return null; } /** * 以文件形式,批量上传图片 + * * @param files * @return * @throws IOException @@ -69,7 +71,7 @@ public class PhotoUtil { String newName = ""; String oldName = ""; List fireTaskPhotos = new ArrayList<>(); - for(MultipartFile file : files){ + for (MultipartFile file : files) { //获取file图片名称 oldName = file.getOriginalFilename(); //找到 . 的位置 @@ -99,27 +101,27 @@ public class PhotoUtil { } - /** * 删除本地或服务器储存的图片 + * * @param path * @return */ - public static String delFile(String path){ + public static String delFile(String path) { String resultInfo = null; int lastIndexOf = path.lastIndexOf("/"); - String imgPath = path.substring(lastIndexOf + 1,path.length()); + String imgPath = path.substring(lastIndexOf + 1, path.length()); System.out.println(imgPath); imgPath = "/usr/local/etc/images/" + imgPath; // img_path = "/usr/etc/images/Folder/" + img_path; File file = new File(imgPath); - if(file.exists()){ - if(file.delete()){ + if (file.exists()) { + if (file.delete()) { resultInfo = "删除成功!"; - }else { + } else { resultInfo = "删除失败!"; } - }else { + } else { resultInfo = "文件不存在"; } return resultInfo; @@ -127,6 +129,7 @@ public class PhotoUtil { /** * 通过图片路径解析 ,上传保存 + * * @param listImgSrc * @return */ @@ -171,17 +174,18 @@ public class PhotoUtil { /** * 删除本地文件夹图片 + * * @param url */ - public static void deleteImage(String url){ - File file=new File(url); + public static void deleteImage(String url) { + File file = new File(url); //判断file是否是文件目录 若是返回TRUE - if (file.isDirectory()){ + if (file.isDirectory()) { //name存储file文件夹中的文件名 - String[] name =file.list(); - for (int i=0; i MAX_DATACENTER_NUM || datacenterId < 0) { - throw new IllegalArgumentException("data center id can't be greater than MAX_DATACENTER_NUM or less than 0"); - } - if (machineId > MAX_MACHINE_NUM || machineId < 0) { - throw new IllegalArgumentException("machine id can't be greater than MAX_MACHINE_NUM or less than 0"); - } - this.datacenterId = datacenterId; - this.machineId = machineId; - } - - /** - * 产生下一个ID - * @return - */ - public synchronized long nextId() { - long currStmp = getNewstmp(); - if (currStmp < lastStmp) { - throw new RuntimeException("Clock moved backwards. Refusing to generate id"); - } - - if (currStmp == lastStmp) { - //相同毫秒内,序列号自增 - sequence = (sequence + 1) & MAX_SEQUENCE; - //同一毫秒的序列数已经达到最大 - if (sequence == 0L) { - currStmp = getNextMill(); - } - } else { - //不同毫秒内,序列号置为0 - sequence = 0L; - } - - lastStmp = currStmp; - //时间戳部分 - return (currStmp - START_STMP) << TIMESTMP_LEFT - //数据中心部分 - | datacenterId << DATACENTER_LEFT - //机器标识部分 - | machineId << MACHINE_LEFT - //序列号部分 - | sequence; - } - - private long getNextMill() { - long mill = getNewstmp(); - while (mill <= lastStmp) { - mill = getNewstmp(); - } - return mill; - } - - private long getNewstmp() { - return System.currentTimeMillis(); - } - - public static void main(String[] args) { - SnowFlakeUtil snowFlake = new SnowFlakeUtil(5, 5); - //测试次数 - int testTimes = 10000; - long start = System.currentTimeMillis(); - for (int i = 0; i < testTimes; i++) { - System.out.println(snowFlake.nextId()); - } - - System.out.println(System.currentTimeMillis() - start); - } -}