53 Commits

Author SHA1 Message Date
88650c3d9f 代码优化 2026-01-14 18:36:23 +08:00
dyf
ca11ef0e35 Merge pull request 'feat(equipment): 添加设备图片上传功能' (#22) from liwenlong/fys-Multi-tenant:jingquan into jingquan
Reviewed-on: dyf/fys-Multi-tenant#22
2026-01-12 11:15:56 +08:00
ef2dc6a6f6 feat(equipment): 添加设备图片上传功能
- 在DeviceType实体类中新增devicePic字段用于存储设备图片
- 修改控制器方法参数从RequestBody改为ModelAttribute以支持文件上传
- 更新DeviceTypeForm表单类添加MultipartFile类型的file字段
- 实现图片上传服务集成OSS存储和文件哈希处理
- 添加HTTP到HTTPS的URL强制转换机制
- 更新数据库操作逻辑以支持图片路径存储
- 在设备创建流程中集成设备类型图片信息传递
2026-01-12 11:06:44 +08:00
dff37b245a Merge branch 'dyf-device' into 6170 2025-12-26 16:22:00 +08:00
d7c4d22de3 该设备类型下已有设备,无法修改设备类型名称!!! 2025-12-26 16:21:33 +08:00
6a058318f2 设备记录列表显示问题修改 2025-12-26 15:54:14 +08:00
f2d74b8f17 Merge branch 'dyf-device' into 6170 2025-12-22 15:09:39 +08:00
af42a2199c 根据用户ID查询菜单 2025-12-22 15:09:07 +08:00
aaf142ca67 提交 2025-12-19 17:55:48 +08:00
c0dfe36b59 cn.idev.excel 2025-12-19 16:21:56 +08:00
c480bda112 围栏进出记录 2025-12-19 14:06:01 +08:00
8c636d0484 设备维修记录 2025-12-12 14:55:03 +08:00
0c474ae1f3 维修时间 2025-12-11 15:24:46 +08:00
b85664900e 分页查询围栏进出记录列表 2025-12-10 09:39:00 +08:00
dyf
035b24fedd Merge pull request 'feat(equipment): 新增高德轨迹服务相关功能与设备终端管理' (#21) from liwenlong/fys-Multi-tenant:jingquan into jingquan
Reviewed-on: dyf/fys-Multi-tenant#21
2025-12-03 16:52:09 +08:00
e920cfb860 feat(equipment): 新增高德轨迹服务相关功能与设备终端管理
- 新增 AmapTrackUtil 工具类,封装高德猎鹰轨迹服务 API 调用
- 在 Device 实体中增加高德服务、终端、轨迹 ID 字段(sid, tid, trid)
- 新增设备终端分页查询接口 /pageTerminal 及对应实现
- 新增围栏与设备关联实体 DeviceFenceTerminal 及 Mapper
- 扩展 DeviceGeoFence 相关注入高德服务及围栏 ID 字段
- 新增添加/删除围栏终端绑定接口及业务逻辑
- 新增轨迹服务模块(TrackService)包括 Controller、Service、BO、DTO 等完整结构
- 在 DeviceMapper.xml 中补充终端相关字段查询及筛选条件
- 新增 TerminalDeviceBo、TerminalDelBo、TerminalQueryBo 等数据传输对象
- 补充设备查询条件支持高德终端状态及服务 ID 过滤
- 新增围栏终端关联表 device_fence_terminal 并注册至菜单配置
- 完善设备分配逻辑以兼容角色权限判断及终端信息展示
2025-12-03 11:39:18 +08:00
b33ee00dbd APP文件上传 2025-12-01 10:34:41 +08:00
c8f9cc4f31 Merge branch 'dyf-device' into 6170 2025-11-28 10:17:42 +08:00
26d2f05c4e 绑定状态 2025-11-28 10:13:26 +08:00
d57d17dc50 登录提示去掉 2025-11-28 09:15:35 +08:00
20ddbf6e05 app注销删除相关联数据2 2025-11-27 11:16:07 +08:00
63a9d2f8f9 导出图片压缩 2025-11-27 11:00:34 +08:00
7753444f25 Merge branch 'dyf-device' into jingquan
# Conflicts:
#	fys-admin/src/main/java/com/fuyuanshen/app/controller/AppVideoController.java
2025-11-25 14:52:10 +08:00
bf182ebc89 强制将HTTP替换为HTTPS 2025-11-25 14:51:10 +08:00
dyf
d5a29feca3 Merge pull request 'jingquan' (#20) from liwenlong/fys-Multi-tenant:jingquan into jingquan
Reviewed-on: dyf/fys-Multi-tenant#20
2025-11-25 14:47:00 +08:00
0457877c09 merge upstream 2025-11-24 08:30:34 +08:00
1e9e815314 uploadVideo 2025-11-21 16:24:07 +08:00
b18ab98feb 导出设备数据 2025-11-21 13:36:13 +08:00
7c6f3be844 merge upstream 2025-11-20 16:25:33 +08:00
aa69b552aa Merge remote-tracking branch 'liwenlong-fys/jingquan' into jingquan 2025-11-20 16:25:04 +08:00
3dd0d4cc90 feat(video): 支持BGR565格式视频处理及MQTT设备确认消息更新
- 新增BGR565格式转换逻辑,支持RGB565与BGR565两种颜色格式- 视频上传接口增加code参数,默认值为1(RGB565)
- 在VideoProcessUtil中实现convertFramesToBGR565方法
- 添加bgr565ToMp4工具方法用于将BGR565数据编码为MP4文件
- MQTT规则新增对“设备已收到通知”的处理逻辑
- 设备确认消息后更新数据库日志状态并推送SSE消息
- 引入ScheduledExecutorService延时推送SSE消息- 增加设备日志和设备Mapper依赖以支持数据操作
2025-11-20 16:24:45 +08:00
00a4394b43 新增设备 2025-11-20 16:15:15 +08:00
2376a3b42a 修改设备类型 2025-11-20 10:11:14 +08:00
359cabbd2c feat(video): 支持BGR565格式视频处理- 新增code参数用于指定视频转码格式
- 实现BGR565格式的帧数据转换逻辑
- 添加convertFramesToBGR565和convertToBGR565方法
- 支持将BGR565数据通过FFmpeg生成MP4文件- 更新VideoProcessUtil工具类以支持两种颜色格式
- 在视频处理服务中记录处理日志及hex列表信息
2025-11-20 09:06:05 +08:00
76c11fff15 Merge remote-tracking branch 'upstream/6170' into 6170 2025-11-19 17:17:40 +08:00
a0ab5e9fe0 app注销删除相关联数据 2025-11-19 17:17:34 +08:00
891ee7c1c9 Merge branch 'dyf-device' into 6170 2025-11-19 10:56:12 +08:00
a145c372b8 优化设备导出 2025-11-19 10:55:44 +08:00
3798e52ee0 导入设备数据 2025-11-18 15:34:46 +08:00
6488b8a724 Merge branch 'dyf-device' into 6170 2025-11-12 11:25:55 +08:00
6d58268874 根据新增业务对象插入设备语音 2025-11-11 15:10:15 +08:00
88b54a49f4 Merge branch 'dyf-device' into 6170
# Conflicts:
#	fys-admin/src/main/resources/application-prod.yml
2025-11-11 14:34:19 +08:00
56dbfbde71 prod 2025-11-11 14:33:10 +08:00
dce043f63d Merge branch 'dyf-device' into 6170 2025-11-11 10:51:57 +08:00
77626673e9 设备语音 2025-11-11 10:51:28 +08:00
759c72fc65 Merge branch 'dyf-device' into 6170 2025-11-10 10:37:43 +08:00
1be80be309 灯光模式 5 2025-11-10 10:37:03 +08:00
92df1c8668 Merge branch 'dyf-device' of http://47.107.152.87:3000/dyf/fys-Multi-tenant into dyf-device 2025-11-08 09:48:18 +08:00
cc2b7664a8 处理MQTT消息 2025-11-08 09:48:12 +08:00
33d6108172 处理MQTT消息 2025-11-08 09:38:19 +08:00
70c416779f Merge branch 'dyf-device' into 6170 2025-11-07 17:11:45 +08:00
f4369f7581 分享设备bug修改 2025-10-30 14:27:01 +08:00
df28eed305 prod配置文件 2025-10-28 10:51:05 +08:00
136 changed files with 6366 additions and 577 deletions

View File

@ -0,0 +1,64 @@
package com.fuyuanshen;
import com.fuyuanshen.equipment.utils.AlibabaTTSUtil;
import com.fuyuanshen.equipment.utils.AudioProcessUtil;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author: 默苍璃
* @date: 2025-12-1518:51
*/
public class Text {
public static void main(String[] args) throws IOException {
String text = "简述人生观的主要内容。\n" +
"人生观的主要内容包括以下三个方面:\n" +
"1.人生目的:回答“人为什么活着”的根本问题。它规定了人生的方向,是人生观的核心。\n" +
"2.人生态度:回答“人应该怎样活着”的问题。它是指人们通过生活实践形成的对人生问题的一种稳定的心理倾向和基本意图。\n" +
"3.人生价值:回答“什么样的人生才有意义”的问题。它是指人的生命及其实践活动对于社会和个人所具有的作用和意义。\n" +
"人生目的、人生态度和人生价值相互联系、相辅相成,共同构成一个有机整体。\n" +
"人生目的是人生观的核心,它决定人生态度和人生价值的方向;人生态度影响人生目的的实现和人生价值的创造;人生价值是衡量人生观正确与否的尺度。";
AlibabaTTSUtil alibabaTTSUtil = new AlibabaTTSUtil();
AudioProcessUtil audioProcessUtil = new AudioProcessUtil();
byte[] rawPcmData = alibabaTTSUtil.generateStandardPcmData(text);
// 使用AudioProcessUtil转换成带头44字节 PCM
byte[] pcmData = audioProcessUtil.rawPcmToStandardWav(rawPcmData);
// String savedPath = audioProcessUtil.saveWavToFile(pcmData, "test_output.wav");
// if (savedPath != null) {
// log.info("测试文件已保存: {}", savedPath);
// }
// 保存WAV文件到本地
String savedPath = saveByteArrayToFile(pcmData, "人生观.wav");
if (savedPath != null) {
System.out.println("WAV文件已保存: " + savedPath);
}
}
private static String saveByteArrayToFile(byte[] data, String filename) throws IOException {
// 确定保存路径(可以是临时目录或指定目录)
String directory = System.getProperty("java.io.tmpdir"); // 使用系统临时目录
File dir = new File(directory);
if (!dir.exists()) {
dir.mkdirs();
}
// 创建完整文件路径
File file = new File(dir, filename);
// 写入文件
try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(data);
}
return file.getAbsolutePath();
}
}

View File

@ -11,6 +11,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -39,7 +40,7 @@ public class AppFileController extends BaseController {
* 上传文件 * 上传文件
*/ */
@PostMapping("/upload") @PostMapping("/upload")
public R<Void> upload(@Validated @ModelAttribute AppFileDto bo) { public R<Void> upload(@Validated @ModelAttribute AppFileDto bo) throws IOException {
return toAjax(appFileService.add(bo)); return toAjax(appFileService.add(bo));
} }

View File

@ -29,10 +29,13 @@ public class AppVideoController extends BaseController {
private final VideoProcessService videoProcessService; private final VideoProcessService videoProcessService;
private final AudioProcessService audioProcessService; private final AudioProcessService audioProcessService;
/**
* 上传视频转码code默认1RGB565 2BGR565
*/
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!") @RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
public R<List<String>> uploadVideo(@RequestParam("file") MultipartFile file) { public R<List<String>> uploadVideo(@RequestParam("file") MultipartFile file, @RequestParam(defaultValue = "1") int code) {
return R.ok(videoProcessService.processVideo(file)); return R.ok(videoProcessService.processVideo(file, code));
} }
/** /**
@ -61,4 +64,5 @@ public class AppVideoController extends BaseController {
public R<String> extract(@RequestParam("file") MultipartFile file) throws Exception { public R<String> extract(@RequestParam("file") MultipartFile file) throws Exception {
return R.ok("Success",audioProcessService.extract(file)); return R.ok("Success",audioProcessService.extract(file));
} }
} }

View File

@ -31,6 +31,7 @@ public class AppDeviceBJQController extends BaseController {
private final DeviceBJQBizService appDeviceService; private final DeviceBJQBizService appDeviceService;
/** /**
* 获取设备详细信息 * 获取设备详细信息
* *
@ -86,7 +87,6 @@ public class AppDeviceBJQController extends BaseController {
} }
/** /**
* 灯光模式 * 灯光模式
* 0关灯1强光模式2弱光模式, 3爆闪模式, 4泛光模式 * 0关灯1强光模式2弱光模式, 3爆闪模式, 4泛光模式

View File

@ -28,6 +28,7 @@ public class AppDeviceHBYController extends BaseController {
private final DeviceBJQBizService appDeviceService; private final DeviceBJQBizService appDeviceService;
/** /**
* 获取设备详细信息 * 获取设备详细信息
* *

View File

@ -38,6 +38,8 @@ public class AppDeviceXinghanController extends BaseController {
private final DeviceXinghanBizService appDeviceService; private final DeviceXinghanBizService appDeviceService;
private final DeviceService deviceService; private final DeviceService deviceService;
/** /**
* 人员信息登记 * 人员信息登记
*/ */
@ -67,7 +69,7 @@ public class AppDeviceXinghanController extends BaseController {
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) { public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
MultipartFile file = bo.getFile(); MultipartFile file = bo.getFile();
if(file.getSize()>1024*1024*2){ if (file.getSize() > 1024 * 1024 * 2) {
return R.warn("图片不能大于2M"); return R.warn("图片不能大于2M");
} }
appDeviceService.uploadDeviceLogo(bo); appDeviceService.uploadDeviceLogo(bo);
@ -125,7 +127,7 @@ public class AppDeviceXinghanController extends BaseController {
@GetMapping(value = "/typeAll") @GetMapping(value = "/typeAll")
@Operation(summary = "查询所有设备类型") @Operation(summary = "查询所有设备类型")
public R<List<DeviceType>> queryDeviceTypes() { public R<List<DeviceType>> queryDeviceTypes() {
List<DeviceType> deviceTypes = appDeviceService.queryDeviceTypes(); List<DeviceType> deviceTypes = appDeviceService.queryDeviceTypes();
return R.ok(deviceTypes); return R.ok(deviceTypes);
} }

View File

@ -11,7 +11,6 @@ import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation
import com.fuyuanshen.common.web.core.BaseController; import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo; import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService; import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService;
import com.fuyuanshen.web.service.device.DeviceBJQBizService;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -27,7 +26,6 @@ import org.springframework.web.multipart.MultipartFile;
@RequestMapping("/app/bjq6075/device") @RequestMapping("/app/bjq6075/device")
public class AppDeviceBJQ6075Controller extends BaseController { public class AppDeviceBJQ6075Controller extends BaseController {
private final DeviceBJQBizService appDeviceService;
private final DeviceBJQ6075BizService appDeviceService6075; private final DeviceBJQ6075BizService appDeviceService6075;
@ -44,33 +42,36 @@ public class AppDeviceBJQ6075Controller extends BaseController {
/** /**
* 人员信息登记 * 人员信息登记 1
*/ */
@PostMapping(value = "/registerPersonInfo") @PostMapping(value = "/registerPersonInfo")
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) { public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
return toAjax(appDeviceService.registerPersonInfo(bo)); return toAjax(appDeviceService6075.registerPersonInfo(bo));
} }
/** /**
* 发送信息 * 发送信息 2
*/ */
@PostMapping(value = "/sendMessage") @PostMapping(value = "/sendMessage")
@FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40) @FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) { public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService.sendMessage(bo)); return toAjax(appDeviceService6075.sendMessage(bo));
} }
/** /**
* 发送报警信息 * 发送报警信息 3
*/ */
@PostMapping(value = "/sendAlarmMessage") @PostMapping(value = "/sendAlarmMessage")
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10) @FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) { public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService.sendAlarmMessage(bo)); return toAjax(appDeviceService6075.sendAlarmMessage(bo));
} }
/** /**
* 上传设备logo图片 * 上传设备logo图片 4
*/ */
@PostMapping("/uploadLogo") @PostMapping("/uploadLogo")
@FunctionAccessAnnotation("uploadLogo") @FunctionAccessAnnotation("uploadLogo")
@ -80,61 +81,62 @@ public class AppDeviceBJQ6075Controller extends BaseController {
if (file.getSize() > 1024 * 1024 * 2) { if (file.getSize() > 1024 * 1024 * 2) {
return R.warn("图片不能大于2M"); return R.warn("图片不能大于2M");
} }
appDeviceService.uploadDeviceLogo(bo); appDeviceService6075.uploadDeviceLogo(bo);
return R.ok(); return R.ok();
} }
/** /**
* 灯光模式 * 灯光模式 5
* (主光模式) * (主光模式)
* 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS * 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS
*/ */
@PostMapping("/lightModeSettings") @PostMapping("/lightModeSettings")
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) { public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.lightModeSettings(params); appDeviceService6075.lightModeSettings(params);
return R.ok(); return R.ok();
} }
/** /**
* 灯光模式 * 灯光模式 6
* (辅光模式) * (辅光模式)
* 0关闭灯光1泛光2泛光爆闪, 3警示灯, 4警示灯/泛光) * 0关闭灯光1泛光2泛光爆闪, 3警示灯, 4警示灯/泛光)
*/ */
@PostMapping("/auxiliaryLightModeSettings") @PostMapping("/auxiliaryLightModeSettings")
public R<Void> auxiliaryLightModeSettings(@RequestBody DeviceInstructDto params) { public R<Void> auxiliaryLightModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.lightModeSettings(params); appDeviceService6075.lightModeSettings(params);
return R.ok(); return R.ok();
} }
/** /**
* 灯光亮度设置 * 灯光亮度设置 7
*/ */
@PostMapping("/lightBrightnessSettings") @PostMapping("/lightBrightnessSettings")
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) { public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.lightBrightnessSettings(params); appDeviceService6075.lightBrightnessSettings(params);
return R.ok(); return R.ok();
} }
/** /**
* 激光模式设置 * 激光模式设置 8
*/ */
@PostMapping("/laserModeSettings") @PostMapping("/laserModeSettings")
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) { public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.laserModeSettings(params); appDeviceService6075.laserModeSettings(params);
return R.ok(); return R.ok();
} }
/** /**
* 声光报警模式设置 * 声光报警模式设置 9
* Sound and light alarm * Sound and light alarm
*/ */
@PostMapping("/salaModeSettings") @PostMapping("/salaModeSettings")
public R<Void> salaModeSettings(@RequestBody DeviceInstructDto params) { public R<Void> salaModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.laserModeSettings(params); appDeviceService6075.laserModeSettings(params);
return R.ok(); return R.ok();
} }
@ -146,7 +148,7 @@ public class AppDeviceBJQ6075Controller extends BaseController {
*/ */
@GetMapping("/getShareInfo/{id}") @GetMapping("/getShareInfo/{id}")
public R<AppDevice6075DetailVo> getShareInfo(@NotNull(message = "主键不能为空") public R<AppDevice6075DetailVo> getShareInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) { @PathVariable Long id) {
return R.ok(appDeviceService6075.getInfo(id)); return R.ok(appDeviceService6075.getInfo(id));
} }

View File

@ -0,0 +1,155 @@
package com.fuyuanshen.app.controller.device.bjq;
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
import com.fuyuanshen.app.domain.vo.AppDevice6075DetailVo;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
* BJQ6331便携式工作灯
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/BJQ6331/device")
public class AppDeviceBJQ6331Controller extends BaseController {
private final DeviceBJQ6075BizService appDeviceService6075;
/**
* 获取设备详细信息
*
* @param id 主键
*/
@GetMapping("/{id}")
public R<AppDevice6075DetailVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
return R.ok(appDeviceService6075.getInfo(id));
}
/**
* 人员信息登记 1
*/
@PostMapping(value = "/registerPersonInfo")
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
return toAjax(appDeviceService6075.registerPersonInfo(bo));
}
/**
* 发送信息 2
*/
@PostMapping(value = "/sendMessage")
@FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService6075.sendMessage(bo));
}
/**
* 发送报警信息 3
*/
@PostMapping(value = "/sendAlarmMessage")
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService6075.sendAlarmMessage(bo));
}
/**
* 上传设备logo图片 4
*/
@PostMapping("/uploadLogo")
@FunctionAccessAnnotation("uploadLogo")
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
MultipartFile file = bo.getFile();
if (file.getSize() > 1024 * 1024 * 2) {
return R.warn("图片不能大于2M");
}
appDeviceService6075.uploadDeviceLogo(bo);
return R.ok();
}
/**
* 灯光模式 5
* (主光模式)
* 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS
*/
@PostMapping("/lightModeSettings")
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService6075.lightModeSettings(params);
return R.ok();
}
/**
* 灯光模式 6
* (辅光模式)
* 0关闭灯光1泛光2泛光爆闪, 3警示灯, 4警示灯/泛光)
*/
@PostMapping("/auxiliaryLightModeSettings")
public R<Void> auxiliaryLightModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService6075.lightModeSettings(params);
return R.ok();
}
/**
* 灯光亮度设置 7
*/
@PostMapping("/lightBrightnessSettings")
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
appDeviceService6075.lightBrightnessSettings(params);
return R.ok();
}
/**
* 激光模式设置 8
*/
@PostMapping("/laserModeSettings")
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService6075.laserModeSettings(params);
return R.ok();
}
/**
* 声光报警模式设置 9
* Sound and light alarm
*/
@PostMapping("/salaModeSettings")
public R<Void> salaModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService6075.laserModeSettings(params);
return R.ok();
}
/**
* 获取设备分享详细信息
*
* @param id 主键
*/
@GetMapping("/getShareInfo/{id}")
public R<AppDevice6075DetailVo> getShareInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(appDeviceService6075.getInfo(id));
}
}

View File

@ -0,0 +1,156 @@
package com.fuyuanshen.app.controller.device.bjq;
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
import com.fuyuanshen.app.domain.vo.AppDevice6075DetailVo;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
* HBY335LED救生照明线
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/HBY335/device")
public class AppDeviceHBY335Controller extends BaseController {
private final DeviceBJQ6075BizService appDeviceService6075;
/**
* 获取设备详细信息
*
* @param id 主键
*/
@GetMapping("/{id}")
public R<AppDevice6075DetailVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(appDeviceService6075.getInfo(id));
}
/**
* 人员信息登记 1
*/
@PostMapping(value = "/registerPersonInfo")
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
return toAjax(appDeviceService6075.registerPersonInfo(bo));
}
/**
* 发送信息 2
*/
@PostMapping(value = "/sendMessage")
@FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService6075.sendMessage(bo));
}
/**
* 发送报警信息 3
*/
@PostMapping(value = "/sendAlarmMessage")
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService6075.sendAlarmMessage(bo));
}
/**
* 上传设备logo图片 4
*/
@PostMapping("/uploadLogo")
@FunctionAccessAnnotation("uploadLogo")
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
MultipartFile file = bo.getFile();
if (file.getSize() > 1024 * 1024 * 2) {
return R.warn("图片不能大于2M");
}
appDeviceService6075.uploadDeviceLogo(bo);
return R.ok();
}
/**
* 灯光模式 5
* (主光模式)
* 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS
*/
@PostMapping("/lightModeSettings")
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService6075.lightModeSettings(params);
return R.ok();
}
/**
* 灯光模式 6
* (辅光模式)
* 0关闭灯光1泛光2泛光爆闪, 3警示灯, 4警示灯/泛光)
*/
@PostMapping("/auxiliaryLightModeSettings")
public R<Void> auxiliaryLightModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService6075.lightModeSettings(params);
return R.ok();
}
/**
* 灯光亮度设置 7
*/
@PostMapping("/lightBrightnessSettings")
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
appDeviceService6075.lightBrightnessSettings(params);
return R.ok();
}
/**
* 激光模式设置 8
*/
@PostMapping("/laserModeSettings")
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService6075.laserModeSettings(params);
return R.ok();
}
/**
* 声光报警模式设置 9
* Sound and light alarm
*/
@PostMapping("/salaModeSettings")
public R<Void> salaModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService6075.laserModeSettings(params);
return R.ok();
}
/**
* 获取设备分享详细信息
*
* @param id 主键
*/
@GetMapping("/getShareInfo/{id}")
public R<AppDevice6075DetailVo> getShareInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(appDeviceService6075.getInfo(id));
}
}

View File

