|
@@ -54,192 +54,204 @@ public class GdDeviceResolverExcelTemplate extends AbstractResolverExcelTemplate
|
|
|
protected void cycleExcel() {
|
|
|
log.info("begin GdDeviceResolverExcelTemplate");
|
|
|
String executeSheetName = "表格模板";
|
|
|
- try {
|
|
|
- // 循环工作表Sheet
|
|
|
- for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
|
|
|
- Sheet hssfSheet = workbook.getSheetAt(numSheet);
|
|
|
- if (hssfSheet == null || !StringUtils.equals(executeSheetName, hssfSheet.getSheetName())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- invalidTemplate = true;
|
|
|
- // 循环行Row
|
|
|
- for (int rowNum = 4; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
|
|
|
- Row row = hssfSheet.getRow(rowNum);
|
|
|
- if (row != null) {
|
|
|
- Cell electronicNoCell = row.getCell(0);
|
|
|
- Cell fileNoCell = row.getCell(1);
|
|
|
- Cell deviceTypeNameCell = row.getCell(2);
|
|
|
- Cell customerNameCell = row.getCell(3);
|
|
|
- Cell buildingNameCell = row.getCell(4);
|
|
|
- Cell locDescCell = row.getCell(5);
|
|
|
- Cell concentratorNameCell = row.getCell(6);
|
|
|
- Cell collectorNameCell = row.getCell(7);
|
|
|
- Cell channelNumberNameCell = row.getCell(8);
|
|
|
- Cell portCell = row.getCell(9);
|
|
|
- Cell remarkCell = row.getCell(10);
|
|
|
-
|
|
|
- electronicNoCell.setCellType(CellType.STRING);
|
|
|
- fileNoCell.setCellType(CellType.STRING);
|
|
|
- locDescCell.setCellType(CellType.STRING);
|
|
|
- concentratorNameCell.setCellType(CellType.STRING);
|
|
|
- portCell.setCellType(CellType.STRING);
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.equals("", electronicNoCell.getStringCellValue())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (deviceTypeNameCell == null || StringUtils.equals("", deviceTypeNameCell.getStringCellValue())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (customerNameCell == null || StringUtils.equals("", customerNameCell.getStringCellValue())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (buildingNameCell == null || StringUtils.equals("", buildingNameCell.getStringCellValue())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (locDescCell == null || StringUtils.equals("", locDescCell.getStringCellValue())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (concentratorNameCell == null || StringUtils.equals("", concentratorNameCell.getStringCellValue())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (channelNumberNameCell == null || StringUtils.equals("", channelNumberNameCell.getStringCellValue())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (portCell == null || StringUtils.equals("", portCell.getStringCellValue())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- String[] deviceType = StringUtils.split(deviceTypeNameCell.getStringCellValue().trim(),"/");
|
|
|
- DeviceTypeDto dt = deviceTypeService.getByName(deviceType[1],deviceType[2]);
|
|
|
- if(dt == null) {
|
|
|
- failTime.incrementAndGet();
|
|
|
- remarkCell.setCellValue(ResultStatus.DEVICE_TYPE_NOT_EXISTED.getMessage());
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- Customer customer = customerService.findCacheByName(record.getSiteId(),customerNameCell.getStringCellValue().trim());
|
|
|
- if (customer == null) {
|
|
|
- failTime.incrementAndGet();
|
|
|
- remarkCell.setCellValue(ResultStatus.CUSTOMER_IS_NOT_EXISTED.getMessage());
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- Building building = buildingService.findCacheByName(record.getSiteId(),buildingNameCell.getStringCellValue().trim());
|
|
|
- if (building == null) {
|
|
|
- failTime.incrementAndGet();
|
|
|
- remarkCell.setCellValue(ResultStatus.BUILDING_IS_NOT_EXISTED.getMessage());
|
|
|
- continue;
|
|
|
- }
|
|
|
- Concentrator concentrator = concentratorService.findCacheByName(record.getSiteId(),concentratorNameCell.getStringCellValue().trim());
|
|
|
- if (concentrator == null) {
|
|
|
- failTime.incrementAndGet();
|
|
|
- remarkCell.setCellValue(ResultStatus.CONCENTRATOR_IS_NOT_EXISTED.getMessage());
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- Collector collector = null;
|
|
|
- if(!StringUtils.equals("", collectorNameCell.getStringCellValue())){
|
|
|
- collector = collectorService.findCacheByName(concentrator.getId(),collectorNameCell.getStringCellValue().trim());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- ChannelNumber channelNumber = channelNumberService.findCacheByName(concentrator.getId(),channelNumberNameCell.getStringCellValue().trim());
|
|
|
- if (channelNumber == null) {
|
|
|
- failTime.incrementAndGet();
|
|
|
- remarkCell.setCellValue(ResultStatus.CHANNEL_NUMBER_IS_NOT_EXISTED.getMessage());
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- int resultWaterMeterNo = deviceMapper.findByWaterMeterNoUnique(null, electronicNoCell.getStringCellValue().trim());
|
|
|
- if (resultWaterMeterNo > 0) {
|
|
|
- failTime.incrementAndGet();
|
|
|
- remarkCell.setCellValue(ResultStatus.DEVICE_ELECTRONIC_NO_NOT_EXISTED.getMessage());
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // 1、添加设备
|
|
|
- Device device = new Device();
|
|
|
- device.setId(idWorker.nextId());
|
|
|
- device.setSysId(sysId);
|
|
|
- device.setSiteId(record.getSiteId());
|
|
|
- device.setDeviceType(dt.getId());
|
|
|
- device.setCustomerId(customer.getId());
|
|
|
- device.setBuildingId(building.getId());
|
|
|
- device.setManufacturerId(dt.getManufacturerId());
|
|
|
- device.setWaterMeterNo(electronicNoCell.getStringCellValue().trim());
|
|
|
- device.setWaterMeterFileNo(StringUtils.equals("", fileNoCell.getStringCellValue())?null:fileNoCell.getStringCellValue().trim());
|
|
|
- device.setLocDesc(locDescCell.getStringCellValue().trim());
|
|
|
- device.setDeviceStatus(5);//未启用
|
|
|
- device.setStatus(1);
|
|
|
- device.setIsTag(0);
|
|
|
- device.setCreateBy("system");
|
|
|
- device.setDateCreate(LocalDateTime.now());
|
|
|
- device.setUpdateBy("system");
|
|
|
- device.setDateUpdate(LocalDateTime.now());
|
|
|
- deviceMapper.insertSelective(device);
|
|
|
-
|
|
|
- //2、同步集中器关系
|
|
|
- WaterRelatedDevice waterRelatedDevice = new WaterRelatedDevice();
|
|
|
- waterRelatedDevice.setDeviceId(device.getId());
|
|
|
- waterRelatedDevice.setConcentratorId(concentrator.getId());
|
|
|
- waterRelatedDevice.setCollectorId(collector!=null?collector.getId():null);
|
|
|
- waterRelatedDevice.setChannelNumberId(channelNumber.getId());
|
|
|
- waterRelatedDevice.setPort(portCell.getStringCellValue().trim());
|
|
|
- waterRelatedDevice.setIssueStatus(0);
|
|
|
- waterRelatedDevice.setStatus(1);
|
|
|
- waterRelatedDevice.setDateCreate(LocalDateTime.now());
|
|
|
- waterRelatedDevice.setDateUpdate(LocalDateTime.now());
|
|
|
- waterRelatedDevice.setCreateBy("system");
|
|
|
- waterRelatedDevice.setUpdateBy("system");
|
|
|
- waterRelatedDeviceMapper.insertSelective(waterRelatedDevice);
|
|
|
-
|
|
|
- //3、同步设备维度关系
|
|
|
- //Building building = buildingMapper.getBuilding(device.getBuildingId());
|
|
|
- DeviceDimension deviceDimension = new DeviceDimension();
|
|
|
- deviceDimension.setDeviceId(device.getId());
|
|
|
- deviceDimension.setProvince(String.valueOf(building.getProvince()));
|
|
|
- deviceDimension.setCity(String.valueOf(building.getCity()));
|
|
|
- deviceDimension.setRegion(String.valueOf(building.getRegion()));
|
|
|
- deviceDimension.setCommunity(String.valueOf(building.getCommunity()));
|
|
|
- deviceDimension.setBuilding(String.valueOf(building.getId()));
|
|
|
- deviceDimension.setFloor(String.valueOf(device.getFloor()));
|
|
|
- deviceDimension.setDevice(device.getDeviceNo());
|
|
|
- deviceDimension.setCustomer(String.valueOf(device.getCustomerId()));
|
|
|
- deviceDimension.setStatus(1);
|
|
|
- deviceDimension.setCreateBy("system");
|
|
|
- deviceDimension.setUpdateBy("system");
|
|
|
- deviceDimension.setDateCreate(LocalDateTime.now());
|
|
|
- deviceDimension.setDateUpdate(LocalDateTime.now());
|
|
|
-
|
|
|
- deviceDimensionMapper.insertSelective(deviceDimension);
|
|
|
-
|
|
|
- hssfSheet.removeRow(row);//成功删除该行
|
|
|
-
|
|
|
- successTime.incrementAndGet();
|
|
|
+ // 循环工作表Sheet
|
|
|
+ for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
|
|
|
+ Sheet hssfSheet = workbook.getSheetAt(numSheet);
|
|
|
+ if (hssfSheet == null || !StringUtils.equals(executeSheetName, hssfSheet.getSheetName())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ invalidTemplate = true;
|
|
|
+ // 循环行Row
|
|
|
+ for (int rowNum = 4; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
|
|
|
+ Row row = hssfSheet.getRow(rowNum);
|
|
|
+ if (row != null) {
|
|
|
+ Cell electronicNoCell = row.getCell(0);
|
|
|
+ Cell fileNoCell = row.getCell(1);
|
|
|
+ Cell deviceTypeNameCell = row.getCell(2);
|
|
|
+ Cell customerNameCell = row.getCell(3);
|
|
|
+ Cell buildingNameCell = row.getCell(4);
|
|
|
+ Cell locDescCell = row.getCell(5);
|
|
|
+ Cell concentratorNameCell = row.getCell(6);
|
|
|
+ Cell collectorNameCell = row.getCell(7);
|
|
|
+ Cell channelNumberNameCell = row.getCell(8);
|
|
|
+ Cell portCell = row.getCell(9);
|
|
|
+ Cell remarkCell = row.getCell(10);
|
|
|
+
|
|
|
+ electronicNoCell.setCellType(CellType.STRING);
|
|
|
+ fileNoCell.setCellType(CellType.STRING);
|
|
|
+ locDescCell.setCellType(CellType.STRING);
|
|
|
+ concentratorNameCell.setCellType(CellType.STRING);
|
|
|
+ portCell.setCellType(CellType.STRING);
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.equals("", electronicNoCell.getStringCellValue()) &&
|
|
|
+ StringUtils.equals("", deviceTypeNameCell.getStringCellValue()) &&
|
|
|
+ StringUtils.equals("", customerNameCell.getStringCellValue()) &&
|
|
|
+ StringUtils.equals("", buildingNameCell.getStringCellValue()) &&
|
|
|
+ StringUtils.equals("", locDescCell.getStringCellValue()) &&
|
|
|
+ StringUtils.equals("", concentratorNameCell.getStringCellValue()) &&
|
|
|
+ StringUtils.equals("", channelNumberNameCell.getStringCellValue()) &&
|
|
|
+ StringUtils.equals("", portCell.getStringCellValue())
|
|
|
+ ) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.equals("", electronicNoCell.getStringCellValue())) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtils.equals("", deviceTypeNameCell.getStringCellValue())) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtils.equals("", customerNameCell.getStringCellValue())) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtils.equals("", buildingNameCell.getStringCellValue())) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtils.equals("", locDescCell.getStringCellValue())) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtils.equals("", concentratorNameCell.getStringCellValue())) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtils.equals("", channelNumberNameCell.getStringCellValue())) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtils.equals("", portCell.getStringCellValue())) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String[] deviceType = StringUtils.split(deviceTypeNameCell.getStringCellValue().trim(),"/");
|
|
|
+ DeviceTypeDto dt = deviceTypeService.getByName(deviceType[1],deviceType[2]);
|
|
|
+ if(dt == null) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ remarkCell.setCellValue(ResultStatus.DEVICE_TYPE_NOT_EXISTED.getMessage());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Customer customer = customerService.findCacheByName(record.getSiteId(),customerNameCell.getStringCellValue().trim());
|
|
|
+ if (customer == null) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ remarkCell.setCellValue(ResultStatus.CUSTOMER_IS_NOT_EXISTED.getMessage());
|
|
|
+ continue;
|
|
|
}
|
|
|
+
|
|
|
+ Building building = buildingService.findCacheByName(record.getSiteId(),buildingNameCell.getStringCellValue().trim());
|
|
|
+ if (building == null) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ remarkCell.setCellValue(ResultStatus.BUILDING_IS_NOT_EXISTED.getMessage());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Concentrator concentrator = concentratorService.findCacheByName(record.getSiteId(),concentratorNameCell.getStringCellValue().trim());
|
|
|
+ if (concentrator == null) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ remarkCell.setCellValue(ResultStatus.CONCENTRATOR_IS_NOT_EXISTED.getMessage());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Collector collector = null;
|
|
|
+ if(!StringUtils.equals("", collectorNameCell.getStringCellValue())){
|
|
|
+ collector = collectorService.findCacheByName(concentrator.getId(),collectorNameCell.getStringCellValue().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ChannelNumber channelNumber = channelNumberService.findCacheByName(concentrator.getId(),channelNumberNameCell.getStringCellValue().trim());
|
|
|
+ if (channelNumber == null) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ remarkCell.setCellValue(ResultStatus.CHANNEL_NUMBER_IS_NOT_EXISTED.getMessage());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ int resultWaterMeterNo = deviceMapper.findByWaterMeterNoUnique(null, electronicNoCell.getStringCellValue().trim());
|
|
|
+ if (resultWaterMeterNo > 0) {
|
|
|
+ failTime.incrementAndGet();
|
|
|
+ remarkCell.setCellValue(ResultStatus.DEVICE_ELECTRONIC_NO_NOT_EXISTED.getMessage());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1、添加设备
|
|
|
+ Device device = new Device();
|
|
|
+ device.setId(idWorker.nextId());
|
|
|
+ device.setSysId(sysId);
|
|
|
+ device.setSiteId(record.getSiteId());
|
|
|
+ device.setDeviceType(dt.getId());
|
|
|
+ device.setCustomerId(customer.getId());
|
|
|
+ device.setBuildingId(building.getId());
|
|
|
+ device.setManufacturerId(dt.getManufacturerId());
|
|
|
+ device.setWaterMeterNo(electronicNoCell.getStringCellValue().trim());
|
|
|
+ device.setWaterMeterFileNo(StringUtils.equals("", fileNoCell.getStringCellValue())?null:fileNoCell.getStringCellValue().trim());
|
|
|
+ device.setLocDesc(locDescCell.getStringCellValue().trim());
|
|
|
+ device.setDeviceStatus(5);//未启用
|
|
|
+ device.setStatus(1);
|
|
|
+ device.setIsTag(0);
|
|
|
+ device.setCreateBy("system");
|
|
|
+ device.setDateCreate(LocalDateTime.now());
|
|
|
+ device.setUpdateBy("system");
|
|
|
+ device.setDateUpdate(LocalDateTime.now());
|
|
|
+ deviceMapper.insertSelective(device);
|
|
|
+
|
|
|
+ //2、同步集中器关系
|
|
|
+ WaterRelatedDevice waterRelatedDevice = new WaterRelatedDevice();
|
|
|
+ waterRelatedDevice.setDeviceId(device.getId());
|
|
|
+ waterRelatedDevice.setConcentratorId(concentrator.getId());
|
|
|
+ waterRelatedDevice.setCollectorId(collector!=null?collector.getId():null);
|
|
|
+ waterRelatedDevice.setChannelNumberId(channelNumber.getId());
|
|
|
+ waterRelatedDevice.setPort(portCell.getStringCellValue().trim());
|
|
|
+ waterRelatedDevice.setIssueStatus(0);
|
|
|
+ waterRelatedDevice.setStatus(1);
|
|
|
+ waterRelatedDevice.setDateCreate(LocalDateTime.now());
|
|
|
+ waterRelatedDevice.setDateUpdate(LocalDateTime.now());
|
|
|
+ waterRelatedDevice.setCreateBy("system");
|
|
|
+ waterRelatedDevice.setUpdateBy("system");
|
|
|
+ waterRelatedDeviceMapper.insertSelective(waterRelatedDevice);
|
|
|
+
|
|
|
+ //3、同步设备维度关系
|
|
|
+ //Building building = buildingMapper.getBuilding(device.getBuildingId());
|
|
|
+ DeviceDimension deviceDimension = new DeviceDimension();
|
|
|
+ deviceDimension.setDeviceId(device.getId());
|
|
|
+ deviceDimension.setProvince(String.valueOf(building.getProvince()));
|
|
|
+ deviceDimension.setCity(String.valueOf(building.getCity()));
|
|
|
+ deviceDimension.setRegion(String.valueOf(building.getRegion()));
|
|
|
+ deviceDimension.setCommunity(String.valueOf(building.getCommunity()));
|
|
|
+ deviceDimension.setBuilding(String.valueOf(building.getId()));
|
|
|
+ deviceDimension.setFloor(String.valueOf(device.getFloor()));
|
|
|
+ deviceDimension.setDevice(device.getDeviceNo());
|
|
|
+ deviceDimension.setCustomer(String.valueOf(device.getCustomerId()));
|
|
|
+ deviceDimension.setStatus(1);
|
|
|
+ deviceDimension.setCreateBy("system");
|
|
|
+ deviceDimension.setUpdateBy("system");
|
|
|
+ deviceDimension.setDateCreate(LocalDateTime.now());
|
|
|
+ deviceDimension.setDateUpdate(LocalDateTime.now());
|
|
|
+
|
|
|
+ deviceDimensionMapper.insertSelective(deviceDimension);
|
|
|
+
|
|
|
+ hssfSheet.removeRow(row);//成功删除该行
|
|
|
+
|
|
|
+ successTime.incrementAndGet();
|
|
|
}
|
|
|
- //循环为空的行上移
|
|
|
- if(failTime.get() > 0){
|
|
|
- for (int rowNum = hssfSheet.getLastRowNum(); rowNum > 3 ; rowNum--) {
|
|
|
- Row row = hssfSheet.getRow(rowNum);
|
|
|
- if (row == null) {
|
|
|
- hssfSheet.shiftRows(rowNum+1, 5000, -1);
|
|
|
- }
|
|
|
+ }
|
|
|
+ //循环为空的行上移
|
|
|
+ if(failTime.get() > 0){
|
|
|
+ for (int rowNum = hssfSheet.getLastRowNum(); rowNum > 3 ; rowNum--) {
|
|
|
+ Row row = hssfSheet.getRow(rowNum);
|
|
|
+ if (row == null) {
|
|
|
+ hssfSheet.shiftRows(rowNum+1, 5000, -1);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
- isDownload = true;
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- invalidTemplate = true;
|
|
|
- log.error("read excel error" + e.getMessage());
|
|
|
- messageContent.append("导入失败,读取文件错误。");
|
|
|
- }finally {
|
|
|
- FileUtil.deleteFile(record.getImportFilePath());
|
|
|
+ isDownload = true;
|
|
|
}
|
|
|
|
|
|
log.info("end GdDeviceResolverExcelTemplate");
|