Browse Source

#综合报表

zhongwei
yang_shj 3 months ago
parent
commit
7069843ced
  1. 65
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/ComprehensiveElectricVo.java
  2. 2
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/DeviceElectricVo.java
  3. 2
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/TableHeadVo.java
  4. 10
      hzims-service/equipment/src/main/java/com/hnac/hzims/electric/controller/ElectricReportController.java
  5. 5
      hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/IElectricReportService.java
  6. 114
      hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java

65
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/ComprehensiveElectricVo.java

@ -0,0 +1,65 @@
package com.hnac.hzims.electric.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author ysj
*/
@Data
public class ComprehensiveElectricVo {
@ApiModelProperty(value = "月份")
private String month;
@ApiModelProperty(value = "本月电量")
private Double monthGenerate;
@ApiModelProperty(value = "去年同月")
private Double lastMonthGenerate;
@ApiModelProperty(value = "月同比")
private Double lastMonthGenerateRate;
@ApiModelProperty(value = "年发电量")
private Double yearGenerate;
@ApiModelProperty(value = "去年同期")
private Double lastYearGenerate;
@ApiModelProperty(value = "年同比")
private Double lastYearGenerateRate;
@ApiModelProperty(value = "本月降雨")
private Double monthRain;
@ApiModelProperty(value = "去年同月")
private Double lastMonthRain;
@ApiModelProperty(value = "月同比")
private Double lastMonthRainRate;
@ApiModelProperty(value = "年降雨量")
private Double yearRain;
@ApiModelProperty(value = "去年同期")
private Double lastYearRain;
@ApiModelProperty(value = "年同比")
private Double lastYearRainRate;
@ApiModelProperty(value = "本月等效小时")
private Double monthEquivalent;
@ApiModelProperty(value = "去年同月")
private Double lastMonthEquivalent;
@ApiModelProperty(value = "年等效小时")
private Double yearEquivalent;
@ApiModelProperty(value = "去年同期")
private Double lastYearEquivalent;
}

2
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/DeviceElectricVo.java

@ -5,7 +5,7 @@ import lombok.Data;
/** /**
* @author 表头 * @author ysj
*/ */
@Data @Data
public class DeviceElectricVo { public class DeviceElectricVo {

2
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/TableHeadVo.java

@ -7,7 +7,7 @@ import java.util.List;
/** /**
* @author 表头 * @author ysj
*/ */
@Data @Data
public class TableHeadVo { public class TableHeadVo {

10
hzims-service/equipment/src/main/java/com/hnac/hzims/electric/controller/ElectricReportController.java

@ -2,6 +2,7 @@ package com.hnac.hzims.electric.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.electric.service.IElectricReportService; import com.hnac.hzims.electric.service.IElectricReportService;
import com.hnac.hzims.electric.vo.ComprehensiveElectricVo;
import com.hnac.hzims.equipment.entity.EmAssociationEntity; import com.hnac.hzims.equipment.entity.EmAssociationEntity;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -35,4 +37,12 @@ public class ElectricReportController extends BladeController {
@RequestParam(value = "time") String time) { @RequestParam(value = "time") String time) {
return R.data(service.basics(deptId,type,time)); return R.data(service.basics(deptId,type,time));
} }
@GetMapping("/comprehensive")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "综合报表", notes = "传入 deptId")
public R<List<ComprehensiveElectricVo>> comprehensive(@RequestParam(value = "deptId") Long deptId,
@RequestParam(value = "year") String year) {
return R.data(service.comprehensive(deptId,year));
}
} }

5
hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/IElectricReportService.java

@ -1,5 +1,8 @@
package com.hnac.hzims.electric.service; package com.hnac.hzims.electric.service;
import com.hnac.hzims.electric.vo.ComprehensiveElectricVo;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -9,4 +12,6 @@ public interface IElectricReportService {
Map<String, Object> basics(Long deptId, Long type,String time); Map<String, Object> basics(Long deptId, Long type,String time);
List<ComprehensiveElectricVo> comprehensive(Long deptId,String year);
} }

114
hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java

