历史数据统计接口
This commit is contained in:
parent
6fc63e7563
commit
a1c68e8506
|
@ -3,10 +3,12 @@ package com.isu.gaswellwatch.controller;
|
||||||
|
|
||||||
import com.isu.gaswellwatch.entity.Response;
|
import com.isu.gaswellwatch.entity.Response;
|
||||||
import com.isu.gaswellwatch.service.SummaryService;
|
import com.isu.gaswellwatch.service.SummaryService;
|
||||||
|
import com.isu.gaswellwatch.vo.summary.LineSummaryVO;
|
||||||
import com.isu.gaswellwatch.vo.summary.PieSummaryVO;
|
import com.isu.gaswellwatch.vo.summary.PieSummaryVO;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -25,5 +27,20 @@ public class SummaryController {
|
||||||
return Response.succeed(this.summaryService.getIndexPieSummary());
|
return Response.succeed(this.summaryService.getIndexPieSummary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getPressureChartData")
|
||||||
|
public Response<LineSummaryVO> getPressureChartData(@RequestParam(required = false)String startTime,
|
||||||
|
@RequestParam (required = false)String endTime,
|
||||||
|
@RequestParam Long deviceId) {
|
||||||
|
return Response.succeed(this.summaryService.getPressureChartData(startTime,endTime,deviceId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getSwitchChartData")
|
||||||
|
public Response<LineSummaryVO> getSwitchChartData(@RequestParam(required = false)String startTime,
|
||||||
|
@RequestParam (required = false)String endTime,
|
||||||
|
@RequestParam Long deviceId) {
|
||||||
|
return Response.succeed(this.summaryService.getSwitchChartData(startTime,endTime,deviceId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,5 +39,9 @@ public interface DeviceDao extends BaseMapper<Device> {
|
||||||
@Param("deviceId") Long deviceId);
|
@Param("deviceId") Long deviceId);
|
||||||
|
|
||||||
List<DeviceVO> getDeviceVOByIds(@Param("idList")List<Long> deviceIdList);
|
List<DeviceVO> getDeviceVOByIds(@Param("idList")List<Long> deviceIdList);
|
||||||
|
|
||||||
|
List<DeviceHistoryVO> getPressureChartData(Long deviceId, String startTime, String endTime, String tableName);
|
||||||
|
|
||||||
|
List<DeviceHistoryVO> getSwitchStatusData(Long deviceId, String startTime, String endTime, String tableName,String deviceProduct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,5 +32,9 @@ public interface DeviceService extends IService<Device> {
|
||||||
Page<DeviceOptLog> getDeviceLogData(Integer currentPage, Integer pageSize, String startTime, String endTime, Long deviceId) throws ParseException;
|
Page<DeviceOptLog> getDeviceLogData(Integer currentPage, Integer pageSize, String startTime, String endTime, Long deviceId) throws ParseException;
|
||||||
|
|
||||||
List<DeviceVO> getDeviceVOByIds(List<Long> deviceIdList);
|
List<DeviceVO> getDeviceVOByIds(List<Long> deviceIdList);
|
||||||
|
|
||||||
|
List<DeviceHistoryVO> getPressureChartData(Long deviceId, String startTime, String endTime);
|
||||||
|
|
||||||
|
List<DeviceHistoryVO> getSwitchStatusData(Long deviceId, String startTime, String endTime,String deviceProduct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.isu.gaswellwatch.service;
|
package com.isu.gaswellwatch.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.isu.gaswellwatch.vo.summary.LineSummaryVO;
|
||||||
import com.isu.gaswellwatch.vo.summary.PieSummaryVO;
|
import com.isu.gaswellwatch.vo.summary.PieSummaryVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -8,5 +9,9 @@ import java.util.List;
|
||||||
public interface SummaryService{
|
public interface SummaryService{
|
||||||
|
|
||||||
List<PieSummaryVO> getIndexPieSummary();
|
List<PieSummaryVO> getIndexPieSummary();
|
||||||
|
|
||||||
|
LineSummaryVO getPressureChartData(String startTime, String endTime, Long deviceId);
|
||||||
|
|
||||||
|
LineSummaryVO getSwitchChartData(String startTime, String endTime, Long deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,6 +183,18 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements
|
||||||
return this.deviceDao.getDeviceVOByIds(deviceIdList);
|
return this.deviceDao.getDeviceVOByIds(deviceIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceHistoryVO> getPressureChartData(Long deviceId, String startTime, String endTime) {
|
||||||
|
String tableName = Redis2DBPersistenceService.DEFAULT_DATA_TABLE + deviceId;
|
||||||
|
return deviceDao.getPressureChartData(deviceId,startTime,endTime,tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceHistoryVO> getSwitchStatusData(Long deviceId, String startTime, String endTime,String deviceProduct) {
|
||||||
|
String tableName = Redis2DBPersistenceService.DEFAULT_DATA_TABLE + deviceId;
|
||||||
|
return deviceDao.getSwitchStatusData(deviceId,startTime,endTime,tableName,deviceProduct);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<DeviceHistoryVO> getDeviceHistoryData(Integer currentPage, Integer pageSize, String startTime, String endTime, Long deviceId) throws ParseException {
|
public Page<DeviceHistoryVO> getDeviceHistoryData(Integer currentPage, Integer pageSize, String startTime, String endTime, Long deviceId) throws ParseException {
|
||||||
|
|
|
@ -2,11 +2,15 @@ package com.isu.gaswellwatch.service.impl;
|
||||||
|
|
||||||
import com.isu.gaswellwatch.service.DeviceService;
|
import com.isu.gaswellwatch.service.DeviceService;
|
||||||
import com.isu.gaswellwatch.service.SummaryService;
|
import com.isu.gaswellwatch.service.SummaryService;
|
||||||
|
import com.isu.gaswellwatch.vo.DeviceHistoryVO;
|
||||||
import com.isu.gaswellwatch.vo.DeviceVO;
|
import com.isu.gaswellwatch.vo.DeviceVO;
|
||||||
|
import com.isu.gaswellwatch.vo.summary.LineDataVO;
|
||||||
|
import com.isu.gaswellwatch.vo.summary.LineSummaryVO;
|
||||||
import com.isu.gaswellwatch.vo.summary.PieDataVO;
|
import com.isu.gaswellwatch.vo.summary.PieDataVO;
|
||||||
import com.isu.gaswellwatch.vo.summary.PieSummaryVO;
|
import com.isu.gaswellwatch.vo.summary.PieSummaryVO;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -95,6 +99,95 @@ public class SummaryServiceImpl implements SummaryService {
|
||||||
return pieSummaryVOList;
|
return pieSummaryVOList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LineSummaryVO getPressureChartData(String startTime, String endTime, Long deviceId) {
|
||||||
|
//根据设备ID、时间范围查询设备历史数据表的油压 套压
|
||||||
|
DeviceVO deviceVO = deviceService.getDevice(deviceId);
|
||||||
|
if(deviceVO == null){
|
||||||
|
throw new RuntimeException("设备不存在");
|
||||||
|
}
|
||||||
|
List<String> xAxisData = new ArrayList<>();
|
||||||
|
|
||||||
|
List<DeviceHistoryVO> dataList = deviceService.getPressureChartData(deviceId,startTime,endTime);
|
||||||
|
//将查询到的结果组装成LineSummaryVO返回给前端
|
||||||
|
LineSummaryVO lineSummaryVO = new LineSummaryVO();
|
||||||
|
lineSummaryVO.setTitle(deviceVO.getGasWell().getName());
|
||||||
|
|
||||||
|
//设置图例数据
|
||||||
|
List<String> legendData = new ArrayList<>();
|
||||||
|
legendData.add("油压");
|
||||||
|
legendData.add("套压");
|
||||||
|
lineSummaryVO.setLegendData(legendData);
|
||||||
|
|
||||||
|
List<String> oilPressureData = new ArrayList<>();
|
||||||
|
List<String> casPressureData = new ArrayList<>();
|
||||||
|
|
||||||
|
for(DeviceHistoryVO deviceHistoryVO : dataList){
|
||||||
|
xAxisData.add(deviceHistoryVO.getCollectionTime());
|
||||||
|
oilPressureData.add(StringUtils.isEmpty(deviceHistoryVO.getOilPressure())?"0":deviceHistoryVO.getOilPressure());
|
||||||
|
casPressureData.add(StringUtils.isEmpty(deviceHistoryVO.getCasPressure())?"0":deviceHistoryVO.getCasPressure());
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置x轴数据(日期)
|
||||||
|
lineSummaryVO.setXAxisData(xAxisData);
|
||||||
|
|
||||||
|
//设置y轴数据(油压、套压)
|
||||||
|
List<LineDataVO> series = new ArrayList<>();
|
||||||
|
LineDataVO oil = new LineDataVO();
|
||||||
|
oil.setName("油压");
|
||||||
|
oil.setType("line");
|
||||||
|
oil.setData(oilPressureData);
|
||||||
|
|
||||||
|
LineDataVO cas = new LineDataVO();
|
||||||
|
cas.setName("套压");
|
||||||
|
cas.setType("line");
|
||||||
|
cas.setData(casPressureData);
|
||||||
|
|
||||||
|
series.add(oil);
|
||||||
|
series.add(cas);
|
||||||
|
|
||||||
|
lineSummaryVO.setSeries(series);
|
||||||
|
return lineSummaryVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LineSummaryVO getSwitchChartData(String startTime, String endTime, Long deviceId) {
|
||||||
|
DeviceVO deviceVO = deviceService.getDevice(deviceId);
|
||||||
|
if(deviceVO == null){
|
||||||
|
throw new RuntimeException("设备不存在");
|
||||||
|
}
|
||||||
|
List<String> xAxisData = new ArrayList<>();
|
||||||
|
|
||||||
|
List<DeviceHistoryVO> dataList = deviceService.getSwitchStatusData(deviceId,startTime,endTime,deviceVO.getProduct().getCode());
|
||||||
|
LineSummaryVO lineSummaryVO = new LineSummaryVO();
|
||||||
|
lineSummaryVO.setTitle(deviceVO.getGasWell().getName());
|
||||||
|
|
||||||
|
//设置图例数据
|
||||||
|
List<String> legendData = new ArrayList<>();
|
||||||
|
legendData.add("开关状态");
|
||||||
|
lineSummaryVO.setLegendData(legendData);
|
||||||
|
|
||||||
|
List<String> switchStatusData = new ArrayList<>();
|
||||||
|
|
||||||
|
for(DeviceHistoryVO deviceHistoryVO : dataList){
|
||||||
|
xAxisData.add(deviceHistoryVO.getCollectionTime());
|
||||||
|
switchStatusData.add(StringUtils.isEmpty(deviceHistoryVO.getWellStatus())?"0":deviceHistoryVO.getWellStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置x轴数据(日期)
|
||||||
|
lineSummaryVO.setXAxisData(xAxisData);
|
||||||
|
|
||||||
|
//设置y轴数据(开关状态)
|
||||||
|
List<LineDataVO> series = new ArrayList<>();
|
||||||
|
LineDataVO status = new LineDataVO();
|
||||||
|
status.setName("开关状态");
|
||||||
|
status.setType("line");
|
||||||
|
status.setData(switchStatusData);
|
||||||
|
series.add(status);
|
||||||
|
lineSummaryVO.setSeries(series);
|
||||||
|
return lineSummaryVO;
|
||||||
|
}
|
||||||
|
|
||||||
private static List<PieSummaryVO> getPieSummaryVOS() {
|
private static List<PieSummaryVO> getPieSummaryVOS() {
|
||||||
List<PieSummaryVO> result = new ArrayList<>();
|
List<PieSummaryVO> result = new ArrayList<>();
|
||||||
PieSummaryVO pieSummaryVO = new PieSummaryVO();
|
PieSummaryVO pieSummaryVO = new PieSummaryVO();
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.isu.gaswellwatch.vo.summary;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class LineDataVO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String type = "line";
|
||||||
|
|
||||||
|
private List<String> data;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.isu.gaswellwatch.vo.summary;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class LineSummaryVO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private List<String> xAxisData;
|
||||||
|
|
||||||
|
private List<String> legendData;
|
||||||
|
|
||||||
|
/** 数据 */
|
||||||
|
private List<LineDataVO> series;
|
||||||
|
|
||||||
|
/** 井号 */
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
}
|
|
@ -108,5 +108,38 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getPressureChartData" resultType="com.isu.gaswellwatch.vo.DeviceHistoryVO">
|
||||||
|
select t.collection_time,t.oil_pressure,t.cas_pressure
|
||||||
|
from ${tableName} t
|
||||||
|
<where>
|
||||||
|
t.device_id = #{deviceId}
|
||||||
|
<if test="startTime!=null">
|
||||||
|
and t.collection_time >= #{startTime}
|
||||||
|
</if>
|
||||||
|
<if test="endTime!=null">
|
||||||
|
and t.collection_time <= #{endTime}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by t.collection_time asc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getSwitchStatusData" resultType="com.isu.gaswellwatch.vo.DeviceHistoryVO">
|
||||||
|
select t.collection_time
|
||||||
|
<if test="deviceProduct!=null and deviceProduct=='knpc'">,t.well_status</if>
|
||||||
|
<if test="deviceProduct!=null and deviceProduct=='etc'">,t.solenoid_valve_status as wellStatus</if>
|
||||||
|
<if test="deviceProduct!=null and deviceProduct=='scss'">,t.first_solenoid_status as wellStatus</if>
|
||||||
|
from ${tableName} t
|
||||||
|
<where>
|
||||||
|
t.device_id = #{deviceId}
|
||||||
|
<if test="startTime!=null">
|
||||||
|
and t.collection_time >= #{startTime}
|
||||||
|
</if>
|
||||||
|
<if test="endTime!=null">
|
||||||
|
and t.collection_time <= #{endTime}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by t.collection_time asc
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,10 @@
|
||||||
<if test="gasWellName!=null and gasWellName!='' ">
|
<if test="gasWellName!=null and gasWellName!='' ">
|
||||||
and g.name LIKE CONCAT('%',#{gasWellName},'%')
|
and g.name LIKE CONCAT('%',#{gasWellName},'%')
|
||||||
</if>
|
</if>
|
||||||
<if test="startTime!=null">
|
<if test="startTime!=null and startTime!=''">
|
||||||
and t.create_time >= #{startTime}
|
and t.create_time >= #{startTime}
|
||||||
</if>
|
</if>
|
||||||
<if test="endTime!=null">
|
<if test="endTime!=null and endTime!=''">
|
||||||
and t.create_time <= #{endTime}
|
and t.create_time <= #{endTime}
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
|
|
Loading…
Reference in New Issue