package cn.estsh.i3plus.ext.mes.apiservice.daoimpl;

import cn.estsh.i3plus.ext.mes.apiservice.dao.IProjectContainersComputeChartDao;
import cn.estsh.i3plus.ext.mes.pojo.model.ProduceSnRepairModel;
import cn.estsh.i3plus.ext.mes.pojo.model.ProjectContainersComputeChartParamModel;
import cn.estsh.i3plus.ext.mes.pojo.model.ProjectContainersComputeChartResultModel;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
import cn.estsh.i3plus.platform.common.tool.MathOperation;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.util.StringUtil;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

@Service
public class ProjectContainersComputeChartDao implements IProjectContainersComputeChartDao {

    @Autowired
    private EntityManager entityManager;

    @Override
    public List<ProjectContainersComputeChartResultModel> queryProduceQty(ProjectContainersComputeChartParamModel paramModel) {

        StringBuffer hql = new StringBuffer();
        hql.append(" select new " + ProjectContainersComputeChartResultModel.class.getName() + "(o.workTime, sum(o.qty) as produceQty, o.partNo, o.partName )" );
        hql.append(" from MesOutPutStatistics as o");
        hql.append(" where o.organizeCode = :organizeCode ");
        hql.append(" and o.isValid = :isValid ");
        hql.append(" and o.isDeleted = :isDeleted ");
        if (!StringUtils.isEmpty(paramModel.getWorkTimeStart()) && !StringUtils.isEmpty(paramModel.getWorkTimeEnd())) {
            hql.append(" and o.workTime >= :workTimeStart");
            hql.append(" and o.workTime <= :workTimeEnd");
        }
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            hql.append(" and o.partNo = :partNo ");
        }
        hql.append(" group by o.workTime,o.partNo ");
        hql.append(" order by o.workTime desc ");

        Query query = entityManager.createQuery(hql.toString(), ProjectContainersComputeChartResultModel.class);
        query.setParameter(MesExtConstWords.ORGANIZE_CODE, AuthUtil.getOrganizeCode());
        query.setParameter(MesExtConstWords.IS_VALID, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        query.setParameter(MesExtConstWords.IS_DELETED, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        if (!StringUtils.isEmpty(paramModel.getWorkTimeStart()) && !StringUtils.isEmpty(paramModel.getWorkTimeEnd())) {
            query.setParameter(MesExtConstWords.WORK_TIME_START, paramModel.getWorkTimeStart());
            query.setParameter(MesExtConstWords.WORK_TIME_END, paramModel.getWorkTimeEnd());
        }
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            query.setParameter(MesExtConstWords.PART_NO, paramModel.getPartNo());
        }

        return query.getResultList();
    }

    @Override
    public List<ProjectContainersComputeChartResultModel> queryBadQty(ProjectContainersComputeChartParamModel paramModel) {


        return null;
    }


    @Override
    public int queryPartCheckDetailByDefectCodeCount(ProjectContainersComputeChartParamModel paramModel) {
        StringBuffer hql = new StringBuffer();
        hql.append("SELECT count(1)" +
                "FROM\n" +
                "\tmes_bad_cell_detail AS b\n" +
                "\tLEFT JOIN mes_repair_record r ON r.defect_record_id = b.id \n" +
                "\tAND b.organize_code = :organizeCode \n" +
                "\tAND b.is_deleted = :isDeleted \n" +
                "\tAND b.is_valid = :isValid\n" +
                "\tLEFT JOIN mes_repair_record_ext re ON r.id = re.pid \n" +
                "\tAND r.organize_code = :organizeCode \n" +
                "\tAND r.is_deleted = :isDeleted \n" +
                "\tAND r.is_valid = :isValid\n" +
                "\tINNER JOIN (\n" +
                "\tSELECT\n" +
                "\t\to.work_time AS work_time,\n" +
                "\t\tsum( o.qty ) AS produce_qty,\n" +
                "\t\to.part_no AS part_no \n" +
                "\tFROM\n" +
                "\t\tmes_out_put_statistics o \n" +
                "\tWHERE\n" +
                "\t\to.work_time >= :workTimeStart " +
                "\t\tAND o.work_time <= :workTimeEnd" +
                "\tAND o.organize_code = :organizeCode \n" +
                "\tAND o.is_deleted = :isDeleted \n" +
                "\tAND o.is_valid = :isValid " +
                "\tGROUP BY\n" +
                "\t\to.work_time,\n" +
                "\t\to.part_no \n" +
                "\tORDER BY\n" +
                "\t\to.work_time DESC \n" +
                "\t) AS o1 ON o1.work_time = b.work_time \n" +
                "\tAND o1.part_no = b.part_no \n" +
                "WHERE\n" +
                "\tb.work_time >= :workTimeStart " +
                "\tAND b.work_time <= :workTimeEnd" +
                "\tAND b.approval_status = :approvalStatus " );
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            hql.append("\tAND b.part_no = :partNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getDefectName())) {
            hql.append("\tAND b.defect_name like :defectName " );
        }
        hql.append("GROUP BY\n" +
                "\tb.defect_code,\n" +
                "\tb.work_time,\n" +
                "\tb.part_no");
        Query query = entityManager.createNativeQuery(hql.toString());
        query.setParameter(MesExtConstWords.ORGANIZE_CODE, AuthUtil.getOrganizeCode());
        query.setParameter(MesExtConstWords.IS_VALID, CommonEnumUtil.IS_VAILD.VAILD.getValue());
        query.setParameter(MesExtConstWords.IS_DELETED, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        query.setParameter(MesExtConstWords.WORK_TIME_START, paramModel.getWorkTimeStart());
        query.setParameter(MesExtConstWords.WORK_TIME_END, paramModel.getWorkTimeEnd());
        query.setParameter(MesExtConstWords.APPROVAL_STATUS, MesExtEnumUtil.BAD_CELL_DETAIL_APPROVAL_STATUS.APPROVAL.getValue());
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            query.setParameter(MesExtConstWords.PART_NO, paramModel.getPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getDefectName())) {
            query.setParameter(MesExtConstWords.DEFECT_NAME, "%"+paramModel.getDefectName()+"%");
        }
        List resultList = query.getResultList();
        Integer count = Integer.valueOf(resultList.size());
        return count;
    }

