package com.ruoyi.device.controller; import com.ruoyi.common.core.domain.Result; import com.ruoyi.device.pojo.NA7672LRequestBean; import com.ruoyi.device.pojo.NA7672LValueVO; import com.ruoyi.device.utils.NA7672LTCPClientUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * demo 表 * * @author pig * @date 2023-07-31 14:07:58 */ @RestController @RequiredArgsConstructor @RequestMapping("tcpClient") @Api(value = "tcp", tags = "读取网分仪数据") public class NA7672LTCPController { @ApiOperation(value = "获取网分仪所有值", notes = "获取网分仪所有值") @PostMapping("/getTCPValuesNew") public Result getTCPValuesNew(@RequestBody NA7672LRequestBean requestBean) throws IOException, InterruptedException { // List valueList = new ArrayList<>(); // //设置默认配置,可在yml里进行配置 // String serverIp = requestBean.getServerIp(); // int serverPort = requestBean.getServerPort(); // NA7672LTCPClientUtils tcpClient = new NA7672LTCPClientUtils(serverIp, serverPort); // //设置全部通道(界面save/recall-调式2,需要本地有state02文件) // tcpClient.initMemory(requestBean.getMemoryDir()); // String valueUnit = this.getMemoryDirName(requestBean.getMemoryDir()); // //延迟两秒再取值 // try { // Thread.sleep(2000); // } catch (InterruptedException e) { // e.printStackTrace(); // } // List rs = new ArrayList<>(); // if (valueUnit.equals("state01")) { // rs = tcpClient.getState01AllValue(requestBean); // } else if (valueUnit.equals("state02")) { // rs = tcpClient.getState02AllValue(requestBean); // } else if (valueUnit.equals("state03")) { // rs = tcpClient.getState03AllValue(requestBean); // } else if (valueUnit.equals("state04")) { // rs = tcpClient.getState04AllValue(requestBean); // } else if (valueUnit.equals("state05")) { // rs = tcpClient.getState05AllValue(requestBean); // } else if (valueUnit.equals("state06")) { // rs = tcpClient.getState06AllValue(requestBean); // } else if (valueUnit.equals("state07")) { // rs = tcpClient.getState07AllValue(requestBean); // } else if (valueUnit.equals("state08")) { // rs = tcpClient.getState08AllValue(requestBean); // } else if (valueUnit.equals("autorec")) { // rs = tcpClient.getStateAutoRecAllValue(requestBean); // } else { // // } // System.out.println(rs); // return Result.success(rs); List rs = new ArrayList<>(); // 示例数据添加 rs.add(new NA7672LValueVO(3, 1, 1, 1, "swr_155m", null, null, new BigDecimal("299892.062500"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 1, 2, 1, "swr_30m", null, null, new BigDecimal("314821.968750"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 3, 1, 1, "swr_701m", null, null, new BigDecimal("332.007080078"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 3, 2, 1, "swr_700m", null, null, new BigDecimal("354.251983643"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 4, 1, 1, "swr_1713m", null, null, new BigDecimal("47.4854316711"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 4, 2, 1, "swr_1700m", null, null, new BigDecimal("45.4008331299"), null, null, null, 1)); rs.add(new NA7672LValueVO(4, 5, 1, 1, "swr_1902m", null, null, new BigDecimal("37.0886840820"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 5, 2, 1, "swr_1913m", null, null, new BigDecimal("36.3293724060"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 6, 1, 1, "swr_2345m", null, null, new BigDecimal("24.7591514587"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 6, 2, 1, "swr_2324m", null, null, new BigDecimal("22.8147945404"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 7, 1, 1, "swr_3301m", null, null, new BigDecimal("12.0206012726"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 7, 2, 1, "swr_3324m", null, null, new BigDecimal("10.9548406601"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 8, 1, 1, "swr_4800m", null, null, new BigDecimal("5.30891036987"), null, null, null, 1)); rs.add(new NA7672LValueVO(3, 8, 2, 1, "swr_4806m", null, null, new BigDecimal("5.10930156708"), null, null, null, 1)); rs.add(new NA7672LValueVO(2, 2, 1, -1, "impedance_mean", null, null, new BigDecimal("-8.24090110890"), null, null, null, 1)); return Result.success(rs); } /*依照约定把前端传递的查询转化为后端接口查询*/ private String decayLabelOrg2Label(String labelOrg) { String label = "decay_0m"; Pattern pattern = Pattern.compile("(\\d*)M"); Matcher matcher = pattern.matcher(labelOrg); String valueUnit = null; if (matcher.find()) { valueUnit = matcher.group(); } if (valueUnit != null) { label = "decay_" + valueUnit.substring(0, valueUnit.length() - 1) + "m"; } return label; } /*使用memory_dir的路径解析出类别*/ private String getMemoryDirName(String pathName) { String[] splitString = pathName.split("/"); String filename_1 = splitString[splitString.length - 1]; String[] filename_2 = filename_1.split("\\."); String filename_3 = filename_2[0]; return filename_3; /*Pattern pattern = Pattern.compile("state(\\d*)"); Matcher matcher = pattern.matcher(pathName); String valueUnit = null; if (matcher.find()) { valueUnit = matcher.group(); } return valueUnit;*/ } }