package com.cf.imes.module.executor.service.order;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.enums.OrderStatusEnum;
import com.cf.imes.framework.common.enums.StatisticsUnit;
import com.cf.imes.framework.common.util.date.LocalDateTimeUtils;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderGoodsPlateRespVO;
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsAreaRespVO;
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO;
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsStatusRespVO;
import com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsAreaRespVO;
import com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsCountRespVO;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateGoodDO;
import com.cf.imes.module.executor.dal.mysql.order.OrderStatisticsMapper;
import com.cf.imes.module.executor.dal.mysql.plan.PlanMapper;
import com.cf.imes.module.executor.dal.mysql.plate.OrderPlateStatisticsMapper;
import com.cf.imes.module.executor.dal.mysql.plate.PlateGoodMapper;
import com.cf.imes.module.system.api.dict.DictDataApi;
import com.cf.imes.module.system.api.dict.dto.DictDataRespDTO;
import com.cf.imes.module.system.enums.DictTypeConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import jakarta.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;

import static com.cf.imes.framework.common.constants.StatisticsConstants.DATELIST_FIELD_NAME;
import static com.cf.imes.framework.common.constants.StatisticsConstants.SERIES_FIELD_NAME;
import static com.cf.imes.framework.common.util.time.StatisticsChangeUtils.generateDateRangeAxis;
import static com.cf.imes.framework.common.util.time.StatisticsChangeUtils.getDateList;

/**
 * @author Gqr
 * @since 2024/8/5 16:58
 */
@Service
@Validated
@Slf4j
public class OrderStatisticsServiceImpl implements OrderStatisticsService {

    @Resource
    private OrderStatisticsMapper orderStatisticsMapper;

    @Resource
    private PlanMapper planMapper;

    @Resource
    private OrderPlateStatisticsMapper orderPlateStatisticsMapper;

    @Resource
    private DictDataApi dictDataApi;

    @Resource
    private PlateGoodMapper plateGoodMapper;

    // 常用的字段key
    private static final String ORDER_REMAIN_PLATE_MODEL_CREATE_TIME_FIELDNAME = "createTime";
    private static final String ORDER_REMAIN_PLATE_MODEL_GOODS_GROUP_NAME = "goods_group";
    private static final String ORDER_REMAIN_PLATE_MODEL_GOODS_COUNT_NAME = "goods_count";
    private static final String ORDER_REMAIN_PLATE_MODEL_DATE_GROUP_NAME = "date_group";
    private static final String DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH = "yyyy-M";
    private static final String DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH_DAY = "yyyy-M-d";
    private static final String ORDER_REMAIN_PLATE_MODEL_GOODS_ID_NAME = "goodsId";

    @Override
    public Integer orderCount() {
        return orderStatisticsMapper.selectOrderCount();
    }

    @Override
    public Integer orderCountToday() {
        return orderStatisticsMapper.selectOrderCountToday();
    }

    @Override
    public Integer orderCountTodayFinish() {
        return orderStatisticsMapper.selectOrderCountTodayFinish();
    }

    @Override
    public Integer orderCountProduce() {
        return orderStatisticsMapper.selectOrderCountProduce();
    }

    @Override
    public Double orderSquareProduce() {
        return orderStatisticsMapper.selectOrderSquareProduce();
    }

