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

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

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

    private static final long serialVersionUID = -4228658471439174920L;

    @ApiParam("组织代码")
    public String organizeCode;

    @ApiParam("时间维度")
    public Integer dimension;

    @ApiParam("查询时间")
    public String workTimeStart;

    @ApiParam("查询时间")
    public String workTimeEnd;

    @ApiParam("年份")
    public Integer year;

    @ApiParam("松下年标志")
    public Boolean sxYearFlag = false;

    @ApiParam("事业别")
    public String careerCode;

    @ApiParam("产品别")
    public String categoryCode;

    @ApiParam("班次代码")
    public String shiftCode;

    @ApiParam("系别")
    public String isDont;

    @ApiParam("班别")
    public String dontClass;

    @ApiParam("生产线代码")
    public String workCenterCode;

    @ApiParam("作业时间")
    public String ymdStart;
    @ApiParam("作业时间")
    public String ymdEnd;

    @ApiParam("作业时间")
    public String statisticsYmStart;
    @ApiParam("作业时间")
    public String statisticsYmEnd;

    @ApiParam("作业时间")
    public String statisticsYmdStart;
    @ApiParam("作业时间")
    public String statisticsYmdEnd;

    @ApiParam("作业时间")
    public String workTimeYmdStart;
    @ApiParam("作业时间")
    public String workTimeYmdEnd;

    @ApiParam("作业时间")
    public String workTimeYmStart;
    @ApiParam("作业时间")
    public String workTimeYmEnd;

    @Data
    class SxDataModel implements Serializable {

        private static final long serialVersionUID = 610906287907931845L;

        public String key;
        public Object value;
        public Object value2;
        public Object value3;
        public Object value4;

        public Double valueToSort;

        public SxDataModel(String key, Object value) {
            this.key = key;
            this.value = value;
        }

        public SxDataModel(String key, Object value, Object value2) {
            this.key = key;
            this.value = value;
            this.value2 = value2;
        }

        public SxDataModel(String key, Object value, Object value2, Object value3) {
            this.key = key;
            this.value = value;
            this.value2 = value2;
            this.value3 = value3;
        }

        public SxDataModel(String key, Object value, Object value2, Object value3, Object value4) {
            this.key = key;
            this.value = value;
            this.value2 = value2;
            this.value3 = value3;
            this.value4 = value4;
        }

        public SxDataModel valueToSort(Double valueToSort) {
            this.valueToSort = valueToSort;
            return this;
        }
    }

    public List<SxDataModel> sortReversedValue(List<SxDataModel> dataList) {
        return CollectionUtils.isEmpty(dataList) ? null : dataList.stream().filter(o -> null != o).sorted(Comparator.comparing(SxDataModel::getValueToSort).reversed()).collect(Collectors.toList());
    }

}
