package com.smppw.modaq.application.components;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.smppw.modaq.application.util.EmailUtil;
import com.smppw.modaq.common.conts.EmailTypeConst;
import com.smppw.modaq.common.conts.PatternConsts;
import com.smppw.modaq.common.enums.ReportType;
import com.smppw.modaq.domain.dto.report.ReportAssetAllocationDTO;
import com.smppw.modaq.infrastructure.util.DateUtils;

import java.time.YearMonth;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


public final class ReportParseUtils {
    /**
     * 基金基本信息表格列名称
     */
    public static final List<String> FUND_INFO_COLUMN_NAMES = ListUtil.list(false);
    /**
     * 行业配置的表格列名称
     */
    public static final List<String> INDUSTRY_COLUMN_NAMES = ListUtil.list(false);
    /**
     * 份额变动的表格列名称
     */
    public static final List<String> SHARE_CHANGE_COLUMN_NAMES = ListUtil.list(false);
    /**
     * 主要财务指标识别列名称
     */
    public static final List<String> FINANCIAL_INDICATORS_COLUMN_NAMES = ListUtil.list(false);
    /**
     * 资产配置明细和大类关系映射
     */
    public static final Map<String, String> ASSET_ALLOCATION_TYPE_MAPPER = MapUtil.newHashMap(32, true);

