优化代码

This commit is contained in:
weitang 2025-04-27 18:15:00 +08:00
parent 2d4a76f9ce
commit a81c158a64
12 changed files with 161 additions and 66 deletions

View File

@ -77,8 +77,7 @@ public class IEC61850Service {
//sendCommand("", "a397bf1d4042ae948d248b1f1856937e", "yk", "true");
//sendCommand("", "a397bf1d4042ae948d248b1f1856937e", "yt", "25.6");
} catch (ServiceError | IOException e) {
log.info("未能关联或检索设备的模型 %s: %s", gatewayDevice.getDeviceCode(),
e.getMessage());
log.info("未能关联或检索设备的模型 {}: {}", gatewayDevice.getDeviceCode(), e.getMessage());
}
return true;
}

View File

@ -72,6 +72,18 @@ public class DeviceSignalController {
return ResponseResult.successData(list);
}
/**********************************
* 用途说明: 查询信号信息
* 参数说明
* areaid 区域ID
* 返回值说明: 变电站辅控设备信号集合
***********************************/
@GetMapping("/querySignalDataById")
@ApiOperation("查询信号信息")
public ResponseResult querySignalDataById(String signalId) {
Map<String, Object> map = deviceSignalService.querySignalDataById(signalId);
return ResponseResult.successData(map);
}
/***********************************
* 用途说明新增变电站辅控设备信号
@ -79,7 +91,7 @@ public class DeviceSignalController {
* deviceSignal 变电站辅控设备信号
* 返回值说明: com.yfd.platform.config.ResponseResult 返回新增成功或者失败
***********************************/
@Log(module = "变电站辅控设备信号", value = "新增变电站辅控设备信号!",type = "1")
@Log(module = "变电站辅控设备信号", value = "新增变电站辅控设备信号!", type = "1")
@PostMapping("/addDeviceSignal")
@ApiOperation("新增变电站辅控设备信号")
@ResponseBody

View File

@ -1,11 +1,18 @@
package com.yfd.platform.modules.auxcontrol.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.modules.auxcontrol.domain.DeviceAlarmRecord;
import com.yfd.platform.modules.auxcontrol.domain.DeviceWorkData;
import com.yfd.platform.modules.auxcontrol.service.IDeviceWorkDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* <p>
* 变电站-设备-运行数据 前端控制器
@ -19,4 +26,14 @@ import org.springframework.web.bind.annotation.RestController;
@Api(value = "DeviceWorkDataController", tags = "变电站设备运行数据")
public class DeviceWorkDataController {
@Resource
private IDeviceWorkDataService deviceWorkDataService;
@GetMapping("/page")
@ApiOperation("分页查询变电站辅控设备告警记录")
public ResponseResult getDeviceWorkDataPage(Page<DeviceWorkData> page, String startDate, String endDate) {
Page<DeviceWorkData> deviceWorkDataPage = deviceWorkDataService.getDeviceWorkDataPage(page, startDate, endDate);
return ResponseResult.successData(deviceWorkDataPage);
}
}

View File

@ -26,4 +26,7 @@ public interface DeviceSignalMapper extends BaseMapper<DeviceSignal> {
boolean updateDeviceSignalValue_yc(String node_addr,String value,String datetime);
@Update("UPDATE fk_device_signal SET yx_value = #{value}, lastmodifydate = #{datetime} WHERE yx_addr = #{node_addr}")
boolean updateDeviceSignalValue_yx(String node_addr,String value,String datetime);
Map<String, Object> querySignalDataById(String signalId);
}

View File

@ -1,5 +1,6 @@
package com.yfd.platform.modules.auxcontrol.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.modules.auxcontrol.domain.DeviceWorkData;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -13,4 +14,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface DeviceWorkDataMapper extends BaseMapper<DeviceWorkData> {
Page<DeviceWorkData> getDeviceWorkDataPage(Page<DeviceWorkData> page, String startDate, String endDate);
}

View File

@ -54,4 +54,7 @@ public interface IDeviceSignalService extends IService<DeviceSignal> {
Page<DeviceSignal> getDeviceSignalPage(String deviceId, String signalName, Page<DeviceSignal> page);
List<Map<String, Object>> getDeviceSignalMaps(String mainDeviceId, String signalName);
Map<String, Object> querySignalDataById(String signalId);
}

View File

@ -1,5 +1,6 @@
package com.yfd.platform.modules.auxcontrol.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.modules.auxcontrol.domain.DeviceWorkData;
import com.baomidou.mybatisplus.extension.service.IService;
@ -24,4 +25,7 @@ public interface IDeviceWorkDataService extends IService<DeviceWorkData> {
* 返回值说明:
***********************************/
void insertData(String from, String slave_ip, String address, String value, String dateTimeString);
Page<DeviceWorkData> getDeviceWorkDataPage(Page<DeviceWorkData> page, String startDate, String endDate);
}

View File

@ -132,4 +132,9 @@ public class DeviceSignalServiceImpl extends ServiceImpl<DeviceSignalMapper, Dev
public List<Map<String, Object>> getDeviceSignalMaps(String mainDeviceId, String signalName) {
return deviceSignalMapper.getDeviceSignalMaps(mainDeviceId, signalName);
}
@Override
public Map<String, Object> querySignalDataById(String signalId) {
return deviceSignalMapper.querySignalDataById(signalId);
}
}

