Commit 8aafabca authored by tianbo's avatar tianbo

气瓶预警预报统计接口

parent 0552ff9a
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<!-- Vastbase G100 --> <!-- Vastbase G100 -->
<dependency>@ <dependency>
<groupId>cn.com.vastdata</groupId> <groupId>cn.com.vastdata</groupId>
<artifactId>vastbase</artifactId> <artifactId>vastbase</artifactId>
<version>1.0.0.2</version> <version>1.0.0.2</version>
......
...@@ -102,19 +102,19 @@ public class ESCylinderFillingRecordDto { ...@@ -102,19 +102,19 @@ public class ESCylinderFillingRecordDto {
private String fillingResult; private String fillingResult;
//装后检查人员姓名 //装后检查人员姓名
@Field(type = FieldType.Text) @Field(type = FieldType.Text)
private String inspector; private String inspector;
//装后检查时间 //装后检查时间
@Field(type = FieldType.Text) @Field(type = FieldType.Text)
private String inspectionDateAfter; private String inspectionDateAfter;
//充装检查结果毫秒值 //充装检查结果毫秒值
@Field(type = FieldType.Long) @Field(type = FieldType.Long)
private Long inspectionDateAfterMS; private Long inspectionDateAfterMS;
//装后检查结果 //装后检查结果
@Field(type = FieldType.Text) @Field(type = FieldType.Text)
private String checkResult; private String checkResult;
......
...@@ -2,6 +2,9 @@ package com.yeejoin.amos.boot.module.cylinder.flc.api.mapper; ...@@ -2,6 +2,9 @@ package com.yeejoin.amos.boot.module.cylinder.flc.api.mapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderAreaData; import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderAreaData;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.Map;
/** /**
* 气瓶区域统计表 Mapper 接口 * 气瓶区域统计表 Mapper 接口
...@@ -11,4 +14,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -11,4 +14,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/ */
public interface CylinderAreaDataMapper extends BaseMapper<CylinderAreaData> { public interface CylinderAreaDataMapper extends BaseMapper<CylinderAreaData> {
Map<String, Object> getLicenseEfficiency(@Param(value = "regionCode")String regionCode, @Param(value = "appId")String appId);
Map<String, Object> getInspectionExpiredRate(@Param(value = "regionCode")String regionCode, @Param(value = "appId")String appId);
Map<String, Object> getInspectionResultRate(@Param(value = "regionCode")String regionCode, @Param(value = "appId")String appId);
} }
...@@ -2,4 +2,52 @@ ...@@ -2,4 +2,52 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderAreaDataMapper"> <mapper namespace="com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderAreaDataMapper">
<select id="getLicenseEfficiency" resultType="java.util.Map">
SELECT
CASE WHEN COUNT ( CASE WHEN ul.expiry_date >= now( ) THEN 1 END ) = 1 THEN '正常' ELSE '已超期' END AS licenseOk,
CASE WHEN COUNT(*) = 0 THEN 0 ELSE ROUND( ( COUNT ( CASE WHEN ul.expiry_date >= now( ) THEN 1 END ) * 100.0 / COUNT ( * ) ), 2 ) END AS licenseRate
FROM
tz_cylinder_unit cu
LEFT JOIN tz_base_unit_licence ul ON cu.credit_code = ul.unit_code
<where>
<if test="regionCode != null and regionCode != ''">
cu.region_code like concat('%', #{regionCode}, '%')
</if>
<if test="appId != null and appId != ''">
cu.app_id = #{appId}
</if>
</where>
</select>
<select id="getInspectionExpiredRate" resultType="java.util.Map">
SELECT
CASE WHEN COUNT(*) = 0 THEN 0 ELSE ROUND((COUNT(CASE WHEN ci.next_inspection_date > now() THEN 1 END) * 100.0 / COUNT(*)), 2) END AS expiredRate
FROM
"tz_cylinder_inspection" ci
LEFT JOIN tz_cylinder_unit cu on ci.app_id = cu.app_id
<where>
<if test="regionCode != null and regionCode != ''">
cu.region_code like concat('%', #{regionCode}, '%')
</if>
<if test="appId != null and appId != ''">
cu.app_id = #{appId}
</if>
</where>
</select>
<select id="getInspectionResultRate" resultType="java.util.Map">
SELECT
CASE WHEN COUNT(*) = 0 THEN 0 ELSE ROUND((COUNT(CASE WHEN ci.inspection_result = '3123' THEN 1 END) * 100.0 / COUNT(*)), 2) END AS resultRate
FROM
"tz_cylinder_inspection" ci
LEFT JOIN tz_cylinder_unit cu on ci.app_id = cu.app_id
<where>
<if test="regionCode != null and regionCode != ''">
cu.region_code like concat('%', #{regionCode}, '%')
</if>
<if test="appId != null and appId != ''">
cu.app_id = #{appId}
</if>
</where>
</select>
</mapper> </mapper>
package com.yeejoin.amos.boot.module.cylinder.flc.biz.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.cylinder.flc.biz.service.impl.CylinderAreaDataServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List;
import java.util.Map;
@RestController
@Api(tags = "气瓶统计Api")
@RequestMapping(value = "/statistics")
public class CylinderStatisticsController {
@Autowired
private CylinderAreaDataServiceImpl service;
/**
* 预警预报统计
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@RequestMapping(value = "/earlyWarning", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "预警预报")
public ResponseModel<Page<Map<String, Object>>> getEarlyWarning(@RequestParam(value = "regionCode", required = false) String regionCode, @RequestParam(value = "appId", required = false) String appId){
return ResponseHelper.buildResponse(service.getEarlyWarningStatistics(regionCode, appId));
}
}
package com.yeejoin.amos.boot.module.cylinder.flc.biz.service.impl; package com.yeejoin.amos.boot.module.cylinder.flc.biz.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yeejoin.amos.boot.module.cylinder.api.entity.ESCylinderFillingRecordDto;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderAreaData; import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderAreaData;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderAreaDataMapper; import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderAreaDataMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.service.ICylinderAreaDataService; import com.yeejoin.amos.boot.module.cylinder.flc.api.service.ICylinderAreaDataService;
import com.yeejoin.amos.boot.module.cylinder.flc.api.dto.CylinderAreaDataDto; import com.yeejoin.amos.boot.module.cylinder.flc.api.dto.CylinderAreaDataDto;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
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.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 气瓶区域统计表服务实现类 * 气瓶区域统计表服务实现类
...@@ -17,6 +39,13 @@ import java.util.List; ...@@ -17,6 +39,13 @@ import java.util.List;
*/ */
@Service @Service
public class CylinderAreaDataServiceImpl extends BaseService<CylinderAreaDataDto,CylinderAreaData,CylinderAreaDataMapper> implements ICylinderAreaDataService { public class CylinderAreaDataServiceImpl extends BaseService<CylinderAreaDataDto,CylinderAreaData,CylinderAreaDataMapper> implements ICylinderAreaDataService {
@Autowired
private CylinderAreaDataMapper mapper;
@Autowired
RestHighLevelClient restHighLevelClient;
/** /**
* 分页查询 * 分页查询
*/ */
...@@ -30,4 +59,113 @@ public class CylinderAreaDataServiceImpl extends BaseService<CylinderAreaDataDto ...@@ -30,4 +59,113 @@ public class CylinderAreaDataServiceImpl extends BaseService<CylinderAreaDataDto
public List<CylinderAreaDataDto> queryForCylinderAreaDataList() { public List<CylinderAreaDataDto> queryForCylinderAreaDataList() {
return this.queryForList("" , false); return this.queryForList("" , false);
} }
public Page<Map<String, Object>> getEarlyWarningStatistics(String regionCode, String appId) {
Page<Map<String, Object>> page = new Page<>();
List<Map<String, Object>> list = Lists.newArrayList();
Map<String, Object> result1 = Maps.newHashMap();
Map<String, Object> result2 = Maps.newHashMap();
// 1.许可有效率
if (!ValidationUtil.isEmpty(appId)) {
result1.put("name", "许可有效期");
result1.put("value", mapper.getLicenseEfficiency(null, appId).get("licenseOk").toString());
} else if (!ValidationUtil.isEmpty(regionCode)){
result1.put("name", "许可有效率(%)");
result1.put("value", mapper.getLicenseEfficiency(regionCode, null).get("licenseRate").toString());
}
// 2.使用登记办理率
if (!ValidationUtil.isEmpty(appId)) {
result2.put("name", "使用登记");
result2.put("value", "已办理");
} else {
result2.put("name", "使用登记办理率(%)");
result2.put("value", "100");
}
// 3.检验超期率
Map<String, Object> result3 = Maps.newHashMap();
result3.put("name", "检验超期率(%)");
result3.put("value", mapper.getInspectionExpiredRate(regionCode, appId).get("expiredRate").toString());
// 4.检验合格率
Map<String, Object> result4 = Maps.newHashMap();
result4.put("name", "检验合格率(%)");
result4.put("value", mapper.getInspectionResultRate(regionCode, appId).get("resultRate").toString());
// 5.充装检查率
Map<String, Object> result5 = Maps.newHashMap();
long totalAll = searchEsCount(false, false, regionCode, appId);
long totalCheck = searchEsCount(true, false, regionCode, appId);
long totalResult = searchEsCount(false, true, regionCode, appId);
result5.put("name", "充装检查率(%)");
if (totalAll != 0) {
result5.put("value", (totalCheck / totalAll) * 100);
} else {
result5.put("value", 0);
}
// 6.充装检查合格率
Map<String, Object> result6 = Maps.newHashMap();
result6.put("name", "充装检查合格率(%)");
if (totalAll != 0) {
result6.put("value", (totalResult / totalAll) * 100);
} else {
result6.put("value", 0);
}
// list中按以下固定顺序返回给前端
list.add(result1);
list.add(result3);
list.add(result5);
list.add(result2);
list.add(result4);
list.add(result6);
page.setRecords(list);
return page;
}
private Map<String, Object> getFillingCheckRate(ESCylinderFillingRecordDto esCylinderFillingRecordDto) {
return null;
}
private Map<String, Object> getValidFillingCheckRate(ESCylinderFillingRecordDto esCylinderFillingRecordDto) {
return null;
}
private long searchEsCount(Boolean checkOk, Boolean resultOk, String regionCode, String appId) {
CountRequest countRequest = new CountRequest();
countRequest.indices("cylinder_filling");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
if (checkOk) {
//匹配充装前检查和充装后检查都有数据
BoolQueryBuilder meBuilder = QueryBuilders.boolQuery();
meBuilder.must(QueryBuilders.existsQuery("inspectionDateMs"));
meBuilder.must(QueryBuilders.existsQuery("inspectionDateAfterMS"));
boolMust.must(meBuilder);
}
if (resultOk) {
//匹配充装前检查和充装后检查都有数据
BoolQueryBuilder meBuilder = QueryBuilders.boolQuery();
meBuilder.must(QueryBuilders.matchQuery("fillingResult", "合格"));
meBuilder.must(QueryBuilders.matchQuery("checkResult", "合格"));
boolMust.must(meBuilder);
}
//匹配行政区划
if (!ObjectUtils.isEmpty(regionCode)) {
BoolQueryBuilder query = QueryBuilders.boolQuery();
query.must(QueryBuilders.wildcardQuery("regionCode", "*" + regionCode + "*"));
boolMust.must(query);
}
//匹配appId
if (!ObjectUtils.isEmpty(appId)) {
BoolQueryBuilder query = QueryBuilders.boolQuery();
query.must(QueryBuilders.matchQuery("appId", appId));
boolMust.must(query);
}
countRequest.query(boolMust);
try {
CountResponse countResponse = restHighLevelClient.count(countRequest, RequestOptions.DEFAULT);
return countResponse.getCount();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
} }
\ 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