提交首页灾害统计代码-liyuchen

This commit is contained in:
李宇辰 2023-04-15 17:09:45 +08:00
parent a8a9141684
commit b8e97e3b94
6 changed files with 179 additions and 0 deletions

View File

@ -0,0 +1,10 @@
package com.kening.vordm.entity;
import lombok.Data;
@Data
public class DisasterData {
private String type;
private Integer value;
private String date;
}

View File

@ -329,4 +329,13 @@ public class DisasterInfoController {
Boolean flag=disasterInfoService.updateById(disasterInfo);
return R.data(flag);
}
/**
* 后台管理系统-控制台灾害各项统计
* @return
*/
@GetMapping("/statistics")
public R statistics(){
return R.data(disasterInfoService.statistics());
}
}

View File

@ -12,6 +12,7 @@ import org.apache.ibatis.annotations.Param;
import org.apache.poi.ss.formula.functions.T;
import java.util.List;
import java.util.Map;
/**
* @author G1393
@ -49,4 +50,16 @@ public interface DisasterInfoMapper extends BaseMapper<DisasterInfo> {
List<GroupByUse> getLeft2Data();
List<CallForHelpVo> page(IPage page,@Param("callForHelpVo" )CallForHelpVo callForHelpVo);
/**
* 获取灾害数据 关联字典项
* @return
*/
List<DisasterInfo> getAllData();
/**
* 查询每个月响应的灾害
* @return
*/
List<Map<String, Object>> getDisasterInfoByMouth(@Param("start") String start,@Param("end") String end,@Param("type") Integer type);
}

View File

@ -158,4 +158,31 @@
</where>
order by d.upload_time desc
</select>
<select id="getAllData" resultType="com.kening.vordm.entity.DisasterInfo">
select
<include refid="Base_Column_List"/>,
bdb.dict_value AS dictValue
from disaster_info di
left join blade_dict_biz bdb on bdb.dict_key = di.disaster_type
</select>
<select id="getDisasterInfoByMouth" resultType="java.util.Map">
SELECT
<if test="type == 1">
date_format(di.disaster_time,'%m') AS date,
</if>
<if test="type == 2">
date_format(di.respond_time,'%m') AS date,
</if>
COUNT(1) AS value
FROM
disaster_info di
WHERE
di.respond_time BETWEEN #{start} AND #{end}
<if test="type == 2">
AND di.respond_status > 1
</if>
GROUP BY date
</select>
</mapper>

View File

@ -10,6 +10,7 @@ import com.kening.vordm.vo.GroupByUse;
import com.kening.vordm.vo.UserTenantVo;
import java.util.List;
import java.util.Map;
/**
* @author G1393
@ -55,4 +56,10 @@ public interface DisasterInfoService extends IService<DisasterInfo> {
Boolean addVisitCount(Long id);
IPage<CallForHelpVo> page(IPage<CallForHelpVo> page, CallForHelpVo callForHelpVo);
/**
* 后台管理系统-控制台灾害各项统计
* @return
*/
Map<String,Object> statistics();
}

View File

