This commit is contained in:
王洪庆 2023-04-24 20:11:57 +08:00
commit cb44e02ef5
5 changed files with 171 additions and 14 deletions

View File

@ -362,8 +362,8 @@ public class DisasterInfoController {
* @return * @return
*/ */
@GetMapping("/statistics") @GetMapping("/statistics")
public R statistics() { public R statistics(String year) {
return R.data(disasterInfoService.statistics()); return R.data(disasterInfoService.statistics(year));
} }
/** /**

View File

@ -68,4 +68,16 @@ public interface DisasterInfoMapper extends BaseMapper<DisasterInfo> {
List<Map<String, Object>> getDisasterInfoByMouth(@Param("start") String start,@Param("end") String end,@Param("type") Integer type,@Param("chiefId") Long chiefId); List<Map<String, Object>> getDisasterInfoByMouth(@Param("start") String start,@Param("end") String end,@Param("type") Integer type,@Param("chiefId") Long chiefId);
void updataUserByEmail(@Param("email") String email,@Param("password") String password); void updataUserByEmail(@Param("email") String email,@Param("password") String password);
List<DisasterInfo> listGetByYear(String year);
List<Map<String, Long>> visitAndDownLoad(String year);
List<Map<String, Long>> initiateAndResponseData(String year);
List<Map<String, Long>> chiefData(String year);
List<Map<String, Long>> adminData(String year);
List<Map<String, Long>> disasterNum(String year);
} }

View File

@ -272,5 +272,105 @@
</if> </if>
GROUP BY date GROUP BY date
</select> </select>
<select id="listGetByYear" resultType="com.kening.vordm.entity.DisasterInfo">
select * from disaster_info t where date_format(t.disaster_time,'%Y') = #{year}
</select>
<select id="visitAndDownLoad" resultType="java.util.Map">
SELECT d.dict_value, SUM(t.visit_count) as visit, SUM(t.download_count) as download FROM disaster_info t INNER JOIN blade_dict_biz d on t.disaster_type = d.dict_key
where date_format(t.disaster_time,'%Y') = #{year} GROUP BY d.dict_value
</select>
<select id="initiateAndResponseData" resultType="java.util.Map">
select d.`key`, sum(d.response) as response, SUM(d.initiate) as initiate from (
SELECT CONCAT(#{year},'-01' ) as `key`, 0 as response ,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-01')
union ALL
SELECT CONCAT(#{year},'-02' ) as `key`, 0 as response ,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-02')
union ALL
SELECT CONCAT(#{year},'-03' ) as `key`, 0 as response ,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-03')
union ALL
SELECT CONCAT(#{year},'-04' ) as `key`, 0 as response ,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-04' )
union ALL
SELECT CONCAT(#{year},'-05') as `key`, 0 as response ,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-05' )
union ALL
SELECT CONCAT(#{year},'-06') as `key`, 0 as response ,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-06')
union ALL
SELECT CONCAT(#{year},'-07') as `key`, 0 as response ,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-07')
union ALL
SELECT CONCAT(#{year},'-08') as `key`, 0 as response ,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-08')
union ALL
SELECT CONCAT(#{year},'-09') as `key`, 0 as response ,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-09')
union ALL
SELECT CONCAT(#{year},'-10') as `key` , 0 as response,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-10')
union ALL
SELECT CONCAT(#{year},'-11') as `key`, 0 as response ,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-11')
union ALL
SELECT CONCAT(#{year},'-12') as `key`, 0 as response ,count(1) as initiate FROM disaster_info t
where date_format(t.disaster_time,'%Y-%m') = CONCAT(#{year},'-12')
union ALL
SELECT CONCAT(#{year},'-01') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-01')
union ALL
SELECT CONCAT(#{year},'-02') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-02')
union ALL
SELECT CONCAT(#{year},'-03') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-03')
union ALL
SELECT CONCAT(#{year},'-04') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-04')
union ALL
SELECT CONCAT(#{year},'-05') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-05')
union ALL
SELECT CONCAT(#{year},'-06') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-06')
union ALL
SELECT CONCAT(#{year},'-07') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-07')
union ALL
SELECT CONCAT(#{year},'-08') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-08')
union ALL
SELECT CONCAT(#{year},'-09') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-09')
union ALL
SELECT CONCAT(#{year},'-10') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-10')
union ALL
SELECT CONCAT(#{year},'-11') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-11')
union ALL
SELECT CONCAT(#{year},'-12') as `key`, count(1) as response ,0 as initiate FROM disaster_info t
where date_format(t.respond_time,'%Y-%m') = CONCAT(#{year},'-12') ) d
GROUP BY d.`key` ORDER BY d.`key`
</select>
<select id="chiefData" resultType="java.util.Map">
SELECT b.`name`, count(*) as val FROM disaster_info t INNER JOIN blade_user b on t.chief_id = b.id
where date_format(t.disaster_time,'%Y') = #{year} GROUP BY b.`name` ORDER BY val desc limit 10
</select>
<select id="adminData" resultType="java.util.Map">
SELECT b.`name`, count(*) as val FROM guest_manage_disaster_ref t INNER JOIN blade_user b on t.manager_id = b.id INNER JOIN disaster_info d on d.id = t.disaster_id
where date_format(d.disaster_time,'%Y') = #{year} and b.role_id = '1123598816738675202' GROUP BY b.`name` ORDER BY val desc limit 10
</select>
<select id="disasterNum" resultType="java.util.Map">
SELECT d.dict_value as `name`, count(1) as val FROM disaster_info t INNER JOIN blade_dict_biz d on t.disaster_type = d.dict_key
where date_format(t.disaster_time,'%Y') = #{year} GROUP BY d.dict_value
</select>
</mapper> </mapper>

View File

@ -61,7 +61,7 @@ public interface DisasterInfoService extends IService<DisasterInfo> {
* 后台管理系统-控制台灾害各项统计 * 后台管理系统-控制台灾害各项统计
* @return * @return
*/ */
Map<String,Object> statistics(); Map<String,Object> statistics(String year);
boolean removeManage(List<DisasterInfo> disasterInfoList); boolean removeManage(List<DisasterInfo> disasterInfoList);

View File

@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -241,29 +242,70 @@ public class DisasterInfoServiceImpl extends ServiceImpl<DisasterInfoMapper, Dis
* @return * @return
*/ */
@Override @Override
public Map<String, Object> statistics() { public Map<String, Object> statistics(String year) {
Map<String,Object> resultMap = Maps.newHashMap(); Map<String,Object> resultMap = Maps.newHashMap();
boolean isAdmin = AuthUtil.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? true : false; //boolean isAdmin = AuthUtil.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? true : false;
//查询灾害表数据 //查询灾害表数据
List<DisasterInfo> disasterInfoList = isAdmin ? list():list(Wrappers.<DisasterInfo>lambdaQuery().eq(DisasterInfo::getChiefId,AuthUtil.getUserId())); List<DisasterInfo> disasterInfoList = this.baseMapper.listGetByYear(year);
//统计head头部的数据 //统计head头部的数据
Map<String,Object> headMap = headData(disasterInfoList); Map<String,Object> headMap = headData(disasterInfoList);
//访问量和下载量
List<Map<String,Long>> visitAndDownLoadData = this.baseMapper.visitAndDownLoad(year);
//响应量和发起量
List<Map<String,Long>> initiateAndResponseData = this.baseMapper.initiateAndResponseData(year);
//统计灾害发生区域占比 //统计灾害发生区域占比
Map<String,Long> countryData = disasterCountryProportion(disasterInfoList); Map<String,Long> countryData = disasterCountryProportion(disasterInfoList);
//统计当年的灾害申请次数 按月查询 //统计当年的灾害申请次数 按月查询
List<Map<String,Object>> applyMonth = getDisasterReponseByMouth(1,isAdmin); //List<Map<String,Object>> applyMonth = getDisasterReponseByMouth(1,isAdmin);
//统计灾害数量占比 //统计灾害数量占比 那个饼图
Map<String,Long> disasterNum = disasterNumProportion(isAdmin); List<Map<String,Long>> disasterNum = this.baseMapper.disasterNum(year);
//统计chief
List<Map<String,Long>> chiefMap = this.baseMapper.chiefData(year);
//统计admin
List<Map<String,Long>> adminfMap = this.baseMapper.adminData(year);
//统计当年的灾害响应次数 按月查询 //统计当年的灾害响应次数 按月查询
List<Map<String,Object>> responseMonth = getDisasterReponseByMouth(2,isAdmin); //List<Map<String,Object>> responseMonth = getDisasterReponseByMouth(2,isAdmin);
resultMap.put("header",headMap); resultMap.put("header",headMap);
//响应量
resultMap.put("line",initiateAndResponseData);
//下载量
resultMap.put("vandd",visitAndDownLoadData);
//admin
resultMap.put("admin",adminfMap);
//chief
resultMap.put("chief",chiefMap);
//国家
resultMap.put("country",countryData); resultMap.put("country",countryData);
//灾害类型分类
resultMap.put("disasterNum",disasterNum); resultMap.put("disasterNum",disasterNum);
resultMap.put("responseMonth",responseMonth);
resultMap.put("applyMonth",applyMonth);
return resultMap; return resultMap;
} }
// @Override
// public Map<String, Object> statistics(String year) {
// Map<String,Object> resultMap = Maps.newHashMap();
// boolean isAdmin = AuthUtil.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? true : false;
// //查询灾害表数据
// List<DisasterInfo> disasterInfoList = isAdmin ? list():list(Wrappers.<DisasterInfo>lambdaQuery().eq(DisasterInfo::getChiefId,AuthUtil.getUserId()));
// //统计head头部的数据
// Map<String,Object> headMap = headData(disasterInfoList);
// //统计灾害发生区域占比
// Map<String,Long> countryData = disasterCountryProportion(disasterInfoList);
// //统计当年的灾害申请次数 按月查询
// List<Map<String,Object>> applyMonth = getDisasterReponseByMouth(1,isAdmin);
// //统计灾害数量占比
// Map<String,Long> disasterNum = disasterNumProportion(isAdmin);
// //统计当年的灾害响应次数 按月查询
// List<Map<String,Object>> responseMonth = getDisasterReponseByMouth(2,isAdmin);
// resultMap.put("header",headMap);
// resultMap.put("country",countryData);
// resultMap.put("disasterNum",disasterNum);
// resultMap.put("responseMonth",responseMonth);
// resultMap.put("applyMonth",applyMonth);
// return resultMap;
// }
/** /**
* 统计head头部信息 * 统计head头部信息
* @return * @return
@ -291,9 +333,12 @@ public class DisasterInfoServiceImpl extends ServiceImpl<DisasterInfoMapper, Dis
* @return * @return
*/ */
private Map<String,Long> disasterCountryProportion(List<DisasterInfo> disasterInfoList){ private Map<String,Long> disasterCountryProportion(List<DisasterInfo> disasterInfoList){
Map<String,Long> proportionMap; Map<String,Long> proportionMap = new LinkedHashMap<>();
//根据国家分组统计次数以及总灾害的占比 //根据国家分组统计次数以及总灾害的占比
proportionMap = disasterInfoList.stream().filter(data->data.getDisasterCountry()!=null).collect(Collectors.groupingBy(DisasterInfo::getDisasterCountry,Collectors.counting())); disasterInfoList.stream().filter(data->
data.getDisasterCountry()!=null
).collect(Collectors.groupingBy(DisasterInfo::getDisasterCountry,Collectors.counting()))
.entrySet().stream().sorted(Map.Entry.<String,Long>comparingByValue().reversed()).limit(15).forEachOrdered(e -> proportionMap.put(e.getKey(), e.getValue()));
return proportionMap; return proportionMap;
} }