    @Override
    public Map<String, Object> getOrderStatusCount(OrderStatisticsReqVO reqVO) {
        Map<String, Object> resultMap = new HashMap<>();

        // 所有的日期集合
        List<String> dateList = getDateList(reqVO);

        reqVO.setCreateTimeForQry(LocalDateTimeUtils.generateTimeSection(reqVO.getCreateTime()));
        // 查询订单状态统计数据
        List<OrderStatisticsStatusRespVO> orderStatusRespVOS = orderStatisticsMapper.selectOrderStatusCountGroupBy(reqVO);

        // 基于相同的orderDate分组
        Map<String, List<OrderStatisticsStatusRespVO>> orderDateMap = orderStatusRespVOS.stream()
                .sorted(Comparator.naturalOrder())
                .collect(Collectors.groupingBy(OrderStatisticsStatusRespVO::getDate, LinkedHashMap::new, Collectors.toList()));

        // 遍历订单状态所有枚举值
        List<Map<String, Object>> series = new ArrayList<>();
        for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) {
            Map<String, Object> seriesItem = new HashMap<>();
            int[] sumArr = new int[dateList.size()];

            // 遍历完整的日期范围
            int index = 0;
            for (String dateStr : dateList) {
                // 查找匹配的订单状态
                List<OrderStatisticsStatusRespVO> listForDate = orderDateMap.get(dateStr);
                int count = 0;
                if (listForDate != null) {
                    count = listForDate.stream()
                            .filter(respVO -> Objects.equals(orderStatusEnum.getStatus(), respVO.getOrderStatus()))
                            .mapToInt(OrderStatisticsStatusRespVO::getOrderCount)
                            .sum();
                }

                sumArr[index++] = count;
            }

            seriesItem.put("data", sumArr);
            seriesItem.put("name", orderStatusEnum.getDescription());
            series.add(seriesItem);
        }
        // x轴时间区间字符串
        resultMap.put(DATELIST_FIELD_NAME, dateList.stream().map(date -> generateDateRangeAxis(date, reqVO.getUnit())).toList());
        // 类别：订单类型：数量数组
        resultMap.put(SERIES_FIELD_NAME, series);