@ -3,9 +3,12 @@ package com.kening.vordm.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.kening.vordm.entity.DisasterData;
import com.kening.vordm.entity.DisasterInfo;
import com.kening.vordm.mapper.DisasterInfoMapper;
import com.kening.vordm.service.DisasterInfoService;
import com.kening.vordm.service.GuestManageDisasterRefService;
import com.kening.vordm.vo.CallForHelpVo;
import com.kening.vordm.vo.DisasterMangerInfo;
import com.kening.vordm.vo.GroupByUse;
@ -14,8 +17,12 @@ import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author G1393
@ -27,6 +34,8 @@ import java.util.List;
public class DisasterInfoServiceImpl extends ServiceImpl<DisasterInfoMapper, DisasterInfo>
implements DisasterInfoService {
private final GuestManageDisasterRefService guestManageDisasterRefService;
/**
* 返回指定的灾害条目
* @param type
@ -131,5 +140,109 @@ implements DisasterInfoService {
return page.setRecords(this.baseMapper.page(page,callForHelpVo));
}
/**
* 后台管理系统-控制台灾害各项统计
* @description 暂时没有条件查询 所有统计都暂时写在一个查询里面
* @return
*/
@Override
public Map<String, Object> statistics() {
Map<String,Object> resultMap = Maps.newHashMap();
//查询灾害表全部数据数据tip:暂时没有条件 需要的话后期改
List<DisasterInfo> disasterInfoList = list();
//统计head头部的数据
Map<String,Object> headMap = headData(disasterInfoList);
//统计灾害发生区域占比
Map<String,Long> countryData = disasterCountryProportion(disasterInfoList);
//统计当年的灾害申请次数 按月查询
List<Map<String,Object>> applyMonth = getDisasterReponseByMouth(1);
//统计灾害数量占比
Map<String,Long> disasterNum = disasterNumProportion();
//统计当年的灾害响应次数 按月查询
List<Map<String,Object>> responseMonth = getDisasterReponseByMouth(2);
resultMap.put("header",headMap);
resultMap.put("country",countryData);
resultMap.put("disasterNum",disasterNum);
resultMap.put("responseMonth",responseMonth);
resultMap.put("applyMonth",applyMonth);
return resultMap;
}
/**
* 统计head头部信息
* @return
*/
private Map<String,Object> headData(List<DisasterInfo> disasterInfoList){
Map<String,Object> headMap = Maps.newHashMap();
//用户访问量
Integer visitCount = disasterInfoList.stream().map(DisasterInfo::getVisitCount).reduce(Integer::sum).orElse(0);
//数据下载量
Integer downloadCount = disasterInfoList.stream().map(DisasterInfo::getDownloadCount).reduce(Integer::sum).orElse(0);
//灾害响应申请次数
Integer size = disasterInfoList.size();
//灾害响应实际次数
Long actResponseNum = disasterInfoList.stream().filter(data-> data.getRespondStatus() > 1).count();
//灾害响应百分比
headMap.put("visitCount",visitCount);
headMap.put("downloadCount",downloadCount);
headMap.put("applyCount",size);
headMap.put("actResponseNum",actResponseNum);
return headMap;
}
/**
*计算每个国家的灾害占比
* @return
*/
private Map<String,Long> disasterCountryProportion(List<DisasterInfo> disasterInfoList){
Map<String,Long> proportionMap;
//根据国家分组统计次数以及总灾害的占比
proportionMap = disasterInfoList.stream().collect(Collectors.groupingBy(DisasterInfo::getDisasterCountry,Collectors.counting()));
return proportionMap;
}
/**
* 计算每个灾害发生的次数
* @return
*/
private Map<String,Long> disasterNumProportion(){
List<DisasterInfo> disasterInfoList = baseMapper.getAllData();
Map<String,Long> proportionMap = disasterInfoList.stream().collect(Collectors.groupingBy(DisasterInfo::getDictValue,Collectors.counting()));
return proportionMap;
}
/**
* 按月统计当年每个月的响应或者申请量
* @return
*/
private List<Map<String, Object>> getDisasterReponseByMouth(Integer type){
//统计每个月的个数
final String[] MONTH = new String[]{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
int year = LocalDate.now().getYear();
List<Map<String, Object>> resultList = new ArrayList<>();
//查询开始时间
String start = year + "-01-01 00:00:00";
//查询结束时间
String end = year + 1 + "-01-01 00:00:00";
List<Map<String, Object>> mapList = baseMapper.getDisasterInfoByMouth(start,end,type);
List<DisasterData> disasterList = mapList.stream().map((map) -> {
return cn.hutool.core.bean.BeanUtil.mapToBean(map, DisasterData.class, true);
}).collect(Collectors.toList());
int size = MONTH.length;
Map<String, List<DisasterData>> collect = disasterList.stream().collect(Collectors.groupingBy(DisasterData::getDate));
for (int i = 0; i < size; ++i) {
Map<String, Object> result = Maps.newLinkedHashMap();
String month = MONTH[i];
List<DisasterData> disasterData = collect.get(month);
if (disasterData!=null&&!disasterData.isEmpty()){
DisasterData disasterData1 = disasterData.get(0);
result.put(year+"-"+month,disasterData1);
}else {
result.put(year+"-"+month,null);
}
resultList.add(result);
}
return resultList;
}
}