瀏覽代碼

用能月报调整1

jichaobo 3 年之前
父節點
當前提交
1a45b9cc24

+ 16 - 0
fiveep-persistence/src/main/java/com/bizmatics/persistence/mapper/HtAnalogDataMapper.java

@@ -116,6 +116,13 @@ public interface HtAnalogDataMapper extends CrudMapper<HtAnalogData> {
                                        @Param("cycle") Integer cycle,
                                        @Param("sign") Integer sign);
 
+    List<HtAnalogDataVo> getEnergyUseList(@Param("deviceCode") String deviceCode,
+                                          @Param("startTime") String startTime,
+                                          @Param("endTime") String endTime,
+                                          @Param("cycle") Integer cycle,
+                                          @Param("sign") Integer sign,
+                                          @Param("table") String table);
+
     List<HtAnalogDataVo> demandAnalysisList(@Param("deviceCode") String deviceCode,
                                             @Param("monthDate") String monthDate);
 
@@ -128,6 +135,15 @@ public interface HtAnalogDataMapper extends CrudMapper<HtAnalogData> {
                                              @Param("size") Integer size,
                                              @Param("startCurrent") Integer startCurrent);
 
+    List<HtAnalogDataOneVo> getEnergyUseListOne(@Param("deviceCode") String deviceCode,
+                                                @Param("startTime") String startTime,
+                                                @Param("endTime") String endTime,
+                                                @Param("cycle") Integer cycle,
+                                                @Param("sign") Integer sign,
+                                                @Param("size") Integer size,
+                                                @Param("startCurrent") Integer startCurrent,
+                                                @Param("table") String table);
+
     List<SingleLoopReportVo> SingleLoopReportData(@Param("deviceCode") String deviceCode,
                                                   @Param("startTime") String startTime,
                                                   @Param("endTime") String endTime);

+ 234 - 0
fiveep-persistence/src/main/resources/mapper/mysql/HtAnalogDataMapper.xml

@@ -964,6 +964,120 @@
         </if>
     </select>
 
+    <select id="getEnergyUseList" resultType="com.bizmatics.model.vo.HtAnalogDataVo">
+        <if test="cycle == 1">
+            SELECT
+            b.id,
+            a.minid,
+            b.Epp,
+            b.Demand,
+            freezingTime AS freezingTimes
+            FROM
+            (
+            <if test="sign == 1">
+                SELECT
+                max(id) AS minid,
+                freezingTime AS freezingTimess
+            </if>
+            <if test="sign == 2">
+                SELECT
+                min(id) AS minid,
+                freezingTime AS freezingTimess
+            </if>
+            FROM
+            ${table}
+            <where>
+                and deviceName = #{deviceCode}
+                <if test="endTime != null and startTime != null and endTime != '' and startTime != ''">
+                    and dataTime BETWEEN #{startTime} and #{endTime}
+                </if>
+            </where>
+            GROUP BY freezingTimess
+            ) a
+            LEFT JOIN ${table} b ON a.minid = b.id;
+        </if>
+        <if test="cycle == 2">
+            SELECT
+            b.id,
+            a.minid,
+            b.Epp,
+            b.Demand,
+            FROM_UNIXTIME(
+            UNIX_TIMESTAMP(b.dataTime),
+            '%Y-%m'
+            ) AS freezingTimes
+            FROM
+            (
+            <if test="sign == 1">
+                SELECT
+                max(id) AS minid,
+                FROM_UNIXTIME(
+                UNIX_TIMESTAMP(dataTime),
+                '%Y-%m'
+                ) AS freezingTimess
+            </if>
+            <if test="sign == 2">
+                SELECT
+                min(id) AS minid,
+                FROM_UNIXTIME(
+                UNIX_TIMESTAMP(dataTime),
+                '%Y-%m'
+                ) AS freezingTimess
+            </if>
+            FROM
+            ${table}
+            <where>
+                and deviceName = #{deviceCode}
+                <if test="endTime != null and startTime != null and endTime != '' and startTime != ''">
+                    and dataTime BETWEEN #{startTime} and #{endTime}
+                </if>
+            </where>
+            GROUP BY freezingTimess
+            ) a
+            LEFT JOIN ${table} b ON a.minid = b.id;
+        </if>
+        <if test="cycle == 3">
+            SELECT
+            b.id,
+            a.minid,
+            b.Epp,
+            b.Demand,
+            FROM_UNIXTIME(
+            UNIX_TIMESTAMP(b.dataTime),
+            '%Y-%m'
+            ) AS freezingTimes
+            FROM
+            (
+            <if test="sign == 1">
+                SELECT
+                max(id) AS minid,
+                FROM_UNIXTIME(
+                UNIX_TIMESTAMP(dataTime),
+                '%Y'
+                ) AS freezingTimess
+            </if>
+            <if test="sign == 2">
+                SELECT
+                min(id) AS minid,
+                FROM_UNIXTIME(
+                UNIX_TIMESTAMP(dataTime),
+                '%Y'
+                ) AS freezingTimess
+            </if>
+            FROM
+            ${table}
+            <where>
+                and deviceName = #{deviceCode}
+                <if test="endTime != null and startTime != null and endTime != '' and startTime != ''">
+                    and dataTime BETWEEN #{startTime} and #{endTime}
+                </if>
+            </where>
+            GROUP BY freezingTimess
+            ) a
+            LEFT JOIN ${table} b ON a.minid = b.id;
+        </if>
+    </select>
+
     <select id="energyUseListOne" resultType="com.bizmatics.model.vo.HtAnalogDataOneVo">
         <if test="cycle == 1">
             SELECT
