HuaweiCloudTest.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.fs.course;
  2. import com.fs.common.core.domain.R;
  3. import com.fs.course.config.RedPacketConfig;
  4. import lombok.extern.slf4j.Slf4j;
  5. import java.time.LocalDate;
  6. import java.time.LocalDateTime;
  7. import java.time.ZoneId;
  8. import java.time.format.DateTimeFormatter;
  9. import java.util.*;
  10. @Slf4j
  11. public class HuaweiCloudTest {
  12. public static void main(String[] args) {
  13. RedPacketConfig config = new RedPacketConfig();
  14. config.setIsNew(1);
  15. R result = new R();
  16. // 根据 isNew 判断使用哪种发红包方式
  17. if (config.getIsNew() != null && config.getIsNew() == 1) {
  18. result = test1();
  19. } else {
  20. result= test2();
  21. }
  22. result.put("isNew",config.getIsNew());
  23. System.out.println(result);
  24. }
  25. public static R test1(){
  26. return R.ok().put("code",1);
  27. }
  28. public static R test2(){
  29. return R.ok().put("data",2);
  30. }
  31. public static String extractPathByRegex(String urlString) {
  32. // ^https?:// 匹配 http:// 或 https:// 开头
  33. // [^/]+ 匹配域名部分(直到遇到第一个 '/')
  34. // / 紧跟一个 '/'
  35. // 最后将这段内容替换为空字符串
  36. return urlString.replaceAll("^https?://[^/]+/", "");
  37. }
  38. public static String updateUrlPrefix(String url) {
  39. final String oldPrefix = "https://obs.ylrztop.com";
  40. final String newPrefix = "https://rtobs.ylrztop.com";
  41. // 判断是否以 oldPrefix 开头,如果是,则进行替换
  42. if (url.startsWith(oldPrefix)) {
  43. // 去掉 oldPrefix 前缀,然后拼上 newPrefix
  44. return newPrefix + url.substring(oldPrefix.length());
  45. }
  46. // 如果不是以 oldPrefix 开头,则原样返回
  47. return url;
  48. }
  49. public static Date convertStringToDate(String dateString,String pattern) {
  50. if (dateString == null || dateString.isEmpty()) {
  51. return null;
  52. }
  53. DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
  54. LocalDateTime localDateTime;
  55. LocalDate localDate;
  56. // 先解析成 LocalDate(只含年月日)
  57. if (pattern.equals("yyyy-MM-dd")){
  58. // 先解析成 LocalDate(只含年月日)
  59. localDate = LocalDate.parse(dateString, formatter);
  60. // 将 LocalDate 转为当天 00:00:00 的 LocalDateTime
  61. localDateTime = localDate.atStartOfDay();
  62. }else {
  63. localDateTime = LocalDateTime.parse(dateString, formatter);
  64. }
  65. return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
  66. }
  67. }