commit for pull

This commit is contained in:
caixiang 2023-02-22 20:48:15 +08:00
parent 4535677c93
commit 4d1a58b8c7
24 changed files with 1179 additions and 3 deletions

View File

@ -23,9 +23,19 @@
<artifactId>ym-common</artifactId> <artifactId>ym-common</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>com.cnbm</groupId>-->
<!-- <artifactId>ym-core</artifactId>-->
<!-- <version>1.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>com.cnbm</groupId> <groupId>com.cnbm</groupId>
<artifactId>ym-core</artifactId> <artifactId>ym-s7</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cnbm</groupId>
<artifactId>ym-dynamic-datasource</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -0,0 +1,351 @@
package com.cnbm.packing.dispatch;
import cn.hutool.core.util.RandomUtil;
import com.cnbm.packing.dispatch.enums.kuka.step1.Step1Mes2PlcVar;
import com.cnbm.packing.dispatch.enums.kuka.step1.Step1Plc2MesVar;
import com.cnbm.packing.dispatch.enums.kuka.step2.Step2Mes2PlcVar;
import com.cnbm.packing.dispatch.enums.kuka.step2.Step2Plc2MesVar;
import com.cnbm.packing.dispatch.enums.kuka.step3.Step3Mes2PlcVar;
import com.cnbm.packing.dispatch.enums.kuka.step3.Step3Plc2MesVar;
import com.cnbm.packing.dto.WoPowerLevelDTO;
import com.cnbm.packing.entity.WoPackagingBoxSubstrate;
import com.cnbm.packing.entity.WoPowerLevel;
import com.cnbm.packing.service.DynamicDataSourceService;
import com.cnbm.packing.service.WoCompensationPowerServiceBiz;
import com.cnbm.packing.service.WoPackagingBoxSubstrateServiceBiz;
import com.cnbm.packing.service.WoPowerLevelServiceBiz;
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.time.LocalDateTime;
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 KukaJoinThread implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger(KukaJoinThread.class);
@Autowired
DynamicDataSourceService service;
@Autowired
WoPowerLevelServiceBiz levelServiceBiz;
@Autowired
WoCompensationPowerServiceBiz compensationPowerServiceBiz;
@Autowired
WoPackagingBoxSubstrateServiceBiz substrateServiceBiz;
public KukaJoinThread(){
this.kukaStep1 = Executors.newScheduledThreadPool(1);
this.kukaStep2 = Executors.newScheduledThreadPool(1);
this.kukaStep3 = Executors.newScheduledThreadPool(1);
}
private ScheduledExecutorService kukaStep1;
private ScheduledExecutorService kukaStep2;
private ScheduledExecutorService kukaStep3;
/**
* return
* 成功 返回相应的object对象
* 失败 返回null
* */
private Object read(S7Client s7Client,Step1Plc2MesVar var) {
try {
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
}catch (Exception e){
logger.error("host:"+s7Client.getHost()+" ; read 操作出现问题: "+e.getMessage());
e.printStackTrace();
return null;
}
}
private void write(S7Client s7Client, Step1Mes2PlcVar 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 (Exception e){
logger.error("host:"+s7Client.getHost()+" ; read 操作出现问题: "+e.getMessage());
e.printStackTrace();
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 (Exception e){
logger.error("host:"+s7Client.getHost()+" ; read 操作出现问题: "+e.getMessage());
e.printStackTrace();
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);
}
}
@Override
public void run(ApplicationArguments args) throws Exception {
kukaStep1.execute(new Runnable() {
@Override
public void run() {
while (true){
//read one
// logger.info("过程一 : "+ Arrays.toString((String[])read(S7Client.S7_1500,PlcVarActual.SubIdArrays)));
// try {
// Thread.sleep(300);
// } catch (InterruptedException e) {
// throw new S7ParseDataException(e);
// }
// //write one
// String[] toWrite = new String[60];
// for(int i=0;i<60;i++){
// toWrite[i] = RandomStringUtils.randomAlphanumeric(18);
// }
// try {
// write(S7Client.S7_1500,PlcVarActual.SubIdArrays,toWrite);
// } catch (Exception e) {
// throw new S7ParseDataException(e);
// }
}
}
});
kukaStep1.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
//调度开始
logger.info("");
logger.info("================= 现在开始执行 过程一 任务 ==================");
Integer subArrived = waitingForTarget(Step1Plc2MesVar.SubArrivedToMes, true);
if(subArrived != 1){
logger.info("失败"+" --- "+"步骤1. MES监听 Step1Plc2MesVar.SubArrivedToMes 是否 等于 1 失败");
}
//1. 从plc 中获取 subId lineNum
String subId = (String) read(S7Client.S7_KUKA,Step1Plc2MesVar.SubIdToMes);
Integer lineNum = (Integer) read(S7Client.S7_KUKA,Step1Plc2MesVar.LineNum);
//2. 从comline数据库中获取 实际pmpp
float pmppBySubId = service.getPMPPBySubId(subId);
//3. 匹配和计算补偿功率
float actualPMPP = compensationPowerServiceBiz.calculCompensationPMPP(pmppBySubId,lineNum);
//4. 依据补偿功率获取工艺参数并且把这些工艺参数传给kuka
WoPowerLevel argByPMPP = levelServiceBiz.getArgByPMPP(actualPMPP, lineNum);
write(S7Client.S7_KUKA,Step1Mes2PlcVar.dLable_Pnom,argByPMPP.getPowerClass());
write(S7Client.S7_KUKA,Step1Mes2PlcVar.dLable_Voc,argByPMPP.getLableVoc());
write(S7Client.S7_KUKA,Step1Mes2PlcVar.dLable_Isc,argByPMPP.getLableIsc());
write(S7Client.S7_KUKA,Step1Mes2PlcVar.dLable_Vmpp,argByPMPP.getLableVmpp());
write(S7Client.S7_KUKA,Step1Mes2PlcVar.dLable_Impp,argByPMPP.getLableImpp());
//5. 把基板录到数据库
WoPackagingBoxSubstrate woPackagingBoxSubstrate = new WoPackagingBoxSubstrate();
woPackagingBoxSubstrate.setLineBody(1);
woPackagingBoxSubstrate.setPowerLevel(argByPMPP.getPowerClass().toString());
woPackagingBoxSubstrate.setSapMaterial(argByPMPP.getSapMaterialNum());
woPackagingBoxSubstrate.setWoSubstrateId("sub123");
substrateServiceBiz.insert(woPackagingBoxSubstrate);
}
},1,1, TimeUnit.SECONDS);
kukaStep2.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
String s = RandomUtil.randomString(5);
System.out.println("start + "+s+" : "+LocalDateTime.now());
Thread.sleep(3000);
//写业务代码
WoPowerLevel argByPMPP = levelServiceBiz.getArgByPMPP(2.1111f, 1);
WoPackagingBoxSubstrate woPackagingBoxSubstrate = new WoPackagingBoxSubstrate();
woPackagingBoxSubstrate.setLineBody(1);
woPackagingBoxSubstrate.setPowerLevel(argByPMPP.getPowerClass().toString());
woPackagingBoxSubstrate.setSapMaterial(argByPMPP.getSapMaterialNum());
woPackagingBoxSubstrate.setWoSubstrateId("sub123");
substrateServiceBiz.insert(woPackagingBoxSubstrate);
System.err.println(argByPMPP.toString());
// service.salve3Get();
System.out.println("end "+ s +" : "+ LocalDateTime.now());
}catch (Throwable e){
//Error Exception 都继承于Throwable ,所以当业务代码出现Error/Exception 都不会导致程序down掉
e.printStackTrace();
}
}
},1,1, TimeUnit.SECONDS);
kukaStep3.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
String s = RandomUtil.randomString(5);
System.out.println("start + "+s+" : "+LocalDateTime.now());
Thread.sleep(3000);
//写业务代码
service.salve1Get();
// service.salve3Get();
System.out.println("end "+ s +" : "+ LocalDateTime.now());
}catch (Throwable e){
//Error Exception 都继承于Throwable ,所以当业务代码出现Error/Exception 都不会导致程序down掉
e.printStackTrace();
}
}
},1,1, TimeUnit.SECONDS);
}
/**
*
* arg:
* Step1Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step1Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_KUKA,var);
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Exception e){
logger.info("S7 数据采集 异常。");
res = 2;
break;
}
}
return res;
}
/**
*
* arg:
* Step2Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step2Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_KUKA,var);
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Exception e){
logger.info("S7 数据采集 异常。");
res = 2;
break;
}
}
return res;
}
/**
*
* arg:
* Step3Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step3Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_KUKA,var);
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Exception e){
logger.info("S7 数据采集 异常。");
res = 2;
break;
}
}
return res;
}
}

View File

@ -0,0 +1,15 @@
package com.cnbm.packing.dispatch.enums;
/**
* @Author: 蔡翔
* @Date: 2019/10/14 10:07
* @Version 1.0
*/
public interface CodeEnum {
Integer getNamespace();
String getIdentity();
String getType();
String getName();
String getDesc();
void set(String name,Integer nameSpace,String identity);
}

