| | |
| | | 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 { |
| | |
| | | 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){ |
| | |
| | | |
| | | return result.toString(); |
| | | } |
| | | //给Map<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")); |
| | | //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); |
| | | } |
| | | } |