@ -216,6 +216,7 @@ public class AppDeviceShareService {
uw.eq("phonenumber", bo.getPhonenumber()); uw.eq("phonenumber", bo.getPhonenumber());
uw.set("permission", bo.getPermission()); uw.set("permission", bo.getPermission());
uw.set("update_by", userId); uw.set("update_by", userId);
uw.set("create_by", userId);
uw.set("update_time", new Date()); uw.set("update_time", new Date());
return appDeviceShareMapper.update(uw); return appDeviceShareMapper.update(uw);
@ -226,7 +227,7 @@ public class AppDeviceShareService {
appDeviceShare.setPermission(bo.getPermission()); appDeviceShare.setPermission(bo.getPermission());
appDeviceShare.setCreateBy(userId); appDeviceShare.setCreateBy(userId);
return appDeviceShareMapper.insert(appDeviceShare); return appDeviceShareMapper.insert(appDeviceShare);
} }
} }
public int remove(Long[] ids) { public int remove(Long[] ids) {

View File

@ -8,6 +8,7 @@ import com.fuyuanshen.common.core.exception.ServiceException;
import com.fuyuanshen.common.oss.core.OssClient; import com.fuyuanshen.common.oss.core.OssClient;
import com.fuyuanshen.common.oss.factory.OssFactory; import com.fuyuanshen.common.oss.factory.OssFactory;
import com.fuyuanshen.common.satoken.utils.AppLoginHelper; import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
import com.fuyuanshen.equipment.utils.FileHashUtil;
import com.fuyuanshen.system.domain.vo.SysOssVo; import com.fuyuanshen.system.domain.vo.SysOssVo;
import com.fuyuanshen.system.service.ISysOssService; import com.fuyuanshen.system.service.ISysOssService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -15,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -31,24 +33,38 @@ public class AppFileService {
private final IAppBusinessFileService appBusinessFileService; private final IAppBusinessFileService appBusinessFileService;
private final FileHashUtil fileHashUtil;
private final ISysOssService ossService;
public List<AppFileVo> list(AppBusinessFileBo bo) { public List<AppFileVo> list(AppBusinessFileBo bo) {
// bo.setCreateBy(AppLoginHelper.getUserId()); // bo.setCreateBy(AppLoginHelper.getUserId());
return appBusinessFileService.queryAppFileList(bo); return appBusinessFileService.queryAppFileList(bo);
} }
public Boolean add(AppFileDto bo) {
/**
* APP文件上传
*/
public Boolean add(AppFileDto bo) throws IOException {
MultipartFile[] files = bo.getFiles(); MultipartFile[] files = bo.getFiles();
if(files == null || files.length == 0){ if (files == null || files.length == 0) {
throw new ServiceException("请选择要上传的文件"); throw new ServiceException("请选择要上传的文件");
} }
if(files.length > 5){ if (files.length > 5) {
throw new ServiceException("最多只能上传5个文件"); throw new ServiceException("最多只能上传5个文件");
} }
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
MultipartFile file = files[i]; MultipartFile file = files[i];
// 上传文件 // 上传文件
SysOssVo upload = sysOssService.upload(file); // SysOssVo upload = sysOssService.upload(file);
String fileHash = fileHashUtil.hash(file);
SysOssVo upload = ossService.updateHash(file, fileHash);
// 强制将HTTP替换为HTTPS
if (upload.getUrl() != null && upload.getUrl().startsWith("http://")) {
upload.setUrl(upload.getUrl().replaceFirst("^http://", "https://"));
}
if (upload == null) { if (upload == null) {
return false; return false;
@ -66,6 +82,7 @@ public class AppFileService {
return true; return true;
} }
public Boolean delete(Long[] ids) { public Boolean delete(Long[] ids) {
AppBusinessFileBo bo = new AppBusinessFileBo(); AppBusinessFileBo bo = new AppBusinessFileBo();
// bo.setCreateBy(AppLoginHelper.getUserId()); // bo.setCreateBy(AppLoginHelper.getUserId());
@ -79,4 +96,5 @@ public class AppFileService {
} }
return appBusinessFileService.deleteWithValidByIds(List.of(ids), true); return appBusinessFileService.deleteWithValidByIds(List.of(ids), true);
} }
} }

View File

@ -4,6 +4,11 @@ import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fuyuanshen.app.domain.bo.AppDeviceBindRecordBo;
import com.fuyuanshen.app.domain.bo.AppDeviceShareBo;
import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo;
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
import com.fuyuanshen.app.domain.vo.AppRoleVo; import com.fuyuanshen.app.domain.vo.AppRoleVo;
import com.fuyuanshen.app.domain.vo.AppUserVo; import com.fuyuanshen.app.domain.vo.AppUserVo;
import com.fuyuanshen.common.core.constant.Constants; import com.fuyuanshen.common.core.constant.Constants;
@ -23,6 +28,8 @@ import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
import com.fuyuanshen.common.satoken.utils.LoginHelper; import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.common.tenant.exception.TenantException; import com.fuyuanshen.common.tenant.exception.TenantException;
import com.fuyuanshen.common.tenant.helper.TenantHelper; import com.fuyuanshen.common.tenant.helper.TenantHelper;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.service.DeviceService;
import com.fuyuanshen.system.domain.vo.SysTenantVo; import com.fuyuanshen.system.domain.vo.SysTenantVo;
import com.fuyuanshen.system.service.ISysTenantService; import com.fuyuanshen.system.service.ISysTenantService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -33,6 +40,7 @@ import org.springframework.stereotype.Service;
import java.time.Duration; import java.time.Duration;
import java.util.*; import java.util.*;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors;
/** /**
* 登录校验方法 * 登录校验方法
@ -52,6 +60,9 @@ public class AppLoginService {
private final ISysTenantService tenantService; private final ISysTenantService tenantService;
private final IAppUserService appUserService; private final IAppUserService appUserService;
private final IAppDeviceShareService appDeviceShareService;
private final IAppDeviceBindRecordService appDeviceBindRecordService;
private final DeviceService deviceService;
/** /**
@ -188,10 +199,46 @@ public class AppLoginService {
public void cancelAccount() { public void cancelAccount() {
try { try {
AppLoginUser loginUser = AppLoginHelper.getLoginUser(); AppLoginUser loginUser = AppLoginHelper.getLoginUser();
// AppLoginUser loginUser = new AppLoginUser();
// loginUser.setUserId(1988398584423133187L);
// loginUser.setUsername("19022528079");
if (ObjectUtil.isNull(loginUser)) { if (ObjectUtil.isNull(loginUser)) {
return; return;
} }
appUserService.deleteWithValidByIds(Collections.singletonList(loginUser.getUserId()),true); appUserService.deleteWithValidByIds(Collections.singletonList(loginUser.getUserId()),true);
AppDeviceBindRecordBo appDeviceBindRecordBo = new AppDeviceBindRecordBo();
appDeviceBindRecordBo.setBindingUserId(loginUser.getUserId());
List<AppDeviceBindRecordVo> appDeviceBindRecordVos = appDeviceBindRecordService.queryList(appDeviceBindRecordBo);
if(ObjectUtil.length(appDeviceBindRecordVos)>0){
Set<Long> deviceIds = appDeviceBindRecordVos.stream().map(AppDeviceBindRecordVo::getDeviceId).collect(Collectors.toSet());
appDeviceShareService.deleteByDeviceIds(deviceIds);
List<Long> ids = appDeviceBindRecordVos.stream()
.map(AppDeviceBindRecordVo::getId)
.collect(Collectors.toList());
appDeviceBindRecordService.deleteWithValidByIds(ids, true);
log.info("删除绑定关系表数据ids={}",ids);
// 检查设备id是否存在绑定关系
for (Long deviceId : deviceIds){
// 根据设备id查询是否存在绑定关系
Long count = appDeviceBindRecordService.checkDeviceExistBindRecord(deviceId);
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",deviceId);
if(count>0){
updateWrapper.set("binding_status",1);
}else{
updateWrapper.set("binding_status",0);
}
deviceService.update(updateWrapper);
}
}
if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) { if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) {
// 超级管理员 登出清除动态租户 // 超级管理员 登出清除动态租户
TenantHelper.clearDynamic(); TenantHelper.clearDynamic();

View File

@ -28,7 +28,7 @@ public class VideoProcessService {
private final VideoProcessUtil videoProcessUtil; private final VideoProcessUtil videoProcessUtil;
public List<String> processVideo(MultipartFile file) { public List<String> processVideo(MultipartFile file, int code) {
// 1. 参数校验 // 1. 参数校验
validateVideoFile(file); validateVideoFile(file);
@ -39,9 +39,10 @@ public class VideoProcessService {
// 3. 处理视频并提取帧数据 // 3. 处理视频并提取帧数据
List<String> hexList = videoProcessUtil.processVideoToHex( List<String> hexList = videoProcessUtil.processVideoToHex(
tempFile, FRAME_RATE, DURATION, WIDTH, HEIGHT tempFile, FRAME_RATE, DURATION, WIDTH, HEIGHT, code
); );
log.info("code: {} hexList(前100个): {}", code,
hexList.subList(0, Math.min(100, hexList.size())));
log.info("视频处理成功生成Hex数据长度: {}", hexList.size()); log.info("视频处理成功生成Hex数据长度: {}", hexList.size());
return hexList; return hexList;

View File

@ -0,0 +1,48 @@
package com.fuyuanshen.global.mqtt.base;
import lombok.Data;
import java.util.List;
/**
* MQTT消息基础模型
*/
@Data
public class MqttMessage {
/**
* 请求ID用于匹配请求和响应
*/
private String requestId;
/**
* 设备IMEI
*/
private String imei;
/**
* 时间戳(毫秒)
*/
private Long timestamp;
/**
* 功能类型
*/
private Integer funcType;
/**
* 数据内容
*/
private Object data;
/**
* 状态(响应时使用)
*/
private String status;
/**
* 批量数据(设备上报时使用)
*/
private List<SensorData> batch;
}

View File

@ -0,0 +1,29 @@
package com.fuyuanshen.global.mqtt.base;
import lombok.Data;
/**
* MQTT主题信息模型
*/
@Data
public class MqttTopicInfo {
/**
* 操作类型 (command/status/report)
*/
private String operation;
/**
* 租户编码
*/
private String tenantCode;
/**
* 设备类型
*/
private String deviceType;
/**
* 设备IMEI
*/
private String imei;
}

View File

@ -0,0 +1,24 @@
package com.fuyuanshen.global.mqtt.base;
import lombok.Data;
/**
* 传感器数据模型
*/
@Data
public class SensorData {
/**
* 传感器名称
*/
private String sensor;
/**
* 传感器值
*/
private Object value;
/**
* 时间戳(毫秒)
*/
private Long timestamp;
}

View File

@ -10,22 +10,43 @@ import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
@Configuration @Configuration
public class MqttConfiguration { public class MqttConfiguration {
@Autowired @Autowired
private MqttPropertiesConfig mqttPropertiesConfig; private MqttPropertiesConfig mqttPropertiesConfig;
/** 创建连接工厂 **/
/**
* 创建连接工厂
**/
@Bean @Bean
public MqttPahoClientFactory mqttPahoClientFactory(){ public MqttPahoClientFactory mqttPahoClientFactory() {
DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory(); DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
MqttConnectOptions options = new MqttConnectOptions(); MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(true); //设置新会话 options.setCleanSession(true); // 设置新会话
options.setUserName(mqttPropertiesConfig.getUsername());
options.setPassword(mqttPropertiesConfig.getPassword().toCharArray()); // 修复用户名为null时的空指针异常
options.setServerURIs(new String[]{mqttPropertiesConfig.getUrl()}); String username = mqttPropertiesConfig.getUsername();
if (username != null) {
options.setUserName(username);
}
// 修复密码为null时的空指针异常
String password = mqttPropertiesConfig.getPassword();
if (password != null) {
options.setPassword(password.toCharArray());
}
// 修复URL为null时的空指针异常
String url = mqttPropertiesConfig.getUrl();
if (url != null) {
options.setServerURIs(new String[]{url});
}
options.setAutomaticReconnect(true); // 启用自动重连 options.setAutomaticReconnect(true); // 启用自动重连
options.setConnectionTimeout(10); // 设置连接超时时间 options.setConnectionTimeout(10); // 设置连接超时时间
options.setKeepAliveInterval(60); // 设置心跳间隔 options.setKeepAliveInterval(60); // 设置心跳间隔
factory.setConnectionOptions(options); factory.setConnectionOptions(options);
return factory; return factory;
} }
} }

View File

@ -39,8 +39,14 @@ public class MqttInboundConfiguration {
public MessageProducer messageProducer(){ public MessageProducer messageProducer(){
// 生成一个不重复的随机数 // 生成一个不重复的随机数
String clientId = mqttPropertiesConfig.getSubClientId() + "_" + UUID.fastUUID(); String clientId = mqttPropertiesConfig.getSubClientId() + "_" + UUID.fastUUID();
// 修复URL为null时的空指针异常
String url = mqttPropertiesConfig.getUrl();
if (url == null) {
throw new IllegalStateException("MQTT服务器URL未配置");
}
MqttPahoMessageDrivenChannelAdapter mqttPahoMessageDrivenChannelAdapter = new MqttPahoMessageDrivenChannelAdapter( MqttPahoMessageDrivenChannelAdapter mqttPahoMessageDrivenChannelAdapter = new MqttPahoMessageDrivenChannelAdapter(
mqttPropertiesConfig.getUrl(), url,
clientId, clientId,
mqttPahoClientFactory, mqttPahoClientFactory,
mqttPropertiesConfig.getSubTopic().split(",") mqttPropertiesConfig.getSubTopic().split(",")

View File

@ -15,11 +15,14 @@ import org.springframework.messaging.MessageHandler;
@Configuration @Configuration
@Slf4j @Slf4j
public class MqttOutboundConfiguration { public class MqttOutboundConfiguration {
@Autowired @Autowired
private MqttPropertiesConfig mqttPropertiesConfig; private MqttPropertiesConfig mqttPropertiesConfig;
@Autowired @Autowired
private MqttPahoClientFactory mqttPahoClientFactory; private MqttPahoClientFactory mqttPahoClientFactory;
// 消息通道 // 消息通道
@Bean @Bean
public MessageChannel mqttOutboundChannel(){ public MessageChannel mqttOutboundChannel(){
@ -32,8 +35,14 @@ public class MqttOutboundConfiguration {
@ServiceActivator(inputChannel = "mqttOutboundChannel") // 指定处理器针对哪个通道的消息进行处理 @ServiceActivator(inputChannel = "mqttOutboundChannel") // 指定处理器针对哪个通道的消息进行处理
public MessageHandler mqttOutboundMessageHandler(){ public MessageHandler mqttOutboundMessageHandler(){
String clientId = mqttPropertiesConfig.getPubClientId() + "_" + UUID.fastUUID(); String clientId = mqttPropertiesConfig.getPubClientId() + "_" + UUID.fastUUID();
// 修复URL为null时的空指针异常
String url = mqttPropertiesConfig.getUrl();
if (url == null) {
throw new IllegalStateException("MQTT服务器URL未配置");
}
MqttPahoMessageHandler mqttPahoMessageHandler = new MqttPahoMessageHandler( MqttPahoMessageHandler mqttPahoMessageHandler = new MqttPahoMessageHandler(
mqttPropertiesConfig.getUrl(), url,
clientId, clientId,
mqttPahoClientFactory mqttPahoClientFactory
); );

View File

@ -1,6 +1,7 @@
package com.fuyuanshen.global.mqtt.constants; package com.fuyuanshen.global.mqtt.constants;
public class DeviceRedisKeyConstants { public class DeviceRedisKeyConstants {
public static final String DEVICE_KEY_PREFIX = "device:"; public static final String DEVICE_KEY_PREFIX = "device:";
// 设备上报状态 // 设备上报状态
public static final String DEVICE_STATUS_KEY_PREFIX = ":status"; public static final String DEVICE_STATUS_KEY_PREFIX = ":status";
@ -52,4 +53,5 @@ public class DeviceRedisKeyConstants {
* 告警信息 * 告警信息
*/ */
public static final String DEVICE_ALARM_MESSAGE_KEY_PREFIX = ":alarmMessage"; public static final String DEVICE_ALARM_MESSAGE_KEY_PREFIX = ":alarmMessage";
} }

View File

@ -36,7 +36,6 @@ public class LightingCommandTypeConstants {
*/ */
public static final String SEND_MESSAGE = "Light_6"; public static final String SEND_MESSAGE = "Light_6";
/** /**
* 报警模式 * 报警模式
*/ */

View File

@ -0,0 +1,82 @@
package com.fuyuanshen.global.mqtt.enums;
/**
* 设备功能类型枚举
* 基于AppDeviceBJQ6075Controller中的功能注释1-9设计
*/
public enum DeviceFunctionType6075 {
/**
* 人员信息登记
*/
REGISTER_PERSON_INFO(1, "REGISTER_PERSON_INFO", "人员信息登记"),
/**
* 发送信息
*/
SEND_MESSAGE(2, "SEND_MESSAGE", "发送信息"),
/**
* 发送报警信息
*/
SEND_ALARM_MESSAGE(3, "SEND_ALARM_MESSAGE", "发送报警信息"),
/**
* 上传设备logo图片
*/
UPLOAD_LOGO(4, "UPLOAD_LOGO", "上传设备logo图片"),
/**
* 灯光模式(主光模式)
* 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS
*/
LIGHT_MODE(5, "LIGHT_MODE", "灯光模式"),
/**
* 灯光模式(辅光模式)
* 0关闭灯光1泛光2泛光爆闪, 3警示灯, 4警示灯/泛光)
*/
AUXILIARY_LIGHT_MODE(6, "AUXILIARY_LIGHT_MODE", "辅光模式"),
/**
* 灯光亮度设置
*/
LIGHT_BRIGHTNESS(7, "LIGHT_BRIGHTNESS", "灯光亮度设置"),
/**
* 激光模式设置
*/
LASER_MODE(8, "LASER_MODE", "激光模式设置"),
/**
* 声光报警模式设置
*/
SOUND_AND_LIGHT_ALARM(9, "SOUND_AND_LIGHT_ALARM", "声光报警模式设置");
private final int number;
private final String code;
private final String description;
DeviceFunctionType6075(int number, String code, String description) {
this.number = number;
this.code = code;
this.description = description;
}
public int getNumber() {
return number;
}
public String getCode() {
return code;
}
public String getDescription() {
return description;
}
@Override
public String toString() {
return code;
}
}

View File

@ -0,0 +1,136 @@
package com.fuyuanshen.global.mqtt.handler;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.global.mqtt.base.MqttTopicInfo;
import com.fuyuanshen.global.mqtt.service.IotMqttService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* IoT设备MQTT消息处理器
* 用于处理设备上报的数据和响应消息
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class IotMqttMessageHandler {
private final IotMqttService iotMqttService;
/**
* 处理MQTT消息
*
* @param topic 主题
* @param payload 消息内容
*/
public void handleMessage(String topic, String payload) {
try {
// 解析主题
MqttTopicInfo topicInfo = parseTopic(topic);
if (topicInfo == null) {
log.warn("无法解析MQTT主题: topic={}", topic);
return;
}
// 解析消息内容
JSONObject message = JSON.parseObject(payload);
// 根据主题类型处理消息
switch (topicInfo.getOperation()) {
case "command":
// 处理下发指令设备端不会主动发送command类型消息
log.warn("收到非法的MQTT消息类型: operation={}", topicInfo.getOperation());
break;
case "status":
// 处理设备对指令的响应
iotMqttService.handleCommandResponse(
topicInfo.getTenantCode(),
topicInfo.getDeviceType(),
topicInfo.getImei(),
message);
break;
case "report":
// 处理设备主动上报的数据
handleDeviceReport(topicInfo, message);
break;
default:
log.warn("未知的MQTT主题操作类型: operation={}", topicInfo.getOperation());
break;
}
} catch (Exception e) {
log.error("处理MQTT消息时发生错误: topic={}, payload={}", topic, payload, e);
}
}
/**
* 解析MQTT主题
*
* @param topic 主题字符串
* @return 主题信息对象
*/
MqttTopicInfo parseTopic(String topic) {
if (topic == null || topic.isEmpty()) {
return null;
}
String[] parts = topic.split("/");
if (parts.length != 4) {
return null;
}
MqttTopicInfo info = new MqttTopicInfo();
info.setOperation(parts[0]);
info.setTenantCode(parts[1]);
info.setDeviceType(parts[2]);
info.setImei(parts[3]);
return info;
}
/**
* 处理设备上报数据
*
* @param topicInfo 主题信息
* @param message 消息内容
*/
private void handleDeviceReport(MqttTopicInfo topicInfo, JSONObject message) {
// 获取时间戳
Long timestamp = message.getLong("timestamp");
// 处理批量数据上报
if (message.containsKey("batch")) {
JSONObject batchData = message.getJSONObject("batch");
iotMqttService.handleBatchReport(
topicInfo.getTenantCode(),
topicInfo.getDeviceType(),
topicInfo.getImei(),
batchData,
timestamp);
}
// 处理单个数据上报
else if (message.containsKey("sensor") && message.containsKey("value")) {
String sensor = message.getString("sensor");
Object value = message.get("value");
iotMqttService.handleSingleReport(
topicInfo.getTenantCode(),
topicInfo.getDeviceType(),
topicInfo.getImei(),
sensor,
value,
timestamp);
}
// 处理其他格式的数据
else {
// 将整个消息作为批量数据处理
iotMqttService.handleBatchReport(
topicInfo.getTenantCode(),
topicInfo.getDeviceType(),
topicInfo.getImei(),
message,
timestamp);
}
}
}

View File

@ -0,0 +1,71 @@
package com.fuyuanshen.global.mqtt.handler;
import com.alibaba.fastjson2.JSON;
import com.fuyuanshen.global.mqtt.base.MqttMessage;
import com.fuyuanshen.global.mqtt.service.MqttMessageService;
import com.fuyuanshen.global.mqtt.utils.MqttTopicUtils;
import com.fuyuanshen.global.mqtt.base.MqttTopicInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* MQTT消息处理器
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class MqttMessageHandler {
private final MqttMessageService mqttMessageService;
/**
* 处理MQTT消息
* @param topic 主题
* @param payload 消息内容
*/
public void handleMessage(String topic, String payload) {
try {
// 解析主题
MqttTopicInfo topicInfo = MqttTopicUtils.parseTopic(topic);
if (topicInfo == null) {
log.warn("无法解析MQTT主题: topic={}", topic);
return;
}
// 解析消息内容
MqttMessage message = JSON.parseObject(payload, MqttMessage.class);
// 根据主题类型处理消息
switch (topicInfo.getOperation()) {
case "command":
// 处理下发指令设备端不会主动发送command类型消息
log.warn("收到非法的MQTT消息类型: operation={}", topicInfo.getOperation());
break;
case "status":
// 处理设备对指令的响应
mqttMessageService.handleCommandResponse(
topicInfo.getTenantCode(),
topicInfo.getDeviceType(),
topicInfo.getImei(),
message);
break;
case "report":
// 处理设备主动上报的数据
mqttMessageService.handleDeviceReport(
topicInfo.getTenantCode(),
topicInfo.getDeviceType(),
topicInfo.getImei(),
message);
break;
default:
log.warn("未知的MQTT主题操作类型: operation={}", topicInfo.getOperation());
break;
}
} catch (Exception e) {
log.error("处理MQTT消息时发生错误: topic={}, payload={}", topic, payload, e);
}
}
}

View File

@ -67,31 +67,29 @@ public class BjqActiveReportingDeviceDataRule implements MqttMessageRule {
*/ */
public void asyncSendDeviceDataToRedisWithFuture(String deviceImei, String mainLightMode, String laserLightMode, public void asyncSendDeviceDataToRedisWithFuture(String deviceImei, String mainLightMode, String laserLightMode,
String batteryPercentage, String chargeState, String batteryRemainingTime) { String batteryPercentage, String chargeState, String batteryRemainingTime) {
CompletableFuture.runAsync(() -> { try {
try { // 构造设备状态信息对象
// 构造设备状态信息对象 Map<String, Object> deviceInfo = new LinkedHashMap<>();
Map<String, Object> deviceInfo = new LinkedHashMap<>(); deviceInfo.put("deviceImei", deviceImei);
deviceInfo.put("deviceImei", deviceImei); deviceInfo.put("mainLightMode", mainLightMode);
deviceInfo.put("mainLightMode", mainLightMode); deviceInfo.put("laserLightMode", laserLightMode);
deviceInfo.put("laserLightMode", laserLightMode); deviceInfo.put("batteryPercentage", batteryPercentage);
deviceInfo.put("batteryPercentage", batteryPercentage); deviceInfo.put("chargeState", chargeState);
deviceInfo.put("chargeState", chargeState); deviceInfo.put("batteryRemainingTime", batteryRemainingTime);
deviceInfo.put("batteryRemainingTime", batteryRemainingTime); deviceInfo.put("timestamp", System.currentTimeMillis());
deviceInfo.put("timestamp", System.currentTimeMillis());
// 将设备状态信息存储到Redis中 // 将设备状态信息存储到Redis中
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + deviceImei + DEVICE_STATUS_KEY_PREFIX; String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + deviceImei + DEVICE_STATUS_KEY_PREFIX;
String deviceInfoJson = JsonUtils.toJsonString(deviceInfo); String deviceInfoJson = JsonUtils.toJsonString(deviceInfo);
// 存储到Redis // 存储到Redis
RedisUtils.setCacheObject(deviceRedisKey, deviceInfoJson); RedisUtils.setCacheObject(deviceRedisKey, deviceInfoJson);
log.info("设备状态信息已异步发送到Redis: device={}, mainLightMode={}, laserLightMode={}, batteryPercentage={}", log.info("设备状态信息已异步发送到Redis: device={}, mainLightMode={}, laserLightMode={}, batteryPercentage={}",
deviceImei, mainLightMode, laserLightMode, batteryPercentage); deviceImei, mainLightMode, laserLightMode, batteryPercentage);
} catch (Exception e) { } catch (Exception e) {
log.error("异步发送设备信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e); log.error("异步发送设备信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e);
} }
});
} }

View File

@ -57,12 +57,12 @@ public class BjqAlarmRule implements MqttMessageRule {
if (StringUtils.isNotBlank(convertValue)) { if (StringUtils.isNotBlank(convertValue)) {
// 将设备状态信息存储到Redis中 // 将设备状态信息存储到Redis中
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX; String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX;
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending"; String sendMessageIng = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
if ("1".equals(convertValue)) { if ("1".equals(convertValue)) {
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1)); RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
// 存储到Redis // 存储到Redis
RedisUtils.setCacheObject(deviceRedisKey, "1"); RedisUtils.setCacheObject(deviceRedisKey, "1");
}else if ("0".equals(convertValue)){ } else if ("0".equals(convertValue)) {
RedisUtils.deleteObject(sendMessageIng); RedisUtils.deleteObject(sendMessageIng);
RedisUtils.deleteObject(deviceRedisKey); RedisUtils.deleteObject(deviceRedisKey);
} }

View File

@ -71,5 +71,4 @@ public class BjqLaserModeSettingsRule implements MqttMessageRule {
} }
} }

View File

@ -121,16 +121,15 @@ public class BjqLocationDataRule implements MqttMessageRule {
* @param longitude 经度 * @param longitude 经度
*/ */
public void asyncSendLocationToRedisWithFuture(String deviceImei, String latitude, String longitude) { public void asyncSendLocationToRedisWithFuture(String deviceImei, String latitude, String longitude) {
CompletableFuture.runAsync(() -> { try {
try { if (StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)) {
if (StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)) { return;
return; }
}
// String[] latArr = latitude.split("\\."); // String[] latArr = latitude.split("\\.");
// String[] lonArr = longitude.split("\\."); // String[] lonArr = longitude.split("\\.");
// // 将位置信息存储到Redis中 // // 将位置信息存储到Redis中
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX; String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX;
// String redisObj = RedisUtils.getCacheObject(redisKey); // String redisObj = RedisUtils.getCacheObject(redisKey);
// JSONObject jsonOBj = JSONObject.parseObject(redisObj); // JSONObject jsonOBj = JSONObject.parseObject(redisObj);
// if(jsonOBj != null){ // if(jsonOBj != null){
@ -150,34 +149,33 @@ public class BjqLocationDataRule implements MqttMessageRule {
// } // }
// } // }
// 构造位置信息对象 // 构造位置信息对象
Map<String, Object> locationInfo = new LinkedHashMap<>(); Map<String, Object> locationInfo = new LinkedHashMap<>();
double[] doubles = LngLonUtil.gps84_To_Gcj02(Double.parseDouble(latitude), Double.parseDouble(longitude)); double[] doubles = LngLonUtil.gps84_To_Gcj02(Double.parseDouble(latitude), Double.parseDouble(longitude));
locationInfo.put("deviceImei", deviceImei); locationInfo.put("deviceImei", deviceImei);
locationInfo.put("latitude", doubles[0]); locationInfo.put("latitude", doubles[0]);
locationInfo.put("longitude", doubles[1]); locationInfo.put("longitude", doubles[1]);
locationInfo.put("wgs84_latitude", latitude); locationInfo.put("wgs84_latitude", latitude);
locationInfo.put("wgs84_longitude", longitude); locationInfo.put("wgs84_longitude", longitude);
String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0])); String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
locationInfo.put("address", address); locationInfo.put("address", address);
locationInfo.put("timestamp", System.currentTimeMillis()); locationInfo.put("timestamp", System.currentTimeMillis());
String locationJson = JsonUtils.toJsonString(locationInfo); String locationJson = JsonUtils.toJsonString(locationInfo);
// 存储到Redis // 存储到Redis
RedisUtils.setCacheObject(redisKey, locationJson); RedisUtils.setCacheObject(redisKey, locationJson);
// 存储到一个列表中,保留历史位置信息 // 存储到一个列表中,保留历史位置信息
// String locationHistoryKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX + deviceImei; // String locationHistoryKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX + deviceImei;
// RedisUtils.addCacheList(locationHistoryKey, locationJson); // RedisUtils.addCacheList(locationHistoryKey, locationJson);
// RedisUtils.expire(locationHistoryKey, Duration.ofDays(90)); // RedisUtils.expire(locationHistoryKey, Duration.ofDays(90));
storeDeviceTrajectoryWithSortedSet(deviceImei, locationJson); storeDeviceTrajectoryWithSortedSet(deviceImei, locationJson);
log.info("位置信息已异步发送到Redis: device={}, lat={}, lon={}", deviceImei, latitude, longitude); log.info("位置信息已异步发送到Redis: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
} catch (Exception e) { } catch (Exception e) {
log.error("异步发送位置信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e); log.error("异步发送位置信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e);
} }
});
} }
@ -189,20 +187,18 @@ public class BjqLocationDataRule implements MqttMessageRule {
* @param longitude 经度 * @param longitude 经度
*/ */
public void asyncSaveLocationToMySQLWithFuture(String deviceImei, String latitude, String longitude) { public void asyncSaveLocationToMySQLWithFuture(String deviceImei, String latitude, String longitude) {
CompletableFuture.runAsync(() -> { try {
try { if (StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)) {
if (StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)) { return;
return;
}
// 调用服务层方法更新设备位置信息
deviceService.updateDeviceLocationByImei(deviceImei, longitude, latitude);
log.info("位置信息已异步保存到MySQL: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
} catch (Exception e) {
log.error("异步保存位置信息到MySQL时出错: device={}, error={}", deviceImei, e.getMessage(), e);
} }
});
// 调用服务层方法更新设备位置信息
deviceService.updateDeviceLocationByImei(deviceImei, longitude, latitude);
log.info("位置信息已异步保存到MySQL: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
} catch (Exception e) {
log.error("异步保存位置信息到MySQL时出错: device={}, error={}", deviceImei, e.getMessage(), e);
}
} }

View File

@ -45,6 +45,7 @@ public class BjqModeRule implements MqttMessageRule {
return LightingCommandTypeConstants.LIGHT_MODE; return LightingCommandTypeConstants.LIGHT_MODE;
} }
@Override @Override
public void execute(MqttRuleContext context) { public void execute(MqttRuleContext context) {
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei(); String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();

View File

@ -1,32 +1,18 @@
package com.fuyuanshen.global.mqtt.rule.bjq; package com.fuyuanshen.global.mqtt.rule.bjq;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.json.utils.JsonUtils;
import com.fuyuanshen.common.redis.utils.RedisUtils; import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
import com.fuyuanshen.equipment.utils.map.LngLonUtil;
import com.fuyuanshen.global.mqtt.base.MqttMessageRule; import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
import com.fuyuanshen.global.mqtt.base.MqttRuleContext; import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
import com.fuyuanshen.global.mqtt.config.MqttGateway; import com.fuyuanshen.global.mqtt.config.MqttGateway;
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants; import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus; import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.Duration; import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY; import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
/** /**
* 定位数据命令处理 * 定位数据命令处理
@ -55,4 +41,5 @@ public class BjqPersonnelInfoDataRule implements MqttMessageRule {
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(30)); RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(30));
} }
} }
} }

View File

@ -1,8 +1,13 @@
package com.fuyuanshen.global.mqtt.rule.xinghan; package com.fuyuanshen.global.mqtt.rule.xinghan;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson2.JSONWriter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fuyuanshen.common.core.constant.GlobalConstants; import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.utils.StringUtils; import com.fuyuanshen.common.core.utils.StringUtils;
@ -10,11 +15,20 @@ import com.fuyuanshen.common.core.utils.date.DurationUtils;
import com.fuyuanshen.common.json.utils.JsonUtils; import com.fuyuanshen.common.json.utils.JsonUtils;
import com.fuyuanshen.common.redis.utils.RedisUtils; import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.equipment.domain.Device; import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.DeviceFenceAccessRecord;
import com.fuyuanshen.equipment.domain.DeviceGeoFence;
import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo; import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo;
import com.fuyuanshen.equipment.domain.bo.DeviceFenceAccessRecordBo;
import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo; import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo;
import com.fuyuanshen.equipment.domain.vo.DeviceGeoFenceVo;
import com.fuyuanshen.equipment.mapper.DeviceAlarmMapper; import com.fuyuanshen.equipment.mapper.DeviceAlarmMapper;
import com.fuyuanshen.equipment.mapper.DeviceFenceAccessRecordMapper;
import com.fuyuanshen.equipment.mapper.DeviceGeoFenceMapper;
import com.fuyuanshen.equipment.service.DeviceService; import com.fuyuanshen.equipment.service.DeviceService;
import com.fuyuanshen.equipment.service.IDeviceAlarmService; import com.fuyuanshen.equipment.service.IDeviceAlarmService;
import com.fuyuanshen.equipment.service.IDeviceFenceAccessRecordService;
import com.fuyuanshen.equipment.service.IDeviceGeoFenceService;
import com.fuyuanshen.equipment.utils.map.AmapTrackUtil;
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil; import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
import com.fuyuanshen.equipment.utils.map.LngLonUtil; import com.fuyuanshen.equipment.utils.map.LngLonUtil;
import com.fuyuanshen.global.mqtt.base.MqttMessageRule; import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
@ -30,13 +44,16 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock; import org.redisson.api.RLock;
import org.redisson.api.RedissonClient; import org.redisson.api.RedissonClient;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.text.DecimalFormat;
import java.time.Duration; import java.time.Duration;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY; import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY; import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
@ -72,6 +89,12 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
private final IDeviceAlarmService deviceAlarmService; private final IDeviceAlarmService deviceAlarmService;
private final DeviceService deviceService; private final DeviceService deviceService;
private final DeviceAlarmMapper deviceAlarmMapper; private final DeviceAlarmMapper deviceAlarmMapper;
private final AmapTrackUtil amapTrackUtil;
private final IDeviceFenceAccessRecordService deviceFenceAccessRecordService;
private final DeviceFenceAccessRecordMapper deviceFenceAccessRecordMapper;
private final DeviceGeoFenceMapper deviceGeoFenceMapper;
/** 位置未发生明显变化的距离阈值(米),可通过配置中心动态调整 */
private final double MOVEMENT_THRESHOLD_METER = 10.0;
@Override @Override
public void execute(MqttRuleContext context) { public void execute(MqttRuleContext context) {
@ -127,16 +150,20 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
* 入口保存报警SOS 与 Shake 完全独立) * 入口保存报警SOS 与 Shake 完全独立)
*/ */
public void saveAlarm(String deviceImei, MqttXinghanJson status) { public void saveAlarm(String deviceImei, MqttXinghanJson status) {
int sos = Optional.ofNullable(status.getStaSOSGrade()).orElse(0); try {
// 1. 处理 SOS 报警 int sos = Optional.ofNullable(status.getStaSOSGrade()).orElse(0);
handleSingleAlarm(deviceImei, // 1. 处理 SOS 报警
sos > 0, handleSingleAlarm(deviceImei,
AlarmTypeEnum.SOS); sos > 0,
int shake = Optional.ofNullable(status.getStaShakeBit()).orElse(0); AlarmTypeEnum.SOS);
// 2. 处理 Shake 报警 int shake = Optional.ofNullable(status.getStaShakeBit()).orElse(0);
handleSingleAlarm(deviceImei, // 2. 处理 Shake 报警
shake > 0, handleSingleAlarm(deviceImei,
AlarmTypeEnum.SHAKE); shake > 0,
AlarmTypeEnum.SHAKE);
} catch (Exception e) {
log.error("异步保存报警SOS 与 Shake 完全独立)报错: device={}, error={}", deviceImei, e.getMessage(), e);
}
} }
/** /**
@ -236,7 +263,7 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
String location = RedisUtils.getCacheObject( String location = RedisUtils.getCacheObject(
GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX); GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX);
if (StrUtil.isNotBlank(location)) { if (StrUtil.isNotBlank(location)) {
bo.setLocation(JSONObject.parseObject(location).getString("address")); bo.setLocation(com.alibaba.fastjson2.JSONObject.parseObject(location).getString("address"));
} }
return bo; return bo;
} }
@ -259,63 +286,312 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
public void asyncSendLocationToRedisWithFuture(String deviceImei, String latitude, String longitude) { public void asyncSendLocationToRedisWithFuture(String deviceImei, String latitude, String longitude) {
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
try { try {
if(StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)){ if (StringUtils.isAnyBlank(deviceImei, latitude, longitude)) {
log.warn("位置上报参数为空deviceImei={}", deviceImei);
return;
}
//log.info("位置上报deviceImei={}, lat={}, lon={}", deviceImei, latitude, longitude);
// 1. 解析当前上报的经纬度
Double curLat = parseDoubleSafe(latitude.trim());
Double curLon = parseDoubleSafe(longitude.trim());
if (curLat == null || curLon == null) {
log.warn("经纬度格式错误直接更新deviceImei={}, lat={}, lon={}", deviceImei, latitude, longitude);
doSaveLocation(deviceImei, latitude, longitude);
return; return;
} }
String[] latArr = latitude.split("\\.");
String[] lonArr = longitude.split("\\.");
// 将位置信息存储到Redis中
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX;
String redisObj = RedisUtils.getCacheObject(redisKey);
JSONObject jsonOBj = JSONObject.parseObject(redisObj);
if(jsonOBj != null){
String str1 = latArr[0] +"."+ latArr[1].substring(0,4);
String str2 = lonArr[0] +"."+ lonArr[1].substring(0,4);
String cacheLatitude = jsonOBj.getString("wgs84_latitude"); // 2. 读取 Redis 中缓存的上一次位置
String cacheLongitude = jsonOBj.getString("wgs84_longitude"); String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX;
String[] latArr1 = cacheLatitude.split("\\."); String cachedJson = RedisUtils.getCacheObject(redisKey);
String[] lonArr1 = cacheLongitude.split("\\.");
String cacheStr1 = latArr1[0] +"."+ latArr1[1].substring(0,4); if (StringUtils.isNotBlank(cachedJson)) {
String cacheStr2 = lonArr1[0] +"."+ lonArr1[1].substring(0,4); com.alibaba.fastjson2.JSONObject cachedObj = com.alibaba.fastjson2.JSONObject.parseObject(cachedJson);
if(str1.equals(cacheStr1) && str2.equals(cacheStr2)){ String cachedWgs84Lat = cachedObj.getString("wgs84_latitude");
log.info("位置信息未发生变化: device={}, lat={}, lon={}", deviceImei, latitude, longitude); String cachedWgs84Lon = cachedObj.getString("wgs84_longitude");
return;
Double oldLat = parseDoubleSafe(cachedWgs84Lat);
Double oldLon = parseDoubleSafe(cachedWgs84Lon);
if (oldLat != null && oldLon != null) {
double distance = haversine(oldLat, oldLon, curLat, curLon);
if (distance <= MOVEMENT_THRESHOLD_METER) {
log.info("位置未发生明显变化({}米 <= {}米),不更新 RedisdeviceImei={}, lat={}, lon={}",
distance, MOVEMENT_THRESHOLD_METER, deviceImei, latitude, longitude);
return;
}
} }
} }
// 构造位置信息对象 // 3. 位置有明显变化,执行保存
Map<String, Object> locationInfo = new LinkedHashMap<>(); doSaveLocation(deviceImei, latitude, longitude);
double[] doubles = LngLonUtil.gps84_To_Gcj02(Double.parseDouble(latitude), Double.parseDouble(longitude));
locationInfo.put("deviceImei", deviceImei);
locationInfo.put("latitude", doubles[0]);
locationInfo.put("longitude", doubles[1]);
locationInfo.put("wgs84_latitude", latitude);
locationInfo.put("wgs84_longitude", longitude);
String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
locationInfo.put("address", address);
locationInfo.put("timestamp", System.currentTimeMillis());
String locationJson = JsonUtils.toJsonString(locationInfo);
// 存储到Redis
RedisUtils.setCacheObject(redisKey, locationJson);
// 存储到一个列表中,保留历史位置信息
// String locationHistoryKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX + deviceImei;
// RedisUtils.addCacheList(locationHistoryKey, locationJson);
// RedisUtils.expire(locationHistoryKey, Duration.ofDays(90));
storeDeviceTrajectoryWithSortedSet(deviceImei, locationJson);
log.info("位置信息已异步发送到Redis: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
} catch (Exception e) { } catch (Exception e) {
log.error("异步发送位置信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e); log.error("异步发送位置信息到 Redis 失败,deviceImei={}", deviceImei, e);
} }
}); });
} }
/** 真正执行保存逻辑(抽取出来便于测试和阅读) */
private void doSaveLocation(String deviceImei, String wgs84Lat, String wgs84Lon) {
// Map<String, Object> locationInfo = new LinkedHashMap<>();
// locationInfo.put("deviceImei", deviceImei);
// locationInfo.put("latitude", gcj02[0]); // GCJ02 纬度
// locationInfo.put("longitude", gcj02[1]); // GCJ02 经度
// locationInfo.put("wgs84_latitude", wgs84Lat);
// locationInfo.put("wgs84_longitude", wgs84Lon);
//
//
// locationInfo.put("address", StringUtils.defaultIfBlank(address, "未知"));
// locationInfo.put("timestamp", System.currentTimeMillis());
//
// String locationJson = JsonUtils.toJsonString(locationInfo);
// 使用 fastjson2 零 GC 序列化
// WGS84 → GCJ02火星坐标
double[] gcj02 = LngLonUtil.gps84_To_Gcj02(
Double.parseDouble(wgs84Lat),
Double.parseDouble(wgs84Lon)
);
String gcj02Lat = String.format("%.6f", gcj02[0]);
String gcj02Lon = String.format("%.6f", gcj02[1]);
// 逆地理编码(可自行决定是否异步)
String address = GetAddressFromLatUtil.getAdd(gcj02Lon, gcj02Lat);
String locationJson = buildLocationJsonFastJSON2(deviceImei, wgs84Lat, wgs84Lon, gcj02Lon, gcj02Lat,address);
// 主位置信息(最新一条)
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX;
RedisUtils.setCacheObject(redisKey, locationJson);
// 轨迹存储SortedSet按时间戳排序
storeDeviceTrajectoryWithSortedSet(deviceImei, locationJson);
// 轨迹上传 查询检测对象与围栏关系 记录设备进出围栏事件
uploadTrackPointAsync(deviceImei, gcj02Lat, gcj02Lon, address);
log.info("位置信息已更新 RedisdeviceImei={}, wgs84=({},{})", deviceImei, wgs84Lat, wgs84Lon);
}
private String buildLocationJsonFastJSON2(
String deviceImei,
String wgs84Lat, String wgs84Lon,
String gcj02Lon, String gcj02Lat,String address) {
long timestamp = System.currentTimeMillis();
// 直接用默认 writer零配置自动零 GC
try (JSONWriter w = JSONWriter.of()) {
w.startObject();
w.writeString("deviceImei"); w.writeColon(); w.writeString(deviceImei); w.writeComma();
w.writeString("latitude"); w.writeColon(); w.writeString(gcj02Lat); w.writeComma();
w.writeString("longitude"); w.writeColon(); w.writeString(gcj02Lon); w.writeComma();
w.writeString("wgs84_latitude"); w.writeColon(); w.writeString(wgs84Lat); w.writeComma();
w.writeString("wgs84_longitude"); w.writeColon(); w.writeString(wgs84Lon); w.writeComma();
w.writeString("address"); w.writeColon(); w.writeString(StringUtils.defaultIfBlank(address, "未知")); w.writeComma();
w.writeString("timestamp"); w.writeColon(); w.writeInt64(timestamp);
w.endObject();
return w.toString();
}
}
/**
* 上传轨迹点并处理电子围栏出入事件(高德猎鹰服务)
* 优化点:
* 1. 避免重复查询数据库(围栏信息批量缓存)
* 2. 防御性编程:全面空指针防护
* 3. Redis 操作原子性 + 合理 TTL
* 4. 减少不必要的对象创建和流操作
* 5. 精确的事件时间使用 locationTime
* 6. 失败不阻塞主流程,记录关键错误
*/
private void uploadTrackPointAsync(String deviceImei,
String gcj02Lat,
String gcj02Lon,String address) {
if (StrUtil.hasBlank(deviceImei, gcj02Lat, gcj02Lon)) {
log.warn("上传轨迹点参数非法deviceImei={}, lat={}, lon={}", deviceImei, gcj02Lat, gcj02Lon);
return;
}
long locationTime = System.currentTimeMillis();
String fenceStatusKey = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + ":terminal:status";
try {
// 1. 查询设备信息建议加缓存热点设备可大幅降低DB压力
Device device = deviceService.selectDeviceByImei(deviceImei);
if (device == null || device.getSid() == null || device.getTid() == null) {
log.warn("设备不存在或未完成高德终端创建imei={}", deviceImei);
return;
}
Long trid = ObjectUtil.defaultIfNull(device.getTrid(), 0L); // trid 可能为空
// 2. 上传轨迹点
JSONObject point = new JSONObject();
point.set("location", String.format("%s,%s", gcj02Lon, gcj02Lat));
point.set("locatetime", locationTime);
JSONArray pointsArray = new JSONArray();
pointsArray.add(point);
log.info("上传轨迹点开始deviceImei={}, point={}", deviceImei, point);
JSONObject uploadResult = amapTrackUtil.uploadPoints(device.getSid(), device.getTid(), trid, pointsArray);
if (uploadResult == null || uploadResult.getInt("errcode", -1) != 10000) {
return;
}
log.info("上传轨迹点成功deviceImei={}, result={}", deviceImei, uploadResult);
// 3. 查询当前围栏状态
JSONObject fenceResult = amapTrackUtil.queryTerminalFenceStatus(device.getSid(), null, device.getTid());
if (fenceResult == null || fenceResult.getInt("errcode", -1) != 10000) {
log.warn("查询设备围栏状态失败imei={}, result={}", deviceImei, fenceResult);
return;
}
log.info("查询设备围栏状态成功imei={}, result={}", deviceImei, fenceResult);
JSONArray results = fenceResult.getByPath("data.results", JSONArray.class);
if (results == null || results.isEmpty()) {
// 没有任何围栏关系,清空旧状态
RedisUtils.deleteObject(fenceStatusKey);
return;
}
// 4. 当前在围栏内的 gfid 集合
Set<Long> newInFenceGfids = new HashSet<>();
List<JSONObject> currentInList = new ArrayList<>();
for (Object obj : results) {
JSONObject item = (JSONObject) obj;
if (item.getInt("in", 0) == 1) {
Long gfid = item.getLong("gfid");
if (gfid != null) {
newInFenceGfids.add(gfid);
currentInList.add(item);
}
}
}
// 5. 获取上一次的围栏状态
List<JSONObject> oldInList = RedisUtils.getCacheObject(fenceStatusKey);
Set<Long> oldInFenceGfids = (oldInList == null || oldInList.isEmpty())
? Collections.emptySet()
: oldInList.stream()
.map(o -> o.getLong("gfid"))
.collect(Collectors.toSet());
// 6. 计算出入事件(使用高效的 Set 操作)
Set<Long> enteredGfids = new HashSet<>(newInFenceGfids);
enteredGfids.removeAll(oldInFenceGfids);// 进入:这次有,上次没有
Set<Long> exitedGfids = new HashSet<>(oldInFenceGfids);
exitedGfids.removeAll(newInFenceGfids);// 离开:上次有,这次没有
Date eventTime = new Date(locationTime);
Double latitude = Double.valueOf(gcj02Lat);
Double longitude = Double.valueOf(gcj02Lon);
// 批量查询围栏信息(关键优化:避免 N+1 查询)
Set<Long> allChangedGfids = new HashSet<>();
allChangedGfids.addAll(enteredGfids);
allChangedGfids.addAll(exitedGfids);
Map<Long, DeviceGeoFenceVo> fenceMap = new HashMap<>();
if (CollUtil.isNotEmpty(allChangedGfids)) {
List<DeviceGeoFenceVo> fenceList = deviceGeoFenceMapper.selectVoList(
new LambdaQueryWrapper<DeviceGeoFence>().in(DeviceGeoFence::getGfid, allChangedGfids));
fenceMap = fenceList.stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(DeviceGeoFenceVo::getGfid, v -> v, (a, b) -> a));
}
// 7. 记录进入事件
if (CollUtil.isNotEmpty(enteredGfids)) {
List<DeviceFenceAccessRecord> enterRecords = new ArrayList<>();
for (Long gfid : enteredGfids) {
DeviceFenceAccessRecord record = buildFenceRecord(device, fenceMap.get(gfid), 1L, latitude, longitude, eventTime, address);
if (record != null) {
enterRecords.add(record);
}
}
deviceFenceAccessRecordMapper.insertBatch(enterRecords);
log.info("设备进入围栏imei={}, gfids={}", deviceImei, enteredGfids);
}
// 8. 记录离开事件
if (CollUtil.isNotEmpty(exitedGfids)) {
List<DeviceFenceAccessRecord> exitRecords = new ArrayList<>();
for (Long gfid : exitedGfids) {
DeviceFenceAccessRecord record = buildFenceRecord(device, fenceMap.get(gfid), 2L, latitude, longitude, eventTime, address);
if (record != null) {
exitRecords.add(record);
}
}
deviceFenceAccessRecordMapper.insertBatch(exitRecords);
log.info("设备离开围栏imei={}, gfids={}", deviceImei, exitedGfids);
}
// 9. 更新 Redis 状态TTL 5分钟防止频繁查询
if (CollUtil.isNotEmpty(currentInList)) {
RedisUtils.setCacheObject(fenceStatusKey, currentInList, Duration.ofMinutes(5));
} else {
RedisUtils.deleteObject(fenceStatusKey);
}
} catch (Exception e) {
log.error("上传轨迹点并处理围栏事件异常imei={}, lat={}, lon={}, time={}",
deviceImei, gcj02Lat, gcj02Lon, locationTime, e);
// 可落库待重试或发告警,此处不抛异常影响定位主流程
}
}
/**
* 构建围栏出入记录(提取公共逻辑,避免重复代码)
*/
private DeviceFenceAccessRecord buildFenceRecord(Device device,
DeviceGeoFenceVo fence,
Long eventType,
Double latitude,
Double longitude,
Date eventTime,String address) {
if (fence == null || fence.getId() == null) {
log.warn("围栏信息不存在gfid 可能已被删除或未绑定");
return null;
}
DeviceFenceAccessRecord bo = new DeviceFenceAccessRecord();
bo.setDeviceId(device.getId().toString());
bo.setFenceId(fence.getId());
bo.setEventType(eventType); // 1=进入, 2=离开
bo.setAccuracy(20L);
bo.setLatitude(latitude);
bo.setLongitude(longitude);
bo.setEventTime(eventTime);
bo.setTenantId(device.getTenantId());
bo.setCreateBy(device.getCreateBy());
bo.setCreateDept(device.getCreateDept());
bo.setEventAddress(address);
return bo;
}
/** 安全解析 double解析失败返回 null */
private Double parseDoubleSafe(String str) {
if (StringUtils.isBlank(str)) return null;
try {
return Double.parseDouble(str.trim());
} catch (NumberFormatException e) {
return null;
}
}
/** Haversine 公式计算两点球面距离(米) */
private double haversine(double lat1, double lon1, double lat2, double lon2) {
double dLat = Math.toRadians(lat2 - lat1);
double dLon = Math.toRadians(lon2 - lon1);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
/** 地球平均半径(米) */
double EARTH_RADIUS = 6371_393.0;
return EARTH_RADIUS * c;
}
/** /**
* 存储设备30天历史轨迹到Redis (使用Sorted Set) * 存储设备30天历史轨迹到Redis (使用Sorted Set)
*/ */
@ -358,4 +634,6 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
return map; return map;
} }
} }

View File

@ -1,9 +1,18 @@
package com.fuyuanshen.global.mqtt.rule.xinghan; package com.fuyuanshen.global.mqtt.rule.xinghan;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fuyuanshen.common.json.utils.JsonUtils; import com.fuyuanshen.common.json.utils.JsonUtils;
import com.fuyuanshen.common.redis.utils.RedisUtils; import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.common.sse.dto.SseMessageDto;
import com.fuyuanshen.common.sse.utils.SseMessageUtils;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.DeviceLog;
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.global.mqtt.base.MqttMessageRule; import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
import com.fuyuanshen.global.mqtt.base.MqttRuleContext; import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
import com.fuyuanshen.global.mqtt.config.MqttGateway; import com.fuyuanshen.global.mqtt.config.MqttGateway;
@ -21,6 +30,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY; import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY; import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
@ -40,6 +51,18 @@ public class XinghanSendAlarmMessageRule implements MqttMessageRule {
private final MqttGateway mqttGateway; private final MqttGateway mqttGateway;
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
private final ScheduledExecutorService scheduledExecutorService;
private final DeviceLogMapper deviceLogMapper;
private final DeviceMapper deviceMapper;
/**
* 设备上行确认消息
*/
public static final String BREAK_NEWS_CONFIRMATION = "I get it";
/**
* 设备上行成功标记
*/
public static final String BREAK_NEWS_SUCCESS = "cover!";
@Override @Override
public String getCommandType() { public String getCommandType() {
@ -62,9 +85,36 @@ public class XinghanSendAlarmMessageRule implements MqttMessageRule {
log.warn("重复消息丢弃 {}", dedupKey); log.warn("重复消息丢弃 {}", dedupKey);
return; return;
} }
// 1. I get it —— 表示用户确认收到消息
if (BREAK_NEWS_CONFIRMATION.equalsIgnoreCase(respText)) {
var device = deviceMapper.selectOne(new QueryWrapper<Device>().eq("device_imei", ctx.getDeviceImei()));
// 使用MyBatis-Plus内置方法查询最新一条紧急通知
QueryWrapper<DeviceLog> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("device_id", device.getId())
.eq("device_action", "发送紧急通知") // 根据您的表结构调整
.orderByDesc("create_time")
.last("LIMIT 1");
DeviceLog latestLog = deviceLogMapper.selectOne(queryWrapper);
log.info("设备 {} 最新紧急通知:{}", ctx.getDeviceImei(), latestLog);
if (latestLog == null) {
return;
}
// 更新数据源字段
UpdateWrapper<DeviceLog> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", latestLog.getId()) // 条件ID匹配
.set("data_source", "设备已收到通知"); // 要更新的字段
deviceLogMapper.update(null, updateWrapper);
// 推送SSE消息
scheduledExecutorService.schedule(() -> {
SseMessageDto dto = new SseMessageDto();
dto.setMessage(String.format("%s设备已收到通知", latestLog.getDeviceName()));
dto.setUserIds(List.of(latestLog.getCreateBy()));
SseMessageUtils.publishMessage(dto);
}, 2, TimeUnit.SECONDS);
return;
}
// 1. cover! —— 成功标记 // 1. cover! —— 成功标记
if ("cover!".equalsIgnoreCase(respText)) { if (BREAK_NEWS_SUCCESS.equalsIgnoreCase(respText)) {
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20)); RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
log.info("设备 {} 发送紧急通知完成", ctx.getDeviceImei()); log.info("设备 {} 发送紧急通知完成", ctx.getDeviceImei());
return; return;

View File

@ -0,0 +1,106 @@
package com.fuyuanshen.global.mqtt.service;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.global.mqtt.base.MqttMessage;
/**
* 通用IoT设备MQTT协议服务接口
* 遵循统一的MQTT通信协议规范
*/
public interface IotMqttService {
/**
* 构建下发指令主题
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @return 指令主题
*/
String buildCommandTopic(String tenantCode, Long deviceType, String imei);
/**
* 构建响应数据主题
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @return 响应主题
*/
String buildStatusTopic(String tenantCode, String deviceType, String imei);
/**
* 构建设备上报数据主题
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @return 上报主题
*/
String buildReportTopic(String tenantCode, String deviceType, String imei);
/**
* 发送指令到设备
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 指令消息 (JSON格式)
*/
void sendCommand(String tenantCode, Long deviceType, String imei, MqttMessage message);
/**
* 发送响应消息到设备
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 响应消息 (JSON格式)
*/
void sendStatus(String tenantCode, String deviceType, String imei, JSONObject message);
/**
* 发送设备上报数据的确认消息
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 确认消息 (JSON格式)
*/
void sendReportAck(String tenantCode, String deviceType, String imei, JSONObject message);
/**
* 处理设备上报的单个传感器数据
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param sensor 传感器名称
* @param value 传感器值
* @param timestamp 时间戳
*/
void handleSingleReport(String tenantCode, String deviceType, String imei,
String sensor, Object value, Long timestamp);
/**
* 处理设备上报的批量传感器数据
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param batchData 批量数据
* @param timestamp 时间戳
*/
void handleBatchReport(String tenantCode, String deviceType, String imei,
JSONObject batchData, Long timestamp);
/**
* 处理设备对指令的响应
*
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 响应消息 (JSON格式)
*/
void handleCommandResponse(String tenantCode, String deviceType, String imei, JSONObject message);
}

View File

@ -0,0 +1,37 @@
package com.fuyuanshen.global.mqtt.service;
import com.fuyuanshen.global.mqtt.base.MqttMessage;
/**
* MQTT消息处理服务接口
*/
public interface MqttMessageService {
/**
* 处理下发指令的响应消息
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 响应消息
*/
void handleCommandResponse(String tenantCode, String deviceType, String imei, MqttMessage message);
/**
* 处理设备主动上报的数据
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 上报消息
*/
void handleDeviceReport(String tenantCode, String deviceType, String imei, MqttMessage message);
/**
* 发送指令到设备
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 指令消息
*/
void sendCommand(String tenantCode, String deviceType, String imei, MqttMessage message);
}

View File

@ -0,0 +1,111 @@
package com.fuyuanshen.global.mqtt.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.global.mqtt.base.MqttMessage;
import com.fuyuanshen.global.mqtt.service.IotMqttService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import java.lang.reflect.Method;
/**
* 通用IoT设备MQTT协议服务实现类
* 遵循统一的MQTT通信协议规范
*/
@Slf4j
@Service
public class IotMqttServiceImpl implements IotMqttService {
@Autowired
private ApplicationContext applicationContext;
// MQTT主题前缀
private static final String COMMAND_PREFIX = "command";
private static final String STATUS_PREFIX = "status";
private static final String REPORT_PREFIX = "report";
@Override
public String buildCommandTopic(String tenantCode, Long deviceType, String imei) {
return String.format("%s/%s/%s/%s", COMMAND_PREFIX, tenantCode, deviceType, imei);
}
@Override
public String buildStatusTopic(String tenantCode, String deviceType, String imei) {
return String.format("%s/%s/%s/%s", STATUS_PREFIX, tenantCode, deviceType, imei);
}
@Override
public String buildReportTopic(String tenantCode, String deviceType, String imei) {
return String.format("%s/%s/%s/%s", REPORT_PREFIX, tenantCode, deviceType, imei);
}
@Override
public void sendCommand(String tenantCode, Long deviceType, String imei, MqttMessage message) {
String topic = buildCommandTopic(tenantCode, deviceType, imei);
String payload = JSON.toJSONString(message);
sendMqttMessage(topic, 1, payload);
log.info("发送指令到设备: topic={}, payload={}", topic, payload);
}
@Override
public void sendStatus(String tenantCode, String deviceType, String imei, JSONObject message) {
String topic = buildStatusTopic(tenantCode, deviceType, imei);
String payload = message.toJSONString();
sendMqttMessage(topic, 1, payload);
log.info("发送响应消息到设备: topic={}, payload={}", topic, payload);
}
@Override
public void sendReportAck(String tenantCode, String deviceType, String imei, JSONObject message) {
String topic = buildReportTopic(tenantCode, deviceType, imei);
String payload = message.toJSONString();
sendMqttMessage(topic, 1, payload);
log.info("发送设备上报数据确认消息: topic={}, payload={}", topic, payload);
}
@Override
public void handleSingleReport(String tenantCode, String deviceType, String imei,
String sensor, Object value, Long timestamp) {
log.info("处理设备上报的单个传感器数据: tenantCode={}, deviceType={}, imei={}, sensor={}, value={}, timestamp={}",
tenantCode, deviceType, imei, sensor, value, timestamp);
// TODO: 实现具体的业务逻辑,如更新设备状态、存储传感器数据等
}
@Override
public void handleBatchReport(String tenantCode, String deviceType, String imei,
JSONObject batchData, Long timestamp) {
log.info("处理设备上报的批量传感器数据: tenantCode={}, deviceType={}, imei={}, batchData={}, timestamp={}",
tenantCode, deviceType, imei, JSON.toJSONString(batchData), timestamp);
// TODO: 实现具体的业务逻辑,如批量更新设备状态、存储传感器数据等
}
@Override
public void handleCommandResponse(String tenantCode, String deviceType, String imei, JSONObject message) {
log.info("处理设备对指令的响应: tenantCode={}, deviceType={}, imei={}, message={}",
tenantCode, deviceType, imei, JSON.toJSONString(message));
// TODO: 实现具体的业务逻辑,如更新指令执行状态等
}
/**
* 通过反射方式发送MQTT消息
*
* @param topic 主题
* @param qos 服务质量等级
* @param payload 消息内容
*/
private void sendMqttMessage(String topic, int qos, String payload) {
try {
Object mqttGateway = applicationContext.getBean("mqttGateway");
Method sendMethod = mqttGateway.getClass().getMethod("sendMsgToMqtt", String.class, int.class, String.class);
sendMethod.invoke(mqttGateway, topic, qos, payload);
} catch (Exception e) {
log.error("发送MQTT消息失败: topic={}, payload={}", topic, payload, e);
}
}
}

View File

@ -0,0 +1,163 @@
package com.fuyuanshen.global.mqtt.service.impl;
import com.alibaba.fastjson2.JSON;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.global.mqtt.base.MqttMessage;
import com.fuyuanshen.global.mqtt.base.SensorData;
import com.fuyuanshen.global.mqtt.config.MqttGateway;
import com.fuyuanshen.global.mqtt.service.MqttMessageService;
import com.fuyuanshen.global.mqtt.utils.MqttTopicUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* MQTT消息处理服务实现类
*/
@Slf4j
@Service
public class MqttMessageServiceImpl implements MqttMessageService {
private final MqttGateway mqttGateway;
private final DeviceMapper deviceMapper;
public MqttMessageServiceImpl(MqttGateway mqttGateway, DeviceMapper deviceMapper) {
this.mqttGateway = mqttGateway;
this.deviceMapper = deviceMapper;
}
/**
* 处理下发指令的响应消息
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 响应消息
*/
@Override
public void handleCommandResponse(String tenantCode, String deviceType, String imei, MqttMessage message) {
log.info("处理设备响应消息: tenantCode={}, deviceType={}, imei={}, message={}",
tenantCode, deviceType, imei, JSON.toJSONString(message));
// 根据requestId更新指令执行状态
// TODO: 实现具体的业务逻辑,比如更新指令执行结果等
}
/**
* 处理设备主动上报的数据
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 上报消息
*/
@Override
public void handleDeviceReport(String tenantCode, String deviceType, String imei, MqttMessage message) {
log.info("处理设备上报数据: tenantCode={}, deviceType={}, imei={}, message={}",
tenantCode, deviceType, imei, JSON.toJSONString(message));
// 查找设备
Device device = deviceMapper.selectDeviceByImei(imei);
if (device == null) {
log.warn("未找到对应设备: imei={}", imei);
return;
}
// 处理批量数据上报
if (message.getBatch() != null && !message.getBatch().isEmpty()) {
for (int i = 0; i < message.getBatch().size(); i++) {
processSensorData(device, message.getBatch().get(i));
}
}
// 处理单个数据上报
else if (message.getData() != null) {
// 如果data是一个SensorData对象则处理它
// 这里可以根据实际的数据结构做相应处理
}
}
/**
* 发送指令到设备
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @param message 指令消息
*/
@Override
public void sendCommand(String tenantCode, String deviceType, String imei, MqttMessage message) {
// 构建下发指令主题
String topic = MqttTopicUtils.buildCommandTopic(tenantCode, deviceType, imei);
// 设置时间戳
if (message.getTimestamp() == null) {
message.setTimestamp(System.currentTimeMillis());
}
// 发送消息到MQTT
String payload = JSON.toJSONString(message);
mqttGateway.sendMsgToMqtt(topic, 1, payload);
log.info("发送指令到设备: topic={}, payload={}", topic, payload);
}
/**
* 处理传感器数据
* @param device 设备对象
* @param sensorData 传感器数据
*/
private void processSensorData(Device device, SensorData sensorData) {
log.info("处理传感器数据: deviceId={}, sensor={}, value={}",
device.getId(), sensorData.getSensor(), sensorData.getValue());
String sensor = sensorData.getSensor();
Object value = sensorData.getValue();
// 根据不同的传感器类型处理数据
switch (sensor) {
case "mainLightMode":
// 处理主灯模式数据
updateDeviceMainLightMode(device, value);
break;
case "mainLightBrightness":
// 处理主灯亮度数据
updateDeviceMainLightBrightness(device, value);
break;
case "batteryPercent":
// 处理电池电量数据
updateDeviceBatteryPercent(device, value);
break;
default:
log.warn("未知的传感器类型: sensor={}", sensor);
break;
}
}
/**
* 更新设备主灯模式
* @param device 设备对象
* @param value 主灯模式值
*/
private void updateDeviceMainLightMode(Device device, Object value) {
// TODO: 实现具体的业务逻辑
log.info("更新设备主灯模式: deviceId={}, value={}", device.getId(), value);
}
/**
* 更新设备主灯亮度
* @param device 设备对象
* @param value 主灯亮度值
*/
private void updateDeviceMainLightBrightness(Device device, Object value) {
// TODO: 实现具体的业务逻辑
log.info("更新设备主灯亮度: deviceId={}, value={}", device.getId(), value);
}
/**
* 更新设备电池电量
* @param device 设备对象
* @param value 电池电量值
*/
private void updateDeviceBatteryPercent(Device device, Object value) {
// TODO: 实现具体的业务逻辑
log.info("更新设备电池电量: deviceId={}, value={}", device.getId(), value);
}
}

View File

@ -0,0 +1,71 @@
package com.fuyuanshen.global.mqtt.utils;
import com.fuyuanshen.global.mqtt.base.MqttTopicInfo;
import lombok.experimental.UtilityClass;
/**
* MQTT主题处理工具类
*/
@UtilityClass
public class MqttTopicUtils {
public static final String COMMAND_PREFIX = "command";
public static final String STATUS_PREFIX = "status";
public static final String REPORT_PREFIX = "report";
/**
* 构建下发指令主题
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @return 主题字符串
*/
public static String buildCommandTopic(String tenantCode, String deviceType, String imei) {
return String.format("%s/%s/%s/%s", COMMAND_PREFIX, tenantCode, deviceType, imei);
}
/**
* 构建响应数据主题
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @return 主题字符串
*/
public static String buildStatusTopic(String tenantCode, String deviceType, String imei) {
return String.format("%s/%s/%s/%s", STATUS_PREFIX, tenantCode, deviceType, imei);
}
/**
* 构建设备上报数据主题
* @param tenantCode 租户编码
* @param deviceType 设备类型
* @param imei 设备IMEI
* @return 主题字符串
*/
public static String buildReportTopic(String tenantCode, String deviceType, String imei) {
return String.format("%s/%s/%s/%s", REPORT_PREFIX, tenantCode, deviceType, imei);
}
/**
* 解析MQTT主题
* @param topic 主题字符串
* @return 主题信息对象
*/
public static MqttTopicInfo parseTopic(String topic) {
if (topic == null || topic.isEmpty()) {
return null;
}
String[] parts = topic.split("/");
if (parts.length != 4) {
return null;
}
MqttTopicInfo info = new MqttTopicInfo();
info.setOperation(parts[0]);
info.setTenantCode(parts[1]);
info.setDeviceType(parts[2]);
info.setImei(parts[3]);
return info;
}
}

View File

@ -27,11 +27,12 @@ public class MqttMessageConsumer {
@Autowired @Autowired
private DeviceMapper deviceMapper; private DeviceMapper deviceMapper;
// 创建两个线程池:一个用于消息获取,一个用于业务处理 // 创建两个线程池:一个用于消息获取,一个用于业务处理
private ExecutorService messageConsumerPool = Executors.newFixedThreadPool(3); private ExecutorService messageConsumerPool = Executors.newFixedThreadPool(3);
private ExecutorService messageProcessorPool = Executors.newFixedThreadPool(10); private ExecutorService messageProcessorPool = Executors.newFixedThreadPool(10);
// 初始化方法,启动消息监听 // 初始化方法,启动消息监听
@PostConstruct @PostConstruct
public void start() { public void start() {
@ -130,4 +131,5 @@ public class MqttMessageConsumer {
log.error("业务处理线程 {} 处理消息时发生错误: {}", threadName, message, e); log.error("业务处理线程 {} 处理消息时发生错误: {}", threadName, message, e);
} }
} }
} }

View File

@ -22,6 +22,8 @@ public class OnlineStatusTask {
@Autowired @Autowired
private DeviceMapper deviceMapper; private DeviceMapper deviceMapper;
// 使用cron表达式每分钟的第0秒执行 // 使用cron表达式每分钟的第0秒执行
@Scheduled(cron = "0 */3 * * * ?") @Scheduled(cron = "0 */3 * * * ?")
public void cronTask() { public void cronTask() {
@ -37,4 +39,5 @@ public class OnlineStatusTask {
} }
}); });
} }
} }

View File

@ -101,13 +101,13 @@ public class AuthController {
// 登录 // 登录
LoginVo loginVo = IAuthStrategy.login(body, client, grantType); LoginVo loginVo = IAuthStrategy.login(body, client, grantType);
Long userId = LoginHelper.getUserId(); // Long userId = LoginHelper.getUserId();
scheduledExecutorService.schedule(() -> { // scheduledExecutorService.schedule(() -> {
SseMessageDto dto = new SseMessageDto(); // SseMessageDto dto = new SseMessageDto();
dto.setMessage("欢迎登录fys-Vue-Plus后台管理系统"); // dto.setMessage("欢迎登录fys-Vue-Plus后台管理系统");
dto.setUserIds(List.of(userId)); // dto.setUserIds(List.of(userId));
SseMessageUtils.publishMessage(dto); // SseMessageUtils.publishMessage(dto);
}, 5, TimeUnit.SECONDS); // }, 5, TimeUnit.SECONDS);
return R.ok(loginVo); return R.ok(loginVo);
} }

View File

@ -157,4 +157,4 @@ public class CaptchaController {
return captchaVo; return captchaVo;
} }
} }

View File

@ -98,6 +98,7 @@ public class DeviceControlCenterController extends BaseController {
return R.ok(appDeviceService.getDeviceInfo(deviceMac)); return R.ok(appDeviceService.getDeviceInfo(deviceMac));
} }
/** /**
* 指令下发记录 * 指令下发记录
*/ */
@ -106,6 +107,7 @@ public class DeviceControlCenterController extends BaseController {
return appDeviceService.getInstructionRecord(dto, pageQuery); return appDeviceService.getInstructionRecord(dto, pageQuery);
} }
/** /**
* 导出 * 导出
*/ */

