|
@@ -126,157 +126,177 @@ public class AsyncTaskImportService {
|
|
|
Workbook hssfWorkbook = null;
|
|
|
hssfWorkbook = new XSSFWorkbook(inputStream);//Excel 2007
|
|
|
|
|
|
+ FormulaEvaluator evaluator = hssfWorkbook.getCreationHelper().createFormulaEvaluator();
|
|
|
+
|
|
|
// 循环工作表Sheet
|
|
|
for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
|
|
|
Sheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
|
|
|
if (hssfSheet == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (!StringUtils.equals("水表安装计划单模板", hssfSheet.getSheetName())) {
|
|
|
+ if (!StringUtils.equals("安装计划模板", hssfSheet.getSheetName())) {
|
|
|
continue;
|
|
|
}
|
|
|
- // 1,处理表头,解析客户、小区、户数、建筑
|
|
|
- Row r_cust = hssfSheet.getRow(1); // 客户行
|
|
|
- String customerName = r_cust.getCell(3).getStringCellValue();
|
|
|
- Customer customer = customerMapper.findCustomerByName(siteId, customerName);
|
|
|
- if(customer == null ) {
|
|
|
- //throw new ServiceException(ResultStatus.CUSTOMER_IS_NOT_EXISTED);
|
|
|
+ // 1,处理表头,解析客户、户数
|
|
|
+ Row customerIdRow = hssfSheet.getRow(2); // 客户Id行
|
|
|
+ Cell customerIdCell = customerIdRow.getCell(7);
|
|
|
+ if(customerIdCell == null ) {
|
|
|
messageContent.append("导入失败,");
|
|
|
messageContent.append(ResultStatus.CUSTOMER_IS_NOT_EXISTED.getMessage());
|
|
|
continue;
|
|
|
}
|
|
|
- dto.setCustomerId(customer.getId());
|
|
|
+ CellValue customerIdCellValue = evaluator.evaluate(customerIdCell);
|
|
|
+ Integer customerId = (int) customerIdCellValue.getNumberValue();
|
|
|
+ dto.setCustomerId(customerId);
|
|
|
|
|
|
- Row r_community = hssfSheet.getRow(2); // 小区行
|
|
|
- String communityName = r_community.getCell(3).getStringCellValue();
|
|
|
- Community community = communityMapper.findByName(siteId, communityName);
|
|
|
- if(community == null) {
|
|
|
- //throw new ServiceException(ResultStatus.COMMUNITY_IS_NOT_EXISTED);
|
|
|
- messageContent.append("导入失败,");
|
|
|
- messageContent.append(ResultStatus.COMMUNITY_IS_NOT_EXISTED.getMessage());
|
|
|
- continue;
|
|
|
- }
|
|
|
- dto.setCommunityId(community.getId());
|
|
|
- dto.setCommunityName(communityName);
|
|
|
-
|
|
|
- Row r_building = hssfSheet.getRow(3); // 建筑行
|
|
|
- String buildingName = r_building.getCell(3).getStringCellValue();
|
|
|
- Building building = buildingMapper.findByName(siteId, buildingName);
|
|
|
- if(building == null) {
|
|
|
- //throw new ServiceException(ResultStatus.BUILDING_IS_NOT_EXISTED);
|
|
|
- messageContent.append("导入失败,");
|
|
|
- messageContent.append(ResultStatus.BUILDING_IS_NOT_EXISTED.getMessage());
|
|
|
- continue;
|
|
|
- }
|
|
|
- dto.setBuildingId(building.getId());
|
|
|
- dto.setBuildingName(buildingName);
|
|
|
|
|
|
+ Row numberRow = hssfSheet.getRow(3); // 安装数字,只处理指定安装户数的数据
|
|
|
+ Cell numberCell = numberRow.getCell(7);
|
|
|
|
|
|
- Row r_number = hssfSheet.getRow(4); // 安装数字,只处理指定安装户数的数据
|
|
|
- int number = (int)r_number.getCell(3).getNumericCellValue();
|
|
|
+ numberCell.setCellType(CellType.NUMERIC);
|
|
|
+ int number = ((Double)numberCell.getNumericCellValue()).intValue();
|
|
|
if(number < 0 || number > 5000) {
|
|
|
- //throw new ServiceException(ResultStatus.NUMBER_IS_OUT_RANGE);
|
|
|
messageContent.append("导入失败,");
|
|
|
messageContent.append(ResultStatus.NUMBER_IS_OUT_RANGE.getMessage());
|
|
|
continue;
|
|
|
}
|
|
|
+
|
|
|
// 2,处理明细行数据
|
|
|
for (int rowNum = 9; rowNum < 9+number ; rowNum++) {
|
|
|
Row row = hssfSheet.getRow(rowNum);
|
|
|
if (row != null) {
|
|
|
|
|
|
- Cell c_id = row.getCell(1) ; // 编号
|
|
|
- Cell c_doorNo = row.getCell(2);
|
|
|
- Cell c_deviceType = row.getCell(3);
|
|
|
- Cell c_electronicNo = row.getCell(4);
|
|
|
- Cell c_deviceNo = row.getCell(5);
|
|
|
- Cell c_fileNo = row.getCell(6);
|
|
|
- Cell c_newMeterStart = row.getCell(7);
|
|
|
- Cell c_oldMeterEnd = row.getCell(8);
|
|
|
- Cell c_userName = row.getCell(9);
|
|
|
- Cell c_userPhone = row.getCell(10);
|
|
|
- Cell c_remark = row.getCell(11);
|
|
|
-
|
|
|
- Double idVal = c_id.getNumericCellValue();
|
|
|
- if(c_id !=null && idVal != 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);
|
|
|
+
|
|
|
+
|
|
|
+ if(idCell !=null){
|
|
|
+ Double idVal = idCell.getNumericCellValue();
|
|
|
dto.setId(idVal.intValue());
|
|
|
- String doorNo;
|
|
|
- if (c_doorNo.getCellTypeEnum() == CellType.NUMERIC) {
|
|
|
- doorNo = String.format("%.0f", c_doorNo.getNumericCellValue());
|
|
|
- } else {
|
|
|
- doorNo = c_doorNo.getStringCellValue().trim();
|
|
|
}
|
|
|
- if(StringUtils.isBlank(doorNo)) {
|
|
|
+
|
|
|
+ communityCell.setCellType(CellType.STRING);
|
|
|
+ if (StringUtils.equals("", communityCell.getStringCellValue())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (communityIdCell != null) {
|
|
|
+ CellValue communityIdCellValue = evaluator.evaluate(communityIdCell);
|
|
|
+ Integer communityId = ((Double) communityIdCellValue.getNumberValue()).intValue();
|
|
|
+ if(communityId==0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ dto.setCommunityId(communityId);
|
|
|
+ }
|
|
|
+
|
|
|
+ buildingCell.setCellType(CellType.STRING);
|
|
|
+ if (StringUtils.equals("", buildingCell.getStringCellValue())) {
|
|
|
continue;
|
|
|
}
|
|
|
- dto.setDoorNo(doorNo);
|
|
|
- dto.setLocation(doorNo);
|
|
|
+ if (buildingIdCell != null) {
|
|
|
+ CellValue buildingIdCellValue = evaluator.evaluate(buildingIdCell);
|
|
|
+ Integer buildingId = ((Double) buildingIdCellValue.getNumberValue()).intValue();
|
|
|
+ if(buildingId==0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ dto.setBuildingId(buildingId);
|
|
|
+ }
|
|
|
|
|
|
- String deviceTypeNameTemp = c_deviceType.getStringCellValue();
|
|
|
- if(StringUtils.isBlank(deviceTypeNameTemp)) {
|
|
|
+ doorNoCell.setCellType(CellType.STRING);
|
|
|
+ if (!StringUtils.equals("", doorNoCell.getStringCellValue())) {
|
|
|
+ String doorNo = doorNoCell.getStringCellValue().trim();
|
|
|
+ dto.setDoorNo(doorNo);
|
|
|
+ dto.setLocation(doorNo);
|
|
|
+ }else {
|
|
|
continue;
|
|
|
}
|
|
|
- String[] temp = deviceTypeNameTemp.split("/");
|
|
|
- String deviceTypeName = temp[1];
|
|
|
- String deviceTypeModel = temp[2];
|
|
|
- DeviceTypeDto dt = deviceTypeService.getByName(deviceTypeName,deviceTypeModel);
|
|
|
- if(dt == null) {
|
|
|
- //throw new ServiceException(ResultStatus.DEVICE_TYPE_NOT_EXISTED);
|
|
|
- failTime++ ;
|
|
|
- c_remark.setCellValue(ResultStatus.DEVICE_TYPE_NOT_EXISTED.getMessage());
|
|
|
+
|
|
|
+
|
|
|
+ deviceTypeCell.setCellType(CellType.STRING);
|
|
|
+ if (StringUtils.equals("", deviceTypeCell.getStringCellValue())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (deviceTypeIdCell != null) {
|
|
|
+ CellValue deviceTypeIdCellValue = evaluator.evaluate(customerIdCell);
|
|
|
+ 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());
|
|
|
+ }else {
|
|
|
+ dto.setDeviceTypeId(dt.getId());
|
|
|
+ dto.setFactoryId(dt.getManufacturerId());
|
|
|
+ }
|
|
|
}
|
|
|
- dto.setDeviceTypeId(dt.getId());
|
|
|
- dto.setFactoryId(dt.getManufacturerId());
|
|
|
|
|
|
- c_electronicNo.setCellType(CellType.STRING);
|
|
|
- String electronicNo = c_electronicNo.getStringCellValue();
|
|
|
+
|
|
|
+ electronicNoCell.setCellType(CellType.STRING);
|
|
|
+ String electronicNo = electronicNoCell.getStringCellValue().trim();
|
|
|
if(StringUtils.isBlank(electronicNo)) {
|
|
|
continue;
|
|
|
}
|
|
|
dto.setElectronicNo(electronicNo);
|
|
|
|
|
|
- c_deviceNo.setCellType(CellType.STRING);
|
|
|
- String deviceNo = c_deviceNo.getStringCellValue();
|
|
|
+ deviceNoCell.setCellType(CellType.STRING);
|
|
|
+ String deviceNo = deviceNoCell.getStringCellValue().trim();
|
|
|
if(StringUtils.isBlank(deviceNo)) {
|
|
|
continue;
|
|
|
}
|
|
|
dto.setDeviceNo(deviceNo);
|
|
|
|
|
|
- if(c_fileNo != null){
|
|
|
- c_fileNo.setCellType(CellType.STRING);
|
|
|
- String fileNo = c_fileNo.getStringCellValue();
|
|
|
+ if(fileNoCell != null){
|
|
|
+ fileNoCell.setCellType(CellType.STRING);
|
|
|
+ String fileNo = fileNoCell.getStringCellValue().trim();
|
|
|
if(!StringUtils.equals("",fileNo)) {
|
|
|
dto.setFileNo(fileNo);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- String newMeterStart;
|
|
|
- if (c_newMeterStart.getCellTypeEnum() == CellType.NUMERIC) {
|
|
|
- newMeterStart = Double.toString(c_newMeterStart.getNumericCellValue());
|
|
|
- } else {
|
|
|
- newMeterStart = c_newMeterStart.getStringCellValue();
|
|
|
- }
|
|
|
+ newMeterStartCell.setCellType(CellType.STRING);
|
|
|
+ String newMeterStart = newMeterStartCell.getStringCellValue().trim();
|
|
|
if(StringUtils.isBlank(newMeterStart)) {
|
|
|
continue;
|
|
|
}
|
|
|
dto.setNewMeterStart(newMeterStart);
|
|
|
|
|
|
-
|
|
|
- String oldMeterEnd = c_oldMeterEnd.getStringCellValue();
|
|
|
+ oldMeterEndCell.setCellType(CellType.STRING);
|
|
|
+ String oldMeterEnd = oldMeterEndCell.getStringCellValue().trim();
|
|
|
dto.setOldMeterEnd(oldMeterEnd);
|
|
|
- String userName = c_userName.getStringCellValue();
|
|
|
+
|
|
|
+ userNameCell.setCellType(CellType.STRING);
|
|
|
+ String userName = userNameCell.getStringCellValue().trim();
|
|
|
dto.setUserName(userName);
|
|
|
|
|
|
- if(c_userPhone.getCellTypeEnum() == CellType.NUMERIC){
|
|
|
- String userPhone = Double.toString(c_userPhone.getNumericCellValue());
|
|
|
- dto.setUserPhone(userPhone);
|
|
|
- }else {
|
|
|
- String userPhone = c_userPhone.getStringCellValue();
|
|
|
- dto.setUserPhone(userPhone);
|
|
|
- }
|
|
|
+ userPhoneCell.setCellType(CellType.STRING);
|
|
|
+ String userPhone = userPhoneCell.getStringCellValue().trim();
|
|
|
+ dto.setUserPhone(userPhone);
|
|
|
+
|
|
|
+ //身份证号
|
|
|
+ idCardCell.setCellType(CellType.STRING);
|
|
|
+ String idCard = idCardCell.getStringCellValue().trim();
|
|
|
+ dto.setIdCard(idCard);
|
|
|
+
|
|
|
|
|
|
dto.setChannelId(-99);
|
|
|
+ System.out.println(JSON.toJSONString(dto));
|
|
|
try {
|
|
|
//保存安装信息
|
|
|
boolean isOk = installManagerService.saveInstallInfo(dto);
|
|
@@ -285,18 +305,18 @@ public class AsyncTaskImportService {
|
|
|
successTime++ ;
|
|
|
}else {
|
|
|
failTime++ ;
|
|
|
- c_remark.setCellValue(ResultStatus.DELETE_AND_DOOR_EXISTED.getMessage());
|
|
|
+ remarkCell.setCellValue(ResultStatus.DELETE_AND_DOOR_EXISTED.getMessage());
|
|
|
}
|
|
|
} catch (ServiceException e){
|
|
|
if(e.getStatus() == ResultStatus.DEVICE_NO_IS_EXISTED.getStatus()){
|
|
|
failTime++ ;
|
|
|
- c_remark.setCellValue(e.getMessage());
|
|
|
+ remarkCell.setCellValue(e.getMessage());
|
|
|
}else {
|
|
|
failTime++ ;
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
failTime++ ;
|
|
|
- c_remark.setCellValue("导入异常");
|
|
|
+ remarkCell.setCellValue("导入异常");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -321,6 +341,7 @@ public class AsyncTaskImportService {
|
|
|
messageContent.append(failTime);
|
|
|
messageContent.append("条。");
|
|
|
}
|
|
|
+
|
|
|
if(failTime > 0){
|
|
|
String FailFilePath = this.getFilePath();
|
|
|
FileOutputStream os = new FileOutputStream(FailFilePath);
|
|
@@ -340,9 +361,9 @@ public class AsyncTaskImportService {
|
|
|
isDownload = true;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
log.error("read excel error", e);
|
|
|
messageContent.append("导入失败,读取文件错误。");
|
|
|
- //throw new ServiceException(-900, "读取文件错误!");
|
|
|
} finally {
|
|
|
FileUtil.deleteFile(record.getImportFilePath());
|
|
|
}
|
|
@@ -356,7 +377,7 @@ public class AsyncTaskImportService {
|
|
|
|
|
|
|
|
|
//更新完成生成消息
|
|
|
- Message message = new Message();
|
|
|
+ /*Message message = new Message();
|
|
|
message.setSiteId(record.getUserId());
|
|
|
message.setUserId(record.getUserId());
|
|
|
message.setMessageType(record.getType());
|
|
@@ -368,7 +389,7 @@ public class AsyncTaskImportService {
|
|
|
|
|
|
message.setObjId(record.getId());
|
|
|
message.setRead(0);
|
|
|
- messageService.insertSelective(message);
|
|
|
+ messageService.insertSelective(message);*/
|
|
|
|
|
|
log.info("end executeAsyncInstallTask!");
|
|
|
}
|
|
@@ -486,11 +507,8 @@ public class AsyncTaskImportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //新增udip平台集成元
|
|
|
DeviceTypeDto deviceType = deviceTypeMapper.getById(device.getDeviceType());
|
|
|
- String udipId = udipUnitService.saveUdipUnit(device.getDeviceNo(),device.getCustomerId(),deviceType);
|
|
|
|
|
|
- device.setUdipId(udipId);
|
|
|
//DeviceType deviceType = deviceTypeMapper.findByid(device.getDeviceType());
|
|
|
device.setManufacturerId(deviceType.getManufacturerId());
|
|
|
device.setDeviceStatus(5);//未启用
|