add:新增超威大屏接口。

This commit is contained in:
2024-10-22 21:14:32 +08:00
parent e008fcb93d
commit 517214a61a
22 changed files with 2312 additions and 9 deletions

View File

@@ -0,0 +1,67 @@
package org.nl.acs.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.nl.acs.utils.MapOf;
import java.util.Map;
/**
* acs状态枚举
*
* @author gbx
* @since 2024-01-31
*/
@AllArgsConstructor
@Getter
public enum AcsDefineEnum {
//agv状态 1-关机2-运行中3-交通管制4-任务等待5-充电中6-故障中7-低电量
AGV_STATUS(MapOf.of("关机", "1", "运行中", "2", "交通管制", "3", "任务等待", "4", "充电中", "5", "故障中", "6", "低电量", "7")),
//RGV状态 1-空闲 2-工作中 3-手动 4-下线
RGV_STATUS(MapOf.of("1","IDLE","2","WORK","3","UNAVAIL","4","OFFLINE")),
//载具类型
VEHICLE_TYPE(MapOf.of("普涂", "1", "连涂", "2")),
//是否
IS_USED(MapOf.of("启用", "1", "未启用", "0"));
private Map<String, String> code;
public String code(String desc) {
String code = this.getCode().get(desc);
if (StringUtils.isNotEmpty(code)) {
return code;
}
throw new RuntimeException(this.name() + "对应类型" + desc + "未定义");
}
public Long longCode(String desc) {
String code = this.getCode().get(desc);
if (StringUtils.isNotEmpty(code)) {
return Long.valueOf(code);
}
throw new RuntimeException(this.name() + "对应类型" + desc + "未定义");
}
public String check(String code) {
for (Map.Entry<String, String> entry : this.getCode().entrySet()) {
if (entry.getValue().equals(code)) {
return entry.getValue();
}
}
throw new RuntimeException(this.name() + "对应类型" + code + "未定义");
}
public String check1(String code) {
for (Map.Entry<String, String> entry : this.getCode().entrySet()) {
if (entry.getValue().equals(code)) {
return entry.getKey();
}
}
throw new RuntimeException(this.name() + "对应类型" + code + "未定义");
}
}

View File

@@ -0,0 +1,20 @@
package org.nl.acs.utils;
import java.io.Serializable;
import java.util.HashMap;
/*
* @author ZZQ
* @Date 2022/11/29 2:55 下午
*/
public class MapOf implements Serializable {
public static <K> HashMap of(K... key) {
HashMap map = new HashMap<>();
for (int i = 0; i < (key.length & ~1); i = i + 2) {
map.put(key[i], key[i + 1]);
}
return map;
}
}

View File

