|
@@ -60,6 +60,8 @@ public class AsyncTaskImportService {
|
|
|
@Resource
|
|
|
private BuildingMapper buildingMapper;
|
|
|
@Autowired
|
|
|
+ private BuildingService buildingService;
|
|
|
+ @Autowired
|
|
|
private InstallManagerService installManagerService;
|
|
|
@Autowired
|
|
|
private DeviceTypeService deviceTypeService;
|
|
@@ -140,25 +142,27 @@ public class AsyncTaskImportService {
|
|
|
}
|
|
|
invalidTemplate = true;
|
|
|
// 1,处理表头,解析客户、户数
|
|
|
- Row customerIdRow = hssfSheet.getRow(2); // 客户Id行
|
|
|
- Cell customerIdCell = customerIdRow.getCell(7);
|
|
|
- if(customerIdCell == null ) {
|
|
|
+ Row customerRow = hssfSheet.getRow(1); // 客户Id行
|
|
|
+ Cell customerNameCell = customerRow.getCell(5);
|
|
|
+ customerNameCell.setCellType(CellType.STRING);
|
|
|
+ if(StringUtils.equals("", customerNameCell.getStringCellValue().trim())) {
|
|
|
messageContent.append("导入失败,");
|
|
|
messageContent.append(ResultStatus.CUSTOMER_IS_NOT_EXISTED.getMessage());
|
|
|
continue;
|
|
|
}
|
|
|
- CellValue customerIdCellValue = evaluator.evaluate(customerIdCell);
|
|
|
- Integer customerId = (int) customerIdCellValue.getNumberValue();
|
|
|
- if(customerId==0){
|
|
|
+ Customer customer = customerMapper.findByName(record.getSiteId(),customerNameCell.getStringCellValue().trim());
|
|
|
+ if(customer!=null){
|
|
|
+ dto.setCustomerId(customer.getId());
|
|
|
+
|
|
|
+ }else {
|
|
|
messageContent.append("导入失败,");
|
|
|
messageContent.append(ResultStatus.CUSTOMER_IS_NOT_EXISTED.getMessage());
|
|
|
continue;
|
|
|
}
|
|
|
- dto.setCustomerId(customerId);
|
|
|
|
|
|
|
|
|
- Row numberRow = hssfSheet.getRow(3); // 安装数字,只处理指定安装户数的数据
|
|
|
- Cell numberCell = numberRow.getCell(7);
|
|
|
+ Row numberRow = hssfSheet.getRow(2); // 安装数字,只处理指定安装户数的数据
|
|
|
+ Cell numberCell = numberRow.getCell(5);
|
|
|
|
|
|
numberCell.setCellType(CellType.NUMERIC);
|
|
|
int number = ((Double)numberCell.getNumericCellValue()).intValue();
|
|
@@ -169,27 +173,24 @@ public class AsyncTaskImportService {
|
|
|
}
|
|
|
|
|
|
// 2,处理明细行数据
|
|
|
- for (int rowNum = 9; rowNum < 9+number ; rowNum++) {
|
|
|
+ for (int rowNum = 8; rowNum < 8+number ; rowNum++) {
|
|
|
Row row = hssfSheet.getRow(rowNum);
|
|
|
if (row != null) {
|
|
|
|
|
|
Cell idCell = row.getCell(1) ; // 编号
|
|
|
Cell communityCell = row.getCell(2);
|
|
|
- Cell communityIdCell = row.getCell(3);
|
|
|
- Cell buildingCell = row.getCell(4);
|
|
|
- Cell buildingIdCell = row.getCell(5);
|
|
|
- Cell doorNoCell = row.getCell(6);
|
|
|
- Cell deviceTypeCell = row.getCell(7);
|
|
|
- Cell deviceTypeIdCell = row.getCell(8);
|
|
|
- Cell electronicNoCell = row.getCell(9);
|
|
|
- Cell deviceNoCell = row.getCell(10);
|
|
|
- Cell fileNoCell = row.getCell(11);
|
|
|
- Cell newMeterStartCell = row.getCell(12);
|
|
|
- Cell oldMeterEndCell = row.getCell(13);
|
|
|
- Cell userNameCell = row.getCell(14);
|
|
|
- Cell userPhoneCell = row.getCell(15);
|
|
|
- Cell idCardCell = row.getCell(16);
|
|
|
- Cell remarkCell = row.getCell(17);
|
|
|
+ Cell buildingCell = row.getCell(3);
|
|
|
+ Cell doorNoCell = row.getCell(4);
|
|
|
+ Cell deviceTypeCell = row.getCell(5);
|
|
|
+ Cell electronicNoCell = row.getCell(6);
|
|
|
+ Cell deviceNoCell = row.getCell(7);
|
|
|
+ Cell fileNoCell = row.getCell(8);
|
|
|
+ Cell newMeterStartCell = row.getCell(9);
|
|
|
+ Cell oldMeterEndCell = row.getCell(10);
|
|
|
+ Cell userNameCell = row.getCell(11);
|
|
|
+ Cell userPhoneCell = row.getCell(12);
|
|
|
+ Cell idCardCell = row.getCell(13);
|
|
|
+ Cell remarkCell = row.getCell(14);
|
|
|
|
|
|
|
|
|
if(idCell !=null){
|
|
@@ -198,31 +199,33 @@ public class AsyncTaskImportService {
|
|
|
}
|
|
|
|
|
|
communityCell.setCellType(CellType.STRING);
|
|
|
- if (StringUtils.equals("", communityCell.getStringCellValue())) {
|
|
|
+ if (StringUtils.equals("", communityCell.getStringCellValue().trim())) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (communityIdCell != null) {
|
|
|
- CellValue communityIdCellValue = evaluator.evaluate(communityIdCell);
|
|
|
- Integer communityId = ((Double) communityIdCellValue.getNumberValue()).intValue();
|
|
|
- if(communityId==0){
|
|
|
- continue;
|
|
|
- }
|
|
|
- dto.setCommunityId(communityId);
|
|
|
+ Community community = communityService.findCacheByName(record.getSiteId(),communityCell.getStringCellValue().trim());
|
|
|
+ if (community != null) {
|
|
|
+ dto.setCommunityId(community.getId());
|
|
|
+ }else {
|
|
|
+ failTime++ ;
|
|
|
+ remarkCell.setCellValue(ResultStatus.COMMUNITY_IS_NOT_EXISTED.getMessage());
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
buildingCell.setCellType(CellType.STRING);
|
|
|
- if (StringUtils.equals("", buildingCell.getStringCellValue())) {
|
|
|
+ if (StringUtils.equals("", buildingCell.getStringCellValue().trim())) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (buildingIdCell != null) {
|
|
|
- CellValue buildingIdCellValue = evaluator.evaluate(buildingIdCell);
|
|
|
- Integer buildingId = ((Double) buildingIdCellValue.getNumberValue()).intValue();
|
|
|
- if(buildingId==0){
|
|
|
- continue;
|
|
|
- }
|
|
|
- dto.setBuildingId(buildingId);
|
|
|
+ Building building = buildingService.findCacheByName(record.getSiteId(),buildingCell.getStringCellValue().trim());
|
|
|
+ if (building != null) {
|
|
|
+ dto.setBuildingId(building.getId());
|
|
|
+ }else {
|
|
|
+ failTime++ ;
|
|
|
+ remarkCell.setCellValue(ResultStatus.BUILDING_IS_NOT_EXISTED.getMessage());
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
doorNoCell.setCellType(CellType.STRING);
|
|
|
if (!StringUtils.equals("", doorNoCell.getStringCellValue())) {
|
|
|
String doorNo = doorNoCell.getStringCellValue().trim();
|
|
@@ -234,24 +237,18 @@ public class AsyncTaskImportService {
|
|
|
|
|
|
|
|
|
deviceTypeCell.setCellType(CellType.STRING);
|
|
|
- if (StringUtils.equals("", deviceTypeCell.getStringCellValue())) {
|
|
|
+ if (StringUtils.equals("", deviceTypeCell.getStringCellValue().trim())) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (deviceTypeIdCell != null) {
|
|
|
- CellValue deviceTypeIdCellValue = evaluator.evaluate(deviceTypeIdCell);
|
|
|
- Integer deviceTypeId = ((Double) deviceTypeIdCellValue.getNumberValue()).intValue();
|
|
|
- if(deviceTypeId==0){
|
|
|
- continue;
|
|
|
- }
|
|
|
- DeviceTypeDto dt = deviceTypeService.findById(deviceTypeId);
|
|
|
- if(dt == null) {
|
|
|
- failTime++ ;
|
|
|
- remarkCell.setCellValue(ResultStatus.DEVICE_TYPE_NOT_EXISTED.getMessage());
|
|
|
- continue;
|
|
|
- }else {
|
|
|
- dto.setDeviceTypeId(dt.getId());
|
|
|
- dto.setFactoryId(dt.getManufacturerId());
|
|
|
- }
|
|
|
+ String[] deviceType = StringUtils.split(deviceTypeCell.getStringCellValue().trim(),"/");
|
|
|
+ DeviceTypeDto dt = deviceTypeService.getByName(deviceType[1],deviceType[2]);
|
|
|
+ if(dt != null) {
|
|
|
+ dto.setDeviceTypeId(dt.getId());
|
|
|
+ dto.setFactoryId(dt.getManufacturerId());
|
|
|
+ }else {
|
|
|
+ failTime++ ;
|
|
|
+ remarkCell.setCellValue(ResultStatus.DEVICE_TYPE_NOT_EXISTED.getMessage());
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -333,7 +330,7 @@ public class AsyncTaskImportService {
|
|
|
|
|
|
//循环为空的行上移
|
|
|
if(failTime > 0){
|
|
|
- for (int rowNum = 9+number-1; rowNum >= 9 ; rowNum--) {
|
|
|
+ for (int rowNum = 8+number-1; rowNum >= 8 ; rowNum--) {
|
|
|
Row row = hssfSheet.getRow(rowNum);
|
|
|
if (row == null) {
|
|
|
hssfSheet.shiftRows(rowNum+1, 5000, -1);
|