| | |
| | | /** |
| | | * 数采入口 |
| | | * |
| | | * @param request |
| | | * @param dataConfig |
| | | * @param device |
| | | * @return |
| | | */ |
| | | public static Map<String, String> dataAcquisitionEntrance(HttpServletRequest request, List<DataConfig> dataConfig, Device device, String entrustCode, String sampleCode, String ip) { |
| | | String http = HTTP + ip + GETFILE + "?filePath=" + device.getCollectUrl() + "&fileExtension=" + device.getFileType(); |
| | | public static Map<String, String> dataAcquisitionEntrance(List<DataConfig> dataConfig, Device device, String entrustCode, String sampleCode, String ip) { |
| | | String http = HTTP + ip + GETFILE + |
| | | "?filePath=" + device.getCollectUrl() + |
| | | "&fileExtension=" + device.getFileType() + |
| | | "&entrustCode=" + entrustCode + |
| | | "&sampleCode=" + sampleCode; |
| | | String result = null; |
| | | try { |
| | | result = HttpUtil.get(http); |
| | |
| | | } else { |
| | | String data = jsonObject.get("data").toString(); |
| | | // 考虑到一个检测项可能会存在多个数采配置,所以需要进行分组 |
| | | Map<String, List<DataConfig>> userMap = dataConfig.stream().collect(Collectors.groupingBy(DataConfig::getInsProductItem)); |
| | | Map<String, List<DataConfig>> userMap = dataConfig.stream() |
| | | .peek(i -> i.setInsProductItem( |
| | | i.getInspectionItem().equals(i.getInspectionItemSubclass()) ? i.getInspectionItem() + "," : i.getInspectionItem() + "," + i.getInspectionItemSubclass() |
| | | )) |
| | | .collect(Collectors.groupingBy(DataConfig::getInsProductItem)); |
| | | Map<String, String> map; |
| | | switch (device.getFileType()) { |
| | | case ".docx": |
| | |
| | | map = analysisMdb(data, userMap, entrustCode, sampleCode); |
| | | break; |
| | | case ".db": |
| | | map = analysisDb(data, userMap); |
| | | map = analysisDb(data, userMap, entrustCode, sampleCode); |
| | | break; |
| | | case ".png": |
| | | map = readPngString(data, userMap); |
| | |
| | | * @param dataConfig |
| | | * @return |
| | | */ |
| | | private static Map<String, String> analysisDb(String data, Map<String, List<DataConfig>> dataConfig) { |
| | | private static Map<String, String> analysisDb(String data, Map<String, List<DataConfig>> dataConfig, String entrustCode, String sampleCode) { |
| | | JSONObject jsonObject = JSON.parseObject(data); |
| | | JSONArray dataList = JSONArray.parseArray(jsonObject.get("data").toString()); |
| | | JSONArray columnList = JSONArray.parseArray(jsonObject.get("column").toString()); |
| | | Map<String, String> map = new HashMap<>(); |
| | | dataConfig.forEach((k, v) -> { |
| | | List<Object> list = new ArrayList<>(); |
| | | for (int config = 0; config < v.size(); config++) { |
| | | String referx = getRefer(v.get(config).getReferx()); |
| | | int x = getXOrY(v.get(config).getX(), k, "X"); |
| | | int y = getXOrY(v.get(config).getY(), k, "Y"); |
| | | String key = ""; |
| | | for (int i = 0; i < columnList.size(); i++) { |
| | | if (columnList.get(i).equals(referx)) { |
| | | key = columnList.get(i + x).toString(); |
| | | for (int i = 0; i < dataList.size(); i++) { |
| | | JSONObject jsonObject1 = JSON.parseObject(dataList.get(i).toString()); |
| | | if (entrustCode.equals(jsonObject1.get("ExtInfo_Value1"))) { |
| | | Object o = jsonObject1.get(referx); |
| | | if (ObjectUtils.isNotEmpty(o)) { |
| | | list.add(o); |
| | | } |
| | | } |
| | | } |
| | | JSONObject jsonObject1 = JSON.parseObject(dataList.get(y).toString()); |
| | | Object o = jsonObject1.get(key); |
| | | if (ObjectUtils.isNotEmpty(o)) { |
| | | // 小数点进三位 |
| | | double v1 = 0; |
| | | try { |
| | | v1 = Double.parseDouble(o.toString()); |
| | | double v2 = v1 / 1000; |
| | | list.add(v2); |
| | | } catch (NumberFormatException e) { |
| | | list.add(o); |
| | | } |
| | | |
| | | } |
| | | } |
| | | // 进行公式计算 |
| | |
| | | private static Map<String, String> analysisMdb(String data, Map<String, List<DataConfig>> dataConfig, String entrustCode, String sampleCode) { |
| | | JSONObject jsonObject = JSON.parseObject(data); |
| | | JSONArray dataList = JSONArray.parseArray(jsonObject.get("data").toString()); |
| | | JSONArray columnList = JSONArray.parseArray(jsonObject.get("column").toString()); |
| | | Map<String, String> map = new HashMap<>(); |
| | | dataConfig.forEach((k, v) -> { |
| | | List<Object> list = new ArrayList<>(); |
| | | for (int config = 0; config < v.size(); config++) { |
| | | String referx = getRefer(v.get(config).getReferx()); |
| | | int x = getXOrY(v.get(config).getX(), k, "X"); |
| | | String key = ""; |
| | | for (int i = 0; i < columnList.size(); i++) { |
| | | if (columnList.get(i).equals(referx)) { |
| | | key = columnList.get(i + x).toString(); |
| | | } |
| | | } |
| | | for (int i = 0; i < dataList.size(); i++) { |
| | | JSONObject jsonObject1 = JSON.parseObject(dataList.get(i).toString()); |
| | | if (entrustCode.equals(jsonObject1.get("OrderNumber")) && sampleCode.equals(jsonObject1.get("SampleNumber"))) { |
| | | Object o = jsonObject1.get(key); |
| | | Object o = jsonObject1.get(referx); |
| | | if (ObjectUtils.isNotEmpty(o)) { |
| | | list.add(o); |
| | | } |
| | |
| | | return value; |
| | | } |
| | | } |
| | | |
| | | public static String getIp(HttpServletRequest request) { |
| | | String ipAddress = request.getRemoteAddr(); |
| | | // 防止回环地址变为IPv6 |
| | | return ipAddress.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ipAddress; |
| | | } |
| | | } |