diff --git a/ruoyi-common/src/main/java/com/zc/common/core/websocket/constant/WebSocketEvent.java b/ruoyi-common/src/main/java/com/zc/common/core/websocket/constant/WebSocketEvent.java index 3b2e1080..aa4cced4 100644 --- a/ruoyi-common/src/main/java/com/zc/common/core/websocket/constant/WebSocketEvent.java +++ b/ruoyi-common/src/main/java/com/zc/common/core/websocket/constant/WebSocketEvent.java @@ -19,4 +19,7 @@ public class WebSocketEvent { //处置记录 public static final String EVENT_PROCESS = "eventProcess"; + //设备离线记录 + public static final String DEVICE_OFFLINE_RECORD = "deviceOfflineRecord"; + } diff --git a/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java b/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java index 5c501d5c..c221f1e4 100644 --- a/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java +++ b/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java @@ -63,4 +63,9 @@ public class RedisKeyConstants * 高速云导入事件列表 */ public static final String SDHS_EVENT_FILE = "sdhsEventFile"; + + /** + * 设备离线记录 + */ + public static final String DC_DEVICE_OFFLINE_RECORD = "dc:deviceOfflineRecord"; } diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOfflineRecordController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOfflineRecordController.java new file mode 100644 index 00000000..53afadcc --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOfflineRecordController.java @@ -0,0 +1,98 @@ +package com.zc.business.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.zc.business.domain.DcDeviceOfflineRecord; +import com.zc.business.service.IDcDeviceOfflineRecordService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 设备离线记录Controller + * + * @author ruoyi + * @date 2024-09-18 + */ +@RestController +@RequestMapping("/deviceOfflineRecord") +public class DcDeviceOfflineRecordController extends BaseController +{ + @Autowired + private IDcDeviceOfflineRecordService dcDeviceOfflineRecordService; + + /** + * 查询设备离线记录列表 + */ + @GetMapping("/list") + public TableDataInfo list(DcDeviceOfflineRecord dcDeviceOfflineRecord) + { + startPage(); + List list = dcDeviceOfflineRecordService.selectDcDeviceOfflineRecordList(dcDeviceOfflineRecord); + return getDataTable(list); + } + + /** + * 导出设备离线记录列表 + */ + @Log(title = "设备离线记录", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, DcDeviceOfflineRecord dcDeviceOfflineRecord) + { + List list = dcDeviceOfflineRecordService.selectDcDeviceOfflineRecordList(dcDeviceOfflineRecord); + ExcelUtil util = new ExcelUtil<>(DcDeviceOfflineRecord.class); + util.exportExcel(response, list, "设备离线记录数据"); + } + + /** + * 获取设备离线记录详细信息 + */ + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return AjaxResult.success(dcDeviceOfflineRecordService.selectDcDeviceOfflineRecordById(id)); + } + + /** + * 新增设备离线记录 + */ + @Log(title = "设备离线记录", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody DcDeviceOfflineRecord dcDeviceOfflineRecord) + { + return toAjax(dcDeviceOfflineRecordService.insertDcDeviceOfflineRecord(dcDeviceOfflineRecord)); + } + + /** + * 修改设备离线记录 + */ + @Log(title = "设备离线记录", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody DcDeviceOfflineRecord dcDeviceOfflineRecord) + { + return toAjax(dcDeviceOfflineRecordService.updateDcDeviceOfflineRecord(dcDeviceOfflineRecord)); + } + + /** + * 删除设备离线记录 + */ + @Log(title = "设备离线记录", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(dcDeviceOfflineRecordService.deleteDcDeviceOfflineRecordByIds(ids)); + } +} diff --git a/zc-business/src/main/java/com/zc/business/controller/VideoController.java b/zc-business/src/main/java/com/zc/business/controller/VideoController.java index e2913ded..c03b6a71 100644 --- a/zc-business/src/main/java/com/zc/business/controller/VideoController.java +++ b/zc-business/src/main/java/com/zc/business/controller/VideoController.java @@ -14,6 +14,7 @@ import com.zc.business.domain.DcDevice; import com.zc.business.enums.CameraDirectionEnum; import com.zc.business.enums.LaneDirectionEnum; import com.zc.business.enums.UniversalEnum; +import com.zc.business.service.IDcDeviceOfflineRecordService; import com.zc.business.service.IDcDeviceService; import com.zc.business.service.IMiddleDatabaseService; import com.zc.common.core.httpclient.OkHttp; @@ -79,6 +80,9 @@ public class VideoController extends BaseController { @Resource private IMiddleDatabaseService middleDatabaseService; + + @Resource + private IDcDeviceOfflineRecordService dcDeviceOfflineRecordService; @Autowired private ISysConfigService configService; @@ -293,6 +297,9 @@ public class VideoController extends BaseController { //更新中间库的设备状态 middleDatabaseService.updateMiddleDatabaseDeviceByList(list); + //设备离线记录 + dcDeviceOfflineRecordService.batchDeviceOfflineRecord(list); + logger.debug("执行:同步数据平台视频设备的设备状态成功!!"); } @@ -313,6 +320,9 @@ public class VideoController extends BaseController { //更新中间库的设备状态 middleDatabaseService.updateMiddleDatabaseDeviceByList(dcDevices); + //设备离线记录 + dcDeviceOfflineRecordService.batchDeviceOfflineRecord(dcDevices); + logger.debug("执行:同步物联平台设备的设备状态成功!!"); } @@ -331,6 +341,13 @@ public class VideoController extends BaseController { //更新中间库的设备状态 middleDatabaseService.updateMiddleDatabaseDevice(dcDevice); + + + + //设备离线记录 + List list = new ArrayList<>(); + list.add(dcDevice); + dcDeviceOfflineRecordService.batchDeviceOfflineRecord(list); } logger.debug("执行:同步广播设备的设备状态成功!!"); diff --git a/zc-business/src/main/java/com/zc/business/domain/DcDeviceOfflineRecord.java b/zc-business/src/main/java/com/zc/business/domain/DcDeviceOfflineRecord.java new file mode 100644 index 00000000..e19b9b22 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/DcDeviceOfflineRecord.java @@ -0,0 +1,255 @@ +package com.zc.business.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 设备离线记录对象 dc_device_offline_record + * + * @author ruoyi + * @date 2024-09-18 + */ +public class DcDeviceOfflineRecord extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Long id; + + /** 设备表id */ + @Excel(name = "设备表id") + private Long deviceId; + + /** 物联id */ + @Excel(name = "物联id") + private String iotDeviceId; + + /** 设备名称 */ + @Excel(name = "设备名称") + private String deviceName; + + /** 设备类型 + 1 摄像机 + 2 可变信息标志 + 3 气象监测器 + 4 出口诱导灯 + 5 路段语音广播 + 6 护栏碰撞 + 7 毫米波雷达 + 8 合流区预警 + 9 智慧锥桶 + 10 激光疲劳唤醒 + 11 一类交通量调查站 + 12 行车诱导 + 13 智能设备箱 + 14 光线在线监测 + 15 太阳能板 + 16 远端机 + */ + @Excel(name = "设备类型") + private String deviceType; + + /** 所在桩号 */ + @Excel(name = "所在桩号") + private String stakeMark; + + /** 方向1-上行,2-中,3-下行 */ + @Excel(name = "方向1-上行,2-中,3-下行") + private String direction; + + /** 安装位置 */ + @Excel(name = "安装位置") + private String installationSite; + + /** 设备ip */ + @Excel(name = "设备ip") + private String deviceIp; + + /** 设施归属类型(0:默认1: 道路沿线2:桥梁3: 隧道4:收费广场5: 收费站6: 服务区等 */ + @Excel(name = "设施归属类型", readConverterExp = "设施归属类型(0:默认1: 道路沿线2:桥梁3: 隧道4:收费广场5: 收费站6: 服务区等") + private String facilitiesType; + + /** 子设备类型 + 1-1 高清网络枪型固定摄像机 + 1-2 高清网络球形摄像机 + 1-3 桥下高清网络球形摄像机 + 1-4 360°全景摄像机 + 1-5 180°全景摄像机 + + + 2-1 门架式可变信息标志 + + 2-2站前可变信息标志 160*80 + + + 2-3 雨棚可变信息标志 + + + 2-4 站前悬臂式可变信息标志192*160 */ + @Excel(name = "子设备类型") + private String childType; + + /** 经度 */ + @Excel(name = "经度") + private String longitude; + + /** 纬度 */ + @Excel(name = "纬度") + private String latitude; + + /** 状态(0未处理 1已处理 2自动处理) */ + @Excel(name = "状态(0未处理 1已处理 2自动处理)") + private String status; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setDeviceId(Long deviceId) + { + this.deviceId = deviceId; + } + + public Long getDeviceId() + { + return deviceId; + } + + public String getIotDeviceId() { + return iotDeviceId; + } + + public void setIotDeviceId(String iotDeviceId) { + this.iotDeviceId = iotDeviceId; + } + + public void setDeviceName(String deviceName) + { + this.deviceName = deviceName; + } + + public String getDeviceName() + { + return deviceName; + } + public void setDeviceType(String deviceType) + { + this.deviceType = deviceType; + } + + public String getDeviceType() + { + return deviceType; + } + public void setStakeMark(String stakeMark) + { + this.stakeMark = stakeMark; + } + + public String getStakeMark() + { + return stakeMark; + } + public void setDirection(String direction) + { + this.direction = direction; + } + + public String getDirection() + { + return direction; + } + public void setInstallationSite(String installationSite) + { + this.installationSite = installationSite; + } + + public String getInstallationSite() + { + return installationSite; + } + public void setDeviceIp(String deviceIp) + { + this.deviceIp = deviceIp; + } + + public String getDeviceIp() + { + return deviceIp; + } + public void setFacilitiesType(String facilitiesType) + { + this.facilitiesType = facilitiesType; + } + + public String getFacilitiesType() + { + return facilitiesType; + } + public void setChildType(String childType) + { + this.childType = childType; + } + + public String getChildType() + { + return childType; + } + public void setLongitude(String longitude) + { + this.longitude = longitude; + } + + public String getLongitude() + { + return longitude; + } + public void setLatitude(String latitude) + { + this.latitude = latitude; + } + + public String getLatitude() + { + return latitude; + } + public void setStatus(String status) + { + this.status = status; + } + + public String getStatus() + { + return status; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("deviceId", getDeviceId()) + .append("iotDeviceId", getIotDeviceId()) + .append("deviceName", getDeviceName()) + .append("deviceType", getDeviceType()) + .append("stakeMark", getStakeMark()) + .append("direction", getDirection()) + .append("installationSite", getInstallationSite()) + .append("deviceIp", getDeviceIp()) + .append("facilitiesType", getFacilitiesType()) + .append("childType", getChildType()) + .append("longitude", getLongitude()) + .append("latitude", getLatitude()) + .append("status", getStatus()) + .append("createTime", getCreateTime()) + .append("updateTime", getUpdateTime()) + .append("updateBy", getUpdateBy()) + .toString(); + } +} diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcDeviceOfflineRecordMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceOfflineRecordMapper.java new file mode 100644 index 00000000..986ad8d6 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceOfflineRecordMapper.java @@ -0,0 +1,63 @@ +package com.zc.business.mapper; + +import java.util.List; +import com.zc.business.domain.DcDeviceOfflineRecord; + +/** + * 设备离线记录Mapper接口 + * + * @author ruoyi + * @date 2024-09-18 + */ +public interface DcDeviceOfflineRecordMapper +{ + /** + * 查询设备离线记录 + * + * @param id 设备离线记录主键 + * @return 设备离线记录 + */ + public DcDeviceOfflineRecord selectDcDeviceOfflineRecordById(Long id); + + public List selectDcDeviceOfflineRecordByIds(Long[] id); + + /** + * 查询设备离线记录列表 + * + * @param dcDeviceOfflineRecord 设备离线记录 + * @return 设备离线记录集合 + */ + List selectDcDeviceOfflineRecordList(DcDeviceOfflineRecord dcDeviceOfflineRecord); + + /** + * 新增设备离线记录 + * + * @param dcDeviceOfflineRecord 设备离线记录 + * @return 结果 + */ + int insertDcDeviceOfflineRecord(DcDeviceOfflineRecord dcDeviceOfflineRecord); + + /** + * 修改设备离线记录 + * + * @param dcDeviceOfflineRecord 设备离线记录 + * @return 结果 + */ + int updateDcDeviceOfflineRecord(DcDeviceOfflineRecord dcDeviceOfflineRecord); + + /** + * 删除设备离线记录 + * + * @param id 设备离线记录主键 + * @return 结果 + */ + int deleteDcDeviceOfflineRecordById(Long id); + + /** + * 批量删除设备离线记录 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + int deleteDcDeviceOfflineRecordByIds(Long[] ids); +} diff --git a/zc-business/src/main/java/com/zc/business/service/IDcDeviceOfflineRecordService.java b/zc-business/src/main/java/com/zc/business/service/IDcDeviceOfflineRecordService.java new file mode 100644 index 00000000..f2c2e110 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/IDcDeviceOfflineRecordService.java @@ -0,0 +1,73 @@ +package com.zc.business.service; + +import java.util.List; + +import com.ruoyi.common.core.domain.AjaxResult; +import com.zc.business.domain.DcDevice; +import com.zc.business.domain.DcDeviceOfflineRecord; + +/** + * 设备离线记录Service接口 + * + * @author ruoyi + * @date 2024-09-18 + */ +public interface IDcDeviceOfflineRecordService +{ + /** + * 查询设备离线记录 + * + * @param id 设备离线记录主键 + * @return 设备离线记录 + */ + public DcDeviceOfflineRecord selectDcDeviceOfflineRecordById(Long id); + + /** + * 查询设备离线记录列表 + * + * @param dcDeviceOfflineRecord 设备离线记录 + * @return 设备离线记录集合 + */ + List selectDcDeviceOfflineRecordList(DcDeviceOfflineRecord dcDeviceOfflineRecord); + + /** + * 新增设备离线记录 + * + * @param dcDeviceOfflineRecord 设备离线记录 + * @return 结果 + */ + int insertDcDeviceOfflineRecord(DcDeviceOfflineRecord dcDeviceOfflineRecord); + + /** + * 修改设备离线记录 + * + * @param dcDeviceOfflineRecord 设备离线记录 + * @return 结果 + */ + int updateDcDeviceOfflineRecord(DcDeviceOfflineRecord dcDeviceOfflineRecord); + + /** + * 批量删除设备离线记录 + * + * @param ids 需要删除的设备离线记录主键集合 + * @return 结果 + */ + int deleteDcDeviceOfflineRecordByIds(Long[] ids); + + /** + * 删除设备离线记录信息 + * + * @param id 设备离线记录主键 + * @return 结果 + */ + int deleteDcDeviceOfflineRecordById(Long id); + + + /** + * 批量处理 设备离线记录 + * + * @param deviceList + * @return 结果 + */ + AjaxResult batchDeviceOfflineRecord(List deviceList); +} diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceOfflineRecordServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceOfflineRecordServiceImpl.java new file mode 100644 index 00000000..fd06f586 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceOfflineRecordServiceImpl.java @@ -0,0 +1,194 @@ +package com.zc.business.service.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.StringUtils; +import com.zc.business.constant.RedisKeyConstants; +import com.zc.business.domain.DcDevice; +import com.zc.common.core.websocket.WebSocketService; +import com.zc.common.core.websocket.constant.WebSocketEvent; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.zc.business.mapper.DcDeviceOfflineRecordMapper; +import com.zc.business.domain.DcDeviceOfflineRecord; +import com.zc.business.service.IDcDeviceOfflineRecordService; + +import static com.ruoyi.common.utils.SecurityUtils.getUsername; + +/** + * 设备离线记录Service业务层处理 + * + * @author ruoyi + * @date 2024-09-18 + */ +@Service +public class DcDeviceOfflineRecordServiceImpl implements IDcDeviceOfflineRecordService +{ + @Autowired + private DcDeviceOfflineRecordMapper dcDeviceOfflineRecordMapper; + @Autowired + private RedisCache redisCache; + + /** + * 查询设备离线记录 + * + * @param id 设备离线记录主键 + * @return 设备离线记录 + */ + @Override + public DcDeviceOfflineRecord selectDcDeviceOfflineRecordById(Long id) + { + return dcDeviceOfflineRecordMapper.selectDcDeviceOfflineRecordById(id); + } + + /** + * 查询设备离线记录列表 + * + * @param dcDeviceOfflineRecord 设备离线记录 + * @return 设备离线记录 + */ + @Override + public List selectDcDeviceOfflineRecordList(DcDeviceOfflineRecord dcDeviceOfflineRecord) + { + return dcDeviceOfflineRecordMapper.selectDcDeviceOfflineRecordList(dcDeviceOfflineRecord); + } + + /** + * 新增设备离线记录 + * + * @param dcDeviceOfflineRecord 设备离线记录 + * @return 结果 + */ + @Override + public int insertDcDeviceOfflineRecord(DcDeviceOfflineRecord dcDeviceOfflineRecord) + { + dcDeviceOfflineRecord.setCreateTime(DateUtils.getNowDate()); + int i = dcDeviceOfflineRecordMapper.insertDcDeviceOfflineRecord(dcDeviceOfflineRecord); + redisCache.setCacheMapValue(RedisKeyConstants.DC_DEVICE_OFFLINE_RECORD,dcDeviceOfflineRecord.getIotDeviceId(),dcDeviceOfflineRecord); + + //websocket推送 + Map contentMap = new HashMap<>(); + String direction = ""; + if (StringUtils.isNotEmpty(dcDeviceOfflineRecord.getDirection())){ + if ("1".equals(dcDeviceOfflineRecord.getDirection())){ + direction = "菏泽方向"; + } else if ("3".equals(dcDeviceOfflineRecord.getDirection())){ + direction = "济南方向"; + } + } + String content = dcDeviceOfflineRecord.getStakeMark() + direction + dcDeviceOfflineRecord.getDeviceName() + "发生故障"; + contentMap.put("content",content); + contentMap.put("deviceOfflineRecord",dcDeviceOfflineRecord); + WebSocketService.broadcast(WebSocketEvent.DEVICE_OFFLINE_RECORD, contentMap); + + return i; + } + + /** + * 修改设备离线记录 + * + * @param dcDeviceOfflineRecord 设备离线记录 + * @return 结果 + */ + @Override + public int updateDcDeviceOfflineRecord(DcDeviceOfflineRecord dcDeviceOfflineRecord) + { + dcDeviceOfflineRecord.setUpdateTime(DateUtils.getNowDate()); + dcDeviceOfflineRecord.setUpdateBy(getUsername()); + String status = dcDeviceOfflineRecord.getStatus(); + if (StringUtils.isNotEmpty(status) && ("1".equals(status) || "2".equals(status))){ + redisCache.delCacheMapValue(RedisKeyConstants.DC_DEVICE_OFFLINE_RECORD,dcDeviceOfflineRecord.getIotDeviceId()); + } else { + redisCache.setCacheMapValue(RedisKeyConstants.DC_DEVICE_OFFLINE_RECORD,dcDeviceOfflineRecord.getIotDeviceId(),dcDeviceOfflineRecord); + } + return dcDeviceOfflineRecordMapper.updateDcDeviceOfflineRecord(dcDeviceOfflineRecord); + } + + /** + * 批量删除设备离线记录 + * + * @param ids 需要删除的设备离线记录主键 + * @return 结果 + */ + @Override + public int deleteDcDeviceOfflineRecordByIds(Long[] ids) + { + + List list = dcDeviceOfflineRecordMapper.selectDcDeviceOfflineRecordByIds(ids); + for (int i = 0; i < list.size(); i++) { + redisCache.delCacheMapValue(RedisKeyConstants.DC_DEVICE_OFFLINE_RECORD,list.get(i).getIotDeviceId()); + } + return dcDeviceOfflineRecordMapper.deleteDcDeviceOfflineRecordByIds(ids); + } + + /** + * 删除设备离线记录信息 + * + * @param id 设备离线记录主键 + * @return 结果 + */ + @Override + public int deleteDcDeviceOfflineRecordById(Long id) + { + return dcDeviceOfflineRecordMapper.deleteDcDeviceOfflineRecordById(id); + } + + /** + * 批量处理 设备离线记录 + * + * @param deviceList + * @return 结果 + */ + @Override + public AjaxResult batchDeviceOfflineRecord(List deviceList) + { + for (DcDevice dcDevice : deviceList) { + String iotDeviceId = dcDevice.getIotDeviceId(); + String deviceState = dcDevice.getDeviceState(); + if (StringUtils.isNotEmpty(iotDeviceId) && StringUtils.isNotEmpty(deviceState)){ + DcDeviceOfflineRecord cache = redisCache.getCacheMapValue(RedisKeyConstants.DC_DEVICE_OFFLINE_RECORD,iotDeviceId); + + if ("0".equals(deviceState) && cache == null){ + //异常状态并且表里有无此纪录, 新增 + DcDevice dcDeviceCache = redisCache.getCacheMapValue(RedisKeyConstants.DC_DEVICES, iotDeviceId); + + if (dcDeviceCache != null){ + DcDeviceOfflineRecord dcDeviceOfflineRecord = new DcDeviceOfflineRecord(); + dcDeviceOfflineRecord.setDeviceId(dcDeviceCache.getId()); + dcDeviceOfflineRecord.setIotDeviceId(dcDeviceCache.getIotDeviceId()); + dcDeviceOfflineRecord.setDeviceName(dcDeviceCache.getDeviceName()); + dcDeviceOfflineRecord.setDeviceType(dcDeviceCache.getDeviceType()); + dcDeviceOfflineRecord.setStakeMark(dcDeviceCache.getStakeMark()); + dcDeviceOfflineRecord.setDirection(dcDeviceCache.getDirection()); + dcDeviceOfflineRecord.setInstallationSite(dcDeviceCache.getInstallationSite()); + dcDeviceOfflineRecord.setDeviceIp(dcDeviceCache.getDeviceIp()); + dcDeviceOfflineRecord.setFacilitiesType(dcDeviceCache.getFacilitiesType()); + dcDeviceOfflineRecord.setChildType(dcDeviceCache.getChildType()); + dcDeviceOfflineRecord.setLatitude(dcDeviceCache.getLatitude()); + dcDeviceOfflineRecord.setLongitude(dcDeviceCache.getLongitude()); + dcDeviceOfflineRecord.setStatus("0"); + + insertDcDeviceOfflineRecord(dcDeviceOfflineRecord); + } + + + } else if ("1".equals(deviceState) && cache != null){ + //正常状态并且表里有离线记录, 修改为自动结束 + DcDeviceOfflineRecord dcDeviceOfflineRecord = new DcDeviceOfflineRecord(); + dcDeviceOfflineRecord.setId(cache.getId()); + dcDeviceOfflineRecord.setStatus("2"); + dcDeviceOfflineRecord.setUpdateTime(DateUtils.getNowDate()); + dcDeviceOfflineRecordMapper.updateDcDeviceOfflineRecord(dcDeviceOfflineRecord); + redisCache.delCacheMapValue(RedisKeyConstants.DC_DEVICE_OFFLINE_RECORD,iotDeviceId); + + } + } + } + return AjaxResult.success("操作成功"); + } +} diff --git a/zc-business/src/main/resources/mapper/business/DcDeviceOfflineRecordMapper.xml b/zc-business/src/main/resources/mapper/business/DcDeviceOfflineRecordMapper.xml new file mode 100644 index 00000000..18fa449b --- /dev/null +++ b/zc-business/src/main/resources/mapper/business/DcDeviceOfflineRecordMapper.xml @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + select id, device_id,iot_device_id, device_name, device_type, stake_mark, direction, installation_site, device_ip, facilities_type, child_type, longitude, latitude, status, create_time, update_time, update_by from dc_device_offline_record + + + + + + + + + insert into dc_device_offline_record + + device_id, + iot_device_id, + device_name, + device_type, + stake_mark, + direction, + installation_site, + device_ip, + facilities_type, + child_type, + longitude, + latitude, + status, + create_time, + update_time, + update_by, + + + #{deviceId}, + #{iotDeviceId}, + #{deviceName}, + #{deviceType}, + #{stakeMark}, + #{direction}, + #{installationSite}, + #{deviceIp}, + #{facilitiesType}, + #{childType}, + #{longitude}, + #{latitude}, + #{status}, + #{createTime}, + #{updateTime}, + #{updateBy}, + + + + + update dc_device_offline_record + + device_id = #{deviceId}, + iot_device_id = #{iotDeviceId}, + device_name = #{deviceName}, + device_type = #{deviceType}, + stake_mark = #{stakeMark}, + direction = #{direction}, + installation_site = #{installationSite}, + device_ip = #{deviceIp}, + facilities_type = #{facilitiesType}, + child_type = #{childType}, + longitude = #{longitude}, + latitude = #{latitude}, + status = #{status}, + create_time = #{createTime}, + update_time = #{updateTime}, + update_by = #{updateBy}, + + where id = #{id} + + + + delete from dc_device_offline_record where id = #{id} + + + + delete from dc_device_offline_record where id in + + #{id} + + + \ No newline at end of file