物联设备设备管理优化

This commit is contained in:
曹磊 2026-03-19 13:34:16 +08:00
parent dc86e89366
commit 0dc7fb92de
9 changed files with 232 additions and 64 deletions

View File

@ -114,5 +114,26 @@ public class IotDeviceInfoController extends JeecgController<IotDeviceInfo, IIot
return service.unbindOrg(iotDeviceInfo);
}
/**
* 设备释放
*
* @param iotDeviceInfo
* @return
*/
@PostMapping(value = "/releaseDevice")
public Result<String> releaseDevice(@RequestBody IotDeviceInfo iotDeviceInfo) {
return service.releaseDevice(iotDeviceInfo);
}
/**
* 设备解绑
*
* @param iotDeviceInfo
* @return
*/
@PostMapping(value = "/unbindDevice")
public Result<String> unbindDevice(@RequestBody IotDeviceInfo iotDeviceInfo) {
return service.unbindDevice(iotDeviceInfo);
}
}

View File

@ -31,4 +31,10 @@ public class IotDeviceLog implements Serializable {
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date updateDate;
//更新人
private String updateBy;
//实际姓名
private String realName;
}

View File

@ -25,5 +25,5 @@ public interface IotDeviceInfoMapper extends BaseMapper<IotDeviceInfo> {
void releaseElectricity(IotDeviceInfo iotDeviceInfo);
void releaseWater(IotDeviceInfo iotDeviceInfo);
void releaseHumid(IotDeviceInfo iotDeviceInfo);
String getDeviceTypeName(IotDeviceInfo iotDeviceInfo);
}

View File

