diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index bcb23aa..7e34d45 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -48,7 +48,8 @@ public enum DriverTypeEnum { STANDARD_MANIPULATOR(19, "standard_manipulator", "标准版-行架机械手", "station"), - BOX_MANIPULATOR(20, "box_manipulator", "装箱行架机械手", "station"); + BOX_MANIPULATOR(20, "box_manipulator", "装箱行架机械手", "station"), + BOX_MANIPULATOR_SITE(21, "box_manipulator_site", "木箱机械手对接位", "station"); /** diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java index c7b19c6..bc2c1e0 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java @@ -229,6 +229,7 @@ public class DeviceServiceImpl extends CommonServiceImpl i wrapper.eq(StringUtils.isNotBlank((String) whereJson.get("device_type")), Device::getDevice_type, whereJson.get("device_type")); wrapper.nested(StringUtils.isNotBlank((String) whereJson.get("blurry")), i -> i.like(Device::getDevice_code, whereJson.get("blurry")).or().like(Device::getDevice_name, whereJson.get("blurry"))); wrapper.orderByAsc(Device::getIs_config).orderByDesc(Device::getSeq_num).orderByDesc(Device::getUpdate_time); + wrapper.orderByDesc(Device::getCreate_time); IPage devicePage = deviceMapper.queryPage(queryPage, wrapper); final JSONObject json = (JSONObject) JSON.toJSON(ConvertUtil.convertPage(devicePage, Device.class)); return json; diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor_with_scanner_weight/ConveyorWithScannerWeightDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/conveyor_box_storage/ConveyorWithScannerWeightDefination.java similarity index 96% rename from acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor_with_scanner_weight/ConveyorWithScannerWeightDefination.java rename to acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/conveyor_box_storage/ConveyorWithScannerWeightDefination.java index 2395978..c7f16ce 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor_with_scanner_weight/ConveyorWithScannerWeightDefination.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/conveyor_box_storage/ConveyorWithScannerWeightDefination.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.conveyor_with_scanner_weight; +package org.nl.acs.device_driver.conveyor.conveyor_box_storage; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device.domain.Device; diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor_with_scanner_weight/ConveyorWithScannerWeightDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/conveyor_box_storage/ConveyorWithScannerWeightDeviceDriver.java similarity index 99% rename from acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor_with_scanner_weight/ConveyorWithScannerWeightDeviceDriver.java rename to acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/conveyor_box_storage/ConveyorWithScannerWeightDeviceDriver.java index b55fea9..6f432c2 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor_with_scanner_weight/ConveyorWithScannerWeightDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/conveyor_box_storage/ConveyorWithScannerWeightDeviceDriver.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.conveyor_with_scanner_weight; +package org.nl.acs.device_driver.conveyor.conveyor_box_storage; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor_with_scanner_weight/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/conveyor_box_storage/ItemProtocol.java similarity index 98% rename from acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor_with_scanner_weight/ItemProtocol.java rename to acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/conveyor_box_storage/ItemProtocol.java index 8fafad1..947d947 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor_with_scanner_weight/ItemProtocol.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/conveyor_box_storage/ItemProtocol.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.conveyor_with_scanner_weight; +package org.nl.acs.device_driver.conveyor.conveyor_box_storage; import lombok.Data; import lombok.extern.slf4j.Slf4j; diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/box_storage_conveyor/BoxStorageConveyorDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/box_storage_conveyor/BoxStorageConveyorDefination.java new file mode 100644 index 0000000..5215ae9 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/box_storage_conveyor/BoxStorageConveyorDefination.java @@ -0,0 +1,64 @@ +package org.nl.acs.device_driver.one_conveyor.box_storage_conveyor; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.enums.DeviceType; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 一楼木箱入库站点 + * + */ +@Service +public class BoxStorageConveyorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "box_storage_conveyor"; + } + + @Override + public String getDriverName() { + return "一楼木箱入库站点"; + } + + @Override + public String getDriverDescription() { + return "一楼木箱入库站点"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new BoxStorageConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return BoxStorageConveyorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.station); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/box_storage_conveyor/BoxStorageConveyorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/box_storage_conveyor/BoxStorageConveyorDeviceDriver.java new file mode 100644 index 0000000..b159d70 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/box_storage_conveyor/BoxStorageConveyorDeviceDriver.java @@ -0,0 +1,698 @@ +package org.nl.acs.device_driver.one_conveyor.box_storage_conveyor; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.nl.acs.AcsConfig; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.FeedLmsRealFailed; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; +import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.history.ErrorUtil; +import org.nl.acs.history.service.DeviceErrorLogService; +import org.nl.acs.history.service.dto.DeviceErrorLogDto; +import org.nl.acs.history.service.impl.DeviceErrorLogServiceImpl; +import org.nl.acs.instruction.domain.Instruction; +import org.nl.acs.instruction.enums.InstructionStatusEnum; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.config.SpringContextHolder; +import org.nl.config.thread.ThreadPoolExecutorUtil; + +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * 一楼木箱入库站点 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class BoxStorageConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed { + private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll(); + protected ItemProtocol itemProtocol = new ItemProtocol(this); + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + + RouteLineService routelineserver = SpringContextHolder.getBean(RouteLineService.class); + + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + + + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + + + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); + + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); + + DeviceErrorLogService deviceErrorLogService = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class); + //当前指令 + Instruction inst = null; + + private String error_type = "ssx_error_type"; + + //工作模式 + int mode = 0; + int last_mode = 0; + //光电信号 + int move = 0; + int last_move = 0; + //托盘方向 + int carrier_direction = 0; + int last_carrier_direction = 0; + //报警信号 + int error = 0; + int last_error = 0; + //任务号 + int task = 0; + int last_task = 0; + int agvphase = 0; + String task_code = null; + int to_command = 0; + int last_to_command = 0; + + int to_target = 0; + int last_to_target = 0; + + int to_task = 0; + int last_to_task = 0; + + int to_strap_times = 0; + int last_to_strap_times = 0; + int to_length = 0; + int last_to_length = 0; + int to_weight = 0; + int last_to_weight = 0; + int to_height = 0; + int last_to_height = 0; + + int phase = 0; + int index = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + String hand_barcode = null; + + Integer heartbeat_tag; + private Date instruction_update_time = new Date(); + private int instruction_update_time_out = 500; + + private Date instruction_require_time = new Date(); + private Date require_apply_labeling_time = new Date(); + private Date require_apply_strangulation_time = new Date(); + private Date require_empty_in_time = new Date(); + private Date require_empty_out_time = new Date(); + + private int instruction_require_time_out = 3000; + //行架机械手申请任务成功标识 + boolean requireSucess = false; + boolean requireEmptyInSuccess = false; + boolean requiresShipDeviceUpdate = true; + private int instruction_finished_time_out; + + int branchProtocol = 0; + String inst_message; + String last_inst_message; + int heartbeat = 0; + int last_heartbeat = 0; + //当前指令 + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String device_code; + + String vehicle_code; + String last_vehicle_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + move = this.itemProtocol.getMove(); + carrier_direction = this.itemProtocol.getCarrier_direction(); + error = this.itemProtocol.getError(); + task = this.itemProtocol.getTask(); + to_command = this.itemProtocol.getTo_command(); + to_target = this.itemProtocol.getTo_target(); + to_task = this.itemProtocol.getTo_task(); + heartbeat = this.itemProtocol.getHeartbeat(); + + + if (to_strap_times != last_to_strap_times) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_strap_times:" + last_to_strap_times + "->" + to_strap_times); + } + if (to_length != last_to_length) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_length:" + last_to_length + "->" + to_length); + } + if (to_weight != last_to_weight) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_weight:" + last_to_weight + "->" + to_weight); + } + if (to_height != last_to_height) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_height:" + last_to_height + "->" + to_height); + } + if (to_command != last_to_command) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); + } + if (to_target != last_to_target) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); + } + if (to_task != last_to_task) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); + } + if (mode != last_mode) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode + "复位请求标记:" + requireSucess); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); + } + + if (carrier_direction != last_carrier_direction) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(carrier_direction)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号carrier_direction:" + last_carrier_direction + "->" + carrier_direction); + } + if (error != last_error) { + if (error != 0) { + DeviceErrorLogDto dto = new DeviceErrorLogDto(); + dto.setDevice_code(device_code); + dto.setError_code(String.valueOf(error)); + String errorInfo = ErrorUtil.getDictDetail("ssx_error_type", String.valueOf(error)); + dto.setError_info(errorInfo); + deviceErrorLogService.create(dto); + } + + if (error != 110 && error != 70) { + JSONObject param = new JSONObject(); + param.put("device_code", this.device_code); + param.put("error", error); + param.put("error_msg", error == 0 ? "" : ErrorUtil.getDictDetail("ssx_error_type", String.valueOf(error))); + param.put("device_name", this.getDevice().getDevice_name()); + param.put("device_type", "1"); + } + + + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + + if (move != 0 && task > 0) { + + update_instruction_status(); + } + + } catch (Exception var17) { + var17.printStackTrace(); + logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol)); + } + + + if (mode == 0) { + this.setIsonline(false); + message = "未联机"; + //有报警 + + } else { + this.setIsonline(true); + this.setIserror(false); + if (error != 0) { + this.setIserror(true); + message = "有报警"; + } + + Instruction instruction = null; + List toInstructions; + + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + //申请任务 + if (move > 0 && !requireSucess) { + instruction_require(); + } + break; + } + } + last_mode = mode; + last_move = move; + last_carrier_direction = carrier_direction; + last_error = error; + last_task = task; + last_heartbeat = heartbeat; + last_to_task = to_task; + last_to_command = to_command; + last_to_target = to_target; + last_to_strap_times = to_strap_times; + last_to_length = to_length; + last_to_weight = to_weight; + last_to_height = to_height; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + + public boolean exe_business() { + return true; + } + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + + + protected void thingToNothing() throws Exception { + requireSucess = false; + } + + + public void executing(Server server, Map itemMap) { + this.control(itemMap); + } + + public void writing(int command) { + Map itemMap = new HashMap(); + this.control(itemMap); + } + + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + String mode = ""; + String move = ""; + String carrier_direction = ""; + if (this.getMode() == 0) { + mode = "脱机"; + } else if (this.getMode() == 1) { + mode = "单机"; + } else if (this.getMode() == 2) { + mode = "待机"; + } else if (this.getMode() == 3) { + mode = "运行中"; + } else if (this.getMode() == 4) { + mode = "申请捆扎中"; + } else if (this.getMode() == 5) { + mode = "申请贴标中"; + } else if (this.getMode() == 6) { + mode = "申请空盘入库中"; + } else if (this.getMode() == 7) { + mode = "申请空盘出库中"; + } else if (this.getMode() == 8) { + mode = "申请AGV任务中"; + } + + if (this.getMove() == 0) { + move = "无货"; + jo.put("hasGoods", false); + } else if (this.getMove() == 1) { + move = "有货"; + jo.put("hasGoods", true); + } else if (this.getMove() == 2) { + move = "有托盘有货"; + jo.put("hasGoods", true); + } + + if (this.carrier_direction == 1) { + carrier_direction = "正转"; + } else if (this.carrier_direction == 2) { + carrier_direction = "反转"; + } + String requireSucess = "0"; + if (this.requireSucess) { + requireSucess = "1"; + } + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("mode", mode); + jo.put("move", move); + jo.put("carrier_direction", carrier_direction); + jo.put("task", task); + jo.put("last_task", last_task); + jo.put("task_code", task_code); + jo.put("inst_message", this.inst_message); + jo.put("last_inst_message", this.last_inst_message); + jo.put("isOnline", this.getIsonline()); + jo.put("error", ErrorUtil.getDictDetail("ssx_error_type", String.valueOf(this.getError()))); + jo.put("isError", this.getIserror()); + jo.put("message", this.getMessage()); + jo.put("hand_barcode", hand_barcode); + jo.put("barcode", this.getMove() == 0 ? null : checkInst() == null ? vehicle_code : checkInst().getVehicle_code()); + jo.put("is_click", true); + jo.put("requireSucess", requireSucess); + jo.put("driver_type", "siemens_conveyor"); + return jo; + } + + @Override + public void setDeviceStatus(JSONObject data) { + String requestSucess = data.getString("requireSucess"); + if (StrUtil.equals(requestSucess, "0")) { + this.requireSucess = false; + } else if (StrUtil.equals(requestSucess, "1")) { + this.requireSucess = true; + } + + String hand_barcode = data.getString("hand_barcode"); + this.setHand_barcode(hand_barcode); + } + + @Override + public JSONObject feedLmsRealFailedInfo() { + JSONObject jo = new JSONObject(); + jo.put("device_code", this.getDevice().getDevice_code()); + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("fault_code", String.valueOf(error)); + jo.put("fault_info", ErrorUtil.getDictDetail(error_type, String.valueOf(this.getError()))); + jo.put("fault_type", error_type); + return jo; + } + + public void writing(List list) { + + Map itemMap = new HashMap(); + for (int i = 0; i < list.size(); i++) { + Object ob = list.get(i); + JSONObject json = (JSONObject) JSONObject.toJSON(ob); + if (!StrUtil.isEmpty(json.getString("value"))) { + String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + json.getString("code"); + itemMap.put(to_param, json.getString("value")); + } + } + logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); + try { + this.checkcontrol(itemMap); + } catch (Exception e) { + e.printStackTrace(); + try { + this.checkcontrol(itemMap); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + + } + + + /** + * 请求指令 + */ + public synchronized boolean instruction_require() { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + //判断是否存在起点相同 任务状态就绪的任务 + TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code); + if (!ObjectUtil.isEmpty(taskdto)) { + //需要判断当前设备是否已经存在就绪的指令 如果存在就直接下发 不存在则创建 + Instruction inst = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()); + if (ObjectUtil.isNotEmpty(inst)) { + List list = new ArrayList(); + Map map2 = new HashMap(); + map2.put("code", "to_task"); + map2.put("value", inst.getInstruction_code()); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_command"); + map3.put("value", "1"); + list.add(map3); + this.writing(list); + requireSucess = true; + while (!StrUtil.equals(this.getOpcValueAccessor().getValue(this.getOpcServer() + "." + this.getOpcPlc() + "." + this.getDevice_code() + ".task").toString() + , inst.getInstruction_code())) { + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发信号"); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (ObjectUtil.isEmpty(instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()))) { + requireSucess = false; + return false; + } + } + message = "下发电气任务号成功"; + requireSucess = true; + return true; + } + String taskid = taskdto.getTask_id(); + String taskcode = taskdto.getTask_code(); + String vehiclecode = taskdto.getVehicle_code(); + String priority = taskdto.getPriority(); + String start_point_code = taskdto.getStart_point_code(); + String start_device_code = taskdto.getStart_device_code(); + String route_plan_code = taskdto.getRoute_plan_code(); + String next_device_code = ""; + + /** + * 开始平均分配 + */ + String this_coevice_code = taskserver.queryAssignedByDevice(device_code, taskdto.getNext_device_code()); + if (StrUtil.isEmpty(this_coevice_code)) { + List shortPathsList = routeLineService.getShortPathLines(start_device_code, taskdto.getNext_device_code(), route_plan_code); + RouteLineDto routeLineDto = shortPathsList.get(0); + + String path = routeLineDto.getPath(); + String type = routeLineDto.getType(); + String[] str = path.split("->"); + + List pathlist = Arrays.asList(str); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(start_device_code)) { + index = m + 1; + break; + } + } + next_device_code = pathlist.get(index); + } else { + next_device_code = this_coevice_code; + } + //校验路由关系 + List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + if (ObjectUtils.isEmpty(shortPathsList)) { + throw new RuntimeException("路由不通!"); + } + + Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); + Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); + String next_point_code; + if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = taskdto.getTo_x() + "-" + taskdto.getTo_y() + "-" + taskdto.getTo_z(); + } else { + next_point_code = next_device_code; + } + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(taskdto.getRemark()); + instdto.setMaterial(taskdto.getMaterial()); + instdto.setQuantity(taskdto.getQuantity()); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + instdto.setVehicle_code(vehiclecode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setPriority(priority); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(start_point_code); + try { + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("指令创建失败!", e.getMessage()); + return false; + } + //创建指令后修改任务状态 + taskdto.setTask_status("1"); + taskserver.update(taskdto); + requireSucess = true; + String next_addr = nextdevice.getExtraValue().get("address").toString(); + + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_target"); + map.put("value", next_addr); + list.add(map); + Map map2 = new HashMap(); + map2.put("code", "to_task"); + map2.put("value", instdto.getInstruction_code()); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_command"); + map3.put("value", "1"); + list.add(map3); + this.writing(list); + requireSucess = true; + while (!StrUtil.equals(this.getOpcValueAccessor().getValue(this.getOpcServer() + "." + this.getOpcPlc() + "." + this.getDevice_code() + ".task").toString() + , instdto.getInstruction_code())) { + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (ObjectUtil.isEmpty(taskserver.findByCode(taskdto.getTask_code()))) { + requireSucess = false; + return false; + } + } + } else { + //如果不存在则直接找对应指令 + Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code); + if (ObjectUtil.isEmpty(inst)) { + return false; + } + + Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code()); + String next_addr = nextdevice.getExtraValue().get("address").toString(); + + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_target"); + map.put("value", next_addr); + list.add(map); + Map map2 = new HashMap(); + map2.put("code", "to_task"); + map2.put("value", inst.getInstruction_code()); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_command"); + map3.put("value", "1"); + list.add(map3); + this.writing(list); + requireSucess = true; + while (!StrUtil.equals(this.getOpcValueAccessor().getValue(this.getOpcServer() + "." + this.getOpcPlc() + "." + this.getDevice_code() + ".task").toString() + , inst.getInstruction_code())) { + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (ObjectUtil.isEmpty(instructionService.findByDeviceCodeFromCache(this.device_code))) { + requireSucess = false; + return false; + } + } + } + return true; + } + } + + /** + * 更新指令状态 + */ + public synchronized void update_instruction_status() throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); + + } else { + this.instruction_update_time = date; + inst = checkInst(); + if (inst != null) { + inst_message = "当前指令号:" + inst.getInstruction_code() + " " + inst.getStart_point_code() + "->" + inst.getNext_point_code() + " 载具号:" + inst.getVehicle_code(); + vehicle_code = inst.getVehicle_code(); + task_code = inst.getTask_code(); + if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { + inst.setInstruction_status("1"); + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + logServer.deviceExecuteLog(device_code, "", "", "纸箱入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task + ",载具号:" + inst.getVehicle_code()); + } + if (StrUtil.equals(inst.getInstruction_status(), "1") || StrUtil.equals(inst.getInstruction_status(), "0")) { + if (StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { + vehicle_code = inst.getVehicle_code(); + inst.setExecute_device_code(this.device_code); + if (mode == 2) { + finish_instruction(); + } + logServer.deviceExecuteLog(device_code, "", "", "纸箱入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task + ",载具号:" + inst.getVehicle_code()); + } else { + + } + } + } else { +// message = "输送线任务反馈状态,查询不到指令号:" + task +"指令已完成"; + inst_message = null; + } + + } + } + + public Instruction checkInst() { + if (ObjectUtil.isNotEmpty(this.inst)) { + if (this.task > 0) { + if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) { + return this.inst; + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + } + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + return null; + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/box_storage_conveyor/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/box_storage_conveyor/ItemProtocol.java new file mode 100644 index 0000000..9c4547d --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/box_storage_conveyor/ItemProtocol.java @@ -0,0 +1,177 @@ +package org.nl.acs.device_driver.one_conveyor.box_storage_conveyor; + +import cn.hutool.core.util.StrUtil; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + /** + * 心跳 + */ + public static String item_heartbeat = "heartbeat"; + /** + * 工作模式 + */ + public static String item_mode = "mode"; + /** + * 光电信号 + */ + public static String item_move = "move"; + /** + * 托盘方向 + */ + public static String item_carrier_direction = "carrier_direction"; + + /** + * 载具类型 + */ + public static String item_container_type = "container_type"; + + /** + * 报警 + */ + public static String item_error = "error"; + /** + * 任务号 + */ + public static String item_task = "task"; + + /** + * 动作信号 + */ + public static String item_action = "action"; + + /** + * 下发命令 + */ + public static String item_to_command = "to_command"; + /** + * 下发目标站 + */ + public static String item_to_target = "to_target"; + /** + * 下发托盘类型 + */ + public static String item_to_container_type = "to_container_type"; + /** + * 下发任务号 + */ + public static String item_to_task = "to_task"; + + + + private BoxStorageConveyorDeviceDriver driver; + + public int getContainer_type() { + return this.getOpcIntegerValue(item_container_type); + } + + + public ItemProtocol(BoxStorageConveyorDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getCarrier_direction() { + return this.getOpcIntegerValue(item_carrier_direction); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_target() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getTo_task() { + return this.getOpcIntegerValue(item_to_task); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + // log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public String getOpcStringValue(String protocol) { + String value = this.driver.getStringValue(protocol); + if (StrUtil.isEmpty(value)) { + + } else { + return value; + } + return "0"; + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB600.B2")); + list.add(new ItemDto(item_move, "光电信号", "DB600.B3")); + list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB600.B4")); + list.add(new ItemDto(item_action, "动作信号", "DB600.B5")); + list.add(new ItemDto(item_error, "报警信号", "DB600.B6")); + list.add(new ItemDto(item_container_type, "托盘类型", "DB101.B7")); + list.add(new ItemDto(item_task, "任务号", "DB600.D10")); + + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2")); + list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W4")); + list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB601.W6")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8")); + + return list; + } + + @Override + public String toString() { + return ""; + } + +} + diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/box_manipulator/BoxManipulatorDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/BoxPackageManipulatorDefination.java similarity index 72% rename from acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/box_manipulator/BoxManipulatorDefination.java rename to acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/BoxPackageManipulatorDefination.java index cfc28c7..4e95e75 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/box_manipulator/BoxManipulatorDefination.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/BoxPackageManipulatorDefination.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.box_manipulator; +package org.nl.acs.device_driver.one_manipulator.box_package_manipulator; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device.domain.Device; @@ -11,31 +11,31 @@ import java.util.LinkedList; import java.util.List; @Service -public class BoxManipulatorDefination implements OpcDeviceDriverDefination { +public class BoxPackageManipulatorDefination implements OpcDeviceDriverDefination { @Override public String getDriverCode() { - return "box_manipulator"; + return "box_package_manipulator"; } @Override public String getDriverName() { - return "装箱行架机械手"; + return "装箱智能行架"; } @Override public String getDriverDescription() { - return "装箱行架机械手"; + return "装箱智能行架"; } @Override public DeviceDriver getDriverInstance(Device device) { - return (new BoxManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); + return (new BoxPackageManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); } @Override public Class getDeviceDriverType() { - return BoxManipulatorDeviceDriver.class; + return BoxPackageManipulatorDeviceDriver.class; } @Override diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/box_manipulator/BoxManipulatorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/BoxPackageManipulatorDeviceDriver.java similarity index 62% rename from acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/box_manipulator/BoxManipulatorDeviceDriver.java rename to acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/BoxPackageManipulatorDeviceDriver.java index 8a64c2a..41823eb 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/box_manipulator/BoxManipulatorDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/BoxPackageManipulatorDeviceDriver.java @@ -1,7 +1,10 @@ -package org.nl.acs.device_driver.box_manipulator; +package org.nl.acs.device_driver.one_manipulator.box_package_manipulator; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.RequiredArgsConstructor; @@ -13,6 +16,7 @@ import org.nl.acs.device.service.impl.DeviceExtraServiceImpl; import org.nl.acs.device_driver.DeviceDriver; import org.nl.acs.device_driver.FeedLmsRealFailed; import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.box_manipulator_site.BoxManipulatorSiteDeviceDriver; import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; import org.nl.acs.history.ErrorUtil; @@ -27,34 +31,29 @@ import org.nl.acs.opc.DeviceAppServiceImpl; import org.nl.acs.route.service.RouteLineService; import org.nl.acs.route.service.impl.RouteLineServiceImpl; import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; import org.nl.config.SpringContextHolder; -import org.springframework.beans.factory.annotation.Autowired; import java.util.Date; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; /** - * 装箱行架机械手 + * 装箱智能行架 */ @Slf4j @Data @RequiredArgsConstructor -public class BoxManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed { +public class BoxPackageManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed { protected ItemProtocol itemProtocol = new ItemProtocol(this); - @Autowired DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - @Autowired TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); - @Autowired InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); - @Autowired DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - @Autowired RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); - @Autowired DeviceExtraService deviceExtraService = SpringContextHolder.getBean(DeviceExtraServiceImpl.class); - @Autowired DeviceErrorLogService errorLogServer = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class); //工作模式 @@ -99,6 +98,12 @@ public class BoxManipulatorDeviceDriver extends AbstractOpcDeviceDriver implemen int to_seq = 0; int last_to_seq = 0; + int to_max_no = 0; + int last_to_max_no = 0; + + int to_direction = 0; + int last_to_direction = 0; + int to_last = 0; int last_to_last = 0; @@ -164,11 +169,19 @@ public class BoxManipulatorDeviceDriver extends AbstractOpcDeviceDriver implemen x_position = this.itemProtocol.getX_position(); y_position = this.itemProtocol.getY_position(); to_seq = this.itemProtocol.getTo_seq(); + to_max_no = this.itemProtocol.getTo_max_no(); + to_direction = this.itemProtocol.getTo_direction(); to_last = this.itemProtocol.getTo_last(); if (to_last != last_to_last) { logServer.deviceExecuteLog(this.device_code, "", "", "信号to_last:" + last_to_last + "->" + to_last); } + if (to_max_no != last_to_max_no) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_max_no:" + last_to_max_no + "->" + to_max_no); + } + if (to_direction != last_to_direction) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_direction:" + last_to_direction + "->" + to_direction); + } if (to_seq != last_to_seq) { logServer.deviceExecuteLog(this.device_code, "", "", "信号to_seq:" + last_to_seq + "->" + to_seq); } @@ -220,24 +233,7 @@ public class BoxManipulatorDeviceDriver extends AbstractOpcDeviceDriver implemen // 更新指令状态 if (mode == 3 && task > 0) { - Date date = new Date(); - if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); - - } else { - this.instruction_update_time = date; - //更改指令状态 - if (task > 0) { - Instruction inst = checkInst(); - if (inst != null) { - if (StrUtil.equals(inst.getInstruction_status(), "0")) { - inst.setInstruction_status(CommonFinalParam.ONE); - inst.setExecute_device_code(this.device_code); - instructionService.update(inst); - } - } - } - } + updateInstrction(); } } catch (Exception var17) { @@ -264,15 +260,13 @@ public class BoxManipulatorDeviceDriver extends AbstractOpcDeviceDriver implemen //行架机械手申请任务 if (mode == 2 && move == 0 && task == 0 && !requireSucess) { -// boolean res = applyTask(); -// if (res) { -// notCreateInstMessage = ""; -// notCreateTaskMessage = ""; -// feedMessage = ""; -// } + boolean res = applyTask(); + if (res) { + notCreateInstMessage = ""; + notCreateTaskMessage = ""; + feedMessage = ""; + } } else { - if (mode == 2) { - //if (!requireSucess) { String remark = "未查找任务原因为:"; if (mode != 2) { remark = remark + "工作模式(mode)不是待机状态,"; @@ -290,8 +284,6 @@ public class BoxManipulatorDeviceDriver extends AbstractOpcDeviceDriver implemen remark = remark + "请右击该图标,将请求任务复位标记(requireSucess)改为否。"; } this.setNotCreateTaskMessage(remark); - //} - } } } @@ -310,6 +302,148 @@ public class BoxManipulatorDeviceDriver extends AbstractOpcDeviceDriver implemen last_y_position = y_position; last_to_seq = to_seq; last_to_last = to_last; + last_to_direction = to_direction; + last_to_max_no = to_max_no; + } + + private void updateInstrction() { + Date date = new Date(); + if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); + + } else { + this.instruction_update_time = date; + //更改指令状态 + if (task > 0) { + Instruction inst = checkInst(); + if (inst != null) { + if (StrUtil.equals(inst.getInstruction_status(), "0")) { + inst.setInstruction_status(CommonFinalParam.ONE); + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + } + } + } + } + } + + public synchronized boolean applyTask() { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + BoxManipulatorSiteDeviceDriver boxManipulatorSiteDeviceDriver = new BoxManipulatorSiteDeviceDriver(); + String deviceCode = boxManipulatorSiteDeviceDriver.getDevice_code(); + TaskDto taskDto = taskserver.findByEndCodeAndReady(deviceCode); + if (ObjectUtil.isNotEmpty(taskDto)) { + + String interactionJson = taskDto.getInteraction_json(); + InteractionJsonDTO interactionJsonDTO = JSON.parseObject(interactionJson, InteractionJsonDTO.class); + String start_device_code = taskDto.getStart_device_code(); + String next_device_code = taskDto.getNext_device_code(); + Device startDevice = deviceAppService.findDeviceByCode(start_device_code); + Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); + String start_addr = startDevice.getExtraValue().get("address").toString(); + String next_addr = nextDevice.getExtraValue().get("address").toString(); + String taskid = taskDto.getTask_id(); + String taskcode = taskDto.getTask_code(); + String start_point_code = taskDto.getStart_point_code(); + String route_plan_code = taskDto.getRoute_plan_code(); + String next_point_code = taskDto.getNext_point_code(); + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(device_code); + + try { + instructionService.create(instdto); + } catch (Exception e) { + notCreateInstMessage = e.getMessage(); + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); + return false; + } + logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() + + ",指令终点:" + instdto.getNext_device_code() + ",交互参数:" + interactionJsonDTO.toString()); + + + Map map = new LinkedHashMap<>(); + map.put("to_command", 1); + map.put("to_target", next_addr); + map.put("to_onset", start_addr); + map.put("to_task", instdto.getInstruction_code()); + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_seq())) { + map.put("to_seq", interactionJsonDTO.getItem_to_seq()); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_last_one())) { + map.put("to_last_one", interactionJsonDTO.getItem_to_last_one()); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_direction())) { + map.put("to_direction", interactionJsonDTO.getItem_to_direction()); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_max_no())) { + map.put("to_max_no", interactionJsonDTO.getItem_to_max_no()); + } + + + try { + this.writing(map); + } catch (Exception e) { + logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() + + ",指令终点:" + instdto.getNext_device_code() + ",交互参数:" + interactionJsonDTO.toString() + ",指令执行失败:" + e.getMessage()); + } + this.setRequireSucess(true); + return true; + } else { + notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; + } + return true; + } + + } + + /** + * 下发 + * @param map + */ + public void writing(Map map) { + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + Map itemMap = new LinkedHashMap<>(); + map.forEach((key, value) -> { + if (ObjectUtil.isNotEmpty(value)) { + itemMap.put(getToParam() + key, value); + } + }); + if (ObjectUtil.isNotEmpty(itemMap)) { + try { + this.checkcontrol(itemMap); + } catch (Exception e) { + throw new RuntimeException(e); + } + logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); + } + } + + /** + * 抽取统一下发电气信号前缀 + * + * @return + */ + public String getToParam() { + return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; } @Override diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/InteractionJsonDTO.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/InteractionJsonDTO.java new file mode 100644 index 0000000..4b13088 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/InteractionJsonDTO.java @@ -0,0 +1,28 @@ +package org.nl.acs.device_driver.one_manipulator.box_package_manipulator; + +import lombok.Data; + +@Data +public class InteractionJsonDTO { + + /** + *木箱长度 + */ + private String item_to_max_no = "to_max_no"; + /** + *木箱宽度 + */ + private String item_to_direction = "to_direction"; + /** + *木箱高度 + */ + private String item_to_seq = "to_seq"; + + /** + *下发木箱条码 + */ + private String item_to_last_one = "to_last_one"; + + + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/box_manipulator/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/ItemProtocol.java similarity index 75% rename from acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/box_manipulator/ItemProtocol.java rename to acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/ItemProtocol.java index d5617e0..5375b4d 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/box_manipulator/ItemProtocol.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_package_manipulator/ItemProtocol.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.box_manipulator; +package org.nl.acs.device_driver.one_manipulator.box_package_manipulator; import cn.hutool.core.util.StrUtil; import lombok.Data; @@ -11,42 +11,83 @@ import java.util.List; @Slf4j @Data public class ItemProtocol { - //心跳 + /** + * 心跳 + */ public static String item_heartbeat = "heartbeat"; - //工作模式 + /** + * 工作模式 + */ public static String item_mode = "mode"; - //光电信号 + /** + * 光电信号 + */ public static String item_move = "move"; - //动作信号 + /** + * 动作信号 + */ public static String item_action = "action"; - //行走列 + /** + * 行走列 + */ public static String item_walk_y = "walk_y"; - //任务号 + /** + * 任务号 + */ public static String item_task = "task"; - //报警 + /** + * 报警 + */ public static String item_error = "error"; - //x轴坐标 + /** + * x轴坐标 + */ public static String item_x_position = "x_position"; - //y轴坐标 + /** + * y轴坐标 + */ public static String item_y_position = "y_position"; - //下发命令 + /** + * 下发命令 + */ public static String item_to_command = "to_command"; - //下发起始站 + /** + * 下发起始站 + */ public static String item_to_onset = "to_onset"; - //下发目标站 + /** + * 下发目标站 + */ public static String item_to_target = "to_target"; - //下发任务号 + /** + * 下发任务号 + */ public static String item_to_task = "to_task"; - //下发木箱工位顺序 + + /** + * 木箱最大数量 + */ + public static String item_to_max_no = "to_max_no"; + + /** + * 子卷摆放方向 + */ + public static String item_to_direction = "to_direction"; + + /** + * 下发木箱工位顺序 + */ public static String item_to_seq = "to_seq"; - //下发是否最后子卷 - public static String item_to_last = "to_last"; + /** + * 下发是否最后子卷 + */ + public static String item_to_last_one = "to_last_one"; - private BoxManipulatorDeviceDriver driver; + private BoxPackageManipulatorDeviceDriver driver; - public ItemProtocol(BoxManipulatorDeviceDriver driver) { + public ItemProtocol(BoxPackageManipulatorDeviceDriver driver) { this.driver = driver; } @@ -105,9 +146,15 @@ public class ItemProtocol { public int getTo_seq(){ return this.getOpcIntegerValue(item_to_seq); } + public int getTo_max_no(){ + return this.getOpcIntegerValue(item_to_max_no); + } + public int getTo_direction(){ + return this.getOpcIntegerValue(item_to_direction); + } public int getTo_last(){ - return this.getOpcIntegerValue(item_to_last); + return this.getOpcIntegerValue(item_to_last_one); } @@ -169,8 +216,10 @@ public class ItemProtocol { list.add(new ItemDto(item_to_onset, "下发起始站", "DB2.W2")); list.add(new ItemDto(item_to_target, "下发目标站", "DB2.W4")); list.add(new ItemDto(item_to_task, "下发任务号", "DB2.D6")); - list.add(new ItemDto(item_to_seq, "下发木箱工位顺序", "DB2.W8")); - list.add(new ItemDto(item_to_last, "下发是否最后子卷", "DB2.W10")); + list.add(new ItemDto(item_to_max_no, "木箱最大数量", "DB2.D8")); + list.add(new ItemDto(item_to_direction, "子卷摆放方向", "DB2.D10")); + list.add(new ItemDto(item_to_seq, "下发木箱工位顺序", "DB2.W12")); + list.add(new ItemDto(item_to_last_one, "下发是否最后子卷", "DB2.W14")); return list; } } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDefination.java new file mode 100644 index 0000000..c947295 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDefination.java @@ -0,0 +1,56 @@ +package org.nl.acs.device_driver.one_manipulator.box_storage_manipulator; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.enums.DeviceType; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +@Service +public class BoxStorageManipulatorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "box_storage"; + } + + @Override + public String getDriverName() { + return "木箱入库行架"; + } + + @Override + public String getDriverDescription() { + return "木箱入库行架"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new BoxStorageManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return BoxStorageManipulatorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.robot); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDeviceDriver.java new file mode 100644 index 0000000..2cf8c7d --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDeviceDriver.java @@ -0,0 +1,497 @@ +package org.nl.acs.device_driver.one_manipulator.box_storage_manipulator; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.common.base.CommonFinalParam; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.service.DeviceExtraService; +import org.nl.acs.device.service.impl.DeviceExtraServiceImpl; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.FeedLmsRealFailed; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.box_manipulator_site.BoxManipulatorSiteDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.history.ErrorUtil; +import org.nl.acs.history.service.DeviceErrorLogService; +import org.nl.acs.history.service.impl.DeviceErrorLogServiceImpl; +import org.nl.acs.instruction.domain.Instruction; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.DeviceAppServiceImpl; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.impl.RouteLineServiceImpl; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.config.SpringContextHolder; + +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 木箱入库行架 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class BoxStorageManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed { + + protected ItemProtocol itemProtocol = new ItemProtocol(this); + + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + + DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); + + DeviceExtraService deviceExtraService = SpringContextHolder.getBean(DeviceExtraServiceImpl.class); + + DeviceErrorLogService errorLogServer = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class); + + + int mode = 0; + int last_mode = 0; + int move = 0; + int last_move = 0; + int action = 0; + int last_action = 0; + int error = 0; + int last_error = 0; + int task = 0; + int last_task = 0; + + + int heartbeat = 0; + int last_heartbeat = 0; + int to_command = 0; + int last_to_command = 0; + + int to_target = 0; + int last_to_target = 0; + + int to_onset = 0; + int last_to_onset = 0; + + int to_task = 0; + int last_to_task = 0; + int to_layer = 0; + int last_to_layer = 0; + int to_barcode = 0; + int last_to_barcode = 0; + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + private Date instruction_update_time = new Date(); + private int instruction_update_time_out = 1000; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + + private int instruction_require_time_out = 3000; + //行架机械手申请任务成功标识 + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + private String error_type = "hxhj_error_type"; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String device_code; + + //当前指令 + Instruction inst = null; + + //0 无任务执行 1更新指令状态 2下发电气信号 3允许取货 允许放货 5放货完成 + int now_steps_type = 0; + String notCreateTaskMessage = ""; + String notCreateInstMessage = ""; + String feedMessage = ""; + + + List getDeviceCodeList = null; + + List putDeviceCodeList = null; + + + @Override + public Device getDevice() { + return this.device; + } + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + move = this.itemProtocol.getMove(); + action = this.itemProtocol.getAction(); + error = this.itemProtocol.getError(); + task = this.itemProtocol.getTask(); + heartbeat = this.itemProtocol.getHeartbeat(); + to_command = this.itemProtocol.getTo_command(); + to_target = this.itemProtocol.getTo_target(); + to_onset = this.itemProtocol.getTo_onset(); + to_task = this.itemProtocol.getTo_task(); + to_layer = this.itemProtocol.getTo_layer(); + to_barcode = this.itemProtocol.getTo_barcode(); + if (mode != last_mode) { + requireSucess = false; + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); + } + if (action != last_action) { + logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); + } + if (to_command != last_to_command) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); + } + if (to_target != last_to_target) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); + } + if (to_onset != last_to_onset) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_onset:" + last_to_target + "->" + to_target); + } + if (to_task != last_to_task) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); + } + + + // 更新指令状态 + if (mode == 3 && task > 0) { + updateInstructionStatus(); + } + + } catch (Exception var17) { + var17.printStackTrace(); + feedMessage = var17.getMessage(); + logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol)); + + } + + if (mode == 0) { + this.setIsonline(false); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + + //行架机械手申请任务 + if (mode == 2 && move == 0 && task == 0 && !requireSucess) { + boolean res = applyTask(); + if (res) { + notCreateInstMessage = ""; + notCreateTaskMessage = ""; + feedMessage = ""; + } + } else { + String remark = "未查找任务原因为:"; + if (mode != 2) { + remark = remark + "工作模式(mode)不是待机状态,"; + } + if (move != 0) { + remark = remark + "光电信号(move)为有货状态,"; + } + if (task != 0) { + remark = remark + "当前上报任务号(task)应该为0,"; + if (ObjectUtil.isNotEmpty(this.inst)) { + this.inst = null; + } + } + if (requireSucess) { + remark = remark + "请右击该图标,将请求任务复位标记(requireSucess)改为否。"; + } + this.setNotCreateTaskMessage(remark); + } + + } + last_mode = mode; + last_move = move; + last_action = action; + last_error = error; + last_task = task; + last_heartbeat = heartbeat; + last_to_task = to_task; + last_to_command = to_command; + last_to_target = to_target; + last_to_layer = to_layer; + last_to_barcode = to_barcode; + + } + + private void updateInstructionStatus() { + Date date = new Date(); + if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); + + } else { + this.instruction_update_time = date; + //更改指令状态 + if (task > 0) { + Instruction inst = checkInst(); + if (inst != null) { + if (StrUtil.equals(inst.getInstruction_status(), "0")) { + inst.setInstruction_status(CommonFinalParam.ONE); + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + } + } + } + } + } + + public synchronized boolean applyTask() { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + BoxManipulatorSiteDeviceDriver boxManipulatorSiteDeviceDriver = new BoxManipulatorSiteDeviceDriver(); + String deviceCode = boxManipulatorSiteDeviceDriver.getDevice_code(); + TaskDto taskDto = taskserver.findByEndCodeAndReady(deviceCode); + if (ObjectUtil.isNotEmpty(taskDto)) { + + String interactionJson = taskDto.getInteraction_json(); + InteractionJsonDTO interactionJsonDTO = JSON.parseObject(interactionJson, InteractionJsonDTO.class); + String start_device_code = taskDto.getStart_device_code(); + String next_device_code = taskDto.getNext_device_code(); + Device startDevice = deviceAppService.findDeviceByCode(start_device_code); + Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); + String start_addr = startDevice.getExtraValue().get("address").toString(); + String next_addr = nextDevice.getExtraValue().get("address").toString(); + String taskid = taskDto.getTask_id(); + String taskcode = taskDto.getTask_code(); + String start_point_code = taskDto.getStart_point_code(); + String route_plan_code = taskDto.getRoute_plan_code(); + String next_point_code = taskDto.getNext_point_code(); + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(device_code); + + try { + instructionService.create(instdto); + } catch (Exception e) { + notCreateInstMessage = e.getMessage(); + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); + return false; + } + logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() + + ",指令终点:" + instdto.getNext_device_code() + ",交互参数:" + interactionJsonDTO.toString()); + + + Map map = new LinkedHashMap<>(); + map.put("to_command", 1); + map.put("to_target", next_addr); + map.put("to_onset", start_addr); + map.put("to_task", instdto.getInstruction_code()); + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_weight())) { + map.put("to_wedth", interactionJsonDTO.getItem_to_weight()); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_length())) { + map.put("to_length", interactionJsonDTO.getItem_to_length()); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_height())) { + map.put("to_height", interactionJsonDTO.getItem_to_height()); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_barcode())) { + map.put("to_barcode", interactionJsonDTO.getItem_to_barcode()); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_layer())) { + map.put("to_layer", interactionJsonDTO.getItem_to_layer()); + } + + + try { + this.writing(map); + } catch (Exception e) { + logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() + + ",指令终点:" + instdto.getNext_device_code() + ",交互参数:" + interactionJsonDTO.toString() + ",指令执行失败:" + e.getMessage()); + } + this.setRequireSucess(true); + return true; + } else { + notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; + } + return true; + } + + } + + /** + * 下发 + * @param map + */ + public void writing(Map map) { + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + Map itemMap = new LinkedHashMap<>(); + map.forEach((key, value) -> { + if (ObjectUtil.isNotEmpty(value)) { + itemMap.put(getToParam() + key, value); + } + }); + if (ObjectUtil.isNotEmpty(itemMap)) { + try { + this.checkcontrol(itemMap); + } catch (Exception e) { + throw new RuntimeException(e); + } + logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); + } + } + + /** + * 抽取统一下发电气信号前缀 + * + * @return + */ + public String getToParam() { + return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; + } + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + String mode = ""; + String move = ""; + String action = ""; + String walk_y = ""; + if (this.getMode() == 0) { + mode = "脱机"; + } else if (this.getMode() == 1) { + mode = "单机"; + } else if (this.getMode() == 2) { + mode = "待机"; + } else if (this.getMode() == 3) { + mode = "运行中"; + } + + if (this.getMove() == 0) { + move = "无货"; + } else if (this.getMove() == 1) { + move = "有货"; + } + + String requireSucess = "0"; + if (this.requireSucess) { + requireSucess = "1"; + } + jo.put("requireSucess", requireSucess); + if (this.getAction() == 1) { + action = "取货中"; + } else if (this.getAction() == 2) { + action = "取货完成"; + } else if (this.getAction() == 3) { + action = "放货中"; + } else if (this.getAction() == 4) { + action = "放货完成"; + } + + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("mode", mode); + jo.put("move", move); + jo.put("action", action); + jo.put("task", task); + jo.put("isOnline", this.getIsonline()); + jo.put("error", this.getError()); + jo.put("isError", this.getIserror()); + jo.put("message", this.getMessage()); + jo.put("notCreateTaskMessage", notCreateTaskMessage); + jo.put("notCreateInstMessage", notCreateInstMessage); + jo.put("feedMessage", feedMessage); + jo.put("driver_type", "siemens_conveyor"); + jo.put("is_click", true); + return jo; + } + + @Override + public void setDeviceStatus(JSONObject data) { + String requestSucess = data.getString("requireSucess"); + if (StrUtil.equals(requestSucess, "0")) { + this.requireSucess = false; + } else if (StrUtil.equals(requestSucess, "1")) { + this.requireSucess = true; + } + } + + @Override + public JSONObject feedLmsRealFailedInfo() { + JSONObject jo = new JSONObject(); + jo.put("device_code", this.getDevice().getDevice_code()); + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("fault_code", String.valueOf(error)); + jo.put("fault_info", ErrorUtil.getDictDetail(error_type, String.valueOf(this.getError()))); + jo.put("fault_type", error_type); + return jo; + } + + + public Instruction checkInst() { + if (ObjectUtil.isNotEmpty(this.inst)) { + if (this.task > 0) { + if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) { + return this.inst; + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + } + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + return null; + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/InteractionJsonDTO.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/InteractionJsonDTO.java new file mode 100644 index 0000000..2f193a5 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/InteractionJsonDTO.java @@ -0,0 +1,31 @@ +package org.nl.acs.device_driver.one_manipulator.box_storage_manipulator; + +import lombok.Data; + +@Data +public class InteractionJsonDTO { + + /** + *木箱长度 + */ + private String item_to_length = "to_length"; + /** + *木箱宽度 + */ + private String item_to_weight = "to_weight"; + /** + *木箱高度 + */ + private String item_to_height = "to_height"; + + /** + *下发木箱条码 + */ + private String item_to_barcode = "to_barcode"; + + /** + *下发木箱层数 + */ + private String item_to_layer = "to_layer"; + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/ItemProtocol.java new file mode 100644 index 0000000..45549be --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/ItemProtocol.java @@ -0,0 +1,186 @@ +package org.nl.acs.device_driver.one_manipulator.box_storage_manipulator; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + /** + * 心跳 + */ + public static String item_heartbeat = "heartbeat"; + /** + * 工作模式 + */ + public static String item_mode = "mode"; + /** + * 光电信号 + */ + public static String item_move = "move"; + /** + * 动作信号 + */ + public static String item_action = "action"; + + /** + * 任务号 + */ + public static String item_task = "task"; + /** + * 报警 + */ + public static String item_error = "error"; + /** + * 行走列 + */ + public static String item_walk_y = "walk_y"; + + + /** + * 下发命令 + */ + 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_to_onset = "to_onset"; + + /** + *木箱长度 + */ + public static String item_to_length = "to_length"; + /** + *木箱宽度 + */ + public static String item_to_weight = "to_weight"; + /** + *木箱高度 + */ + public static String item_to_height = "to_height"; + + /** + *下发木箱条码 + */ + public static String item_to_barcode = "to_barcode"; + + /** + *下发木箱层数 + */ + public static String item_to_layer = "to_layer"; + + private BoxStorageManipulatorDeviceDriver driver; + + public ItemProtocol(BoxStorageManipulatorDeviceDriver driver){ + this.driver=driver; + } + + public int getTo_onset() { + return this.getOpcIntegerValue(item_to_onset); + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + + public int getWalk_y() { + return this.getOpcIntegerValue(item_walk_y); + } + + + + public int getTo_task() { + return this.getOpcIntegerValue(item_to_task); + } + + public int getTo_layer() { + return this.getOpcIntegerValue(item_to_layer); + } + + public int getTo_barcode() { + return this.getOpcIntegerValue(item_to_barcode); + } + + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_target() { + return this.getOpcIntegerValue(item_to_target); + } + + + + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList<>(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB1.B1")); + list.add(new ItemDto(item_move, "光电信号", "DB1.B2")); + list.add(new ItemDto(item_action, "动作信号", "DB1.B3")); + list.add(new ItemDto(item_error, "报警信号", "DB1.B5")); + list.add(new ItemDto(item_task, "任务号", "DB1.D6")); + list.add(new ItemDto(item_walk_y, "行走列", "DB1.B4")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList<>(); + list.add(new ItemDto(item_to_command, "下发命令", "DB2.W0")); + list.add(new ItemDto(item_to_target, "下发目标站", "DB2.W4")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB2.D6")); + list.add(new ItemDto(item_to_onset, "下发起始站", "DB2.W2")); + list.add(new ItemDto(item_to_length, "木箱长度", "DB601.W14")); + list.add(new ItemDto(item_to_weight, "木箱宽度", "DB601.W16")); + list.add(new ItemDto(item_to_height, "木箱高度", "DB601.W18")); + return list; + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ItemProtocol.java new file mode 100644 index 0000000..03545c6 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ItemProtocol.java @@ -0,0 +1,161 @@ +package org.nl.acs.device_driver.one_manipulator.return_good_manipulator; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + /** + * 心跳 + */ + public static String item_heartbeat = "heartbeat"; + /** + * 工作模式 + */ + public static String item_mode = "mode"; + /** + * 光电信号 + */ + public static String item_move = "move"; + /** + * 动作信号 + */ + public static String item_action = "action"; + + /** + * 任务号 + */ + public static String item_task = "task"; + /** + * 报警 + */ + public static String item_error = "error"; + /** + * 行走列 + */ + public static String item_walk_y = "walk_y"; + + /** + * 下发托盘类型 + */ + public static String item_to_container_type = "to_container_type"; + + + /** + * 下发命令 + */ + 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_to_onset = "to_onset"; + + + private ReturnGoodManipulatorDeviceDriver driver; + + public ItemProtocol(ReturnGoodManipulatorDeviceDriver driver){ + this.driver=driver; + } + + public int getTo_onset() { + return this.getOpcIntegerValue(item_to_onset); + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + + public int getWalk_y() { + return this.getOpcIntegerValue(item_walk_y); + } + + + + public int getTo_task() { + return this.getOpcIntegerValue(item_to_task); + } + + + + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_target() { + return this.getOpcIntegerValue(item_to_target); + } + + + + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList<>(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB1.B1")); + list.add(new ItemDto(item_move, "光电信号", "DB1.B2")); + list.add(new ItemDto(item_action, "动作信号", "DB1.B3")); + list.add(new ItemDto(item_error, "报警信号", "DB1.B5")); + list.add(new ItemDto(item_task, "任务号", "DB1.D6")); + list.add(new ItemDto(item_walk_y, "行走列", "DB1.B4")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList<>(); + list.add(new ItemDto(item_to_command, "下发命令", "DB2.W0")); + list.add(new ItemDto(item_to_target, "下发目标站", "DB2.W4")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB2.D6")); + list.add(new ItemDto(item_to_onset, "下发起始站", "DB2.W2")); + list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB102.B8")); + return list; + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDefination.java new file mode 100644 index 0000000..483f2bb --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDefination.java @@ -0,0 +1,56 @@ +package org.nl.acs.device_driver.one_manipulator.return_good_manipulator; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.enums.DeviceType; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +@Service +public class ReturnGoodManipulatorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "box_storage"; + } + + @Override + public String getDriverName() { + return "木箱入库行架"; + } + + @Override + public String getDriverDescription() { + return "木箱入库行架"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new ReturnGoodManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return ReturnGoodManipulatorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.robot); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDeviceDriver.java new file mode 100644 index 0000000..cdf1e6a --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDeviceDriver.java @@ -0,0 +1,477 @@ +package org.nl.acs.device_driver.one_manipulator.return_good_manipulator; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.common.base.CommonFinalParam; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.service.DeviceExtraService; +import org.nl.acs.device.service.impl.DeviceExtraServiceImpl; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.FeedLmsRealFailed; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.box_manipulator_site.BoxManipulatorSiteDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.history.ErrorUtil; +import org.nl.acs.history.service.DeviceErrorLogService; +import org.nl.acs.history.service.impl.DeviceErrorLogServiceImpl; +import org.nl.acs.instruction.domain.Instruction; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.DeviceAppServiceImpl; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.impl.RouteLineServiceImpl; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.config.SpringContextHolder; + +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 木箱入库行架 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class ReturnGoodManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed { + + protected ItemProtocol itemProtocol = new ItemProtocol(this); + + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + + DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); + + DeviceExtraService deviceExtraService = SpringContextHolder.getBean(DeviceExtraServiceImpl.class); + + DeviceErrorLogService errorLogServer = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class); + + + int mode = 0; + int last_mode = 0; + int move = 0; + int last_move = 0; + int action = 0; + int last_action = 0; + int error = 0; + int last_error = 0; + int task = 0; + int last_task = 0; + + + int heartbeat = 0; + int last_heartbeat = 0; + int to_command = 0; + int last_to_command = 0; + + int to_target = 0; + int last_to_target = 0; + + int to_onset = 0; + int last_to_onset = 0; + + int to_task = 0; + int last_to_task = 0; + int to_layer = 0; + int last_to_layer = 0; + int to_barcode = 0; + int last_to_barcode = 0; + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + private Date instruction_update_time = new Date(); + private int instruction_update_time_out = 1000; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + + private int instruction_require_time_out = 3000; + //行架机械手申请任务成功标识 + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + private String error_type = "hxhj_error_type"; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String device_code; + + //当前指令 + Instruction inst = null; + + //0 无任务执行 1更新指令状态 2下发电气信号 3允许取货 允许放货 5放货完成 + int now_steps_type = 0; + String notCreateTaskMessage = ""; + String notCreateInstMessage = ""; + String feedMessage = ""; + + + List getDeviceCodeList = null; + + List putDeviceCodeList = null; + + + @Override + public Device getDevice() { + return this.device; + } + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + move = this.itemProtocol.getMove(); + action = this.itemProtocol.getAction(); + error = this.itemProtocol.getError(); + task = this.itemProtocol.getTask(); + heartbeat = this.itemProtocol.getHeartbeat(); + to_command = this.itemProtocol.getTo_command(); + to_target = this.itemProtocol.getTo_target(); + to_onset = this.itemProtocol.getTo_onset(); + to_task = this.itemProtocol.getTo_task(); + if (mode != last_mode) { + requireSucess = false; + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); + } + if (action != last_action) { + logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); + } + if (to_command != last_to_command) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); + } + if (to_target != last_to_target) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); + } + if (to_onset != last_to_onset) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_onset:" + last_to_target + "->" + to_target); + } + if (to_task != last_to_task) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); + } + + + // 更新指令状态 + if (mode == 3 && task > 0) { + updateInstructionStatus(); + } + + } catch (Exception var17) { + var17.printStackTrace(); + feedMessage = var17.getMessage(); + logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol)); + + } + + if (mode == 0) { + this.setIsonline(false); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + + //行架机械手申请任务 + if (mode == 2 && move == 0 && task == 0 && !requireSucess) { + boolean res = applyTask(); + if (res) { + notCreateInstMessage = ""; + notCreateTaskMessage = ""; + feedMessage = ""; + } + } else { + String remark = "未查找任务原因为:"; + if (mode != 2) { + remark = remark + "工作模式(mode)不是待机状态,"; + } + if (move != 0) { + remark = remark + "光电信号(move)为有货状态,"; + } + if (task != 0) { + remark = remark + "当前上报任务号(task)应该为0,"; + if (ObjectUtil.isNotEmpty(this.inst)) { + this.inst = null; + } + } + if (requireSucess) { + remark = remark + "请右击该图标,将请求任务复位标记(requireSucess)改为否。"; + } + this.setNotCreateTaskMessage(remark); + } + + } + last_mode = mode; + last_move = move; + last_action = action; + last_error = error; + last_task = task; + last_heartbeat = heartbeat; + last_to_task = to_task; + last_to_command = to_command; + last_to_target = to_target; + last_to_layer = to_layer; + last_to_barcode = to_barcode; + + } + + private void updateInstructionStatus() { + Date date = new Date(); + if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); + + } else { + this.instruction_update_time = date; + //更改指令状态 + if (task > 0) { + Instruction inst = checkInst(); + if (inst != null) { + if (StrUtil.equals(inst.getInstruction_status(), "0")) { + inst.setInstruction_status(CommonFinalParam.ONE); + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + } + } + } + } + } + + public synchronized boolean applyTask() { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + BoxManipulatorSiteDeviceDriver boxManipulatorSiteDeviceDriver = new BoxManipulatorSiteDeviceDriver(); + String deviceCode = boxManipulatorSiteDeviceDriver.getDevice_code(); + TaskDto taskDto = taskserver.findByEndCodeAndReady(deviceCode); + if (ObjectUtil.isNotEmpty(taskDto)) { + String start_device_code = taskDto.getStart_device_code(); + String next_device_code = taskDto.getNext_device_code(); + Device startDevice = deviceAppService.findDeviceByCode(start_device_code); + Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); + String start_addr = startDevice.getExtraValue().get("address").toString(); + String next_addr = nextDevice.getExtraValue().get("address").toString(); + String taskid = taskDto.getTask_id(); + String taskcode = taskDto.getTask_code(); + String start_point_code = taskDto.getStart_point_code(); + String route_plan_code = taskDto.getRoute_plan_code(); + String next_point_code = taskDto.getNext_point_code(); + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(device_code); + + try { + instructionService.create(instdto); + } catch (Exception e) { + notCreateInstMessage = e.getMessage(); + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); + return false; + } + logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() + + ",指令终点:" + instdto.getNext_device_code() ); + + + Map map = new LinkedHashMap<>(); + map.put("to_command", 1); + map.put("to_target", next_addr); + map.put("to_onset", start_addr); + map.put("to_task", instdto.getInstruction_code()); + + + + try { + this.writing(map); + } catch (Exception e) { + logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() + + ",指令终点:" + instdto.getNext_device_code() + ",指令执行失败:" + e.getMessage()); + } + this.setRequireSucess(true); + return true; + } else { + notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; + } + return true; + } + + } + + /** + * 下发 + * @param map + */ + public void writing(Map map) { + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + Map itemMap = new LinkedHashMap<>(); + map.forEach((key, value) -> { + if (ObjectUtil.isNotEmpty(value)) { + itemMap.put(getToParam() + key, value); + } + }); + if (ObjectUtil.isNotEmpty(itemMap)) { + try { + this.checkcontrol(itemMap); + } catch (Exception e) { + throw new RuntimeException(e); + } + logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); + } + } + + /** + * 抽取统一下发电气信号前缀 + * + * @return + */ + public String getToParam() { + return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; + } + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + String mode = ""; + String move = ""; + String action = ""; + String walk_y = ""; + if (this.getMode() == 0) { + mode = "脱机"; + } else if (this.getMode() == 1) { + mode = "单机"; + } else if (this.getMode() == 2) { + mode = "待机"; + } else if (this.getMode() == 3) { + mode = "运行中"; + } + + if (this.getMove() == 0) { + move = "无货"; + } else if (this.getMove() == 1) { + move = "有货"; + } + + String requireSucess = "0"; + if (this.requireSucess) { + requireSucess = "1"; + } + jo.put("requireSucess", requireSucess); + if (this.getAction() == 1) { + action = "取货中"; + } else if (this.getAction() == 2) { + action = "取货完成"; + } else if (this.getAction() == 3) { + action = "放货中"; + } else if (this.getAction() == 4) { + action = "放货完成"; + } + + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("mode", mode); + jo.put("move", move); + jo.put("action", action); + jo.put("task", task); + jo.put("isOnline", this.getIsonline()); + jo.put("error", this.getError()); + jo.put("isError", this.getIserror()); + jo.put("message", this.getMessage()); + jo.put("notCreateTaskMessage", notCreateTaskMessage); + jo.put("notCreateInstMessage", notCreateInstMessage); + jo.put("feedMessage", feedMessage); + jo.put("driver_type", "siemens_conveyor"); + jo.put("is_click", true); + return jo; + } + + @Override + public void setDeviceStatus(JSONObject data) { + String requestSucess = data.getString("requireSucess"); + if (StrUtil.equals(requestSucess, "0")) { + this.requireSucess = false; + } else if (StrUtil.equals(requestSucess, "1")) { + this.requireSucess = true; + } + } + + @Override + public JSONObject feedLmsRealFailedInfo() { + JSONObject jo = new JSONObject(); + jo.put("device_code", this.getDevice().getDevice_code()); + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("fault_code", String.valueOf(error)); + jo.put("fault_info", ErrorUtil.getDictDetail(error_type, String.valueOf(this.getError()))); + jo.put("fault_type", error_type); + return jo; + } + + + public Instruction checkInst() { + if (ObjectUtil.isNotEmpty(this.inst)) { + if (this.task > 0) { + if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) { + return this.inst; + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + } + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + return null; + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/InteractionJsonDTO.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/InteractionJsonDTO.java new file mode 100644 index 0000000..d9feac1 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/InteractionJsonDTO.java @@ -0,0 +1,27 @@ +package org.nl.acs.device_driver.one_manipulator.trapped_manipulator; + +import lombok.Data; + +@Data +public class InteractionJsonDTO { + + /** + *木箱长度 + */ + private String item_to_length = "to_length"; + /** + *木箱宽度 + */ + private String item_to_weight = "to_weight"; + /** + *木箱高度 + */ + private String item_to_height = "to_height"; + + /** + *下发堆叠模板 + */ + private String item_to_template = "to_template"; + + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/ItemProtocol.java new file mode 100644 index 0000000..962bf67 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/ItemProtocol.java @@ -0,0 +1,179 @@ +package org.nl.acs.device_driver.one_manipulator.trapped_manipulator; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + /** + * 心跳 + */ + public static String item_heartbeat = "heartbeat"; + /** + * 工作模式 + */ + public static String item_mode = "mode"; + /** + * 光电信号 + */ + public static String item_move = "move"; + /** + * 动作信号 + */ + public static String item_action = "action"; + + /** + * 任务号 + */ + public static String item_task = "task"; + /** + * 报警 + */ + public static String item_error = "error"; + + + /** + * 下发托盘类型 + */ + public static String item_to_container_type = "to_container_type"; + + + /** + * 下发命令 + */ + 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_to_onset = "to_onset"; + + /** + *木箱长度 + */ + public static String item_to_length = "to_length"; + /** + *木箱宽度 + */ + public static String item_to_weight = "to_weight"; + /** + *木箱高度 + */ + public static String item_to_height = "to_height"; + + + /** + *下发堆叠模板 + */ + public static String item_to_template = "to_template"; + + + + + private TrappedManipulatorManipulatorDeviceDriver driver; + + public ItemProtocol(TrappedManipulatorManipulatorDeviceDriver driver){ + this.driver=driver; + } + + public int getTo_onset() { + return this.getOpcIntegerValue(item_to_onset); + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + + + + + public int getTo_task() { + return this.getOpcIntegerValue(item_to_task); + } + + + + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_target() { + return this.getOpcIntegerValue(item_to_target); + } + + + + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList<>(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB1.B1")); + list.add(new ItemDto(item_move, "光电信号", "DB1.B2")); + list.add(new ItemDto(item_action, "动作信号", "DB1.B3")); + list.add(new ItemDto(item_error, "报警信号", "DB1.B5")); + list.add(new ItemDto(item_task, "任务号", "DB1.D6")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList<>(); + list.add(new ItemDto(item_to_command, "下发命令", "DB2.W0")); + list.add(new ItemDto(item_to_target, "下发目标站", "DB2.W4")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB2.D6")); + list.add(new ItemDto(item_to_onset, "下发起始站", "DB2.W2")); + list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB102.B8")); + list.add(new ItemDto(item_to_length, "木箱长度", "DB601.W10")); + list.add(new ItemDto(item_to_weight, "木箱宽度", "DB601.W12")); + list.add(new ItemDto(item_to_height, "木箱高度", "DB601.W14")); + list.add(new ItemDto(item_to_template, "堆叠模板", "DB601.W16")); + return list; + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorDefination.java new file mode 100644 index 0000000..b6365b2 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorDefination.java @@ -0,0 +1,56 @@ +package org.nl.acs.device_driver.one_manipulator.trapped_manipulator; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.enums.DeviceType; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +@Service +public class TrappedManipulatorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "trapped_manipulator"; + } + + @Override + public String getDriverName() { + return "捆扎智能行架"; + } + + @Override + public String getDriverDescription() { + return "捆扎智能行架"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new TrappedManipulatorManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return TrappedManipulatorManipulatorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.robot); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorManipulatorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorManipulatorDeviceDriver.java new file mode 100644 index 0000000..405323c --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorManipulatorDeviceDriver.java @@ -0,0 +1,492 @@ +package org.nl.acs.device_driver.one_manipulator.trapped_manipulator; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.common.base.CommonFinalParam; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.service.DeviceExtraService; +import org.nl.acs.device.service.impl.DeviceExtraServiceImpl; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.FeedLmsRealFailed; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.box_manipulator_site.BoxManipulatorSiteDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.history.ErrorUtil; +import org.nl.acs.history.service.DeviceErrorLogService; +import org.nl.acs.history.service.impl.DeviceErrorLogServiceImpl; +import org.nl.acs.instruction.domain.Instruction; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.DeviceAppServiceImpl; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.impl.RouteLineServiceImpl; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.config.SpringContextHolder; + +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 捆扎智能行架 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class TrappedManipulatorManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed { + + protected ItemProtocol itemProtocol = new ItemProtocol(this); + + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + + DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); + + DeviceExtraService deviceExtraService = SpringContextHolder.getBean(DeviceExtraServiceImpl.class); + + DeviceErrorLogService errorLogServer = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class); + + + int mode = 0; + int last_mode = 0; + int move = 0; + int last_move = 0; + int action = 0; + int last_action = 0; + int error = 0; + int last_error = 0; + int task = 0; + int last_task = 0; + + + int heartbeat = 0; + int last_heartbeat = 0; + int to_command = 0; + int last_to_command = 0; + + int to_target = 0; + int last_to_target = 0; + + int to_onset = 0; + int last_to_onset = 0; + + int to_task = 0; + int last_to_task = 0; + int to_layer = 0; + int last_to_layer = 0; + int to_barcode = 0; + int last_to_barcode = 0; + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + private Date instruction_update_time = new Date(); + private int instruction_update_time_out = 1000; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + + private int instruction_require_time_out = 3000; + //行架机械手申请任务成功标识 + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + private String error_type = "hxhj_error_type"; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String device_code; + + //当前指令 + Instruction inst = null; + + //0 无任务执行 1更新指令状态 2下发电气信号 3允许取货 允许放货 5放货完成 + int now_steps_type = 0; + String notCreateTaskMessage = ""; + String notCreateInstMessage = ""; + String feedMessage = ""; + + + List getDeviceCodeList = null; + + List putDeviceCodeList = null; + + + @Override + public Device getDevice() { + return this.device; + } + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + move = this.itemProtocol.getMove(); + action = this.itemProtocol.getAction(); + error = this.itemProtocol.getError(); + task = this.itemProtocol.getTask(); + heartbeat = this.itemProtocol.getHeartbeat(); + to_command = this.itemProtocol.getTo_command(); + to_target = this.itemProtocol.getTo_target(); + to_onset = this.itemProtocol.getTo_onset(); + to_task = this.itemProtocol.getTo_task(); + if (mode != last_mode) { + requireSucess = false; + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); + } + if (action != last_action) { + logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); + } + if (to_command != last_to_command) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); + } + if (to_target != last_to_target) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); + } + if (to_onset != last_to_onset) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_onset:" + last_to_target + "->" + to_target); + } + if (to_task != last_to_task) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); + } + + + // 更新指令状态 + if (mode == 3 && task > 0) { + updateInstructionStatus(); + } + + } catch (Exception var17) { + var17.printStackTrace(); + feedMessage = var17.getMessage(); + logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol)); + + } + + if (mode == 0) { + this.setIsonline(false); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + + //行架机械手申请任务 + if (mode == 2 && move == 0 && task == 0 && !requireSucess) { + boolean res = applyTask(); + if (res) { + notCreateInstMessage = ""; + notCreateTaskMessage = ""; + feedMessage = ""; + } + } else { + String remark = "未查找任务原因为:"; + if (mode != 2) { + remark = remark + "工作模式(mode)不是待机状态,"; + } + if (move != 0) { + remark = remark + "光电信号(move)为有货状态,"; + } + if (task != 0) { + remark = remark + "当前上报任务号(task)应该为0,"; + if (ObjectUtil.isNotEmpty(this.inst)) { + this.inst = null; + } + } + if (requireSucess) { + remark = remark + "请右击该图标,将请求任务复位标记(requireSucess)改为否。"; + } + this.setNotCreateTaskMessage(remark); + } + + } + last_mode = mode; + last_move = move; + last_action = action; + last_error = error; + last_task = task; + last_heartbeat = heartbeat; + last_to_task = to_task; + last_to_command = to_command; + last_to_target = to_target; + last_to_layer = to_layer; + last_to_barcode = to_barcode; + + } + + private void updateInstructionStatus() { + Date date = new Date(); + if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); + + } else { + this.instruction_update_time = date; + //更改指令状态 + if (task > 0) { + Instruction inst = checkInst(); + if (inst != null) { + if (StrUtil.equals(inst.getInstruction_status(), "0")) { + inst.setInstruction_status(CommonFinalParam.ONE); + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + } + } + } + } + } + + public synchronized boolean applyTask() { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + + BoxManipulatorSiteDeviceDriver boxManipulatorSiteDeviceDriver = new BoxManipulatorSiteDeviceDriver(); + String deviceCode = boxManipulatorSiteDeviceDriver.getDevice_code(); + TaskDto taskDto = taskserver.findByEndCodeAndReady(deviceCode); + String interactionJson = taskDto.getInteraction_json(); + InteractionJsonDTO interactionJsonDTO = JSON.parseObject(interactionJson, InteractionJsonDTO.class); + if (ObjectUtil.isNotEmpty(taskDto)) { + String start_device_code = taskDto.getStart_device_code(); + String next_device_code = taskDto.getNext_device_code(); + Device startDevice = deviceAppService.findDeviceByCode(start_device_code); + Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); + String start_addr = startDevice.getExtraValue().get("address").toString(); + String next_addr = nextDevice.getExtraValue().get("address").toString(); + String taskid = taskDto.getTask_id(); + String taskcode = taskDto.getTask_code(); + String start_point_code = taskDto.getStart_point_code(); + String route_plan_code = taskDto.getRoute_plan_code(); + String next_point_code = taskDto.getNext_point_code(); + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(device_code); + + try { + instructionService.create(instdto); + } catch (Exception e) { + notCreateInstMessage = e.getMessage(); + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); + return false; + } + logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() + + ",指令终点:" + instdto.getNext_device_code() ); + + + Map map = new LinkedHashMap<>(); + map.put("to_command", 1); + map.put("to_target", next_addr); + map.put("to_onset", start_addr); + map.put("to_task", instdto.getInstruction_code()); + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_weight())) { + map.put("to_wedth", interactionJsonDTO.getItem_to_weight()); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_length())) { + map.put("to_length", interactionJsonDTO.getItem_to_length()); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_height())) { + map.put("to_height", interactionJsonDTO.getItem_to_height()); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_template())) { + map.put("to_template", interactionJsonDTO.getItem_to_template()); + } + + + try { + this.writing(map); + } catch (Exception e) { + logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() + + ",指令终点:" + instdto.getNext_device_code() + ",指令执行失败:" + e.getMessage()); + } + this.setRequireSucess(true); + return true; + } else { + notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; + } + return true; + } + + } + + /** + * 下发 + * @param map + */ + public void writing(Map map) { + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + Map itemMap = new LinkedHashMap<>(); + map.forEach((key, value) -> { + if (ObjectUtil.isNotEmpty(value)) { + itemMap.put(getToParam() + key, value); + } + }); + if (ObjectUtil.isNotEmpty(itemMap)) { + try { + this.checkcontrol(itemMap); + } catch (Exception e) { + throw new RuntimeException(e); + } + logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); + } + } + + /** + * 抽取统一下发电气信号前缀 + * + * @return + */ + public String getToParam() { + return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; + } + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + String mode = ""; + String move = ""; + String action = ""; + String walk_y = ""; + if (this.getMode() == 0) { + mode = "脱机"; + } else if (this.getMode() == 1) { + mode = "单机"; + } else if (this.getMode() == 2) { + mode = "待机"; + } else if (this.getMode() == 3) { + mode = "运行中"; + } + + if (this.getMove() == 0) { + move = "无货"; + } else if (this.getMove() == 1) { + move = "有货"; + } + + String requireSucess = "0"; + if (this.requireSucess) { + requireSucess = "1"; + } + jo.put("requireSucess", requireSucess); + if (this.getAction() == 1) { + action = "取货中"; + } else if (this.getAction() == 2) { + action = "取货完成"; + } else if (this.getAction() == 3) { + action = "放货中"; + } else if (this.getAction() == 4) { + action = "放货完成"; + } + + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("mode", mode); + jo.put("move", move); + jo.put("action", action); + jo.put("task", task); + jo.put("isOnline", this.getIsonline()); + jo.put("error", this.getError()); + jo.put("isError", this.getIserror()); + jo.put("message", this.getMessage()); + jo.put("notCreateTaskMessage", notCreateTaskMessage); + jo.put("notCreateInstMessage", notCreateInstMessage); + jo.put("feedMessage", feedMessage); + jo.put("driver_type", "siemens_conveyor"); + jo.put("is_click", true); + return jo; + } + + @Override + public void setDeviceStatus(JSONObject data) { + String requestSucess = data.getString("requireSucess"); + if (StrUtil.equals(requestSucess, "0")) { + this.requireSucess = false; + } else if (StrUtil.equals(requestSucess, "1")) { + this.requireSucess = true; + } + } + + @Override + public JSONObject feedLmsRealFailedInfo() { + JSONObject jo = new JSONObject(); + jo.put("device_code", this.getDevice().getDevice_code()); + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("fault_code", String.valueOf(error)); + jo.put("fault_info", ErrorUtil.getDictDetail(error_type, String.valueOf(this.getError()))); + jo.put("fault_type", error_type); + return jo; + } + + + public Instruction checkInst() { + if (ObjectUtil.isNotEmpty(this.inst)) { + if (this.task > 0) { + if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) { + return this.inst; + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + } + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + return null; + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/rgv/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/rgv/ItemProtocol.java index f2e9b51..824ee20 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/rgv/ItemProtocol.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/rgv/ItemProtocol.java @@ -9,7 +9,8 @@ import java.util.List; @Slf4j @Data -public class ItemProtocol { +public class +ItemProtocol { //心跳 public static String item_heartbeat = "heartbeat"; diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index 7db35fe..36f394d 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -10,7 +10,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.device.domain.Device; import org.nl.acs.device_driver.blank_manipulator.BlankManipulatorDeviceDriver; -import org.nl.acs.device_driver.box_manipulator.BoxManipulatorDeviceDriver; +import org.nl.acs.device_driver.one_manipulator.box_package_manipulator.BoxPackageManipulatorDeviceDriver; import org.nl.acs.device_driver.conveyor.box_palletizing_manipulator.BoxPalletizingManipulatorDeviceDriver; import org.nl.acs.device_driver.manipulator.standard_manipulator.OvenGantryManipulatorDeviceDriver; import org.nl.acs.device_driver.paper_tube_device2.PaperTubeConveyor2DeviceDriver; @@ -88,7 +88,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { //烘箱行架机械手 OvenGantryManipulatorDeviceDriver ovenGantryManipulatorDeviceDriver; //装箱行架机械手 - BoxManipulatorDeviceDriver boxManipulatorDeviceDriver; + BoxPackageManipulatorDeviceDriver boxManipulatorDeviceDriver; //木箱码垛机械手 BoxPalletizingManipulatorDeviceDriver boxPalletizingManipulatorDeviceDriver; //纸管库2 @@ -142,8 +142,8 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { jo.put("walk_y", ovenGantryManipulatorDeviceDriver.getWalk_y()); jo.put("task", ovenGantryManipulatorDeviceDriver.getTask()); jo.put("error", ovenGantryManipulatorDeviceDriver.getError()); - } else if (device.getDeviceDriver() instanceof BoxManipulatorDeviceDriver) { - boxManipulatorDeviceDriver = (BoxManipulatorDeviceDriver) device.getDeviceDriver(); + } else if (device.getDeviceDriver() instanceof BoxPackageManipulatorDeviceDriver) { + boxManipulatorDeviceDriver = (BoxPackageManipulatorDeviceDriver) device.getDeviceDriver(); jo.put("device_code", boxManipulatorDeviceDriver.getDevice().getDevice_code()); jo.put("device_name", boxManipulatorDeviceDriver.getDevice().getDevice_name()); jo.put("status", Math.min(3, boxManipulatorDeviceDriver.getMode())); diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index 1cf9ef8..dc33d3a 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -205,6 +205,7 @@ public class InstructionServiceImpl extends CommonServiceImpl insPage = instructionMapper.selectPage(queryPage, wrapper); final JSONObject json = (JSONObject) JSON.toJSON(ConvertUtil.convertPage(insPage, InstructionDto.class)); return json; diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/service/impl/OpcServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/service/impl/OpcServiceImpl.java index af9d9c6..9074a70 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/service/impl/OpcServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/service/impl/OpcServiceImpl.java @@ -134,6 +134,7 @@ public class OpcServiceImpl extends CommonServiceImpl implements if (whereJson.get(BLURRY) != null) { wrapper.like(Opc::getOpc_code, whereJson.get("blurry")).or().like(Opc::getOpc_name, whereJson.get("blurry")).or().like(Opc::getOpc_host, whereJson.get("blurry")); } + wrapper.orderByDesc(Opc::getCreate_time); IPage opcPage = opcMapper.selectPage(queryPage, wrapper); final JSONObject json = (JSONObject) JSON.toJSON(ConvertUtil.convertPage(opcPage, OpcDto.class)); JSONArray newja = new JSONArray(); diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/domain/Task.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/domain/Task.java index 98826d6..a09862b 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/domain/Task.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/domain/Task.java @@ -233,6 +233,9 @@ public class Task extends CommonModel implements Serializable { @ApiModelProperty(value = "时间") private String oven_time; + @ApiModelProperty(value = "交互字段") + private String interaction_json; + public void copyFrom(Task source) { BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/enums/TaskTypeEnum.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/enums/TaskTypeEnum.java index b5711cf..57eba11 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/enums/TaskTypeEnum.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/enums/TaskTypeEnum.java @@ -25,7 +25,8 @@ public enum TaskTypeEnum { Inner_Truss_Task("9", "9", "内包间行架任务"), - Stacker_Task("11", "11", "堆垛机任务"); + Stacker_Task("11", "11", "堆垛机任务"), + Box_Storage("12", "12", "木箱入库任务"); /** * 索引 diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java index af234e9..6f67e63 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java @@ -404,6 +404,15 @@ public interface TaskService extends CommonService { TaskDto findByStartCodeAndReady(String device_code); + /** + * 根据终点设备编号查询当前是否有就绪任务 + * + * @param device_code + * @return + */ + TaskDto findByEndCodeAndReady(String device_code); + + /** * 查询内存任务 * diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/dto/TaskDto.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/dto/TaskDto.java index 0679a1a..e8c46d6 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/dto/TaskDto.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/dto/TaskDto.java @@ -302,6 +302,8 @@ public class TaskDto implements Serializable { * 烘箱温度 */ private String temperature; - - + /** + * 交互字段 + */ + private String interaction_json; } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java index 31cbaee..f933898 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java @@ -161,6 +161,7 @@ public class TaskFeedbackServiceImpl extends CommonServiceImpl queryPage = PageUtil.toMybatisPage(page); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(TaskFeedback::getIs_finished, "0"); + wrapper.orderByDesc(TaskFeedback::getCreate_time); IPage tfPage = taskFeedbackMapper.selectPage(queryPage, wrapper); final JSONObject json = (JSONObject) JSON.toJSON(ConvertUtil.convertPage(tfPage, TaskFeedbackDto.class)); return json; diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index a308442..054e92e 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -244,6 +244,7 @@ public class TaskServiceImpl extends CommonServiceImpl impleme } } wrapper.le(Task::getTask_status, 1); + wrapper.orderByDesc(Task::getCreate_time); IPage taskPage = taskMapper.selectPage(queryPage, wrapper); final JSONObject json = (JSONObject) JSON.toJSON(ConvertUtil.convertPage(taskPage, TaskDto.class)); return json; @@ -1372,6 +1373,28 @@ public class TaskServiceImpl extends CommonServiceImpl impleme return null; } + + + @Override + public TaskDto findByEndCodeAndReady(String device_code) { + Iterator var3 = tasks.iterator(); + + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + // if (!StrUtil.equals(task.getTask_type(), "5")) { + // continue; + // } + if (StrUtil.equals(task.getNext_device_code(), device_code) + && StrUtil.equals(task.getTask_status(), TaskStatusEnum.READY.getIndex())) { + return task; + } + } + return null; + } + + + + @Override public TaskDto findByStartCode(String device_code) { Iterator var3 = tasks.iterator(); diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/config/ConfigurerAdapter.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/config/ConfigurerAdapter.java index d9aa6eb..eeee128 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/config/ConfigurerAdapter.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/config/ConfigurerAdapter.java @@ -49,4 +49,16 @@ public class ConfigurerAdapter implements WebMvcConfigurer { registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0); registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0); } + + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + config.addAllowedOrigin("*"); + config.addAllowedHeader("*"); + config.addAllowedMethod("*"); + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); + } } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/config/saconfig/CorsFilter.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/config/saconfig/CorsFilter.java index cc2e734..9a67267 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/config/saconfig/CorsFilter.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/config/saconfig/CorsFilter.java @@ -1,56 +1,56 @@ -package org.nl.config.saconfig; - -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; -import org.springframework.web.cors.CorsConfiguration; - -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -/** - * 跨域过滤器 - * @author kong - */ -@Component -@Order(-200) -public class CorsFilter implements Filter { - - static final String OPTIONS = "OPTIONS"; - - @Override - public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) - throws IOException, ServletException { - HttpServletRequest request = (HttpServletRequest) req; - HttpServletResponse response = (HttpServletResponse) res; - // 允许指定域访问跨域资源 - response.setHeader("Access-Control-Allow-Origin", "*"); - // 允许所有请求方式 - response.setHeader("Access-Control-Allow-Methods", "*"); - // 有效时间 - response.setHeader("Access-Control-Max-Age", "3600"); - // 允许的header参数 - response.setHeader("Access-Control-Allow-Headers", "*"); - response.setHeader("Access-Control-Allow-Credentials", "true"); - - // 如果是预检请求,直接返回 - if (OPTIONS.equals(request.getMethod())) { - System.out.println("=======================浏览器发来了OPTIONS预检请求=========="); - response.getWriter().print(""); - return; - } - - // System.out.println("*********************************过滤器被使用**************************"); - chain.doFilter(req, res); - } - - @Override - public void init(FilterConfig filterConfig) { - } - - @Override - public void destroy() { - } - -} +//package org.nl.config.saconfig; +// +//import org.springframework.core.annotation.Order; +//import org.springframework.stereotype.Component; +//import org.springframework.web.cors.CorsConfiguration; +// +//import javax.servlet.*; +//import javax.servlet.http.HttpServletRequest; +//import javax.servlet.http.HttpServletResponse; +//import java.io.IOException; +// +///** +// * 跨域过滤器 +// * @author kong +// */ +//@Component +//@Order(-200) +//public class CorsFilter implements Filter { +// +// static final String OPTIONS = "OPTIONS"; +// +// @Override +// public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) +// throws IOException, ServletException { +// HttpServletRequest request = (HttpServletRequest) req; +// HttpServletResponse response = (HttpServletResponse) res; +// // 允许指定域访问跨域资源 +// response.setHeader("Access-Control-Allow-Origin", "*"); +// // 允许所有请求方式 +// response.setHeader("Access-Control-Allow-Methods", "*"); +// // 有效时间 +// response.setHeader("Access-Control-Max-Age", "3600"); +// // 允许的header参数 +// response.setHeader("Access-Control-Allow-Headers", "*"); +// response.setHeader("Access-Control-Allow-Credentials", "true"); +// +// // 如果是预检请求,直接返回 +// if (OPTIONS.equals(request.getMethod())) { +// System.out.println("=======================浏览器发来了OPTIONS预检请求=========="); +// response.getWriter().print(""); +// return; +// } +// +// // System.out.println("*********************************过滤器被使用**************************"); +// chain.doFilter(req, res); +// } +// +// @Override +// public void init(FilterConfig filterConfig) { +// } +// +// @Override +// public void destroy() { +// } +// +//} diff --git a/acs/nladmin-ui/vue.config.js b/acs/nladmin-ui/vue.config.js index a881ad5..a319591 100644 --- a/acs/nladmin-ui/vue.config.js +++ b/acs/nladmin-ui/vue.config.js @@ -19,6 +19,8 @@ module.exports = { lintOnSave: process.env.NODE_ENV === 'development', productionSourceMap: false, devServer: { + allowedHosts: ['all'], + disableHostCheck: true, port: port, open: false, overlay: {