浏览代码

新增能源管理-需量分析接口

lw 1 年之前
父节点
当前提交
eda866fd68

+ 39 - 3
jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -5,9 +5,7 @@ import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
+import java.util.*;
 
 import org.jeecg.common.constant.SymbolConstant;
 import org.springframework.util.StringUtils;
@@ -650,6 +648,44 @@ public class DateUtils extends PropertyEditorSupport {
         return new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
     }
 
+    public static List<String> MonthSplit(String beginTime, String endTime) {
+        List<String> monthSplit = new ArrayList<>();
+        if (beginTime.substring(0, 4).equals(endTime.substring(0, 4))) {
+            int beginMonth = Integer.parseInt(beginTime.substring(5));
+            int endMonth = Integer.parseInt(endTime.substring(5));
+
+            for (int month = beginMonth; month <= endMonth; month++) {
+                monthSplit.add(beginTime.substring(0, 4) + "-" + (month < 10 ? "0" + month : "" + month));
+            }
+        }
+        else {
+            int beginYear = Integer.parseInt(beginTime.substring(0, 4));
+            int endYear = Integer.parseInt(endTime.substring(0, 4));
+            int beginMonth = Integer.parseInt(beginTime.substring(5));
+            int endMonth = Integer.parseInt(endTime.substring(5));
+
+            for (int year = beginYear; year <= endYear; year++) {
+                if (year == beginYear) {
+                    for (int month = beginMonth; month <= 12; month++) {
+                        monthSplit.add(year + "-" + (month < 10 ? "0" + month : String.valueOf(month)));
+                    }
+                }
+                else if (year == endYear) {
+                    for (int month = 1; month <= endMonth; month++) {
+                        monthSplit.add(year + "-" + (month < 10 ? "0" + month : String.valueOf(month)));
+                    }
+                }
+                else {
+                    for (int month = 1; month <= 12; month++) {
+                        monthSplit.add(year + "-" + (month < 10 ? "0" + month : String.valueOf(month)));
+                    }
+                }
+            }
+        }
+
+        return monthSplit;
+    }
+
     /**
      * String类型 转换为Date, 如果参数长度为10 转换格式”yyyy-MM-dd“ 如果参数长度为19 转换格式”yyyy-MM-dd
      * HH:mm:ss“ * @param text String类型的时间值

+ 1 - 0
module_base/src/main/java/org/jeecg/modules/elecfeeBase/mapper/ElecfeeBaseMapper.java

@@ -16,4 +16,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 @Mapper
 public interface ElecfeeBaseMapper extends BaseMapper<ElecfeeBase> {
 
+    ElecfeeBase selectDemandByYearmonth(String month);
 }

+ 8 - 0
module_base/src/main/java/org/jeecg/modules/elecfeeBase/mapper/xml/ElecfeeBaseMapper.xml

@@ -2,4 +2,12 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.elecfeeBase.mapper.ElecfeeBaseMapper">
 
+    <select id="selectDemandByYearmonth" resultType="org.jeecg.modules.elecfeeBase.entity.ElecfeeBase">
+        select *
+        from base_elecfee_base
+        where feetype=1 and date_format(begintime,'%Y-%m') &lt;= #{yearmonth}
+          and date_format(ifnull(endtime,now()),'%Y-%m') &gt;= #{yearmonth}
+        order by id desc
+        limit 1
+    </select>
 </mapper>

+ 1 - 1
module_ems/src/main/java/org/jeecg/modules/emsStatistics/mapper/EmsStatisticsMapper.java

@@ -77,7 +77,7 @@ public interface EmsStatisticsMapper {
      * @param yearMonth 年月
      * @return 分析统计
      */
-    public Float SelectMaxDmand(@Param("ids") List<Long> ids, @Param("yearmonth") String yearMonth);
+    public Float SelectMaxDmand(@Param("ids") List<String> ids, @Param("yearmonth") String yearMonth);
 
     /**
      * 实际用能、计划用能、累计节能

+ 8 - 0
module_ems/src/main/java/org/jeecg/modules/emsStatistics/mapper/xml/EmsStatisticsMapper.xml

@@ -151,4 +151,12 @@
         group by t.energyitemid
         order by t.energyitemid asc
     </select>
+    <select id="SelectMaxDmand" resultType="java.lang.Float">
+        select max(a.tagvalue) as howManyValue
+        from ems_data_demand a
+        where yearmonth = #{yearmonth} and a.equipmentid in
+        <foreach collection="ids" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+    </select>
 </mapper>

+ 32 - 1
module_ems/src/main/java/org/jeecg/modules/emsStatistics/service/impl/IEmsStatisticsServiceImpl.java

@@ -9,6 +9,7 @@ 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.entity.ElecfeeBase;
 import org.jeecg.modules.elecfeeBase.mapper.ElecfeeBaseMapper;
 import org.jeecg.modules.emsStatistics.entity.EmsStatistics;
 import org.jeecg.modules.emsStatistics.mapper.EmsStatisticsMapper;
@@ -278,7 +279,37 @@ public class IEmsStatisticsServiceImpl implements IEmsStatisticsService {
      */
     @Override
     public Result<Object> DemandAnalysis(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());
+        }
+        List<String> months = DateUtils.MonthSplit(beginTime, endTime);
+        List<String> monthSplit = new ArrayList<>();
+        List<Double> mubiao = new ArrayList<>();
+        List<Float> shiji = new ArrayList<>();
+
+        // 循环遍历年月
+        for (String month : months) {
+            monthSplit.add(month.substring(5));
+
+            Float demand = 0f;
+            if (equipmentids.size() > 0) {
+                demand = emsStatisticsMapper.SelectMaxDmand(equipmentids, month);
+            }
+            shiji.add(demand == null ? 0f : demand);
+
+           ElecfeeBase elecfeeBase = elecfeeBaseMapper.selectDemandByYearmonth(month);
+            mubiao.add(elecfeeBase == null ? 0f : elecfeeBase.getKva());
+        }
+        map.put("monthsplit", monthSplit);
+        map.put("mubiao", mubiao);
+        map.put("shiji", shiji);
+        return Result.OK(map);
     }
 
     /**