Commit 95a8067b authored by hcing's avatar hcing

fix:统计服务,大屏综合统计查询接口--人员统计

parent f65026ad
package com.yeejoin.amos.boot.module.statistics.api.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public enum PersonTypeEnum {
/**
* *人员类型
*/
jyry("检验人员"),
jcry("检测人员"),
aqy("安全员"),
agwfzr("安改维负责人"),
zyfzr("主要负责人"),
aqzj("安全总监"),
zlaqy("质量安全员"),
zlaqzj("质量安全总监");
private final String name;
}
......@@ -16,6 +16,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* 综合统计分析API
......@@ -177,7 +178,35 @@ public class ComprehensiveStatisticalAnalysisController extends BaseController {
@PostMapping(value = "/page")
@ApiOperation(httpMethod = "POST", value = "综合统计分析接口分页查询", notes = "综合统计分析接口分页查询")
public ResponseModel<JSONObject> queryForPage(@RequestBody Map<String, Object> map) {
return ResponseHelper.buildResponse(statisticalAnalysisService.queryForPage(new JSONObject(map)));
}
/**
* 综合统计分析接口分页查询-大屏中人员列表
* 区别在于【资质状态】 无资质 certNo_0
* @param map
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/person/page")
@ApiOperation(httpMethod = "POST", value = "综合统计分析接口分页查询-大屏中人员列表", notes = "综合统计分析接口分页查询-大屏中人员列表")
public ResponseModel<JSONObject> queryPersonForPage(@RequestBody Map<String, Object> map) {
JSONObject jsonObject = new JSONObject(map);
String targetValue = "certNo_0";
boolean containsTarget = Optional.of(jsonObject)
.map(obj -> obj.getJSONObject("filterParams"))
.map(filterParams -> filterParams.getJSONArray("expiryDate"))
.map(expiryDateArray -> expiryDateArray.contains(targetValue))
.orElse(false);
if (containsTarget) {
JSONObject filterParams = jsonObject.getJSONObject("filterParams");
JSONArray expiryDate = filterParams.getJSONArray("expiryDate");
expiryDate.remove(targetValue);
JSONArray certNo = filterParams.getJSONArray("certNo");
certNo.add("0");
filterParams.fluentPut("expiryDate", expiryDate).fluentPut("certNo", certNo);
jsonObject.put("filterParams", filterParams);
}
return ResponseHelper.buildResponse(statisticalAnalysisService.queryForPage(jsonObject));
}
......@@ -197,16 +226,6 @@ public class ComprehensiveStatisticalAnalysisController extends BaseController {
}
/**
* 大屏综合统计--人员统计
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/dp/statistics/person")
@ApiOperation(httpMethod = "POST", value = "大屏综合统计查询接口--人员统计", notes = "大屏综合统计查询接口--人员统计")
public ResponseModel<JSONObject> queryDpStatisticsForPerson(@RequestBody Map<String, Object> map) {
return ResponseHelper.buildResponse(statisticalAnalysisService.queryDpStatisticsForPerson(new JSONObject(map)));
}
/**
* 综合统计分析接口-导出
*
* @param map 入参
......
......@@ -2694,55 +2694,79 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
// 组装人员过滤条件
this.getPersonBoolQueryBuilder(filterParams, boolMust, filterType);
// 计算总数
long personTotal = this.queryDpPersonStatisticsTotal(boolMust);
// 聚合查询
builder.size(0);// 不返回任何文档,只返回聚合结果
String aggName = "unit_types_split";
QueryBuilderUtils.buildSplitFieldAggCondition(builder, "unitType.keyword", "#", aggName);
builder.query(boolMust);
request.source(builder);
Map<String, Object> result = new HashMap<>();
try {
SearchResponse searchResponse = restHighLevelClient.search(request, RequestOptions.DEFAULT);
// 解析聚合结果
Terms unitTypesTerms = searchResponse.getAggregations().get(aggName);
if (unitTypesTerms != null) {
for (Terms.Bucket bucket : unitTypesTerms.getBuckets()) {
if (bucket.getKeyAsString().equals(UnitTypeEnum.sydw.getName())) {
result.put("sydw", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.grzt.getLabel())) {
result.put("grzt", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.sjdw.getLabel())) {
result.put("sjdw", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.zzdw.getLabel())) {
result.put("zzdw", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.azgzwxdw.getLabel())) {
result.put("azgzwxdw", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.czdw.getLabel())) {
result.put("czdw", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.jyjg.getLabel())) {
result.put("jyjg", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.jcjg.getLabel())) {
result.put("jcjg", bucket.getDocCount());
}
// 通过是否传参 unitType 单位类型 区分一二级查询
boolean is2LeveFlag = Optional.of(filter)
.map(obj -> obj.getJSONObject("filterParams"))
.map(filterParamsObj -> filterParams.getJSONArray("unitType"))
.map(unitTypeObj -> !unitTypeObj.isEmpty())
.orElse(false);
// 一级统计
if (!is2LeveFlag) {
// 计算总数
long personTotal = this.queryDpPersonStatisticsTotal(boolMust);
// 聚合查询
builder.size(0);// 不返回任何文档,只返回聚合结果
String aggName = "unit_types_split";
QueryBuilderUtils.buildSplitFieldAggCondition(builder, "unitType.keyword", "#", aggName);
builder.query(boolMust);
request.source(builder);
Map<String, Object> result = new HashMap<>();
try {
SearchResponse searchResponse = restHighLevelClient.search(request, RequestOptions.DEFAULT);
// 解析聚合结果
Terms unitTypesTerms = searchResponse.getAggregations().get(aggName);
this.buildPersonWithCompanyTypeGroupResult(unitTypesTerms, result);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 汇总总数
tabTotalMap.put(StatisticalAnalysisEnum.person.getCode(), personTotal);
return Collections.singletonList(result);
} else {
// 二级统计
Map<String, Object> result = new HashMap<>();
JSONObject expiryDateStatus = this.getExpiryDateStatusGroupStatistics(boolMust);
JSONObject personType = this.getPersonTypeGroupStatistics(boolMust);
result.put("tabTotalMap", new JSONObject()
.fluentPut("expiryDateStatusTotal", this.sumWithJSONObjectValues(expiryDateStatus))
.fluentPut("personTypeTotal", this.sumWithJSONObjectValues(personType)));
result.put("datas", new JSONObject()
.fluentPut("expiryDateStatus", expiryDateStatus)
.fluentPut("personType", personType));
return Collections.singletonList(result);
}
}
private void buildPersonWithCompanyTypeGroupResult(Terms unitTypesTerms, Map<String, Object> result) {
if (unitTypesTerms != null) {
for (Terms.Bucket bucket : unitTypesTerms.getBuckets()) {
if (bucket.getKeyAsString().equals(UnitTypeEnum.sydw.getName())) {
result.put("sydw", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.grzt.getLabel())) {
result.put("grzt", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.sjdw.getLabel())) {
result.put("sjdw", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.zzdw.getLabel())) {
result.put("zzdw", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.azgzwxdw.getLabel())) {
result.put("azgzwxdw", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.czdw.getLabel())) {
result.put("czdw", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.jyjg.getLabel())) {
result.put("jyjg", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.jcjg.getLabel())) {
result.put("jcjg", bucket.getDocCount());
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
// 汇总总数
tabTotalMap.put(StatisticalAnalysisEnum.person.getCode(), personTotal);
return Collections.singletonList(result);
}
private long queryDpPersonStatisticsTotal(BoolQueryBuilder boolMust) {
......@@ -2892,6 +2916,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
String filterType = "advanced";
// 组装人员过滤条件
this.getPersonBoolQueryBuilder(filterParams, boolQuery, filterType);
// 查询
JSONObject expiryDateStatus = this.getExpiryDateStatusGroupStatistics(boolQuery);
JSONObject personType = this.getPersonTypeGroupStatistics(boolQuery);
......@@ -2936,7 +2961,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
);
normalBoolQuery.must(normalNestedQuery);
Long normalCount = getStatisticCount(normalBoolQuery, StatisticalAnalysisEnum.person.getKey());
result.put("资质正常", normalCount);
result.put("zzzc", normalCount);
// 资质临期
BoolQueryBuilder nearBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery);
......@@ -2947,7 +2972,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
);
nearBoolQuery.must(nearNestedQuery);
Long nearCount = getStatisticCount(nearBoolQuery, StatisticalAnalysisEnum.person.getKey());
result.put("资质临期", nearCount);
result.put("zzlq", nearCount);
// 资质超期
BoolQueryBuilder overBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery);
......@@ -2958,7 +2983,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
);
overBoolQuery.must(overNestedQuery);
Long overCount = getStatisticCount(overBoolQuery, StatisticalAnalysisEnum.person.getKey());
result.put("资质超期", overCount);
result.put("zzcq", overCount);
// 无有效期
BoolQueryBuilder nothingBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery);
......@@ -2969,7 +2994,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
);
nothingBoolQuery.must(nothingNestedQuery);
Long nothingCount = getStatisticCount(nothingBoolQuery, StatisticalAnalysisEnum.person.getKey());
result.put("无有效期", nothingCount);
result.put("wyxq", nothingCount);
// 无资质
BoolQueryBuilder notLicensesBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery);
......@@ -2999,7 +3024,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
mainBuilder.and(enhancedDynamicQueryBuilder.build());
notLicensesBoolQuery.must(mainBuilder.build());
Long otLicensesCount = getStatisticCount(notLicensesBoolQuery, StatisticalAnalysisEnum.person.getKey());
result.put("无资质", otLicensesCount);
result.put("wzz", otLicensesCount);
return result;
}
......@@ -3024,12 +3049,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
try {
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
Terms personTypeGroupAgg = searchResponse.getAggregations().get(aggName);
if (personTypeGroupAgg != null) {
for (Terms.Bucket bucket : personTypeGroupAgg.getBuckets()) {
result.put(bucket.getKeyAsString(), bucket.getDocCount());
}
}
result.remove("作业人员");
this.buildPersonWithPersonTypeGroupResult(personTypeGroupAgg, result);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
......@@ -3045,7 +3065,35 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
} catch (Exception exception) {
throw new RuntimeException(exception);
}
result.put("作业人员(仅持证人员)", ObjectUtils.isEmpty(countResponse) ? 0L : countResponse.getCount());
result.put("zyczry", ObjectUtils.isEmpty(countResponse) ? 0L : countResponse.getCount());
return result;
}
private void buildPersonWithPersonTypeGroupResult(Terms personTypeGroupAgg, JSONObject result) {
if (personTypeGroupAgg != null) {
for (Terms.Bucket bucket : personTypeGroupAgg.getBuckets()) {
if (bucket.getKeyAsString().equals(PersonTypeEnum.zyfzr.getName())){
result.put("zyfzr", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(PersonTypeEnum.aqzj.getName())){
result.put("aqzj", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(PersonTypeEnum.aqy.getName())){
result.put("aqy", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(PersonTypeEnum.jyry.getName())){
result.put("jyry", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(PersonTypeEnum.jcry.getName())){
result.put("jcry", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(PersonTypeEnum.zlaqzj.getName())){
result.put("zlaqzj", bucket.getDocCount());
}
if (bucket.getKeyAsString().equals(PersonTypeEnum.zlaqy.getName())){
result.put("zlaqy", bucket.getDocCount());
}
}
}
}
}
\ No newline at end of file
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