This commit is contained in:
psh
2023-08-18 15:37:12 +08:00
parent c8f2f0e19e
commit c4d496e1c6
12 changed files with 417 additions and 237 deletions

View File

@@ -10,6 +10,9 @@ import java.util.List;
@Component
public class ApplicationAutoInitialExecuter {
/**
* 获取所有实现ApplicationAutoInitial接口的bean对象
*/
@Autowired(required = false)
List<ApplicationAutoInitial> applicationAutoInitial;
//是否启动
@@ -25,7 +28,7 @@ public class ApplicationAutoInitialExecuter {
while (it.hasNext()) {
ApplicationAutoInitial service = (ApplicationAutoInitial) it.next();
service.autoInitial();
service.autoInitial(); // 执行实现的autoInitial方法
}

View File

@@ -13,15 +13,18 @@ import org.springframework.stereotype.Service;
import java.util.*;
/**
* 初始化启动线程
*/
@Service
@Slf4j
public class AutoRunServiceImpl implements AutoRunService, ApplicationAutoInitial {
@Autowired(required = false)
private List<AbstractAutoRunnable> abstractAutoRunnableList;
private List<String> autoRun_code_index = new ArrayList();
private List<Thread> threads = new ArrayList();
private List<AbstractAutoRunnable> thread_autoRun = new ArrayList();
private List<String> thread_code_index = new ArrayList();
private List<AbstractAutoRunnable> thread_autoRun = new ArrayList(); // 线程类
private List<String> autoRun_code_index = new ArrayList(); // key
private List<Thread> threads = new ArrayList(); // 运行线程
private List<String> thread_code_index = new ArrayList(); // key
@Override
public synchronized void startThread(String threadCode) {
@@ -172,8 +175,13 @@ public class AutoRunServiceImpl implements AutoRunService, ApplicationAutoInitia
: new LinkedList();
}
/**
* 自动初始化线程
* @throws Exception
*/
@Override
public void autoInitial() throws Exception {
// 获取所有的类型为AbstractAutoRunnable的bean
List<AbstractAutoRunnable> list = this.getAllAutoThread();
Iterator it = list.iterator();

View File

@@ -1776,6 +1776,9 @@ public class DeviceServiceImpl extends CommonServiceImpl<DeviceMapper, Device> i
this.reload();
}
/**
* 加载货位信息
*/
@Override
public void reload() {
this.storageCells = queryAllStorageCell();

View File

@@ -159,6 +159,9 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
}
}*/
/**
* 加载指令数据
*/
@Override
public void autoInitial() {
this.reload();

View File

@@ -20,8 +20,8 @@ import java.util.*;
@Slf4j
@Service
public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoInitial {
private List<Device> devices = new ArrayList();
private List<String> code_indexs = new ArrayList();
private List<Device> devices = new ArrayList(); // 所有设备链表
private List<String> code_indexs = new ArrayList(); // 设备对应的下表
@Autowired
private DeviceManageService deviceManageService;
@Autowired
@@ -315,7 +315,7 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn
}
public synchronized void reload() {
List<DeviceManageDto> deviceManageDtos = this.deviceManageService.queryAllWithExtra();
List<DeviceManageDto> deviceManageDtos = deviceManageService.queryAllWithExtra();
this.devices = new ArrayList();
Collections.synchronizedList(this.devices);
this.code_indexs = new ArrayList();

View File

@@ -42,13 +42,16 @@ public class DeviceManageServiceImpl implements DeviceManageService {
@Override
public List<DeviceManageDto> queryAllWithExtra() {
// JSONArray arr = WQLObject.getWQLObject("acs_device").query().getResultJSONArray(0);
// 获取所有的设备
List<Device> deviceList= new LambdaQueryChainWrapper<>(deviceMapper).list();
JSONArray arr = JSONArray.parseArray(JSON.toJSONString(deviceList));
// 获取列表扩展
// JSONArray extArr = WQLObject.getWQLObject("acs_device_extra").query().getResultJSONArray(0);
List<DeviceExtra> deviceExtraList= new LambdaQueryChainWrapper<>(deviceExtraMapper).list();
JSONArray extArr = JSONArray.parseArray(JSON.toJSONString(deviceExtraList));
// 设备+扩展DTO
List<DeviceExtraManageDto> extras = extArr.toJavaList(DeviceExtraManageDto.class);
// WQLObject runpointTab = WQLObject.getWQLObject("acs_device_runpoint");

View File

@@ -30,127 +30,131 @@ import java.util.Map;
@Service
public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoInitial {
private static final Logger log = LoggerFactory.getLogger(OpcServerServiceImpl.class);
@Autowired OpcServerManageService opcServerManageService;
Map<String, OpcServerManageDto> opcServerManageDtos = new HashMap();
Map<String, Server> servers = Collections.synchronizedMap(new HashMap());
Map<String, Group> groups = Collections.synchronizedMap(new HashMap());
private static final Logger log = LoggerFactory.getLogger(OpcServerServiceImpl.class);
@Autowired
OpcServerManageService opcServerManageService;
Map<String, OpcServerManageDto> opcServerManageDtos = new HashMap();
Map<String, Server> servers = Collections.synchronizedMap(new HashMap());
Map<String, Group> groups = Collections.synchronizedMap(new HashMap());
public OpcServerServiceImpl() {}
public void autoInitial() throws Exception {
this.reload();
if (OpcConfig.auto_start_opc) {
Thread t =
new Thread() {
public void run() {
Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator();
while (var1.hasNext()) {
OpcServerManageDto dto = (OpcServerManageDto) var1.next();
try {
OpcServerServiceImpl.this.getServer(dto.getOpc_code());
OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code());
} catch (Exception var4) {
OpcServerServiceImpl.log.warn("启动无法载入servers", var4);
}
}
}
};
t.start();
public OpcServerServiceImpl() {
}
}
public synchronized void reload() {
this.opcServerManageDtos = this.opcServerManageService.queryAllServerMap();
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
}
/**
* 加载opc服务启动opc线程
* @throws Exception
*/
public void autoInitial() throws Exception {
this.reload(); // 加载opc服务
if (OpcConfig.auto_start_opc) {
Thread t =
new Thread(() -> {
Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator();
public synchronized Group getServer(String code) {
Group group = null;
group = (Group) this.groups.get(code);
if (group != null) {
try {
if (group.isActive()) {
return group;
while (var1.hasNext()) {
OpcServerManageDto dto = (OpcServerManageDto) var1.next();
try {
OpcServerServiceImpl.this.getServer(dto.getOpc_code());
OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code());
} catch (Exception var4) {
OpcServerServiceImpl.log.warn("启动无法载入servers", var4);
}
}
});
t.start();
}
} catch (JIException var9) {
var9.printStackTrace();
}
}
Server server = (Server) this.servers.get(code);
boolean needcreate = false;
if (server == null) {
needcreate = true;
} else {
try {
group = server.findGroup(OpcConfig.opc_server_default_group);
} catch (UnknownHostException
| JIException
| UnknownGroupException
| NotConnectedException
| IllegalArgumentException var8) {
var8.printStackTrace();
needcreate = true;
}
public synchronized void reload() {
this.opcServerManageDtos = this.opcServerManageService.queryAllServerMap();
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
}
if (needcreate) {
OpcServerManageDto dto = (OpcServerManageDto) this.opcServerManageDtos.get(code);
if (dto == null) {
throw new BadRequestException("code 不存在");
}
public synchronized Group getServer(String code) {
Group group = null;
group = (Group) this.groups.get(code);
if (group != null) {
try {
if (group.isActive()) {
return group;
}
} catch (JIException var9) {
var9.printStackTrace();
}
}
server = OpcServerUtl.getServerWithOutException(
dto.getOpc_host(),
dto.getCls_id(),
dto.getUser(),
dto.getPassword(),
dto.getDomain());
Server server = (Server) this.servers.get(code);
boolean needcreate = false;
if (server == null) {
needcreate = true;
} else {
try {
group = server.findGroup(OpcConfig.opc_server_default_group);
} catch (UnknownHostException
| JIException
| UnknownGroupException
| NotConnectedException
| IllegalArgumentException var8) {
var8.printStackTrace();
needcreate = true;
}
}
if (needcreate) {
OpcServerManageDto dto = (OpcServerManageDto) this.opcServerManageDtos.get(code);
if (dto == null) {
throw new BadRequestException("code 不存在");
}
server = OpcServerUtl.getServerWithOutException(
dto.getOpc_host(),
dto.getCls_id(),
dto.getUser(),
dto.getPassword(),
dto.getDomain());
// server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
try {
group = server.addGroup(OpcConfig.opc_server_default_group);
} catch (Exception var7) {
throw new BadRequestException(var7.toString());
}
try {
group = server.addGroup(OpcConfig.opc_server_default_group);
} catch (Exception var7) {
throw new BadRequestException(var7.toString());
}
this.servers.put(code, server);
this.groups.put(code, group);
this.servers.put(code, server);
this.groups.put(code, group);
}
return group;
}
return group;
}
public synchronized void clearServer(String code) {
try {
Server server = (Server) this.servers.get(code);
if (server != null) {
server.disconnect();
}
public synchronized void clearServer(String code) {
try {
Server server = (Server) this.servers.get(code);
if (server!=null){
server.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
log.error("清理server异常,", e.getMessage());
}
} catch (Exception e) {
e.printStackTrace();
log.error("清理server异常,",e.getMessage());
this.servers.remove(code);
this.groups.remove(code);
}
this.servers.remove(code);
this.groups.remove(code);
}
public void writeInteger(String code, ItemValue... values) {
try {
Group group = this.getServer(code);
OpcUtl.writeValue(group, values);
} catch (Exception var4) {
this.clearServer(code);
log.warn("写入出错opc server {} 重新加载", code, var4);
ThreadUtl.sleep(5000L);
throw var4;
public void writeInteger(String code, ItemValue... values) {
try {
Group group = this.getServer(code);
OpcUtl.writeValue(group, values);
} catch (Exception var4) {
this.clearServer(code);
log.warn("写入出错opc server {} 重新加载", code, var4);
ThreadUtl.sleep(5000L);
throw var4;
}
}
}
}

View File

@@ -514,6 +514,10 @@ public class RouteLineServiceImpl extends CommonServiceImpl<RouteLineMapper, Rou
return false;
}
/**
* 加载路由路线
* @throws SQLException
*/
@Override
public void reload() throws SQLException {
Object[] param = new Object[0];

View File

@@ -246,6 +246,10 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
FileUtil.downloadExcel(list, response);
}*/
/**
* 获取未完成任务
* @throws Exception
*/
@Override
public void autoInitial() throws Exception {
Class var1 = TaskInstructionLock.class;