| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | @Scheduled(cron = "0/5 * * * * ?") |
| | | private void wcsOpenComplete() { |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | StaProtocol staProtocol305 = devpThread.getStation().get(305); |
| | | if (staProtocol305!= null && staProtocol305.getIfOpenDoor()) { |
| | | BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", 305)); |
| | | if (basDevp.getWrkNo() != 0) { |
| | | WrkMast wrkMast = wrkMastService.selectById(basDevp.getWrkNo()); |
| | | if (wrkMast == null || wrkMast.getWhsType() == null || wrkMast.getWhsType() == 3){ |
| | | return; |
| | | } |
| | | if (wrkMast.getWhsType() == 4) { |
| | | return; |
| | | } |
| | | WrkDetl wrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo())); |
| | | // 判断开门完成,则通知agv可以放货 |
| | | // 调用结果 |
| | | boolean success = false; |
| | | // 构造请求头 |
| | | Map<String, Object> headers = new HashMap<>(); |
| | | headers.put("Content-Type", "application/json;charset=UTF-8"); |
| | | // 构造请求体 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("matnr",wrkDetl.getMatnr()); |
| | | jsonObject.put("batch",wrkDetl.getBatch()); |
| | | jsonObject.put("flag",wrkMast.getIoType() > 100 ? "0" : "1"); |
| | | String body = jsonObject.toJSONString(); |
| | | String response = ""; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(AgvApi.OPEN_COMPLETE_PUSH.getURI()) |
| | | .setPath(AgvApi.OPEN_COMPLETE_PUSH.getPath()) |
| | | .setHeaders(headers) |
| | | .setJson(body) |
| | | .build() |
| | | .doPost(); |
| | | if (!Cools.isEmpty(response)) { |
| | | JSONObject jsonObject1 = JSONObject.parseObject(response); |
| | | if ((Integer) jsonObject1.get("code") == 200) { |
| | | success = true; |
| | | wrkMast.setWhsType(3); |
| | | wrkMastService.updateById(wrkMast); |
| | | } |
| | | } else { |
| | | log.error("wcs开门完成通知agv接口异常接口失败!!!url:{};request:{};response:{}", "", body, response); |
| | | List<StaProtocol> staProtocols = new ArrayList<StaProtocol>() {{ |
| | | add(devpThread.getStation().get(305)); |
| | | add(devpThread.getStation().get(1202)); |
| | | }}; |
| | | // StaProtocol staProtocol305 = devpThread.getStation().get(305); |
| | | for (StaProtocol staProtocol : staProtocols) { |
| | | // if (staProtocol305 != null && staProtocol305.getIfOpenDoor()) { |
| | | if (staProtocol != null && staProtocol.getIfOpenDoor()) { |
| | | BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", staProtocol.getSiteId())); |
| | | if (basDevp.getWrkNo() != 0) { |
| | | WrkMast wrkMast = wrkMastService.selectById(basDevp.getWrkNo()); |
| | | if (wrkMast == null || wrkMast.getWhsType() == null || wrkMast.getWhsType() == 3) { |
| | | return; |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("wcs开门完成通知agv接口异常:{}", e.getMessage()); |
| | | } finally { |
| | | log.error("wcs开门完成通知agv接口:{}", success); |
| | | if (wrkMast.getWhsType() == 4) { |
| | | return; |
| | | } |
| | | WrkDetl wrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo())); |
| | | // 判断开门完成,则通知agv可以放货 |
| | | // 调用结果 |
| | | boolean success = false; |
| | | // 构造请求头 |
| | | Map<String, Object> headers = new HashMap<>(); |
| | | headers.put("Content-Type", "application/json;charset=UTF-8"); |
| | | // 构造请求体 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("matnr", wrkDetl.getMatnr()); |
| | | jsonObject.put("batch", wrkDetl.getBatch()); |
| | | jsonObject.put("flag", wrkMast.getIoType() > 100 ? "0" : "1"); |
| | | String body = jsonObject.toJSONString(); |
| | | String response = ""; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(AgvApi.OPEN_COMPLETE_PUSH.getURI()) |
| | | .setPath(AgvApi.OPEN_COMPLETE_PUSH.getPath()) |
| | | .setHeaders(headers) |
| | | .setJson(body) |
| | | .build() |
| | | .doPost(); |
| | | if (!Cools.isEmpty(response)) { |
| | | JSONObject jsonObject1 = JSONObject.parseObject(response); |
| | | if ((Integer) jsonObject1.get("code") == 200) { |
| | | success = true; |
| | | wrkMast.setWhsType(3); |
| | | wrkMastService.updateById(wrkMast); |
| | | } |
| | | } else { |
| | | log.error("wcs开门完成通知agv接口异常接口失败!!!url:{};request:{};response:{}", "", body, response); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("wcs开门完成通知agv接口异常:{}", e.getMessage()); |
| | | } finally { |
| | | log.error("wcs开门完成通知agv接口:{}", success); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 读已关门 |
| | |
| | | @Scheduled(cron = "0/5 * * * * ?") |
| | | private void wcsCloseComplete() { |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | StaProtocol staProtocol = devpThread.getStation().get(305); |
| | | if (staProtocol == null) { |
| | | return; |
| | | } else { |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", 305)); |
| | | List<StaProtocol> staProtocols = new ArrayList<StaProtocol>() {{ |
| | | add(devpThread.getStation().get(305)); |
| | | add(devpThread.getStation().get(1202)); |
| | | }}; |
| | | // StaProtocol staProtocol = devpThread.getStation().get(305); |
| | | for (StaProtocol staProtocol : staProtocols) { |
| | | if (staProtocol == null) { |
| | | return; |
| | | } else { |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", staProtocol.getSiteId())); |
| | | if (basDevp.getWrkNo() != 0 && basDevp.getWrkNo() != 9999) { |
| | | WrkMast wrkMast = wrkMastService.selectById(basDevp.getWrkNo()); |
| | | if (wrkMast == null || wrkMast.getWhsType() == null ||wrkMast.getWhsType() != 4) { |
| | | if (wrkMast == null || wrkMast.getWhsType() == null || wrkMast.getWhsType() != 4) { |
| | | return; |
| | | } |
| | | if (wrkMast.getIoType() == 1 && wrkMast.getWrkSts() == 1) { |
| | | staProtocol.setWorkNo(wrkMast.getWrkNo()); |
| | | staProtocol.setStaNo(wrkMast.getStaNo().shortValue()); |
| | | if(!MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol))){ |
| | | if (!MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol))) { |
| | | log.error("入库关门完成失败"); |
| | | } |
| | | wrkMast.setWrkSts(2L); |
| | |
| | | } else if (wrkMast.getIoType() == 101) { |
| | | staProtocol.setWorkNo(9999); |
| | | staProtocol.setStaNo(wrkMast.getSourceStaNo().shortValue()); |
| | | if(!MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol))){ |
| | | if (!MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol))) { |
| | | log.error("出库关门完成失败"); |
| | | } |
| | | basDevp.setWrkNo(staProtocol.getWorkNo()); |
| | | basDevpService.updateById(basDevp); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |