diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/AgvService.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/AgvService.java index 4ad0de55d..f45fa6cc5 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/AgvService.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/AgvService.java @@ -1,6 +1,7 @@ package org.nl.acs.agv.server; import org.nl.acs.agv.server.dto.AgvDto; +import org.nl.acs.instruction.domain.InstructionMybatis; import java.util.Map; diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/agv/ndctwo/AgvNdcTwoDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/agv/ndctwo/AgvNdcTwoDeviceDriver.java index 848bfedf6..e9af097f9 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/agv/ndctwo/AgvNdcTwoDeviceDriver.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/agv/ndctwo/AgvNdcTwoDeviceDriver.java @@ -24,6 +24,9 @@ import org.nl.acs.device_driver.two_conveyor.manipulator_agv_station.Manipulator import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; 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.service.InstructionService; import org.nl.acs.instruction.service.impl.InstructionServiceImpl; @@ -57,6 +60,7 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); + DeviceErrorLogService deviceErrorLogService = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class); DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class); LuceneExecuteLogService luceneExecuteLogService = SpringContextHolder.getBean(LuceneExecuteLogService.class); TwoAgvPhase twoAgvPhase = new TwoAgvPhase(); @@ -70,6 +74,7 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic int phase = 0; int region = 0; int error = 0; + int last_error = 0; private Instruction instruction; String message = null; int x = 0; //x坐标 @@ -218,10 +223,27 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); + if (ObjectUtil.isNotEmpty(device.getExtraValue().get("wait")) + && StrUtil.equals("true", device.getExtraValue().get("wait").toString()) + && StrUtil.equals(task.getTask_type(), "1")) { + if (standardOrdinarySiteDeviceDriver.getOption() == 1) { + String task_code = standardOrdinarySiteDeviceDriver.getTask_code(); + log.info("当前任务号{},创建任务号{}", task.getTask_code(), task_code); + if (StrUtil.isEmpty(task_code) || !task_code.equals(task.getTask_code())) { + log.info("等待LMS系统进行确认允许取货,设备号{},指令号{},任务号{}", device_code, ikey, task.getTask_code()); + message = "等待LMS系统进行确认允许取货,设备号:" + device_code + ",指令号:" + ikey; + logServer.deviceExecuteLog(this.device_code, "", "", "等待LMS系统进行确认允许取货,设备号" + device.getDevice_code() + ",指令号" + ikey); + } else { + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + } + }else { + log.info("等待LMS系统进行确认允许取货,设备号{},指令号{}", device_code, ikey); + message = "等待LMS系统进行确认允许取货,设备号:" + device_code + ",指令号:" + ikey; + logServer.deviceExecuteLog(this.device_code, "", "", "等待LMS系统进行确认允许取货,设备号" + device.getDevice_code() + ",指令号" + ikey); + } + }else { + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + } } else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); @@ -340,10 +362,15 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); + if (ObjectUtil.isNotEmpty(this.device.getExtraValue().get("wait")) + && StrUtil.equals("true", this.device.getExtraValue().get("wait").toString()) + && StrUtil.equals(task.getTask_type(), "1")) { + standardOrdinarySiteDeviceDriver.setOption(0); + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + }else { + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + } + this.setPhase(phase); } else if (device.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) { manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) device.getDeviceDriver(); @@ -455,10 +482,30 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic if (StrUtil.equals(agv_inst_type, CommonFinalParam.ONE) || StrUtil.equals(agv_inst_type, "3")) { if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); + if (ObjectUtil.isNotEmpty(standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait")) + && StrUtil.equals("true", standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait").toString()) + && StrUtil.equals(task.getTask_type(), "1")) { + if (standardOrdinarySiteDeviceDriver.getOption() == 1) { + standardOrdinarySiteDeviceDriver.setAgvphase(0); + String task_code = standardOrdinarySiteDeviceDriver.getTask_code(); + log.info("当前任务号{},创建任务号{}", task.getTask_code(), task_code); + if (StrUtil.isEmpty(task_code) || !task_code.equals(task.getTask_code())) { + log.info("等待LMS系统进行确认允许取货,设备号{},指令号{},任务号{}", device_code, ikey, task.getTask_code()); + message = "等待LMS系统进行确认允许取货,设备号:" + device_code + ",指令号:" + ikey; + logServer.deviceExecuteLog(this.device_code, "", "", "等待LMS系统进行确认允许取货,设备号" + device.getDevice_code() + ",指令号" + ikey); + } else { + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + } + } else { + log.info("等待LMS系统进行确认允许取货,设备号{},指令号{}", device_code, ikey); + message = "等待LMS系统进行确认允许取货,设备号:" + device_code + ",指令号:" + ikey; + logServer.deviceExecuteLog(this.device_code, "", "", "等待LMS系统进行确认允许取货,设备号" + device.getDevice_code()); + + } + }else { + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + } } else if (device.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) { manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) device.getDeviceDriver(); @@ -568,6 +615,13 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic if (StrUtil.equals(agv_inst_type, CommonFinalParam.ONE) || StrUtil.equals(agv_inst_type, "3")) { if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); + if (ObjectUtil.isNotEmpty(standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait")) + && StrUtil.equals("true", standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait").toString()) + && StrUtil.equals(task.getTask_type(), "1")) { + standardOrdinarySiteDeviceDriver.setOption(0); + }else { + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + } data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); standardOrdinarySiteDeviceDriver.setAgvphase(phase); standardOrdinarySiteDeviceDriver.setIndex(index); @@ -651,6 +705,14 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic weight = agvaddr; inst.setWeight(String.valueOf(weight)); instructionService.update(inst); + + if (ObjectUtil.isNotEmpty(task)) { + logServer.deviceExecuteLog(this.device_code, "", "", "上报满卷重量,weight:" + weight); + message = "上报满卷重量,weight:" + weight + ",指令号:" + ikey; + task.setWeight(String.valueOf(weight)); + task.setCarno(this.device_code); + taskService.update(task); + } data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); LuceneLogDto logDto = LuceneLogDto.builder() .device_code(device_code) @@ -817,9 +879,7 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic // data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); // } data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); + this.setPhase(phase); } else if (device.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) { manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) device.getDeviceDriver(); @@ -929,9 +989,7 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic // data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); // } data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); + this.setPhase(phase); } else if (device.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) { manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) device.getDeviceDriver(); @@ -1037,9 +1095,7 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic // data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); // } data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); + this.setPhase(phase); } else if (device.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) { manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) device.getDeviceDriver(); @@ -1130,32 +1186,10 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic last_status = status; } //进入区域(phase值) else if (phase == 0x50) { - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - region = agvaddr; - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - LuceneLogDto logDto = LuceneLogDto.builder() - .device_code(device_code) - .content("agvphase:" + phase + "反馈:" + data) - .build(); - luceneExecuteLogService.deviceExecuteLog(logDto); } //离开区域(phase值) else if (phase == 0x51) { - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - region = agvaddr; - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - LuceneLogDto logDto = LuceneLogDto.builder() - .device_code(device_code) - .content("agvphase:" + phase + "反馈:" + data) - .build(); - luceneExecuteLogService.deviceExecuteLog(logDto); } //上报异常信息 @@ -1170,11 +1204,23 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic String info = error.get("info"); this.setErrorInfo(ikey, code, info); } - LuceneLogDto logDto = LuceneLogDto.builder() - .device_code(device_code) - .content("agvphase:" + phase + "反馈:" + data) - .build(); - luceneExecuteLogService.deviceExecuteLog(logDto); + if (error != last_error) { + DeviceErrorLogDto dto = new DeviceErrorLogDto(); + dto.setDevice_code(this.getDevice().getDevice_code()); + dto.setError_code(String.valueOf(error_code)); + dto.setError_info(error_message); + deviceErrorLogService.create(dto); + + JSONObject param = new JSONObject(); + param.put("device_code", this.device_code); + param.put("error", error); + param.put("error_msg", error == 0 ? "" : this.getError_message()); + param.put("device_name", this.getDevice().getDevice_name()); + param.put("device_type", "4"); + param.put("product_area", ISysParamService.findByCode("productArea").getValue()); + acsToWmsService.sendDeviceStatus(param); + } + last_error = error; } if (!ObjectUtil.isEmpty(data)) { LuceneLogDto logDto = LuceneLogDto.builder() @@ -1183,11 +1229,14 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic .build(); luceneExecuteLogService.deviceExecuteLog(logDto); // if (StrUtil.equals(inst.getAgv_system_type(), "2")) { - TwoNDCSocketConnectionAutoRun.write(data); +// TwoNDCSocketConnectionAutoRun.write(data); // } // else if (StrUtil.equals(inst.getAgv_system_type(), "3")) { // TwoNDC2SocketConnectionAutoRun.write(data); // } + if (StrUtil.equals(inst.getAgv_system_type(), "2")) { + TwoNDCSocketConnectionAutoRun.write(data); + } } } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java index 88a1e4c00..1e438a7fd 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java @@ -1,6 +1,7 @@ package org.nl.acs.device_driver.conveyor.standard_ordinary_site; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.RequiredArgsConstructor; @@ -61,6 +62,9 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple Boolean iserror = false; Boolean islock = false; + // 1 上位系统允许进入 2 上位系统允许离开 + int option = 0; + int branchProtocol = 0; int last_branchProtocol = 0; /** @@ -223,6 +227,14 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple String mode = ""; String action = ""; String move = ""; + String option = ""; + if(this.getOption() == 0){ + option ="禁止进出"; + } else if(this.getOption() == 1){ + option ="允许进入"; + } else if(this.getOption() == 2){ + option ="允许离开"; + } if (this.getMode() == 0) { mode = LangProcess.msg("universal_off-line"); } else if (this.getMode() == 1) { @@ -252,13 +264,18 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple jo.put("isOnline", true); jo.put("error", this.getError()); jo.put("isError", this.getIserror()); + jo.put("option", option); + jo.put("is_click", true); return jo; } @Override public void setDeviceStatus(JSONObject data) { - + String flag = data.getString("option"); + if(StrUtil.isNotEmpty(flag)){ + option = Integer.parseInt(flag); + } } } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/dto/TaskDto.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/dto/TaskDto.java index 34855a6b5..b5a63553a 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/dto/TaskDto.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/dto/TaskDto.java @@ -54,6 +54,11 @@ public class TaskDto implements Serializable { */ private String task_status; + /** + * 车号 + */ + private String carno; + /** * 复合任务 */ diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index a4e562884..645951863 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -1007,6 +1007,7 @@ public class TaskServiceImpl extends CommonServiceImpl impleme map.put("路由方案编码", acsTask.getRoute_plan_code()); map.put("是否需要反馈上位系统", acsTask.getIs_needfeedback()); map.put("备注", acsTask.getRemark()); + map.put("agv车号", acsTask.getCarno()); map.put("是否启用", acsTask.getIs_active()); map.put("是否删除", acsTask.getIs_delete()); map.put("创建者", acsTask.getCreate_by()); @@ -1588,6 +1589,12 @@ public class TaskServiceImpl extends CommonServiceImpl impleme feed_jo.put("task_id", entity.getExt_task_id()); feed_jo.put("task_code", entity.getTask_code()); feed_jo.put("task_status", entity.getTask_status()); + if (ObjectUtil.isNotEmpty(entity.getWeight())) { + feed_jo.put("weight", entity.getWeight()); + } + if (ObjectUtil.isNotEmpty(entity.getCarno())) { + feed_jo.put("car_no", entity.getCarno()); + } JSONArray ja = new JSONArray(); ja.add(feed_jo); //TODO 有需要根据上位系统反馈的信息再做进一步处理 diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/B2HeadDto.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/B2HeadDto.java new file mode 100644 index 000000000..2988dec90 --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/B2HeadDto.java @@ -0,0 +1,37 @@ +package org.nl.hand.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author : TuQiang + * @create 2024/4/15 13:59 + */ +@Data +public class B2HeadDto implements Serializable { + /** + * 起始设备编码1 + */ + private String start_device_code1; + + /** + * 目标设备编码1 + */ + private String next_device_code1; + + /** + * 起始设备编码2 + */ + private String start_device_code2; + + /** + * 目标设备编码2 + */ + private String next_device_code2; + + /** + * 任务类型 + */ + private String task_type; +} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadDeviceDto.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadDeviceDto.java new file mode 100644 index 000000000..7fe53c279 --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadDeviceDto.java @@ -0,0 +1,26 @@ +package org.nl.hand.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author : TuQiang + * @create 2024/4/15 15:04 + */ +@Data +public class HeadDeviceDto implements Serializable { + /** + * 设备号 + */ + private String device_code; + + /** + * 操作类型 + * 0-禁止进出; + * 1-允许取放 + * 2-允许离开 + * + */ + private String option; +} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/rest/B2HandController.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/rest/B2HandController.java new file mode 100644 index 000000000..8d1c518df --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/rest/B2HandController.java @@ -0,0 +1,83 @@ +package org.nl.hand.rest; + +import cn.dev33.satoken.annotation.SaIgnore; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.common.logging.annotation.Log; +import org.nl.hand.dto.B2HeadDto; +import org.nl.hand.dto.HeadDeviceDto; +import org.nl.hand.dto.RegionDto; +import org.nl.hand.service.B2HandService; +import org.nl.hand.service.HandService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Author : TuQiang + * @create 2024/4/15 13:50 + */ +@RestController +@RequiredArgsConstructor +@Api(tags = "手持接口") +@RequestMapping("api/hands") +@Slf4j +public class B2HandController { + @Autowired + private B2HandService b2HandService; + + @Autowired + private HandService handService; + + @PostMapping("/queryArea") + @Log("查询区域") + @ApiOperation("查询区域") + @SaIgnore + //@PreAuthorize("@el.check('sect:list')") + public ResponseEntity queryArea() { + return new ResponseEntity<>(handService.queryArea(), HttpStatus.OK); + } + + @PostMapping("/queryPointByArea") + @Log("根据区域编码查点位") + @ApiOperation("根据区域编码查点位") + @SaIgnore + //@PreAuthorize("@el.check('sect:list')") + public ResponseEntity queryPointByArea(@RequestBody RegionDto dto) { + String region_code = dto.getRegion_code(); + return new ResponseEntity<>(handService.queryPointByArea(region_code), HttpStatus.OK); + } + + @PostMapping("/callTask") + @Log("手持创建任务") + @ApiOperation("手持创建任务") + @SaIgnore + //@PreAuthorize("@el.check('sect:list')") + public ResponseEntity callTask(@RequestBody B2HeadDto dto) { + return new ResponseEntity<>(b2HandService.callTask(dto), HttpStatus.OK); + } + + @PostMapping("/queryDevices") + @Log("查询所有设备") + @ApiOperation("查询所有设备") + @SaIgnore + //@PreAuthorize("@el.check('sect:list')") + public ResponseEntity queryDevices() { + return new ResponseEntity<>(b2HandService.queryDevices(), HttpStatus.OK); + } + + @PostMapping("/updateDeviceStatus") + @Log("更新设备状态") + @ApiOperation("更新设备状态") + @SaIgnore + //@PreAuthorize("@el.check('sect:list')") + public ResponseEntity updateDeviceStatus(@RequestBody HeadDeviceDto dto) { + return new ResponseEntity<>(b2HandService.updateDeviceStatus(dto), HttpStatus.OK); + } +} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/B2HandService.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/B2HandService.java new file mode 100644 index 000000000..f28bfaa3d --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/B2HandService.java @@ -0,0 +1,25 @@ +package org.nl.hand.service; + +import org.nl.hand.dto.B2HeadDto; +import org.nl.hand.dto.HeadDeviceDto; + +import java.util.Map; + +/** + * @Author : TuQiang + * @create 2024/4/15 13:52 + */ +public interface B2HandService { + + /** + * 手持创建任务 + * + * @param dto + * @return + */ + Map callTask(B2HeadDto dto); + + Map queryDevices(); + + Map updateDeviceStatus(HeadDeviceDto dto); +} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/impl/B2HandServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/impl/B2HandServiceImpl.java new file mode 100644 index 000000000..1d43340c5 --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/impl/B2HandServiceImpl.java @@ -0,0 +1,191 @@ +package org.nl.hand.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +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.DeviceService; +import org.nl.acs.device_driver.conveyor.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; +import org.nl.acs.instruction.domain.Instruction; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.common.exception.BadRequestException; +import org.nl.hand.dto.B2HeadDto; +import org.nl.hand.dto.HeadDeviceDto; +import org.nl.hand.service.B2HandService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +/** + * @Author : TuQiang + * @create 2024/4/15 13:52 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class B2HandServiceImpl implements B2HandService { + @Autowired + private TaskService taskserver; + @Autowired + private DeviceService deviceService; + @Autowired + private DeviceAppService deviceAppService; + @Autowired + private InstructionService instructionService; + + @Override + public Map callTask(B2HeadDto dto) { + JSONArray errArr = new JSONArray(); + String start_device_code = dto.getStart_device_code1(); + String next_device_code = dto.getNext_device_code1(); + String start_device_code2 = dto.getStart_device_code2(); + String next_device_code2 = dto.getNext_device_code2(); + String task_type = dto.getTask_type(); + + if (StrUtil.isEmpty(start_device_code)) { + JSONObject json = new JSONObject(); + json.put("message", "起点1不能为空"); + errArr.add(json); + } + if (StrUtil.isEmpty(next_device_code)) { + JSONObject json = new JSONObject(); + json.put("message", "终点1不能为空"); + errArr.add(json); + } + if (StrUtil.isEmpty(task_type)) { + JSONObject json = new JSONObject(); + json.put("message", "任务类型不能为空"); + errArr.add(json); + } + + JSONObject jo = new JSONObject(); + if (StrUtil.equals(task_type, CommonFinalParam.TYPE_ONE)) { + jo.put("start_device_code2", start_device_code2); + jo.put("next_device_code2", next_device_code2); + jo.put("start_point_code2", start_device_code2); + jo.put("next_point_code2", next_device_code2); + } else if (StrUtil.equals(task_type, CommonFinalParam.TYPE_TWO)) { + jo.put("start_device_code2", start_device_code2); + jo.put("next_device_code2", next_device_code2); + jo.put("start_point_code2", start_device_code2); + jo.put("next_point_code2", next_device_code2); + } + jo.put("start_device_code", start_device_code); + jo.put("next_device_code", next_device_code); + jo.put("start_point_code", start_device_code); + jo.put("next_point_code", next_device_code); + jo.put("start_device_code2", start_device_code2); + jo.put("next_device_code2", next_device_code2); + jo.put("start_point_code2", start_device_code2); + jo.put("next_point_code2", next_device_code2); + jo.put("task_type", task_type); + jo.put("agv_system_type", "2"); + jo.put("priority", "1"); + + TaskDto task_dto = jo.toJavaObject(TaskDto.class); + try { + taskserver.create(task_dto); + } catch (Exception e) { +// e.printStackTrace(); + JSONObject json = new JSONObject(); + json.put("message", e.getMessage()); + errArr.add(json); + } + JSONArray data = new JSONArray(); + JSONObject resultJson = new JSONObject(); + if (ObjectUtil.isEmpty(errArr)) { + resultJson.put("message", "操作成功"); + resultJson.put("data", data); + } else { + resultJson.put("message", "操作失败"); + resultJson.put("data", data); + } + return resultJson; + } + + @Override + public Map queryDevices() { + JSONArray data = new JSONArray(); + //查询所有生箔区的设备 + List list = deviceService.lambdaQuery() + .eq(Device::getRegion, "2") + .list(); + if (CollectionUtil.isEmpty(list)) { + throw new BadRequestException("未查到该区域的设备!"); + } + + StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; + for (int i = 0; i < list.size(); i++) { + JSONObject jo = new JSONObject(); + Device device = list.get(i); + String device_id = device.getDevice_id(); + String device_code = device.getDevice_code(); + Device deviceCode = deviceAppService.findDeviceByCode(device_code); + int option = 0; + if (deviceCode.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) deviceCode.getDeviceDriver(); + option = standardOrdinarySiteDeviceDriver.getOption(); + } + String device_name = device.getDevice_name(); + BigDecimal seq_num = device.getSeq_num(); + jo.put("device_id", device_id); + jo.put("device_code", device_code); + jo.put("device_name", device_name); + jo.put("seq_num", seq_num); + jo.put("option", option); + data.add(jo); + } + JSONObject resultJson = new JSONObject(); + resultJson.put("message", "操作成功"); + resultJson.put("data", data); + return resultJson; + } + + @Override + public Map updateDeviceStatus(HeadDeviceDto dto) { + JSONArray errArr = new JSONArray(); + String device_code = dto.getDevice_code(); + String option = dto.getOption(); + if (StrUtil.isEmpty(device_code)) { + JSONObject json = new JSONObject(); + json.put("message", "设备号不能为空"); + errArr.add(json); + } + if (StrUtil.isEmpty(option)) { + JSONObject json = new JSONObject(); + json.put("message", "操作不能为空"); + errArr.add(json); + } + if (device_code.contains("K")&&(!"1".equals(option))){ + throw new BadRequestException("该设备为空轴位,不能进行该操作"); + } + if (device_code.contains("M")&&(!"2".equals(option))){ + throw new BadRequestException("该设备为满轴位,不能进行该操作"); + } + StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; + Device device = deviceAppService.findDeviceByCode(device_code); + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); + standardOrdinarySiteDeviceDriver.setOption(Integer.parseInt(option)); + JSONArray data = new JSONArray(); + JSONObject resultJson = new JSONObject(); + if (ObjectUtil.isEmpty(errArr)) { + resultJson.put("message", "操作成功"); + resultJson.put("data", data); + } else { + resultJson.put("message", "操作失败"); + resultJson.put("data", data); + } + return resultJson; + } +}