@ -1,6 +1,9 @@
package com.hnac.hzims.electric.service.impl; package com.hnac.hzims.electric.service.impl;
import cn.hutool.core.io.unit.DataUnit;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.electric.entity.ThirtyEntity; import com.hnac.hzims.electric.entity.ThirtyEntity;
@ -8,17 +11,15 @@ import com.hnac.hzims.electric.entity.ThreeEntity;
import com.hnac.hzims.electric.service.IElectricReportService; import com.hnac.hzims.electric.service.IElectricReportService;
import com.hnac.hzims.electric.service.ThirtyService; import com.hnac.hzims.electric.service.ThirtyService;
import com.hnac.hzims.electric.service.ThreeService; import com.hnac.hzims.electric.service.ThreeService;
import com.hnac.hzims.electric.vo.ComprehensiveElectricVo;
import com.hnac.hzims.electric.vo.DeviceElectricVo; import com.hnac.hzims.electric.vo.DeviceElectricVo;
import com.hnac.hzims.electric.vo.TableHeadVo; import com.hnac.hzims.electric.vo.TableHeadVo;
import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo;
import com.hnac.hzims.equipment.service.IEmInfoService;
import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient; import com.hnac.hzims.operational.station.feign.IStationClient;
import com.hnac.hzims.operational.station.vo.StationsByDeptIdsParamVo;
import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient;
import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO;
import com.hnac.hzinfo.datasearch.analyse.po.AnalyzeDataConditionPO; import com.hnac.hzinfo.datasearch.analyse.po.AnalyzeDataConditionPO;
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO;
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -26,9 +27,9 @@ import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.entity.Dept; import org.springblade.system.entity.Dept;
import org.springblade.system.feign.ISysClient; import org.springblade.system.feign.ISysClient;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -48,14 +49,16 @@ public class ElectricReportServiceImpl implements IElectricReportService {
private final ThirtyService thirtyService; private final ThirtyService thirtyService;
private final IEmInfoService deviceService;
private final ISysClient sysClient; private final ISysClient sysClient;
private final IStationClient stationClient; private final IStationClient stationClient;
private final IAnalyseDataSearchClient analyseDataSearchClient; private final IAnalyseDataSearchClient analyseDataSearchClient;
private final RedisTemplate redisTemplate;
public final static String DEVICE_CACHE_COFIG_FINAL = "hzims:equipment:emInfo:deviceCode.emInfoList";
/** /**
* 基础报表 * 基础报表
* @param deptId * @param deptId
@ -92,6 +95,57 @@ public class ElectricReportServiceImpl implements IElectricReportService {
} }
/** /**
* 综合报表
* @param deptId
* @return
*/
@Override
public List<ComprehensiveElectricVo> comprehensive(Long deptId,String year) {
// 查询站点
StationEntity param = new StationEntity();
param.setRefDept(deptId);
R<StationEntity> station = stationClient.getStationByCodeOrRedDept(param);
if(!station.isSuccess() || ObjectUtil.isEmpty(station.getData())){
return new ArrayList<>();
}
// 查询设备
List<EminfoAndEmParamVo> devices = JSONObject.parseObject(redisTemplate.opsForValue().get(DEVICE_CACHE_COFIG_FINAL).toString(), new TypeReference<List<EminfoAndEmParamVo>>() {});
if(CollectionUtil.isEmpty(devices)){
return new ArrayList<>();
}
// 设备装机容量
double installedCapacity = devices.stream().filter(device->device.getCreateDept().equals(deptId)).mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum();
// 查询两年发电量
Calendar calendar = Calendar.getInstance();
calendar.setTime(DateUtil.parse(year,"yyyy"));
calendar.add(Calendar.YEAR,1);
Date end = calendar.getTime();
calendar.add(Calendar.YEAR,-2);
Date start = calendar.getTime();
List<ThreeEntity> threes = threeService.list(Wrappers.<ThreeEntity>lambdaQuery()
.eq(ThreeEntity::getStationId,station.getData().getCode())
.ge(ThreeEntity::getStrMonth, DateUtil.format(start,DateUtil.PATTERN_DATE))
.le(ThreeEntity::getStrMonth, DateUtil.format(end,DateUtil.PATTERN_DATE))
);
calendar.setTime(DateUtil.parse(year,"yyyy"));
calendar.add(Calendar.YEAR,1);
Date finish = calendar.getTime();
calendar.add(Calendar.YEAR,-1);
Date current = calendar.getTime();
while (current.compareTo(finish) < 0){
calendar.add(Calendar.MONTH,1);
current = calendar.getTime();
}
return null;
}
/**
* 确认机构级别 * 确认机构级别
* @param deptId * @param deptId
* @return * @return
@ -450,17 +504,17 @@ public class ElectricReportServiceImpl implements IElectricReportService {
// 日 // 日
if (type == 0) { if (type == 0) {
// 站点设备集合 // 站点设备集合
List<EmInfoEntity> devices = deviceService.list(Wrappers.<EmInfoEntity>lambdaQuery() List<EminfoAndEmParamVo> devices = JSONObject.parseObject(redisTemplate.opsForValue().get(DEVICE_CACHE_COFIG_FINAL).toString(), new TypeReference<List<EminfoAndEmParamVo>>() {});
.eq(EmInfoEntity::getCreateDept,station.getData().getRefDept())
.eq(EmInfoEntity::getEmType,2)
.eq(EmInfoEntity::getHomePageDisplay,1)
);
if(CollectionUtil.isEmpty(devices)){ if(CollectionUtil.isEmpty(devices)){
return new HashMap<>(); return new HashMap<>();
} }
List<EminfoAndEmParamVo> stationDevices = devices.stream().filter(device->device.getCreateDept().equals(station.getData().getRefDept())).collect(Collectors.toList());
if(CollectionUtil.isEmpty(stationDevices)){
return new HashMap<>();
}
Date date = DateUtil.parse(time,DateUtil.PATTERN_DATE); Date date = DateUtil.parse(time,DateUtil.PATTERN_DATE);
// 根据设备查询当日有功/无功电量 // 根据设备查询当日有功/无功电量
List<DeviceElectricVo> electrics = this.deviceElectrics(devices,date); List<DeviceElectricVo> electrics = this.deviceElectrics(stationDevices,date);
// 表头 // 表头
List<TableHeadVo> tableHeads = new ArrayList<>(); List<TableHeadVo> tableHeads = new ArrayList<>();
@ -475,7 +529,7 @@ public class ElectricReportServiceImpl implements IElectricReportService {
tableHeads.add(secondHead); tableHeads.add(secondHead);
// 根据设备分组 // 根据设备分组
devices.forEach(device->{ stationDevices.forEach(device->{
TableHeadVo tableHead = new TableHeadVo(); TableHeadVo tableHead = new TableHeadVo();
tableHead.setTableName(device.getName() + "发电量(kWh)"); tableHead.setTableName(device.getName() + "发电量(kWh)");
tableHead.setIsChildren(true); tableHead.setIsChildren(true);
@ -486,24 +540,25 @@ public class ElectricReportServiceImpl implements IElectricReportService {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(date); calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH,1);
Date end = calendar.getTime(); Date end = calendar.getTime();
calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); calendar.add(Calendar.DAY_OF_MONTH,-1);
Date start = calendar.getTime(); Date start = calendar.getTime();
List<List<Object>> tableDate = new ArrayList<>(); List<List<Object>> tableDate = new ArrayList<>();
while (start.compareTo(end) < 0){ while (start.compareTo(end) < 0){
List<Object> item = new ArrayList<>(); List<Object> item = new ArrayList<>();
String hours = DateUtil.format(start,"yyyy-MM-dd HH"); String hours = DateUtil.format(start,"yyyy-MM-dd HH");
item.add(start.getMonth() + 1 + "月"); item.add(start.getHours() + "时");
// 总计:有功、无功 // 总计:有功、无功
item.add(electrics.stream().filter(electric -> electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getGenerate).sum()); item.add(electrics.stream().filter(electric -> electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getGenerate).sum());
item.add(electrics.stream().filter(electric -> electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getReactiveGenerate).sum()); item.add(electrics.stream().filter(electric -> electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getReactiveGenerate).sum());
// 遍历机组 // 遍历机组
devices.stream().sorted(Comparator.comparing(EmInfoEntity::getEmIndex)).forEach(device->{ stationDevices.stream().sorted(Comparator.comparing(EminfoAndEmParamVo::getOrd)).forEach(device->{
item.add(electrics.stream().filter(electric -> electric.getDeviceCode().equals(device.getNumber()) && electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getGenerate).sum()); item.add(electrics.stream().filter(electric -> electric.getDeviceCode().equals(device.getEmCode()) && electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getGenerate).sum());
item.add(electrics.stream().filter(electric -> electric.getDeviceCode().equals(device.getNumber()) && electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getReactiveGenerate).sum()); item.add(electrics.stream().filter(electric -> electric.getDeviceCode().equals(device.getEmCode()) && electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getReactiveGenerate).sum());
}); });
calendar.add(Calendar.DAY_OF_MONTH,1); calendar.add(Calendar.HOUR_OF_DAY,1);
start = calendar.getTime(); start = calendar.getTime();
tableDate.add(item); tableDate.add(item);
} }
@ -641,18 +696,19 @@ public class ElectricReportServiceImpl implements IElectricReportService {
* @param devices * @param devices
* @return * @return
*/ */
private List<DeviceElectricVo> deviceElectrics(List<EmInfoEntity> devices,Date date) { private List<DeviceElectricVo> deviceElectrics(List<EminfoAndEmParamVo> devices,Date date) {
List<DeviceElectricVo> electrics = new ArrayList<>(); List<DeviceElectricVo> electrics = new ArrayList<>();
devices.forEach(device->{ devices.forEach(device->{
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(date); calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH,1);
Date endTime = calendar.getTime(); Date endTime = calendar.getTime();
LocalDateTime end = LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(endTime,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME)); LocalDateTime end = LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(endTime,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME));
calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); calendar.add(Calendar.DAY_OF_MONTH,-1);
Date startTime = calendar.getTime(); Date startTime = calendar.getTime();
LocalDateTime start = LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(startTime,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME)); LocalDateTime start = LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(startTime,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME));
AnalyseCodeByAnalyseDataPO param = new AnalyseCodeByAnalyseDataPO(); AnalyseCodeByAnalyseDataPO param = new AnalyseCodeByAnalyseDataPO();
param.setDeviceCode(device.getNumber()); param.setDeviceCode(device.getEmCode());
List<AnalyzeDataConditionPO> conditions = new ArrayList<>(); List<AnalyzeDataConditionPO> conditions = new ArrayList<>();
// 有功电量 // 有功电量
AnalyzeDataConditionPO generate = new AnalyzeDataConditionPO(); AnalyzeDataConditionPO generate = new AnalyzeDataConditionPO();
@ -674,7 +730,8 @@ public class ElectricReportServiceImpl implements IElectricReportService {
reactive.setSignages("reactive_generation"); reactive.setSignages("reactive_generation");
reactive.setTimeInterval(1); reactive.setTimeInterval(1);
reactive.setBeginTime(start); reactive.setBeginTime(start);
reactive.setEndTime(end);conditions.add(reactive); reactive.setEndTime(end);
conditions.add(reactive);
param.setSignboardConditions(conditions); param.setSignboardConditions(conditions);
R<List<AnalyzeDataConditionVO>> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(param); R<List<AnalyzeDataConditionVO>> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(param);
if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData())){ if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData())){
@ -682,24 +739,25 @@ public class ElectricReportServiceImpl implements IElectricReportService {
} }
while (startTime.compareTo(endTime) < 0){ while (startTime.compareTo(endTime) < 0){
DeviceElectricVo electric = new DeviceElectricVo(); DeviceElectricVo electric = new DeviceElectricVo();
electric.setDeviceCode(device.getEmCode());
electric.setStrTime(DateUtil.format(startTime,"yyyy-MM-dd HH")); electric.setStrTime(DateUtil.format(startTime,"yyyy-MM-dd HH"));
electric.setTime(startTime.getHours()); electric.setTime(startTime.getHours());
if(ObjectUtil.isEmpty(result.getData().get(0)) || CollectionUtil.isEmpty(result.getData().get(0).getList())){ if(CollectionUtil.isNotEmpty(result.getData()) && ObjectUtil.isNotEmpty(result.getData().get(0)) && CollectionUtil.isNotEmpty(result.getData().get(0).getList())){
electric.setGenerate(result.getData().get(0).getList().stream().filter(o->o.getTs().contains(electric.getStrTime())).mapToDouble(val->{ electric.setGenerate(result.getData().get(0).getList().stream().filter(o->o.getTs().contains(electric.getStrTime())).mapToDouble(val->{
if(StringUtils.isEmpty(val.getVal())){ if(StringUtils.isEmpty(val.getVal())){
return 0.0; return 0.0;
} }
return Double.parseDouble(val.getVal()); return Double.parseDouble(val.getVal()) * device.getRideCount();
}).sum()); }).sum());
}else{ }else{
electric.setGenerate(0.0); electric.setGenerate(0.0);
} }
if(ObjectUtil.isEmpty(result.getData().get(1)) || CollectionUtil.isEmpty(result.getData().get(1).getList())){ if(CollectionUtil.isNotEmpty(result.getData()) && result.getData().size() > 1 && ObjectUtil.isNotEmpty(result.getData().get(1)) && CollectionUtil.isNotEmpty(result.getData().get(1).getList())){
electric.setReactiveGenerate(result.getData().get(1).getList().stream().filter(o->o.getTs().contains(electric.getStrTime())).mapToDouble(val->{ electric.setReactiveGenerate(result.getData().get(1).getList().stream().filter(o->o.getTs().contains(electric.getStrTime())).mapToDouble(val->{
if(StringUtils.isEmpty(val.getVal())){ if(StringUtils.isEmpty(val.getVal())){
return 0.0; return 0.0;
} }
return Double.parseDouble(val.getVal()); return Double.parseDouble(val.getVal()) * device.getRideCount();
}).sum()); }).sum());
}else{ }else{
electric.setReactiveGenerate(0.0); electric.setReactiveGenerate(0.0);

Loading…
Cancel
Save