View File

@ -59,6 +59,7 @@ public class DeviceFenceAccessRecordController extends BaseController {
ExcelUtil.exportExcel(list, "围栏进出记录", DeviceFenceAccessRecordVo.class, response); ExcelUtil.exportExcel(list, "围栏进出记录", DeviceFenceAccessRecordVo.class, response);
} }
/** /**
* 获取围栏进出记录详细信息 * 获取围栏进出记录详细信息
* *

View File

@ -3,6 +3,7 @@ package com.fuyuanshen.web.controller.device.fence;
import java.util.List; import java.util.List;
import com.fuyuanshen.equipment.domain.bo.DeviceGeoFenceBo; import com.fuyuanshen.equipment.domain.bo.DeviceGeoFenceBo;
import com.fuyuanshen.equipment.domain.bo.FenceTerminalBo;
import com.fuyuanshen.equipment.domain.dto.FenceCheckResponse; import com.fuyuanshen.equipment.domain.dto.FenceCheckResponse;
import com.fuyuanshen.equipment.domain.query.FenceCheckRequest; import com.fuyuanshen.equipment.domain.query.FenceCheckRequest;
import com.fuyuanshen.equipment.domain.vo.DeviceGeoFenceVo; import com.fuyuanshen.equipment.domain.vo.DeviceGeoFenceVo;
@ -102,6 +103,7 @@ public class DeviceGeoFenceController extends BaseController {
return toAjax(deviceGeoFenceService.updateByBo(bo)); return toAjax(deviceGeoFenceService.updateByBo(bo));
} }
/** /**
* 删除电子围栏 * 删除电子围栏
* *
@ -129,4 +131,26 @@ public class DeviceGeoFenceController extends BaseController {
return ResponseEntity.ok(response); return ResponseEntity.ok(response);
} }
/**
* 添加电子围栏终端
*
* @param bo
* @return
*/
@PostMapping("/addTerminal")
public R<Void> addFenceTerminal(@RequestBody FenceTerminalBo bo) {
return toAjax(deviceGeoFenceService.addFenceTerminal(bo));
}
/**
* 删除电子围栏终端
*
* @param bo
* @return
*/
@PostMapping("/delTerminal")
public R<Void> delFenceTerminal(@RequestBody FenceTerminalBo bo) {
return toAjax(deviceGeoFenceService.delFenceTerminal(bo));
}
} }

