package cn.stylefeng.guns.plcserver.server.OP010.impl; import cn.stylefeng.guns.GunsApplication; import cn.stylefeng.guns.modular.bs.locationInfo.model.params.LocationInfoParam; import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult; import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService; import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam; import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService; import cn.stylefeng.guns.modular.om.productionOrdeInfo.entity.ProductionOrdeInfo; import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam; import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult; import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService; import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam; import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult; import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService; import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam; import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult; import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService; import cn.stylefeng.guns.plcserver.opc.GlobalVariable; import cn.stylefeng.guns.plcserver.opc.OPCComm; import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit; import cn.stylefeng.guns.plcserver.opc.unit.SFCCodeTool; import cn.stylefeng.guns.plcserver.server.OP010.OP010ServerInterface; import cn.stylefeng.guns.plcserver.tool.DateTool; import cn.stylefeng.guns.plcserver.tool.LogUtil; import cn.stylefeng.roses.core.util.ToolUtil; import lombok.Synchronized; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.springframework.boot.SpringApplication; import java.util.Calendar; import java.util.Date; import java.util.List; public class OP010ServerInterfaceImpl implements OP010ServerInterface { private static Logger logger; LogUtil logUtil = new LogUtil(); static { logger = Logger.getLogger(OP010ServerInterfaceImpl.class); } private OPCComm opc = OPCComm.getInstance(); private static String S_ORDER_CODE = "";//工单编号 private static String S_PRODUCT_CODE = "";//产品编号 private static String S_PRODUCT_TYPE= "";//产品类型 private static String S_SFC_CODE = "test222";//总成编码 private static String S_RIGHT_CODE = "test333";//右壳体编码 private static String PRODUCTION_LINE = "OP";//产线号 private static String LOCATION_CODE = "OP010";//工位号 private static Date IN_TIME = null;//进站时间 private static Integer ACTUAL_ONLINE_QTY = 0 ;//上线数量 @Override public synchronized void monitor() { String ecpStr = "";//异常记录标记 try{ if(GlobalVariable.OP010_F_HEART_BEAT) { //PC读工单 String isPLCStart = OPCUnit.read(opc.getOP010_J_PLC_START());//PLC开始 if(isPLCStart.equals("true")){ String isFinish = OPCUnit.read(opc.getOP010_J_PC_WRITE_ORDER());//PC下发工单完成 if(isFinish.equals("false")){ String isRepair = OPCUnit.read(opc.getOP010_P_REPAIR());//是否返修 if(isRepair.equals("true")){ handleRepair(); }else{ handleOrder(); } } } //PC完成 String isPLCFinish = OPCUnit.read(opc.getOP010_J_PLC_FINISH());//PLC完成 if(isPLCFinish.equals("true")){ String isFinish = OPCUnit.read(opc.getOP010_J_PC_FINISH());//PC操作完成 if(isFinish.equals("false")){ handleFinsh(); } } }else{ logger.info("OP010工位与PLC断开,请检查PLC或网络是否异常!"); } }catch (Exception e) { ecpStr ="出现异常:" + logUtil.getTrace(e); }finally { if(!"".equals(ecpStr)){ logger.info(ecpStr+"\r\n"); } } } public void handleRepair() { RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam(); repairManageInfoParam.setLocationCode(LOCATION_CODE); repairManageInfoParam.setManageType("2"); repairManageInfoParam.setUpPlc("0"); RepairManageInfoService repairManageInfoService = opc.repairManageInfoService; List list = repairManageInfoService.findListBySpec(repairManageInfoParam); if(list.size()>0) { RepairManageInfoResult result = list.get(0); S_SFC_CODE = result.getSfc(); S_ORDER_CODE = result.getWorkOrderNo(); S_PRODUCT_CODE = result.getProductCode(); S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE); String repairLocation = result.getPoorLocationCode();// //根据工位编码查询工位表中配置的返修工位号 LocationInfoParam param = new LocationInfoParam(); param.setLocationCode(repairLocation); LocationInfoService locationInfoService = opc.locationInfoService; List results = locationInfoService.findListBySpec(param); if(results.size()>0) { LocationInfoResult r = results.get(0); String repairLocationNo = r.getSpareField2(); if(null != repairLocationNo && "" != repairLocationNo){ OPCUnit.write(opc.getOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号 OPCUnit.write(opc.getOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号 OPCUnit.write(opc.getOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码 OPCUnit.write(opc.getOP010_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号 OPCUnit.write(opc.getOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成 //更新为已经返修上线 Long id = result.getId(); repairManageInfoParam.setId(id); repairManageInfoParam.setUpPlc("1"); repairManageInfoService.update(repairManageInfoParam); }else{ logger.info("OP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!"); } }else{ logger.info("OP010工位,handleRepair 无法查询到"+repairLocation+"工位!"); } } } //PC下发工单 public void handleOrder() { logger.info("OP010工位,handleOrder PC处理开始!"); IN_TIME = DateTool.getLocalTimeForDate(); ProductionOrdeInfoParam param = new ProductionOrdeInfoParam(); param.setProductionLine("");//产线 param.setOrderStatus("3");//工单状态 ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService; List list = productionOrdeInfoService.findListBySpec(param); if(list.size()>0) { ProductionOrdeInfoResult result = list.get(0); String customerCode = result.getCustom();//客户编码 String productCode = result.getMaterialCode();//产品编码 String softwareVersionCode = result.getSoftwareVersionCode();//产品型号 String productCompanyCode = result.getProductCompanyCode();//班次 //序列号 String serialNumbers = "0000"; SerialNumbersConfParam serialNumbersConfParam = new SerialNumbersConfParam(); Calendar calendar = Calendar.getInstance(); String Years = String.valueOf(calendar.get(Calendar.YEAR)); //年份 String Months = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH) + 1),2, "0"); //月份 String Dates = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)),2, "0"); //日期 serialNumbersConfParam.setYears(Years+Months+Dates);//获取当前是哪一天 serialNumbersConfParam.setState("1"); SerialNumbersConfService serialNumbersConfService = opc.serialNumbersConfService; List serialNumberslist = serialNumbersConfService.findListBySpec(serialNumbersConfParam); if(serialNumberslist.size()>0){ SerialNumbersConfResult serialNumbersConfResult = serialNumberslist.get(0); serialNumbers = serialNumbersConfResult.getSerialNumber(); serialNumbersConfParam.setId(serialNumbersConfResult.getId()); }else{ serialNumbersConfParam.setSerialNumber(serialNumbers); serialNumbersConfParam.setLengths("4"); serialNumbersConfService.add(serialNumbersConfParam); List serialNumberslist2 = serialNumbersConfService.findListBySpec(serialNumbersConfParam); if(serialNumberslist2.size()>0){ SerialNumbersConfResult serialNumbersConfResult = serialNumberslist2.get(0); //serialNumbers = serialNumbersConfResult.getSerialNumber(); serialNumbersConfParam.setId(serialNumbersConfResult.getId()); } //logger.info("序列号没有配置,请找管理员进行配置!"); } //更新序列号+1 int i = Integer.valueOf(serialNumbers)+1; serialNumbers = StringUtils.leftPad(String.valueOf(i),4, "0"); serialNumbersConfParam.setSerialNumber(serialNumbers); serialNumbersConfService.update(serialNumbersConfParam); //生成总成编码 String sfcCode = SFCCodeTool.createCodingRulesSFC(softwareVersionCode,productCompanyCode,serialNumbers);//总成号 S_SFC_CODE = sfcCode; S_ORDER_CODE = result.getWorkOrderNo(); S_PRODUCT_CODE = result.getMaterialCode(); S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE); ACTUAL_ONLINE_QTY = result.getActualOnlineQty(); OPCUnit.write(opc.getOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号 OPCUnit.write(opc.getOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号 OPCUnit.write(opc.getOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码 //OPCUnit.write(opc.getOP010_S_RIGHT_CODE(), S_RIGHT_CODE); //右壳体编码 OPCUnit.write(opc.getOP010_S_NUMBER(), result.getPlanQty().toString()); //计划数量 OPCUnit.write(opc.getOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成 logger.info("OP010工位,handleOrder PC处理完成!^--------------------------------------------"); }else{ logger.info("OP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!"); } } //PC完成 public void handleFinsh() { logger.info("OP010工位,handleFinsh PC处理开始!"); if("".equals(S_ORDER_CODE)){ IN_TIME = DateTool.getLocalTimeForDate(); S_ORDER_CODE = OPCUnit.read(opc.getOP010_S_ORDER_CODE());//工单编号 S_PRODUCT_TYPE = OPCUnit.read(opc.getOP010_S_PRODUCT_CODE());//产品编号 S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); S_SFC_CODE = OPCUnit.read(opc.getOP010_S_SFC_CODE());//总成编码 } //处理过站信息 String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP010_S_PRODUCT_STATE_CODE()); PassingStationCollectionParam param = new PassingStationCollectionParam(); param.setWorkOrderNo(S_ORDER_CODE); param.setProductCode(S_PRODUCT_CODE); param.setSfcCode(S_SFC_CODE); param.setProductionLine(PRODUCTION_LINE); param.setLocationCode(LOCATION_CODE); param.setInboundTime(IN_TIME); param.setOutboundTime(DateTool.getLocalTimeForDate()); param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格 PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService; passingStationCollectionService.add(param); //上线数量加1 根据工单号,更新 ACTUAL_ONLINE_QTY +1 /* ProductionOrdeInfoParam orderParam = new ProductionOrdeInfoParam(); orderParam.setWorkOrderNo(S_ORDER_CODE); orderParam.setActualOnlineQty(ACTUAL_ONLINE_QTY+1); ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService; productionOrdeInfoService.updateOrderOnlineQry(orderParam);*/ //写完成 OPCUnit.write(opc.getOP010_J_PC_FINISH(), "true"); //PC完成 logger.info("OP010工位,handleFinsh PC处理完成!-------------------------------"); } }