You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
339 lines
17 KiB
339 lines
17 KiB
package com.mh.user.controller; |
|
|
|
import com.mh.common.http.HttpResult; |
|
import com.mh.user.annotation.BusinessType; |
|
import com.mh.user.annotation.SysLogger; |
|
import com.mh.user.entity.*; |
|
import com.mh.user.model.DeviceModel; |
|
import com.mh.user.model.MultiControlModel; |
|
import com.mh.user.model.PumpModel; |
|
import com.mh.user.model.WaterLevelModel; |
|
import com.mh.user.service.*; |
|
import org.slf4j.Logger; |
|
import org.slf4j.LoggerFactory; |
|
import org.springframework.beans.factory.annotation.Autowired; |
|
import org.springframework.web.bind.annotation.PostMapping; |
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
import org.springframework.web.bind.annotation.RequestParam; |
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
import java.text.SimpleDateFormat; |
|
import java.util.ArrayList; |
|
import java.util.Date; |
|
import java.util.List; |
|
|
|
@RestController |
|
@RequestMapping("monitor") |
|
public class NowDataController { |
|
|
|
private static final Logger log = LoggerFactory.getLogger(NowDataController.class); |
|
@Autowired |
|
NowDataService nowDataService; |
|
|
|
@Autowired |
|
BuildingService buildingService; |
|
|
|
@Autowired |
|
NowPublicDataService nowPublicDataService; |
|
|
|
@Autowired |
|
DeviceInstallService deviceInstallService; |
|
|
|
@Autowired |
|
DeviceFloorService deviceFloorService; |
|
|
|
@SysLogger(title = "实时监控", optDesc = "实时查看每楼栋热水运行情况") |
|
@PostMapping("/queryNow") |
|
public HttpResult queryNowData(@RequestParam(value = "buildingId") String buildingId) { |
|
try { |
|
//把热泵的水温保存到公共信息中中的用水温度和回水温度 |
|
String avgWaterTemp = nowDataService.selectAve(buildingId); |
|
String maxWaterTemp = nowDataService.selectMaxTemp(buildingId); |
|
String buildingName = buildingService.queryBuildingName(buildingId);//获取楼栋名称 |
|
|
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
Date date = new Date(); |
|
String curDate = sdf1.format(date); |
|
curDate = curDate.substring(0, 13) + ":00:00"; |
|
|
|
NowPublicDataEntity nowPublicData = new NowPublicDataEntity(); |
|
nowPublicData.setBuildingId(buildingId); |
|
nowPublicData.setBuildingName(buildingName); |
|
if (avgWaterTemp != null) { |
|
nowPublicData.setBackWaterTemp(avgWaterTemp); |
|
} else { |
|
nowPublicData.setBackWaterTemp("0"); |
|
} |
|
if (maxWaterTemp != null) { |
|
nowPublicData.setUseWaterTemp(maxWaterTemp); |
|
} else { |
|
nowPublicData.setUseWaterTemp("0"); |
|
} |
|
nowPublicDataService.saveNowHistoryPublicData(nowPublicData); |
|
|
|
//监视表生成初始记录 |
|
List<NowDataEntity> list = nowDataService.queryNowData(buildingId); |
|
if (list.size() == 0) {//实时表生成记录 |
|
List<DeviceModel> deviceList = deviceInstallService.selectDevices(buildingId, "热泵"); |
|
if (deviceList.size() > 0) { |
|
for (DeviceModel list2 : deviceList) { |
|
NowDataEntity nowData = new NowDataEntity(); |
|
nowData.setPumpId(list2.getDeviceAddr()); |
|
nowData.setPumpName(list2.getDeviceName()); |
|
nowData.setBuildingId(buildingId); |
|
nowData.setBuildingName(buildingName); |
|
nowData.setCurDate(curDate); |
|
nowDataService.saveNowData(nowData); //当前状态表 |
|
nowDataService.saveHistoryData(nowData); //历史状态表 |
|
} |
|
} else { |
|
NowDataEntity nowData = new NowDataEntity(); |
|
PumpModel pump = deviceFloorService.selectDeviceId2("热泵", buildingId); |
|
if (pump != null) { |
|
nowData.setPumpId(pump.getPumpId()); |
|
nowData.setPumpName(pump.getPumpName()); |
|
nowData.setBuildingId(buildingId); |
|
nowData.setBuildingName(buildingName); |
|
nowData.setCurDate(curDate); |
|
nowDataService.saveNowData(nowData); |
|
nowDataService.saveHistoryData(nowData); |
|
} |
|
} |
|
} |
|
list = nowDataService.queryNowData(buildingId); |
|
return HttpResult.ok(list); |
|
} catch (Exception e) { |
|
log.error("查询当前监控状态出错!", e); |
|
return HttpResult.error("查询当前监控状态出错!"); |
|
} |
|
} |
|
|
|
@SysLogger(title = "实时监控", optDesc = "实时查看每楼栋多路控制运行情况") |
|
@PostMapping("/queryMultiNow") |
|
public HttpResult queryMultiNowData(@RequestParam(value = "buildingId") String buildingId) { |
|
try { |
|
//把热泵的水温保存到公共信息中中的用水温度和回水温度 |
|
String avgWaterTemp = nowDataService.selectAve(buildingId); |
|
String maxWaterTemp = nowDataService.selectMaxTemp(buildingId); |
|
String buildingName = buildingService.queryBuildingName(buildingId);//获取楼栋名称 |
|
|
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
Date date = new Date(); |
|
String curDate = sdf1.format(date); |
|
curDate = curDate.substring(0, 13) + ":00:00"; |
|
|
|
NowPublicDataEntity nowPublicData = new NowPublicDataEntity(); |
|
nowPublicData.setBuildingId(buildingId); |
|
nowPublicData.setBuildingName(buildingName); |
|
if (avgWaterTemp != null) { |
|
nowPublicData.setBackWaterTemp(avgWaterTemp); |
|
} else { |
|
nowPublicData.setBackWaterTemp("0"); |
|
} |
|
if (maxWaterTemp != null) { |
|
nowPublicData.setUseWaterTemp(maxWaterTemp); |
|
} else { |
|
nowPublicData.setUseWaterTemp("0"); |
|
} |
|
nowPublicDataService.saveNowHistoryPublicData(nowPublicData); |
|
|
|
//监视表生成初始记录 |
|
List<NowDataEntity> list = nowDataService.queryNowData(buildingId); |
|
if (list.isEmpty()) {//实时表生成记录 |
|
List<DeviceModel> deviceList = deviceInstallService.selectDevices(buildingId, "多路控制"); |
|
if (!deviceList.isEmpty()) { |
|
for (DeviceModel list2 : deviceList) { |
|
NowDataEntity nowData = new NowDataEntity(); |
|
nowData.setPumpId(list2.getDeviceAddr()); |
|
nowData.setPumpName("1号供水泵"); |
|
nowData.setBuildingId(buildingId); |
|
nowData.setBuildingName(buildingName); |
|
nowData.setRunState("0"); |
|
nowData.setIsFault("0"); |
|
nowData.setCurDate(curDate); |
|
nowDataService.saveNowData(nowData); //当前状态表 |
|
nowDataService.saveHistoryData(nowData); //历史状态表 |
|
|
|
nowData.setPumpId(list2.getDeviceAddr()); |
|
nowData.setPumpName("2号供水泵"); |
|
nowData.setBuildingId(buildingId); |
|
nowData.setBuildingName(buildingName); |
|
nowData.setRunState("0"); |
|
nowData.setIsFault("0"); |
|
nowData.setCurDate(curDate); |
|
nowDataService.saveNowData(nowData); //当前状态表 |
|
nowDataService.saveHistoryData(nowData); //历史状态表 |
|
|
|
nowData.setPumpId(list2.getDeviceAddr()); |
|
nowData.setPumpName("1号抽水泵"); |
|
nowData.setBuildingId(buildingId); |
|
nowData.setBuildingName(buildingName); |
|
nowData.setRunState("0"); |
|
nowData.setIsFault("0"); |
|
nowData.setCurDate(curDate); |
|
nowDataService.saveNowData(nowData); //当前状态表 |
|
nowDataService.saveHistoryData(nowData); //历史状态表 |
|
|
|
nowData.setPumpId(list2.getDeviceAddr()); |
|
nowData.setPumpName("2号抽水泵"); |
|
nowData.setBuildingId(buildingId); |
|
nowData.setBuildingName(buildingName); |
|
nowData.setRunState("0"); |
|
nowData.setIsFault("0"); |
|
nowData.setCurDate(curDate); |
|
nowDataService.saveNowData(nowData); //当前状态表 |
|
nowDataService.saveHistoryData(nowData); //历史状态表 |
|
|
|
nowData.setPumpId(list2.getDeviceAddr()); |
|
nowData.setPumpName("补水电磁阀"); |
|
nowData.setBuildingId(buildingId); |
|
nowData.setBuildingName(buildingName); |
|
nowData.setRunState("0"); |
|
nowData.setIsFault("0"); |
|
nowData.setCurDate(curDate); |
|
nowDataService.saveNowData(nowData); //当前状态表 |
|
nowDataService.saveHistoryData(nowData); //历史状态表 |
|
} |
|
} |
|
} |
|
List<MultiControlModel> resultList = nowDataService.queryMultiControlNowData(buildingId); |
|
return HttpResult.ok(resultList); |
|
} catch (Exception e) { |
|
log.error("查询当前监控状态出错!", e); |
|
return HttpResult.error("查询当前监控状态出错!"); |
|
} |
|
} |
|
|
|
@SysLogger(title = "实时监控", optDesc = "分别查看热泵运行情况") |
|
@PostMapping("/queryNowByPump") |
|
public HttpResult queryNowByPump(@RequestParam(value = "buildingId") String buildingId, @RequestParam(value = "pumpId") String pumpId) { |
|
try { |
|
NowDataEntity nowDataEntity = nowDataService.queryNowDataByPump(buildingId, pumpId); |
|
return HttpResult.ok(nowDataEntity); |
|
} catch (Exception e) { |
|
e.printStackTrace(); |
|
return HttpResult.error("按热泵查询当前监控状态出错!"); |
|
} |
|
|
|
} |
|
|
|
@SysLogger(title = "运行信息", optDesc = "热泵历史状态查询") |
|
@PostMapping("/query") |
|
public HttpResult queryHistoryData(@RequestParam(value = "curDate") String curDate, |
|
@RequestParam(value = "buildingId") String buildingId, |
|
@RequestParam(value = "pumpId", required = false) String pumpId, |
|
@RequestParam(value = "tankId", required = false) String tankId, |
|
@RequestParam(value = "page") int page, |
|
@RequestParam(value = "limit") int limit) { |
|
try { |
|
List<NowDataEntity> list; |
|
list = nowDataService.queryHistoryData(curDate, buildingId, pumpId, tankId, page, limit); |
|
int count = nowDataService.getHistoryDataCount(curDate, buildingId, pumpId, tankId, page, limit); |
|
return HttpResult.ok(count, list); |
|
} catch (Exception e) { |
|
// e.printStackTrace(); |
|
return HttpResult.error("查询出错!"); |
|
} |
|
} |
|
|
|
//查询水位开始 |
|
@SysLogger(title = "水位变化表", optDesc = "水位变化查询") |
|
@PostMapping("/waterLevel") |
|
public HttpResult queryWaterLevel(@RequestParam(value = "curDate") String curDate, |
|
@RequestParam(value = "buildingID") String buildingID, |
|
@RequestParam(value = "level", defaultValue = "0") int level, |
|
@RequestParam(value = "page") int page, |
|
@RequestParam(value = "limit") int limit) { |
|
try { |
|
if (buildingID == null || buildingID.equals("") || buildingID.equals("所有楼栋") || level == 0 || level == 1) { |
|
List<WaterLevelEntity> list = nowDataService.queryBuildWaterLevel(curDate, page, limit, level, buildingID); |
|
// int count = nowDataService.buildWaterLevelCount(curDate); |
|
int count = list.size(); |
|
return HttpResult.ok(count, list); |
|
} else { |
|
List<WaterLevelEntity> list = nowDataService.queryWaterLevel(curDate, buildingID, page, limit); |
|
int count = nowDataService.getWaterLevelCount(curDate, buildingID); |
|
return HttpResult.ok(count, list); |
|
} |
|
} catch (Exception e) { |
|
// e.printStackTrace(); |
|
return HttpResult.error("查询出错!"); |
|
} |
|
} |
|
|
|
@PostMapping("/levelByTime") |
|
public HttpResult queryWaterLevelByTime(@RequestParam(value = "curDate") String curDate, |
|
@RequestParam(value = "page") int page, |
|
@RequestParam(value = "limit") int limit) { |
|
try { |
|
int count = nowDataService.waterLevelByTimeCount(curDate); |
|
List<WaterLevelModel> list = nowDataService.queryWaterLevelByTime(curDate, page, limit); |
|
return HttpResult.ok(count, list); |
|
} catch (Exception e) { |
|
// e.printStackTrace(); |
|
return HttpResult.error("查询出错!"); |
|
} |
|
} |
|
|
|
//查询水位结束 |
|
//查询水温,每天24小时情况 |
|
@SysLogger(title = "温度变化表", optDesc = "温度变化查询") |
|
@PostMapping("/waterTemp") |
|
public HttpResult queryWaterTemp(@RequestParam(value = "buildingID") String buildingID, |
|
@RequestParam(value = "curDate") String curDate, |
|
@RequestParam(value = "level", defaultValue = "0") int level, |
|
@RequestParam(value = "page") int page, |
|
@RequestParam(value = "limit") int limit) { |
|
try { |
|
List<WaterTempEntity> list; |
|
int count; |
|
// 校区或者区域 |
|
if (buildingID == null || buildingID.equals("") || buildingID.equals("所有楼栋") || level == 0 || level == 1) { |
|
list = nowDataService.queryWaterTemp2(curDate, page, limit, level, buildingID); |
|
// count = nowDataService.queryWaterTempCount2(curDate, level, buildingID); |
|
count = list.size(); |
|
} else { |
|
list = nowDataService.queryWaterTemp(buildingID, curDate, page, limit); |
|
count = nowDataService.queryWaterTempCount(buildingID, curDate); |
|
} |
|
return HttpResult.ok(count, list); |
|
} catch (Exception e) { |
|
// e.printStackTrace(); |
|
return HttpResult.error("查询出错!"); |
|
} |
|
} |
|
|
|
//查询运行时长 |
|
@SysLogger(title = "运行时长", optDesc = "热泵运行时长查询") |
|
@PostMapping("/minutes") |
|
public HttpResult pumpMinutes(@RequestParam(value = "startDate") String startDate, |
|
@RequestParam(value = "endDate") String endDate, |
|
@RequestParam(value = "buildingId", required = false) String buildingId, |
|
@RequestParam(value = "pumpId", required = false) String pumpId, |
|
@RequestParam(value = "type") int type, |
|
@RequestParam(value = "page") int page, |
|
@RequestParam(value = "limit") int limit) { |
|
try { |
|
int count = 0; |
|
List<PumpMinutesEntity> list; |
|
if (type == 1) { |
|
list = nowDataService.pumpMinutes(startDate, endDate, buildingId, pumpId, page, limit); |
|
count = nowDataService.pumpMinutesCount(startDate, endDate, buildingId, pumpId); |
|
} else if (type == 2) { |
|
list = nowDataService.pumpWeekMinutes(startDate, endDate, buildingId, pumpId, page, limit); |
|
count = nowDataService.pumpWeekMinutesCount(startDate, endDate, buildingId, pumpId); |
|
} else if (type == 3) { |
|
list = nowDataService.pumpMonthMinutes(startDate, endDate, buildingId, pumpId, page, limit); |
|
count = nowDataService.pumpMonthMinutesCount(startDate, endDate, buildingId, pumpId); |
|
} else { |
|
list = nowDataService.pumpMinutes(startDate, endDate, buildingId, pumpId, page, limit); |
|
count = nowDataService.pumpMinutesCount(startDate, endDate, buildingId, pumpId); |
|
} |
|
|
|
return HttpResult.ok(count, list); |
|
} catch (Exception e) { |
|
// e.printStackTrace(); |
|
return HttpResult.error("查询出错!"); |
|
} |
|
} |
|
}
|
|
|