123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- package com.onemap.api.util;
- import com.onemap.common.core.utils.StringUtils;
- import java.io.*;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipInputStream;
- import java.util.zip.ZipOutputStream;
- /**
- * @author : wanger
- * @createDate: 2025/2/18
- * @description:公用工具类
- **/
- public class utils {
- /**
- * 自治区成果包查询需要的plantype
- *
- * @param ghlx
- * @return
- */
- public static Integer getPlanType(String ghlx) {
- switch (ghlx) {
- case "总体规划":
- return 1;
- case "村庄规划":
- return 2;
- case "报批项目":
- return 3;
- case "总体规划(对部)":
- return 4;
- case "详细规划":
- return 5;
- case "专项规划":
- return 6;
- case "乡镇苏木国土空间规划":
- return 7;
- default:
- return 1;
- }
- }
- /**
- * 市级成果接口需要的plantype
- *
- * @param ghlx
- * @return
- */
- public static Integer getPlanTypeForSj(String ghlx) {
- switch (ghlx) {
- case "评估成果":
- return 1;
- case "规划成果":
- return 2;
- case "总体规划":
- return 3;
- case "详细规划":
- return 4;
- case "专项规划":
- return 5;
- case "报批项目":
- return 6;
- case "苏木乡镇规划":
- return 7;
- case "城市更新":
- return 8;
- case "村庄规划":
- return 9;
- default:
- return 0;
- }
- }
- /**
- * 判断文件夹是否存在,不存在则创建
- *
- * @param folderpath
- */
- public static void makedir(String folderpath) {
- File folderFile = new File(folderpath);
- if (!folderFile.exists()) {
- try {
- Files.createDirectories(Paths.get(folderpath));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- /**
- * 控制台打印
- *
- * @param info
- */
- public static void loginfo(String info) {
- System.out.println(info);
- }
- /**
- * 合并zip分片数据包
- *
- * @param fileNames
- * @param outputFileName
- * @throws IOException
- */
- public static void mergeZipFiles(List<String> fileNames, String outputFileName) throws IOException {
- FileOutputStream fos = new FileOutputStream(outputFileName);
- for (String fileName : fileNames) {
- File cur = new File(fileName);
- byte[] buffer = Files.readAllBytes(Paths.get(fileName));
- fos.write(buffer, 0, buffer.length);
- }
- fos.flush();
- fos.close();
- }
- /**
- * 读取txt文本文件
- *
- * @param filepath
- * @return Map<String, String>
- */
- public static Map<String, String> readTxt(String filepath) {
- Map<String, String> resMap = new HashMap<>();
- try {
- File file = new File(filepath);
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "GBK"));
- String line;
- while ((line = reader.readLine()) != null) {
- if (StringUtils.isNotEmpty(line)) {
- String[] curline = line.split("=");
- resMap.put(curline[0], curline[1]);
- }
- }
- reader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return resMap;
- }
- /**
- * 搜索文件夹下指定文件名结尾的文件 默认返回第一个
- *
- * @param filepath
- * @param endsWith
- * @return String
- */
- public static String FileSearch(String filepath, String endsWith) {
- File folder = new File(filepath);
- File[] files = folder.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(endsWith);
- }
- });
- if (files != null) {
- return files[0].getAbsolutePath();
- } else {
- return null;
- }
- }
- /**
- * 正则表达式 获取参数占位信息
- *
- * @param str
- * @return
- */
- public static List<String> extractUniqueMatches(String str) {
- // 定义正则表达式
- Pattern regex = Pattern.compile("\\{.*?\\}", Pattern.CASE_INSENSITIVE);
- Matcher matcher = regex.matcher(str);
- // 用于存储匹配结果的集合
- Set<String> uniqueMatches = new HashSet<>();
- // 查找所有匹配项
- while (matcher.find()) {
- uniqueMatches.add(matcher.group());
- }
- // 将Set转换为List并返回
- return new ArrayList<>(uniqueMatches);
- }
- }
|