@ -38,18 +38,7 @@ public class DmpMonitorNumServiceImpl implements DmpMonitorNumService {
HashMap < String , Object > map = new HashMap < > ( ) ;
List < DmpMonitorJpaDto > mapData = getMapData ( dmpMonitorNumDto , 1 ) ;
HashMap < String , List < DmpMonitorJpaDto > > numMapGroupByTag = new HashMap < > ( 8 ) ;
for ( DmpMonitorJpaDto info : mapData ) {
List < DmpMonitorJpaDto > list = new ArrayList < > ( ) ;
if ( numMapGroupByTag . containsKey ( info . getTag ( ) ) ) {
List < DmpMonitorJpaDto > list1 = numMapGroupByTag . get ( info . getTag ( ) ) ;
list1 . add ( info ) ;
numMapGroupByTag . put ( info . getTag ( ) , list1 ) ;
} else {
List < DmpMonitorJpaDto > list1 = new ArrayList < > ( ) ;
list1 . add ( info ) ;
numMapGroupByTag . put ( info . getTag ( ) , list1 ) ;
}
}
mapData . stream ( ) . collect ( Collectors . groupingBy ( DmpMonitorJpaDto : : getTag , Collectors . toList ( ) ) ) . forEach ( numMapGroupByTag : : put ) ;
for ( String key : dmpMonitorNumDto . getTags ( ) ) {
if ( ! numMapGroupByTag . containsKey ( key ) ) {
numMapGroupByTag . put ( key , new ArrayList < > ( ) ) ;
@ -127,15 +116,22 @@ public class DmpMonitorNumServiceImpl implements DmpMonitorNumService {
return listAll ;
}
//按时间分组
/ * *
* 组 装 数 据 返 回 前 端 , 按 时 间 分 组
*
* @param beginTime
* @param endTime
* @param dto
* @return
* /
private List < HashMap < String , Object > > getGroupByTime ( Date beginTime , Date endTime , List < DmpMonitorJpaDto > dto ) {
List < HashMap < String , Object > > list = new ArrayList < > ( ) ;
int betweenDay = ( int ) DateUtil . between ( beginTime , endTime , DateUnit . DAY ) ;
for ( int i = 0 ; i < = betweenDay ; i + + ) {
HashMap < String , Object > map = new HashMap < > ( ) ;
Date dateTime = DateUtil . offsetDay ( beginTime , i ) ;
String dateTime = DateUtil . format( DateUtil . offsetDay( beginTime , i ) , "yyyy-MM-dd" ) ;
if ( dto . size ( ) > 0 ) {
List < DmpMonitorJpaDto > collect = dto . stream ( ) . filter ( c - > betweenByDay( dateTime , DateUtil . parseDate ( c . getGmtCreate ( ) ) )) . collect ( Collectors . toList ( ) ) ;
List < DmpMonitorJpaDto > collect = dto . stream ( ) . filter ( c - > DateUtil. between ( DateUtil . parseDate ( dateTime ) , DateUtil . parseDate ( c . getGmtCreate ( ) ) , DateUnit . DAY ) = = 0 ) . collect ( Collectors . toList ( ) ) ;
if ( collect . size ( ) > 0 ) {
DmpMonitorJpaDto dmpMonitorJpaDto = collect . get ( 0 ) ;
map . put ( "date" , dateTime ) ;
@ -154,13 +150,6 @@ public class DmpMonitorNumServiceImpl implements DmpMonitorNumService {
return list ;
}
private static Boolean betweenByDay ( Date begin , Date end ) {
begin = DateUtil . parse ( DateUtil . format ( begin , "yyyy-MM-dd" ) ) ;
end = DateUtil . parse ( DateUtil . format ( end , "yyyy-MM-dd" ) ) ;
long between = DateUtil . between ( begin , end , DateUnit . DAY ) ;
return between = = 0 ;
}
@Transactional ( rollbackFor = Exception . class )
public List < DmpMonitorJpaDto > getImeiNumJpa ( String tableName , Date startDate , Date endDate , List < String > tags , Integer flag ) {
String sql = getSqlString ( tableName , flag ) ;
@ -178,7 +167,7 @@ public class DmpMonitorNumServiceImpl implements DmpMonitorNumService {
private String getSqlString ( String tableName , Integer flag ) {
StringBuilder sql = new StringBuilder ( ) ;
if ( 1 = = flag ) {
sql . append ( " select a.tag,a.date as date ,COUNT(*) as num FROM ( SELECT DISTINCT(tb.imei),tb.tag ,DATE_FORMAT( tb.gmt_create, '%Y-%m-%d' ) AS date FROM " + tableName + " as tb where " ) ;
sql . append ( " select a.tag,a.date as date ,COUNT(*) as num FROM ( SELECT DISTINCT(tb.imei),tb.tag ,DATE_FORMAT( tb.gmt_create, '%Y-%m-%d' ) AS date FROM " ) . append ( tableName ) . append ( " as tb where " ) ;
sql . append ( " tb.imei != :imei1 " ) ;
sql . append ( " and tb.imei != :imei2 " ) ;
sql . append ( " and tb.gmt_create >= :startDate " ) ;
@ -186,7 +175,7 @@ public class DmpMonitorNumServiceImpl implements DmpMonitorNumService {
sql . append ( " and tb.tag in :tag " ) ;
sql . append ( " ) a group by a.tag,a.date" ) ;
} else {
sql . append ( "select DISTINCT DATE_FORMAT( tb.gmt_create, '%Y-%m-%d' ) as date ,tb.imei as imei ,tb.tag as tag from " + tableName + " as tb where" ) ;
sql . append ( "select DISTINCT DATE_FORMAT( tb.gmt_create, '%Y-%m-%d' ) as date ,tb.imei as imei ,tb.tag as tag from " ) . append ( tableName ) . append ( " as tb where" ) ;
sql . append ( " tb.imei != :imei1 " ) ;
sql . append ( " and tb.imei != :imei2 " ) ;
sql . append ( " and tb.gmt_create >= :startDate " ) ;