package com.storlead.sales.pojo.vo.report;

import com.baomidou.mybatisplus.annotation.TableField;
import com.storlead.sales.pojo.entity.report.DashboardSketchEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2025-12-18 16:37
 */
@Data
public class DashboardSketchVO {

    @ApiModelProperty(value = "订单金额新增数")
    private BigDecimal orderAmountTotal;

    @ApiModelProperty(value = "客户新增数")
    private Integer customerNewTotalNum;

    @ApiModelProperty(value = "商机新增数")
    private Integer businessNewTotalNum;

    @ApiModelProperty(value = "订单新增数")
    private Integer orderNewTotalNum;

    @ApiModelProperty(value = "线索新增数")
    private Integer leadNewTotalNum;

    @ApiModelProperty(value = "跟进新增数")
    private Integer followNewTotalNum;

    @ApiModelProperty(value = "邮件新增数")
    private Integer mailNewTotalNum;

    public static DashboardSketchVO totalDataByListVo(List<DashboardSketchEntity> entityInfos) {
        DashboardSketchVO vo = new DashboardSketchVO();

        if (entityInfos == null || entityInfos.isEmpty()) {
            return vo;
        }

        vo.setOrderAmountTotal(
                entityInfos.stream()
                        .map(e -> e.getOrderAmount() == null ? BigDecimal.ZERO : e.getOrderAmount())
                        .reduce(BigDecimal.ZERO, BigDecimal::add)
        );

        vo.setCustomerNewTotalNum(
                entityInfos.stream()
                        .mapToInt(e -> e.getCustomerNewNum() == null ? 0 : e.getCustomerNewNum())
                        .sum()
        );

        vo.setBusinessNewTotalNum(
                entityInfos.stream()
                        .mapToInt(e -> e.getBusinessNewNum() == null ? 0 : e.getBusinessNewNum())
                        .sum()
        );

        vo.setOrderNewTotalNum(
                entityInfos.stream()
                        .mapToInt(e -> e.getOrderNewNum() == null ? 0 : e.getOrderNewNum())
                        .sum()
        );

        vo.setLeadNewTotalNum(
                entityInfos.stream()
                        .mapToInt(e -> e.getLeadNewNum() == null ? 0 : e.getLeadNewNum())
                        .sum()
        );

        vo.setFollowNewTotalNum(
                entityInfos.stream()
                        .mapToInt(e -> e.getFollowNewNum() == null ? 0 : e.getFollowNewNum())
                        .sum()
        );

        vo.setMailNewTotalNum(
                entityInfos.stream()
                        .mapToInt(e -> e.getMailNewNum() == null ? 0 : e.getMailNewNum())
                        .sum()
        );

        return vo;
    }


}
