|
@@ -90,9 +90,6 @@ public class UnifiedApiServiceImpl implements IUnifiedApiService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 处理客户列表查询
|
|
|
|
|
- */
|
|
|
|
|
private UnifiedApiRespDTO handleCustomerList(UnifiedApiReqVO requestVO) {
|
|
private UnifiedApiRespDTO handleCustomerList(UnifiedApiReqVO requestVO) {
|
|
|
try {
|
|
try {
|
|
|
// 解析请求参数
|
|
// 解析请求参数
|
|
@@ -104,72 +101,101 @@ public class UnifiedApiServiceImpl implements IUnifiedApiService {
|
|
|
queryVO = new CustomerListQueryVO();
|
|
queryVO = new CustomerListQueryVO();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 设置分页
|
|
|
|
|
- PageHelper.startPage(queryVO.getPage(), queryVO.getLimit());
|
|
|
|
|
-
|
|
|
|
|
// 构建查询条件
|
|
// 构建查询条件
|
|
|
WwkjCustomerInfo queryCondition = buildQueryCondition(queryVO);
|
|
WwkjCustomerInfo queryCondition = buildQueryCondition(queryVO);
|
|
|
|
|
|
|
|
- // 查询客户信息
|
|
|
|
|
- List<WwkjCustomerInfo> customerList = customerInfoMapper.selectCustomerList(queryCondition);
|
|
|
|
|
- PageInfo<WwkjCustomerInfo> pageInfo = new PageInfo<>(customerList);
|
|
|
|
|
|
|
+ // 1. 先查询所有符合条件的客户(不分页)
|
|
|
|
|
+ List<WwkjCustomerInfo> allCustomers = customerInfoMapper.selectCustomerList(queryCondition);
|
|
|
|
|
|
|
|
- if (CollectionUtils.isEmpty(customerList)) {
|
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(allCustomers)) {
|
|
|
return buildCustomerListResponse(new ArrayList<>(), 0L);
|
|
return buildCustomerListResponse(new ArrayList<>(), 0L);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 批量获取关联信息
|
|
|
|
|
- List<String> customerCodes = customerList.stream()
|
|
|
|
|
|
|
+ // 获取所有客户编号
|
|
|
|
|
+ List<String> customerCodes = allCustomers.stream()
|
|
|
.map(WwkjCustomerInfo::getCustomerCode)
|
|
.map(WwkjCustomerInfo::getCustomerCode)
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
- // 1. 获取水表信息
|
|
|
|
|
|
|
+ // 2. 获取所有水表信息(包括没有水表的客户)
|
|
|
List<WwkjWaterMeter> waterMeters = waterMeterMapper.selectWaterMeterByCustomerCodes(customerCodes);
|
|
List<WwkjWaterMeter> waterMeters = waterMeterMapper.selectWaterMeterByCustomerCodes(customerCodes);
|
|
|
Map<String, List<WwkjWaterMeter>> waterMeterMap = waterMeters.stream()
|
|
Map<String, List<WwkjWaterMeter>> waterMeterMap = waterMeters.stream()
|
|
|
.collect(Collectors.groupingBy(WwkjWaterMeter::getCustomerCode));
|
|
.collect(Collectors.groupingBy(WwkjWaterMeter::getCustomerCode));
|
|
|
|
|
|
|
|
- // 2. 获取所有水表编号
|
|
|
|
|
|
|
+ // 3. 计算总记录数:每个水表一条记录 + 没有水表的客户也有一条记录
|
|
|
|
|
+ long totalRecords = 0;
|
|
|
|
|
+ for (WwkjCustomerInfo customer : allCustomers) {
|
|
|
|
|
+ List<WwkjWaterMeter> customerWaterMeters = waterMeterMap.get(customer.getCustomerCode());
|
|
|
|
|
+ if (CollectionUtils.isEmpty(customerWaterMeters)) {
|
|
|
|
|
+ totalRecords += 1; // 没有水表,也有一条记录
|
|
|
|
|
+ } else {
|
|
|
|
|
+ totalRecords += customerWaterMeters.size(); // 每个水表一条记录
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 分页逻辑:基于水表记录进行分页
|
|
|
|
|
+ int page = queryVO.getPage();
|
|
|
|
|
+ int limit = queryVO.getLimit();
|
|
|
|
|
+ int startIndex = (page - 1) * limit;
|
|
|
|
|
+ int endIndex = startIndex + limit;
|
|
|
|
|
+
|
|
|
|
|
+ // 构建最终响应列表
|
|
|
|
|
+ List<CustomerListQueryRespDTO> respList = new ArrayList<>();
|
|
|
|
|
+ int currentRecordIndex = 0;
|
|
|
|
|
+ int collectedCount = 0;
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 批量获取抄表记录等信息(为所有水表获取)
|
|
|
List<String> allMeterCodes = waterMeters.stream()
|
|
List<String> allMeterCodes = waterMeters.stream()
|
|
|
.map(WwkjWaterMeter::getMeterCode)
|
|
.map(WwkjWaterMeter::getMeterCode)
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
- // 3. 获取抄表记录
|
|
|
|
|
- List<WwkjReadingRecord> readingRecords = readingRecordMapper.selectLatestReadingByMeterCodes(allMeterCodes);
|
|
|
|
|
- Map<String, WwkjReadingRecord> readingRecordMap = readingRecords.stream()
|
|
|
|
|
- .collect(Collectors.toMap(WwkjReadingRecord::getMeterCode, record -> record));
|
|
|
|
|
|
|
+ Map<String, WwkjReadingRecord> readingRecordMap = new HashMap<>();
|
|
|
|
|
+ if (!allMeterCodes.isEmpty()) {
|
|
|
|
|
+ List<WwkjReadingRecord> readingRecords = readingRecordMapper.selectLatestReadingByMeterCodes(allMeterCodes);
|
|
|
|
|
+ readingRecordMap = readingRecords.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(WwkjReadingRecord::getMeterCode, record -> record));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 4. 获取所有表册号
|
|
|
|
|
- List<String> allRouteCodes = readingRecords.stream()
|
|
|
|
|
- .map(WwkjReadingRecord::getRouteCode)
|
|
|
|
|
- .filter(StringUtils::isNotBlank)
|
|
|
|
|
- .distinct()
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
|
|
+ // 6. 按顺序遍历客户,构建响应数据
|
|
|
|
|
+ for (WwkjCustomerInfo customer : allCustomers) {
|
|
|
|
|
+ // 如果已经收集够本页数据,则停止
|
|
|
|
|
+ if (collectedCount >= limit) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 5. 获取表册信息
|
|
|
|
|
- List<WwkjReadingRoute> readingRoutes = readingRouteMapper.selectReadingRouteByRouteCodes(allRouteCodes);
|
|
|
|
|
- Map<String, WwkjReadingRoute> readingRouteMap = readingRoutes.stream()
|
|
|
|
|
- .collect(Collectors.toMap(WwkjReadingRoute::getRouteCode, route -> route));
|
|
|
|
|
|
|
+ // 获取该客户的水表列表
|
|
|
|
|
+ List<WwkjWaterMeter> customerWaterMeters = waterMeterMap.get(customer.getCustomerCode());
|
|
|
|
|
|
|
|
- // 转换响应数据 - 每个水表生成一条记录
|
|
|
|
|
- List<CustomerListQueryRespDTO> respList = new ArrayList<>();
|
|
|
|
|
- for (WwkjCustomerInfo customer : customerList) {
|
|
|
|
|
- List<CustomerListQueryRespDTO> customerRespList = convertCustomerToRespList(
|
|
|
|
|
- customer, waterMeterMap, readingRecordMap, readingRouteMap
|
|
|
|
|
- );
|
|
|
|
|
- respList.addAll(customerRespList);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 获取总水表数量(不是客户数量)
|
|
|
|
|
- long totalWaterMeters = 0L;
|
|
|
|
|
- for (String customerCode : customerCodes) {
|
|
|
|
|
- List<WwkjWaterMeter> customerWaterMeters = waterMeterMap.get(customerCode);
|
|
|
|
|
- if (customerWaterMeters != null) {
|
|
|
|
|
- totalWaterMeters += customerWaterMeters.size();
|
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(customerWaterMeters)) {
|
|
|
|
|
+ // 客户没有水表,也生成一条记录
|
|
|
|
|
+ if (currentRecordIndex >= startIndex && collectedCount < limit) {
|
|
|
|
|
+ CustomerListQueryRespDTO emptyResp = createEmptyRespForCustomer(customer);
|
|
|
|
|
+ respList.add(emptyResp);
|
|
|
|
|
+ collectedCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+ currentRecordIndex++;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 客户有水表,为每个水表生成一条记录
|
|
|
|
|
+ for (WwkjWaterMeter waterMeter : customerWaterMeters) {
|
|
|
|
|
+ // 如果已经收集够本页数据,则停止
|
|
|
|
|
+ if (collectedCount >= limit) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 判断是否在分页范围内
|
|
|
|
|
+ if (currentRecordIndex >= startIndex && collectedCount < limit) {
|
|
|
|
|
+ CustomerListQueryRespDTO resp = convertWaterMeterToResp(
|
|
|
|
|
+ customer, waterMeter, readingRecordMap, new HashMap<>()
|
|
|
|
|
+ );
|
|
|
|
|
+ respList.add(resp);
|
|
|
|
|
+ collectedCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ currentRecordIndex++;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 重新分页处理(因为一个客户可能有多条记录)
|
|
|
|
|
- return buildCustomerListResponse(respList, totalWaterMeters);
|
|
|
|
|
|
|
+ return buildCustomerListResponse(respList, totalRecords);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("查询客户列表失败", e);
|
|
log.error("查询客户列表失败", e);
|
|
@@ -429,6 +455,55 @@ public class UnifiedApiServiceImpl implements IUnifiedApiService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将单个水表转换为响应DTO
|
|
|
|
|
+ */
|
|
|
|
|
+ private CustomerListQueryRespDTO convertWaterMeterToResp(WwkjCustomerInfo customer,
|
|
|
|
|
+ WwkjWaterMeter waterMeter,
|
|
|
|
|
+ Map<String, WwkjReadingRecord> readingRecordMap,
|
|
|
|
|
+ Map<String, WwkjReadingRoute> readingRouteMap) {
|
|
|
|
|
+ CustomerListQueryRespDTO resp = new CustomerListQueryRespDTO();
|
|
|
|
|
+
|
|
|
|
|
+ // 客户基本信息
|
|
|
|
|
+ resp.setAccountNumber(customer.getCustomerCode());
|
|
|
|
|
+ resp.setAccountName(customer.getCustomerName());
|
|
|
|
|
+ resp.setMobilePhone(customer.getMobile());
|
|
|
|
|
+ resp.setAccountAddr(customer.getDetailedAddress());
|
|
|
|
|
+ resp.setIdNo(customer.getCertificateCode());
|
|
|
|
|
+ resp.setRegistrationDate(customer.getOpenCusDate());
|
|
|
|
|
+ resp.setUserWaterNature(customer.getWaterNature());
|
|
|
|
|
+
|
|
|
|
|
+ // 用户状态转换
|
|
|
|
|
+ resp.setAccountStatus(convertAccountStatus(customer.getAccountStatus()));
|
|
|
|
|
+
|
|
|
|
|
+ // 水表基本信息
|
|
|
|
|
+ resp.setWaterMeterNum(waterMeter.getMeterCode());
|
|
|
|
|
+ resp.setWaterMeterSteelSealNum(waterMeter.getLifetimeCode());
|
|
|
|
|
+ resp.setWaterMeterCaliber(waterMeter.getMeterCliber());
|
|
|
|
|
+ resp.setWaterMeterBrand(convertMeterBrand(waterMeter.getMeterPlaceCode()));
|
|
|
|
|
+
|
|
|
|
|
+ // 获取该水表的抄表记录
|
|
|
|
|
+ WwkjReadingRecord readingRecord = readingRecordMap.get(waterMeter.getMeterCode());
|
|
|
|
|
+ if (readingRecord != null) {
|
|
|
|
|
+ // 设置最新表指数
|
|
|
|
|
+ if (readingRecord.getThisMeterNumber() != null) {
|
|
|
|
|
+ resp.setLatestTableIndex(readingRecord.getThisMeterNumber().toString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置册本号
|
|
|
|
|
+ String routeCode = readingRecord.getRouteCode();
|
|
|
|
|
+ if (StringUtils.isNotBlank(routeCode)) {
|
|
|
|
|
+ resp.setBookNumber(routeCode);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 没有抄表记录的情况
|
|
|
|
|
+ resp.setLatestTableIndex("0");
|
|
|
|
|
+ resp.setBookNumber("");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return resp;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 转换客户类型
|
|
* 转换客户类型
|
|
|
* @param customerType 数据库中的客户类型编码
|
|
* @param customerType 数据库中的客户类型编码
|