diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/AgvController.java b/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/AgvController.java index 8e5ed8a..f96af5f 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/AgvController.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/AgvController.java @@ -4,6 +4,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONObject; import org.apache.commons.lang3.StringUtils; import org.nl.acs.agv.server.AgvService; import org.nl.acs.device.service.DeviceService; @@ -96,5 +97,17 @@ public class AgvController { return new ResponseEntity<>(agvService.queryDeviceStation(), HttpStatus.OK); } + @PostMapping("/xgAGVControlDoorSwitch") + @Log("仙工AGV控制门开关") + @ApiOperation("仙工AGV控制门开关") + public ResponseEntity xgAGVControlDoorSwitch(@RequestBody JSONObject requestParam) { + return new ResponseEntity<>(agvService.xgAGVControlDoorSwitch(requestParam), HttpStatus.OK); + } + @PostMapping("/xgAGVQueryDoorStatus") + @Log("仙工AGV查询门状态") + @ApiOperation("仙工AGV查询门状态") + public ResponseEntity xgAGVQueryDoorStatus(@RequestBody JSONObject requestParam) { + return new ResponseEntity<>(agvService.xgAGVQueryDoorStatus(requestParam), HttpStatus.OK); + } } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java index 5d789c8..234f960 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java @@ -182,4 +182,38 @@ public interface AgvService { String queryDeviceStation(); + + /** + * 控制门开关 + * + * @param requestParam 请求参数 + * 示例:{ + * "deviceID":"DOOR_001", //门禁ID + * "state":"1", //控制指令 0关门 1开门 + * } + * @return 示例:{ + * "result":0, // -1操作失败 -2不存在当前设备 + * "message":"操作成功" + * } + */ + JSONObject xgAGVControlDoorSwitch(JSONObject requestParam); + + /** + * @param requestParam 请求参数 + * 示例:{ + * "deviceIDs":"DOOR_001,DOOR_002", //门禁ID,英文逗号分割 + * } + * @return 示例:{ + * "result": 0, + * "message": "操作成功", + * "data": [ + * { + * "deviceID": "设备id", + * "doorState": "门磁状态", // 0门磁吸合,指门已经完全关闭;1门磁未吸合,指门未完全关闭,可能处于打开中、打开到位、关闭中;-1门禁不在线 + * "timePoke": 0 //更新时间戳 + * } + * ] + * } + */ + JSONObject xgAGVQueryDoorStatus(JSONObject requestParam); } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java index 9d8a244..1694f16 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java @@ -44,11 +44,15 @@ import org.nl.logger.BusinessLogger; import org.nl.start.auto.run.NDCSocketConnectionAutoRun; import org.nl.utils.SpringContextHolder; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; @Slf4j @Service @@ -572,7 +576,7 @@ public class AgvServiceImpl implements AgvService { if (result.getStatus() == 200) { arr.add(result.body()); } - } catch (Exception e ){ + } catch (Exception e) { e.printStackTrace(); } } @@ -613,7 +617,7 @@ public class AgvServiceImpl implements AgvService { String transportOrder = jo.getString("transportOrder"); JSONObject detailjo = JSONObject.fromObject(result2.body()); JSONObject item = (JSONObject) detailjo.get(name); - if(ObjectUtil.isEmpty(detailjo.get(name))){ + if (ObjectUtil.isEmpty(detailjo.get(name))) { continue; } String x = item.getString("x"); @@ -901,7 +905,7 @@ public class AgvServiceImpl implements AgvService { yzjaSpecialDeviceDriver.setManua_confirm(0); inst.setExecute_status("1"); is_feedback = true; - } else if (ObjectUtil.isEmpty(inst.getExecute_status()) || !inst.getExecute_status().equals("1")){ + } else if (ObjectUtil.isEmpty(inst.getExecute_status()) || !inst.getExecute_status().equals("1")) { yzjaSpecialDeviceDriver.setManua_confirm(1); } } else { @@ -917,7 +921,7 @@ public class AgvServiceImpl implements AgvService { yzjaSpecialDeviceDriver.setManua_confirm(0); inst.setExecute_status("3"); is_feedback = true; - } else if (ObjectUtil.isEmpty(inst.getExecute_status()) || !inst.getExecute_status().equals("3")){ + } else if (ObjectUtil.isEmpty(inst.getExecute_status()) || !inst.getExecute_status().equals("3")) { yzjaSpecialDeviceDriver.setManua_confirm(1); } } else { @@ -1152,7 +1156,7 @@ public class AgvServiceImpl implements AgvService { //请求进 if (StrUtil.equals(type, "07") && address.endsWith("IQ")) { sandardManipulatorInspectSiteDeviceDriver.writing(1, 7); - if ( sandardManipulatorInspectSiteDeviceDriver.getIo_action() == 1 + if (sandardManipulatorInspectSiteDeviceDriver.getIo_action() == 1 || sandardManipulatorInspectSiteDeviceDriver.getIo_action() == 3) { is_feedback = true; } @@ -1854,8 +1858,8 @@ public class AgvServiceImpl implements AgvService { //起点 if (startdevice.getDeviceDriver() instanceof StandardManipulatorInspectSiteDeviceDriver) { standardManipulatorInspectSiteDeviceDriver = (StandardManipulatorInspectSiteDeviceDriver) startdevice.getDeviceDriver(); - if(ObjectUtil.equal(standardManipulatorInspectSiteDeviceDriver.getExtraValue().get("is_pickup_spin"),"true") && - ObjectUtil.isNotEmpty(standardManipulatorInspectSiteDeviceDriver.getExtraValue().get("pickup_spin")) ){ + if (ObjectUtil.equal(standardManipulatorInspectSiteDeviceDriver.getExtraValue().get("is_pickup_spin"), "true") && + ObjectUtil.isNotEmpty(standardManipulatorInspectSiteDeviceDriver.getExtraValue().get("pickup_spin"))) { ja.add(destination2(startAddress + "IQ", "Spin", "2", standardManipulatorInspectSiteDeviceDriver.getExtraValue().get("pickup_spin").toString())); } @@ -1889,8 +1893,8 @@ public class AgvServiceImpl implements AgvService { //终点 if (nextdevice.getDeviceDriver() instanceof StandardManipulatorInspectSiteDeviceDriver) { standardManipulatorInspectSiteDeviceDriver = (StandardManipulatorInspectSiteDeviceDriver) nextdevice.getDeviceDriver(); - if(ObjectUtil.equal(standardManipulatorInspectSiteDeviceDriver.getExtraValue().get("is_release_spin"),"true") && - ObjectUtil.isNotEmpty(standardManipulatorInspectSiteDeviceDriver.getExtraValue().get("release_spin")) ){ + if (ObjectUtil.equal(standardManipulatorInspectSiteDeviceDriver.getExtraValue().get("is_release_spin"), "true") && + ObjectUtil.isNotEmpty(standardManipulatorInspectSiteDeviceDriver.getExtraValue().get("release_spin"))) { ja.add(destination2(nextAddress + "IQ", "Spin", "2", standardManipulatorInspectSiteDeviceDriver.getExtraValue().get("release_spin").toString())); } @@ -2060,12 +2064,84 @@ public class AgvServiceImpl implements AgvService { return ret; } - public static void main(String[] args) { - String address = "L1-01-01"; - if (address.indexOf("-") > 0) { - String str = address.substring(address.indexOf("-"), address.length()); - address = address.substring(0, address.indexOf("-")); - System.out.println(address); + @Override + public JSONObject xgAGVControlDoorSwitch(JSONObject requestParam) { + try { + JSONObject requestWMSParam = new JSONObject(); + requestWMSParam.put("device_code", requestParam.optString("deviceID")); + requestWMSParam.put("device_status", "1".equals(requestParam.optString("state")) ? "open" : "close"); + JSONObject wmsResult = acsToWmsService.gccControlDoorSwitch(requestWMSParam); + + JSONObject result = new JSONObject(); + if (HttpStatus.OK.value() == wmsResult.optInt("status")) { + result.put("result", 0); + result.put("message", "操作成功"); + } else { + result.put("result", -1); + result.put("message", wmsResult.optString("message")); + } + return result; + } catch (Exception e) { + JSONObject result = new JSONObject(); + result.put("result", -1); + result.put("message", e.getMessage()); + return result; + } + } + + @Override + public JSONObject xgAGVQueryDoorStatus(JSONObject requestParam) { + String[] deviceIDs = requestParam.optString("deviceIDs").split(","); + + if (deviceIDs.length == 1 && StrUtil.isBlank(deviceIDs[0])) { + JSONObject result = new JSONObject(); + result.put("result", 0); + result.put("message", "操作成功"); + return result; + } + + try { + com.alibaba.fastjson.JSONArray wmsResult = acsToWmsService.gccQueryDoorStatus(); + + if (ObjectUtil.isEmpty(wmsResult)) { + JSONObject result = new JSONObject(); + result.put("result", 0); + result.put("message", "操作成功"); + result.put("data", Arrays.stream(deviceIDs) + .map(id -> { + JSONObject door = new JSONObject(); + door.put("deviceID", id); + door.put("doorState", -1); + door.put("timePoke", System.currentTimeMillis()); + return door; + }).collect(Collectors.toList())); + return result; + } + + List data = Arrays.stream(deviceIDs).map(id -> { + JSONObject door = new JSONObject(); + door.put("deviceID", id); + List list = wmsResult.stream().filter(o -> id.equals(((com.alibaba.fastjson.JSONObject) o).getString("device_code"))).collect(Collectors.toList()); + if (list.isEmpty()) { + door.put("doorState", -1); + } else { + com.alibaba.fastjson.JSONObject row = (com.alibaba.fastjson.JSONObject) list.get(0); + door.put("doorState", "close".equals(row.getString("device_status")) ? 0 : 1); + } + door.put("timePoke", System.currentTimeMillis()); + return door; + }).collect(Collectors.toList()); + + JSONObject result = new JSONObject(); + result.put("result", 0); + result.put("message", "操作成功"); + result.put("data", data); + return result; + } catch (Exception e) { + JSONObject result = new JSONObject(); + result.put("result", 0); + result.put("message", e.getMessage()); + return result; } } } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java index 3f2ff6c..574bcaf 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java @@ -108,4 +108,35 @@ public interface AcsToWmsService { HttpResponse queryDoorsStatus(); + /** + * 六维广钞厂请求开门或关门 + * + * @param requestWMSParam 示例:{ + * "device_code":"AD1", + * "device_status":"open" + * } + * @return 示例:{ + * "status": 200, + * "message": "任务状态反馈成功!", + * "data": {}, + * "errArr": [] + * } + */ + JSONObject gccControlDoorSwitch(JSONObject requestWMSParam); + + /** + * 六维广钞厂查询自动门状态 + * + * @return 示例:[ + * { + * "device_code":"AD1", + * "device_status":"open" + * }, + * { + * "device_code":"AD2", + * "device_status":"open" + * } + * ] + */ + com.alibaba.fastjson.JSONArray gccQueryDoorStatus(); } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java index 9cb6efa..006c3da 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java @@ -233,7 +233,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { HttpResponse result2 = null; log.info("feedbackActionStatusToWms-----请求参数{}", data.toString()); - logServer.log(task_code, "feedbackActionStatusToWms", "", data.toString(), "","", wmsurl, vehicle_code); + logServer.log(task_code, "feedbackActionStatusToWms", "", data.toString(), "", "", wmsurl, vehicle_code); AddressDto addressDto = addressService.findByCode("feedbackActionStatusToWms"); String methods_url = addressDto.getMethods_url(); @@ -252,7 +252,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } String type = ""; - if(!ObjectUtil.isEmpty(result2)){ + if (!ObjectUtil.isEmpty(result2)) { if (result2.getStatus() == 200) { type = "info"; } else { @@ -518,4 +518,45 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { return result; } + @Override + public JSONObject gccControlDoorSwitch(JSONObject requestWMSParam) { + try { + String wmsurl = acsConfigService.findConfigFromCache().get(AcsConfig.WMSURL); + AddressDto addressDto = addressService.findByCode("gccControlDoorSwitch"); + + log.info("gccControlDoorSwitch - 请求参数{}", requestWMSParam); + String responseBody = HttpRequest + .post(wmsurl + addressDto.getMethods_url()) + .body(requestWMSParam.toString()) + .execute() + .body(); + log.info("gccControlDoorSwitch - 响应参数{}", responseBody); + + return JSONObject.fromObject(responseBody); + } catch (Exception e) { + JSONObject result = new JSONObject(); + result.put("status", HttpStatus.BAD_REQUEST.value()); + result.put("message", e.getMessage()); + return result; + } + } + + @Override + public com.alibaba.fastjson.JSONArray gccQueryDoorStatus() { + try { + String wmsurl = acsConfigService.findConfigFromCache().get(AcsConfig.WMSURL); + AddressDto addressDto = addressService.findByCode("gccQueryDoorStatus"); + + log.info("gccQueryDoorStatus - 请求"); + String responseBody = HttpRequest + .get(wmsurl + addressDto.getMethods_url()) + .execute() + .body(); + log.info("gccControlDoorSwitch - 响应参数{}", responseBody); + + return com.alibaba.fastjson.JSONArray.parseArray(responseBody); + } catch (Exception e) { + return new com.alibaba.fastjson.JSONArray(); + } + } } diff --git a/hd/nladmin-system/src/main/resources/config/application-prod.yml b/hd/nladmin-system/src/main/resources/config/application-prod.yml index 9cc5214..c6eeee8 100644 --- a/hd/nladmin-system/src/main/resources/config/application-prod.yml +++ b/hd/nladmin-system/src/main/resources/config/application-prod.yml @@ -8,7 +8,7 @@ spring: druid: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy - url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:tg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true + url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:gcc_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true username: ${DB_USER:root} password: ${DB_PWD:123456} # 初始连接数