新增
Этот коммит содержится в:
родитель
11b41b18f1
Коммит
df116253ff
@ -344,6 +344,57 @@
|
||||
</appender>
|
||||
<!-- 1线 结束 -->
|
||||
|
||||
<!-- event4 开始 -->
|
||||
<appender name="EVENT4_APPENDER_LINE1" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文档的路径及文档名 -->
|
||||
<file>${logging.eventlog}/line1/event4/kuka-ngEvent-log-info.log</file>
|
||||
<!--日志文档输出格式-->
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<!-- rollover daily -->
|
||||
<fileNamePattern>${logging.eventlog}/line1/kuka-ngEvent-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
|
||||
<maxHistory>999</maxHistory>
|
||||
<totalSizeCap>200GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
<!-- 此日志文档只记录info级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>info</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
<appender name="EVENT4_APPENDER_LINE2" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文档的路径及文档名 -->
|
||||
<file>${logging.eventlog}/line2/event4/kuka-ngEvent-log-info.log</file>
|
||||
<!--日志文档输出格式-->
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<!-- rollover daily -->
|
||||
<fileNamePattern>${logging.eventlog}/line2/kuka-ngEvent-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
|
||||
<maxHistory>999</maxHistory>
|
||||
<totalSizeCap>200GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
<!-- 此日志文档只记录info级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>info</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
<!-- event4 结束 -->
|
||||
|
||||
<!-- 2.3 level为 WARN 日志,时间滚动输出 -->
|
||||
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文档的路径及文档名 -->
|
||||
@ -567,6 +618,15 @@
|
||||
</logger>
|
||||
<!-- LINE2 结束 -->
|
||||
|
||||
<!-- LINE4NG 开始 -->
|
||||
<logger name="EVENT4NGLine1" level="INFO" additivity="false">
|
||||
<appender-ref ref="EVENT4_APPENDER_LINE1" />
|
||||
</logger>
|
||||
<logger name="EVENT4NGLine2" level="INFO" additivity="false">
|
||||
<appender-ref ref="EVENT4_APPENDER_LINE2" />
|
||||
</logger>
|
||||
<!-- LINE4NG 结束 -->
|
||||
|
||||
<!-- LINE1 开始 -->
|
||||
<logger name="EVENT1Line1" level="INFO" additivity="false">
|
||||
<appender-ref ref="EVENT1_APPENDER_LINE1" />
|
||||
|
@ -14,7 +14,6 @@ public enum Step1Plc2MesVar {
|
||||
SubIdToMes("SubIdToMes",PlcVar.STRING,1,DaveArea.DB,2000,2,0,20),
|
||||
LineNum("LineNum", PlcVar.UINT,1, DaveArea.DB,2000,24,0),
|
||||
|
||||
|
||||
;
|
||||
|
||||
private String name;
|
||||
|
@ -0,0 +1,90 @@
|
||||
package com.cnbm.dispatch.enums.kuka.step4;
|
||||
|
||||
import com.cnbm.s7.s7connector.api.DaveArea;
|
||||
import com.cnbm.s7.s7connector.type.PlcVar;
|
||||
|
||||
/**
|
||||
* @Desc: ""
|
||||
* @Author: caixiang
|
||||
* @DATE: 2023/2/21 19:35
|
||||
*/
|
||||
public enum Step4Mes2PlcVar {
|
||||
SubArrivedFinish("SubArrivedFinish", PlcVar.BOOL,1, DaveArea.DB,2001,24,0),
|
||||
|
||||
dLable_Pnom("dLable_Pnom", PlcVar.DINT,1, DaveArea.DB,2001,26,0),
|
||||
dLable_Voc("dLable_Voc", PlcVar.REAL,1, DaveArea.DB,2001,30,0),
|
||||
dLable_Isc("dLable_Isc", PlcVar.REAL,1, DaveArea.DB,2001,34,0),
|
||||
dLable_Vmpp("dLable_Vmpp", PlcVar.REAL,1, DaveArea.DB,2001,38,0),
|
||||
dLable_Impp("dLable_Vmpp", PlcVar.REAL,1, DaveArea.DB,2001,42,0),
|
||||
;
|
||||
|
||||
private String name;
|
||||
private DaveArea area;
|
||||
private Integer areaNumber;
|
||||
private Integer byteOffset;
|
||||
private Integer bitOffset;
|
||||
private PlcVar type;
|
||||
//length = 1代表 非数组;;; length > 1 代表数组 ;; 注意 length这个参数 是实际plc中 数组的长度,和read操作相关
|
||||
//如果是String 类型不用填length 只需要填string类型的起始位置就行了,我会自己去取数据长度(也就是说这里的length并不是string 的长度)。
|
||||
private Integer length;
|
||||
|
||||
//这个字段只是给 字符串变量 和 字符串数组 用, 这个字段是plc中设置的最大String长度
|
||||
private Integer strSize;
|
||||
|
||||
Step4Mes2PlcVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset){
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.length = length;
|
||||
this.area = area;
|
||||
this.areaNumber = areaNumber;
|
||||
this.byteOffset = byteOffset;
|
||||
this.bitOffset = bitOffset;
|
||||
this.strSize = 0;
|
||||
}
|
||||
Step4Mes2PlcVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset, Integer strSize){
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.length = length;
|
||||
this.area = area;
|
||||
this.areaNumber = areaNumber;
|
||||
this.byteOffset = byteOffset;
|
||||
this.bitOffset = bitOffset;
|
||||
this.strSize = strSize;
|
||||
}
|
||||
|
||||
public Integer getStrSize() {
|
||||
return strSize;
|
||||
}
|
||||
|
||||
public void setStrSize(Integer strSize) {
|
||||
this.strSize = strSize;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public DaveArea getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public Integer getAreaNumber() {
|
||||
return areaNumber;
|
||||
}
|
||||
|
||||
public Integer getBitOffset() {
|
||||
return bitOffset;
|
||||
}
|
||||
|
||||
public Integer getByteOffset() {
|
||||
return byteOffset;
|
||||
}
|
||||
|
||||
public PlcVar getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Integer getLength() {
|
||||
return length;
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.cnbm.dispatch.enums.kuka.step4;
|
||||
|
||||
import com.cnbm.s7.s7connector.api.DaveArea;
|
||||
import com.cnbm.s7.s7connector.type.PlcVar;
|
||||
|
||||
/**
|
||||
* @Desc: ""
|
||||
* @Author: caixiang
|
||||
* @DATE: 2023/2/21 19:35
|
||||
*/
|
||||
public enum Step4Plc2MesVar {
|
||||
|
||||
SubArrivedToMes("SubArrivedToMes", PlcVar.BOOL,1, DaveArea.DB,2001,0,0),
|
||||
SubIdToMes("SubIdToMes",PlcVar.STRING,1,DaveArea.DB,2001,2,0,20),
|
||||
|
||||
;
|
||||
|
||||
private String name;
|
||||
private DaveArea area;
|
||||
private Integer areaNumber;
|
||||
private Integer byteOffset;
|
||||
private Integer bitOffset;
|
||||
private PlcVar type;
|
||||
//length = 1代表 非数组;;; length > 1 代表数组 ;; 注意 length这个参数 是实际plc中 数组的长度,和read操作相关
|
||||
//如果是String 类型不用填length 只需要填string类型的起始位置就行了,我会自己去取数据长度(也就是说这里的length并不是string 的长度)。
|
||||
private Integer length;
|
||||
|
||||
//这个字段只是给 字符串变量 和 字符串数组 用, 这个字段是plc中设置的最大String长度
|
||||
private Integer strSize;
|
||||
|
||||
Step4Plc2MesVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset){
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.length = length;
|
||||
this.area = area;
|
||||
this.areaNumber = areaNumber;
|
||||
this.byteOffset = byteOffset;
|
||||
this.bitOffset = bitOffset;
|
||||
this.strSize = 0;
|
||||
}
|
||||
Step4Plc2MesVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset, Integer strSize){
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.length = length;
|
||||
this.area = area;
|
||||
this.areaNumber = areaNumber;
|
||||
this.byteOffset = byteOffset;
|
||||
this.bitOffset = bitOffset;
|
||||
this.strSize = strSize;
|
||||
}
|
||||
|
||||
public Integer getStrSize() {
|
||||
return strSize;
|
||||
}
|
||||
|
||||
public void setStrSize(Integer strSize) {
|
||||
this.strSize = strSize;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public DaveArea getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public Integer getAreaNumber() {
|
||||
return areaNumber;
|
||||
}
|
||||
|
||||
public Integer getBitOffset() {
|
||||
return bitOffset;
|
||||
}
|
||||
|
||||
public Integer getByteOffset() {
|
||||
return byteOffset;
|
||||
}
|
||||
|
||||
public PlcVar getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Integer getLength() {
|
||||
return length;
|
||||
}
|
||||
}
|
@ -261,7 +261,6 @@ public class KukaEvent1ThreadLine1 implements ApplicationRunner {
|
||||
CamlineExtendArgDTO extendArgFromCamline = service.getExtendArgFromCamline(subId);
|
||||
logger.info("标签打印Event--- 基板ID: "+subId+", 从camline获取PID16~PID22 的实测数据 成功, 数据内容:"+extendArgFromCamline.toString());
|
||||
woPackagingBoxSubstrate.setLastUpdateTime(extendArgFromCamline.getLastUpdateTime());
|
||||
|
||||
woPackagingBoxSubstrate.setOrderName(extendArgFromCamline.getOrderName());
|
||||
woPackagingBoxSubstrate.setBinclassFl1(extendArgFromCamline.getBinclassFl1());
|
||||
woPackagingBoxSubstrate.setBinclassFl2(extendArgFromCamline.getBinclassFl2());
|
||||
@ -320,7 +319,6 @@ public class KukaEvent1ThreadLine1 implements ApplicationRunner {
|
||||
}
|
||||
}
|
||||
},1,1, TimeUnit.SECONDS);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -152,18 +152,22 @@ public class KukaEvent2ThreadLine1 implements ApplicationRunner {
|
||||
String nowTime = DateUtil.format(new Date(), "yyMMdd");
|
||||
|
||||
todayBoxNum+=500;
|
||||
Format f1 = new DecimalFormat("000");
|
||||
System.out.println(f1.format(todayBoxNum));
|
||||
logger.info("BOXID生成Event-------现在生成boxId ,sapMaterial: "+sapMaterial+",nowTime:"+nowTime+",todayBoxNum:"+formateString(todayBoxNum));
|
||||
String res = "301"+sapMaterial+nowTime+formateString(todayBoxNum);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public String getErrorBoxId(String sapMaterial){
|
||||
|
||||
|
||||
public String getErrorBoxId(String sapMaterial){
|
||||
Integer todayErrBoxNum = service.getTodayErrBoxNum()+1;
|
||||
String nowTime = DateUtil.format(new Date(), "yyMMdd");
|
||||
String mixBoxError = "001";
|
||||
String res = "444"+sapMaterial+nowTime+mixBoxError;
|
||||
logger.info("BOXID生成Event-------现在生成errBoxId ,sapMaterial: "+sapMaterial+",nowTime:"+nowTime);
|
||||
String res = "444"+sapMaterial+nowTime+mixBoxError+"01"+todayErrBoxNum;
|
||||
logger.info("BOXID生成Event-------现在生成errBoxId ,sapMaterial: "+sapMaterial+",nowTime:"+nowTime+",todayErrBoxNum:"+todayErrBoxNum);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -174,8 +178,10 @@ public class KukaEvent2ThreadLine1 implements ApplicationRunner {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer a = 102;
|
||||
Integer b = 1;
|
||||
Format f1 = new DecimalFormat("000");
|
||||
System.out.println(f1.format(a));
|
||||
System.out.println(f1.format(b));
|
||||
}
|
||||
public String formateString(Integer a){
|
||||
Format f1 = new DecimalFormat("000");
|
||||
@ -183,12 +189,68 @@ public class KukaEvent2ThreadLine1 implements ApplicationRunner {
|
||||
}
|
||||
|
||||
//return true 出现混档了,return false 没有出现混档
|
||||
// private boolean isMixLevel(String[] subIds,Integer size){
|
||||
// WoPackagingBoxSubstrate bySubId = substrateServiceBiz.getBySubId(subIds[0]);
|
||||
// String correctLevel = null;
|
||||
// String powerLevel = null;
|
||||
// //如果 我们数据库没有 去camline 数据库里面取 -- 开始
|
||||
// if(bySubId == null){
|
||||
// logger.info("BOXID生成Event-------检查是否混箱时,发现数据库中 无subId:"+ subIds[0]+"现在从camline 系统获取这个基板相关信息");
|
||||
// //todo
|
||||
// CamlineSubIdDTO subIdByCamline = service.getSubIdByCamline(subIds[0]);
|
||||
// logger.info("BOXID生成Event-------检查是否混箱时,发现数据库中 无subId:"+ subIds[0]+"现在从camline 系统获取这个基板相关信息是:"+subIdByCamline);
|
||||
//
|
||||
// correctLevel = subIdByCamline.getPowerLevel();
|
||||
// powerLevel = subIdByCamline.getSapMaterial();
|
||||
// }else {
|
||||
// correctLevel = bySubId.getPowerLevel();
|
||||
// powerLevel = bySubId.getSapMaterial();
|
||||
// }
|
||||
// String errMsg = "以下基板ID出现混档:";
|
||||
// boolean res = false;
|
||||
// for(int i=0;i<size;i++){
|
||||
//
|
||||
// if(!powerLevel.equals(correctLevel)){
|
||||
// errMsg += "基板ID:"+subIds[i]+" 档位:"+powerLevel+", ";
|
||||
// res = true;
|
||||
// }
|
||||
// }
|
||||
// if(res){
|
||||
// logger.error(errMsg);
|
||||
// }
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
private CamlineSubIdDTO getFromCamline(String subId){
|
||||
return service.getSubIdByCamline(subId);
|
||||
}
|
||||
private boolean isMixLevel(String[] subIds,Integer size){
|
||||
String correctLevel = substrateServiceBiz.getBySubId(subIds[0]).getPowerLevel();
|
||||
WoPackagingBoxSubstrate bySubId = substrateServiceBiz.getBySubId(subIds[0]);
|
||||
String correctLevel = null;
|
||||
|
||||
//如果 我们数据库没有 去camline 数据库里面取 -- 开始
|
||||
if(bySubId == null){
|
||||
logger.info("BOXID生成Event-------检查是否混箱时,发现数据库中 无subId:"+ subIds[0]+"现在从camline 系统获取这个基板相关信息");
|
||||
//todo
|
||||
CamlineSubIdDTO subIdByCamline = service.getSubIdByCamline(subIds[0]);
|
||||
logger.info("BOXID生成Event-------检查是否混箱时,发现数据库中 无subId:"+ subIds[0]+"现在从camline 系统获取这个基板相关信息是:"+subIdByCamline);
|
||||
|
||||
correctLevel = subIdByCamline.getPowerLevel();
|
||||
}else {
|
||||
correctLevel = bySubId.getPowerLevel();
|
||||
}
|
||||
|
||||
|
||||
String errMsg = "以下基板ID出现混档:";
|
||||
boolean res = false;
|
||||
for(int i=0;i<size;i++){
|
||||
String powerLevel = substrateServiceBiz.getBySubId(subIds[i]).getPowerLevel();
|
||||
WoPackagingBoxSubstrate innerSub = substrateServiceBiz.getBySubId(subIds[i]);
|
||||
String powerLevel = null;
|
||||
if(innerSub==null){
|
||||
powerLevel = getFromCamline(subIds[i]).getPowerLevel();
|
||||
}else {
|
||||
powerLevel = innerSub.getPowerLevel();
|
||||
}
|
||||
|
||||
if(!powerLevel.equals(correctLevel)){
|
||||
errMsg += "基板ID:"+subIds[i]+" 档位:"+powerLevel+", ";
|
||||
@ -203,8 +265,6 @@ public class KukaEvent2ThreadLine1 implements ApplicationRunner {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
kukaStep2.scheduleAtFixedRate(new Runnable() {
|
||||
@ -212,7 +272,6 @@ public class KukaEvent2ThreadLine1 implements ApplicationRunner {
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
|
||||
//调度开始
|
||||
Integer shelfIsFull = waitingForTarget(Step2Plc2MesVar.ShelfIsFull, true);
|
||||
logger.info("");
|
||||
@ -251,30 +310,38 @@ public class KukaEvent2ThreadLine1 implements ApplicationRunner {
|
||||
|
||||
|
||||
//如果我们系统中找不到这块基板那么就去camline里面找
|
||||
// if(bySubId == null){
|
||||
// logger.info("BOXID生成Event-------数据库中 无subId:"+ subIdList[0]+"现在从camline 系统获取这个基板相关信息");
|
||||
// //todo
|
||||
// CamlineSubIdDTO subIdByCamline = service.getSubIdByCamline(subIdList[0]);
|
||||
// logger.info("BOXID生成Event-------camline 中关于此基板信息:"+ subIdByCamline);
|
||||
//
|
||||
// bySubId = new WoPackagingBoxSubstrate();
|
||||
// bySubId.setPowerLevel(subIdByCamline.getPowerLevel());
|
||||
// bySubId.setSapMaterial(subIdByCamline.getSapMaterial());
|
||||
// bySubId.setLineBody(1);
|
||||
// }
|
||||
if(bySubId == null){
|
||||
logger.info("BOXID生成Event-------数据库中 无subId:"+ subIdList[0]+"现在从camline 系统获取这个基板相关信息");
|
||||
//todo
|
||||
CamlineSubIdDTO subIdByCamline = service.getSubIdByCamline(subIdList[0]);
|
||||
bySubId = new WoPackagingBoxSubstrate();
|
||||
bySubId.setPowerLevel(subIdByCamline.getPowerLevel());
|
||||
bySubId.setSapMaterial(subIdByCamline.getSapMaterial());
|
||||
bySubId.setLineBody(1);
|
||||
logger.info("BOXID生成Event-------数据库中 无subId:"+ subIdList[0]);
|
||||
throw new Exception("BOXID生成Event-------数据库中 无subId:"+ subIdList[0]);
|
||||
}
|
||||
|
||||
|
||||
//校验是否存在混档位情况
|
||||
//校验是否存在混档位情况 -- 开始
|
||||
String boxId = "";
|
||||
if(isMixLevel(subIdList,listSize)){
|
||||
//出现混档
|
||||
logger.info("BOXID生成Event-------subIdList :"+subIdList+"出现混档");
|
||||
logger.info("BOXID生成Event-------subIdList :"+Arrays.asList(subIdList)+"出现混档");
|
||||
boxId = getErrorBoxId(bySubId.getSapMaterial());
|
||||
|
||||
}else {
|
||||
//正常情况
|
||||
logger.info("BOXID生成Event-------subIdList :"+subIdList+"没有出现混档");
|
||||
logger.info("BOXID生成Event-------subIdList :"+Arrays.asList(subIdList)+"没有出现混档");
|
||||
boxId = getBoxId(bySubId.getSapMaterial());
|
||||
}
|
||||
logger.info("BOXID生成Event-------subIdList :"+subIdList+"isMixLevel 校验结束");
|
||||
logger.info("BOXID生成Event-------subIdList :"+Arrays.asList(subIdList)+"isMixLevel 校验结束");
|
||||
//校验是否存在混档位情况 -- 结束
|
||||
|
||||
|
||||
logger.info("BOXID生成Event-------mes 生成的boxId :"+ boxId);
|
||||
//2. 依次update 基板表,把boxId 赋予这些基板
|
||||
|
@ -0,0 +1,306 @@
|
||||
package com.cnbm.dispatch.line1;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.cnbm.dispatch.enums.kuka.step2.Step2Mes2PlcVar;
|
||||
import com.cnbm.dispatch.enums.kuka.step2.Step2Plc2MesVar;
|
||||
import com.cnbm.dispatch.enums.kuka.step3.Step3Mes2PlcVar;
|
||||
import com.cnbm.dispatch.enums.kuka.step3.Step3Plc2MesVar;
|
||||
import com.cnbm.dispatch.enums.kuka.step4.Step4Mes2PlcVar;
|
||||
import com.cnbm.dispatch.enums.kuka.step4.Step4Plc2MesVar;
|
||||
import com.cnbm.packing.entity.WoPowerLevel;
|
||||
import com.cnbm.packing.service.*;
|
||||
import com.cnbm.s7.s7connector.enmuc.S7Client;
|
||||
import com.cnbm.s7.s7connector.type.PlcVar;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.Format;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Desc: ""
|
||||
* @Author: caixiang
|
||||
* @DATE: 2022/12/23 12:33
|
||||
*/
|
||||
@Component
|
||||
@Order(value = 1)
|
||||
public class KukaEvent4ThreadLine1 implements ApplicationRunner {
|
||||
private static final Logger logger = LoggerFactory.getLogger("EVENT4NGLine1");
|
||||
|
||||
@Autowired
|
||||
DynamicDataSourceService service;
|
||||
@Autowired
|
||||
WoPowerLevelServiceBiz levelServiceBiz;
|
||||
|
||||
@Autowired
|
||||
WoCompensationPowerServiceBiz compensationPowerServiceBiz;
|
||||
|
||||
@Autowired
|
||||
WoPackagingBoxSubstrateServiceBiz substrateServiceBiz;
|
||||
|
||||
@Autowired
|
||||
WoPackagingBoxServiceBiz boxServiceBiz;
|
||||
|
||||
public KukaEvent4ThreadLine1(){
|
||||
this.kukaStep1 = Executors.newScheduledThreadPool(1);
|
||||
}
|
||||
|
||||
private ScheduledExecutorService kukaStep1;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* return
|
||||
* 成功: 返回相应的object对象
|
||||
* 失败: 返回null
|
||||
* */
|
||||
private Object read(S7Client s7Client, Step4Plc2MesVar var) {
|
||||
try {
|
||||
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
|
||||
}catch (Throwable e){
|
||||
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private void write(S7Client s7Client, Step4Mes2PlcVar var, Object newValue) {
|
||||
if(var.getType().equals(PlcVar.STRING_Array)){
|
||||
String[] s = (String[])newValue;
|
||||
String[] ss = (String[])newValue;
|
||||
if(s.length > var.getLength() ){
|
||||
ss = new String[var.getLength()];
|
||||
for(int i=0;i< var.getLength();i++){
|
||||
ss[i] = s[i];
|
||||
}
|
||||
}
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
|
||||
}else {
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
|
||||
}
|
||||
}
|
||||
|
||||
private Object read(S7Client s7Client, Step2Plc2MesVar var) {
|
||||
try {
|
||||
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
|
||||
}catch (Throwable e){
|
||||
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private void write(S7Client s7Client, Step2Mes2PlcVar var, Object newValue) {
|
||||
if(var.getType().equals(PlcVar.STRING_Array)){
|
||||
String[] s = (String[])newValue;
|
||||
String[] ss = (String[])newValue;
|
||||
if(s.length > var.getLength() ){
|
||||
ss = new String[var.getLength()];
|
||||
for(int i=0;i< var.getLength();i++){
|
||||
ss[i] = s[i];
|
||||
}
|
||||
}
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
|
||||
}else {
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
|
||||
}
|
||||
}
|
||||
|
||||
private Object read(S7Client s7Client, Step3Plc2MesVar var) {
|
||||
try {
|
||||
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
|
||||
}catch (Throwable e){
|
||||
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private void write(S7Client s7Client, Step3Mes2PlcVar var, Object newValue) {
|
||||
if(var.getType().equals(PlcVar.STRING_Array)){
|
||||
String[] s = (String[])newValue;
|
||||
String[] ss = (String[])newValue;
|
||||
if(s.length > var.getLength() ){
|
||||
ss = new String[var.getLength()];
|
||||
for(int i=0;i< var.getLength();i++){
|
||||
ss[i] = s[i];
|
||||
}
|
||||
}
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
|
||||
}else {
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getBoxId(String sapMaterial){
|
||||
Integer todayBoxNum = service.getTodayBoxNum()+1;
|
||||
String nowTime = DateUtil.format(new Date(), "yyMMdd");
|
||||
|
||||
todayBoxNum+=500;
|
||||
logger.info("BOXID生成Event-------现在生成boxId ,sapMaterial: "+sapMaterial+",nowTime:"+nowTime+",todayBoxNum:"+formateString(todayBoxNum));
|
||||
String res = "301"+sapMaterial+nowTime+formateString(todayBoxNum);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public String getErrorBoxId(String sapMaterial){
|
||||
|
||||
String nowTime = DateUtil.format(new Date(), "yyMMdd");
|
||||
String mixBoxError = "001";
|
||||
String res = "444"+sapMaterial+nowTime+mixBoxError;
|
||||
logger.info("BOXID生成Event-------现在生成errBoxId ,sapMaterial: "+sapMaterial+",nowTime:"+nowTime);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public String removeKG(String str){
|
||||
return str.substring(0,17);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer a = 102;
|
||||
Format f1 = new DecimalFormat("000");
|
||||
System.out.println(f1.format(a));
|
||||
}
|
||||
public String formateString(Integer a){
|
||||
Format f1 = new DecimalFormat("000");
|
||||
return f1.format(a);
|
||||
}
|
||||
|
||||
//return true 出现混档了,return false 没有出现混档
|
||||
private boolean isMixLevel(String[] subIds,Integer size){
|
||||
String correctLevel = substrateServiceBiz.getBySubId(subIds[0]).getPowerLevel();
|
||||
String errMsg = "以下基板ID出现混档:";
|
||||
boolean res = false;
|
||||
for(int i=0;i<size;i++){
|
||||
String powerLevel = substrateServiceBiz.getBySubId(subIds[i]).getPowerLevel();
|
||||
|
||||
if(!powerLevel.equals(correctLevel)){
|
||||
errMsg += "基板ID:"+subIds[i]+" 档位:"+powerLevel+", ";
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
if(res){
|
||||
logger.error(errMsg);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
|
||||
kukaStep1.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
//调度开始
|
||||
Integer subArrived = waitingForTarget(Step4Plc2MesVar.SubArrivedToMes, true);
|
||||
logger.info("");
|
||||
logger.info("================================== 现在开始执行 过程四 任务( 开始 ) ===================================");
|
||||
if(subArrived != 1){
|
||||
logger.info("NG口基板Event--- 失败"+" --- "+" MES监听 Step4Plc2MesVar.SubArrivedToMes 是否 等于 true 失败");
|
||||
} else if (subArrived == 2) {
|
||||
throw new Exception("MES 监听值出现异常。");
|
||||
}
|
||||
logger.info("NG口基板Event --- 成功 ---- MES监听到 Step4Plc2MesVar.SubArrivedToMes==true");
|
||||
|
||||
//一. 从plc 中获取 subId
|
||||
String subId = (String) read(S7Client.S7_DDJ1,Step4Plc2MesVar.SubIdToMes);
|
||||
Integer lineNum = 1;
|
||||
//把基板ID字符串的空格去掉,因为plc中设置的20位,但实际基板ID就是17位,因为带空格去数据库查询 有问题的。
|
||||
if(subId == null ){
|
||||
logger.info("NG口基板Event--- 失败"+" --- "+" MES采集到null值,subId:"+subId);
|
||||
}
|
||||
subId = removeKG(subId);
|
||||
logger.info("NG口基板Event --- 成功 ---- MES 从plu中 read 到基板id:"+subId);
|
||||
|
||||
//二. MES 业务
|
||||
//=============== MES 业务 开始 =================
|
||||
logger.info("================= 现在开始执行 过程四 任务 ( MES 业务 ) ( 开始 ) ==================");
|
||||
//1. 从comline数据库中获取 实际pmpp
|
||||
float pmppActual = service.getPMPPBySubId(subId);
|
||||
//2. 匹配和计算补偿功率
|
||||
float pmppCompensation = compensationPowerServiceBiz.calculCompensationPMPP(pmppActual,lineNum);
|
||||
//3. 依据补偿功率,获取工艺参数,并且把这些工艺参数传给kuka
|
||||
WoPowerLevel argByPMPP = levelServiceBiz.getArgByPMPP(pmppCompensation, lineNum);
|
||||
write(S7Client.S7_DDJ1,Step4Mes2PlcVar.dLable_Pnom,Integer.valueOf(argByPMPP.getPowerClass()));
|
||||
write(S7Client.S7_DDJ1,Step4Mes2PlcVar.dLable_Voc,argByPMPP.getLableVoc());
|
||||
write(S7Client.S7_DDJ1,Step4Mes2PlcVar.dLable_Isc,argByPMPP.getLableIsc());
|
||||
write(S7Client.S7_DDJ1,Step4Mes2PlcVar.dLable_Vmpp,argByPMPP.getLableVmpp());
|
||||
write(S7Client.S7_DDJ1,Step4Mes2PlcVar.dLable_Impp,argByPMPP.getLableImpp());
|
||||
logger.info("NG口基板Event--- 采集到 基板ID: "+subId+", 线边号:"+lineNum+",从camline 获取到实际pmpp"+pmppActual+",计算后 补偿功率:"+pmppCompensation+",dLable_Pnom: "+argByPMPP.getPowerClass() +",dLable_Voc: "+argByPMPP.getLableVoc()+",dLable_Isc: "+argByPMPP.getLableIsc()+",dLable_Vmpp: "+argByPMPP.getLableVmpp()+",dLable_Impp: "+argByPMPP.getLableImpp());
|
||||
|
||||
logger.info("================= 现在开始执行 过程四 任务 ( MES 业务 - 数据已经传给PLC ) ( 结束 ) ==================");
|
||||
//=============== MES 业务 结束 =================
|
||||
|
||||
//三. 当MES完成任务后,把MesToPlc.SubArrivedFinish变量置为true,告诉plc,我操作完成了
|
||||
write(S7Client.S7_DDJ1,Step4Mes2PlcVar.SubArrivedFinish,true);
|
||||
logger.info("NG口基板Event--- 基板ID: "+subId+", SubArrivedFinish,置为true 成功");
|
||||
//四. mes 监控 到PlcToMes.SubArrived==false,就把MesToPlc.SubArrivedFinish置为false
|
||||
Integer subArrived2 = waitingForTarget(Step4Plc2MesVar.SubArrivedToMes, false);
|
||||
if(subArrived2 != 1){
|
||||
logger.info("NG口基板Event--- 失败"+" --- "+"MES监听 Step4Plc2MesVar.SubArrivedToMes 是否 等于 1 失败");
|
||||
}else if (subArrived2 == 2) {
|
||||
throw new Exception("MES 监听值出现异常。");
|
||||
}
|
||||
|
||||
write(S7Client.S7_DDJ1,Step4Mes2PlcVar.SubArrivedFinish,false);
|
||||
logger.info("NG口基板Event--- 基板ID: "+subId+", SubArrivedFinish,置为 false 成功");
|
||||
logger.info("================================== 现在开始执行 过程四 任务( 结束 ) ===================================");
|
||||
logger.info("");
|
||||
}catch (Throwable e){
|
||||
logger.info("NG口基板Event--- 出现异常 : {}",e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
},1,1, TimeUnit.SECONDS);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* arg:
|
||||
* Step4Plc2MesVar 参数类型
|
||||
* targetValue 目的值
|
||||
* return:
|
||||
* 2 s7 访问异常;
|
||||
* 1 成功;
|
||||
* */
|
||||
private Integer waitingForTarget(Step4Plc2MesVar var, Boolean targetValue) {
|
||||
Integer res = 0;
|
||||
while (true){
|
||||
try {
|
||||
|
||||
Boolean now = (Boolean) read(S7Client.S7_DDJ1,var);
|
||||
//注意:即使now为null ,这里也不会抛出异常,这里很容易产生 空轮询。
|
||||
if(now == null){
|
||||
throw new Exception("");
|
||||
}
|
||||
if(targetValue.equals(now)){
|
||||
res = 1;
|
||||
break;
|
||||
}
|
||||
Thread.sleep(200);
|
||||
}catch (Throwable e){
|
||||
logger.info("S7 数据采集 异常. 监听 变量 :"+var.getName()+" 为目标值:"+targetValue+"失败");
|
||||
res = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -158,12 +158,22 @@ public class KukaEvent2ThreadLine2 implements ApplicationRunner {
|
||||
}
|
||||
|
||||
|
||||
public String getErrorBoxId(String sapMaterial){
|
||||
// public String getErrorBoxId(String sapMaterial){
|
||||
//
|
||||
// String nowTime = DateUtil.format(new Date(), "yyMMdd");
|
||||
// String mixBoxError = "001";
|
||||
// String res = "444"+sapMaterial+nowTime+mixBoxError +"02";
|
||||
// logger.info("BOXID生成Event-------现在生成errBoxId ,sapMaterial: "+sapMaterial+",nowTime:"+nowTime);
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
|
||||
public String getErrorBoxId(String sapMaterial){
|
||||
Integer todayErrBoxNum = service.getTodayErrBoxNum()+1;
|
||||
String nowTime = DateUtil.format(new Date(), "yyMMdd");
|
||||
String mixBoxError = "001";
|
||||
String res = "444"+sapMaterial+nowTime+mixBoxError;
|
||||
logger.info("BOXID生成Event-------现在生成errBoxId ,sapMaterial: "+sapMaterial+",nowTime:"+nowTime);
|
||||
String res = "444"+sapMaterial+nowTime+mixBoxError+"02"+todayErrBoxNum;
|
||||
logger.info("BOXID生成Event-------现在生成errBoxId ,sapMaterial: "+sapMaterial+",nowTime:"+nowTime+",todayErrBoxNum:"+todayErrBoxNum);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -183,12 +193,57 @@ public class KukaEvent2ThreadLine2 implements ApplicationRunner {
|
||||
}
|
||||
|
||||
//return true 出现混档了,return false 没有出现混档
|
||||
// private boolean isMixLevel(String[] subIds,Integer size){
|
||||
// String correctLevel = substrateServiceBiz.getBySubId(subIds[0]).getPowerLevel();
|
||||
// String errMsg = "以下基板ID出现混档:";
|
||||
// boolean res = false;
|
||||
// for(int i=0;i<size;i++){
|
||||
// String powerLevel = substrateServiceBiz.getBySubId(subIds[i]).getPowerLevel();
|
||||
//
|
||||
// if(!powerLevel.equals(correctLevel)){
|
||||
// errMsg += "基板ID:"+subIds[i]+" 档位:"+powerLevel+", ";
|
||||
// res = true;
|
||||
// }
|
||||
// }
|
||||
// if(res){
|
||||
// logger.error(errMsg);
|
||||
// }
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
|
||||
|
||||
private CamlineSubIdDTO getFromCamline(String subId){
|
||||
return service.getSubIdByCamline(subId);
|
||||
}
|
||||
|
||||
private boolean isMixLevel(String[] subIds,Integer size){
|
||||
String correctLevel = substrateServiceBiz.getBySubId(subIds[0]).getPowerLevel();
|
||||
WoPackagingBoxSubstrate bySubId = substrateServiceBiz.getBySubId(subIds[0]);
|
||||
String correctLevel = null;
|
||||
|
||||
//如果 我们数据库没有 去camline 数据库里面取 -- 开始
|
||||
if(bySubId == null){
|
||||
logger.info("BOXID生成Event-------检查是否混箱时,发现数据库中 无subId:"+ subIds[0]+"现在从camline 系统获取这个基板相关信息");
|
||||
//todo
|
||||
CamlineSubIdDTO subIdByCamline = service.getSubIdByCamline(subIds[0]);
|
||||
logger.info("BOXID生成Event-------检查是否混箱时,发现数据库中 无subId:"+ subIds[0]+"现在从camline 系统获取这个基板相关信息是:"+subIdByCamline);
|
||||
|
||||
correctLevel = subIdByCamline.getPowerLevel();
|
||||
}else {
|
||||
correctLevel = bySubId.getPowerLevel();
|
||||
}
|
||||
|
||||
|
||||
String errMsg = "以下基板ID出现混档:";
|
||||
boolean res = false;
|
||||
for(int i=0;i<size;i++){
|
||||
String powerLevel = substrateServiceBiz.getBySubId(subIds[i]).getPowerLevel();
|
||||
WoPackagingBoxSubstrate innerSub = substrateServiceBiz.getBySubId(subIds[i]);
|
||||
String powerLevel = null;
|
||||
if(innerSub==null){
|
||||
powerLevel = getFromCamline(subIds[i]).getPowerLevel();
|
||||
}else {
|
||||
powerLevel = innerSub.getPowerLevel();
|
||||
}
|
||||
|
||||
if(!powerLevel.equals(correctLevel)){
|
||||
errMsg += "基板ID:"+subIds[i]+" 档位:"+powerLevel+", ";
|
||||
@ -197,14 +252,13 @@ public class KukaEvent2ThreadLine2 implements ApplicationRunner {
|
||||
}
|
||||
if(res){
|
||||
logger.error(errMsg);
|
||||
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
kukaStep2.scheduleAtFixedRate(new Runnable() {
|
||||
@ -251,14 +305,18 @@ public class KukaEvent2ThreadLine2 implements ApplicationRunner {
|
||||
|
||||
|
||||
//如果我们系统中找不到这块基板那么就去camline里面找
|
||||
// if(bySubId == null){
|
||||
// logger.info("BOXID生成Event-------数据库中 无subId:"+ subIdList[0]+"现在从camline 系统获取这个基板相关信息");
|
||||
// //todo
|
||||
// CamlineSubIdDTO subIdByCamline = service.getSubIdByCamline(subIdList[0]);
|
||||
// bySubId = new WoPackagingBoxSubstrate();
|
||||
// bySubId.setPowerLevel(subIdByCamline.getPowerLevel());
|
||||
// bySubId.setSapMaterial(subIdByCamline.getSapMaterial());
|
||||
// bySubId.setLineBody(2);
|
||||
// }
|
||||
if(bySubId == null){
|
||||
logger.info("BOXID生成Event-------数据库中 无subId:"+ subIdList[0]+"现在从camline 系统获取这个基板相关信息");
|
||||
//todo
|
||||
CamlineSubIdDTO subIdByCamline = service.getSubIdByCamline(subIdList[0]);
|
||||
bySubId = new WoPackagingBoxSubstrate();
|
||||
bySubId.setPowerLevel(subIdByCamline.getPowerLevel());
|
||||
bySubId.setSapMaterial(subIdByCamline.getSapMaterial());
|
||||
bySubId.setLineBody(2);
|
||||
logger.info("BOXID生成Event-------数据库中 无subId:"+ subIdList[0]);
|
||||
throw new Exception("BOXID生成Event-------数据库中 无subId:"+ subIdList[0]);
|
||||
}
|
||||
|
||||
|
||||
@ -266,15 +324,15 @@ public class KukaEvent2ThreadLine2 implements ApplicationRunner {
|
||||
String boxId = "";
|
||||
if(isMixLevel(subIdList,listSize)){
|
||||
//出现混档
|
||||
logger.info("BOXID生成Event-------subIdList :"+subIdList+"出现混档");
|
||||
logger.info("BOXID生成Event-------subIdList :"+Arrays.asList(subIdList)+"出现混档");
|
||||
boxId = getErrorBoxId(bySubId.getSapMaterial());
|
||||
|
||||
}else {
|
||||
//正常情况
|
||||
logger.info("BOXID生成Event-------subIdList :"+subIdList+"没有出现混档");
|
||||
logger.info("BOXID生成Event-------subIdList :"+Arrays.asList(subIdList)+"没有出现混档");
|
||||
boxId = getBoxId(bySubId.getSapMaterial());
|
||||
}
|
||||
logger.info("BOXID生成Event-------subIdList :"+subIdList+"isMixLevel 校验结束");
|
||||
logger.info("BOXID生成Event-------subIdList :"+Arrays.asList(subIdList)+"isMixLevel 校验结束");
|
||||
|
||||
logger.info("BOXID生成Event-------mes 生成的boxId :"+ boxId);
|
||||
//2. 依次update 基板表,把boxId 赋予这些基板
|
||||
|
@ -0,0 +1,306 @@
|
||||
package com.cnbm.dispatch.line2;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.cnbm.dispatch.enums.kuka.step2.Step2Mes2PlcVar;
|
||||
import com.cnbm.dispatch.enums.kuka.step2.Step2Plc2MesVar;
|
||||
import com.cnbm.dispatch.enums.kuka.step3.Step3Mes2PlcVar;
|
||||
import com.cnbm.dispatch.enums.kuka.step3.Step3Plc2MesVar;
|
||||
import com.cnbm.dispatch.enums.kuka.step4.Step4Mes2PlcVar;
|
||||
import com.cnbm.dispatch.enums.kuka.step4.Step4Plc2MesVar;
|
||||
import com.cnbm.packing.entity.WoPowerLevel;
|
||||
import com.cnbm.packing.service.*;
|
||||
import com.cnbm.s7.s7connector.enmuc.S7Client;
|
||||
import com.cnbm.s7.s7connector.type.PlcVar;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.Format;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Desc: ""
|
||||
* @Author: caixiang
|
||||
* @DATE: 2022/12/23 12:33
|
||||
*/
|
||||
@Component
|
||||
@Order(value = 1)
|
||||
public class KukaEvent4ThreadLine2 implements ApplicationRunner {
|
||||
private static final Logger logger = LoggerFactory.getLogger("EVENT4NGLine2");
|
||||
|
||||
@Autowired
|
||||
DynamicDataSourceService service;
|
||||
@Autowired
|
||||
WoPowerLevelServiceBiz levelServiceBiz;
|
||||
|
||||
@Autowired
|
||||
WoCompensationPowerServiceBiz compensationPowerServiceBiz;
|
||||
|
||||
@Autowired
|
||||
WoPackagingBoxSubstrateServiceBiz substrateServiceBiz;
|
||||
|
||||
@Autowired
|
||||
WoPackagingBoxServiceBiz boxServiceBiz;
|
||||
|
||||
public KukaEvent4ThreadLine2(){
|
||||
this.kukaStep1 = Executors.newScheduledThreadPool(1);
|
||||
}
|
||||
|
||||
private ScheduledExecutorService kukaStep1;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* return
|
||||
* 成功: 返回相应的object对象
|
||||
* 失败: 返回null
|
||||
* */
|
||||
private Object read(S7Client s7Client, Step4Plc2MesVar var) {
|
||||
try {
|
||||
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
|
||||
}catch (Throwable e){
|
||||
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private void write(S7Client s7Client, Step4Mes2PlcVar var, Object newValue) {
|
||||
if(var.getType().equals(PlcVar.STRING_Array)){
|
||||
String[] s = (String[])newValue;
|
||||
String[] ss = (String[])newValue;
|
||||
if(s.length > var.getLength() ){
|
||||
ss = new String[var.getLength()];
|
||||
for(int i=0;i< var.getLength();i++){
|
||||
ss[i] = s[i];
|
||||
}
|
||||
}
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
|
||||
}else {
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
|
||||
}
|
||||
}
|
||||
|
||||
private Object read(S7Client s7Client, Step2Plc2MesVar var) {
|
||||
try {
|
||||
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
|
||||
}catch (Throwable e){
|
||||
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private void write(S7Client s7Client, Step2Mes2PlcVar var, Object newValue) {
|
||||
if(var.getType().equals(PlcVar.STRING_Array)){
|
||||
String[] s = (String[])newValue;
|
||||
String[] ss = (String[])newValue;
|
||||
if(s.length > var.getLength() ){
|
||||
ss = new String[var.getLength()];
|
||||
for(int i=0;i< var.getLength();i++){
|
||||
ss[i] = s[i];
|
||||
}
|
||||
}
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
|
||||
}else {
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
|
||||
}
|
||||
}
|
||||
|
||||
private Object read(S7Client s7Client, Step3Plc2MesVar var) {
|
||||
try {
|
||||
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
|
||||
}catch (Throwable e){
|
||||
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private void write(S7Client s7Client, Step3Mes2PlcVar var, Object newValue) {
|
||||
if(var.getType().equals(PlcVar.STRING_Array)){
|
||||
String[] s = (String[])newValue;
|
||||
String[] ss = (String[])newValue;
|
||||
if(s.length > var.getLength() ){
|
||||
ss = new String[var.getLength()];
|
||||
for(int i=0;i< var.getLength();i++){
|
||||
ss[i] = s[i];
|
||||
}
|
||||
}
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
|
||||
}else {
|
||||
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getBoxId(String sapMaterial){
|
||||
Integer todayBoxNum = service.getTodayBoxNum()+1;
|
||||
String nowTime = DateUtil.format(new Date(), "yyMMdd");
|
||||
|
||||
todayBoxNum+=500;
|
||||
logger.info("BOXID生成Event-------现在生成boxId ,sapMaterial: "+sapMaterial+",nowTime:"+nowTime+",todayBoxNum:"+formateString(todayBoxNum));
|
||||
String res = "301"+sapMaterial+nowTime+formateString(todayBoxNum);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public String getErrorBoxId(String sapMaterial){
|
||||
|
||||
String nowTime = DateUtil.format(new Date(), "yyMMdd");
|
||||
String mixBoxError = "001";
|
||||
String res = "444"+sapMaterial+nowTime+mixBoxError;
|
||||
logger.info("BOXID生成Event-------现在生成errBoxId ,sapMaterial: "+sapMaterial+",nowTime:"+nowTime);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public String removeKG(String str){
|
||||
return str.substring(0,17);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer a = 102;
|
||||
Format f1 = new DecimalFormat("000");
|
||||
System.out.println(f1.format(a));
|
||||
}
|
||||
public String formateString(Integer a){
|
||||
Format f1 = new DecimalFormat("000");
|
||||
return f1.format(a);
|
||||
}
|
||||
|
||||
//return true 出现混档了,return false 没有出现混档
|
||||
private boolean isMixLevel(String[] subIds,Integer size){
|
||||
String correctLevel = substrateServiceBiz.getBySubId(subIds[0]).getPowerLevel();
|
||||
String errMsg = "以下基板ID出现混档:";
|
||||
boolean res = false;
|
||||
for(int i=0;i<size;i++){
|
||||
String powerLevel = substrateServiceBiz.getBySubId(subIds[i]).getPowerLevel();
|
||||
|
||||
if(!powerLevel.equals(correctLevel)){
|
||||
errMsg += "基板ID:"+subIds[i]+" 档位:"+powerLevel+", ";
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
if(res){
|
||||
logger.error(errMsg);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
|
||||
kukaStep1.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
//调度开始
|
||||
Integer subArrived = waitingForTarget(Step4Plc2MesVar.SubArrivedToMes, true);
|
||||
logger.info("");
|
||||
logger.info("================================== 现在开始执行 过程四 任务( 开始 ) ===================================");
|
||||
if(subArrived != 1){
|
||||
logger.info("NG口基板Event--- 失败"+" --- "+" MES监听 Step4Plc2MesVar.SubArrivedToMes 是否 等于 true 失败");
|
||||
} else if (subArrived == 2) {
|
||||
throw new Exception("MES 监听值出现异常。");
|
||||
}
|
||||
logger.info("NG口基板Event --- 成功 ---- MES监听到 Step4Plc2MesVar.SubArrivedToMes==true");
|
||||
|
||||
//一. 从plc 中获取 subId
|
||||
String subId = (String) read(S7Client.S7_DDJ2,Step4Plc2MesVar.SubIdToMes);
|
||||
Integer lineNum = 1;
|
||||
//把基板ID字符串的空格去掉,因为plc中设置的20位,但实际基板ID就是17位,因为带空格去数据库查询 有问题的。
|
||||
if(subId == null ){
|
||||
logger.info("NG口基板Event--- 失败"+" --- "+" MES采集到null值,subId:"+subId);
|
||||
}
|
||||
subId = removeKG(subId);
|
||||
logger.info("NG口基板Event --- 成功 ---- MES 从plu中 read 到基板id:"+subId);
|
||||
|
||||
//二. MES 业务
|
||||
//=============== MES 业务 开始 =================
|
||||
logger.info("================= 现在开始执行 过程四 任务 ( MES 业务 ) ( 开始 ) ==================");
|
||||
//1. 从comline数据库中获取 实际pmpp
|
||||
float pmppActual = service.getPMPPBySubId(subId);
|
||||
//2. 匹配和计算补偿功率
|
||||
float pmppCompensation = compensationPowerServiceBiz.calculCompensationPMPP(pmppActual,lineNum);
|
||||
//3. 依据补偿功率,获取工艺参数,并且把这些工艺参数传给kuka
|
||||
WoPowerLevel argByPMPP = levelServiceBiz.getArgByPMPP(pmppCompensation, lineNum);
|
||||
write(S7Client.S7_DDJ2,Step4Mes2PlcVar.dLable_Pnom,Integer.valueOf(argByPMPP.getPowerClass()));
|
||||
write(S7Client.S7_DDJ2,Step4Mes2PlcVar.dLable_Voc,argByPMPP.getLableVoc());
|
||||
write(S7Client.S7_DDJ2,Step4Mes2PlcVar.dLable_Isc,argByPMPP.getLableIsc());
|
||||
write(S7Client.S7_DDJ2,Step4Mes2PlcVar.dLable_Vmpp,argByPMPP.getLableVmpp());
|
||||
write(S7Client.S7_DDJ2,Step4Mes2PlcVar.dLable_Impp,argByPMPP.getLableImpp());
|
||||
logger.info("NG口基板Event--- 采集到 基板ID: "+subId+", 线边号:"+lineNum+",从camline 获取到实际pmpp"+pmppActual+",计算后 补偿功率:"+pmppCompensation+",dLable_Pnom: "+argByPMPP.getPowerClass() +",dLable_Voc: "+argByPMPP.getLableVoc()+",dLable_Isc: "+argByPMPP.getLableIsc()+",dLable_Vmpp: "+argByPMPP.getLableVmpp()+",dLable_Impp: "+argByPMPP.getLableImpp());
|
||||
|
||||
logger.info("================= 现在开始执行 过程四 任务 ( MES 业务 - 数据已经传给PLC ) ( 结束 ) ==================");
|
||||
//=============== MES 业务 结束 =================
|
||||
|
||||
//三. 当MES完成任务后,把MesToPlc.SubArrivedFinish变量置为true,告诉plc,我操作完成了
|
||||
write(S7Client.S7_DDJ2,Step4Mes2PlcVar.SubArrivedFinish,true);
|
||||
logger.info("NG口基板Event--- 基板ID: "+subId+", SubArrivedFinish,置为true 成功");
|
||||
//四. mes 监控 到PlcToMes.SubArrived==false,就把MesToPlc.SubArrivedFinish置为false
|
||||
Integer subArrived2 = waitingForTarget(Step4Plc2MesVar.SubArrivedToMes, false);
|
||||
if(subArrived2 != 1){
|
||||
logger.info("NG口基板Event--- 失败"+" --- "+"MES监听 Step4Plc2MesVar.SubArrivedToMes 是否 等于 1 失败");
|
||||
}else if (subArrived2 == 2) {
|
||||
throw new Exception("MES 监听值出现异常。");
|
||||
}
|
||||
|
||||
write(S7Client.S7_DDJ2,Step4Mes2PlcVar.SubArrivedFinish,false);
|
||||
logger.info("NG口基板Event--- 基板ID: "+subId+", SubArrivedFinish,置为 false 成功");
|
||||
logger.info("================================== 现在开始执行 过程四 任务( 结束 ) ===================================");
|
||||
logger.info("");
|
||||
}catch (Throwable e){
|
||||
logger.info("NG口基板Event--- 出现异常 : {}",e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
},1,1, TimeUnit.SECONDS);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* arg:
|
||||
* Step4Plc2MesVar 参数类型
|
||||
* targetValue 目的值
|
||||
* return:
|
||||
* 2 s7 访问异常;
|
||||
* 1 成功;
|
||||
* */
|
||||
private Integer waitingForTarget(Step4Plc2MesVar var, Boolean targetValue) {
|
||||
Integer res = 0;
|
||||
while (true){
|
||||
try {
|
||||
|
||||
Boolean now = (Boolean) read(S7Client.S7_DDJ2,var);
|
||||
//注意:即使now为null ,这里也不会抛出异常,这里很容易产生 空轮询。
|
||||
if(now == null){
|
||||
throw new Exception("");
|
||||
}
|
||||
if(targetValue.equals(now)){
|
||||
res = 1;
|
||||
break;
|
||||
}
|
||||
Thread.sleep(200);
|
||||
}catch (Throwable e){
|
||||
logger.info("S7 数据采集 异常. 监听 变量 :"+var.getName()+" 为目标值:"+targetValue+"失败");
|
||||
res = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -28,6 +28,7 @@ public interface CamlineMapper {
|
||||
CamlineExtendArgDTO getExtendArgFromCamline(@Param("subId") String subId);
|
||||
|
||||
Integer getTodayBoxNum();
|
||||
Integer getTodayErrBoxNum();
|
||||
|
||||
CamlineSubIdDTO getSubIdByCamline(@Param("subId") String subId);
|
||||
|
||||
|
@ -31,6 +31,10 @@ public class DynamicDataSourceService {
|
||||
return mapper.getTodayBoxNum();
|
||||
}
|
||||
|
||||
public Integer getTodayErrBoxNum(){
|
||||
return mapper.getTodayErrBoxNum();
|
||||
}
|
||||
|
||||
@DataSource("camline")
|
||||
@Transactional
|
||||
public float getPMPPBySubId(String subId){
|
||||
|
@ -195,5 +195,17 @@
|
||||
twpb.model = 2
|
||||
</select>
|
||||
|
||||
<select id="getTodayErrBoxNum" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from t_wo_packaging_box twpb
|
||||
where
|
||||
twpb.CREATE_TIME BETWEEN DATE_FORMAT(NOW(),'%Y-%m-%d 00:00:00') AND DATE_FORMAT(NOW(),'%Y-%m-%d 23:59:59')
|
||||
and
|
||||
twpb.model = 2
|
||||
and twpb.BOX_NO like '444%'
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
</mapper>
|
@ -6,7 +6,7 @@
|
||||
<id column="actl_pmpp_low" property="actlPmppLow" />
|
||||
<id column="actl_pmpp_high" property="actlPmppHigh" />
|
||||
<id column="formula" property="formula" />
|
||||
<id column="line_body" property="lineBody" />
|
||||
<id column="line_body" prope】/rty="lineBody" />
|
||||
<id column="coefficient_a" property="coefficientA" />
|
||||
<id column="coefficient_b" property="coefficientB" />
|
||||
<id column="remark" property="remark" />
|
||||
@ -43,7 +43,7 @@
|
||||
<if test="param.pmpp != null">
|
||||
and twcp.actl_pmpp_high <![CDATA[ > ]]> #{param.pmpp} and twcp.actl_pmpp_low <![CDATA[ <= ]]> #{param.pmpp}
|
||||
</if>
|
||||
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -40,6 +40,7 @@
|
||||
<if test="param.pmpp != null">
|
||||
and twpl.pmpp_high <![CDATA[ > ]]> #{param.pmpp} and twpl.pmpp_low <![CDATA[ <= ]]> #{param.pmpp}
|
||||
</if>
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -30,7 +30,7 @@ public enum S7Client {
|
||||
|
||||
//1线
|
||||
//S7_DDJ1("10.10.3.152",0,1,2),
|
||||
S7_DDJ1("10.10.3.152",0,1,2),
|
||||
S7_DDJ1("10.10.3.154",0,1,2),
|
||||
//2线
|
||||
S7_DDJ2("10.10.3.158",0,1,2),
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user