同步
This commit is contained in:
@@ -10,9 +10,6 @@ import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ApplicationAutoInitialExecuter {
|
||||
/**
|
||||
* 获取所有实现ApplicationAutoInitial接口的bean对象
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
List<ApplicationAutoInitial> applicationAutoInitial;
|
||||
//是否启动
|
||||
@@ -28,7 +25,7 @@ public class ApplicationAutoInitialExecuter {
|
||||
|
||||
while (it.hasNext()) {
|
||||
ApplicationAutoInitial service = (ApplicationAutoInitial) it.next();
|
||||
service.autoInitial(); // 执行实现的autoInitial方法
|
||||
service.autoInitial();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,18 +13,15 @@ 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<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
|
||||
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();
|
||||
|
||||
@Override
|
||||
public synchronized void startThread(String threadCode) {
|
||||
@@ -175,13 +172,8 @@ 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();
|
||||
|
||||
|
||||
@@ -1776,9 +1776,6 @@ public class DeviceServiceImpl extends CommonServiceImpl<DeviceMapper, Device> i
|
||||
this.reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载货位信息
|
||||
*/
|
||||
@Override
|
||||
public void reload() {
|
||||
this.storageCells = queryAllStorageCell();
|
||||
|
||||
@@ -10,9 +10,11 @@ import java.util.List;
|
||||
public class ItemProtocol {
|
||||
public static String item_heartbeat = "heartbeat";
|
||||
public static String item_mode = "mode";
|
||||
public static String item_state = "state";
|
||||
public static String item_action = "action";
|
||||
public static String item_error = "error";
|
||||
public static String item_to_command = "to_command";
|
||||
public static String item_to_state ="to_state";
|
||||
|
||||
|
||||
private StandardAutodoorDeviceDriver driver;
|
||||
@@ -41,6 +43,10 @@ public class ItemProtocol {
|
||||
return this.getOpcIntegerValue(item_to_command);
|
||||
}
|
||||
|
||||
public int getToState() {
|
||||
return this.getOpcIntegerValue(item_to_state);
|
||||
}
|
||||
|
||||
|
||||
public int getOpcIntegerValue(String protocol) {
|
||||
Integer value = this.driver.getIntegeregerValue(protocol);
|
||||
@@ -55,16 +61,18 @@ public class ItemProtocol {
|
||||
|
||||
public static List<ItemDto> getReadableItemDtos() {
|
||||
ArrayList list = new ArrayList();
|
||||
list.add(new ItemDto(item_heartbeat, "心跳", "DB51.B0"));
|
||||
list.add(new ItemDto(item_mode, "工作状态", "DB51.B1", Boolean.valueOf(true)));
|
||||
list.add(new ItemDto(item_action, "动作信号", "DB51.B2"));
|
||||
list.add(new ItemDto(item_error, "报警信号", "DB51.B4"));
|
||||
list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0"));
|
||||
list.add(new ItemDto(item_mode, "工作模式", "DB600.B1", Boolean.valueOf(true)));
|
||||
list.add(new ItemDto(item_state, "工作状态", "DB600.B2"));
|
||||
list.add(new ItemDto(item_action, "动作信号", "DB600.B3"));
|
||||
list.add(new ItemDto(item_error, "报警信号", "DB600.B4"));
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<ItemDto> getWriteableItemDtos() {
|
||||
ArrayList list = new ArrayList();
|
||||
list.add(new ItemDto(item_to_command, "作业命令", "DB52.W2", Boolean.valueOf(true)));
|
||||
list.add(new ItemDto(item_to_command, "作业命令", "DB601.W2", Boolean.valueOf(true)));
|
||||
list.add(new ItemDto(item_to_state, "下发状态", "DB601.W3", Boolean.valueOf(true)));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ public class StandardAutodoorDeviceDriver extends AbstractOpcDeviceDriver implem
|
||||
|
||||
int move = 0;
|
||||
int task = 0;
|
||||
int state = 0;
|
||||
int last_state = 0;
|
||||
int last_action = 0;
|
||||
int last_mode = 0;
|
||||
int last_error = 0;
|
||||
@@ -135,9 +137,8 @@ public class StandardAutodoorDeviceDriver extends AbstractOpcDeviceDriver implem
|
||||
}
|
||||
|
||||
|
||||
public void writeing(int command) {
|
||||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||
+ "." + ItemProtocol.item_to_command;
|
||||
public void writing(String param,int command) {
|
||||
String to_command = String.format("%s.%s.%s.%s", this.getDevice().getOpc_server_code(), this.getDevice().getOpc_plc_code(), this.getDevice().getDevice_code(), param);
|
||||
|
||||
String opcservcerid = this.getDevice().getOpc_server_id();
|
||||
Server server = ReadUtil.getServer(opcservcerid);
|
||||
@@ -153,9 +154,9 @@ public class StandardAutodoorDeviceDriver extends AbstractOpcDeviceDriver implem
|
||||
|
||||
//开门
|
||||
if ("1".equals(type)) {
|
||||
writeing(1);
|
||||
writing(ItemProtocol.item_to_command,1);
|
||||
} else {
|
||||
writeing(2);
|
||||
writing(ItemProtocol.item_to_command,2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,12 +15,15 @@ public class ItemProtocol {
|
||||
public static String item_mode = "mode";
|
||||
public static String item_move = "move";
|
||||
public static String item_action = "action";
|
||||
public static String item_io_action = "io_action";
|
||||
public static String item_error = "error";
|
||||
public static String item_task = "task";
|
||||
public static String item_to_command = "to_command";
|
||||
public static String item_to_target = "to_target";
|
||||
public static String item_to_task = "to_task";
|
||||
public static String item_weight = "weight";
|
||||
public static String item_material_type = "material_type";
|
||||
public static String item_barcode = "barcode";
|
||||
|
||||
private StandardInspectSiteDeviceDriver driver;
|
||||
|
||||
@@ -44,6 +47,10 @@ public class ItemProtocol {
|
||||
return this.getOpcIntegerValue(item_action);
|
||||
}
|
||||
|
||||
public int getIoAction() {
|
||||
return this.getOpcIntegerValue(item_io_action);
|
||||
}
|
||||
|
||||
public int getError() {
|
||||
return this.getOpcIntegerValue(item_error);
|
||||
}
|
||||
@@ -52,6 +59,13 @@ public class ItemProtocol {
|
||||
return this.getOpcIntegerValue(item_task);
|
||||
}
|
||||
|
||||
public int getMaterialType() {
|
||||
return this.getOpcIntegerValue(item_material_type);
|
||||
}
|
||||
public int getBarcode() {
|
||||
return this.getOpcIntegerValue(item_barcode);
|
||||
}
|
||||
|
||||
public int getToCommand() {
|
||||
return this.getOpcIntegerValue(item_to_command);
|
||||
}
|
||||
@@ -87,11 +101,14 @@ public class ItemProtocol {
|
||||
public static List<ItemDto> getReadableItemDtos() {
|
||||
ArrayList list = new ArrayList();
|
||||
list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0"));
|
||||
list.add(new ItemDto(item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true)));
|
||||
list.add(new ItemDto(item_move, "光电开关信号", "DB600.B2"));
|
||||
list.add(new ItemDto(item_move, "动作信号", "DB600.B3"));
|
||||
list.add(new ItemDto(item_error, "报警信号", "DB600.B6"));
|
||||
list.add(new ItemDto(item_task, "任务号", "DB600.D8"));
|
||||
list.add(new ItemDto(item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true)));
|
||||
list.add(new ItemDto(item_move, "光电开关信号", "DB600.B3"));
|
||||
list.add(new ItemDto(item_action, "取放信号", "DB600.B4"));
|
||||
list.add(new ItemDto(item_io_action, "进出信号", "DB600.B5"));
|
||||
list.add(new ItemDto(item_task, "任务号", "DB600.D6"));
|
||||
list.add(new ItemDto(item_material_type, "任务号", "DB600.D6"));
|
||||
list.add(new ItemDto(item_error, "报警信号", "DB600.B7"));
|
||||
list.add(new ItemDto(item_barcode, "条码", "DB600.D8"));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,13 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp
|
||||
String message = null;
|
||||
Boolean iserror = false;
|
||||
|
||||
int io_action = 0;
|
||||
int last_io_action = 0;
|
||||
int material_type = 0;
|
||||
int last_material_type = 0;
|
||||
int barcode = 0;
|
||||
int last_barcode =0;
|
||||
|
||||
|
||||
boolean hasVehicle = false;
|
||||
boolean isReady = false;
|
||||
@@ -141,6 +148,7 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp
|
||||
task = this.itemProtocol.getTask();
|
||||
hasGoods = this.itemProtocol.getMove();
|
||||
action = this.itemProtocol.getAction();
|
||||
io_action = this.itemProtocol.getIoAction();
|
||||
if (mode != last_mode) {
|
||||
this.setRequireSucess(false);
|
||||
}
|
||||
|
||||
@@ -159,9 +159,6 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 加载指令数据
|
||||
*/
|
||||
@Override
|
||||
public void autoInitial() {
|
||||
this.reload();
|
||||
|
||||
@@ -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 = deviceManageService.queryAllWithExtra();
|
||||
List<DeviceManageDto> deviceManageDtos = this.deviceManageService.queryAllWithExtra();
|
||||
this.devices = new ArrayList();
|
||||
Collections.synchronizedList(this.devices);
|
||||
this.code_indexs = new ArrayList();
|
||||
|
||||
@@ -42,16 +42,13 @@ 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");
|
||||
|
||||
@@ -30,131 +30,127 @@ 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 OpcServerServiceImpl() {}
|
||||
|
||||
/**
|
||||
* 加载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 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();
|
||||
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 synchronized void reload() {
|
||||
this.opcServerManageDtos = this.opcServerManageService.queryAllServerMap();
|
||||
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
|
||||
}
|
||||
|
||||
public synchronized Group getServer(String code) {
|
||||
Group group = null;
|
||||
group = (Group) this.groups.get(code);
|
||||
if (group != null) {
|
||||
try {
|
||||
if (group.isActive()) {
|
||||
return group;
|
||||
try {
|
||||
OpcServerServiceImpl.this.getServer(dto.getOpc_code());
|
||||
OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code());
|
||||
} catch (Exception var4) {
|
||||
OpcServerServiceImpl.log.warn("启动无法载入servers", var4);
|
||||
}
|
||||
} catch (JIException var9) {
|
||||
var9.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void reload() {
|
||||
this.opcServerManageDtos = this.opcServerManageService.queryAllServerMap();
|
||||
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
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 不存在");
|
||||
}
|
||||
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(
|
||||
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);
|
||||
}
|
||||
|
||||
return group;
|
||||
this.servers.put(code, server);
|
||||
this.groups.put(code, group);
|
||||
}
|
||||
|
||||
public synchronized void clearServer(String code) {
|
||||
try {
|
||||
Server server = (Server) this.servers.get(code);
|
||||
if (server != null) {
|
||||
server.disconnect();
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("清理server异常,", e.getMessage());
|
||||
}
|
||||
public synchronized void clearServer(String code) {
|
||||
try {
|
||||
Server server = (Server) this.servers.get(code);
|
||||
if (server!=null){
|
||||
server.disconnect();
|
||||
}
|
||||
|
||||
this.servers.remove(code);
|
||||
this.groups.remove(code);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("清理server异常,",e.getMessage());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,10 +514,6 @@ public class RouteLineServiceImpl extends CommonServiceImpl<RouteLineMapper, Rou
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载路由路线
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Override
|
||||
public void reload() throws SQLException {
|
||||
Object[] param = new Object[0];
|
||||
|
||||
@@ -246,10 +246,6 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 获取未完成任务
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void autoInitial() throws Exception {
|
||||
Class var1 = TaskInstructionLock.class;
|
||||
|
||||
Reference in New Issue
Block a user