|
@@ -5,6 +5,7 @@ import cn.com.ty.lift.batch.applet.dao.mapper.LiftDataMapper;
|
|
|
import cn.com.ty.lift.batch.applet.dao.model.LiftDataModel;
|
|
|
import cn.com.ty.lift.batch.applet.dao.model.request.CommonRequest;
|
|
|
import cn.com.ty.lift.batch.applet.dao.model.request.LiftDataRequest;
|
|
|
+import cn.com.ty.lift.batch.applet.dao.model.response.RegionLiftResponse;
|
|
|
import cn.com.ty.lift.batch.applet.util.DataStatisticsUtil;
|
|
|
import cn.com.ty.lift.common.constants.ApiConstants;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
@@ -12,8 +13,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -30,6 +30,18 @@ public class LiftDataService {
|
|
|
@Resource
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
+ /**
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @description 从redis中获取电梯数据
|
|
|
+ * @date 2020/2/7 12:01 下午
|
|
|
+ */
|
|
|
+ private List<LiftDataModel> getLiftDataModels(LiftDataRequest liftDataRequest) {
|
|
|
+ return (List<LiftDataModel>)
|
|
|
+ DataStatisticsUtil.getStatisticsDataFromRedis(redisTemplate,
|
|
|
+ DataStatisticsConstants.LIFT_DATA_FIELD, liftDataRequest.getMtCompanyId());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param commonRequest 起始时间 终止时间
|
|
|
* @return
|
|
@@ -51,19 +63,19 @@ public class LiftDataService {
|
|
|
*/
|
|
|
public List<LiftDataModel> getLiftDataListFromRedis(LiftDataRequest liftDataRequest) {
|
|
|
//从redis中获取当前公司电梯信息
|
|
|
- List<LiftDataModel> liftDataModelList = (List<LiftDataModel>)
|
|
|
- DataStatisticsUtil.getStatisticsDataFromRedis(redisTemplate,
|
|
|
- DataStatisticsConstants.LIFT_DATA_FIELD, liftDataRequest.getMtCompanyId());
|
|
|
+ List<LiftDataModel> liftDataModelList = getLiftDataModels(liftDataRequest);
|
|
|
if (liftDataModelList != null) {
|
|
|
//过滤起始时间之前的数据
|
|
|
if (liftDataRequest.getStartTimeDate() != null) {
|
|
|
liftDataModelList = liftDataModelList.stream()
|
|
|
+ //新增电梯的时间
|
|
|
.filter(a -> a.getConnectTime().isAfter(liftDataRequest.getStartTimeDate()))
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
//过滤终止时间之后的数据
|
|
|
if (liftDataRequest.getEndTimeDate() != null) {
|
|
|
liftDataModelList = liftDataModelList.stream()
|
|
|
+ //新增电梯的时间
|
|
|
.filter(a -> a.getConnectTime().isBefore(liftDataRequest.getEndTimeDate()))
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
@@ -71,6 +83,38 @@ public class LiftDataService {
|
|
|
return liftDataModelList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @description 区域电梯数据:从redis中获取,并通过新增电梯时间和丢失电梯时间过滤
|
|
|
+ * @date 2020/2/7 11:57 上午
|
|
|
+ */
|
|
|
+ public List<LiftDataModel> getRegionListFromRedis(LiftDataRequest liftDataRequest) {
|
|
|
+ //从redis中获取当前公司电梯信息
|
|
|
+ List<LiftDataModel> liftDataModelList = getLiftDataModels(liftDataRequest);
|
|
|
+ if (liftDataModelList != null) {
|
|
|
+ //过滤起始时间之前的数据:过滤条件,新增电梯的时间或者丢失电梯的时间
|
|
|
+ if (liftDataRequest.getStartTimeDate() != null) {
|
|
|
+ liftDataModelList = liftDataModelList.stream()
|
|
|
+ //新增电梯的时间
|
|
|
+ .filter(a -> a.getConnectTime().isAfter(liftDataRequest.getStartTimeDate())
|
|
|
+ //丢失电梯的时间
|
|
|
+ || a.getLostTime().isAfter(liftDataRequest.getStartTimeDate()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ //过滤终止时间之后的数据:过滤条件,新增电梯的时间或者丢失电梯的时间
|
|
|
+ if (liftDataRequest.getEndTimeDate() != null) {
|
|
|
+ liftDataModelList = liftDataModelList.stream()
|
|
|
+ //新增电梯的时间
|
|
|
+ .filter(a -> a.getConnectTime().isBefore(liftDataRequest.getEndTimeDate())
|
|
|
+ //丢失电梯的时间
|
|
|
+ || a.getLostTime().isBefore(liftDataRequest.getEndTimeDate()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return liftDataModelList;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param
|
|
|
* @return
|
|
@@ -78,7 +122,67 @@ public class LiftDataService {
|
|
|
* @date 2020/2/5 12:28 下午
|
|
|
*/
|
|
|
public RestResponse liftOverView(LiftDataRequest liftDataRequest) {
|
|
|
- Map<Integer, Integer> liftStatusToNums = DataStatisticsConstants.LIFT_STATUS_TO_LIFT_NUM;
|
|
|
+ //获取时间段内按月份统计的丢失电梯数量
|
|
|
+ Map<Integer, List<Long>> liftStatusToNums = new HashMap<>();
|
|
|
+
|
|
|
+ //从redis中获取当前公司总的电梯信息
|
|
|
+ List<LiftDataModel> companyTotalLiftDataList = getLiftDataModels(liftDataRequest);
|
|
|
+ //设置时间段
|
|
|
+ DataStatisticsUtil.setBeginYearToNow(liftDataRequest);
|
|
|
+ //从redis中获取当前公司时间段之内的电梯信息
|
|
|
+ List<LiftDataModel> liftDataModelList = getLiftDataListFromRedis(liftDataRequest);
|
|
|
+
|
|
|
+ if ((companyTotalLiftDataList != null && companyTotalLiftDataList.size() > 0) &&
|
|
|
+ liftDataModelList != null && liftDataModelList.size() > 0) {
|
|
|
+ //获取传递起始时间之前的电梯信息
|
|
|
+ List<LiftDataModel> beforeLiftDataList = companyTotalLiftDataList.stream()
|
|
|
+ //新建时间在起始时间之前的
|
|
|
+ .filter(a -> a.getConnectTime().isBefore(liftDataRequest.getStartTimeDate()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //时间段之前的电梯台数,去掉丢失的电梯
|
|
|
+ long beforeLiftTotalNum = 0L;
|
|
|
+ if (beforeLiftDataList != null && beforeLiftDataList.size() > 0) {
|
|
|
+ beforeLiftTotalNum = beforeLiftDataList.stream()
|
|
|
+ .filter(a -> a.getLiftStatus() != 3).count();
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取时间段内按月份统计的新增电梯数量
|
|
|
+ Map<Integer, Long> monthToNewLiftNums = liftDataModelList.stream()
|
|
|
+ //获取电梯状态是新增的电梯数据
|
|
|
+ .filter(a -> a.getLiftStatus() == 1)
|
|
|
+ //通过新增时间顺序排列
|
|
|
+ .sorted(Comparator.comparing(LiftDataModel::getConnectTime))
|
|
|
+ .collect(Collectors.groupingBy(liftDataModel ->
|
|
|
+ DataStatisticsUtil.getMonth(liftDataModel.getConnectTime()), Collectors.counting()));
|
|
|
+
|
|
|
+ //获取时间段内按月份统计的丢失电梯数量
|
|
|
+ Map<Integer, Long> monthToLostLiftNums = liftDataModelList.stream()
|
|
|
+ //获取电梯状态是丢失的电梯数据
|
|
|
+ .filter(a -> a.getLiftStatus() == 3)
|
|
|
+ //通过丢失时间顺序排列
|
|
|
+ .sorted(Comparator.comparing(LiftDataModel::getLostTime))
|
|
|
+ .collect(Collectors.groupingBy(liftDataModel ->
|
|
|
+ DataStatisticsUtil.getMonth(liftDataModel.getLostTime()), Collectors.counting()));
|
|
|
+ //获取截止时间的月份值
|
|
|
+ int nowMonthValue = liftDataRequest.getEndTimeDate().getMonthValue();
|
|
|
+
|
|
|
+ //设置不同状态对应的电梯台量
|
|
|
+ List<Long> newLiftNums = new ArrayList<>();
|
|
|
+ List<Long> onMaintenanceLiftNums = new ArrayList<>();
|
|
|
+ List<Long> lostLiftNums = new ArrayList<>();
|
|
|
+ for (int i = 1; i <= nowMonthValue; i++) {
|
|
|
+ long newLiftNum = monthToNewLiftNums.get(i) != null ? monthToNewLiftNums.get(i) : 0L;
|
|
|
+ long lostLiftNum = monthToLostLiftNums.get(i) != null ? monthToLostLiftNums.get(i) : 0L;
|
|
|
+ //计算在保电梯台量:原有电梯台量 + 新增电梯台量 - 丢失电梯台量
|
|
|
+ long onMaintenanceLiftNum = beforeLiftTotalNum + newLiftNum - lostLiftNum;
|
|
|
+ newLiftNums.add(newLiftNum);
|
|
|
+ onMaintenanceLiftNums.add(onMaintenanceLiftNum);
|
|
|
+ lostLiftNums.add(lostLiftNum);
|
|
|
+ }
|
|
|
+ liftStatusToNums.put(1, newLiftNums);
|
|
|
+ liftStatusToNums.put(2, onMaintenanceLiftNums);
|
|
|
+ liftStatusToNums.put(3, lostLiftNums);
|
|
|
+ }
|
|
|
return RestResponse.success(liftStatusToNums, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
|
|
|
}
|
|
|
|
|
@@ -89,7 +193,36 @@ public class LiftDataService {
|
|
|
* @date 2020/2/5 2:43 下午
|
|
|
*/
|
|
|
public RestResponse regionRank(LiftDataRequest liftDataRequest) {
|
|
|
- return RestResponse.success(ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
|
|
|
+ //区域电梯数据
|
|
|
+ List<RegionLiftResponse> regionLiftResponseList = new ArrayList<>();
|
|
|
+ List<LiftDataModel> liftDataModelList = getRegionListFromRedis(liftDataRequest);
|
|
|
+ if (liftDataModelList != null && liftDataModelList.size() > 0) {
|
|
|
+ //将数据转化为 区域名称->电梯数据列表
|
|
|
+ Map<String, List<LiftDataModel>> regionNameToLiftData = liftDataModelList.stream()
|
|
|
+ .collect(Collectors.groupingBy(LiftDataModel::getRegionName));
|
|
|
+ //封装区域电梯信息
|
|
|
+ regionNameToLiftData.forEach((key, value) -> {
|
|
|
+ RegionLiftResponse regionLiftResponse = new RegionLiftResponse();
|
|
|
+ //总电梯数
|
|
|
+ long totalLiftNums = value.stream().count();
|
|
|
+ //计算新增电梯的数量
|
|
|
+ long newLiftNums = value.stream()
|
|
|
+ .filter(a -> a.getLiftStatus() == 1).count();
|
|
|
+ regionLiftResponse.setNewLiftNums(newLiftNums);
|
|
|
+ //丢失电梯台量
|
|
|
+ long lostLiftNums = value.stream()
|
|
|
+ .filter(a -> a.getLiftStatus() == 3).count();
|
|
|
+ regionLiftResponse.setLostLiftNums(lostLiftNums);
|
|
|
+ //实际总台量
|
|
|
+ regionLiftResponse.setTotalLiftNums(totalLiftNums - lostLiftNums);
|
|
|
+ });
|
|
|
+ //通过丢失台量排序并获取前五的数据
|
|
|
+ regionLiftResponseList = regionLiftResponseList.stream()
|
|
|
+ .sorted(Comparator.comparing(RegionLiftResponse::getLostLiftNums)).limit(5)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ //通过丢失台量排序获取前五的台量
|
|
|
+ return RestResponse.success(regionLiftResponseList, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -99,6 +232,28 @@ public class LiftDataService {
|
|
|
* @date 2020/2/5 4:46 下午
|
|
|
*/
|
|
|
public RestResponse projectLiftNums(LiftDataRequest liftDataRequest) {
|
|
|
- return RestResponse.success(ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
|
|
|
+ Map<String, Long> projectNameToLiftNums = new HashMap<>();
|
|
|
+ //获取时间段内的电梯数量
|
|
|
+ List<LiftDataModel> liftDataModelList = getLiftDataListFromRedis(liftDataRequest);
|
|
|
+ if (liftDataModelList != null && liftDataModelList.size() > 0) {
|
|
|
+ //过滤掉丢失的电梯
|
|
|
+ liftDataModelList = liftDataModelList.stream()
|
|
|
+ .filter(a -> a.getLiftStatus() != 3).collect(Collectors.toList());
|
|
|
+ //通过项目名称给电梯数据分组
|
|
|
+ projectNameToLiftNums = liftDataModelList.stream()
|
|
|
+ .collect(Collectors.groupingBy(LiftDataModel::getProjectName, Collectors.counting()));
|
|
|
+ }
|
|
|
+ //通过电梯台量给map排序
|
|
|
+ projectNameToLiftNums.entrySet().stream()
|
|
|
+ .sorted(Comparator.comparing(entry -> entry.getValue()));
|
|
|
+ //获取前5的数据
|
|
|
+ Map<String, Long> topFive = new HashMap<>();
|
|
|
+ projectNameToLiftNums.forEach((key, value) -> {
|
|
|
+ if (topFive.size() < 5) {
|
|
|
+ topFive.put(key, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return RestResponse.success(topFive, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
|
|
|
}
|
|
|
}
|