View File

@ -69,7 +69,12 @@ public interface DeviceBJQ6075BizService {
*/ */
public void recordDeviceLog(Long deviceId, String deviceName, String deviceAction, String content, Long operator); public void recordDeviceLog(Long deviceId, String deviceName, String deviceAction, String content, Long operator);
/**
* 注册人员信息
*
* @param bo 参数
* @return 结果
*/
public boolean registerPersonInfo(AppPersonnelInfoBo bo); public boolean registerPersonInfo(AppPersonnelInfoBo bo);
public void uploadDeviceLogo2(AppDeviceLogoUploadDto bo); public void uploadDeviceLogo2(AppDeviceLogoUploadDto bo);
@ -78,9 +83,9 @@ public interface DeviceBJQ6075BizService {
/** /**
* 灯光模式 * 灯光模式
* 0关灯1强光模式2弱光模式, 3爆闪模式, 4光模式) * (主光模式)
* 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS
*/ */
public void lightModeSettings(DeviceInstructDto params); public void lightModeSettings(DeviceInstructDto params);
// 灯光亮度设置 // 灯光亮度设置

View File

@ -59,6 +59,7 @@ public class DeviceBJQBizService {
private final MqttGateway mqttGateway; private final MqttGateway mqttGateway;
private final DeviceLogMapper deviceLogMapper; private final DeviceLogMapper deviceLogMapper;
public int sendMessage(AppDeviceSendMsgBo bo) { public int sendMessage(AppDeviceSendMsgBo bo) {
List<Long> deviceIds = bo.getDeviceIds(); List<Long> deviceIds = bo.getDeviceIds();
if (deviceIds == null || deviceIds.isEmpty()) { if (deviceIds == null || deviceIds.isEmpty()) {
@ -573,4 +574,5 @@ public class DeviceBJQBizService {
uploadDeviceLogo(dto); uploadDeviceLogo(dto);
} }
} }
} }

View File

@ -739,6 +739,7 @@ public class DeviceXinghanBizService {
device.setCreateByName(loginUser.getNickname()); device.setCreateByName(loginUser.getNickname());
device.setTypeName(deviceTypes.getTypeName()); device.setTypeName(deviceTypes.getTypeName());
device.setDeviceType(deviceTypes.getId()); device.setDeviceType(deviceTypes.getId());
device.setDevicePic(deviceTypes.getDevicePic());
if (device.getDeviceImei() != null) { if (device.getDeviceImei() != null) {
device.setPubTopic("A/" + device.getDeviceImei()); device.setPubTopic("A/" + device.getDeviceImei());
device.setSubTopic("B/" + device.getDeviceImei()); device.setSubTopic("B/" + device.getDeviceImei());

View File

@ -27,9 +27,12 @@ import com.fuyuanshen.equipment.enums.LightModeEnum;
import com.fuyuanshen.equipment.mapper.DeviceLogMapper; import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
import com.fuyuanshen.equipment.mapper.DeviceMapper; import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper; import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
import com.fuyuanshen.global.mqtt.base.MqttMessage;
import com.fuyuanshen.global.mqtt.config.MqttGateway; import com.fuyuanshen.global.mqtt.config.MqttGateway;
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants; import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
import com.fuyuanshen.global.mqtt.constants.MqttConstants; import com.fuyuanshen.global.mqtt.constants.MqttConstants;
import com.fuyuanshen.global.mqtt.enums.DeviceFunctionType6075;
import com.fuyuanshen.global.mqtt.service.IotMqttService;
import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService; import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -60,6 +63,8 @@ public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
private final MqttGateway mqttGateway; private final MqttGateway mqttGateway;
private final DeviceLogMapper deviceLogMapper; private final DeviceLogMapper deviceLogMapper;
private final IotMqttService iotMqttService;
/** /**
* 获取设备详情 * 获取设备详情
@ -246,6 +251,12 @@ public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
} }
/**
* 注册人员信息
*
* @param bo
* @return
*/
@Override @Override
public boolean registerPersonInfo(AppPersonnelInfoBo bo) { public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
Long deviceId = bo.getDeviceId(); Long deviceId = bo.getDeviceId();
@ -259,7 +270,7 @@ public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>() QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
.eq("device_id", deviceId); .eq("device_id", deviceId);
List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw); List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw);
// unitName,position,name,id // 生成固定长度的点阵数据
byte[] unitName = generateFixedBitmapData(bo.getUnitName(), 120); byte[] unitName = generateFixedBitmapData(bo.getUnitName(), 120);
byte[] position = generateFixedBitmapData(bo.getPosition(), 120); byte[] position = generateFixedBitmapData(bo.getPosition(), 120);
byte[] name = generateFixedBitmapData(bo.getName(), 120); byte[] name = generateFixedBitmapData(bo.getName(), 120);
@ -396,12 +407,67 @@ public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
} }
} }
/** /**
* 灯光模式 * 灯光模式
* 0关灯1强光模式2弱光模式, 3爆闪模式, 4光模式) * (主光模式)
* 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS
*/ */
@Override @Override
public void lightModeSettings(DeviceInstructDto params) { public void lightModeSettings(DeviceInstructDto params) {
try {
Long deviceId = params.getDeviceId();
Device device = deviceMapper.selectById(deviceId);
if (device == null) {
throw new ServiceException("设备不存在");
}
if (getDeviceStatus(device.getDeviceImei())) {
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
}
String deviceImei = device.getDeviceImei();
Long deviceType = device.getDeviceType();
String tenantCode = device.getTenantId();
// 构建发送强光模式的MqttMessage对象
MqttMessage message = new MqttMessage();
message.setRequestId(UUID.randomUUID().toString()); // 生成唯一的请求ID
message.setImei(device.getDeviceImei()); // 设备IMEI
message.setTimestamp(System.currentTimeMillis()); // 当前时间戳
message.setFuncType(DeviceFunctionType6075.LIGHT_MODE.getNumber()); // 功能类型,这里假设为灯光模式
// 构建数据内容 - 强光模式参数
Map<String, Object> lightData = new HashMap<>();
lightData.put("mode", 1); // 1表示强光模式
lightData.put("type", "mainLight"); // 主灯类型
// 可以根据需要添加更多参数
lightData.put("brightness", 100); // 亮度设置为100%
message.setData(lightData);
// 调用sendCommand方法发送指令
iotMqttService.sendCommand(tenantCode, deviceType, deviceImei, message);
Integer instructValue = Integer.parseInt(params.getInstructValue());
ArrayList<Integer> intData = new ArrayList<>();
intData.add(1);
intData.add(instructValue);
intData.add(0);
intData.add(0);
intData.add(0);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
LightModeEnum modeEnum = LightModeEnum.getByCode(instructValue);
recordDeviceLog(device.getId(), device.getDeviceName(), "灯光模式", modeEnum != null ? modeEnum.getName() : null, AppLoginHelper.getUserId());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException("发送指令失败");
}
}
public void lightModeSettings1(DeviceInstructDto params) {
try { try {
Long deviceId = params.getDeviceId(); Long deviceId = params.getDeviceId();
Device device = deviceMapper.selectById(deviceId); Device device = deviceMapper.selectById(deviceId);
@ -430,6 +496,7 @@ public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
} }
} }
// 灯光亮度设置 // 灯光亮度设置
@Override @Override
public void lightBrightnessSettings(DeviceInstructDto params) { public void lightBrightnessSettings(DeviceInstructDto params) {

View File

@ -11,6 +11,8 @@ import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -37,63 +39,104 @@ public class VideoProcessUtil {
/** /**
* 处理视频并转换为Hex字符串列表 * 处理视频并转换为Hex字符串列表
*/ */
public List<String> processVideoToHex(File videoFile, int frameRate, int duration, int width, int height) throws Exception { public List<String> processVideoToHex(File videoFile, int frameRate, int duration, int width, int height, int code) throws Exception {
// 1. 提取视频帧 // 1. 提取视频帧
List<BufferedImage> frames = extractFramesFromVideo(videoFile, frameRate, duration, width, height); List<BufferedImage> frames = extractFramesFromVideo(videoFile, frameRate, duration, width, height);
// 2. 转换为RGB565格式 if (code == 1) {
byte[] binaryData = convertFramesToRGB565(frames); // 1. 转换为RGB565格式
byte[] binaryData = convertFramesToRGB565(frames);
// 3. 转换为Hex字符串列表 // 2. 转换为Hex字符串列表
return bytesToHexList(binaryData); return bytesToHexList(binaryData);
} else {
// 1. 转换为BGR565格式
byte[] binaryData = convertFramesToBGR565(frames);
// 新增:直接生成 mp4
//bgr565ToMp4(binaryData, width, height, frameRate, "output.mp4");
// 2. 转换为Hex字符串列表
return bytesToHexList(binaryData);
}
} }
/** /**
* 从视频中提取帧 * 从视频中提取帧
*
* @param videoFile 视频文件对象
* @param frameRate 每秒提取的帧数(帧率)
* @param duration 需要提取的视频时长(秒)
* @param width 提取帧的宽度
* @param height 提取帧的高度
* @return 提取的帧图像列表
* @throws Exception 如果在提取过程中发生错误
*/ */
private List<BufferedImage> extractFramesFromVideo(File videoFile, int frameRate, int duration, int width, int height) throws Exception { private List<BufferedImage> extractFramesFromVideo(File videoFile, int frameRate, int duration, int width, int height) throws Exception {
// 初始化帧列表
List<BufferedImage> frames = new ArrayList<>(); List<BufferedImage> frames = new ArrayList<>();
// 计算需要提取的总帧数 = 帧率 × 时长
int totalFramesToExtract = frameRate * duration; int totalFramesToExtract = frameRate * duration;
// 使用FFmpegFrameGrabber从视频文件中抓取帧
try (FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(videoFile)) { try (FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(videoFile)) {
// 启动抓取器
grabber.start(); grabber.start();
// 获取视频总帧数
long totalFramesInVideo = grabber.getLengthInFrames(); long totalFramesInVideo = grabber.getLengthInFrames();
// 获取视频帧率如果获取不到则默认为30fps
int fps = (int) Math.round(grabber.getFrameRate()); int fps = (int) Math.round(grabber.getFrameRate());
if (fps <= 0) fps = 30; if (fps <= 0) fps = 30;
// 计算视频总时长(秒)
double durationSeconds = (double) totalFramesInVideo / fps; double durationSeconds = (double) totalFramesInVideo / fps;
// 检查视频时长是否满足要求
if (durationSeconds < duration) { if (durationSeconds < duration) {
throw new IllegalArgumentException("视频太短,至少需要 " + duration + ""); throw new IllegalArgumentException("视频太短,至少需要 " + duration + "");
} }
// 计算帧间隔,用于均匀分布提取的帧
double frameInterval = (double) totalFramesInVideo / totalFramesToExtract; double frameInterval = (double) totalFramesInVideo / totalFramesToExtract;
// 循环提取指定数量的帧
for (int i = 0; i < totalFramesToExtract; i++) { for (int i = 0; i < totalFramesToExtract; i++) {
// 计算目标帧号
int targetFrameNumber = (int) Math.round(i * frameInterval); int targetFrameNumber = (int) Math.round(i * frameInterval);
// 检查目标帧号是否超出视频范围
if (targetFrameNumber >= totalFramesInVideo) { if (targetFrameNumber >= totalFramesInVideo) {
throw new IllegalArgumentException("目标帧超出范围: " + targetFrameNumber); throw new IllegalArgumentException("目标帧超出范围: " + targetFrameNumber);
} }
// 设置抓取器到目标帧
grabber.setFrameNumber(targetFrameNumber); grabber.setFrameNumber(targetFrameNumber);
// 抓取当前帧
Frame frame = grabber.grab(); Frame frame = grabber.grab();
// 如果成功抓取到帧且帧图像不为空
if (frame != null && frame.image != null) { if (frame != null && frame.image != null) {
// 将帧转换为BufferedImage并裁剪到指定尺寸
BufferedImage bufferedImage = Java2DFrameUtils.toBufferedImage(frame); BufferedImage bufferedImage = Java2DFrameUtils.toBufferedImage(frame);
frames.add(cropImage(bufferedImage, width, height)); frames.add(cropImage(bufferedImage, width, height));
} else { } else {
// 如果无法获取帧则抛出异常
throw new IllegalArgumentException("无法获取第 " + targetFrameNumber + ""); throw new IllegalArgumentException("无法获取第 " + targetFrameNumber + "");
} }
} }
// 停止抓取器
grabber.stop(); grabber.stop();
} }
// 记录提取的帧数
log.debug("从视频中提取了 {} 帧", frames.size()); log.debug("从视频中提取了 {} 帧", frames.size());
// 返回提取的帧列表
return frames; return frames;
} }
/** /**
* 将所有帧转换为 RGB565 格式字节数组 * 将所有帧转换为 RGB565 格式字节数组
*/ */
@ -110,6 +153,55 @@ public class VideoProcessUtil {
return result; return result;
} }
/**
* 将所有帧转换为 BGR565 格式字节数组
*/
private byte[] convertFramesToBGR565(List<BufferedImage> frames) throws Exception {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
for (BufferedImage image : frames) {
byte[] bgr565Bytes = convertToBGR565(image);
byteArrayOutputStream.write(bgr565Bytes);
}
byte[] result = byteArrayOutputStream.toByteArray();
log.debug("转换BGR565数据完成总字节数: {}", result.length);
return result;
}
/**
* 将BufferedImage转换为真正的BGR565格式字节数组
*/
private byte[] convertToBGR565(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
byte[] bgr565Data = new byte[width * height * 2];
int index = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int rgb = image.getRGB(x, y);
// 提取RGB分量
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = rgb & 0xFF;
int b = (blue >> 3) & 0x1F; // 5位蓝色
int g = (green >> 2) & 0x3F; // 6位绿色
int r = (red >> 3) & 0x1F; // 5位红色
// 正确的BGR565组合红色在高位蓝色在低位
int bgr565 = (b << 11) | (g << 5) | r;
bgr565Data[index++] = (byte) ((bgr565 >> 8) & 0xFF);
// 小端序存储
bgr565Data[index++] = (byte) (bgr565 & 0xFF);
}
}
return bgr565Data;
}
/** /**
* 将字节数组转换为Hex字符串列表 * 将字节数组转换为Hex字符串列表
*/ */
@ -191,4 +283,76 @@ public class VideoProcessUtil {
} }
} }
} }
/**
* 把 BGR565 字节流直接写成 MP4H.264
* @param bgr565 完整的 BGR565 裸帧流(每像素 2 字节)
* @param width 帧宽
* @param height 帧高
* @param fps 帧率
* @param outMp4 输出 mp4 文件绝对路径
* @throws IOException 进程启动 / IO 失败
*/
public static void bgr565ToMp4(byte[] bgr565,
int width,
int height,
int fps,
String outMp4) throws IOException {
int framePixels = width * height;
int frameBytes = framePixels * 2;
if (bgr565.length % frameBytes != 0) {
throw new IllegalArgumentException("字节数组长度不是整帧");
}
/* 1. 构造 FFmpeg 命令 */
String[] cmd = {
"ffmpeg",
"-y", // 覆盖输出
"-f", "rawvideo",
"-pixel_format", "bgr24",
"-video_size", width + "x" + height,
"-framerate", String.valueOf(fps),
"-i", "-", // 从 stdin 读
"-c:v", "libx264",
"-pix_fmt", "yuv420p",
"-crf", "23", // 画质可自己调
outMp4
};
/* 2. 启动进程 */
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectError(ProcessBuilder.Redirect.INHERIT); // 把 FFmpeg 日志打到控制台
Process p = pb.start();
try (OutputStream ffmpegIn = p.getOutputStream()) {
/* 3. 逐帧转换并写入管道 */
byte[] bgr24 = new byte[framePixels * 3];
for (int off = 0; off < bgr565.length; off += frameBytes) {
for (int i = 0, j = 0; i < frameBytes; i += 2, j += 3) {
int u = ((bgr565[off + i + 1] & 0xFF) << 8)
| (bgr565[off + i] & 0xFF);
int b = (u & 0x1F) << 3;
int g = ((u >> 5) & 0x3F) << 2;
int r = ((u >> 11) & 0x1F) << 3;
bgr24[j] = (byte) b;
bgr24[j + 1] = (byte) g;
bgr24[j + 2] = (byte) r;
}
ffmpegIn.write(bgr24);
}
ffmpegIn.flush();
}
/* 4. 等待编码结束 */
try {
int exit = p.waitFor();
if (exit != 0) {
throw new IOException("FFmpeg 异常退出code=" + exit);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("等待 FFmpeg 被中断", e);
}
}
} }

