Commit f3cd3e18 authored by suhuiguang's avatar suhuiguang

1.全景监控,今日安全指数

parent 70cc550b
package com.yeejoin.amos.fas.common.enums;
/**
* @author suhg
*/
public enum RpnChangeTypeEum {
/**
* rpn 上升
*/
upper("上升",0),
/**
* rpn 下降
*/
down("下降",1);
private String label;
private int value;
RpnChangeTypeEum(String label,int value ){
this.label = label;
this.value = value;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
...@@ -8,12 +8,7 @@ import com.yeejoin.amos.fas.core.util.CommonResponseUtil; ...@@ -8,12 +8,7 @@ import com.yeejoin.amos.fas.core.util.CommonResponseUtil;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yeejoin.amos.fas.business.service.intfc.IRiskSourceService; import com.yeejoin.amos.fas.business.service.intfc.IRiskSourceService;
import com.yeejoin.amos.fas.business.vo.ReginParams; import com.yeejoin.amos.fas.business.vo.ReginParams;
...@@ -47,8 +42,9 @@ public class View3dController extends BaseController { ...@@ -47,8 +42,9 @@ public class View3dController extends BaseController {
@ApiOperation(value = "区域详情查询", notes = "区域详情查询") @ApiOperation(value = "区域详情查询", notes = "区域详情查询")
@GetMapping(value = "region/detail/{id}") @GetMapping(value = "region/detail/{id}")
public CommonResponse getRegionDetail(@PathVariable("id") Long id) { public CommonResponse getRegionDetail(@PathVariable("id") Long id) {
ReginParams reginParams =getSelectedOrgInfo(); // ReginParams reginParams =getSelectedOrgInfo();
String orgCode = this.getOrgCode(reginParams); // String orgCode = this.getOrgCode(reginParams);
String orgCode = "1*2";
return CommonResponseUtil.success(riskSourceService.findRegionById(id,orgCode)); return CommonResponseUtil.success(riskSourceService.findRegionById(id,orgCode));
} }
...@@ -70,12 +66,25 @@ public class View3dController extends BaseController { ...@@ -70,12 +66,25 @@ public class View3dController extends BaseController {
} }
@ApiOperation(value = "按照分类查询点树", notes = "按照分类查询点树") @ApiOperation(value = "按照分类查询点树", notes = "按照分类查询点树")
@GetMapping(value = "point/type/{type}") @GetMapping(value = "point/tree/{type}")
public CommonResponse getPointTreeByType(@PathVariable("type") String type) { public CommonResponse getPointTreeByType(@PathVariable("type") String type) {
ReginParams reginParams =getSelectedOrgInfo(); ReginParams reginParams =getSelectedOrgInfo();
String orgCode = this.getOrgCode(reginParams); String orgCode = this.getOrgCode(reginParams);
return CommonResponseUtil.success(view3dService.getPointTreeByType(type,orgCode)); return CommonResponseUtil.success(view3dService.getPointTreeByType(type,orgCode));
} }
@ApiOperation(value = "今日安全指数查询",notes = "按照日期查询安全指数及分类数据")
@GetMapping(value = "/statistics/safetyIndex")
public CommonResponse getSafetyIndexInfoByDate(@RequestParam(name = "date",required = false) String date){
// ReginParams reginParams =getSelectedOrgInfo();
// String orgCode = this.getOrgCode(reginParams);
String orgCode = "1*2";
return CommonResponseUtil.success(view3dService.getSafetyIndexInfoByDate(orgCode,date));
}
@GetMapping(value = "safetyIndex/detail/{type}")
public CommonResponse SafetyIndexDetail(@PathVariable String type){
;
return CommonResponseUtil.success(view3dService.getSafetyIndexDetail(type));
}
} }
package com.yeejoin.amos.fas.business.dao.mapper; package com.yeejoin.amos.fas.business.dao.mapper;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -10,4 +11,17 @@ public interface View3dMapper extends BaseMapper{ ...@@ -10,4 +11,17 @@ public interface View3dMapper extends BaseMapper{
List<RegionTreeResponse> getPointTreeByType(@Param("type")String type,@Param("orgCode")String orgCode); List<RegionTreeResponse> getPointTreeByType(@Param("type")String type,@Param("orgCode")String orgCode);
/**
* 统计风险上升异常数量(风险点)-日期+机构
* @param param:{type,orgCode}
* @return Long
*/
Long countUpperRiskPoint(Map<String,Object> param);
/**
* 统计巡检异常数量(不合格、漏检)-日期+机构
* @param param{}
* @return Long
*/
Long countCheckException(Map<String,Object> param);
} }
...@@ -36,5 +36,5 @@ public interface IRiskSourceDao extends BaseDao<RiskSource, Long> { ...@@ -36,5 +36,5 @@ public interface IRiskSourceDao extends BaseDao<RiskSource, Long> {
List<RiskSource> queryRiskAreaRpn(); List<RiskSource> queryRiskAreaRpn();
Optional<RiskSource> findByOrgCodeAndParentId(String orgCode, Long parentId);
} }
package com.yeejoin.amos.fas.business.service.impl; package com.yeejoin.amos.fas.business.service.impl;
import java.util.List; import java.math.BigDecimal;
import java.util.Map; import java.util.*;
import java.util.Optional;
import com.alibaba.fastjson.JSONObject;
import com.sun.xml.internal.bind.v2.TODO;
import com.yeejoin.amos.fas.business.bo.BindPointBo; import com.yeejoin.amos.fas.business.bo.BindPointBo;
import com.yeejoin.amos.fas.business.dao.mapper.PatrolMapper; import com.yeejoin.amos.fas.business.dao.mapper.PatrolMapper;
import com.yeejoin.amos.fas.business.dao.repository.*; import com.yeejoin.amos.fas.business.dao.repository.*;
import com.yeejoin.amos.fas.business.service.intfc.IView3dService; import com.yeejoin.amos.fas.business.service.intfc.IView3dService;
import com.yeejoin.amos.fas.core.util.CommonResponse; import com.yeejoin.amos.fas.business.vo.SafetyIndexDetailVo;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil; import com.yeejoin.amos.fas.business.vo.TodaySafetyIndexVo;
import com.yeejoin.amos.fas.common.enums.RpnChangeTypeEum;
import com.yeejoin.amos.fas.core.common.request.DateUtil;
import com.yeejoin.amos.fas.core.util.*;
import com.yeejoin.amos.fas.dao.entity.*; import com.yeejoin.amos.fas.dao.entity.*;
import com.yeejoin.amos.fas.exception.YeeException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -49,10 +54,11 @@ public class View3dServiceImpl implements IView3dService { ...@@ -49,10 +54,11 @@ public class View3dServiceImpl implements IView3dService {
private IEquipmentDao iEquipmentDao; private IEquipmentDao iEquipmentDao;
@Autowired @Autowired
private IWaterResourceDao iWaterResourceDao; private IWaterResourceDao iWaterResourceDao;
@Autowired @Autowired
private PatrolMapper patrolMapper; private PatrolMapper patrolMapper;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public CommonResponse setPoint3dPosition(List<BindPointBo> pointBoList) { public CommonResponse setPoint3dPosition(List<BindPointBo> pointBoList) {
...@@ -171,4 +177,57 @@ public class View3dServiceImpl implements IView3dService { ...@@ -171,4 +177,57 @@ public class View3dServiceImpl implements IView3dService {
public List<RegionTreeResponse> getPointTreeByType(String type,String orgCode) { public List<RegionTreeResponse> getPointTreeByType(String type,String orgCode) {
return view3dMapper.getPointTreeByType(type,orgCode); return view3dMapper.getPointTreeByType(type,orgCode);
} }
@Override
public TodaySafetyIndexVo getSafetyIndexInfoByDate(String orgCode,String date) {
if(!StringUtil.isNotEmpty(date)){
date = DateUtil.getDateFormat(new Date(),DateUtil.DATE_DEFAULT_FORMAT);
}
Optional<RiskSource> optional = iRiskSourceDao.findByOrgCodeAndParentId(orgCode,0L);
TodaySafetyIndexVo vo = new TodaySafetyIndexVo();
if(optional.isPresent()){
//1.按照等级进行转换rpn为分数-机构
RiskSource riskSource = optional.get();
double safetyIndex = this.calSafetyIndex(riskSource);
vo.setSafetyIndex(safetyIndex);
//2.统计风险上升异常数量(风险点)-日期+机构
Long upperNum = this.getRiskUpperNum(orgCode, date);
vo.setRiskExceptionNum(upperNum);
//3.统计巡检异常数量(不合格、漏检)-日期+机构
Long checkExceptionNum = this.getCheckExceptionNum(orgCode,date);
vo.setCheckExceptionNum(checkExceptionNum);
//4.统计火灾报警数量-日期+机构
//TODO:待毛颖确认调整完成后继续
vo.setFireExceptionNum(0L);
} else {
throw new YeeException("机构:"+orgCode+" 不存在");
}
return vo;
}
@Override
public List<SafetyIndexDetailVo> getSafetyIndexDetail(String type) {
return null;
}
private Long getCheckExceptionNum(String orgCode, String date) {
Map<String,Object> params = new HashMap<>();
params.put("orgCode", orgCode);
params.put("date", date);
return view3dMapper.countCheckException(params);
}
private Long getRiskUpperNum(String orgCode, String date) {
Map<String,Object> param = new HashMap<>();
param.put("type", RpnChangeTypeEum.upper.getValue());
param.put("orgCode", orgCode);
param.put("date", date);
return view3dMapper.countUpperRiskPoint(param);
}
private double calSafetyIndex(RiskSource riskSource) {
BigDecimal rpn = new BigDecimal(String.valueOf(riskSource.getRpn() == null ? "0" : riskSource.getRpn()));
//计算规则:除10 减100 求绝对值,结果保留1位小数
return rpn.divide(new BigDecimal("10")).subtract(new BigDecimal("100")).abs().setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();
}
} }
package com.yeejoin.amos.fas.business.service.intfc; package com.yeejoin.amos.fas.business.service.intfc;
import com.yeejoin.amos.fas.business.bo.BindPointBo; import com.yeejoin.amos.fas.business.bo.BindPointBo;
import com.yeejoin.amos.fas.business.vo.SafetyIndexDetailVo;
import com.yeejoin.amos.fas.business.vo.TodaySafetyIndexVo;
import com.yeejoin.amos.fas.core.common.response.RegionTreeResponse; import com.yeejoin.amos.fas.core.common.response.RegionTreeResponse;
import com.yeejoin.amos.fas.core.util.CommonResponse; import com.yeejoin.amos.fas.core.util.CommonResponse;
...@@ -12,9 +14,39 @@ import java.util.Map; ...@@ -12,9 +14,39 @@ import java.util.Map;
*/ */
public interface IView3dService { public interface IView3dService {
/**
* 区域绑定保存
* @param pointBoList 数组
* @return 空
*/
CommonResponse setPoint3dPosition(List<BindPointBo> pointBoList); CommonResponse setPoint3dPosition(List<BindPointBo> pointBoList);
/**
* 点类型查询
* @return list
*/
List<Map<String, String>> getPointType(); List<Map<String, String>> getPointType();
/**
* 按照分类查询点树
* @param type 树类型字典值
* @param orgCode 登陆机构
* @return list
*/
List<RegionTreeResponse> getPointTreeByType(String type,String orgCode); List<RegionTreeResponse> getPointTreeByType(String type,String orgCode);
/**
* 今日安全指数
* @param orgCode 登陆机构
* @param date 日期
* @return TodaySafetyIndexVo
*/
TodaySafetyIndexVo getSafetyIndexInfoByDate(String orgCode, String date);
/**
* 今日安全指数详情
* @param type 详情类型
* @return list
*/
List<SafetyIndexDetailVo> getSafetyIndexDetail(String type);
} }
package com.yeejoin.amos.fas.business.vo;
/**
* @author suhg
*/
public class ErrorContentVo {
/**
* 名称
*/
private String name;
/**
* 日期
*/
private String changeDate;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getChangeDate() {
return changeDate;
}
public void setChangeDate(String changeDate) {
this.changeDate = changeDate;
}
}
package com.yeejoin.amos.fas.business.vo;
import java.util.List;
/**
* @author suhg
*/
public class SafetyIndexDetailVo {
/**
* 类型字典
*/
private String typeCode;
/**
* 类型名称
*/
private String typeName;
/**
* 异常内容数组
*/
private List<ErrorContentVo> content;
public String getTypeCode() {
return typeCode;
}
public void setTypeCode(String typeCode) {
this.typeCode = typeCode;
}
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
public List<ErrorContentVo> getContent() {
return content;
}
public void setContent(List<ErrorContentVo> content) {
this.content = content;
}
}
package com.yeejoin.amos.fas.business.vo;
/**
* @author suhg
*/
public class TodaySafetyIndexVo {
private Double safetyIndex;
private Long riskExceptionNum;
private Long checkExceptionNum;
private Long fireExceptionNum;
public Long getRiskExceptionNum() {
return riskExceptionNum;
}
public void setRiskExceptionNum(Long riskExceptionNum) {
this.riskExceptionNum = riskExceptionNum;
}
public Long getCheckExceptionNum() {
return checkExceptionNum;
}
public void setCheckExceptionNum(Long checkExceptionNum) {
this.checkExceptionNum = checkExceptionNum;
}
public Long getFireExceptionNum() {
return fireExceptionNum;
}
public void setFireExceptionNum(Long fireExceptionNum) {
this.fireExceptionNum = fireExceptionNum;
}
public Double getSafetyIndex() {
return safetyIndex;
}
public void setSafetyIndex(Double safetyIndex) {
this.safetyIndex = safetyIndex;
}
}
...@@ -31,5 +31,39 @@ ...@@ -31,5 +31,39 @@
AND org_code like CONCAT(#{orgCode},'%') AND org_code like CONCAT(#{orgCode},'%')
</if> </if>
</select> </select>
<select id="countUpperRiskPoint" resultType="long">
SELECT
count(DISTINCT frcl.id)
FROM
(
SELECT
a.id,
a.risk_source_id,
date_format(a.create_date, '%Y-%m-%d') AS create_date
FROM
`f_rpn_change_log` a,
`f_risk_source` b
WHERE
a.type = #{type}
and a.risk_source_id = b.id
and b.org_code = #{orgCode}
) as frcl
WHERE
frcl.create_date = #{date}
</select>
<select id="countCheckException" resultType="long">
select count(1) from
(
SELECT
a.id,
DATE_FORMAT(b.begin_time,'%Y-%m-%d') as begin_date,
DATE_FORMAT(b.end_time,'%Y-%m-%d') as end_date
FROM `p_plan_task_detail` a , p_plan_task b
where
a.task_no = b.id
and a.`status` in ('2','3')
and (b.org_code = #{orgCode} or b.org_code like CONCAT(#{orgCode},'-','%'))
) pt
where #{date} BETWEEN pt.begin_date and pt.end_date
</select>
</mapper> </mapper>
\ 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