|
|
@ -1,19 +1,25 @@ |
|
|
|
package com.epmet.dataaggre.service.impl; |
|
|
|
|
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.dataaggre.dto.epmetuser.result.StaffPatrolRecordDailyResultDTO; |
|
|
|
import com.epmet.dataaggre.dto.govorg.CustomerGridDTO; |
|
|
|
import com.epmet.dataaggre.dto.govorg.result.GridMemberDataAnalysisResultDTO; |
|
|
|
import com.epmet.dataaggre.entity.govorg.CustomerAgencyEntity; |
|
|
|
import com.epmet.dataaggre.service.AggreGridService; |
|
|
|
import com.epmet.dataaggre.service.datastats.DataStatsService; |
|
|
|
import com.epmet.dataaggre.service.epmetuser.StatsStaffPatrolRecordDailyService; |
|
|
|
import com.epmet.dataaggre.service.govorg.GovOrgService; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class AggreGridServiceImpl implements AggreGridService { |
|
|
@ -24,6 +30,9 @@ public class AggreGridServiceImpl implements AggreGridService { |
|
|
|
@Autowired |
|
|
|
private DataStatsService dataStatsService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private StatsStaffPatrolRecordDailyService statsStaffPatrolRecordDailyService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<GridMemberDataAnalysisResultDTO> getGridMemberDataAnalysis( |
|
|
|
List<String> gridIds, |
|
|
@ -48,4 +57,85 @@ public class AggreGridServiceImpl implements AggreGridService { |
|
|
|
return records; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<GridMemberDataAnalysisResultDTO> getGridMemberDataAnalysis4PcWork(String agencyId, Integer pageNo, Integer pageSize, Date startTime, Date endTime) { |
|
|
|
|
|
|
|
// 计算出开始dateId和结束endId
|
|
|
|
String startDateID = DateUtils.format(startTime, DateUtils.DATE_PATTERN_YYYYMMDD); |
|
|
|
String endDateID = DateUtils.format(endTime, DateUtils.DATE_PATTERN_YYYYMMDD); |
|
|
|
|
|
|
|
// 拿到组织pids,含自身
|
|
|
|
String pids = getPidsByAgencyId(agencyId); |
|
|
|
|
|
|
|
// 一.查询网格员数据统计相关信息
|
|
|
|
List<GridMemberDataAnalysisResultDTO> datas = dataStatsService.getGridMemberIssueProjectStats4PcWork(pids, pageNo, pageSize, startDateID, endDateID); |
|
|
|
long total = new PageInfo<>(datas).getTotal(); |
|
|
|
|
|
|
|
// 二.匹配用户巡查,例行工作数据
|
|
|
|
int partSize = 100; |
|
|
|
|
|
|
|
// 将数据列表结构化 <staffId:<gridId:data>>
|
|
|
|
HashMap<String, Map<String, GridMemberDataAnalysisResultDTO>> structedData = new HashMap<>(); |
|
|
|
|
|
|
|
for (GridMemberDataAnalysisResultDTO data : datas) { |
|
|
|
// 填充gridName
|
|
|
|
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(data.getGridId()); |
|
|
|
Optional.ofNullable(gridInfo).ifPresent((d) -> data.setOrgName(d.getGridName())); |
|
|
|
|
|
|
|
// 生成结构化map
|
|
|
|
Map<String, GridMemberDataAnalysisResultDTO> gridAndData = structedData.get(data.getStaffId()); |
|
|
|
if (gridAndData == null) { |
|
|
|
HashMap<String, GridMemberDataAnalysisResultDTO> gat = new HashMap<>(); |
|
|
|
gat.put(data.getGridId(), data); |
|
|
|
structedData.put(data.getStaffId(), gat); |
|
|
|
} else { |
|
|
|
Map<String, GridMemberDataAnalysisResultDTO> gat = structedData.get(data.getStaffId()); |
|
|
|
gat.put(data.getGridId(), data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ArrayList<String> userIds = new ArrayList<>(structedData.keySet()); |
|
|
|
|
|
|
|
// 分片
|
|
|
|
List<List<String>> userIdsParts = Lists.partition(userIds, partSize); |
|
|
|
|
|
|
|
for (List<String> userIdsPart : userIdsParts) { |
|
|
|
List<StaffPatrolRecordDailyResultDTO> patrolDatas = statsStaffPatrolRecordDailyService.listStaffPatrolRecordDailyAnalysis(pids, userIdsPart, startDateID, endDateID); |
|
|
|
for (StaffPatrolRecordDailyResultDTO d : patrolDatas) { |
|
|
|
Map<String, GridMemberDataAnalysisResultDTO> gridAndData = structedData.get(d.getStaffId()); |
|
|
|
|
|
|
|
if (gridAndData != null) { |
|
|
|
GridMemberDataAnalysisResultDTO data = gridAndData.get(d.getGridId()); |
|
|
|
if (data != null) { |
|
|
|
data.setPatrolTimes(d.getPatrolTimes()); |
|
|
|
data.setTotalTime(d.getTotalTime()); |
|
|
|
data.setPatrolRoutineWorkTimes(d.getPatrolRoutineWorkTimes()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new PageData<GridMemberDataAnalysisResultDTO>(datas, total); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 使用agencyId,获取pids(agencyPids:agencyId) |
|
|
|
* @param agencyId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String getPidsByAgencyId(String agencyId) { |
|
|
|
CustomerAgencyEntity agencyInfo = govOrgService.getAgencyInfo(agencyId); |
|
|
|
|
|
|
|
if (agencyInfo == null) { |
|
|
|
String errorMsg = "【网格员数据统计查询pcwork】查询组织信息返回为null"; |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); |
|
|
|
} |
|
|
|
|
|
|
|
String pidsAndAgencyIdPath = agencyInfo.getPids().concat(":").concat(agencyId); |
|
|
|
if (pidsAndAgencyIdPath.startsWith(":")) { |
|
|
|
pidsAndAgencyIdPath = pidsAndAgencyIdPath.replaceFirst(":", ""); |
|
|
|
} |
|
|
|
|
|
|
|
return pidsAndAgencyIdPath; |
|
|
|
} |
|
|
|
} |
|
|
|