View File

@ -55,32 +55,32 @@ spring:
url: jdbc:mysql://47.120.79.150:3306/fys-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true url: jdbc:mysql://47.120.79.150:3306/fys-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
username: root username: root
password: Jq_123456# password: Jq_123456#
# # 从库数据源 # # 从库数据源
# slave: # slave:
# lazy: true # lazy: true
# type: ${spring.datasource.type} # type: ${spring.datasource.type}
# driverClassName: com.mysql.cj.jdbc.Driver # driverClassName: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
# username: # username:
# password: # password:
# oracle: # oracle:
# type: ${spring.datasource.type} # type: ${spring.datasource.type}
# driverClassName: oracle.jdbc.OracleDriver # driverClassName: oracle.jdbc.OracleDriver
# url: jdbc:oracle:thin:@//localhost:1521/XE # url: jdbc:oracle:thin:@//localhost:1521/XE
# username: ROOT # username: ROOT
# password: root # password: root
# postgres: # postgres:
# type: ${spring.datasource.type} # type: ${spring.datasource.type}
# driverClassName: org.postgresql.Driver # driverClassName: org.postgresql.Driver
# url: jdbc:postgresql://localhost:5432/postgres?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true # url: jdbc:postgresql://localhost:5432/postgres?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
# username: root # username: root
# password: root # password: root
# sqlserver: # sqlserver:
# type: ${spring.datasource.type} # type: ${spring.datasource.type}
# driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver # driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
# url: jdbc:sqlserver://localhost:1433;DatabaseName=tempdb;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true # url: jdbc:sqlserver://localhost:1433;DatabaseName=tempdb;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true
# username: SA # username: SA
# password: root # password: root
hikari: hikari:
# 最大连接池数量 # 最大连接池数量
maxPoolSize: 20 maxPoolSize: 20
@ -281,10 +281,10 @@ justauth:
mqtt: mqtt:
username: admin username: admin
password: #YtvpSfCNG password: #YtvpSfCNG
url: tcp://47.120.79.150:2883 url: tcp://47.120.79.150:3883
subClientId: fys_subClient subClientId: fys_subClient
subTopic: A/#,B/#,worker/location/# subTopic: A/#,status/tenantCode/#,report/tenantCode/#
pubTopic: B/# pubTopic: B/#,command/tenantCode/#
pubClientId: fys_pubClient pubClientId: fys_pubClient
# TTS语音交互配置 # TTS语音交互配置

View File

@ -269,4 +269,4 @@ justauth:
server-url: https://demo.gitea.com server-url: https://demo.gitea.com
client-id: 10**********6 client-id: 10**********6
client-secret: 1f7d08**********5b7**********29e client-secret: 1f7d08**********5b7**********29e
redirect-uri: ${justauth.address}/social-callback?source=gitea redirect-uri: ${justauth.address}/social-callback?source=gitea

View File

@ -69,9 +69,9 @@ spring:
servlet: servlet:
multipart: multipart:
# 单个文件大小 # 单个文件大小
max-file-size: 10MB max-file-size: 100MB
# 设置总上传的文件大小 # 设置总上传的文件大小
max-request-size: 20MB max-request-size: 200MB
mvc: mvc:
# 设置静态资源路径 防止所有请求都去查静态资源 # 设置静态资源路径 防止所有请求都去查静态资源
static-path-pattern: /static/** static-path-pattern: /static/**
@ -132,6 +132,8 @@ tenant:
- app_menu - app_menu
- app_user_role - app_user_role
- app_role_menu - app_role_menu
- track_service
- device_fence_terminal
# MyBatisPlus配置 # MyBatisPlus配置
# https://baomidou.com/config/ # https://baomidou.com/config/

View File

@ -77,4 +77,9 @@ public interface SystemConstants {
*/ */
String ROOT_DEPT_ANCESTORS = "0"; String ROOT_DEPT_ANCESTORS = "0";
/**
* 菜单ID
*/
public static final Long RESTRICTED_MENU_ID = 102L;
} }

View File

@ -27,14 +27,14 @@ public class Bitmap80x12Generator {
BufferedImage image = convertByteArrayToImage(bytes, 12, 80); BufferedImage image = convertByteArrayToImage(bytes, 12, 80);
ImageIO.write(image, "PNG", new File("D:\\bitmap_preview.png")); ImageIO.write(image, "PNG", new File("D:\\bitmap_preview.png"));
System.out.println("成功生成预览图片: D:\\bitmap_preview.png"); System.out.println("成功生成预览图片: D:\\bitmap_preview.png");
// 打印十六进制数据 // 打印十六进制数据
// System.out.println("生成的点阵数据2:"); // System.out.println("生成的点阵数据2:");
// printHexData(bitmapData); // printHexData(bitmapData);
// int[] ints = convertHexToDecimal(bitmapData); // int[] ints = convertHexToDecimal(bitmapData);
System.out.println("打印十进制无符号:"+Arrays.toString(ints)); System.out.println("打印十进制无符号:" + Arrays.toString(ints));
// printDecimalData(bitmapData); // printDecimalData(bitmapData);
// 生成C文件 // 生成C文件
generateCFile(bitmapData, "bitmap_data.c", "chinese_text"); generateCFile(bitmapData, "bitmap_data.c", "chinese_text");
} }
@ -125,7 +125,7 @@ public class Bitmap80x12Generator {
System.out.println(); System.out.println();
} }
public static void buildArr(int[] data,List<Integer> intData){ public static void buildArr(int[] data, List<Integer> intData) {
for (int datum : data) { for (int datum : data) {
intData.add(datum); intData.add(datum);
} }
@ -133,8 +133,8 @@ public class Bitmap80x12Generator {
/** /**
* 生成固定长度的点阵数据 * 生成固定长度的点阵数据
* *
* @param text 要转换的文本 * @param text 要转换的文本
* @param fixedLength 固定长度(字节) * @param fixedLength 固定长度(字节)
* @return 固定长度的点阵数据 * @return 固定长度的点阵数据
*/ */
@ -157,10 +157,11 @@ public class Bitmap80x12Generator {
int copyLength = Math.min(rawData.length, fixedLength); int copyLength = Math.min(rawData.length, fixedLength);
System.arraycopy(rawData, 0, result, 0, copyLength); System.arraycopy(rawData, 0, result, 0, copyLength);
// 剩余部分自动初始化为0 // 剩余部分自动初始化为0
return result; return result;
} }
/** /**
* 创建文本图像 * 创建文本图像
*/ */
@ -185,14 +186,14 @@ public class Bitmap80x12Generator {
// 获取字体度量 // 获取字体度量
FontMetrics metrics = g.getFontMetrics(); FontMetrics metrics = g.getFontMetrics();
// 计算文本绘制位置(居中) // 计算文本绘制位置(居中)
int textWidth = metrics.stringWidth(text); int textWidth = metrics.stringWidth(text);
// int x = Math.max(0, (width - textWidth) / 2); // 水平居中 // int x = Math.max(0, (width - textWidth) / 2); // 水平居中
// 左对齐 // 左对齐
int x = 0; int x = 0;
int y = (height - metrics.getHeight()) / 2 + metrics.getAscent(); // 垂直居中 int y = (height - metrics.getHeight()) / 2 + metrics.getAscent(); // 垂直居中
// 绘制文本 // 绘制文本
g.drawString(text, x, y); g.drawString(text, x, y);
@ -242,6 +243,7 @@ public class Bitmap80x12Generator {
return byteListToArray(byteList); return byteListToArray(byteList);
} }
public static byte[] byteListToArray(List<Byte> byteList) { public static byte[] byteListToArray(List<Byte> byteList) {
byte[] result = new byte[byteList.size()]; byte[] result = new byte[byteList.size()];
for (int i = 0; i < byteList.size(); i++) { for (int i = 0; i < byteList.size(); i++) {
@ -282,7 +284,7 @@ public class Bitmap80x12Generator {
} }
} }
bitIndex++; bitIndex++;
// 如果已经处理完所有像素,则退出 // 如果已经处理完所有像素,则退出
if (bitIndex >= width * height) { if (bitIndex >= width * height) {
return image; return image;
@ -313,6 +315,7 @@ public class Bitmap80x12Generator {
sb.append("\n};"); sb.append("\n};");
return sb.toString(); return sb.toString();
} }
/** /**
* 打印十六进制数据 * 打印十六进制数据
*/ */
@ -320,7 +323,7 @@ public class Bitmap80x12Generator {
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
int value = data[i] & 0xFF; int value = data[i] & 0xFF;
System.out.printf("0x%02X", value); System.out.printf("0x%02X", value);
if (i < data.length - 1) { if (i < data.length - 1) {
System.out.print(", "); System.out.print(", ");
if ((i + 1) % 12 == 0) System.out.println(); if ((i + 1) % 12 == 0) System.out.println();
@ -348,6 +351,7 @@ public class Bitmap80x12Generator {
} }
} }
private static void writeByteArray(FileWriter writer, byte[] data) throws IOException { private static void writeByteArray(FileWriter writer, byte[] data) throws IOException {
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
int value = data[i] & 0xFF; int value = data[i] & 0xFF;
@ -359,4 +363,6 @@ public class Bitmap80x12Generator {
} }
} }
} }
} }

