File was renamed from pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/common/ComSupport.java |
| | |
| | | package com.dy.pipIrrRemote.common; |
| | | package com.dy.pipIrrGlobal.command; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.dy.common.mw.protocol.Command; |
| | | import com.dy.common.mw.protocol.CommandType; |
| | | import com.dy.common.mw.protocol.Data; |
| | | import com.dy.common.mw.protocol.p206V202404.CodeV202404; |
| | | import com.dy.common.mw.protocol.p206V202404.downVos.ComCdXyVo; |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.pipIrrGlobal.command.result.CommandResultCode; |
| | | import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper; |
| | | import com.dy.pipIrrGlobal.daoPr.PrControllerMapper; |
| | | import com.dy.pipIrrGlobal.pojoPr.PrController; |
| | | import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory; |
| | | import com.dy.pipIrrRemote.result.RemoteResultCode; |
| | | import jakarta.annotation.PostConstruct; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.DependsOn; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.util.UriComponentsBuilder; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.ExecutionException; |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-05-21 15:30 |
| | | * @LastEditTime 2024-05-21 15:30 |
| | | * @Description |
| | | * @date 2024-05-30 15:45 |
| | | * @LastEditTime 2024-05-30 15:45 |
| | | * @Description 命令支撑类 |
| | | */ |
| | | |
| | | @Component |
| | | @DependsOn({"baSettingsMapper", "prControllerMapper"}) |
| | | public class ComSupport { |
| | | //@NotNull |
| | | //private final CommandSv commandSv; |
| | | |
| | | protected static String mwUrlTest = "http://127.0.0.1:8070/rtuMw/com/test" ; |
| | | protected static String mwUrlSendCom = "http://127.0.0.1:8070/rtuMw/com/send" ; |
| | | |
| | | //protected static String rtuAddr = "37142501020100215" ; |
| | | protected static String rtuResultSendWebUrl = "http://127.0.0.1:8081/remote/comRes/receive" ; |
| | | |
| | | protected static String controllerType = "57" ;//控制器类型 |
| | | protected static Integer projectNo = 100 ;//项目编码 |
| | | |
| | | //protected static String icCardAddr = "04BEA5BB" ;//IC卡地址 |
| | | //protected static String icCardNo = "37142501020500001" ;//IC卡编号(用户卡序列号) |
| | | //protected String protocolName = ProtocolConstantV206V202404.protocolName; |
| | | |
| | | protected static String controllerType = null; |
| | | protected static Integer projectNo = null; |
| | | protected String commandTypeOuter = CommandType.outerCommand; |
| | | |
| | | // 存储实例化的 CompletableFuture<Data> 对象 |
| | |
| | | |
| | | @Autowired |
| | | private BaSettingsMapper baSettingsMapper; |
| | | @Autowired |
| | | private PrControllerMapper prControllerMapper; |
| | | public static ComSupport comSupport; |
| | | |
| | | /** |
| | |
| | | public void init() { |
| | | comSupport = this; |
| | | comSupport.baSettingsMapper = this.baSettingsMapper; |
| | | comSupport.prControllerMapper = this.prControllerMapper; |
| | | } |
| | | |
| | | /** |
| | | * 获取系统配置参数 |
| | | */ |
| | | public void setUp() { |
| | | //protocolName = comSupport.baSettingsMapper.getItemValue("protocolName"); |
| | | controllerType = comSupport.baSettingsMapper.getItemValue("controllerType"); |
| | | projectNo = Integer.parseInt(comSupport.baSettingsMapper.getItemValue("projectNo")); |
| | | setuped = true; |
| | | } |
| | | |
| | | protected ComCdXyVo comCdXyVo(){ |
| | | ComCdXyVo comVo = new ComCdXyVo() ; |
| | | comVo.controllerType = controllerType ; |
| | | comVo.projectNo = projectNo ; |
| | | return comVo ; |
| | | /** |
| | | * 生成订单号 |
| | | * @return |
| | | */ |
| | | public String generateOrderNo() { |
| | | DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyMMddHHmmss"); |
| | | LocalDateTime dateTime = LocalDateTime.now(); |
| | | Random random = new Random(); |
| | | String CHARACTERS = "0123456789"; |
| | | StringBuilder sb = new StringBuilder(4); |
| | | for (int i = 0; i < 4; i++) { |
| | | int index = random.nextInt(CHARACTERS.length()); |
| | | sb.append(CHARACTERS.charAt(index)); |
| | | } |
| | | return dtf.format(dateTime) + sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 根据取水口ID或阀控器地址获取阀控器对象 |
| | | * @param intakeId |
| | | * @return |
| | | */ |
| | | public JSONObject getRtu(Long intakeId, String rtuAddr) { |
| | | PrController prController = prControllerMapper.getRtu(intakeId, rtuAddr); |
| | | if(prController == null) { |
| | | return null; |
| | | } |
| | | JSONObject job_rtu = new JSONObject(); |
| | | job_rtu.put("rtuAddr", prController.getRtuAddr()); |
| | | job_rtu.put("protocol", prController.getProtocol()); |
| | | job_rtu.put("intakeId", prController.getIntakeId()); |
| | | |
| | | return job_rtu; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param operator 操作员 |
| | | * @return |
| | | */ |
| | | protected RmCommandHistory getComHistory(Long comId, String commandCode, Long intakeId, String rtuAddr, String protocol, Object param, Long operator ) { |
| | | protected RmCommandHistory getComHistory(Long comId, String commandCode, String commandName, Long intakeId, String rtuAddr, String protocol, Object param, Long operator ) { |
| | | RmCommandHistory rmCommandHistory = new RmCommandHistory(); |
| | | rmCommandHistory.setId(comId); |
| | | rmCommandHistory.setCommandCode(commandCode); |
| | | rmCommandHistory.setCommandName(CodeV202404.getCodeName(commandCode)); |
| | | //rmCommandHistory.setCommandName(CodeV202404.getCodeName(commandCode)); |
| | | rmCommandHistory.setCommandName(commandName); |
| | | rmCommandHistory.setIntakeId(intakeId); |
| | | rmCommandHistory.setRtuAddr(rtuAddr); |
| | | rmCommandHistory.setProtocol(protocol); |
| | |
| | | * @param param 参数数据 |
| | | * @return 构造好的命令对象 |
| | | */ |
| | | protected Command command(Long comId, String commandCode, String rtuAddr, String protocol, Object param){ |
| | | protected Command command(Long comId, String commandCode, String rtuAddr, String protocol, String rtuResultSendWebUrl, Object param){ |
| | | Command com = new Command() ; |
| | | com.id = String.valueOf(comId); |
| | | com.code = commandCode ; |
| | |
| | | try { |
| | | CompletableFuture<Data> feature = (CompletableFuture<Data>) features.get(comId); |
| | | System.out.println("receive result ID:" + comId); |
| | | Data resultData = feature.get(10, TimeUnit.SECONDS); |
| | | Data resultData = feature.get(30, TimeUnit.SECONDS); |
| | | features.remove(comId); |
| | | String commandId = resultData.getCommandId(); |
| | | Long commandId = Long.parseLong(resultData.getCommandId()); |
| | | if(commandId.equals(comId)) { |
| | | return BaseResponseUtils.buildSuccess(resultData); |
| | | }else { |
| | |
| | | } |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | return BaseResponseUtils.buildFail(RemoteResultCode.GET_RESULT_ERROR.getMessage()); |
| | | return BaseResponseUtils.buildFail(CommandResultCode.GET_RESULT_ERROR.getMessage()); |
| | | } catch (ExecutionException e) { |
| | | e.printStackTrace(); |
| | | return BaseResponseUtils.buildFail(RemoteResultCode.GET_RESULT_ERROR.getMessage()); |
| | | return BaseResponseUtils.buildFail(CommandResultCode.GET_RESULT_ERROR.getMessage()); |
| | | } catch (TimeoutException e) { |
| | | return BaseResponseUtils.buildFail(RemoteResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage()); |
| | | return BaseResponseUtils.buildFail(CommandResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 连接通信中间件测试 |
| | | * @return |
| | | */ |
| | | protected BaseResponse sendTest(){ |
| | | String url = UriComponentsBuilder.fromUriString(mwUrlTest) |
| | | .build() |
| | | .toUriString(); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | HttpEntity<?> httpEntity = new HttpEntity<>(headers); |
| | | ResponseEntity<BaseResponse> response = null; |
| | | try { |
| | | // 通过Get方式调用接口 |
| | | response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, BaseResponse.class); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return response.getBody(); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | return response.getBody(); |
| | | } |
| | | |
| | | } |