package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.busi;

import cn.estsh.i3plus.ext.mes.api.busi.ISxBadStatisticsReportFormService;
import cn.estsh.i3plus.ext.mes.apiservice.dao.ISxRepairRecordDao;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesBadCell;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesBadCellDetail;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesOutPutStatistics;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesRepairRecordExt;
import cn.estsh.i3plus.ext.mes.pojo.model.BadStatisticsReportModel;
import cn.estsh.i3plus.ext.mes.pojo.model.BadStatisticsReportParamModel;
import cn.estsh.i3plus.ext.mes.pojo.model.ProjectBadPerformanceReportModel;
import cn.estsh.i3plus.ext.mes.pojo.model.SxRepairRecordReportModel;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesBadCellDetailRepository;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesBadCellRepository;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesOutPutStatisticsRepository;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesRepairRecordExtRepository;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.tool.MathOperation;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.common.PagerHelper;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author wangjie
 * @version 1.0
 * @date 2021/1/13 9:28
 **/
@Slf4j
@Service
public class SxBadStatisticsReportFormService implements ISxBadStatisticsReportFormService {

    @Autowired
    private MesOutPutStatisticsRepository outPutStatisticsRepository;

    @Autowired
    private MesBadCellRepository badCellRepository;

    @Autowired
    private MesRepairRecordExtRepository repairRecordExtRepository;

    @Autowired
    private ISxRepairRecordDao repairRecordDao;

    @Autowired
    private MesBadCellDetailRepository badCellDetailRepository;

    @Override
    public List<ProjectBadPerformanceReportModel> queryProjectBadPerformance(BadStatisticsReportParamModel model) {
        List<ProjectBadPerformanceReportModel> resultList = null;
        DdlPackBean packBean = DdlPackBean.getDdlPackBean(model.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(model.getWorkCenterCode(), MesExtConstWords.WORK_CENTER_CODE, packBean);
        if (!StringUtils.isEmpty(model.getWorkTimeStart()) || !StringUtils.isEmpty(model.getWorkTimeEnd())) {
            DdlPreparedPack.timeBuilder(model.getWorkTimeStart(), model.getWorkTimeEnd(), MesExtConstWords.WORK_TIME, packBean, false);
        }

        List<MesRepairRecordExt> repairRecordExtList = repairRecordExtRepository.findByHqlWhere(packBean);
        if (CollectionUtils.isEmpty(repairRecordExtList)) {
            log.info("工程不良实绩未查询到维修数据,维度[{}]", MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()));
            return resultList;
        }

        log.info("工程不良实绩已查询到维修数据,维度[{}]", MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()));
        packRepairRecordWorkTime(repairRecordExtList, model);

        Map<String, List<MesRepairRecordExt>> repairRecordMap = packRepairRecordMap(repairRecordExtList);

        List<MesOutPutStatistics> outPutStatisticsList = outPutStatisticsRepository.findByHqlWhere(packBean);
        Map<String, List<MesOutPutStatistics>> outPutStatisticsMap = null;
        if (!CollectionUtils.isEmpty(outPutStatisticsList)) {
            log.info("工程不良实绩已查询到产量数据,维度[{}]", MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()));
            packOutPutStatisticsWorkTime(outPutStatisticsList, model);

