|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据PLC按钮测试信号,发送启动申请到测试系统 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void startTest() { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | // 根据输送线plc遍历 | 
|---|
|  |  |  | for (DevpSlave devp : slaveProperties.getDevp()) { | 
|---|
|  |  |  | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); | 
|---|
|  |  |  | if(null != devpThread){ | 
|---|
|  |  |  | if (devpThread.startSignal1 == 1){ | 
|---|
|  |  |  | TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>() | 
|---|
|  |  |  | .eq("channel",1).eq("status",0)); | 
|---|
|  |  |  | if(null != testMast){ | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | //http请求测试 | 
|---|
|  |  |  | TestDto testDto = new TestDto(); | 
|---|
|  |  |  | testDto.setLocNo(testMast.getLocNo()); | 
|---|
|  |  |  | testDto.setBarcode(testMast.getBarcode()); | 
|---|
|  |  |  | testDto.setUserId(testMast.getUserId()); | 
|---|
|  |  |  | testDto.setRequestTime(DateUtils.convert(now)); | 
|---|
|  |  |  | String response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(testUrl) | 
|---|
|  |  |  | .setPath("/testUrlPath") | 
|---|
|  |  |  | .setJson(JSON.toJSONString(testDto)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | if (jsonObject.getInteger("code").equals(200)) { | 
|---|
|  |  |  | //更新测试表状态 | 
|---|
|  |  |  | testMast.setStatus(1); | 
|---|
|  |  |  | testMast.setModiTime(now); | 
|---|
|  |  |  | testMastService.update(testMast,new EntityWrapper<TestMast>() | 
|---|
|  |  |  | .eq("channel",1).eq("status",0)); | 
|---|
|  |  |  | //复位PLC信号 | 
|---|
|  |  |  | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, 0)); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | log.error("请求接口失败!!!url:{},request:{},response:{}", testUrl+"/rpc/pakin/loc/v1", JSON.toJSONString(testDto), response); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int channel = 0; | 
|---|
|  |  |  | for (int i = 0; i < 4; i++){ | 
|---|
|  |  |  | switch (i){ | 
|---|
|  |  |  | case 0: | 
|---|
|  |  |  | channel = devpThread.startSignal1; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | channel = devpThread.startSignal2; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | channel = devpThread.startSignal3; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | channel = devpThread.startSignal4; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (channel == 1){ | 
|---|
|  |  |  | TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>() | 
|---|
|  |  |  | .eq("channel",(i+1)).eq("status",0)); | 
|---|
|  |  |  | if(null != testMast){ | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | //http请求测试 | 
|---|
|  |  |  | TestDto testDto = new TestDto(); | 
|---|
|  |  |  | testDto.setLocNo(testMast.getLocNo()); | 
|---|
|  |  |  | testDto.setBarcode(testMast.getBarcode()); | 
|---|
|  |  |  | testDto.setUserId(testMast.getUserId()); | 
|---|
|  |  |  | testDto.setRequestTime(DateUtils.convert(now)); | 
|---|
|  |  |  | String response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(testUrl) | 
|---|
|  |  |  | .setPath("/testUrlPath") | 
|---|
|  |  |  | .setJson(JSON.toJSONString(testDto)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | if (jsonObject.getInteger("code").equals(200)) { | 
|---|
|  |  |  | //更新测试表状态 | 
|---|
|  |  |  | testMast.setStatus(1); | 
|---|
|  |  |  | testMast.setModiTime(now); | 
|---|
|  |  |  | if(!testMastService.update(testMast,new EntityWrapper<TestMast>() | 
|---|
|  |  |  | .eq("channel",1).eq("status",0))){ | 
|---|
|  |  |  | throw new CoolException("更新产品测试状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                                    //更新库位状态,锁定pack状态,禁止入出库作业 | 
|---|
|  |  |  | //                                    LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no",testMast.getLocNo())); | 
|---|
|  |  |  | //                                    if(null != locMast){ | 
|---|
|  |  |  | //                                        locMast.setPackStatus(2);//测试中 | 
|---|
|  |  |  | //                                        locMast.setModiTime(now); | 
|---|
|  |  |  | //                                        if(!locMastService.update(locMast,new EntityWrapper<LocMast>().eq("loc_no",testMast.getLocNo()))){ | 
|---|
|  |  |  | //                                            throw new CoolException("产品开始测试,更新目标库位锁定状态失败"); | 
|---|
|  |  |  | //                                        } | 
|---|
|  |  |  | //                                    } | 
|---|
|  |  |  | //复位PLC信号 | 
|---|
|  |  |  | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, i*2)); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | log.error("请求接口失败!!!url:{},request:{},response:{}", testUrl+"/rpc/pakin/loc/v1", JSON.toJSONString(testDto), response); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("启动测试  ===>> 启动测试失败", e); | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|