package com.api.customization.qc3189074.util;

import com.engine.kq.biz.KQFormatData;
import com.wbi.util.Util;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Map;

public class ThreadUtil implements Runnable  {
    Map<String,Map<String,Object>> scheduleMap;
    public ThreadUtil(Map<String,Map<String,Object>> scheduleMap) {
        this.scheduleMap = scheduleMap;
    }
    @Override
    public void run() {
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        for (Map.Entry<String, Map<String,Object>> entry : scheduleMap.entrySet()) {
            String key = entry.getKey();
            Map<String,Object> shceduleData = entry.getValue();
            String validatefrom = Util.null2String(shceduleData.get("validatefrom"));
            String validateto = Util.null2String(shceduleData.get("validateto"));
            LocalDate fromLocal = LocalDate.parse(validatefrom);
            LocalDate toLocal = LocalDate.parse(validateto);
            if(!toLocal.isBefore(fromLocal)){
                long betweenDays = toLocal.toEpochDay() - fromLocal.toEpochDay();
                for (int j = 0; j <= betweenDays; j++) {
                    LocalDate curLocalDate = fromLocal.plusDays(j);
                    String shiftDate = curLocalDate.format(dateFormatter);
                    new KQFormatData().formatKqDateByLock(key, shiftDate,17);
                }
            }
        }
    }
}