View File

@ -0,0 +1,289 @@
package com.fuyuanshen.common.core.utils.file;
import lombok.extern.slf4j.Slf4j;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Iterator;
/**
* 图片压缩工具类
*
* @author AprilWind
*/
@Slf4j
public class ImageCompressUtil {
/**
* 默认压缩目标大小(100KB)
*/
private static final int DEFAULT_COMPRESS_SIZE = 100 * 1024;
/**
* 默认触发压缩的大小(1MB)
*/
private static final int DEFAULT_TRIGGER_SIZE = 1024 * 1024;
/**
* 压缩图片到指定大小以下(默认100KB)
*
* @param imageData 原始图片数据
* @return 压缩后的图片数据
*/
public static byte[] compressImage(byte[] imageData) {
return compressImage(imageData, DEFAULT_COMPRESS_SIZE);
}
/**
* 压缩图片到指定大小以下
*
* @param imageData 原始图片数据
* @param maxSize 最大大小(字节)
* @return 压缩后的图片数据
*/
public static byte[] compressImage(byte[] imageData, int maxSize) {
try {
// 如果图片本身小于等于最大大小,直接返回
if (imageData.length <= maxSize) {
return imageData;
}
// 读取原始图片
BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(imageData));
if (originalImage == null) {
log.warn("无法读取图片数据");
return imageData;
}
// 检查图片是否包含透明度
boolean hasAlpha = hasAlpha(originalImage);
String formatName = hasAlpha ? "png" : "jpg";
// 对于小尺寸PNG图片可跳过压缩以保持图像质量
if ("png".equals(formatName) && imageData.length <= 2 * maxSize) {
log.debug("PNG图片大小适中({} bytes),跳过压缩", imageData.length);
return imageData;
}
// 先尝试质量压缩
byte[] compressedData = compressImageQuality(originalImage, formatName, 0.7f);
// 如果质量压缩后仍大于目标大小,则进行尺寸压缩
if (compressedData.length > maxSize) {
// 计算缩放比例
double scale = Math.sqrt((double) maxSize / compressedData.length);
scale = Math.max(scale, 0.2); // 最小缩放到原来的20%
// 尺寸压缩
compressedData = compressImageByScale(originalImage, scale, formatName);
}
// 如果压缩后还是太大,继续压缩
int attempts = 0;
while (compressedData.length > maxSize && attempts < 15) { // 增加尝试次数到15次
// 优先降低质量
float quality = Math.max(0.01f, 0.7f - attempts * 0.1f); // 最低质量降至0.01
compressedData = compressImageQuality(originalImage, formatName, quality);
// 如果质量压缩不够,再缩小尺寸
if (compressedData.length > maxSize) {
double scale = 0.8 - attempts * 0.15; // 更积极地缩小尺寸
scale = Math.max(scale, 0.1); // 最小缩放到原来的10%
compressedData = compressImageByScale(originalImage, scale, formatName);
}
attempts++;
}
// 如果经过多次尝试仍然大于目标大小,则强制压缩到目标大小以下
if (compressedData.length > maxSize) {
// 强制尺寸压缩到目标大小
double finalScale = Math.sqrt((double) maxSize / compressedData.length) * 0.8; // 留一些余量
finalScale = Math.max(finalScale, 0.05); // 至少保留5%的尺寸
compressedData = compressImageByScale(originalImage, finalScale, formatName);
// 如果仍然太大,强制质量压缩
if (compressedData.length > maxSize) {
// 计算需要的质量值
float finalQuality = (float) maxSize / compressedData.length * 0.7f; // 留一些余量
finalQuality = Math.max(finalQuality, 0.005f); // 至少保留0.5%的质量
compressedData = compressImageQuality(originalImage, formatName, finalQuality);
}
}
log.info("图片压缩完成,原始大小: {} bytes, 压缩后大小: {} bytes, 压缩率: {}%",
imageData.length, compressedData.length,
String.format("%.2f", (1.0 - (double) compressedData.length / imageData.length) * 100));
// 如果压缩后反而变大了,则使用原始数据
if (compressedData.length >= imageData.length) {
log.debug("压缩后数据变大,使用原始数据");
return imageData;
}
// 特殊处理如果目标大小是50KB或更小确保最终结果符合要求
if (maxSize <= 50 * 1024 && compressedData.length > maxSize) {
// 使用更强力的压缩策略
compressedData = forceCompressToSize(originalImage, formatName, maxSize);
}
return compressedData;
} catch (Exception e) {
log.error("图片压缩失败: {}", e.getMessage(), e);
return imageData; // 压缩失败时返回原始数据
}
}
/**
* 强制压缩到指定大小
*
* @param originalImage 原始图片
* @param formatName 图片格式
* @param maxSize 目标大小
* @return 压缩后的图片数据
*/
private static byte[] forceCompressToSize(BufferedImage originalImage, String formatName, int maxSize) throws IOException {
byte[] result = null;
int width = originalImage.getWidth();
int height = originalImage.getHeight();
// 通过不断缩小尺寸来达到目标大小
double scale = 0.9;
do {
int newWidth = (int) (width * scale);
int newHeight = (int) (height * scale);
// 创建缩放后的图片
Image scaledImage = originalImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);
BufferedImage bufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bufferedImage.createGraphics();
// 绘制缩放后的图片
g2d.drawImage(scaledImage, 0, 0, null);
g2d.dispose();
// 以最低质量压缩
result = compressImageQuality(bufferedImage, formatName, 0.01f);
if (result.length <= maxSize) {
break;
}
scale -= 0.1;
} while (scale > 0.1 && result.length > maxSize);
// 如果还是太大,强制调整大小
if (result.length > maxSize) {
// 计算精确的缩放比例
double targetScale = Math.sqrt((double) maxSize / result.length) * 0.9;
int newWidth = Math.max((int) (width * targetScale), 5);
int newHeight = Math.max((int) (height * targetScale), 5);
Image scaledImage = originalImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);
BufferedImage bufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bufferedImage.createGraphics();
g2d.drawImage(scaledImage, 0, 0, null);
g2d.dispose();
result = compressImageQuality(bufferedImage, formatName, 0.005f);
}
return result;
}
/**
* 按比例缩放图片
*
* @param originalImage 原始图片
* @param scale 缩放比例
* @param formatName 图片格式
* @return 缩放后的图片数据
* @throws IOException IO异常
*/
private static byte[] compressImageByScale(BufferedImage originalImage, double scale, String formatName) throws IOException {
int width = (int) (originalImage.getWidth() * scale);
int height = (int) (originalImage.getHeight() * scale);
// 确保最小尺寸不小于5像素
width = Math.max(width, 5);
height = Math.max(height, 5);
// 创建缩放后的图片
Image scaledImage = originalImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bufferedImage.createGraphics();
// 绘制缩放后的图片
g2d.drawImage(scaledImage, 0, 0, null);
g2d.dispose();
// 输出为指定格式
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, formatName, baos);
return baos.toByteArray();
}
/**
* 按质量压缩图片
*
* @param originalImage 原始图片
* @param formatName 图片格式
* @param quality 压缩质量(0.1-1.0)
* @return 压缩后的图片数据
* @throws IOException IO异常
*/
private static byte[] compressImageQuality(BufferedImage originalImage, String formatName, float quality) throws IOException {
// 创建压缩参数
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(formatName);
if (!writers.hasNext()) {
log.warn("找不到合适的图片写入器");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(originalImage, formatName, baos);
return baos.toByteArray();
}
ImageWriter writer = writers.next();
ImageWriteParam param = writer.getDefaultWriteParam();
// 设置压缩参数
if (param.canWriteCompressed()) {
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(quality);
}
// 写入压缩后的图片数据
ByteArrayOutputStream compressedOutputStream = new ByteArrayOutputStream();
writer.setOutput(ImageIO.createImageOutputStream(compressedOutputStream));
writer.write(null, new javax.imageio.IIOImage(originalImage, null, null), param);
writer.dispose();
return compressedOutputStream.toByteArray();
}
/**
* 检查图片是否包含透明度
*
* @param image 图片
* @return 是否包含透明度
*/
private static boolean hasAlpha(BufferedImage image) {
return image.getType() == BufferedImage.TYPE_4BYTE_ABGR ||
image.getType() == BufferedImage.TYPE_INT_ARGB ||
image.getColorModel().hasAlpha();
}
/**
* 判断图片是否需要压缩(超过1MB)
*
* @param imageData 图片数据
* @return 是否需要压缩
*/
public static boolean needCompress(byte[] imageData) {
return imageData.length > DEFAULT_TRIGGER_SIZE;
}
}

View File

@ -39,8 +39,8 @@ public class EncryptUtilsTest {
loginBody.setClientId("e5cd7e4891bf95d1d19206ce24a7b32e"); loginBody.setClientId("e5cd7e4891bf95d1d19206ce24a7b32e");
loginBody.setGrantType("password"); loginBody.setGrantType("password");
loginBody.setTenantId("894078"); loginBody.setTenantId("894078");
loginBody.setCode("0"); loginBody.setCode("15");
loginBody.setUuid("1d6615668c7f410da77c4e002c601073"); loginBody.setUuid("28ecf3d396ce4e6db8eb414992235fad");
// loginBody.setUsername("admin"); // loginBody.setUsername("admin");
// loginBody.setPassword("admin123"); // loginBody.setPassword("admin123");
loginBody.setUsername("dyf"); loginBody.setUsername("dyf");

View File

@ -74,6 +74,7 @@ public class ExcelUtil {
return listener.getExcelResult(); return listener.getExcelResult();
} }
/** /**
* 导出excel * 导出excel
* *
@ -92,6 +93,7 @@ public class ExcelUtil {
} }
} }
/** /**
* 导出excel * 导出excel
* *
@ -174,6 +176,7 @@ public class ExcelUtil {
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, OutputStream os, List<DropDownOptions> options) { public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, OutputStream os, List<DropDownOptions> options) {
exportExcel(list, sheetName, clazz, false, os, options); exportExcel(list, sheetName, clazz, false, os, options);
} }
/** /**
* 导出excel * 导出excel
@ -187,13 +190,13 @@ public class ExcelUtil {
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, boolean merge, public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, boolean merge,
OutputStream os, List<DropDownOptions> options) { OutputStream os, List<DropDownOptions> options) {
ExcelWriterSheetBuilder builder = FastExcel.write(os, clazz) ExcelWriterSheetBuilder builder = FastExcel.write(os, clazz)
.autoCloseStream(false) .autoCloseStream(false)
// 自动适配 // 自动适配
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
// 大数值自动转换 防止失真 // 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert()) .registerConverter(new ExcelBigNumberConvert())
.registerWriteHandler(new DataWriteHandler(clazz)) .registerWriteHandler(new DataWriteHandler(clazz))
.sheet(sheetName); .sheet(sheetName);
if (merge) { if (merge) {
// 合并处理器 // 合并处理器
builder.registerWriteHandler(new CellMergeStrategy(list, true)); builder.registerWriteHandler(new CellMergeStrategy(list, true));
@ -203,6 +206,7 @@ public class ExcelUtil {
builder.doWrite(list); builder.doWrite(list);
} }
/** /**
* 单表多数据模板导出 模板格式为 {.属性} * 单表多数据模板导出 模板格式为 {.属性}
* *
@ -238,12 +242,12 @@ public class ExcelUtil {
public static <T> void exportTemplate(List<T> data, String templatePath, OutputStream os) { public static <T> void exportTemplate(List<T> data, String templatePath, OutputStream os) {
ClassPathResource templateResource = new ClassPathResource(templatePath); ClassPathResource templateResource = new ClassPathResource(templatePath);
ExcelWriter excelWriter = FastExcel.write(os) ExcelWriter excelWriter = FastExcel.write(os)
.withTemplate(templateResource.getStream()) .withTemplate(templateResource.getStream())
.autoCloseStream(false) .autoCloseStream(false)
// 大数值自动转换 防止失真 // 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert()) .registerConverter(new ExcelBigNumberConvert())
.registerWriteHandler(new DataWriteHandler(data.get(0).getClass())) .registerWriteHandler(new DataWriteHandler(data.get(0).getClass()))
.build(); .build();
WriteSheet writeSheet = FastExcel.writerSheet().build(); WriteSheet writeSheet = FastExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
// 单表多数据导出 模板格式为 {.属性} // 单表多数据导出 模板格式为 {.属性}
@ -311,11 +315,11 @@ public class ExcelUtil {
public static void exportTemplateMultiList(Map<String, Object> data, String templatePath, OutputStream os) { public static void exportTemplateMultiList(Map<String, Object> data, String templatePath, OutputStream os) {
ClassPathResource templateResource = new ClassPathResource(templatePath); ClassPathResource templateResource = new ClassPathResource(templatePath);
ExcelWriter excelWriter = FastExcel.write(os) ExcelWriter excelWriter = FastExcel.write(os)
.withTemplate(templateResource.getStream()) .withTemplate(templateResource.getStream())
.autoCloseStream(false) .autoCloseStream(false)
// 大数值自动转换 防止失真 // 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert()) .registerConverter(new ExcelBigNumberConvert())
.build(); .build();
WriteSheet writeSheet = FastExcel.writerSheet().build(); WriteSheet writeSheet = FastExcel.writerSheet().build();
for (Map.Entry<String, Object> map : data.entrySet()) { for (Map.Entry<String, Object> map : data.entrySet()) {
// 设置列表后续还有数据 // 设置列表后续还有数据
@ -342,11 +346,11 @@ public class ExcelUtil {
public static void exportTemplateMultiSheet(List<Map<String, Object>> data, String templatePath, OutputStream os) { public static void exportTemplateMultiSheet(List<Map<String, Object>> data, String templatePath, OutputStream os) {
ClassPathResource templateResource = new ClassPathResource(templatePath); ClassPathResource templateResource = new ClassPathResource(templatePath);
ExcelWriter excelWriter = FastExcel.write(os) ExcelWriter excelWriter = FastExcel.write(os)
.withTemplate(templateResource.getStream()) .withTemplate(templateResource.getStream())
.autoCloseStream(false) .autoCloseStream(false)
// 大数值自动转换 防止失真 // 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert()) .registerConverter(new ExcelBigNumberConvert())
.build(); .build();
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
WriteSheet writeSheet = FastExcel.writerSheet(i).build(); WriteSheet writeSheet = FastExcel.writerSheet(i).build();
for (Map.Entry<String, Object> map : data.get(i).entrySet()) { for (Map.Entry<String, Object> map : data.get(i).entrySet()) {

View File

@ -216,4 +216,5 @@ public class LogAspect {
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|| o instanceof BindingResult; || o instanceof BindingResult;
} }
} }

View File

@ -0,0 +1,79 @@
package com.fuyuanshen.app.controller;
import com.fuyuanshen.app.domain.AppDeviceVoice;
import com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo;
import com.fuyuanshen.app.service.IAppDeviceVoiceService;
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.core.validate.QueryGroup;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import jakarta.validation.constraints.NotNull;
import java.util.Arrays;
/**
* 设备语音Controller
*
* @author Lion Li
* @date 2025-07-02
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/device/voice")
public class AppDeviceVoiceController extends BaseController {
private final IAppDeviceVoiceService appDeviceVoiceService;
/**
* 查询设备语音列表
*/
@GetMapping("/list")
public TableDataInfo<AppDeviceVoice> list(AppDeviceVoiceBo bo, PageQuery pageQuery) {
return appDeviceVoiceService.queryPageList(bo, pageQuery);
}
/**
* 获取设备语音详细信息
*
* @param id 主键
*/
@GetMapping("/{id}")
public R<AppDeviceVoice> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
return R.ok(appDeviceVoiceService.queryById(id));
}
/**
* 新增设备语音
*/
@PostMapping()
public R<Void> add(@RequestPart("bo") @Validated(AddGroup.class) AppDeviceVoiceBo bo,
@RequestPart(value = "file", required = false) MultipartFile file) {
return toAjax(appDeviceVoiceService.insertByBo(bo, file));
}
/**
* 修改设备语音
*/
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppDeviceVoiceBo bo) {
return toAjax(appDeviceVoiceService.updateByBo(bo));
}
/**
* 删除设备语音
*
* @param ids 主键串
*/
@DeleteMapping("/{ids}")
public R<Void> remove(@NotNull(message = "主键不能为空") @PathVariable Long[] ids) {
return toAjax(appDeviceVoiceService.deleteWithValidByIds(Arrays.asList(ids), true));
}
}

View File

@ -0,0 +1,72 @@
package com.fuyuanshen.app.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fuyuanshen.common.tenant.core.TenantEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
/**
* 设备语音
*
* @author Lion Li
* @date 2025-07-02
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("app_device_voice")
public class AppDeviceVoice extends TenantEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@TableId(value = "id")
private Long id;
/**
* 视频名称
*/
private String videoName;
/**
* 视频链接
*/
private String videoUrl;
/**
* 设备di
*/
private Long deviceId;
/**
* 备注
*/
private String remark;
/**
* 文件类型
* audio/mp3, audio/wav 等
*/
private String type;
/**
* 时长(秒)
*/
private Integer duration;
/**
* 文件大小(字节)
*/
private Long size;
/**
* 封面图URL
*/
private String cover;
}

View File

@ -0,0 +1,71 @@
package com.fuyuanshen.app.domain.bo;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.core.validate.EditGroup;
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
/**
* 设备语音业务对象 app_device_voice
*
* @author Lion Li
* @date 2025-07-02
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class AppDeviceVoiceBo extends BaseEntity {
/**
* 主键id
*/
@NotNull(message = "主键id不能为空", groups = { EditGroup.class })
private Long id;
/**
* 视频名称
*/
@NotBlank(message = "视频名称不能为空", groups = { AddGroup.class, EditGroup.class })
private String videoName;
/**
* 视频链接
*/
@NotBlank(message = "视频链接不能为空", groups = { AddGroup.class, EditGroup.class })
private String videoUrl;
/**
* 设备di
*/
@NotNull(message = "设备di不能为空", groups = { AddGroup.class, EditGroup.class })
private Long deviceId;
/**
* 备注
*/
private String remark;
/**
* 文件类型
* audio/mp3, audio/wav 等
*/
private String type;
/**
* 时长(秒)
*/
private Integer duration;
/**
* 文件大小(字节)
*/
private Long size;
/**
* 封面图URL
*/
private String cover;
}

View File

@ -64,4 +64,5 @@ public class AppPersonnelInfoBo extends BaseEntity {
* ID号 * ID号
*/ */
private String code; private String code;
} }

View File

@ -0,0 +1,52 @@
package com.fuyuanshen.app.domain.vo;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.TimeZone;
public class Main {
public static void main(String[] args) throws IOException {
String[] availableIDs = TimeZone.getAvailableIDs();
for (String id : availableIDs) {
System.out.println(id);
}
byte[] data = "hello, world!".getBytes(StandardCharsets.UTF_8);
try (CountInputStream input = new CountInputStream(new ByteArrayInputStream(data))) {
int n;
while ((n = input.read()) != -1) {
System.out.println((char)n);
}
System.out.println("Total read " + input.getBytesRead() + " bytes");
}
}
}
class CountInputStream extends FilterInputStream {
private int count = 0;
CountInputStream(InputStream in) {
super(in);
}
public int getBytesRead() {
return this.count;
}
public int read() throws IOException {
int n = in.read();
if (n != -1) {
this.count ++;
}
return n;
}
public int read(byte[] b, int off, int len) throws IOException {
int n = in.read(b, off, len);
if (n != -1) {
this.count += n;
}
return n;
}
}

View File

@ -3,6 +3,7 @@ package com.fuyuanshen.app.mapper;
import com.fuyuanshen.app.domain.AppDeviceBindRecord; import com.fuyuanshen.app.domain.AppDeviceBindRecord;
import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo; import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo;
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus; import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Param;
/** /**
* 设备绑定关系Mapper接口 * 设备绑定关系Mapper接口
@ -12,4 +13,5 @@ import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
*/ */
public interface AppDeviceBindRecordMapper extends BaseMapperPlus<AppDeviceBindRecord, AppDeviceBindRecordVo> { public interface AppDeviceBindRecordMapper extends BaseMapperPlus<AppDeviceBindRecord, AppDeviceBindRecordVo> {
Long checkDeviceExistBindRecord(@Param("deviceId") Long deviceId);
} }

View File

@ -9,6 +9,9 @@ import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus; import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/** /**
* 设备分享Mapper接口 * 设备分享Mapper接口
* *
@ -27,4 +30,6 @@ public interface AppDeviceShareMapper extends BaseMapperPlus<AppDeviceShare, App
* @return 设备分享 * @return 设备分享
*/ */
Page<AppDeviceShareVo> selectWebDeviceShareList(@Param("bo") AppDeviceShareBo bo, Page<AppDeviceShareVo> page); Page<AppDeviceShareVo> selectWebDeviceShareList(@Param("bo") AppDeviceShareBo bo, Page<AppDeviceShareVo> page);
void deleteByDeviceIds(@Param("deviceIds") Set<Long> deviceIds);
} }

View File

@ -0,0 +1,32 @@
package com.fuyuanshen.app.mapper;
import com.fuyuanshen.app.domain.AppDeviceVoice;
import com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo;
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 设备语音Mapper接口
*
* @author Lion Li
* @date 2025-07-02
*/
public interface AppDeviceVoiceMapper extends BaseMapperPlus<AppDeviceVoice, AppDeviceVoice> {
/**
* 分页查询设备语音列表
*/
Page<AppDeviceVoice> selectPage(AppDeviceVoiceBo bo, PageQuery pageQuery);
/**
* 查询设备语音列表
*/
List<AppDeviceVoice> selectList(AppDeviceVoiceBo bo);
}

View File

@ -4,6 +4,7 @@ import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo;
import com.fuyuanshen.app.domain.bo.AppDeviceBindRecordBo; import com.fuyuanshen.app.domain.bo.AppDeviceBindRecordBo;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.mybatis.core.page.PageQuery; import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import org.apache.ibatis.annotations.Param;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -65,4 +66,6 @@ public interface IAppDeviceBindRecordService {
* @return 是否删除成功 * @return 是否删除成功
*/ */
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
Long checkDeviceExistBindRecord(Long deviceId);
} }

View File

@ -7,6 +7,7 @@ import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* 设备分享Service接口 * 设备分享Service接口
@ -67,4 +68,6 @@ public interface IAppDeviceShareService {
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery); TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery);
void deleteByDeviceIds(Set<Long> deviceIds);
} }

View File

