@ -2,19 +2,28 @@
package org.springblade.lims.service.impl ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import lombok.AllArgsConstructor ;
import org.apache.commons.collections4.CollectionUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.commons.lang3.time.DateFormatUtils ;
import org.apache.commons.lang3.time.DateUtils ;
import org.springblade.core.mp.support.Query ;
import org.springblade.lims.entry.CarbonEmissionPlan ;
import org.springblade.lims.entry.Instrument ;
import org.springblade.lims.entry.LargeScreenVO ;
import org.springblade.lims.mapper.LargeScreenMapper ;
import org.springblade.lims.service.ICarbonEmissionPlanService ;
import org.springblade.lims.service.IInstrumentService ;
import org.springblade.lims.service.ILargeScreenService ;
import org.springblade.lims.tools.RedisUtil ;
import org.springframework.stereotype.Service ;
import java.text.ParseException ;
import java.time.YearMonth ;
import java.util.* ;
import java.util.stream.Collectors ;
/ * *
@ -25,6 +34,9 @@ import java.util.stream.Collectors;
@AllArgsConstructor
public class LargeScreenServiceImpl implements ILargeScreenService {
private final LargeScreenMapper largeScreenMapper ;
private final IInstrumentService instrumentService ;
private final RedisUtil redisUtil ;
private final ICarbonEmissionPlanService carbonEmissionPlanService ;
@Override
public Map < String , Double > getTotalElectricity ( String manufacturerBrand ) {
@ -69,14 +81,17 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
Map < String , Map < String , Double > > map = new HashMap < > ( ) ;
try {
String lastMonth = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( entity . getCurrentMonth ( ) , "yyyy-MM" ) , - 1 ) , "yyyy-MM" ) ;
//初始化每月电量数据
Map < String , Double > currentMap = initMonthData ( entity . getCurrentMonth ( ) ) ;
Map < String , Double > lastMap = initMonthData ( lastMonth ) ;
//查询本月电量
List < LargeScreenVO > currentList = largeScreenMapper . getDayElectricity ( entity ) ;
if ( CollectionUtils . isNotEmpty ( currentList ) ) {
currentList . forEach ( largeScreenVO - > {
currentMap . put ( largeScreenVO . getDate ( ) , largeScreenVO . getTotalElectricity ( ) ) ;
} ) ;
}
//查询上月电量
entity . setCurrentMonth ( lastMonth ) ;
List < LargeScreenVO > lastList = largeScreenMapper . getDayElectricity ( entity ) ;
if ( CollectionUtils . isNotEmpty ( lastList ) ) {
@ -104,6 +119,38 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
@Override
public List < LargeScreenVO > getPeriodElectricity ( LargeScreenVO entity ) {
/ * List < TimeVO > jianList = new ArrayList < > ( ) ;
List < TimeVO > fengList = new ArrayList < > ( ) ;
List < TimeVO > pingList = new ArrayList < > ( ) ;
List < TimeVO > guList = new ArrayList < > ( ) ;
List < Dict > dictlist = DictCache . getList ( "electricity_period" ) ;
for ( Dict dict : dictlist ) {
List < String > timeList1 = Arrays . asList ( dict . getDictKey ( ) . split ( "," ) ) ;
timeList1 . forEach ( s - > {
String [ ] times = s . split ( "-" ) ;
TimeVO timeVO = new TimeVO ( ) ;
timeVO . setStartTime ( entity . getToday ( ) + " " + times [ 0 ] ) ;
timeVO . setEndTime ( entity . getToday ( ) + " " + times [ 1 ] ) ;
if ( dict . getDictValue ( ) . equals ( "尖" ) ) {
jianList . add ( timeVO ) ;
}
if ( dict . getDictValue ( ) . equals ( "峰" ) ) {
fengList . add ( timeVO ) ;
}
if ( dict . getDictValue ( ) . equals ( "平" ) ) {
pingList . add ( timeVO ) ;
}
if ( dict . getDictValue ( ) . equals ( "谷" ) ) {
guList . add ( timeVO ) ;
}
} ) ;
}
entity . setJianList ( jianList ) ;
entity . setFengList ( fengList ) ;
entity . setPingList ( pingList ) ;
entity . setGuList ( guList ) ; * /
return largeScreenMapper . getPeriodElectricity ( entity ) ;
}
@ -118,53 +165,82 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
}
@Override
public Map < String , Map < String , Integer > > getInstrumentDaylyLoad ( LargeScreenVO entity ) {
List < LargeScreenVO > list = largeScreenMapper . getInstrumentDaylyLoad ( entity ) ;
Map < String , Map < String , Integer > > map = new HashMap < > ( ) ;
if ( CollectionUtils . isNotEmpty ( list ) ) {
List < String > nameList = list . stream ( ) . map ( LargeScreenVO : : getName ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
nameList . forEach ( s - > {
Map < String , Integer > map1 = new HashMap < > ( ) ;
map1 . put ( "空载" , 0 ) ;
map1 . put ( "轻载" , 0 ) ;
map1 . put ( "正常" , 0 ) ;
map1 . put ( "过载" , 0 ) ;
map1 . put ( "重载" , 0 ) ;
map . put ( s , map1 ) ;
} ) ;
for ( LargeScreenVO largeScreenVO : list ) {
Map < String , Integer > map1 = map . get ( largeScreenVO . getName ( ) ) ;
if ( map1 . containsKey ( largeScreenVO . getLoadLevel ( ) ) ) {
map1 . put ( largeScreenVO . getLoadLevel ( ) , largeScreenVO . getCount ( ) ) ;
}
}
for ( Map . Entry < String , Map < String , Integer > > entry : map . entrySet ( ) ) {
Map < String , Integer > map1 = entry . getValue ( ) ;
int sum = 0 ;
for ( Map . Entry < String , Integer > entry1 : map1 . entrySet ( ) ) {
sum + = entry1 . getValue ( ) ;
}
for ( Map . Entry < String , Integer > entry1 : map1 . entrySet ( ) ) {
double load = ( double ) entry1 . getValue ( ) / sum * 100 ;
map1 . put ( entry1 . getKey ( ) , ( int ) Math . round ( load ) ) ;
public List < Map < String , Object > > getInstrumentDaylyLoad ( LargeScreenVO entity ) {
List < Map < String , Object > > list = new ArrayList < > ( ) ;
List < LargeScreenVO > list1 = largeScreenMapper . getInstrumentDaylyCount ( entity ) ;
List < LargeScreenVO > list2 = largeScreenMapper . getInstrumentDaylyLoad ( entity ) ;
if ( CollectionUtils . isNotEmpty ( list1 ) ) {
for ( LargeScreenVO vo1 : list1 ) {
Map < String , Object > map = new HashMap < > ( ) ;
map . put ( "name" , vo1 . getName ( ) ) ;
map . put ( "kongzai" , 0 ) ;
map . put ( "qingzai" , 0 ) ;
map . put ( "zhengchang" , 0 ) ;
map . put ( "guozai" , 0 ) ;
map . put ( "zhongzai" , 0 ) ;
for ( LargeScreenVO vo2 : list2 ) {
if ( vo1 . getName ( ) . equals ( vo2 . getName ( ) ) ) {
int load = ( int ) Math . round ( ( double ) vo2 . getCount ( ) / vo1 . getCount ( ) * 100 ) ;
if ( "空载" . equals ( vo2 . getLoadLevel ( ) ) ) {
map . put ( "kongzai" , load ) ;
} else if ( "轻载" . equals ( vo2 . getLoadLevel ( ) ) ) {
map . put ( "qingzai" , load ) ;
} else if ( "正常" . equals ( vo2 . getLoadLevel ( ) ) ) {
map . put ( "zhengchang" , load ) ;
} else if ( "过载" . equals ( vo2 . getLoadLevel ( ) ) ) {
map . put ( "guozai" , load ) ;
} else if ( "重载" . equals ( vo2 . getLoadLevel ( ) ) ) {
map . put ( "zhongzai" , load ) ;
}
}
}
map . put ( entry . getKey ( ) , map1 ) ;
list . add ( map ) ;
}
}
return map ;
return list ;
}
@Override
public Map < String , Map < String , Double > > getWeekElectricity ( LargeScreenVO entity ) {
String day = entity . getToday ( ) ;
Map < String , Map < String , Double > > map = new HashMap < > ( ) ;
/ * List < TimeVO > jianList = new ArrayList < > ( ) ;
List < TimeVO > fengList = new ArrayList < > ( ) ;
List < TimeVO > pingList = new ArrayList < > ( ) ;
List < TimeVO > guList = new ArrayList < > ( ) ;
List < Dict > dictlist = DictCache . getList ( "electricity_period" ) ; * /
for ( int i = 0 ; i < 7 ; i + + ) {
try {
String today = DateFormatUtils . format ( DateUtils . addDays ( DateUtils . parseDate ( day , "yyyy-MM-dd" ) , - i ) , "yyyy-MM-dd" ) ;
entity . setToday ( today ) ;
/ * for ( Dict dict : dictlist ) {
List < String > timeList1 = Arrays . asList ( dict . getDictKey ( ) . split ( "," ) ) ;
timeList1 . forEach ( s - > {
String [ ] times = s . split ( "-" ) ;
TimeVO timeVO = new TimeVO ( ) ;
timeVO . setStartTime ( entity . getToday ( ) + " " + times [ 0 ] ) ;
timeVO . setEndTime ( entity . getToday ( ) + " " + times [ 1 ] ) ;
if ( dict . getDictValue ( ) . equals ( "尖" ) ) {
jianList . add ( timeVO ) ;
}
if ( dict . getDictValue ( ) . equals ( "峰" ) ) {
fengList . add ( timeVO ) ;
}
if ( dict . getDictValue ( ) . equals ( "平" ) ) {
pingList . add ( timeVO ) ;
}
if ( dict . getDictValue ( ) . equals ( "谷" ) ) {
guList . add ( timeVO ) ;
}
} ) ;
}
entity . setJianList ( jianList ) ;
entity . setFengList ( fengList ) ;
entity . setPingList ( pingList ) ;
entity . setGuList ( guList ) ; * /
List < LargeScreenVO > list1 = largeScreenMapper . getWeekElectricity ( entity ) ;
Map < String , Double > map1 = new HashMap < > ( ) ;
list1 . forEach ( largeScreenVO - > {
@ -178,6 +254,300 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
return map ;
}
@Override
public List < Map < String , Object > > getInstrumentRunStatus ( LargeScreenVO entity ) {
List < Map < String , Object > > list = new ArrayList < > ( ) ;
Date date = new Date ( ) ;
if ( Integer . parseInt ( DateFormatUtils . format ( date , "HH" ) ) > = 8 & & Integer . parseInt ( DateFormatUtils . format ( date , "HH" ) ) < = 20 ) {
//查询设备运行状态
LambdaQueryWrapper < Instrument > wrapper = new LambdaQueryWrapper < > ( ) ;
if ( StringUtils . isNotEmpty ( entity . getManufacturerBrand ( ) ) ) {
wrapper . eq ( Instrument : : getManufacturerBrand , entity . getManufacturerBrand ( ) ) ;
}
List < Instrument > instrumentList = instrumentService . list ( wrapper ) ;
if ( CollectionUtils . isNotEmpty ( instrumentList ) ) {
for ( Instrument instrument : instrumentList ) {
Map < String , Object > map = new HashMap < > ( ) ;
List < Map < String , String > > list1 = ( List ) redisUtil . get ( instrument . getName ( ) + "-runStatus" ) ;
map . put ( "name" , instrument . getName ( ) ) ;
map . put ( "list" , list1 ) ;
list . add ( map ) ;
}
}
return list ;
}
return null ;
}
@Override
public Map < String , Double > getTotalCarbonEmissions ( ) {
String currentYear = DateFormatUtils . format ( new Date ( ) , "yyyy" ) ;
LargeScreenVO largeScreenVO = largeScreenMapper . getTotalCarbonEmissions ( currentYear ) ;
CarbonEmissionPlan carbonEmissionPlan = carbonEmissionPlanService . getCarbonEmissionPlan ( currentYear ) ;
String lastYear = DateFormatUtils . format ( DateUtils . addYears ( new Date ( ) , - 1 ) , "yyyy" ) ;
LargeScreenVO largeScreenVO1 = largeScreenMapper . getTotalCarbonEmissions ( lastYear ) ;
CarbonEmissionPlan carbonEmissionPlan1 = carbonEmissionPlanService . getCarbonEmissionPlan ( lastYear ) ;
Map < String , Double > map = new HashMap < > ( ) ;
map . put ( "jnzl" , largeScreenVO . getTotalCarbonEmissions ( ) ) ;
if ( largeScreenVO1 ! = null ) {
map . put ( "qnzl" , largeScreenVO1 . getTotalCarbonEmissions ( ) ) ;
} else {
map . put ( "qnzl" , 0 . 0 ) ;
}
if ( carbonEmissionPlan1 ! = null ) {
map . put ( "qnjhl" , carbonEmissionPlan1 . getCarbonPlan ( ) ) ;
map . put ( "qnjpzl" , carbonEmissionPlan1 . getTotalCarbonReduction ( ) ) ;
} else {
map . put ( "qnjhl" , 0 . 0 ) ;
map . put ( "qnjpzl" , 0 . 0 ) ;
}
map . put ( "jnjhzl" , carbonEmissionPlan . getTotalCarbonPlan ( ) ) ;
map . put ( "jnjhl" , carbonEmissionPlan . getCarbonPlan ( ) ) ;
map . put ( "jnjpzl" , carbonEmissionPlan . getTotalCarbonReduction ( ) ) ;
map . put ( "gffd" , carbonEmissionPlan . getPvPower ( ) ) ;
map . put ( "gyyh" , carbonEmissionPlan . getProcessOpt ( ) ) ;
map . put ( "sbgh" , carbonEmissionPlan . getEquipReplace ( ) ) ;
map . put ( "gffdzb" , Double . parseDouble ( String . format ( "%.2f" , carbonEmissionPlan . getPvPower ( ) / carbonEmissionPlan . getTotalCarbonReduction ( ) * 100 ) ) ) ;
map . put ( "gyyhzb" , Double . parseDouble ( String . format ( "%.2f" , carbonEmissionPlan . getProcessOpt ( ) / carbonEmissionPlan . getTotalCarbonReduction ( ) * 100 ) ) ) ;
map . put ( "sbghzb" , Double . parseDouble ( String . format ( "%.2f" , carbonEmissionPlan . getEquipReplace ( ) / carbonEmissionPlan . getTotalCarbonReduction ( ) * 100 ) ) ) ;
map . put ( "ypfzb" , Double . parseDouble ( String . format ( "%.2f" , carbonEmissionPlan . getTotalCarbonPlan ( ) / largeScreenVO . getTotalCarbonEmissions ( ) * 100 ) ) ) ;
return map ;
}
@Override
public List < Map < String , Object > > getEnterprisePower ( LargeScreenVO entity ) {
List < Map < String , Object > > list = new ArrayList < > ( ) ;
List < LargeScreenVO > dataList = largeScreenMapper . getEnterprisePower ( entity ) ;
if ( CollectionUtils . isNotEmpty ( dataList ) ) {
for ( LargeScreenVO largeScreenVO : dataList ) {
Map < String , Object > map = new TreeMap < > ( ) ;
map . put ( "name" , largeScreenVO . getManufacturerBrand ( ) ) ;
map . put ( "electricity" , largeScreenVO . getSum ( ) ) ;
map . put ( "carbon" , largeScreenVO . getTotalCarbonEmissions ( ) ) ;
list . add ( map ) ;
}
}
return list ;
}
@Override
public Map < String , Double > getSixMonthElectricity ( ) {
Map < String , Double > map = new HashMap < > ( ) ;
try {
List < String > monthList = new ArrayList < > ( ) ;
String currentMonth = DateFormatUtils . format ( new Date ( ) , "yyyy-MM" ) ;
monthList . add ( currentMonth ) ;
monthList . add ( DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( currentMonth , "yyyy-MM" ) , - 1 ) , "yyyy-MM" ) ) ;
monthList . add ( DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( currentMonth , "yyyy-MM" ) , - 2 ) , "yyyy-MM" ) ) ;
monthList . add ( DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( currentMonth , "yyyy-MM" ) , - 3 ) , "yyyy-MM" ) ) ;
monthList . add ( DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( currentMonth , "yyyy-MM" ) , - 4 ) , "yyyy-MM" ) ) ;
monthList . add ( DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( currentMonth , "yyyy-MM" ) , - 5 ) , "yyyy-MM" ) ) ;
monthList . forEach ( s - > {
map . put ( s , 0 . 0 ) ;
} ) ;
LargeScreenVO largeScreenVO = new LargeScreenVO ( ) ;
largeScreenVO . setMonthList ( monthList ) ;
List < LargeScreenVO > dataList = largeScreenMapper . getSixMonthElectricity ( largeScreenVO ) ;
if ( CollectionUtils . isNotEmpty ( dataList ) ) {
dataList . forEach ( largeScreenVO1 - > {
map . put ( largeScreenVO1 . getCurrentMonth ( ) , largeScreenVO1 . getSum ( ) ) ;
} ) ;
}
} catch ( ParseException e ) {
throw new RuntimeException ( e ) ;
}
return map ;
}
@Override
public Map < String , String > getSixMonthCarbonQoq ( ) {
Map < String , String > map = new HashMap < > ( ) ;
Map < String , Double > map1 = new HashMap < > ( ) ;
try {
List < String > monthList = new ArrayList < > ( ) ;
String currentMonth = DateFormatUtils . format ( new Date ( ) , "yyyy-MM" ) ;
String month1 = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( currentMonth , "yyyy-MM" ) , - 1 ) , "yyyy-MM" ) ;
String month2 = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( currentMonth , "yyyy-MM" ) , - 2 ) , "yyyy-MM" ) ;
String month3 = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( currentMonth , "yyyy-MM" ) , - 3 ) , "yyyy-MM" ) ;
String month4 = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( currentMonth , "yyyy-MM" ) , - 4 ) , "yyyy-MM" ) ;
String month5 = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( currentMonth , "yyyy-MM" ) , - 5 ) , "yyyy-MM" ) ;
String month6 = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( currentMonth , "yyyy-MM" ) , - 6 ) , "yyyy-MM" ) ;
monthList . add ( currentMonth ) ;
monthList . add ( month1 ) ;
monthList . add ( month2 ) ;
monthList . add ( month3 ) ;
monthList . add ( month4 ) ;
monthList . add ( month5 ) ;
monthList . forEach ( s - > {
map . put ( s , "0" ) ;
} ) ;
monthList . add ( month6 ) ;
monthList . forEach ( s - > {
map1 . put ( s , 0 . 0 ) ;
} ) ;
LargeScreenVO largeScreenVO = new LargeScreenVO ( ) ;
largeScreenVO . setMonthList ( monthList ) ;
List < LargeScreenVO > dataList = largeScreenMapper . getMonthCarbon ( largeScreenVO ) ;
if ( CollectionUtils . isNotEmpty ( dataList ) ) {
dataList . forEach ( largeScreenVO1 - > {
map1 . put ( largeScreenVO1 . getCurrentMonth ( ) , largeScreenVO1 . getTotalCarbonEmissions ( ) ) ;
} ) ;
if ( map1 . get ( month6 ) ! = 0 ) {
map . put ( month5 , String . format ( "%.2f" , ( map1 . get ( month5 ) - map1 . get ( month6 ) ) / map1 . get ( month6 ) * 100 ) ) ;
}
if ( map1 . get ( month5 ) ! = 0 ) {
map . put ( month4 , String . format ( "%.2f" , ( map1 . get ( month4 ) - map1 . get ( month5 ) ) / map1 . get ( month5 ) * 100 ) ) ;
}
if ( map1 . get ( month4 ) ! = 0 ) {
map . put ( month3 , String . format ( "%.2f" , ( map1 . get ( month3 ) - map1 . get ( month4 ) ) / map1 . get ( month4 ) * 100 ) ) ;
}
if ( map1 . get ( month3 ) ! = 0 ) {
map . put ( month2 , String . format ( "%.2f" , ( map1 . get ( month2 ) - map1 . get ( month3 ) ) / map1 . get ( month3 ) * 100 ) ) ;
}
if ( map1 . get ( month2 ) ! = 0 ) {
map . put ( month1 , String . format ( "%.2f" , ( map1 . get ( month1 ) - map1 . get ( month2 ) ) / map1 . get ( month2 ) * 100 ) ) ;
}
if ( map1 . get ( month1 ) ! = 0 ) {
map . put ( currentMonth , String . format ( "%.2f" , ( map1 . get ( currentMonth ) - map1 . get ( month1 ) ) / map1 . get ( month1 ) * 100 ) ) ;
}
}
} catch ( ParseException e ) {
throw new RuntimeException ( e ) ;
}
return map ;
}
@Override
public List < Map < String , Object > > getSixMonthCarbonYoy ( ) {
List < Map < String , Object > > list = new ArrayList < > ( ) ;
try {
List < String > monthList = new ArrayList < > ( ) ;
String month = DateFormatUtils . format ( new Date ( ) , "yyyy-MM" ) ; ;
String month1 = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( month , "yyyy-MM" ) , - 1 ) , "yyyy-MM" ) ;
String month2 = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( month , "yyyy-MM" ) , - 2 ) , "yyyy-MM" ) ;
String month3 = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( month , "yyyy-MM" ) , - 3 ) , "yyyy-MM" ) ;
String month4 = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( month , "yyyy-MM" ) , - 4 ) , "yyyy-MM" ) ;
String month5 = DateFormatUtils . format ( DateUtils . addMonths ( DateUtils . parseDate ( month , "yyyy-MM" ) , - 5 ) , "yyyy-MM" ) ;
monthList . add ( month ) ;
monthList . add ( month1 ) ;
monthList . add ( month2 ) ;
monthList . add ( month3 ) ;
monthList . add ( month4 ) ;
monthList . add ( month5 ) ;
monthList . forEach ( s - > {
Map < String , Object > map = new HashMap < > ( ) ;
try {
map . put ( "jn" , s ) ;
map . put ( "qn" , DateFormatUtils . format ( DateUtils . addYears ( DateUtils . parseDate ( s , "yyyy-MM" ) , - 1 ) , "yyyy-MM" ) ) ;
map . put ( "jnpf" , 0 . 0 ) ;
map . put ( "qnpf" , 0 . 0 ) ;
map . put ( "tongbi" , 0 . 0 ) ;
} catch ( ParseException e ) {
throw new RuntimeException ( e ) ;
}
list . add ( map ) ;
} ) ;
LargeScreenVO largeScreenVO = new LargeScreenVO ( ) ;
largeScreenVO . setMonthList ( monthList ) ;
List < LargeScreenVO > dataList1 = largeScreenMapper . getMonthCarbon ( largeScreenVO ) ;
if ( CollectionUtils . isNotEmpty ( dataList1 ) ) {
for ( LargeScreenVO largeScreenVO1 : dataList1 ) {
for ( Map < String , Object > map : list ) {
if ( map . get ( "jn" ) . toString ( ) . equals ( largeScreenVO1 . getCurrentMonth ( ) ) ) {
map . put ( "jnpf" , largeScreenVO1 . getTotalCarbonEmissions ( ) ) ;
}
}
}
}
String lmonth = DateFormatUtils . format ( DateUtils . addYears ( DateUtils . parseDate ( month , "yyyy-MM" ) , - 1 ) , "yyyy-MM" ) ;
String lmonth1 = DateFormatUtils . format ( DateUtils . addYears ( DateUtils . parseDate ( month1 , "yyyy-MM" ) , - 1 ) , "yyyy-MM" ) ;
String lmonth2 = DateFormatUtils . format ( DateUtils . addYears ( DateUtils . parseDate ( month2 , "yyyy-MM" ) , - 1 ) , "yyyy-MM" ) ;
String lmonth3 = DateFormatUtils . format ( DateUtils . addYears ( DateUtils . parseDate ( month3 , "yyyy-MM" ) , - 1 ) , "yyyy-MM" ) ;
String lmonth4 = DateFormatUtils . format ( DateUtils . addYears ( DateUtils . parseDate ( month4 , "yyyy-MM" ) , - 1 ) , "yyyy-MM" ) ;
String lmonth5 = DateFormatUtils . format ( DateUtils . addYears ( DateUtils . parseDate ( month5 , "yyyy-MM" ) , - 1 ) , "yyyy-MM" ) ;
monthList . clear ( ) ;
monthList . add ( lmonth ) ;
monthList . add ( lmonth1 ) ;
monthList . add ( lmonth2 ) ;
monthList . add ( lmonth3 ) ;
monthList . add ( lmonth4 ) ;
monthList . add ( lmonth5 ) ;
largeScreenVO . setMonthList ( monthList ) ;
List < LargeScreenVO > dataList2 = largeScreenMapper . getMonthCarbon ( largeScreenVO ) ;
if ( CollectionUtils . isNotEmpty ( dataList2 ) ) {
for ( LargeScreenVO largeScreenVO1 : dataList2 ) {
for ( Map < String , Object > map : list ) {
if ( map . get ( "qn" ) . toString ( ) . equals ( largeScreenVO1 . getCurrentMonth ( ) ) ) {
map . put ( "qnpf" , largeScreenVO1 . getTotalCarbonEmissions ( ) ) ;
}
}
}
}
for ( Map < String , Object > map : list ) {
if ( ( double ) map . get ( "qnpf" ) ! = 0 . 0 ) {
map . put ( "tongbi" , Double . parseDouble ( String . format ( "%.2f" , ( ( double ) map . get ( "jnpf" ) - ( double ) map . get ( "qnpf" ) ) / ( double ) map . get ( "qnpf" ) * 100 ) ) ) ;
}
}
} catch ( ParseException e ) {
throw new RuntimeException ( e ) ;
}
return list ;
}
@Override
public void getInstrumentRunStatusJob ( ) {
Date date = new Date ( ) ;
if ( Integer . parseInt ( DateFormatUtils . format ( date , "HH" ) ) > = 8 & & Integer . parseInt ( DateFormatUtils . format ( date , "HH" ) ) < = 20 ) {
List < Instrument > instrumentList = instrumentService . list ( new LambdaQueryWrapper < > ( ) ) ;
if ( CollectionUtils . isNotEmpty ( instrumentList ) ) {
for ( Instrument instrument : instrumentList ) {
List < Map < String , String > > list = new ArrayList < > ( ) ;
if ( redisUtil . get ( instrument . getName ( ) + "-runStatus" ) = = null ) {
list = new ArrayList < > ( ) ;
Map < String , String > map = new HashMap < > ( ) ;
map . put ( "time" , DateFormatUtils . format ( date , "HH:mm" ) ) ;
map . put ( "runStatus" , instrument . getRunStatus ( ) = = null ? "2" : instrument . getRunStatus ( ) . toString ( ) ) ;
list . add ( map ) ;
//早8点到晚8点,redis过期时间设置为4小时
redisUtil . set ( instrument . getName ( ) + "-runStatus" , list , 60 * 60 * 4 ) ;
} else {
list = ( List ) redisUtil . get ( instrument . getName ( ) + "-runStatus" ) ;
Map < String , String > map = new HashMap < > ( ) ;
map . put ( "time" , DateFormatUtils . format ( date , "HH:mm" ) ) ;
map . put ( "runStatus" , instrument . getRunStatus ( ) = = null ? "2" : instrument . getRunStatus ( ) . toString ( ) ) ;
list . add ( map ) ;
redisUtil . set ( instrument . getName ( ) + "-runStatus" , list , 60 * 60 * 4 ) ;
}
}
}
}
}
@Override
public IPage < LargeScreenVO > getInstrumentRunDetail ( LargeScreenVO entity , Query query ) {
List < LargeScreenVO > list = largeScreenMapper . getInstrumentRunDetail ( entity ) ;
IPage < LargeScreenVO > page = new Page < > ( query . getCurrent ( ) , query . getSize ( ) ) ;
int startIndex = ( int ) ( ( query . getCurrent ( ) - 1 ) * query . getSize ( ) ) ;
if ( null = = list | | list . isEmpty ( ) | | startIndex > list . size ( ) ) {
page . setTotal ( 0 ) ;
page . setRecords ( null ) ;
}
else {
page . setTotal ( list . size ( ) ) ;
int toIndex = ( int ) ( query . getCurrent ( ) * query . getSize ( ) ) ;
page . setRecords ( list . subList ( startIndex , toIndex > list . size ( ) ? list . size ( ) : toIndex ) ) ;
}
return page ;
}
public TreeMap < String , Double > initMonthData ( String currentMonth ) {
int year = Integer . parseInt ( currentMonth . split ( "-" ) [ 0 ] ) ;
int month = Integer . parseInt ( currentMonth . split ( "-" ) [ 1 ] ) ;