This commit is contained in:
liuchengqian 2023-03-08 11:59:44 +08:00
parent 3bb0add35a
commit ec296a3540
15 changed files with 19 additions and 496 deletions

View File

@ -2,7 +2,7 @@ package com.xkrs.common;
import com.xkrs.straw.helper.FirePointSubscribeManager; import com.xkrs.straw.helper.FirePointSubscribeManager;
import com.xkrs.straw.utilsnew.DateTimeUtils; import com.xkrs.straw.utilsnew.DateTimeUtils;
import com.xkrs.straw.utilsold.WDWxSendMsgUtil; import com.xkrs.straw.utilsnew.WeiXinMessageUtils;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
@ -30,7 +30,7 @@ public class StaticScheduleTask {
@Scheduled(cron = "0 0 * * * ?") @Scheduled(cron = "0 0 * * * ?")
private void testPushWeiXinMessage() { private void testPushWeiXinMessage() {
try { try {
WDWxSendMsgUtil.sendMsg("18447024917@chatroom", "微信发消息测试 " + DateTimeUtils.localDateTimeToString(LocalDateTime.now()), 0); WeiXinMessageUtils.sendMsg("18447024917@chatroom", "微信发消息测试 " + DateTimeUtils.localDateTimeToString(LocalDateTime.now()), 0);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -16,7 +16,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
import static com.xkrs.straw.utilsold.CommonConstant.*; import static com.xkrs.straw.utilsnew.CommonConstant.*;
import static com.xkrs.straw.utilsold.HttpClientUtils.sendHttpsGet; import static com.xkrs.straw.utilsold.HttpClientUtils.sendHttpsGet;
/** /**

View File

@ -15,7 +15,7 @@ import com.xkrs.straw.model.vo.SysUserVo;
import com.xkrs.straw.service.SysUserService; import com.xkrs.straw.service.SysUserService;
import com.xkrs.straw.utilsnew.*; import com.xkrs.straw.utilsnew.*;
import com.xkrs.straw.utilsold.AliYunSmsUtils; import com.xkrs.straw.utilsold.AliYunSmsUtils;
import com.xkrs.straw.utilsold.RandomUtil; import com.xkrs.straw.utilsnew.RandomUtil;
import org.apache.hc.core5.util.TextUtils; import org.apache.hc.core5.util.TextUtils;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;

View File

@ -9,9 +9,9 @@ import com.xkrs.straw.model.entity.SysUserEntity;
import com.xkrs.straw.model.helper.PushHelper; import com.xkrs.straw.model.helper.PushHelper;
import com.xkrs.straw.model.vo.AllFirePointVo; import com.xkrs.straw.model.vo.AllFirePointVo;
import com.xkrs.straw.utilsnew.FirePointConvertUtils; import com.xkrs.straw.utilsnew.FirePointConvertUtils;
import com.xkrs.straw.utilsold.FirePointCodeUtils; import com.xkrs.straw.utilsnew.FirePointCodeUtils;
import com.xkrs.straw.utilsnew.SMSUtils; import com.xkrs.straw.utilsnew.SMSUtils;
import com.xkrs.straw.utilsold.WDWxSendMsgUtil; import com.xkrs.straw.utilsnew.WeiXinMessageUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -122,7 +122,7 @@ public class FirePointPushManager {
for (String weixinId : weixinIdList) { for (String weixinId : weixinIdList) {
stringBuilder.append(weixinId).append("\n"); stringBuilder.append(weixinId).append("\n");
try { try {
WDWxSendMsgUtil.sendMsg(weixinId, messageContent, 0); WeiXinMessageUtils.sendMsg(weixinId, messageContent, 0);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -12,7 +12,7 @@ import com.xkrs.straw.utilsnew.FirePointConvertUtils;
import com.xkrs.straw.utilsnew.JsonUtils; import com.xkrs.straw.utilsnew.JsonUtils;
import com.xkrs.straw.utilsold.DateTimeUtil; import com.xkrs.straw.utilsold.DateTimeUtil;
import com.xkrs.straw.utilsnew.DateTimeUtils; import com.xkrs.straw.utilsnew.DateTimeUtils;
import com.xkrs.straw.utilsold.FirePointCodeUtils; import com.xkrs.straw.utilsnew.FirePointCodeUtils;
import org.apache.hc.core5.util.TextUtils; import org.apache.hc.core5.util.TextUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View File

@ -11,7 +11,7 @@ import com.xkrs.straw.model.entity.SysUserEntity;
import com.xkrs.straw.utilsnew.JsonUtils; import com.xkrs.straw.utilsnew.JsonUtils;
import com.xkrs.straw.utilsnew.VipTimeRangeUtils; import com.xkrs.straw.utilsnew.VipTimeRangeUtils;
import com.xkrs.straw.utilsnew.DateTimeUtils; import com.xkrs.straw.utilsnew.DateTimeUtils;
import com.xkrs.straw.utilsold.FirePointCodeUtils; import com.xkrs.straw.utilsnew.FirePointCodeUtils;
import com.xkrs.straw.utilsnew.ListUtils; import com.xkrs.straw.utilsnew.ListUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -1,4 +1,4 @@
package com.xkrs.straw.utilsold; package com.xkrs.straw.utilsnew;
public interface CommonConstant { public interface CommonConstant {

View File

@ -1,7 +1,6 @@
package com.xkrs.straw.utilsold; package com.xkrs.straw.utilsnew;
import com.xkrs.straw.model.entity.SysUserEntity; import com.xkrs.straw.model.entity.SysUserEntity;
import com.xkrs.straw.utilsnew.VipTimeRangeUtils;
import org.apache.hc.core5.util.TextUtils; import org.apache.hc.core5.util.TextUtils;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package com.xkrs.straw.utilsold; package com.xkrs.straw.utilsnew;
import java.util.Random; import java.util.Random;

View File

@ -1,4 +1,4 @@
package com.xkrs.straw.utilsold; package com.xkrs.straw.utilsnew;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -7,12 +7,7 @@ import java.util.Map;
import static com.xkrs.straw.utilsold.WDHttpClientUtils.sendHttpPost; import static com.xkrs.straw.utilsold.WDHttpClientUtils.sendHttpPost;
/** public class WeiXinMessageUtils {
* @author wudong
* @date 2022/6/2 9:25
* @description
*/
public class WDWxSendMsgUtil {
/** /**
* 通过udp通信调用发送微信消息服务发送微信消息 * 通过udp通信调用发送微信消息服务发送微信消息

View File

@ -51,7 +51,7 @@ public class FileFastDfs {
* @param dir * @param dir
* @return * @return
*/ */
public String uploadFile(MultipartFile file, String dir) { public String uploadsFile(MultipartFile file, String dir) {
File file1 = null; File file1 = null;
InputStreamResource isr = null; InputStreamResource isr = null;
try { try {
@ -103,94 +103,7 @@ public class FileFastDfs {
return result; return result;
} }
/** public String upddloadBigFile(File file, String dir, String fileType) {
* @description: 文件上传到dfs服务器
* @params [fileFile 文件, dir 文件存放路径]
* @author: wd
* @time: 2020/3/31 2020/3/31
*/
public String uploadFile(File file, String dir) {
//文件地址
//声明参数集合
HashMap<String, Object> paramMap = new HashMap<>(7);
//文件
paramMap.put("file", file);
//输出
paramMap.put("output", "json");
//自定义路径
paramMap.put("path", dir);
//场景
// System.err.println(file.getName());
// paramMap.put("fileName", System.currentTimeMillis() + "" + file.getName().substring(file.getName().lastIndexOf(".")));
paramMap.put("fileName", file.getName());
System.err.println(paramMap);
//上传
String result = HttpUtil.post("http://" + ip + ":" + port + "/group1/upload", paramMap);
System.err.println(result);
// 拿出状态码判断上传状态
ObjectMapper mapper = new ObjectMapper();
JsonNode node = null;
try {
node = mapper.readTree(result);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
final String status = "status";
final String statusFail = "fail";
if (null != node) {
if (statusFail.equals(node.path(status).asText())) {
return null;
}
}
return result;
}
/**
* @description: 文件上传到dfs服务器
* @params [fileFile 文件, dir 文件存放路径]
* @author: wd
* @time: 2020/3/31 2020/3/31
*/
public String uploadFile(File file, String dir, String fileType) {
//文件地址
//声明参数集合
HashMap<String, Object> paramMap = new HashMap<>(7);
//文件
paramMap.put("file", file);
//输出
paramMap.put("output", "json");
//自定义路径
paramMap.put("path", dir);
//场景
System.err.println(file.getName());
// paramMap.put("fileName", System.currentTimeMillis() + "" + file.getName().substring(file.getName().lastIndexOf(".")));
paramMap.put("fileName", file.getName());
paramMap.put("scene", fileType);
System.err.println(paramMap);
//上传
String result = HttpUtil.post("http://" + ip + ":" + port + "/group1/upload", paramMap);
System.err.println(result);
// 拿出状态码判断上传状态
ObjectMapper mapper = new ObjectMapper();
JsonNode node = null;
try {
node = mapper.readTree(result);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
final String status = "status";
final String statusFail = "fail";
if (null != node) {
if (statusFail.equals(node.path(status).asText())) {
return null;
}
}
return result;
}
public String uploadBigFile(File file, String dir, String fileType) {
// 下面这个一定要注意如果不设置为true将会直接返回301 // 下面这个一定要注意如果不设置为true将会直接返回301
System.setProperty("http.strictPostRedirect", Boolean.toString(true)); System.setProperty("http.strictPostRedirect", Boolean.toString(true));
TusClient tusClient = new TusClient(); TusClient tusClient = new TusClient();
@ -250,7 +163,7 @@ public class FileFastDfs {
* @author: chqf * @author: chqf
* @time: 2020/3/31 2020/3/31 * @time: 2020/3/31 2020/3/31
*/ */
public String getBase64(String fileName) { public String geddtBase64(String fileName) {
if (fileName == null || "".equals(fileName)) { if (fileName == null || "".equals(fileName)) {
return null; return null;
} }

View File

@ -1,216 +0,0 @@
package com.xkrs.straw.utilsold;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.xkrs.straw.utilsold.DateTimeUtil.getNowTimeStr;
public class FileUtil {
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
/**
* 判断目录是否存在 不存在创建
* @param path 路径目录最后带 File.separator
* @return
*/
public static boolean isFileExit(String path){
path = path.replace("/",File.separator);
File file = new File(path);
if (file.exists()) {
log.info("文件已存在");
return true;
}
if(path.endsWith(File.separator)) {
log.info("创建单个文件" + path + "失败,目标不能是目录!");
return false;
}
if(!file.getParentFile().exists()) {
log.info("目标文件所在路径不存在,准备创建。。。");
if (file.getParentFile().mkdirs()) {
if (file.mkdir()) {
log.info("创建目录文件成功!");
}
}
} else {
log.info("目标文件所在路径存在");
if (file.mkdir()) {
log.info("创建目录文件成功!");
}
}
return true;
}
/**
* 获取目录下的所有文件
* @param filePath 目录
* @return
* @throws Exception
*/
public static List<String> showListFile(String filePath) {
File dir = new File(filePath);
List<String> list = new ArrayList<>();
// 查找参数文件是否存在,只检查第一个入参
if(!dir.exists()) {
log.error("找不到文件");
}
// 如果是目录那么进行递归调用
if(dir.isDirectory()) {
// 获取目录下的所有文件
File[] f = dir.listFiles();
// 进行递归调用,最后总会返回一个list
assert f != null;
for (File file : f) {
list.addAll(showListFile(file.getPath()));
}
}else {
// 不是目录直接添加进去,判断是否为xml文件
list.add(dir.getPath());
}
return list;
}
/**
* 读取txt文件内容
* @param file
* @return
*/
public static String txt2String(File file){
StringBuilder result = new StringBuilder();
try{
//构造一个BufferedReader类来读取文件
BufferedReader br = new BufferedReader(new FileReader(file));
String s = null;
//使用readLine方法一次读一行
while((s = br.readLine())!=null){
result.append(System.lineSeparator()).append(s);
}
br.close();
}catch(Exception e){
e.printStackTrace();
}
return result.toString();
}
/**
* 确定上传文件路径遥感数据 栅格
* @param file 文件
* @return
*/
public static String fileRsSaveType(File file) {
String name = file.getName();
String suffix = name.substring(name.indexOf("."));
// 判断是否为栅格数据
if (!suffix.contains("tif")) {
return null;
}
// GF1_PMS1_E116.8_N36.6_20190528_L1A0004026837-MSS1_ORTHO_MS.tif
String[] s = name.split("_");
// 卫星种类
String satelliteType = s[0];
// 传感器种类
String sensorType = s[1];
// 中心点经度
String lat = s[2];
// 中心点纬度
String lon = s[3];
// 时间
String time = s[4];
String year = time.substring(0, 4);
String month = time.substring(4, 6);
String day = time.substring(6);
// 产品号
String product = s[5];
String productLevel = product.substring(0, 3);
String productCode = product.substring(3);
// 种类
String type = s[6];
// 文件路径
String filePath = "/" + satelliteType + "/" + sensorType + "/" + productLevel + "/" + year + "/" + month + "/"
+ day + "/" + productCode + "/";
return filePath;
}
/**
* 矢量数据路径
* C:\Users\dong\Desktop\2018年山东省矢量数据\2018年山东省矢量数据\2018年动态\分县动态\山东.gdb\sa.gdb
* @param file
* @return
*/
public static String fileShpSavePath(File file) {
if (file.exists()) {
if (file.isFile()) {
String path = file.getPath();
String[] dirNames = path.split("\\\\");
StringBuffer sb = new StringBuffer();
int length = dirNames.length;
final int minLength = 5;
if (length >= minLength) {
for (int i = 5; i > 1; i--) {
sb.append("/").append(dirNames[length - i]);
}
return sb.toString();
}
}
}
return null;
}
public static Map<String, String> getUploadInfo(String info) {
final String statusFail = "fail";
final String status = "status";
ObjectMapper mapper = new ObjectMapper();
JsonNode resultNode = null;
Map<String, String> map = new HashMap<>();
try {
resultNode = mapper.readTree(info);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
if (!statusFail.equals(resultNode.path(status).asText())) {
String path = resultNode.path("path").asText();
String fileName = path.substring(path.lastIndexOf("/") + 1);
map.put("md5", resultNode.path("md5").asText());
map.put("mtime", getNowTimeStr());
map.put("path", path);
map.put("scene", resultNode.path("scene").asText());
map.put("size", resultNode.path("size").asText());
map.put("url", resultNode.path("url").asText());
map.put("fileName", fileName);
}
return map;
}
public static boolean checkFileSize(Long len, int size, String unit) {
double fileSize = 0;
if ("B".equals(unit.toUpperCase())) {
fileSize = (double) len;
} else if ("K".equals(unit.toUpperCase())) {
fileSize = (double) len / 1024;
} else if ("M".equals(unit.toUpperCase())) {
fileSize = (double) len / 1048576;
} else if ("G".equals(unit.toUpperCase())) {
fileSize = (double) len / 1073741824;
}
if (fileSize > size) {
return false;
}
return true;
}
public static void main(String[] args) {
String s = "C:/Users/dong/Desktop/2018年山东省矢量数据/2018年山东省矢量数据/2018年动态/分县动态/山东.gdb/a0000000a.gdbindexes";
fileShpSavePath(new File(s));
}
}

View File

@ -10,8 +10,8 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.xkrs.straw.utilsold.CommonConstant.INVERSEGEOGRAPHY_KEY; import static com.xkrs.straw.utilsnew.CommonConstant.INVERSEGEOGRAPHY_KEY;
import static com.xkrs.straw.utilsold.CommonConstant.INVERSEGEOGRAPHY_URL; import static com.xkrs.straw.utilsnew.CommonConstant.INVERSEGEOGRAPHY_URL;
import static com.xkrs.straw.utilsold.HttpClientUtils.sendHttpsGet; import static com.xkrs.straw.utilsold.HttpClientUtils.sendHttpsGet;
/** /**

View File

@ -1,16 +0,0 @@
package com.xkrs.straw.utilsold;
public class LocalNullUtils {
private LocalNullUtils() {
}
public static String formatNullValue(String value) {
return formatNullValue(value, "");
}
public static String formatNullValue(String value, String defaultValue) {
return null == value ? defaultValue : value;
}
}

View File

@ -1,152 +0,0 @@
package com.xkrs.straw.utilsold;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author wudong
* @date 2021/12/22 17:47
* @description
*/
public class XlsxUtil {
private static final Logger log = LoggerFactory.getLogger(XlsxUtil.class);
/**
* 获取表格内容, 第一行为表头第二行为数据最少两行
*
* @param is
* @return
*/
public static List<Map<Object, Object>> getXlsxData(InputStream is) {
List<Map<Object, Object>> list = new ArrayList<>();
Workbook wb = null;
try {
wb = new XSSFWorkbook(is);
} catch (IOException e) {
log.error("xlsx读取数据失败");
return list;
}
Sheet sheet = wb.getSheetAt(0);
int physicalNumberOfRows = sheet.getPhysicalNumberOfRows();
if (physicalNumberOfRows < 2) {
return list;
}
Row row = sheet.getRow(0);
int titNums = row.getPhysicalNumberOfCells();
Object[] tit = new String[titNums];
for (int j = 0; j < titNums; j++) {
Cell cell = row.getCell(j);
Object value = getValue(cell);
tit[j] = value;
}
for (int i = 1; i < physicalNumberOfRows; i++) {
Row contentRow = sheet.getRow(i);
int physicalNumberOfCells = contentRow.getPhysicalNumberOfCells();
Map<Object, Object> map = new HashMap<>(physicalNumberOfCells);
for (int j = 0; j < physicalNumberOfCells; j++) {
Cell cell = contentRow.getCell(j);
Object value = getValue(cell);
map.put(tit[j], value);
}
list.add(map);
}
return list;
}
/**
* 获取值
*
* @param cell
* @return
*/
private static Object getValue(Cell cell) {
CellType cellType = cell.getCellType();
Object value;
switch (cellType) {
case STRING:
value = cell.getStringCellValue().trim();
break;
case NUMERIC:
// 获取时间数据
if (DateUtil.isCellDateFormatted(cell)) {
Date tempValue = cell.getDateCellValue();
SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd");
value = simpleFormat.format(tempValue);
} else {
// 防止出现科学计数法
DecimalFormat df = new DecimalFormat("0");
value = df.format(cell.getNumericCellValue());
}
break;
case BOOLEAN:
value = cell.getBooleanCellValue();
break;
default:
value = null;
}
return value;
}
/**
* 按内容生成xlsx 不关闭输出流
*
* @param contextList 参数
* @param os
*/
public static void createXml(List<Map<String, String>> contextList, OutputStream os) {
// 提取表头
Set<String> strings = contextList.get(0).keySet();
Workbook wb = new XSSFWorkbook();
// 创建一页sheet
Sheet sheet = wb.createSheet();
// 创建表头
Row row = sheet.createRow(0);
int i = 0;
for (String key : strings) {
row.createCell(i++).setCellValue(key);
}
// 填写内容
for (int j = 0; j < contextList.size(); j++) {
Row ct = sheet.createRow(j + 1);
ct.setHeight((short) 1200);
Map<String, String> map = contextList.get(j);
for (int k = 0; k < map.size(); k++) {
ct.createCell(k).setCellValue(String.valueOf(map.get(row.getCell(k).getStringCellValue())));
}
}
try {
// 可以直接写入到zipOutputStream嘛需要转一下转为输入流再进行写入这样的话就需要把流输出不能在该地方关闭
wb.write(os);
wb.close();
System.out.println("finish");
} catch (IOException e) {
log.error("生成Xlsx失败IO操作失败 输出到IO失败", e);
}
}
/**
* 下载文件 单个
*
* @param contextList
* @param os
*/
public static void downloadXlsx(List<Map<String, String>> contextList, OutputStream os) {
createXml(contextList, os);
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}