修改首页统计查询条件-liyuchen

This commit is contained in:
李宇辰 2023-04-17 18:08:34 +08:00
parent cfc85721db
commit 742827006e
3 changed files with 22 additions and 11 deletions

View File

@ -59,11 +59,11 @@ public interface DisasterInfoMapper extends BaseMapper<DisasterInfo> {
* 获取灾害数据 关联字典项
* @return
*/
List<DisasterInfo> getAllData();
List<DisasterInfo> getAllData(@Param("chiefId") Long chiefId);
/**
* 查询每个月响应的灾害
* @return
*/
List<Map<String, Object>> getDisasterInfoByMouth(@Param("start") String start,@Param("end") String end,@Param("type") Integer type);
List<Map<String, Object>> getDisasterInfoByMouth(@Param("start") String start,@Param("end") String end,@Param("type") Integer type,@Param("chief") Long chief);
}

View File

@ -205,6 +205,11 @@
bdb.dict_value AS dictValue
from disaster_info di
left join blade_dict_biz bdb on bdb.dict_key = di.disaster_type
<where>
<if test="chiefId != null" >
di.chief_id = #{chiefId}
</if>
</where>
</select>
<select id="getDisasterInfoByMouth" resultType="java.util.Map">
@ -223,6 +228,9 @@
<if test="type == 2">
AND di.respond_status > 1
</if>
<if test="chiefId != null" >
di.chief_id = #{chiefId}
</if>
GROUP BY date
</select>

View File

@ -14,7 +14,9 @@ import com.kening.vordm.vo.*;
import lombok.RequiredArgsConstructor;
import org.springblade.common.cache.CacheNames;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.DigestUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.scheduling.annotation.Async;
@ -192,18 +194,19 @@ public class DisasterInfoServiceImpl extends ServiceImpl<DisasterInfoMapper, Dis
@Override
public Map<String, Object> statistics() {
Map<String,Object> resultMap = Maps.newHashMap();
//查询灾害表全部数据数据tip:暂时没有条件 需要的话后期改
List<DisasterInfo> disasterInfoList = list();
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);
List<Map<String,Object>> applyMonth = getDisasterReponseByMouth(1,isAdmin);
//统计灾害数量占比
Map<String,Long> disasterNum = disasterNumProportion();
Map<String,Long> disasterNum = disasterNumProportion(isAdmin);
//统计当年的灾害响应次数 按月查询
List<Map<String,Object>> responseMonth = getDisasterReponseByMouth(2);
List<Map<String,Object>> responseMonth = getDisasterReponseByMouth(2,isAdmin);
resultMap.put("header",headMap);
resultMap.put("country",countryData);
resultMap.put("disasterNum",disasterNum);
@ -249,8 +252,8 @@ public class DisasterInfoServiceImpl extends ServiceImpl<DisasterInfoMapper, Dis
* 计算每个灾害发生的次数
* @return
*/
private Map<String,Long> disasterNumProportion(){
List<DisasterInfo> disasterInfoList = baseMapper.getAllData();
private Map<String,Long> disasterNumProportion(boolean type){
List<DisasterInfo> disasterInfoList = baseMapper.getAllData(type ? null:AuthUtil.getUserId());
Map<String,Long> proportionMap = disasterInfoList.stream().filter(data->data.getDictValue()!=null).collect(Collectors.groupingBy(DisasterInfo::getDictValue,Collectors.counting()));
return proportionMap;
}
@ -259,7 +262,7 @@ public class DisasterInfoServiceImpl extends ServiceImpl<DisasterInfoMapper, Dis
* 按月统计当年每个月的响应或者申请量
* @return
*/
private List<Map<String, Object>> getDisasterReponseByMouth(Integer type){
private List<Map<String, Object>> getDisasterReponseByMouth(Integer type,boolean isAdmin){
//统计每个月的个数
final String[] MONTH = new String[]{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
int year = LocalDate.now().getYear();
@ -268,7 +271,7 @@ public class DisasterInfoServiceImpl extends ServiceImpl<DisasterInfoMapper, Dis
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<Map<String, Object>> mapList = baseMapper.getDisasterInfoByMouth(start,end,type,isAdmin ? null:AuthUtil.getUserId());
List<DisasterData> disasterList = mapList.stream().map((map) -> {
return cn.hutool.core.bean.BeanUtil.mapToBean(map, DisasterData.class, true);
}).collect(Collectors.toList());