package com.iden.bms.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.iden.common.entity.*; import com.iden.common.enums.*; import com.iden.common.service.*; import com.iden.common.vo.*; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; /** * * @author makejava * @since 2021-05-21 00:08:38 */ @Service public class WarningStaService { @Resource private IdenWarningStaService idenWarningStaService; public Integer countCommunity(String type,String district, String subdistrict, String communityName, String beginDate, String endDate, UserLoginedConvertVO loginUser) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(IdenWarningSta::getType,type) .like(StrUtil.isNotEmpty(communityName),IdenWarningSta::getCommunityName,communityName) .eq(StrUtil.isNotEmpty(district),IdenWarningSta::getDistrict,district) .eq(StrUtil.isNotEmpty(subdistrict),IdenWarningSta::getSubdistrict,subdistrict) .ge(StrUtil.isNotEmpty(beginDate),IdenWarningSta::getDataDate,beginDate) .le(StrUtil.isNotEmpty(endDate),IdenWarningSta::getDataDate,endDate); queryWrapper.groupBy("community_id"); queryWrapper.select( "community_id communityId", "max(community_code) communityCode", "max(community_name) communityName", "max(district) district", "max(subdistrict) subdistrict", "max(data_date) dataDate", "IFNULL(SUM(total),0) total" ); return this.idenWarningStaService.count(queryWrapper); } /** * 查询预警统计列表 * @return */ public IPage listWarningSta(String type, String district, String subdistrict, String communityName, String beginDate, String endDate, UserLoginedConvertVO loginUser, PageReqVO pageReqVo) { IPage page = new Page<>(pageReqVo.getCurrent(), pageReqVo.getPageSize()); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(IdenWarningSta::getType,type) .like(StrUtil.isNotEmpty(communityName), IdenWarningSta::getCommunityName,communityName) .eq(StrUtil.isNotEmpty(district),IdenWarningSta::getDistrict,district) .eq(StrUtil.isNotEmpty(subdistrict),IdenWarningSta::getSubdistrict,subdistrict) .ge(StrUtil.isNotEmpty(beginDate),IdenWarningSta::getDataDate,beginDate) .le(StrUtil.isNotEmpty(endDate),IdenWarningSta::getDataDate,endDate) .orderByAsc(IdenWarningSta::getId); queryWrapper.groupBy("community_id"); queryWrapper.select( "community_id communityId", "max(community_code) communityCode", "max(community_name) communityName", "max(district) district", "max(subdistrict) subdistrict", "max(data_date) dataDate", "IFNULL(SUM(total),0) total" ); IPage pageRes = this.idenWarningStaService.page(page, queryWrapper); IPage results = new Page<>(pageRes.getCurrent(),pageRes.getSize(),pageRes.getTotal()); if(CollUtil.isNotEmpty(pageRes.getRecords())){ List list = new ArrayList<>(); pageRes.getRecords().forEach(item -> { WarningStaVO resVO = new WarningStaVO(); BeanUtils.copyProperties(item,resVO); resVO.setTypeName(WarningTypeEnum.getValueToName(resVO.getType())); list.add(resVO); }); results.setRecords(list); } return results; } }