2023-05-10 15:45:20 完成能源监测总电表的查询接口!

master
魔神煜修罗皇 2 years ago
parent 9b51b10d6e
commit 1efb3f20da
  1. 8
      psdc-business/src/main/java/com/psdc/entity/res/PsdcDevicePowerRes.java
  2. 26
      psdc-business/src/main/java/com/psdc/entity/res/TodayThisHourUseElectricInfoRes.java
  3. 7
      psdc-business/src/main/java/com/psdc/mapper/PsdcElectricHtdataMapper.java
  4. 8
      psdc-business/src/main/java/com/psdc/mapper/PsdcThermometerHtdataMapper.java
  5. 20
      psdc-business/src/main/java/com/psdc/service/IPsdcElectricHtdataService.java
  6. 11
      psdc-business/src/main/java/com/psdc/service/IPsdcElectricRtdataService.java
  7. 5
      psdc-business/src/main/java/com/psdc/service/IPsdcThermometerHtdataService.java
  8. 64
      psdc-business/src/main/java/com/psdc/service/impl/PsdcElectricHtdataServiceImpl.java
  9. 38
      psdc-business/src/main/java/com/psdc/service/impl/PsdcThermometerHtdataServiceImpl.java
  10. 27
      psdc-business/src/main/resources/mapper/business/PsdcElectricHtdataMapper.xml
  11. 23
      psdc-business/src/main/resources/mapper/business/PsdcThermometerHtdataMapper.xml
  12. 4
      psdc-web/src/main/java/com/psdc/controller/index/Index.java
  13. 52
      psdc-web/src/main/java/com/psdc/controller/monitor/TotalElectricMeterController.java

