| | |
| | | baseMapper.delete(new QueryWrapper<ChannelModBusTagEntity>().eq("device", name)); |
| | | } |
| | | |
| | | // /** |
| | | // * 导入Tag |
| | | // * |
| | | // * @param device |
| | | // * @param file |
| | | // * @throws Exception |
| | | // */ |
| | | // @Override |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | // public void importTag(String device, MultipartFile file) throws Exception { |
| | | // try { |
| | | // String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); |
| | | // String fileName = UUID.randomUUID().toString() + suffix; |
| | | // String path = uploadDir + fileName; |
| | | // file.transferTo(new File(path)); |
| | | // |
| | | // XSSFWorkbook hssfWorkbook = new XSSFWorkbook(new FileInputStream(path)); |
| | | // XSSFSheet sheet = hssfWorkbook.getSheetAt(0); |
| | | // int lastRowNum = sheet.getLastRowNum(); |
| | | // log.info("最后一行:" + lastRowNum); |
| | | // int lastCellNum = 6; |
| | | // List<ChannelModBusTagEntity> dangerList = new ArrayList<>(); |
| | | // for (int i = 1; i <= lastRowNum; i++) { |
| | | // XSSFRow row = sheet.getRow(i); |
| | | // for (int j = row.getFirstCellNum(); j < lastCellNum; j++) { |
| | | // row.getCell(j).setCellType(CellType.STRING); |
| | | // } |
| | | // ChannelModBusTagEntity tagEntity = new ChannelModBusTagEntity(); |
| | | // tagEntity.setId(UUID.randomUUID().toString()); |
| | | // tagEntity.setTagName(row.getCell(1).getStringCellValue()); |
| | | // tagEntity.setDataType(row.getCell(2).getStringCellValue()); |
| | | // tagEntity.setEnabled(true); |
| | | // tagEntity.setFormat(""); |
| | | // tagEntity.setDevice(device); |
| | | // tagEntity.setSamplingRate(0); |
| | | // row.getCell(4).setCellType(CellType.STRING); |
| | | // System.out.println(row.getCell(3).getStringCellValue()); |
| | | // if(row.getCell(3).getStringCellValue().equals("1")){ |
| | | // tagEntity.setAddress(String.format("1%04d",Integer.parseInt(row.getCell(4).getStringCellValue()))); |
| | | // }else if(row.getCell(3).getStringCellValue().equals("3")){ |
| | | // tagEntity.setAddress(String.format("4%04d",Integer.parseInt(row.getCell(4).getStringCellValue()))); |
| | | // } |
| | | // tagEntity.setTagDesc(row.getCell(5).getStringCellValue()); |
| | | // dangerList.add(tagEntity); |
| | | // } |
| | | // if (CollectionUtils.isEmpty(dangerList)) { |
| | | // return; |
| | | // } |
| | | // //getBaseMapper().insertList(dangerList); |
| | | // dangerList.forEach(item -> { |
| | | // try { |
| | | // getBaseMapper().insert(item); |
| | | // } catch (Exception ex) { |
| | | // log.warn("插入异常:" + item.getTagName()); |
| | | // } |
| | | // }); |
| | | // } catch (Exception ex) { |
| | | // ex.printStackTrace(); |
| | | // log.warn("导入失败!"); |
| | | // throw ex; |
| | | // } |
| | | // } |
| | | |
| | | } |