View File

@ -0,0 +1,93 @@
package com.cnbm.packing.dispatch.enums.kuka.step1;
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 Step1Mes2PlcVar {
SubArrivedFinish("SubArrivedFinish", PlcVar.BOOL,1, DaveArea.DB,2000,26,0),
dLable_Pnom("dLable_Pnom", PlcVar.DINT,1, DaveArea.DB,2000,28,0),
dLable_Voc("dLable_Voc", PlcVar.REAL,1, DaveArea.DB,2000,32,0),
dLable_Isc("dLable_Isc", PlcVar.REAL,1, DaveArea.DB,2000,36,0),
dLable_Vmpp("dLable_Vmpp", PlcVar.REAL,1, DaveArea.DB,2000,40,0),
dLable_Impp("dLable_Vmpp", PlcVar.REAL,1, DaveArea.DB,2000,44,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;
Step1Mes2PlcVar(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;
}
Step1Mes2PlcVar(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;
}
}

View File

@ -0,0 +1,89 @@
package com.cnbm.packing.dispatch.enums.kuka.step1;
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 Step1Plc2MesVar {
SubArrivedToMes("SubArrivedToMes", PlcVar.BOOL,1, DaveArea.DB,2000,0,0),
SubIdToMes("SubIdToMes",PlcVar.STRING,1,DaveArea.DB,2000,2,0,20),
LineNum("LineNum", PlcVar.UINT,1, DaveArea.DB,2000,24,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;
Step1Plc2MesVar(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;
}
Step1Plc2MesVar(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;
}
}

View File

@ -0,0 +1,88 @@
package com.cnbm.packing.dispatch.enums.kuka.step2;
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 Step2Mes2PlcVar {
//心跳变量这个可以要求电控同事加一个不和业务关联只用于通讯
BoxId("BoxId",PlcVar.STRING,1,DaveArea.DB,2000,714,0,20),
ShelfIsFullFinish("ShelfIsFullFinish",PlcVar.BOOL,1,DaveArea.DB,2000,712,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;
Step2Mes2PlcVar(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;
}
Step2Mes2PlcVar(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;
}
}

View File

@ -0,0 +1,89 @@
package com.cnbm.packing.dispatch.enums.kuka.step2;
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 Step2Plc2MesVar {
//心跳变量这个可以要求电控同事加一个不和业务关联只用于通讯
ShelfIsFull("ShelfIsFull", PlcVar.BOOL,1, DaveArea.DB,2000,48,0),
SubIdList("SubIdList",PlcVar.STRING_Array,30,DaveArea.DB,2000,50,0,20),
LineNum("LineNum", PlcVar.BOOL,1, DaveArea.DB,2000,710,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;
Step2Plc2MesVar(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;
}
Step2Plc2MesVar(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;
}
}

View File

@ -0,0 +1,87 @@
package com.cnbm.packing.dispatch.enums.kuka.step3;
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 Step3Mes2PlcVar {
//心跳变量这个可以要求电控同事加一个不和业务关联只用于通讯
ShelfIsFullArrivedFinish("ShelfIsFullArrivedFinish", PlcVar.BOOL,1, DaveArea.DB,2000,762,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;
Step3Mes2PlcVar(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;
}
Step3Mes2PlcVar(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;
}
}

View File

@ -0,0 +1,90 @@
package com.cnbm.packing.dispatch.enums.kuka.step3;
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 Step3Plc2MesVar {
//心跳变量这个可以要求电控同事加一个不和业务关联只用于通讯
ShelfIsFullArrived("ShelfIsFullArrived", PlcVar.BOOL,1, DaveArea.DB,2000,736,0),
BoxId("BoxId",PlcVar.STRING,60,DaveArea.DB,2000,738,0,20),
LineNum("LineNum", PlcVar.UINT,1, DaveArea.DB,2000,760,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;
Step3Plc2MesVar(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;
}
Step3Plc2MesVar(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;
}
}

View File

@ -0,0 +1,21 @@
package com.cnbm.packing.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/22 16:48
*/
@Data
@ApiModel(value = "补偿功率 计算系数")
public class CompensationPowerXSDTO implements Serializable {
private static final long serialVersionUID = 1L;
private float a;
private float b;
}

View File

@ -0,0 +1,26 @@
package com.cnbm.packing.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 机台表
*
* @author codeGenerator
* @since 2023-02-15
*/
@Mapper
public interface CamlineMapper {
float getByid(@Param("subId") String subId);
//从camline 系统获取实际pmpp
float getPMPPBySubId(@Param("subId") String subId);
String getOrderNameBySubId(@Param("subId") String subId);
Integer getTodayBoxNum();
}

View File

@ -1,9 +1,12 @@
package com.cnbm.packing.mapper; package com.cnbm.packing.mapper;
import com.cnbm.common.dao.BaseDao; import com.cnbm.common.dao.BaseDao;
import com.cnbm.packing.dto.CompensationPowerXSDTO;
import com.cnbm.packing.dto.WoCompensationPowerDTO; import com.cnbm.packing.dto.WoCompensationPowerDTO;
import com.cnbm.packing.entity.WoCompensationPower; import com.cnbm.packing.entity.WoCompensationPower;
import com.cnbm.packing.param.CompensationQueryParam;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -17,5 +20,6 @@ import java.util.List;
public interface WoCompensationPowerMapper extends BaseDao<WoCompensationPower> { public interface WoCompensationPowerMapper extends BaseDao<WoCompensationPower> {
List<WoCompensationPowerDTO> list(); List<WoCompensationPowerDTO> list();
CompensationPowerXSDTO getConffBySubIdAndLineBody(@Param("param") CompensationQueryParam param);
} }

View File

@ -1,9 +1,12 @@
package com.cnbm.packing.mapper; package com.cnbm.packing.mapper;
import com.cnbm.common.dao.BaseDao; import com.cnbm.common.dao.BaseDao;
import com.cnbm.packing.dto.CompensationPowerXSDTO;
import com.cnbm.packing.dto.WoPowerLevelDTO; import com.cnbm.packing.dto.WoPowerLevelDTO;
import com.cnbm.packing.entity.WoPowerLevel; import com.cnbm.packing.entity.WoPowerLevel;
import com.cnbm.packing.param.CompensationQueryParam;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -18,4 +21,7 @@ public interface WoPowerLevelMapper extends BaseDao<WoPowerLevel> {
List<WoPowerLevelDTO> list(); List<WoPowerLevelDTO> list();
WoPowerLevel getPowerLevelByLineBodyAndPMPP(@Param("param") CompensationQueryParam param);
} }

View File

@ -0,0 +1,16 @@
package com.cnbm.packing.param;
import io.swagger.models.auth.In;
import lombok.Data;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/15 19:05
*/
@Data
public class CompensationQueryParam {
private float pmpp;
private Integer lineBody;
}

View File

@ -0,0 +1,50 @@
package com.cnbm.packing.service;
import com.cnbm.dynamic.datasource.annotation.DataSource;
import com.cnbm.packing.dto.WoPowerLevelDTO;
import com.cnbm.packing.mapper.CamlineMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/15 14:19
*/
@Service
public class DynamicDataSourceService {
@Autowired
CamlineMapper mapper;
@Autowired
WoPowerLevelServiceBiz powerLevelServiceBiz;
@Transactional
@DataSource("slave1")
public void salve1Get(){
WoPowerLevelDTO woPowerLevelDTO = powerLevelServiceBiz.get(Long.valueOf(1));
System.out.println(woPowerLevelDTO.toString());
}
public void getTodayBoxNum(){
Integer todayBoxNum = mapper.getTodayBoxNum();
System.out.println(todayBoxNum);
}
public float getPMPPBySubId(String subId){
return mapper.getPMPPBySubId(subId);
}
@DataSource("slave2")
@Transactional
public void salve3Get(){
float byid = mapper.getByid("LTWeight");
System.out.println(byid);
}
}

View File

@ -2,6 +2,7 @@ package com.cnbm.packing.service;
import com.cnbm.common.page.PageData; import com.cnbm.common.page.PageData;
import com.cnbm.common.service.CrudService; import com.cnbm.common.service.CrudService;
import com.cnbm.packing.dto.CompensationPowerXSDTO;
import com.cnbm.packing.dto.WoCompensationPowerDTO; import com.cnbm.packing.dto.WoCompensationPowerDTO;
import com.cnbm.packing.entity.WoCompensationPower; import com.cnbm.packing.entity.WoCompensationPower;
@ -16,6 +17,7 @@ import java.util.Map;
*/ */
public interface WoCompensationPowerServiceBiz extends CrudService<WoCompensationPower, WoCompensationPowerDTO> { public interface WoCompensationPowerServiceBiz extends CrudService<WoCompensationPower, WoCompensationPowerDTO> {
PageData<WoCompensationPowerDTO> page (Map<String, Object> params); PageData<WoCompensationPowerDTO> page (Map<String, Object> params);
WoCompensationPowerDTO get(Long id); WoCompensationPowerDTO get(Long id);
@ -27,5 +29,7 @@ public interface WoCompensationPowerServiceBiz extends CrudService<WoCompensatio
void delete(Long[] ids); void delete(Long[] ids);
List<WoCompensationPowerDTO> list(); List<WoCompensationPowerDTO> list();
float calculCompensationPMPP(float pmpp, Integer lineBody);
} }

View File

@ -27,5 +27,6 @@ public interface WoPowerLevelServiceBiz extends CrudService<WoPowerLevel, WoPowe
void delete(Long[] ids); void delete(Long[] ids);
List<WoPowerLevelDTO> list(); List<WoPowerLevelDTO> list();
WoPowerLevel getArgByPMPP(float pmpp, Integer lineBody);
} }

View File

@ -6,11 +6,14 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.cnbm.common.page.PageData; import com.cnbm.common.page.PageData;
import com.cnbm.common.service.impl.CrudServiceImpl; import com.cnbm.common.service.impl.CrudServiceImpl;
import com.cnbm.common.utils.ConvertUtils; import com.cnbm.common.utils.ConvertUtils;
import com.cnbm.packing.dto.CompensationPowerXSDTO;
import com.cnbm.packing.dto.WoCompensationPowerDTO; import com.cnbm.packing.dto.WoCompensationPowerDTO;
import com.cnbm.packing.entity.WoCompensationPower; import com.cnbm.packing.entity.WoCompensationPower;
import com.cnbm.packing.entity.WoPowerLevel; import com.cnbm.packing.entity.WoPowerLevel;
import com.cnbm.packing.mapper.WoCompensationPowerMapper; import com.cnbm.packing.mapper.WoCompensationPowerMapper;
import com.cnbm.packing.param.CompensationQueryParam;
import com.cnbm.packing.service.WoCompensationPowerServiceBiz; import com.cnbm.packing.service.WoCompensationPowerServiceBiz;
import lombok.var;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -86,5 +89,21 @@ public class WoCompensationPowerServiceBizImpl extends CrudServiceImpl<WoCompens
List<WoCompensationPowerDTO> list = mapper.list(); List<WoCompensationPowerDTO> list = mapper.list();
return list; return list;
} }
@Override
public float calculCompensationPMPP(float pmpp, Integer lineBody) {
CompensationQueryParam compensationQueryParam = new CompensationQueryParam();
compensationQueryParam.setPmpp(pmpp);
compensationQueryParam.setLineBody(lineBody);
CompensationPowerXSDTO conffBySubIdAndLineBody = mapper.getConffBySubIdAndLineBody(compensationQueryParam);
float res = pmpp*conffBySubIdAndLineBody.getA()+conffBySubIdAndLineBody.getB();
return res;
}
public WoCompensationPowerMapper getMapper() {
return mapper;
}
} }

