//package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.equiplog;
//
//import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepService;
//import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsOutContext;
//import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesScanMonitorContext;
//import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
//import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.swslog.ISwsWriteDbLogService;
//import cn.estsh.i3plus.platform.common.convert.ConvertBean;
//import cn.estsh.i3plus.platform.common.tool.TimeTool;
//import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
//import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
//import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
//import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
//import cn.estsh.i3plus.pojo.mes.bean.MesWorkCellScanMonitorLog;
//import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
//import cn.estsh.i3plus.pojo.mes.repository.MesWorkCellScanMonitorLogRepository;
//import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
//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.List;
//import java.util.StringJoiner;
//import java.util.stream.Collectors;
//
//@Slf4j
//@Service
//public class MesWorkCellScanMonitorLogExtServiceBak implements ISwsWriteDbLogService {
//
//    @Autowired
//    private IMesProductionProcessContextStepService productionProcessContextStepService;
//
//    @Autowired
//    private MesWorkCellScanMonitorLogRepository workCellScanMonitorLogRepository;
//
//    @Override
//    public void doWriteDbLog(StationResultBean resultBean) {
//
//        MesWorkCellScanMonitorLog workCellScanMonitorLog;
//
//        //获取上下文工位扫描监控信息
//        MesScanMonitorContext scanMonitorContext = productionProcessContextStepService.getScanMonitorContext(resultBean.getOrganizeCode(), resultBean.getWorkCenterCode(), resultBean.getWorkCellCode());
//
//        if (null != scanMonitorContext) {
//
//            if (checkRepeat(resultBean, scanMonitorContext)) return;
//
//            workCellScanMonitorLog = new MesWorkCellScanMonitorLog();
//
//            BeanUtils.copyProperties(scanMonitorContext, workCellScanMonitorLog);
//
//        } else {
//
//            workCellScanMonitorLog = new MesWorkCellScanMonitorLog();
//
//            log.info("工厂{}生产线{}工位{}: MesWorkCellScanMonitorLogExtService --- 上下文当前不存在工位扫描监控信息 --- {}", resultBean.getOrganizeCode(), resultBean.getWorkCenterCode(), resultBean.getWorkCellCode(), resultBean.toWriteDbString());
//
//        }
//
//        BeanUtils.copyProperties(resultBean, workCellScanMonitorLog);
//
//        workCellScanMonitorLog.setMessageType(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_MESSAGE_TYPE.codeOfValue(resultBean.getDataType()));
//
//        workCellScanMonitorLog.setDealStatus(MesExtEnumUtil.MES_LOG_DEAL_STATUS.UNDEAL.getValue());
//
//        workCellScanMonitorLog.setOrgWorkCode(new StringJoiner(MesPcnExtConstWords.E_UNDERLINE).add(workCellScanMonitorLog.getOrganizeCode()).add(workCellScanMonitorLog.getWorkCenterCode()).toString());
//
//        ConvertBean.serviceModelInitialize(workCellScanMonitorLog, resultBean.getUserInfo());
//
//        workCellScanMonitorLogRepository.insert(workCellScanMonitorLog);
//
//    }
//
//    private Boolean checkRepeat(StationResultBean resultBean, MesScanMonitorContext scanMonitorContext) {
//
//        if (resultBean.getIsCheckRepeat().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0) return false;
//
//        DdlPackBean packBean = DdlPackBean.getDdlPackBean(resultBean.getOrganizeCode());
//        DdlPreparedPack.getStringEqualPack(resultBean.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
//        DdlPreparedPack.getStringEqualPack(resultBean.getWorkCellCode(), MesPcnExtConstWords.WORK_CELL_CODE, packBean);
//        DdlPreparedPack.getNumEqualPack(scanMonitorContext.getMouldRecordId(), MesPcnExtConstWords.MOULD_RECORD_ID, packBean);
//        DdlPreparedPack.getStringEqualPack(resultBean.getStepCode(), MesPcnExtConstWords.STEP_CODE, packBean);
//        if (resultBean.getCheckRepeatType().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0) DdlPreparedPack.getStringEqualPack(resultBean.getMessage(), MesPcnExtConstWords.MESSAGE, packBean);
//        else DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{MesPcnExtConstWords.CREATE_DATE_TIME}, packBean);
//        MesWorkCellScanMonitorLog workCellScanMonitorLogDb = workCellScanMonitorLogRepository.getByProperty(packBean);
//        if (null == workCellScanMonitorLogDb || StringUtils.isEmpty(workCellScanMonitorLogDb.getMessage())) return false;
//        if (resultBean.getCheckRepeatType().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0 && !workCellScanMonitorLogDb.getMessage().equals(resultBean.getMessage())) return false;
//        return true;
//
//    }
//
//    @Override
//    public void doRestoreDbLog(StationResultBean resultBean) {
//
//        if (StringUtils.isEmpty(resultBean.getScanInfo()) || CollectionUtils.isEmpty(resultBean.getResultList())) return;
//
//        List<MesProductionPsOutContext> productionPsOutContextList = resultBean.getResultList();
//
//        String workOrderNo = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getWorkOrderNo()))).map(MesProductionPsOutContext::getWorkOrderNo).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
//        String serialNumber = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getSerialNumber()))).map(MesProductionPsOutContext::getSerialNumber).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
//        String productSn = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getProductSn()))).map(MesProductionPsOutContext::getProductSn).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
//        String custSn = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getCustSn()))).map(MesProductionPsOutContext::getCustSn).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
//        String partNo = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPartNo()))).map(MesProductionPsOutContext::getPartNo).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
//        String partName = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPartName()))).map(MesProductionPsOutContext::getPartName).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
//
//        DdlPackBean packBean = DdlPackBean.getDdlPackBean(resultBean.getOrganizeCode());
//        DdlPreparedPack.getStringEqualPack(resultBean.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
////        DdlPreparedPack.getStringEqualPack(resultBean.getWorkCellCode(), MesPcnExtConstWords.WORK_CELL_CODE, packBean);
//        DdlPreparedPack.getNumEqualPack(Long.valueOf(resultBean.getScanInfo()), MesPcnExtConstWords.MOULD_RECORD_ID, packBean);
//
//        workCellScanMonitorLogRepository.updateByProperties(
//                new String[]{MesPcnExtConstWords.WORK_ORDER_NO, MesPcnExtConstWords.SERIAL_NUMBER, MesPcnExtConstWords.PRODUCT_SN, MesPcnExtConstWords.CUST_SN,
//                        MesPcnExtConstWords.PART_NO, MesPcnExtConstWords.PART_NAME, MesPcnExtConstWords.MODIFY_DATE_TIME, MesPcnExtConstWords.MODIFY_USER, MesPcnExtConstWords.DEAL_STATUS},
//                new Object[]{workOrderNo, serialNumber, productSn, custSn,
//                        partNo, partName, TimeTool.getNowTime(true), resultBean.getUserInfo(), MesExtEnumUtil.MES_LOG_DEAL_STATUS.DEAL_SUCCESS.getValue()},
//                packBean);
//
//    }
//
//
//}
