@ -9,9 +9,13 @@ import org.dromara.business.mapper.BusinessAlertMapper;
import org.dromara.business.service.IBusinessAlertStatisticsService ;
import org.dromara.common.satoken.utils.LoginHelper ;
import org.dromara.system.api.RemoteDeptService ;
import org.dromara.system.api.RemoteLabelPostService ;
import org.dromara.system.api.domain.vo.RemoteAiLabelPostVo ;
import org.dromara.system.api.domain.vo.RemoteDeptVo ;
import org.springframework.stereotype.Service ;
import java.math.BigDecimal ;
import java.math.RoundingMode ;
import java.util.* ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
@ -31,6 +35,9 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
@DubboReference
RemoteDeptService remoteDeptService ;
@DubboReference
RemoteLabelPostService remoteLabelPostService ;
/ * *
* 按照月份分类预警数量 ( 包含权限 )
* @param businessAlertBo
@ -44,16 +51,18 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
businessAlertBo . setDeptIdList ( departIdList ) ;
}
businessAlertBo . setAiLabelEnList ( getAiLabel ( businessAlertBo . getPostCode ( ) ) ) ;
List < Map < String , Object > > mapList = baseMapper . listMonthAlert ( businessAlertBo ) ;
return mapList . stream ( ) . map ( data - > new StatObj ( data . get ( "dateMonth" ) + "" , data . get ( "total" ) ) ) . collect ( Collectors . toList ( ) ) ;
}
@Override
public List < StatObj > countDepartAlert ( BusinessAlertBo businessAlertBo ) {
businessAlertBo . setDeptId ( String . valueOf ( LoginHelper . getDeptId ( ) ) ) ;
businessAlertBo . setAiLabelEnList ( getAiLabel ( businessAlertBo . getPostCode ( ) ) ) ;
List < Map < String , Object > > mapList = baseMapper . listDepartAlert ( businessAlertBo ) ;
return mapList . stream ( ) . map ( data - > new StatObj ( data . get ( "deptName" ) + "" , Long . parseLong ( data . get ( "total" ) + "" ) , "deptId" , data . get ( "deptId" ) ) ) . collect ( Collectors . toList ( ) ) ;
@ -61,6 +70,8 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
@Override
public List < StatObj > countMonthAlertStatus ( BusinessAlertBo businessAlertBo ) {
businessAlertBo . setAiLabelEnList ( getAiLabel ( businessAlertBo . getPostCode ( ) ) ) ;
List < Map < String , Object > > mapList = baseMapper . listMonthAlertStatus ( businessAlertBo ) ;
return mapList . stream ( )
@ -79,6 +90,8 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
@Override
public List < StatObj > countDepartAlertStatus ( BusinessAlertBo businessAlertBo ) {
businessAlertBo . setAiLabelEnList ( getAiLabel ( businessAlertBo . getPostCode ( ) ) ) ;
List < Map < String , Object > > mapList = baseMapper . listDepartAlertStatus ( businessAlertBo ) ;
return mapList . stream ( )
@ -102,12 +115,14 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
* /
@Override
public List < Map < String , Object > > countAlertStatusCompare ( BusinessAlertBo businessAlertBo ) {
businessAlertBo . setAiLabelEnList ( getAiLabel ( businessAlertBo . getPostCode ( ) ) ) ;
businessAlertBo . setDateList ( buildDateList ( businessAlertBo ) ) ;
return baseMapper . countAlertCompare ( businessAlertBo ) ;
}
@Override
public List < StatObj > countPanelAlert ( BusinessAlertBo businessAlertBo ) {
businessAlertBo . setAiLabelEnList ( getAiLabel ( businessAlertBo . getPostCode ( ) ) ) ;
List < Map < String , Object > > mapList = baseMapper . countPanelAlert ( businessAlertBo ) ;
return mapList . stream ( )
@ -122,10 +137,30 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
@Override
public List < Map < String , Object > > countAlertTypeCompare ( BusinessAlertBo businessAlertBo ) {
businessAlertBo . setAiLabelEnList ( getAiLabel ( businessAlertBo . getPostCode ( ) ) ) ;
businessAlertBo . setDateList ( buildDateList ( businessAlertBo ) ) ;
return baseMapper . countAlertTypeCompare ( businessAlertBo ) ;
}
@Override
public Double alertRate ( BusinessAlertBo businessAlertBo ) {
List < Map < String , Object > > mapList = baseMapper . countPanelAlert ( businessAlertBo ) ;
double averageDisposalRate = mapList . stream ( )
. mapToDouble ( map - > {
double total = Double . parseDouble ( String . valueOf ( map . get ( "total" ) ) ) ;
double finishCount = Double . parseDouble ( String . valueOf ( map . get ( "finishCount" ) ) ) ;
return ( total = = 0 ) ? 0 . 0 : finishCount / total ;
} )
. average ( ) // 计算平均值
. orElse ( 0 . 0 ) ;
// 四舍五入保留两位小数
BigDecimal roundedAverage = BigDecimal . valueOf ( averageDisposalRate )
. setScale ( 2 , RoundingMode . HALF_UP ) ;
return roundedAverage . doubleValue ( ) ;
}
private List < String > buildDateList ( BusinessAlertBo businessAlertBo ) {
List < String > resultList = new ArrayList < > ( ) ;
String currentYear = String . valueOf ( Calendar . getInstance ( ) . get ( Calendar . YEAR ) ) ;
@ -149,4 +184,8 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
}
return resultList ;
}
private List < String > getAiLabel ( String postCode ) {
return remoteLabelPostService . selectLabelByList ( postCode , LoginHelper . getDeptId ( ) ) . stream ( ) . map ( RemoteAiLabelPostVo : : getLabelEn ) . collect ( Collectors . toList ( ) ) ;
}
}