View File

@ -9,6 +9,7 @@ import com.cnbm.common.utils.ConvertUtils;
import com.cnbm.packing.dto.WoPowerLevelDTO; import com.cnbm.packing.dto.WoPowerLevelDTO;
import com.cnbm.packing.entity.WoPowerLevel; import com.cnbm.packing.entity.WoPowerLevel;
import com.cnbm.packing.mapper.WoPowerLevelMapper; import com.cnbm.packing.mapper.WoPowerLevelMapper;
import com.cnbm.packing.param.CompensationQueryParam;
import com.cnbm.packing.service.WoPowerLevelServiceBiz; import com.cnbm.packing.service.WoPowerLevelServiceBiz;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -87,4 +88,11 @@ public class WoPowerLevelServiceBizImpl extends CrudServiceImpl<WoPowerLevelMapp
return list; return list;
} }
@Override
public WoPowerLevel getArgByPMPP(float pmpp, Integer lineBody) {
CompensationQueryParam compensationQueryParam = new CompensationQueryParam();
compensationQueryParam.setLineBody(lineBody);
compensationQueryParam.setPmpp(pmpp);
return mapper.getPowerLevelByLineBodyAndPMPP(compensationQueryParam);
}
} }

View File

@ -0,0 +1,17 @@
package com.cnbm.packing.vo;
import lombok.Data;
import java.time.LocalDateTime;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/15 16:32
*/
@Data
public class ComlinePMPP {
private String machineName;
private Long platformId;
private LocalDateTime createTime;
}

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cnbm.packing.mapper.CamlineMapper">
<resultMap id="ResultMap" type="com.cnbm.packing.vo.ComlinePMPP">
<result column="machine_name" property="machineName" />
<result column="platform_id" property="platformId" />
<result column="create_time" property="createTime" />
</resultMap>
<select id="getByid" resultType="float">
select pd.pmpp from process_data pd
where pd.arg_name = #{subId}
ORDER BY
pd.create_time DESC
LIMIT 1
</select>
<select id="getPMPPBySubId" resultType="float">
SELECT
-- tu.`NAME`,-- DMC就是基板ID/模组ID
-- flr.LAST_UPDATE_TIME,
flr.PMPP_FL2
FROM
ue_flasher_data_raw flr
LEFT JOIN e_tracking_unit tu ON flc.mainid = tu.id
WHERE
flr.PMPP != 0
and
tu.name=#{subId} -- 查特定基板功率
ORDER BY
flc.LAST_UPDATE_TIME DESC
LIMIT 1
</select>
<select id="getOrderNameBySubId" resultType="string">
SELECT
eorder.name
FROM
e_tracking_unit tu
LEFT JOIN er_order eorder ON tu.order_id = eorder.id
WHERE
tu.name=#{subId} -- 依据基板id 查询对应的订单名
ORDER BY
tu.LAST_UPDATE_TIME DESC
LIMIT 1
</select>
<select id="getTodayBoxNum" 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')
</select>
</mapper>

