Browse Source

客户抄表率

lin 4 years ago
parent
commit
8f7d735c4d

+ 31 - 5
smart-city-platform/src/main/java/com/bz/smart_city/commom/util/TreeUtil.java

@@ -11,10 +11,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 import static com.google.common.collect.Lists.newArrayList;
 
@@ -352,11 +350,14 @@ public class TreeUtil {
         if (list != null && list.size()>0) {
             for (CustomerRateDto customerRateDto : list) {
                 postorderTraversalCustomerRateCalculate(customerRateDto.getChildren());
+                int totalNumber = 0;
                 if (customerRateDto.getMap() != null && customerRateDto.getMap().size() > 0) {
+
                     List<WaterReadRateListDto> tempList = newArrayList();
                     for (Map.Entry<Integer, List<WaterReadRateListDto>> m : customerRateDto.getMap().entrySet()) {
                         WaterReadRateListDto temp = new WaterReadRateListDto();
                         if (m.getValue() != null && m.getValue().size() > 0) {
+
                             for (WaterReadRateListDto waterReadRateListDto : m.getValue()) {
 
                                 temp.setDeviceCount(temp.getDeviceCount() + waterReadRateListDto.getDeviceCount());
@@ -370,14 +371,39 @@ public class TreeUtil {
                             temp.setCustomerId(m.getValue().get(0).getCustomerId());
                             temp.setCustomerName(m.getValue().get(0).getCustomerName());
                             temp.setReadRate(new BigDecimal((float)temp.getRealReadTimes()/temp.getDeviceCount()*100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+                            totalNumber+=temp.getDeviceCount();
                         }
                         tempList.add(temp);
                     }
-                    customerRateDto.setList(tempList);
+                    //排序
+                    customerRateDto.setList(tempList.stream().sorted(Comparator.comparingDouble(WaterReadRateListDto::getReadRate).reversed()).collect(Collectors.toList()));
+
+                }else {
+                    if (customerRateDto.getList() != null && customerRateDto.getList().size() > 0) {
+                        for (WaterReadRateListDto waterReadRateListDto : customerRateDto.getList()) {
+                            totalNumber+=waterReadRateListDto.getDeviceCount();
+                        }
+                    }
                 }
+                customerRateDto.setDeviceCount(totalNumber);
+            }
+        }
+    }
 
+    public static void  traversalCustomerRate(List<CustomerRateDto> list,List<WaterReadRateListDto> newList,String parentCustomerName){
+
+        if (list != null && list.size()>0) {
+            for (CustomerRateDto customerRateDto : list) {
+                if (customerRateDto.getList() != null && customerRateDto.getList().size() > 0) {
+                    for (WaterReadRateListDto waterReadRateListDto : customerRateDto.getList()) {
+                        waterReadRateListDto.setCustomerName(parentCustomerName+customerRateDto.getCustomerName());
+                        newList.add(waterReadRateListDto);
+                    }
+                }
+                traversalCustomerRate(customerRateDto.getChildren(),newList,parentCustomerName+customerRateDto.getCustomerName()+"/");
             }
         }
+
     }
 
 

+ 1 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/CustomerRateDto.java

@@ -13,6 +13,7 @@ public class CustomerRateDto {
     private Integer customerId;
     private Integer parentId;
     private String customerName;
+    private Integer deviceCount;
     private List<WaterReadRateListDto> list;
     private List<CustomerRateDto> children;
     @JsonIgnore

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

@@ -457,6 +457,7 @@ public  class DeviceServiceImpl implements DeviceService {
             device.setCustomerId(deviceDataDto.getCustomerId());
             device.setWaterMeterNo(deviceDataDto.getWaterMeterNo());
             device.setUdipId(udipId);
+            device.setRegisterStatus(0);
             if (udipId != null) {
                 device.setRegisterStatus(1);
             }else {

+ 2 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/JobCardServiceImpl.java

@@ -70,7 +70,8 @@ public class JobCardServiceImpl implements JobCardService {
 		Device device = convertJobCardToDevice(card);
 		device.setId(deviceId);
 		device.setStatus(1);
-		
+		device.setRegisterStatus(0);
+
 		int result = deviceMapper.insert(device);
 		// 2,添加设备扩展信息,一个是设备种类信息,一个是设备是否使用的信息
 		List<DeviceExtendInfo> extendsInfos = new ArrayList<DeviceExtendInfo>();

+ 16 - 30
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/StatMeterReadRateByBuildingServiceImpl.java

@@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
@@ -386,13 +387,12 @@ public class StatMeterReadRateByBuildingServiceImpl implements StatMeterReadRate
         if (list == null) {
             return newArrayList();
         }
-        List<CustomerRateDto> newList = list.stream().filter(p -> (p.getList() != null && p.getList().size() > 0) || (p.getChildren() != null && p.getChildren().size() > 0)).collect(Collectors.toList());
-        //List<CustomerRateDto> newList = list.stream().filter(p -> p.getCustomerId()==121).collect(Collectors.toList());
-        TreeUtil.postorderTraversalCustomerRate(newList);
-        TreeUtil.postorderTraversalCustomerRateCalculate(newList);
+        TreeUtil.postorderTraversalCustomerRate(list);
+        TreeUtil.postorderTraversalCustomerRateCalculate(list);
         if (customerId != null) {
-            return TreeUtil.getCustomerRateTreeNode(newList,customerId);
+            return TreeUtil.getCustomerRateTreeNode(list,customerId);
         }
+        List<CustomerRateDto> newList = list.stream().filter(p -> p.getDeviceCount() > 0).sorted(Comparator.comparingInt(CustomerRateDto::getDeviceCount).reversed()).collect(Collectors.toList());
         return newList;
     }
 
@@ -433,37 +433,23 @@ public class StatMeterReadRateByBuildingServiceImpl implements StatMeterReadRate
 
     @Override
     public void getRateExcelByCustomer(Integer period, Integer channelId, Integer customerId, HttpServletResponse httpServletResponse) {
-        LoginUser loginUser = UserUtil.getCurrentUser();
-        //1、查询数据权限的建筑ids
-        List<Integer> buildingIds = buildingService.getIdsByDataPermission();
-
-        //2、根据数据项查询客户
-        List<Customer> customerList = customerService.getCustomerListByItem(loginUser.getSiteId(), buildingIds, null);
-
-        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
-        Integer startDate = Integer.valueOf(LocalDate.now().plusDays(-1).format(formatter));
-
-        List<WaterReadRateListDto> list = newArrayList();
-        if (period == 2) { // 昨天,查询天表
-            list = statMeterReadRateByBuildingMapper.getRateListByCustomer(loginUser.getSiteId(), startDate, buildingIds, customerList, null, null);
-        } else if (period == 7) { // 近7天,查询7天表
-            list = statMeterReadRateByBuildingMapper.getRateList7DayByCustomer(loginUser.getSiteId(), startDate, buildingIds, customerList, null, null);
-        } else if (period == 15) {// 近15天,查询15天表
-            list = statMeterReadRateByBuildingMapper.getRateList15DayByCustomer(loginUser.getSiteId(), startDate, buildingIds, customerList, null, null);
-        }
-
+        List<CustomerRateDto> list = this.getListByCustomer(period,channelId,customerId,null,null);
+        List<WaterReadRateListDto> newList = newArrayList();
+        TreeUtil.traversalCustomerRate(list,newList,"");
         String title = "按客户统计抄表率";
-        String[] rowsName = new String[]{"序号", "客户名称", "应抄水表总个数", "多次抄收成功水表数", "多次抄收成功率(%)"};
+        //客户、水表类型、应抄水表总数、抄收成功总数、抄收成功率(%)
+        String[] rowsName = new String[]{"序号", "客户", "水表类型", "应抄水表总数", "抄收成功总数", "抄收成功率(%)"};
         List<Object[]> dataList = newArrayList();
         Object[] objs = null;
-        for (int i = 0; i < list.size(); i++) {
-            WaterReadRateListDto waterReadRateListDto = list.get(i);
+        for (int i = 0; i < newList.size(); i++) {
+            WaterReadRateListDto waterReadRateListDto = newList.get(i);
             objs = new Object[rowsName.length];
             objs[0] = i;
             objs[1] = waterReadRateListDto.getCustomerName();
-            objs[2] = waterReadRateListDto.getDeviceCount();
-            objs[3] = waterReadRateListDto.getRealReadTimes();
-            objs[4] = waterReadRateListDto.getReadRate();
+            objs[2] = waterReadRateListDto.getChannelName();
+            objs[3] = waterReadRateListDto.getDeviceCount();
+            objs[4] = waterReadRateListDto.getRealReadTimes();
+            objs[5] = waterReadRateListDto.getReadRate();
             dataList.add(objs);
         }
         ExcelUtil excelUtil = new ExcelUtil(title, rowsName, dataList);

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

@@ -707,6 +707,7 @@ public class InstallManagerServiceImpl implements InstallManagerService, Initial
 		// 4,保存设备信息
 		DeviceDto d = convertInstallList(dto);
 		d.setDateCreate(LocalDateTime.now());
+		d.setRegisterStatus(0);
 		deviceMapper.insert(d);
 		// 6,保存设备维度信息
 		saveDeviceDimInfo(d);
@@ -759,6 +760,7 @@ public class InstallManagerServiceImpl implements InstallManagerService, Initial
 			}
 			DeviceDto d = convertInstallList(dto);
 			d.setDateCreate(LocalDateTime.now());
+			d.setRegisterStatus(0);
 			deviceMapper.insert(d);
 			saveDeviceDimInfo(d);
 

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

@@ -240,6 +240,7 @@ public class AsyncTaskImportService {
                                 if(dt == null) {
                                     failTime++ ;
                                     remarkCell.setCellValue(ResultStatus.DEVICE_TYPE_NOT_EXISTED.getMessage());
+                                    continue;
                                 }else {
                                     dto.setDeviceTypeId(dt.getId());
                                     dto.setFactoryId(dt.getManufacturerId());
@@ -362,7 +363,7 @@ public class AsyncTaskImportService {
 
             } catch (Exception e) {
                 e.printStackTrace();
-                log.error("read excel error", e);
+                log.error("read excel error,{}", e.getMessage());
                 messageContent.append("导入失败,读取文件错误。");
             } finally {
                 FileUtil.deleteFile(record.getImportFilePath());