diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/QueryAGVStatus.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/QueryAGVStatus.java index ff43f3f..d1e3e43 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/QueryAGVStatus.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/QueryAGVStatus.java @@ -65,8 +65,8 @@ public class QueryAGVStatus { String body = result.body(); JSONObject json = JSONObject.parseObject(body); JSONObject taskStatus = json.getJSONObject("TaskStatus"); - String taskNo = taskStatus.getString("TaskNo"); - if ("true".equals(json.getString("Result")) && taskNo.equals(instruction.getInstruction_code())) { + String instructionCode = taskStatus.getString("TaskNo"); + if ("true".equals(json.getString("Result")) && instructionCode.equals(instruction.getInstruction_code())) { // 已创建=CREATED, // 待分配=TOBEDISPATCHED, // 正在执行=RUNNING, @@ -78,26 +78,16 @@ public class QueryAGVStatus { //执行中 String state = json.getString("Status"); String carNo = json.getString("VehicleNo"); - String instructionCode = json.getString("id"); if ("running".equals(state)) { - if ("1".equals(instruction.getInstruction_status())) { + TaskDto task = taskService.findById(instruction.getTask_id()); + if ("0".equals(instruction.getInstruction_status())&&"1".equals(task.getTask_status())) { instruction.setCarno(carNo); - TaskDto task = new TaskDto(); + instruction.setInstruction_status("1"); + instructionService.update(instruction); instructionService.update(instruction); task.setCarno(carNo); task.setTask_id(instruction.getTask_id()); - instructionService.update(instruction); taskService.update(task); -// if (StrUtil.isNotEmpty(instructionCode)) { -// Device carCode = deviceAppService.findDeviceByCode(instructionCode); -// XgAgvCarDeviceDriver xgAgvCarDeviceDriver; -// if (null != carCode) { -// if (carCode.getDeviceDriver() instanceof XgAgvCarDeviceDriver) { -// xgAgvCarDeviceDriver = (XgAgvCarDeviceDriver) carCode.getDeviceDriver(); -// xgAgvCarDeviceDriver.setTaskType(AgvActionTypeEnum.getStatus(instruction.getAgv_action_type())); -// } -// } -// } } } else if ("finish".equals(state)) { @@ -113,6 +103,7 @@ public class QueryAGVStatus { } else if ("paused".equals(state) || "aborted".equals(state) || "Error".equals(state)) { if (!"1".equals(instruction.getInstruction_status())) { instruction.setInstruction_status("1"); + //todo 备注异常信息 instructionService.update(instruction); } } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/rest/KeCongAgvController.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/rest/KeCongAgvController.java index a804e07..cb0ce53 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/rest/KeCongAgvController.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/rest/KeCongAgvController.java @@ -22,16 +22,16 @@ public class KeCongAgvController { @PostMapping("/waitPointRequest") @Log("等待点请求") @SaIgnore - public ResponseEntity waitPointRequest(@RequestBody JSONObject requestParam) { + public ResponseEntity waitPointRequest(@RequestBody JSONObject requestParam) { return new ResponseEntity<>(keCongAgvService.agvWaitPointRequest(requestParam), HttpStatus.OK); } - @PostMapping("/requestResource") + @PostMapping("/applyIn") @Log("请求资源") @SaIgnore - public ResponseEntity requestResource(@RequestBody JSONObject requestParam) { - return new ResponseEntity<>(keCongAgvService.requestResource(requestParam), HttpStatus.OK); + public ResponseEntity applyIn(@RequestBody JSONObject requestParam) { + return new ResponseEntity<>(keCongAgvService.applyIn(requestParam), HttpStatus.OK); } @PostMapping("/releaseResource") @@ -41,4 +41,11 @@ public class KeCongAgvController { return new ResponseEntity<>(keCongAgvService.releaseResource(requestParam), HttpStatus.OK); } + @PostMapping("/requestAction") + @Log("AGV请求取放货") + @SaIgnore + public ResponseEntity requestAction(@RequestBody JSONObject requestParam) { + return new ResponseEntity<>(keCongAgvService.requestAction(requestParam), HttpStatus.OK); + } + } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/KeCongAgvService.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/KeCongAgvService.java index 818b2c9..c53e80a 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/KeCongAgvService.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/KeCongAgvService.java @@ -7,6 +7,8 @@ import org.nl.acs.instruction.domain.Instruction; public interface KeCongAgvService { + public HttpResponse deleteTask(String instruction_code) throws Exception; + /** * 下发运单序列 * @@ -31,14 +33,16 @@ public interface KeCongAgvService { // */ // public HttpResponse queryKZAgvStatus(String vehicleCode); - AgvResponse agvWaitPointRequest(JSONObject requestParam); + JSONObject agvWaitPointRequest(JSONObject requestParam); // public AgvResponse updateKZAgvInst(JSONObject requestParam); - AgvResponse requestResource(JSONObject requestParam); + JSONObject applyIn(JSONObject requestParam); AgvResponse releaseResource(JSONObject requestParam); + JSONObject requestAction(JSONObject requestParam); + // HttpResponse getRobotInfo(String robotCode); /** diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/KeCongAgvServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/KeCongAgvServiceImpl.java index d5fbb81..5a7a3cb 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/KeCongAgvServiceImpl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/KeCongAgvServiceImpl.java @@ -4,8 +4,10 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.AcsConfig; @@ -13,15 +15,28 @@ import org.nl.acs.agv.server.KeCongAgvService; import org.nl.acs.agv.server.MagicAgvService; import org.nl.acs.agv.server.dao.AgvResponse; import org.nl.acs.common.base.CommonFinalParam; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device.service.impl.DeviceServiceImpl; +import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.instruction.domain.Instruction; import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.storage_cell.domain.StorageCell; +import org.nl.acs.storage_cell.service.mapper.StorageCellMapper; +import org.nl.acs.task.enums.ActionTypeEnum; +import org.nl.acs.task.enums.AgvActionTypeEnum; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; import org.nl.common.exception.BadRequestException; +import org.nl.config.SpringContextHolder; import org.nl.config.lucene.service.LuceneExecuteLogService; import org.nl.config.lucene.service.dto.LuceneLogDto; import org.nl.system.service.param.ISysParamService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import java.util.List; + @Slf4j @Service @RequiredArgsConstructor @@ -32,6 +47,52 @@ public class KeCongAgvServiceImpl implements KeCongAgvService { @Autowired private InstructionService instructionService; private final ISysParamService paramService; + @Autowired + private AcsToWmsService acsToWmsService; + @Autowired + private TaskService taskserver; + @Autowired + private StorageCellMapper storageCellMapper; + + @Override + public HttpResponse deleteTask(String instCode) throws Exception { + LuceneLogDto logDto = LuceneLogDto.builder() + .device_code("下发科聪任务") + .content(instCode) + .build(); + logDto.setLog_level(4); + luceneExecuteLogService.deviceExecuteLog(logDto); + log.info("删除科聪任务序列参数:{}", instCode); + if (StrUtil.equals(paramService.findByCode(AcsConfig.FORKAGV). + + getValue(), CommonFinalParam.ONE)) { + String agvurl = paramService.findByCode(AcsConfig.AGVURL).getValue(); + String agvport = paramService.findByCode(AcsConfig.AGVPORT).getValue(); + + agvurl = agvurl + ":" + agvport + "/api/fms/abortTask"; + + log.info(agvurl); + JSONObject ja = new JSONObject(); + ja.put("TaskNo", instCode); + HttpResponse result = HttpRequest.post(agvurl) + //表单内容 + .body(String.valueOf(ja)) + //超时,毫秒 + .timeout(20000) + .execute(); + LuceneLogDto logDto1 = LuceneLogDto.builder() + .device_code("删除科聪任务") + .content("指令号:" + instCode + ",删除科聪任务序列反馈参数:" + ja) + .build(); + logDto.setLog_level(4); + luceneExecuteLogService.deviceExecuteLog(logDto1); + log.info("指令号{},删除agv订单序列反馈:{}", instCode, result.body()); + + return result; + } else { + return null; + } + } @Override public HttpResponse addTask(Instruction inst) throws Exception { @@ -39,50 +100,24 @@ public class KeCongAgvServiceImpl implements KeCongAgvService { JSONArray arr = new JSONArray(); jo.put("TaskType", inst.getInstruction_type()); JSONObject json1 = new JSONObject(); - json1.put("Key", "TaskId"); + json1.put("Key", "TaskNo"); json1.put("Value", inst.getInstruction_code()); arr.add(json1); - JSONObject json2 = new JSONObject(); - json2.put("Key", "VehicleNo"); - json2.put("Value", "3"); - arr.add(json2); +// JSONObject json2 = new JSONObject(); +// json2.put("Key", "VehicleNo"); +// json2.put("Value", "3"); +// arr.add(json2); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + int startAddress = deviceService.queryAddressBydeviceCode(inst.getStart_point_code()); + int nextAddress = deviceService.queryAddressBydeviceCode(inst.getNext_point_code()); JSONObject json3 = new JSONObject(); - json3.put("Key", "point1"); - json3.put("Value", inst.getStart_device_code()); + json3.put("Key", "Point1"); + json3.put("Value", String.valueOf(startAddress)); arr.add(json3); JSONObject json4 = new JSONObject(); - json4.put("Key", "point2"); - json4.put("Value", inst.getNext_device_code()); + json4.put("Key", "Point2"); + json4.put("Value", String.valueOf(nextAddress)); arr.add(json4); - if ("任务1" .equals(inst.getInstruction_type())) { - JSONObject json5 = new JSONObject(); - json5.put("Key", "point3"); - json5.put("Value", inst.getStart_device_code2()); - arr.add(json5); - JSONObject json6 = new JSONObject(); - json6.put("Key", "point4"); - json6.put("Value", inst.getNext_device_code2()); - arr.add(json6); - } else if ("任务11" .equals(inst.getInstruction_type())) { - JSONObject json5 = new JSONObject(); - json5.put("Key", "isget"); - json5.put("Value", "0"); - arr.add(json5); - } else if ("任务12" .equals(inst.getInstruction_type())) { - JSONObject json6 = new JSONObject(); - json6.put("Key", "isput"); - json6.put("Value", "0"); - arr.add(json6); - } else if ("任务13" .equals(inst.getInstruction_type())) { - JSONObject json5 = new JSONObject(); - json5.put("Key", "isget"); - json5.put("Value", "0"); - arr.add(json5); - JSONObject json6 = new JSONObject(); - json6.put("Key", "isput"); - json6.put("Value", "0"); - arr.add(json6); - } jo.put("Params", arr); System.out.println(jo); LuceneLogDto logDto = LuceneLogDto.builder() @@ -173,108 +208,76 @@ public class KeCongAgvServiceImpl implements KeCongAgvService { // } @Override - public AgvResponse agvWaitPointRequest(JSONObject requestParam) { - System.out.println("请求kc参数:" + requestParam); - String taskId = requestParam.getString("TaskId"); + public JSONObject agvWaitPointRequest(JSONObject requestParam) { + log.info("科聪二次分配请求参数:" + requestParam); + String instNo = requestParam.getString("TaskNo"); + String vehicleNo = requestParam.getString("VehicleNo"); String type = requestParam.getString("type"); // 1 取货点等待 2 放货点等待 - Instruction inst = instructionService.findByCodeFromCache(taskId); + Instruction inst = instructionService.findByCodeFromCache(instNo); if (ObjectUtil.isEmpty(inst)) { throw new BadRequestException("请求失败,未找到指令!"); } - JSONObject jo = new JSONObject(); - JSONArray arr = new JSONArray(); - jo.put("TaskNo", taskId); - if ("任务11" .equals(inst.getInstruction_type())) { - //todo :需要跟上位申请新的点位 - JSONObject json1 = new JSONObject(); - json1.put("Name", "point1"); - json1.put("Value", "3"); - arr.add(json1); - } else if ("任务12" .equals(inst.getInstruction_type())) { - //todo :需要跟上位申请新的点位 - JSONObject json1 = new JSONObject(); - json1.put("Name", "point2"); - json1.put("Value", "4"); - arr.add(json1); - } else if ("任务13" .equals(inst.getInstruction_type())) { - if ("1" .equals(type)) { - //todo :需要跟上位申请新的点位 - JSONObject json1 = new JSONObject(); - json1.put("Name", "point1"); - json1.put("Value", "1"); - arr.add(json1); - } else if ("2" .equals(type)) { - //todo :需要跟上位申请新的点位 - JSONObject json1 = new JSONObject(); - json1.put("Name", "point2"); - json1.put("Value", "1"); - arr.add(json1); - } + if ("1".equals(type)) { + String newPointCode = applyNewPoint(vehicleNo, type, inst); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + int startAddress = deviceService.queryAddressBydeviceCode(newPointCode); + JSONObject ja = new JSONObject(); + ja.put("code", "200"); + ja.put("message", "操作成功"); + ja.put("point_code", String.valueOf(startAddress)); + log.info("科聪二次分配返回参数:" + ja); + return ja; } - if ("任务11" .equals(inst.getInstruction_type())) { - JSONObject json2 = new JSONObject(); - json2.put("Name", "isget"); - json2.put("Value", "1"); - arr.add(json2); - } else if ("任务12" .equals(inst.getInstruction_type())) { - JSONObject json2 = new JSONObject(); - json2.put("Name", "isput"); - json2.put("Value", "1"); - arr.add(json2); - } else if ("任务13" .equals(inst.getInstruction_type())) { - if ("1" .equals(type)) { - JSONObject json3 = new JSONObject(); - json3.put("Name", "isget"); - json3.put("Value", "1"); - arr.add(json3); - } else if ("2" .equals(type)) { - JSONObject json2 = new JSONObject(); - json2.put("Name", "isput"); - json2.put("Value", "1"); - arr.add(json2); - } + //如果是放货二次分配 + if ("2".equals(type)) { + String newPointCode = applyNewPoint(vehicleNo, type, inst); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + int nextAddress = deviceService.queryAddressBydeviceCode(newPointCode); + JSONObject ja = new JSONObject(); + ja.put("code", "200"); + ja.put("message", "操作成功"); + ja.put("point_code", String.valueOf(nextAddress)); + LuceneLogDto logDto = LuceneLogDto.builder() + .device_code(vehicleNo) + .content("放货二次分配,参数:" + inst.getTask_code() + "--" + ActionTypeEnum.getStatus(Integer.parseInt(inst.getInstruction_type()))) + .build(); + logDto.setLog_level(4); + return ja; } - jo.put("Params", arr); - String agvurl = paramService.findByCode(AcsConfig.AGVURL).getValue(); - String agvport = paramService.findByCode(AcsConfig.AGVPORT).getValue(); + throw new BadRequestException("请求失败,IN OUT 站点错误!"); + } - //更新任务参数 - agvurl = agvurl + ":" + agvport + "/api/fms/updateTaskParam"; - - log.info(agvurl); - HttpResponse result = HttpRequest.post(agvurl) - //表单内容 - .body(String.valueOf(jo)) - //超时,毫秒 - .timeout(20000) - .execute(); - LuceneLogDto logDto1 = LuceneLogDto.builder() - .device_code("下发科聪任务") - .content("任务号:" + inst.getTask_code() + ",指令号:" + inst.getInstruction_code() + ",下发科聪任务序列反馈参数:" + jo) + private String applyNewPoint(String vehicleNo, String type, Instruction inst) { + JSONObject param = new JSONObject(); + param.put("taskCode", inst.getTask_code()); + param.put("actionType", inst.getInstruction_type()); + param.put("type", type); + LuceneLogDto logDto = LuceneLogDto.builder() + .device_code(vehicleNo) + .content("二次分配请求wms,参数:" + inst.getTask_code() + "--" + ActionTypeEnum.getStatus(Integer.parseInt(inst.getInstruction_type()))) .build(); - logDto1.setLog_level(4); - luceneExecuteLogService.deviceExecuteLog(logDto1); - log.info("任务号:{},指令号{},状态{},下发agv订单序列反馈:{}", inst.getTask_code(), inst.getInstruction_code(), result.getStatus(), result.body()); - JSONObject jsonObject = null; - if (ObjectUtil.isNotEmpty(result)) { - String body = result.body(); - jsonObject = JSONObject.parseObject(body); - if (ObjectUtil.isNotNull(jsonObject) && "true" .equals(jsonObject.getString("Result"))) { - AgvResponse agvResponse = new AgvResponse(); - agvResponse.setResult("true"); - agvResponse.setErrMsg(""); - return agvResponse; - } else { - AgvResponse agvResponse = new AgvResponse(); - agvResponse.setResult("false"); - agvResponse.setErrMsg(""); - return agvResponse; - } + logDto.setLog_level(4); + luceneExecuteLogService.deviceExecuteLog(logDto); + String response = acsToWmsService.secondaryAllocationPoint(param); + JSONObject jo = JSON.parseObject(response); + if (jo.getInteger("status") == 200) { + LuceneLogDto logDto2 = LuceneLogDto.builder() + .device_code(vehicleNo) + .content("二次分配请求lms,参数,接口返回:" + jo) + .build(); + logDto2.setLog_level(4); + //二次分配更新点位 + updataTask(inst, jo.getString("data")); + return jo.getString("data"); } else { - AgvResponse agvResponse = new AgvResponse(); - agvResponse.setResult("false"); - agvResponse.setErrMsg(""); - return agvResponse; + LuceneLogDto logDto2 = LuceneLogDto.builder() + .device_code(vehicleNo) + .content("二次分配请求lms,返回参数:" + jo) + .build(); + logDto2.setLog_level(4); + luceneExecuteLogService.deviceExecuteLog(logDto2); + log.info("科聪二次分配请求lms失败,返回参数:" + jo); + throw new BadRequestException("二次分配请求lms返回失败" + jo); } } @@ -291,12 +294,76 @@ public class KeCongAgvServiceImpl implements KeCongAgvService { // } @Override - public AgvResponse requestResource(JSONObject requestParam) { - //todo: 延迟十秒 - AgvResponse agvResponse = new AgvResponse(); - agvResponse.setResult("true"); - agvResponse.setErrMsg("请求失败"); - return agvResponse; + public JSONObject applyIn(JSONObject requestParam) { + String resourceID = requestParam.getString("point_code"); + String vehicleNo = requestParam.getString("VehicleNo"); + if (resourceID.equals("659") || resourceID.equals("17")) { + log.info("科聪申请离开请求参数:" + requestParam); + LuceneLogDto logDto2 = LuceneLogDto.builder() + .device_code(vehicleNo) + .content("agv申请进入请求离开成功") + .build(); + logDto2.setLog_level(4); + JSONObject json = new JSONObject(); + json.put("code", "200"); + json.put("message", "操作成功"); + return json; + } + log.info("科聪申请进入请求参数:" + requestParam); + List storageCells = storageCellMapper.selectList(new LambdaQueryWrapper().eq(StorageCell::getAddress, resourceID).orderByDesc(StorageCell::getUpdate_time)); + StorageCell storageCell = storageCells.get(0); + String storage_code = storageCell.getStorage_code(); + JSONObject ja = new JSONObject(); + ja.put("point_code", storage_code); + String response = acsToWmsService.applyIn(ja); + + JSONObject jo = JSON.parseObject(response); + if (jo.getInteger("status") == 200) { + log.info("agv申请进入请求lms成功,参数,接口返回:" + jo); + LuceneLogDto logDto2 = LuceneLogDto.builder() + .device_code(vehicleNo) + .content("agv申请进入请求lms成功,参数,接口返回:" + jo) + .build(); + logDto2.setLog_level(4); + JSONObject json = new JSONObject(); + json.put("code", "200"); + json.put("message", "操作成功"); + log.info("科聪申请进入下发返回参数:" + json); + return json; + } else { + log.info("agv申请进入请求lms失败,参数,接口返回:" + jo); + LuceneLogDto logDto2 = LuceneLogDto.builder() + .device_code(vehicleNo) + .content("agv申请进入请求lms失败,返回参数:" + jo) + .build(); + logDto2.setLog_level(4); + luceneExecuteLogService.deviceExecuteLog(logDto2); + JSONObject json = new JSONObject(); + json.put("code", "400"); + json.put("message", "申请进入失败,接口返回:" + jo); + log.info("科聪申请进入下发返回参数:" + json); + return json; + } + } + + private void updataTask(Instruction instructionDto, String newPoint) { + + TaskDto taskUpdate = new TaskDto(); + if (AgvActionTypeEnum.IN_STOCK.getCode().equals(instructionDto.getAgv_action_type())) { + instructionDto.setStart_point_code(newPoint); + taskUpdate.setStart_point_code(newPoint); + instructionDto.setStart_device_code(newPoint); + taskUpdate.setStart_device_code(newPoint); + } + if (AgvActionTypeEnum.OUT_STOCK.getCode().equals(instructionDto.getAgv_action_type())) { + instructionDto.setNext_point_code(newPoint); + taskUpdate.setNext_point_code(newPoint); + instructionDto.setNext_device_code(newPoint); + taskUpdate.setNext_device_code(newPoint); + } + taskUpdate.setTask_id(instructionDto.getTask_id()); + instructionService.update(instructionDto); + taskserver.update(taskUpdate); } @Override @@ -307,6 +374,25 @@ public class KeCongAgvServiceImpl implements KeCongAgvService { return agvResponse; } + @Override + public JSONObject requestAction(JSONObject requestParam) { + String taskNo = requestParam.getString("TaskNo"); + Instruction instruction = instructionService.findByCode(taskNo); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("task_code", instruction.getTask_code()); + LuceneLogDto logDto1 = LuceneLogDto.builder() + .device_code(taskNo) + .content("取货完成反馈:" + jsonObject.toJSONString() + ";指令号:" + taskNo) + .build(); + logDto1.setLog_level(4); + luceneExecuteLogService.deviceExecuteLog(logDto1); + acsToWmsService.actionFinishRequest2(jsonObject); + JSONObject jo = new JSONObject(); + jo.put("code", "200"); + jo.put("message", "请求成功"); + return jo; + } + // @Override // public HttpResponse getRobotInfo(String robotCode) { // if (StrUtil.equals(paramService.findByCode(AcsConfig.FORKAGV).getValue(), "1")) { diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/common/base/CommonFinalParam.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/common/base/CommonFinalParam.java index ba3609b..853b847 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/common/base/CommonFinalParam.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/common/base/CommonFinalParam.java @@ -55,13 +55,21 @@ public class CommonFinalParam { /** * 申请任务type类型 */ - public static final String TYPE_ONE = "1"; - public static final String TYPE_TWO = "2"; - public static final String TYPE_THREE = "3"; - public static final String TYPE_FOUR = "4"; - public static final String TYPE_FIVE = "5"; - public static final String TYPE_SIX = "6"; - public static final String TYPE_SEVEN = "7"; +// public static final String TYPE_ONE = "1"; +// public static final String TYPE_TWO = "2"; +// public static final String TYPE_THREE = "3"; +// public static final String TYPE_FOUR = "4"; +// public static final String TYPE_FIVE = "5"; +// public static final String TYPE_SIX = "6"; +// public static final String TYPE_SEVEN = "7"; + + /** + * 申请任务type类型 + */ + public static final String TYPE_ONE = "ONE"; + public static final String TYPE_TWO = "TWO"; + public static final String TYPE_THREE = "THREE"; + public static final String TYPE_FOUR = "FOUR"; diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/DeviceService.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/DeviceService.java index 7582b73..6c919ed 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/DeviceService.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/DeviceService.java @@ -132,6 +132,14 @@ public interface DeviceService extends CommonService { */ DeviceDto findByCode(String code); + /** + * 根据站点号查询 + * + * @param code code + * @return Device + */ + DeviceDto findByAgvCode(String code); + /** * 创建 * diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java index 9fc61f9..e7ca314 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java @@ -273,6 +273,14 @@ public class DeviceServiceImpl extends CommonServiceImpl i return ConvertUtil.convert(device, DeviceDto.class); } + @Override + public DeviceDto findByAgvCode(String code) { + Device device = new LambdaQueryChainWrapper<>(deviceMapper) + .eq(Device::getAddress, code) + .one(); + return ConvertUtil.convert(device, DeviceDto.class); + } + @Override @Transactional(rollbackFor = Exception.class) public void create(DeviceDto dto) { 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 494b51b..9c0a094 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 @@ -16,6 +16,7 @@ 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.agv.utils.TwoAgvPhase; +import org.nl.acs.device_driver.conveyor.belt_conveyor.BeltConveyorDeviceDriver; import org.nl.acs.device_driver.conveyor.standard_inspect_site.StandardInspectSiteDeviceDriver; import org.nl.acs.device_driver.conveyor.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; import org.nl.acs.device_driver.driver.AbstractDeviceDriver; @@ -165,8 +166,6 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic //普通站点 StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - //标准-光电检测 - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; if (phase == 0x02) { @@ -483,11 +482,11 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic //当前上报的车号 String now_car = String.valueOf(this.agvaddr); //如果配置的车号是诺宝车号 - if(now_car.equals(is_atuo_car)){ + if (now_car.equals(is_atuo_car)) { //是否开启自动充电 String is_atuo_electric = ISysParamService.findByCode(AcsConfig.IS_ATUO_ELECTRIC).getValue(); log.info("接收agv上报信息,is_atuo_electric:" + is_atuo_electric); - if("1".equals(is_atuo_electric)){ + if ("1".equals(is_atuo_electric)) { String electric_begin = ISysParamService.findByCode(AcsConfig.ELECTRIC_BEGIN).getValue(); String[] begins = electric_begin.split(":"); String electric_end = ISysParamService.findByCode(AcsConfig.ELECTRIC_END).getValue(); @@ -499,27 +498,27 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic LocalTime now = LocalTime.now(); // 判断当前时间是否在时间段内 boolean isInRange = !now.isBefore(startTime) && !now.isAfter(endTime); - int electric = 0 ; + int electric = 0; //早上8-22点 - if(isInRange){ + if (isInRange) { electric = Integer.parseInt(ISysParamService.findByCode(AcsConfig.ELECTRIC).getValue()); - }else{ + } else { electric = Integer.parseInt(ISysParamService.findByCode(AcsConfig.ELECTRIC2).getValue()); } - if (electric_qty>0 && electric_qty < electric) { - log.info("当前车辆{}电量为{}低于{},开始判断是否需要充电!", this.agvaddr, electric_qty,electric); + if (electric_qty > 0 && electric_qty < electric) { + log.info("当前车辆{}电量为{}低于{},开始判断是否需要充电!", this.agvaddr, electric_qty, electric); //判断是否已下发充电任务 - Dict dict1 = dictService.getDictByName3("station",String.valueOf(this.agvaddr),null); - if(ObjectUtil.isNotEmpty(dict1)){ - log.info("当前车辆{}已分配充电桩{},退出后续判断",this.agvaddr,dict1.getPara1()); - }else{ + Dict dict1 = dictService.getDictByName3("station", String.valueOf(this.agvaddr), null); + if (ObjectUtil.isNotEmpty(dict1)) { + log.info("当前车辆{}已分配充电桩{},退出后续判断", this.agvaddr, dict1.getPara1()); + } else { //未下发,判断是否有空闲充电桩 Dict dict = dictService.getDictByName2("station"); - if(ObjectUtil.isNotEmpty(dict)){ + if (ObjectUtil.isNotEmpty(dict)) { ndcAgvService.charge(String.valueOf(this.agvaddr)); - isCharge =true; - }else{ - log.info("当前车辆{}电量为{}低于{},但无空闲充电桩!", this.agvaddr, electric_qty,electric); + isCharge = true; + } else { + log.info("当前车辆{}电量为{}低于{},但无空闲充电桩!", this.agvaddr, electric_qty, electric); } } } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java index 5775403..749e24f 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java @@ -32,6 +32,7 @@ import java.util.List; @RequiredArgsConstructor @RequestMapping("/api/wms") @Slf4j +@SaIgnore public class WmsToAcsController { private final WmsToAcsService wmstoacsService; diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java index b7b4c41..4cd231e 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java @@ -127,7 +127,7 @@ public interface AcsToWmsService { * @param arr * @return */ - HttpResponse feedTaskStatus(JSONArray arr); + HttpResponse feedTaskStatus(JSONObject arr); /** * ACS向WMS反馈任务状态 @@ -225,4 +225,6 @@ public interface AcsToWmsService { * @return */ ManipulatorApplyPointResponse manipulatorApplyPointRequest(ManipulatorApplyPointRequest param); + + String applyIn(JSONObject ja); } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java index 4a7af9e..c74579e 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java @@ -326,20 +326,11 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { @Override - public HttpResponse feedTaskStatus(JSONArray data) { + public HttpResponse feedTaskStatus(JSONObject data) { //feedTaskStatus try { MDC.put(log_file_type, log_type); String wmsurl = paramService.findByCode(AcsConfig.WMSURL).getValue(); - - String task_code = ""; - for (int i = 0; i < data.size(); i++) { - JSONObject json = (JSONObject) data.get(i); - task_code = json.getString("task_code"); - } - TaskDto taskDto = taskService.findByCode(task_code); - String vehicle_code = taskDto.getVehicle_code(); - HttpResponse result2 = null; log.info("feedbackTaskStatusToWms-----请求参数{}", data.toString()); @@ -347,7 +338,6 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { String methods_url = addressDto.getMethods_url(); try { result2 = HttpRequest.post(wmsurl + methods_url) - .addInterceptor(tLogHutoolhttpInterceptor) .header(Header.USER_AGENT, "Hutool http") .header("Authorization", token).body(String.valueOf(data)) .execute(); @@ -744,6 +734,48 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } } + @Override + public String applyIn(JSONObject param) { + try { + MDC.put(log_file_type, log_type); + log.info("applyIn-----agv申请进入输入参数{}", param); + String wmsurl = paramService.findByCode(AcsConfig.WMSURL).getValue(); + AddressDto addressDto = addressService.findByCode("applyIn"); + String url = wmsurl + addressDto.getMethods_url(); + HttpResponse result2 = null; + try { + result2 = HttpRequest.post(url) + .addInterceptor(tLogHutoolhttpInterceptor) + .header(Header.USER_AGENT, "Hutool http") + .header("Authorization", token) + .body(String.valueOf(param)) + .execute(); + } catch (Exception e) { + String msg = e.getMessage(); + log.info("applyIn-----输出参数{}", msg); + //网络不通 + } + if (ObjectUtil.isEmpty(result2)) { + log.info("applyIn-----输出参数{}", "返回结果为空"); + return null; + } + String type = ""; + if (result2.getStatus() == 200) { + type = "info"; + } else { + type = "error"; + } + log.info("secondaryAllocationPoint-----输出参数{}", result2.body()); + LuceneLogDto luceneLogDto = new LuceneLogDto(4, "applyIn", String.valueOf(result2.getStatus()), + JSON.toJSONString(param), String.valueOf(result2.body()), "agv申请进入"); + luceneLogService.interfaceExecuteLog(luceneLogDto); + return result2.body(); + + } finally { + MDC.remove(log_file_type); + } + } + @Override public String forceMove(JSONObject param) { diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index 3b3e93c..b6f5fa1 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -1,5 +1,6 @@ package org.nl.acs.ext.wms.service.impl; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; @@ -12,7 +13,10 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; 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.service.impl.DeviceServiceImpl; import org.nl.acs.device_driver.agv.ndctwo.AgvNdcTwoDeviceDriver; import org.nl.acs.device_driver.conveyor.belt_conveyor.BeltConveyorDeviceDriver; import org.nl.acs.device_driver.conveyor.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; @@ -74,91 +78,41 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { .build(); logDto.setLog_level(4); luceneExecuteLogService.deviceExecuteLog(logDto); - JSONArray datas = JSONArray.parseArray(param); + JSONObject req = JSONObject.parseObject(param); + org.nl.acs.ext.wms.data.WmstoAcsData.createTask.CreateTaskRequest tasks = JSON.toJavaObject(req, org.nl.acs.ext.wms.data.WmstoAcsData.createTask.CreateTaskRequest.class); CreateTaskResponse response = new CreateTaskResponse(); -// ParamService paramService = SpringContextHolder.getBean(ParamService.class); - ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class); -// String cancelTaskCheck = paramService.findByCode(AcsConfig.ISALLOWTASK).getValue(); JSONArray errArr = new JSONArray(); -// if (StrUtil.equals(cancelTaskCheck, "0")) { -// response.setStatus(400); -// response.setMessage("ACS系统需要更新,请稍等"); -// response.setErrArr(datas); -// return response; -// } - for (int i = 0; i < datas.size(); i++) { - String data = datas.get(i).toString(); - CreateTaskRequest request = JsonUtl.format(data, CreateTaskRequest.class); - String paper_array = request.getPaper_array(); - String ext_task_id = request.getExt_task_id(); - String task_code = request.getTask_code(); - String start_device_code = request.getStart_device_code(); - String start_device_code2 = request.getStart_device_code2(); - String next_device_code = request.getNext_device_code(); - String next_device_code2 = request.getNext_device_code2(); - String put_device_code = request.getPut_device_code(); - String priority = request.getPriority(); - String vehicle_code = request.getVehicle_code(); - String vehicle_code2 = request.getVehicle_code2(); - String vehicle_type = request.getVehicle_type(); - String route_plan_code = request.getRoute_plan_code(); - String task_type = request.getTask_type(); - String class_type = request.getClass_type(); - String truss_type = request.getTruss_type(); - Integer agv_action_type = request.getAgv_action_type(); - String empty_site = request.getEmpty_site(); - String is_bushing = request.getIs_bushing(); - String is_pulling = request.getIs_pulling(); - String size = request.getSize(); - String version = request.getVersion(); - String bushing_num = request.getBushing_num(); - String storage_task_type = request.getDtl_type(); - String agv_system_type = request.getAgv_system_type(); - String remark = request.getRemark(); - double oven_time = 0.00d; - if (StrUtil.isNotEmpty(request.getOven_time())) { - oven_time = Double.parseDouble(request.getOven_time()); - } - String temperature = request.getTemperature(); - String start_height = request.getStart_height(); - String next_height = request.getNext_height(); - String params2 = request.getParams2(); - Map params = request.getParams(); + for (int i = 0; i < tasks.getList().size(); i++) { + TaskDto task = tasks.getList().get(i); + String ext_task_uuid = task.getExt_task_uuid(); + String task_code = task.getTask_code(); + String start_point_code = task.getStart_device_code(); + String next_point_code = task.getNext_device_code(); + String priority = task.getPriority(); + String vehicle_code = task.getVehicle_code(); + String vehicle_type = task.getVehicle_type(); + String route_plan_code = task.getRoute_plan_code(); + String task_type = task.getTask_type(); + String remark = task.getRemark(); + String params = task.getParams(); + Integer agv_action_type = task.getAgv_action_type(); - String start_point_code = ""; - String start_point_code2 = ""; - String next_point_code = ""; - String next_point_code2 = ""; - String put_point_code = ""; + String put_device_code = task.getPut_device_code(); + String agv_system_type = task.getAgv_system_type(); + + String start_device_code2 = task.getStart_device_code2(); + String next_device_code2 = task.getNext_device_code2(); + String start_device_code = ""; + String next_device_code = ""; if (StrUtil.isEmpty(task_code)) { JSONObject json = new JSONObject(); json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); + json.put("ext_task_id", ext_task_uuid); json.put("message", "任务号不能为空"); errArr.add(json); continue; } - if (StrUtil.isEmpty(start_device_code)) { - JSONObject json = new JSONObject(); - json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); - json.put("message", "起点不能为空"); - errArr.add(json); - continue; - } - if (StrUtil.isEmpty(next_device_code)) { - JSONObject json = new JSONObject(); - json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); - json.put("message", "终点不能为空"); - errArr.add(json); - continue; - } - if (StrUtil.equals(task_type, "8")) { - next_device_code = request.getPut_device_code(); - put_device_code = request.getNext_device_code(); - } StorageCell start_storageCell = new LambdaQueryChainWrapper<>(storageCellMapper) .eq(StorageCell::getStorage_code, start_device_code) @@ -166,15 +120,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { StorageCell next_storageCell = new LambdaQueryChainWrapper<>(storageCellMapper) .eq(StorageCell::getStorage_code, next_device_code) .one(); - StorageCell start2_storageCell = new LambdaQueryChainWrapper<>(storageCellMapper) - .eq(StorageCell::getStorage_code, start_device_code2) - .one(); - StorageCell next2_storageCell = new LambdaQueryChainWrapper<>(storageCellMapper) - .eq(StorageCell::getStorage_code, next_device_code2) - .one(); - StorageCell put_storageCell = new LambdaQueryChainWrapper<>(storageCellMapper) - .eq(StorageCell::getStorage_code, put_device_code) - .one(); JSONObject start_device_json = (JSONObject) JSONObject.toJSON(start_storageCell); if (!ObjectUtil.isEmpty(start_device_json)) { @@ -184,18 +129,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { if (!ObjectUtil.isEmpty(next_device_json)) { next_point_code = (String) next_device_json.get("parent_storage_code") == null ? next_point_code : (String) next_device_json.get("storage_code"); } - JSONObject start_device_json2 = (JSONObject) JSONObject.toJSON(start2_storageCell); - if (!ObjectUtil.isEmpty(start_device_json2)) { - start_point_code2 = (String) start_device_json2.get("parent_storage_code") == null ? start_device_code2 : (String) start_device_json2.get("storage_code"); - } - JSONObject next_device_json2 = (JSONObject) JSONObject.toJSON(next2_storageCell); - if (!ObjectUtil.isEmpty(next_device_json2)) { - next_point_code2 = (String) next_device_json2.get("parent_storage_code") == null ? next_device_code2 : (String) next_device_json2.get("storage_code"); - } - JSONObject put_device_json = (JSONObject) JSONObject.toJSON(put_storageCell); - if (!ObjectUtil.isEmpty(put_device_json)) { - put_point_code = (String) put_device_json.get("parent_storage_code") == null ? put_device_code : (String) put_device_json.get("storage_code"); - } if (StrUtil.isNotEmpty(start_point_code) && start_point_code.indexOf("-") > 0) { String str[] = start_point_code.split("-"); start_device_code = str[0]; @@ -210,47 +143,16 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { next_device_code = next_point_code; } - if (StrUtil.isNotEmpty(start_point_code2) && start_point_code2.indexOf("-") > 0) { - String str[] = start_point_code2.split("-"); - start_device_code2 = str[0]; - } else { - start_device_code2 = start_point_code2; - } - - if (StrUtil.isNotEmpty(next_point_code2) && next_point_code2.indexOf("-") > 0) { - String str[] = next_point_code2.split("-"); - next_device_code2 = str[0]; - } else { - next_device_code2 = next_point_code2; - } - - if (StrUtil.isNotEmpty(put_point_code) && put_point_code.indexOf("-") > 0) { - String str[] = put_point_code.split("-"); - put_device_code = str[0]; - } else { - put_device_code = put_point_code; - } - if (StrUtil.isEmpty(route_plan_code)) { route_plan_code = "normal"; } - if (StrUtil.equals(task_type, "5")) { - if (taskserver.querySameDeviceReadyTask(start_device_code, next_device_code, "0") > 1) { - JSONObject json = new JSONObject(); - json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); - json.put("message", "已存在相同的起点:" + start_device_code + "终点:" + next_device_code + "未执行的输送任务"); - errArr.add(json); - continue; - } - } TaskDto taskDto = taskserver.findByCodeFromCache(task_code); if (taskDto != null) { JSONObject json = new JSONObject(); json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); + json.put("ext_task_id", ext_task_uuid); json.put("message", "存在相同的任务号:" + task_code); errArr.add(json); continue; @@ -260,7 +162,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { if (vehicle_dto != null) { JSONObject json = new JSONObject(); json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); + json.put("ext_task_id", ext_task_uuid); json.put("message", "已存在任务编号为" + vehicle_dto.getTask_code() + "托盘号:" + vehicle_code); errArr.add(json); continue; @@ -279,93 +181,57 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { if (StrUtil.isEmpty(start_point_code)) { JSONObject json = new JSONObject(); json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); - json.put("message", request.getStart_device_code() + " 该设备号未找到对应点位"); + json.put("ext_task_id", ext_task_uuid); + json.put("message", task.getStart_device_code() + " 该设备号未找到对应点位"); errArr.add(json); continue; } if (StrUtil.isEmpty(next_point_code)) { JSONObject json = new JSONObject(); json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); - json.put("message", request.getNext_device_code() + " 该设备号未找到对应点位"); + json.put("ext_task_id", ext_task_uuid); + json.put("message", task.getNext_device_code() + " 该设备号未找到对应点位"); errArr.add(json); continue; } JSONObject jo = new JSONObject(); - jo.put("task_id", IdUtil.simpleUUID()); jo.put("task_code", task_code); + jo.put("ext_task_id", ext_task_uuid); jo.put("start_point_code", start_point_code); jo.put("next_point_code", next_point_code); - jo.put("start_point_code2", start_point_code2); - jo.put("next_point_code2", next_point_code2); - jo.put("put_point_code", put_point_code); - jo.put("start_parent_code", start_point_code); - jo.put("next_parent_code", next_point_code); jo.put("start_device_code", start_device_code); jo.put("next_device_code", next_device_code); + jo.put("start_point_code2", start_device_code2); + jo.put("next_point_code2", next_device_code2); jo.put("start_device_code2", start_device_code2); jo.put("next_device_code2", next_device_code2); - jo.put("put_device_code", put_device_code); - jo.put("agv_action_type", agv_action_type); jo.put("priority", priority); jo.put("vehicle_code", vehicle_code); - jo.put("vehicle_code2", vehicle_code2); jo.put("vehicle_type", vehicle_type); - jo.put("storage_task_type", storage_task_type); - jo.put("agv_system_type", agv_system_type); - jo.put("start_height", start_height); - jo.put("next_height", next_height); - jo.put("oven_time", (int) Math.ceil(oven_time)); jo.put("remark", remark); jo.put("params", params); - jo.put("params2", params2); + jo.put("agv_system_type", agv_system_type); + jo.put("agv_action_type", agv_action_type); jo.put("task_type", StrUtil.isEmpty(task_type) ? 1 : Integer.parseInt(task_type)); - jo.put("class_type", class_type); - jo.put("route_plan_code", route_plan_code); - jo.put("paper_array", JSONUtil.toJsonStr(paper_array)); - jo.put("truss_type", JSONUtil.toJsonStr(truss_type)); - jo.put("empty_site", JSONUtil.toJsonStr(empty_site)); - jo.put("is_bushing", JSONUtil.toJsonStr(is_bushing)); - jo.put("is_pulling", JSONUtil.toJsonStr(is_pulling)); - jo.put("size", JSONUtil.toJsonStr(size)); - jo.put("version", JSONUtil.toJsonStr(version)); - jo.put("bushing_num", JSONUtil.toJsonStr(bushing_num)); - if (!StrUtil.isEmpty(ext_task_id)) { - jo.put("ext_task_id", ext_task_id); - } + jo.put("put_device_code", put_device_code); TaskDto task_dto = jo.toJavaObject(TaskDto.class); try { - if (ObjectUtil.isNotEmpty(request.getInteraction_json())) { - task_dto.setInteractionJson(request.getInteraction_json()); - } +// if (ObjectUtil.isNotEmpty(task.getInteraction_json())) { +// task_dto.setInteractionJson(task.getInteraction_json()); +// } taskserver.create(task_dto); } catch (Exception e) { // e.printStackTrace(); JSONObject json = new JSONObject(); json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); + json.put("ext_task_id", ext_task_uuid); json.put("message", e.getMessage()); errArr.add(json); continue; } - if ("RK1002".equals(task_dto.getStart_device_code())){ - Device device = deviceAppService.findDeviceByCode("RK1003"); - BeltConveyorDeviceDriver beltConveyorDeviceDriver1; - if (device.getDeviceDriver() instanceof BeltConveyorDeviceDriver) { - beltConveyorDeviceDriver1 = (BeltConveyorDeviceDriver) device.getDeviceDriver(); - List list1 = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_command"); - map.put("value", "55"); - list1.add(map); - beltConveyorDeviceDriver1.writing(list1); - } - - } } if (ObjectUtil.isEmpty(errArr)) { response.setStatus(200); @@ -500,34 +366,26 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } @Override - public PutActionResponse putAction(String jsonObject) throws Exception { - log.info("WMS下发点位信号--------------:输入参数" + jsonObject); - String date = new Date().toString(); + public PutActionResponse putAction(String whereJson) throws Exception { + log.info("WMS下发点位信号--------------:输入参数" + whereJson); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); LuceneLogDto logDto = LuceneLogDto.builder() .device_code("WMS下发点位信号") - .content("WMS下发点位信号-----输入参数:" + jsonObject) + .content("WMS下发点位信号-----输入参数:" + whereJson) .build(); logDto.setLog_level(4); luceneExecuteLogService.deviceExecuteLog(logDto); - JSONArray datas = JSONArray.parseArray(jsonObject); PutActionResponse response = new PutActionResponse(); - JSONArray errArr = new JSONArray(); - for (int i = 0; i < datas.size(); i++) { - String data = datas.get(i).toString(); - PutActionRequest request = JsonUtl.format(data, PutActionRequest.class); - String device_code = request.getDevice_code(); - String code = request.getCode(); - String value = request.getValue(); - Device device = deviceAppService.findDeviceByCode(device_code); - if (ObjectUtil.isEmpty(device)) { - throw new Exception("未找到对应设备:" + device_code); - } - BeltConveyorDeviceDriver beltConveyorDeviceDriver; - if (device.getDeviceDriver() instanceof BeltConveyorDeviceDriver) { - beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) device.getDeviceDriver(); - beltConveyorDeviceDriver.writing(code, value); - } - } + JSONObject jsonObject = JSONObject.parseObject(whereJson); + + String device_code = jsonObject.getString("point_code"); + //1-进入; 0-离开 + String option = jsonObject.getString("option"); + Device device = deviceAppService.findDeviceByCode(device_code); + device.setAddress(option); + device.setUpdate_time(DateUtil.now()); + device.setUpdate_by("WMS"); + deviceService.updateById(device); response.setStatus(200); response.setMessage("success"); LuceneLogDto logDto1 = LuceneLogDto.builder() @@ -541,7 +399,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } - @Override public Map getTubeMes(String jsonObject) throws Exception { log.info("下发管芯信息--------------:输入参数" + jsonObject); @@ -582,8 +439,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { JSONArray datas = JSONArray.parseArray(jsonObject); - - //标准版输送线 BeltConveyorDeviceDriver beltConveyorDeviceDriver; diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index c7014e7..64b6a62 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -459,13 +459,7 @@ public class InstructionServiceImpl extends CommonServiceImpl" + dto.getNext_device_code() + "路由不通"); } -// if (StrUtil.equals(shortPathsList.get(0).getType(), CommonFinalParam.ONE)) { -// throw new BadRequestException(dto.getStart_device_code() + "->" + dto.getNext_device_code() + "路由类型不是agv类型"); -// } - if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { - NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); - ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); - } + if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "5")) { HttpResponse response = keCongAgvService.addTask(dto); JSONObject jsonObject = null; @@ -476,7 +470,9 @@ public class InstructionServiceImpl extends CommonServiceImpl" + dto.getNext_device_code() + "任务下发科聪调度失败!"); } } } catch (Exception e) { @@ -1171,7 +1167,12 @@ public class InstructionServiceImpl extends CommonServiceImpl query(@RequestParam Map whereJson, PageQuery page) { - //写入标签 - //bmVehicleRfidService.writeEpc("1"); - return new ResponseEntity<>(TableDataInfo.build(bmVehicleRfidService.query(whereJson, page)), HttpStatus.OK); - } - - - - - /** - * 条件查询 - * - * @param params 查询条件 - */ - @PostMapping("/selectList") - //@SaCheckPermission("@el.check(BmVehicleRfid:list") - public ResponseEntity selectList(@RequestBody BmVehicleRfidParam params) { - return new ResponseEntity<>(bmVehicleRfidService.selectList(params), HttpStatus.OK); - } - - - /** - * 新增数据 - * - * @param params 实体对象 - * @return 新增结果 - */ - @PostMapping - //@SaCheckPermission("@el.check(BmVehicleRfid:add") - public ResponseEntity create(@RequestBody BmVehicleRfidParam params) { - bmVehicleRfidService.create(params); - return new ResponseEntity<>(HttpStatus.OK); - } - - /** - * 连接测试 - * @return 结果 - */ - @PostMapping("/open") - //@SaCheckPermission("@el.check(BmVehicleRfid:add") - public ResponseEntity connectRfid(@RequestBody BmVehicleRfidParam params) { - bmVehicleRfidService.connectRfid(params); - return new ResponseEntity<>(HttpStatus.OK); - } - - - /** - * 修改数据 - * - * @param params 实体对象 - * @return 修改结果 - */ - @PutMapping - //@SaCheckPermission("@el.check(BmVehicleRfid:edit')") - public ResponseEntity update(@RequestBody BmVehicleRfidParam params) { - bmVehicleRfidService.update(params); - return new ResponseEntity<>(HttpStatus.OK); - } - - - /** - * 删除数据 - * - * @param ids 多个主键Id - * @return 删除结果 - */ - //@SaCheckPermission("@el.check(BmVehicleRfid:del')") - @DeleteMapping - public ResponseEntity delete(@RequestBody Set ids) { - bmVehicleRfidService.deleteAll(ids); - return new ResponseEntity<>(HttpStatus.OK); - } -} +//package org.nl.acs.rfid_manage.controller; +// +//import cn.dev33.satoken.annotation.SaIgnore; +//import lombok.RequiredArgsConstructor; +//import lombok.extern.slf4j.Slf4j; +//import org.nl.acs.rfid_manage.service.IbmVehicleRfidService; +//import org.nl.acs.rfid_manage.service.dto.BmVehicleRfidParam; +//import org.nl.common.base.TableDataInfo; +//import org.nl.common.domain.query.PageQuery; +//import org.springframework.http.HttpStatus; +//import org.springframework.http.ResponseEntity; +//import org.springframework.web.bind.annotation.*; +// +//import javax.annotation.Resource; +//import java.util.Map; +//import java.util.Set; +// +// +//@RestController +//@RequiredArgsConstructor +//@RequestMapping("/api/rfid") +//@Slf4j +//@SaIgnore +//public class BmVehicleRfidController { +// +// @Resource +// private IbmVehicleRfidService bmVehicleRfidService; +// +// +// /** +// * 分页查询 +// * +// * @param whereJson 查询条件 +// * @param page 分页参数 +// */ +// @GetMapping +// //@SaCheckPermission("@el.check(BmVehicleRfid:list") +// public ResponseEntity query(@RequestParam Map whereJson, PageQuery page) { +// //写入标签 +// //bmVehicleRfidService.writeEpc("1"); +// return new ResponseEntity<>(TableDataInfo.build(bmVehicleRfidService.query(whereJson, page)), HttpStatus.OK); +// } +// +// +// +// +// /** +// * 条件查询 +// * +// * @param params 查询条件 +// */ +// @PostMapping("/selectList") +// //@SaCheckPermission("@el.check(BmVehicleRfid:list") +// public ResponseEntity selectList(@RequestBody BmVehicleRfidParam params) { +// return new ResponseEntity<>(bmVehicleRfidService.selectList(params), HttpStatus.OK); +// } +// +// +// /** +// * 新增数据 +// * +// * @param params 实体对象 +// * @return 新增结果 +// */ +// @PostMapping +// //@SaCheckPermission("@el.check(BmVehicleRfid:add") +// public ResponseEntity create(@RequestBody BmVehicleRfidParam params) { +// bmVehicleRfidService.create(params); +// return new ResponseEntity<>(HttpStatus.OK); +// } +// +// /** +// * 连接测试 +// * @return 结果 +// */ +// @PostMapping("/open") +// //@SaCheckPermission("@el.check(BmVehicleRfid:add") +// public ResponseEntity connectRfid(@RequestBody BmVehicleRfidParam params) { +// bmVehicleRfidService.connectRfid(params); +// return new ResponseEntity<>(HttpStatus.OK); +// } +// +// +// /** +// * 修改数据 +// * +// * @param params 实体对象 +// * @return 修改结果 +// */ +// @PutMapping +// //@SaCheckPermission("@el.check(BmVehicleRfid:edit')") +// public ResponseEntity update(@RequestBody BmVehicleRfidParam params) { +// bmVehicleRfidService.update(params); +// return new ResponseEntity<>(HttpStatus.OK); +// } +// +// +// /** +// * 删除数据 +// * +// * @param ids 多个主键Id +// * @return 删除结果 +// */ +// //@SaCheckPermission("@el.check(BmVehicleRfid:del')") +// @DeleteMapping +// public ResponseEntity delete(@RequestBody Set ids) { +// bmVehicleRfidService.deleteAll(ids); +// return new ResponseEntity<>(HttpStatus.OK); +// } +//} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/rfid_manage/service/IbmVehicleRfidService.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/rfid_manage/service/IbmVehicleRfidService.java index a07bf42..65935f7 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/rfid_manage/service/IbmVehicleRfidService.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/rfid_manage/service/IbmVehicleRfidService.java @@ -1,58 +1,58 @@ -package org.nl.acs.rfid_manage.service; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.IService; -import org.nl.acs.rfid_manage.service.dao.BmVehicleRfid; -import org.nl.acs.rfid_manage.service.dto.BmVehicleRfidParam; -import org.nl.common.domain.query.PageQuery; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -public interface IbmVehicleRfidService extends IService { - - /** - * 分页查询 - * - * @param whereJson 查询条件 - * @return IPage - */ - IPage query(Map whereJson, PageQuery page); - - /** - * 条件查询 - * - * @param params 查询条件 - * @return List - */ - List selectList(BmVehicleRfidParam params); - - - /** - * 创建 - * - * @param params 对象实体 - */ - void create(BmVehicleRfidParam params); - - - /** - * 编辑 - * - * @param params 对象实体 - */ - void update(BmVehicleRfidParam params); - - /** - * 多选删除 - * - * @param ids / - */ - void deleteAll(Set ids); - - - void connectRfid(BmVehicleRfidParam params); - - void writeEpc(String id); -} +//package org.nl.acs.rfid_manage.service; +// +//import com.baomidou.mybatisplus.core.metadata.IPage; +//import com.baomidou.mybatisplus.extension.service.IService; +//import org.nl.acs.rfid_manage.service.dao.BmVehicleRfid; +//import org.nl.acs.rfid_manage.service.dto.BmVehicleRfidParam; +//import org.nl.common.domain.query.PageQuery; +// +//import java.util.List; +//import java.util.Map; +//import java.util.Set; +// +//public interface IbmVehicleRfidService extends IService { +// +// /** +// * 分页查询 +// * +// * @param whereJson 查询条件 +// * @return IPage +// */ +// IPage query(Map whereJson, PageQuery page); +// +// /** +// * 条件查询 +// * +// * @param params 查询条件 +// * @return List +// */ +// List selectList(BmVehicleRfidParam params); +// +// +// /** +// * 创建 +// * +// * @param params 对象实体 +// */ +// void create(BmVehicleRfidParam params); +// +// +// /** +// * 编辑 +// * +// * @param params 对象实体 +// */ +// void update(BmVehicleRfidParam params); +// +// /** +// * 多选删除 +// * +// * @param ids / +// */ +// void deleteAll(Set ids); +// +// +// void connectRfid(BmVehicleRfidParam params); +// +// void writeEpc(String id); +//} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/rfid_manage/service/impl/BmVehicleRfidServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/rfid_manage/service/impl/BmVehicleRfidServiceImpl.java index 88ffc39..0c908d7 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/rfid_manage/service/impl/BmVehicleRfidServiceImpl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/rfid_manage/service/impl/BmVehicleRfidServiceImpl.java @@ -1,512 +1,512 @@ -package org.nl.acs.rfid_manage.service.impl; - -import cn.hutool.core.date.DateTime; -import cn.hutool.core.date.DateUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.gg.reader.api.dal.GClient; -import com.gg.reader.api.dal.HandlerTagEpcLog; -import com.gg.reader.api.dal.HandlerTcpDisconnected; -import com.gg.reader.api.protocol.gx.*; -import org.apache.commons.lang3.StringUtils; -import org.nl.acs.rfid_manage.service.IbmVehicleRfidService; -import org.nl.acs.rfid_manage.service.dao.BmVehicleRfid; -import org.nl.acs.rfid_manage.service.dao.mapper.BmVehicleRfidMapper; -import org.nl.acs.rfid_manage.service.dto.BmVehicleRfidParam; -import org.nl.acs.rfid_manage.service.dto.EpcRecord; -import org.nl.acs.utils.StructUtil; -import org.nl.common.domain.query.PageQuery; -import org.springframework.beans.BeanUtils; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.time.Duration; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -@Service("bmVehicleRfidService") -public class BmVehicleRfidServiceImpl extends ServiceImpl implements IbmVehicleRfidService { - - @Resource - private BmVehicleRfidMapper bmVehicleRfidMapper; - // EPC 缓存:设备ID -> 天线号 -> EPC记录对象(包含EPC值 + 时间戳) - - private static final ConcurrentHashMap> epcCache = new ConcurrentHashMap<>(); - - //rfid读写器列表 - private static final ConcurrentHashMap clientMap = new ConcurrentHashMap<>(); - - // 缓存过期时间,单位:毫秒(例如5分钟) - private static final long EXPIRE_MILLIS = 5 * 60 * 1000; - - @Override - public void connectRfid(BmVehicleRfidParam params) { - //reconnectAllDisconnectedClients(); - List clientList = this.list(new QueryWrapper().eq("is_used", '1')); - for (BmVehicleRfid r : clientList) { - String deviceId = r.getId(); - GClient client = clientMap.get(deviceId); - String port = StringUtils.isNotBlank(params.getPort()) ? params.getPort() : r.getPort(); - String ip = r.getIp() + ":" + port; - // 打开连接命令 "1" 为开启所有设备连接,"0" 为关闭所有设备连接 - if ("1".equals(params.getIsOpen())) { - // 如果客户端连接对象不存在或未打开,创建新连接 - if (client == null) { - client = new GClient(); - if (client.openTcp(ip, 2000)) { - addClient(deviceId, client); - client.setSendHeartBeat(true); - stopEpc(deviceId); - // 发送扫码启动命令 - MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc(); - msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1); // 默认1号天线 - msgBaseInventoryEpc.setInventoryMode(EnumG.InventoryMode_Inventory); - client.sendSynMsg(msgBaseInventoryEpc); - if (msgBaseInventoryEpc.getRtCode() == 0x00) { - System.out.println("设备[" + ip + "] 开始扫码任务成功"); - } else { - System.err.println("设备[" + ip + "] 扫码配置失败: " + msgBaseInventoryEpc.getRtMsg()); - } - //写入数据 -// MsgBaseWriteEpc msg = new MsgBaseWriteEpc(); -// msg.setAntennaEnable(EnumG.AntennaNo_1); -// //字起始地址 第0个为CRC,不可写 -// msg.setStart(1);//word -// //写EPC,数据默认为 hex 432 -// msg.setArea(EnumG.WriteArea_Epc); -// String sWriteHexData = "888"; // 写入数据 (16进制) -// System.out.println("Write hex " + sWriteHexData); -// int iWordLen = StructUtil.getValueLen(sWriteHexData); -// // PC值为EPC区域的长度标识(前5个bit标记长度),参考文档说明 -// sWriteHexData = StructUtil.getPc(iWordLen) + StructUtil.padLeft(sWriteHexData.toUpperCase(), 4 * iWordLen, '0'); // PC值+数据内容 -// msg.setHexWriteData(sWriteHexData); -// // 若需要写入带特殊编码数据,请自行进行编码并使用 "BwriteData" 属性。 -// // msg.setBwriteData(HexUtils.hexString2Bytes(sWriteHexData)); -// client.sendSynMsg(msg); -// if (0 == msg.getRtCode()) { -// System.out.println("写入:" + sWriteHexData + "成功!"); +//package org.nl.acs.rfid_manage.service.impl; +// +//import cn.hutool.core.date.DateTime; +//import cn.hutool.core.date.DateUtil; +//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +//import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +//import com.baomidou.mybatisplus.core.metadata.IPage; +//import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +//import com.gg.reader.api.dal.GClient; +//import com.gg.reader.api.dal.HandlerTagEpcLog; +//import com.gg.reader.api.dal.HandlerTcpDisconnected; +//import com.gg.reader.api.protocol.gx.*; +//import org.apache.commons.lang3.StringUtils; +//import org.nl.acs.rfid_manage.service.IbmVehicleRfidService; +//import org.nl.acs.rfid_manage.service.dao.BmVehicleRfid; +//import org.nl.acs.rfid_manage.service.dao.mapper.BmVehicleRfidMapper; +//import org.nl.acs.rfid_manage.service.dto.BmVehicleRfidParam; +//import org.nl.acs.rfid_manage.service.dto.EpcRecord; +//import org.nl.acs.utils.StructUtil; +//import org.nl.common.domain.query.PageQuery; +//import org.springframework.beans.BeanUtils; +//import org.springframework.stereotype.Service; +// +//import javax.annotation.Resource; +//import java.time.Duration; +//import java.time.LocalDateTime; +//import java.time.format.DateTimeFormatter; +//import java.util.List; +//import java.util.Map; +//import java.util.Set; +//import java.util.concurrent.ConcurrentHashMap; +// +//@Service("bmVehicleRfidService") +//public class BmVehicleRfidServiceImpl extends ServiceImpl implements IbmVehicleRfidService { +// +// @Resource +// private BmVehicleRfidMapper bmVehicleRfidMapper; +// // EPC 缓存:设备ID -> 天线号 -> EPC记录对象(包含EPC值 + 时间戳) +// +// private static final ConcurrentHashMap> epcCache = new ConcurrentHashMap<>(); +// +// //rfid读写器列表 +// private static final ConcurrentHashMap clientMap = new ConcurrentHashMap<>(); +// +// // 缓存过期时间,单位:毫秒(例如5分钟) +// private static final long EXPIRE_MILLIS = 5 * 60 * 1000; +// +// @Override +// public void connectRfid(BmVehicleRfidParam params) { +// //reconnectAllDisconnectedClients(); +// List clientList = this.list(new QueryWrapper().eq("is_used", '1')); +// for (BmVehicleRfid r : clientList) { +// String deviceId = r.getId(); +// GClient client = clientMap.get(deviceId); +// String port = StringUtils.isNotBlank(params.getPort()) ? params.getPort() : r.getPort(); +// String ip = r.getIp() + ":" + port; +// // 打开连接命令 "1" 为开启所有设备连接,"0" 为关闭所有设备连接 +// if ("1".equals(params.getIsOpen())) { +// // 如果客户端连接对象不存在或未打开,创建新连接 +// if (client == null) { +// client = new GClient(); +// if (client.openTcp(ip, 2000)) { +// addClient(deviceId, client); +// client.setSendHeartBeat(true); +// stopEpc(deviceId); +// // 发送扫码启动命令 +// MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc(); +// msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1); // 默认1号天线 +// msgBaseInventoryEpc.setInventoryMode(EnumG.InventoryMode_Inventory); +// client.sendSynMsg(msgBaseInventoryEpc); +// if (msgBaseInventoryEpc.getRtCode() == 0x00) { +// System.out.println("设备[" + ip + "] 开始扫码任务成功"); // } else { -// System.out.println("写入:" + sWriteHexData + "失败!"); +// System.err.println("设备[" + ip + "] 扫码配置失败: " + msgBaseInventoryEpc.getRtMsg()); // } - - // 订阅标签事件 - subscribeHandler(client, deviceId); - MsgAppGetBaseVersion msgAppGetBaseVersion = new MsgAppGetBaseVersion(); - //获取版本号 - client.sendSynMsg(msgAppGetBaseVersion); - if (0x00 == msgAppGetBaseVersion.getRtCode()) { - System.out.println("msgAppGetBaseVersion[OK]."); - } else { - System.out.println(msgAppGetBaseVersion.getRtMsg()); - } - //获取设备信息 - MsgAppGetReaderInfo msgAppGetReaderInfo = new MsgAppGetReaderInfo(); - client.sendSynMsg(msgAppGetReaderInfo); - if (0x00 == msgAppGetReaderInfo.getRtCode()) { - System.out.println("msgAppGetReaderInfo[OK]."); - } else { - System.out.println(msgAppGetReaderInfo.getRtMsg()); - } - BmVehicleRfid updated = new BmVehicleRfid(); - updated.setId(deviceId); - updated.setStart_time(DateUtil.now()); - updated.setStatus(1); - updated.setLog(DateUtil.now() + ":设备:" + r.getDevice_code() + "连接服务器成功!"); - this.updateById(updated); - } else { - System.err.println("设备[" + ip + "] TCP连接失败"); - BmVehicleRfid updated = new BmVehicleRfid(); - updated.setId(deviceId); - updated.setRfid(null); - updated.setLog(DateUtil.now() + ":设备:" + r.getDevice_code() + "连接服务器失败!"); - updated.setStatus(0); - this.updateById(updated); - continue; - } - } - // 检查连接有效性(通过版本获取判断) - if (!checkConnection(client)) { - System.err.println("设备[" + ip + "] 连接无效,关闭重试"); - removeClient(deviceId); - } - } else if ("0".equals(params.getIsOpen())) { - // 关闭连接 - if (client != null) { - // MsgBaseStop stopMsg = new MsgBaseStop(); - // client.sendSynMsg(stopMsg); - // if (stopMsg.getRtCode() == 0x00) { - // System.out.println("设备[" + ip + "] 停止扫码任务成功"); - // } else { - // System.err.println("设备[" + ip + "] 停止扫码失败: " + stopMsg.getRtMsg()); - // } - // client.close(); - // removeClient(deviceId); - disconnectAllClients(); - System.out.println("设备[" + ip + "] 已断开连接"); - BmVehicleRfid updated = new BmVehicleRfid(); - updated.setId(deviceId); - updated.setRfid(null); - updated.setLog(DateUtil.now() + ":设备:" + r.getDevice_code() + "已与服务器断开连接!"); - updated.setStart_time(null); - updated.setStatus(0); - this.updateById(updated); - } else { - BmVehicleRfid updated = new BmVehicleRfid(); - updated.setId(deviceId); - updated.setLog(DateUtil.now() + ":设备:" + r.getDevice_code() + "未连接,无需断开"); - updated.setStart_time(null); - updated.setStatus(0); - this.updateById(updated); - System.out.println("设备[" + ip + "] 未连接,无需断开"); - } - } - } - } - - @Override - public void writeEpc(String id) { - GClient client = getClient("1"); - if (client != null) { - MsgBaseWriteEpc msg = new MsgBaseWriteEpc(); - stopEpc(id); - msg.setAntennaEnable(EnumG.AntennaNo_1); - //字起始地址 第0个为CRC,不可写 - msg.setStart(1);//word - //写EPC,数据默认为 hex 432 - msg.setArea(EnumG.WriteArea_Epc); - String sWriteHexData = "666"; // 写入数据 (16进制) - System.out.println("Write hex " + sWriteHexData); - int iWordLen = StructUtil.getValueLen(sWriteHexData); - // PC值为EPC区域的长度标识(前5个bit标记长度),参考文档说明 - sWriteHexData = StructUtil.getPc(iWordLen) + StructUtil.padLeft(sWriteHexData.toUpperCase(), 4 * iWordLen, '0'); // PC值+数据内容 - msg.setHexWriteData(sWriteHexData); - // 若需要写入带特殊编码数据,请自行进行编码并使用 "BwriteData" 属性。 - // msg.setBwriteData(HexUtils.hexString2Bytes(sWriteHexData)); - client.sendSynMsg(msg); - if (0 == msg.getRtCode()) { - System.out.println("写入:" + sWriteHexData + "成功!"); - } else { - System.out.println("写入:" + sWriteHexData + "失败!"); - } - } - } - - public void stopEpc(String id) { - GClient client = getClient("1"); - if (client != null) { - MsgBaseStop msgBaseStop = new MsgBaseStop(); - client.sendSynMsg(msgBaseStop); - if (0 == msgBaseStop.getRtCode()) { - System.out.println("停止成功!"); - } else { - System.out.println("停止失败!"); - } - } - } - - /** - * 判断设备是否已连接(通过获取版本信息判断) - */ - private boolean checkConnection(GClient client) { - try { - MsgAppGetBaseVersion versionMsg = new MsgAppGetBaseVersion(); - client.sendSynMsg(versionMsg); - return versionMsg.getRtCode() == 0x00; - } catch (Exception e) { - return false; - } - } - - /** - * 定时器执行断线重连 - */ - public void reconnectAllDisconnectedClients() { - List clientList = this.list(new QueryWrapper().eq("is_used", '1')); - for (BmVehicleRfid r : clientList) { - String ip = r.getIp() + ":" + r.getPort(); - System.out.println("设备[" + ip + "] 连接异常,开始重连..."); - if (tryReconnect(r.getId(), ip)) { - System.out.println("设备[" + ip + "] 重连成功"); - } else { - System.err.println("设备[" + ip + "] 重连失败"); - } - } - } - - public boolean tryReconnect(String deviceId, String ip) { - final int MAX_RETRY = 3; - final int WAIT_MS = 500; - for (int i = 1; i <= MAX_RETRY; i++) { - System.out.println("设备[" + ip + "] 第" + i + "次重连尝试..."); - GClient oldClient = clientMap.remove(deviceId); - if (oldClient != null) { - try { - oldClient.close(); - } catch (Exception ignored) { - } - } - GClient newClient = new GClient(); - if (newClient.openTcp(ip, 2000)) { - addClient(deviceId, newClient); - subscribeHandler(newClient, deviceId); - newClient.setSendHeartBeat(true); - if (checkConnection(newClient)) { - System.out.println("设备[" + ip + "] 重连成功"); - return true; - } else { - try { - newClient.close(); - } catch (Exception ignored) { - } - } - } - try { - Thread.sleep(WAIT_MS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return false; - } - } - return false; - } - - - public static GClient getClient(String deviceId) { - return clientMap.get(deviceId); - } - - public static void disconnectAllClients() { - for (String deviceId : clientMap.keySet()) { - removeClient(deviceId); - } - } - - - public static void addClient(String deviceId, GClient client) { - clientMap.put(deviceId, client); - } - - - public static void removeClient(String deviceId) { - GClient client = clientMap.remove(deviceId); - if (client != null) { - client.close(); - // try { - // MsgBaseStop stopMsg = new MsgBaseStop(); - // client.sendSynMsg(stopMsg); - // if (stopMsg.getRtCode() == 0x00) { - // System.out.println("停止扫码任务成功: " + deviceId); - // } else { - // System.err.println("停止扫码失败: " + stopMsg.getRtMsg()); - // } - // } catch (Exception e) { - // System.err.println("停止扫码任务异常: " + e.getMessage()); - // } finally { - // client.close(); - // System.out.println("已断开设备连接: " + deviceId); - // } - } - } - - - /** - * 上报RFID信息 - */ - private void subscribeHandler(GClient client, String id) { - //上报标签信息 - client.onTagEpcLog = new HandlerTagEpcLog() { - @Override - public void log(String s, LogBaseEpcInfo logBaseEpcInfo) { - if (logBaseEpcInfo != null && logBaseEpcInfo.getResult() == 0) { - String epc = logBaseEpcInfo.getEpc(); - handleEpc(epc, id, "1"); - } - } - }; - //断开连接通知 - client.onDisconnected = new HandlerTcpDisconnected() { - @Override - public void log(String s) { - System.out.println("command log output5:onDisconnected:" + "connect" + s + "close.........."); - client.close();//释放当前连接资源 - BmVehicleRfid updated = new BmVehicleRfid(); - updated.setId(id); - updated.setRfid(null); - // updated.setLog(DateUtil.now() + ":设备:" + r.getDevice_code() + "已与服务器断开连接!"); - updated.setStart_time(null); - updated.setStatus(0); - //todo 更新断开状态 - // this.updateById(updated); - } - }; - - } - - /** - * 主处理方法:如果 EPC 不同或过期,则更新数据库 - */ - private void handleEpc(String epc, String deviceId, String antenna) { - if (epc == null) { - return; - } - ConcurrentHashMap antennaMap = epcCache.get(deviceId); - EpcRecord record = antennaMap != null ? antennaMap.get(antenna) : null; - boolean isSame = record != null && epc.equals(record.epc) - && System.currentTimeMillis() - record.timestamp < EXPIRE_MILLIS; - - if (isSame) { - System.out.println(epc + "与上次标签值相同,不上报,跳过...."); - return; // EPC 相同且未过期,跳过 - } - epcCache.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>()) - .put(antenna, new EpcRecord(epc, System.currentTimeMillis())); - BmVehicleRfid currentDevice = this.getById(deviceId); - if (currentDevice != null && !epc.equals(currentDevice.getRfid())) { - BmVehicleRfid updated = new BmVehicleRfid(); - updated.setId(deviceId); - updated.setRfid(epc); - updated.setLog(DateUtil.now() + ":设备:" + currentDevice.getDevice_code() + "读取RFID值:" + epc + "成功!"); - this.updateById(updated); - System.out.println("读取RFID值:" + epc + "成功!"); - } - } - - - /** - * 定期清理过期 EPC 缓存(建议由定时任务调用) - */ - private void clearExpiredCache() { - long now = System.currentTimeMillis(); - for (Map.Entry> deviceEntry : epcCache.entrySet()) { - ConcurrentHashMap antennaMap = deviceEntry.getValue(); - for (Map.Entry antennaEntry : antennaMap.entrySet()) { - if (now - antennaEntry.getValue().timestamp >= EXPIRE_MILLIS) { - antennaMap.remove(antennaEntry.getKey()); - } - } - if (antennaMap.isEmpty()) { - epcCache.remove(deviceEntry.getKey()); - } - } - } - - - /** - * 查询数据分页 - * - * @param whereJson 查询条件 - * @param page 分页参数 - */ - @Override - public IPage query(Map whereJson, PageQuery page) { - IPage resultPage = new Page<>(page.getPage(), page.getSize()); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - IPage list = bmVehicleRfidMapper.selectPage(resultPage, queryWrapper); - list.getRecords().forEach(r -> { - if (r.getStart_time() != null) { - LocalDateTime createTime = LocalDateTime.parse(r.getStart_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - LocalDateTime updateTime = DateTime.now().toLocalDateTime(); - // 计算时间间隔 - Duration duration = Duration.between(createTime, updateTime); - if (duration.toMinutes() > 0) { - r.setOnline_time(duration.toMinutes() + "分钟"); - } else { - r.setOnline_time(duration.getSeconds() + "秒钟"); - } - } - }); - return list; - } - - - /** - * 根据条件查询 - * - * @param params 查询条件 - */ - @Override - public List selectList(BmVehicleRfidParam params) { - return bmVehicleRfidMapper.selectList(new QueryWrapper() - .lambda() - //.eq(ObjectUtil.isNotEmpty(params), BmVehicleRfid::getId, params.getFuzzy()) - //.or() - //.eq(ObjectUtil.isNotEmpty(params), BmVehicleRfid::getDjid, params.getFuzzy()) - ); - } - - - /** - * 创建 - * - * @param params 对象实体 - */ - @Override - public void create(BmVehicleRfidParam params) { - bmVehicleRfidMapper.insert(getBasicInfo(params, true)); - } - - - /** - * 编辑 - * - * @param params 对象实体 - */ - @Override - public void update(BmVehicleRfidParam params) { - // BmVehicleRfid dto = bmVehicleRfidMapper.selectById(params.getId()); - // if (dto == null) { - // throw new BadRequestException("不存在该数据!"); - // } - bmVehicleRfidMapper.updateById(getBasicInfo(params, false)); - } - - - /** - * 多选删除 - * - * @param ids 多个Id主键 - */ - @Override - public void deleteAll(Set ids) { - UpdateWrapper updateWrapper = new UpdateWrapper<>(); - updateWrapper.set("is_delete", "1") - //.set("update_optid", SecurityUtils.getCurrentUserId()) - //.set("update_optname", SecurityUtils.getCurrentNickName()) - //.set("update_time", DateUtil.now()) - .in("id", ids); - bmVehicleRfidMapper.update(null, updateWrapper); - //bmVehicleRfidMapper.deleteBatchIds(ids); - } - - - /** - * 获取实体基础信息 - * - * @param params 对象实体 - * @param isCreate 是否创建 - */ - private BmVehicleRfid getBasicInfo(BmVehicleRfidParam params, boolean isCreate) { - // if (isCreate) { - // params.setId(IdUtil.getStringId()); - // params.setCreate_id(Long.valueOf(SecurityUtils.getCurrentUserId())); - // params.setCreate_name(SecurityUtils.getCurrentNickName()); - // params.setCreate_time(DateUtil.now()); - // params.setIs_delete(IOSEnum.IS_NOTANDYES.code("否")); - // } - // params.setUpdate_optid(Long.valueOf(SecurityUtils.getCurrentUserId())); - // params.setUpdate_optname(SecurityUtils.getCurrentNickName()); - // params.setUpdate_time(DateUtil.now()); - BmVehicleRfid bmVehicleRfid = new BmVehicleRfid(); - BeanUtils.copyProperties(params, bmVehicleRfid); - return bmVehicleRfid; - } - -} +// //写入数据 +//// MsgBaseWriteEpc msg = new MsgBaseWriteEpc(); +//// msg.setAntennaEnable(EnumG.AntennaNo_1); +//// //字起始地址 第0个为CRC,不可写 +//// msg.setStart(1);//word +//// //写EPC,数据默认为 hex 432 +//// msg.setArea(EnumG.WriteArea_Epc); +//// String sWriteHexData = "888"; // 写入数据 (16进制) +//// System.out.println("Write hex " + sWriteHexData); +//// int iWordLen = StructUtil.getValueLen(sWriteHexData); +//// // PC值为EPC区域的长度标识(前5个bit标记长度),参考文档说明 +//// sWriteHexData = StructUtil.getPc(iWordLen) + StructUtil.padLeft(sWriteHexData.toUpperCase(), 4 * iWordLen, '0'); // PC值+数据内容 +//// msg.setHexWriteData(sWriteHexData); +//// // 若需要写入带特殊编码数据,请自行进行编码并使用 "BwriteData" 属性。 +//// // msg.setBwriteData(HexUtils.hexString2Bytes(sWriteHexData)); +//// client.sendSynMsg(msg); +//// if (0 == msg.getRtCode()) { +//// System.out.println("写入:" + sWriteHexData + "成功!"); +//// } else { +//// System.out.println("写入:" + sWriteHexData + "失败!"); +//// } +// +// // 订阅标签事件 +// subscribeHandler(client, deviceId); +// MsgAppGetBaseVersion msgAppGetBaseVersion = new MsgAppGetBaseVersion(); +// //获取版本号 +// client.sendSynMsg(msgAppGetBaseVersion); +// if (0x00 == msgAppGetBaseVersion.getRtCode()) { +// System.out.println("msgAppGetBaseVersion[OK]."); +// } else { +// System.out.println(msgAppGetBaseVersion.getRtMsg()); +// } +// //获取设备信息 +// MsgAppGetReaderInfo msgAppGetReaderInfo = new MsgAppGetReaderInfo(); +// client.sendSynMsg(msgAppGetReaderInfo); +// if (0x00 == msgAppGetReaderInfo.getRtCode()) { +// System.out.println("msgAppGetReaderInfo[OK]."); +// } else { +// System.out.println(msgAppGetReaderInfo.getRtMsg()); +// } +// BmVehicleRfid updated = new BmVehicleRfid(); +// updated.setId(deviceId); +// updated.setStart_time(DateUtil.now()); +// updated.setStatus(1); +// updated.setLog(DateUtil.now() + ":设备:" + r.getDevice_code() + "连接服务器成功!"); +// this.updateById(updated); +// } else { +// System.err.println("设备[" + ip + "] TCP连接失败"); +// BmVehicleRfid updated = new BmVehicleRfid(); +// updated.setId(deviceId); +// updated.setRfid(null); +// updated.setLog(DateUtil.now() + ":设备:" + r.getDevice_code() + "连接服务器失败!"); +// updated.setStatus(0); +// this.updateById(updated); +// continue; +// } +// } +// // 检查连接有效性(通过版本获取判断) +// if (!checkConnection(client)) { +// System.err.println("设备[" + ip + "] 连接无效,关闭重试"); +// removeClient(deviceId); +// } +// } else if ("0".equals(params.getIsOpen())) { +// // 关闭连接 +// if (client != null) { +// // MsgBaseStop stopMsg = new MsgBaseStop(); +// // client.sendSynMsg(stopMsg); +// // if (stopMsg.getRtCode() == 0x00) { +// // System.out.println("设备[" + ip + "] 停止扫码任务成功"); +// // } else { +// // System.err.println("设备[" + ip + "] 停止扫码失败: " + stopMsg.getRtMsg()); +// // } +// // client.close(); +// // removeClient(deviceId); +// disconnectAllClients(); +// System.out.println("设备[" + ip + "] 已断开连接"); +// BmVehicleRfid updated = new BmVehicleRfid(); +// updated.setId(deviceId); +// updated.setRfid(null); +// updated.setLog(DateUtil.now() + ":设备:" + r.getDevice_code() + "已与服务器断开连接!"); +// updated.setStart_time(null); +// updated.setStatus(0); +// this.updateById(updated); +// } else { +// BmVehicleRfid updated = new BmVehicleRfid(); +// updated.setId(deviceId); +// updated.setLog(DateUtil.now() + ":设备:" + r.getDevice_code() + "未连接,无需断开"); +// updated.setStart_time(null); +// updated.setStatus(0); +// this.updateById(updated); +// System.out.println("设备[" + ip + "] 未连接,无需断开"); +// } +// } +// } +// } +// +// @Override +// public void writeEpc(String id) { +// GClient client = getClient("1"); +// if (client != null) { +// MsgBaseWriteEpc msg = new MsgBaseWriteEpc(); +// stopEpc(id); +// msg.setAntennaEnable(EnumG.AntennaNo_1); +// //字起始地址 第0个为CRC,不可写 +// msg.setStart(1);//word +// //写EPC,数据默认为 hex 432 +// msg.setArea(EnumG.WriteArea_Epc); +// String sWriteHexData = "666"; // 写入数据 (16进制) +// System.out.println("Write hex " + sWriteHexData); +// int iWordLen = StructUtil.getValueLen(sWriteHexData); +// // PC值为EPC区域的长度标识(前5个bit标记长度),参考文档说明 +// sWriteHexData = StructUtil.getPc(iWordLen) + StructUtil.padLeft(sWriteHexData.toUpperCase(), 4 * iWordLen, '0'); // PC值+数据内容 +// msg.setHexWriteData(sWriteHexData); +// // 若需要写入带特殊编码数据,请自行进行编码并使用 "BwriteData" 属性。 +// // msg.setBwriteData(HexUtils.hexString2Bytes(sWriteHexData)); +// client.sendSynMsg(msg); +// if (0 == msg.getRtCode()) { +// System.out.println("写入:" + sWriteHexData + "成功!"); +// } else { +// System.out.println("写入:" + sWriteHexData + "失败!"); +// } +// } +// } +// +// public void stopEpc(String id) { +// GClient client = getClient("1"); +// if (client != null) { +// MsgBaseStop msgBaseStop = new MsgBaseStop(); +// client.sendSynMsg(msgBaseStop); +// if (0 == msgBaseStop.getRtCode()) { +// System.out.println("停止成功!"); +// } else { +// System.out.println("停止失败!"); +// } +// } +// } +// +// /** +// * 判断设备是否已连接(通过获取版本信息判断) +// */ +// private boolean checkConnection(GClient client) { +// try { +// MsgAppGetBaseVersion versionMsg = new MsgAppGetBaseVersion(); +// client.sendSynMsg(versionMsg); +// return versionMsg.getRtCode() == 0x00; +// } catch (Exception e) { +// return false; +// } +// } +// +// /** +// * 定时器执行断线重连 +// */ +// public void reconnectAllDisconnectedClients() { +// List clientList = this.list(new QueryWrapper().eq("is_used", '1')); +// for (BmVehicleRfid r : clientList) { +// String ip = r.getIp() + ":" + r.getPort(); +// System.out.println("设备[" + ip + "] 连接异常,开始重连..."); +// if (tryReconnect(r.getId(), ip)) { +// System.out.println("设备[" + ip + "] 重连成功"); +// } else { +// System.err.println("设备[" + ip + "] 重连失败"); +// } +// } +// } +// +// public boolean tryReconnect(String deviceId, String ip) { +// final int MAX_RETRY = 3; +// final int WAIT_MS = 500; +// for (int i = 1; i <= MAX_RETRY; i++) { +// System.out.println("设备[" + ip + "] 第" + i + "次重连尝试..."); +// GClient oldClient = clientMap.remove(deviceId); +// if (oldClient != null) { +// try { +// oldClient.close(); +// } catch (Exception ignored) { +// } +// } +// GClient newClient = new GClient(); +// if (newClient.openTcp(ip, 2000)) { +// addClient(deviceId, newClient); +// subscribeHandler(newClient, deviceId); +// newClient.setSendHeartBeat(true); +// if (checkConnection(newClient)) { +// System.out.println("设备[" + ip + "] 重连成功"); +// return true; +// } else { +// try { +// newClient.close(); +// } catch (Exception ignored) { +// } +// } +// } +// try { +// Thread.sleep(WAIT_MS); +// } catch (InterruptedException e) { +// Thread.currentThread().interrupt(); +// return false; +// } +// } +// return false; +// } +// +// +// public static GClient getClient(String deviceId) { +// return clientMap.get(deviceId); +// } +// +// public static void disconnectAllClients() { +// for (String deviceId : clientMap.keySet()) { +// removeClient(deviceId); +// } +// } +// +// +// public static void addClient(String deviceId, GClient client) { +// clientMap.put(deviceId, client); +// } +// +// +// public static void removeClient(String deviceId) { +// GClient client = clientMap.remove(deviceId); +// if (client != null) { +// client.close(); +// // try { +// // MsgBaseStop stopMsg = new MsgBaseStop(); +// // client.sendSynMsg(stopMsg); +// // if (stopMsg.getRtCode() == 0x00) { +// // System.out.println("停止扫码任务成功: " + deviceId); +// // } else { +// // System.err.println("停止扫码失败: " + stopMsg.getRtMsg()); +// // } +// // } catch (Exception e) { +// // System.err.println("停止扫码任务异常: " + e.getMessage()); +// // } finally { +// // client.close(); +// // System.out.println("已断开设备连接: " + deviceId); +// // } +// } +// } +// +// +// /** +// * 上报RFID信息 +// */ +// private void subscribeHandler(GClient client, String id) { +// //上报标签信息 +// client.onTagEpcLog = new HandlerTagEpcLog() { +// @Override +// public void log(String s, LogBaseEpcInfo logBaseEpcInfo) { +// if (logBaseEpcInfo != null && logBaseEpcInfo.getResult() == 0) { +// String epc = logBaseEpcInfo.getEpc(); +// handleEpc(epc, id, "1"); +// } +// } +// }; +// //断开连接通知 +// client.onDisconnected = new HandlerTcpDisconnected() { +// @Override +// public void log(String s) { +// System.out.println("command log output5:onDisconnected:" + "connect" + s + "close.........."); +// client.close();//释放当前连接资源 +// BmVehicleRfid updated = new BmVehicleRfid(); +// updated.setId(id); +// updated.setRfid(null); +// // updated.setLog(DateUtil.now() + ":设备:" + r.getDevice_code() + "已与服务器断开连接!"); +// updated.setStart_time(null); +// updated.setStatus(0); +// //todo 更新断开状态 +// // this.updateById(updated); +// } +// }; +// +// } +// +// /** +// * 主处理方法:如果 EPC 不同或过期,则更新数据库 +// */ +// private void handleEpc(String epc, String deviceId, String antenna) { +// if (epc == null) { +// return; +// } +// ConcurrentHashMap antennaMap = epcCache.get(deviceId); +// EpcRecord record = antennaMap != null ? antennaMap.get(antenna) : null; +// boolean isSame = record != null && epc.equals(record.epc) +// && System.currentTimeMillis() - record.timestamp < EXPIRE_MILLIS; +// +// if (isSame) { +// System.out.println(epc + "与上次标签值相同,不上报,跳过...."); +// return; // EPC 相同且未过期,跳过 +// } +// epcCache.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>()) +// .put(antenna, new EpcRecord(epc, System.currentTimeMillis())); +// BmVehicleRfid currentDevice = this.getById(deviceId); +// if (currentDevice != null && !epc.equals(currentDevice.getRfid())) { +// BmVehicleRfid updated = new BmVehicleRfid(); +// updated.setId(deviceId); +// updated.setRfid(epc); +// updated.setLog(DateUtil.now() + ":设备:" + currentDevice.getDevice_code() + "读取RFID值:" + epc + "成功!"); +// this.updateById(updated); +// System.out.println("读取RFID值:" + epc + "成功!"); +// } +// } +// +// +// /** +// * 定期清理过期 EPC 缓存(建议由定时任务调用) +// */ +// private void clearExpiredCache() { +// long now = System.currentTimeMillis(); +// for (Map.Entry> deviceEntry : epcCache.entrySet()) { +// ConcurrentHashMap antennaMap = deviceEntry.getValue(); +// for (Map.Entry antennaEntry : antennaMap.entrySet()) { +// if (now - antennaEntry.getValue().timestamp >= EXPIRE_MILLIS) { +// antennaMap.remove(antennaEntry.getKey()); +// } +// } +// if (antennaMap.isEmpty()) { +// epcCache.remove(deviceEntry.getKey()); +// } +// } +// } +// +// +// /** +// * 查询数据分页 +// * +// * @param whereJson 查询条件 +// * @param page 分页参数 +// */ +// @Override +// public IPage query(Map whereJson, PageQuery page) { +// IPage resultPage = new Page<>(page.getPage(), page.getSize()); +// LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); +// IPage list = bmVehicleRfidMapper.selectPage(resultPage, queryWrapper); +// list.getRecords().forEach(r -> { +// if (r.getStart_time() != null) { +// LocalDateTime createTime = LocalDateTime.parse(r.getStart_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); +// LocalDateTime updateTime = DateTime.now().toLocalDateTime(); +// // 计算时间间隔 +// Duration duration = Duration.between(createTime, updateTime); +// if (duration.toMinutes() > 0) { +// r.setOnline_time(duration.toMinutes() + "分钟"); +// } else { +// r.setOnline_time(duration.getSeconds() + "秒钟"); +// } +// } +// }); +// return list; +// } +// +// +// /** +// * 根据条件查询 +// * +// * @param params 查询条件 +// */ +// @Override +// public List selectList(BmVehicleRfidParam params) { +// return bmVehicleRfidMapper.selectList(new QueryWrapper() +// .lambda() +// //.eq(ObjectUtil.isNotEmpty(params), BmVehicleRfid::getId, params.getFuzzy()) +// //.or() +// //.eq(ObjectUtil.isNotEmpty(params), BmVehicleRfid::getDjid, params.getFuzzy()) +// ); +// } +// +// +// /** +// * 创建 +// * +// * @param params 对象实体 +// */ +// @Override +// public void create(BmVehicleRfidParam params) { +// bmVehicleRfidMapper.insert(getBasicInfo(params, true)); +// } +// +// +// /** +// * 编辑 +// * +// * @param params 对象实体 +// */ +// @Override +// public void update(BmVehicleRfidParam params) { +// // BmVehicleRfid dto = bmVehicleRfidMapper.selectById(params.getId()); +// // if (dto == null) { +// // throw new BadRequestException("不存在该数据!"); +// // } +// bmVehicleRfidMapper.updateById(getBasicInfo(params, false)); +// } +// +// +// /** +// * 多选删除 +// * +// * @param ids 多个Id主键 +// */ +// @Override +// public void deleteAll(Set ids) { +// UpdateWrapper updateWrapper = new UpdateWrapper<>(); +// updateWrapper.set("is_delete", "1") +// //.set("update_optid", SecurityUtils.getCurrentUserId()) +// //.set("update_optname", SecurityUtils.getCurrentNickName()) +// //.set("update_time", DateUtil.now()) +// .in("id", ids); +// bmVehicleRfidMapper.update(null, updateWrapper); +// //bmVehicleRfidMapper.deleteBatchIds(ids); +// } +// +// +// /** +// * 获取实体基础信息 +// * +// * @param params 对象实体 +// * @param isCreate 是否创建 +// */ +// private BmVehicleRfid getBasicInfo(BmVehicleRfidParam params, boolean isCreate) { +// // if (isCreate) { +// // params.setId(IdUtil.getStringId()); +// // params.setCreate_id(Long.valueOf(SecurityUtils.getCurrentUserId())); +// // params.setCreate_name(SecurityUtils.getCurrentNickName()); +// // params.setCreate_time(DateUtil.now()); +// // params.setIs_delete(IOSEnum.IS_NOTANDYES.code("否")); +// // } +// // params.setUpdate_optid(Long.valueOf(SecurityUtils.getCurrentUserId())); +// // params.setUpdate_optname(SecurityUtils.getCurrentNickName()); +// // params.setUpdate_time(DateUtil.now()); +// BmVehicleRfid bmVehicleRfid = new BmVehicleRfid(); +// BeanUtils.copyProperties(params, bmVehicleRfid); +// return bmVehicleRfid; +// } +// +//} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/storage_cell/service/StorageCellService.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/storage_cell/service/StorageCellService.java index 3db5ca3..8bbbbd6 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/storage_cell/service/StorageCellService.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/storage_cell/service/StorageCellService.java @@ -117,7 +117,7 @@ public interface StorageCellService extends CommonService { * @param code code * @return StorageCell */ -// StorageCellDto findByCode(String code); + StorageCellDto findByCode(String code); /** * 根据地址查询 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 8a77885..1688dec 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 @@ -348,7 +348,7 @@ public class TaskDto implements Serializable { /** * 扩展属性 */ - String params2; + String params; /** * 是否拔轴 0/1 @@ -361,6 +361,11 @@ public class TaskDto implements Serializable { */ private Integer agv_action_type; + /** + * 外部系统标识 + */ + private String ext_task_uuid; + /** * 任务类型 * 9 子卷下线行架任务 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 1ae68be..3a2d1ce 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 @@ -910,10 +910,6 @@ public class TaskServiceImpl extends CommonServiceImpl impleme if (!TaskStatusEnum.FINISHED.getIndex().equals(updateTask.getTask_status())) { //反馈上位系统任务状态 this.feedWmsTaskStatus(entity); - //关闭仙工运单序列 - if (StrUtil.equals(task.getTask_type(), TaskTypeEnum.Standard_AGV_Task.getCode()) && (StrUtil.equals(task.getAgv_system_type(), AgvSystemTypeEnum.One_NDC_System_Type.getCode()) || StrUtil.equals(task.getAgv_system_type(), AgvSystemTypeEnum.XG_System_Type.getCode()))) { - this.markComplete(entity); - } } } @@ -1804,17 +1800,17 @@ public class TaskServiceImpl extends CommonServiceImpl impleme if (ObjectUtil.isNotEmpty(entity.getCarno())) { feed_jo.put("car_no", entity.getCarno()); } - JSONArray ja = new JSONArray(); - ja.add(feed_jo); +// JSONArray ja = new JSONArray(); +// ja.add(feed_jo); //TODO 有需要根据上位系统反馈的信息再做进一步处理 - CompletableFuture.runAsync(() -> { - acstowmsService.feedTaskStatus(ja); +// CompletableFuture.runAsync(() -> { // 异步更新任务状态 try { + acstowmsService.feedTaskStatus(feed_jo); } catch (Exception e) { e.printStackTrace(); } - }); +// }); } } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/StructUtil.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/StructUtil.java index 6aa2d45..bb836d4 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/StructUtil.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/StructUtil.java @@ -1,66 +1,66 @@ -package org.nl.acs.utils; - -import com.gg.reader.api.utils.BitBuffer; -import com.gg.reader.api.utils.HexUtils; - -public class StructUtil { - - public static String getZdPoint(int row,String source_code) { - if (row == 2 || row == 3) { - return source_code; - } - int blockRow = row == 1 ? 2 : 3; - String replace = source_code.replaceFirst("L0" + row, "L0%s"); - return String.format(replace, blockRow); - } - - public static String getDeepPoint(int row,String source_code) { - if (row == 1 || row == 4) { - return source_code; - } - int blockRow = row == 2 ? 1 : 4; - String replace = source_code.replaceFirst("L0" + row, "L0%s"); - return String.format(replace, blockRow); - } - - public static String getPc(int pcLen) { - int iPc = pcLen << 11; - BitBuffer buffer = BitBuffer.allocateDynamic(); - buffer.put(iPc); - buffer.position(16); - byte[] bTmp = new byte[2]; - buffer.get(bTmp); - return HexUtils.bytes2HexString(bTmp); - } - - public static String getGbPc(int pcLen) { - int iPc = pcLen << 8; - BitBuffer buffer = BitBuffer.allocateDynamic(); - buffer.put(iPc); - buffer.position(16); - byte[] bTmp = new byte[2]; - buffer.get(bTmp); - return HexUtils.bytes2HexString(bTmp); - } - - //写入数据不足4位后面补'0' AA00 - public static String padLeft(String src, int len, char ch) { - int diff = len - src.length(); - if (diff <= 0) { - return src; - } - - char[] chars = new char[len]; - System.arraycopy(src.toCharArray(), 0, chars, 0, src.length()); - for (int i = src.length(); i < len; i++) { - chars[i] = ch; - } - return new String(chars); - } - - public static int getValueLen(String data) { - data = data.trim(); - return data.length() % 4 == 0 ? data.length() / 4 - : (data.length() / 4) + 1; - } -} +//package org.nl.acs.utils; +// +//import com.gg.reader.api.utils.BitBuffer; +//import com.gg.reader.api.utils.HexUtils; +// +//public class StructUtil { +// +// public static String getZdPoint(int row,String source_code) { +// if (row == 2 || row == 3) { +// return source_code; +// } +// int blockRow = row == 1 ? 2 : 3; +// String replace = source_code.replaceFirst("L0" + row, "L0%s"); +// return String.format(replace, blockRow); +// } +// +// public static String getDeepPoint(int row,String source_code) { +// if (row == 1 || row == 4) { +// return source_code; +// } +// int blockRow = row == 2 ? 1 : 4; +// String replace = source_code.replaceFirst("L0" + row, "L0%s"); +// return String.format(replace, blockRow); +// } +// +// public static String getPc(int pcLen) { +// int iPc = pcLen << 11; +// BitBuffer buffer = BitBuffer.allocateDynamic(); +// buffer.put(iPc); +// buffer.position(16); +// byte[] bTmp = new byte[2]; +// buffer.get(bTmp); +// return HexUtils.bytes2HexString(bTmp); +// } +// +// public static String getGbPc(int pcLen) { +// int iPc = pcLen << 8; +// BitBuffer buffer = BitBuffer.allocateDynamic(); +// buffer.put(iPc); +// buffer.position(16); +// byte[] bTmp = new byte[2]; +// buffer.get(bTmp); +// return HexUtils.bytes2HexString(bTmp); +// } +// +// //写入数据不足4位后面补'0' AA00 +// public static String padLeft(String src, int len, char ch) { +// int diff = len - src.length(); +// if (diff <= 0) { +// return src; +// } +// +// char[] chars = new char[len]; +// System.arraycopy(src.toCharArray(), 0, chars, 0, src.length()); +// for (int i = src.length(); i < len; i++) { +// chars[i] = ch; +// } +// return new String(chars); +// } +// +// public static int getValueLen(String data) { +// data = data.trim(); +// return data.length() % 4 == 0 ? data.length() / 4 +// : (data.length() / 4) + 1; +// } +//} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/quartz/task/AutoCreateInst.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/quartz/task/AutoCreateInst.java index 4bac297..4a59141 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/quartz/task/AutoCreateInst.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/quartz/task/AutoCreateInst.java @@ -57,18 +57,11 @@ public class AutoCreateInst { List list = taskserver.queryAllByStatus("0"); for (int i = 0; i < list.size(); i++) { TaskDto acsTask = list.get(i); - if (StrUtil.equals(acsTask.getTask_type(), TaskTypeEnum.AGV_Task.getIndex()) && !StrUtil.startWith(acsTask.getTask_code(), "-")) { - continue; - } - if (StrUtil.equals(acsTask.getTask_type(), TaskTypeEnum.Truss_Task.getIndex()) && !StrUtil.startWith(acsTask.getTask_code(), "-")) { - continue; - } String taskid = acsTask.getTask_id(); String taskcode = acsTask.getTask_code(); String task_type = acsTask.getTask_type(); String vehiclecode = acsTask.getVehicle_code(); String vehiclecode2 = acsTask.getVehicle_code2(); - String storage_task_type = acsTask.getStorage_task_type(); String priority = acsTask.getPriority(); String is_send = acsTask.getIs_send(); @@ -101,16 +94,16 @@ public class AutoCreateInst { } //校验路由关系 -// List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); -// if (ObjectUtils.isEmpty(shortPathsList)) { -// acsTask.setRemark("路由不通无法生成指令"); -// taskserver.updateByCodeFromCache(acsTask); -// continue; -// } -// -// if (!StrUtil.equals(shortPathsList.get(0).getType(), CommonFinalParam.ONE)) { -// continue; -// } + List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + if (ObjectUtils.isEmpty(shortPathsList)) { + acsTask.setRemark("路由不通无法生成指令"); + taskserver.updateByCodeFromCache(acsTask); + continue; + } + + if (!StrUtil.equals(shortPathsList.get(0).getType(), CommonFinalParam.ONE)) { + continue; + } // RouteLineDto routeLineDto = shortPathsList.get(0); // String path = routeLineDto.getPath(); @@ -147,9 +140,6 @@ public class AutoCreateInst { Instruction instdto = new Instruction(); instdto.setInstruction_type(task_type); instdto.setInstruction_id(IdUtil.simpleUUID()); - if (acsTask.getAgv_system_type().equals(AgvSystemTypeEnum.One_NDC_System_Type.getIndex())){ - instdto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } instdto.setRoute_plan_code(route_plan_code); instdto.setRemark(acsTask.getRemark()); instdto.setMaterial(acsTask.getMaterial()); @@ -182,34 +172,6 @@ public class AutoCreateInst { instdto.setStart_height(start_height); instdto.setNext_height(next_height); instdto.setAgv_action_type(agvActionType); - //判断agv系统 - //1、1楼叉车系统 - //2、2楼1区域AGV系统 - //3、2楼2区域AGV系统 -已废弃 - if (StrUtil.equals(agv_system_type, CommonFinalParam.TWO)) { - // task_type - //1、生箔; Itype=1:取空,取满,放空,放满; - //2、分切 Itype=3取满、取空、放满、放空; - //3、普通任务 Itype=2:取货、放货; - //4、叉车任务 - //5、输送任务 - //6、行架 - //7、立库 - if (StrUtil.equals(task_type, CommonFinalParam.ONE)) { - instdto.setAgv_inst_type(CommonFinalParam.ONE); - } else if (StrUtil.equals(task_type, "3")) { - instdto.setAgv_inst_type("2"); - } else if (StrUtil.equals(task_type, "2")) { - instdto.setAgv_inst_type("3"); - } else if (StrUtil.equals(task_type, "8")) { - instdto.setAgv_inst_type("2"); - } else { - log.info("未找到对应的AGV指令类型,任务号:" + acsTask.getTask_code() + ",task_type:" + acsTask.getTask_type()); - continue; - } - } else { - instdto.setAgv_inst_type("4"); - } try { instructionService.create(instdto); } catch (Exception e) { @@ -225,8 +187,6 @@ public class AutoCreateInst { } //创建指令后修改任务状态 acsTask.setTask_status(TaskStatusEnum.BUSY.getIndex()); - acsTask.setUpdate_time(DateUtil.now()); - acsTask.setRemark(" "); taskserver.update(acsTask); } diff --git a/acs2/nladmin-system/nlsso-server/src/main/resources/log/KeCongAgvServiceImpl.xml b/acs2/nladmin-system/nlsso-server/src/main/resources/log/KeCongAgvServiceImpl.xml new file mode 100644 index 0000000..4d7405a --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/resources/log/KeCongAgvServiceImpl.xml @@ -0,0 +1,29 @@ + + + + + + + + + ${LOG_HOME}/科聪agv请求/%d{yyyy-MM-dd}.%i.log + + 15 + + 50MB + + 2GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + ${log.charset} + + + + + + + + + diff --git a/acs2/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml b/acs2/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml index 427aaa5..ce996be 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml +++ b/acs2/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml @@ -68,11 +68,11 @@ https://juejin.cn/post/6844903775631572999 - - + + - + diff --git a/acs2/nladmin-ui/src/assets/images/ftdl.png b/acs2/nladmin-ui/src/assets/images/ftdl.png new file mode 100644 index 0000000..d065d63 Binary files /dev/null and b/acs2/nladmin-ui/src/assets/images/ftdl.png differ diff --git a/acs2/nladmin-ui/src/assets/images/miri.png b/acs2/nladmin-ui/src/assets/images/miri.png new file mode 100644 index 0000000..fca2d58 Binary files /dev/null and b/acs2/nladmin-ui/src/assets/images/miri.png differ diff --git a/acs2/nladmin-ui/src/layout/components/Sidebar/Logo.vue b/acs2/nladmin-ui/src/layout/components/Sidebar/Logo.vue index 34f9ee5..fb438b6 100644 --- a/acs2/nladmin-ui/src/layout/components/Sidebar/Logo.vue +++ b/acs2/nladmin-ui/src/layout/components/Sidebar/Logo.vue @@ -14,7 +14,7 @@ + + diff --git a/acs2/nladmin-ui/src/views/acs/device/driver/agv/agv_ndc_two.vue b/acs2/nladmin-ui/src/views/acs/device/driver/agv/agv_ndc_two.vue index e69de29..867afad 100644 --- a/acs2/nladmin-ui/src/views/acs/device/driver/agv/agv_ndc_two.vue +++ b/acs2/nladmin-ui/src/views/acs/device/driver/agv/agv_ndc_two.vue @@ -0,0 +1,114 @@ + + + + +