    @Override
    public List<ProjectContainersComputeChartResultModel> queryPartCheckDetailByDefectCodePager(ProjectContainersComputeChartParamModel paramModel, Pager pager) {
        StringBuffer hql = new StringBuffer();
        hql.append("SELECT\n" +
                "\tb.work_time AS work_time,\n" +
                "\to1.produce_qty AS produce_qty,\n" +
                "\tb.part_no AS part_no,\n" +
                "\tb.part_name_rdd AS part_name_rdd,\n" +
                "\tb.defect_code AS defect_code,\n" +
                "\tb.defect_name AS defect_name,\n" +
                "\tsum( re.qty ) AS bad_qty \n" +
                "FROM\n" +
                "\tmes_bad_cell_detail AS b\n" +
                "\tLEFT JOIN mes_repair_record r ON r.defect_record_id = b.id \n" +
                "\tAND b.organize_code = :organizeCode \n" +
                "\tAND b.is_deleted = :isDeleted \n" +
                "\tAND b.is_valid = :isValid\n" +
                "\tLEFT JOIN mes_repair_record_ext re ON r.id = re.pid \n" +
                "\tAND r.organize_code = :organizeCode \n" +
                "\tAND r.is_deleted = :isDeleted \n" +
                "\tAND r.is_valid = :isValid\n" +
                "\tINNER JOIN (\n" +
                "\tSELECT\n" +
                "\t\to.work_time AS work_time,\n" +
                "\t\tsum( o.qty ) AS produce_qty,\n" +
                "\t\to.part_no AS part_no \n" +
                "\tFROM\n" +
                "\t\tmes_out_put_statistics o \n" +
                "\tWHERE\n" +
                "\t\to.work_time >= :workTimeStart " +
                "\t\tAND o.work_time <= :workTimeEnd" +
                "\tAND o.organize_code = :organizeCode \n" +
                "\tAND o.is_deleted = :isDeleted \n" +
                "\tAND o.is_valid = :isValid " +
                "\tGROUP BY\n" +
                "\t\to.work_time,\n" +
                "\t\to.part_no \n" +
                "\tORDER BY\n" +
                "\t\to.work_time DESC \n" +
                "\t) AS o1 ON o1.work_time = b.work_time \n" +
                "\tAND o1.part_no = b.part_no \n" +
                "WHERE\n" +
                "\tb.work_time >= :workTimeStart " +
                "\tAND b.work_time <= :workTimeEnd" +
                "\tAND b.approval_status = :approvalStatus " );
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            hql.append("\tAND b.part_no = :partNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getDefectName())) {
            hql.append("\tAND b.defect_name like :defectName " );
        }
        hql.append("GROUP BY\n" +
                "\tb.defect_code,\n" +
                "\tb.work_time,\n" +
                "\tb.part_no");
        Query query = entityManager.createNativeQuery(hql.toString());
        query.setParameter(MesExtConstWords.ORGANIZE_CODE, AuthUtil.getOrganizeCode());
        query.setParameter(MesExtConstWords.IS_VALID, CommonEnumUtil.IS_VAILD.VAILD.getValue());
        query.setParameter(MesExtConstWords.IS_DELETED, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        query.setParameter(MesExtConstWords.WORK_TIME_START, paramModel.getWorkTimeStart());
        query.setParameter(MesExtConstWords.WORK_TIME_END, paramModel.getWorkTimeEnd());
        query.setParameter(MesExtConstWords.APPROVAL_STATUS, MesExtEnumUtil.BAD_CELL_DETAIL_APPROVAL_STATUS.APPROVAL.getValue());
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            query.setParameter(MesExtConstWords.PART_NO, paramModel.getPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getDefectName())) {
            query.setParameter(MesExtConstWords.DEFECT_NAME, "%"+paramModel.getDefectName()+"%");
        }
        query.setMaxResults(pager.getPageSize());
        if (pager.getCurrentPage() == 0) {
            pager.setCurrentPage(1);
        }
        query.setFirstResult(pager.getCurrentPage() * pager.getPageSize() - pager.getPageSize());
        List<Object[]> resultList = query.getResultList();
        List<ProjectContainersComputeChartResultModel> resultModelList = null;
        if(CollectionUtils.isEmpty(resultList)){
            return null;
        }else{
            resultModelList = new ArrayList<>();
            for (Object[] objects : resultList) {
                ProjectContainersComputeChartResultModel resultModel= new ProjectContainersComputeChartResultModel();
                resultModel.setWorkTime(StringUtil.isEmpty(objects[0]) ? null : String.valueOf(objects[0]));
                resultModel.setProduceQty(StringUtil.isEmpty(objects[1]) ? 0.0 : Double.parseDouble(String.valueOf(objects[1])));
                resultModel.setPartNo(StringUtil.isEmpty(objects[2]) ? null : String.valueOf(objects[2]));
                resultModel.setPartName(StringUtil.isEmpty(objects[3]) ? null : String.valueOf(objects[3]));
                resultModel.setDefectCode(StringUtil.isEmpty(objects[4]) ? null : String.valueOf(objects[4]));
                resultModel.setDefectName(StringUtil.isEmpty(objects[5]) ? null : String.valueOf(objects[5]));
                resultModel.setBadQty(StringUtil.isEmpty(objects[6]) ? 0.0 : Double.parseDouble(String.valueOf(objects[6])));
                resultModelList.add(resultModel);
            }
        }
        return resultModelList;
    }

