Commit c6edf1f9 authored by 耿迪迪's avatar 耿迪迪

隐患统计 gengdidi

parent 4420e17c
package com.zehong.web.controller.hiddenDanger;
import java.util.Date;
import java.util.List;
import java.util.Map;
import cn.hutool.core.date.DateUtil;
import com.zehong.common.core.domain.entity.SysUser;
import com.zehong.common.core.domain.model.LoginUser;
import com.zehong.common.utils.ServletUtils;
import com.zehong.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
......@@ -121,4 +117,23 @@ public class TStaningBookController extends BaseController
public AjaxResult statics(String type){
return AjaxResult.success(tStaningBookService.statics(type));
}
/**
* 隐患统计图
* @param troubleLevel 隐患等级
* @param beginTime 开始时间
* @param endTime 结束时间
* @return Map
*/
@GetMapping(value = "/hiddenStat")
public AjaxResult hiddenStat(@RequestParam(value="troubleLevel",required=false) Integer troubleLevel,
@RequestParam(value="beginTime",required=false)Date beginTime,
@RequestParam(value="endTime",required=false)Date endTime){
if(null == beginTime && null == endTime){
beginTime = DateUtil.beginOfYear(new Date());
endTime = DateUtil.endOfYear(new Date());
}
return AjaxResult.success(tStaningBookService.hiddenStat(troubleLevel,beginTime,endTime));
}
}
package com.zehong.system.domain.vo;
public class HiddenStatVO {
/**
* 隐患发现月份
*/
private int month;
/**
* 发现隐患数量
*/
private int hiddenCount;
/**
* 整改数量
*/
private int rectifiedCount;
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getHiddenCount() {
return hiddenCount;
}
public void setHiddenCount(int hiddenCount) {
this.hiddenCount = hiddenCount;
}
public int getRectifiedCount() {
return rectifiedCount;
}
public void setRectifiedCount(int rectifiedCount) {
this.rectifiedCount = rectifiedCount;
}
}
package com.zehong.system.mapper;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.zehong.system.domain.TStaningBook;
import com.zehong.system.domain.vo.HiddenStatVO;
import org.apache.ibatis.annotations.Param;
/**
* 隐患台账Mapper接口
......@@ -62,4 +65,22 @@ public interface TStaningBookMapper
public int deleteTStaningBookByIds(Long[] bookIds);
public Map statics(String type);
/**
* 隐患统计柱状图
* @param troubleLevel 隐患等级
* @param beginTime 开始时间
* @param endTime 结束时间
* @return List<HiddenStatVO>
*/
List<HiddenStatVO> hiddenBarStat(@Param(value = "troubleLevel")Integer troubleLevel, @Param(value = "beginTime")Date beginTime, @Param(value = "endTime")Date endTime);
/**
* 隐患统计环状图
* @param troubleLevel 隐患等级
* @param beginTime 开始时间
* @param endTime 结束时间
* @return
*/
Map<String,Integer> hiddenPieStat(@Param(value = "troubleLevel")Integer troubleLevel, @Param(value = "beginTime")Date beginTime, @Param(value = "endTime")Date endTime);
}
package com.zehong.system.service;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -67,4 +68,13 @@ public interface ITStaningBookService
* @return
*/
public Map statics(String type);
/**
* 隐患统计图
* @param troubleLevel 隐患等级
* @param beginTime 开始时间
* @param endTime 结束时间
* @return Map
*/
Map<String,List> hiddenStat(Integer troubleLevel, Date beginTime, Date endTime);
}
package com.zehong.system.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.math.BigDecimal;
import java.util.*;
import com.zehong.common.core.domain.entity.SysDept;
import com.zehong.common.utils.DateUtils;
import com.zehong.system.domain.THiddenTroubleWork;
import com.zehong.system.domain.vo.HiddenStatVO;
import com.zehong.system.mapper.SysDeptMapper;
import com.zehong.system.mapper.THiddenTroubleWorkMapper;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -120,4 +120,66 @@ public class TStaningBookServiceImpl implements ITStaningBookService
public Map statics(String type) {
return tStaningBookMapper.statics(type);
}
@Override
public Map<String,List> hiddenStat(Integer troubleLevel, Date beginTime, Date endTime){
Map<String,List> result = new HashMap<>(16);
List<HiddenStatVO> barData = tStaningBookMapper.hiddenBarStat(troubleLevel,beginTime,endTime);
//柱状图月份数据
List<String> months = new ArrayList<>();
//柱状图隐患数量
List<Integer> hiddens = new ArrayList<>();
//柱状图整改数量
List<Integer> rectifieds = new ArrayList<>();
for(HiddenStatVO hidden : barData){
months.add(changeMonth(hidden.getMonth()));
hiddens.add(hidden.getHiddenCount());
rectifieds.add(hidden.getRectifiedCount());
}
result.put("months",months);
result.put("hiddens",hiddens);
result.put("rectifieds",rectifieds);
//环状统计图
Map<String,Integer> pieData = tStaningBookMapper.hiddenPieStat(troubleLevel,beginTime,endTime);
List<Map<String,Object>> pieResult = new ArrayList<>();
Map<String,Object> rectifiedMap = new HashMap<>(16);
rectifiedMap.put("name","已整改");
rectifiedMap.put("value",pieData.get("rectifiedCount"));
pieResult.add(rectifiedMap);
Map<String,Object> stayRectifiedMap = new HashMap<>(16);
stayRectifiedMap.put("name","未整改");
stayRectifiedMap.put("value",pieData.get("stayRectifiedCount"));
pieResult.add(stayRectifiedMap);
result.put("pieData",pieResult);
return result;
}
private String changeMonth(int month){
switch (month){
case 1:
return "一月";
case 2:
return "二月";
case 3:
return "三月";
case 4:
return "四月";
case 5:
return "五月";
case 6:
return "六月";
case 7:
return "七月";
case 8:
return "八月";
case 9:
return "九月";
case 10:
return "十月";
case 11:
return "十一月";
default:
return "十二月";
}
}
}
......@@ -197,4 +197,38 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and DATE_SUB(now(), INTERVAL 365 DAY) &lt; date(find_time)
</if>
</select>
<select id="hiddenBarStat" resultType="HiddenStatVO">
SELECT
IFNULL(MONTH(find_time),0) AS month,
IFNULL(count(1),0) hiddenCount,
IFNULL(sum(CASE state WHEN '2' THEN 1 ELSE 0 END),0) AS rectifiedCount
FROM
t_staning_book
WHERE
is_del = 0
<if test="beginTime != null and endTime != null">
AND find_time BETWEEN #{ beginTime } AND #{ endTime }
</if>
<if test="troubleLevel != null and troubleLevel != ''">
AND trouble_level = #{troubleLevel}
</if>
GROUP BY MONTH(find_time)
</select>
<select id="hiddenPieStat" resultType="java.util.Map">
SELECT
IFNULL(sum(CASE state WHEN '2' THEN 1 ELSE 0 END),0) AS rectifiedCount,
IFNULL(sum(IF(IFNULL(state,'-1') != '2',1,0)),0) AS stayRectifiedCount
FROM
t_staning_book
WHERE
is_del = 0
<if test="beginTime != null and endTime != null">
AND find_time BETWEEN #{ beginTime } AND #{ endTime }
</if>
<if test="troubleLevel != null and troubleLevel != ''">
AND trouble_level = #{troubleLevel}
</if>
</select>
</mapper>
......@@ -51,3 +51,12 @@ export function exportBook(query) {
params: query
})
}
//隐患统计图
export function hiddenStat(query) {
return request({
url: '/system/book/hiddenStat',
method: 'get',
params: query
})
}
<template>
<div class="hiddenStat">
<el-form :model="queryParams" :inline="true" label-width="100px" style="margin-top: 10px">
<el-form-item label="隐患级别" prop="hiddenLevel">
<el-select v-model="queryParams.troubleLevel" placeholder="请选择隐患级别">
<el-option
v-for="dict in troubleLevelOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="parseInt(dict.dictValue)"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="隐患发现时间" prop="hiddenTime">
<el-date-picker
v-model="findTime"
value-format="yyyy-MM-dd HH:mm:ss"
type="datetimerange"
range-separator="至"
start-placeholder="开始时间"
end-placeholder="结束时间"
@change="dateFormat">
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="search">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<div class="stat">
<div id="barChar" :style="{width: '50%', height: '100%'}"></div>
<div id="pieChar" :style="{width: '50%', height: '100%'}"></div>
</div>
</div>
</template>
<script>
import { hiddenStat } from "@/api/system/book";
export default {
name: "index",
data(){
return{
queryParams:{
hiddenLevel: null,
beginTime: null,
endTime: null
},
monthData: [],
hiddenBarData: [],
closeHiddenBarData: [],
pieData: [],
troubleLevelOptions: [],
findTime: ""
}
},
mounted(){
this.getHiddenData();
this.getDicts("t_trouble_level").then(response => {
this.troubleLevelOptions = response.data;
});
},
methods:{
//初始化柱状图
initBarEchars(){
let echar = this.$echarts.init(document.getElementById('barChar'));
let option = {
title: {
text: "隐患数量统计",
left: "20"
},
legend: {
type: "plain",
align: "left",
right: "50"
},
xAxis: {
type: 'category',
//data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
data: this.monthData
},
yAxis: {
type: 'value'
},
series: [
{
name: '发现数量',
type: 'bar',
//data: [120, 200, 150, 80, 70, 110, 130],
data: this.hiddenBarData
},
{
name: '闭环数量',
type: 'bar',
data: this.closeHiddenBarData,
/*itemStyle: {
color: "rgba(0, 30, 255, 1)"
}*/
},
]
}
echar.setOption(option);
},
//初始化环状图
initPieEchars(){
let echar = this.$echarts.init(document.getElementById('pieChar'));
let option = {
title: {
text: "隐患整改率",
left: "20"
},
tooltip: {
trigger: 'item',
formatter: '{b}:{c} ({d}%)'
},
legend: {
type: "plain",
align: "left",
right: "50"
},
series: [
{
name: 'gun',
type: 'pie',
radius: ['40%', '70%'],
/*data: [
{ value: 50, name: '已整改' },
{ value: 50, name: '未整改' }
],*/
data: this.pieData
}
]
}
echar.setOption(option);
},
getHiddenData(){
hiddenStat(this.queryParams).then(res =>{
if(res.code = 200){
this.monthData = res.data.months;
this.hiddenBarData = res.data.hiddens;
this.closeHiddenBarData = res.data.rectifieds;
this.pieData = res.data.pieData;
//柱状图初始化
this.initBarEchars();
//环状图初始化
this.initPieEchars();
}
})
},
dateFormat(picker){
this.queryParams.beginTime = picker[0];
this.queryParams.endTime = picker[1];
},
search(){
this.getHiddenData();
},
resetQuery(){
this.reset();
this.getHiddenData();
},
reset(){
this.queryParams = {
hiddenLevel: null,
beginTime: null,
endTime: null
};
this.findTime = "";
}
}
}
</script>
<style scoped lang="scss">
.hiddenStat{
height: calc(100vh - 50px);
width: 100%;
}
.stat{
height: 90%;
width: 100%;
display: inline-flex;
}
</style>
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