@@ -1084,6 +1198,126 @@
         </if>
     </select>
 
+    <select id="getEnergyUseListOne" resultType="com.bizmatics.model.vo.HtAnalogDataOneVo">
+        <if test="cycle == 1">
+            SELECT
+            b.id,
+            b.Epp,
+            freezingTime AS freezingTime
+            FROM
+            (
+            <if test="sign == 1">
+                SELECT
+                max(id) AS minid,
+                freezingTime AS freezingTimess
+            </if>
+            <if test="sign == 2">
+                SELECT
+                min(id) AS minid,
+                freezingTime AS freezingTimess
+            </if>
+            FROM
+            ${tabel}
+            <where>
+                and deviceName = #{deviceCode}
+                <if test="endTime != null and startTime != null and endTime != '' and startTime != ''">
+                    and dataTime BETWEEN #{startTime} and #{endTime}
+                </if>
+            </where>
+            GROUP BY freezingTimess
+            ) a
+            LEFT JOIN ${tabel} b ON a.minid = b.id
+            <if test="startCurrent != null and size !=0 and size!=null">
+                LIMIT #{startCurrent},
+                #{size}
+            </if>
+        </if>
+        <if test="cycle == 2">
+            SELECT
+            b.id,
+            b.Epp,
+            FROM_UNIXTIME(
+            UNIX_TIMESTAMP(b.dataTime),
+            '%Y-%m'
+            ) AS freezingTime
+            FROM
+            (
+            <if test="sign == 1">
+                SELECT
+                max(id) AS minid,
+                FROM_UNIXTIME(
+                UNIX_TIMESTAMP(dataTime),
+                '%Y-%m'
+                ) AS freezingTimess
+            </if>
+            <if test="sign == 2">
+                SELECT
+                min(id) AS minid,
+                FROM_UNIXTIME(
+                UNIX_TIMESTAMP(dataTime),
+                '%Y-%m'
+                ) AS freezingTimess
+            </if>
+            FROM
+            ${tabel}
+            <where>
+                and deviceName = #{deviceCode}
+                <if test="endTime != null and startTime != null and endTime != '' and startTime != ''">
+                    and dataTime BETWEEN #{startTime} and #{endTime}
+                </if>
+            </where>
+            GROUP BY freezingTimess
+            ) a
+            LEFT JOIN ${tabel} b ON a.minid = b.id
+            <if test="startCurrent != null and size !=0 and size!=null">
+                LIMIT #{startCurrent},
+                #{size}
+            </if>
+        </if>
+        <if test="cycle == 3">
+            SELECT
+            b.id,
+            b.Epp,
+            FROM_UNIXTIME(
+            UNIX_TIMESTAMP(b.dataTime),
+            '%Y-%m'
+            ) AS freezingTime
+            FROM
+            (
+            <if test="sign == 1">
+                SELECT
+                max(id) AS minid,
+                FROM_UNIXTIME(
+                UNIX_TIMESTAMP(dataTime),
+                '%Y'
+                ) AS freezingTimess
+            </if>
+            <if test="sign == 2">
+                SELECT
+                min(id) AS minid,
+                FROM_UNIXTIME(
+                UNIX_TIMESTAMP(dataTime),
+                '%Y'
+                ) AS freezingTimess
+            </if>
+            FROM
+            ${tabel}
+            <where>
+                and deviceName = #{deviceCode}
+                <if test="endTime != null and startTime != null and endTime != '' and startTime != ''">
+                    and dataTime BETWEEN #{startTime} and #{endTime}
+                </if>
+            </where>
+            GROUP BY freezingTimess
+            ) a
+            LEFT JOIN ${tabel} b ON a.minid = b.id
+            <if test="startCurrent != null and size !=0 and size!=null">
+                LIMIT #{startCurrent},
+                #{size}
+            </if>
+        </if>
+    </select>
+
     <select id="demandAnalysisList" resultType="com.bizmatics.model.vo.HtAnalogDataVo">
         SELECT
         MAX(Demand) as Demand,

+ 54 - 4
fiveep-service/src/main/java/com/bizmatics/service/impl/HtAnalogDataServiceImpl.java

