diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/AppRealTimeStatusDto.java b/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/AppRealTimeStatusDto.java index 01a13d3..c927504 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/AppRealTimeStatusDto.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/domain/dto/AppRealTimeStatusDto.java @@ -14,7 +14,7 @@ public class AppRealTimeStatusDto { private String deviceImei; /** - * 设备类型 + * 获取实时状态类型:FunctionAccessBatchStatusRule 批量 ,FunctionAccessStatusRule 单个 */ private String typeName; diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/receiver/ReceiverMessageHandler.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/receiver/ReceiverMessageHandler.java index 4259cd1..2581db7 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/receiver/ReceiverMessageHandler.java +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/receiver/ReceiverMessageHandler.java @@ -10,6 +10,7 @@ import com.fuyuanshen.global.mqtt.base.MqttRuleContext; import com.fuyuanshen.global.mqtt.base.MqttRuleEngine; import com.fuyuanshen.global.mqtt.base.MqttXinghanCommandType; import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants; +import com.fuyuanshen.global.queue.MqttMessageQueueConstants; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.Message; @@ -51,6 +52,9 @@ public class ReceiverMessageHandler implements MessageHandler { //在线状态 String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ; RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1", Duration.ofSeconds(62)); +// String queueKey = MqttMessageQueueConstants.MQTT_MESSAGE_QUEUE_KEY; +// String dedupKey = MqttMessageQueueConstants.MQTT_MESSAGE_DEDUP_KEY; +// RedisUtils.offerDeduplicated(queueKey,dedupKey,deviceImei, Duration.ofHours(24)); } String state = payloadDict.getStr("state"); diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/queue/MqttMessageConsumer.java b/fys-admin/src/main/java/com/fuyuanshen/global/queue/MqttMessageConsumer.java new file mode 100644 index 0000000..9172fa8 --- /dev/null +++ b/fys-admin/src/main/java/com/fuyuanshen/global/queue/MqttMessageConsumer.java @@ -0,0 +1,110 @@ +package com.fuyuanshen.global.queue; + +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.fuyuanshen.common.redis.utils.RedisUtils; +import com.fuyuanshen.equipment.domain.Device; +import com.fuyuanshen.equipment.mapper.DeviceMapper; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +@Service +@Slf4j +public class MqttMessageConsumer { + + @Autowired + private DeviceMapper deviceMapper; + + // 创建两个线程池:一个用于消息获取,一个用于业务处理 + private ExecutorService messageConsumerPool = Executors.newFixedThreadPool(3); + private ExecutorService messageProcessorPool = Executors.newFixedThreadPool(10); + + // 初始化方法,启动消息监听 +// @PostConstruct + public void start() { + log.info("启动MQTT消息消费者..."); + // 启动消息获取线程 + for (int i = 0; i < 3; i++) { + messageConsumerPool.submit(this::consumeMessages); + } + } + + // 销毁方法,关闭线程池 + @PreDestroy + public void stop() { + log.info("关闭MQTT消息消费者..."); + shutdownExecutorService(messageConsumerPool); + shutdownExecutorService(messageProcessorPool); + } + + private void shutdownExecutorService(ExecutorService executorService) { + if (executorService != null && !executorService.isShutdown()) { + executorService.shutdown(); + try { + if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) { + executorService.shutdownNow(); + } + } catch (InterruptedException e) { + executorService.shutdownNow(); + Thread.currentThread().interrupt(); + } + } + } + + // 消费者方法 - 专门负责从队列获取消息 + public void consumeMessages() { + String queueKey = MqttMessageQueueConstants.MQTT_MESSAGE_QUEUE_KEY; + String threadName = Thread.currentThread().getName(); + log.info("消息消费者线程 {} 开始监听队列: {}", threadName, queueKey); + + try { + while (!Thread.currentThread().isInterrupted() && !messageConsumerPool.isShutdown()) { + // 阻塞式获取队列中的消息 + String message = RedisUtils.pollDeduplicated( + queueKey, + MqttMessageQueueConstants.MQTT_MESSAGE_DEDUP_KEY, + 1, + TimeUnit.SECONDS + ); + + if (message != null) { + log.info("线程 {} 从队列中获取到消息,提交到处理线程池: {}", threadName, message); + // 将消息处理任务提交到处理线程池 + messageProcessorPool.submit(() -> processMessage(message)); + } + } + } catch (Exception e) { + log.error("线程 {} 消费消息时发生错误", threadName, e); + } + + log.info("消息消费者线程 {} 停止监听队列", threadName); + } + + // 处理具体业务逻辑的方法 + private void processMessage(String message) { + String threadName = Thread.currentThread().getName(); + try { + log.info("业务处理线程 {} 开始处理消息: {}", threadName, message); + + // 实现具体的业务逻辑 + // 例如更新数据库、发送通知等 + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("device_imei", message) + .set("online_status", 1); + deviceMapper.update(updateWrapper); + // 模拟业务处理耗时 + Thread.sleep(200); + + log.info("业务处理线程 {} 完成消息处理: {}", threadName, message); + } catch (Exception e) { + log.error("业务处理线程 {} 处理消息时发生错误: {}", threadName, message, e); + } + } +} diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/queue/MqttMessageQueueConstants.java b/fys-admin/src/main/java/com/fuyuanshen/global/queue/MqttMessageQueueConstants.java new file mode 100644 index 0000000..b4eb34d --- /dev/null +++ b/fys-admin/src/main/java/com/fuyuanshen/global/queue/MqttMessageQueueConstants.java @@ -0,0 +1,6 @@ +package com.fuyuanshen.global.queue; + +public class MqttMessageQueueConstants { + public static final String MQTT_MESSAGE_QUEUE_KEY = "mqtt:message:queue"; + public static final String MQTT_MESSAGE_DEDUP_KEY = "mqtt:message:dedup"; +} diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceAlarmController.java b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceAlarmController.java new file mode 100644 index 0000000..309bc14 --- /dev/null +++ b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceAlarmController.java @@ -0,0 +1,107 @@ +package com.fuyuanshen.web.controller.device; + +import com.fuyuanshen.common.core.domain.R; +import com.fuyuanshen.common.core.validate.AddGroup; +import com.fuyuanshen.common.core.validate.EditGroup; +import com.fuyuanshen.common.excel.utils.ExcelUtil; +import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit; +import com.fuyuanshen.common.log.annotation.Log; +import com.fuyuanshen.common.log.enums.BusinessType; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.web.core.BaseController; +import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo; +import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo; +import com.fuyuanshen.equipment.service.IDeviceAlarmService; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 设备告警 + * + * @author Lion Li + * @date 2025-08-28 + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("api/equipment/alarm") +public class DeviceAlarmController extends BaseController { + + private final IDeviceAlarmService deviceAlarmService; + + + /** + * 查询设备告警列表 + */ + // @SaCheckPermission("equipment:alarm:list") + @GetMapping("/list") + public TableDataInfo list(DeviceAlarmBo bo, PageQuery pageQuery) { + return deviceAlarmService.queryPageList(bo, pageQuery); + } + + /** + * 导出设备告警列表 + */ + // @SaCheckPermission("equipment:alarm:export") + @Log(title = "导出设备告警列表", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(DeviceAlarmBo bo, HttpServletResponse response) { + List list = deviceAlarmService.queryList(bo); + ExcelUtil.exportExcel(list, "设备告警", DeviceAlarmVo.class, response); + } + + /** + * 获取设备告警详细信息 + * + * @param id 主键 + */ + // @SaCheckPermission("equipment:alarm:query") + @GetMapping("/{id}") + public R getInfo(@NotNull(message = "主键不能为空") + @PathVariable Long id) { + return R.ok(deviceAlarmService.queryById(id)); + } + + /** + * 新增设备告警 + */ + // @SaCheckPermission("equipment:alarm:add") + @Log(title = "设备告警", businessType = BusinessType.INSERT) + @RepeatSubmit() + @PostMapping() + public R add(@Validated(AddGroup.class) @RequestBody DeviceAlarmBo bo) { + return toAjax(deviceAlarmService.insertByBo(bo)); + } + + /** + * 修改设备告警 + */ + // @SaCheckPermission("equipment:alarm:edit") + @Log(title = "设备告警", businessType = BusinessType.UPDATE) + @RepeatSubmit() + @PutMapping() + public R edit(@Validated(EditGroup.class) @RequestBody DeviceAlarmBo bo) { + return toAjax(deviceAlarmService.updateByBo(bo)); + } + + /** + * 删除设备告警 + * + * @param ids 主键串 + */ + // @SaCheckPermission("equipment:alarm:remove") + @Log(title = "设备告警", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public R remove(@NotEmpty(message = "主键不能为空") + @PathVariable Long[] ids) { + return toAjax(deviceAlarmService.deleteWithValidByIds(List.of(ids), true)); + } + +} diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceChargeDischargeController.java b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceChargeDischargeController.java new file mode 100644 index 0000000..c8cc77c --- /dev/null +++ b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceChargeDischargeController.java @@ -0,0 +1,105 @@ +package com.fuyuanshen.web.controller.device; + +import java.util.List; + +import lombok.RequiredArgsConstructor; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.*; +import cn.dev33.satoken.annotation.SaCheckPermission; +import org.springframework.web.bind.annotation.*; +import org.springframework.validation.annotation.Validated; +import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit; +import com.fuyuanshen.common.log.annotation.Log; +import com.fuyuanshen.common.web.core.BaseController; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import com.fuyuanshen.common.core.domain.R; +import com.fuyuanshen.common.core.validate.AddGroup; +import com.fuyuanshen.common.core.validate.EditGroup; +import com.fuyuanshen.common.log.enums.BusinessType; +import com.fuyuanshen.common.excel.utils.ExcelUtil; +import com.fuyuanshen.equipment.domain.vo.DeviceChargeDischargeVo; +import com.fuyuanshen.equipment.domain.bo.DeviceChargeDischargeBo; +import com.fuyuanshen.equipment.service.IDeviceChargeDischargeService; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; + +/** + * 设备充放电记录 + * + * @author Lion Li + * @date 2025-08-30 + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/equipment/chargeDischarge") +public class DeviceChargeDischargeController extends BaseController { + + private final IDeviceChargeDischargeService deviceChargeDischargeService; + + /** + * 查询设备充放电记录列表 + */ + @SaCheckPermission("equipment:chargeDischarge:list") + @GetMapping("/list") + public TableDataInfo list(DeviceChargeDischargeBo bo, PageQuery pageQuery) { + return deviceChargeDischargeService.queryPageList(bo, pageQuery); + } + + /** + * 设备充放电记录列表 + */ + @SaCheckPermission("equipment:chargeDischarge:export") + @Log(title = "设备充放电记录", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(DeviceChargeDischargeBo bo, HttpServletResponse response) { + List list = deviceChargeDischargeService.queryList(bo); + ExcelUtil.exportExcel(list, "设备充放电记录", DeviceChargeDischargeVo.class, response); + } + + /** + * 获取设备充放电记录详细信息 + * + * @param id 主键 + */ + @SaCheckPermission("equipment:chargeDischarge:query") + @GetMapping("/{id}") + public R getInfo(@NotNull(message = "主键不能为空") + @PathVariable Long id) { + return R.ok(deviceChargeDischargeService.queryById(id)); + } + + /** + * 新增设备充放电记录 + */ + @SaCheckPermission("equipment:chargeDischarge:add") + @Log(title = "设备充放电记录", businessType = BusinessType.INSERT) + @RepeatSubmit() + @PostMapping() + public R add(@Validated(AddGroup.class) @RequestBody DeviceChargeDischargeBo bo) { + return toAjax(deviceChargeDischargeService.insertByBo(bo)); + } + + /** + * 修改设备充放电记录 + */ + @SaCheckPermission("equipment:chargeDischarge:edit") + @Log(title = "设备充放电记录", businessType = BusinessType.UPDATE) + @RepeatSubmit() + @PutMapping() + public R edit(@Validated(EditGroup.class) @RequestBody DeviceChargeDischargeBo bo) { + return toAjax(deviceChargeDischargeService.updateByBo(bo)); + } + + /** + * 删除设备充放电记录 + * + * @param ids 主键串 + */ + @SaCheckPermission("equipment:chargeDischarge:remove") + @Log(title = "设备充放电记录", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public R remove(@NotEmpty(message = "主键不能为空") + @PathVariable Long[] ids) { + return toAjax(deviceChargeDischargeService.deleteWithValidByIds(List.of(ids), true)); + } +} diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceControlCenterController.java b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceControlCenterController.java index 789ca85..64f395e 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceControlCenterController.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceControlCenterController.java @@ -4,16 +4,16 @@ import com.fuyuanshen.app.domain.dto.APPReNameDTO; import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto; import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo; import com.fuyuanshen.common.core.domain.R; +import com.fuyuanshen.common.excel.utils.ExcelUtil; import com.fuyuanshen.common.mybatis.core.page.PageQuery; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; import com.fuyuanshen.common.web.core.BaseController; import com.fuyuanshen.equipment.domain.dto.AppDeviceBo; import com.fuyuanshen.equipment.domain.dto.InstructionRecordDto; import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria; -import com.fuyuanshen.equipment.domain.vo.AppDeviceVo; -import com.fuyuanshen.equipment.domain.vo.InstructionRecordVo; -import com.fuyuanshen.equipment.domain.vo.WebDeviceVo; +import com.fuyuanshen.equipment.domain.vo.*; import com.fuyuanshen.web.service.device.DeviceBizService; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; @@ -32,6 +32,8 @@ import java.util.Map; public class DeviceControlCenterController extends BaseController { private final DeviceBizService appDeviceService; + + /** * 查询设备列表 */ @@ -101,4 +103,48 @@ public class DeviceControlCenterController extends BaseController { return appDeviceService.getInstructionRecord(dto,pageQuery); } + /** + * 导出 + */ + @GetMapping("/export") + public void export(InstructionRecordDto dto, PageQuery pageQuery, HttpServletResponse response) { + pageQuery.setPageNum(1); + pageQuery.setPageSize(2000); + TableDataInfo instructionRecord = appDeviceService.getInstructionRecord(dto, pageQuery); + if(instructionRecord.getRows() == null){ + return; + } + ExcelUtil.exportExcel(instructionRecord.getRows(), "设备操作日志", InstructionRecordVo.class, response); + } + + + /** + * 历史轨迹查询 + */ + @GetMapping("/locationHistory") + public TableDataInfo getLocationHistory(InstructionRecordDto dto, PageQuery pageQuery) { + return appDeviceService.getLocationHistory(dto,pageQuery); + } + + /** + * 历史轨迹导出 + */ + @GetMapping("/locationHistoryExport") + public void locationHistoryExport(InstructionRecordDto dto, PageQuery pageQuery, HttpServletResponse response) { + pageQuery.setPageNum(1); + pageQuery.setPageSize(2000); + TableDataInfo result = appDeviceService.getLocationHistory(dto, pageQuery); + if(result.getRows() == null){ + return; + } + ExcelUtil.exportExcel(result.getRows(), "历史轨迹记录", LocationHistoryVo.class, response); + } + + /** + * 历史轨迹播放 + */ + @GetMapping("/getLocationHistoryDetail") + public R> getLocationHistoryDetail(Long id) { + return R.ok(appDeviceService.getLocationHistoryDetail(id)); + } } diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceGroupController.java b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceGroupController.java index 3e1018e..ab2297d 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceGroupController.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceGroupController.java @@ -1,27 +1,27 @@ package com.fuyuanshen.web.controller.device; -import java.util.List; - -import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; -import org.springframework.web.bind.annotation.*; -import org.springframework.validation.annotation.Validated; -import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit; -import com.fuyuanshen.common.log.annotation.Log; -import com.fuyuanshen.common.web.core.BaseController; import com.fuyuanshen.common.core.domain.R; import com.fuyuanshen.common.core.validate.AddGroup; import com.fuyuanshen.common.core.validate.EditGroup; -import com.fuyuanshen.common.log.enums.BusinessType; import com.fuyuanshen.common.excel.utils.ExcelUtil; -import com.fuyuanshen.equipment.domain.vo.DeviceGroupVo; +import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit; +import com.fuyuanshen.common.log.annotation.Log; +import com.fuyuanshen.common.log.enums.BusinessType; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.web.core.BaseController; import com.fuyuanshen.equipment.domain.bo.DeviceGroupBo; +import com.fuyuanshen.equipment.domain.vo.DeviceGroupVo; import com.fuyuanshen.equipment.service.IDeviceGroupService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.NotNull; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; /** * 设备分组 @@ -51,6 +51,24 @@ public class DeviceGroupController extends BaseController { } + /** + * 查询设备分组列表(分页) + */ + @Operation(summary = "查询设备分组列表(分页)") + @SaCheckPermission("fys-equipment:group:list") + @GetMapping("/listPage") + public TableDataInfo listPage(DeviceGroupBo bo) { + List list = deviceGroupService.queryList(bo); + // return R.ok(list); + return null; + } + + // @GetMapping("/list") + // public TableDataInfo list(DeviceAlarmBo bo, PageQuery pageQuery) { + // return deviceAlarmService.queryPageList(bo, pageQuery); + // } + + /** * 导出设备分组列表 */ @@ -110,7 +128,7 @@ public class DeviceGroupController extends BaseController { @SaCheckPermission("fys-equipment:group:remove") @Log(title = "设备分组", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") - public R remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) { + public R remove(@NotNull(message = "主键不能为空") @PathVariable Long[] ids) { return toAjax(deviceGroupService.deleteWithValidByIds(List.of(ids), true)); } @@ -124,11 +142,25 @@ public class DeviceGroupController extends BaseController { @Operation(summary = "绑定设备分组") // @SaCheckPermission("fys-equipment:group:remove") @Log(title = "绑定设备分组", businessType = BusinessType.DELETE) - @GetMapping("/groupId/{deviceId}") - public R bindingDevice(@NotEmpty(message = "分组id 不能为空") @PathVariable Long groupId, - @NotEmpty(message = "设备id 不能为空") @PathVariable Long[] deviceId) { + @GetMapping("/groupId/{groupId}/{deviceId}") + public R bindingDevice(@NotNull(message = "分组id 不能为空") @PathVariable Long groupId, + @NotNull(message = "设备id 不能为空") @PathVariable Long[] deviceId) { return toAjax(deviceGroupService.bindingDevice(groupId, deviceId)); } + /** + * 解绑设备分组 + * + * @param deviceId 设备id + */ + @Operation(summary = "解绑设备分组") + // @SaCheckPermission("fys-equipment:group:remove") + @Log(title = "解绑设备分组", businessType = BusinessType.DELETE) + @GetMapping("/groupUnbind/{deviceId}") + public R groupUnbind(@NotNull(message = "设备id 不能为空") @PathVariable Long[] deviceId) { + return toAjax(deviceGroupService.groupUnbind(deviceId)); + } + + } diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceShareController.java b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceShareController.java new file mode 100644 index 0000000..e623e9d --- /dev/null +++ b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/DeviceShareController.java @@ -0,0 +1,43 @@ +package com.fuyuanshen.web.controller.device; + +import com.fuyuanshen.app.domain.bo.AppDeviceShareBo; +import com.fuyuanshen.app.domain.vo.AppDeviceShareVo; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.web.core.BaseController; +import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo; +import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo; +import com.fuyuanshen.web.service.DeviceShareService; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 设备分享管理 + * + * @author Lion Li + * @date 2025-08-28 + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("api/equipment/share") +public class DeviceShareController extends BaseController { + + private final DeviceShareService appDeviceShareService; + + + /** + *查询设备分享列表(web) + */ + // @SaCheckPermission("equipment:alarm:list") + @GetMapping("/list") + public TableDataInfo list(AppDeviceShareBo bo, PageQuery pageQuery) { + return appDeviceShareService.queryWebList(bo, pageQuery); + } + + + +} diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/HomePageController.java b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/HomePageController.java new file mode 100644 index 0000000..b8786bf --- /dev/null +++ b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/HomePageController.java @@ -0,0 +1,67 @@ +package com.fuyuanshen.web.controller.device; + +import com.fuyuanshen.common.core.domain.R; +import com.fuyuanshen.equipment.domain.vo.DataOverviewVo; +import com.fuyuanshen.equipment.service.DeviceService; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 首页数据 + * + * @author: 默苍璃 + * @date: 2025-09-0113:46 + */ +@Tag(name = "首页数据", description = "首页数据") +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/device/homepage") +public class HomePageController { + + private final DeviceService deviceService; + + + /** + * 获取 数据总览 + * DataOverview + */ + @GetMapping("/getDataOverview") + public R getDataOverview() { + return R.ok(deviceService.getDataOverview()); + } + + + + + // 获取设备使用数据 + @GetMapping("/{deviceId}") + public Map getUsageData( + @PathVariable String deviceId, + @RequestParam String range) { + + Map response = new HashMap<>(); + + if ("halfYear".equals(range)) { + response.put("months", Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月")); + response.put("data", Arrays.asList(45, 52, 38, 60, 56, 48)); + } else if ("oneYear".equals(range)) { + response.put("months", Arrays.asList("7月", "8月", "9月", "10月", "11月", "12月", + "1月", "2月", "3月", "4月", "5月", "6月")); + response.put("data", Arrays.asList(42, 38, 45, 48, 52, 55, 45, 52, 38, 60, 56, 48)); + } + + response.put("deviceId", deviceId); + response.put("range", range); + response.put("lastUpdate", new Date()); + + return response; + } +} diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/WEBDeviceController.java b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/WEBDeviceController.java index 9f7ddad..c958059 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/WEBDeviceController.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/WEBDeviceController.java @@ -4,6 +4,8 @@ package com.fuyuanshen.web.controller.device; import com.fuyuanshen.app.domain.AppPersonnelInfoRecords; import com.fuyuanshen.common.core.domain.R; import com.fuyuanshen.common.web.core.BaseController; +import com.fuyuanshen.equipment.domain.DeviceLog; +import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo; import com.fuyuanshen.equipment.domain.vo.WebDeviceVo; import com.fuyuanshen.web.service.WEBDeviceService; import io.swagger.v3.oas.annotations.Operation; @@ -51,7 +53,7 @@ public class WEBDeviceController extends BaseController { */ @Operation(summary = "设备详情") @GetMapping(value = "/pc/detail/{id}") - public R getDevice(@PathVariable Long id) { + public R getDeviceDetail(@PathVariable Long id) { WebDeviceVo device = deviceService.getDevice(id); return R.ok(device); } @@ -60,13 +62,41 @@ public class WEBDeviceController extends BaseController { /** * 设备用户详情 * - * @param id + * @param deviceId * @return */ @Operation(summary = "设备详情") - @GetMapping(value = "/getDeviceUser/{id}") - public R> getDeviceUser(@PathVariable Long id) { - List device = deviceService.getDeviceUser(id); + @GetMapping(value = "/getDeviceUser/{deviceId}") + public R> getDeviceUser(@PathVariable Long deviceId) { + List device = deviceService.getDeviceUser(deviceId); + return R.ok(device); + } + + + /** + * 设备操作记录 + * + * @param deviceId + * @return + */ + @Operation(summary = "设备操作记录") + @GetMapping(value = "/getOperationRecord/{deviceId}") + public R> getOperationRecord(@PathVariable Long deviceId) { + List device = deviceService.getOperationRecord(deviceId); + return R.ok(device); + } + + + /** + * 设备告警记录 + * + * @param deviceId + * @return + */ + @Operation(summary = "设备告警记录") + @GetMapping(value = "/getAlarmRecord/{deviceId}") + public R> getAlarmRecord(@PathVariable Long deviceId) { + List device = deviceService.getAlarmRecord(deviceId); return R.ok(device); } diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/service/DeviceShareService.java b/fys-admin/src/main/java/com/fuyuanshen/web/service/DeviceShareService.java index d73eaa7..9e493b1 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/service/DeviceShareService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/service/DeviceShareService.java @@ -43,7 +43,7 @@ import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*; public class DeviceShareService { private final AppDeviceShareMapper appDeviceShareMapper; - + private final DeviceMapper deviceMapper; private final DeviceTypeMapper deviceTypeMapper; @@ -61,32 +61,32 @@ public class DeviceShareService { } private static void buildDeviceStatus(AppDeviceShareVo item) { - //设备在线状态 - String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX); - if(StringUtils.isNotBlank(onlineStatus)){ + // 设备在线状态 + String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX); + if (StringUtils.isNotBlank(onlineStatus)) { item.setOnlineStatus(1); - }else{ + } else { item.setOnlineStatus(0); } - String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX); + String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX); // 获取电量 - if(StringUtils.isNotBlank(deviceStatus)){ + if (StringUtils.isNotBlank(deviceStatus)) { JSONObject jsonObject = JSONObject.parseObject(deviceStatus); item.setBattery(jsonObject.getString("batteryPercentage")); - }else{ + } else { item.setBattery("0"); } - String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_LOCATION_KEY_PREFIX); - if(StringUtils.isNotBlank(location)){ + String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_LOCATION_KEY_PREFIX); + if (StringUtils.isNotBlank(location)) { JSONObject jsonObject = JSONObject.parseObject(location); item.setLatitude(jsonObject.getString("latitude")); item.setLongitude(jsonObject.getString("longitude")); } - String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX); - if(StringUtils.isNotBlank(alarmStatus)){ + String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX); + if (StringUtils.isNotBlank(alarmStatus)) { item.setAlarmStatus(alarmStatus); } } @@ -96,7 +96,7 @@ public class DeviceShareService { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(AppDeviceShare::getId, id); List appDeviceShareVos = appDeviceShareMapper.selectVoList(queryWrapper); - if(appDeviceShareVos==null || appDeviceShareVos.isEmpty()){ + if (appDeviceShareVos == null || appDeviceShareVos.isEmpty()) { return null; } @@ -113,7 +113,7 @@ public class DeviceShareService { shareDetailVo.setDeviceMac(device.getDeviceMac()); DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType()); - if(deviceType!=null){ + if (deviceType != null) { shareDetailVo.setCommunicationMode(Integer.valueOf(deviceType.getCommunicationMode())); } shareDetailVo.setDevicePic(device.getDevicePic()); @@ -125,52 +125,53 @@ public class DeviceShareService { LambdaQueryWrapper qw = new LambdaQueryWrapper<>(); qw.eq(AppPersonnelInfo::getDeviceId, device.getId()); List appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw); - if(appPersonnelInfoVos!=null && !appPersonnelInfoVos.isEmpty()){ + if (appPersonnelInfoVos != null && !appPersonnelInfoVos.isEmpty()) { shareDetailVo.setPersonnelInfo(appPersonnelInfoVos.get(0)); } - //设备在线状态 - String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei()+ DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX); - if(StringUtils.isNotBlank(onlineStatus)){ + // 设备在线状态 + String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX); + if (StringUtils.isNotBlank(onlineStatus)) { shareDetailVo.setOnlineStatus(1); - }else{ + } else { shareDetailVo.setOnlineStatus(0); } - String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX); + String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX); // 获取电量 - if(StringUtils.isNotBlank(deviceStatus)){ + if (StringUtils.isNotBlank(deviceStatus)) { JSONObject jsonObject = JSONObject.parseObject(deviceStatus); shareDetailVo.setMainLightMode(jsonObject.getString("mainLightMode")); shareDetailVo.setLaserLightMode(jsonObject.getString("laserLightMode")); shareDetailVo.setBatteryPercentage(jsonObject.getString("batteryPercentage")); shareDetailVo.setChargeState(jsonObject.getString("chargeState")); shareDetailVo.setBatteryRemainingTime(jsonObject.getString("batteryRemainingTime")); - }else{ + } else { shareDetailVo.setBatteryPercentage("0"); } // 获取经度纬度 - String locationKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX; + String locationKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX; String locationInfo = RedisUtils.getCacheObject(locationKey); - if(StringUtils.isNotBlank(locationInfo)){ + if (StringUtils.isNotBlank(locationInfo)) { JSONObject jsonObject = JSONObject.parseObject(locationInfo); shareDetailVo.setLongitude(jsonObject.get("longitude").toString()); shareDetailVo.setLatitude(jsonObject.get("latitude").toString()); - shareDetailVo.setAddress((String)jsonObject.get("address")); + shareDetailVo.setAddress((String) jsonObject.get("address")); } - String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ device.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX); - if(StringUtils.isNotBlank(alarmStatus)){ + String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX); + if (StringUtils.isNotBlank(alarmStatus)) { shareDetailVo.setAlarmStatus(alarmStatus); } - String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ device.getDeviceImei()+ DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX); - if(StringUtils.isNotBlank(lightBrightness)){ + String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX); + if (StringUtils.isNotBlank(lightBrightness)) { shareDetailVo.setLightBrightness(lightBrightness); } return shareDetailVo; } + /** * 校验短信验证码 */ @@ -181,14 +182,15 @@ public class DeviceShareService { } return code.equals(smsCode); } + public int deviceShare(AppDeviceShareBo bo) { boolean flag = validateSmsCode(AppLoginHelper.getTenantId(), bo.getPhonenumber(), bo.getSmsCode()); - if(!flag){ + if (!flag) { throw new ServiceException("验证码错误"); } Device device = deviceMapper.selectById(bo.getDeviceId()); - if(device==null){ + if (device == null) { throw new ServiceException("设备不存在"); } Long userId = AppLoginHelper.getUserId(); @@ -196,7 +198,7 @@ public class DeviceShareService { lqw.eq(AppDeviceShare::getDeviceId, bo.getDeviceId()); lqw.eq(AppDeviceShare::getPhonenumber, bo.getPhonenumber()); Long count = appDeviceShareMapper.selectCount(lqw); - if(count>0){ + if (count > 0) { UpdateWrapper uw = new UpdateWrapper<>(); uw.eq("device_id", bo.getDeviceId()); @@ -206,7 +208,7 @@ public class DeviceShareService { uw.set("update_time", new Date()); return appDeviceShareMapper.update(uw); - }else { + } else { AppDeviceShare appDeviceShare = new AppDeviceShare(); appDeviceShare.setDeviceId(bo.getDeviceId()); appDeviceShare.setPhonenumber(bo.getPhonenumber()); @@ -232,4 +234,19 @@ public class DeviceShareService { } + /** + * 查询设备分享列表(web) + * + * @param bo + * @param pageQuery + * @return + */ + public TableDataInfo queryWebList(AppDeviceShareBo bo, PageQuery pageQuery) { + Page page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()); + Page result = appDeviceShareMapper.selectWebDeviceShareList(bo, page); + List records = result.getRecords(); + records.forEach(DeviceShareService::buildDeviceStatus); + return TableDataInfo.build(result); + } + } diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/service/WEBDeviceService.java b/fys-admin/src/main/java/com/fuyuanshen/web/service/WEBDeviceService.java index 48edf4e..7066a51 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/service/WEBDeviceService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/service/WEBDeviceService.java @@ -6,11 +6,13 @@ import com.fuyuanshen.app.domain.AppPersonnelInfoRecords; import com.fuyuanshen.common.mybatis.core.page.PageQuery; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; import com.fuyuanshen.equipment.domain.Device; +import com.fuyuanshen.equipment.domain.DeviceLog; import com.fuyuanshen.equipment.domain.dto.AppDeviceBo; import com.fuyuanshen.equipment.domain.form.DeviceForm; import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria; import com.fuyuanshen.equipment.domain.vo.AppDeviceVo; import com.fuyuanshen.equipment.domain.vo.CustomerVo; +import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo; import com.fuyuanshen.equipment.domain.vo.WebDeviceVo; import java.io.IOException; @@ -45,6 +47,22 @@ public interface WEBDeviceService extends IService { * @param id * @return */ - List getDeviceUser(Long id); + List getDeviceUser(Long id); + /** + * 设备操作记录 + * + * @param deviceId + * @return + */ + List getOperationRecord(Long deviceId); + + + /** + * 设备告警记录 + * + * @param deviceId + * @return + */ + List getAlarmRecord(Long deviceId); } diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java b/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java index 4e468f3..21cf14e 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/service/device/DeviceBizService.java @@ -1,6 +1,7 @@ package com.fuyuanshen.web.service.device; import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; @@ -27,9 +28,7 @@ import com.fuyuanshen.equipment.domain.Device; import com.fuyuanshen.equipment.domain.dto.AppDeviceBo; import com.fuyuanshen.equipment.domain.dto.InstructionRecordDto; import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria; -import com.fuyuanshen.equipment.domain.vo.AppDeviceVo; -import com.fuyuanshen.equipment.domain.vo.InstructionRecordVo; -import com.fuyuanshen.equipment.domain.vo.WebDeviceVo; +import com.fuyuanshen.equipment.domain.vo.*; import com.fuyuanshen.equipment.enums.BindingStatusEnum; import com.fuyuanshen.equipment.enums.CommunicationModeEnum; import com.fuyuanshen.equipment.mapper.DeviceLogMapper; @@ -41,9 +40,8 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.time.*; +import java.util.*; import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY; import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*; @@ -313,8 +311,8 @@ public class DeviceBizService { public Map getRealTimeStatus(AppRealTimeStatusDto statusDto) { try { - String commandType = statusDto.getTypeName()+"_" + statusDto.getFunctionMode(); - DeviceStatusRule rule = realTimeStatusEngine.getDeviceStatusRule(commandType); +// String commandType = statusDto.getTypeName()+"_" + statusDto.getFunctionMode();"FunctionAccessBatchStatusRule" + DeviceStatusRule rule = realTimeStatusEngine.getDeviceStatusRule(statusDto.getTypeName()); if(rule == null){ throw new ServiceException("未匹配到处理命令"); } @@ -336,4 +334,63 @@ public class DeviceBizService { Page result = deviceLogMapper.getInstructionRecord(pageQuery.build(), bo); return TableDataInfo.build(result); } + + public TableDataInfo getLocationHistory(InstructionRecordDto bo, PageQuery pageQuery) { + Page result = deviceMapper.getLocationHistory(pageQuery.build(), bo); + return TableDataInfo.build(result); + } + + public List getLocationHistoryDetail(Long id) { + Device device = deviceMapper.selectById(id); + if (device == null) { + throw new ServiceException("设备不存在"); + } + + // 计算七天前的凌晨时间戳 + LocalDateTime sevenDaysAgo = LocalDateTime.of(LocalDate.now().minusDays(7), LocalTime.MIDNIGHT); + long startTime = sevenDaysAgo.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + + // 计算今天的凌晨时间戳 + LocalDateTime today = LocalDateTime.of(LocalDate.now(), LocalTime.MAX); + long endTime = today.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + + String deviceImei = device.getDeviceImei(); + String a = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX + ":history"; + Collection list = RedisUtils.zRangeByScore(a, startTime, endTime); + if (CollectionUtil.isEmpty(list)) { + return null; + } + + + Map> map = new LinkedHashMap<>(); + for (String obj : list){ + JSONObject jsonObject = JSONObject.parseObject(obj); + Long timestamp = jsonObject.getLong("timestamp"); + LocalDate date = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()).toLocalDate(); + if (map.containsKey(date.toString())) { + map.get(date.toString()).add(jsonObject); + } else { + ArrayList jsonList = new ArrayList<>(); + jsonList.add(jsonObject); + map.put(date.toString(), jsonList); + } + } + + List result = new ArrayList<>(); + for (Map.Entry> entry : map.entrySet()) { + LocationHistoryDetailVo detailVo = new LocationHistoryDetailVo(); + detailVo.setDate(entry.getKey()); + detailVo.setDeviceName(device.getDeviceName()); + detailVo.setStartLocation(entry.getValue().get(0).getString("address")); + detailVo.setEndLocation(entry.getValue().get(entry.getValue().size()-1).getString("address")); + String jsonString = JSONArray.toJSONString(entry.getValue()); + List strings = JSONArray.parseArray(jsonString); + detailVo.setDetailList(strings); + result.add(detailVo); + } + + + return result; + } + } diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/service/device/status/FunctionAccessBatchStatusRule.java b/fys-admin/src/main/java/com/fuyuanshen/web/service/device/status/FunctionAccessBatchStatusRule.java index 116b5c9..3bc4ada 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/service/device/status/FunctionAccessBatchStatusRule.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/service/device/status/FunctionAccessBatchStatusRule.java @@ -22,7 +22,7 @@ import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCES public class FunctionAccessBatchStatusRule implements DeviceStatusRule { @Override public String getCommandType() { - return DeviceTypeConstants.TYPE_BJQ6170+"_2"; + return "FunctionAccessBatchStatusRule"; } @Override diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/service/device/status/FunctionAccessStatusRule.java b/fys-admin/src/main/java/com/fuyuanshen/web/service/device/status/FunctionAccessStatusRule.java index 6b6f094..c1be377 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/service/device/status/FunctionAccessStatusRule.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/service/device/status/FunctionAccessStatusRule.java @@ -21,7 +21,7 @@ import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCES public class FunctionAccessStatusRule implements DeviceStatusRule { @Override public String getCommandType() { - return DeviceTypeConstants.TYPE_BJQ6170+"_1"; + return "FunctionAccessStatusRule"; } @Override diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/service/impl/WEBDeviceServiceImpl.java b/fys-admin/src/main/java/com/fuyuanshen/web/service/impl/WEBDeviceServiceImpl.java index d6a062f..cc92780 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/web/service/impl/WEBDeviceServiceImpl.java +++ b/fys-admin/src/main/java/com/fuyuanshen/web/service/impl/WEBDeviceServiceImpl.java @@ -12,10 +12,15 @@ import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper; import com.fuyuanshen.app.mapper.AppDeviceShareMapper; import com.fuyuanshen.app.mapper.AppPersonnelInfoRecordsMapper; import com.fuyuanshen.equipment.domain.Device; +import com.fuyuanshen.equipment.domain.DeviceAlarm; import com.fuyuanshen.equipment.domain.DeviceAssignments; +import com.fuyuanshen.equipment.domain.DeviceLog; +import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo; import com.fuyuanshen.equipment.domain.vo.WebDeviceVo; import com.fuyuanshen.equipment.enums.BindingStatusEnum; +import com.fuyuanshen.equipment.mapper.DeviceAlarmMapper; import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper; +import com.fuyuanshen.equipment.mapper.DeviceLogMapper; import com.fuyuanshen.equipment.mapper.DeviceMapper; import com.fuyuanshen.web.service.WEBDeviceService; import com.fuyuanshen.web.service.device.DeviceBizService; @@ -40,6 +45,8 @@ public class WEBDeviceServiceImpl extends ServiceImpl impl private final AppDeviceBindRecordMapper appDeviceBindRecordMapper; private final AppPersonnelInfoRecordsMapper infoRecordsMapper; + private final DeviceLogMapper deviceLogMapper; + private final DeviceAlarmMapper deviceAlarmMapper; private final DeviceMapper deviceMapper; private final AppDeviceShareMapper appDeviceShareMapper; @@ -115,4 +122,35 @@ public class WEBDeviceServiceImpl extends ServiceImpl impl } + /** + * 设备操作记录 + * + * @param deviceId + * @return + */ + @Override + public List getOperationRecord(Long deviceId) { + List logList = deviceLogMapper.selectList( + new QueryWrapper().eq("device_id", deviceId) + .orderByDesc("create_time")); + return logList; + } + + + /** + * 设备告警记录 + * + * @param deviceId + * @return + */ + @Override + public List getAlarmRecord(Long deviceId) { + List alarmList = deviceAlarmMapper.selectList( + new QueryWrapper().eq("device_id", deviceId) + .orderByDesc("create_time")); + List deviceAlarmVoList = BeanUtil.copyToList(alarmList, DeviceAlarmVo.class); + return deviceAlarmVoList; + } + + } diff --git a/fys-common/fys-common-redis/src/main/java/com/fuyuanshen/common/redis/utils/RedisUtils.java b/fys-common/fys-common-redis/src/main/java/com/fuyuanshen/common/redis/utils/RedisUtils.java index 17292c0..6357d16 100644 --- a/fys-common/fys-common-redis/src/main/java/com/fuyuanshen/common/redis/utils/RedisUtils.java +++ b/fys-common/fys-common-redis/src/main/java/com/fuyuanshen/common/redis/utils/RedisUtils.java @@ -11,6 +11,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -373,6 +374,28 @@ public class RedisUtils { return 0; } } + + /** + * 根据时间范围查询Sorted Set中的元素(重载方法,适用于时间戳查询) + * + * @param key 键 + * @param startTime 开始时间戳 + * @param endTime 结束时间戳 + * @return 指定时间范围内的元素集合 + */ + public static Collection zRangeByScore(String key, Long startTime, Long endTime) { + try { + RScoredSortedSet sortedSet = CLIENT.getScoredSortedSet(key); + return sortedSet.valueRange(startTime, true, endTime, true); + } catch (Exception e) { + // 记录错误日志(如果项目中有日志工具的话) + // log.error("根据时间范围查询Sorted Set中的元素失败: key={}, startTime={}, endTime={}, error={}", + // key, startTime, endTime, e.getMessage(), e); + return null; + } + } + + /** * 追加缓存Set数据 * @@ -614,4 +637,73 @@ public class RedisUtils { RKeys rKeys = CLIENT.getKeys(); return rKeys.countExists(key) > 0; } + + + /** + * 向去重阻塞队列中添加元素 + * + * @param queueKey 队列键 + * @param dedupKey 去重集合键 + * @param value 消息值 + * @param timeout 过期时间 + * @return 是否添加成功 + */ + public static boolean offerDeduplicated(String queueKey, String dedupKey, String value, Duration timeout) { +// String jsonValue = value instanceof String ? (String) value : JsonUtils.toJsonString(value); + + RLock lock = CLIENT.getLock("lock:" + queueKey); + try { + lock.lock(); + + RSet dedupSet = CLIENT.getSet(dedupKey); + if (dedupSet.contains(value)) { + return false; // 元素已存在,不重复添加 + } + + // 添加到去重集合 + dedupSet.add(value); + + // 添加到阻塞队列 + RBlockingQueue queue = CLIENT.getBlockingQueue(queueKey); + boolean offered = queue.offer(value); + + // 设置过期时间 + if (timeout != null) { + queue.expire(timeout); + dedupSet.expire(timeout); + } + + return offered; + } finally { + lock.unlock(); + } + } + + /** + * 从去重阻塞队列中消费元素 + * + * @param queueKey 队列键 + * @param dedupKey 去重集合键 + * @param timeout 超时时间 + * @param timeUnit 时间单位 + * @return 消息值 + */ + public static String pollDeduplicated(String queueKey, String dedupKey, long timeout, TimeUnit timeUnit) { + try { + RBlockingQueue queue = CLIENT.getBlockingQueue(queueKey); + String value = queue.poll(timeout, timeUnit); + + // 从去重集合中移除 + if (value != null) { + RSet dedupSet = CLIENT.getSet(dedupKey); + dedupSet.remove(value); + } + + return value; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return null; + } + } + } diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/bo/AppDeviceShareBo.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/bo/AppDeviceShareBo.java index 07fe7e0..0262567 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/bo/AppDeviceShareBo.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/bo/AppDeviceShareBo.java @@ -1,5 +1,7 @@ package com.fuyuanshen.app.domain.bo; +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; import com.fuyuanshen.app.domain.AppDeviceShare; import com.fuyuanshen.common.mybatis.core.domain.BaseEntity; import io.github.linpeilie.annotations.AutoMapper; @@ -7,6 +9,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import jakarta.validation.constraints.*; +import java.util.Date; + /** * 设备分享业务对象 app_device_share * @@ -35,10 +39,16 @@ public class AppDeviceShareBo extends BaseEntity { /** * 功能权限(1:灯光模式;2:激光模式;3:开机画面;4:人员信息登记;5:发送信息;6:产品信息) -以逗号分隔 + * 以逗号分隔 */ private String permission; + /** + * 分享用户 + * share_user + */ + private String shareUser; + /** * 备注 */ @@ -46,4 +56,11 @@ public class AppDeviceShareBo extends BaseEntity { private String smsCode; + + /** + * 分享时间 + */ + private Date shareStartTime; + private Date shareEndTime; + } diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceShareMapper.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceShareMapper.java index 1de4c14..99bc47c 100644 --- a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceShareMapper.java +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/AppDeviceShareMapper.java @@ -18,5 +18,13 @@ import org.apache.ibatis.annotations.Param; public interface AppDeviceShareMapper extends BaseMapperPlus { IPage otherDeviceShareList(@Param("bo") AppDeviceShareBo bo, Page page); - Page selectAppDeviceShareList(@Param("bo") AppDeviceShareBo bo,Page page); + Page selectAppDeviceShareList(@Param("bo") AppDeviceShareBo bo, Page page); + + /** + * 查询设备分享列表(web) + * + * @param bo 设备分享 + * @return 设备分享 + */ + Page selectWebDeviceShareList(@Param("bo") AppDeviceShareBo bo, Page page); } diff --git a/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceShareMapper.xml b/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceShareMapper.xml index 137f67f..0b76a8e 100644 --- a/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceShareMapper.xml +++ b/fys-modules/fys-app/src/main/resources/mapper/app/AppDeviceShareMapper.xml @@ -1,27 +1,27 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + + diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/Device.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/Device.java index 5c90dc8..2c9a452 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/Device.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/Device.java @@ -25,6 +25,13 @@ public class Device extends TenantEntity { @Schema(title = "ID") private Long id; + /** + * 设备ID + */ + @TableField(exist = false) + @Schema(title = "设备ID") + private Long deviceId; + @Schema(title = "设备记录ID") @TableField(exist = false) private Long assignId; @@ -153,6 +160,7 @@ public class Device extends TenantEntity { */ @Schema(title = "出厂日期") private Date productionDate; + /** * 在线状态(0离线,1在线) */ diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceAlarm.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceAlarm.java new file mode 100644 index 0000000..f83e161 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceAlarm.java @@ -0,0 +1,99 @@ +package com.fuyuanshen.equipment.domain; + +import com.fuyuanshen.common.tenant.core.TenantEntity; +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; + +import java.io.Serial; + +/** + * 设备告警对象 device_alarm + * + * @author Lion Li + * @date 2025-08-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("device_alarm") +public class DeviceAlarm extends TenantEntity { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @TableId(value = "id") + private Long id; + + /** + * 设备ID + */ + private Long deviceId; + + /** + * 报警事项 + */ + private String deviceAction; + + /** + * 设备名称 + */ + private String deviceName; + + /** + * 数据来源 + */ + private String dataSource; + + /** + * 内容 + */ + private String content; + + /** + * 设备类型 + */ + private Long deviceType; + + /** + * 经度 + + */ + private Long longitude; + + /** + * 纬度 + */ + private Long latitude; + + /** + * 报警位置 + */ + private String location; + + /** + * 报警开始时间 + */ + private Date startTime; + + /** + * 报警结束时间 + */ + private Date finishTime; + + /** + * 报警持续时间 + */ + private Long durationTime; + + /** + * 0已处理,1未处理 + */ + private Long treatmentState; + + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceChargeDischarge.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceChargeDischarge.java new file mode 100644 index 0000000..67b3d48 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceChargeDischarge.java @@ -0,0 +1,108 @@ +package com.fuyuanshen.equipment.domain; + +import com.fuyuanshen.common.tenant.core.TenantEntity; +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; + +import java.io.Serial; + +/** + * 设备充放电记录对象 device_charge_discharge + * + * @author Lion Li + * @date 2025-08-30 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("device_charge_discharge") +public class DeviceChargeDischarge extends TenantEntity { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 记录唯一标识 + */ + @TableId(value = "id") + private Long id; + + /** + * 设备唯一标识 + */ + private String deviceId; + + /** + * 操作类型: 0 charge-充电, 1 discharge-放电 + */ + private Long operationType; + + /** + * 开始时间 + */ + private Date startTime; + + /** + * 结束时间 + */ + private Date endTime; + + /** + * 起始电量百分比(0-100) + */ + private Long initialSoc; + + /** + * 结束电量百分比(0-100) + */ + private Long finalSoc; + + /** + * 充放电量(kWh) + */ + private Long energyKwh; + + /** + * 设备额定功率(kW) + */ + private Long powerRating; + + /** + * 电压(V) + */ + private Long voltage; + + /** + * 电流(A) + */ + private Long current; + + /** + * 温度(℃) + */ + private Long temperature; + + /** + * 当前状态 + */ + private Long status; + + /** + * 错误代码 + */ + private String errorCode; + + /** + * 记录创建时间 + */ + private Date createdAt; + + /** + * 记录更新时间 + */ + private Date updatedAt; + + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceType.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceType.java index d0ab5b0..a8e4618 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceType.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceType.java @@ -21,6 +21,12 @@ public class DeviceType extends TenantEntity { @Schema(title = "ID", hidden = true) private Long id; + /** + * 设备类型ID + */ + @TableField(exist = false) + private Long deviceTypeId; + @Schema(title = "客户号") private Long customerId; diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/bo/DeviceAlarmBo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/bo/DeviceAlarmBo.java new file mode 100644 index 0000000..0918f18 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/bo/DeviceAlarmBo.java @@ -0,0 +1,116 @@ +package com.fuyuanshen.equipment.domain.bo; + +import com.fuyuanshen.common.core.validate.EditGroup; +import com.fuyuanshen.common.mybatis.core.domain.BaseEntity; +import com.fuyuanshen.equipment.domain.DeviceAlarm; +import io.github.linpeilie.annotations.AutoMapper; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 设备告警业务对象 device_alarm + * + * @author Lion Li + * @date 2025-08-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DeviceAlarm.class, reverseConvertGenerate = false) +public class DeviceAlarmBo extends BaseEntity { + + /** + * ID + */ + @NotNull(message = "ID不能为空", groups = {EditGroup.class}) + private Long id; + + /** + * 设备ID + */ + private Long deviceId; + + /** + * 报警事项 + * device_action + */ + private Integer deviceAction; + + /** + * 设备名称 + */ + private String deviceName; + + /** + * 设备MAC + * device_mac + */ + private String deviceMac; + + /** + * 设备IMEI + * device_imei + */ + private String deviceImei; + + /** + * 数据来源 + */ + private String dataSource; + + /** + * 内容 + */ + private String content; + + /** + * 设备类型 + * device_type + */ + private Long deviceType; + + /** + * 经度 + */ + private Long longitude; + + /** + * 纬度 + */ + private Long latitude; + + /** + * 报警位置 + */ + private String location; + + /** + * 报警开始时间 + */ + private Date startTime; + + /** + * 报警结束时间 + */ + private Date finishTime; + + /** + * 报警持续时间 + */ + private Long durationTime; + + /** + * 报警查询时间 + */ + private String queryTime1; + private String queryTime2; + + /** + * 0已处理,1未处理 + */ + private Integer treatmentState; + + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/bo/DeviceChargeDischargeBo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/bo/DeviceChargeDischargeBo.java new file mode 100644 index 0000000..e953b0e --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/bo/DeviceChargeDischargeBo.java @@ -0,0 +1,110 @@ +package com.fuyuanshen.equipment.domain.bo; + +import com.fuyuanshen.common.core.validate.AddGroup; +import com.fuyuanshen.common.core.validate.EditGroup; +import com.fuyuanshen.equipment.domain.DeviceChargeDischarge; +import com.fuyuanshen.common.mybatis.core.domain.BaseEntity; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import lombok.EqualsAndHashCode; +import jakarta.validation.constraints.*; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; + +/** + * 设备充放电记录业务对象 device_charge_discharge + * + * @author Lion Li + * @date 2025-08-30 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DeviceChargeDischarge.class, reverseConvertGenerate = false) +public class DeviceChargeDischargeBo extends BaseEntity { + + /** + * 记录唯一标识 + */ + @NotNull(message = "记录唯一标识不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 设备唯一标识 + */ + @NotBlank(message = "设备唯一标识不能为空", groups = { AddGroup.class, EditGroup.class }) + private String deviceId; + + /** + * 操作类型: 0 charge-充电, 1 discharge-放电 + */ + @NotNull(message = "操作类型: 0 charge-充电, 1 discharge-放电不能为空", groups = { AddGroup.class, EditGroup.class }) + private Long operationType; + + /** + * 开始时间 + */ + @NotNull(message = "开始时间不能为空", groups = { AddGroup.class, EditGroup.class }) + private Date startTime; + + /** + * 结束时间 + */ + private Date endTime; + + /** + * 起始电量百分比(0-100) + */ + private Long initialSoc; + + /** + * 结束电量百分比(0-100) + */ + private Long finalSoc; + + /** + * 充放电量(kWh) + */ + private Long energyKwh; + + /** + * 设备额定功率(kW) + */ + private Long powerRating; + + /** + * 电压(V) + */ + private Long voltage; + + /** + * 电流(A) + */ + private Long current; + + /** + * 温度(℃) + */ + private Long temperature; + + /** + * 当前状态 + */ + private Long status; + + /** + * 错误代码 + */ + private String errorCode; + + /** + * 记录创建时间 + */ + private Date createdAt; + + /** + * 记录更新时间 + */ + private Date updatedAt; + + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/dto/InstructionRecordDto.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/dto/InstructionRecordDto.java index 240fc48..42f5c7e 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/dto/InstructionRecordDto.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/dto/InstructionRecordDto.java @@ -20,6 +20,12 @@ public class InstructionRecordDto { * 设备IMEI */ private String deviceImei; + + /** + * content + */ + private String content; + /** * 操作时间-开始时间 */ @@ -29,4 +35,9 @@ public class InstructionRecordDto { * 操作时间-结束时间 */ private String endTime; + + /** + * 分组id + */ + private Long groupId; } diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/query/DeviceQueryCriteria.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/query/DeviceQueryCriteria.java index b9643d6..233230e 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/query/DeviceQueryCriteria.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/query/DeviceQueryCriteria.java @@ -101,16 +101,16 @@ public class DeviceQueryCriteria extends BaseEntity { */ private Boolean isAdmin = false; - /** * 设备所属分组 */ private Long groupId; - /** * 设备地区 */ private String area; + private String content; + } diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/AlarmInformationVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/AlarmInformationVo.java new file mode 100644 index 0000000..09e73b6 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/AlarmInformationVo.java @@ -0,0 +1,44 @@ +package com.fuyuanshen.equipment.domain.vo; + +import lombok.Data; + +/** + * 报警信息 + * + * @author: 默苍璃 + * @date: 2025-09-0114:24 + */ +@Data +public class AlarmInformationVo { + + /** + * 报警总数 + */ + private Integer alarmsTotal = 0; + + /** + * 总处理报警 + */ + private Integer processingAlarm = 0; + + /** + * 强制报警 + */ + private Integer alarmForced = 0; + + /** + * 撞击闯入 + */ + private Integer intrusionImpact = 0; + + /** + * 手动报警 + */ + private Integer alarmManual = 0; + + /** + * 电子围栏 + */ + private Integer fenceElectronic = 0; + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DataOverviewVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DataOverviewVo.java new file mode 100644 index 0000000..c8c016d --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DataOverviewVo.java @@ -0,0 +1,34 @@ +package com.fuyuanshen.equipment.domain.vo; + +import lombok.Data; + +/** + * 数据总览 + * + * @author: 默苍璃 + * @date: 2025-09-0114:24 + */ +@Data +public class DataOverviewVo { + + /** + * 设备数据量 + */ + private Integer devicesNumber = 0; + + /** + * 在线设备 + */ + private Integer equipmentOnline = 0; + + /** + * 新增绑定设备 + */ + private Integer bindingNew = 0; + + /** + * 异常设备 + */ + private Integer equipmentAbnormal = 0; + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DeviceAlarmVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DeviceAlarmVo.java new file mode 100644 index 0000000..4e9935d --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DeviceAlarmVo.java @@ -0,0 +1,137 @@ +package com.fuyuanshen.equipment.domain.vo; + +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fuyuanshen.equipment.domain.DeviceAlarm; +import cn.idev.excel.annotation.ExcelIgnoreUnannotated; +import cn.idev.excel.annotation.ExcelProperty; +import com.fuyuanshen.common.excel.annotation.ExcelDictFormat; +import com.fuyuanshen.common.excel.convert.ExcelDictConvert; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Date; + + +/** + * 设备告警视图对象 device_alarm + * + * @author Lion Li + * @date 2025-08-28 + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = DeviceAlarm.class) +public class DeviceAlarmVo implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @ExcelProperty(value = "ID") + private Long id; + + /** + * 设备ID + */ + @ExcelProperty(value = "设备ID") + private Long deviceId; + + /** + * 报警事项 + * 0-强制报警,1-撞击闯入,2-手动报警,3-电子围栏告警,4-强制告警 + */ + @ExcelProperty(value = "报警事项") + private Integer deviceAction; + + /** + * 设备名称 + */ + @ExcelProperty(value = "设备名称") + private String deviceName; + + /** + * 设备MAC + */ + private String deviceMac; + + /** + * 设备IMEI + */ + private String deviceImei; + + /** + * 数据来源 + */ + @ExcelProperty(value = "数据来源") + private String dataSource; + + /** + * 内容 + */ + @ExcelProperty(value = "内容") + private String content; + + /** + * 设备类型 + */ + @ExcelProperty(value = "设备类型") + private Long deviceType; + private String deviceTypeName; + + /** + * 经度 + */ + @ExcelProperty(value = "经度") + private Long longitude; + + /** + * 纬度 + */ + @ExcelProperty(value = "纬度") + private Long latitude; + + /** + * 报警位置 + */ + @ExcelProperty(value = "报警位置") + private String location; + + /** + * 报警开始时间 + */ + @ExcelProperty(value = "报警开始时间") + private Date startTime; + + /** + * 报警结束时间 + */ + @ExcelProperty(value = "报警结束时间") + private Date finishTime; + + /** + * 报警持续时间 + */ + @ExcelProperty(value = "报警持续时间") + private String durationTime; + + /** + * 0已处理,1未处理 + */ + @ExcelProperty(value = "0已处理,1未处理") + private Integer treatmentState; + + /** + * 设备图片 + * device_pic + */ + @Schema(name = "设备图片") + private String devicePic; + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DeviceChargeDischargeVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DeviceChargeDischargeVo.java new file mode 100644 index 0000000..35e0413 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DeviceChargeDischargeVo.java @@ -0,0 +1,130 @@ +package com.fuyuanshen.equipment.domain.vo; + +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fuyuanshen.equipment.domain.DeviceChargeDischarge; +import cn.idev.excel.annotation.ExcelIgnoreUnannotated; +import cn.idev.excel.annotation.ExcelProperty; +import com.fuyuanshen.common.excel.annotation.ExcelDictFormat; +import com.fuyuanshen.common.excel.convert.ExcelDictConvert; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Date; + + + +/** + * 设备充放电记录视图对象 device_charge_discharge + * + * @author Lion Li + * @date 2025-08-30 + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = DeviceChargeDischarge.class) +public class DeviceChargeDischargeVo implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 记录唯一标识 + */ + @ExcelProperty(value = "记录唯一标识") + private Long id; + + /** + * 设备唯一标识 + */ + @ExcelProperty(value = "设备唯一标识") + private String deviceId; + + /** + * 操作类型: 0 charge-充电, 1 discharge-放电 + */ + @ExcelProperty(value = "操作类型: 0 charge-充电, 1 discharge-放电") + private Long operationType; + + /** + * 开始时间 + */ + @ExcelProperty(value = "开始时间") + private Date startTime; + + /** + * 结束时间 + */ + @ExcelProperty(value = "结束时间") + private Date endTime; + + /** + * 起始电量百分比(0-100) + */ + @ExcelProperty(value = "起始电量百分比(0-100)") + private Long initialSoc; + + /** + * 结束电量百分比(0-100) + */ + @ExcelProperty(value = "结束电量百分比(0-100)") + private Long finalSoc; + + /** + * 充放电量(kWh) + */ + @ExcelProperty(value = "充放电量(kWh)") + private Long energyKwh; + + /** + * 设备额定功率(kW) + */ + @ExcelProperty(value = "设备额定功率(kW)") + private Long powerRating; + + /** + * 电压(V) + */ + @ExcelProperty(value = "电压(V)") + private Long voltage; + + /** + * 电流(A) + */ + @ExcelProperty(value = "电流(A)") + private Long current; + + /** + * 温度(℃) + */ + @ExcelProperty(value = "温度(℃)") + private Long temperature; + + /** + * 当前状态 + */ + @ExcelProperty(value = "当前状态") + private Long status; + + /** + * 错误代码 + */ + @ExcelProperty(value = "错误代码") + private String errorCode; + + /** + * 记录创建时间 + */ + @ExcelProperty(value = "记录创建时间") + private Date createdAt; + + /** + * 记录更新时间 + */ + @ExcelProperty(value = "记录更新时间") + private Date updatedAt; + + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/EquipmentClassificationVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/EquipmentClassificationVo.java new file mode 100644 index 0000000..d84f59a --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/EquipmentClassificationVo.java @@ -0,0 +1,29 @@ +package com.fuyuanshen.equipment.domain.vo; + +import lombok.Data; + +/** + * 设备分类 + * + * @author: 默苍璃 + * @date: 2025-09-0114:24 + */ +@Data +public class EquipmentClassificationVo { + + /** + * 4G设备 + */ + private Integer equipment4G = 0; + + /** + * 蓝牙设备 + */ + private Integer deviceBluetooth = 0; + + /** + * 4G & 蓝牙 设备 + */ + private Integer devices4GAndBluetooth = 0; + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/InstructionRecordVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/InstructionRecordVo.java index 97964ec..9d37e0b 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/InstructionRecordVo.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/InstructionRecordVo.java @@ -1,5 +1,6 @@ package com.fuyuanshen.equipment.domain.vo; +import cn.idev.excel.annotation.ExcelProperty; import lombok.Data; @Data @@ -8,25 +9,31 @@ public class InstructionRecordVo { /** * 设备名称 */ + + @ExcelProperty(value = "设备名称") private String deviceName; /** * 设备类型 */ + @ExcelProperty(value = "设备型号") private String deviceType; /** * 操作模块 */ + @ExcelProperty(value = "操作模块") private String deviceAction; /** * 操作内容 */ + @ExcelProperty(value = "操作内容") private String content; /** * 操作时间 */ + @ExcelProperty(value = "操作时间") private String createTime; } diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/LocationHistoryDetailVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/LocationHistoryDetailVo.java new file mode 100644 index 0000000..3ae7cfb --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/LocationHistoryDetailVo.java @@ -0,0 +1,41 @@ +package com.fuyuanshen.equipment.domain.vo; + +import cn.idev.excel.annotation.ExcelProperty; +import com.alibaba.fastjson2.JSONObject; +import lombok.Data; + +import java.util.List; + +@Data +public class LocationHistoryDetailVo { + + /** + * 日期 + */ + @ExcelProperty(value = "日期") + private String date; + /** + * 设备名称 + */ + @ExcelProperty(value = "设备名称") + private String deviceName; + + /** + * 初始地点 + */ + @ExcelProperty(value = "初始地点") + private String startLocation; + + /** + * 结束地点 + */ + @ExcelProperty(value = "结束地点") + private String endLocation; + + /** + * 轨迹详情 + */ + @ExcelProperty(value = "轨迹详情") + private List detailList; + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/LocationHistoryVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/LocationHistoryVo.java new file mode 100644 index 0000000..702ea3f --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/LocationHistoryVo.java @@ -0,0 +1,39 @@ +package com.fuyuanshen.equipment.domain.vo; + +import cn.idev.excel.annotation.ExcelProperty; +import lombok.Data; + +@Data +public class LocationHistoryVo { + private Long id; + /** + * 设备名称 + */ + + @ExcelProperty(value = "设备名称") + private String deviceName; + + /** + * 设备类型 + */ + private String deviceType; + + /** + * 设备类型 + */ + @ExcelProperty(value = "设备型号") + private String deviceTypeName; + + /** + * 设备IMEI + */ + @ExcelProperty(value = "设备IMEI") + private String deviceImei; + + /** + * 设备MAC + */ + @ExcelProperty(value = "设备MAC") + private String deviceMac; + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/WebDeviceVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/WebDeviceVo.java index 94b20e8..82c3eb1 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/WebDeviceVo.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/WebDeviceVo.java @@ -1,5 +1,6 @@ package com.fuyuanshen.equipment.domain.vo; +import cn.idev.excel.annotation.ExcelProperty; import lombok.Data; import java.io.Serializable; diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceAlarmMapper.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceAlarmMapper.java new file mode 100644 index 0000000..39fbe99 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceAlarmMapper.java @@ -0,0 +1,28 @@ +package com.fuyuanshen.equipment.mapper; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import com.fuyuanshen.equipment.domain.DeviceAlarm; +import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo; +import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo; +import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus; +import org.apache.ibatis.annotations.Param; + +/** + * 设备告警Mapper接口 + * + * @author Lion Li + * @date 2025-08-28 + */ +public interface DeviceAlarmMapper extends BaseMapperPlus { + + + /** + * 查询设备告警列表 + * + * @param bo 设备告警 + * @return 设备告警 + */ + Page selectVoPage( Page pageQuery,@Param("bo") DeviceAlarmBo bo); + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceChargeDischargeMapper.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceChargeDischargeMapper.java new file mode 100644 index 0000000..1c73196 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceChargeDischargeMapper.java @@ -0,0 +1,15 @@ +package com.fuyuanshen.equipment.mapper; + +import com.fuyuanshen.equipment.domain.DeviceChargeDischarge; +import com.fuyuanshen.equipment.domain.vo.DeviceChargeDischargeVo; +import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus; + +/** + * 设备充放电记录Mapper接口 + * + * @author Lion Li + * @date 2025-08-30 + */ +public interface DeviceChargeDischargeMapper extends BaseMapperPlus { + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceMapper.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceMapper.java index e75e1c2..1a38350 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceMapper.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceMapper.java @@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fuyuanshen.equipment.domain.Device; +import com.fuyuanshen.equipment.domain.dto.InstructionRecordDto; import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria; import com.fuyuanshen.equipment.domain.vo.AppDeviceVo; +import com.fuyuanshen.equipment.domain.vo.LocationHistoryVo; import com.fuyuanshen.equipment.domain.vo.WebDeviceVo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -71,4 +73,6 @@ public interface DeviceMapper extends BaseMapper { AppDeviceVo getDeviceInfo(@Param("deviceMac") String deviceMac); Page queryWebDeviceList(Page build,@Param("criteria") DeviceQueryCriteria criteria); + + Page getLocationHistory(Page build, @Param("bo") InstructionRecordDto criteria); } diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/DeviceService.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/DeviceService.java index 22d738d..d2216b6 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/DeviceService.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/DeviceService.java @@ -11,6 +11,7 @@ import com.fuyuanshen.equipment.domain.form.DeviceForm; import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria; import com.fuyuanshen.equipment.domain.vo.AppDeviceVo; import com.fuyuanshen.equipment.domain.vo.CustomerVo; +import com.fuyuanshen.equipment.domain.vo.DataOverviewVo; import java.io.IOException; import java.util.List; @@ -115,4 +116,10 @@ public interface DeviceService extends IService { */ int webUnBindDevice(Long id); + /** + * 获取数据总览 + * + * @return + */ + DataOverviewVo getDataOverview(); } diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceAlarmService.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceAlarmService.java new file mode 100644 index 0000000..c3dc9ff --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceAlarmService.java @@ -0,0 +1,68 @@ +package com.fuyuanshen.equipment.service; + +import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo; +import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; + +import java.util.Collection; +import java.util.List; + +/** + * 设备告警Service接口 + * + * @author Lion Li + * @date 2025-08-28 + */ +public interface IDeviceAlarmService { + + /** + * 查询设备告警 + * + * @param id 主键 + * @return 设备告警 + */ + DeviceAlarmVo queryById(Long id); + + /** + * 分页查询设备告警列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 设备告警分页列表 + */ + TableDataInfo queryPageList(DeviceAlarmBo bo, PageQuery pageQuery); + + /** + * 查询符合条件的设备告警列表 + * + * @param bo 查询条件 + * @return 设备告警列表 + */ + List queryList(DeviceAlarmBo bo); + + /** + * 新增设备告警 + * + * @param bo 设备告警 + * @return 是否新增成功 + */ + Boolean insertByBo(DeviceAlarmBo bo); + + /** + * 修改设备告警 + * + * @param bo 设备告警 + * @return 是否修改成功 + */ + Boolean updateByBo(DeviceAlarmBo bo); + + /** + * 校验并批量删除设备告警信息 + * + * @param ids 待删除的主键集合 + * @param isValid 是否进行有效性校验 + * @return 是否删除成功 + */ + Boolean deleteWithValidByIds(Collection ids, Boolean isValid); +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceChargeDischargeService.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceChargeDischargeService.java new file mode 100644 index 0000000..079a659 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceChargeDischargeService.java @@ -0,0 +1,68 @@ +package com.fuyuanshen.equipment.service; + +import com.fuyuanshen.equipment.domain.vo.DeviceChargeDischargeVo; +import com.fuyuanshen.equipment.domain.bo.DeviceChargeDischargeBo; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; + +import java.util.Collection; +import java.util.List; + +/** + * 设备充放电记录Service接口 + * + * @author Lion Li + * @date 2025-08-30 + */ +public interface IDeviceChargeDischargeService { + + /** + * 查询设备充放电记录 + * + * @param id 主键 + * @return 设备充放电记录 + */ + DeviceChargeDischargeVo queryById(Long id); + + /** + * 分页查询设备充放电记录列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 设备充放电记录分页列表 + */ + TableDataInfo queryPageList(DeviceChargeDischargeBo bo, PageQuery pageQuery); + + /** + * 查询符合条件的设备充放电记录列表 + * + * @param bo 查询条件 + * @return 设备充放电记录列表 + */ + List queryList(DeviceChargeDischargeBo bo); + + /** + * 新增设备充放电记录 + * + * @param bo 设备充放电记录 + * @return 是否新增成功 + */ + Boolean insertByBo(DeviceChargeDischargeBo bo); + + /** + * 修改设备充放电记录 + * + * @param bo 设备充放电记录 + * @return 是否修改成功 + */ + Boolean updateByBo(DeviceChargeDischargeBo bo); + + /** + * 校验并批量删除设备充放电记录信息 + * + * @param ids 待删除的主键集合 + * @param isValid 是否进行有效性校验 + * @return 是否删除成功 + */ + Boolean deleteWithValidByIds(Collection ids, Boolean isValid); +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceGroupService.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceGroupService.java index 3be6a88..2f407aa 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceGroupService.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceGroupService.java @@ -66,5 +66,13 @@ public interface IDeviceGroupService { * @param deviceId 设备id * @return 是否绑定成功 */ - Boolean bindingDevice(@NotEmpty(message = "分组id 不能为空") Long groupId, @NotEmpty(message = "设备id 不能为空") Long[] deviceId); + Boolean bindingDevice(Long groupId, Long[] deviceId); + + /** + * 解绑设备分组 + * + * @param deviceId 设备id + * @return 是否解绑成功 + */ + Boolean groupUnbind( Long[] deviceId); } diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceAlarmServiceImpl.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceAlarmServiceImpl.java new file mode 100644 index 0000000..1bf0671 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceAlarmServiceImpl.java @@ -0,0 +1,148 @@ +package com.fuyuanshen.equipment.service.impl; + +import com.fuyuanshen.common.core.utils.MapstructUtils; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo; +import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo; +import com.fuyuanshen.equipment.domain.DeviceAlarm; +import com.fuyuanshen.equipment.mapper.DeviceAlarmMapper; +import com.fuyuanshen.equipment.service.IDeviceAlarmService; + +import java.util.List; +import java.util.Map; +import java.util.Collection; + +/** + * 设备告警Service业务层处理 + * + * @author Lion Li + * @date 2025-08-28 + */ +@Slf4j +@RequiredArgsConstructor +@Service +public class DeviceAlarmServiceImpl implements IDeviceAlarmService { + + private final DeviceAlarmMapper baseMapper; + + + /** + * 查询设备告警 + * + * @param id 主键 + * @return 设备告警 + */ + @Override + public DeviceAlarmVo queryById(Long id) { + return baseMapper.selectVoById(id); + } + + + /** + * 分页查询设备告警列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 设备告警分页列表 + */ + @Override + public TableDataInfo queryPageList(DeviceAlarmBo bo, PageQuery pageQuery) { + // LambdaQueryWrapper lqw = buildQueryWrapper(bo); + // Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); + Page result = baseMapper.selectVoPage(pageQuery.build(), bo); + return TableDataInfo.build(result); + } + + + /** + * 查询符合条件的设备告警列表 + * + * @param bo 查询条件 + * @return 设备告警列表 + */ + @Override + public List queryList(DeviceAlarmBo bo) { + LambdaQueryWrapper lqw = buildQueryWrapper(bo); + return baseMapper.selectVoList(lqw); + } + + private LambdaQueryWrapper buildQueryWrapper(DeviceAlarmBo bo) { + Map params = bo.getParams(); + LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); + lqw.orderByAsc(DeviceAlarm::getId); + lqw.eq(bo.getDeviceId() != null, DeviceAlarm::getDeviceId, bo.getDeviceId()); + // lqw.eq(StringUtils.isNotBlank(bo.getDeviceAction()), DeviceAlarm::getDeviceAction, bo.getDeviceAction()); + lqw.like(StringUtils.isNotBlank(bo.getDeviceName()), DeviceAlarm::getDeviceName, bo.getDeviceName()); + lqw.eq(StringUtils.isNotBlank(bo.getDataSource()), DeviceAlarm::getDataSource, bo.getDataSource()); + lqw.eq(StringUtils.isNotBlank(bo.getContent()), DeviceAlarm::getContent, bo.getContent()); + lqw.eq(bo.getDeviceType() != null, DeviceAlarm::getDeviceType, bo.getDeviceType()); + lqw.eq(bo.getLongitude() != null, DeviceAlarm::getLongitude, bo.getLongitude()); + lqw.eq(bo.getLatitude() != null, DeviceAlarm::getLatitude, bo.getLatitude()); + lqw.eq(StringUtils.isNotBlank(bo.getLocation()), DeviceAlarm::getLocation, bo.getLocation()); + lqw.eq(bo.getStartTime() != null, DeviceAlarm::getStartTime, bo.getStartTime()); + lqw.eq(bo.getFinishTime() != null, DeviceAlarm::getFinishTime, bo.getFinishTime()); + lqw.eq(bo.getDurationTime() != null, DeviceAlarm::getDurationTime, bo.getDurationTime()); + lqw.eq(bo.getTreatmentState() != null, DeviceAlarm::getTreatmentState, bo.getTreatmentState()); + return lqw; + } + + /** + * 新增设备告警 + * + * @param bo 设备告警 + * @return 是否新增成功 + */ + @Override + public Boolean insertByBo(DeviceAlarmBo bo) { + DeviceAlarm add = MapstructUtils.convert(bo, DeviceAlarm.class); + validEntityBeforeSave(add); + boolean flag = baseMapper.insert(add) > 0; + if (flag) { + bo.setId(add.getId()); + } + return flag; + } + + /** + * 修改设备告警 + * + * @param bo 设备告警 + * @return 是否修改成功 + */ + @Override + public Boolean updateByBo(DeviceAlarmBo bo) { + DeviceAlarm update = MapstructUtils.convert(bo, DeviceAlarm.class); + validEntityBeforeSave(update); + return baseMapper.updateById(update) > 0; + } + + /** + * 保存前的数据校验 + */ + private void validEntityBeforeSave(DeviceAlarm entity) { + // TODO 做一些数据校验,如唯一约束 + } + + /** + * 校验并批量删除设备告警信息 + * + * @param ids 待删除的主键集合 + * @param isValid 是否进行有效性校验 + * @return 是否删除成功 + */ + @Override + public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { + if (isValid) { + // TODO 做一些业务上的校验,判断是否需要校验 + } + return baseMapper.deleteByIds(ids) > 0; + } +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceChargeDischargeServiceImpl.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceChargeDischargeServiceImpl.java new file mode 100644 index 0000000..bcfb9cb --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceChargeDischargeServiceImpl.java @@ -0,0 +1,146 @@ +package com.fuyuanshen.equipment.service.impl; + +import com.fuyuanshen.common.core.utils.MapstructUtils; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import com.fuyuanshen.equipment.domain.bo.DeviceChargeDischargeBo; +import com.fuyuanshen.equipment.domain.vo.DeviceChargeDischargeVo; +import com.fuyuanshen.equipment.domain.DeviceChargeDischarge; +import com.fuyuanshen.equipment.mapper.DeviceChargeDischargeMapper; +import com.fuyuanshen.equipment.service.IDeviceChargeDischargeService; + +import java.util.List; +import java.util.Map; +import java.util.Collection; + +/** + * 设备充放电记录Service业务层处理 + * + * @author Lion Li + * @date 2025-08-30 + */ +@Slf4j +@RequiredArgsConstructor +@Service +public class DeviceChargeDischargeServiceImpl implements IDeviceChargeDischargeService { + + private final DeviceChargeDischargeMapper baseMapper; + + /** + * 查询设备充放电记录 + * + * @param id 主键 + * @return 设备充放电记录 + */ + @Override + public DeviceChargeDischargeVo queryById(Long id){ + return baseMapper.selectVoById(id); + } + + /** + * 分页查询设备充放电记录列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 设备充放电记录分页列表 + */ + @Override + public TableDataInfo queryPageList(DeviceChargeDischargeBo bo, PageQuery pageQuery) { + LambdaQueryWrapper lqw = buildQueryWrapper(bo); + Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); + return TableDataInfo.build(result); + } + + /** + * 查询符合条件的设备充放电记录列表 + * + * @param bo 查询条件 + * @return 设备充放电记录列表 + */ + @Override + public List queryList(DeviceChargeDischargeBo bo) { + LambdaQueryWrapper lqw = buildQueryWrapper(bo); + return baseMapper.selectVoList(lqw); + } + + private LambdaQueryWrapper buildQueryWrapper(DeviceChargeDischargeBo bo) { + Map params = bo.getParams(); + LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); + lqw.orderByAsc(DeviceChargeDischarge::getId); + lqw.eq(StringUtils.isNotBlank(bo.getDeviceId()), DeviceChargeDischarge::getDeviceId, bo.getDeviceId()); + lqw.eq(bo.getOperationType() != null, DeviceChargeDischarge::getOperationType, bo.getOperationType()); + lqw.eq(bo.getStartTime() != null, DeviceChargeDischarge::getStartTime, bo.getStartTime()); + lqw.eq(bo.getEndTime() != null, DeviceChargeDischarge::getEndTime, bo.getEndTime()); + lqw.eq(bo.getInitialSoc() != null, DeviceChargeDischarge::getInitialSoc, bo.getInitialSoc()); + lqw.eq(bo.getFinalSoc() != null, DeviceChargeDischarge::getFinalSoc, bo.getFinalSoc()); + lqw.eq(bo.getEnergyKwh() != null, DeviceChargeDischarge::getEnergyKwh, bo.getEnergyKwh()); + lqw.eq(bo.getPowerRating() != null, DeviceChargeDischarge::getPowerRating, bo.getPowerRating()); + lqw.eq(bo.getVoltage() != null, DeviceChargeDischarge::getVoltage, bo.getVoltage()); + lqw.eq(bo.getCurrent() != null, DeviceChargeDischarge::getCurrent, bo.getCurrent()); + lqw.eq(bo.getTemperature() != null, DeviceChargeDischarge::getTemperature, bo.getTemperature()); + lqw.eq(bo.getStatus() != null, DeviceChargeDischarge::getStatus, bo.getStatus()); + lqw.eq(StringUtils.isNotBlank(bo.getErrorCode()), DeviceChargeDischarge::getErrorCode, bo.getErrorCode()); + lqw.eq(bo.getCreatedAt() != null, DeviceChargeDischarge::getCreatedAt, bo.getCreatedAt()); + lqw.eq(bo.getUpdatedAt() != null, DeviceChargeDischarge::getUpdatedAt, bo.getUpdatedAt()); + return lqw; + } + + /** + * 新增设备充放电记录 + * + * @param bo 设备充放电记录 + * @return 是否新增成功 + */ + @Override + public Boolean insertByBo(DeviceChargeDischargeBo bo) { + DeviceChargeDischarge add = MapstructUtils.convert(bo, DeviceChargeDischarge.class); + validEntityBeforeSave(add); + boolean flag = baseMapper.insert(add) > 0; + if (flag) { + bo.setId(add.getId()); + } + return flag; + } + + /** + * 修改设备充放电记录 + * + * @param bo 设备充放电记录 + * @return 是否修改成功 + */ + @Override + public Boolean updateByBo(DeviceChargeDischargeBo bo) { + DeviceChargeDischarge update = MapstructUtils.convert(bo, DeviceChargeDischarge.class); + validEntityBeforeSave(update); + return baseMapper.updateById(update) > 0; + } + + /** + * 保存前的数据校验 + */ + private void validEntityBeforeSave(DeviceChargeDischarge entity){ + //TODO 做一些数据校验,如唯一约束 + } + + /** + * 校验并批量删除设备充放电记录信息 + * + * @param ids 待删除的主键集合 + * @param isValid 是否进行有效性校验 + * @return 是否删除成功 + */ + @Override + public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { + if(isValid){ + //TODO 做一些业务上的校验,判断是否需要校验 + } + return baseMapper.deleteByIds(ids) > 0; + } +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceGroupServiceImpl.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceGroupServiceImpl.java index ecf9a82..bb02c2c 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceGroupServiceImpl.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceGroupServiceImpl.java @@ -92,6 +92,7 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService { vo.setId(group.getId()); vo.setGroupName(group.getGroupName()); vo.setStatus(group.getStatus() == 1 ? "正常" : "禁用"); + vo.setParentId(group.getParentId()); vo.setCreateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(group.getCreateTime())); return vo; } @@ -124,10 +125,12 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService { throw new RuntimeException("分组名称已存在,请勿重复添加!!!"); } - // 验证父分组是否存在(如果提供了parentId) - DeviceGroup pDeviceGroup = baseMapper.selectById(bo.getParentId()); - if (bo.getParentId() != null && pDeviceGroup == null) { - throw new RuntimeException("父分组不存在!!!"); + if (bo.getParentId() != null) { + // 验证父分组是否存在(如果提供了parentId) + DeviceGroup pDeviceGroup = baseMapper.selectById(bo.getParentId()); + if (bo.getParentId() != null && pDeviceGroup == null) { + throw new RuntimeException("父分组不存在!!!"); + } } DeviceGroup add = MapstructUtils.convert(bo, DeviceGroup.class); @@ -199,4 +202,27 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService { return true; } + + /** + * 解绑设备分组 + * + * @param deviceId 设备id + * @return 是否解绑成功 + */ + @Override + public Boolean groupUnbind( Long[] deviceId) { + + if (deviceId != null && deviceId.length > 0) { + // 创建更新条件 + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.in("id", Arrays.asList(deviceId)); + updateWrapper.set("group_id", null); + + // 执行批量更新 + deviceMapper.update(updateWrapper); + } + + return true; + } + } diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceServiceImpl.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceServiceImpl.java index 357a82d..2de40b4 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceServiceImpl.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceServiceImpl.java @@ -30,6 +30,7 @@ import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria; import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria; import com.fuyuanshen.equipment.domain.vo.AppDeviceVo; import com.fuyuanshen.equipment.domain.vo.CustomerVo; +import com.fuyuanshen.equipment.domain.vo.DataOverviewVo; import com.fuyuanshen.equipment.enums.BindingStatusEnum; import com.fuyuanshen.equipment.enums.CommunicationModeEnum; import com.fuyuanshen.equipment.enums.DeviceActiveStatusEnum; @@ -595,6 +596,8 @@ public class DeviceServiceImpl extends ServiceImpl impleme } + + /** * 查询设备MAC号 * @@ -613,4 +616,14 @@ public class DeviceServiceImpl extends ServiceImpl impleme } + /** + * 获取数据总览 + * + * @return + */ + @Override + public DataOverviewVo getDataOverview() { + return null; + } + } diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceTypeServiceImpl.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceTypeServiceImpl.java index cdeaacd..d3cb540 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceTypeServiceImpl.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceTypeServiceImpl.java @@ -157,11 +157,11 @@ public class DeviceTypeServiceImpl extends ServiceImpl devices = deviceMapper.selectList(new QueryWrapper() - .eq("device_type", deviceTypeGrants.getDeviceTypeId())); - if (CollectionUtil.isNotEmpty(devices)) { - throw new RuntimeException("该设备类型已绑定设备,无法修改!!!"); - } + // List devices = deviceMapper.selectList(new QueryWrapper() + // .eq("device_type", deviceTypeGrants.getDeviceTypeId())); + // if (CollectionUtil.isNotEmpty(devices)) { + // throw new RuntimeException("该设备类型已绑定设备,无法修改!!!"); + // } // 校验设备类型名称 DeviceType dt = deviceTypeMapper.selectOne(new QueryWrapper().eq("type_name", resources.getTypeName())); diff --git a/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceAlarmMapper.xml b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceAlarmMapper.xml new file mode 100644 index 0000000..cdb76f8 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceAlarmMapper.xml @@ -0,0 +1,33 @@ + + + + + + + + diff --git a/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceChargeDischargeMapper.xml b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceChargeDischargeMapper.xml new file mode 100644 index 0000000..5d60dc4 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceChargeDischargeMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceLogMapper.xml b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceLogMapper.xml index d15eeb8..e0946b8 100644 --- a/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceLogMapper.xml +++ b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceLogMapper.xml @@ -28,11 +28,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND b.device_imei = #{bo.deviceImei} + + AND b.device_imei = #{bo.content} or b.device_mac = #{bo.content} + - AND create_time =]]> #{bo.startTime} + AND a.create_time =]]> #{bo.startTime} - AND create_time #{bo.startTime} + AND a.create_time #{bo.endTime} + + + and b.group_id = #{bo.groupId} ORDER BY a.create_time DESC diff --git a/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceMapper.xml b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceMapper.xml index 7e4423c..20b385c 100644 --- a/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceMapper.xml +++ b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceMapper.xml @@ -41,7 +41,7 @@ SELECT * FROM ( SELECT - da.id AS id, d.device_name, d.bluetooth_name, + da.id AS id, d.id AS deviceId, d.device_name, d.bluetooth_name, d.group_id, d.pub_topic, d.sub_topic, d.device_pic, d.device_mac, d.device_sn, d.update_by, d.device_imei, d.update_time, dg.id AS device_type, @@ -71,6 +71,9 @@ and da.active = #{criteria.deviceStatus} + + and d.group_id = #{criteria.groupId} + and da.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime} @@ -257,11 +260,11 @@ and d.device_name like concat('%', #{criteria.deviceName}, '%') - - and d.device_mac = #{criteria.deviceMac} + + and (d.device_imei = #{criteria.deviceImei} - - and d.device_imei = #{criteria.deviceImei} + + AND d.device_imei = #{criteria.content} or d.device_mac = #{criteria.content} and d.device_status = #{criteria.deviceStatus} @@ -276,5 +279,36 @@ and d.group_id = #{criteria.groupId} + \ No newline at end of file diff --git a/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceTypeMapper.xml b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceTypeMapper.xml index 624c395..cdfbbca 100644 --- a/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceTypeMapper.xml +++ b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceTypeMapper.xml @@ -4,6 +4,7 @@ + @@ -21,7 +22,7 @@ -