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

import cn.estsh.i3plus.ext.mes.api.busi.ISxOqcReportFormService;
import cn.estsh.i3plus.ext.mes.api.busi.ISxReportFormService;
import cn.estsh.i3plus.ext.mes.apiservice.dao.IOqcCheckDao;
import cn.estsh.i3plus.ext.mes.apiservice.dao.IOutPutStatisticsDao;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesErrorLineOff;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesErrorLineOffDetail;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesOqcCheck;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesOqcCheckDetail;
import cn.estsh.i3plus.ext.mes.pojo.model.*;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesErrorLineOffDetailRepository;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesErrorLineOffRepository;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesOqcCheckDetailRepository;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesOqcCheckRepository;
import cn.estsh.i3plus.ext.mes.pojo.sqlpack.MesExtHqlPack;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
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 SxOqcReportFormService implements ISxOqcReportFormService {

    @Autowired
    private IOutPutStatisticsDao outPutStatisticsDao;

    @Autowired
    private IOqcCheckDao oqcCheckDao;

    @Autowired
    private MesOqcCheckRepository oqcCheckRepository;

    @Autowired
    private MesOqcCheckDetailRepository oqcCheckDetailRepository;

    @Autowired
    private ISxReportFormService sxReportFormService;

    @Autowired
    private MesErrorLineOffRepository errorLineOffRepository;

    @Autowired
    private MesErrorLineOffDetailRepository errorLineOffDetailRepository;

    @Override
    public ListPager<OqcLastCheckDetailModel> queryOqcLastCheckDetailPager(OqcReportParamModel model, Pager pager) {
        pager = PagerHelper.getPager(pager, outPutStatisticsDao.queryOqcLastCheckDetailPagerCount(model));
        List<OqcLastCheckDetailModel> resultList = outPutStatisticsDao.queryOqcLastCheckDetailPager(model , pager);

        if (!CollectionUtils.isEmpty(resultList)) {

            DdlPackBean packBean = DdlPackBean.getDdlPackBean(model.getOrganizeCode());
            DdlPreparedPack.getStringEqualPack(model.getWorkOrderNo(), MesExtConstWords.ORDER_NO, packBean);
            DdlPreparedPack.getStringEqualPack(model.getPartNo(), MesExtConstWords.PART_NO, packBean);
            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<MesOqcCheck> oqcCheckList = oqcCheckRepository.findByHqlWhere(packBean);
            Map<String, List<MesOqcCheck>> lotMap = CollectionUtils.isEmpty(oqcCheckList) ? null :
                    oqcCheckList.stream().filter(o -> (null != o))
                            .collect(Collectors.groupingBy(o -> new StringJoiner(MesExtConstWords.AND).add(o.getWorkOrderNo()).add(o.getWorkTime()).add(o.getShiftCode()).toString()));

            DdlPackBean packBean1 = DdlPackBean.getDdlPackBean(model.getOrganizeCode());
            DdlPreparedPack.getStringEqualPack(model.getWorkOrderNo(), MesExtConstWords.ORDER_NO, packBean1);
            DdlPreparedPack.getStringEqualPack(model.getPartNo(), MesExtConstWords.PART_NO, packBean1);
            DdlPreparedPack.getStringEqualPack(model.getWorkCenterCode(), MesExtConstWords.WORK_CENTER_CODE, packBean1);
            if (!StringUtils.isEmpty(model.getWorkTimeStart()) || !StringUtils.isEmpty(model.getWorkTimeEnd())) {
                DdlPreparedPack.timeBuilder(model.getWorkTimeStart(), model.getWorkTimeEnd(), MesExtConstWords.WORK_TIME, packBean1, false);
            }
            DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.OQC_PROJECT_RESULT.NG.getValue(), MesExtConstWords.RESULT, packBean1);
            List<MesOqcCheckDetail> oqcCheckDetailList = oqcCheckDetailRepository.findByHqlWhere(packBean1);
            Map<String, List<MesOqcCheckDetail>> projectMap = CollectionUtils.isEmpty(oqcCheckDetailList) ? null :
                    oqcCheckDetailList.stream().filter(o -> (null != o)).collect(Collectors.groupingBy(MesOqcCheckDetail::getOqcNo));

            for (OqcLastCheckDetailModel result : resultList) {
                if (null == result) {
                    continue;
                }
                result.setCheckResultName(
                        (StringUtils.isEmpty(result.getCheckResult()) || StringUtils.isEmpty(MesExtEnumUtil.OQC_TOTAL_STATUS.valueOfDescription(result.getCheckResult())))
                                ? MesExtEnumUtil.OQC_TOTAL_STATUS.UNTREATED.getDescription()
                                : MesExtEnumUtil.OQC_TOTAL_STATUS.valueOfDescription(result.getCheckResult()));
                List<MesOqcCheck> itemList = CollectionUtils.isEmpty(lotMap) ? null :
                        lotMap.get(new StringJoiner(MesExtConstWords.AND).add(result.getWorkOrderNo()).add(result.getWorkTime()).add(result.getShiftCode()).toString());
                if (!CollectionUtils.isEmpty(itemList)) {
                    List<String> unQcList;
                    if (!StringUtils.isEmpty(itemList.get(0).getSerialNumber())) {
                        //成品
                        unQcList = (itemList.stream().filter(o ->
                                (null != o && !StringUtils.isEmpty(o.getCheckResult()) && MesExtEnumUtil.OQC_CHECK_RESULT.UNQUALIFIED.getValue() == o.getCheckResult()))
                                .map(MesOqcCheck::getSerialNumber).collect(Collectors.toList()))
                                .stream().filter(o -> !StringUtils.isEmpty(o)).distinct().collect(Collectors.toList());
                    } else {
                        //组件
                        unQcList = itemList.stream().filter(o ->
                                (null != o && !StringUtils.isEmpty(o.getCheckResult()) && MesExtEnumUtil.OQC_CHECK_RESULT.UNQUALIFIED.getValue() == o.getCheckResult()))
                                .map(MesOqcCheck::getOqcNo).collect(Collectors.toList());
                    }
                    result.setUnQcQty(CollectionUtils.isEmpty(unQcList) ? 0 : unQcList.size());

                    List<OqcLastCheckDetailModel> detailList = new ArrayList<>();
                    for (MesOqcCheck oqcCheck : itemList) {
                        if (null == oqcCheck) {
                            continue;
                        }
                        OqcLastCheckDetailModel detail = new OqcLastCheckDetailModel();
                        BeanUtils.copyProperties(oqcCheck, detail);
                        detail.setOqcTypeName(MesExtEnumUtil.OQC_CHECK_TYPE.valueOfDescription(detail.getOqcType()));
                        detail.setCheckResultName(
                                (StringUtils.isEmpty(detail.getCheckResult()) || StringUtils.isEmpty(MesExtEnumUtil.OQC_CHECK_RESULT.valueOfDescription(detail.getCheckResult())))
                                        ? null : MesExtEnumUtil.OQC_CHECK_RESULT.valueOfDescription(detail.getCheckResult()));
                        detail.setUnQcQty((!CollectionUtils.isEmpty(projectMap) && projectMap.containsKey(oqcCheck.getOqcNo())) ? projectMap.get(oqcCheck.getOqcNo()).size() : 0);
                        detailList.add(detail);
                    }
                    result.setDetailList(detailList);
                }
            }
        }
        return new ListPager(resultList, pager);
    }

    @Override
    public ListPager<OqcCheckModel> queryOqcCheckDetailPager(OqcReportParamModel model, Pager pager) {
        pager = PagerHelper.getPager(pager, oqcCheckDao.queryOqcCheckDetailPagerCount(model));
        List<OqcCheckModel> resultList = oqcCheckDao.queryOqcCheckDetailByPager(model , pager);
        if (!CollectionUtils.isEmpty(resultList)) {
            for (OqcCheckModel result : resultList) {
                if (null == result) {
                    continue;
                }
                result.setOqcTypeName(MesExtEnumUtil.OQC_CHECK_TYPE.valueOfDescription(result.getOqcType()));
                result.setCheckResultName(
                        (StringUtils.isEmpty(result.getCheckResult()) || StringUtils.isEmpty(MesExtEnumUtil.OQC_CHECK_RESULT.valueOfDescription(result.getCheckResult())))
                                ? null : MesExtEnumUtil.OQC_CHECK_RESULT.valueOfDescription(result.getCheckResult()));
                result.setWorkOrderTypeName(MesExtEnumUtil.WORK_ORDER_TYPE.valueOfDescription(result.getWorkOrderType()));
            }
        }
        return new ListPager(resultList, pager);
    }

    @Override
    public ListPager<MesOqcCheckDetail> queryOqcCheckProjectDetailPager(OqcReportParamModel model, Pager pager) {
        MesOqcCheckDetail detail = new MesOqcCheckDetail();
        detail.setOrganizeCode(model.getOrganizeCode());
        detail.setOqcNo(model.getOqcNo());
        DdlPackBean hqlPack = MesExtHqlPack.getOqcCheckDetail(detail);
        pager = PagerHelper.getPager(pager, oqcCheckDetailRepository.findByHqlWhereCount(hqlPack));
        hqlPack.setOrderByStr(" order by seq asc ");
        List<MesOqcCheckDetail> oqcCheckDetailList = oqcCheckDetailRepository.findByHqlWherePage(hqlPack, pager);
        if (!CollectionUtils.isEmpty(oqcCheckDetailList)) {
            //for (MesOqcCheckDetail item : oqcCheckDetailList) {
            //    if (null == item) {
            //        continue;
            //    }
            //    item.setResultName(
            //            (StringUtils.isEmpty(item.getResult()) || StringUtils.isEmpty(MesExtEnumUtil.OQC_PROJECT_RESULT.valueOfDescription(item.getResult())))
            //                    ? null : MesExtEnumUtil.OQC_PROJECT_RESULT.valueOfDescription(item.getResult()));
            //}
        }
        return new ListPager(oqcCheckDetailList, pager);
    }

    @Override
    public List<OqcCheckStatisticsModel> queryOqcCheckStatistics(OqcReportParamModel model) {
        List<OqcCheckStatisticsModel> resultList = null;
        List<OqcCheckStatisticsModel> modelList = outPutStatisticsDao.queryOqcLastCheckDetailList(model);
        if (CollectionUtils.isEmpty(modelList)) {
            log.info("出货检验月报日报未查询到数据,维度[{}][{}]",
                    MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.OQC_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));
            return resultList;
        }
        log.info("出货检验月报日报已查询到数据,维度[{}][{}]",
                MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.OQC_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));
        packOqcCheckStatisticsWorkTime(modelList, model);

        Map<String, List<OqcCheckStatisticsModel>> modelMap = packOqcCheckStatisticsMap(modelList, model.getDimension1());
        if (CollectionUtils.isEmpty(modelMap)) {
            return resultList;
        }
        log.info("出货检验月报日报根据维度封装数据成功,维度[{}][{}]",
                MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.OQC_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));
        List<OqcCheckModel> oqcCheckModelList = oqcCheckDao.queryOqcCheckListByPart(model);
        packOqcCheckListWorkTime(oqcCheckModelList, model);

        Map<String, List<OqcCheckModel>> oqcCheckMap = CollectionUtils.isEmpty(oqcCheckModelList) ? null : packOqcCheckMap(oqcCheckModelList, model.getDimension1());

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

            String[] keyArr = key.split(MesExtConstWords.AND);
            OqcCheckStatisticsModel result = new OqcCheckStatisticsModel();
            packOqcCheckStatisticsResult(result, keyArr, model.getDimension1(), itemList.get(0));
            //生产批量数=产量行数
            result.setWorkTimesQty(itemList.size());
            //检验批量数=有检验结果的产量行数
            List<OqcCheckStatisticsModel> lastCheckedList = itemList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getCheckResult()))).collect(Collectors.toList());
            result.setLastCheckedOty(CollectionUtils.isEmpty(lastCheckedList) ? 0 : lastCheckedList.size());
            //检验台数=汇总产量数量的抽检数量
            Double checkAmountQty = itemList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getSpotCheckQty()))).mapToDouble(OqcCheckStatisticsModel::getSpotCheckQty).sum();
            result.setCheckAmountQty(checkAmountQty);
            //产量=汇总产量数量的产量
            Double qty = itemList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getQty()))).mapToDouble(OqcCheckStatisticsModel::getQty).sum();
            result.setQty(qty);
            //抽样率=检验台数/产量,保留2位小数
            result.setSampleRate(sxReportFormService.getRateDecimalTwo(checkAmountQty, qty));
            //缺点数=汇总检验单不合格行数
            result.setUnQcQty(getOqcCheckStatisticsUnQcQty(CollectionUtils.isEmpty(oqcCheckMap) ? null : oqcCheckMap.get(key)));

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

        log.info("出货检验月报日报数据开始重新排序,维度[{}][{}]",
                MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.OQC_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));
        if (!CollectionUtils.isEmpty(resultList)) {
            resultList = sortOqcCheckStatisticsResult(resultList, model.getDimension1());
            log.info("出货检验月报日报数据重新排序成功,维度[{}][{}]",
                    MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.valueOfDescription(model.getDimension()), MesExtEnumUtil.OQC_REPORT_DIMENSION.valueOfDescription(model.getDimension1()));
        }

        return resultList;
    }

    private Integer getOqcCheckStatisticsUnQcQty(List<OqcCheckModel> oqcCheckModelList) {
        if (CollectionUtils.isEmpty(oqcCheckModelList)) {
            return 0;
        }
        oqcCheckModelList = oqcCheckModelList.stream().filter(o -> (null != o
                && !StringUtils.isEmpty(o.getCheckResult()) && MesExtEnumUtil.OQC_CHECK_RESULT.UNQUALIFIED.getValue() == o.getCheckResult())).collect(Collectors.toList());
        List<String> snList = CollectionUtils.isEmpty(oqcCheckModelList) ? null :
                (oqcCheckModelList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getSerialNumber())))
                        .map(OqcCheckModel::getSerialNumber).collect(Collectors.toList()))
                        .stream().filter(o -> !StringUtils.isEmpty(o)).distinct().collect(Collectors.toList());
        List<String> unSnList = CollectionUtils.isEmpty(oqcCheckModelList) ? null :
                oqcCheckModelList.stream().filter(o -> (null != o && StringUtils.isEmpty(o.getSerialNumber()))).map(OqcCheckModel::getOqcNo).collect(Collectors.toList());
        return (CollectionUtils.isEmpty(snList) ? 0 : snList.size()) + (CollectionUtils.isEmpty(unSnList) ? 0 : unSnList.size());
    }

    private void packOqcCheckStatisticsWorkTime(List<OqcCheckStatisticsModel> modelList, OqcReportParamModel model) {
        modelList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getWorkTime()))).forEach(o -> {
            if (MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.MONTH.getValue() == model.getDimension()) {
                o.setWorkTime(o.getWorkTime().substring(0, 7));
            }
            if (StringUtils.isEmpty(o.getSalesTo())) {
                o.setSalesTo(" ");
            }
        });
    }

    private void packOqcCheckListWorkTime(List<OqcCheckModel> modelList, OqcReportParamModel model) {
        if (CollectionUtils.isEmpty(modelList)) {
            return;
        }
        modelList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getWorkTime()))).forEach(o -> {
            if (MesExtEnumUtil.REPORT_DIMENSION_DAY_OR_MONTH.MONTH.getValue() == model.getDimension()) {
                o.setWorkTime(o.getWorkTime().substring(0, 7));
            }
            if (StringUtils.isEmpty(o.getSalesTo())) {
                o.setSalesTo(" ");
            }
        });
    }

    private Map<String, List<OqcCheckStatisticsModel>> packOqcCheckStatisticsMap(List<OqcCheckStatisticsModel> modelList, Integer dimension) {
        Map<String, List<OqcCheckStatisticsModel>> modelMap;
        if (CollectionUtils.isEmpty(modelList)) {
            return null;
        }
        switch (MesExtEnumUtil.OQC_REPORT_DIMENSION.getByValue(dimension)) {
            case PART_NO:
                modelMap = modelList.stream().filter(
                        o -> (null != o && !StringUtils.isEmpty(o.getWorkTime()) && !StringUtils.isEmpty(o.getCategoryCode3()) && !StringUtils.isEmpty(o.getPartNo())))
                        .collect(Collectors.groupingBy(o -> (new StringJoiner(MesExtConstWords.AND).add(o.getWorkTime()).add(o.getCategoryCode3()).add(o.getSalesTo()).add(o.getPartNo()).toString())));
                break;
            case CATEGORY_CODE3:
            default:
                modelMap = modelList.stream().filter(
                        o -> (null != o && !StringUtils.isEmpty(o.getWorkTime()) && !StringUtils.isEmpty(o.getCategoryCode3())))
                        .collect(Collectors.groupingBy(o -> (new StringJoiner(MesExtConstWords.AND).add(o.getWorkTime()).add(o.getCategoryCode3()).add(o.getSalesTo()).toString())));
                break;
        }
        return modelMap;
    }

    private Map<String, List<OqcCheckModel>> packOqcCheckMap(List<OqcCheckModel> oqcCheckModelList, Integer dimension) {
        Map<String, List<OqcCheckModel>> oqcCheckMap;
        if (CollectionUtils.isEmpty(oqcCheckModelList)) {
            return null;
        }
        switch (MesExtEnumUtil.OQC_REPORT_DIMENSION.getByValue(dimension)) {
            case PART_NO:
                oqcCheckMap = oqcCheckModelList.stream().filter(
                        o -> (null != o && !StringUtils.isEmpty(o.getWorkTime()) && !StringUtils.isEmpty(o.getCategoryCode3()) && !StringUtils.isEmpty(o.getPartNo())))
                        .collect(Collectors.groupingBy(o -> (new StringJoiner(MesExtConstWords.AND).add(o.getWorkTime()).add(o.getCategoryCode3()).add(o.getSalesTo()).add(o.getPartNo()).toString())));
                break;
            case CATEGORY_CODE3:
            default:
                oqcCheckMap = oqcCheckModelList.stream().filter(
                        o -> (null != o && !StringUtils.isEmpty(o.getWorkTime()) && !StringUtils.isEmpty(o.getCategoryCode3())))
                        .collect(Collectors.groupingBy(o -> (new StringJoiner(MesExtConstWords.AND).add(o.getWorkTime()).add(o.getCategoryCode3()).add(o.getSalesTo()).toString())));
                break;
        }
        return oqcCheckMap;
    }

    private void packOqcCheckStatisticsResult(OqcCheckStatisticsModel result, String[] keyArr, Integer dimension, OqcCheckStatisticsModel model) {
        result.setWorkTime(keyArr[0]);
        result.setCategoryCode3(keyArr[1]);
        result.setSalesTo(keyArr[2]);
        if (!StringUtils.isEmpty(result.getSalesTo()) && !result.getSalesTo().equals(" ")) {
            result.setSalesToName(MesExtEnumUtil.SALES_TO.valueOfDescription(Integer.valueOf(keyArr[2])));
        }
        switch (MesExtEnumUtil.OQC_REPORT_DIMENSION.getByValue(dimension)) {
            case PART_NO:
                result.setPartNo(keyArr[3]);
                result.setPartNameRdd(model.getPartNameRdd());
                break;
            case CATEGORY_CODE3:
            default:
                break;
        }
    }

    private List<OqcCheckStatisticsModel> sortOqcCheckStatisticsResult(List<OqcCheckStatisticsModel> resultList, Integer dimension) {
        switch (MesExtEnumUtil.OQC_REPORT_DIMENSION.getByValue(dimension)) {
            case PART_NO:
                resultList = resultList.stream().sorted(Comparator.comparing(OqcCheckStatisticsModel::getWorkTime)
                        .thenComparing(OqcCheckStatisticsModel::getCategoryCode3)
                        .thenComparing(OqcCheckStatisticsModel::getSalesTo)
                        .thenComparing(OqcCheckStatisticsModel::getPartNo)).collect(Collectors.toList());
                break;
            case CATEGORY_CODE3:
            default:
                resultList = resultList.stream().sorted(Comparator.comparing(OqcCheckStatisticsModel::getWorkTime)
                        .thenComparing(OqcCheckStatisticsModel::getCategoryCode3)
                        .thenComparing(OqcCheckStatisticsModel::getSalesTo)).collect(Collectors.toList());
                break;
        }
        return resultList;
    }

    @Override
    public ListPager<ErrorOffLineModel> queryErrorLineOffFreConfirm(ErrorOffLineModel model, Pager pager) {
        List<ErrorOffLineModel> resultList = new ArrayList<>();
        DdlPackBean hqlPack = MesExtHqlPack.getErrorLineOff(model);
        pager = PagerHelper.getPager(pager, errorLineOffRepository.findByHqlWhereCount(hqlPack));
        hqlPack.setOrderByStr(" order by modifyDatetime desc ");
        List<MesErrorLineOff> errorLineOffList = errorLineOffRepository.findByHqlWherePage(hqlPack, pager);
        if (!CollectionUtils.isEmpty(errorLineOffList)) {
            for (MesErrorLineOff errorLineOff : errorLineOffList) {
                if (null == errorLineOff) {
                    continue;
                }
                ErrorOffLineModel result = new ErrorOffLineModel();
                BeanUtils.copyProperties(errorLineOff, result);
                result.setFreStatusName(StringUtils.isEmpty(result.getFreStatus()) ? null :CommonEnumUtil.TRUE_OR_FALSE.valueOfDescription(result.getFreStatus()));
                result.setConfirmStatusName(StringUtils.isEmpty(result.getConfirmStatus()) ? null :CommonEnumUtil.TRUE_OR_FALSE.valueOfDescription(result.getConfirmStatus()));
                resultList.add(result);
            }
        }
        return new ListPager(resultList, pager);
    }

    @Override
    public List<ErrorOffLineDetailModel> queryErrorLineOffFreConfirmDetail(ErrorOffLineDetailModel model) {
        List<ErrorOffLineDetailModel> resultList = null;
        List<MesErrorLineOffDetail> errorLineOffDetailList = errorLineOffDetailRepository.findByProperty(new String[]{MesExtConstWords.PID}, new Object[]{model.getId()});
        if (!CollectionUtils.isEmpty(errorLineOffDetailList)) {
            for (MesErrorLineOffDetail errorLineOffDetail : errorLineOffDetailList) {
                if (null == errorLineOffDetail) {
                    continue;
                }
                ErrorOffLineDetailModel result = new ErrorOffLineDetailModel();
                BeanUtils.copyProperties(errorLineOffDetail, result);
                result.setPartNo(model.getPartNo());
                result.setPartName(model.getPartName());
                if (CollectionUtils.isEmpty(resultList)) {
                    resultList = new ArrayList<>();
                }
                resultList.add(result);
            }
        }
        return resultList;
    }
}
