Commit d7414bf9 authored by 李秀明's avatar 李秀明

消防资源卡片相关接口

parent 79d55e08
package com.yeejoin.equipmanage.common.entity.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "消防资源监管子项DTO", description = "消防资源监管子项DTO")
public class FireResourceStatsDTO {
@ApiModelProperty(value = "资源总数")
private long totalCounts;
@ApiModelProperty(value = "黄码资源数")
private long yellowCounts;
@ApiModelProperty(value = "红码资源数")
private long redCounts;
@ApiModelProperty(value = "异常百分比", notes = "非正常资源数/资源总数, 非正常资源数=黄码资源数+红码资源数")
private Number abnormalRatio;
}
package com.yeejoin.amos.boot.module.jcs.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.common.api.entity.OrgUsr;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
public interface FireResourceSupervisionMapper extends BaseMapper<OrgUsr> {
List<Map<String, Object>> selectPersonnelStats(@Param("bizOrgCode") String bizOrgCode);
Long selectTodayAttendance(@Param("bizOrgCode") String bizOrgCode);
}
package com.yeejoin.amos.boot.module.jcs.api.service;
import java.util.Map;
/**
* 消防资源监管
*/
public interface IFireResourceSupervisionService {
/**
* 获取人员统计信息
*
* @param bizOrgCode 机构编码
*/
Map<String, Map<String, Number>> getPersonnelStats(String bizOrgCode);
}
<?xml version="1.0" encoding="UTF-8"?>
<!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.jcs.api.mapper.FireResourceSupervisionMapper">
<select id="selectPersonnelStats" resultType="java.util.HashMap">
SELECT
IF(dfi.field_value = 1601, 1, IF(dfi.field_value = 1602, 0, -1)) AS peopleType,
COUNT(DISTINCT u.sequence_nbr) AS totalCount,
SUM(IF(ISNULL(cfp.post_qualification), 0, 1)) AS certifiedCount
FROM
cb_org_usr u
INNER JOIN cb_dynamic_form_instance dfi ON dfi.instance_id = u.sequence_nbr AND dfi.field_code = 'peopleType'
LEFT JOIN cb_firefighters_post cfp ON cfp.org_usr_id = u.sequence_nbr AND cfp.is_delete = false
WHERE
u.is_delete = false
AND u.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%')
GROUP BY
peopleType
HAVING peopleType in (0, 1);
</select>
<select id="selectTodayAttendance" resultType="java.lang.Long">
SELECT COUNT(DISTINCT cs.user_id)
FROM cb_sign cs
WHERE cs.date = date_format(now(), '%Y-%m-%d')
AND cs.is_delete = FALSE
AND cs.org_code like concat(#{bizOrgCode}, '%')
</select>
</mapper>
package com.yeejoin.equipmanage.controller;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.equipmanage.common.entity.dto.FireResourceStatsDTO;
import com.yeejoin.equipmanage.service.IFireResourceSupervisionService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
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.HashMap;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping(value = "/fire-resource-superv")
public class FireResourceSupervisionController extends BaseController {
@Autowired
private IFireResourceSupervisionService iFireResourceSupervisionService;
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "消防系统、检测部件、消防车辆统计信息查询", notes = "聚合接口: 消防系统、检测部件、消防车辆统计信息查询")
@RequestMapping(value = "/stats", method = RequestMethod.GET)
public ResponseModel<Object> stats() {
String orgCode = this.getOrgCode();
FireResourceStatsDTO fireSystemStats = iFireResourceSupervisionService.getFireSystemStats(orgCode);
FireResourceStatsDTO monitorComponentStats = iFireResourceSupervisionService.getMonitorComponentStats(orgCode);
FireResourceStatsDTO fireCarStats = iFireResourceSupervisionService.getFireCarStats(orgCode);
Map<String, FireResourceStatsDTO> result = new HashMap<String, FireResourceStatsDTO>() {{
put("fireSystemStats", fireSystemStats);
put("monitorComponentStats", monitorComponentStats);
put("fireCarStats", fireCarStats);
}};
return ResponseHelper.buildResponse(result);
}
}
...@@ -678,4 +678,10 @@ public interface FireFightingSystemMapper extends BaseMapper<FireFightingSystemE ...@@ -678,4 +678,10 @@ public interface FireFightingSystemMapper extends BaseMapper<FireFightingSystemE
List<Map<String, Object>> selectPressureDetails(@Param("bizOrgCode") String bizOrgCode); List<Map<String, Object>> selectPressureDetails(@Param("bizOrgCode") String bizOrgCode);
Map<String, Object> selectEquipmentSpecificById(@Param("id") String id); Map<String, Object> selectEquipmentSpecificById(@Param("id") String id);
Map<String, Object> selectFireFightingSystemStats(@Param("bizOrgCode") String bizOrgCode);
Map<String, Object> selectEquipmentSpecificStats(@Param("bizOrgCode") String bizOrgCode);
Map<String, Object> selectCarStats(@Param("bizOrgCode") String bizOrgCode);
} }
package com.yeejoin.equipmanage.service;
import com.yeejoin.equipmanage.common.entity.dto.FireResourceStatsDTO;
/**
* 消防资源监管
*/
public interface IFireResourceSupervisionService {
/**
* 消防系统信息
* @param bizOrgCode 机构编码
*/
FireResourceStatsDTO getFireSystemStats(String bizOrgCode);
/**
* 监测部件
* @param bizOrgCode 机构编码
*/
FireResourceStatsDTO getMonitorComponentStats(String bizOrgCode);
/**
* 消防车辆
* @param bizOrgCode 机构编码
*/
FireResourceStatsDTO getFireCarStats(String bizOrgCode);
}
package com.yeejoin.equipmanage.service.impl;
import com.yeejoin.equipmanage.common.entity.dto.FireResourceStatsDTO;
import com.yeejoin.equipmanage.mapper.FireFightingSystemMapper;
import com.yeejoin.equipmanage.service.IFireResourceSupervisionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Map;
@Slf4j
@Service
public class IFireResourceSupervisionServiceImpl implements IFireResourceSupervisionService {
@Autowired
private FireFightingSystemMapper fireFightingSystemMapper;
/**
* 消防系统信息
*
* @param bizOrgCode 机构编码
*/
@Override
public FireResourceStatsDTO getFireSystemStats(String bizOrgCode) {
Map<String, Object> resultMap = fireFightingSystemMapper.selectFireFightingSystemStats(bizOrgCode);
return buildFireResourceStatsDTO(resultMap);
}
/**
* 监测部件
*
* @param bizOrgCode 机构编码
*/
@Override
public FireResourceStatsDTO getMonitorComponentStats(String bizOrgCode) {
Map<String, Object> resultMap = fireFightingSystemMapper.selectEquipmentSpecificStats(bizOrgCode);
return buildFireResourceStatsDTO(resultMap);
}
/**
* 消防车辆
*
* @param bizOrgCode 机构编码
*/
@Override
public FireResourceStatsDTO getFireCarStats(String bizOrgCode) {
Map<String, Object> resultMap = fireFightingSystemMapper.selectCarStats(bizOrgCode);
return buildFireResourceStatsDTO(resultMap);
}
private FireResourceStatsDTO buildFireResourceStatsDTO(Map<String, Object> resultMap) {
FireResourceStatsDTO fireResourceStats = new FireResourceStatsDTO();
fireResourceStats.setTotalCounts((long) resultMap.get("totalCount"));
fireResourceStats.setYellowCounts((long) resultMap.get("yellowCodeCount"));
fireResourceStats.setRedCounts((long) resultMap.get("redCodeCount"));
long expCount = fireResourceStats.getYellowCounts() + fireResourceStats.getRedCounts();
double abnormalRatio = 0;
if (fireResourceStats.getTotalCounts() != 0 && expCount != 0) {
abnormalRatio = (double) expCount / fireResourceStats.getTotalCounts() * 100;
}
if (abnormalRatio == 0) {
fireResourceStats.setAbnormalRatio(0);
} else {
DecimalFormat decimalFormat = new DecimalFormat("#.00");
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
String formattedRatio = decimalFormat.format(abnormalRatio);
fireResourceStats.setAbnormalRatio(Double.parseDouble(formattedRatio));
}
return fireResourceStats;
}
}
package com.yeejoin.amos.boot.module.jcs.biz.controller;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.jcs.api.service.IFireResourceSupervisionService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
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.Map;
@Slf4j
@RestController
@RequestMapping("/fire-resource-superv")
public class FireResourceSupervisionController extends BaseController {
@Autowired
private IFireResourceSupervisionService iFireResourceSupervisionService;
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "驻站消防员、运维人员统计信息查询", notes = "驻站消防员、运维人员统计信息查询")
@RequestMapping(value = "/stats", method = RequestMethod.GET)
public ResponseModel<Object> stats() {
String orgCode = this.getOrgCode();
Map<String, Map<String, Number>> personnelStats = iFireResourceSupervisionService.getPersonnelStats(orgCode);
return ResponseHelper.buildResponse(personnelStats);
}
}
package com.yeejoin.amos.boot.module.jcs.biz.service.impl;
import com.yeejoin.amos.boot.module.jcs.api.mapper.FireResourceSupervisionMapper;
import com.yeejoin.amos.boot.module.jcs.api.service.IFireResourceSupervisionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service
public class FireResourceSupervisionServiceImpl implements IFireResourceSupervisionService {
@Autowired
private FireResourceSupervisionMapper fireResourceSupervisionMapper;
/**
* 获取人员统计信息
*
* @param bizOrgCode 机构编码
*/
@Override
public Map<String, Map<String, Number>> getPersonnelStats(String bizOrgCode) {
List<Map<String, Object>> maps = fireResourceSupervisionMapper.selectPersonnelStats(bizOrgCode);
Long attendanceCount = fireResourceSupervisionMapper.selectTodayAttendance(bizOrgCode);
Map<String, Map<String, Number>> result = new HashMap<>();
for (Map<String, Object> map : maps) {
Object peopleType = map.get("peopleType");
if (Objects.isNull(peopleType)) {
continue;
}
long totalCount = Long.parseLong(map.get("totalCount").toString());
long certifiedCount = Long.parseLong(map.get("certifiedCount").toString());
Map<String, Number> stats = getStringNumberMap(certifiedCount, totalCount, attendanceCount);
String key;
switch (peopleType.toString()) {
case "0":
key = "operationStats";
break;
case "1":
key = "fireStats";
break;
default:
continue;
}
result.put(key, stats);
}
return result;
}
private Map<String, Number> getStringNumberMap(long certifiedCount, long totalCount, Long attendanceCount) {
Map<String, Number> stats = new HashMap<>();
stats.put("totalCount", totalCount);
stats.put("certifiedRate", calculateRate(certifiedCount, totalCount));
stats.put("attendanceRate", calculateRate(attendanceCount, totalCount));
stats.put("monthStudyRate", BigDecimal.ZERO);
return stats;
}
private BigDecimal calculateRate(Number numerator, Number denominator) {
BigDecimal rate = new BigDecimal(numerator.toString())
.divide(new BigDecimal(denominator.toString()), 4, RoundingMode.HALF_UP)
.multiply(new BigDecimal(100))
.setScale(2, RoundingMode.HALF_UP);
return rate.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : rate;
}
}
...@@ -5887,4 +5887,37 @@ ...@@ -5887,4 +5887,37 @@
ORDER BY ORDER BY
dat.updateDate DESC dat.updateDate DESC
</select> </select>
<select id="selectFireFightingSystemStats" resultType="java.util.Map">
SELECT
COUNT(*) AS totalCount,
-- COUNT(CASE WHEN ffs.equip_status = '1' THEN 1 END) AS yellowCodeCount,
-- COUNT(CASE WHEN ffs.equip_status = '2' THEN 1 END) AS redCodeCount,
0 AS yellowCodeCount,
0 AS redCodeCount
FROM f_fire_fighting_system ffs
WHERE ffs.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%')
</select>
<select id="selectEquipmentSpecificStats" resultType="java.util.Map">
SELECT
COUNT(*) AS totalCount,
COUNT( CASE WHEN wes.equip_status = '1' THEN 1 END ) AS yellowCodeCount,
COUNT( CASE WHEN wes.equip_status = '2' THEN 1 END ) AS redCodeCount
FROM
wl_equipment_specific wes
WHERE
wes.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%')
</select>
<select id="selectCarStats" resultType="java.util.Map">
SELECT
COUNT(*) AS totalCount,
0 AS yellowCodeCount,
0 AS redCodeCount
FROM
wl_car wc
WHERE
wc.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%')
</select>
</mapper> </mapper>
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