Commit ce504948 authored by 刘凡's avatar 刘凡

*)修改从ES查询电梯数据

parent 11b4af99
......@@ -6,20 +6,23 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
import com.yeejoin.amos.boot.module.common.api.enums.ReginStepEnum;
import com.yeejoin.amos.boot.module.elevator.api.dto.AlertMaintenanceUnitStatisticsDto;
import com.yeejoin.amos.boot.module.elevator.api.dto.AlertPaperInfoDto;
import com.yeejoin.amos.boot.module.elevator.api.dto.AlertUseUnitStatisticsDto;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertMaintenanceUnitStatistics;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertRescueStatistics;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertUseUnitStatistics;
import com.yeejoin.amos.boot.module.elevator.api.entity.Elevator;
import com.yeejoin.amos.boot.module.elevator.api.enums.EquipmentClassifityEnum;
import com.yeejoin.amos.boot.module.elevator.api.mapper.*;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.RegionModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.core.CountRequest;
import org.elasticsearch.client.core.CountResponse;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.Bean;
......@@ -27,6 +30,7 @@ import org.typroject.tyboot.core.foundation.utils.DateTimeUtil;
import org.typroject.tyboot.core.foundation.utils.DateUtil;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
......@@ -63,6 +67,9 @@ public class DPStatisticsServiceImpl {
@Autowired
AlertCalledServiceImpl alertCalledService;
@Autowired
private RestHighLevelClient restHighLevelClient;
private static Map<String, String> regionCodeOrgCodeMap = new ConcurrentHashMap<>();
private static Map<String, List<RegionModel>> regionChildRegionMap = new ConcurrentHashMap<>();
......@@ -118,16 +125,10 @@ public class DPStatisticsServiceImpl {
List<RegionModel> regionList = this.getRegionList(dpFilterParamDto);
List<String> xdata = regionList.stream().map(r -> r.getRegionName().toString()).collect(Collectors.toList());
List<Integer> ydata = new ArrayList<>();
Map<String, Integer> map = new HashMap<>();
regionList.parallelStream().forEach(x -> {
LambdaQueryWrapper<Elevator> lambda = new QueryWrapper<Elevator>().lambda();
lambda.like(Elevator::getRegionCode, x.getRegionCode());
map.put(x.getRegionName(), elevatorMapper.selectCount(lambda));
});
xdata.stream().forEach(x -> {
ydata.add(map.get(x));
List<Long> ydata = new ArrayList<>();
regionList.stream().forEach(x -> {
String orgCode = this.getAndSetOrgCode(x.getRegionCode().toString());
ydata.add(elevatorCountByES(orgCode));
});
JSONObject jsonObject = new JSONObject();
jsonObject.put("xdata", xdata);
......@@ -376,4 +377,23 @@ public class DPStatisticsServiceImpl {
dpFilterParamDto.setEndDate(cn.hutool.core.date.DateUtil.today());
}
}
private long elevatorCountByES(String orgCode) {
long num = 0L;
CountRequest request = new CountRequest();
request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
// 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 在用状态设备
boolMust.must(QueryBuilders.termQuery("EQU_LIST_CODE", EquipmentClassifityEnum.DT.getCode()));
request.query(boolMust);
try {
CountResponse response = restHighLevelClient.count(request, RequestOptions.DEFAULT);
num = response.getCount();
} catch (IOException e) {
throw new RuntimeException(e);
}
return num;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment