| | |
| | | } |
| | | |
| | | @ValueClassify(value = "能力范围") |
| | | @ApiOperation(value = "装备导入检验项目") |
| | | @PostMapping("/importEquipData") |
| | | @Transactional |
| | | public Result importEquipData(@RequestParam("file") MultipartFile file) throws Exception { |
| | | InputStream inputStream = file.getInputStream(); |
| | | List<StructureItemParameter> lists = new ArrayList<>(); |
| | | AtomicReference<String> sample = new AtomicReference<>(); |
| | | ExcelUtil.readBySax(inputStream, -1, (i, l, list1) -> { |
| | | if (l == 1) { |
| | | sample.set(list1.get(1) + ""); |
| | | } |
| | | if (l >= 1) { |
| | | StructureItemParameter str = new StructureItemParameter(); |
| | | if (list1.get(1) == null) { |
| | | str.setSample(null); |
| | | } else { |
| | | String brand = (String) list1.get(1); |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append("["); |
| | | if (ObjectUtil.isNotEmpty(list1.get(2))) { |
| | | String production = (String) list1.get(2); |
| | | if (!production.contains(";")) { |
| | | builder.append(String.format("[\"%s\",\"%s\"]", brand, production)); |
| | | } else { |
| | | Arrays.stream(production.split(";")).forEach(item -> { |
| | | builder.append(String.format("[\"%s\",\"%s\"],", brand, item)); |
| | | }); |
| | | builder.deleteCharAt(builder.length() - 1); |
| | | } |
| | | } else { |
| | | builder.append("["); |
| | | builder.append(String.format("\"%s\"", brand)); |
| | | builder.append("]"); |
| | | } |
| | | builder.append("]"); |
| | | str.setSample(builder.toString()); |
| | | } |
| | | str.setInspectionItem(list1.get(4).toString()); |
| | | if (list1.get(5) != null) { |
| | | str.setInspectionItemEn(list1.get(5).toString()); |
| | | } |
| | | if (list1.get(6) == null) { |
| | | str.setInspectionItemSubclass(null); |
| | | } else { |
| | | str.setInspectionItemSubclass(list1.get(6).toString()); |
| | | } |
| | | if (list1.get(7) == null) { |
| | | str.setInspectionItemSubclassEn(null); |
| | | } else { |
| | | str.setInspectionItemSubclassEn(String.valueOf(list1.get(7).toString())); |
| | | } |
| | | StructureItemParameter db_str; |
| | | if (StringUtils.isEmpty(str.getInspectionItemSubclass())) { |
| | | // 比较两个条件 |
| | | try { |
| | | db_str = structureItemParameterService.getOne(Wrappers.lambdaQuery(StructureItemParameter.class) |
| | | .eq(StructureItemParameter::getInspectionItem, str.getInspectionItem()) |
| | | .eq(StructureItemParameter::getSample, str.getSample()) |
| | | .last("limit 1") |
| | | ); |
| | | } catch (Exception e) { |
| | | throw new ErrorException("重复查询:" + str.getInspectionItem()); |
| | | } |
| | | } else { |
| | | try { |
| | | db_str = structureItemParameterService.getOne(Wrappers.lambdaQuery(StructureItemParameter.class) |
| | | .eq(StructureItemParameter::getInspectionItem, str.getInspectionItem()) |
| | | .eq(StructureItemParameter::getSample, str.getSample()) |
| | | .eq(StructureItemParameter::getInspectionItemSubclass, str.getInspectionItemSubclass()) |
| | | .last("limit 1") |
| | | ); |
| | | } catch (Exception e) { |
| | | throw new ErrorException("重复查询:" + str.getInspectionItem() + " " + str.getInspectionItemSubclass()); |
| | | } |
| | | } |
| | | if (ObjectUtils.isNotEmpty(db_str)) { |
| | | str.setId(db_str.getId()); |
| | | } |
| | | if (list1.get(8) == null) { |
| | | str.setMethod(null); |
| | | } else { |
| | | StringBuffer buffer = new StringBuffer(); |
| | | String input = list1.get(8).toString(); |
| | | buffer.append("["); |
| | | String[] values = input.split(";"); |
| | | for (String value : values) { |
| | | buffer.append("\"").append(value.trim()).append("\","); |
| | | } |
| | | buffer.deleteCharAt(buffer.length() - 1); |
| | | buffer.append("]"); |
| | | str.setMethod(buffer.toString()); |
| | | } |
| | | |
| | | if (list1.get(9) == null) { |
| | | str.setSonLaboratory(null); |
| | | } else { |
| | | str.setSonLaboratory(list1.get(9).toString()); |
| | | } |
| | | if (list1.get(10) == null) { |
| | | str.setUnit(null); |
| | | } else { |
| | | str.setUnit(list1.get(10).toString()); |
| | | } |
| | | |
| | | if (list1.get(11) == null) { |
| | | str.setAskTell(null); |
| | | } else { |
| | | str.setAskTell(list1.get(11).toString()); |
| | | } |
| | | |
| | | if (list1.get(12) == null) { |
| | | str.setAsk(null); |
| | | } else { |
| | | str.setAsk(list1.get(12).toString()); |
| | | } |
| | | |
| | | if (list1.get(13) == null) { |
| | | str.setPrice(null); |
| | | } else { |
| | | str.setPrice(list1.get(13) + ""); |
| | | } |
| | | |
| | | if (list1.get(14) == null) { |
| | | str.setManHour(null); |
| | | } else { |
| | | str.setManHour(Double.valueOf(list1.get(14).toString())); |
| | | } |
| | | |
| | | if (list1.get(15) == null) { |
| | | str.setManHourGroup(null); |
| | | } else { |
| | | str.setManHourGroup(list1.get(15).toString()); |
| | | } |
| | | |
| | | if (list1.get(16) == null) { |
| | | str.setManDay(null); |
| | | } else { |
| | | str.setManDay(Integer.valueOf(list1.get(16).toString())); |
| | | } |
| | | String jy; |
| | | if (list1.get(17).toString().equals("非采集类型")) { |
| | | jy = "0"; |
| | | } else { |
| | | jy = "1"; |
| | | } |
| | | str.setInspectionItemType(jy); |
| | | String validateValueType = list1.get(18).toString(); |
| | | if (StringUtils.isNotBlank(validateValueType)) { |
| | | Enums enums = enumService.getOne(Wrappers.lambdaQuery(Enums.class) |
| | | .eq(Enums::getCategory, "检验值类型") |
| | | .eq(Enums::getLabel, validateValueType)); |
| | | str.setInspectionValueType(enums.getValue()); |
| | | } |
| | | int bsm; |
| | | if (list1.get(19).toString().equals("否")) { |
| | | bsm = 0; |
| | | } else { |
| | | bsm = 1; |
| | | } |
| | | str.setBsm(bsm + ""); |
| | | if (list1.get(20) != null) { |
| | | str.setDic(list1.get(20) + ""); |
| | | } else { |
| | | str.setDic(null); |
| | | } |
| | | StandardTemplate standTempIdByName = standardTemplateService.getStandTempIdByName(String.valueOf(list1.get(21))); |
| | | if (standTempIdByName != null) { |
| | | str.setTemplateId(standTempIdByName.getId()); |
| | | } else { |
| | | str.setTemplateId(null); |
| | | } |
| | | try { |
| | | if (list1.get(22) != null && list1.get(22) != "") { |
| | | str.setInspectionItemClass(list1.get(22) + ""); |
| | | } else { |
| | | str.setInspectionItemClass(null); |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | try { |
| | | if (list1.get(23) != null && list1.get(23) != "") { |
| | | str.setInspectionItemClassEn(list1.get(23) + ""); |
| | | } else { |
| | | str.setInspectionItemClassEn(null); |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | try { |
| | | if (list1.get(24) != null) { |
| | | str.setLaboratory(list1.get(24) + ""); |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | lists.add(str); |
| | | } |
| | | }); |
| | | structureItemParameterService.removeNoSample(sample.get()); |
| | | // 如果数据库里面的数据存在那么就执行更新拷贝操作 |
| | | try { |
| | | structureItemParameterService.saveOrUpdateBatch(lists); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("服务端报错啦!!!"); |
| | | } |
| | | return Result.success(); |
| | | } |
| | | |
| | | @ValueClassify(value = "能力范围") |
| | | @ApiOperation(value = "导入检验对象") |
| | | @PostMapping("/importExcel") |
| | | public Result importExcel(@RequestParam("file") MultipartFile file) { |
| | |
| | | } |
| | | return Result.success(); |
| | | } |
| | | } |
| | | } |