16 changed files with 259 additions and 1101 deletions
-
6modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/controller/ManageBoardController.java
-
24modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/controller/PlantController.java
-
2modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PhotovoltaicDTO.java
-
6modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PhotovoltaicOverviewDTO.java
-
8modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PlantDTO.java
-
19modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/entity/PlantEntity.java
-
2modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/ManageBoardService.java
-
11modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/PlantService.java
-
45modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/impl/ManageBoardServiceImpl.java
-
199modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/impl/PlantServiceImpl.java
-
129modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/controller/PhotovoltaicController.java
-
33modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicConsumptionDTO.java
-
43modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicReportDTO.java
-
45modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/service/PhotovoltaicService.java
-
776modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/service/impl/PhotovoltaicServiceImpl.java
-
12modules/qingyuan/src/main/java/com/thing/qingyuan/util/CalculationUtil.java
@ -1,4 +1,4 @@ |
|||
package com.thing.qingyuan.photovoltaic.dto; |
|||
package com.thing.qingyuan.manageboard.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
@ -1,129 +0,0 @@ |
|||
package com.thing.qingyuan.photovoltaic.controller; |
|||
|
|||
import com.thing.common.core.annotation.LogOperation; |
|||
import com.thing.common.core.web.response.Result; |
|||
import com.thing.common.data.tskv.TsKvDTO; |
|||
import com.thing.qingyuan.chargeStation.dto.ChargeStatisticRequest; |
|||
import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicDTO; |
|||
import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicOverviewDTO; |
|||
import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicReportDTO; |
|||
import com.thing.qingyuan.photovoltaic.service.PhotovoltaicService; |
|||
import com.thing.qingyuan.screen.ScreenData; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import jakarta.servlet.http.HttpServletResponse; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 光伏项目点位信息 |
|||
* |
|||
* @author xc |
|||
* @since 3.0 2024-01-29 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("photovoltaic") |
|||
@Tag(name="光伏项目点位信息") |
|||
@RequiredArgsConstructor |
|||
public class PhotovoltaicController { |
|||
|
|||
private final PhotovoltaicService photovoltaicService; |
|||
|
|||
|
|||
@GetMapping("overview") |
|||
@Operation(summary="获取光伏概览数据信息") |
|||
public Result<PhotovoltaicOverviewDTO> getOverview(){ |
|||
PhotovoltaicOverviewDTO data = photovoltaicService.getOverview(); |
|||
return new Result<PhotovoltaicOverviewDTO>().ok(data); |
|||
} |
|||
|
|||
@GetMapping("{plantId}") |
|||
@Operation(summary="获取电站信息") |
|||
public Result<PhotovoltaicDTO> get(@PathVariable("plantId") Long plantId){ |
|||
PhotovoltaicDTO data = photovoltaicService.findById(plantId); |
|||
return new Result<PhotovoltaicDTO>().ok(data); |
|||
} |
|||
|
|||
@GetMapping("video/{plantId}") |
|||
@Operation(summary="获取视频信息") |
|||
public Result getVideo(@PathVariable("plantId") Long plantId){ |
|||
PhotovoltaicDTO data = photovoltaicService.findById(plantId); |
|||
return new Result<PhotovoltaicDTO>().ok(data); |
|||
} |
|||
|
|||
|
|||
@GetMapping("heatMap") |
|||
@Operation(summary="获取热力图信息") |
|||
public Result<List<ScreenData>> getHeatMap(){ |
|||
List<ScreenData> heatMap = photovoltaicService.getHeatMap(); |
|||
return new Result<List<ScreenData>>().ok(heatMap); |
|||
} |
|||
|
|||
@GetMapping("powerAnalysis/{plantId}/{type}") |
|||
@Operation(summary="发电分析") |
|||
public Result<Map<String,List<TsKvDTO>>> powerAnalysis(@PathVariable("plantId") Long plantId,@PathVariable("type") String type){ |
|||
Map<String,List<TsKvDTO>> resultData = photovoltaicService.getPowerAnalysis(plantId,type); |
|||
return new Result<Map<String,List<TsKvDTO>>>().ok(resultData); |
|||
} |
|||
|
|||
@GetMapping("electricPowerAnalysis/{plantId}/{type}") |
|||
@Operation(summary="发电消纳分析") |
|||
public Result<Map<String,List<TsKvDTO>>> electricPowerAnalysis(@PathVariable("plantId") Long plantId,@PathVariable("type") String type){ |
|||
Map<String,List<TsKvDTO>> resultData = photovoltaicService.getElectricPowerAnalysis(plantId,type); |
|||
return new Result<Map<String,List<TsKvDTO>>>().ok(resultData); |
|||
} |
|||
|
|||
@GetMapping("inverter/{code}") |
|||
@Operation(summary="逆变器详情") |
|||
public Result<Map<String,List<TsKvDTO>>> inverterDetails(@PathVariable String code){ |
|||
Map<String,List<TsKvDTO>> resultData = photovoltaicService.getInverterDetails(code); |
|||
return new Result<Map<String,List<TsKvDTO>>>().ok(resultData); |
|||
} |
|||
|
|||
@PostMapping("report/electric") |
|||
@Operation(summary="发电报表") |
|||
public Result<List<PhotovoltaicReportDTO>> reportElectric(@RequestBody ChargeStatisticRequest chargeStatisticRequest){ |
|||
List<PhotovoltaicReportDTO> reportElectric = photovoltaicService.getReportElectric(chargeStatisticRequest); |
|||
return new Result<List<PhotovoltaicReportDTO>>().ok(reportElectric); |
|||
} |
|||
|
|||
@PostMapping("report/electric/export") |
|||
@Operation(summary="发电报表导出") |
|||
@LogOperation("发电报表导出") |
|||
public void electricExport( @RequestBody ChargeStatisticRequest chargeStatisticRequest, HttpServletResponse response) throws Exception { |
|||
photovoltaicService.electricExport(chargeStatisticRequest, response); |
|||
} |
|||
|
|||
@PostMapping("report/consumption") |
|||
@Operation(summary="上网消纳量报表") |
|||
public Result<List<PhotovoltaicReportDTO>> reportConsumption(@RequestBody ChargeStatisticRequest chargeStatisticRequest){ |
|||
List<PhotovoltaicReportDTO> reportElectric = photovoltaicService.getReportConsumption(chargeStatisticRequest); |
|||
return new Result<List<PhotovoltaicReportDTO>>().ok(reportElectric); |
|||
} |
|||
|
|||
@PostMapping("report/consumption/export") |
|||
@Operation(summary="上网消纳量报表导出") |
|||
@LogOperation("上网消纳量报表导出") |
|||
public void reportElectric(@RequestBody ChargeStatisticRequest chargeStatisticRequest,HttpServletResponse response){ |
|||
photovoltaicService.consumptionExport(chargeStatisticRequest, response); |
|||
} |
|||
|
|||
/* @GetMapping("page") |
|||
@Operation(summary="分页") |
|||
@Parameters({ |
|||
@Parameter(name = Constant.PAGE, description = "当前页码,从1开始") , |
|||
@Parameter(name = Constant.LIMIT, description = "每页显示记录数") , |
|||
@Parameter(name = Constant.ORDER_FIELD, description = "排序字段") , |
|||
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"), |
|||
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") |
|||
}) |
|||
public Result<PageData<PlantDTO>> page(@RequestParam Map<String, Object> params){ |
|||
PageData<PlantDTO> page = photovoltaicService.getP(params, PlantDTO.class); |
|||
return new Result<PageData<PlantDTO>>().ok(page); |
|||
}*/ |
|||
|
|||
|
|||
} |
|||
@ -1,33 +0,0 @@ |
|||
package com.thing.qingyuan.photovoltaic.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serial; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
|
|||
/** |
|||
* 光伏项目概览数据信息 |
|||
* |
|||
* @author xc |
|||
* @since 3.0 2024-01-29 |
|||
*/ |
|||
@Data |
|||
@Schema( description= "消纳报表数据信息") |
|||
public class PhotovoltaicConsumptionDTO implements Serializable { |
|||
|
|||
@Serial |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@Schema(description = "发电量") |
|||
private BigDecimal electricityUsage = BigDecimal.ZERO; |
|||
@Schema(description = "消纳量") |
|||
private BigDecimal consumptionUsage = BigDecimal.ZERO; |
|||
@Schema(description = "上网量") |
|||
private BigDecimal internetUsage = BigDecimal.ZERO; |
|||
@Schema(description = "消纳率") |
|||
private BigDecimal consumptionRate = BigDecimal.ZERO; |
|||
@Schema(description = "时间") |
|||
private Long ts ; |
|||
} |
|||
@ -1,43 +0,0 @@ |
|||
package com.thing.qingyuan.photovoltaic.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serial; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 光伏项目概览数据信息 |
|||
* |
|||
* @author xc |
|||
* @since 3.0 2024-01-29 |
|||
*/ |
|||
@Data |
|||
@Schema( description= "光伏和消纳报表数据信息") |
|||
public class PhotovoltaicReportDTO implements Serializable { |
|||
|
|||
@Serial |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@Schema(description = "物的id") |
|||
private Long thingId; |
|||
@Schema(description = "结构编码") |
|||
private String code; |
|||
@Schema(description = "结构名称") |
|||
private String name; |
|||
@Schema(description = "发电总量 (单位:kwh)") |
|||
private BigDecimal electricityUsage = BigDecimal.ZERO; |
|||
@Schema(description = "光伏报表数据,key: ts,val ") |
|||
private List<Map<String,Object>> plantDataList; |
|||
@Schema(description = "消纳报表总量数据") |
|||
private PhotovoltaicConsumptionDTO consumptionTotal; |
|||
@Schema(description = "消纳报表数据") |
|||
private List<PhotovoltaicConsumptionDTO> consumptionDataList; |
|||
@Schema(description = "时间列表:暂时后端使用") |
|||
private List<Long> timeList; |
|||
|
|||
|
|||
} |
|||
@ -1,45 +0,0 @@ |
|||
package com.thing.qingyuan.photovoltaic.service; |
|||
|
|||
|
|||
import com.thing.common.data.tskv.TsKvDTO; |
|||
import com.thing.qingyuan.chargeStation.dto.ChargeStatisticRequest; |
|||
import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicDTO; |
|||
import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicOverviewDTO; |
|||
import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicReportDTO; |
|||
import com.thing.qingyuan.screen.ScreenData; |
|||
import jakarta.servlet.http.HttpServletResponse; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 光伏项目点位信息 |
|||
* |
|||
* @author xc |
|||
* @since 3.0 2024-01-29 |
|||
*/ |
|||
public interface PhotovoltaicService { |
|||
|
|||
|
|||
PhotovoltaicOverviewDTO getOverview(); |
|||
|
|||
PhotovoltaicDTO findById(Long plantId); |
|||
|
|||
List<String> findVideoById(Long plantId); |
|||
|
|||
List<ScreenData> getHeatMap(); |
|||
|
|||
Map<String,List<TsKvDTO>> getPowerAnalysis(Long plantId, String type); |
|||
|
|||
Map<String,List<TsKvDTO>> getElectricPowerAnalysis(Long plantId, String type); |
|||
|
|||
Map<String,List<TsKvDTO>> getInverterDetails(String code); |
|||
|
|||
List<PhotovoltaicReportDTO> getReportElectric(ChargeStatisticRequest chargeStatisticRequest); |
|||
|
|||
void electricExport(ChargeStatisticRequest chargeStatisticRequest, HttpServletResponse response); |
|||
|
|||
List<PhotovoltaicReportDTO> getReportConsumption(ChargeStatisticRequest chargeStatisticRequest); |
|||
|
|||
void consumptionExport(ChargeStatisticRequest chargeStatisticRequest, HttpServletResponse response); |
|||
} |
|||
@ -1,776 +0,0 @@ |
|||
package com.thing.qingyuan.photovoltaic.service.impl; |
|||
|
|||
import cn.afterturn.easypoi.excel.ExcelExportUtil; |
|||
import cn.afterturn.easypoi.excel.entity.ExportParams; |
|||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; |
|||
import cn.hutool.core.collection.CollectionUtil; |
|||
import cn.hutool.core.comparator.CompareUtil; |
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import com.google.common.collect.Lists; |
|||
import com.thing.common.core.enumeration.ThingAttrType; |
|||
import com.thing.common.core.enumeration.TimeType; |
|||
import com.thing.common.core.exception.SysException; |
|||
import com.thing.common.core.utils.DateTimeUtils; |
|||
import com.thing.common.core.utils.excel.ExcelUtils; |
|||
import com.thing.common.data.tskv.TsKvDTO; |
|||
import com.thing.common.tskv.service.TsKvService; |
|||
import com.thing.qingyuan.basedevice.dto.DeviceDTO; |
|||
import com.thing.qingyuan.basedevice.service.IotDeviceService; |
|||
import com.thing.qingyuan.chargeStation.dto.ChargeStatisticRequest; |
|||
import com.thing.qingyuan.manageboard.entity.PlantEntity; |
|||
import com.thing.qingyuan.manageboard.service.PlantService; |
|||
import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicConsumptionDTO; |
|||
import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicDTO; |
|||
import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicOverviewDTO; |
|||
import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicReportDTO; |
|||
import com.thing.qingyuan.photovoltaic.service.PhotovoltaicService; |
|||
import com.thing.qingyuan.screen.ScreenData; |
|||
import com.thing.qingyuan.util.CalculationUtil; |
|||
|
|||
import com.thing.sys.security.context.UserContext; |
|||
import com.thing.thing.entity.dto.IotThingEntityDTO; |
|||
import com.thing.thing.entity.entity.IotThingEntity; |
|||
import com.thing.thing.entity.service.IotThingEntityService; |
|||
import jakarta.servlet.http.HttpServletResponse; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.collections4.CollectionUtils; |
|||
import org.apache.commons.collections4.MapUtils; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.apache.poi.ss.usermodel.Workbook; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.math.RoundingMode; |
|||
import java.util.*; |
|||
import java.util.stream.Collectors; |
|||
import java.util.stream.Stream; |
|||
|
|||
/** |
|||
* 光伏项目点位信息 |
|||
* |
|||
* @author xc |
|||
* @since 3.0 2024-01-29 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
public class PhotovoltaicServiceImpl implements PhotovoltaicService { |
|||
|
|||
private final PlantService plantService; |
|||
private final IotThingEntityService thingEntityService; |
|||
private final TsKvService tsKvService; |
|||
private final IotDeviceService iotDeviceService; |
|||
|
|||
|
|||
private final static BigDecimal coefficient = BigDecimal.ONE.divide(BigDecimal.TEN.pow(3)); |
|||
private final static BigDecimal reductionFactor = new BigDecimal("0.475"); |
|||
private final static BigDecimal energySaveFactor = new BigDecimal("0.4"); |
|||
private final static String attrA16 = "A16"; |
|||
private final static String attrA29 = "A29"; |
|||
private final static String attrA29dd = "A29dd"; |
|||
private final static String attrA29mm = "A29mm"; |
|||
private final static String attrA30 = "A30"; |
|||
private final static String attrA30hh = "A30hh"; |
|||
private final static String attrA30dd = "A30dd"; |
|||
private final static String attrA30mm = "A30mm"; |
|||
private final static String attrA30yy = "A30yy"; |
|||
private final static String attrA29yy = "A29yy"; |
|||
private final static Long ONE_DAY = 86400000L; |
|||
|
|||
@Override |
|||
public PhotovoltaicOverviewDTO getOverview() { |
|||
PhotovoltaicOverviewDTO photovoltaicOverviewDTO = new PhotovoltaicOverviewDTO(); |
|||
List<PlantEntity> list = plantService.list(); |
|||
if (CollectionUtils.isNotEmpty(list)) { |
|||
photovoltaicOverviewDTO.setNum(new BigDecimal(CollectionUtils.size(list))); |
|||
BigDecimal capacity = list.stream().map(PlantEntity::getCapacity).reduce(BigDecimal.ZERO, BigDecimal::add); |
|||
photovoltaicOverviewDTO.setCapacity(capacity); |
|||
|
|||
List<String> entityCodes = list.stream().map(PlantEntity::getPlantId).map(Object::toString).toList(); |
|||
Optional<List<IotThingEntityDTO>> thingEntities = thingEntityService.findByCodes(entityCodes, UserContext.getRealTenantCode(), true); |
|||
if (thingEntities.isPresent()) { |
|||
List<TsKvDTO> tsKvDTOList = tsKvService.findLatestByCodesAndAttrs(thingEntities.get().stream().map(IotThingEntityDTO::getCode).toList(), Lists.newArrayList(attrA29yy, attrA30yy), false); |
|||
if (CollectionUtils.isNotEmpty(tsKvDTOList)) { |
|||
//年发电总量 |
|||
BigDecimal electricityUsage = tsKvDTOList.stream().filter(s -> StringUtils.equals(s.getAttrKey(), attrA29yy)).map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|||
BigDecimal performance = CalculationUtil.getPerformance(electricityUsage, new BigDecimal(10000), 2); |
|||
photovoltaicOverviewDTO.setElectricityUsage(performance); |
|||
BigDecimal internetUsage = tsKvDTOList.stream().filter(s -> StringUtils.equals(s.getAttrKey(), attrA30yy)).map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|||
photovoltaicOverviewDTO.setInternetUsage(internetUsage); |
|||
//年节能量 |
|||
BigDecimal energySaveUsage = CalculationUtil.getCarbonUsage(electricityUsage, energySaveFactor, coefficient, 2); |
|||
photovoltaicOverviewDTO.setEnergySaveUsage(energySaveUsage); |
|||
//年减排量 |
|||
BigDecimal reductionUsage = CalculationUtil.getCarbonUsage(electricityUsage, reductionFactor, coefficient, 2); |
|||
photovoltaicOverviewDTO.setReductionUsage(reductionUsage); |
|||
} |
|||
} |
|||
} |
|||
return photovoltaicOverviewDTO; |
|||
} |
|||
|
|||
@Override |
|||
public PhotovoltaicDTO findById(Long plantId) { |
|||
PhotovoltaicDTO photovoltaicDTO = plantService.getByIdAs(plantId, PhotovoltaicDTO.class); |
|||
if (ObjectUtil.isNull(photovoltaicDTO)) { |
|||
throw new SysException("电站信息不存在,请重新选择"); |
|||
} |
|||
Optional<IotThingEntityDTO> entityByCode = thingEntityService.findEntityByCode(String.valueOf(photovoltaicDTO.getPlantId()), UserContext.getRealTenantCode(), true); |
|||
if (entityByCode.isEmpty()) { |
|||
throw new SysException("当前电站实体不存在,请重新选择"); |
|||
} |
|||
List<DeviceDTO> deviceDTOS = iotDeviceService.findByPlantId(photovoltaicDTO.getPlantId(), 2); |
|||
//逆变器数量 |
|||
photovoltaicDTO.setInverterNum(CollectionUtils.size(deviceDTOS)); |
|||
//今日发电量(A29dd)和今日上网量(??) |
|||
List<TsKvDTO> tsKvDTOList = tsKvService.findLatestByCodeAndAttrs(String.valueOf(photovoltaicDTO.getPlantId()), Lists.newArrayList(attrA29dd, attrA30dd), false); |
|||
if (CollectionUtils.isNotEmpty(tsKvDTOList)) { |
|||
BigDecimal a29dd = tsKvDTOList.stream() |
|||
.filter(s -> StringUtils.equals(attrA29dd, s.getAttrKey())) |
|||
.map(s -> new BigDecimal(s.getVal())/*.divide(new BigDecimal("1000"),2, RoundingMode.UP)*/) |
|||
.findFirst() |
|||
.orElse(BigDecimal.ZERO); |
|||
photovoltaicDTO.setElectricityUsage(a29dd); |
|||
//今日减碳排量 |
|||
// BigDecimal carbonUsage = CalculationUtil.getCarbonUsage(a29dd, reductionFactor, coefficient, 2); |
|||
BigDecimal carbonUsage = CalculationUtil.getCarbonUsage(a29dd, reductionFactor, BigDecimal.ONE, 2); |
|||
photovoltaicDTO.setCarbonUsage(carbonUsage); |
|||
//今日上网量 |
|||
BigDecimal internetUsage = tsKvDTOList.stream() |
|||
.filter(s -> StringUtils.equals(attrA30dd, s.getAttrKey())) |
|||
.map(s -> new BigDecimal(s.getVal())) |
|||
.findFirst() |
|||
.orElse(BigDecimal.ZERO); |
|||
photovoltaicDTO.setInternetUsage(internetUsage); |
|||
} |
|||
//调用大华视频接口,获取检测点数,获取正常和总数 |
|||
return photovoltaicDTO; |
|||
} |
|||
|
|||
@Override |
|||
public List<String> findVideoById(Long plantId) { |
|||
//调用大华视频接口,获取最新视频数据 |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public List<ScreenData> getHeatMap() { |
|||
List<PlantEntity> list = plantService.list(); |
|||
if (CollectionUtils.isEmpty(list)) { |
|||
throw new SysException("光伏信息不存在"); |
|||
} |
|||
List<String> entityCodes = list.stream().map(PlantEntity::getPlantId).map(String::valueOf).toList(); |
|||
Optional<List<IotThingEntityDTO>> entityDTOList = thingEntityService.findByCodes(entityCodes, UserContext.getRealTenantCode(), true); |
|||
if (entityDTOList.isEmpty()) { |
|||
throw new SysException("光伏信息不存在"); |
|||
} |
|||
return list.stream().flatMap(s -> { |
|||
ScreenData screenData = new ScreenData(); |
|||
IotThingEntityDTO iotThingEntity = entityDTOList.get().stream().filter(t -> StringUtils.equals(s.getPlantId().toString(), t.getCode())).findFirst().orElse(null); |
|||
if(ObjectUtil.isNotNull(iotThingEntity)){ |
|||
screenData.setId(s.getPlantId()); |
|||
screenData.setName(iotThingEntity.getName()); |
|||
screenData.setLon(s.getLongitude()); |
|||
screenData.setLat(s.getLatitude()); |
|||
List<ScreenData.AttrData> attrDataList = Lists.newArrayList(); |
|||
//装机容量单独处理 |
|||
ScreenData.AttrData attrCapacity = getAttr(null, "capacity", "装机容量", "kWp", s.getCapacity()); |
|||
attrDataList.add(attrCapacity); |
|||
//日发电量,日上网量,实时功率 |
|||
List<TsKvDTO> tsKvDTOList = tsKvService.findLatestByCodeAndAttrs(String.valueOf(s.getPlantId()), Lists.newArrayList(attrA29dd, attrA30dd, attrA16), false); |
|||
//发电功率 |
|||
ScreenData.AttrData attr16 = getAttr(tsKvDTOList, attrA16, "发电功率", "W", BigDecimal.ZERO); |
|||
attrDataList.add(attr16); |
|||
//日发电量 |
|||
ScreenData.AttrData attrA29 = getAttr(tsKvDTOList, attrA29dd, "日发电量", "kWh", BigDecimal.ZERO); |
|||
attrDataList.add(attrA29); |
|||
BigDecimal dayUsage = filterAttrVal(tsKvDTOList, attrA29dd); |
|||
screenData.setMeasure(dayUsage); |
|||
//日上网量 |
|||
ScreenData.AttrData attrA30 = getAttr(tsKvDTOList, attrA30dd, "日上网量", "kWh", BigDecimal.ZERO); |
|||
attrDataList.add(attrA30); |
|||
//性能比 |
|||
ScreenData.AttrData performance = getAttr(null, "performance", "性能比", "", |
|||
CalculationUtil.getPerformance(filterAttrVal(tsKvDTOList, attrA16).divide(new BigDecimal("1000")), s.getCapacity(), 2)); |
|||
attrDataList.add(performance); |
|||
screenData.setData(attrDataList); |
|||
return Stream.of(screenData); |
|||
} |
|||
return null; |
|||
}).collect(Collectors.toList()); |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, List<TsKvDTO>> getPowerAnalysis(Long plantId, String type) { |
|||
Map<String, List<TsKvDTO>> result = new HashMap<>(); |
|||
Optional<IotThingEntityDTO> entityByCode = thingEntityService.findEntityByCode(plantId.toString(), UserContext.getRealTenantCode(), true); |
|||
//获取今天的开始时间和结束时间 |
|||
String dayBeginTime = DateTimeUtils.getDayBeginTime(); |
|||
Long startTimeT = DateTimeUtils.convertTimeToLong(dayBeginTime); |
|||
//获取昨天的开始时间和结束时间 |
|||
Long endTimeT = startTimeT + ONE_DAY - 1; |
|||
Long startTimeY = startTimeT - ONE_DAY; |
|||
Long endTimeY = startTimeT - 1; |
|||
String attrCode; |
|||
if (StringUtils.equals(type, "2")) { |
|||
attrCode = attrA30hh; |
|||
} else { |
|||
attrCode = attrA16; |
|||
} |
|||
List<TsKvDTO> tsKvDTOST = tsKvService.findTsKvByCodeAndAttr(entityByCode.get().getCode(), attrCode, startTimeT, endTimeT, true); |
|||
tsKvDTOST.forEach(temp->{ |
|||
temp.setTs(getStartOfHour(temp.getTs())); |
|||
}); |
|||
List<TsKvDTO> distinctAndSortedTsKvDTOST = tsKvDTOST.stream() |
|||
// 按 ts 字段去重,保留每个 ts 的第一个出现的对象 |
|||
.collect(Collectors.collectingAndThen( |
|||
Collectors.toMap( |
|||
TsKvDTO::getTs, // 假设 TsKvDTO 有 getTs() 方法 |
|||
tsKvDTO -> tsKvDTO, |
|||
(existing, replacement) -> existing), |
|||
map -> map.values().stream().sorted( |
|||
(o1, o2) -> o1.getTs().compareTo(o2.getTs()) // 按 ts 字段升序排序 |
|||
).collect(Collectors.toList()) |
|||
)); |
|||
List<TsKvDTO> tsKvDTOSY = tsKvService.findTsKvByCodeAndAttr(entityByCode.get().getCode(), attrCode, startTimeY, endTimeY, true); |
|||
tsKvDTOSY.forEach(temp->{ |
|||
temp.setTs(getStartOfHour(temp.getTs())); |
|||
}); |
|||
List<TsKvDTO> distinctAndSortedTsKvDTOSY = tsKvDTOSY.stream() |
|||
// 按 ts 字段去重,保留每个 ts 的第一个出现的对象 |
|||
.collect(Collectors.collectingAndThen( |
|||
Collectors.toMap( |
|||
TsKvDTO::getTs, // 假设 TsKvDTO 有 getTs() 方法 |
|||
tsKvDTO -> tsKvDTO, |
|||
(existing, replacement) -> existing), |
|||
map -> map.values().stream().sorted( |
|||
(o1, o2) -> o1.getTs().compareTo(o2.getTs()) // 按 ts 字段升序排序 |
|||
).collect(Collectors.toList()) |
|||
)); |
|||
List<TsKvDTO> yyTskv = Lists.newArrayList(); |
|||
for (int i = 0; i < distinctAndSortedTsKvDTOSY.size(); i++) { |
|||
//本期的数据 |
|||
TsKvDTO tsKvDTOY = distinctAndSortedTsKvDTOSY.get(i); |
|||
Long ts = tsKvDTOY.getTs(); |
|||
//同期的数据 |
|||
List<TsKvDTO> tsKvDTOT = distinctAndSortedTsKvDTOST.stream().filter(s->s.getTs().compareTo(ts) == 0 ).toList(); |
|||
if(CollectionUtil.isEmpty(tsKvDTOT)){ |
|||
TsKvDTO yy = new TsKvDTO(tsKvDTOY.getThingCode(), tsKvDTOY.getAttrKey(), ts, "0"); |
|||
yyTskv.add(yy); |
|||
}else{ |
|||
BigDecimal yoy = CalculationUtil.getYOY(new BigDecimal(tsKvDTOT.get(0).getVal()), new BigDecimal(tsKvDTOY.getVal())); |
|||
TsKvDTO yy = new TsKvDTO(tsKvDTOY.getThingCode(), tsKvDTOY.getAttrKey(), ts, yoy.toString()); |
|||
yyTskv.add(yy); |
|||
|
|||
} |
|||
tsKvDTOY.setVal(new BigDecimal(tsKvDTOY.getVal()).divide(new BigDecimal(1000),2,RoundingMode.HALF_UP).toString()); |
|||
} |
|||
for (int i = 0; i < distinctAndSortedTsKvDTOST.size(); i++) { |
|||
//本期的数据 |
|||
TsKvDTO tsKvDTOY = distinctAndSortedTsKvDTOST.get(i); |
|||
tsKvDTOY.setVal(new BigDecimal(tsKvDTOY.getVal()).divide(new BigDecimal(1000),2,RoundingMode.HALF_UP).toString()); |
|||
} |
|||
result.put("today", distinctAndSortedTsKvDTOST); |
|||
result.put("yesterday", distinctAndSortedTsKvDTOSY); |
|||
result.put("yy", yyTskv); |
|||
return result; |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 获取指定时间戳所在的整点时间戳 |
|||
* |
|||
* @param timestamp 时间戳 |
|||
* @return 整点时间戳 |
|||
*/ |
|||
public static long getStartOfHour(long timestamp) { |
|||
// 将时间戳截断到整点(小时) |
|||
return (timestamp / 3600000) * 3600000; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public Map<String, List<TsKvDTO>> getElectricPowerAnalysis(Long plantId, String type) { |
|||
Map<String, List<TsKvDTO>> result = new HashMap<>(); |
|||
Optional<IotThingEntityDTO> entityByCode = thingEntityService.findEntityByCode(plantId.toString(), UserContext.getRealTenantCode(), true); |
|||
if (StringUtils.endsWithIgnoreCase(type, ThingAttrType.YY.getTime().getName())) { |
|||
String yearBeginTime = DateTimeUtils.getYearBeginTime(); |
|||
Long startTime = DateTimeUtils.convertTimeToLong(yearBeginTime); |
|||
String yearEndTime = DateTimeUtils.getYearEndTime(); |
|||
Long endTime = DateTimeUtils.convertTimeToLong(yearEndTime); |
|||
//时间列表 |
|||
List<Long> intervalTimeList = DateTimeUtils.getIntervalMonthList(startTime, endTime, 1); |
|||
consumption(entityByCode.get(), startTime, endTime, intervalTimeList, attrA29mm, attrA30mm, 1, TimeType.MONTH, result); |
|||
} |
|||
if (StringUtils.endsWithIgnoreCase(type, ThingAttrType.MM.getTime().getName())) { |
|||
String monthBeginTime = DateTimeUtils.getMonthBeginTime(); |
|||
Long startTime = DateTimeUtils.convertTimeToLong(monthBeginTime); |
|||
String monthEndTime = DateTimeUtils.getMonthEndTime(); |
|||
Long endTime = DateTimeUtils.convertTimeToLong(monthEndTime); |
|||
List<Long> intervalTimeList = DateTimeUtils.getIntervalDayList(startTime, endTime, 1); |
|||
consumption(entityByCode.get(), startTime, endTime, intervalTimeList, attrA29dd, attrA30dd, 1, TimeType.DAY, result); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, List<TsKvDTO>> getInverterDetails(String code) { |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public List<PhotovoltaicReportDTO> getReportElectric(ChargeStatisticRequest chargeStatisticRequest) { |
|||
List<PhotovoltaicReportDTO> resultList = new ArrayList<>(); |
|||
List<Long> thingIds = chargeStatisticRequest.getThingIds(); |
|||
List<IotThingEntityDTO> entities = thingEntityService.findEntityByIds(thingIds); |
|||
if (CollectionUtils.isEmpty(entities)) { |
|||
return resultList; |
|||
} |
|||
List<String> codes = entities.stream().map(IotThingEntityDTO::getCode).toList(); |
|||
String attrType = chargeStatisticRequest.getAttrType(); |
|||
Long startTime = 0L; |
|||
Long endTime = 0L; |
|||
List<Long> timeList = new ArrayList<>(); |
|||
String timeType = chargeStatisticRequest.getTimeType(); |
|||
if (StringUtils.equalsIgnoreCase(TimeType.DAY.getName(), timeType)) { |
|||
String dayBeginTime = DateTimeUtils.getDayBeginTime(chargeStatisticRequest.getBeginTime()); |
|||
startTime = DateTimeUtils.dateToTimestamp(dayBeginTime); |
|||
endTime = startTime + ONE_DAY - 1; |
|||
timeList = DateTimeUtils.getIntervalList(startTime, endTime, 60 * 60 * 1000); |
|||
} |
|||
if (StringUtils.equalsIgnoreCase(TimeType.MONTH.getName(), timeType)) { |
|||
String monthBeginTime = DateTimeUtils.getMonthBeginTime(chargeStatisticRequest.getBeginTime()); |
|||
String monthEndTime = DateTimeUtils.getMonthEndTime(chargeStatisticRequest.getBeginTime()); |
|||
startTime = DateTimeUtils.dateToTimestamp(monthBeginTime); |
|||
endTime = DateTimeUtils.dateToTimestamp(monthEndTime); |
|||
timeList = DateTimeUtils.getIntervalDayList(startTime, endTime, 1); |
|||
} |
|||
if (StringUtils.equalsIgnoreCase(TimeType.YEAR.getName(), timeType)) { |
|||
String monthBeginTime = DateTimeUtils.getYearBeginTime(chargeStatisticRequest.getBeginTime()); |
|||
String monthEndTime = DateTimeUtils.getYearEndTime(chargeStatisticRequest.getBeginTime()); |
|||
startTime = DateTimeUtils.convertTimeToLong(monthBeginTime); |
|||
endTime = DateTimeUtils.convertTimeToLong(monthEndTime); |
|||
timeList = DateTimeUtils.getIntervalMonthList(startTime, endTime, 1); |
|||
} |
|||
if (StringUtils.equalsIgnoreCase(TimeType.ANY.getName(), timeType)) { |
|||
startTime = DateTimeUtils.dateToTimestamp(chargeStatisticRequest.getBeginTime()); |
|||
endTime = DateTimeUtils.dateToTimestamp(chargeStatisticRequest.getEndTime()); |
|||
} |
|||
long currentTime = DateTimeUtils.getCurrentTime(); |
|||
//去除超过的时间 |
|||
timeList.removeIf(s -> CompareUtil.compare(s, currentTime) > 0); |
|||
List<TsKvDTO> tsKvList = tsKvService.findTsKvByCodesAndAttrs(codes, Lists.newArrayList(attrA29 + attrType), startTime, endTime, false); |
|||
|
|||
List<Long> finalTimeList = timeList; |
|||
if (CollectionUtils.isEmpty(tsKvList)) { |
|||
return entities.stream().map(e -> { |
|||
PhotovoltaicReportDTO reportDTO = new PhotovoltaicReportDTO(); |
|||
reportDTO.setThingId(e.getId()); |
|||
reportDTO.setCode(e.getCode()); |
|||
reportDTO.setName(e.getName()); |
|||
reportDTO.setTimeList(finalTimeList); |
|||
return reportDTO; |
|||
}).toList(); |
|||
} |
|||
|
|||
return entities.stream().map(e -> { |
|||
PhotovoltaicReportDTO reportDTO = new PhotovoltaicReportDTO(); |
|||
reportDTO.setThingId(e.getId()); |
|||
reportDTO.setCode(e.getCode()); |
|||
reportDTO.setName(e.getName()); |
|||
reportDTO.setTimeList(finalTimeList); |
|||
//过滤数据 |
|||
List<TsKvDTO> dataList = tsKvList.stream().filter(tsKvDTO -> StringUtils.equals(tsKvDTO.getThingCode(), e.getCode())).toList(); |
|||
|
|||
List<Map<String, Object>> collect = Lists.newArrayList(); |
|||
for (int i = 0; i < finalTimeList.size(); i++) { |
|||
int finalI = i; |
|||
List<TsKvDTO> list; |
|||
if(i== (finalTimeList.size()-1)){ |
|||
list = dataList.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 ) |
|||
.toList(); |
|||
}else { |
|||
list = dataList.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 && CompareUtil.compare(s.getTs(), finalTimeList.get(finalI + 1)) < 0).toList(); |
|||
} |
|||
BigDecimal total = list.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|||
collect.addAll(list.stream().map(data -> Map.<String, Object>of("ts", finalTimeList.get(finalI), "val", total)).toList()); |
|||
|
|||
} |
|||
reportDTO.setPlantDataList(collect); |
|||
BigDecimal total = dataList.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|||
reportDTO.setElectricityUsage(total); |
|||
return reportDTO; |
|||
}).toList(); |
|||
} |
|||
|
|||
@Override |
|||
public void electricExport(ChargeStatisticRequest chargeStatisticRequest, HttpServletResponse response) { |
|||
List<PhotovoltaicReportDTO> reportDTOList = getReportElectric(chargeStatisticRequest); |
|||
//获取动态时间 |
|||
List<Long> timeList = reportDTOList.get(0).getTimeList(); |
|||
//创建表头 |
|||
List<ExcelExportEntity> tableHeaderList = getTableHeader(timeList, chargeStatisticRequest.getTimeType()); |
|||
|
|||
if (CollectionUtils.isEmpty(reportDTOList)) { |
|||
ExportParams exportParams = new ExportParams("发电统计报表", "发电统计"); |
|||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, tableHeaderList, Lists.newArrayList()); |
|||
ExcelUtils.downLoadExcel("发电统计报表.xls", response, workbook); |
|||
} |
|||
List<Map<String, Object>> dataList = new ArrayList<>(); |
|||
for (PhotovoltaicReportDTO photovoltaicReportDTO : reportDTOList) { |
|||
Map<String, Object> valMap = new HashMap<>(); |
|||
valMap.put("name", photovoltaicReportDTO.getName()); |
|||
valMap.put("electricityUsage", photovoltaicReportDTO.getElectricityUsage()); |
|||
List<Map<String, Object>> plantDataList = photovoltaicReportDTO.getPlantDataList(); |
|||
if (CollectionUtils.isNotEmpty(plantDataList)) { |
|||
for (Map<String, Object> plantData : plantDataList) { |
|||
Long ts = MapUtils.getLong(plantData, "ts"); |
|||
String val = MapUtils.getString(plantData, "val"); |
|||
valMap.put(String.valueOf(ts), val); |
|||
} |
|||
} |
|||
dataList.add(valMap); |
|||
} |
|||
ExportParams exportParams = new ExportParams("发电统计报表", "发电统计"); |
|||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, tableHeaderList, dataList); |
|||
ExcelUtils.downLoadExcel("发电统计报表.xls", response, workbook); |
|||
} |
|||
|
|||
@Override |
|||
public List<PhotovoltaicReportDTO> getReportConsumption(ChargeStatisticRequest chargeStatisticRequest) { |
|||
List<PhotovoltaicReportDTO> resultList = new ArrayList<>(); |
|||
List<Long> thingIds = chargeStatisticRequest.getThingIds(); |
|||
List<IotThingEntityDTO> entities = thingEntityService.findEntityByIds(thingIds); |
|||
if (CollectionUtils.isEmpty(entities)) { |
|||
return resultList; |
|||
} |
|||
List<String> codes = entities.stream().map(IotThingEntityDTO::getCode).toList(); |
|||
String attrType = chargeStatisticRequest.getAttrType(); |
|||
Long startTime = 0L; |
|||
Long endTime = 0L; |
|||
List<Long> timeList = new ArrayList<>(); |
|||
String timeType = chargeStatisticRequest.getTimeType(); |
|||
if (StringUtils.equalsIgnoreCase(TimeType.DAY.getName(), timeType)) { |
|||
String dayBeginTime = DateTimeUtils.getDayBeginTime(chargeStatisticRequest.getBeginTime()); |
|||
startTime = DateTimeUtils.dateToTimestamp(dayBeginTime); |
|||
endTime = startTime + ONE_DAY - 1; |
|||
timeList = DateTimeUtils.getIntervalList(startTime, endTime, 60 * 60 * 1000); |
|||
} |
|||
if (StringUtils.equalsIgnoreCase(TimeType.MONTH.getName(), timeType)) { |
|||
String monthBeginTime = DateTimeUtils.getMonthBeginTime(chargeStatisticRequest.getBeginTime()); |
|||
String monthEndTime = DateTimeUtils.getMonthEndTime(chargeStatisticRequest.getBeginTime()); |
|||
startTime = DateTimeUtils.dateToTimestamp(monthBeginTime); |
|||
endTime = DateTimeUtils.dateToTimestamp(monthEndTime); |
|||
timeList = DateTimeUtils.getIntervalDayList(startTime, endTime, 1); |
|||
} |
|||
|
|||
if (StringUtils.equalsIgnoreCase(TimeType.YEAR.getName(), timeType)) { |
|||
String monthBeginTime = DateTimeUtils.getYearBeginTime(chargeStatisticRequest.getBeginTime()); |
|||
String monthEndTime = DateTimeUtils.getYearEndTime(chargeStatisticRequest.getBeginTime()); |
|||
startTime = DateTimeUtils.convertTimeToLong(monthBeginTime); |
|||
endTime = DateTimeUtils.convertTimeToLong(monthEndTime); |
|||
timeList = DateTimeUtils.getIntervalMonthList(startTime, endTime, 1); |
|||
} |
|||
if (StringUtils.equalsIgnoreCase(TimeType.ANY.getName(), timeType)) { |
|||
startTime = DateTimeUtils.dateToTimestamp(chargeStatisticRequest.getBeginTime()); |
|||
endTime = DateTimeUtils.dateToTimestamp(chargeStatisticRequest.getEndTime()); |
|||
} |
|||
|
|||
long currentTime = DateTimeUtils.getCurrentTime(); |
|||
//去除超过的时间 |
|||
timeList.removeIf(s -> CompareUtil.compare(s, currentTime) > 0); |
|||
//发电量 |
|||
List<TsKvDTO> tsKvList29 = getFillDataList(codes, attrA29 + attrType, startTime, endTime, timeList); |
|||
//上网量 |
|||
List<TsKvDTO> tsKvList30 = getFillDataList(codes, attrA30 + attrType, startTime, endTime, timeList); |
|||
//获取总量 |
|||
List<Long> finalTimeList = timeList; |
|||
entities.forEach(e -> { |
|||
PhotovoltaicReportDTO photovoltaicReportDTO = new PhotovoltaicReportDTO(); |
|||
photovoltaicReportDTO.setThingId(e.getId()); |
|||
photovoltaicReportDTO.setCode(e.getCode()); |
|||
photovoltaicReportDTO.setName(e.getName()); |
|||
photovoltaicReportDTO.setTimeList(finalTimeList); |
|||
List<TsKvDTO> list29 = tsKvList29.stream().filter(tsKvDTO -> StringUtils.equals(tsKvDTO.getThingCode(), e.getCode()) && StringUtils.startsWith(tsKvDTO.getAttrKey(), attrA29)).toList(); |
|||
BigDecimal reduce29 = list29.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|||
List<TsKvDTO> list30 = tsKvList30.stream().filter(tsKvDTO -> StringUtils.equals(tsKvDTO.getThingCode(), e.getCode()) && StringUtils.startsWith(tsKvDTO.getAttrKey(), attrA30)).toList(); |
|||
BigDecimal reduce30 = list30.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|||
//消纳量 = 发电量 - 上网量 |
|||
BigDecimal consumption = reduce29.subtract(reduce30); |
|||
//消纳率 |
|||
BigDecimal performance = CalculationUtil.getPerformance(consumption, reduce29, 4); |
|||
PhotovoltaicConsumptionDTO consumptionTotal = new PhotovoltaicConsumptionDTO(); |
|||
consumptionTotal.setElectricityUsage(reduce29); |
|||
consumptionTotal.setInternetUsage(reduce30); |
|||
consumptionTotal.setConsumptionUsage(consumption); |
|||
consumptionTotal.setConsumptionRate(performance); |
|||
photovoltaicReportDTO.setConsumptionTotal(consumptionTotal); |
|||
//时间段的消纳报表数据 |
|||
List<PhotovoltaicConsumptionDTO> consumptionDTOList = Lists.newArrayList(); |
|||
|
|||
for (int i = 0; i < finalTimeList.size(); i++) { |
|||
int finalI = i; |
|||
List<TsKvDTO> list2; |
|||
List<TsKvDTO> list3; |
|||
if(i== (finalTimeList.size()-1)){ |
|||
list2 = list29.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 ) |
|||
.toList(); |
|||
list3 = list30.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 ) |
|||
.toList(); |
|||
}else { |
|||
list2 = list29.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 && CompareUtil.compare(s.getTs(), finalTimeList.get(finalI + 1)) < 0) |
|||
.toList(); |
|||
list3 = list30.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 && CompareUtil.compare(s.getTs(), finalTimeList.get(finalI + 1)) < 0) |
|||
.toList(); |
|||
} |
|||
BigDecimal reduce2 = list2.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|||
BigDecimal reduce3 = list3.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|||
PhotovoltaicConsumptionDTO consumptionDTO = new PhotovoltaicConsumptionDTO(); |
|||
consumptionDTO.setElectricityUsage(reduce2); |
|||
consumptionDTO.setInternetUsage(reduce3); |
|||
BigDecimal subtract = reduce2.subtract(reduce3); |
|||
consumptionDTO.setConsumptionUsage(subtract); |
|||
consumptionDTO.setConsumptionRate(CalculationUtil.getPerformance(subtract, reduce2, 4)); |
|||
consumptionDTO.setTs(finalTimeList.get(finalI)); |
|||
consumptionDTOList.add(consumptionDTO); |
|||
} |
|||
photovoltaicReportDTO.setConsumptionDataList(consumptionDTOList); |
|||
resultList.add(photovoltaicReportDTO); |
|||
}); |
|||
return resultList; |
|||
} |
|||
|
|||
@Override |
|||
public void consumptionExport(ChargeStatisticRequest chargeStatisticRequest, HttpServletResponse response) { |
|||
try { |
|||
List<PhotovoltaicReportDTO> reportDTOList = getReportConsumption(chargeStatisticRequest); |
|||
//获取动态时间 |
|||
List<Long> timeList = reportDTOList.get(0).getTimeList(); |
|||
//创建表头 |
|||
List<ExcelExportEntity> tableHeaderList = getConsumptionTableHeader(timeList, chargeStatisticRequest.getTimeType()); |
|||
if (CollectionUtils.isEmpty(reportDTOList)) { |
|||
ExportParams exportParams = new ExportParams("上网消纳报表", "上网消纳"); |
|||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, tableHeaderList, Lists.newArrayList()); |
|||
ExcelUtils.downLoadExcel("上网消纳报表.xls", response, workbook); |
|||
} |
|||
List<Map<String, Object>> dataList = new ArrayList<>(); |
|||
for (PhotovoltaicReportDTO photovoltaicReportDTO : reportDTOList) { |
|||
Map<String, Object> valMap = new HashMap<>(); |
|||
valMap.put("name", photovoltaicReportDTO.getName()); |
|||
//发电总量的数据 |
|||
PhotovoltaicConsumptionDTO consumptionTotal = photovoltaicReportDTO.getConsumptionTotal(); |
|||
List<Map<String, Object>> yhxxList = new ArrayList<>(); |
|||
Map<String, Object> yhxxMap = new HashMap<>(); |
|||
yhxxMap.put("electricityUsage", consumptionTotal.getElectricityUsage()); |
|||
yhxxMap.put("consumptionUsage", consumptionTotal.getConsumptionUsage()); |
|||
yhxxMap.put("internetUsage", consumptionTotal.getInternetUsage()); |
|||
yhxxMap.put("consumptionRate", consumptionTotal.getConsumptionRate()); |
|||
yhxxList.add(yhxxMap); |
|||
valMap.put("electricityUsage", yhxxList); |
|||
//动态时间量 |
|||
List<PhotovoltaicConsumptionDTO> consumptionDataList = photovoltaicReportDTO.getConsumptionDataList(); |
|||
consumptionDataList.forEach(c -> { |
|||
// int time = 0; |
|||
// if (StringUtils.equalsIgnoreCase(TimeType.DAY.getName(), chargeStatisticRequest.getTimeType())){ |
|||
// time = DateTimeUtils.parseDateTime(c.getTs()).getHour(); |
|||
// } |
|||
// if (StringUtils.equalsIgnoreCase(TimeType.MONTH.getName(), chargeStatisticRequest.getTimeType())){ |
|||
// time = DateTimeUtils.parseDateTime(c.getTs()).getDayOfMonth(); |
|||
// } |
|||
// if (StringUtils.equalsIgnoreCase(TimeType.YEAR.getName(), chargeStatisticRequest.getTimeType())){ |
|||
// time = DateTimeUtils.parseDateTime(c.getTs()).getMonth().getValue(); |
|||
// } |
|||
List<Map<String, Object>> yhxxList1 = new ArrayList<>(); |
|||
Map<String, Object> yhxxMap1 = new HashMap<>(); |
|||
yhxxMap1.put("electricityUsage", c.getElectricityUsage()); |
|||
yhxxMap1.put("consumptionUsage", c.getConsumptionUsage()); |
|||
yhxxMap1.put("internetUsage", c.getInternetUsage()); |
|||
yhxxMap1.put("consumptionRate", c.getConsumptionRate()); |
|||
yhxxList1.add(yhxxMap1); |
|||
valMap.put(String.valueOf(c.getTs()), yhxxList1); |
|||
}); |
|||
dataList.add(valMap); |
|||
} |
|||
ExportParams exportParams = new ExportParams("发电统计报表", "发电统计"); |
|||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, tableHeaderList, dataList); |
|||
ExcelUtils.downLoadExcel("发电统计报表.xls", response, workbook); |
|||
} catch (Exception e) { |
|||
log.error("222222", e); |
|||
} |
|||
} |
|||
|
|||
private List<TsKvDTO> getFillDataList(List<String> codes, String attr, Long startTime, Long endTime, List<Long> timeList) { |
|||
List<TsKvDTO> tsKvList29 = tsKvService.findTsKvByCodesAndAttrs(codes, Lists.newArrayList(attr), startTime, endTime, false); |
|||
return codes.stream().flatMap(s -> fillData(timeList, tsKvList29, s, attr).stream()).toList(); |
|||
} |
|||
|
|||
private void consumption(IotThingEntityDTO thingEntityDTO, Long startTime, Long endTime, List<Long> intervalTimeList, String attrA29, String attrA30, Integer interval, TimeType timeType, Map<String, List<TsKvDTO>> result) { |
|||
//月发电量 |
|||
List<TsKvDTO> tsKvYYList = tsKvService.findTsKvByCodeAndAttr(thingEntityDTO.getCode(), attrA29, startTime, endTime, true); |
|||
//补全数据 |
|||
List<TsKvDTO> tsKvDTOS = fillData(intervalTimeList, tsKvYYList, thingEntityDTO.getCode(), attrA29); |
|||
//月上网量 |
|||
List<TsKvDTO> tsKvYY30List = tsKvService.findTsKvByCodeAndAttr(thingEntityDTO.getCode(), attrA30, startTime, endTime, true); |
|||
//List<TsKvDTO> tsKvYY30List = tsKvService.findTsKvIntervalAggByCodeAndAttr(thingEntityDTO.getCode(), attrA30, startTime, endTime, AggType.SUM, interval, timeType, true); |
|||
//补全数据 |
|||
List<TsKvDTO> tsKv30DTOS = fillData(intervalTimeList, tsKvYY30List, thingEntityDTO.getCode(), attrA30); |
|||
//消纳量 |
|||
List<TsKvDTO> consumptionTskv = Lists.newArrayList(); |
|||
List<TsKvDTO> consumptionTskvRate = Lists.newArrayList(); |
|||
for (int i = 0; i < tsKvDTOS.size(); i++) { |
|||
TsKvDTO tsKvDTO29 = tsKvDTOS.get(i); |
|||
tsKvDTO29.setVal(new BigDecimal(tsKvDTO29.getVal())/*.divide(new BigDecimal(1000), 2, BigDecimal.ROUND_HALF_UP)*/.toPlainString()); |
|||
TsKvDTO tsKvDTO30 = tsKv30DTOS.get(i); |
|||
//消纳量 |
|||
BigDecimal consumption = new BigDecimal(tsKvDTO29.getVal()).subtract(new BigDecimal(tsKvDTO30.getVal())); |
|||
TsKvDTO tsKv = new TsKvDTO(thingEntityDTO.getCode(), "consumption", tsKvDTO29.getTs(), consumption.toString()); |
|||
consumptionTskv.add(tsKv); |
|||
//消纳比 |
|||
BigDecimal consumptionPerformance = CalculationUtil.getPerformance(consumption, new BigDecimal(tsKvDTO29.getVal()), 4); |
|||
TsKvDTO tsKvDTO = new TsKvDTO(thingEntityDTO.getCode(), "consumptionRate", tsKvDTO29.getTs(), consumptionPerformance.toString()); |
|||
consumptionTskvRate.add(tsKvDTO); |
|||
} |
|||
result.put("A29", tsKvDTOS); |
|||
result.put("consumption",consumptionTskv); |
|||
result.put("consumptionRate", consumptionTskvRate); |
|||
} |
|||
|
|||
|
|||
private ScreenData.AttrData getAttr(List<TsKvDTO> tsKvDTOList, String attrCode, String attrName, String attrUnit, BigDecimal defaultVal) { |
|||
ScreenData.AttrData attrData = new ScreenData.AttrData(); |
|||
attrData.setAttrCode(attrCode); |
|||
attrData.setAttrName(attrName); |
|||
attrData.setAttrUnit(attrUnit); |
|||
if (CollectionUtils.isNotEmpty(tsKvDTOList)) { |
|||
if(attrCode.startsWith(attrA29)){ |
|||
//attrData.setAttrValue(filterAttrVal(tsKvDTOList, attrCode).toString()); |
|||
attrData.setAttrValue(filterAttrVal(tsKvDTOList, attrCode)/*.divide(new BigDecimal("1000"),2, RoundingMode.UP)*/.toPlainString()); |
|||
}else { |
|||
attrData.setAttrValue(filterAttrVal(tsKvDTOList, attrCode).divide(new BigDecimal("1000"),2, RoundingMode.UP).toPlainString()); |
|||
} |
|||
} else { |
|||
attrData.setAttrValue(defaultVal.toString()); |
|||
} |
|||
return attrData; |
|||
} |
|||
|
|||
private static BigDecimal filterAttrVal(List<TsKvDTO> tsKvDTOList, String attrCode) { |
|||
return tsKvDTOList.stream() |
|||
.filter(d -> StringUtils.equals(attrCode, d.getAttrKey())) |
|||
.map(d -> new BigDecimal(d.getVal())) |
|||
.findFirst() |
|||
.orElse(BigDecimal.ZERO); |
|||
} |
|||
|
|||
private static List<TsKvDTO> fillData(List<Long> intervalTimeList, List<TsKvDTO> tsKvList, String code, String attr) { |
|||
if (CollectionUtils.isEmpty(tsKvList)) { |
|||
return intervalTimeList.stream() |
|||
.map(s -> new TsKvDTO(code, attr, s, "0")) |
|||
.collect(Collectors.toList()); |
|||
} |
|||
if(CollectionUtils.isEmpty(intervalTimeList)){ |
|||
return tsKvList; |
|||
} |
|||
List<TsKvDTO> handleList = tsKvList.stream().filter(d -> StringUtils.equals(code, d.getThingCode()) && StringUtils.equals(attr, d.getAttrKey())).toList(); |
|||
Map<String, Map<String, List<TsKvDTO>>> groupedMap = handleList.stream() |
|||
.collect(Collectors.groupingBy(TsKvDTO::getThingCode, |
|||
Collectors.groupingBy(TsKvDTO::getAttrKey))); |
|||
List<TsKvDTO> result = new ArrayList<>(); |
|||
for (Map.Entry<String, Map<String, List<TsKvDTO>>> stringMapEntry : groupedMap.entrySet()) { |
|||
String thingCode = stringMapEntry.getKey(); |
|||
for (Map.Entry<String, List<TsKvDTO>> stringListEntry : stringMapEntry.getValue().entrySet()) { |
|||
String attrKey = stringListEntry.getKey(); |
|||
List<TsKvDTO> value = stringListEntry.getValue(); |
|||
List<Long> existingTimestamps = value.stream().map(TsKvDTO::getTs).toList(); |
|||
for (Long timestamp : intervalTimeList) { |
|||
if (existingTimestamps.contains(timestamp)) { |
|||
TsKvDTO tsKvDTO1 = value.stream() |
|||
.filter(tsKvDTO -> tsKvDTO.getTs().equals(timestamp)) |
|||
.findAny().orElse(null); |
|||
//电力要/1000 |
|||
if (ObjectUtil.isNotNull(tsKvDTO1) && tsKvDTO1.getAttrKey().startsWith(attrA16)) { |
|||
BigDecimal performance = CalculationUtil.getPerformance(new BigDecimal(tsKvDTO1.getVal()), new BigDecimal(1000), 2); |
|||
tsKvDTO1.setVal(performance.toString()); |
|||
} |
|||
result.add(tsKvDTO1); |
|||
} else { |
|||
result.add(new TsKvDTO(thingCode, attrKey, timestamp, "0")); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
private List<ExcelExportEntity> getConsumptionTableHeader(List<Long> timeList, String timeType) { |
|||
List<ExcelExportEntity> paramCols = new ArrayList<>(); |
|||
ExcelExportEntity colEntity1 = new ExcelExportEntity("结构", "name"); |
|||
colEntity1.setNeedMerge(true); |
|||
paramCols.add(colEntity1); |
|||
ExcelExportEntity colEntity2 = new ExcelExportEntity("发电总量(kWh)", "electricityUsage"); |
|||
List<ExcelExportEntity> yyxxList = new ArrayList<>(); |
|||
yyxxList.add(new ExcelExportEntity("发电量", "electricityUsage")); |
|||
yyxxList.add(new ExcelExportEntity("消纳量", "consumptionUsage")); |
|||
yyxxList.add(new ExcelExportEntity("上网量", "internetUsage")); |
|||
yyxxList.add(new ExcelExportEntity("消纳率", "consumptionRate")); |
|||
colEntity2.setList(yyxxList); |
|||
paramCols.add(colEntity2); |
|||
//动态表头集合 |
|||
paramCols.addAll(new ArrayList<>(timeList.stream() |
|||
.flatMap(c -> { |
|||
ExcelExportEntity excelExportEntity = null; |
|||
if (StringUtils.equalsIgnoreCase(TimeType.DAY.getName(), timeType)) { |
|||
int hour = DateTimeUtils.parseDateTime(c).getHour(); |
|||
excelExportEntity = new ExcelExportEntity(hour + "时", String.valueOf(c)); |
|||
} |
|||
if (StringUtils.equalsIgnoreCase(TimeType.MONTH.getName(), timeType)) { |
|||
int day = DateTimeUtils.parseDateTime(c).getDayOfMonth(); |
|||
excelExportEntity = new ExcelExportEntity(day + "日", String.valueOf(c)); |
|||
} |
|||
if (StringUtils.equalsIgnoreCase(TimeType.YEAR.getName(), timeType)) { |
|||
int month = DateTimeUtils.parseDateTime(c).getMonth().getValue(); |
|||
excelExportEntity = new ExcelExportEntity(month + "月", String.valueOf(c)); |
|||
} |
|||
List<ExcelExportEntity> yyxxList1 = new ArrayList<>(); |
|||
yyxxList1.add(new ExcelExportEntity("发电量", "electricityUsage")); |
|||
yyxxList1.add(new ExcelExportEntity("消纳量", "consumptionUsage")); |
|||
yyxxList1.add(new ExcelExportEntity("上网量", "internetUsage")); |
|||
yyxxList1.add(new ExcelExportEntity("消纳率", "consumptionRate")); |
|||
if (ObjectUtil.isNotNull(excelExportEntity)) { |
|||
excelExportEntity.setList(yyxxList1); |
|||
return Stream.of(excelExportEntity); |
|||
} |
|||
return Stream.empty(); |
|||
}).toList())); |
|||
return paramCols; |
|||
} |
|||
|
|||
private List<ExcelExportEntity> getTableHeader(List<Long> timeList, String timeType) { |
|||
List<ExcelExportEntity> paramCols = new ArrayList<>(); |
|||
ExcelExportEntity colEntity1 = new ExcelExportEntity("结构", "name"); |
|||
paramCols.add(colEntity1); |
|||
ExcelExportEntity colEntity2 = new ExcelExportEntity("发电总量(kWh)", "electricityUsage"); |
|||
paramCols.add(colEntity2); |
|||
//动态表头集合 |
|||
paramCols.addAll(new ArrayList<>(timeList.stream() |
|||
.flatMap(c -> { |
|||
if (StringUtils.equalsIgnoreCase(TimeType.DAY.getName(), timeType)) { |
|||
int hour = DateTimeUtils.parseDateTime(c).getHour(); |
|||
return Stream.of(new ExcelExportEntity(hour + "时", String.valueOf(c))); |
|||
} |
|||
if (StringUtils.equalsIgnoreCase(TimeType.MONTH.getName(), timeType)) { |
|||
int day = DateTimeUtils.parseDateTime(c).getDayOfMonth(); |
|||
return Stream.of(new ExcelExportEntity(day + "日", String.valueOf(c))); |
|||
} |
|||
if (StringUtils.equalsIgnoreCase(TimeType.YEAR.getName(), timeType)) { |
|||
int month = DateTimeUtils.parseDateTime(c).getMonth().getValue(); |
|||
return Stream.of(new ExcelExportEntity(month + "月", String.valueOf(c))); |
|||
} |
|||
return Stream.empty(); |
|||
}).toList())); |
|||
return paramCols; |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue