package com.fs;

import com.fs.crm.utils.CidUserOrderExtractor;
import com.fs.crm.vo.CrmOrderInfoVo;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;


public class FSServletInitializer extends SpringBootServletInitializer
{
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
    {
        return application.sources(FsWxApiApplication.class);
    }


    public static void main(String[] args) {
        // 构造带不确定间隔的订单文本（空格、换行、制表符混合）
        List<String> orderTextList = Arrays.asList(
                "京东-关舒宝医药旗舰店（侯）日期2026-01-12 09:13:36订单号3376231002663571商品盐酸氨基葡萄糖颗粒(关舒宝)规格0.48g*12袋/盒物流京东-京东-8192JDVG04843590091数量（件）3实付金额128",
                "天猫-挑宝大药房旗舰店（侯）日期2026-01-12 10:10:12订单号3178588622077244779商品今正牌氨糖硫酸软骨素钙片(今正)规格10g(1g/片*10片)/盒物流天猫-中通菜鸟-侯78973651022516数量（件）3实付金额79.9"
        );

        // Java 8 Stream API 批量提取
        List<CrmOrderInfoVo> orderInfoList = orderTextList.stream()
                .map(CidUserOrderExtractor::extractSingleOrder)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());

        // 打印结果（验证日期转换和间隔适配）
        System.out.println("订单提取结果（适配间隔不确定）：");
        orderInfoList.forEach(System.out::println);

        // 演示：Java 8 日期格式化（LocalDateTime → 自定义字符串格式）
        if (!orderInfoList.isEmpty()) {
            String customDate = CidUserOrderExtractor.formatLocalDateTime(
                    orderInfoList.get(0).getBuyDate(), "yyyy/MM/dd HH:mm"
            );
            System.out.println("\n自定义格式日期示例：" + customDate);
        }
    }
}
