package cn.estsh.i3plus.ext.mes.pcn.pojo.sqlpack;

import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.*;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxWorkCellModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.WorkOrderQueryDto;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.ep.EpQmsBadCellDetailModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.MesProcess;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Description:
 * @Reference: Mes 条件封装
 * @Author: wangjie
 * @CreateDate:2019-04-22-14:58
 * @Modify:
 **/
public class MesPcnExtHqlPack {

    public static DdlPackBean getAllBaseDataByNormalPro(BaseBean baseBean, String organizeCode) {
        DdlPackBean packBean = new DdlPackBean();
        DdlPreparedPack.getStringEqualPack(organizeCode, MesPcnExtConstWords.ORGANIZE_CODE, packBean);
        DdlPreparedPack.getNumEqualPack(baseBean.getIsValid(), MesPcnExtConstWords.IS_VALID, packBean);
        DdlPreparedPack.getNumEqualPack(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), MesPcnExtConstWords.IS_DELETED, packBean);
        return packBean;
    }

    public static DdlPackBean getAllValidData(String organizeCode) {
        DdlPackBean packBean = new DdlPackBean();
        DdlPreparedPack.getStringEqualPack(organizeCode, MesPcnExtConstWords.ORGANIZE_CODE, packBean);
        DdlPreparedPack.getNumEqualPack(CommonEnumUtil.IS_VAILD.VAILD.getValue(), MesPcnExtConstWords.IS_VALID, packBean);
        DdlPreparedPack.getNumEqualPack(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), MesPcnExtConstWords.IS_DELETED, packBean);
        return packBean;
    }

    public static DdlPackBean getShiftProd(MesShiftProd shiftProd) {
        DdlPackBean packBean = getAllValidData(shiftProd.getOrganizeCode());
        DdlPreparedPack.getStringLikerPack(shiftProd.getProdCode(), MesPcnExtConstWords.PROD_CODE, packBean);
        DdlPreparedPack.getStringLikerPack(shiftProd.getProdName(), MesPcnExtConstWords.PROD_NAME, packBean);
        DdlPreparedPack.getNumEqualPack(shiftProd.getProdCategory(), MesPcnExtConstWords.PROD_CATEGORY, packBean);
        DdlPreparedPack.getNumEqualPack(shiftProd.getProdType(), MesPcnExtConstWords.PROD_TYPE, packBean);
        DdlPreparedPack.getNumEqualPack(shiftProd.getIsProdTime(), MesPcnExtConstWords.IS_PROD_TIME, packBean);
        return packBean;
    }

    public static DdlPackBean getProduceSnExt(MesProduceSnExt produceSnExt) {
        DdlPackBean packBean = getAllValidData(produceSnExt.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(produceSnExt.getWorkOrderNo(), MesPcnExtConstWords.WORK_ORDER_NO, packBean);
        DdlPreparedPack.getStringLikerPack(produceSnExt.getSerialNumber(), MesPcnExtConstWords.SERIAL_NUMBER, packBean);
        DdlPreparedPack.getNumEqualPack(produceSnExt.getQcStatus(), MesPcnExtConstWords.QC_STATUS, packBean);
        DdlPreparedPack.getNumEqualPack(produceSnExt.getSnStatus(), MesPcnExtConstWords.SN_STATUS, packBean);
        DdlPreparedPack.getNumEqualPack(produceSnExt.getPrintStatus(), MesPcnExtConstWords.PRINT_STATUS, packBean);
        DdlPreparedPack.getNumEqualPack(produceSnExt.getSnType(), MesPcnExtConstWords.SN_TYPE, packBean);
        return packBean;
    }

    public static DdlPackBean getProduceSnExtOnlyCreateAndProcess(MesProduceSnExt produceSnExt , List<Integer> statusList) {
        DdlPackBean packBean = getAllValidData(produceSnExt.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(produceSnExt.getWorkOrderNo(), MesPcnExtConstWords.WORK_ORDER_NO, packBean);
        DdlPreparedPack.getStringLikerPack(produceSnExt.getSerialNumber(), MesPcnExtConstWords.SERIAL_NUMBER, packBean);
        DdlPreparedPack.getInPackList(statusList, MesPcnExtConstWords.SN_STATUS, packBean);
        DdlPreparedPack.getNumEqualPack(produceSnExt.getPrintStatus(), MesPcnExtConstWords.PRINT_STATUS, packBean);
        DdlPreparedPack.getNumEqualPack(produceSnExt.getSnType(), MesPcnExtConstWords.SN_TYPE, packBean);
        return packBean;
    }

    public static DdlPackBean getWindowWorkOrderExt(WorkOrderQueryDto workOrderQueryDto) {
        DdlPackBean packBean = getAllValidData(workOrderQueryDto.getOrganizeCode());
        DdlPreparedPack.getStringLikerPack(workOrderQueryDto.getOrderNo(), MesPcnExtConstWords.ORDER_NO, packBean);
        DdlPreparedPack.getStringLikerPack(workOrderQueryDto.getPartNo(), MesPcnExtConstWords.PART_NO, packBean);
        DdlPreparedPack.getStringEqualPack(workOrderQueryDto.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
        DdlPreparedPack.getStringEqualPack(workOrderQueryDto.getAreaCode(), MesPcnExtConstWords.AREA_CODE, packBean);
        DdlPreparedPack.getNumEqualPack(workOrderQueryDto.getWorkOrderStatus(), MesPcnExtConstWords.WORK_ORDER_STATUS, packBean);
        DdlPreparedPack.getNumEqualPack(workOrderQueryDto.getWorkOrderType(), MesPcnExtConstWords.WORK_ORDER_TYPE, packBean);
        DdlPreparedPack.getNumEqualPack(workOrderQueryDto.getSnCreateStatus(), MesPcnExtConstWords.SN_CREATE_STATUS, packBean);
        if (!StringUtils.isEmpty(workOrderQueryDto.getStartTimeStart()) || !StringUtils.isEmpty(workOrderQueryDto.getStartTimeEnd())) {
            DdlPreparedPack.timeBuilder(workOrderQueryDto.getStartTimeStart(), workOrderQueryDto.getStartTimeEnd(), MesPcnExtConstWords.START_TIME, packBean, true);
        }
        if (!StringUtils.isEmpty(workOrderQueryDto.getModifyStartTime()) || !StringUtils.isEmpty(workOrderQueryDto.getModifyEndTime())) {
            DdlPreparedPack.timeBuilder(workOrderQueryDto.getModifyStartTime(), workOrderQueryDto.getModifyEndTime(), MesPcnExtConstWords.MODIFY_DATE_TIME, packBean, true);
        }
        return packBean;
    }

    public static DdlPackBean getPackageExt(MesPackageExt pack) {
        DdlPackBean packBean = getAllValidData(pack.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(pack.getWorkOrderNo(), MesPcnExtConstWords.WORK_ORDER_NO, packBean);
        DdlPreparedPack.getStringLikerPack(pack.getPackageNo(), MesPcnExtConstWords.PACKAGENO, packBean);
        DdlPreparedPack.getStringEqualPack(pack.getPartNo(), MesPcnExtConstWords.PART_NO, packBean);
        DdlPreparedPack.getStringEqualPack(pack.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
        DdlPreparedPack.timeBuilder(pack.getCreateDateTimeStart(), pack.getCreateDateTimeEnd(), MesPcnExtConstWords.CREATE_DATE_TIME, packBean, true);
        return packBean;
    }

    public static DdlPackBean getWorkOrderProcessBom(MesWorkOrderProcessBom workOrderProcessBom) {
        DdlPackBean packBean = getAllBaseDataByNormalPro(workOrderProcessBom, workOrderProcessBom.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(workOrderProcessBom.getWorkOrderNo(), MesPcnExtConstWords.WORK_ORDER_NO, packBean);
        DdlPreparedPack.getStringEqualPack(workOrderProcessBom.getProcessCode(), MesPcnExtConstWords.PROCESS_CODE, packBean);
        DdlPreparedPack.getStringLikerPack(workOrderProcessBom.getItemPartNo(), MesPcnExtConstWords.ITEM_PART_NO, packBean);
        return packBean;
    }

    public static DdlPackBean getProcessBom(MesProcessBom processBom) {
        DdlPackBean packBean = getAllValidData(processBom.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(processBom.getProcessCode(), MesPcnExtConstWords.PROCESS_CODE, packBean);
        DdlPreparedPack.getStringLikerPack(processBom.getPartNo(), MesPcnExtConstWords.PART_NO, packBean);
        return packBean;
    }

    public static DdlPackBean getMesProcess(MesProcess process, String organizeCode) {
        DdlPackBean packBean = getAllBaseDataByNormalPro(process, organizeCode);
        DdlPreparedPack.getStringLikerPack(process.getProcessCode(), MesPcnExtConstWords.PROCESS_CODE, packBean);
        DdlPreparedPack.getStringLikerPack(process.getProcessName(), MesPcnExtConstWords.PROCESS_NAME, packBean);
        return packBean;
    }

    public static DdlPackBean getOqcCheckDetail(String organizeCode, String oqcNo) {
        DdlPackBean packBean = getAllValidData(organizeCode);
        DdlPreparedPack.getStringEqualPack(oqcNo, MesPcnExtConstWords.OQC_NO, packBean);
        return packBean;
    }

    public static DdlPackBean getPrinterRecord(MesWorkCellPrintRecordDetail detail) {
        DdlPackBean packBean = getAllValidData(detail.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(detail.getWorkOrderNo(), MesPcnExtConstWords.WORK_ORDER_NO, packBean);
        DdlPreparedPack.getStringEqualPack(detail.getSn(), MesPcnExtConstWords.SN, packBean);
        DdlPreparedPack.getNumEqualPack(detail.getTagType(), MesPcnExtConstWords.TAG_TYPE, packBean);
        return packBean;
    }

    /************** EP ******************/

    public static DdlPackBean getBom(String organizeCode, String partNo, String itemPartNo, String itemPartName){
        DdlPackBean packBean = getAllValidData(organizeCode);
        DdlPreparedPack.getStringLikerPack(partNo, MesPcnExtConstWords.PART_NO, packBean);
        DdlPreparedPack.getStringLikerPack(itemPartNo, MesPcnExtConstWords.ITEM_PART_NO, packBean);
        DdlPreparedPack.getStringLikerPack(itemPartName, MesPcnExtConstWords.ITEM_PART_NAME, packBean);
        return packBean;
    }

    public static DdlPackBean getEpBadCellDetail(EpQmsBadCellDetailModel badCellDetailModel) {
        DdlPackBean packBean = getAllValidData(badCellDetailModel.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(badCellDetailModel.getPartNo(), MesPcnExtConstWords.PART_NO, packBean);
        DdlPreparedPack.getStringEqualPack(badCellDetailModel.getItemPartNo(), MesPcnExtConstWords.ITEM_PART_NO, packBean);
        DdlPreparedPack.getStringEqualPack(badCellDetailModel.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
        DdlPreparedPack.getStringEqualPack(badCellDetailModel.getWorkCellCode(), MesPcnExtConstWords.WORK_CELL_CODE, packBean);
        DdlPreparedPack.getStringEqualPack(badCellDetailModel.getDefectType(), MesPcnExtConstWords.DEFECT_TYPE, packBean);
        DdlPreparedPack.getStringEqualPack(badCellDetailModel.getDefectCode(), MesPcnExtConstWords.DEFECT_CODE, packBean);
        DdlPreparedPack.getStringEqualPack(badCellDetailModel.getHappenStation(), MesPcnExtConstWords.HAPPEN_STATION, packBean);
        DdlPreparedPack.timeBuilder(badCellDetailModel.getDefectActionTimeStart(), badCellDetailModel.getDefectActionTimeEnd(), MesPcnExtConstWords.DEFECT_ACTION_TIME, packBean, true);
        return packBean;
    }

    public static DdlPackBean getValidWorkCell(SxWorkCellModel workCellModel) {
        DdlPackBean packBean = getAllValidData(workCellModel.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(workCellModel.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
        DdlPreparedPack.getStringEqualPack(workCellModel.getWorkCellCode(), MesPcnExtConstWords.WORK_CELL_CODE, packBean);
        DdlPreparedPack.getStringEqualPack(workCellModel.getAreaCode(), MesPcnExtConstWords.AREA_CODE, packBean);
        return packBean;
    }

    public static DdlPackBean getWorkCenterMovtrnCfg(MesWorkCenterMovtrnCfg workCenterMovtrnCfg) {
        DdlPackBean packBean = getAllValidData(workCenterMovtrnCfg.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(workCenterMovtrnCfg.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
        DdlPreparedPack.getStringEqualPack(workCenterMovtrnCfg.getStatus(), MesPcnExtConstWords.STATUS, packBean);
        return packBean;
    }

    public static DdlPackBean getOutPackage(MesOuterPackageDetail outerPackageDetail) {
        DdlPackBean packBean = getAllValidData(outerPackageDetail.getOrganizeCode());
        DdlPreparedPack.getStringLikerPack(outerPackageDetail.getWorkOrderNo(), MesPcnExtConstWords.WORK_ORDER_NO, packBean);
        DdlPreparedPack.getStringLikerPack(outerPackageDetail.getOuterPackageNo(), MesPcnExtConstWords.OUTER_PACKAGE_NO, packBean);
        DdlPreparedPack.timeBuilder(outerPackageDetail.getCreateDateTimeStart(), outerPackageDetail.getCreateDateTimeEnd(), MesPcnExtConstWords.CREATE_DATE_TIME, packBean, true);
        return packBean;
    }

    public static DdlPackBean getUnbindProduceSn(MesUnbindProduceSn unbindProduceSn) {
        DdlPackBean packBean = getAllValidData(unbindProduceSn.getOrganizeCode());
        DdlPreparedPack.getStringLikerPack(unbindProduceSn.getWorkOrderNo(), MesPcnExtConstWords.WORK_ORDER_NO, packBean);
        DdlPreparedPack.getStringLikerPack(unbindProduceSn.getPartNo(), MesPcnExtConstWords.PART_NO, packBean);
        DdlPreparedPack.getStringLikerPack(unbindProduceSn.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
        DdlPreparedPack.getStringLikerPack(unbindProduceSn.getPartNameRdd(), MesPcnExtConstWords.PART_NAME_RDD, packBean);
        DdlPreparedPack.getNumEqualPack(unbindProduceSn.getBindStatus(), MesPcnExtConstWords.BIND_STATUS, packBean);
        DdlPreparedPack.timeBuilder(unbindProduceSn.getCreateDateTimeStart(), unbindProduceSn.getCreateDateTimeEnd(), MesPcnExtConstWords.START_TIME, packBean, true);
        return packBean;
    }

    public static DdlPackBean getUnbindProduceSnTravel(MesUnbindProduceSnTravel unbindProduceSnTravel) {
        DdlPackBean packBean = getAllValidData(unbindProduceSnTravel.getOrganizeCode());
        DdlPreparedPack.getStringLikerPack(unbindProduceSnTravel.getWorkOrderNo(), MesPcnExtConstWords.WORK_ORDER_NO, packBean);
        DdlPreparedPack.getStringLikerPack(unbindProduceSnTravel.getPartNo(), MesPcnExtConstWords.PART_NO, packBean);
        DdlPreparedPack.getStringLikerPack(unbindProduceSnTravel.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
        DdlPreparedPack.getStringLikerPack(unbindProduceSnTravel.getPartNameRdd(), MesPcnExtConstWords.PART_NAME_RDD, packBean);
        DdlPreparedPack.getNumEqualPack(unbindProduceSnTravel.getBindStatus(), MesPcnExtConstWords.BIND_STATUS, packBean);
        DdlPreparedPack.timeBuilder(unbindProduceSnTravel.getCreateDateTimeStart(), unbindProduceSnTravel.getCreateDateTimeEnd(), MesPcnExtConstWords.START_TIME, packBean, true);
        return packBean;
    }

    public static DdlPackBean getOqcCheckDetailByOqcNo(MesOqcCheck oqcCheckDb) {
        DdlPackBean packBean = getAllValidData(oqcCheckDb.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(oqcCheckDb.getOqcNo(), MesPcnExtConstWords.OQC_NO, packBean);
        return packBean;
    }

    public static DdlPackBean getSxBadnessClassifyDetail(MesBadnessClassifyDetail badnessClassifyDetail) {
        DdlPackBean packBean = getAllBaseDataByNormalPro(badnessClassifyDetail, badnessClassifyDetail.getOrganizeCode());
        DdlPreparedPack.getStringLikerPack(badnessClassifyDetail.getBadnessClassifyName(), MesPcnExtConstWords.BADNESS_CLASSIFY_NAME, packBean);
        DdlPreparedPack.getStringLikerPack(badnessClassifyDetail.getBadnessClassifyDetailName(), MesPcnExtConstWords.BADNESS_CLASSIFY_DETAIL_NAME, packBean);
        DdlPreparedPack.getStringLikerPack(badnessClassifyDetail.getBadnessClassifyCode(), MesPcnExtConstWords.BADNESS_CLASSIFY_CODE, packBean);
        DdlPreparedPack.getStringLikerPack(badnessClassifyDetail.getBadnessClassifyDetailCode(), MesPcnExtConstWords.BADNESS_CLASSIFY_DETAIL_CODE, packBean);
        return packBean;
    }

    public static DdlPackBean getSxBadnessClassify(MesBadnessClassify badnessClassify) {
        DdlPackBean packBean = getAllBaseDataByNormalPro(badnessClassify, badnessClassify.getOrganizeCode());
        DdlPreparedPack.getStringLikerPack(badnessClassify.getBadnessTypeName(), MesPcnExtConstWords.BADNESS_TYPE_NAME, packBean);
        DdlPreparedPack.getStringLikerPack(badnessClassify.getBadnessTypeCode(), MesPcnExtConstWords.BADNESS_TYPE_CODE, packBean);
        DdlPreparedPack.getStringLikerPack(badnessClassify.getBadnessClassifyName(), MesPcnExtConstWords.BADNESS_CLASSIFY_NAME, packBean);
        DdlPreparedPack.getStringLikerPack(badnessClassify.getBadnessClassifyCode(), MesPcnExtConstWords.BADNESS_CLASSIFY_CODE, packBean);
        return packBean;
    }
}
