From e5b3e3492a7d5f079cad2ca5958a724cabfec401 Mon Sep 17 00:00:00 2001 From: whycxzp <glperry@163.com> Date: 星期六, 28 六月 2025 21:22:42 +0800 Subject: [PATCH] 文档类型管理更新 --- src/main/java/com/whyc/util/ActionUtil.java | 81 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/whyc/util/ActionUtil.java b/src/main/java/com/whyc/util/ActionUtil.java index 3b2bd86..d2820e9 100644 --- a/src/main/java/com/whyc/util/ActionUtil.java +++ b/src/main/java/com/whyc/util/ActionUtil.java @@ -18,15 +18,23 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.YearMonth; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + import com.whyc.pojo.db_user.User; public class ActionUtil { public static String time_yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss"; public static String time_yyyyMMdd = "yyyy-MM-dd"; + public static String time_yyyyMM = "yyyy-MM"; + public static String time_yyyy_MM = "yyyy_MM"; public static String time_yyyyMMdd_HH_mm_ss = "yyyy-MM-dd_HH_mm_ss"; public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static SimpleDateFormat sdfwithOutday = new SimpleDateFormat("yyyy_MM"); @@ -337,7 +345,6 @@ cal.set(Calendar.DAY_OF_MONTH,day); if(type==1){ return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"00:00:00"; - } else if(type==2){ return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"09:00:00"; }else if(type==3){ @@ -637,5 +644,77 @@ } return lang; } + //涓ゆ椂闂翠箣闂寸殑骞存湀闆嗗悎 + public static List<String> getDateListBetweenDates(Date startTime, Date endTime) { + // 鎸囧畾寮�濮嬫棩鏈熷拰缁撴潫鏃ユ湡 + LocalDate startDate = LocalDate.of(startTime.getYear() + 1900, startTime.getMonth() + 1, startTime.getDay()); // 绀轰緥璧峰鏃ユ湡 + LocalDate endDate = LocalDate.of(endTime.getYear() + 1900, endTime.getMonth() + 1, endTime.getDay()); // 绀轰緥缁撴潫鏃ユ湡 + List<String> dateList = new ArrayList<>(); + LocalDate currentDate = startDate; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(ActionUtil.time_yyyy_MM); + while (!currentDate.isAfter(endDate)) { + String formattedDate = currentDate.format(formatter); + dateList.add(formattedDate); + currentDate = currentDate.plusMonths(1); + } + return dateList; + } + // 鍖归厤 "_" 鍚庤窡涓�涓瓧姣嶏紙灏忓啓鎴栧ぇ鍐欙級 + public static String toCamelCase(String input) { + // 鍖归厤 "_" 鍚庤窡涓�涓瓧姣嶏紙灏忓啓鎴栧ぇ鍐欙級 + Pattern pattern = Pattern.compile("_(\\w)"); + Matcher matcher = pattern.matcher(input); + StringBuffer result = new StringBuffer(); + + while (matcher.find()) { + // 灏嗗尮閰嶅埌鐨勫瓧姣嶈浆涓哄ぇ鍐欙紝骞舵浛鎹㈡帀鍓嶉潰鐨勪笅鍒掔嚎 + matcher.appendReplacement(result, matcher.group(1).toUpperCase()); + } + matcher.appendTail(result); + + return result.toString(); + } + //缁橫ap<String, Map<String,List<String>>>鍘婚噸鍚堝苟 + public static Map<String, List<String>> getMergeMap(Map<String, Map<String,List<String>>> allTimeMap) { + Map<String, List<String>> mergedMap = new HashMap<>(); + for (Map<String, List<String>> innerMap : allTimeMap.values()) { + for (Map.Entry<String, List<String>> entry : innerMap.entrySet()) { + String key = entry.getKey(); + List<String> valueList = entry.getValue(); + + mergedMap.computeIfAbsent(key, k -> new ArrayList<>()) + .addAll(valueList); + } + } + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + // 鍘婚噸锛堜繚鐣欓『搴忥級 + mergedMap.forEach((key, list) -> { + Set<String> seen = new LinkedHashSet<>(); + list.removeIf(s -> !seen.add(s)); + // 鎺掑簭锛氬皢瀛楃涓茶В鏋愪负 LocalDateTime 鍚庢帓搴� + list.sort((s1, s2) -> { + LocalDateTime d1 = LocalDateTime.parse(s1, formatter); + LocalDateTime d2 = LocalDateTime.parse(s2, formatter); + return d1.compareTo(d2); + }); + }); + return mergedMap; + } + public static void main(String[] args) throws ParseException { + /*List<String> dateList =getDateListBetweenDates(ActionUtil.sdf.parse("2025-01-01 00:00:00"),new Date()); + for (String date : dateList) { + System.out.println(date); + }*/ + //System.out.println(toCamelCase("user_name_and_age")); + /*Date time1=getDateAdd(new Date(),-10); + System.out.println(ActionUtil.sdf.format(time1));*/ + Map<String, List<String>> map = new HashMap<>(); + map.put("key1", Stream.of("value1", "value2").collect(Collectors.toList())); + map.put("key2", Stream.of("value3", "value4").collect(Collectors.toList())); + String result = map.values().stream() + .flatMap(List::stream) + .collect(Collectors.joining(",")); + System.out.println( result); + } } -- Gitblit v1.9.1