View File

@ -3,6 +3,7 @@ package com.yfd.platform.modules.auxcontrol.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.modules.auxcontrol.domain.DeviceWorkData;
import com.yfd.platform.modules.auxcontrol.mapper.DeviceSignalMapper;
import com.yfd.platform.modules.auxcontrol.mapper.DeviceWorkDataMapper;
@ -28,8 +29,11 @@ import java.util.Map;
*/
@Service
public class DeviceWorkDataServiceImpl extends ServiceImpl<DeviceWorkDataMapper, DeviceWorkData> implements IDeviceWorkDataService {
@Resource
private DeviceSignalMapper deviceSignalMapper;
@Resource
private DeviceWorkDataMapper deviceWorkDataMapper;
/**********************************
* 用途说明: 导出变电站设备运行数据
@ -67,4 +71,9 @@ public class DeviceWorkDataServiceImpl extends ServiceImpl<DeviceWorkDataMapper,
}
@Override
public Page<DeviceWorkData> getDeviceWorkDataPage(Page<DeviceWorkData> page, String startDate, String endDate) {
return deviceWorkDataMapper.getDeviceWorkDataPage(page,startDate,endDate);
}
}

View File

@ -7,9 +7,12 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.yfd.platform.annotation.Log;
import com.yfd.platform.config.HttpServerConfig;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.modules.auxcontrol.domain.GatewayDevice;
import com.yfd.platform.modules.auxcontrol.service.IGatewayDeviceService;
import com.yfd.platform.modules.basedata.domain.DeviceChannel;
import com.yfd.platform.modules.basedata.domain.PatroldeviceResume;
import com.yfd.platform.modules.basedata.domain.SubstationPatroldevice;
@ -84,6 +87,8 @@ public class SubstationPatroldeviceController {
private HttpRESTfulUtils httpUtil;
@Resource
private IRobotOfflineLogService robotOfflineLogService;
@Resource
private IGatewayDeviceService gatewayDeviceService;
@Value("${file-space.system}")
private String systempath;
@ -838,78 +843,71 @@ public class SubstationPatroldeviceController {
return ResponseResult.error("未传变电站信息");
}
LambdaQueryWrapper<SubstationPatroldevice> queryWrapper = new LambdaQueryWrapper<>();
SysUser userInfo = userService.getUserInfo();
Integer usertype = userInfo.getUsertype();
if (usertype != 0) {
// 非管理员只可以查看指定摄像头
List<String> ids = substationPatroldeviceService.getCameraIds(userInfo.getId());
// 获取用户所有的摄像头
if (ids.size() > 0) {
queryWrapper.in(SubstationPatroldevice::getPatroldeviceId, ids);
} else {
return ResponseResult.successData(null);
}
}
queryWrapper.eq(SubstationPatroldevice::getStationId, stationId).eq(SubstationPatroldevice::getDatastatus, "1");
// SysUser userInfo = userService.getUserInfo();
// Integer usertype = userInfo.getUsertype();
// if (usertype != 0) {
// // 非管理员只可以查看指定摄像头
// List<String> ids = substationPatroldeviceService.getCameraIds(userInfo.getId());
// // 获取用户所有的摄像头
// if (ids.size() > 0) {
// queryWrapper.in(SubstationPatroldevice::getPatroldeviceId, ids);
// } else {
// return ResponseResult.successData(null);
// }
// }
List<String> typeList = Lists.newArrayList("10", "14");
queryWrapper.eq(SubstationPatroldevice::getStationId, stationId).in(SubstationPatroldevice::getType,
typeList).eq(SubstationPatroldevice::getDatastatus, "1");
List<SubstationPatroldevice> list = substationPatroldeviceService.list(queryWrapper);
String[] codeArray = {"1", "2", "3", "4", "10", "13"};
List<String> codeList = Arrays.asList(codeArray);
Map<String, List<SubstationPatroldevice>> collect =
list.stream().filter(l -> (StrUtil.isNotBlank(l.getType()) && codeList.contains(l.getType()))).collect(Collectors.groupingBy(SubstationPatroldevice::getType));
Map<String, List<SubstationPatroldevice>> listMap =
list.stream().filter(l -> (StrUtil.isNotBlank(l.getType()))).collect(Collectors.groupingBy(SubstationPatroldevice::getType));
Map<String, Object> map = new HashMap<>();
for (String code : codeList) {
List<SubstationPatroldevice> substationPatroldevices = collect.get(code);
for (String type : typeList) {
List<SubstationPatroldevice> substationPatroldevices = listMap.get(type);
Map<String, Object> map1 = new HashMap<>();
if (substationPatroldevices == null) {
map1.put("allCount", 0);
map1.put("online", 0);
map1.put("onLineRate", 0);
map.put(code, map1);
map.put(type, map1);
continue;
}
List<SubstationPatroldevice> collect1 =
substationPatroldevices.stream().filter(s -> "1".equals(s.getOnline())).collect(Collectors.toList
());
int allCount1 = substationPatroldevices.size();
int online1 = collect1.size();
List<SubstationPatroldevice> patroldevices =
substationPatroldevices.stream().filter(s -> "1".equals(s.getOnline())).collect(Collectors.toList());
int allCount = substationPatroldevices.size();
int online = patroldevices.size();
map1.put("allCount", allCount1);
map1.put("online", online1);
map1.put("onLineRate", (int) (((float) online1 / allCount1) * 100 + 0.5));
map.put(code, map1);
map1.put("allCount", allCount);
map1.put("online", online);
map1.put("onLineRate", (int) (((float) online / allCount) * 100 + 0.5));
map.put(type, map1);
}
// 机器人
Map<String, Object> map1 = BeanUtil.beanToMap(map.get("1"));
map.remove("1");
int allCount1 = (Integer) map1.get("allCount");
int online1 = (Integer) map1.get("online");
Map<String, Object> map2 = BeanUtil.beanToMap(map.get("2"));
map.remove("2");
int allCount2 = (Integer) map2.get("allCount");
int online2 = (Integer) map2.get("online");
Map<String, Object> map3 = BeanUtil.beanToMap(map.get("3"));
map.remove("3");
int allCount3 = (Integer) map3.get("allCount");
int online3 = (Integer) map3.get("online");
Map<String, Object> map4 = BeanUtil.beanToMap(map.get("4"));
map.remove("4");
int allCount4 = (Integer) map4.get("allCount");
int online4 = (Integer) map4.get("online");
int count = allCount1 + allCount2 + allCount3 + allCount4;
int online = online1 + online2 + online3 + online4;
Map<String, Object> mapAll = new HashMap<>();
mapAll.put("allCount", count);
mapAll.put("online", online);
mapAll.put("onLineRate", (int) (((float) online / count) * 100 + 0.5));
map.put("robot", mapAll);
// 无人机
Map<String, Object> uav = BeanUtil.beanToMap(map.get("13"));
map.remove("13");
map.put("uav", uav);
// 摄像头
Map<String, Object> camera = BeanUtil.beanToMap(map.get("10"));
Map<String, Object> cameraMap = BeanUtil.beanToMap(map.get("10"));
Map<String, Object> voiceMap = BeanUtil.beanToMap(map.get("14"));
map.put("camera", cameraMap);
map.remove("10");
map.put("camera", camera);
map.put("voice", voiceMap);
map.remove("14");
List<GatewayDevice> gatewayDevices =
gatewayDeviceService.list(new LambdaQueryWrapper<GatewayDevice>().ne(GatewayDevice::getStatus, "00"));
if (gatewayDevices.size() <= 0) {
Map<String, Object> map1 = new HashMap<>();
map1.put("allCount", 0);
map1.put("online", 0);
map1.put("onLineRate", 0);
map.put("gateway", map1);
} else {
Map<String, Object> map1 = new HashMap<>();
long online = gatewayDevices.stream().filter(g -> "01".equals(g.getStatus())).count();
long allCount = gatewayDevices.size();
map1.put("allCount", allCount);
map1.put("online", online);
map1.put("onLineRate", (int) (((float) online / allCount) * 100 + 0.5));
map.put("gateway", map1);
}
return ResponseResult.successData(map);
}

View File

@ -65,7 +65,7 @@
</if>
<if test="signalName != null and signalName != ''">
fds.signal_name LIKE CONCAT('',#{signalName},'')
AND fds.signal_name LIKE CONCAT('%',#{signalName},'%')
</if>
</select>
<select id="selectDeviceSignalByIp" resultType="com.yfd.platform.modules.auxcontrol.domain.DeviceSignal">
@ -88,5 +88,26 @@
b.device_type = '30'
AND b.ip_addr = #{ip}
</select>
<select id="querySignalDataById" resultType="java.util.Map">
SELECT
fds.signal_id,
fds.signal_code,
fds.signal_type,
fds.signal_name,
fds.signal_unit,
fds.normal_range,
fds.ykyt_type,
fmd.device_model,
fgd.ip_addr,
fgd.Protocol,
fgd.frequency,
fgd.device_type
FROM
fk_device_signal fds
INNER JOIN fk_meter_device fmd ON fds.meter_device_id = fmd.device_id
INNER JOIN fk_gateway_device fgd ON fgd.ip_addr = fmd.netdevice_ip
WHERE signal_id =#{signalId}
LIMIT 1
</select>
</mapper>

View File

@ -2,4 +2,26 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yfd.platform.modules.auxcontrol.mapper.DeviceWorkDataMapper">
<select id="getDeviceWorkDataPage" resultType="com.yfd.platform.modules.auxcontrol.domain.DeviceWorkData">
SELECT
station_id,
device_id,
device_name,
signal_id,
signal_name,
`value`,
unit,
start_time
FROM
fk_device_work_data
WHERE 1=1
<if test="startDate != null and startDate != ''">
AND start_time &gt;= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
AND start_time &lt;= #{endDate}
</if>
ORDER BY start_time DESC
</select>
</mapper>