import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Week;
import com.alibaba.fastjson.JSONObject;
import com.gic.haoban.manage.api.enums.NoticeMessageTypeEnum;
import com.gic.haoban.manage.api.enums.content.MaterialReportType;
import com.gic.haoban.manage.api.util.notify.NoticeMessageUtil;
import com.gic.haoban.manage.service.entity.TabHaobanPreDealLog;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.junit.Test;


public class test {
    private static final TimedCache<String, TestQo> cache = CacheUtil.newTimedCache(3000L);

    public static void main(String[] args) throws Exception {
// pages/hb/material/material-root/material-root?contentMaterialId=517690074188505121&storeId=ff8080818499a5f301849ceb9f870035&channelSource=5&clerkId=bcbfff6c8e2e40aaac795a99d0dde2aa
        String refUrl = "pages/hb/material/material-root/material-root?contentMaterialId=517690074188505121&storeId=ff8080818499a5f301849ceb9f870035&channelSource=5&clerkId=bcbfff6c8e2e40aaac795a99d0dde2aaADASDD";
        int indexOf = StringUtils.indexOf(refUrl, "clerkId=");
        if (indexOf != -1) {
            String clerkId = StringUtils.substring(refUrl, indexOf + 8, indexOf + 40);
            System.out.println(clerkId);
        }

        System.out.println(DateUtil.year(new Date()) + "-" + DateUtil.month(DateUtil.lastMonth()));
        System.out.println(DateUtil.year(new Date()) + "" + DateUtil.weekOfYear(DateUtil.lastWeek()));


        System.out.println("-----");
        int weekOfYear = DateUtil.weekOfYear(DateUtil.lastWeek());
        System.out.println(DateUtil.thisYear() + "-" + StringUtils.leftPad(weekOfYear + "", 2, "0"));
        // 月报
        int month = DateUtil.lastMonth().month() + 1;
        System.out.println(DateUtil.thisYear() + "-" + StringUtils.leftPad(month + "", 2, "0"));

        System.out.println("---------------------");
        DateTime dateTime = DateUtil.parse("2023-01-01", "yyyy-MM-dd");
        System.out.println(DateUtil.weekOfYear(dateTime));

        System.out.println(DateUtil.beginOfWeek(DateUtil.lastWeek()).toString("yyyy-MM-dd"));
        System.out.println(DateUtil.offset(DateUtil.lastWeek(), DateField.DAY_OF_WEEK, DateUtil.weekOfYear(DateUtil.lastWeek())));
        System.out.println(DateUtil.offsetWeek(new Date(), DateUtil.weekOfYear(DateUtil.lastWeek())));
        System.out.println(DateUtil.offsetWeek(new Date(), DateUtil.weekOfYear(DateUtil.lastWeek())));
        System.out.println(DateUtil.offsetWeek(new Date(), DateUtil.weekOfYear(DateUtil.lastWeek())));
        System.out.println(DateUtil.beginOfMonth(DateUtil.lastMonth()).toString("yyyy-MM-dd"));
    }


    @Test
    public void urlTest(){
        JSONObject params = new JSONObject();
        //params.put("clerkId", "300b60c7f8874ca2b9cc696ad6b6a480");
        String bizDate = DateUtil.beginOfWeek(DateUtil.lastWeek()).toString("yyyy-MM-dd");
        params.put("k", "ff8080816e216c04016e34294282004a_1_" + bizDate);
//        params.put("t", 1);
//        params.put("d", "04");
        String s = params.toJSONString();
        String s1 = NoticeMessageUtil.buildMiniAppUrl(NoticeMessageTypeEnum.MATERIAL_REPORT_NOTIFY, s);
        System.out.println("/pages/route/index?pageType=hbapp_material_report&data=".length());
        System.out.println(s1);
        System.out.println(s1.length());
    }

    @Test
    public void timeTest(){
        DateTime now = DateUtil.parse("2023-04-09 08:00:00", "yyyy-MM-dd HH:mm:ss");
        int hour_sec = 30 * 60;
        DateTime temp = cn.hutool.core.date.DateUtil.offsetSecond(now, -(hour_sec));
        int hour = DateUtil.hour(temp, true);
        System.out.println(hour);
        Week week = DateUtil.dayOfWeekEnum(new Date());
        System.out.println(week);
        if (Week.MONDAY.equals(week)) {
            System.out.println("周一");
        }
    }

}