@ -21,6 +21,14 @@ public class PsdcDevicePowerRes {
* 总有功功率
*/
private Double totp;
/**
* 今日用电量
*/
private Double eDay;
/**
* 本月用电量
*/
private Double eMonth;
/**
* 当前总有功电能
*/

@ -0,0 +1,26 @@
package com.psdc.entity.res;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author戴仕崑
* @Projectpsdc
* @FilenameTodayThisHourUseElectricInfoRes
* @Date2023/5/10 15:20
* @Version 1.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TodayThisHourUseElectricInfoRes {
Integer id; // 序号
String hour; // 当前小时间段
Integer deviceId; // 设备Id
String upDateTime; // 更新时间
Double useElectric; // 该小时间段用电量
}

@ -3,6 +3,7 @@ package com.psdc.mapper;
import java.util.List;
import com.psdc.entity.PsdcElectricHtdata;
import com.psdc.entity.res.TodayThisHourUseElectricInfoRes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
@ -23,8 +24,12 @@ public interface PsdcElectricHtdataMapper{
*/
PsdcElectricHtdata queryById(Integer electricHtdataId);
List<TodayThisHourUseElectricInfoRes> selThisHourUseElectric(@Param(value = "deviceId") Integer deviceId,
@Param(value = "upDate") String upDate);
Double selTodayUseEnergy(@Param(value = "deviceId") Integer deviceId,
@Param(value = "updateTime") String updateTime);
@Param(value = "beginTime") String begin_time,
@Param(value = "endTime") String end_time);
/**

@ -34,12 +34,10 @@ public interface PsdcThermometerHtdataMapper{
List<PsdcThermometerHtdata> queryAllByLimit(PsdcThermometerHtdata psdcThermometerHtdata, @Param("pageable") Pageable pageable);
List<Double> selTodayThermometer(@Param(value = "temp") String temp,
@Param(value = "deviceId") Integer deviceId,
@Param(value = "updateTime") String updateTime);
List<PsdcThermometerHtdata> selTodayThermometer(@Param(value = "deviceId") Integer deviceId,
@Param(value = "beginTime") String begin_time,
@Param(value = "endTime") String end_time);
List<String> selTodayThermometer2(@Param(value = "deviceId") Integer deviceId,
@Param(value = "updateTime") String updateTime);
/**
* 统计总行数

@ -0,0 +1,20 @@
package com.psdc.service;
import java.util.List;
import java.util.Map;
/**
* @Author戴仕崑
* @Projectpsdc
* @FilenameIPsdcElectricHtdata
* @Date2023/5/10 9:00
* @Version 1.0
*/
public interface IPsdcElectricHtdataService {
Map selTotalElectricityInfo();
List selThisHourUseElectric();
}

@ -0,0 +1,11 @@
package com.psdc.service;
/**
* @Author戴仕崑
* @Projectpsdc
* @FilenameIPsdcElectricRtdata
* @Date2023/5/10 9:00
* @Version 1.0
*/
public interface IPsdcElectricRtdataService {
}

@ -1,8 +1,9 @@
package com.psdc.service;
import com.psdc.core.domain.AjaxResult;
import com.psdc.entity.PsdcDevicePowerHdata96;
import com.psdc.entity.res.PsdcDevicePowerRes;
import java.util.List;
/**
* @Author戴仕崑
@ -18,6 +19,6 @@ public interface IPsdcThermometerHtdataService {
AjaxResult sel8WnDu();
AjaxResult selTotalElectricityInfo();
PsdcDevicePowerRes selTotalElectricityInfo();
}

@ -0,0 +1,64 @@
package com.psdc.service.impl;
import com.psdc.mapper.PsdcElectricHtdataMapper;
import com.psdc.service.IPsdcElectricHtdataService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @Author戴仕崑
* @Projectpsdc
* @FilenamePsdcElectricRtdataServiceImpl
* @Date2023/5/10 9:01
* @Version 1.0
*/
@Service
public class PsdcElectricHtdataServiceImpl implements IPsdcElectricHtdataService {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
@Resource
PsdcElectricHtdataMapper electricHtdataMapper;
@Override
public Map selTotalElectricityInfo() {
Date date = new Date();
Map<String, Double> map = new HashMap<>();
String tb = df.format(date) + " 00:00:00"; // 今天开始检索时间
String te = df.format(date) + " 23:59:59"; // 今天结束检索时间
String mb = benYue()[0] + " 00:00:00"; // 本月开始检索时间
String me = benYue()[1] + " 23:59:59"; // 本月结束检索时间
Double todayUseElectric = electricHtdataMapper.selTodayUseEnergy(13, tb, te);// 总电表今日用电量
Double toMonthUseElectric = electricHtdataMapper.selTodayUseEnergy(13, mb, me);// 总电表本月用电量
map.put("eday", todayUseElectric);
map.put("emonth", toMonthUseElectric);
return map;
}
@Override
public List selThisHourUseElectric() {
return electricHtdataMapper.selThisHourUseElectric(13, df.format(new Date()));
}
private String[] benYue(){
String startDay = df.format(new Date());
String[] s1 = new String[2];
Calendar calendar = Calendar.getInstance();
calendar.set(Integer.parseInt(startDay.substring(0,4)), Integer.parseInt(startDay.substring(5,7)) - 1, 1);
String firstDayOfMonth = df.format(calendar.getTime());
s1[0] = firstDayOfMonth;
// 这里先设置要获取月份的下月的第一天
calendar.set(Integer.parseInt(startDay.substring(0,4)), Integer.parseInt(startDay.substring(5,7)), 1);
// 这里将日期值减去一天,从而获取到要求的月份最后一天
calendar.add(Calendar.DATE, -1);
String lastDayOfMonth = df.format(calendar.getTime());
s1[1] = lastDayOfMonth;
return s1;
}
}

@ -2,7 +2,7 @@ package com.psdc.service.impl;
import com.psdc.core.domain.AjaxResult;
import com.psdc.entity.PsdcDevicePowerHdata96;
import com.psdc.entity.PsdcElectricRtdata;
import com.psdc.entity.PsdcThermometerHtdata;
import com.psdc.entity.res.PsdcDevicePowerRes;
import com.psdc.entity.res.PsdcThermometerDataRes;
import com.psdc.mapper.*;
@ -49,13 +49,33 @@ public class PsdcThermometerHtdataServiceImpl implements IPsdcThermometerHtdataS
List<PsdcThermometerDataRes> ary = new ArrayList();
for (Integer d : devList) {
// 查询今日实时温度数据
PsdcThermometerDataRes dataRes = psdcThermometerRtdataMapper.queryById(d);
List<Double> listIn = psdcThermometerHtdataMapper.selTodayThermometer("thermometer_value_in", d, sdf.format(date));
List<Double> listOut = psdcThermometerHtdataMapper.selTodayThermometer("thermometer_value_out", d, sdf.format(date));
List<Double> listTemp = psdcThermometerHtdataMapper.selTodayThermometer("thermometer_value", d, sdf.format(date));
List<String> times = psdcThermometerHtdataMapper.selTodayThermometer2(d, sdf.format(date));
Double useEnergy = psdcElectricHtdataMapper.selTodayUseEnergy(d, sdf.format(date));
String tb = sdf.format(date) + " 00:00:00"; // 今天开始检索时间
String te = sdf.format(date) + " 23:59:59"; // 今天结束检索时间
List<Double> listIn = new ArrayList(); // 今天历史进水温度集合
List<Double> listOut = new ArrayList(); // 今天历史出水温度集合
List<Double> listTemp = new ArrayList(); // 今天历史温度集合
List<String> times = new ArrayList(); // 时间轴
// 循环遍历今天历史数据对象集合
List<PsdcThermometerHtdata> htdata = psdcThermometerHtdataMapper.selTodayThermometer(d, tb, te);
for (PsdcThermometerHtdata h : htdata){
listTemp.add(h.getThermometerValue());
if (null != h.getThermometerValueIn()){
listIn.add(h.getThermometerValueIn());
}
if (null != h.getThermometerValueOut()){
listOut.add(h.getThermometerValueOut());
}
String t = h.getUpdateTime().split(" ")[1].substring(0,5);
times.add(t);
}
Double useEnergy = psdcElectricHtdataMapper.selTodayUseEnergy(d, tb, te);
dataRes.setTimeList(times);
dataRes.setTempTodayList(listTemp);
dataRes.setTempInTodayList(listIn);
@ -75,12 +95,12 @@ public class PsdcThermometerHtdataServiceImpl implements IPsdcThermometerHtdataS
}
@Override
public AjaxResult selTotalElectricityInfo() {
public PsdcDevicePowerRes selTotalElectricityInfo() {
long userId = SecurityUtils.getUserId();
PsdcDevicePowerHdata96 hdata96 = psdcDevicePowerHdata96Mapper.queryById(userId, 13, sdf2.format(new Date()));
PsdcDevicePowerRes rtdata = psdcElectricRtdataMapper.queryById(13);
rtdata.setTodayUsePowers(hdata96);
return AjaxResult.success(rtdata);
return rtdata;
}

@ -45,6 +45,14 @@
<result property="combqh" column="CombQh" />
</resultMap>
<resultMap id="PsdcElectricHtdataMap2" type="com.psdc.entity.res.TodayThisHourUseElectricInfoRes">
<result property="id" column="electric_htdata_id" />
<result property="hour" column="hour" />
<result property="deviceId" column="device_id" />
<result property="upDateTime" column="update_time" />
<result property="useElectric" column="use_deiffen" />
</resultMap>
<!-- 通过ID查询单条数据 -->
<select id="queryById" resultMap="PsdcElectricHtdataMap">
select
@ -54,18 +62,33 @@
where electric_htdata_id = #{electricHtdataId}
</select>
<select id="selThisHourUseElectric" resultMap="PsdcElectricHtdataMap2">
Select electric_htdata_id ,dt.time As `hour`,device_id,DATE_FORMAT(update_time,'%H:%i:%S') As `update_time`,
IFNULL(SUM(use_deiffen),0) As use_deiffen
From psdc_datetime dt
Left Join psdc_electric_htdata peht On dt.time = DATE_FORMAT(update_time,'%H')
And device_id = ${deviceId} And DATE_FORMAT(update_time,'%Y-%m-%d') = #{upDate}
Where dt.time is Not Null
Group By dt.time
Order By dt.time
</select>
<select id="selTodayUseEnergy" resultType="java.lang.Double">
Select SUM(use_deiffen) From psdc_electric_htdata
<where>
<if test="deviceId != null and deviceId != ''">
device_id = #{deviceId}
</if>
<if test="updateTime != null and updateTime != ''">
And update_time Like concat('%',#{updateTime},'%')
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
And date_format(update_time,'%Y-%m-%d %H:%i:%S') &gt;= date_format(#{beginTime},'%Y-%m-%d %H:%i:%S')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
And date_format(update_time,'%Y-%m-%d %H:%i:%S') &lt;= date_format(#{endTime},'%Y-%m-%d %H:%i:%S')
</if>
</where>
</select>
<!--分页查询指定行数据-->
<select id="queryAllByLimit" resultMap="PsdcElectricHtdataMap">
select

@ -18,30 +18,23 @@
where thermometer_htdata_id = #{thermometerHtdataId}
</select>
<select id="selTodayThermometer" resultType="java.lang.Double">
Select ${temp} From psdc_thermometer_htdata
<select id="selTodayThermometer" resultMap="PsdcThermometerHtdataMap">
Select thermometer_htdata_id,device_id,thermometer_value,thermometer_value_in,thermometer_value_out,update_time From psdc_thermometer_htdata
<where>
<if test="deviceId != null and deviceId != ''">
device_id = #{deviceId}
</if>
<if test="updateTime != null and updateTime != ''">
And update_time Like concat('%',#{updateTime},'%')
</if>
</where>
</select>
<select id="selTodayThermometer2" resultType="java.lang.String">
Select update_time From psdc_thermometer_htdata
<where>
<if test="deviceId != null and deviceId != ''">
device_id = #{deviceId}
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
And date_format(update_time,'%Y-%m-%d %H:%i:%S') &gt;= date_format(#{beginTime},'%Y-%m-%d %H:%i:%S')
</if>
<if test="updateTime != null and updateTime != ''">
And update_time Like concat('%',#{updateTime},'%')
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
And date_format(update_time,'%Y-%m-%d %H:%i:%S') &lt;= date_format(#{endTime},'%Y-%m-%d %H:%i:%S')
</if>
</where>
ORDER BY update_time
</select>
<!--分页查询指定行数据-->
<select id="queryAllByLimit" resultMap="PsdcThermometerHtdataMap">
Select

@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/api/indexLook")
@ -28,7 +27,8 @@ public class Index {
@RequestMapping(value = "/zdb", method = RequestMethod.GET)
public AjaxResult selzdb() {
return psdcThermometerHtdataService.selTotalElectricityInfo();
AjaxResult ajax = AjaxResult.success(psdcThermometerHtdataService.selTotalElectricityInfo());
return ajax;
}
}

@ -0,0 +1,52 @@
package com.psdc.controller.monitor;
import com.psdc.core.domain.AjaxResult;
import com.psdc.entity.res.PsdcDevicePowerRes;
import com.psdc.service.IPsdcElectricHtdataService;
import com.psdc.service.IPsdcThermometerHtdataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* @Author戴仕崑
* @Projectpsdc
* @FilenameTotalElectricMeterController
* @Date2023/5/10 10:59
* @Version 1.0
*/
@RestController
@RequestMapping("/api/monitor/db/index")
public class TotalElectricMeterController {
@Autowired
IPsdcThermometerHtdataService psdcThermometerHtdataService;
@Autowired
IPsdcElectricHtdataService psdcElectricHtdataService;
@PreAuthorize("@ss.hasPermi('emonitor:db')")
@RequestMapping(value = "/sel1", method = RequestMethod.GET)
public AjaxResult selzdb1() {
PsdcDevicePowerRes devicePowerRes = psdcThermometerHtdataService.selTotalElectricityInfo();
Map map = psdcElectricHtdataService.selTotalElectricityInfo();
devicePowerRes.setEDay((Double) map.get("eday"));
devicePowerRes.setEMonth((Double) map.get("emonth"));
AjaxResult ajax = AjaxResult.success(devicePowerRes);
return ajax;
}
@PreAuthorize("@ss.hasPermi('emonitor:db')")
@RequestMapping(value = "/sel2", method = RequestMethod.GET)
public AjaxResult selzdb2() {
List list = psdcElectricHtdataService.selThisHourUseElectric();
AjaxResult ajax = AjaxResult.success(list);
return ajax;
}
}
Loading…
Cancel
Save