package com.shanghaichengdi.ghjgitem;

import com.alibaba.fastjson.JSONObject;
import com.shanghaigeography.Util.DateUtils;
import org.junit.jupiter.api.Test;

import java.sql.Date;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.HashMap;


public class JSONString {
    @Test
    public void test(){
        HashMap<String, String> map = new HashMap<>();
        map.put("shipId","CN20204209331");
        System.out.println(JSONObject.toJSONString(map));
    }

    @Test
    public void testDm(){

        Date fistDay = Date.valueOf("2025-01-01");

        // bayonet_dynamic.GPSINFO_HISTORY
/*        while (fistDay.before(Date.valueOf("2026-1-1"))){
            String partitionName = "GPSINFO_HISTORY_" + DateUtils.dateToString(fistDay, DateUtils.DATE_FORMAT_11);
            // fistDay下一天赋值给endDateStr
            Date endDay = new Date(fistDay.getTime() + 24 * 60 * 60 * 1000);
            String endDateStr = DateUtils.dateToString(endDay, DateUtils.DATE_FORMAT_19);

            String tablespaceName = "BAYONET_DYNAMIC_GPSINFO_HISTORY_" + DateUtils.dateToString(fistDay, "yyyyMM");

            String sql = String.format(
                "ALTER TABLE bayonet_dynamic.GPSINFO_HISTORY ADD PARTITION %s VALUES LESS THAN ('%s') TABLESPACE %s;",
                partitionName,
                endDateStr,
                tablespaceName
            );
            System.out.println(sql + "\n");

            fistDay = endDay;
        }*/

        // BAYONET_BASICS.C_CB_SHIP_EEP_REPORT_REC
/*        while (fistDay.before(Date.valueOf("2026-1-1"))){
            String partitionName = "C_CB_SHIP_EEP_REPORT_REC_" + DateUtils.dateToString(fistDay, DateUtils.DATE_FORMAT_11);
            // fistDay下一天赋值给endDateStr
            Date endDay = new Date(fistDay.getTime() + 24 * 60 * 60 * 1000);
            String endDateStr = DateUtils.dateToString(endDay, DateUtils.DATE_FORMAT_19);

            String tablespaceName = "BAYONET_BASICS_C_CB_SHIP_EEP_REPORT_REC_" + DateUtils.dateToString(fistDay, "yyyyMM");

            String sql = String.format(
                "ALTER TABLE BAYONET_BASICS.C_CB_SHIP_EEP_REPORT_REC ADD PARTITION %s VALUES LESS THAN ('%s') TABLESPACE %s;",
                partitionName,
                endDateStr,
                tablespaceName
            );
            System.out.println(sql + "\n");

            fistDay = endDay;
        }*/


        // C_CB_ON_SHIP_CREW_REC
/*        while (fistDay.before(Date.valueOf("2026-1-1"))){
            String partitionName = "C_CB_ON_SHIP_CREW_REC_" + DateUtils.dateToString(fistDay, DateUtils.DATE_FORMAT_11);
            // fistDay下一天赋值给endDateStr
            Date endDay = new Date(fistDay.getTime() + 24 * 60 * 60 * 1000);
            String endDateStr = DateUtils.dateToString(endDay, DateUtils.DATE_FORMAT_19);

            String tablespaceName = "BAYONET_BASICS_C_CB_ON_SHIP_CREW_REC_" + DateUtils.dateToString(fistDay, "yyyyMM");

            String sql = String.format(
                "ALTER TABLE BAYONET_BASICS.C_CB_ON_SHIP_CREW_REC ADD PARTITION %s VALUES LESS THAN ('%s') TABLESPACE %s;",
                partitionName,
                endDateStr,
                tablespaceName
            );
            System.out.println(sql + "\n");

            fistDay = endDay;
        }*/

        // C_CB_CARGO_DECLARE_REC
        while (fistDay.before(Date.valueOf("2026-1-1"))){
            String partitionName = "C_CB_CARGO_DECLARE_REC_" + DateUtils.dateToString(fistDay, DateUtils.DATE_FORMAT_11);
            // fistDay下一天赋值给endDateStr
            Date endDay = new Date(fistDay.getTime() + 24 * 60 * 60 * 1000);
            String endDateStr = DateUtils.dateToString(endDay, DateUtils.DATE_FORMAT_19);

            String tablespaceName = "BAYONET_BASICS_C_CB_CARGO_DECLARE_REC_" + DateUtils.dateToString(fistDay, "yyyyMM");

            String sql = String.format(
                "ALTER TABLE BAYONET_BASICS.C_CB_CARGO_DECLARE_REC ADD PARTITION %s VALUES LESS THAN ('%s') TABLESPACE %s;",
                partitionName,
                endDateStr,
                tablespaceName
            );
            System.out.println(sql + "\n");

            fistDay = endDay;
        }
    }
}