@ -91,6 +91,7 @@
nu_id,
replace(mac,'-','') as sn,
device_type,
'tplink' as deviceCategory,
( case device_status when '0' then '离线' when '1' then '在线' end ) as device_status,
( case iz_allocate
when 'N' then '未分配'
@ -106,6 +107,7 @@
nu_id,
sn,
'db' as device_type,
'electricity' as deviceCategory,
( case when timestampdiff(minute, str_to_date(read_time, '%y-%m-%d %h:%i:%s'), now()) > 120 then '离线' else '在线' end ) as device_status,
( case iz_allocate
when 'N' then '未分配'
@ -121,6 +123,7 @@
a.nu_id,
a.cid as sn,
'sb' as device_type,
'water' as deviceCategory,
( case aa.online when 'true' then '在线' else '离线' end ) as device_status,
( case a.iz_allocate
when 'N' then '未分配'
@ -137,6 +140,7 @@
nu_id,
sn,
'wsdj' as device_type,
'humid' as deviceCategory,
( case status when '0' then '在线' else '离线' end ) as device_status,
( case iz_allocate
when 'N' then '未分配'
@ -283,11 +287,10 @@
a.org_code,
b.nu_id as nuId,
replace(b.mac,'-','') as sn,
d.item_text as deviceType,
b.device_type as deviceType,
'tplink' as deviceCategory
from sys_depart a
inner join nu_iot_tplink_camera b on a.id = b.depart_id
inner join (select sdi.item_value, sdi.item_text from sys_dict sd inner join sys_dict_item sdi on sd.id = sdi.dict_id where sd.dict_code = 'tplink_device_type') d on b.device_type = d.item_value
where a.org_code = #{orgCode}
<if test="nuId != null and nuId != ''">
AND b.nu_id = #{nuId}
@ -298,7 +301,7 @@
a.org_code,
b.nu_id as nuId,
b.sn,
'智能电表' as deviceType,
'db' as deviceType,
'electricity' as deviceCategory
from sys_depart a
inner join nu_iot_ds_electricity_meter b on a.id = b.depart_id
@ -312,7 +315,7 @@
a.org_code,
b.nu_id as nuId,
b.cid as sn,
'智能水表' as deviceType,
'sb' as deviceType,
'water' as deviceCategory
from sys_depart a
inner join nu_iot_tq_water_meter b on a.id = b.depart_id
@ -327,7 +330,7 @@
a.org_code,
b.nu_id as nuId,
b.sn,
'温湿度计' as deviceType,
'wsdj' as deviceType,
'humid' as deviceCategory
from sys_depart a
inner join nu_iot_yiweilian_humid_device b on a.id = b.depart_id
@ -461,4 +464,12 @@
where sn = #{sn}
</update>
<select id="getDeviceTypeName" parameterType="com.nu.modules.manager.entity.IotDeviceInfo" resultType="String">
select sdi.item_text as deviceType
from sys_dict sd
inner join sys_dict_item sdi on sd.id = sdi.dict_id
where sd.dict_code = 'tplink_device_type'
and sdi.item_value = #{deviceType}
</select>
</mapper>

View File

@ -4,31 +4,32 @@
<select id="findPage" parameterType="com.nu.modules.manager.entity.IotDeviceLog" resultType="com.nu.modules.manager.entity.IotDeviceLog">
select
id,
opt_type,
device_id,
device_name,
device_type,
nu_id,
org_code,
remark,
update_date
from nu_iot_device_log
a.id,
a.opt_type,
a.device_id,
a.device_name,
a.device_type,
a.nu_id,
a.org_code,
a.remark,
a.update_date,
a.update_by
from nu_iot_device_log a
<where>
<if test="params.orgCode != null and params.orgCode != ''">
AND org_code = #{params.orgCode}
AND a.org_code = #{params.orgCode}
</if>
<if test="params.nuId != null and params.nuId != ''">
AND nu_id = #{params.nuId}
AND a.nu_id = #{params.nuId}
</if>
<if test="params.deviceType != null and params.deviceType != ''">
AND device_type = #{params.deviceType}
AND a.device_type = #{params.deviceType}
</if>
<if test="params.deviceId != null and params.deviceId != ''">
AND device_id = #{params.deviceId}
AND a.device_id = #{params.deviceId}
</if>
</where>
order by update_date desc
order by a.update_date desc
</select>
<insert id="addLog">
@ -40,7 +41,8 @@
nu_id,
org_code,
remark,
update_date
update_date,
update_by
)
values (
#{optType},
@ -50,7 +52,8 @@
#{nuId},
#{orgCode},
#{remark},
#{updateDate}
#{updateDate},
#{updateBy}
)
</insert>

View File

@ -20,4 +20,6 @@ public interface IIotDeviceInfoService extends IService<IotDeviceInfo> {
Result<String> addOrgBatch(IotDeviceInfo iotDeviceInfo);
Result<String> unbindOrg(IotDeviceInfo iotDeviceInfo);
Result<String> releaseNu(IotDeviceInfo iotDeviceInfo);
Result<String> releaseDevice(IotDeviceInfo iotDeviceInfo);
Result<String> unbindDevice(IotDeviceInfo iotDeviceInfo);
}

View File

@ -10,7 +10,9 @@ import com.nu.modules.manager.service.IIotDeviceInfoService;
import com.nu.modules.manager.service.IIotDeviceLogService;
import com.nu.modules.syncbiz.service.ISyncBizService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -77,14 +79,24 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
if(category.equals("humid")){
baseMapper.bindHumid(idi);
}
String deviceType = baseMapper.getDeviceTypeName(idi);
String remark = "机构["+orgCode+"]";
if(idi.getNuId()!=null){
remark += "区域["+idi.getNuId()+"]";
}
remark += deviceType + "["+idi.getSn()+"]已绑定,绑定备注:"+remarks;
IotDeviceLog log = new IotDeviceLog();
log.setOptType("绑定");
log.setDeviceId(idi.getSn());
log.setDeviceType(idi.getDeviceType());
log.setDeviceType(deviceType);
log.setNuId(nuId);
log.setOrgCode(orgCode);
log.setRemark(remarks);
log.setRemark(remark);
log.setUpdateDate(new Date());
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
if(sysUser!=null){
log.setUpdateBy(sysUser.getUsername());
}
logService.addLog(log);
}
syncBizService.syncIot(nuId);//mq同步设备
@ -117,13 +129,23 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
if(category.equals("humid")){
baseMapper.bindHumid(idi);
}
String deviceType = baseMapper.getDeviceTypeName(idi);
String remark = "机构["+orgCode+"]";
if(idi.getNuId()!=null){
remark += "区域["+idi.getNuId()+"]";
}
remark += deviceType + "["+idi.getSn()+"]已绑定,绑定备注:"+remarks;
IotDeviceLog log = new IotDeviceLog();
log.setOptType("绑定");
log.setDeviceId(idi.getSn());
log.setDeviceType(idi.getDeviceType());
log.setDeviceType(deviceType);
log.setOrgCode(orgCode);
log.setRemark(remarks);
log.setRemark(remark);
log.setUpdateDate(new Date());
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
if(sysUser!=null){
log.setUpdateBy(sysUser.getUsername());
}
logService.addLog(log);
}
syncBizService.syncOrgIot(departId);//mq同步设备
@ -149,14 +171,24 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
if(idi.getDeviceCategory().equals("humid")){
baseMapper.unbindHumid(idi);
}
String deviceType = baseMapper.getDeviceTypeName(idi);
String remark = "机构["+idi.getOrgCode()+"]";
if(idi.getNuId()!=null){
remark += "区域["+idi.getNuId()+"]";
}
remark += deviceType + "["+idi.getSn()+"]已解绑";
IotDeviceLog log = new IotDeviceLog();
log.setOptType("解绑");
log.setDeviceId(idi.getSn());
log.setDeviceType(idi.getDeviceType());
log.setDeviceType(deviceType);
log.setNuId(idi.getNuId());
log.setOrgCode(idi.getOrgCode());
log.setRemark("机构解绑");
log.setRemark(remark);
log.setUpdateDate(new Date());
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
if(sysUser!=null){
log.setUpdateBy(sysUser.getUsername());
}
logService.addLog(log);
}
return Result.OK("解绑设备成功");
@ -181,16 +213,102 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
if(idi.getDeviceCategory().equals("humid")){
baseMapper.releaseHumid(idi);
}
String deviceType = baseMapper.getDeviceTypeName(idi);
String remark = "机构["+idi.getOrgCode()+"]";
if(idi.getNuId()!=null){
remark += "区域["+idi.getNuId()+"]";
}
remark += deviceType + "["+idi.getSn()+"]已释放";
IotDeviceLog log = new IotDeviceLog();
log.setOptType("释放");
log.setDeviceId(idi.getSn());
log.setDeviceType(idi.getDeviceType());
log.setDeviceType(deviceType);
log.setNuId(idi.getNuId());
log.setOrgCode(idi.getOrgCode());
log.setRemark(idi.getNuId()+"区域释放");
log.setRemark(remark);
log.setUpdateDate(new Date());
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
if(sysUser!=null){
log.setUpdateBy(sysUser.getUsername());
}
logService.addLog(log);
}
return Result.OK("释放设备成功");
}
@Override
@Transactional
public Result<String> releaseDevice(IotDeviceInfo iotDeviceInfo){
if(iotDeviceInfo.getDeviceCategory().equals("tplink")){
baseMapper.releaseTplink(iotDeviceInfo);
}
if(iotDeviceInfo.getDeviceCategory().equals("electricity")){
baseMapper.releaseElectricity(iotDeviceInfo);
}
if(iotDeviceInfo.getDeviceCategory().equals("water")){
baseMapper.releaseWater(iotDeviceInfo);
}
if(iotDeviceInfo.getDeviceCategory().equals("humid")){
baseMapper.releaseHumid(iotDeviceInfo);
}
String deviceType = baseMapper.getDeviceTypeName(iotDeviceInfo);
String remark = "机构["+iotDeviceInfo.getOrgCode()+"]";
if(iotDeviceInfo.getNuId()!=null){
remark += "区域["+iotDeviceInfo.getNuId()+"]";
}
remark += deviceType + "["+iotDeviceInfo.getSn()+"]已释放";
IotDeviceLog log = new IotDeviceLog();
log.setOptType("释放");
log.setDeviceId(iotDeviceInfo.getSn());
log.setDeviceType(deviceType);
log.setNuId(iotDeviceInfo.getNuId());
log.setOrgCode(iotDeviceInfo.getOrgCode());
log.setRemark(remark);
log.setUpdateDate(new Date());
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
if(sysUser!=null){
log.setUpdateBy(sysUser.getUsername());
}
logService.addLog(log);
return Result.OK("释放设备成功");
}
@Override
@Transactional
public Result<String> unbindDevice(IotDeviceInfo iotDeviceInfo){
if(iotDeviceInfo.getDeviceCategory().equals("tplink")){
baseMapper.unbindTplink(iotDeviceInfo);
}
if(iotDeviceInfo.getDeviceCategory().equals("electricity")){
baseMapper.unbindElectricity(iotDeviceInfo);
}
if(iotDeviceInfo.getDeviceCategory().equals("water")){
baseMapper.unbindWater(iotDeviceInfo);
}
if(iotDeviceInfo.getDeviceCategory().equals("humid")){
baseMapper.unbindHumid(iotDeviceInfo);
}
String deviceType = baseMapper.getDeviceTypeName(iotDeviceInfo);
String remark = "机构["+iotDeviceInfo.getOrgCode()+"]";
if(iotDeviceInfo.getNuId()!=null){
remark += "区域["+iotDeviceInfo.getNuId()+"]";
}
remark += deviceType + "["+iotDeviceInfo.getSn()+"]已解绑";
IotDeviceLog log = new IotDeviceLog();
log.setOptType("解绑");
log.setDeviceId(iotDeviceInfo.getSn());
log.setDeviceType(deviceType);
log.setNuId(iotDeviceInfo.getNuId());
log.setOrgCode(iotDeviceInfo.getOrgCode());
log.setRemark(remark);
log.setUpdateDate(new Date());
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
if(sysUser!=null){
log.setUpdateBy(sysUser.getUsername());
}
logService.addLog(log);
return Result.OK("解绑设备成功");
}
}

