1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package com.fs.course;
- import com.fs.common.core.domain.R;
- import com.fs.course.config.RedPacketConfig;
- import lombok.extern.slf4j.Slf4j;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.ZoneId;
- import java.time.format.DateTimeFormatter;
- import java.util.*;
- @Slf4j
- public class HuaweiCloudTest {
- public static void main(String[] args) {
- RedPacketConfig config = new RedPacketConfig();
- config.setIsNew(1);
- R result = new R();
- // 根据 isNew 判断使用哪种发红包方式
- if (config.getIsNew() != null && config.getIsNew() == 1) {
- result = test1();
- } else {
- result= test2();
- }
- result.put("isNew",config.getIsNew());
- System.out.println(result);
- }
- public static R test1(){
- return R.ok().put("code",1);
- }
- public static R test2(){
- return R.ok().put("data",2);
- }
- public static String extractPathByRegex(String urlString) {
- // ^https?:// 匹配 http:// 或 https:// 开头
- // [^/]+ 匹配域名部分(直到遇到第一个 '/')
- // / 紧跟一个 '/'
- // 最后将这段内容替换为空字符串
- return urlString.replaceAll("^https?://[^/]+/", "");
- }
- public static String updateUrlPrefix(String url) {
- final String oldPrefix = "https://obs.ylrztop.com";
- final String newPrefix = "https://rtobs.ylrztop.com";
- // 判断是否以 oldPrefix 开头,如果是,则进行替换
- if (url.startsWith(oldPrefix)) {
- // 去掉 oldPrefix 前缀,然后拼上 newPrefix
- return newPrefix + url.substring(oldPrefix.length());
- }
- // 如果不是以 oldPrefix 开头,则原样返回
- return url;
- }
- public static Date convertStringToDate(String dateString,String pattern) {
- if (dateString == null || dateString.isEmpty()) {
- return null;
- }
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
- LocalDateTime localDateTime;
- LocalDate localDate;
- // 先解析成 LocalDate(只含年月日)
- if (pattern.equals("yyyy-MM-dd")){
- // 先解析成 LocalDate(只含年月日)
- localDate = LocalDate.parse(dateString, formatter);
- // 将 LocalDate 转为当天 00:00:00 的 LocalDateTime
- localDateTime = localDate.atStartOfDay();
- }else {
- localDateTime = LocalDateTime.parse(dateString, formatter);
- }
- return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
- }
- }
|