package com.zcloud.basic.info.domain.model;

import com.alibaba.cola.dto.ClientObject;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

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


/**
 * web-client
 *
 * @Author zhaokai
 * @Date 2025-10-30 10:10:48
 */
@Data
public class CorpDepartmentE extends ClientObject {
    //主键
    @ApiModelProperty(value = "企业主键")
    private Long id;
    @ApiModelProperty(value = "企业名称")
    private String corpName;
    //行业分类
    @ApiModelProperty(value = "行业分类")
    private String corpType;
    //行业分类
    @ApiModelProperty(value = "行业分类")
    private String corpType2;
    //行业分类
    @ApiModelProperty(value = "行业分类")
    private String corpType3;
    //行业分类
    @ApiModelProperty(value = "行业分类")
    private String corpType4;
    @ApiModelProperty(value = "企业状态")
    private String corpState;
    @ApiModelProperty(value = "企业状态名称")
    private String corpStateName;
    @ApiModelProperty(value = "是否启用，1:启用,0:关闭")
    private Integer useFlag;

    @ApiModelProperty(value = "厂级部门数")
    private Integer factoryCount;

    @ApiModelProperty(value = "科/队部门数")
    private Integer sectionCount;

    @ApiModelProperty(value = "班组级部门数")
    private Integer classCount;


    public void addDepart(List<DepartmentE> list) {
        //过滤掉为DepartmentE::getLevel为null的

        Map<String, Integer> levelToDepartmentMap = list.stream()
                .filter(Objects::nonNull)
                .filter(departmentE -> departmentE.getLevel() != null)
                .collect(Collectors.groupingBy(
                        DepartmentE::getLevel,
                        Collectors.collectingAndThen(
                                Collectors.counting(),
                                Long::intValue  // 直接将 Long 转为 Integer
                        )
                ));

        // 部门级别待定
        this.factoryCount =levelToDepartmentMap.get("departmentLevel0001");
        this.sectionCount =levelToDepartmentMap.get("departmentLevel0002");
        this.classCount =levelToDepartmentMap.get("departmentLevel0003");


    }
}