    static {
        FUND_INFO_COLUMN_NAMES.add("基金名称");
        FUND_INFO_COLUMN_NAMES.add("基金编码");
        FUND_INFO_COLUMN_NAMES.add("基金运作方式");
        FUND_INFO_COLUMN_NAMES.add("基金成立日期");
        FUND_INFO_COLUMN_NAMES.add("基金管理人");
        FUND_INFO_COLUMN_NAMES.add("基金托管人");
        FUND_INFO_COLUMN_NAMES.add("投资顾问");
        FUND_INFO_COLUMN_NAMES.add("期末基金总份额/期末基金实缴总额");
        FUND_INFO_COLUMN_NAMES.add("基金到期日期");
        FUND_INFO_COLUMN_NAMES.add("投资目标");
        FUND_INFO_COLUMN_NAMES.add("投资策略");
        FUND_INFO_COLUMN_NAMES.add("业绩比较基准");
        FUND_INFO_COLUMN_NAMES.add("风险收益特征");
        FUND_INFO_COLUMN_NAMES.add("信息披露报告是否经托管机构复核");

        // 财务指标
        FINANCIAL_INDICATORS_COLUMN_NAMES.add("期末基金净资产");
        FINANCIAL_INDICATORS_COLUMN_NAMES.add("期末基金资产净值");

        FINANCIAL_INDICATORS_COLUMN_NAMES.add("报告期期末单位净值");
        FINANCIAL_INDICATORS_COLUMN_NAMES.add("期末基金份额净值");

        FINANCIAL_INDICATORS_COLUMN_NAMES.add("本期利润");
        FINANCIAL_INDICATORS_COLUMN_NAMES.add("本期已实现收益");
        FINANCIAL_INDICATORS_COLUMN_NAMES.add("期末可供分配利润");
        FINANCIAL_INDICATORS_COLUMN_NAMES.add("期末可供分配基金份额利润");
        FINANCIAL_INDICATORS_COLUMN_NAMES.add("基金份额累计净值增长率");

        // 中国证监会行业标准
        INDUSTRY_COLUMN_NAMES.add("农、林、牧、渔业");
        INDUSTRY_COLUMN_NAMES.add("采矿业");
        INDUSTRY_COLUMN_NAMES.add("制造业");
        INDUSTRY_COLUMN_NAMES.add("电力、热力、燃气及水生产和供应业");
        INDUSTRY_COLUMN_NAMES.add("建筑业");
        INDUSTRY_COLUMN_NAMES.add("批发和零售业");
        INDUSTRY_COLUMN_NAMES.add("交通运输、仓储和邮政业");
        INDUSTRY_COLUMN_NAMES.add("住宿和餐饮业");
        INDUSTRY_COLUMN_NAMES.add("信息传输、软件和信息技术服务业");
        INDUSTRY_COLUMN_NAMES.add("金融业");
        INDUSTRY_COLUMN_NAMES.add("房地产业");
        INDUSTRY_COLUMN_NAMES.add("租赁和商务服务业");
        INDUSTRY_COLUMN_NAMES.add("科学研究和技术服务业");
        INDUSTRY_COLUMN_NAMES.add("水利、环境和公共设施管理业");
        INDUSTRY_COLUMN_NAMES.add("居民服务、修理和其他服务业");
        INDUSTRY_COLUMN_NAMES.add("教育");
        INDUSTRY_COLUMN_NAMES.add("卫生和社会工作");
        INDUSTRY_COLUMN_NAMES.add("文化、体育和娱乐业");
        INDUSTRY_COLUMN_NAMES.add("综合");

        INDUSTRY_COLUMN_NAMES.add("港股通");

        // 以下为国际标准
        INDUSTRY_COLUMN_NAMES.add("能源");
        INDUSTRY_COLUMN_NAMES.add("原材料");
        INDUSTRY_COLUMN_NAMES.add("材料");
        INDUSTRY_COLUMN_NAMES.add("工业");
        INDUSTRY_COLUMN_NAMES.add("可选消费品");
        INDUSTRY_COLUMN_NAMES.add("非日常生活消费品");
        INDUSTRY_COLUMN_NAMES.add("必须消费品");
        INDUSTRY_COLUMN_NAMES.add("日常消费品");
        INDUSTRY_COLUMN_NAMES.add("医疗保健");
        INDUSTRY_COLUMN_NAMES.add("金融");
        INDUSTRY_COLUMN_NAMES.add("信息技术");
        INDUSTRY_COLUMN_NAMES.add("通讯服务");
        INDUSTRY_COLUMN_NAMES.add("电信服务");
        INDUSTRY_COLUMN_NAMES.add("公用事业");
        INDUSTRY_COLUMN_NAMES.add("房地产");

        // 份额变动表格识别列
        SHARE_CHANGE_COLUMN_NAMES.add("报告期期初基金份额总额");
        SHARE_CHANGE_COLUMN_NAMES.add("减:报告期期间基金总赎回份额");
        SHARE_CHANGE_COLUMN_NAMES.add("期末基金总份额/期末基金实缴总额");
        SHARE_CHANGE_COLUMN_NAMES.add("报告期期间基金拆分变动份额");
        SHARE_CHANGE_COLUMN_NAMES.add("报告期期间基金总申购份额");

        // 资产配置
        ASSET_ALLOCATION_TYPE_MAPPER.put("银行存款", "现金类资产");
        // 境内未上市、未挂牌公司股权投资
        ASSET_ALLOCATION_TYPE_MAPPER.put("股权投资", "境内未上市、未挂牌公司股权投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("其中:优先股", "境内未上市、未挂牌公司股权投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("其他股权类投资", "境内未上市、未挂牌公司股权投资");
        // 上市公司定向增发投资
        ASSET_ALLOCATION_TYPE_MAPPER.put("上市公司定向增发股票投资", "上市公司定向增发投资");
        // 新三板投资
        ASSET_ALLOCATION_TYPE_MAPPER.put("新三板挂牌企业投资", "新三板投资");
        // 境内证券投资规模
        ASSET_ALLOCATION_TYPE_MAPPER.put("结算备付金", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("存出保证金", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("股票投资", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("债券投资", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("其中:银行间市场债券", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("其中:利率债", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("其中:信用债", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("资产支持证券", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("基金投资(公募基金)", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("其中:货币基金", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("期货及衍生品交易保证金", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("买入返售金融资产", "境内证券投资规模");
        ASSET_ALLOCATION_TYPE_MAPPER.put("其他证券类标的", "境内证券投资规模");
        // 资管计划投资
        ASSET_ALLOCATION_TYPE_MAPPER.put("商业银行理财产品投资", "资管计划投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("信托计划投资", "资管计划投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("基金公司及其子公司资产管理计划投资", "资管计划投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("保险资产管理计划投资", "资管计划投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("证券公司及其子公司资产管理计划投资", "资管计划投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("期货公司及其子公司资产管理计划投资", "资管计划投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("私募基金产品投资", "资管计划投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("未在协会备案的合伙企业份额", "资管计划投资");
        // 另类投资
        ASSET_ALLOCATION_TYPE_MAPPER.put("另类投资", "另类投资");
        // 境内债权类投资
        ASSET_ALLOCATION_TYPE_MAPPER.put("银行委托贷款规模", "境内债权类投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("信托贷款", "境内债权类投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("应收账款投资", "境内债权类投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("各类受(收)益权投资", "境内债权类投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("票据(承兑汇票等)投资", "境内债权类投资");
        ASSET_ALLOCATION_TYPE_MAPPER.put("其他债权投资", "境内债权类投资");
        // 境外投资
        ASSET_ALLOCATION_TYPE_MAPPER.put("境外投资", "境外投资");
        // 其他资产
        ASSET_ALLOCATION_TYPE_MAPPER.put("其他资产", "其他资产");
        // 基金负债情况
        ASSET_ALLOCATION_TYPE_MAPPER.put("债券回购总额", "基金负债情况");
        ASSET_ALLOCATION_TYPE_MAPPER.put("融资、融券总额", "基金负债情况");
        ASSET_ALLOCATION_TYPE_MAPPER.put("其中:融券总额", "基金负债情况");
        ASSET_ALLOCATION_TYPE_MAPPER.put("银行借款总额", "基金负债情况");
        ASSET_ALLOCATION_TYPE_MAPPER.put("其他融资总额", "基金负债情况");
    }

    /**
     * 构建基金资产配置信息
     *
     * @param fileId      文件id
     * @param detail      资产类型（清理过特殊字符的字符串）
     * @param mvAndRemark 市值或备注
     * @param dtos        结果数据
     */
    public static void buildAssetAllocation(Integer fileId, String detail, String mvAndRemark, List<ReportAssetAllocationDTO> dtos) {
        if (StrUtil.isBlank(mvAndRemark)) {
            return;
        }
        // 资产大类
        String assetType = ReportParseUtils.ASSET_ALLOCATION_TYPE_MAPPER.get(detail);
        if (StrUtil.contains(mvAndRemark, "#")) {
            // 有#表示有备注，而且可能有多个，多个用分号分隔的.
            List<String> marketValueAndRemarks = StrUtil.split(mvAndRemark, ";");
            for (String mr : marketValueAndRemarks) {
                if (StrUtil.isBlank(mr)) {
                    continue;
                }
                List<String> mrs = StrUtil.split(mr, "#");
                ReportAssetAllocationDTO dto = new ReportAssetAllocationDTO(fileId);
                dto.setAssetType(assetType);
                dto.setAssetDetails(detail);
                dto.setMarketValue(mrs.get(1));
                dto.setRemark(mrs.get(0));
                dtos.add(dto);
            }
        } else {
            ReportAssetAllocationDTO dto = new ReportAssetAllocationDTO(fileId);
            dto.setAssetType(assetType);
            dto.setAssetDetails(detail);
            dto.setMarketValue(mvAndRemark);
            dtos.add(dto);
        }
    }

    /**
     * 数据清洗，替换圆括号，包含中文或英文的圆括号
     *
     * @param value /
     * @return /
     */
    public static String cleaningValue(Object value) {
        return cleaningValue(value, true);
    }

    /**
     * 数据清洗，替换圆括号，包含中文或英文的圆括号
     *
     * @param value     /
     * @param replaceEn /
     * @return /
     */
    public static String cleaningValue(Object value, boolean replaceEn) {
        return cleaningValue(value, true, replaceEn);
    }

    /**
     * 数据简单清洗，并全部转为字符串类型
     *
     * @param value              待清洗的数据
     * @param replaceParentheses 是否替换圆括号
     * @return /
     */
    public static String cleaningValue(Object value, boolean replaceParentheses, boolean replaceEn) {
        String fieldValue = StrUtil.toStringOrNull(value);
        if (!StrUtil.isNullOrUndefined(fieldValue)) {
            // 特殊字符替换，空格替换为空字符
            fieldValue = fieldValue
                    .replaceAll("\r", StrUtil.EMPTY)
                    .replaceAll("；", ";")
                    .replaceAll("：", ":")
                    .replaceAll("【", StrUtil.EMPTY)
                    .replaceAll("】", StrUtil.EMPTY).trim();
            if (replaceEn) {
                fieldValue = fieldValue.replaceAll("[a-zA-Z]", StrUtil.EMPTY);
            }
            if (replaceParentheses) {
                // 正则表达式匹配中文括号及其内容，并替换为空字符串
                fieldValue = Pattern.compile("\\([^)]*\\)").matcher(fieldValue).replaceAll(StrUtil.EMPTY);
            }
        }
        // 如果仅有 “-” 该字段值为null
        if (Objects.equals("-", fieldValue)) {
            fieldValue = null;
        }
        return StrUtil.isBlank(fieldValue) ? null : fieldValue;
    }

    /**
     * 匹配分级基金名称（并且把母基金追加到第一行）
     *
     * @param text 文本内容
     * @return /
     */
    public static List<String> matchTieredFund(String text) {
        List<String> matches = ListUtil.list(false);
        if (StrUtil.isBlank(text)) {
            matches.add("母基金");
            return matches;
        }
        // 使用正则表达式查找匹配项
        Matcher matcher = PatternConsts.FUND_LEVEL_PATTERN.matcher(text);
        // 收集所有匹配项
        while (matcher.find()) {
            matches.add(matcher.group());
        }
        // 提取字母并按字母顺序排序
        List<String> levels = matches.stream()
                .map(s -> s.replaceAll("[^A-F]", ""))
                .distinct()
                .sorted()
                .map(letter -> letter + "级")
                .collect(Collectors.toList());
        levels.add(0, "母基金");
        return levels;
    }

    /**
     * 分级基金名称
     *
     * @param text 文本内容
     * @return /
     */
    public static String matchFundLevel(String text) {
        // 使用正则表达式查找匹配项
        Matcher matcher = PatternConsts.FUND_LEVEL_PATTERN.matcher(text);
        String result = null;
        while (matcher.find()) {
            result = matcher.group();
        }
        if (StrUtil.isBlank(result)) {
            result = "母基金";
        } else {
            result = result.replaceAll("[^A-F]", "") + "级";
        }
        return result;
    }

    /**
     * 匹配基金代码
     *
     * @param text 字符串
     * @return /
     */
    public static String matchFundCode(String text) {
        if (StrUtil.isBlank(text)) {
            return null;
        }
        Matcher matcher = PatternConsts.FUND_CODE_PATTERN.matcher(text);
        if (matcher.find()) {
            return matcher.group();
        }
        return null;
    }

    /**
     * 根据报告类型和报告名称匹配报告日期
     *
     * @param reportType 报告类型
     * @param text       文本内容
     * @return 报告日期
     */
    public static String matchReportDate(ReportType reportType, String text) {
        if (StrUtil.isBlank(text) || reportType == null) {
            return null;
        }
        text = StrUtil.trim(text);
        if (ReportType.QUARTERLY.equals(reportType)) {
            Matcher matcher = PatternConsts.QUARTERLY_PATTERN.matcher(text);
            if (matcher.find()) {
                String year = matcher.group(1);
                return switch (matcher.group(2)) {
                    case "一", "1" -> year + "-03-31";
                    case "二", "2" -> year + "-06-30";
                    case "三", "3" -> year + "-09-30";
                    case "四", "4" -> year + "-12-31";
                    default -> null;
                };
            }
        }
        if (ReportType.ANNUALLY.equals(reportType)) {
            Matcher matcher = PatternConsts.ANNUALLY_PATTERN.matcher(text);
            if (matcher.find()) {
                return matcher.group(1) + "-12-31";
            }
        }
        if (ReportType.MONTHLY.equals(reportType)) {
            Matcher matcher = PatternConsts.MONTHLY_PATTERN.matcher(text);
            if (matcher.find()) {
                int year = Integer.parseInt(matcher.group(1));
                int month = Integer.parseInt(matcher.group(2));
                return formatMonthEnd(year, month);
            }
        }
        // 其他所有场景下都支持的日期匹配规则
        // 先用严格的日期匹配
        Matcher matcher = PatternConsts.STRICT_DAY_PATTERN.matcher(text);
        if (matcher.find()) {
            return matcher.group();
        }
        // 严格日期匹配不了时
        matcher = PatternConsts.DAY_PATTERN.matcher(text);
        if (matcher.find()) {
            String date = matcher.group();
            if (NumberUtil.isNumber(date) && date.length() >= 10 && !date.contains("-") && !date.contains("_")) {
                return StrUtil.sub(date, 0, 8);
            }
            return date;
        }
        // 其他报告的日期（匹配到日）
        if (ReportType.OTHER.equals(reportType)) {
            matcher = PatternConsts.MONTHLY_PATTERN.matcher(text);
            if (matcher.find()) {
                int year = Integer.parseInt(matcher.group(1));
                int month = Integer.parseInt(matcher.group(2));
                return formatMonthEnd(year, month);
            }
        }
        return null;
    }

    /**
     * 匹配报告类型，如“季度”、“年度”
     *
     * @param emailType 邮件类型
     * @param text      输入字符串
     * @return 匹配到的报告类型子字符串，如果没有匹配到则返回null
     */
    public static ReportType matchReportType(Integer emailType, String text) {
        if (emailType == null) {
            return null;
        }
        ReportType reportType = null;
        // 优先确认函、周报、其他观点，然后才匹配定期报告
        boolean isAmac = Objects.equals(EmailTypeConst.REPORT_EMAIL_TYPE, emailType);
        if (!isAmac) {
            if (Objects.equals(EmailTypeConst.REPORT_LETTER_EMAIL_TYPE, emailType)
                    || StrUtil.containsAny(text, ReportType.LETTER.getPatterns())) {
                reportType = ReportType.LETTER;
            } else if (StrUtil.containsAny(text, ReportType.WEEKLY.getPatterns())) {
                reportType = ReportType.WEEKLY;
            } else if (StrUtil.containsAny(text, ReportType.OTHER.getPatterns())) {
                reportType = ReportType.OTHER;
            }
            return reportType;
        }
        // 类型识别---先识别季度报告，没有季度再识别年度报告，最后识别月报
        Matcher monthMatcher = PatternConsts.MONTHLY_PATTERN.matcher(text);
        Matcher dayMatcher = PatternConsts.DAY_PATTERN.matcher(text);
        if (StrUtil.containsAny(text, ReportType.QUARTERLY.getPatterns())) {
            reportType = ReportType.QUARTERLY;
        } else if (StrUtil.containsAny(text, ReportType.ANNUALLY.getPatterns())) {
            reportType = ReportType.ANNUALLY;
        } else if (StrUtil.containsAny(text, ReportType.MONTHLY.getPatterns())) {
            reportType = ReportType.MONTHLY;
        } else if (monthMatcher.find() && !dayMatcher.find()) {
            // 特殊的月报（当季度->年度->月度报告无法识别时）
            reportType = ReportType.MONTHLY;
        }
        return reportType;
    }

//    private static int getLastDayOfMonth(int year, int month) {
//        Calendar calendar = Calendar.getInstance();
//        calendar.set(Calendar.YEAR, year);
//        calendar.set(Calendar.MONTH, month - 1); // Calendar.MONTH 是从0开始的
//        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
//    }
//
//    private static String padZero(String number) {
//        return String.format("%02d", Integer.parseInt(number));
//    }

    /**
     * 计算指定月份的最后一天
     */
    private static String formatMonthEnd(int year, int month) {
        try {
            YearMonth ym = YearMonth.of(year, month);
            return String.format("%d-%02d-%02d", year, month, ym.lengthOfMonth());
        } catch (Exception e) { // 处理非法月份（如month=13）
            return null;
        }
    }

    public static void main(String[] args) {
        String text = "私募基金2024年04月度报告";
        Integer emailType = 1;
        ReportType reportType = null;

//        text = "投资策略调整.pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        System.out.println(emailType + "," + matchReportType(emailType, text));
//
//        text = "SSH640_天演恒心精选3号私募证券投资基金(SSH640SM200010202504).pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "【复胜周度观点】 2025_04_07-2025_04_11.pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "交睿宏观配置2号私募证券投资基金B类_孙怡乐_20250429_073248861_赎回确认单.pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "远澜宏观周报20250418.pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//
//        text = "官方公众号市场周报披露250430(1).docx";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//
//        text = "涌津涌赢11号私募证券投资基金-月度报告-25250508.pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "年报_多元化CTA私募证券基金_2024年年度报告.pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "投资基金C_20250515_刁志勋-确认单";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "投资基金C_2025年05月15号_刁志勋-确认单";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "证券投资基金_20250331_季报";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "证券投资基金_20241231_年报";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "证券投资基金_20250430_月报";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));

//        text = "潼骁长益3号私募证券投资基金分红预通知公告20250520.pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "ST9332_伏犀奇点2号私募投资基金_2024年年报.pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "SZK953_私募基金季报PDF_香元梅花9号行业精选私募证券投资基金_20250331102500.pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));

//        text = "大岩市场中性2号私募证券投资基金_2025年_4月_月报.pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "查理投资2025年04月披露-23号.pdf"; // monthly ?
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));
//
//        text = "投资策略调整.pdf"; // monthly ?
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));

        // 异常的类型，不要基金合同
//        text = "潼骁周周享私募证券投资基金基金合同（2025-1）.pdf";
//        emailType = EmailUtil.getEmailTypeBySubject(text);
//        reportType = matchReportType(emailType, text);
//        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));

        text = "三希赤霄二号月报2025.05.png";
        emailType = EmailUtil.getEmailTypeBySubject(text);
        reportType = matchReportType(emailType, text);
        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));

        text = "第一创业2025年合同变更公告.png";
        emailType = EmailUtil.getEmailTypeBySubject(text);
        reportType = matchReportType(emailType, text);
        System.out.println(emailType + ",reportType=" + reportType + ",reportDate=" + matchReportDate(reportType, text));

        String date = "2025年6月6日";
        String input = ReportParseUtils.cleaningValue(date, false);
        Date date1 = DateUtils.toDate(input);
        System.out.println(date1);
    }
}