        return resultMap;
    }

    @Override
    public Map<String, Object> getOrderAndPlanCountGroup(OrderStatisticsReqVO reqVO) {
        Map<String, Object> resultMap = new LinkedHashMap<>();

        // 所有的日期集合
        List<String> dateList = getDateList(reqVO);

        reqVO.setCreateTimeForQry(LocalDateTimeUtils.generateTimeSection(reqVO.getCreateTime()));
        // 查询订单单量
        Map<String, List<OrderStatisticsStatusRespVO>> orderRespMap = orderStatisticsMapper.selectOrderCountGroupByOrderDate(reqVO).stream()
                .sorted(Comparator.naturalOrder())
                .collect(Collectors.groupingBy(OrderStatisticsStatusRespVO::getDate, LinkedHashMap::new, Collectors.toList()));
        // 查询排单单量
        Map<String, List<OrderPlanStatisticsCountRespVO>> planRespMap = planMapper.selectPlanCountGroupByCreateTime(reqVO).stream()
                .sorted(Comparator.naturalOrder())
                .collect(Collectors.groupingBy(OrderPlanStatisticsCountRespVO::getDate, LinkedHashMap::new, Collectors.toList()));

        // 类别：单量数组
        List<Map<String, Object>> series = new ArrayList<>();
        Map<String, Object> orderSeriesItem = new HashMap<>();
        Map<String, Object> planSeriesItem = new HashMap<>();
        int[] orderCountArr = new int[dateList.size()];
        int[] planCountArr = new int[dateList.size()];
        // 遍历时间跨度列表，匹配数量存入数组，没有补0存入数组
        for (int i = 0; i < dateList.size(); i++) {
            String dateStr = dateList.get(i);
            // 存入订单数量
            Integer orderCount = Optional.ofNullable(orderRespMap.get(dateStr))
                    .map(list -> list.stream().findFirst().orElse(new OrderStatisticsStatusRespVO()))
                    .map(OrderStatisticsStatusRespVO::getOrderCount)
                    .orElse(0);
            orderCountArr[i] = orderCount;

            // 存入排单数量
            Integer planCount = Optional.ofNullable(planRespMap.get(dateStr))
                    .map(list -> list.stream().findFirst().orElse(new OrderPlanStatisticsCountRespVO()))
                    .map(OrderPlanStatisticsCountRespVO::getCount)
                    .orElse(0);
            planCountArr[i] = planCount;
        }

        orderSeriesItem.put("data", orderCountArr);
        orderSeriesItem.put("name", "订单单量");
        planSeriesItem.put("data", planCountArr);
        planSeriesItem.put("name", "排单单量");
        series.add(orderSeriesItem);
        series.add(planSeriesItem);

        // x轴时间区间字符串
        resultMap.put(DATELIST_FIELD_NAME, dateList.stream().map(date -> generateDateRangeAxis(date, reqVO.getUnit())).toList());
        // 类别：类别：单量数组
        resultMap.put(SERIES_FIELD_NAME, series);

        return resultMap;
    }

    @Override
    public Map<String, Object> getOrderAndPlanAreaSumGroup(OrderStatisticsReqVO reqVO) {
        Map<String, Object> resultMap = new LinkedHashMap<>();

        // 所有的日期集合
        List<String> dateList = getDateList(reqVO);

        reqVO.setCreateTimeForQry(LocalDateTimeUtils.generateTimeSection(reqVO.getCreateTime()));
        Map<String, List<OrderStatisticsAreaRespVO>> orderRespMap = orderStatisticsMapper.selectOrderAreaGroupByOrderDate(reqVO).stream()
                .sorted(Comparator.naturalOrder())
                .collect(Collectors.groupingBy(OrderStatisticsAreaRespVO::getDate, LinkedHashMap::new, Collectors.toList()));
        Map<String, List<OrderPlanStatisticsAreaRespVO>> planRespMap = planMapper.selectPlanAreaGroupByCreateTime(reqVO).stream()
                .sorted(Comparator.naturalOrder())
                .collect(Collectors.groupingBy(OrderPlanStatisticsAreaRespVO::getDate, LinkedHashMap::new, Collectors.toList()));

        // 类别：平方数数组
        List<Map<String, Object>> series = new ArrayList<>();
        Map<String, Object> orderSeriesItem = new HashMap<>();
        Map<String, Object> planSeriesItem = new HashMap<>();
        BigDecimal[] orderAreaArr = new BigDecimal[dateList.size()];
        BigDecimal[] planAreaArr = new BigDecimal[dateList.size()];
        // 遍历时间跨度列表，匹配数量存入数组，没有补0存入数组
        for (int i = 0; i < dateList.size(); i++) {
            String dateStr = dateList.get(i);

            // 存订单面积
            List<OrderStatisticsAreaRespVO> orderCountRespVOS = orderRespMap.get(dateStr);
            orderAreaArr[i] = orderCountRespVOS != null && !orderCountRespVOS.isEmpty() ? orderCountRespVOS.get(0).getAreaSum() : BigDecimal.ZERO;

            // 存排单面积
            List<OrderPlanStatisticsAreaRespVO> planCountRespVOS = planRespMap.get(dateStr);
            planAreaArr[i] = planCountRespVOS != null && !planCountRespVOS.isEmpty() ? planCountRespVOS.get(0).getAreaSum() : BigDecimal.ZERO;
        }

        orderSeriesItem.put("data", orderAreaArr);
        orderSeriesItem.put("name", "订单平方数");
        planSeriesItem.put("data", planAreaArr);
        planSeriesItem.put("name", "排单平方数");
        series.add(orderSeriesItem);
        series.add(planSeriesItem);

        // x轴时间区间字符串
        resultMap.put(DATELIST_FIELD_NAME, dateList.stream().map(date -> generateDateRangeAxis(date, reqVO.getUnit())).toList());
        // 类别：类别：平方数数组
        resultMap.put(SERIES_FIELD_NAME, series);

        return resultMap;
    }


    @Override
    public Map<String, Object> getOrderPlateCountGroup(OrderStatisticsReqVO reqVO) {
        Map<String, Object> resultMap = new LinkedHashMap<>();

        // 所有的日期集合
        List<String> dateList = getDateList(reqVO);

        reqVO.setCreateTimeForQry(LocalDateTimeUtils.generateTimeSection(reqVO.getCreateTime()));
        // 查询时间段内数量最多的小板，列出数量前10的goods_id
        List<String> topTenCountGoodsId = orderPlateStatisticsMapper.selectPlateCountList(reqVO).stream()
                .map(OrderGoodsPlateRespVO::getGoodsId)
                .toList();

        // 前十goods_id基于时间分组
        Map<String, List<OrderGoodsPlateRespVO>> orderGoodsPlateRespMap = new HashMap<>();
        if (CollUtil.isNotEmpty(topTenCountGoodsId)) {
            orderGoodsPlateRespMap = orderPlateStatisticsMapper.selectTopTenPlateCountListGroupByOrderDate(topTenCountGoodsId, reqVO).stream()
                    .sorted(Comparator.naturalOrder())
                    .collect(Collectors.groupingBy(OrderGoodsPlateRespVO::getOrderDate, LinkedHashMap::new, Collectors.toList()));
        }


        // 获取所有商品{goodsId:respvo}，根据top10排序
        Map<String, OrderGoodsPlateRespVO> goodsMap = new LinkedHashMap<>();
        for (String id : topTenCountGoodsId) {
            List<OrderGoodsPlateRespVO> list = orderGoodsPlateRespMap.values().stream()
                    .flatMap(List::stream)
                    .filter(vo -> vo.getGoodsId().equals(id))
                    .toList();
            if (!list.isEmpty()) {
                // goodsId相同，其他属性任取
                goodsMap.put(id, list.get(0));
            }
        }

        // 遍历所有goods_id
        List<Map<String, Object>> series = new ArrayList<>();
        for (Map.Entry<String, OrderGoodsPlateRespVO> entry : goodsMap.entrySet()) {
            Map<String, Object> seriesItem = new HashMap<>();
            int[] sumArr = new int[dateList.size()];

            // 遍历完整的日期范围
            int index = 0;
            for (String dateStr : dateList) {
                // 查找匹配的goodsId
                List<OrderGoodsPlateRespVO> orderGoodsPlateRespVOS = orderGoodsPlateRespMap.get(dateStr);
                int count = 0;
                if (orderGoodsPlateRespVOS != null) {
                    Optional<OrderGoodsPlateRespVO> matchingRespVO = orderGoodsPlateRespVOS.stream()
                            .filter(respVO -> Objects.equals(entry.getKey(), respVO.getGoodsId()))
                            .findFirst();
                    count = matchingRespVO.map(OrderGoodsPlateRespVO::getOrderCount).orElse(0);
                }
                sumArr[index++] = count;
            }

            seriesItem.put("data", sumArr);
            seriesItem.put("id", entry.getKey());
            // 材质-商品名称-颜色-纹理-宽-高-厚-品牌
            OrderGoodsPlateRespVO orderGoodsPlateRespVO = entry.getValue();
            String specification = formatGoodsName('x', stripTrailingZeros(orderGoodsPlateRespVO.getWidth()),
                    stripTrailingZeros(orderGoodsPlateRespVO.getHeight()), stripTrailingZeros(orderGoodsPlateRespVO.getThickness()));
            String goodsName = formatGoodsName('-', orderGoodsPlateRespVO.getMaterial(), orderGoodsPlateRespVO.getGoodsName(), orderGoodsPlateRespVO.getColor(), getTextureFromDict(orderGoodsPlateRespVO.getTexture()), specification, orderGoodsPlateRespVO.getBrand());
            seriesItem.put("name", goodsName);
            series.add(seriesItem);
        }

        // x轴时间区间字符串
        resultMap.put(DATELIST_FIELD_NAME, dateList.stream().map(date -> generateDateRangeAxis(date, reqVO.getUnit())).toList());
        // 类别：大板信息：小板数量数组
        resultMap.put(SERIES_FIELD_NAME, series);
        return resultMap;
    }

    @Override
    public Map<String, Object> getOrderPlateAreaGroup(OrderStatisticsReqVO reqVO) {
        Map<String, Object> resultMap = new LinkedHashMap<>();

        // 所有的日期集合
        List<String> dateList = getDateList(reqVO);

        reqVO.setCreateTimeForQry(LocalDateTimeUtils.generateTimeSection(reqVO.getCreateTime()));
        // 查询时间段内面积最多的小板，列出前10面积的goods_id
        List<String> topTenCountGoodsId = orderPlateStatisticsMapper.selectPlateAreaList(reqVO).stream()
                .map(OrderGoodsPlateRespVO::getGoodsId)
                .toList();

        Map<String, List<OrderGoodsPlateRespVO>> orderGoodsPlateRespMap = new HashMap<>();
        if (CollUtil.isNotEmpty(topTenCountGoodsId)) {
            // 前十goods_id基于时间分组
            orderGoodsPlateRespMap = orderPlateStatisticsMapper.selectTopTenPlateAreaListGroupByOrderDate(topTenCountGoodsId, reqVO).stream()
                    .sorted(Comparator.naturalOrder())
                    .collect(Collectors.groupingBy(OrderGoodsPlateRespVO::getOrderDate, LinkedHashMap::new, Collectors.toList()));
        }


        // 获取所有商品{goodsId:respvo}，根据top10排序
        Map<String, OrderGoodsPlateRespVO> goodsMap = new LinkedHashMap<>();
        for (String id : topTenCountGoodsId) {
            List<OrderGoodsPlateRespVO> list = orderGoodsPlateRespMap.values().stream()
                    .flatMap(List::stream)
                    .filter(vo -> vo.getGoodsId().equals(id))
                    .toList();
            if (!list.isEmpty()) {
                // goodsId相同，其他属性任取
                goodsMap.put(id, list.get(0));
            }
        }

        // 遍历所有goods_id
        List<Map<String, Object>> series = new ArrayList<>();
        for (Map.Entry<String, OrderGoodsPlateRespVO> entry : goodsMap.entrySet()) {
            Map<String, Object> seriesItem = new HashMap<>();
            BigDecimal[] areaArr = new BigDecimal[dateList.size()];

            // 遍历完整的日期范围
            int index = 0;
            for (String dateStr : dateList) {
                // 查找匹配的goodsId
                List<OrderGoodsPlateRespVO> orderGoodsPlateRespVOS = orderGoodsPlateRespMap.get(dateStr);
                BigDecimal area = new BigDecimal(0);
                if (orderGoodsPlateRespVOS != null) {
                    area = orderGoodsPlateRespVOS.stream()
                            .filter(respVO -> Objects.equals(entry.getKey(), respVO.getGoodsId()))
                            .map(vo -> vo.getOrderArea().stripTrailingZeros())
                            .findFirst().orElse(new BigDecimal(0));
                }
                areaArr[index++] = area;
            }

            seriesItem.put("data", areaArr);
            seriesItem.put("id", entry.getKey());
            // 材质-商品名称-颜色-纹理-宽-高-厚-品牌
            OrderGoodsPlateRespVO orderGoodsPlateRespVO = entry.getValue();
            String specification = formatGoodsName('x', stripTrailingZeros(orderGoodsPlateRespVO.getWidth()),
                    stripTrailingZeros(orderGoodsPlateRespVO.getHeight()), stripTrailingZeros(orderGoodsPlateRespVO.getThickness()));
            String goodsName = formatGoodsName('-', orderGoodsPlateRespVO.getMaterial(), orderGoodsPlateRespVO.getGoodsName(), orderGoodsPlateRespVO.getColor(), getTextureFromDict(orderGoodsPlateRespVO.getTexture()), specification, orderGoodsPlateRespVO.getBrand());
            seriesItem.put("name", goodsName);
            series.add(seriesItem);
        }

        // x轴时间区间字符串
        resultMap.put(DATELIST_FIELD_NAME, dateList.stream().map(date -> generateDateRangeAxis(date, reqVO.getUnit())).toList());
        // 类别：大板信息：小板平方数数组
        resultMap.put(SERIES_FIELD_NAME, series);
        return resultMap;
    }

    @Override
    public Map<String, Object> getBigPlateCountGroup(OrderStatisticsReqVO reqVO) {
        Map<String, Object> resultMap = new LinkedHashMap<>();

        // 所有的日期集合
        List<String> dateList = getDateList(reqVO);

        reqVO.setCreateTimeForQry(LocalDateTimeUtils.generateTimeSection(reqVO.getCreateTime()));
        // 查询满足时间条件的最大用量材质编号
        List<String> goodsCodes = planMapper.selectPlanGoodsTopTen(reqVO);

        // 前十goods_id基于时间分组
        Map<String, List<OrderGoodsPlateRespVO>> orderGoodsPlateRespMap = new HashMap<>();
        if (CollUtil.isNotEmpty(goodsCodes)) {
            orderGoodsPlateRespMap = planMapper.selectTopTenBoardCountGroupByOptimizeTime(goodsCodes, reqVO).stream()
                    .sorted(Comparator.naturalOrder())
                    .collect(Collectors.groupingBy(OrderGoodsPlateRespVO::getOrderDate, LinkedHashMap::new, Collectors.toList()));
        }


        List<Map<String, Object>> series = new ArrayList<>();

        // 遍历top10材质
        for (String goodsCode : goodsCodes) {

            Map<String, Object> seriesItem = new HashMap<>();

            int[] countArr = new int[dateList.size()];

            int index = 0;

            // 遍历完整时间轴
            for (String dateStr : dateList) {

                List<OrderGoodsPlateRespVO> respVOS = orderGoodsPlateRespMap.get(dateStr);

                int count = 0;

                if (CollUtil.isNotEmpty(respVOS)) {
                    count = respVOS.stream()
                            .filter(vo -> Objects.equals(goodsCode, vo.getGoodsId()))
                            .map(OrderGoodsPlateRespVO::getOrderCount)
                            .findFirst()
                            .orElse(0);
                }

                countArr[index++] = count;
            }

            seriesItem.put("data", countArr);
            seriesItem.put("id", goodsCode);

            // 查询大板信息
            List<PlateGoodDO> plateGoodDOList = plateGoodMapper.selectList(
                    new LambdaQueryWrapperX<PlateGoodDO>()
                            .eq(PlateGoodDO::getGoodsId, goodsCode));

            if (CollUtil.isEmpty(plateGoodDOList)) {
                log.error("[getBigPlateCountGroup][统计大板数量，查询大板{}不存在]", goodsCode);
                continue;
            }

            PlateGoodDO plateGoodDO = plateGoodDOList.get(0);

            String goodsName = formatGoodsName(
                    '-',
                    plateGoodDO.getMaterial(),
                    plateGoodDO.getGoodsName(),
                    plateGoodDO.getColor(),
                    getTextureFromDict(plateGoodDO.getTexture()),
                    String.valueOf(plateGoodDO.getThickness()),
                    plateGoodDO.getBrand());

            seriesItem.put("name", goodsName);

            series.add(seriesItem);
        }

        // x轴
        resultMap.put(
                DATELIST_FIELD_NAME,
                dateList.stream()
                        .map(date -> generateDateRangeAxis(date, reqVO.getUnit()))
                        .toList());

        // series
        resultMap.put(
                SERIES_FIELD_NAME,
                series);

        return resultMap;
    }

    /**
     * 板材信息用-连接
     *
     * @param connChar 连接符
     * @param texts    信息内容
     * @return 为空时不带connChar
     */
    private String formatGoodsName(char connChar, String... texts) {
        StringBuilder sb = new StringBuilder();
        for (String text : texts) {
            if (StringUtils.isNotEmpty(text)) {
                sb.append(text).append(connChar);
            }
        }
        // 移除最后一个 -
        if (sb.length() > 0 && sb.charAt(sb.length() - 1) == connChar) {
            sb.deleteCharAt(sb.length() - 1);
        }
        return sb.toString();
    }


    /**
     * 根据纹路枚举获取字典中纹路描述
     *
     * @param texture
     * @return
     */
    private String getTextureFromDict(Boolean texture) {
        if (ObjectUtil.isNull(texture)) {
            return "无";
        }
        // 获取纹路描述
        DictDataRespDTO grainDTO = dictDataApi.getDictData(DictTypeConstants.PLATE_TEXTURE_TYPE, String.valueOf(texture)).getData();
        if (ObjectUtil.isNotNull(grainDTO)) {
            return Objects.equals("是", grainDTO.getLabel()) ? "有" : "无";
        } else {
            return "无";
        }
    }


    /**
     * 年月日转年月周
     *
     * @param dateStr
     * @return
     */
    private String dateToWeekMonth(String dateStr, Integer unit) {
        if (StatisticsUnit.WEEK.getValue().equals(unit)) {
            LocalDate date = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH_DAY));
            // 年月
            String outDateStr = date.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH));
            // 计算从月份第一天到当前日期经过了多少周
            LocalDate monthStart = date.with(TemporalAdjusters.firstDayOfMonth());
            long weeksInMonth = ChronoUnit.WEEKS.between(monthStart, date) + 1;
            return outDateStr + "-" + weeksInMonth;
        }
        return dateStr;
    }

    /**
     * 移除尾数的0，600.000 -> 600
     *
     * @param data
     * @return
     */
    private String stripTrailingZeros(BigDecimal data) {
        if (ObjectUtil.isNotNull(data)) {
            return data.stripTrailingZeros().toPlainString();
        } else {
            return "";
        }
    }

}
