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; ...@@ -16,6 +16,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
/** /**
* 综合统计分析API * 综合统计分析API
...@@ -177,7 +178,35 @@ public class ComprehensiveStatisticalAnalysisController extends BaseController { ...@@ -177,7 +178,35 @@ public class ComprehensiveStatisticalAnalysisController extends BaseController {
@PostMapping(value = "/page") @PostMapping(value = "/page")
@ApiOperation(httpMethod = "POST", value = "综合统计分析接口分页查询", notes = "综合统计分析接口分页查询") @ApiOperation(httpMethod = "POST", value = "综合统计分析接口分页查询", notes = "综合统计分析接口分页查询")
public ResponseModel<JSONObject> queryForPage(@RequestBody Map<String, Object> map) { 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); 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)); return ResponseHelper.buildResponse(statisticalAnalysisService.queryForPage(jsonObject));
} }
...@@ -197,16 +226,6 @@ public class ComprehensiveStatisticalAnalysisController extends BaseController { ...@@ -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 入参 * @param map 入参
......
...@@ -2694,55 +2694,79 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2694,55 +2694,79 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
// 组装人员过滤条件 // 组装人员过滤条件
this.getPersonBoolQueryBuilder(filterParams, boolMust, filterType); this.getPersonBoolQueryBuilder(filterParams, boolMust, filterType);
// 计算总数 // 通过是否传参 unitType 单位类型 区分一二级查询
long personTotal = this.queryDpPersonStatisticsTotal(boolMust); boolean is2LeveFlag = Optional.of(filter)
.map(obj -> obj.getJSONObject("filterParams"))
// 聚合查询 .map(filterParamsObj -> filterParams.getJSONArray("unitType"))
builder.size(0);// 不返回任何文档,只返回聚合结果 .map(unitTypeObj -> !unitTypeObj.isEmpty())
String aggName = "unit_types_split"; .orElse(false);
QueryBuilderUtils.buildSplitFieldAggCondition(builder, "unitType.keyword", "#", aggName); // 一级统计
builder.query(boolMust); if (!is2LeveFlag) {
request.source(builder); // 计算总数
long personTotal = this.queryDpPersonStatisticsTotal(boolMust);
Map<String, Object> result = new HashMap<>(); // 聚合查询
try { builder.size(0);// 不返回任何文档,只返回聚合结果
SearchResponse searchResponse = restHighLevelClient.search(request, RequestOptions.DEFAULT); String aggName = "unit_types_split";
// 解析聚合结果 QueryBuilderUtils.buildSplitFieldAggCondition(builder, "unitType.keyword", "#", aggName);
Terms unitTypesTerms = searchResponse.getAggregations().get(aggName); builder.query(boolMust);
if (unitTypesTerms != null) { request.source(builder);
for (Terms.Bucket bucket : unitTypesTerms.getBuckets()) {
if (bucket.getKeyAsString().equals(UnitTypeEnum.sydw.getName())) { Map<String, Object> result = new HashMap<>();
result.put("sydw", bucket.getDocCount()); try {
} SearchResponse searchResponse = restHighLevelClient.search(request, RequestOptions.DEFAULT);
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.grzt.getLabel())) { // 解析聚合结果
result.put("grzt", bucket.getDocCount()); Terms unitTypesTerms = searchResponse.getAggregations().get(aggName);
} this.buildPersonWithCompanyTypeGroupResult(unitTypesTerms, result);
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.sjdw.getLabel())) { } catch (Exception e) {
result.put("sjdw", bucket.getDocCount()); throw new RuntimeException(e);
} }
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.zzdw.getLabel())) { // 汇总总数
result.put("zzdw", bucket.getDocCount()); tabTotalMap.put(StatisticalAnalysisEnum.person.getCode(), personTotal);
} return Collections.singletonList(result);
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.azgzwxdw.getLabel())) { } else {
result.put("azgzwxdw", bucket.getDocCount()); // 二级统计
} Map<String, Object> result = new HashMap<>();
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.czdw.getLabel())) { JSONObject expiryDateStatus = this.getExpiryDateStatusGroupStatistics(boolMust);
result.put("czdw", bucket.getDocCount()); JSONObject personType = this.getPersonTypeGroupStatistics(boolMust);
} result.put("tabTotalMap", new JSONObject()
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.jyjg.getLabel())) { .fluentPut("expiryDateStatusTotal", this.sumWithJSONObjectValues(expiryDateStatus))
result.put("jyjg", bucket.getDocCount()); .fluentPut("personTypeTotal", this.sumWithJSONObjectValues(personType)));
} result.put("datas", new JSONObject()
if (bucket.getKeyAsString().equals(UnitTypeNewEnum.jcjg.getLabel())) { .fluentPut("expiryDateStatus", expiryDateStatus)
result.put("jcjg", bucket.getDocCount()); .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) { private long queryDpPersonStatisticsTotal(BoolQueryBuilder boolMust) {
...@@ -2892,6 +2916,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2892,6 +2916,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
String filterType = "advanced"; String filterType = "advanced";
// 组装人员过滤条件 // 组装人员过滤条件
this.getPersonBoolQueryBuilder(filterParams, boolQuery, filterType); this.getPersonBoolQueryBuilder(filterParams, boolQuery, filterType);
// 查询 // 查询
JSONObject expiryDateStatus = this.getExpiryDateStatusGroupStatistics(boolQuery); JSONObject expiryDateStatus = this.getExpiryDateStatusGroupStatistics(boolQuery);
JSONObject personType = this.getPersonTypeGroupStatistics(boolQuery); JSONObject personType = this.getPersonTypeGroupStatistics(boolQuery);
...@@ -2936,7 +2961,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2936,7 +2961,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
); );
normalBoolQuery.must(normalNestedQuery); normalBoolQuery.must(normalNestedQuery);
Long normalCount = getStatisticCount(normalBoolQuery, StatisticalAnalysisEnum.person.getKey()); Long normalCount = getStatisticCount(normalBoolQuery, StatisticalAnalysisEnum.person.getKey());
result.put("资质正常", normalCount); result.put("zzzc", normalCount);
// 资质临期 // 资质临期
BoolQueryBuilder nearBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery); BoolQueryBuilder nearBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery);
...@@ -2947,7 +2972,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2947,7 +2972,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
); );
nearBoolQuery.must(nearNestedQuery); nearBoolQuery.must(nearNestedQuery);
Long nearCount = getStatisticCount(nearBoolQuery, StatisticalAnalysisEnum.person.getKey()); Long nearCount = getStatisticCount(nearBoolQuery, StatisticalAnalysisEnum.person.getKey());
result.put("资质临期", nearCount); result.put("zzlq", nearCount);
// 资质超期 // 资质超期
BoolQueryBuilder overBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery); BoolQueryBuilder overBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery);
...@@ -2958,7 +2983,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2958,7 +2983,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
); );
overBoolQuery.must(overNestedQuery); overBoolQuery.must(overNestedQuery);
Long overCount = getStatisticCount(overBoolQuery, StatisticalAnalysisEnum.person.getKey()); Long overCount = getStatisticCount(overBoolQuery, StatisticalAnalysisEnum.person.getKey());
result.put("资质超期", overCount); result.put("zzcq", overCount);
// 无有效期 // 无有效期
BoolQueryBuilder nothingBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery); BoolQueryBuilder nothingBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery);
...@@ -2969,7 +2994,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2969,7 +2994,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
); );
nothingBoolQuery.must(nothingNestedQuery); nothingBoolQuery.must(nothingNestedQuery);
Long nothingCount = getStatisticCount(nothingBoolQuery, StatisticalAnalysisEnum.person.getKey()); Long nothingCount = getStatisticCount(nothingBoolQuery, StatisticalAnalysisEnum.person.getKey());
result.put("无有效期", nothingCount); result.put("wyxq", nothingCount);
// 无资质 // 无资质
BoolQueryBuilder notLicensesBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery); BoolQueryBuilder notLicensesBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery);
...@@ -2999,7 +3024,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2999,7 +3024,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
mainBuilder.and(enhancedDynamicQueryBuilder.build()); mainBuilder.and(enhancedDynamicQueryBuilder.build());
notLicensesBoolQuery.must(mainBuilder.build()); notLicensesBoolQuery.must(mainBuilder.build());
Long otLicensesCount = getStatisticCount(notLicensesBoolQuery, StatisticalAnalysisEnum.person.getKey()); Long otLicensesCount = getStatisticCount(notLicensesBoolQuery, StatisticalAnalysisEnum.person.getKey());
result.put("无资质", otLicensesCount); result.put("wzz", otLicensesCount);
return result; return result;
} }
...@@ -3024,12 +3049,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -3024,12 +3049,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
try { try {
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT); SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
Terms personTypeGroupAgg = searchResponse.getAggregations().get(aggName); Terms personTypeGroupAgg = searchResponse.getAggregations().get(aggName);
if (personTypeGroupAgg != null) { this.buildPersonWithPersonTypeGroupResult(personTypeGroupAgg, result);
for (Terms.Bucket bucket : personTypeGroupAgg.getBuckets()) {
result.put(bucket.getKeyAsString(), bucket.getDocCount());
}
}
result.remove("作业人员");
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
...@@ -3045,7 +3065,35 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -3045,7 +3065,35 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
} catch (Exception exception) { } catch (Exception exception) {
throw new RuntimeException(exception); throw new RuntimeException(exception);
} }
result.put("作业人员(仅持证人员)", ObjectUtils.isEmpty(countResponse) ? 0L : countResponse.getCount()); result.put("zyczry", ObjectUtils.isEmpty(countResponse) ? 0L : countResponse.getCount());
return result; 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