    @Override
    public int queryPartCheckDetailByBadPartNoCount(ProjectContainersComputeChartParamModel paramModel) {
        StringBuffer hql = new StringBuffer();
        hql.append("SELECT count(1)" +
                "FROM\n" +
                "\tmes_bad_cell_detail AS b\n" +
                "\tLEFT JOIN mes_repair_record r ON r.defect_record_id = b.id \n" +
                "\tAND b.organize_code = :organizeCode \n" +
                "\tAND b.is_deleted = :isDeleted \n" +
                "\tAND b.is_valid = :isValid\n" +
                "\tLEFT JOIN mes_repair_record_ext re ON r.id = re.pid \n" +
                "\tAND r.organize_code = :organizeCode \n" +
                "\tAND r.is_deleted = :isDeleted \n" +
                "\tAND r.is_valid = :isValid\n" +
                "\tINNER JOIN (\n" +
                "\tSELECT\n" +
                "\t\to.work_time AS work_time,\n" +
                "\t\tsum( o.qty ) AS produce_qty,\n" +
                "\t\to.part_no AS part_no \n" +
                "\tFROM\n" +
                "\t\tmes_out_put_statistics o \n" +
                "\tWHERE\n" +
                "\t\to.work_time >= :workTimeStart " +
                "\t\tAND o.work_time <= :workTimeEnd" +
                "\tAND o.organize_code = :organizeCode \n" +
                "\tAND o.is_deleted = :isDeleted \n" +
                "\tAND o.is_valid = :isValid " +
                "\tGROUP BY\n" +
                "\t\to.work_time,\n" +
                "\t\to.part_no \n" +
                "\tORDER BY\n" +
                "\t\to.work_time DESC \n" +
                "\t) AS o1 ON o1.work_time = b.work_time \n" +
                "\tAND o1.part_no = b.part_no \n" +
                "WHERE\n" +
                "\tb.work_time >= :workTimeStart " +
                "\tAND b.work_time <= :workTimeEnd" +
                "\tAND b.approval_status = :approvalStatus " );
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            hql.append("\tAND b.part_no = :partNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartNo())) {
            hql.append("\tAND re.bad_part_no = :badPartNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartName())) {
            hql.append("\tAND re.bad_part_name like :badPartName " );
        }
        hql.append("GROUP BY\n" +
                "\tre.bad_part_no,\n" +
                "\tb.work_time,\n" +
                "\tb.part_no");
        Query query = entityManager.createNativeQuery(hql.toString());
        query.setParameter(MesExtConstWords.ORGANIZE_CODE, AuthUtil.getOrganizeCode());
        query.setParameter(MesExtConstWords.IS_VALID, CommonEnumUtil.IS_VAILD.VAILD.getValue());
        query.setParameter(MesExtConstWords.IS_DELETED, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        query.setParameter(MesExtConstWords.WORK_TIME_START, paramModel.getWorkTimeStart());
        query.setParameter(MesExtConstWords.WORK_TIME_END, paramModel.getWorkTimeEnd());
        query.setParameter(MesExtConstWords.APPROVAL_STATUS, MesExtEnumUtil.BAD_CELL_DETAIL_APPROVAL_STATUS.APPROVAL.getValue());
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            query.setParameter(MesExtConstWords.PART_NO, paramModel.getPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartNo())) {
            query.setParameter(MesExtConstWords.BAD_PART_NO, paramModel.getBadPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartName())) {
            query.setParameter(MesExtConstWords.BAD_PART_NAME, "%"+paramModel.getBadPartName()+"%");
        }
        List resultList = query.getResultList();
        Integer count = Integer.valueOf(resultList.size());
        return count;
    }

    @Override
    public List<ProjectContainersComputeChartResultModel> queryPartCheckDetailByBadPartNoPager(ProjectContainersComputeChartParamModel paramModel, Pager pager) {
        StringBuffer hql = new StringBuffer();
        hql.append("SELECT\n" +
                "\tb.work_time AS work_time,\n" +
                "\to1.produce_qty AS produce_qty,\n" +
                "\tb.part_no AS part_no,\n" +
                "\tb.part_name_rdd AS part_name_rdd,\n" +
                "\tre.bad_part_no as bad_part_no,\n" +
                "\tre.bad_part_name as bad_part_name,\n" +
                "\tsum( re.qty ) AS bad_qty \n" +
                "FROM\n" +
                "\tmes_bad_cell_detail AS b\n" +
                "\tLEFT JOIN mes_repair_record r ON r.defect_record_id = b.id \n" +
                "\tAND b.organize_code = :organizeCode \n" +
                "\tAND b.is_deleted = :isDeleted \n" +
                "\tAND b.is_valid = :isValid\n" +
                "\tLEFT JOIN mes_repair_record_ext re ON r.id = re.pid \n" +
                "\tAND r.organize_code = :organizeCode \n" +
                "\tAND r.is_deleted = :isDeleted \n" +
                "\tAND r.is_valid = :isValid\n" +
                "\tINNER JOIN (\n" +
                "\tSELECT\n" +
                "\t\to.work_time AS work_time,\n" +
                "\t\tsum( o.qty ) AS produce_qty,\n" +
                "\t\to.part_no AS part_no \n" +
                "\tFROM\n" +
                "\t\tmes_out_put_statistics o \n" +
                "\tWHERE\n" +
                "\t\to.work_time >= :workTimeStart " +
                "\t\tAND o.work_time <= :workTimeEnd" +
                "\tAND o.organize_code = :organizeCode \n" +
                "\tAND o.is_deleted = :isDeleted \n" +
                "\tAND o.is_valid = :isValid " +
                "\tGROUP BY\n" +
                "\t\to.work_time,\n" +
                "\t\to.part_no \n" +
                "\tORDER BY\n" +
                "\t\to.work_time DESC \n" +
                "\t) AS o1 ON o1.work_time = b.work_time \n" +
                "\tAND o1.part_no = b.part_no \n" +
                "WHERE\n" +
                "\tb.work_time >= :workTimeStart " +
                "\tAND b.work_time <= :workTimeEnd" +
                "\tAND b.approval_status = :approvalStatus " );
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            hql.append("\tAND b.part_no = :partNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartNo())) {
            hql.append("\tAND re.bad_part_no = :badPartNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartName())) {
            hql.append("\tAND re.bad_part_name like :badPartName " );
        }
        hql.append("GROUP BY\n" +
                "\tre.bad_part_no,\n" +
                "\tb.work_time,\n" +
                "\tb.part_no");
        Query query = entityManager.createNativeQuery(hql.toString());
        query.setParameter(MesExtConstWords.ORGANIZE_CODE, AuthUtil.getOrganizeCode());
        query.setParameter(MesExtConstWords.IS_VALID, CommonEnumUtil.IS_VAILD.VAILD.getValue());
        query.setParameter(MesExtConstWords.IS_DELETED, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        query.setParameter(MesExtConstWords.WORK_TIME_START, paramModel.getWorkTimeStart());
        query.setParameter(MesExtConstWords.WORK_TIME_END, paramModel.getWorkTimeEnd());
        query.setParameter(MesExtConstWords.APPROVAL_STATUS, MesExtEnumUtil.BAD_CELL_DETAIL_APPROVAL_STATUS.APPROVAL.getValue());
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            query.setParameter(MesExtConstWords.PART_NO, paramModel.getPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartNo())) {
            query.setParameter(MesExtConstWords.BAD_PART_NO, paramModel.getBadPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartName())) {
            query.setParameter(MesExtConstWords.BAD_PART_NAME, "%"+paramModel.getBadPartName()+"%");
        }
        query.setMaxResults(pager.getPageSize());
        if (pager.getCurrentPage() == 0) {
            pager.setCurrentPage(1);
        }
        query.setFirstResult(pager.getCurrentPage() * pager.getPageSize() - pager.getPageSize());
        List<Object[]> resultList = query.getResultList();
        List<ProjectContainersComputeChartResultModel> resultModelList = null;
        if(CollectionUtils.isEmpty(resultList)){
            return null;
        }else{
            resultModelList = new ArrayList<>();
            for (Object[] objects : resultList) {
                ProjectContainersComputeChartResultModel resultModel= new ProjectContainersComputeChartResultModel();
                resultModel.setWorkTime(StringUtil.isEmpty(objects[0]) ? null : String.valueOf(objects[0]));
                resultModel.setProduceQty(StringUtil.isEmpty(objects[1]) ? 0.0 : Double.parseDouble(String.valueOf(objects[1])));
                resultModel.setPartNo(StringUtil.isEmpty(objects[2]) ? null : String.valueOf(objects[2]));
                resultModel.setPartName(StringUtil.isEmpty(objects[3]) ? null : String.valueOf(objects[3]));
                resultModel.setBadPartNo(StringUtil.isEmpty(objects[4]) ? null : String.valueOf(objects[4]));
                resultModel.setBadPartName(StringUtil.isEmpty(objects[5]) ? null : String.valueOf(objects[5]));
                resultModel.setBadQty(StringUtil.isEmpty(objects[6]) ? 0.0 : Double.parseDouble(String.valueOf(objects[6])));
                resultModelList.add(resultModel);
            }
        }
        return resultModelList;
    }

    @Override
    public int queryPartCheckDetailByBadPartVenderCount(ProjectContainersComputeChartParamModel paramModel) {
        StringBuffer hql = new StringBuffer();
        hql.append("SELECT count(1)" +
                "FROM\n" +
                "\tmes_bad_cell_detail AS b\n" +
                "\tLEFT JOIN mes_repair_record r ON r.defect_record_id = b.id \n" +
                "\tAND b.organize_code = :organizeCode \n" +
                "\tAND b.is_deleted = :isDeleted \n" +
                "\tAND b.is_valid = :isValid\n" +
                "\tLEFT JOIN mes_repair_record_ext re ON r.id = re.pid \n" +
                "\tAND r.organize_code = :organizeCode \n" +
                "\tAND r.is_deleted = :isDeleted \n" +
                "\tAND r.is_valid = :isValid\n" +
                "\tINNER JOIN (\n" +
                "\tSELECT\n" +
                "\t\to.work_time AS work_time,\n" +
                "\t\tsum( o.qty ) AS produce_qty,\n" +
                "\t\to.part_no AS part_no \n" +
                "\tFROM\n" +
                "\t\tmes_out_put_statistics o \n" +
                "\tWHERE\n" +
                "\t\to.work_time >= :workTimeStart " +
                "\t\tAND o.work_time <= :workTimeEnd" +
                "\tAND o.organize_code = :organizeCode \n" +
                "\tAND o.is_deleted = :isDeleted \n" +
                "\tAND o.is_valid = :isValid " +
                "\tGROUP BY\n" +
                "\t\to.work_time,\n" +
                "\t\to.part_no \n" +
                "\tORDER BY\n" +
                "\t\to.work_time DESC \n" +
                "\t) AS o1 ON o1.work_time = b.work_time \n" +
                "\tAND o1.part_no = b.part_no \n" +
                "WHERE\n" +
                "\tb.work_time >= :workTimeStart " +
                "\tAND b.work_time <= :workTimeEnd" +
                "\tAND b.approval_status = :approvalStatus " );
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            hql.append("\tAND b.part_no = :partNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartVender())) {
            hql.append("\tAND re.bad_part_vender like :badPartVender " );
        }
        hql.append("GROUP BY\n" +
                "\tre.bad_part_vender,\n" +
                "\tb.work_time,\n" +
                "\tb.part_no");
        Query query = entityManager.createNativeQuery(hql.toString());
        query.setParameter(MesExtConstWords.ORGANIZE_CODE, AuthUtil.getOrganizeCode());
        query.setParameter(MesExtConstWords.IS_VALID, CommonEnumUtil.IS_VAILD.VAILD.getValue());
        query.setParameter(MesExtConstWords.IS_DELETED, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        query.setParameter(MesExtConstWords.WORK_TIME_START, paramModel.getWorkTimeStart());
        query.setParameter(MesExtConstWords.WORK_TIME_END, paramModel.getWorkTimeEnd());
        query.setParameter(MesExtConstWords.APPROVAL_STATUS, MesExtEnumUtil.BAD_CELL_DETAIL_APPROVAL_STATUS.APPROVAL.getValue());
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            query.setParameter(MesExtConstWords.PART_NO, paramModel.getPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartVender())) {
            query.setParameter(MesExtConstWords.BAD_PART_VENDER, "%"+paramModel.getBadPartVender()+"%");
        }
        List resultList = query.getResultList();
        Integer count = Integer.valueOf(resultList.size());
        return count;
    }

    @Override
    public List<ProjectContainersComputeChartResultModel> queryPartCheckDetailByBadPartVenderPager(ProjectContainersComputeChartParamModel paramModel, Pager pager) {
        StringBuffer hql = new StringBuffer();
        hql.append("SELECT\n" +
                "\tb.work_time AS work_time,\n" +
                "\to1.produce_qty AS produce_qty,\n" +
                "\tb.part_no AS part_no,\n" +
                "\tb.part_name_rdd AS part_name_rdd,\n" +
                "\tre.bad_part_vender AS bad_part_vender,\n" +
                "\tsum( re.qty ) AS bad_qty \n" +
                "FROM\n" +
                "\tmes_bad_cell_detail AS b\n" +
                "\tLEFT JOIN mes_repair_record r ON r.defect_record_id = b.id \n" +
                "\tAND b.organize_code = :organizeCode \n" +
                "\tAND b.is_deleted = :isDeleted \n" +
                "\tAND b.is_valid = :isValid\n" +
                "\tLEFT JOIN mes_repair_record_ext re ON r.id = re.pid \n" +
                "\tAND r.organize_code = :organizeCode \n" +
                "\tAND r.is_deleted = :isDeleted \n" +
                "\tAND r.is_valid = :isValid\n" +
                "\tINNER JOIN (\n" +
                "\tSELECT\n" +
                "\t\to.work_time AS work_time,\n" +
                "\t\tsum( o.qty ) AS produce_qty,\n" +
                "\t\to.part_no AS part_no \n" +
                "\tFROM\n" +
                "\t\tmes_out_put_statistics o \n" +
                "\tWHERE\n" +
                "\t\to.work_time >= :workTimeStart " +
                "\t\tAND o.work_time <= :workTimeEnd" +
                "\tAND o.organize_code = :organizeCode \n" +
                "\tAND o.is_deleted = :isDeleted \n" +
                "\tAND o.is_valid = :isValid " +
                "\tGROUP BY\n" +
                "\t\to.work_time,\n" +
                "\t\to.part_no \n" +
                "\tORDER BY\n" +
                "\t\to.work_time DESC \n" +
                "\t) AS o1 ON o1.work_time = b.work_time \n" +
                "\tAND o1.part_no = b.part_no \n" +
                "WHERE\n" +
                "\tb.work_time >= :workTimeStart " +
                "\tAND b.work_time <= :workTimeEnd" +
                "\tAND b.approval_status = :approvalStatus " );
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            hql.append("\tAND b.part_no = :partNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartVender())) {
            hql.append("\tAND re.bad_part_vender like :badPartVender " );
        }
        hql.append("GROUP BY\n" +
                "\tre.bad_part_vender,\n" +
                "\tb.work_time,\n" +
                "\tb.part_no");
        Query query = entityManager.createNativeQuery(hql.toString());
        query.setParameter(MesExtConstWords.ORGANIZE_CODE, AuthUtil.getOrganizeCode());
        query.setParameter(MesExtConstWords.IS_VALID, CommonEnumUtil.IS_VAILD.VAILD.getValue());
        query.setParameter(MesExtConstWords.IS_DELETED, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        query.setParameter(MesExtConstWords.WORK_TIME_START, paramModel.getWorkTimeStart());
        query.setParameter(MesExtConstWords.WORK_TIME_END, paramModel.getWorkTimeEnd());
        query.setParameter(MesExtConstWords.APPROVAL_STATUS, MesExtEnumUtil.BAD_CELL_DETAIL_APPROVAL_STATUS.APPROVAL.getValue());
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            query.setParameter(MesExtConstWords.PART_NO, paramModel.getPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getBadPartVender())) {
            query.setParameter(MesExtConstWords.BAD_PART_VENDER, "%"+paramModel.getBadPartVender()+"%");
        }
        query.setMaxResults(pager.getPageSize());
        if (pager.getCurrentPage() == 0) {
            pager.setCurrentPage(1);
        }
        query.setFirstResult(pager.getCurrentPage() * pager.getPageSize() - pager.getPageSize());
        List<Object[]> resultList = query.getResultList();
        List<ProjectContainersComputeChartResultModel> resultModelList = null;
        if(CollectionUtils.isEmpty(resultList)){
            return null;
        }else{
            resultModelList = new ArrayList<>();
            for (Object[] objects : resultList) {
                ProjectContainersComputeChartResultModel resultModel= new ProjectContainersComputeChartResultModel();
                resultModel.setWorkTime(StringUtil.isEmpty(objects[0]) ? null : String.valueOf(objects[0]));
                resultModel.setProduceQty(StringUtil.isEmpty(objects[1]) ? 0.0 : Double.parseDouble(String.valueOf(objects[1])));
                resultModel.setPartNo(StringUtil.isEmpty(objects[2]) ? null : String.valueOf(objects[2]));
                resultModel.setPartName(StringUtil.isEmpty(objects[3]) ? null : String.valueOf(objects[3]));
                resultModel.setBadPartVender(StringUtil.isEmpty(objects[4]) ? null : String.valueOf(objects[4]));
                resultModel.setBadQty(StringUtil.isEmpty(objects[5]) ? 0.0 : Double.parseDouble(String.valueOf(objects[5])));
                resultModelList.add(resultModel);
            }
        }
        return resultModelList;
    }

    @Override
    public int queryPartCheckDetailByBadRepairJudgeCount(ProjectContainersComputeChartParamModel paramModel) {
        StringBuffer hql = new StringBuffer();
        hql.append("SELECT count(1)" +
                "FROM\n" +
                "\tmes_bad_cell_detail AS b\n" +
                "\tLEFT JOIN mes_repair_record r ON r.defect_record_id = b.id \n" +
                "\tAND b.organize_code = :organizeCode \n" +
                "\tAND b.is_deleted = :isDeleted \n" +
                "\tAND b.is_valid = :isValid\n" +
                "\tLEFT JOIN mes_repair_record_ext re ON r.id = re.pid \n" +
                "\tAND r.organize_code = :organizeCode \n" +
                "\tAND r.is_deleted = :isDeleted \n" +
                "\tAND r.is_valid = :isValid\n" +
                "\tINNER JOIN (\n" +
                "\tSELECT\n" +
                "\t\to.work_time AS work_time,\n" +
                "\t\tsum( o.qty ) AS produce_qty,\n" +
                "\t\to.part_no AS part_no \n" +
                "\tFROM\n" +
                "\t\tmes_out_put_statistics o \n" +
                "\tWHERE\n" +
                "\t\to.work_time >= :workTimeStart " +
                "\t\tAND o.work_time <= :workTimeEnd" +
                "\tAND o.organize_code = :organizeCode \n" +
                "\tAND o.is_deleted = :isDeleted \n" +
                "\tAND o.is_valid = :isValid " +
                "\tGROUP BY\n" +
                "\t\to.work_time,\n" +
                "\t\to.part_no \n" +
                "\tORDER BY\n" +
                "\t\to.work_time DESC \n" +
                "\t) AS o1 ON o1.work_time = b.work_time \n" +
                "\tAND o1.part_no = b.part_no \n" +
                "WHERE\n" +
                "\tb.work_time >= :workTimeStart " +
                "\tAND b.work_time <= :workTimeEnd" +
                "\tAND b.approval_status = :approvalStatus " );
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            hql.append("\tAND b.part_no = :partNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getRepairJudge())) {
            hql.append("\tAND re.repair_judge = :repairJudge " );
        }
        hql.append("GROUP BY\n" +
                "\tre.repair_judge,\n" +
                "\tb.work_time,\n" +
                "\tb.part_no");
        Query query = entityManager.createNativeQuery(hql.toString());
        query.setParameter(MesExtConstWords.ORGANIZE_CODE, AuthUtil.getOrganizeCode());
        query.setParameter(MesExtConstWords.IS_VALID, CommonEnumUtil.IS_VAILD.VAILD.getValue());
        query.setParameter(MesExtConstWords.IS_DELETED, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        query.setParameter(MesExtConstWords.WORK_TIME_START, paramModel.getWorkTimeStart());
        query.setParameter(MesExtConstWords.WORK_TIME_END, paramModel.getWorkTimeEnd());
        query.setParameter(MesExtConstWords.APPROVAL_STATUS, MesExtEnumUtil.BAD_CELL_DETAIL_APPROVAL_STATUS.APPROVAL.getValue());
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            query.setParameter(MesExtConstWords.PART_NO, paramModel.getPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getRepairJudge())) {
            query.setParameter(MesExtConstWords.REPAIR_JUDGE, paramModel.getRepairJudge());
        }
        List resultList = query.getResultList();
        Integer count = Integer.valueOf(resultList.size());
        return count;
    }

    @Override
    public List<ProjectContainersComputeChartResultModel> queryPartCheckDetailByRepairJudgePager(ProjectContainersComputeChartParamModel paramModel, Pager pager) {
        StringBuffer hql = new StringBuffer();
        hql.append("SELECT\n" +
                "\tb.work_time AS work_time,\n" +
                "\to1.produce_qty AS produce_qty,\n" +
                "\tb.part_no AS part_no,\n" +
                "\tb.part_name_rdd AS part_name_rdd,\n" +
                "\tre.repair_judge as repair_judge,\n" +
                "\tsum( re.qty ) AS bad_qty \n" +
                "FROM\n" +
                "\tmes_bad_cell_detail AS b\n" +
                "\tLEFT JOIN mes_repair_record r ON r.defect_record_id = b.id \n" +
                "\tAND b.organize_code = :organizeCode \n" +
                "\tAND b.is_deleted = :isDeleted \n" +
                "\tAND b.is_valid = :isValid\n" +
                "\tLEFT JOIN mes_repair_record_ext re ON r.id = re.pid \n" +
                "\tAND r.organize_code = :organizeCode \n" +
                "\tAND r.is_deleted = :isDeleted \n" +
                "\tAND r.is_valid = :isValid\n" +
                "\tINNER JOIN (\n" +
                "\tSELECT\n" +
                "\t\to.work_time AS work_time,\n" +
                "\t\tsum( o.qty ) AS produce_qty,\n" +
                "\t\to.part_no AS part_no \n" +
                "\tFROM\n" +
                "\t\tmes_out_put_statistics o \n" +
                "\tWHERE\n" +
                "\t\to.work_time >= :workTimeStart " +
                "\t\tAND o.work_time <= :workTimeEnd" +
                "\tAND o.organize_code = :organizeCode \n" +
                "\tAND o.is_deleted = :isDeleted \n" +
                "\tAND o.is_valid = :isValid " +
                "\tGROUP BY\n" +
                "\t\to.work_time,\n" +
                "\t\to.part_no \n" +
                "\tORDER BY\n" +
                "\t\to.work_time DESC \n" +
                "\t) AS o1 ON o1.work_time = b.work_time \n" +
                "\tAND o1.part_no = b.part_no \n" +
                "WHERE\n" +
                "\tb.work_time >= :workTimeStart " +
                "\tAND b.work_time <= :workTimeEnd" +
                "\tAND b.approval_status = :approvalStatus " );
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            hql.append("\tAND b.part_no = :partNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getRepairJudge())) {
            hql.append("\tAND re.repair_judge = :repairJudge " );
        }
        hql.append("GROUP BY\n" +
                "\tre.repair_judge,\n" +
                "\tb.work_time,\n" +
                "\tb.part_no");
        Query query = entityManager.createNativeQuery(hql.toString());
        query.setParameter(MesExtConstWords.ORGANIZE_CODE, AuthUtil.getOrganizeCode());
        query.setParameter(MesExtConstWords.IS_VALID, CommonEnumUtil.IS_VAILD.VAILD.getValue());
        query.setParameter(MesExtConstWords.IS_DELETED, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        query.setParameter(MesExtConstWords.WORK_TIME_START, paramModel.getWorkTimeStart());
        query.setParameter(MesExtConstWords.WORK_TIME_END, paramModel.getWorkTimeEnd());
        query.setParameter(MesExtConstWords.APPROVAL_STATUS, MesExtEnumUtil.BAD_CELL_DETAIL_APPROVAL_STATUS.APPROVAL.getValue());
        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            query.setParameter(MesExtConstWords.PART_NO, paramModel.getPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getRepairJudge())) {
            query.setParameter(MesExtConstWords.REPAIR_JUDGE, paramModel.getRepairJudge());
        }
        query.setMaxResults(pager.getPageSize());
        if (pager.getCurrentPage() == 0) {
            pager.setCurrentPage(1);
        }
        query.setFirstResult(pager.getCurrentPage() * pager.getPageSize() - pager.getPageSize());
        List<Object[]> resultList = query.getResultList();
        List<ProjectContainersComputeChartResultModel> resultModelList = null;
        if(CollectionUtils.isEmpty(resultList)){
            return null;
        }else{
            resultModelList = new ArrayList<>();
            for (Object[] objects : resultList) {
                ProjectContainersComputeChartResultModel resultModel= new ProjectContainersComputeChartResultModel();
                resultModel.setWorkTime(StringUtil.isEmpty(objects[0]) ? null : String.valueOf(objects[0]));
                resultModel.setProduceQty(StringUtil.isEmpty(objects[1]) ? 0.0 : Double.parseDouble(String.valueOf(objects[1])));
                resultModel.setPartNo(StringUtil.isEmpty(objects[2]) ? null : String.valueOf(objects[2]));
                resultModel.setPartName(StringUtil.isEmpty(objects[3]) ? null : String.valueOf(objects[3]));
                resultModel.setRepairJudge(StringUtil.isEmpty(objects[4]) ? null : Integer.parseInt(String.valueOf(objects[4])));
                if(!StringUtils.isEmpty(resultModel.getRepairJudge())){
                    resultModel.setRepairJudgeName(MesExtEnumUtil.MES_REPAIR_JUDGE.valueOfDescription(resultModel.getRepairJudge()));
                }
                resultModel.setBadQty(StringUtil.isEmpty(objects[5]) ? 0.0 : Double.parseDouble(String.valueOf(objects[5])));
                resultModelList.add(resultModel);
            }
        }
        return resultModelList;
    }

    @Override
    public int queryProjectBadRateCount(ProjectContainersComputeChartParamModel paramModel) {
        StringBuffer hql = new StringBuffer();

        hql.append(" SELECT " +
                " b.work_time AS workTime, " +
                " o1.produce_qty AS produceQty, " +
                " b.part_no AS partNo, " +
                " b.part_name_rdd AS partNameRdd, " +
                " re.repair_judge_code AS repairJudge, " +
                " count( re.repair_judge_code ) AS rJuCounts, " +
                " count( re.repair_judge_code ) / o1.produce_qty  AS reRate  " +
                " FROM " +
                " mes_bad_cell_detail AS b " +
                " LEFT JOIN mes_repair_record r ON r.defect_record_id = b.id  " +
                " AND b.organize_code = :organizeCode " +
                " AND b.is_deleted = :isDeleted  " +
                " AND b.is_valid = :isValid " +
                " LEFT JOIN mes_repair_record_ext re ON r.id = re.pid  " +
                " AND r.organize_code = :organizeCode  " +
                " AND r.is_deleted = :isDeleted  " +
                " AND r.is_valid = :isValid " +
                " INNER JOIN ( " +
                " SELECT " +
                " o.work_time AS work_time, " +
                " sum( o.qty ) AS produce_qty, " +
                " o.part_no AS part_no  " +
                " FROM   " +
                " mes_out_put_statistics o  " +
                " WHERE " +
                " o.work_time >= :workTimeStart  " +
                " AND o.work_time <= :workTimeEnd  " +
                " AND o.organize_code = :organizeCode  " +
                " AND o.is_deleted = :isDeleted  " +
                " AND o.is_valid = :isValid " +
                " GROUP BY " +
                " o.work_time, " +
                " o.part_no " +
                " ORDER BY " +
                " o.work_time DESC " +
                " ) AS o1 ON o1.work_time = b.work_time  " +
                " AND o1.part_no = b.part_no " +
                " WHERE " +
                " b.work_time >= :workTimeStart  " +
                " AND b.work_time <= :workTimeEnd  " +
                " AND b.approval_status = :approvalStatus  " );

        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            hql.append(" AND b.part_no = :partNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getRepairJudge())) {
            hql.append(" AND re.repair_judge_code = :repairJudge " );
        }

        hql.append(
                " GROUP BY " +
                " b.part_no, " +
                " b.work_time, " +
                " re.repair_judge " );

        Query query = entityManager.createNativeQuery(hql.toString());
        query.setParameter(MesExtConstWords.ORGANIZE_CODE, paramModel.getOrganizeCode());
        query.setParameter(MesExtConstWords.IS_VALID, CommonEnumUtil.IS_VAILD.VAILD.getValue());
        query.setParameter(MesExtConstWords.IS_DELETED, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        query.setParameter(MesExtConstWords.WORK_TIME_START, paramModel.getWorkTimeStart());
        query.setParameter(MesExtConstWords.WORK_TIME_END, paramModel.getWorkTimeEnd());
        query.setParameter(MesExtConstWords.APPROVAL_STATUS, MesExtEnumUtil.BAD_CELL_DETAIL_APPROVAL_STATUS.APPROVAL.getValue());

        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            query.setParameter(MesExtConstWords.PART_NO, paramModel.getPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getRepairJudge())) {
            query.setParameter(MesExtConstWords.REPAIR_JUDGE, paramModel.getRepairJudge());
        }

        List resultList = query.getResultList();
        return Integer.valueOf(resultList.size());
    }

    @Override
    public List<ProjectContainersComputeChartResultModel> queryProjectBadRatePager(ProjectContainersComputeChartParamModel paramModel, Pager pager) {
        StringBuffer hql = new StringBuffer();

        hql.append(" SELECT " +
                " b.work_time AS workTime, " +
                " o1.produce_qty AS produceQty, " +
                " b.part_no AS partNo, " +
                " b.part_name_rdd AS partName, " +
                " re.repair_judge AS repairJudge, " +
                " sum( re.qty ) AS repairJudgeCounts, " +
                " sum( re.qty ) / o1.produce_qty AS repairJudgeRate  " +
                " FROM " +
                " mes_bad_cell_detail AS b " +
                " LEFT JOIN mes_repair_record r ON r.defect_record_id = b.id  " +
                " AND b.organize_code = :organizeCode " +
                " AND b.is_deleted = :isDeleted  " +
                " AND b.is_valid = :isValid  " +
                " LEFT JOIN mes_repair_record_ext re ON r.id = re.pid  " +
                " AND r.organize_code = :organizeCode  " +
                " AND r.is_deleted = :isDeleted  " +
                " AND r.is_valid = :isValid " +
                " INNER JOIN ( " +
                " SELECT " +
                " o.work_time AS work_time, " +
                " sum( o.qty ) AS produce_qty, " +
                " o.part_no AS part_no  " +
                " FROM " +
                "  mes_out_put_statistics o  " +
                " WHERE " +
                "  o.work_time >= :workTimeStart  " +
                "  AND o.work_time <= :workTimeEnd  " +
                "  AND o.organize_code = :organizeCode  " +
                "  AND o.is_deleted = :isDeleted  " +
                "  AND o.is_valid = :isValid  " +
                " GROUP BY " +
                "  o.work_time, " +
                "  o.part_no  " +
                " ORDER BY " +
                "  o.work_time DESC  " +
                " ) AS o1 ON o1.work_time = b.work_time  " +
                " AND o1.part_no = b.part_no " +
                " WHERE " +
                " b.work_time >= :workTimeStart  " +
                " AND b.work_time <= :workTimeEnd  " +
                " AND b.approval_status = :approvalStatus  " );

        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            hql.append(" AND b.part_no = :partNo " );
        }
        if (!StringUtils.isEmpty(paramModel.getRepairJudge())) {
            hql.append(" AND re.repair_judge = :repairJudge " );
        }

        hql.append(
                " GROUP BY " +
                " b.part_no, " +
                " b.work_time, " +
                " re.repair_judge " );

        Query query = entityManager.createNativeQuery(hql.toString());
        query.setParameter(MesExtConstWords.ORGANIZE_CODE, paramModel.getOrganizeCode());
        query.setParameter(MesExtConstWords.IS_VALID, CommonEnumUtil.IS_VAILD.VAILD.getValue());
        query.setParameter(MesExtConstWords.IS_DELETED, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
        query.setParameter(MesExtConstWords.WORK_TIME_START, paramModel.getWorkTimeStart());
        query.setParameter(MesExtConstWords.WORK_TIME_END, paramModel.getWorkTimeEnd());
        query.setParameter(MesExtConstWords.APPROVAL_STATUS, MesExtEnumUtil.BAD_CELL_DETAIL_APPROVAL_STATUS.APPROVAL.getValue());

        if (!StringUtils.isEmpty(paramModel.getPartNo())) {
            query.setParameter(MesExtConstWords.PART_NO, paramModel.getPartNo());
        }
        if (!StringUtils.isEmpty(paramModel.getRepairJudge())) {
            query.setParameter(MesExtConstWords.REPAIR_JUDGE, paramModel.getRepairJudge());
        }
        query.setMaxResults(pager.getPageSize());
        if (pager.getCurrentPage() == 0) {
            pager.setCurrentPage(1);
        }
        query.setFirstResult(pager.getCurrentPage() * pager.getPageSize() - pager.getPageSize());
        List<Object[]> resultList = query.getResultList();
        List<ProjectContainersComputeChartResultModel> resultModelList = null;
        if(CollectionUtils.isEmpty(resultList)){
            return null;
        }else{
            resultModelList = new ArrayList<>();
            DecimalFormat df = new DecimalFormat("#.00");
            for (Object[] objects : resultList) {
                ProjectContainersComputeChartResultModel resultModel= new ProjectContainersComputeChartResultModel();
                resultModel.setWorkTime(StringUtil.isEmpty(objects[0]) ? null : String.valueOf(objects[0]));
                resultModel.setProduceQty(StringUtil.isEmpty(objects[1]) ? 0.0 : Double.parseDouble(String.valueOf(objects[1])));
                resultModel.setPartNo(StringUtil.isEmpty(objects[2]) ? null : String.valueOf(objects[2]));
                resultModel.setPartName(StringUtil.isEmpty(objects[3]) ? null : String.valueOf(objects[3]));
                resultModel.setRepairJudge(StringUtil.isEmpty(objects[4]) ? null : Integer.parseInt(String.valueOf(objects[4])));
                resultModel.setBadQty(StringUtil.isEmpty(objects[5]) ? 0.0 : Double.parseDouble(String.valueOf(objects[5])));
                resultModel.setBadRate(StringUtil.isEmpty(objects[6]) ? "0.00%" : df.format(MathOperation.mul(Double.valueOf(String.valueOf(objects[6])), 100.00))+ "%" );
                if(resultModel.getRepairJudge() != null){
                    resultModel.setRepairJudgeName(MesExtEnumUtil.REPAIR_JUDGE.valueOfDescription(resultModel.getRepairJudge()));
                }
                resultModelList.add(resultModel);
            }
        }

        return resultModelList;
    }
}