@@ -776,8 +776,25 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
     public List<CommonIcoVO> monthlyReport(String deviceCode, int cycle, String startTime, String endTime) {
         List<Object> eppList = new ArrayList<>();
         List<Object> freezingTimesList = new ArrayList<>();
-        List<HtAnalogDataVo> maxMonthlyReport = baseMapper.energyUseList(deviceCode, startTime, endTime, cycle, 1);
-        List<HtAnalogDataVo> minMonthlyReport = baseMapper.energyUseList(deviceCode, startTime, endTime, cycle, 2);
+
+        LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(Device::getDeviceCode, deviceCode);
+        List<Device> deviceList = deviceService.list(queryWrapper);
+        String table = "ht_analog_data";
+        if(deviceList.size()>0){
+            if (deviceList.get(0).getDeviceType().equals("1")){
+                table = "ht_analog_data";
+            }else if (deviceList.get(0).getDeviceType().equals("4")){
+                table = "ht_analog_173_data";
+            }else {
+                throw new BusinessException("173用电设备无用电数据采集");
+            }
+        }else {
+            throw new BusinessException("错误数据,设备不存在");
+        }
+
+        List<HtAnalogDataVo> maxMonthlyReport = baseMapper.getEnergyUseList(deviceCode, startTime, endTime, cycle, 1,table);
+        List<HtAnalogDataVo> minMonthlyReport = baseMapper.getEnergyUseList(deviceCode, startTime, endTime, cycle, 2,table);
         if (maxMonthlyReport.size() > 0) {
             for (int i = 0; i < maxMonthlyReport.size(); i++) {
                 BigDecimal b1 = new BigDecimal(maxMonthlyReport.get(i).getEpp().toString());
@@ -791,6 +808,24 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
         return list;
     }
 
+//    public List<CommonIcoVO> monthlyReport(String deviceCode, int cycle, String startTime, String endTime) {
+//        List<Object> eppList = new ArrayList<>();
+//        List<Object> freezingTimesList = new ArrayList<>();
+//        List<HtAnalogDataVo> maxMonthlyReport = baseMapper.energyUseList(deviceCode, startTime, endTime, cycle, 1);
+//        List<HtAnalogDataVo> minMonthlyReport = baseMapper.energyUseList(deviceCode, startTime, endTime, cycle, 2);
+//        if (maxMonthlyReport.size() > 0) {
+//            for (int i = 0; i < maxMonthlyReport.size(); i++) {
+//                BigDecimal b1 = new BigDecimal(maxMonthlyReport.get(i).getEpp().toString());
+//                BigDecimal b2 = new BigDecimal(minMonthlyReport.get(i).getEpp().toString());
+//                eppList.add(b1.subtract(b2).doubleValue());
+//                freezingTimesList.add(maxMonthlyReport.get(i).getFreezingTimes());
+//            }
+//        }
+//        List<CommonIcoVO> list = new ArrayList<>();
+//        list.add(CommonIcoVO.builder().name("电量").list(eppList).listDate(freezingTimesList).build());
+//        return list;
+//    }
+
 
     @Override
     public List<CommonIcoVO> demandAnalysis(String deviceCode, String monthDate, int cycle) {
@@ -874,8 +909,23 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
     @Override
     public List<HtAnalogDataOneVo> monthlyReportlist(String deviceCode, String startTime, String endTime, int cycle, Integer startCurrent) {
         List<HtAnalogDataOneVo> listOne = new ArrayList<>();
-        List<HtAnalogDataOneVo> maxMonthlyReport = baseMapper.energyUseListOne(deviceCode, startTime, endTime, cycle, 1, 10000, startCurrent);
-        List<HtAnalogDataOneVo> minMonthlyReport = baseMapper.energyUseListOne(deviceCode, startTime, endTime, cycle, 2, 10000, startCurrent);
+        LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(Device::getDeviceCode, deviceCode);
+        List<Device> deviceList = deviceService.list(queryWrapper);
+        String table = "ht_analog_data";
+        if(deviceList.size()>0){
+            if (deviceList.get(0).getDeviceType().equals("1")){
+                table = "ht_analog_data";
+            }else if (deviceList.get(0).getDeviceType().equals("4")){
+                table = "ht_analog_173_data";
+            }else {
+                throw new BusinessException("173用电设备无用电数据采集");
+            }
+        }else {
+            throw new BusinessException("错误数据,设备不存在");
+        }
+        List<HtAnalogDataOneVo> maxMonthlyReport = baseMapper.getEnergyUseListOne(deviceCode, startTime, endTime, cycle, 1, 10000, startCurrent,table);
+        List<HtAnalogDataOneVo> minMonthlyReport = baseMapper.getEnergyUseListOne(deviceCode, startTime, endTime, cycle, 2, 10000, startCurrent,table);
         if (maxMonthlyReport.size() > 0) {
             Double epp=0.00;
             for (int j = 0; j < maxMonthlyReport.size()+1; j++) {