package com.multictrl.modules.job.utils;

/**
 * 中文转换工具
 *
 * @author Sdy
 * @since 1.0.0 2025/7/24
 */
public class CronToChinese {
    /**
     * 将 Cron 表达式转换为中文描述
     */
    public static String convert(Integer year, Integer month, String days, Integer hour, Integer minute, Integer cronType) {
        switch (cronType) {
            case 1:
                return year + "年" + month + "月" + days + "日" + hour + "点" + minute + "分执行";
            case 2:
                return "每天" + hour + "点" + minute + "分执行";
            case 3:
                String weekday = "";
                String[] split = days.split(",");
                for (String s : split) {
                    if (s.equals("1")) {
                        weekday += "周一、";
                    } else if (s.equals("2")) {
                        weekday += "周二、";
                    } else if (s.equals("3")) {
                        weekday += "周三、";
                    } else if (s.equals("4")) {
                        weekday += "周四、";
                    } else if (s.equals("5")) {
                        weekday += "周五、";
                    } else if (s.equals("6")) {
                        weekday += "周六、";
                    } else if (s.equals("7")) {
                        weekday += "周日、";
                    }
                }
                return "每周" + weekday.substring(0, weekday.length() - 1) + "的" + hour + "点" + minute + "分执行";
            case 4:
                String monthday = "";
                String[] day = days.split(",");
                for (String s : day) {
                    monthday += s + "号、";
                }
                return "每月" + monthday.substring(0, monthday.length() - 1) + "的" + hour + "点" + minute + "分执行";
            default:
                return null;
        }
    }

    // 示例用法
    /*public static void main(String[] args) {
        System.out.println(convert(2025, 7, "24", 3, 23, 1));
        // 输出：2025年7月每月24日的上午3点23分执行

        System.out.println(convert(0, 0, "", 12, 29, 2));
        // 输出：每天中午12点29分执行

        System.out.println(convert(0, 0, "1,3,7", 11, 55, 3));
        // 输出：每周一、周三、周日上午11点55分执行

        System.out.println(convert(0, 0, "1,3,5", 12, 56, 4));
        // 输出：每月1日、3日和5日的中午12点56分执行
    }*/
}
