| | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | |
| | | @ApiOperation(value = "获取网分仪所有值", notes = "获取网分仪所有值") |
| | | @PostMapping("/getTCPValuesNew") |
| | | public Result<?> getTCPValuesNew(@RequestBody NA7672LRequestBean requestBean) throws IOException, InterruptedException { |
| | | List<NA7672LValueVO> 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<NA7672LValueVO> 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<NA7672LValueVO> 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<NA7672LValueVO> 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 { |
| | | // 示例数据添加 |
| | | 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); |
| | | } |
| | | |
| | |
| | | /*是否合法,1为合法,0为不合法*/ |
| | | int ifLegal = 1; |
| | | |
| | | public NA7672LValueVO(int fetchType, Integer channel, Integer trace, Integer mark, String label, String labelOrg, Integer intVal, BigDecimal decimalVal, BigDecimal measureValue, BigDecimal calculateValue, String unit, int ifLegal) { |
| | | this.fetchType = fetchType; |
| | | this.channel = channel; |
| | | this.trace = trace; |
| | | this.mark = mark; |
| | | this.label = label; |
| | | this.labelOrg = labelOrg; |
| | | this.intVal = intVal; |
| | | this.decimalVal = decimalVal; |
| | | this.measureValue = measureValue; |
| | | this.calculateValue = calculateValue; |
| | | this.unit = unit; |
| | | this.ifLegal = ifLegal; |
| | | } |
| | | |
| | | public NA7672LValueVO() { |
| | | |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | /*获取衰减(新)*/ |
| | | public List<NA7672LValueVO> getDecayListNew(int channelId, int traceId, int fetchType, String returnType, double temperture, double length) { |
| | | List<NA7672LValueVO> returnValueList = new ArrayList<>(); |
| | | try { |
| | | this.initTCP(); |
| | | InputStream inputStream = this.socket.getInputStream(); |
| | | OutputStream outputStream = this.socket.getOutputStream(); |
| | | // 把字节流转换成字符流 |
| | | PrintWriter printWriter = new PrintWriter(outputStream); |
| | | Scanner inFromSocket = new Scanner(inputStream); |
| | | //获取mark的x |
| | | for (int markId = 1; markId <= 16; markId++) { |
| | | NA7672LValueVO returnValue = new NA7672LValueVO(); |
| | | String requestString = ":CALC" + channelId + ":TRAC" + traceId + ":MARK" + markId + ":X?"; |
| | | printWriter.println(requestString); |
| | | printWriter.flush(); |
| | | String responseString = inFromSocket.next(); |
| | | BigDecimal val = new BigDecimal(responseString); |
| | | BigDecimal valRound = val.divide(new BigDecimal(1000 * 1000), 0, RoundingMode.CEILING); |
| | | returnValue.setLabel(returnType + "_" + valRound.toString() + "m"); |
| | | //获取mark的y |
| | | requestString = ":CALC" + channelId + ":TRAC" + traceId + ":MARK" + markId + ":Y?"; |
| | | printWriter.println(requestString); |
| | | printWriter.flush(); |
| | | responseString = inFromSocket.next(); |
| | | String[] valList = responseString.split(","); |
| | | val = new BigDecimal(valList[0]); |
| | | val.setScale(4, RoundingMode.HALF_UP); |
| | | returnValue.setDecimalVal(val); |
| | | /*类别衰减、通道、轨迹线、mark*/ |
| | | returnValue.setFetchType(fetchType); |
| | | returnValue.setChannel(channelId); |
| | | returnValue.setTrace(traceId); |
| | | returnValue.setChannel(channelId); |
| | | returnValue.setMark(markId); |
| | | returnValueList.add(returnValue); |
| | | } |
| | | this.closeTcp(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | for (NA7672LValueVO one : returnValueList) { |
| | | /*获取计算值*/ |
| | | /*衰减的温度系数换算公式 = 1+0.002×(实际温度-20℃) |
| | | 测试值÷长度÷温度系数×100*/ |
| | | double wd = 1 + 0.002 * (temperture - 20); |
| | | double decay_cal = one.getDecimalVal().doubleValue() / length / wd * 100; |
| | | one.setMeasureValue(new BigDecimal(decay_cal).setScale(4, RoundingMode.HALF_UP)); |
| | | } |
| | | return returnValueList; |
| | | } |
| | | // public List<NA7672LValueVO> getDecayListNew(int channelId, int traceId, int fetchType, String returnType, double temperture, double length) { |
| | | // List<NA7672LValueVO> returnValueList = new ArrayList<>(); |
| | | // try { |
| | | // this.initTCP(); |
| | | // InputStream inputStream = this.socket.getInputStream(); |
| | | // OutputStream outputStream = this.socket.getOutputStream(); |
| | | // // 把字节流转换成字符流 |
| | | // PrintWriter printWriter = new PrintWriter(outputStream); |
| | | // Scanner inFromSocket = new Scanner(inputStream); |
| | | // //获取mark的x |
| | | // for (int markId = 1; markId <= 16; markId++) { |
| | | // NA7672LValueVO returnValue = new NA7672LValueVO(); |
| | | // String requestString = ":CALC" + channelId + ":TRAC" + traceId + ":MARK" + markId + ":X?"; |
| | | // printWriter.println(requestString); |
| | | // printWriter.flush(); |
| | | // String responseString = inFromSocket.next(); |
| | | // BigDecimal val = new BigDecimal(responseString); |
| | | // BigDecimal valRound = val.divide(new BigDecimal(1000 * 1000), 0, RoundingMode.CEILING); |
| | | // returnValue.setLabel(returnType + "_" + valRound.toString() + "m"); |
| | | // //获取mark的y |
| | | // requestString = ":CALC" + channelId + ":TRAC" + traceId + ":MARK" + markId + ":Y?"; |
| | | // printWriter.println(requestString); |
| | | // printWriter.flush(); |
| | | // responseString = inFromSocket.next(); |
| | | // String[] valList = responseString.split(","); |
| | | // val = new BigDecimal(valList[0]); |
| | | // val.setScale(4, RoundingMode.HALF_UP); |
| | | // returnValue.setDecimalVal(val); |
| | | // /*类别衰减、通道、轨迹线、mark*/ |
| | | // returnValue.setFetchType(fetchType); |
| | | // returnValue.setChannel(channelId); |
| | | // returnValue.setTrace(traceId); |
| | | // returnValue.setChannel(channelId); |
| | | // returnValue.setMark(markId); |
| | | // returnValueList.add(returnValue); |
| | | // } |
| | | // this.closeTcp(); |
| | | // } catch (IOException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // for (NA7672LValueVO one : returnValueList) { |
| | | // /*获取计算值*/ |
| | | // /*衰减的温度系数换算公式 = 1+0.002×(实际温度-20℃) |
| | | // 测试值÷长度÷温度系数×100*/ |
| | | // double wd = 1 + 0.002 * (temperture - 20); |
| | | // double decay_cal = one.getDecimalVal().doubleValue() / length / wd * 100; |
| | | // one.setMeasureValue(new BigDecimal(decay_cal).setScale(4, RoundingMode.HALF_UP)); |
| | | // } |
| | | // return returnValueList; |
| | | // } |
| | | |
| | | /*获取驻波比(新)*/ |
| | | public NA7672LValueVO getSWRNew(int channelId, int fetchType) { |
| | |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | @Override |
| | | public List<ReliabilityPlanProductItem> selectProductItem(ReliabilityPlanProductItemDto reliabilityPlanProductItemDto) { |
| | | return reliabilityPlanProductItemMapper.selectList(new LambdaQueryWrapper<ReliabilityPlanProductItem>().eq(ReliabilityPlanProductItem::getPlanId,reliabilityPlanProductItemDto.getRePlanId()) |
| | | .eq(ReliabilityPlanProductItem::getType,reliabilityPlanProductItemDto.getType())); |
| | | // 从数据库中查询新的数据 |
| | | List<Map<String, Object>> maps = reliabilityPlanProductItemMapper.itemList(reliabilityPlanProductItemDto.getRePlanId()); |
| | | List<ReliabilityPlanProductItem> newItemList = new ArrayList<>(); |
| | | for (Map<String, Object> map : maps) { |
| | | ReliabilityPlanProductItem item = new ReliabilityPlanProductItem(); |
| | | item.setInspectionItem((String) map.get("inspectionItem")); |
| | | item.setStandard((String) map.get("standard")); |
| | | item.setFrequency((String) map.get("frequency")); |
| | | item.setPlanId(reliabilityPlanProductItemDto.getRePlanId()); |
| | | item.setType(reliabilityPlanProductItemDto.getType()); |
| | | newItemList.add(item); |
| | | } |
| | | |
| | | // 查询数据库中已存在的数据 |
| | | List<ReliabilityPlanProductItem> existingItemList = reliabilityPlanProductItemMapper.selectList( |
| | | new LambdaQueryWrapper<ReliabilityPlanProductItem>() |
| | | .eq(ReliabilityPlanProductItem::getPlanId, reliabilityPlanProductItemDto.getRePlanId()) |
| | | .eq(ReliabilityPlanProductItem::getType, reliabilityPlanProductItemDto.getType()) |
| | | ); |
| | | |
| | | // 将已存在的数据转换为以 inspectionItem_planId_type 为键的 Map |
| | | Map<String, ReliabilityPlanProductItem> existingItemMap = new HashMap<>(); |
| | | for (ReliabilityPlanProductItem item : existingItemList) { |
| | | StringBuilder keyBuilder = new StringBuilder(); |
| | | keyBuilder.append(item.getInspectionItem()) |
| | | .append("_") |
| | | .append(item.getPlanId()) |
| | | .append("_") |
| | | .append(item.getType()); |
| | | existingItemMap.put(keyBuilder.toString(), item); |
| | | } |
| | | |
| | | List<ReliabilityPlanProductItem> itemsToUpdate = new ArrayList<>(); |
| | | List<ReliabilityPlanProductItem> itemsToInsert = new ArrayList<>(); |
| | | |
| | | // 对比新数据和已存在的数据,区分出需要更新和需要新增的记录 |
| | | for (ReliabilityPlanProductItem newItem : newItemList) { |
| | | StringBuilder keyBuilder = new StringBuilder(); |
| | | keyBuilder.append(newItem.getInspectionItem()) |
| | | .append("_") |
| | | .append(newItem.getPlanId()) |
| | | .append("_") |
| | | .append(newItem.getType()); |
| | | String key = keyBuilder.toString(); |
| | | ReliabilityPlanProductItem existingItem = existingItemMap.get(key); |
| | | if (existingItem != null) { |
| | | // 存在则更新 |
| | | existingItem.setStandard(newItem.getStandard()); |
| | | existingItem.setFrequency(newItem.getFrequency()); |
| | | itemsToUpdate.add(existingItem); |
| | | } else { |
| | | // 不存在则新增 |
| | | itemsToInsert.add(newItem); |
| | | } |
| | | } |
| | | |
| | | // 执行更新和新增操作 |
| | | if (!itemsToUpdate.isEmpty()) { |
| | | saveOrUpdateBatch(itemsToUpdate); |
| | | } |
| | | if (!itemsToInsert.isEmpty()) { |
| | | saveBatch(itemsToInsert); |
| | | } |
| | | |
| | | // 可以考虑在前面的查询中保留需要的结果,避免再次查询 |
| | | return existingItemList.stream() |
| | | .filter(item -> item.getPlanId().equals(reliabilityPlanProductItemDto.getRePlanId()) |
| | | && item.getType().equals(reliabilityPlanProductItemDto.getType())) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | sp.id |
| | | ) SELECT |
| | | sp.inspection_item AS inspectionItem, |
| | | sm.`code`, |
| | | sm.id |
| | | GROUP_CONCAT(DISTINCT sm.`code` SEPARATOR ',') AS standard, |
| | | sp.frequency |
| | | FROM |
| | | flattened_samples fs |
| | | JOIN structure_item_parameter sp ON fs.id = sp.id |
| | | JOIN reliability_plan_product rp ON JSON_OVERLAPS (fs.flattened_sample, JSON_ARRAY(rp.product_name)) |
| | | LEFT JOIN standard_product_list spl ON spl.structure_item_parameter_id = sp.id |
| | | AND spl.model = rp.product_type |
| | | AND spl.state = 1 |
| | | LEFT JOIN standard_method sm ON sm.id = spl.standard_method_list_id |
| | | WHERE rp.id = #{planId} |
| | | WHERE |
| | | rp.id = #{planId} |
| | | GROUP BY |
| | | sp.inspection_item, sp.frequency |
| | | </select> |
| | | <select id="codeList" resultType="java.util.Map"> |
| | | WITH flattened_samples AS ( |