@@ -0,0 +1,289 @@
package org.nl.quartz.task;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.nl.acs.agv.server.ZheDaAgvService;
import org.nl.acs.device.domain.Device;
import org.nl.acs.device_driver.basedriver.cw_site.CwSiteDeviceDriver;
import org.nl.acs.device_driver.basedriver.standard_autodoor.StandardAutodoorDeviceDriver;
import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.opc.DeviceAppService;
import org.nl.common.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 自动同步设备状态
*/
@Slf4j
@Component
public class SyncDeviceStatus {
@Autowired
ZheDaAgvService agvService;
@Autowired
private RedisUtils redisUtils;
@Resource
private DeviceAppService deviceAppService;
@Resource
private InstructionService instructionService;
public void run() throws Exception {
device();
}
private void device() {
long startTime = System.currentTimeMillis();
try {
//总数
Integer a1_count = 0;
//正常运行
Long a1_item1 = 0L;
//暂未生产
Long a1_item2 = 0L;
//空闲设备
Long a1_item3 = 0L;
//故障设备
Long a1_item4 = 0L;
Integer a2_count = 0;
Long a2_item1 = 0L;
Long a2_item2 = 0L;
Long a2_item3 = 0L;
Long a2_item4 = 0L;
JSONArray tbxList1 = new JSONArray();
JSONArray tbxList2 = new JSONArray();
JSONArray ghsList1 = new JSONArray();
JSONArray ghsList2 = new JSONArray();
List<JSONObject> siteList = new ArrayList<>();
//JSONArray agvList = new JSONArray();
log.info("自动线程开始查询agv设备状态");
List<Device> deviceList = deviceAppService.findAllDevice();
for (Device device : deviceList) {
if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
if (StringUtils.isNotBlank(device.getOpc_server_id())) {
StandardInspectSiteDeviceDriver tbx = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
JSONObject json = new JSONObject();
json.put("device_code", tbx.getDeviceCode());
if (tbx.getError() == 0) {
//0脱机1故障2待机3运行中
//0无货3有货
getDeviceMode(tbx.getMode(), json);
} else {
json.put("mode", "1");
}
//区分车间
if (tbx.getDeviceCode().replaceAll("[^0-9]", "").startsWith("0")) {
json.put("workshop_code", "A1");
tbxList1.add(json);
} else {
json.put("workshop_code", "A2");
tbxList2.add(json);
}
}
} else if (device.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) {
if (StringUtils.isNotBlank(device.getOpc_server_id())) {
StandardAutodoorDeviceDriver ghs = (StandardAutodoorDeviceDriver) device.getDeviceDriver();
JSONObject json = new JSONObject();
json.put("device_code", ghs.getDeviceCode());
if (ghs.getError() == 0) {
//0脱机1故障2待机3运行中
getDeviceMode(ghs.getMode(), json);
//json.put("mode", ghs.getMode() == 0 ? "0" : "3");
} else {
json.put("mode", "1");
}
if (Integer.parseInt(ghs.getDeviceCode().replaceAll("[^0-9]", "")) < 11) {
json.put("workshop_code", "A1");
ghsList1.add(json);
} else {
json.put("workshop_code", "A2");
ghsList2.add(json);
}
}
} else if (device.getDeviceDriver() instanceof CwSiteDeviceDriver) {
if (StringUtils.isNotBlank(device.getOpc_server_id())) {
CwSiteDeviceDriver site = (CwSiteDeviceDriver) device.getDeviceDriver();
JSONObject json = new JSONObject();
json.put("device_code", site.getDeviceCode());
json.put("workshop_code", "A1");
if (site.getError() == 0) {
//0脱机1故障2待机3运行中
getDeviceMode(site.getMode(), json);
//json.put("mode", site.getMode() == 0 ? "0" : "3");
} else {
json.put("mode", "1");
}
siteList.add(json);
}
}
// else if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) {
// AgvNdcOneDeviceDriver agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver();
// JSONObject json = new JSONObject();
// json.put("device_code", device.getDevice_code());
// json.put("device_name", device.getDevice_name());
// json.put("device_status", agvNdcOneDeviceDriver.getStatus());
// json.put("energyLevel", agvNdcOneDeviceDriver.getElectric_qty());
// json.put("positionX", agvNdcOneDeviceDriver.getX());
// json.put("positionY", agvNdcOneDeviceDriver.getY());
// json.put("positionAngle", agvNdcOneDeviceDriver.getAngle());
// agvList.add(json);
// }
}
List<JSONObject> bpList = siteList.stream()
.filter(r -> r.getString("device_code").contains("BP"))
.collect(Collectors.toList());
redisUtils.set("tbxList1", tbxList1);
redisUtils.set("tbxList2", tbxList2);
redisUtils.set("ghsList1", ghsList1);
redisUtils.set("ghsList2", ghsList2);
redisUtils.set("bpjList", bpList);
tbxList1.addAll(ghsList1);
tbxList1.addAll(bpList);
JSONArray a1 = new JSONArray();
JSONArray a2 = new JSONArray();
getDeviceCountAndPercentage(tbxList1, a1);
tbxList2.addAll(ghsList2);
getDeviceCountAndPercentage(tbxList2, a2);
redisUtils.set("deviceA1", a1);
redisUtils.set("deviceA2", a2);
//正极板缓存区出库对接位,正极板空架回收对接位
List<JSONObject> zjbKjHswList = siteList.stream()
.filter(r -> r.getString("device_code").contains("ZJBHCQCKDJW") || r.getString("device_code").contains("ZJBKJHSDJW"))
.collect(Collectors.toList());
redisUtils.set("zjbKjHswList", zjbKjHswList);
//负极板空架对接位
List<JSONObject> fjbKjDjwList = siteList.stream()
.filter(r -> r.getString("device_code").contains("FJBKJDJW"))
.collect(Collectors.toList());
redisUtils.set("fjbKjDjwList", fjbKjDjwList);
//正极板对接位
List<JSONObject> zjbDjwList = siteList.stream()
.filter(r -> r.getString("device_code").contains("ZJBDJW"))
.collect(Collectors.toList());
redisUtils.set("zjbDjwList", zjbDjwList);
// if (ObjectUtil.isNotEmpty(agv)) {
// List<String> deviceCodes = agv.stream()
// .map(r -> {
// String deviceCode = ((JSONObject) r).getString("device_code");
// if (StringUtils.isNotBlank(deviceCode)) {
// return deviceCode.substring(deviceCode.length() - 1);
// } else {
// return null;
// }
// })
// .filter(Objects::nonNull)
// .collect(Collectors.toList());
// if (ObjectUtil.isNotEmpty(deviceCodes)) {
// List<InstructionMybatis> instructionList = instructionService.list(new LambdaQueryWrapper<InstructionMybatis>().in(InstructionMybatis::getCarno, deviceCodes).lt(InstructionMybatis::getInstruction_status, 2).eq(InstructionMybatis::getIs_delete, 0));
// if (ObjectUtil.isNotEmpty(instructionList)) {
// Map<String, String> taskCodeToTaskIdMap = instructionList.stream()
// .filter(instruction -> StringUtils.isNotBlank(instruction.getExt_task_id()))
// .collect(Collectors.toMap(
// InstructionMybatis::getInstruction_code,
// InstructionMybatis::getExt_task_id
// ));
// agv.forEach(r -> {
// JSONObject Item = (JSONObject) r;
// String taskId = taskCodeToTaskIdMap.get(Item.getString("task_code"));
// Item.put("task_id", "");
// if (StringUtils.isNotBlank(taskId)) {
// Item.put("task_id", taskId);
// }
// });
// }
// }
//
// }
//redisUtils.set("agvList", agvList);
log.trace("自动上报驱动状态,完毕耗时{}", System.currentTimeMillis() - startTime);
} catch (Exception e) {
//log.error("自动线程开始查询AGV设备自动上报驱动状态失败{}{}", e, e.getMessage());
}
}
private static void getDeviceCountAndPercentage(JSONArray deviceList, JSONArray result) {
Integer a1_count;
Long a1_item3;
Long a1_item1;
Long a1_item2;
Long a1_item4;
//0脱机1故障2待机3运行中
a1_count = deviceList.size();
JSONObject item1 = new JSONObject();
item1.put("count", a1_count);
result.add(item1);
a1_item1 = deviceList.stream()
.map(JSONObject.class::cast)
.filter(r -> "3".equals(r.getString("mode")))
.count();
JSONObject item2 = new JSONObject();
item2.put("count", a1_item1.toString());
item2.put("name", "正常运行");
// 计算百分比
double a1Item1Percentage = (double) a1_item1 / a1_count * 100;
String a1Item1Percentages = new DecimalFormat("0.00").format(a1Item1Percentage) + "%";
item2.put("percent", a1Item1Percentages);
result.add(item2);
a1_item2 = deviceList.stream()
.map(JSONObject.class::cast)
.filter(r -> "2".equals(r.getString("mode")))
.count();
JSONObject item3 = new JSONObject();
item3.put("count", a1_item2.toString());
item3.put("name", "暂未生产");
// 计算百分比
double a1Item2Percentage = (double) a1_item2 / a1_count * 100;
String a1Item2Percentages = new DecimalFormat("0.00").format(a1Item2Percentage) + "%";
item3.put("percent", a1Item2Percentages);
result.add(item3);
a1_item3 = deviceList.stream()
.map(JSONObject.class::cast)
.filter(r -> "0".equals(r.getString("mode")))
.count();
JSONObject item4 = new JSONObject();
item4.put("count", a1_item3.toString());
item4.put("name", "空闲设备");
// 计算百分比
double a1Item3Percentage = (double) a1_item3 / a1_count * 100;
String a1Item3Percentages = new DecimalFormat("0.00").format(a1Item3Percentage) + "%";
item4.put("percent", a1Item3Percentages);
result.add(item4);
a1_item4 = deviceList.stream()
.map(JSONObject.class::cast)
.filter(r -> "1".equals(r.getString("mode")))
.count();
JSONObject item5 = new JSONObject();
item5.put("count", a1_item4.toString());
item5.put("name", "故障设备");
// 计算百分比
double a1Item4Percentage = (double) a1_item4 / a1_count * 100;
String a1Item4Percentages = new DecimalFormat("0.00").format(a1Item4Percentage) + "%";
item5.put("percent", a1Item4Percentages);
result.add(item5);
}
private static void getDeviceMode(Integer mode, JSONObject json) {
if (mode == 0) {
json.put("mode", "0");
} else if (mode == 2) {
json.put("mode", "2");
} else {
json.put("mode", "3");
}
}
}

View File

@@ -7,10 +7,9 @@ spring:
db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
# url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:stand_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:cw_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.10.10}:${DB_PORT:3306}/${DB_NAME:cw_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&useOldAliasMetadataBehavior=true
username: ${DB_USER:root}
# password: ${DB_PWD:Root.123456}
password: ${DB_PWD:123456}
password: ${DB_PWD:123456789}
# 初始连接数
initial-size: 5
# 最小连接数
@@ -71,7 +70,7 @@ spring:
baseline-on-migrate: true
redis:
#数据库索引
database: ${REDIS_DB:2}
database: ${REDIS_DB:5}
host: ${REDIS_HOST:127.0.0.1}
port: ${REDIS_PORT:6379}
# password: ${REDIS_PWD:}
@@ -169,7 +168,7 @@ sa-token:
token-session-check-login: false
alone-redis:
# Redis数据库索引默认为0
database: 2
database: 5
# Redis服务器地址
host: 127.0.0.1
# Redis服务器连接端口