View File

@ -19,10 +19,31 @@
<id column="update_time" property="updateTime" /> <id column="update_time" property="updateTime" />
<id column="version" property="version" /> <id column="version" property="version" />
</resultMap> </resultMap>
<resultMap id="ResultMap" type="com.cnbm.packing.dto.CompensationPowerXSDTO">
<result column="a" property="a" />
<result column="b" property="b" />
</resultMap>
<select id="list" resultType="com.cnbm.packing.dto.WoCompensationPowerDTO"> <select id="list" resultType="com.cnbm.packing.dto.WoCompensationPowerDTO">
select * from t_wo_compensation_power select * from t_wo_compensation_power
order by id asc order by id asc
</select> </select>
<select id="getConffBySubIdAndLineBody" resultMap="ResultMap">
select
twcp.coefficient_a as a,twcp.coefficient_b as b
from t_wo_compensation_power twcp
where
twcp.valid = 1
<if test="param.lineBody != null">
and twcp.line_body = #{param.lineBody}
</if>
<if test="param.pmpp != null">
and twcp.actl_pmpp_high <![CDATA[ >= ]]> #{param.pmpp} and twcp.actl_pmpp_low <![CDATA[ <= ]]> #{param.pmpp}
</if>
</select>
</mapper> </mapper>

