package com.fs.course;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.fs.common.utils.spring.SpringUtils;
import com.fs.course.mapper.FsUserVideoMapper;
import com.fs.qw.vo.QwSopCourseFinishTempSetting;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONArray;
import org.json.JSONObject;
import com.obs.services.ObsClient;
import com.obs.services.exception.ObsException;
import com.obs.services.model.ProgressListener;
import com.obs.services.model.ProgressStatus;
import com.obs.services.model.PutObjectRequest;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

@Slf4j
public class HuaweiCloudTest {

    public static void main(String[] args) {
       String a = "https://h5.cdwjyyh.com/courseh5/pages/course/learning?course={\"companyId\":170,\"companyUserId\":6824,\"corpId\":\"ww5a88c4f879f204c5\",\"courseId\":79,\"linkType\":0,\"qwExternalId\":8334754,\"qwUserId\":\"18716\",\"videoId\":798}".replace("https://h5.cdwjyyh.com","");
        System.out.println(a);
    }

    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());
    }

}
