|
@@ -0,0 +1,377 @@
|
|
|
|
+package org.jeecg.modules.emsStatistics.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
|
+import org.jeecg.modules.baseSpace.entity.Space;
|
|
|
|
+import org.jeecg.modules.baseSpace.service.ISpaceService;
|
|
|
|
+import org.jeecg.modules.dataCurrent.mapper.DataCurrentMapper;
|
|
|
|
+import org.jeecg.modules.dataElectricity.mapper.DataElectricityMapper;
|
|
|
|
+import org.jeecg.modules.dataPower.mapper.DataPowerMapper;
|
|
|
|
+import org.jeecg.modules.dataVoltage.mapper.DataVoltageMapper;
|
|
|
|
+import org.jeecg.modules.elecfeeBase.mapper.ElecfeeBaseMapper;
|
|
|
|
+import org.jeecg.modules.emsStatistics.entity.EmsStatistics;
|
|
|
|
+import org.jeecg.modules.emsStatistics.mapper.EmsStatisticsMapper;
|
|
|
|
+import org.jeecg.modules.emsStatistics.service.IEmsStatisticsService;
|
|
|
|
+import org.jeecg.modules.energyItem.mapper.EnergyItemMapper;
|
|
|
|
+import org.jeecg.modules.tpmEquipment.entity.TpmEquipment;
|
|
|
|
+import org.jeecg.modules.tpmEquipment.mapper.TpmEquipmentMapper;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.temporal.IsoFields;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class IEmsStatisticsServiceImpl implements IEmsStatisticsService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private EmsStatisticsMapper emsStatisticsMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISpaceService spaceService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private TpmEquipmentMapper equipmentMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DataElectricityMapper electricityMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private EnergyItemMapper energyItemMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ElecfeeBaseMapper elecfeeBaseMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DataCurrentMapper dataCurrentMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DataVoltageMapper dataVoltageMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DataPowerMapper dataPowerMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 能耗总览
|
|
|
|
+ *
|
|
|
|
+ * @param spaceId 区域ID
|
|
|
|
+ * @return 分析统计
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result<Map<String, Object>> energyOverview(String spaceId) {
|
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
+ // 设置当前的时间戳
|
|
|
|
+ calendar.setTime(new Date());
|
|
|
|
+ // 设置星期一为一周开始的第一天
|
|
|
|
+ calendar.setFirstDayOfWeek(Calendar.MONDAY);
|
|
|
|
+ // 获得当前日期所属周
|
|
|
|
+ LocalDate localDate = LocalDate.parse(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
|
+ int week = localDate.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
|
|
|
|
+
|
|
|
|
+ // 获得当前日期所属月
|
|
|
|
+ int month = calendar.get(Calendar.MONTH) + 1;
|
|
|
|
+ // 获得当前日期所属年
|
|
|
|
+ int year = calendar.get(Calendar.YEAR);
|
|
|
|
+
|
|
|
|
+ // 上个月
|
|
|
|
+ Calendar calendarLast = Calendar.getInstance();
|
|
|
|
+ calendarLast.setTime(new Date());
|
|
|
|
+ calendarLast.add(Calendar.MONTH, -1);
|
|
|
|
+ // 获得上个月
|
|
|
|
+ int monthLast = calendarLast.get(Calendar.MONTH) + 1;
|
|
|
|
+ // 获得上个月所属年
|
|
|
|
+ int yearLast = calendarLast.get(Calendar.YEAR);
|
|
|
|
+
|
|
|
|
+ // 正常查询参数(只包括年、月)
|
|
|
|
+ EmsStatistics statisticsParams = new EmsStatistics();
|
|
|
|
+ statisticsParams.setEquipmentid(spaceId);
|
|
|
|
+ statisticsParams.setYear(year);
|
|
|
|
+ statisticsParams.setMonth(month);
|
|
|
|
+
|
|
|
|
+ //区域基本信息
|
|
|
|
+ Space space = spaceService.getById(spaceId);
|
|
|
|
+ if (Objects.isNull(space)) space = new Space();
|
|
|
|
+ map.put("energySpace", space);
|
|
|
|
+
|
|
|
|
+ // 本月用电top5
|
|
|
|
+ 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());
|
|
|
|
+ }
|
|
|
|
+ // 设置区域下的所有的设备信息
|
|
|
|
+ statisticsParams.setIds(equipmentids);
|
|
|
|
+ // 如果选择的是整个厂区的,需要去掉配电室几个
|
|
|
|
+ if ("AREA0002".equals(space.getSerialnum())) {
|
|
|
|
+ equipmentids.remove("301156882513921L");
|
|
|
|
+ equipmentids.remove("301156930748417L");
|
|
|
|
+ equipmentids.remove("301156947525633L");
|
|
|
|
+ equipmentids.remove("301156962205697L");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<EmsStatistics> topStatistics = new ArrayList<>();
|
|
|
|
+ if (equipmentids.size() > 0) {
|
|
|
|
+ topStatistics = emsStatisticsMapper.selectMonthElectricity(statisticsParams);
|
|
|
|
+ }
|
|
|
|
+ // top5上个月的用电量
|
|
|
|
+ if (topStatistics != null && topStatistics.size() > 0) {
|
|
|
|
+ for (EmsStatistics topStatistic : topStatistics) {
|
|
|
|
+ EmsStatistics top5LastParams = new EmsStatistics();
|
|
|
|
+ top5LastParams.setYear(yearLast);
|
|
|
|
+ top5LastParams.setMonth(monthLast);
|
|
|
|
+ top5LastParams.setEquipmentid(topStatistic.getEquipmentid());
|
|
|
|
+ EmsStatistics lastValue = emsStatisticsMapper.selectMonthEquipElectricity(top5LastParams);
|
|
|
|
+ if (lastValue != null) {
|
|
|
|
+ topStatistic.setHowManyValue2(lastValue.getHowManyValue2());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ map.put("top5Statistics", topStatistics);
|
|
|
|
+ } else {
|
|
|
|
+ map.put("top5Statistics", new ArrayList<>());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 用电需量
|
|
|
|
+ List<EmsStatistics> demandStatistics = emsStatisticsMapper.selectMonthDemand(statisticsParams);
|
|
|
|
+ if (demandStatistics == null || demandStatistics.isEmpty()) {
|
|
|
|
+ demandStatistics = new ArrayList<>();
|
|
|
|
+ EmsStatistics demand = new EmsStatistics();
|
|
|
|
+
|
|
|
|
+ demand.setType("需量峰值");
|
|
|
|
+ demand.setHowManyValue(0);
|
|
|
|
+ demandStatistics.add(demand);
|
|
|
|
+
|
|
|
|
+ demand.setType("即时需量");
|
|
|
|
+ demand.setHowManyValue(0);
|
|
|
|
+ demandStatistics.add(demand);
|
|
|
|
+
|
|
|
|
+ demand.setType("目标需量");
|
|
|
|
+ demand.setHowManyValue(0);
|
|
|
|
+ demandStatistics.add(demand);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (demandStatistics.size() < 3) {
|
|
|
|
+
|
|
|
|
+ List<EmsStatistics> demands1 = demandStatistics.stream().filter(sta -> "需量峰值".equals(sta.getType())).collect(Collectors.toList());
|
|
|
|
+ if (demands1.size() < 1) {
|
|
|
|
+ EmsStatistics demand = new EmsStatistics();
|
|
|
|
+ demand.setType("需量峰值");
|
|
|
|
+ demand.setHowManyValue(0);
|
|
|
|
+ demandStatistics.add(demand);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<EmsStatistics> demands2 = demandStatistics.stream().filter(sta -> "即时需量".equals(sta.getType())).collect(Collectors.toList());
|
|
|
|
+ if (demands2.size() < 1) {
|
|
|
|
+ EmsStatistics demand = new EmsStatistics();
|
|
|
|
+ demand.setType("即时需量");
|
|
|
|
+ demand.setHowManyValue(0);
|
|
|
|
+ demandStatistics.add(demand);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<EmsStatistics> demands3 = demandStatistics.stream().filter(sta -> "目标需量".equals(sta.getType())).collect(Collectors.toList());
|
|
|
|
+ if (demands3.size() < 1) {
|
|
|
|
+ EmsStatistics demand = new EmsStatistics();
|
|
|
|
+ demand.setType("目标需量");
|
|
|
|
+ demand.setHowManyValue(0);
|
|
|
|
+ demandStatistics.add(demand);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ map.put("demandStatistics", demandStatistics);
|
|
|
|
+
|
|
|
|
+ // 环境信息
|
|
|
|
+ List<EmsStatistics> environmentStatistics = new ArrayList<>();
|
|
|
|
+ // 如果选择的是整个厂区的,则只需要获取总控的二氧化碳信息即可
|
|
|
|
+ if ("AREA0002".equals(space.getSerialnum())) {
|
|
|
|
+ EmsStatistics statisticsParams1 = new EmsStatistics();
|
|
|
|
+ List<String> equip1 = new ArrayList<>();
|
|
|
|
+ equip1.add("301156882513921L");
|
|
|
|
+ statisticsParams1.setIds(equip1);
|
|
|
|
+ statisticsParams1.setYear(year);
|
|
|
|
+ statisticsParams1.setMonth(month);
|
|
|
|
+ environmentStatistics = emsStatisticsMapper.selectEnvironment(statisticsParams1);
|
|
|
|
+ }
|
|
|
|
+ else if (equipmentids.size() > 0) {
|
|
|
|
+ environmentStatistics = emsStatisticsMapper.selectEnvironment(statisticsParams);
|
|
|
|
+ }
|
|
|
|
+ map.put("environmentStatistics", environmentStatistics);
|
|
|
|
+
|
|
|
|
+ // 能源消耗总标煤
|
|
|
|
+ List<EmsStatistics> kgceStatistics = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ // 如果选择的是整个厂区、配电室的,则只需要获取配电室的几个表的信息即可
|
|
|
|
+ if ("AREA0002".equals(space.getSerialnum()) || "AREA0015".equals(space.getSerialnum())) {
|
|
|
|
+ kgceStatistics = emsStatisticsMapper.selectKgceMonthTotal(statisticsParams);
|
|
|
|
+ }
|
|
|
|
+ else if (equipmentids.size() > 0) {
|
|
|
|
+ kgceStatistics = emsStatisticsMapper.selectKgceMonth(statisticsParams);
|
|
|
|
+ }
|
|
|
|
+ map.put("kgceStatistics", kgceStatistics);
|
|
|
|
+
|
|
|
|
+ // 总用电趋势图
|
|
|
|
+ String yearMonth = DateUtils.parseDateToStr("yyyy-MM", new Date());
|
|
|
|
+ String thisdate = DateUtils.getLastDay(yearMonth.substring(0,4), yearMonth.substring(5));
|
|
|
|
+ int lastDay = Integer.parseInt(thisdate.substring(8));
|
|
|
|
+
|
|
|
|
+ List<String> daysplitStr = new ArrayList<>(); // 天数拆分
|
|
|
|
+ List<Float> dongli = new ArrayList<>();
|
|
|
|
+ List<Float> zhaoming = new ArrayList<>();
|
|
|
|
+ List<Float> kongtiao = new ArrayList<>();
|
|
|
|
+ List<Float> qita = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for(int i = 1; i < lastDay; i++) {
|
|
|
|
+ String day = i < 10 ? "0" + i : String.valueOf(i);
|
|
|
|
+ daysplitStr.add(day);
|
|
|
|
+ dongli.add(0f);
|
|
|
|
+ zhaoming.add(0f);
|
|
|
|
+ kongtiao.add(0f);
|
|
|
|
+ qita.add(0f);
|
|
|
|
+ List<EmsStatistics> dayStatis = null;
|
|
|
|
+ // 如果选择的是整个厂区、配电室的,则只需要获取配电室的几个表的信息即可
|
|
|
|
+ if ("AREA0002".equals(space.getSerialnum()) || "AREA0015".equals(space.getSerialnum())) {
|
|
|
|
+ dayStatis = emsStatisticsMapper.selectItemByEquipidAndDayTotal(equipmentids,yearMonth + "-" + day);
|
|
|
|
+ }
|
|
|
|
+ else if (equipmentids.size() > 0) {
|
|
|
|
+ dayStatis = emsStatisticsMapper.selectItemByEquipidAndDay(equipmentids,yearMonth + "-" + day);
|
|
|
|
+ }
|
|
|
|
+ if (dayStatis != null && dayStatis.size() > 0) {
|
|
|
|
+ for (EmsStatistics daysta : dayStatis) {
|
|
|
|
+ switch (daysta.getEquipmentname()) {
|
|
|
|
+ case "动力用电":
|
|
|
|
+ dongli.set(i - 1, daysta.getHowManyValue());
|
|
|
|
+ break;
|
|
|
|
+ case "照明用电":
|
|
|
|
+ zhaoming.set(i - 1, daysta.getHowManyValue());
|
|
|
|
+ break;
|
|
|
|
+ case "空调用电":
|
|
|
|
+ kongtiao.set(i - 1, daysta.getHowManyValue());
|
|
|
|
+ break;
|
|
|
|
+ case "其它用电":
|
|
|
|
+ qita.set(i - 1, daysta.getHowManyValue());
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ map.put("daysplit", daysplitStr);
|
|
|
|
+ map.put("dongli", dongli);
|
|
|
|
+ map.put("zhaoming", zhaoming);
|
|
|
|
+ map.put("kongtiao", kongtiao);
|
|
|
|
+ map.put("qita", qita);
|
|
|
|
+ return Result.ok(map);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 需量分析
|
|
|
|
+ *
|
|
|
|
+ * @param spaceId 区域ID
|
|
|
|
+ * @param beginTime 开始年月
|
|
|
|
+ * @param endTime 结束年月
|
|
|
|
+ * @return 分析统计
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result<Object> DemandAnalysis(String spaceId, String beginTime, String endTime) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 节能分析
|
|
|
|
+ *
|
|
|
|
+ * @param spaceId 区域ID
|
|
|
|
+ * @param yearMonth 年月
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result<Object> savingAnalysis(String spaceId, String yearMonth) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 能耗排名
|
|
|
|
+ *
|
|
|
|
+ * @param spaceId 区域ID
|
|
|
|
+ * @param beginTime 开始年月
|
|
|
|
+ * @param endTime 结束年月
|
|
|
|
+ * @return 分析统计
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result<Object> ranking(String spaceId, String beginTime, String endTime) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 分项能耗
|
|
|
|
+ *
|
|
|
|
+ * @param spaceId 区域ID
|
|
|
|
+ * @param day 某天
|
|
|
|
+ * @return 分析统计
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result<Object> itemizedEnergy(String spaceId, String day) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 用能平衡分析
|
|
|
|
+ *
|
|
|
|
+ * @return 分析统计
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result<Object> energyBalanceAnalysis() {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 峰平谷分析
|
|
|
|
+ *
|
|
|
|
+ * @return 分析统计
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result<Object> peakValleyAnalysis() {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 能耗定额
|
|
|
|
+ *
|
|
|
|
+ * @return 分析统计
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result<Object> energyQuota() {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 能流分析
|
|
|
|
+ *
|
|
|
|
+ * @param spaceId 区域ID
|
|
|
|
+ * @param beginTime 开始日期
|
|
|
|
+ * @param endTime 结束日期
|
|
|
|
+ * @return 分析统计
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result<Object> energyFlowAnalysis(String spaceId, String beginTime, String endTime) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询设备详情(按日期查询电量、电量、电压、功率)
|
|
|
|
+ *
|
|
|
|
+ * @param equipmentid 设备ID
|
|
|
|
+ * @param day 日期
|
|
|
|
+ * @param tagtype 类型
|
|
|
|
+ * @return 分析统计
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result<Object> searchEquipmentDetail(String equipmentid, String day, String tagtype) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|