View File

@ -28,4 +28,18 @@
order by id asc order by id asc
</select> </select>
<select id="getPowerLevelByLineBodyAndPMPP" resultMap="WoPowerLevelMap">
select
*
from t_wo_power_level twpl
where
twpl.valid = 1
<if test="param.lineBody != null">
and twpl.line_body = #{param.lineBody}
</if>
<if test="param.pmpp != null">
and twpl.pmpp_high <![CDATA[ >= ]]> #{param.pmpp} and twpl.pmpp_low <![CDATA[ <= ]]> #{param.pmpp}
</if>
</select>
</mapper> </mapper>

View File

@ -27,6 +27,7 @@ public enum S7Client {
// S7_1200("192.168.0.52",0,1,1,PlcVarActual.HeartBeatFor1200), // S7_1200("192.168.0.52",0,1,1,PlcVarActual.HeartBeatFor1200),
S7_15001("192.168.0.51",0,1,1), S7_15001("192.168.0.51",0,1,1),
S7_1500("192.168.0.51",0,1,1), S7_1500("192.168.0.51",0,1,1),
S7_KUKA("192.168.0.51",0,1,2),
//1500 机架-0 插槽-1 //1500 机架-0 插槽-1
//后续 在这里扩展 多PLC应用 //后续 在这里扩展 多PLC应用
; ;