Bladeren bron

修改安装模板

lin 4 jaren geleden
bovenliggende
commit
15dcffb8ff

+ 2 - 2
smart-city-platform/src/main/java/com/bz/smart_city/async/AsyncInstallPlanDownloadTask.java

@@ -185,7 +185,7 @@ public class AsyncInstallPlanDownloadTask {
                 }
             }
 
-            InputStream in = this.getClass().getClassLoader().getResourceAsStream("excel/installPlanTemplate20200716.xlsx");   //得到文档的路径
+            InputStream in = this.getClass().getClassLoader().getResourceAsStream("excel/installPlanTemplate20200731.xlsx");   //得到文档的路径
 
             //列表数据将存储到指定的excel文件路径
             FileOutputStream out = new FileOutputStream(filePath);
@@ -243,7 +243,7 @@ public class AsyncInstallPlanDownloadTask {
             //5、获取安装计划清单数据
 
 
-            InputStream in = this.getClass().getClassLoader().getResourceAsStream("excel/installPlanTemplate20200716.xlsx");   //得到文档的路径
+            InputStream in = this.getClass().getClassLoader().getResourceAsStream("excel/installPlanTemplate20200731.xlsx");   //得到文档的路径
 
             //列表数据将存储到指定的excel文件路径
             FileOutputStream out = new FileOutputStream(filePath);

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/CustomerMapper.java

@@ -53,4 +53,6 @@ public interface CustomerMapper {
     List<Integer> findAllSubIds(@Param("customerId") Integer customerId);
 
     List<Integer> findAllIds(@Param("customerId") Integer customerId);
+
+    Customer findByName(@Param("siteId") Integer siteId, @Param("name") String name);
 }

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/BuildingService.java

@@ -86,4 +86,6 @@ public interface BuildingService{
     List<BuildingSelectDto> abnormalAreaBuildingList(Integer sysId, Integer buildingId, Integer floor, Integer measuringId, Long deviceId, String deviceNo, String location, Integer alarmCategory, Integer handleStatus, Integer alarmTypeId, Integer equipmentId, Integer manufacturerId, Integer customerId, Integer province, Integer city, Integer region, Integer communityId, LocalDateTime startDate, LocalDateTime endDate);
 
     List<BuildingSelectDto> installAreaList(String deviceNo, Integer status, String errorType, Integer customerId, Integer province, Integer city, Integer region, Integer community, Integer buildingId, String locDesc, Integer deviceTypeId, Integer registerStatus, LocalDateTime startDate, LocalDateTime endDate);
+
+    Building findCacheByName(Integer siteId, String name);
 }

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/CommunityService.java

@@ -49,4 +49,6 @@ public interface CommunityService {
     List<Community> getMaxCodeBySiteId(Integer siteId);
 
     Community findByNameV2(Integer siteId, Integer province, Integer city, Integer region, String communityName);
+
+    Community findCacheByName(Integer siteId, String communityName);
 }

+ 7 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/BuildingServiceImpl.java

@@ -19,6 +19,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.cache.annotation.Caching;
 import org.springframework.stereotype.Service;
 
@@ -1324,6 +1325,12 @@ public class BuildingServiceImpl implements BuildingService {
         return 0;
     }
 
+    @Override
+    @Cacheable(value = "CacheBuilding", key = "#siteId + #name")
+    public Building findCacheByName(Integer siteId, String name) {
+        return buildingMapper.findByName(siteId,name);
+    }
+
     private String getFilePath() {
         String name = Util.createUUIDId();
         String fullPath = filesPath + "/" + name + ".xlsm";

+ 7 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/CommunityServiceImpl.java

@@ -13,6 +13,7 @@ import com.bz.smart_city.entity.Area;
 import com.bz.smart_city.entity.ProgramItem;
 import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
@@ -288,4 +289,10 @@ public class CommunityServiceImpl implements CommunityService{
     public Community findByNameV2(Integer siteId, Integer province, Integer city, Integer region, String communityName) {
         return communityMapper.findByNameV2(siteId,province,city,region,communityName);
     }
+
+    @Override
+    @Cacheable(value = "CacheCommunity", key = "#siteId + #communityName")
+    public Community findCacheByName(Integer siteId, String communityName) {
+        return communityMapper.findByName(siteId,communityName);
+    }
 }

+ 55 - 58
smart-city-platform/src/main/java/com/bz/smart_city/service/importfile/AsyncTaskImportService.java

@@ -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);

BIN
smart-city-platform/src/main/resources/excel/installPlanTemplate20200731.xlsx


+ 4 - 0
smart-city-platform/src/main/resources/mapper/CustomerMapper.xml

@@ -351,6 +351,10 @@
         ) T1
     </select>
 
+    <select id="findByName" resultMap="BaseResultMap">
+        select id,customer_name from sc_customer where status = 1 and site_id = #{siteId} and customer_name = #{name} limit 1
+    </select>
+
 
 </mapper>