package cn.estsh.i3plus.ext.mes.pojo.model.bu3;

import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @DESCRIPTION:
 * @USER: wangjie
 * @DATE: 2022-11-01 15:54
 */
@Data
@ApiModel("工场损失分析报表数据MODEL")
public class SxOfficialLossAnalysisReportModel extends SxEChartsReportCommonDataModel implements Serializable {

    private static final long serialVersionUID = 6577972347925038953L;

    @ApiParam(value = "事业别代码")
    private String careerCodeArr;

    @ApiParam(value = "事业别名称")
    private String careerNameArr;

    @ApiParam("产品别代码")
    private String categoryCodeArr;

    @ApiParam(value = "产品别名称")
    private String categoryNameArr;

    @ApiParam(value = "生产线代码")
    private String workCenterCodeArr;

    @ApiParam("生产线代码集合")
    private List<String> workCenterCodeList;

    @ApiParam("事业别代码集合")
    private Map<String, String> careerMap;

    @ApiParam("产品别代码集合")
    private Map<String, String> categoryMap;

    @ApiParam(value = "分组对象名称")
    private String groupObjName;

    @ApiParam("表字段")
    private List<SxDataModel> tableNameList;

    @ApiParam("通用表名称")
    private List<String> cellNameList;

    @ApiParam("通用表字段")
    private List<String> cellFieldList;

    @ApiParam("月度集合")
    private Map<String, String> monthMap;

    @ApiParam("表数据")
    private List<Map<String, String>> tableDataList;

    @ApiParam("当前对象集合数据")
    private List<SxOfficialLossAnalysisReportModel> analysisDataList;

    @ApiParam("当前月")
    private String curMonth;

    @ApiParam(value = "标题")
    private String title;

    @ApiParam("柱状图数据")
    private List<SxDataModel> barChartDataList;

    @ApiParam("折线图数据")
    private List<SxDataModel> lineChartDataList;

    public SxOfficialLossAnalysisReportModel workTimeStart(String workTimeStart) {
        super.workTimeStart = workTimeStart;
        return this;
    }

    public SxOfficialLossAnalysisReportModel workTimeEnd(String workTimeEnd) {
        super.workTimeEnd = workTimeEnd;
        return this;
    }

    public SxOfficialLossAnalysisReportModel title(String title) {
        this.title = title;
        return this;
    }

    public SxOfficialLossAnalysisReportModel curMonth(String curMonth) {
        this.curMonth = curMonth;
        return this;
    }

    public SxOfficialLossAnalysisReportModel workCenterCodeList(List<String> workCenterCodeList) {
        this.workCenterCodeList = workCenterCodeList;
        return this;
    }

    public SxOfficialLossAnalysisReportModel careerMap(Map<String, String> careerMap) {
        this.careerMap = careerMap;
        return this;
    }

    public SxOfficialLossAnalysisReportModel categoryMap(Map<String, String> categoryMap) {
        this.categoryMap = categoryMap;
        return this;
    }

    public SxOfficialLossAnalysisReportModel groupObjName(String groupObjName) {
        this.groupObjName = groupObjName;
        return this;
    }

    public SxOfficialLossAnalysisReportModel addCellName(String name) {
        if (CollectionUtils.isEmpty(this.cellNameList)) this.cellNameList = new LinkedList<>();
        this.cellNameList.add(name);
        return this;
    }

    public SxOfficialLossAnalysisReportModel addCellField(String field) {
        if (CollectionUtils.isEmpty(this.cellFieldList)) this.cellFieldList = new LinkedList<>();
        this.cellFieldList.add(field);
        return this;
    }

    public SxOfficialLossAnalysisReportModel addTableName(String field, String name) {
        if (CollectionUtils.isEmpty(this.tableNameList)) this.tableNameList = new LinkedList<>();
        this.tableNameList.add(new SxDataModel(field, name));
        return this;
    }

    public SxOfficialLossAnalysisReportModel addTableName(String month) {
        if (CollectionUtils.isEmpty(this.tableNameList)) this.tableNameList = new LinkedList<>();
        if (CollectionUtils.isEmpty(this.monthMap)) this.monthMap = new LinkedHashMap<>();
        Integer num = Integer.valueOf(month.substring(5, 7));
        String field = MesExtConstWords.MONTH + num;
        String name = num + "月";
        this.tableNameList.add(new SxDataModel(field, name));
        this.monthMap.put(field, month);
        this.addCellField(field).addCellName(name);
        return this;
    }

    public SxOfficialLossAnalysisReportModel addTableName(List<SxDataModel> tableNameList) {
        if (CollectionUtils.isEmpty(this.tableNameList)) this.tableNameList = new LinkedList<>();
        this.tableNameList.addAll(tableNameList);
        return this;
    }

    public SxOfficialLossAnalysisReportModel addTableData(Map<String, String> tableDataMap) {
        if (CollectionUtils.isEmpty(this.tableDataList)) this.tableDataList = new LinkedList<>();
        this.tableDataList.add(tableDataMap);
        return this;
    }

    public SxOfficialLossAnalysisReportModel addTableDataList(List<Map<String, String>> tableDataList) {
        if (CollectionUtils.isEmpty(this.tableDataList)) this.tableDataList = new LinkedList<>();
        if (!CollectionUtils.isEmpty(tableDataList)) this.tableDataList.addAll(tableDataList);
        return this;
    }

    public SxOfficialLossAnalysisReportModel addAnalysisData(SxOfficialLossAnalysisReportModel analysisData) {
        if (CollectionUtils.isEmpty(this.analysisDataList)) this.analysisDataList = new LinkedList<>();
        this.analysisDataList.add(analysisData);
        return this;
    }

    public SxOfficialLossAnalysisReportModel addBarChartData(String key, BigDecimal value, BigDecimal value2, BigDecimal value3) {
        if (CollectionUtils.isEmpty(this.barChartDataList)) this.barChartDataList = new LinkedList<>();
        this.barChartDataList.add(new SxDataModel(key, value, value2, value3));
        return this;
    }

    public SxOfficialLossAnalysisReportModel addLineChartData(String key, BigDecimal value, BigDecimal value2) {
        if (CollectionUtils.isEmpty(this.lineChartDataList)) this.lineChartDataList = new LinkedList<>();
        this.lineChartDataList.add(new SxDataModel(key, value, value2));
        return this;
    }

    public SxOfficialLossAnalysisReportModel() {}

    public SxOfficialLossAnalysisReportModel(SxOfficialLossAnalysisReportModel data) {
        BeanUtils.copyProperties(data, this);
    }

}