View File

@ -22,6 +22,7 @@ public class DeviceMaintain implements Serializable {
private String areaFlag;//区域属性
private String deviceName;//设备标识
private String deviceId;//设备编码
@Dict(dicCode = "tplink_device_type")
private String deviceType;//设备类型
private String deviceStatus;//在线状态
private String izAllocate;//分配状态
@ -29,6 +30,7 @@ public class DeviceMaintain implements Serializable {
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private String updateDate;//时间戳
private String updateBy;//操作人
private String optType;//操作类型
private String remark;//备注
}

View File

@ -12,20 +12,15 @@
d.area_flag,
replace(a.mac,'-','') as deviceName,
a.device_index as deviceId,
( case a.device_type
when 'SURVEILLANCECAMERA' then '摄像头'
when 'NETWORKVIDEORECORDER' then '录像机'
when 'SWITCH' then '交换机'
when 'ROUTER' then '路由器'
when 'AP' then '无线AP'
end ) as deviceType,
a.device_type deviceType,
( case a.device_status when '0' then '离线' when '1' then '在线' end ) as deviceStatus,
( case a.iz_allocate
when 'N' then '未分配'
else (case when a.nu_id is not null then '已分配' else (case a.dimension when '机构维度' then '已分配' else '释放' end) end)
else (case when dimension is null then '释放' else '已分配' end)
end ) as izAllocate,
a.maintain_status as maintainStatus,
b.update_date as updateDate
b.update_date as updateDate,
b.update_by
from nu_iot_tplink_camera a
left join nu_iot_device_log b on replace(a.mac,'-','') = b.device_id and b.id = (
select id from nu_iot_device_log c where replace(a.mac,'-','') = c.device_id order by c.update_date desc limit 1
@ -40,19 +35,16 @@
AND a.nu_id = #{params.nuId}
</if>
<if test="params.deviceType != null and params.deviceType != ''">
AND ( case a.device_type
when 'SURVEILLANCECAMERA' then '摄像头'
when 'NETWORKVIDEORECORDER' then '录像机'
when 'SWITCH' then '交换机'
when 'ROUTER' then '路由器'
when 'AP' then '无线AP'
end ) = #{params.deviceType}
AND a.device_type = #{params.deviceType}
</if>
<if test="params.deviceStatus != null and params.deviceStatus != ''">
AND ( case a.device_status when '0' then '离线' when '1' then '在线' end ) = #{params.deviceStatus}
</if>
<if test="params.izAllocate != null and params.izAllocate != ''">
AND ( case a.iz_allocate when 'Y' then '已分配' else '未分配' end ) = #{params.izAllocate}
AND ( case a.iz_allocate
when 'N' then '未分配'
else (case when dimension is null then '释放' else '已分配' end)
end ) = #{params.izAllocate}
</if>
<if test="params.maintainStatus != null and params.maintainStatus != ''">
AND a.maintain_status = #{params.maintainStatus}
@ -68,14 +60,15 @@
d.area_flag,
a.sn as deviceName,
a.sn as deviceId,
'智能电表' as deviceType,
'db' as deviceType,
( case when timestampdiff(minute, str_to_date(a.read_time, '%y-%m-%d %h:%i:%s'), now()) > 120 then '离线' else '在线' end ) as deviceStatus,
( case a.iz_allocate
when 'N' then '未分配'
else (case when a.nu_id is not null then '已分配' else (case a.dimension when '机构维度' then '已分配' else '释放' end) end)
else (case when dimension is null then '释放' else '已分配' end)
end ) as izAllocate,
a.maintain_status as maintainStatus,
b.update_date as updateDate
b.update_date as updateDate,
b.update_by
from nu_iot_ds_electricity_meter a
left join nu_iot_device_log b on a.sn = b.device_id and b.id = (
select id from nu_iot_device_log c where a.sn = c.device_id order by c.update_date desc limit 1
@ -90,13 +83,16 @@
AND a.nu_id = #{params.nuId}
</if>
<if test="params.deviceType != null and params.deviceType != ''">
AND '智能电表' = #{params.deviceType}
AND 'db' = #{params.deviceType}
</if>
<if test="params.deviceStatus != null and params.deviceStatus != ''">
AND ( case when timestampdiff(minute, str_to_date(a.read_time, '%y-%m-%d %h:%i:%s'), now()) > 120 then '离线' else '在线' end ) = #{params.deviceStatus}
</if>
<if test="params.izAllocate != null and params.izAllocate != ''">
AND ( case a.iz_allocate when 'Y' then '已分配' else '未分配' end ) = #{params.izAllocate}
AND ( case a.iz_allocate
when 'N' then '未分配'
else (case when dimension is null then '释放' else '已分配' end)
end ) = #{params.izAllocate}
</if>
<if test="params.maintainStatus != null and params.maintainStatus != ''">
AND a.maintain_status = #{params.maintainStatus}
@ -112,14 +108,15 @@
d.area_flag,
a.cid as deviceName,
a.cid as deviceId,
'智能水表' as deviceType,
'sb' as deviceType,
( case aa.online when 'true' then '在线' else '离线' end ) as deviceStatus,
( case a.iz_allocate
when 'N' then '未分配'
else (case when a.nu_id is not null then '已分配' else (case a.dimension when '机构维度' then '已分配' else '释放' end) end)
else (case when dimension is null then '释放' else '已分配' end)
end ) as izAllocate,
a.maintain_status as maintainStatus,
b.update_date as updateDate
b.update_date as updateDate,
b.update_by
from nu_iot_tq_water_meter a
inner join nu_iot_tq_collector aa on aa.cid = a.cid
left join nu_iot_device_log b on a.cid = b.device_id and b.id = (
@ -135,13 +132,16 @@
AND a.nu_id = #{params.nuId}
</if>
<if test="params.deviceType != null and params.deviceType != ''">
AND '智能水表' = #{params.deviceType}
AND 'sb' = #{params.deviceType}
</if>
<if test="params.deviceStatus != null and params.deviceStatus != ''">
AND ( case aa.online when 'true' then '在线' else '离线' end ) = #{params.deviceStatus}
</if>
<if test="params.izAllocate != null and params.izAllocate != ''">
AND ( case a.iz_allocate when 'Y' then '已分配' else '未分配' end ) = #{params.izAllocate}
AND ( case a.iz_allocate
when 'N' then '未分配'
else (case when dimension is null then '释放' else '已分配' end)
end ) = #{params.izAllocate}
</if>
<if test="params.maintainStatus != null and params.maintainStatus != ''">
AND a.maintain_status = #{params.maintainStatus}
@ -157,14 +157,15 @@
d.area_flag,
a.sn as deviceName,
a.sn as deviceId,
'温湿度计' as deviceType,
'wsdj' as deviceType,
( case a.status when '0' then '在线' else '离线' end ) as deviceStatus,
( case a.iz_allocate
when 'N' then '未分配'
else (case when a.nu_id is not null then '已分配' else (case a.dimension when '机构维度' then '已分配' else '释放' end) end)
else (case when dimension is null then '释放' else '已分配' end)
end ) as izAllocate,
a.maintain_status as maintainStatus,
b.update_date as updateDate
b.update_date as updateDate,
b.update_by
from nu_iot_yiweilian_humid_device a
left join nu_iot_device_log b on a.sn = b.device_id and b.id = (
select id from nu_iot_device_log c where a.sn = c.device_id order by c.update_date desc limit 1
@ -179,13 +180,16 @@
AND a.nu_id = #{params.nuId}
</if>
<if test="params.deviceType != null and params.deviceType != ''">
AND '温湿度计' = #{params.deviceType}
AND 'wsdj' = #{params.deviceType}
</if>
<if test="params.deviceStatus != null and params.deviceStatus != ''">
AND ( case a.status when '0' then '在线' else '离线' end ) = #{params.deviceStatus}
</if>
<if test="params.izAllocate != null and params.izAllocate != ''">
AND ( case a.iz_allocate when 'Y' then '已分配' else '未分配' end ) = #{params.izAllocate}
AND ( case a.iz_allocate
when 'N' then '未分配'
else (case when dimension is null then '释放' else '已分配' end)
end ) = #{params.izAllocate}
</if>
<if test="params.maintainStatus != null and params.maintainStatus != ''">
AND a.maintain_status = #{params.maintainStatus}
@ -224,7 +228,8 @@
nu_id,
org_code,
remark,
update_date
update_date,
update_by
from nu_iot_device_log
<where>
<if test="params.deviceName != null and params.deviceName != ''">