@ -1,6 +1,8 @@
package com.epmet.service.impl ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.epmet.commons.tools.constant.NumConstant ;
import com.epmet.commons.tools.constant.StrConstant ;
import com.epmet.constant.IcResiCategoryStatsConfigConstant ;
import com.epmet.dao.IcFormItemDao ;
import com.epmet.dao.IcFormItemGroupDao ;
@ -59,11 +61,13 @@ public class ResiCategoryStatsConfigServiceImpl implements ResiCategoryStatsConf
if ( ! CollectionUtils . isEmpty ( groupIds ) ) {
icFormItemGroupEntityList . addAll ( icFormItemGroupDao . selectList ( new QueryWrapper < IcFormItemGroupEntity > ( ) . lambda ( ) . eq ( IcFormItemGroupEntity : : getCustomerId , customerId ) . in ( IcFormItemGroupEntity : : getId , groupIds ) ) ) ;
}
//获取tableName和COLUMN_NAME
Map < String , IcFormItemEntity > tableColumnMap = new HashMap < > ( ) ;
Map < String , String > idTableMap = new HashMap < > ( ) ;
icFormItemEntityList . forEach ( item - > {
Map < String , String > map = new HashMap < > ( ) ;
item . setColumnName ( item . getColumnName ( ) . concat ( NumConstant . ZERO = = item . getColumnNum ( ) ? StrConstant . EPMETY_STR : item . getColumnNum ( ) . toString ( ) ) ) ;
if ( "0" . equals ( item . getItemGroupId ( ) ) ) {
tableColumnMap . put ( IcResiCategoryStatsConfigConstant . IC_RESI_USER + "-" + item . getColumnName ( ) , item ) ;
idTableMap . put ( item . getId ( ) , IcResiCategoryStatsConfigConstant . IC_RESI_USER ) ;
@ -110,7 +114,22 @@ public class ResiCategoryStatsConfigServiceImpl implements ResiCategoryStatsConf
if ( ! CollectionUtils . isEmpty ( newStatsEntityList ) ) {
icResiCategoryStatsConfigService . insertBatch ( newStatsEntityList ) ;
}
List < String > newWarnList = tableColumnMap . keySet ( ) . stream ( ) . filter ( item - > ! warnTableColumnMap . containsKey ( item ) ) . collect ( Collectors . toList ( ) ) ;
List < IcResiCategoryWarnConfigEntity > newWarnEntityList = new ArrayList < > ( ) ;
newWarnList . forEach ( item - > {
IcFormItemEntity icFormItemEntity = tableColumnMap . get ( item ) ;
IcResiCategoryWarnConfigEntity entity = new IcResiCategoryWarnConfigEntity ( ) ;
entity . setCustomerId ( customerId ) ;
entity . setLabel ( icFormItemEntity . getLabel ( ) ) ;
entity . setTableName ( idTableMap . get ( icFormItemEntity . getId ( ) ) ) ;
entity . setColumnName ( icFormItemEntity . getColumnName ( ) ) ;
entity . setWarn ( "0" ) ;
entity . setSort ( icFormItemEntity . getSort ( ) ) ;
newWarnEntityList . add ( entity ) ;
} ) ;
if ( ! CollectionUtils . isEmpty ( newWarnEntityList ) ) {
icResiCategoryWarnConfigService . insertBatch ( newWarnEntityList ) ;
}
List < String > delStatsEntityIdList = new ArrayList < > ( ) ;
List < String > delWarnEntityIdList = new ArrayList < > ( ) ;
//需要删除的
@ -130,90 +149,16 @@ public class ResiCategoryStatsConfigServiceImpl implements ResiCategoryStatsConf
}
//4.返回数据
List < IcResiCategoryStatsConfigEntity > statsConfigList = icResiCategoryStatsConfigDao . selectList ( new QueryWrapper < IcResiCategoryStatsConfigEntity > ( ) . lambda ( )
. eq ( IcResiCategoryStatsConfigEntity : : getCustomerId , customerId )
. orderByAsc ( IcResiCategoryStatsConfigEntity : : getSort ) ) ;
List < IcResiCategoryWarnConfigEntity > warnConfigList = icResiCategoryWarnConfigDao . selectList ( new QueryWrapper < IcResiCategoryWarnConfigEntity > ( ) . lambda ( )
. eq ( IcResiCategoryWarnConfigEntity : : getCustomerId , customerId ) ) ;
Map < String , IcResiCategoryWarnConfigEntity > warnMap = new HashMap < > ( ) ;
warnConfigList . forEach ( item - > {
warnMap . put ( item . getTableName ( ) + "-" + item . getColumnName ( ) , item ) ;
} ) ;
List < IcResiCategoryStatsConfigResultDTO > result = new ArrayList < > ( ) ;
statsConfigList . forEach ( item - > {
IcResiCategoryStatsConfigResultDTO icResiCategoryStatsConfigResultDTO = new IcResiCategoryStatsConfigResultDTO ( ) ;
icResiCategoryStatsConfigResultDTO . setId ( item . getId ( ) ) ;
icResiCategoryStatsConfigResultDTO . setLabel ( item . getLabel ( ) ) ;
icResiCategoryStatsConfigResultDTO . setManagementIcon ( item . getManagementIcon ( ) ) ;
icResiCategoryStatsConfigResultDTO . setDataIcon ( item . getDataIcon ( ) ) ;
icResiCategoryStatsConfigResultDTO . setHouseShowIcon ( item . getHouseShowIcon ( ) ) ;
icResiCategoryStatsConfigResultDTO . setStatus ( item . getStatus ( ) ) ;
icResiCategoryStatsConfigResultDTO . setSort ( item . getSort ( ) ) ;
IcResiCategoryWarnConfigEntity warnConfigEntity = warnMap . get ( item . getTableName ( ) + "-" + item . getColumnName ( ) ) ;
if ( warnConfigEntity = = null ) {
icResiCategoryStatsConfigResultDTO . setWarn ( IcResiCategoryStatsConfigConstant . WARN_NO ) ;
} else {
icResiCategoryStatsConfigResultDTO . setWarn ( IcResiCategoryStatsConfigConstant . WARN_YES ) ;
icResiCategoryStatsConfigResultDTO . setLevel1 ( warnConfigEntity . getLevel1 ( ) ) ;
icResiCategoryStatsConfigResultDTO . setLevel2 ( warnConfigEntity . getLevel2 ( ) ) ;
icResiCategoryStatsConfigResultDTO . setLevel3 ( warnConfigEntity . getLevel3 ( ) ) ;
}
result . add ( icResiCategoryStatsConfigResultDTO ) ;
List < IcResiCategoryStatsConfigResultDTO > result = icResiCategoryStatsConfigDao . listInfo ( customerId , formDTO . getIsWarn ( ) , formDTO . getLevel ( ) ) ;
} ) ;
if ( null = = formDTO ) {
return result ;
}
List < IcResiCategoryStatsConfigResultDTO > collect = new ArrayList < > ( ) ;
for ( IcResiCategoryStatsConfigResultDTO item : result ) {
String isWarn = String . valueOf ( formDTO . getIsWarn ( ) ) ;
if ( null ! = formDTO . getIsWarn ( ) & & ( ! item . getWarn ( ) . equals ( isWarn ) ) ) {
continue ;
}
if ( null ! = formDTO . getLevel ( ) ) {
if ( 1 = = formDTO . getLevel ( ) & & null = = item . getLevel1 ( ) ) {
continue ;
}
if ( 2 = = formDTO . getLevel ( ) & & null = = item . getLevel2 ( ) ) {
continue ;
}
}
collect . add ( item ) ;
}
return collect ;
return result ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public IcResiCategoryStatsConfigResultDTO info ( String id ) {
public IcResiCategoryStatsConfigResultDTO info ( String id , String customerId ) {
IcResiCategoryStatsConfigResultDTO result = new IcResiCategoryStatsConfigResultDTO ( ) ;
IcResiCategoryStatsConfigDTO icResiCategoryStatsConfigDTO = icResiCategoryStatsConfigService . get ( id ) ;
if ( null = = icResiCategoryStatsConfigDTO ) {
return result ;
}
IcResiCategoryWarnConfigEntity icResiCategoryWarnConfigEntity = icResiCategoryWarnConfigDao . selectOne ( new QueryWrapper < IcResiCategoryWarnConfigEntity > ( ) . lambda ( )
. eq ( IcResiCategoryWarnConfigEntity : : getCustomerId , icResiCategoryStatsConfigDTO . getCustomerId ( ) )
. eq ( IcResiCategoryWarnConfigEntity : : getTableName , icResiCategoryStatsConfigDTO . getTableName ( ) )
. eq ( IcResiCategoryWarnConfigEntity : : getColumnName , icResiCategoryStatsConfigDTO . getColumnName ( ) ) ) ;
// IcResiCategoryWarnConfigEntity icResiCategoryWarnConfigEntity = Optional.ofNullable(entity).orElse(new IcResiCategoryWarnConfigEntity());
result . setId ( icResiCategoryStatsConfigDTO . getId ( ) ) ;
result . setLabel ( icResiCategoryStatsConfigDTO . getLabel ( ) ) ;
result . setManagementIcon ( icResiCategoryStatsConfigDTO . getManagementIcon ( ) ) ;
result . setDataIcon ( icResiCategoryStatsConfigDTO . getDataIcon ( ) ) ;
result . setHouseShowIcon ( icResiCategoryStatsConfigDTO . getHouseShowIcon ( ) ) ;
result . setStatus ( icResiCategoryStatsConfigDTO . getStatus ( ) ) ;
result . setSort ( icResiCategoryStatsConfigDTO . getSort ( ) ) ;
result . setWarn ( null = = icResiCategoryWarnConfigEntity ? IcResiCategoryStatsConfigConstant . WARN_NO : IcResiCategoryStatsConfigConstant . WARN_YES ) ;
if ( null ! = icResiCategoryWarnConfigEntity ) {
result . setLevel1 ( icResiCategoryWarnConfigEntity . getLevel1 ( ) ) ;
result . setLevel2 ( icResiCategoryWarnConfigEntity . getLevel2 ( ) ) ;
result . setLevel3 ( icResiCategoryWarnConfigEntity . getLevel3 ( ) ) ;
}
return result ;
return icResiCategoryStatsConfigDao . info ( id , customerId ) ;
}
@Override
@ -231,42 +176,16 @@ public class ResiCategoryStatsConfigServiceImpl implements ResiCategoryStatsConf
icResiCategoryStatsConfigDao . updateById ( icResiCategoryStatsConfigEntity ) ;
//更新配置预警
if ( IcResiCategoryStatsConfigConstant . WARN_YES . equals ( formDTO . getWarn ( ) ) ) {
//更新
IcResiCategoryWarnConfigEntity icResiCategoryWarnConfigEntity = icResiCategoryWarnConfigDao . selectOne ( new QueryWrapper < IcResiCategoryWarnConfigEntity > ( ) . lambda ( )
. eq ( IcResiCategoryWarnConfigEntity : : getCustomerId , customerId )
. eq ( IcResiCategoryWarnConfigEntity : : getTableName , icResiCategoryStatsConfigDTO . getTableName ( ) )
. eq ( IcResiCategoryWarnConfigEntity : : getColumnName , icResiCategoryStatsConfigDTO . getColumnName ( ) ) ) ;
if ( null = = icResiCategoryWarnConfigEntity ) {
icResiCategoryWarnConfigEntity = new IcResiCategoryWarnConfigEntity ( ) ;
icResiCategoryWarnConfigEntity . setCustomerId ( customerId ) ;
icResiCategoryWarnConfigEntity . setLabel ( icResiCategoryStatsConfigDTO . getLabel ( ) ) ;
icResiCategoryWarnConfigEntity . setTableName ( icResiCategoryStatsConfigDTO . getTableName ( ) ) ;
icResiCategoryWarnConfigEntity . setColumnName ( icResiCategoryStatsConfigDTO . getColumnName ( ) ) ;
icResiCategoryWarnConfigEntity . setLevel1 ( formDTO . getLevel1 ( ) ) ;
icResiCategoryWarnConfigEntity . setLevel2 ( formDTO . getLevel2 ( ) ) ;
icResiCategoryWarnConfigEntity . setLevel3 ( formDTO . getLevel3 ( ) ) ;
icResiCategoryWarnConfigEntity . setSort ( icResiCategoryStatsConfigDTO . getSort ( ) ) ;
icResiCategoryWarnConfigDao . insert ( icResiCategoryWarnConfigEntity ) ;
} else {
// icResiCategoryWarnConfigEntity.setCustomerId(customerId);
icResiCategoryWarnConfigEntity . setLabel ( icResiCategoryStatsConfigDTO . getLabel ( ) ) ;
icResiCategoryWarnConfigEntity . setTableName ( icResiCategoryStatsConfigDTO . getTableName ( ) ) ;
icResiCategoryWarnConfigEntity . setColumnName ( icResiCategoryStatsConfigDTO . getColumnName ( ) ) ;
icResiCategoryWarnConfigEntity . setLevel1 ( formDTO . getLevel1 ( ) ) ;
icResiCategoryWarnConfigEntity . setLevel2 ( formDTO . getLevel2 ( ) ) ;
icResiCategoryWarnConfigEntity . setLevel3 ( formDTO . getLevel3 ( ) ) ;
icResiCategoryWarnConfigEntity . setSort ( icResiCategoryStatsConfigDTO . getSort ( ) ) ;
icResiCategoryWarnConfigDao . updateById ( icResiCategoryWarnConfigEntity ) ;
}
} else if ( IcResiCategoryStatsConfigConstant . WARN_NO . equals ( formDTO . getWarn ( ) ) ) {
//删除
icResiCategoryWarnConfigDao . delete ( new QueryWrapper < IcResiCategoryWarnConfigEntity > ( ) . lambda ( )
. eq ( IcResiCategoryWarnConfigEntity : : getCustomerId , customerId )
. eq ( IcResiCategoryWarnConfigEntity : : getTableName , icResiCategoryStatsConfigDTO . getTableName ( ) )
. eq ( IcResiCategoryWarnConfigEntity : : getColumnName , icResiCategoryStatsConfigDTO . getColumnName ( ) ) ) ;
}
//更新
IcResiCategoryWarnConfigEntity icResiCategoryWarnConfigEntity = icResiCategoryWarnConfigDao . selectOne ( new QueryWrapper < IcResiCategoryWarnConfigEntity > ( ) . lambda ( )
. eq ( IcResiCategoryWarnConfigEntity : : getCustomerId , customerId )
. eq ( IcResiCategoryWarnConfigEntity : : getTableName , icResiCategoryStatsConfigDTO . getTableName ( ) )
. eq ( IcResiCategoryWarnConfigEntity : : getColumnName , icResiCategoryStatsConfigDTO . getColumnName ( ) ) ) ;
icResiCategoryWarnConfigEntity . setWarn ( formDTO . getWarn ( ) ) ;
icResiCategoryWarnConfigEntity . setLevel1 ( formDTO . getLevel1 ( ) ) ;
icResiCategoryWarnConfigEntity . setLevel2 ( formDTO . getLevel2 ( ) ) ;
icResiCategoryWarnConfigEntity . setLevel3 ( formDTO . getLevel3 ( ) ) ;
icResiCategoryWarnConfigDao . updateById ( icResiCategoryWarnConfigEntity ) ;
}