            outPutStatisticsMap = packOutPutStatisticsMapForProjectBadPerformance(outPutStatisticsList);
        } else {
            log.info("工程不良实绩未查询到产量数据,维度[{}]", MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()));
        }

        for (String key : repairRecordMap.keySet()) {
            if (StringUtils.isEmpty(key)) {
                continue;
            }
            List<MesRepairRecordExt> itemList = repairRecordMap.get(key);
            if (CollectionUtils.isEmpty(itemList)) {
                continue;
            }

            String[] keyArr = key.split(MesExtConstWords.AND);
            ProjectBadPerformanceReportModel result = new ProjectBadPerformanceReportModel();

            result.setWorkTime(keyArr[0]);
            result.setWorkCenterCode(keyArr[1]);

            List<MesOutPutStatistics> itemOutPutStatisticsList = CollectionUtils.isEmpty(outPutStatisticsMap) ? null : outPutStatisticsMap.get(key);
            //总产量
            result.setQty(getQty(itemOutPutStatisticsList));
            ////误判数
            //result.setMisjudgeQty(getBadQtyByType(itemList, MesExtEnumUtil.REPAIR_JUDGE.MISJUDGE.getValue()));
            ////误判率
            //result.setMisjudgeRate(getRateDecimalOne(result.getMisjudgeQty(), result.getQty()));
            ////部品不良数
            //result.setPartsBadQty(getBadQtyByType(itemList, MesExtEnumUtil.REPAIR_JUDGE.PARTS_BAD.getValue()));
            ////部品不良率
            //result.setPartsBadRate(getRateDecimalOne(result.getPartsBadQty(), result.getQty()));
            ////作业不良数
            //result.setTaskBadQty(getBadQtyByType(itemList, MesExtEnumUtil.REPAIR_JUDGE.TASK_BAD.getValue()));
            //作业不良率
            result.setTaskBadRate(getRateDecimalOne(result.getTaskBadQty(), result.getQty()));
            //总不良率
            result.setAmountBadRate(getRateDecimalOne(CollectionUtils.isEmpty(itemList) ? new Double(0) : new Double(itemList.size()), result.getQty()));

            if (CollectionUtils.isEmpty(resultList)) {
                resultList = new ArrayList<>();
            }
            resultList.add(result);
        }

        log.info("工程不良实绩报表数据开始重新排序,维度[{}]", MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()));
        if (!CollectionUtils.isEmpty(resultList)) {
            resultList = sortProjectBadPerformanceResult(resultList);
            log.info("不良统计报表数据重新排序成功,维度[{}]", MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()));
        }
        return resultList;
    }

    private List<ProjectBadPerformanceReportModel> sortProjectBadPerformanceResult(List<ProjectBadPerformanceReportModel> resultList) {
        return resultList.stream().sorted(Comparator.comparing(ProjectBadPerformanceReportModel::getWorkTime)
                .thenComparing(ProjectBadPerformanceReportModel::getWorkCenterCode)).collect(Collectors.toList());
    }

    private Double getBadQtyByType(List<MesRepairRecordExt> itemList, String type) {
        List<MesRepairRecordExt> list = CollectionUtils.isEmpty(itemList) ? null :
                itemList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getRepairJudgeCode()) && o.getRepairJudgeCode().compareTo(type) == 0)).collect(Collectors.toList());
        return CollectionUtils.isEmpty(list) ? new Double(0) : new Double(list.size());
    }

    private Map<String, List<MesRepairRecordExt>> packRepairRecordMap(List<MesRepairRecordExt> repairRecordExtList) {
        return repairRecordExtList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getWorkTime()) && !StringUtils.isEmpty(o.getWorkCenterCode())))
                .collect(Collectors.groupingBy(o -> (new StringJoiner(MesExtConstWords.AND).add(o.getWorkTime()).add(o.getWorkCenterCode()).toString())));
    }

    @Override
    public List<BadStatisticsReportModel> queryBadStatistics(BadStatisticsReportParamModel model) {
        List<BadStatisticsReportModel> resultList = null;
        DdlPackBean packBean = DdlPackBean.getDdlPackBean(model.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(model.getWorkCellCode(), MesExtConstWords.WORK_CELL_CODE, packBean);
        DdlPreparedPack.getStringEqualPack(model.getWorkCenterCode(), MesExtConstWords.WORK_CENTER_CODE, packBean);
        DdlPreparedPack.getStringEqualPack(model.getPartNo(), MesExtConstWords.PART_NO, packBean);
        if (!StringUtils.isEmpty(model.getWorkTimeStart()) || !StringUtils.isEmpty(model.getWorkTimeEnd())) {
            DdlPreparedPack.timeBuilder(model.getWorkTimeStart(), model.getWorkTimeEnd(), MesExtConstWords.WORK_TIME, packBean, false);
        }

        List<MesBadCell> badCellList = badCellRepository.findByHqlWhere(packBean);
        if (CollectionUtils.isEmpty(badCellList)) {
            log.info("不良统计报表未查询到不良数据,维度[{}][{}]",
                    MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));
            return resultList;
        }

        log.info("不良统计报表已查询到不良数据,维度[{}][{}]",
                MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));

        packBadCellWorkTime(badCellList, model);
        Map<String, List<MesBadCell>> badCellMap = packBadCellMap(badCellList, model.getDimension1());
        if (CollectionUtils.isEmpty(badCellMap)) {
            return resultList;
        }
        log.info("不良统计报表根据维度封装不良数据成功,维度[{}][{}]",
                MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));

        DdlPackBean packBean1 = DdlPackBean.getDdlPackBean(model.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(model.getWorkCenterCode(), MesExtConstWords.WORK_CENTER_CODE, packBean1);
        DdlPreparedPack.getStringEqualPack(model.getPartNo(), MesExtConstWords.PART_NO, packBean1);
        if (!StringUtils.isEmpty(model.getWorkTimeStart()) || !StringUtils.isEmpty(model.getWorkTimeEnd())) {
            DdlPreparedPack.timeBuilder(model.getWorkTimeStart(), model.getWorkTimeEnd(), MesExtConstWords.WORK_TIME, packBean1, false);
        }
        List<MesOutPutStatistics> outPutStatisticsList = outPutStatisticsRepository.findByHqlWhere(packBean1);
        Map<String, List<MesOutPutStatistics>> outPutStatisticsModelMap = null;
        if (CollectionUtils.isEmpty(outPutStatisticsList)) {
            log.info("不良统计报表未查询到产量数据,维度[{}][{}]",
                    MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));
        } else {
            log.info("不良统计报表已查询到产量数据,维度[{}][{}]",
                    MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));

            packOutPutStatisticsWorkTime(outPutStatisticsList, model);
            outPutStatisticsModelMap = packOutPutStatisticsMap(outPutStatisticsList);

            log.info("不良统计报表根据维度封装产量数据成功,维度[{}][{}]",
                    MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));
        }

        for (String key : badCellMap.keySet()) {
            if (StringUtils.isEmpty(key)) {
                continue;
            }
            List<MesBadCell> itemList = badCellMap.get(key);
            if (CollectionUtils.isEmpty(itemList)) {
                continue;
            }

            String[] keyArr = key.split(MesExtConstWords.AND);
            BadStatisticsReportModel result = new BadStatisticsReportModel();
            packBadStatisticsResult(result, keyArr, model.getDimension1(), itemList.get(0));

            List<MesOutPutStatistics> itemOutPutStatisticsList = getItemOutPutStatisticsList(outPutStatisticsModelMap, key, model.getDimension1());
            //生产数量
            result.setQty(getQty(itemOutPutStatisticsList));
            //不良数量
            result.setBadQty(getBadQty(itemList));
            //不良率
            result.setBadRate(getRateDecimalOne(result.getBadQty(), result.getQty()));

            if (CollectionUtils.isEmpty(resultList)) {
                resultList = new ArrayList<>();
            }
            resultList.add(result);
        }

        log.info("不良统计报表数据开始重新排序,维度[{}][{}]",
                MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));
        if (!CollectionUtils.isEmpty(resultList)) {
            resultList = sortBadStatisticsResult(resultList, model.getDimension1());
            log.info("不良统计报表数据重新排序成功,维度[{}][{}]",
                    MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));
        }

        return resultList;
    }

    private void packRepairRecordWorkTime(List<MesRepairRecordExt> repairRecordExtList, BadStatisticsReportParamModel model) {
        if (MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.MONTH.getValue() == model.getDimension()) {
            repairRecordExtList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getWorkTime()))).forEach(o -> {
                o.setWorkTime(o.getWorkTime().substring(0, 7));
            });
        }
    }

    private void packOutPutStatisticsWorkTime(List<MesOutPutStatistics> outPutStatisticsList, BadStatisticsReportParamModel model) {
        if (MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.MONTH.getValue() == model.getDimension()) {
            outPutStatisticsList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getWorkTime()))).forEach(o -> {
                o.setWorkTime(o.getWorkTime().substring(0, 7));
            });
        }
    }

    private void packBadCellWorkTime(List<MesBadCell> badCellList, BadStatisticsReportParamModel model) {
        if (MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.MONTH.getValue() == model.getDimension()) {
            badCellList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getWorkTime()))).forEach(o -> {
                o.setWorkTime(o.getWorkTime().substring(0, 7));
            });
        }
    }

    private Map<String, List<MesOutPutStatistics>> packOutPutStatisticsMap(List<MesOutPutStatistics> outPutStatisticsList) {
        return outPutStatisticsList.stream().filter(o -> (null != o &&
                !StringUtils.isEmpty(o.getWorkTime()) && !StringUtils.isEmpty(o.getShiftCode()) && !StringUtils.isEmpty(o.getWorkCenterCode()) && !StringUtils.isEmpty(o.getPartNo())))
                .collect(Collectors.groupingBy(o -> (new StringJoiner(MesExtConstWords.AND).add(o.getWorkTime()).add(o.getShiftCode()).add(o.getWorkCenterCode()).add(o.getPartNo()).toString())));
    }

    private Map<String, List<MesOutPutStatistics>> packOutPutStatisticsMapForProjectBadPerformance(List<MesOutPutStatistics> outPutStatisticsList) {
        return outPutStatisticsList.stream().filter(o -> (null != o &&
                !StringUtils.isEmpty(o.getWorkTime()) && !StringUtils.isEmpty(o.getWorkCenterCode())))
                .collect(Collectors.groupingBy(o -> (new StringJoiner(MesExtConstWords.AND).add(o.getWorkTime()).add(o.getWorkCenterCode()).toString())));
    }

    private Map<String, List<MesBadCell>> packBadCellMap(List<MesBadCell> badCellList, Integer dimension) {
        Map<String, List<MesBadCell>> badCellMap;
        switch (MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.getByValue(dimension)) {
            case CELL:
                badCellMap = badCellList.stream().filter(o -> (null != o &&
                        !StringUtils.isEmpty(o.getWorkTime()) && !StringUtils.isEmpty(o.getShiftCode()) && !StringUtils.isEmpty(o.getWorkCenterCode()) && !StringUtils.isEmpty(o.getWorkCellCode()) && !StringUtils.isEmpty(o.getPartNo())))
                        .collect(Collectors.groupingBy(o -> (new StringJoiner(MesExtConstWords.AND).add(o.getWorkTime()).add(o.getShiftCode()).add(o.getWorkCenterCode()).add(o.getPartNo()).add(o.getWorkCellCode()).toString())));
                break;
            case CENTER:
            default:
                badCellMap = badCellList.stream().filter(o -> (null != o &&
                        !StringUtils.isEmpty(o.getWorkTime()) && !StringUtils.isEmpty(o.getShiftCode()) && !StringUtils.isEmpty(o.getWorkCenterCode()) && !StringUtils.isEmpty(o.getPartNo())))
                        .collect(Collectors.groupingBy(o -> (new StringJoiner(MesExtConstWords.AND).add(o.getWorkTime()).add(o.getShiftCode()).add(o.getWorkCenterCode()).add(o.getPartNo()).toString())));
                break;
        }
        return badCellMap;
    }

    private void packBadStatisticsResult(BadStatisticsReportModel result, String[] keyArr, Integer dimension, MesBadCell badCell) {
        result.setWorkTime(keyArr[0]);
        result.setShiftCode(keyArr[1]);
        result.setWorkCenterCode(keyArr[2]);
        result.setPartNo(keyArr[3]);
        result.setPartNameRdd(badCell.getPartNameRdd());
        switch (MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.getByValue(dimension)) {
            case CELL:
                result.setWorkCellCode(keyArr[4]);
                break;
            case CENTER:
            default:
                break;
        }
    }

    private List<MesOutPutStatistics> getItemOutPutStatisticsList(Map<String, List<MesOutPutStatistics>> outPutStatisticsModelMap, String key, Integer dimension) {
        List<MesOutPutStatistics> itemOutPutStatisticsList = null;
        if (CollectionUtils.isEmpty(outPutStatisticsModelMap)) {
            return itemOutPutStatisticsList;
        }
        return outPutStatisticsModelMap.get(MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.CENTER.getValue() == dimension ? key : key.substring(0, key.lastIndexOf(MesExtConstWords.AND)));
    }

    private Double getQty(List<MesOutPutStatistics> itemOutPutStatisticsList) {
        return CollectionUtils.isEmpty(itemOutPutStatisticsList) ? new Double(0) :
                itemOutPutStatisticsList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getQty()))).mapToDouble(MesOutPutStatistics::getQty).sum();
    }

    private Double getBadQty(List<MesBadCell> itemBadCellList) {
        return CollectionUtils.isEmpty(itemBadCellList) ? new Double(0) :
                itemBadCellList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getQty()))).mapToDouble(MesBadCell::getQty).sum();
    }

    private String getRateDecimalOne(Double d1, Double d2) {
        if (StringUtils.isEmpty(d2) || MathOperation.compareTo(d2, new Double(0)) == 0) {
            return null;
        }
        return MathOperation.div(MathOperation.mul(d1, 100), d2, 1) + MesExtConstWords.PERCENT;
    }

    private List<BadStatisticsReportModel> sortBadStatisticsResult(List<BadStatisticsReportModel> resultList, Integer dimension) {
        switch (MesExtEnumUtil.BAD_STATISTICS_REPORT_DIMENSION.getByValue(dimension)) {
            case CELL:
                resultList = resultList.stream().sorted(Comparator.comparing(BadStatisticsReportModel::getWorkTime)
                        .thenComparing(BadStatisticsReportModel::getShiftCode)
                        .thenComparing(BadStatisticsReportModel::getWorkCenterCode)
                        .thenComparing(BadStatisticsReportModel::getWorkCellCode)
                        .thenComparing(BadStatisticsReportModel::getPartNo)).collect(Collectors.toList());
                break;
            case CENTER:
            default:
                resultList = resultList.stream().sorted(Comparator.comparing(BadStatisticsReportModel::getWorkTime)
                        .thenComparing(BadStatisticsReportModel::getShiftCode)
                        .thenComparing(BadStatisticsReportModel::getWorkCenterCode)
                        .thenComparing(BadStatisticsReportModel::getPartNo)).collect(Collectors.toList());
                break;
        }
        return resultList;
    }

    @Override
    public ListPager<SxRepairRecordReportModel> queryRepairDetailReport(SxRepairRecordReportModel model, Pager pager) {
        pager = PagerHelper.getPager(pager, repairRecordDao.queryRepairRecordByPagerCount(model));
        List<SxRepairRecordReportModel> resultList = repairRecordDao.queryRepairRecordByPager(model , pager);
        if (!CollectionUtils.isEmpty(resultList)) {
            for (SxRepairRecordReportModel item : resultList) {
                if (null != item) {
                    item.setApprovalStatusName(!StringUtils.isEmpty(item.getApprovalStatus()) ? MesExtEnumUtil.BAD_CELL_DETAIL_APPROVAL_STATUS.valueOfDescription(item.getApprovalStatus()) : null);
                    item.setRepairStatusName(!StringUtils.isEmpty(item.getRepairStatus()) ? MesExtEnumUtil.REPAIR_STATUS.valueOfDescription(item.getRepairStatus()) : null);
                    //item.setRepairJudgeName(!StringUtils.isEmpty(item.getRepairJudge()) ? MesExtEnumUtil.REPAIR_JUDGE.valueOfDescription(item.getRepairJudge()) : null);
                }
            }
        }
        return new ListPager(resultList, pager);
    }

    @Override
    public void updateApprovalStatusById(long id, Integer status) {
        MesBadCellDetail mesBadCellDetailByDb = badCellDetailRepository.getById(id);
        if (null == mesBadCellDetailByDb) {
            throw ImppExceptionBuilder.newInstance()
                    .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
                    .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode())
                    .setErrorDetail("ID[%s]不良明细记录不存在", id)
                    .build();
        }
        mesBadCellDetailByDb.setApprovalStatus(status);
        ConvertBean.serviceModelUpdate(mesBadCellDetailByDb, AuthUtil.getSessionUser().getUserName());
        badCellDetailRepository.update(mesBadCellDetailByDb);
    }
}