@ -0,0 +1,49 @@
package com.fuyuanshen.app.service;
import com.fuyuanshen.app.domain.AppDeviceVoice;
import com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import org.springframework.web.multipart.MultipartFile;
import java.util.Collection;
import java.util.List;
/**
* 设备语音Service接口
*
* @author Lion Li
* @date 2025-07-02
*/
public interface IAppDeviceVoiceService {
/**
* 查询设备语音
*/
AppDeviceVoice queryById(Long id);
/**
* 查询设备语音列表
*/
TableDataInfo<AppDeviceVoice> queryPageList(AppDeviceVoiceBo bo, PageQuery pageQuery);
/**
* 查询设备语音列表
*/
List<AppDeviceVoice> queryList(AppDeviceVoiceBo bo);
/**
* 根据新增业务对象插入设备语音
*/
Boolean insertByBo(AppDeviceVoiceBo bo, MultipartFile file);
/**
* 根据编辑业务对象更新设备语音
*/
Boolean updateByBo(AppDeviceVoiceBo bo);
/**
* 校验并批量删除设备语音信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}

View File

@ -130,4 +130,9 @@ public class AppDeviceBindRecordServiceImpl implements IAppDeviceBindRecordServi
} }
return baseMapper.deleteByIds(ids) > 0; return baseMapper.deleteByIds(ids) > 0;
} }
@Override
public Long checkDeviceExistBindRecord(Long deviceId) {
return baseMapper.checkDeviceExistBindRecord(deviceId);
}
} }

View File

@ -23,6 +23,7 @@ import com.fuyuanshen.app.service.IAppDeviceShareService;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Collection; import java.util.Collection;
import java.util.Set;
/** /**
* 设备分享Service业务层处理 * 设备分享Service业务层处理
@ -166,4 +167,9 @@ public class AppDeviceShareServiceImpl implements IAppDeviceShareService {
}); });
return TableDataInfo.build(result); return TableDataInfo.build(result);
} }
@Override
public void deleteByDeviceIds(Set<Long> deviceIds) {
baseMapper.deleteByDeviceIds(deviceIds);
}
} }

View File

@ -0,0 +1,130 @@
package com.fuyuanshen.app.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.app.domain.AppDeviceVoice;
import com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo;
import com.fuyuanshen.app.mapper.AppDeviceVoiceMapper;
import com.fuyuanshen.app.service.IAppDeviceVoiceService;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.oss.core.OssClient;
import com.fuyuanshen.common.oss.entity.UploadResult;
import com.fuyuanshen.common.oss.factory.OssFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.Collection;
import java.util.List;
/**
* 设备语音Service业务层处理
*
* @author Lion Li
* @date 2025-07-02
*/
@RequiredArgsConstructor
@Service
public class AppDeviceVoiceServiceImpl implements IAppDeviceVoiceService {
private final AppDeviceVoiceMapper baseMapper;
/**
* 查询设备语音
*/
@Override
public AppDeviceVoice queryById(Long id) {
return baseMapper.selectById(id);
}
/**
* 查询设备语音列表
*/
@Override
public TableDataInfo<AppDeviceVoice> queryPageList(AppDeviceVoiceBo bo, PageQuery pageQuery) {
Page<AppDeviceVoice> page = baseMapper.selectPage(bo, pageQuery);
return TableDataInfo.build(page);
}
/**
* 查询设备语音列表
*/
@Override
public List<AppDeviceVoice> queryList(AppDeviceVoiceBo bo) {
return baseMapper.selectList(bo);
}
/**
* 根据新增业务对象插入设备语音
*/
@Override
public Boolean insertByBo(AppDeviceVoiceBo bo, MultipartFile file) {
// 上传文件到MinIO
String videoUrl = "";
String coverUrl = "";
Long size = 0L;
Integer duration = 0;
String type = "";
if (file != null && !file.isEmpty()) {
try {
OssClient storage = OssFactory.instance();
String suffix = "";
String originalFilename = file.getOriginalFilename();
if (originalFilename != null && originalFilename.lastIndexOf(".") > 0) {
suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
}
UploadResult result = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
videoUrl = result.getUrl();
size = file.getSize();
type = file.getContentType();
// TODO: 可以通过其他方式获取音频时长,这里暂时设置为默认值
duration = 0;
// TODO: 可以生成封面图,这里暂时设置为空
coverUrl = "";
} catch (Exception e) {
// 文件上传失败处理
throw new RuntimeException("文件上传失败: " + e.getMessage());
}
}
AppDeviceVoice add = new AppDeviceVoice();
add.setVideoName(bo.getVideoName());
add.setVideoUrl(videoUrl);
add.setDeviceId(bo.getDeviceId());
add.setRemark(bo.getRemark());
add.setType(type);
add.setDuration(duration);
add.setSize(size);
add.setCover(coverUrl);
return baseMapper.insert(add) > 0;
}
/**
* 根据编辑业务对象更新设备语音
*/
@Override
public Boolean updateByBo(AppDeviceVoiceBo bo) {
AppDeviceVoice update = new AppDeviceVoice();
update.setId(bo.getId());
update.setVideoName(bo.getVideoName());
update.setDeviceId(bo.getDeviceId());
update.setRemark(bo.getRemark());
return baseMapper.updateById(update) > 0;
}
/**
* 校验并批量删除设备语音信息
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (ids == null || ids.isEmpty()) {
return false;
}
// TODO: 可以在这里添加删除MinIO文件的逻辑
return baseMapper.deleteBatchIds(ids) > 0;
}
}

View File

@ -4,4 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper"> <mapper namespace="com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper">
<select id="checkDeviceExistBindRecord" resultType="java.lang.Long">
select count(1) from app_device_bind_record where device_id = #{deviceId}
</select>
</mapper> </mapper>

View File

@ -3,6 +3,12 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuyuanshen.app.mapper.AppDeviceShareMapper"> <mapper namespace="com.fuyuanshen.app.mapper.AppDeviceShareMapper">
<delete id="deleteByDeviceIds">
delete from app_device_share where device_id in
<foreach item="item" collection="deviceIds" separator="," open="(" close=")">
#{item}
</foreach>
</delete>
<select id="otherDeviceShareList" resultType="com.fuyuanshen.app.domain.vo.AppDeviceShareVo"> <select id="otherDeviceShareList" resultType="com.fuyuanshen.app.domain.vo.AppDeviceShareVo">
select d.device_name, select d.device_name,

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuyuanshen.app.mapper.AppDeviceVoiceMapper">
<resultMap type="com.fuyuanshen.app.domain.AppDeviceVoice" id="AppDeviceVoiceResult">
<result property="id" column="id"/>
<result property="videoName" column="video_name"/>
<result property="videoUrl" column="video_url"/>
<result property="deviceId" column="device_id"/>
<result property="remark" column="remark"/>
<result property="type" column="type"/>
<result property="duration" column="duration"/>
<result property="size" column="size"/>
<result property="cover" column="cover"/>
<result property="tenantId" column="tenant_id"/>
<result property="createDept" column="create_dept"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<sql id="selectAppDeviceVoiceVo">
select id, video_name, video_url, device_id, remark, type, duration, size, cover, tenant_id, create_dept, create_by, create_time, update_by, update_time from app_device_voice
</sql>
<select id="selectPage" parameterType="com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo" resultMap="AppDeviceVoiceResult">
<include refid="selectAppDeviceVoiceVo"/>
<where>
<if test="videoName != null and videoName != ''"> and video_name like concat('%', #{videoName}, '%')</if>
<if test="videoUrl != null and videoUrl != ''"> and video_url = #{videoUrl}</if>
<if test="deviceId != null "> and device_id = #{deviceId}</if>
<if test="type != null and type != ''"> and type = #{type}</if>
<if test="duration != null "> and duration = #{duration}</if>
<if test="size != null "> and size = #{size}</if>
<if test="cover != null and cover != ''"> and cover = #{cover}</if>
</where>
order by create_time desc
</select>
<select id="selectList" parameterType="com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo" resultMap="AppDeviceVoiceResult">
<include refid="selectAppDeviceVoiceVo"/>
<where>
<if test="videoName != null and videoName != ''"> and video_name like concat('%', #{videoName}, '%')</if>
<if test="videoUrl != null and videoUrl != ''"> and video_url = #{videoUrl}</if>
<if test="deviceId != null "> and device_id = #{deviceId}</if>
<if test="type != null and type != ''"> and type = #{type}</if>
<if test="duration != null "> and duration = #{duration}</if>
<if test="size != null "> and size = #{size}</if>
<if test="cover != null and cover != ''"> and cover = #{cover}</if>
</where>
order by create_time desc
</select>
</mapper>

View File

@ -3,9 +3,7 @@ package com.fuyuanshen.equipment.controller;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.common.core.constant.ResponseMessageConstants;
import com.fuyuanshen.common.core.domain.R; import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.domain.ResponseVO;
import com.fuyuanshen.common.core.domain.model.LoginUser; import com.fuyuanshen.common.core.domain.model.LoginUser;
import com.fuyuanshen.common.core.utils.file.FileUtil; import com.fuyuanshen.common.core.utils.file.FileUtil;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
@ -13,12 +11,13 @@ import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.common.web.core.BaseController; import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.customer.mapper.CustomerMapper; import com.fuyuanshen.customer.mapper.CustomerMapper;
import com.fuyuanshen.equipment.domain.Device; import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.dto.DeviceExcelImportDTO; import com.fuyuanshen.equipment.domain.dto.DeviceExcelImportDTO;
import com.fuyuanshen.equipment.domain.dto.ImportResult; import com.fuyuanshen.equipment.domain.dto.ImportResult;
import com.fuyuanshen.equipment.domain.form.DeviceForm; import com.fuyuanshen.equipment.domain.form.DeviceForm;
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria; import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
import com.fuyuanshen.equipment.excel.DeviceImportParams; import com.fuyuanshen.equipment.excel.DeviceImportParams;
import com.fuyuanshen.equipment.excel.HeadValidateListener;
import com.fuyuanshen.equipment.excel.UploadDeviceDataListener; import com.fuyuanshen.equipment.excel.UploadDeviceDataListener;
import com.fuyuanshen.equipment.mapper.DeviceMapper; import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper; import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
@ -39,7 +38,10 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @Description: * @Description:
@ -70,6 +72,12 @@ public class DeviceController extends BaseController {
return deviceService.queryAll(criteria, page); return deviceService.queryAll(criteria, page);
} }
@GetMapping(value = "/pageTerminal")
public TableDataInfo<Device> deviceFenecSelect(DeviceQueryCriteria criteria) throws IOException {
Page<Device> page = new Page<>(criteria.getPageNum(), criteria.getPageSize());
return deviceService.queryAllTerminal(criteria, page);
}
// @Log("新增设备") // @Log("新增设备")
@Operation(summary = "新增设备") @Operation(summary = "新增设备")
@ -163,7 +171,7 @@ public class DeviceController extends BaseController {
@Operation(summary = "导出数据设备") @Operation(summary = "导出数据设备")
@GetMapping(value = "/download") @GetMapping(value = "/download1")
public R<Void> exportDevice(HttpServletResponse response, DeviceQueryCriteria criteria) throws IOException { public R<Void> exportDevice(HttpServletResponse response, DeviceQueryCriteria criteria) throws IOException {
List<Device> devices = deviceService.queryAll(criteria); List<Device> devices = deviceService.queryAll(criteria);
exportService.export(devices, response); exportService.export(devices, response);
@ -171,9 +179,36 @@ public class DeviceController extends BaseController {
} }
/**
* 导出设备数据(包含完整设备类型信息)
*
* @param response HttpServletResponse对象
* @param criteria 查询条件
* @return R<Void>
*/
@Operation(summary = "导出设备数据(包含完整设备类型信息)")
@GetMapping(value = "/download")
public R<Void> exportDeviceWithFullTypeInfo(HttpServletResponse response, DeviceQueryCriteria criteria) {
// 获取所有符合条件的设备
List<Device> devices = deviceService.queryAll(criteria);
// 获取所有设备类型信息
List<DeviceType> deviceTypes = deviceTypeService.queryDeviceTypes();
// 导出数据(包含完整设备类型信息)
exportService.exportWithTypeInfo(devices, deviceTypes, response);
return R.ok();
}
/**
* 导入设备数据
*
* @param file
* @return
* @throws BadRequestException
*/
@Operation(summary = "导入设备数据") @Operation(summary = "导入设备数据")
@PostMapping(value = "/import", consumes = "multipart/form-data") @PostMapping(value = "/import1", consumes = "multipart/form-data")
public R<ImportResult> importData(@Parameter(name = "文件", required = true) @RequestPart("file") MultipartFile file) throws BadRequestException { public R<ImportResult> importData1(@Parameter(name = "文件", required = true) @RequestPart("file") MultipartFile file) throws BadRequestException {
String suffix = FileUtil.getExtensionName(file.getOriginalFilename()); String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
if (!("xlsx".equalsIgnoreCase(suffix))) { if (!("xlsx".equalsIgnoreCase(suffix))) {
@ -207,6 +242,105 @@ public class DeviceController extends BaseController {
} }
} }
/**
* 导入设备数据
*
* @param file 文件
* @return R<ImportResult>
*/
@Operation(summary = "导入设备数据")
@PostMapping(value = "/import", consumes = "multipart/form-data")
public R<ImportResult> importData(@Parameter(name = "文件", required = true) @RequestPart("file") MultipartFile file) throws BadRequestException {
String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
if (!("xlsx".equalsIgnoreCase(suffix))) {
throw new BadRequestException("只能上传Excel——xlsx格式文件");
}
// 检查文件大小限制为100MB
if (file.getSize() > 100 * 10 * 1024 * 1024) {
throw new BadRequestException("文件大小不能超过100MB");
}
// 校验模板
validateExcelTemplate(file);
ImportResult result = new ImportResult();
try {
LoginUser loginUser = LoginHelper.getLoginUser();
DeviceImportParams params = DeviceImportParams.builder().ossService(ossService)
.deviceService(deviceService).tenantId(loginUser.getTenantId())
.file(file).filePath("").deviceMapper(deviceMapper).deviceTypeService(deviceTypeService)
.deviceTypeMapper(deviceTypeMapper).userId(loginUser.getUserId())
.build();
// 创建监听器
UploadDeviceDataListener listener = new UploadDeviceDataListener(params);
// 读取Excel
EasyExcel.read(file.getInputStream(), DeviceExcelImportDTO.class, listener).sheet().doRead();
// 获取导入结果
result = listener.getImportResult();
// 设置响应消息
String message = String.format("成功导入 %d 条数据,失败 %d 条", result.getSuccessCount(), result.getFailureCount());
// 返回带有正确泛型的响应
return R.ok(message, result);
} catch (Exception e) {
log.error("导入设备数据出错: {}", e.getMessage(), e);
// 在异常情况下,设置默认结果
String errorMessage = String.format("导入失败: %s。成功 %d 条,失败 %d 条", e.getMessage(), result.getSuccessCount(), result.getFailureCount());
// 使用新方法确保类型正确
return R.fail(errorMessage, result);
}
}
/**
* 校验Excel模板是否正确
*
* @param file MultipartFile对象
* @throws BadRequestException 当模板不正确时抛出异常
*/
private void validateExcelTemplate(MultipartFile file) throws BadRequestException {
try {
// 创建一个只读取表头的监听器
HeadValidateListener headValidateListener = new HeadValidateListener();
// 使用EasyExcel读取表头
EasyExcel.read(file.getInputStream(), headValidateListener)
.sheet()
.headRowNumber(0)
.doRead();
// 获取读取到的表头信息
List<String> actualHeaders = headValidateListener.getHeadNames();
// 定义必需的表头
Set<String> requiredHeaders = new HashSet<>(Arrays.asList(
"设备名称", "设备类型名称", "设备图片", "设备MAC", "蓝牙名称", "设备IMEI",
"备注", "是否支持蓝牙", "定位方式", "通讯方式",
"型号字典用于APP页面跳转", "型号字典用于PC页面跳转"
));
// 检查必需的表头是否都存在
Set<String> actualHeaderSet = new HashSet<>(actualHeaders);
if (!actualHeaderSet.containsAll(requiredHeaders)) {
requiredHeaders.removeAll(actualHeaderSet);
throw new BadRequestException("Excel模板缺少必需的列: " + String.join(", ", requiredHeaders));
}
// 检查第三列索引为2是否为"设备图片"
if (actualHeaders.size() > 2 && !"设备图片".equals(actualHeaders.get(2))) {
throw new BadRequestException("Excel模板不正确第三列必须是'设备图片'列");
}
} catch (BadRequestException e) {
throw e; // 直接重新抛出
} catch (Exception e) {
log.error("校验Excel模板时发生错误: {}", e.getMessage(), e);
throw new BadRequestException("校验Excel模板时发生错误: " + e.getMessage());
}
}
} }

View File

@ -41,6 +41,7 @@ public class DeviceRepairRecordsController extends BaseController {
private final IDeviceRepairRecordsService deviceRepairRecordsService; private final IDeviceRepairRecordsService deviceRepairRecordsService;
/** /**
* 查询设备维修记录列表 * 查询设备维修记录列表
*/ */
@ -52,6 +53,7 @@ public class DeviceRepairRecordsController extends BaseController {
return deviceRepairRecordsService.queryPageList(criteria, page); return deviceRepairRecordsService.queryPageList(criteria, page);
} }
/** /**
* 导出设备维修记录列表 * 导出设备维修记录列表
*/ */
@ -63,6 +65,7 @@ public class DeviceRepairRecordsController extends BaseController {
ExcelUtil.exportExcel(list, "设备维修记录", DeviceRepairRecordsVo.class, response); ExcelUtil.exportExcel(list, "设备维修记录", DeviceRepairRecordsVo.class, response);
} }
/** /**
* 获取设备维修记录详细信息 * 获取设备维修记录详细信息
* *
@ -75,6 +78,7 @@ public class DeviceRepairRecordsController extends BaseController {
return R.ok(deviceRepairRecordsService.queryById(recordId)); return R.ok(deviceRepairRecordsService.queryById(recordId));
} }
/** /**
* 新增设备维修记录 * 新增设备维修记录
*/ */
@ -86,6 +90,7 @@ public class DeviceRepairRecordsController extends BaseController {
return toAjax(deviceRepairRecordsService.insertByBo(bo)); return toAjax(deviceRepairRecordsService.insertByBo(bo));
} }
/** /**
* 修改设备维修记录 * 修改设备维修记录
*/ */
@ -109,4 +114,5 @@ public class DeviceRepairRecordsController extends BaseController {
@PathVariable Long[] recordIds) { @PathVariable Long[] recordIds) {
return toAjax(deviceRepairRecordsService.deleteWithValidByIds(List.of(recordIds), true)); return toAjax(deviceRepairRecordsService.deleteWithValidByIds(List.of(recordIds), true));
} }
} }

View File

@ -15,6 +15,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -50,7 +51,7 @@ public class DeviceTypeController {
// @Log("新增设备类型") // @Log("新增设备类型")
@Operation(summary = "新增设备类型") @Operation(summary = "新增设备类型")
@PostMapping(value = "/add") @PostMapping(value = "/add")
public R<Void> createDeviceType(@Validated @RequestBody DeviceType resources) { public R<Void> createDeviceType(@Validated @ModelAttribute DeviceTypeForm resources) throws IOException {
deviceTypeService.create(resources); deviceTypeService.create(resources);
return R.ok(); return R.ok();
} }
@ -59,7 +60,7 @@ public class DeviceTypeController {
// @Log("修改设备类型") // @Log("修改设备类型")
@Operation(summary = "修改设备类型") @Operation(summary = "修改设备类型")
@PutMapping(value = "/update") @PutMapping(value = "/update")
public R<Void> updateDeviceType(@Validated @RequestBody DeviceTypeForm resources) { public R<Void> updateDeviceType(@Validated @ModelAttribute DeviceTypeForm resources) throws IOException {
deviceTypeService.update(resources); deviceTypeService.update(resources);
return R.ok(); return R.ok();
} }
@ -79,7 +80,6 @@ public class DeviceTypeController {
public R<DeviceType> getCommunicationMode(@Parameter(name = "设备类型ID", required = true) Long id) { public R<DeviceType> getCommunicationMode(@Parameter(name = "设备类型ID", required = true) Long id) {
DeviceType communicationMode = deviceTypeService.getCommunicationMode(id); DeviceType communicationMode = deviceTypeService.getCommunicationMode(id);
return R.ok(communicationMode); return R.ok(communicationMode);
} }
} }

View File

@ -0,0 +1,143 @@
package com.fuyuanshen.equipment.controller;
import java.util.List;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.bo.TerminalDelBo;
import com.fuyuanshen.equipment.domain.bo.TerminalDeviceBo;
import com.fuyuanshen.equipment.domain.bo.TerminalQueryBo;
import com.fuyuanshen.equipment.domain.bo.TrackServiceBo;
import com.fuyuanshen.equipment.domain.dto.TerminalDeviceDto;
import com.fuyuanshen.equipment.domain.vo.TrackServiceVo;
import com.fuyuanshen.equipment.service.ITrackServiceService;
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.common.mybatis.core.page.TableDataInfo;
/**
* 轨迹服务
*
* @author Lion Li
* @date 2025-11-24
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/trackService")
public class TrackServiceController extends BaseController {
private final ITrackServiceService trackServiceService;
/**
* 查询轨迹服务列表
*/
// @SaCheckPermission("equipment:trackService:list")
@GetMapping("/list")
public TableDataInfo<TrackServiceVo> list(TrackServiceBo bo, PageQuery pageQuery) {
return trackServiceService.queryPageList(bo, pageQuery);
}
/**
* 轨迹服务列表
*/
// @SaCheckPermission("equipment:trackService:export")
@Log(title = "轨迹服务", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(TrackServiceBo bo, HttpServletResponse response) {
List<TrackServiceVo> list = trackServiceService.queryList(bo);
ExcelUtil.exportExcel(list, "轨迹服务", TrackServiceVo.class, response);
}
/**
* 获取轨迹服务详细信息
*
* @param id 主键
*/
@GetMapping("/{id}")
public R<TrackServiceVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(trackServiceService.queryById(id));
}
/**
* 新增轨迹服务
*/
// @SaCheckPermission("equipment:trackService:add")
@Log(title = "轨迹服务", businessType = BusinessType.INSERT)
@PostMapping(value = "/add")
public R<Void> add(@Validated(AddGroup.class) @RequestBody TrackServiceBo bo) {
return toAjax(trackServiceService.insertByBo(bo));
}
/**
* 修改轨迹服务
*/
// @SaCheckPermission("equipment:trackService:edit")
@Log(title = "轨迹服务", businessType = BusinessType.UPDATE)
@PostMapping(value = "/update")
public R<Void> edit(@Validated(EditGroup.class) @RequestBody TrackServiceBo bo) {
return toAjax(trackServiceService.updateByBo(bo));
}
/**
* 删除轨迹服务
*
* @param ids 主键串
*/
// @SaCheckPermission("equipment:trackService:remove")
@Log(title = "轨迹服务", businessType = BusinessType.DELETE)
@DeleteMapping(value = "/delete")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(trackServiceService.deleteWithValidByIds(List.of(ids), true));
}
@Log(title = "高德添加终端设备")
@PostMapping(value = "/terminal")
public R<Void> terminalDevice(@RequestBody TerminalDeviceBo model) {
trackServiceService.terminal(model);
return R.ok();
}
@Log(title = "高德移除终端设备")
@DeleteMapping(value = "/delTerminal/{ids}")
public R<Void> delTerminalDevice(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(trackServiceService.delTerminalDevice(List.of(ids), true));
}
@Log(title = "高德移除终端设备")
@DeleteMapping(value = "/del/Terminal")
public R<Void> delTerminalDevice(TerminalDelBo bo) {
return toAjax(trackServiceService.delTerminalDevice(bo, true));
}
/**
* 高德终端设备列表
*/
@GetMapping("/listTerminal")
public TableDataInfo<TerminalDeviceDto> listTerminal(TerminalQueryBo bo) {
return trackServiceService.listTerminal(bo);
}
/**
* 高德终端设备列表(关键字查询)
*/
@GetMapping("/searchTerminal")
public TableDataInfo<TerminalDeviceDto> searchTerminal(TerminalQueryBo bo) {
return trackServiceService.searchTerminal(bo);
}
}

View File

