|
@@ -777,7 +777,167 @@ public class EmsStatisticsServiceImpl implements IEmsStatisticsService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Result<Object> energyFlowAnalysis(String spaceId, String beginTime, String endTime) {
|
|
|
- return null;
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ LambdaQueryWrapper<TpmEquipment> eq = new LambdaQueryWrapper<TpmEquipment>()
|
|
|
+ .eq(TpmEquipment::getSpaceid, spaceId)
|
|
|
+ .select(TpmEquipment::getId);
|
|
|
+ List<TpmEquipment> equipments = equipmentMapper.selectList(eq);
|
|
|
+ List<String> equipmentids = new ArrayList<>();
|
|
|
+ if (equipments != null && !equipments.isEmpty()) {
|
|
|
+ equipmentids = equipments.stream().map(TpmEquipment::getId).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ System.out.println(equipmentids);
|
|
|
+
|
|
|
+ List<FlowSource> sourceData = new ArrayList<>();
|
|
|
+ List<FlowLinks> linksData = new ArrayList<>();
|
|
|
+ Float elecSum = 0f;
|
|
|
+
|
|
|
+ // 区域基本信息
|
|
|
+ SpaceDto energySpace = spaceMapper.selectSpaceById(spaceId);
|
|
|
+ // 如果选择的是生产车间、配电室,则执行另外的代码
|
|
|
+ if ("AREA0002".equals(energySpace.getSerialnum()) || "AREA0015".equals(energySpace.getSerialnum())) {
|
|
|
+ energyFlowAnalysisSub(energySpace, equipmentids, beginTime, endTime, map);
|
|
|
+
|
|
|
+ return Result.OK(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 能耗分项
|
|
|
+ EnergyItem energyItemParams = new EnergyItem();
|
|
|
+ energyItemParams.setEnergytypename("电");
|
|
|
+ List<EnergyItem> itemList = energyItemMapper.selectEmsEnergyItemList(energyItemParams);
|
|
|
+ if (itemList != null && itemList.size() > 0) {
|
|
|
+ for (int i = 0; i < itemList.size(); i++) {
|
|
|
+ List<EmsStatistics> emsStatisticsList = new ArrayList<>();
|
|
|
+ if (equipmentids != null && equipmentids.size() > 0) {
|
|
|
+ emsStatisticsList = emsStatisticsMapper.selectElecByEquipAndItem(equipmentids,
|
|
|
+ itemList.get(i).getId(), beginTime + "-01", DateUtils.getLastDay(endTime.substring(0,4), endTime.substring(5)));
|
|
|
+ }
|
|
|
+ Float itemSum = 0f;
|
|
|
+ if (emsStatisticsList != null) {
|
|
|
+ itemSum = (float) emsStatisticsList.stream().mapToDouble(EmsStatistics::getHowManyValue).sum();
|
|
|
+ }
|
|
|
+ elecSum += itemSum;
|
|
|
+ sourceData.add(new FlowSource(itemList.get(i).getEnergyitemname(), 1, itemSum == null ? 0f : itemSum, "KWh"));
|
|
|
+ linksData.add(new FlowLinks("电", itemList.get(i).getEnergyitemname(), itemSum == null ? 0f : itemSum));
|
|
|
+ if (emsStatisticsList != null && emsStatisticsList.size() > 0) {
|
|
|
+ for (EmsStatistics sta : emsStatisticsList) {
|
|
|
+ sourceData.add(new FlowSource(sta.getEquipmentname(), 2, sta.getHowManyValue(), "KWh"));
|
|
|
+ linksData.add(new FlowLinks(itemList.get(i).getEnergyitemname(), sta.getEquipmentname(), sta.getHowManyValue()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sourceData.add(0, new FlowSource("电", 0, elecSum == null ? 0f : elecSum, "KWh"));
|
|
|
+ linksData.add(0, new FlowLinks("", "电", elecSum == null ? 0f : elecSum));
|
|
|
+
|
|
|
+
|
|
|
+ map.put("sourceData", sourceData);
|
|
|
+ map.put("linksData", linksData);
|
|
|
+
|
|
|
+ return Result.OK(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 能流分析-生产车间、配电室
|
|
|
+ *
|
|
|
+ * @param beginTime 开始日期
|
|
|
+ * @param endTime 结束日期
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public void energyFlowAnalysisSub(SpaceDto energySpace, List<String> equipmentids, String beginTime, String endTime, Map<String,Object> map)
|
|
|
+ {
|
|
|
+ List<FlowSource> sourceData = new ArrayList<>();
|
|
|
+ List<FlowLinks> linksData = new ArrayList<>();
|
|
|
+
|
|
|
+ // 如果选择的是整个厂区,去掉配电室的几个表
|
|
|
+ if ("AREA0002".equals(energySpace.getSerialnum()) ) {
|
|
|
+ // 去掉配电室的几个表
|
|
|
+ equipmentids.remove("301156882513921");
|
|
|
+ equipmentids.remove("301156930748417");
|
|
|
+ equipmentids.remove("301156947525633");
|
|
|
+ equipmentids.remove("301156962205697");
|
|
|
+ energyFlowAnalysisSub1(beginTime, endTime, sourceData, linksData);
|
|
|
+ }
|
|
|
+ // 如果选择的是配电室,则只查询配电室的几个表
|
|
|
+ if ("AREA0015".equals(energySpace.getSerialnum())) {
|
|
|
+ energyFlowAnalysisSub1(beginTime, endTime, sourceData, linksData);
|
|
|
+ map.put("sourceData", sourceData);
|
|
|
+ map.put("linksData", linksData);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 能耗分项
|
|
|
+ EnergyItem energyItemParams = new EnergyItem();
|
|
|
+ energyItemParams.setEnergytypename("电");
|
|
|
+ List<EnergyItem> itemList = energyItemMapper.selectEmsEnergyItemList(energyItemParams);
|
|
|
+ if (itemList != null && itemList.size() > 0) {
|
|
|
+ for (int i = 0; i < itemList.size(); i++) {
|
|
|
+ List<EmsStatistics> emsStatisticsList = new ArrayList<>();
|
|
|
+ if (equipmentids != null && equipmentids.size() > 0) {
|
|
|
+ emsStatisticsList = emsStatisticsMapper.selectElecByEquipAndItem(equipmentids,
|
|
|
+ itemList.get(i).getId(), beginTime + "-01", DateUtils.getLastDay(endTime.substring(0,4), endTime.substring(5)));
|
|
|
+ }
|
|
|
+ if (emsStatisticsList != null && emsStatisticsList.size() > 0) {
|
|
|
+ for (EmsStatistics sta : emsStatisticsList) {
|
|
|
+ sourceData.add(new FlowSource(sta.getEquipmentname(), 2, sta.getHowManyValue(), "KWh"));
|
|
|
+ linksData.add(new FlowLinks(itemList.get(i).getEnergyitemname(), sta.getEquipmentname(), sta.getHowManyValue()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("sourceData", sourceData);
|
|
|
+ map.put("linksData", linksData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 能流分析-生产车间、配电室,组合1,2层
|
|
|
+ *
|
|
|
+ * @param beginTime 开始日期
|
|
|
+ * @param endTime 结束日期
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public void energyFlowAnalysisSub1(String beginTime, String endTime, List<FlowSource> sourceData, List<FlowLinks> linksData)
|
|
|
+ {
|
|
|
+ List<String> equipids = new ArrayList<>();
|
|
|
+ // 配电室的四块表
|
|
|
+ equipids.add("301156882513921");
|
|
|
+ equipids.add("301156930748417");
|
|
|
+ equipids.add("301156947525633");
|
|
|
+ equipids.add("301156962205697");
|
|
|
+
|
|
|
+ List<EmsStatistics> emsStatList = emsStatisticsMapper.selectElecByEquipAndItem(equipids,null, beginTime + "-01", DateUtils.getLastDay(endTime.substring(0,4), endTime.substring(5)));
|
|
|
+
|
|
|
+ // 第一层-总表
|
|
|
+ List<EmsStatistics> zongbiao = emsStatList.stream().filter(p -> p.getEquipmentid() == "301156882513921").collect(Collectors.toList());
|
|
|
+ Float zf = zongbiao == null || zongbiao.size() < 1 ? 0f : zongbiao.get(0).getHowManyValue();
|
|
|
+ sourceData.add(new FlowSource("电", 0, zf, "KWh"));
|
|
|
+ linksData.add(new FlowLinks("", "电", zf));
|
|
|
+
|
|
|
+ // 第二层
|
|
|
+ // 动力用电
|
|
|
+ List<EmsStatistics> dongli = emsStatList.stream()
|
|
|
+ .filter(p -> p.getEquipmentid() == "301156930748417" || p.getEquipmentid() == "301156962205697")
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Float df = dongli == null || dongli.size() < 1 ? 0f : (float) dongli.stream().mapToDouble(EmsStatistics::getHowManyValue).sum();;
|
|
|
+
|
|
|
+ // 空调用电
|
|
|
+ List<EmsStatistics> kongtiao = emsStatList.stream()
|
|
|
+ .filter(p -> p.getEquipmentid() == "301156947525633")
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Float kf = kongtiao == null || kongtiao.size() < 1 ? 0f : (float) kongtiao.stream().mapToDouble(EmsStatistics::getHowManyValue).sum();;
|
|
|
+
|
|
|
+ sourceData.add(new FlowSource("动力用电", 1, df, "KWh"));
|
|
|
+ linksData.add(new FlowLinks("电", "动力用电", df));
|
|
|
+
|
|
|
+ sourceData.add(new FlowSource("空调用电", 1, kf, "KWh"));
|
|
|
+ linksData.add(new FlowLinks("电", "空调用电", kf));
|
|
|
+
|
|
|
+ // 其它用电
|
|
|
+ sourceData.add(new FlowSource("其它用电", 1, zf - df - kf, "KWh"));
|
|
|
+ linksData.add(new FlowLinks("电", "其它用电", zf - df - kf));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -887,4 +1047,98 @@ public class EmsStatisticsServiceImpl implements IEmsStatisticsService {
|
|
|
return rtn;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 能流图 - 源点
|
|
|
+ */
|
|
|
+ public class FlowSource {
|
|
|
+ private String name;
|
|
|
+ private Integer depth;
|
|
|
+ private float nameValue;
|
|
|
+ private String valueUnit;
|
|
|
+
|
|
|
+ public String getName() {
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setName(String name) {
|
|
|
+ this.name = name;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Integer getDepth() {
|
|
|
+ return depth;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setDepth(Integer depth) {
|
|
|
+ this.depth = depth;
|
|
|
+ }
|
|
|
+
|
|
|
+ public float getNameValue() {
|
|
|
+ return nameValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setNameValue(float nameValue) {
|
|
|
+ this.nameValue = nameValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getValueUnit() {
|
|
|
+ return valueUnit;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setValueUnit(String valueUnit) {
|
|
|
+ this.valueUnit = valueUnit;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FlowSource() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public FlowSource(String name, Integer depth, float nameValue, String valueUnit) {
|
|
|
+ this.name = name;
|
|
|
+ this.depth = depth;
|
|
|
+ this.nameValue = nameValue;
|
|
|
+ this.valueUnit = valueUnit;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 能流图 - 连接
|
|
|
+ */
|
|
|
+ public class FlowLinks {
|
|
|
+ private String source;
|
|
|
+ private String target;
|
|
|
+ private float value;
|
|
|
+
|
|
|
+ public String getSource() {
|
|
|
+ return source;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setSource(String source) {
|
|
|
+ this.source = source;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getTarget() {
|
|
|
+ return target;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setTarget(String target) {
|
|
|
+ this.target = target;
|
|
|
+ }
|
|
|
+
|
|
|
+ public float getValue() {
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setValue(float value) {
|
|
|
+ this.value = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FlowLinks() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public FlowLinks(String source, String target, float value) {
|
|
|
+ this.source = source;
|
|
|
+ this.target = target;
|
|
|
+ this.value = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|