|
@@ -8,6 +8,7 @@ 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.ty.lift.common.constants.CommonEnum;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -50,6 +51,20 @@ public class LiftDataService {
|
|
|
*/
|
|
|
public void putLiftDataListToRedis(CommonRequest commonRequest) {
|
|
|
List<LiftDataModel> liftDataModelList = liftDataMapper.getLiftDataList(commonRequest);
|
|
|
+ //设置电梯状态:1:新增, 3:丢失
|
|
|
+ if (liftDataModelList != null && liftDataModelList.size() > 0) {
|
|
|
+ liftDataModelList.forEach(entry -> {
|
|
|
+ //默认状态为新增
|
|
|
+ entry.setLiftStatus(1);
|
|
|
+ //电梯停保
|
|
|
+ if (CommonEnum.LiftStatus.STOP_INSURANCE.equals(entry.getLiftCompanyStatus())) {
|
|
|
+ entry.setLiftStatus(3);
|
|
|
+ } else if (CommonEnum.ProjectStatus.STOP_SERVICE.equals(entry.getProjectStatus())) {
|
|
|
+ entry.setLiftStatus(3);
|
|
|
+ entry.setLostTime(entry.getProjectEndTime());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
//通过公司id将数据进行分组,并将数据放入redis中
|
|
|
DataStatisticsUtil.putStatisticsDataToRedis(liftDataModelList, redisTemplate,
|
|
|
DataStatisticsConstants.LIFT_DATA_FIELD);
|
|
@@ -83,38 +98,6 @@ 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
|
|
@@ -163,25 +146,8 @@ public class LiftDataService {
|
|
|
.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);
|
|
|
+ //设置电梯总览情况
|
|
|
+ setLiftOverViewNum(liftDataRequest, liftStatusToNums, beforeLiftTotalNum, monthToNewLiftNums, monthToLostLiftNums);
|
|
|
}
|
|
|
return RestResponse.success(liftStatusToNums, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
|
|
|
}
|
|
@@ -195,7 +161,7 @@ public class LiftDataService {
|
|
|
public RestResponse regionRank(LiftDataRequest liftDataRequest) {
|
|
|
//区域电梯数据
|
|
|
List<RegionLiftResponse> regionLiftResponseList = new ArrayList<>();
|
|
|
- List<LiftDataModel> liftDataModelList = getRegionListFromRedis(liftDataRequest);
|
|
|
+ List<LiftDataModel> liftDataModelList = getLiftDataListFromRedis(liftDataRequest);
|
|
|
if (liftDataModelList != null && liftDataModelList.size() > 0) {
|
|
|
//将数据转化为 区域名称->电梯数据列表
|
|
|
Map<String, List<LiftDataModel>> regionNameToLiftData = liftDataModelList.stream()
|
|
@@ -254,4 +220,31 @@ public class LiftDataService {
|
|
|
});
|
|
|
return RestResponse.success(topFive, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @description 设置电梯总览情况
|
|
|
+ * @date 2020/2/10 11:36 上午
|
|
|
+ */
|
|
|
+ private void setLiftOverViewNum(LiftDataRequest liftDataRequest, Map<Integer, List<Long>> liftStatusToNums, long beforeLiftTotalNum, Map<Integer, Long> monthToNewLiftNums, Map<Integer, Long> monthToLostLiftNums) {
|
|
|
+ //获取截止时间的月份值
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|