package com.njcn.executor.utils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.common.pojo.constant.BizParamConstant;
import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Objects;

/**
 * pqs
 *
 * @author cdf
 * @date 2022/11/2
 */
@Slf4j
public class CommonExecutorUtils {

    public static String prepareTimeDeal(String command){
        if(StrUtil.isBlank(command)){
            log.error(LocalDateTime.now()+"xxl调度任务参数未设置");
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        if (Objects.equals(BizParamConstant.STAT_BIZ_DAY,command)){
            calendar.add(Calendar.DAY_OF_MONTH,-1);
        } else if (Objects.equals(BizParamConstant.STAT_BIZ_MONTH,command)){
            calendar.set(Calendar.DAY_OF_MONTH, 1);
        }
        log.info("job调度时间:"+sdf.format(calendar.getTime()));
        return sdf.format(calendar.getTime());
    }
}