@ -4,6 +4,8 @@ import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration; import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.fuyuanshen.common.core.utils.file.ImageCompressUtil;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -12,86 +14,257 @@ import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.Base64;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/** /**
* @author: 默苍璃 * @author: 默苍璃
* @date: 2025-06-0618:56 * @date: 2025-06-0618:56
*/ */
public class IgnoreFailedImageConverter implements Converter<URL> { public class IgnoreFailedImageConverter implements Converter<URL> {
private static final Logger logger = LoggerFactory.getLogger(IgnoreFailedImageConverter.class); private static final Logger logger = LoggerFactory.getLogger(IgnoreFailedImageConverter.class);
// 重试次数
private static final int MAX_RETRIES = 3;
// 指数退避初始延迟(毫秒)
private static final int INITIAL_DELAY = 1000;
// 图片压缩阈值(1MB)
private static final int COMPRESSION_THRESHOLD = 100 * 1024;
// 压缩目标大小(50KB)
private static final int COMPRESSION_TARGET = 50 * 1024;
// 用于跟踪本次任务中使用到的URL缓存键
private static final ThreadLocal<Set<String>> USED_CACHE_KEYS = new ThreadLocal<Set<String>>() {
@Override
protected Set<String> initialValue() {
return new HashSet<>();
}
};
// 创建线程池用于并发处理图片
private static final ExecutorService IMAGE_PROCESSING_EXECUTOR = Executors.newFixedThreadPool(
Runtime.getRuntime().availableProcessors() * 2);
@Override @Override
public Class<?> supportJavaTypeKey() { public Class<?> supportJavaTypeKey() {
return URL.class; return URL.class;
} }
// @Override
// public CellDataTypeEnum supportExcelTypeKey() {
// return CellDataTypeEnum.STRING;
// }
@Override @Override
public WriteCellData<?> convertToExcelData(URL value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { public WriteCellData<?> convertToExcelData(URL value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
if (value == null) { if (value == null) {
logger.debug("图片URL为空"); logger.info("图片URL为空");
return new WriteCellData<>(new byte[0]); return new WriteCellData<>(new byte[0]);
} }
try { try {
logger.debug("开始加载图片: {}", value); // 使用CompletableFuture异步处理图片加载
URLConnection conn = value.openConnection(); CompletableFuture<WriteCellData<?>> future = CompletableFuture.supplyAsync(() -> {
// 增加连接和读取超时时间 try {
conn.setConnectTimeout(10000); // 10秒连接超时 return loadImageData(value);
conn.setReadTimeout(30000); // 30秒读取超时 } catch (Exception e) {
logger.error("异步加载图片失败: {}", value, e);
// 添加User-Agent避免被服务器拦截
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ExcelExporter/1.0");
// 如果是HTTP连接设置一些额外的属性
if (conn instanceof HttpURLConnection) {
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setRequestMethod("GET");
// 不使用缓存
httpConn.setUseCaches(false);
// 跟随重定向
httpConn.setInstanceFollowRedirects(true);
}
long contentLength = conn.getContentLengthLong();
logger.debug("连接建立成功,图片大小: {} 字节", contentLength);
// 检查内容长度是否有效
if (contentLength == 0) {
logger.warn("图片文件为空: {}", value);
return new WriteCellData<>(new byte[0]);
}
// 限制图片大小(防止过大文件导致内存问题)
if (contentLength > 10 * 1024 * 1024) { // 10MB限制
logger.warn("图片文件过大 ({} bytes),跳过加载: {}", contentLength, value);
return new WriteCellData<>(new byte[0]);
}
try (InputStream inputStream = conn.getInputStream()) {
// byte[] bytes = FileUtils.readInputStream(inputStream, value.toString());
// 替代 FileUtils.readInputStream 的自定义方法
byte[] bytes = readInputStream(inputStream);
// 检查读取到的数据是否为空
if (bytes == null || bytes.length == 0) {
logger.warn("读取到空的图片数据: {}", value);
return new WriteCellData<>(new byte[0]); return new WriteCellData<>(new byte[0]);
} }
}, IMAGE_PROCESSING_EXECUTOR);
logger.debug("成功读取图片数据,大小: {} 字节", bytes.length);
return new WriteCellData<>(bytes); // 设置超时时间,防止长时间阻塞
} return future.get(30, TimeUnit.SECONDS);
} catch (Exception e) { } catch (Exception e) {
// 静默忽略错误,只记录日志 logger.error("图片处理异常: {}", value, e);
logger.warn("图片加载失败: {}, 原因: {}", value, e.getMessage(), e); return new WriteCellData<>(new byte[0]);
// return null; // 返回null表示不写入图片 }
return new WriteCellData<>(new byte[0]); // 返回空数组而不是 null }
/**
* 加载图片数据的核心方法
*
* @param value 图片URL
* @return WriteCellData对象
*/
private WriteCellData<?> loadImageData(URL value) {
String cacheKey = "excel:image:" + value.toString();
// 将当前使用的缓存键添加到集合中
USED_CACHE_KEYS.get().add(cacheKey);
// 尝试从缓存获取
String cachedData = RedisUtils.getCacheObject(cacheKey);
if (cachedData != null) {
// 从缓存中读取Base64编码的数据并解码
byte[] cachedBytes = Base64.getDecoder().decode(cachedData);
logger.info("从缓存获取图片数据: {}, 大小: {} 字节", value, cachedBytes.length);
return new WriteCellData<>(cachedBytes);
}
// 缓存未命中从URL加载
// 尝试多次加载图片
for (int attempt = 1; attempt <= MAX_RETRIES; attempt++) {
try {
logger.info("开始加载图片: {}, 尝试次数: {}", value, attempt);
URLConnection conn = value.openConnection();
// 增加连接和读取超时时间
conn.setConnectTimeout(5000); // 5秒连接超时
conn.setReadTimeout(15000); // 15秒读取超时
// 添加User-Agent避免被服务器拦截
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 ExcelExporter/1.0");
// 添加Connection: close避免保持连接
conn.setRequestProperty("Connection", "close");
// 如果是HTTP连接设置一些额外的属性
if (conn instanceof HttpURLConnection) {
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setRequestMethod("GET");
// 不使用缓存
httpConn.setUseCaches(false);
// 跟随重定向
httpConn.setInstanceFollowRedirects(true);
// 检查响应码
int responseCode = httpConn.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
logger.info("HTTP响应码异常: {}, URL: {}", responseCode, value);
if (attempt < MAX_RETRIES) {
// 等待后重试
waitForRetry(attempt);
continue;
} else {
// 将空数据写入缓存
RedisUtils.setCacheObject(cacheKey, "");
return new WriteCellData<>(new byte[0]);
}
}
}
long contentLength = conn.getContentLengthLong();
logger.info("连接建立成功,图片大小: {} 字节", contentLength);
// 检查内容长度是否有效
if (contentLength == 0) {
logger.info("图片文件为空: {}", value);
if (attempt < MAX_RETRIES) {
waitForRetry(attempt);
continue;
} else {
// 将空数据写入缓存
RedisUtils.setCacheObject(cacheKey, "");
return new WriteCellData<>(new byte[0]);
}
}
// 限制图片大小(防止过大文件导致内存问题)
if (contentLength > 10 * 1024 * 1024) { // 10MB限制
logger.info("图片文件过大 ({} bytes),跳过加载: {}", contentLength, value);
// 将空数据写入缓存
RedisUtils.setCacheObject(cacheKey, "");
return new WriteCellData<>(new byte[0]);
}
try (InputStream inputStream = conn.getInputStream()) {
// byte[] bytes = FileUtils.readInputStream(inputStream, value.toString());
// 替代 FileUtils.readInputStream 的自定义方法
byte[] bytes = readInputStream(inputStream);
// 检查读取到的数据是否为空
if (bytes == null || bytes.length == 0) {
logger.info("读取到空的图片数据: {}", value);
if (attempt < MAX_RETRIES) {
waitForRetry(attempt);
continue;
} else {
// 将空数据写入缓存
RedisUtils.setCacheObject(cacheKey, "");
return new WriteCellData<>(new byte[0]);
}
}
// 如果图片大于1MB则进行压缩
if (bytes.length > COMPRESSION_THRESHOLD) {
logger.info("图片大小超过1MB ({} bytes),开始压缩", bytes.length);
long beforeCompressSize = bytes.length;
// 先尝试质量压缩
byte[] compressed = ImageCompressUtil.compressImage(bytes, COMPRESSION_TARGET);
// 如果压缩后变大了,使用原始数据
if (compressed.length >= bytes.length) {
compressed = bytes;
}
bytes = compressed;
long afterCompressSize = bytes.length;
logger.info("图片压缩完成,压缩前大小: {} bytes, 压缩后大小: {} bytes, 压缩率: {}",
beforeCompressSize, afterCompressSize,
String.format("%.2f", (1.0 - (double) afterCompressSize / beforeCompressSize) * 100));
}
logger.info("成功读取图片数据,大小: {} 字节", bytes.length);
// 将数据写入缓存不设置过期时间使用Base64编码存储
String encodedData = Base64.getEncoder().encodeToString(bytes);
RedisUtils.setCacheObject(cacheKey, encodedData);
return new WriteCellData<>(bytes);
}
} catch (Exception e) {
logger.info("图片加载失败: {}, 尝试次数: {}, 原因: {}", value, attempt, e.getMessage(), e);
if (attempt < MAX_RETRIES) {
// 等待后重试
waitForRetry(attempt);
} else {
// 最后一次尝试也失败了
logger.info("图片加载最终失败,已重试 {} 次: {}", MAX_RETRIES, value, e);
// 将空数据写入缓存
RedisUtils.setCacheObject(cacheKey, "");
return new WriteCellData<>(new byte[0]); // 返回空数组而不是 null
}
}
}
// 所有尝试都失败了
// 将空数据写入缓存
RedisUtils.setCacheObject(cacheKey, "");
return new WriteCellData<>(new byte[0]);
}
/**
* 清理未使用的缓存
* 任务结束后调用此方法删除本次任务中未使用的URL缓存
*/
public static void cleanUnusedCache() {
Set<String> usedKeys = USED_CACHE_KEYS.get();
if (usedKeys != null && !usedKeys.isEmpty()) {
// 获取所有图片缓存键
Iterable<String> allKeys = RedisUtils.keys("excel:image:*");
if (allKeys != null) {
// 删除未使用的缓存
for (String key : allKeys) {
if (!usedKeys.contains(key)) {
RedisUtils.deleteObject(key);
logger.info("删除未使用的缓存: {}", key);
}
}
}
// 清理ThreadLocal
USED_CACHE_KEYS.remove();
}
}
/**
* 等待重试,使用指数退避策略
*
* @param attempt 当前尝试次数
*/
private void waitForRetry(int attempt) {
try {
long delay = (long) INITIAL_DELAY * (1L << (attempt - 1)); // 指数退避
logger.info("等待 {} 毫秒后重试...", delay);
Thread.sleep(delay);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
} }
} }
@ -111,14 +284,49 @@ public class IgnoreFailedImageConverter implements Converter<URL> {
while ((bytesRead = inputStream.read(buffer)) != -1) { while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead); outputStream.write(buffer, 0, bytesRead);
totalBytes += bytesRead; totalBytes += bytesRead;
// 如果读取的数据过大,提前终止 // 如果读取的数据过大,提前终止
if (totalBytes > 10 * 1024 * 1024) { // 10MB限制 if (totalBytes > 10 * 1024 * 1024) { // 10MB限制
logger.warn("读取的图片数据超过10MB限制提前终止"); logger.info("读取的图片数据超过10MB限制提前终止");
break; break;
} }
} }
return outputStream.toByteArray(); return outputStream.toByteArray();
} }
}
/**
* 预加载图片到缓存
*
* @param imageUrls 图片URL列表
*/
public static void preloadImages(Set<URL> imageUrls) {
if (imageUrls == null || imageUrls.isEmpty()) {
return;
}
logger.info("开始预加载 {} 张图片", imageUrls.size());
// 使用并行流并发预加载图片
imageUrls.parallelStream().forEach(url -> {
try {
String cacheKey = "excel:image:" + url.toString();
// 如果缓存中没有,则异步加载
if (!RedisUtils.hasKey(cacheKey)) {
CompletableFuture.runAsync(() -> {
try {
// 简化版图片加载逻辑,只加载到缓存
new IgnoreFailedImageConverter().loadImageData(url);
} catch (Exception e) {
logger.warn("预加载图片失败: {}", url, e);
}
}, IMAGE_PROCESSING_EXECUTOR);
}
} catch (Exception e) {
logger.warn("预加载图片异常: {}", url, e);
}
});
logger.info("图片预加载任务已提交");
}
}

View File

@ -167,4 +167,20 @@ public class Device extends TenantEntity {
*/ */
private Integer onlineStatus; private Integer onlineStatus;
/**
* 高德服务ID
*/
@Schema(title = "服务ID高德")
private Long sid;
/**
* 高德终端ID
*/
@Schema(title = "终端ID高德")
private Long tid;
/**
* 高德轨迹ID
*/
@Schema(title = "轨迹ID高德")
private Long trid;
} }

View File

@ -2,6 +2,7 @@ package com.fuyuanshen.equipment.domain;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity; import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
import com.fuyuanshen.common.tenant.core.TenantEntity;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.util.Date; import java.util.Date;
@ -18,7 +19,7 @@ import java.io.Serial;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName("device_fence_access_record") @TableName("device_fence_access_record")
public class DeviceFenceAccessRecord extends BaseEntity { public class DeviceFenceAccessRecord extends TenantEntity {
@Serial @Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -0,0 +1,26 @@
package com.fuyuanshen.equipment.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* 围栏终端关联
*
* @author Lion Li
*/
@Data
@TableName("device_fence_terminal")
public class DeviceFenceTerminal {
/**
* 围栏ID
*/
@TableId(type = IdType.INPUT)
private Long fenceId;
/**
* 设备ID
*/
private Long deviceId;
}

View File

@ -58,6 +58,14 @@ public class DeviceGeoFence extends BaseEntity {
* 是否激活 * 是否激活
*/ */
private Long isActive; private Long isActive;
/**
* 高德服务ID
*/
private Long sid;
/**
* 高德围栏ID
*/
private Long gfid;
} }

View File

@ -60,7 +60,7 @@ public class DeviceType extends TenantEntity {
private String networkWay; private String networkWay;
@Schema(title = "通讯方式", example = "通讯方式 0:4G;1:蓝牙,2 4G&蓝牙") @Schema(title = "通讯方式", example = "通讯方式 0:4G;1:蓝牙,2 4G&蓝牙")
private Integer communicationMode; private String communicationMode;
/** /**
* 创建人名称 * 创建人名称
@ -85,5 +85,8 @@ public class DeviceType extends TenantEntity {
@Schema(title = "型号字典用于PC页面跳转") @Schema(title = "型号字典用于PC页面跳转")
private String pcModelDictionary; private String pcModelDictionary;
@Schema(title = "设备图片")
private String devicePic;
} }

View File

@ -0,0 +1,41 @@
package com.fuyuanshen.equipment.domain;
import com.baomidou.mybatisplus.annotation.*;
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
/**
* 轨迹服务对象 track_service
*
* @author Lion Li
* @date 2025-11-24
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("track_service")
public class TrackService extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
*
*/
@TableId(value = "id")
private Long id;
/**
* 猎鹰服务ID
*/
private Long sid;
/**
* 服务名称
*/
private String sname;
}

View File

@ -70,6 +70,14 @@ public class DeviceGeoFenceBo extends BaseEntity {
* 更新时间 * 更新时间
*/ */
private Date updateTime; private Date updateTime;
/**
* 高德服务ID
*/
private Long sid;
/**
* 高德围栏ID
*/
private Long gfid;
} }

View File

@ -0,0 +1,17 @@
package com.fuyuanshen.equipment.domain.bo;
import lombok.Data;
import java.util.List;
@Data
public class FenceTerminalBo {
/**
* 围栏ID
*/
private Long fenceId;
/**
* 设备IDs
*/
private List<Long> deviceIds;
}

View File

@ -0,0 +1,19 @@
package com.fuyuanshen.equipment.domain.bo;
import lombok.Data;
@Data
public class TerminalDelBo {
/**
* 猎鹰服务ID
*/
private Long sid;
/**
* 轨迹ID
*/
private Long trid;
/**
* 终端ID
*/
private Long tid;
}

View File

@ -0,0 +1,18 @@
package com.fuyuanshen.equipment.domain.bo;
import com.fuyuanshen.equipment.domain.form.DeviceForm;
import lombok.Data;
import java.util.List;
@Data
public class TerminalDeviceBo {
/**
* 猎鹰服务ID
*/
private Long sid;
/**
* 设备列表
*/
List<DeviceForm> deviceList;
}

View File

@ -0,0 +1,32 @@
package com.fuyuanshen.equipment.domain.bo;
import lombok.Data;
import lombok.Value;
@Data
public class TerminalQueryBo {
/**
* 猎鹰服务ID
*/
private Long sid;
/**
* 名称查询
*/
private String name;
/**
* 终端ID
*/
private Long tid;
/**
* 关键字搜索
*/
private String keywords;
/**
* 分页
*/
private int page = 1;
/**
* 每页数量
*/
private int pagesize = 10;
}

View File

@ -0,0 +1,36 @@
package com.fuyuanshen.equipment.domain.bo;
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
import com.fuyuanshen.equipment.domain.TrackService;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 轨迹服务业务对象 track_service
*
* @author Lion Li
* @date 2025-11-24
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = TrackService.class, reverseConvertGenerate = false)
public class TrackServiceBo extends BaseEntity {
/**
*
*/
private Long id;
/**
* 猎鹰服务ID
*/
private Long sid;
/**
* 服务名称
*/
private String sname;
}

View File

@ -1,24 +1,21 @@
package com.fuyuanshen.equipment.domain.dto; package com.fuyuanshen.equipment.domain.dto;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight; import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight; import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.converters.bytearray.ByteArrayImageConverter;
import lombok.Data; import lombok.Data;
/** /**
* @author: 默苍璃 * @author: 默苍璃
* @date: 2025-06-0710:00 * @date: 2025-06-07 10:00
*/ */
@Data @Data
@HeadRowHeight(20) // 表头行高 @HeadRowHeight(20) // 表头行高
@ContentRowHeight(100) // 内容行高 @ContentRowHeight(100) // 内容行高
public class DeviceExcelImportDTO { public class DeviceExcelImportDTO {
// @ExcelProperty("设备类型")
// private Long deviceType;
@ExcelProperty("设备名称") @ExcelProperty("设备名称")
@ColumnWidth(20) @ColumnWidth(20)
private String deviceName; private String deviceName;
@ -26,14 +23,23 @@ public class DeviceExcelImportDTO {
@ExcelProperty("设备类型名称") @ExcelProperty("设备类型名称")
private String typeName; private String typeName;
// @ExcelProperty(value = "设备图片", converter = ByteArrayImageConverter.class) /**
// @ColumnWidth(15) * 设备图片
// private byte[] devicePic; * 导入时的图片处理方式:
// * 在导入过程中图片不是通过Excel单元格中的文本数据如URL来处理的
// // 添加图片写入方法 * 而是直接从Excel文件中提取嵌入的图片数据
// public void setDevicePicFromBytes(byte[] bytes) { * 代码通过POI库直接读取Excel中的图片对象然后上传到OSS并生成URL
// this.devicePic = bytes; */
// } @ExcelProperty("设备图片")
@ColumnWidth(20)
private byte[] devicePic;
/**
* 用于存储实际图片数据的字段
* 使用@ExcelIgnore注解忽略该字段避免创建额外的列
*/
@ExcelIgnore
private byte[] imageData;
@ExcelProperty("设备MAC") @ExcelProperty("设备MAC")
@ColumnWidth(20) @ColumnWidth(20)
@ -46,18 +52,46 @@ public class DeviceExcelImportDTO {
@ExcelProperty("蓝牙名称") @ExcelProperty("蓝牙名称")
private String bluetoothName; private String bluetoothName;
// @ExcelProperty("设备SN")
// @ColumnWidth(20)
// private String deviceSn;
//
// @ExcelProperty("经度")
// private String longitude;
//
// @ExcelProperty("纬度")
// private String latitude;
@ExcelProperty("备注") @ExcelProperty("备注")
@ColumnWidth(30) @ColumnWidth(30)
private String remark; private String remark;
/*
*设备类型数据
*/
@ExcelProperty("是否支持蓝牙")
@ColumnWidth(15)
private String isSupportBle;
@ExcelProperty("定位方式")
@ColumnWidth(20)
private String locateMode;
@ExcelProperty("通讯方式")
@ColumnWidth(20)
private String communicationMode;
/**
* 型号字典用于APP页面跳转
* app_model_dictionary
*/
@ExcelProperty("型号字典用于APP页面跳转")
@ColumnWidth(20)
private String appModelDictionary;
/**
* 型号字典用于PC页面跳转
* pc_model_dictionary
*/
@ExcelProperty("型号字典用于PC页面跳转")
@ColumnWidth(20)
private String pcModelDictionary;
/**
* 错误原因
*/
@ExcelProperty("错误原因")
@ColumnWidth(30)
private String errorMessage;
} }

View File

@ -0,0 +1,100 @@
package com.fuyuanshen.equipment.domain.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.fuyuanshen.equipment.converter.IgnoreFailedImageConverter;
import lombok.Data;
import java.net.URL;
/**
* 设备及完整类型信息导出DTO
*
* @author: 默苍璃
* @date: 2025-11-04 16:25
*/
@Data
@HeadRowHeight(20) // 表头行高
@ContentRowHeight(100) // 内容行高
public class DeviceWithTypeExcelExportDTO {
@ExcelProperty("设备名称")
@ColumnWidth(20)
private String deviceName;
@ExcelProperty("设备类型名称")
@ColumnWidth(20)
private String typeName;
@ExcelProperty(value = "设备图片", converter = IgnoreFailedImageConverter.class)
// @ExcelProperty(value = "设备图片")
@ColumnWidth(30) // 设置图片列宽度
private URL devicePic; // 使用URL类型
@ExcelProperty("设备MAC")
@ColumnWidth(20)
private String deviceMac;
@ExcelProperty("蓝牙名称")
@ColumnWidth(20)
private String bluetoothName;
@ExcelProperty("设备IMEI")
@ColumnWidth(20)
private String deviceImei;
@ExcelProperty("备注")
@ColumnWidth(30)
private String remark;
/**
* 绑定状态
* 0 未绑定
* 1 已绑定
*/
@ExcelProperty("绑定状态")
@ColumnWidth(20)
private String bindingStatus;
@ExcelProperty("创建时间")
@ColumnWidth(20)
private String createTime;
@ExcelProperty("创建人")
@ColumnWidth(20)
private String createBy;
/*
*设备类型数据
*/
@ExcelProperty("是否支持蓝牙")
@ColumnWidth(15)
private String isSupportBle;
@ExcelProperty("定位方式")
@ColumnWidth(20)
private String locateMode;
@ExcelProperty("通讯方式")
@ColumnWidth(20)
private String communicationMode;
/**
* 型号字典用于APP页面跳转
* app_model_dictionary
*/
@ExcelProperty("型号字典用于APP页面跳转")
@ColumnWidth(20)
private String appModelDictionary;
/**
* 型号字典用于PC页面跳转
* pc_model_dictionary
*/
@ExcelProperty("型号字典用于PC页面跳转")
@ColumnWidth(20)
private String pcModelDictionary;
}

View File

@ -0,0 +1,29 @@
package com.fuyuanshen.equipment.domain.dto;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor // 必须
public class TerminalDeviceDto {
/**
* 终端设备名称
*/
private String name;
/**
* 终端设备ID
*/
private Long tid;
/**
* 终端设备描述
*/
private String desc;
/**
* 终端设备创建时间
*/
private String createtime;
/**
* 终端设备最后定位时间
*/
private String locatetime;
}

View File

@ -26,8 +26,6 @@ public class DeviceForm {
@Schema(title = "客户号") @Schema(title = "客户号")
private Long customerId; private Long customerId;
/*@Schema(value = "设备编号")
private String deviceNo;*/
@NotBlank(message = "设备名称不能为空") @NotBlank(message = "设备名称不能为空")
@Schema(title = "设备名称", required = true) @Schema(title = "设备名称", required = true)
@ -56,4 +54,25 @@ public class DeviceForm {
@Schema(title = "备注") @Schema(title = "备注")
private String remark; private String remark;
// 设备类型相关字段
@Schema(title = "设备类型名称")
private String typeName;
@Schema(title = "是否支持蓝牙")
private String isSupportBle;
@Schema(title = "定位方式")
private String locateMode;
@Schema(title = "通讯方式")
private String communicationMode;
@Schema(title = "APP模型字典")
private String appModelDictionary;
@Schema(title = "PC模型字典")
private String pcModelDictionary;
} }

View File

@ -2,6 +2,7 @@ package com.fuyuanshen.equipment.domain.form;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
/** /**
* @Description: 设备类型 * @Description: 设备类型
@ -48,5 +49,10 @@ public class DeviceTypeForm {
*/ */
@Schema(title = "型号字典用于PC页面跳转") @Schema(title = "型号字典用于PC页面跳转")
private String pcModelDictionary; private String pcModelDictionary;
@Schema(title = "设备图片")
private String devicePic;
@Schema(title = "设备图片")
private MultipartFile file;
} }

View File

@ -122,5 +122,25 @@ public class DeviceQueryCriteria extends BaseEntity {
* online_status * online_status
*/ */
private Integer onlineStatus; private Integer onlineStatus;
/**
* 高德终端ID是否存在
*/
private Boolean isTid;
/**
* 高德服务ID
*/
private String sid;
/**
* 围栏ID
*/
private Long fenceId;
/**
* 绑定状态
* 0 未绑定
* 1 已绑定
*/
@Schema(title = "绑定状态")
private Integer bindingStatus;
} }

View File

@ -2,6 +2,7 @@ package com.fuyuanshen.equipment.domain.vo;
import java.util.Date; import java.util.Date;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import cn.idev.excel.annotation.ExcelIgnoreUnannotated; import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty; import cn.idev.excel.annotation.ExcelProperty;
@ -60,6 +61,13 @@ public class DeviceFenceAccessRecordVo implements Serializable {
@ExcelProperty(value = "设备名称") @ExcelProperty(value = "设备名称")
private String deviceName; private String deviceName;
/**
* 事件时间
*/
@ExcelProperty(value = "事件时间")
@ColumnWidth(120)
private String eventTime;
/** /**
* 用户ID * 用户ID
*/ */
@ -76,27 +84,21 @@ public class DeviceFenceAccessRecordVo implements Serializable {
/** /**
* 纬度 * 纬度
*/ */
@ExcelProperty(value = "纬度") // @ExcelProperty(value = "纬度")
private Double latitude; private Double latitude;
/** /**
* 经度 * 经度
*/ */
@ExcelProperty(value = "经度") // @ExcelProperty(value = "经度")
private Double longitude; private Double longitude;
/** /**
* 定位精度 * 定位精度
*/ */
@ExcelProperty(value = "定位精度") // @ExcelProperty(value = "定位精度")
private Long accuracy; private Long accuracy;
/**
* 事件时间
*/
@ExcelProperty(value = "事件时间")
private Date eventTime;
/** /**
* 事件地址 * 事件地址
*/ */
@ -106,8 +108,7 @@ public class DeviceFenceAccessRecordVo implements Serializable {
/** /**
* 记录创建时间 * 记录创建时间
*/ */
@ExcelProperty(value = "记录创建时间") // @ExcelProperty(value = "记录创建时间")
private Date createTime; private Date createTime;
} }

View File

@ -101,6 +101,14 @@ public class DeviceGeoFenceVo implements Serializable {
*/ */
// @ExcelProperty(value = "更新时间") // @ExcelProperty(value = "更新时间")
private Date updateTime; private Date updateTime;
/**
* 高德服务ID
*/
private Long sid;
/**
* 高德围栏ID
*/
private Long gfid;
public void setAreaTypeNameByAreaType() { public void setAreaTypeNameByAreaType() {

Some files were not shown because too many files have changed in this diff Show More