From 5eed777f0aff8c4e1b172bca4f3e28a4c1638d47 Mon Sep 17 00:00:00 2001 From: LGH <1746689524@qq.com> Date: Fri, 18 Nov 2022 10:12:54 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E4=B8=8A=E6=8A=A5apms=E7=82=89?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mt/wms/empty/task/ScheduledTask.java | 418 ++++++++++-------- 1 file changed, 229 insertions(+), 189 deletions(-) diff --git a/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/ScheduledTask.java b/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/ScheduledTask.java index c31a751..5772591 100644 --- a/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/ScheduledTask.java +++ b/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/ScheduledTask.java @@ -88,20 +88,21 @@ public class ScheduledTask extends BaseService { public void test() throws IOException { } + //@Scheduled(fixedDelay = 1000*60) public void testWebsocket() throws IOException { //查询出正在进炉加工的curr_task,查询对应炉号是否Working,查询计划时间,剩余时间,查询标识卡详情 List currTaskList = currTaskServiceBiz.list(new QueryWrapper().eq(CurrTask.IS_IN, 1)); - if (currTaskList.size()==0){ + if (currTaskList.size() == 0) { return; } List nowCurrTaskDetVoList = BeanUtils.copyList(currTaskList, NowCurrTaskDetVo.class); - for (NowCurrTaskDetVo nowCurrTask:nowCurrTaskDetVoList + for (NowCurrTaskDetVo nowCurrTask : nowCurrTaskDetVoList ) { Long kilnId = nowCurrTask.getKilnId(); Boolean kilnWorking = true; //查询对应炉号是否Working - if (kilnWorking){ + if (kilnWorking) { String nameSpace = plcNameSpaceServiceBiz.getOne(new QueryWrapper() .eq(PlcNameSpace.EQ_TYPE, 0) .eq(PlcNameSpace.TYPE, 0) @@ -113,13 +114,13 @@ public class ScheduledTask extends BaseService { Integer remainingTime = 122; nowCurrTask.setSetupTime(setupTime); nowCurrTask.setRemainingTime(remainingTime); - int completeness =(int) (((float)remainingTime/(float)setupTime )*100); + int completeness = (int) (((float) remainingTime / (float) setupTime) * 100); nowCurrTask.setCompleteness(completeness); nowCurrTask.setKilnCode("BMA1"); //标识卡详情 List currTaskDetList = currTaskDetServiceBiz.list(new QueryWrapper().eq(CurrTaskDet.CURR_TASK_ID, nowCurrTask.getId())); List currTaskDetVoList = BeanUtils.copyList(currTaskDetList, CurrTaskDetVo.class); - for (CurrTaskDetVo currTaskDetVo:currTaskDetVoList + for (CurrTaskDetVo currTaskDetVo : currTaskDetVoList ) { String customerName = orderInfoServiceBiz.getOne(new QueryWrapper().eq(OrderInfo.IDEN_CARD_NUM, currTaskDetVo.getIdenCardNum())).getCustomerName(); currTaskDetVo.setCustomer(customerName); @@ -128,28 +129,28 @@ public class ScheduledTask extends BaseService { } } System.out.println(JSON.toJSONString(nowCurrTaskDetVoList)); - webSocketServer.sendtoUser(JSON.toJSONString(nowCurrTaskDetVoList),"2"); + webSocketServer.sendtoUser(JSON.toJSONString(nowCurrTaskDetVoList), "2"); } /** * 正在加工的加工任务详情 */ - @Scheduled(fixedDelay = 1000*60) + //@Scheduled(fixedDelay = 1000*60) public void screen() throws IOException { //查询出正在进炉加工的curr_task,查询对应炉号是否Working,查询计划时间,剩余时间,查询标识卡详情 List currTaskList = currTaskServiceBiz.list(new QueryWrapper() .eq(CurrTask.IS_IN, 1) - .eq(CurrTask.STATUS,1)); - if (currTaskList.size()==0){ + .eq(CurrTask.STATUS, 1)); + if (currTaskList.size() == 0) { return; } List nowCurrTaskDetVoList = BeanUtils.copyList(currTaskList, NowCurrTaskDetVo.class); - for (NowCurrTaskDetVo nowCurrTask:nowCurrTaskDetVoList - ) { + for (NowCurrTaskDetVo nowCurrTask : nowCurrTaskDetVoList + ) { Long kilnId = nowCurrTask.getKilnId(); Boolean kilnWorking = kilnWorking(kilnId); //查询对应炉号是否Working - if (kilnWorking){ + if (kilnWorking) { String nameSpace = plcNameSpaceServiceBiz.getOne(new QueryWrapper() .eq(PlcNameSpace.EQ_TYPE, 0) .eq(PlcNameSpace.TYPE, 0) @@ -158,79 +159,80 @@ public class ScheduledTask extends BaseService { nowCurrTask.setTaskCode(nowCurrTask.getSheetNo()); nowCurrTask.setKilnCode(kilnInfo.getCode()); //设定时间 - Integer setupTime =1; + Integer setupTime = 1; //剩余时间 - Integer remainingTime=0; - if (kilnInfo.getType()!=4){ - if (kilnInfo.getType()==3){ + Integer remainingTime = 0; + if (kilnInfo.getType() != 4) { + if (kilnInfo.getType() == 3) { remainingTime = readPlc(nameSpace, "ProgramTimeRemaining").intValue(); - }else { + } else { remainingTime = readPlc(nameSpace, "ProgramTimeRemain").intValue(); } } - if(kilnInfo.getType()==1||kilnInfo.getType()==3){ + if (kilnInfo.getType() == 1 || kilnInfo.getType() == 3) { //运行时间 Integer runTime = readPlc(nameSpace, "ProgramRunTime").intValue(); - setupTime=runTime+remainingTime; + setupTime = runTime + remainingTime; } - if (kilnInfo.getType()==2){ - setupTime=readPlc(nameSpace, "SetTime").intValue(); + if (kilnInfo.getType() == 2) { + setupTime = readPlc(nameSpace, "SetTime").intValue(); } nowCurrTask.setSetupTime(setupTime); nowCurrTask.setRemainingTime(remainingTime); - int completeness =(int) (((float)remainingTime/(float)setupTime )*100); + int completeness = (int) (((float) remainingTime / (float) setupTime) * 100); nowCurrTask.setCompleteness(completeness); nowCurrTask.setKilnCode(kilnInfo.getCode()); //标识卡详情 List currTaskDetList = currTaskDetServiceBiz.list(new QueryWrapper() .eq(CurrTaskDet.CURR_TASK_ID, nowCurrTask.getId())); List currTaskDetVoList = BeanUtils.copyList(currTaskDetList, CurrTaskDetVo.class); - for (CurrTaskDetVo currTaskDetVo:currTaskDetVoList - ) { + for (CurrTaskDetVo currTaskDetVo : currTaskDetVoList + ) { String customerName = orderInfoServiceBiz.getOne(new QueryWrapper().eq(OrderInfo.IDEN_CARD_NUM, currTaskDetVo.getIdenCardNum())).getCustomerName(); currTaskDetVo.setCustomer(customerName); } nowCurrTask.setCurrTaskDetVoList(currTaskDetVoList); } } - webSocketServer.sendtoUser(JSON.toJSONString(nowCurrTaskDetVoList),"2"); + webSocketServer.sendtoUser(JSON.toJSONString(nowCurrTaskDetVoList), "2"); } + /** * 查询加工完成的工业炉 */ - @Scheduled(fixedDelay = 1000*30) + @Scheduled(fixedDelay = 1000 * 30) public void taskForStockToKiln() throws IOException { //两辆车是否都空闲,只有两辆车都空闲才被允许做任务 List vehicleInfoList = vehicleInfoServiceBiz.list(new QueryWrapper().eq(VehicleInfo.STATUS, 0)); - if (vehicleInfoList.size()==2){ + if (vehicleInfoList.size() == 2) { //遍历currTask为进行中且is_in为正在加工的工业炉状态,若加工完毕,调用runTaskForOutKiln // 2022/3/6 有两托的判定哪一托好了(通过开始加工时间顺序排列) List currTaskList = currTaskServiceBiz.list(new QueryWrapper() .eq(CurrTask.STATUS, 1) .eq(CurrTask.IS_IN, 1) .orderByAsc(CurrTask.BEGIN_TIME)); - for (CurrTask currTask :currTaskList - ) { + for (CurrTask currTask : currTaskList + ) { Long kilnId = currTask.getKilnId(); KilnInfo kilnInfo = kilnInfoServiceBiz.getById(kilnId); PlcNameSpace plcNameSpace = plcNameSpaceServiceBiz.getOne(new QueryWrapper() .eq(PlcNameSpace.EQ_TYPE, 0) .eq(PlcNameSpace.TYPE, 0) - .eq(PlcNameSpace.EQ_ID,kilnId)); + .eq(PlcNameSpace.EQ_ID, kilnId)); //通过允许出炉信号来判定是否加工完成 String result = readPlcToString(plcNameSpace.getName(), "AllowOut"); Boolean resultBoolean = Boolean.valueOf(JSONObject.parseObject(result).get("result").toString()); - if (resultBoolean){ + if (resultBoolean) { //调用RunTaskUtils.runTaskForOutKiln - logger.info(kilnInfo.getCode()+kilnInfo.getKilnAlias()+"识别到允许出炉信号,进入出库程序!"); + logger.info(kilnInfo.getCode() + kilnInfo.getKilnAlias() + "识别到允许出炉信号,进入出库程序!"); //更新加工单工艺结束时间,只更新一次,因为可能因为不满住出炉条件而进入到下一次定时任务, - if ("null".equals(String.valueOf(currTask.getEndTime()))){ + if ("null".equals(String.valueOf(currTask.getEndTime()))) { currTask.setEndTime(LocalDateTime.now()); currTaskServiceBiz.updateById(currTask); //存入历史任务表以便查询能源消耗 - TaskHis taskHis=new TaskHis(); - org.springframework.beans.BeanUtils.copyProperties(currTask,taskHis); + TaskHis taskHis = new TaskHis(); + org.springframework.beans.BeanUtils.copyProperties(currTask, taskHis); taskHis.setStatus(2); taskHis.setIsIn(2); taskHis.setTaskId(currTask.getId()); @@ -239,8 +241,8 @@ public class ScheduledTask extends BaseService { List taskDetHisList = BeanUtils.copyList(currTaskDets, TaskDetHis.class); taskDetHisServiceBiz.saveBatch(taskDetHisList); //加工结束而没有立马出炉,加工结束记录能源消耗值只记录一次 - asynRunTaskService.asynEndRecordConsume(currTask.getId(),kilnId); - logger.info(kilnInfo.getCode()+"炉子中的任务:"+currTask.getId()+"已加工结束,记录加工结束能源消耗值"); + asynRunTaskService.asynEndRecordConsume(currTask.getId(), kilnId); + logger.info(kilnInfo.getCode() + "炉子中的任务:" + currTask.getId() + "已加工结束,记录加工结束能源消耗值"); } runTaskUtils.runTaskForOutKiln(kilnId); break; @@ -250,58 +252,58 @@ public class ScheduledTask extends BaseService { } //查询出正在加工的工业炉,遍历,根据采集频率的不同,采集高频数据能源消耗。暂定30秒 - @Scheduled(fixedDelay = 1000*30) - public void getFastValue(){ + @Scheduled(fixedDelay = 1000 * 30) + public void getFastValue() { //加工炉列表 - List kilnInfoList = kilnInfoServiceBiz.list(new QueryWrapper().in(KilnInfo.TYPE,1,3)); - for (KilnInfo kilnInfo:kilnInfoList - ) { + List kilnInfoList = kilnInfoServiceBiz.list(new QueryWrapper().in(KilnInfo.TYPE, 1, 3)); + for (KilnInfo kilnInfo : kilnInfoList + ) { PlcNameSpace nameSpace = plcNameSpaceServiceBiz.getOne(new QueryWrapper() .eq(PlcNameSpace.EQ_TYPE, 0) .eq(PlcNameSpace.EQ_ID, kilnInfo.getId()) - .eq(PlcNameSpace.TYPE,0)); + .eq(PlcNameSpace.TYPE, 0)); String nameSpaceNote = nameSpace.getName(); String result = readPlcToString(nameSpaceNote, "Working"); Boolean resultBoolean = Boolean.valueOf(JSONObject.parseObject(result).get("result").toString()); //该炉子在工作中 - if (resultBoolean){ + if (resultBoolean) { Long kilnId = kilnInfo.getId(); - Long currTaskId =0L; + Long currTaskId = 0L; //多用炉因为存在多个识别号且炉子给的DischargeIdentNumber为下油槽后的识别号,所以使用表里记录的任务id根据状态和进炉时间查出正在炉里且先进去的那个 - if (kilnInfo.getType()==1){ + if (kilnInfo.getType() == 1) { List currTaskList = currTaskServiceBiz.list(new QueryWrapper().eq(CurrTask.STATUS, 1) .eq(CurrTask.KILN_ID, kilnId).eq(CurrTask.IS_IN, 1)); - if (currTaskList.size()!=0){ - currTaskId=currTaskList.get(0).getId(); + if (currTaskList.size() != 0) { + currTaskId = currTaskList.get(0).getId(); } - }else { + } else { String identificationNumber = readPlcToString(nameSpaceNote, "DischargeIdentNumber"); - currTaskId=Long.valueOf(JSONObject.parseObject(identificationNumber).get("result").toString()); + currTaskId = Long.valueOf(JSONObject.parseObject(identificationNumber).get("result").toString()); } - if (currTaskId==0){ + if (currTaskId == 0) { continue; } CurrTask currTask = currTaskServiceBiz.getById(currTaskId); //任务为null说明是已删除的任务,不记录 - if (currTask==null){ + if (currTask == null) { continue; } //任务结束时间不为null,说明是已结束的任务,不记录 - if (currTask.getEndTime()!=null){ + if (currTask.getEndTime() != null) { continue; } //任务不在加工状态,不记录 - if (currTask.getIsIn()!=1){ + if (currTask.getIsIn() != 1) { continue; } //加工炉 - if (kilnInfo.getType()==1){ + if (kilnInfo.getType() == 1) { //一号油搅拌转速 Double oilStirringSpeed1 = readPlc(nameSpaceNote, "OilStirringSpeed1"); //二号油搅拌转速 Double oilStirringSpeed2 = readPlc(nameSpaceNote, "OilStirringSpeed2"); - ParRotSpeedValue parRotSpeedValue=new ParRotSpeedValue(); + ParRotSpeedValue parRotSpeedValue = new ParRotSpeedValue(); parRotSpeedValue.setOilStiSpeedAValue(oilStirringSpeed1.floatValue()); parRotSpeedValue.setOilStiSpeedAValue(oilStirringSpeed2.floatValue()); parRotSpeedValue.setKilnId(kilnId); @@ -320,7 +322,7 @@ public class ScheduledTask extends BaseService { Double actualCarbon = readPlc(nameSpaceNote, "ActualCarbon"); //设定碳势 Double setupCarbon = readPlc(nameSpaceNote, "SetupCarbon"); - ParGasValue parGasValue=new ParGasValue(); + ParGasValue parGasValue = new ParGasValue(); parGasValue.setNitFlowValue(nitrogenFlow.floatValue()); parGasValue.setAmmoniaFlowValue(ammoniaFlow.floatValue()); parGasValue.setMethanolFlow(methanolFlow.floatValue()); @@ -333,7 +335,7 @@ public class ScheduledTask extends BaseService { parGasValueServiceBiz.save(parGasValue); } //氮化炉 - if (kilnInfo.getType()==3){ + if (kilnInfo.getType() == 3) { //实际氮势 Double actualCarbon = readPlc(nameSpaceNote, "ActualCarbon"); //设定氮势 @@ -343,12 +345,12 @@ public class ScheduledTask extends BaseService { //分解率 Double decompositionRate = readPlc(nameSpaceNote, "DecompositionRate"); //氨气量 - Double ammoniaFlow=readPlc(nameSpaceNote,"AmmoniaFlow"); + Double ammoniaFlow = readPlc(nameSpaceNote, "AmmoniaFlow"); //氮气量 - Double nitrogenFlow=readPlc(nameSpaceNote,"NitrogenFlow"); + Double nitrogenFlow = readPlc(nameSpaceNote, "NitrogenFlow"); //二氧化碳量 Double carbonDioxideFlow = readPlc(nameSpaceNote, "CO2Flow"); - ParGasValue parGasValue3=new ParGasValue(); + ParGasValue parGasValue3 = new ParGasValue(); parGasValue3.setNitFlowValue(nitrogenFlow.floatValue()); parGasValue3.setAmmoniaFlowValue(ammoniaFlow.floatValue()); parGasValue3.setActualNitPotValue(actualCarbon.floatValue()); @@ -366,63 +368,63 @@ public class ScheduledTask extends BaseService { } //查询出正在加工的工业炉,遍历,根据采集频率的不同,采集低频数据能源消耗。暂定3分钟一次 - @Scheduled(fixedDelay = 1000*60*3) - public void getSlowValue(){ + @Scheduled(fixedDelay = 1000 * 60 * 3) + public void getSlowValue() { List kilnInfoList = kilnInfoServiceBiz.list(); - for (KilnInfo kilnInfo:kilnInfoList - ) { + for (KilnInfo kilnInfo : kilnInfoList + ) { PlcNameSpace nameSpace = plcNameSpaceServiceBiz.getOne(new QueryWrapper() .eq(PlcNameSpace.EQ_TYPE, 0) .eq(PlcNameSpace.EQ_ID, kilnInfo.getId()) - .eq(PlcNameSpace.TYPE,0)); + .eq(PlcNameSpace.TYPE, 0)); String nameSpaceNote = nameSpace.getName(); String result = readPlcToString(nameSpaceNote, "Working"); Boolean resultBoolean = Boolean.valueOf(JSONObject.parseObject(result).get("result").toString()); - if (resultBoolean){ + if (resultBoolean) { Long kilnId = kilnInfo.getId(); - Long currTaskId =0L; + Long currTaskId = 0L; //多用炉因为存在多个识别号且炉子给的DischargeIdentNumber为下油槽后的识别号,所以使用表里记录的任务id根据状态和进炉时间查出正在炉里且先进去的那个 - if (kilnInfo.getType()==1){ + if (kilnInfo.getType() == 1) { List currTaskList = currTaskServiceBiz.list(new QueryWrapper().eq(CurrTask.STATUS, 1) .eq(CurrTask.KILN_ID, kilnId).eq(CurrTask.IS_IN, 1)); - if (currTaskList.size()!=0){ - currTaskId=currTaskList.get(0).getId(); + if (currTaskList.size() != 0) { + currTaskId = currTaskList.get(0).getId(); } - }else { + } else { String identificationNumber = readPlcToString(nameSpaceNote, "DischargeIdentNumber"); - currTaskId=Long.valueOf(JSONObject.parseObject(identificationNumber).get("result").toString()); + currTaskId = Long.valueOf(JSONObject.parseObject(identificationNumber).get("result").toString()); } /* Long kilnId = kilnInfo.getId(); String identificationNumber = readPlcToString(nameSpaceNote, "DischargeIdentNumber"); Long currTaskId = Long.valueOf(JSONObject.parseObject(identificationNumber).get("result").toString());*/ //任务id为0说明不是自动任务,不记录 - if (currTaskId==0){ + if (currTaskId == 0) { continue; } CurrTask currTask = currTaskServiceBiz.getById(currTaskId); //任务为null说明是已删除的任务,不记录 - if (currTask==null){ + if (currTask == null) { continue; } //任务结束时间不为null,说明是已结束的任务,不记录 - if (currTask.getEndTime()!=null){ + if (currTask.getEndTime() != null) { continue; } //任务不在加工状态,不记录 - if (currTask.getIsIn()!=1){ + if (currTask.getIsIn() != 1) { continue; } //加工炉 - if (kilnInfo.getType()==1){ + if (kilnInfo.getType() == 1) { //实际温度 - Double actualTemp =readPlc(nameSpaceNote,"ActualTemp"); + Double actualTemp = readPlc(nameSpaceNote, "ActualTemp"); //设定温度 - Double setUpTemp = readPlc(nameSpaceNote,"SetUpTemp"); + Double setUpTemp = readPlc(nameSpaceNote, "SetUpTemp"); //油槽实际温度 Double actualOilTemp = readPlc(nameSpaceNote, "ActualOilTemp"); //油槽设定温度 - Double setUpOilTemp = readPlc(nameSpaceNote,"SetUpOilTemp"); - ParTemValue parTemValue=new ParTemValue(); + Double setUpOilTemp = readPlc(nameSpaceNote, "SetUpOilTemp"); + ParTemValue parTemValue = new ParTemValue(); parTemValue.setSetTemValue(setUpTemp.floatValue()); parTemValue.setActTemValue(actualTemp.floatValue()); parTemValue.setOilTankSetTemValue(setUpOilTemp.floatValue()); @@ -432,15 +434,24 @@ public class ScheduledTask extends BaseService { parTemValue.setCreateTime(LocalDateTime.now()); parTemValueServiceBiz.save(parTemValue); //电度值 - Double electricalValue = readPlc(nameSpaceNote,"ElectricalValue"); + Double electricalValue = readPlc(nameSpaceNote, "ElectricalValue"); //A向电压 - Double phaseAVoltage = readPlc(nameSpaceNote,"PhaseAVoltage"); + Double phaseAVoltage = readPlc(nameSpaceNote, "PhaseAVoltage"); Double phaseBVoltage = readPlc(nameSpaceNote, "PhaseBVoltage"); Double phaseCVoltage = readPlc(nameSpaceNote, "PhaseCVoltage"); - ParEleValue parEleValue=new ParEleValue(); + //ABC向电流 + Double phaseACurrent = readPlc(nameSpaceNote, "PhaseACurrent"); + Double phaseBCurrent = readPlc(nameSpaceNote, "PhaseBCurrent"); + Double phaseDCurrent = readPlc(nameSpaceNote, "PhaseDCurrent"); + ParEleValue parEleValue = new ParEleValue(); parEleValue.setAVoltagevValue(phaseAVoltage.floatValue()); - parEleValue.setAVoltagevValue(phaseBVoltage.floatValue()); - parEleValue.setAVoltagevValue(phaseCVoltage.floatValue()); + parEleValue.setBVoltagevValue(phaseBVoltage.floatValue()); + parEleValue.setCVoltagevValue(phaseCVoltage.floatValue()); + + parEleValue.setACurrentValue(phaseACurrent.floatValue()); + parEleValue.setBCurrentValue(phaseBCurrent.floatValue()); + parEleValue.setCCurrentValue(phaseDCurrent.floatValue()); + parEleValue.setTotalBat(electricalValue.floatValue()); parEleValue.setKilnId(kilnId); parEleValue.setTaskId(currTaskId); @@ -448,12 +459,12 @@ public class ScheduledTask extends BaseService { parEleValueServiceBiz.save(parEleValue); } //回火炉 - if (kilnInfo.getType()==2){ + if (kilnInfo.getType() == 2) { //实际温度 - Double actualTemp =readPlc(nameSpaceNote,"ActualTemp"); + Double actualTemp = readPlc(nameSpaceNote, "ActualTemp"); //设定温度 - Double setUpTemp = readPlc(nameSpaceNote,"SetUpTemp"); - ParTemValue parTemValue2=new ParTemValue(); + Double setUpTemp = readPlc(nameSpaceNote, "SetUpTemp"); + ParTemValue parTemValue2 = new ParTemValue(); parTemValue2.setSetTemValue(setUpTemp.floatValue()); parTemValue2.setActTemValue(actualTemp.floatValue()); parTemValue2.setKilnId(kilnId); @@ -461,15 +472,22 @@ public class ScheduledTask extends BaseService { parTemValue2.setCreateTime(LocalDateTime.now()); parTemValueServiceBiz.save(parTemValue2); //电度值 - Double electricalValue = readPlc(nameSpaceNote,"TotalElectricity"); + Double electricalValue = readPlc(nameSpaceNote, "TotalElectricity"); //A向电压 - Double phaseAVoltage = readPlc(nameSpaceNote,"AVoltage"); + Double phaseAVoltage = readPlc(nameSpaceNote, "AVoltage"); Double phaseBVoltage = readPlc(nameSpaceNote, "BVoltage"); Double phaseCVoltage = readPlc(nameSpaceNote, "CVoltage"); - ParEleValue parEleValue2=new ParEleValue(); + //ABC三相电流 + Double aCurrent = readPlc(nameSpaceNote, "ACurrent"); + Double bCurrent = readPlc(nameSpaceNote, "BCurrent"); + Double cCurrent = readPlc(nameSpaceNote, "CCurrent"); + ParEleValue parEleValue2 = new ParEleValue(); parEleValue2.setAVoltagevValue(phaseAVoltage.floatValue()); - parEleValue2.setAVoltagevValue(phaseBVoltage.floatValue()); - parEleValue2.setAVoltagevValue(phaseCVoltage.floatValue()); + parEleValue2.setBVoltagevValue(phaseBVoltage.floatValue()); + parEleValue2.setCVoltagevValue(phaseCVoltage.floatValue()); + parEleValue2.setACurrentValue(aCurrent.floatValue()); + parEleValue2.setBCurrentValue(bCurrent.floatValue()); + parEleValue2.setCCurrentValue(cCurrent.floatValue()); parEleValue2.setTotalBat(electricalValue.floatValue()); parEleValue2.setKilnId(kilnId); parEleValue2.setTaskId(currTaskId); @@ -477,18 +495,18 @@ public class ScheduledTask extends BaseService { parEleValueServiceBiz.save(parEleValue2); } //氮化炉 - if (kilnInfo.getType()==3){ + if (kilnInfo.getType() == 3) { //实际温度 - Double actualTemp =readPlc(nameSpaceNote,"ActualTemp"); + Double actualTemp = readPlc(nameSpaceNote, "ActualTemp"); //设定温度 - Double setUpTemp = readPlc(nameSpaceNote,"SetUpTemp"); + Double setUpTemp = readPlc(nameSpaceNote, "SetUpTemp"); //炉压 Double furnacePressure = readPlc(nameSpaceNote, "FurnacePressure"); //外一区温度 Double outerZoneITemperature = readPlc(nameSpaceNote, "OuterZoneITemperature"); //外二区温度 Double outerZone2Temperature = readPlc(nameSpaceNote, "OuterZone2Temperature"); - ParTemValue parTemValue3=new ParTemValue(); + ParTemValue parTemValue3 = new ParTemValue(); parTemValue3.setSetTemValue(setUpTemp.floatValue()); parTemValue3.setActTemValue(actualTemp.floatValue()); parTemValue3.setOuterZone1Temp(outerZoneITemperature.floatValue()); @@ -499,15 +517,22 @@ public class ScheduledTask extends BaseService { parTemValue3.setCreateTime(LocalDateTime.now()); parTemValueServiceBiz.save(parTemValue3); //电度值 - Double electricalValue = readPlc(nameSpaceNote,"ElectricalValue"); + Double electricalValue = readPlc(nameSpaceNote, "ElectricalValue"); //A向电压 - Double phaseAVoltage = readPlc(nameSpaceNote,"PhaseAVoltage"); + Double phaseAVoltage = readPlc(nameSpaceNote, "PhaseAVoltage"); Double phaseBVoltage = readPlc(nameSpaceNote, "PhaseBVoltage"); Double phaseCVoltage = readPlc(nameSpaceNote, "PhaseCVoltage"); - ParEleValue parEleValue3=new ParEleValue(); + //ABC三向电流 + Double phaseACurrent = readPlc(nameSpaceNote, "PhaseACurrent"); + Double phaseBCurrent = readPlc(nameSpaceNote, "PhaseBCurrent"); + Double phaseCCurrent = readPlc(nameSpaceNote, "PhaseCCurrent"); + ParEleValue parEleValue3 = new ParEleValue(); parEleValue3.setAVoltagevValue(phaseAVoltage.floatValue()); - parEleValue3.setAVoltagevValue(phaseBVoltage.floatValue()); - parEleValue3.setAVoltagevValue(phaseCVoltage.floatValue()); + parEleValue3.setBVoltagevValue(phaseBVoltage.floatValue()); + parEleValue3.setCVoltagevValue(phaseCVoltage.floatValue()); + parEleValue3.setACurrentValue(phaseACurrent.floatValue()); + parEleValue3.setBCurrentValue(phaseBCurrent.floatValue()); + parEleValue3.setCCurrentValue(phaseCVoltage.floatValue()); parEleValue3.setTotalBat(electricalValue.floatValue()); parEleValue3.setKilnId(kilnId); parEleValue3.setTaskId(currTaskId); @@ -515,17 +540,24 @@ public class ScheduledTask extends BaseService { parEleValueServiceBiz.save(parEleValue3); } //清洗炉 - if (kilnInfo.getType()==4){ + if (kilnInfo.getType() == 4) { //电度值 - Double electricalValue = readPlc(nameSpaceNote,"TotalElectricity"); + Double electricalValue = readPlc(nameSpaceNote, "TotalElectricity"); //A向电压 - Double phaseAVoltage = readPlc(nameSpaceNote,"AVoltage"); + Double phaseAVoltage = readPlc(nameSpaceNote, "AVoltage"); Double phaseBVoltage = readPlc(nameSpaceNote, "BVoltage"); Double phaseCVoltage = readPlc(nameSpaceNote, "CVoltage"); - ParEleValue parEleValue4=new ParEleValue(); + //ABC三向电流 + Double aCurrent = readPlc(nameSpaceNote, "ACurrent"); + Double bCurrent = readPlc(nameSpaceNote, "BCurrent"); + Double cCurrent = readPlc(nameSpaceNote, "CCurrent"); + ParEleValue parEleValue4 = new ParEleValue(); parEleValue4.setAVoltagevValue(phaseAVoltage.floatValue()); - parEleValue4.setAVoltagevValue(phaseBVoltage.floatValue()); - parEleValue4.setAVoltagevValue(phaseCVoltage.floatValue()); + parEleValue4.setBVoltagevValue(phaseBVoltage.floatValue()); + parEleValue4.setCVoltagevValue(phaseCVoltage.floatValue()); + parEleValue4.setACurrentValue(aCurrent.floatValue()); + parEleValue4.setBCurrentValue(bCurrent.floatValue()); + parEleValue4.setCCurrentValue(cCurrent.floatValue()); parEleValue4.setTotalBat(electricalValue.floatValue()); parEleValue4.setKilnId(kilnId); parEleValue4.setTaskId(currTaskId); @@ -538,36 +570,36 @@ public class ScheduledTask extends BaseService { //遍历工业炉,空工业炉查询缓存区是否有等待加工的任务, //待加工任务存在且没有状态为正在进炉的情况下,按照先进先出的规则选择待加工任务呼叫车辆进炉 - @Scheduled(fixedDelay = 1000*60) + //@Scheduled(fixedDelay = 1000*60) public void runTaskForEmptyKiln() throws IOException { List kilnInfoList = kilnInfoServiceBiz.list(new QueryWrapper() .eq(KilnInfo.VALID, 1).eq(KilnInfo.STATUS, 0).orderByAsc(KilnInfo.TYPE)); // 呼叫车辆运送货物给炉子 //存在空闲工业炉 - if (kilnInfoList.size()!=0) { - for (KilnInfo kilnInfo:kilnInfoList - ) { + if (kilnInfoList.size() != 0) { + for (KilnInfo kilnInfo : kilnInfoList + ) { //查询是否有车辆正在执行任务,如果有,等。(根据车辆是否正在运行可以避免出现前一个任务获取还没进去炉子,炉子状态依然为allowIn,从而继续发送任务的情况) List vehicleInfos = vehicleInfoServiceBiz.list(new QueryWrapper().eq(VehicleInfo.STATUS, 1)); - if (vehicleInfos.size()>0){ + if (vehicleInfos.size() > 0) { return; } - Boolean kilnReadyIn=false; - if (kilnInfo.getType()==1){ - kilnReadyIn=kilnReadyIn(kilnInfo.getId()); + Boolean kilnReadyIn = false; + if (kilnInfo.getType() == 1) { + kilnReadyIn = kilnReadyIn(kilnInfo.getId()); } //查询炉子是否allowIn Boolean kilnAllowIn = kilnAllowIn(kilnInfo.getId()); - if (kilnReadyIn||kilnAllowIn){ + if (kilnReadyIn || kilnAllowIn) { //因为readyIn在多用炉第一托盘下油后一直存在,到出炉为止.所以查询当前炉子在加工的任务,大于一条,则不再根据readyIn发起任务 List currTaskList = currTaskServiceBiz.list(new QueryWrapper() - .eq(CurrTask.KILN_ID, kilnInfo.getId()).eq(CurrTask.IS_IN, 1).eq(CurrTask.STATUS,1)); - if (kilnInfo.getType()==1){ - if (currTaskList.size()>1){ + .eq(CurrTask.KILN_ID, kilnInfo.getId()).eq(CurrTask.IS_IN, 1).eq(CurrTask.STATUS, 1)); + if (kilnInfo.getType() == 1) { + if (currTaskList.size() > 1) { continue; } - }else { - if (currTaskList.size()>0){ + } else { + if (currTaskList.size() > 0) { continue; } } @@ -579,12 +611,12 @@ public class ScheduledTask extends BaseService { .orderByAsc(InStockInfo.IN_TIME)); if (inStockInfoList.size() > 0) { InStockInfo inStockInfo = inStockInfoList.get(0); - logger.info("加工炉"+kilnInfo.getCode()+"readyIn为"+kilnReadyIn.toString()+" allowIn为"+kilnAllowIn.toString()); - logger.info("缓存区等待队列第一位:"+inStockInfo.toString()); + logger.info("加工炉" + kilnInfo.getCode() + "readyIn为" + kilnReadyIn.toString() + " allowIn为" + kilnAllowIn.toString()); + logger.info("缓存区等待队列第一位:" + inStockInfo.toString()); CurrTask currTask = currTaskServiceBiz.getById(inStockInfo.getTaskId()); - if (currTask.getStatus()!=0){ - logger.info(inStockInfo.toString()+"该缓存对应的任务状态为:"+currTask.getStatus()+"不能发起任务。"); - webSocketServer.sendtoUser(inStockInfo.getLocationName()+"对应的缓存加工任务状态不为未加工,不能发起任务,请先确认任务状态!","1"); + if (currTask.getStatus() != 0) { + logger.info(inStockInfo.toString() + "该缓存对应的任务状态为:" + currTask.getStatus() + "不能发起任务。"); + webSocketServer.sendtoUser(inStockInfo.getLocationName() + "对应的缓存加工任务状态不为未加工,不能发起任务,请先确认任务状态!", "1"); } Location location = locationServiceBiz.getById(inStockInfo.getLocationId()); //是否有小车在运行 @@ -594,13 +626,13 @@ public class ScheduledTask extends BaseService { //计算出路径最短的车辆id Long vehicleId = taskDistanceUtils.chooseVehicle(location.getCode(), kilnInfo.getCode()); //占用车辆 - if (vehicleId!=0){ + if (vehicleId != 0) { VehicleInfo vehicleInfo = vehicleInfoServiceBiz.getById(vehicleId); vehicleInfo.setStatus(1); vehicleInfo.setUpdateTime(LocalDateTime.now()); vehicleInfoServiceBiz.updateById(vehicleInfo); asynRunTaskService.asynRunTaskForStockToKiln(inStockInfo.getId(), vehicleId); - }else { + } else { logger.info("当前两辆车都不在线.无法发起任务!"); } } @@ -612,11 +644,11 @@ public class ScheduledTask extends BaseService { } //遍历正在工作炉子的报警变量,记录报警 - @Scheduled(fixedDelay = 1000*60) - public void listenKilnAlarm(){ + //@Scheduled(fixedDelay = 1000*60) + public void listenKilnAlarm() { List kilnInfoList = kilnInfoServiceBiz.list(); - for (KilnInfo kilnInfo:kilnInfoList - ) { + for (KilnInfo kilnInfo : kilnInfoList + ) { PlcNameSpace kilnNameSpace = plcNameSpaceServiceBiz.getOne(new QueryWrapper() .eq(PlcNameSpace.EQ_TYPE, 0) .eq(PlcNameSpace.EQ_ID, kilnInfo.getId())); @@ -624,53 +656,53 @@ public class ScheduledTask extends BaseService { String working = readPlcToString(kilnNameSpace.getName(), "Working"); JSONObject jsonObject = JSON.parseObject(working); Boolean aBoolean = Boolean.valueOf(String.valueOf(jsonObject.get("result"))); - if (aBoolean){ + if (aBoolean) { //命名空间前缀 String nameSpace = kilnNameSpace.getName(); //炉子的报警变量 List alarmNameList = plcNameSpaceServiceBiz.list(new QueryWrapper() .eq(PlcNameSpace.EQ_TYPE, 1) .eq(PlcNameSpace.TYPE, 1) - .eq(PlcNameSpace.EQ_ID,kilnInfo.getId()));; - for (PlcNameSpace plcNameSpace:alarmNameList + .eq(PlcNameSpace.EQ_ID, kilnInfo.getId())); + ; + for (PlcNameSpace plcNameSpace : alarmNameList ) { String name = plcNameSpace.getName(); Map json = new HashMap(); json.put("nameSpace", 6); json.put("plcName", "plc1"); - json.put("identifier",nameSpace+name); + json.put("identifier", nameSpace + name); String jsonString = JSON.toJSONString(json); try { String result = HttpClient.httpPost("http://localhost:8009/opcua/read", jsonString); Boolean resultBoolean = Boolean.valueOf(JSONObject.parseObject(result).get("result").toString()); //报警状态为true - if (resultBoolean){ + if (resultBoolean) { //任务状态为执行中且正在炉子中加工的任务 List currTaskList = currTaskServiceBiz.list(new QueryWrapper() .eq(CurrTask.KILN_ID, kilnInfo.getId()) .eq(CurrTask.IS_IN, 1) .eq(CurrTask.STATUS, 1)); - if (currTaskList.size()!=0){ - for (CurrTask currTask:currTaskList - ) { - AlarmInfo alarmInfo=new AlarmInfo(); + if (currTaskList.size() != 0) { + for (CurrTask currTask : currTaskList + ) { + AlarmInfo alarmInfo = new AlarmInfo(); alarmInfo.setEquipmentId(currTask.getKilnId()); alarmInfo.setEquipmentName(currTask.getKilnName()); alarmInfo.setType(0); alarmInfo.setAlarmCode(CodeGeneratorHelper.getAlarmCode()); - alarmInfo.setAlarmInfo(plcNameSpace.getEqName()+":"+plcNameSpace.getNote()); + alarmInfo.setAlarmInfo(plcNameSpace.getEqName() + ":" + plcNameSpace.getNote()); alarmInfo.setTaskCode(currTask.getTaskCode()); alarmInfo.setCreateTime(LocalDateTime.now()); alarmInfoServiceBiz.save(alarmInfo); } - } - else { - AlarmInfo alarmInfo=new AlarmInfo(); + } else { + AlarmInfo alarmInfo = new AlarmInfo(); alarmInfo.setEquipmentId(kilnInfo.getId()); alarmInfo.setEquipmentName(kilnInfo.getKilnName()); alarmInfo.setType(0); alarmInfo.setAlarmCode(CodeGeneratorHelper.getAlarmCode()); - alarmInfo.setAlarmInfo(plcNameSpace.getEqName()+":"+plcNameSpace.getNote()); + alarmInfo.setAlarmInfo(plcNameSpace.getEqName() + ":" + plcNameSpace.getNote()); alarmInfo.setTaskCode("0"); alarmInfo.setCreateTime(LocalDateTime.now()); alarmInfoServiceBiz.save(alarmInfo); @@ -686,88 +718,94 @@ public class ScheduledTask extends BaseService { //监听车辆是否在线,定时恢复车辆状态会导致避让时等待时间过久,再次发起任务,造成重复发起,废弃 public void listenVehicleOnline() throws IOException { - List vehicleInfoList = vehicleInfoServiceBiz.list(new QueryWrapper().eq(VehicleInfo.STATUS,1)); - for (VehicleInfo vehicleInfo:vehicleInfoList - ) { + List vehicleInfoList = vehicleInfoServiceBiz.list(new QueryWrapper().eq(VehicleInfo.STATUS, 1)); + for (VehicleInfo vehicleInfo : vehicleInfoList + ) { Boolean rgvOnline = rgvOnline(vehicleInfo.getId()); Boolean rgvFree = rgvFree(vehicleInfo.getId()); - if (!rgvOnline){ - webSocketServer.sendtoUser("当前存在车辆不在线,请移动停用的车辆到轨道尽头处或者改车辆为线上模式,如果已经车辆停用,请忽略本提示消息。","1"); + if (!rgvOnline) { + webSocketServer.sendtoUser("当前存在车辆不在线,请移动停用的车辆到轨道尽头处或者改车辆为线上模式,如果已经车辆停用,请忽略本提示消息。", "1"); } - if (rgvOnline&&rgvFree){ + if (rgvOnline && rgvFree) { vehicleInfo.setStatus(0); vehicleInfoServiceBiz.updateById(vehicleInfo); - logger.info("检测到车辆:"+vehicleInfo.getId()+" 显示状态为占用,实际状态为空闲。自动置车辆状态为空闲。"); + logger.info("检测到车辆:" + vehicleInfo.getId() + " 显示状态为占用,实际状态为空闲。自动置车辆状态为空闲。"); } } } + /** * 获取变量值 - * @param nameSpace nameSpace前缀 + * + * @param nameSpace nameSpace前缀 * @param variableName 变量名称 * @return result字符串 */ - private String readPlcToString(String nameSpace, String variableName){ - String identifier=nameSpace.concat(variableName); + private String readPlcToString(String nameSpace, String variableName) { + String identifier = nameSpace.concat(variableName); Map json = new HashMap(); json.put("nameSpace", 6); json.put("plcName", "plc1"); - json.put("identifier",identifier); + json.put("identifier", identifier); String result = null; try { result = HttpClient.httpPost("http://192.168.6.51:8009/opcua/read", JSON.toJSONString(json)); } catch (IOException e) { e.printStackTrace(); - logger.info("readPLC: "+identifier+" 的值失败"); + logger.info("readPLC: " + identifier + " 的值失败"); } return result; } + /** * 获取变量值 - * @param nameSpace nameSpace前缀 + * + * @param nameSpace nameSpace前缀 * @param variableName 变量名称 * @return 变量值 */ - private Double readPlc(String nameSpace, String variableName){ - String identifier=nameSpace.concat(variableName); + private Double readPlc(String nameSpace, String variableName) { + String identifier = nameSpace.concat(variableName); Map json = new HashMap(); json.put("nameSpace", 6); json.put("plcName", "plc1"); - json.put("identifier",identifier); + json.put("identifier", identifier); String result = null; try { result = HttpClient.httpPost("http://192.168.6.51:8009/opcua/read", JSON.toJSONString(json)); } catch (IOException e) { e.printStackTrace(); - logger.info("能源消耗统计:获取 "+identifier+" 的值失败"); + logger.info("能源消耗统计:获取 " + identifier + " 的值失败"); } return Double.valueOf(JSONObject.parseObject(result).get("result").toString()); } - private Boolean kilnAllowIn(Long kilnId){ + private Boolean kilnAllowIn(Long kilnId) { PlcNameSpace nameSpace = plcNameSpaceServiceBiz.getOne(new QueryWrapper() .eq(PlcNameSpace.EQ_TYPE, 0) .eq(PlcNameSpace.EQ_ID, kilnId) - .eq(PlcNameSpace.TYPE,0)); + .eq(PlcNameSpace.TYPE, 0)); String nameSpaceNote = nameSpace.getName(); String result = readPlcToString(nameSpaceNote, "AllowIn"); return Boolean.valueOf(JSONObject.parseObject(result).get("result").toString()); } - private Boolean kilnReadyIn(Long kilnId){ + + private Boolean kilnReadyIn(Long kilnId) { PlcNameSpace nameSpace = plcNameSpaceServiceBiz.getOne(new QueryWrapper() .eq(PlcNameSpace.EQ_TYPE, 0) .eq(PlcNameSpace.EQ_ID, kilnId) - .eq(PlcNameSpace.TYPE,0)); + .eq(PlcNameSpace.TYPE, 0)); String nameSpaceNote = nameSpace.getName(); String result = readPlcToString(nameSpaceNote, "ReadyIn"); return Boolean.valueOf(JSONObject.parseObject(result).get("result").toString()); } - private Boolean kilnWorking(Long kilnId){ + + private Boolean kilnWorking(Long kilnId) { PlcNameSpace nameSpace = plcNameSpaceServiceBiz.getOne(new QueryWrapper() .eq(PlcNameSpace.EQ_TYPE, 0) .eq(PlcNameSpace.EQ_ID, kilnId) - .eq(PlcNameSpace.TYPE,0)); + .eq(PlcNameSpace.TYPE, 0)); String nameSpaceNote = nameSpace.getName(); String result = readPlcToString(nameSpaceNote, "Working"); return Boolean.valueOf(JSONObject.parseObject(result).get("result").toString()); @@ -775,28 +813,29 @@ public class ScheduledTask extends BaseService { /** * 车辆是否在线 + * * @param vehicleId 车辆id * @return true/false - * @throws IOException plc访问失败 + * @throws IOException plc访问失败 */ private Boolean rgvOnline(Long vehicleId) throws IOException { - String identifier=null; - if (vehicleId==1){ - identifier="S7-1200 station_2.Boutique.DB500_PLCToWCS.RGV1ToWCS.Online"; + String identifier = null; + if (vehicleId == 1) { + identifier = "S7-1200 station_2.Boutique.DB500_PLCToWCS.RGV1ToWCS.Online"; } - if (vehicleId==2){ - identifier="S7-1200 station_2.Boutique.DB500_PLCToWCS.RGV2ToWCS.Online"; + if (vehicleId == 2) { + identifier = "S7-1200 station_2.Boutique.DB500_PLCToWCS.RGV2ToWCS.Online"; } Map json = new HashMap(); json.put("nameSpace", 6); json.put("plcName", "plc1"); - json.put("identifier",identifier); + json.put("identifier", identifier); String result = null; try { result = HttpClient.httpPost("http://192.168.6.51:8009/opcua/read", JSON.toJSONString(json)); } catch (IOException e) { e.printStackTrace(); - logger.info("获取车辆"+vehicleId+"当前是否在线失败"); + logger.info("获取车辆" + vehicleId + "当前是否在线失败"); } Boolean online = Boolean.valueOf(JSONObject.parseObject(result).get("result").toString()); return online; @@ -804,28 +843,29 @@ public class ScheduledTask extends BaseService { /** * 车辆是否空闲 + * * @param vehicleId 车辆id * @return true/false - * @throws IOException plc访问失败 + * @throws IOException plc访问失败 */ private Boolean rgvFree(Long vehicleId) throws IOException { - String identifier=null; - if (vehicleId==1){ - identifier="S7-1200 station_2.Boutique.DB500_PLCToWCS.RGV1ToWCS.Free"; + String identifier = null; + if (vehicleId == 1) { + identifier = "S7-1200 station_2.Boutique.DB500_PLCToWCS.RGV1ToWCS.Free"; } - if (vehicleId==2){ - identifier="S7-1200 station_2.Boutique.DB500_PLCToWCS.RGV2ToWCS.Free"; + if (vehicleId == 2) { + identifier = "S7-1200 station_2.Boutique.DB500_PLCToWCS.RGV2ToWCS.Free"; } Map json = new HashMap(); json.put("nameSpace", 6); json.put("plcName", "plc1"); - json.put("identifier",identifier); + json.put("identifier", identifier); String result = null; try { result = HttpClient.httpPost("http://192.168.6.51:8009/opcua/read", JSON.toJSONString(json)); } catch (IOException e) { e.printStackTrace(); - logger.info("获取车辆"+vehicleId+"当前是否空闲失败"); + logger.info("获取车辆" + vehicleId + "当前是否空闲失败"); } Boolean free = Boolean.valueOf(JSONObject.parseObject(result).get("result").toString()); return free;