forked from dyf/fys-Multi-tenant
Compare commits
102 Commits
62af38cbf0
...
prod
| Author | SHA1 | Date | |
|---|---|---|---|
| cde34cab6c | |||
| dff37b245a | |||
| d7c4d22de3 | |||
| 6a058318f2 | |||
| f2d74b8f17 | |||
| af42a2199c | |||
| aaf142ca67 | |||
| 7d256df790 | |||
| c0dfe36b59 | |||
| 3d1c2f4e56 | |||
| c480bda112 | |||
| ccadcb8d4e | |||
| 8c636d0484 | |||
| 0c474ae1f3 | |||
| b85664900e | |||
| b8cb663bbf | |||
| 035b24fedd | |||
| e920cfb860 | |||
| 56e86b070d | |||
| b33ee00dbd | |||
| 0898855108 | |||
| c8f9cc4f31 | |||
| 26d2f05c4e | |||
| d57d17dc50 | |||
| 20ddbf6e05 | |||
| 92b65ce6df | |||
| 63a9d2f8f9 | |||
| 7753444f25 | |||
| bf182ebc89 | |||
| d5a29feca3 | |||
| 0457877c09 | |||
| 1e9e815314 | |||
| b18ab98feb | |||
| 7c6f3be844 | |||
| aa69b552aa | |||
| 3dd0d4cc90 | |||
| 00a4394b43 | |||
| 2376a3b42a | |||
| 359cabbd2c | |||
| 76c11fff15 | |||
| a0ab5e9fe0 | |||
| 891ee7c1c9 | |||
| a145c372b8 | |||
| 3798e52ee0 | |||
| 6488b8a724 | |||
| 6d58268874 | |||
| 88b54a49f4 | |||
| 56dbfbde71 | |||
| dce043f63d | |||
| 77626673e9 | |||
| 759c72fc65 | |||
| 1be80be309 | |||
| 92df1c8668 | |||
| cc2b7664a8 | |||
| 33d6108172 | |||
| 70c416779f | |||
| ee85961eeb | |||
| 004079f7f4 | |||
| 264d0135d9 | |||
| 4961ec47f8 | |||
| f25afe0e9d | |||
| e265dea0ec | |||
| c7ff118bfe | |||
| 1dc3386284 | |||
| c4957aa3aa | |||
| f4369f7581 | |||
| df28eed305 | |||
| 07e60cf7f0 | |||
| 5d42f8a1e1 | |||
| f2a5e63a41 | |||
| 467a7befb1 | |||
| 107ddf8851 | |||
| a85e74c5e6 | |||
| 9bbddee1d5 | |||
| da0833a400 | |||
| 418fb55bf0 | |||
| 1d50981a84 | |||
| 2f80c450c5 | |||
| 09cbdf267b | |||
| 156fdbb53b | |||
| 3246127893 | |||
| dab0440128 | |||
| 740a638444 | |||
| a3d44a157a | |||
| cc23f082a6 | |||
| 1bc7dc676e | |||
| 5cdacad468 | |||
| 82399cffed | |||
| 5538ac96e5 | |||
| b703f80355 | |||
| b3b249ea07 | |||
| aff424e73b | |||
| dc513a858a | |||
| df5ce7ddd9 | |||
| 2174dfdb4d | |||
| 2800b89e06 | |||
| 637e46c510 | |||
| 31c2158c8e | |||
| c7c21dc358 | |||
| a7e0803b00 | |||
| 55cacbd322 | |||
| 99ec6eaff0 |
@ -1,24 +1,24 @@
|
||||
package com.fuyuanshen;
|
||||
package com.fuyuanshen;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class DromaraApplication {
|
||||
/**
|
||||
* 启动程序
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class DromaraApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication application = new SpringApplication(DromaraApplication.class);
|
||||
application.setApplicationStartup(new BufferingApplicationStartup(2048));
|
||||
application.run(args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ fys-Vue-Plus启动成功 ლ(´ڡ`ლ)゙");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication application = new SpringApplication(DromaraApplication.class);
|
||||
application.setApplicationStartup(new BufferingApplicationStartup(2048));
|
||||
application.run(args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ fys-Vue-Plus启动成功 ლ(´ڡ`ლ)゙");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
64
fys-admin/src/main/java/com/fuyuanshen/Text.java
Normal file
64
fys-admin/src/main/java/com/fuyuanshen/Text.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -72,10 +72,8 @@ public class AppAuthController {
|
||||
|
||||
private final AppLoginService loginService;
|
||||
private final AppRegisterService registerService;
|
||||
private final ISysConfigService configService;
|
||||
private final ISysTenantService tenantService;
|
||||
private final ISysClientService clientService;
|
||||
private final ISysDictTypeService dictTypeService;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -92,4 +92,5 @@ public class AppDeviceController extends BaseController {
|
||||
public R<AppDeviceVo> getDeviceInfo(String deviceMac) {
|
||||
return R.ok(appDeviceService.getDeviceInfo(deviceMac));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -44,10 +44,9 @@ import static com.fuyuanshen.common.core.constant.GlobalConstants.DEVICE_SHARE_C
|
||||
@RequestMapping("/app/deviceShare")
|
||||
public class AppDeviceShareController extends BaseController {
|
||||
|
||||
private final IAppDeviceShareService deviceShareService;
|
||||
|
||||
private final AppDeviceShareService appDeviceShareService;
|
||||
|
||||
|
||||
/**
|
||||
* 分享管理列表
|
||||
*/
|
||||
@ -95,6 +94,7 @@ public class AppDeviceShareController extends BaseController {
|
||||
return toAjax(appDeviceShareService.remove(ids));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 短信验证码
|
||||
*
|
||||
@ -116,4 +116,5 @@ public class AppDeviceShareController extends BaseController {
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -25,6 +26,7 @@ public class AppFileController extends BaseController {
|
||||
|
||||
private final AppFileService appFileService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询文件列表
|
||||
*/
|
||||
@ -33,11 +35,12 @@ public class AppFileController extends BaseController {
|
||||
return R.ok(appFileService.list(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*/
|
||||
@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));
|
||||
}
|
||||
|
||||
@ -52,4 +55,5 @@ public class AppFileController extends BaseController {
|
||||
}
|
||||
return toAjax(appFileService.delete(ids));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ public class AppOperationVideoController extends BaseController {
|
||||
|
||||
private final IAppOperationVideoService appOperationVideoService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询操作视频列表
|
||||
*/
|
||||
@ -68,4 +69,5 @@ public class AppOperationVideoController extends BaseController {
|
||||
public R<Void> deleteOperationVideo(@PathVariable Long id) {
|
||||
return toAjax(appOperationVideoService.deleteWithValidByIds(List.of(id), true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,249 +1,68 @@
|
||||
package com.fuyuanshen.app.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import com.fuyuanshen.app.service.AudioProcessService;
|
||||
import com.fuyuanshen.app.service.VideoProcessService;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bytedeco.javacv.FFmpegFrameGrabber;
|
||||
import org.bytedeco.javacv.Frame;
|
||||
import org.bytedeco.javacv.Java2DFrameUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* APP 视频处理
|
||||
* @date 2025-09-15
|
||||
* APP 视频处理控制器
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/app/video")
|
||||
public class AppVideoController extends BaseController {
|
||||
// 可配置项:建议从 application.yml 中读取
|
||||
private static final int MAX_VIDEO_SIZE = 10 * 1024 * 1024; // 10 MB
|
||||
private static final int FRAME_RATE = 15; // 每秒抽15帧
|
||||
private static final int DURATION = 2; // 抽2秒
|
||||
private static final int TOTAL_FRAMES = FRAME_RATE * DURATION;
|
||||
private static final int WIDTH = 160;
|
||||
private static final int HEIGHT = 80;
|
||||
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
private final VideoProcessService videoProcessService;
|
||||
private final AudioProcessService audioProcessService;
|
||||
|
||||
/**
|
||||
* 上传视频转码code默认1:RGB565 2:BGR565
|
||||
*/
|
||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R<List<String>> upload(@RequestParam("file") MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
return R.fail("上传文件不能为空");
|
||||
}
|
||||
|
||||
if (!isVideo(file.getOriginalFilename())) {
|
||||
return R.fail("只允许上传视频文件");
|
||||
}
|
||||
|
||||
if (file.getSize() > MAX_VIDEO_SIZE) {
|
||||
return R.fail("视频大小不能超过10MB");
|
||||
}
|
||||
|
||||
File tempFile = null;
|
||||
try {
|
||||
// 创建临时文件保存上传的视频
|
||||
tempFile = createTempVideoFile(file);
|
||||
|
||||
|
||||
List<BufferedImage> frames = extractFramesFromVideo(tempFile);
|
||||
if (frames.isEmpty()) {
|
||||
return R.fail("无法提取任何帧");
|
||||
}
|
||||
|
||||
// ✅ 新增:保存帧为图片
|
||||
//saveFramesToLocal(frames, "extracted_frame");
|
||||
|
||||
byte[] binaryData = convertFramesToRGB565(frames);
|
||||
// String base64Data = Base64.getEncoder().encodeToString(binaryData);
|
||||
//
|
||||
// return R.ok(base64Data);
|
||||
// 构造响应头
|
||||
// 将二进制数据转为 Hex 字符串
|
||||
// 转换为 Hex 字符串列表
|
||||
List<String> hexList = bytesToHexList(binaryData);
|
||||
|
||||
return R.ok(hexList);
|
||||
|
||||
} catch (Exception e) {
|
||||
return R.fail("视频处理失败:" + e.getMessage());
|
||||
} finally {
|
||||
deleteTempFile(tempFile);
|
||||
}
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<List<String>> uploadVideo(@RequestParam("file") MultipartFile file, @RequestParam(defaultValue = "1") int code) {
|
||||
return R.ok(videoProcessService.processVideo(file, code));
|
||||
}
|
||||
|
||||
/**
|
||||
* rgb565 转 hex
|
||||
* 上传音频文件并转码
|
||||
*/
|
||||
private List<String> bytesToHexList(byte[] bytes) {
|
||||
List<String> hexList = new ArrayList<>();
|
||||
for (byte b : bytes) {
|
||||
int value = b & 0xFF;
|
||||
char high = HEX_ARRAY[value >>> 4];
|
||||
char low = HEX_ARRAY[value & 0x0F];
|
||||
hexList.add(String.valueOf(high) + low);
|
||||
}
|
||||
return hexList;
|
||||
@PostMapping(value = "/audio", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<List<String>> uploadAudio(@RequestParam("file") MultipartFile file) {
|
||||
return R.ok(audioProcessService.processAudio(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时文件并保存上传的视频
|
||||
* 文字转音频TTS服务
|
||||
*/
|
||||
private File createTempVideoFile(MultipartFile file) throws Exception {
|
||||
File tempFile = Files.createTempFile("upload-", ".mp4").toFile();
|
||||
file.transferTo(tempFile);
|
||||
return tempFile;
|
||||
@GetMapping("/audioTTS")
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<List<String>> uploadAudioTTS(@RequestParam String text) throws IOException {
|
||||
return R.ok(audioProcessService.generateStandardPcmData(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从视频中按时间均匀提取指定数量的帧
|
||||
* 提取文本内容(只支持txt/docx)
|
||||
*/
|
||||
private List<BufferedImage> extractFramesFromVideo(File videoFile) throws Exception {
|
||||
List<BufferedImage> frames = new ArrayList<>();
|
||||
|
||||
try (FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(videoFile)) {
|
||||
grabber.start();
|
||||
|
||||
// 获取视频总帧数和帧率
|
||||
long totalFramesInVideo = grabber.getLengthInFrames();
|
||||
int fps = (int) Math.round(grabber.getFrameRate());
|
||||
if (fps <= 0) fps = 30;
|
||||
|
||||
double durationSeconds = (double) totalFramesInVideo / fps;
|
||||
|
||||
if (durationSeconds < DURATION) {
|
||||
throw new IllegalArgumentException("视频太短,至少需要 " + DURATION + " 秒");
|
||||
}
|
||||
|
||||
// 计算每帧之间的间隔(浮点以实现更精确跳转)
|
||||
double frameInterval = (double) totalFramesInVideo / TOTAL_FRAMES;
|
||||
|
||||
for (int i = 0; i < TOTAL_FRAMES; i++) {
|
||||
int targetFrameNumber = (int) Math.round(i * frameInterval);
|
||||
|
||||
// 避免设置无效帧号
|
||||
if (targetFrameNumber >= totalFramesInVideo) {
|
||||
throw new IllegalArgumentException("目标帧超出范围: " + targetFrameNumber + " ");
|
||||
}
|
||||
|
||||
grabber.setFrameNumber(targetFrameNumber);
|
||||
Frame frame = grabber.grab();
|
||||
|
||||
if (frame != null && frame.image != null) {
|
||||
BufferedImage bufferedImage = Java2DFrameUtils.toBufferedImage(frame);
|
||||
frames.add(cropImage(bufferedImage, WIDTH, HEIGHT));
|
||||
} else {
|
||||
throw new IllegalArgumentException("无法获取第 " + targetFrameNumber + "帧 ");
|
||||
}
|
||||
}
|
||||
|
||||
grabber.stop();
|
||||
}
|
||||
|
||||
return frames;
|
||||
@PostMapping(value = "/extract", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<String> extract(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
return R.ok("Success",audioProcessService.extract(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将抽取的帧保存到本地,用于调试
|
||||
*/
|
||||
private void saveFramesToLocal(List<BufferedImage> frames, String prefix) {
|
||||
// 指定输出目录
|
||||
File outputDir = new File("output_frames");
|
||||
if (!outputDir.exists()) {
|
||||
outputDir.mkdirs();
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (BufferedImage frame : frames) {
|
||||
try {
|
||||
File outputImage = new File(outputDir, prefix + "_" + (index++) + ".png");
|
||||
ImageIO.write(frame, "png", outputImage);
|
||||
System.out.println("保存帧图片成功: " + outputImage.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("保存帧图片失败 " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将所有帧转换为 RGB565 格式字节数组
|
||||
*/
|
||||
private byte[] convertFramesToRGB565(List<BufferedImage> frames) throws Exception {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
|
||||
for (BufferedImage image : frames) {
|
||||
byte[] rgb565Bytes = convertToRGB565(image);
|
||||
byteArrayOutputStream.write(rgb565Bytes);
|
||||
}
|
||||
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是支持的视频格式
|
||||
*/
|
||||
private boolean isVideo(String filename) {
|
||||
String ext = filename.substring(filename.lastIndexOf('.')).toLowerCase();
|
||||
return Arrays.asList(".mp4", ".avi", ".mov", ".mkv").contains(ext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 裁剪图像到目标尺寸
|
||||
*/
|
||||
private BufferedImage cropImage(BufferedImage img, int targetWidth, int targetHeight) {
|
||||
int w = Math.min(img.getWidth(), targetWidth);
|
||||
int h = Math.min(img.getHeight(), targetHeight);
|
||||
return img.getSubimage(0, 0, w, h);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 BufferedImage 转换为 RGB565 格式的字节数组
|
||||
*/
|
||||
private byte[] convertToRGB565(BufferedImage image) {
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
byte[] result = new byte[width * height * 2]; // RGB565: 2 bytes per pixel
|
||||
int index = 0;
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int rgb = image.getRGB(x, y);
|
||||
int r = ((rgb >> 16) & 0xFF) >> 3;
|
||||
int g = ((rgb >> 8) & 0xFF) >> 2;
|
||||
int b = (rgb & 0xFF) >> 3;
|
||||
short pixel = (short) ((r << 11) | (g << 5) | b);
|
||||
|
||||
result[index++] = (byte) (pixel >> 8); // High byte first
|
||||
result[index++] = (byte) pixel;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除临时文件
|
||||
*/
|
||||
private void deleteTempFile(File file) {
|
||||
if (file != null && file.exists()) {
|
||||
if (!file.delete()) {
|
||||
throw new IllegalArgumentException("无法删除临时文件: " + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ public class AppDeviceBJQController extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
@ -86,7 +87,6 @@ public class AppDeviceBJQController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
||||
|
||||
@ -28,6 +28,7 @@ public class AppDeviceHBYController extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
|
||||
@ -38,6 +38,8 @@ public class AppDeviceXinghanController extends BaseController {
|
||||
|
||||
private final DeviceXinghanBizService appDeviceService;
|
||||
private final DeviceService deviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
@ -67,7 +69,7 @@ public class AppDeviceXinghanController extends BaseController {
|
||||
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if(file.getSize()>1024*1024*2){
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.uploadDeviceLogo(bo);
|
||||
@ -125,7 +127,7 @@ public class AppDeviceXinghanController extends BaseController {
|
||||
|
||||
@GetMapping(value = "/typeAll")
|
||||
@Operation(summary = "查询所有设备类型")
|
||||
public R<List<DeviceType>> queryDeviceTypes() {
|
||||
public R<List<DeviceType>> queryDeviceTypes() {
|
||||
List<DeviceType> deviceTypes = appDeviceService.queryDeviceTypes();
|
||||
return R.ok(deviceTypes);
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ public class TestController extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 上传设备logo图片
|
||||
*/
|
||||
|
||||
@ -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;
|
||||
|
||||
/**
|
||||
* BJQ6075 设备控制类
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/app/bjq6075/device")
|
||||
public class AppDeviceBJQ6075Controller 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(爆闪),6(SOS)
|
||||
*/
|
||||
@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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -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(爆闪),6(SOS)
|
||||
*/
|
||||
@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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -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;
|
||||
|
||||
/**
|
||||
* HBY335(LED救生照明线)
|
||||
*/
|
||||
@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(爆闪),6(SOS)
|
||||
*/
|
||||
@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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -11,8 +11,9 @@ public class AppDeviceLogoUploadDto {
|
||||
private Long deviceId;
|
||||
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 文件
|
||||
* 文件
|
||||
*/
|
||||
private MultipartFile file;
|
||||
|
||||
@ -25,4 +26,5 @@ public class AppDeviceLogoUploadDto {
|
||||
private List<Long> deviceIds;
|
||||
|
||||
private Integer chunkSize;
|
||||
|
||||
}
|
||||
|
||||
@ -8,9 +8,15 @@ public class DeviceInstructDto {
|
||||
private Long deviceId;
|
||||
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 下发指令
|
||||
* 下发指令
|
||||
*/
|
||||
private String instructValue;
|
||||
|
||||
/**
|
||||
* 下发指令类型
|
||||
*/
|
||||
private String instructType;
|
||||
|
||||
}
|
||||
|
||||
@ -216,6 +216,7 @@ public class AppDeviceShareService {
|
||||
uw.eq("phonenumber", bo.getPhonenumber());
|
||||
uw.set("permission", bo.getPermission());
|
||||
uw.set("update_by", userId);
|
||||
uw.set("create_by", userId);
|
||||
uw.set("update_time", new Date());
|
||||
|
||||
return appDeviceShareMapper.update(uw);
|
||||
@ -226,7 +227,7 @@ public class AppDeviceShareService {
|
||||
appDeviceShare.setPermission(bo.getPermission());
|
||||
appDeviceShare.setCreateBy(userId);
|
||||
return appDeviceShareMapper.insert(appDeviceShare);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int remove(Long[] ids) {
|
||||
|
||||
@ -8,6 +8,7 @@ import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.oss.core.OssClient;
|
||||
import com.fuyuanshen.common.oss.factory.OssFactory;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.equipment.utils.FileHashUtil;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import com.fuyuanshen.system.service.ISysOssService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -15,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -31,24 +33,38 @@ public class AppFileService {
|
||||
|
||||
private final IAppBusinessFileService appBusinessFileService;
|
||||
|
||||
private final FileHashUtil fileHashUtil;
|
||||
private final ISysOssService ossService;
|
||||
|
||||
|
||||
public List<AppFileVo> list(AppBusinessFileBo bo) {
|
||||
// bo.setCreateBy(AppLoginHelper.getUserId());
|
||||
return appBusinessFileService.queryAppFileList(bo);
|
||||
}
|
||||
|
||||
public Boolean add(AppFileDto bo) {
|
||||
|
||||
/**
|
||||
* APP文件上传
|
||||
*/
|
||||
public Boolean add(AppFileDto bo) throws IOException {
|
||||
|
||||
MultipartFile[] files = bo.getFiles();
|
||||
if(files == null || files.length == 0){
|
||||
if (files == null || files.length == 0) {
|
||||
throw new ServiceException("请选择要上传的文件");
|
||||
}
|
||||
if(files.length > 5){
|
||||
if (files.length > 5) {
|
||||
throw new ServiceException("最多只能上传5个文件");
|
||||
}
|
||||
for (int i = 0; i < files.length; 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) {
|
||||
return false;
|
||||
@ -66,6 +82,7 @@ public class AppFileService {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public Boolean delete(Long[] ids) {
|
||||
AppBusinessFileBo bo = new AppBusinessFileBo();
|
||||
// bo.setCreateBy(AppLoginHelper.getUserId());
|
||||
@ -79,4 +96,5 @@ public class AppFileService {
|
||||
}
|
||||
return appBusinessFileService.deleteWithValidByIds(List.of(ids), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,11 @@ import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
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.AppUserVo;
|
||||
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.tenant.exception.TenantException;
|
||||
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.service.ISysTenantService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -33,6 +40,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 登录校验方法
|
||||
@ -52,6 +60,9 @@ public class AppLoginService {
|
||||
|
||||
private final ISysTenantService tenantService;
|
||||
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() {
|
||||
try {
|
||||
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
|
||||
// AppLoginUser loginUser = new AppLoginUser();
|
||||
// loginUser.setUserId(1988398584423133187L);
|
||||
// loginUser.setUsername("19022528079");
|
||||
if (ObjectUtil.isNull(loginUser)) {
|
||||
return;
|
||||
}
|
||||
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()) {
|
||||
// 超级管理员 登出清除动态租户
|
||||
TenantHelper.clearDynamic();
|
||||
|
||||
@ -0,0 +1,308 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
|
||||
import com.fuyuanshen.equipment.utils.AlibabaTTSUtil;
|
||||
import com.fuyuanshen.equipment.utils.AudioProcessUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
/**
|
||||
* 音频处理服务
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AudioProcessService {
|
||||
|
||||
// 配置参数
|
||||
private static final int MAX_AUDIO_SIZE = 5 * 1024 * 1024; // 5MB
|
||||
private static final List<String> SUPPORTED_FORMATS = Arrays.asList(
|
||||
".wav", ".mp3", ".aac", ".flac", ".m4a", ".ogg"
|
||||
);
|
||||
|
||||
private final AudioProcessUtil audioProcessUtil;
|
||||
private final AlibabaTTSUtil alibabaTTSUtil;
|
||||
|
||||
/**
|
||||
* 处理上传的音频文件
|
||||
*/
|
||||
public List<String> processAudio(MultipartFile file) {
|
||||
// 1. 参数校验
|
||||
validateAudioFile(file);
|
||||
|
||||
File tempFile = null;
|
||||
try {
|
||||
// 2. 创建临时文件
|
||||
tempFile = createTempAudioFile(file);
|
||||
|
||||
// 3. 转码为标准PCM-WAV格式
|
||||
byte[] pcmData = audioProcessUtil.convertToStandardWav(tempFile);
|
||||
log.info("音频处理成功,输出数据大小: {} bytes", pcmData.length);
|
||||
|
||||
// 获取音频信息
|
||||
// String audioInfo = audioProcessUtil.getAudioInfo(pcmData);
|
||||
// log.info("音频处理成功,音频信息: {}", audioInfo);
|
||||
//
|
||||
// // 保存测试文件(用于验证)
|
||||
// String savedPath = audioProcessUtil.saveWavToFile(pcmData, "test_output.wav");
|
||||
// if (savedPath != null) {
|
||||
// log.info("测试文件已保存: {}", savedPath);
|
||||
// }
|
||||
|
||||
// 将byte[]转换为16进制字符串列表
|
||||
List<String> hexList = audioProcessUtil.bytesToHexList(pcmData);
|
||||
|
||||
log.info("音频处理完成,原始数据大小: {} bytes, 16进制数据长度: {}",
|
||||
pcmData.length, hexList.size());
|
||||
|
||||
return hexList;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("音频处理失败", e);
|
||||
throw new RuntimeException("音频处理失败", e);
|
||||
} finally {
|
||||
// 4. 清理临时文件
|
||||
deleteTempFile(tempFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成标准PCM数据(单声道,16K采样率,16bit深度,包含44字节WAV头)
|
||||
* 数据总大小不超过2MB,如果超过将抛出异常
|
||||
* @param text 要转换的文本内容
|
||||
* @return 标准PCM数据字节数组(WAV格式)
|
||||
* @throws IOException 处理失败时抛出
|
||||
* @throws IllegalArgumentException 如果生成的数据超过2MB
|
||||
*/
|
||||
public List<String> generateStandardPcmData(String text) throws IOException {
|
||||
// 参数校验
|
||||
if (text == null || text.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("文本内容不能为空");
|
||||
}
|
||||
if (text.length() > 100) {
|
||||
throw new IllegalArgumentException("文本长度超过限制(最大100字符)");
|
||||
}
|
||||
log.info("输入文本长度: {}", text.length());
|
||||
try {
|
||||
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, "tts_output.wav");
|
||||
if (savedPath != null) {
|
||||
log.info("WAV文件已保存: {}", savedPath);
|
||||
}
|
||||
|
||||
// 将byte[]转换为16进制字符串列表
|
||||
List<String> hexList = audioProcessUtil.bytesToHexList(pcmData);
|
||||
|
||||
log.info("generateStandardPcmData音频处理完成,原始数据大小: {} bytes, 16进制数据长度: {}",
|
||||
pcmData.length, hexList.size());
|
||||
|
||||
return hexList;
|
||||
} finally {
|
||||
// 4. 清理临时文件
|
||||
}
|
||||
}
|
||||
|
||||
public String saveWavFileLocally(String text, String filename) throws IOException {
|
||||
// 参数校验
|
||||
if (text == null || text.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("文本内容不能为空");
|
||||
}
|
||||
|
||||
if (filename == null || filename.trim().isEmpty()) {
|
||||
filename = "tts_output.wav"; // 默认文件名
|
||||
}
|
||||
|
||||
try {
|
||||
// 生成PCM数据
|
||||
byte[] rawPcmData = alibabaTTSUtil.generateStandardPcmData(text);
|
||||
|
||||
// 转换为标准WAV格式(添加44字节头部)
|
||||
byte[] wavData = audioProcessUtil.rawPcmToStandardWav(rawPcmData);
|
||||
|
||||
// 保存到本地文件
|
||||
String filePath = saveByteArrayToFile(wavData, filename);
|
||||
|
||||
log.info("WAV文件已保存: {}", filePath);
|
||||
return filePath;
|
||||
} catch (Exception e) {
|
||||
log.error("保存WAV文件失败: {}", e.getMessage(), e);
|
||||
throw new IOException("保存WAV文件失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 验证音频文件
|
||||
*/
|
||||
private void validateAudioFile(MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new IllegalArgumentException("上传文件不能为空");
|
||||
}
|
||||
|
||||
if (!isAudioFile(file.getOriginalFilename())) {
|
||||
throw new IllegalArgumentException("只允许上传音频文件");
|
||||
}
|
||||
|
||||
if (file.getSize() > MAX_AUDIO_SIZE) {
|
||||
throw new IllegalArgumentException("音频大小不能超过5MB");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是支持的音频格式
|
||||
*/
|
||||
private boolean isAudioFile(String filename) {
|
||||
if (filename == null || filename.lastIndexOf('.') == -1) {
|
||||
return false;
|
||||
}
|
||||
String ext = filename.substring(filename.lastIndexOf('.')).toLowerCase();
|
||||
return SUPPORTED_FORMATS.contains(ext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时音频文件
|
||||
*/
|
||||
private File createTempAudioFile(MultipartFile file) throws IOException {
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String extension = "";
|
||||
if (originalFilename != null && originalFilename.contains(".")) {
|
||||
extension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
}
|
||||
|
||||
File tempFile = File.createTempFile("audio-", extension);
|
||||
file.transferTo(tempFile);
|
||||
log.debug("创建临时音频文件: {}", tempFile.getAbsolutePath());
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除临时文件
|
||||
*/
|
||||
private void deleteTempFile(File file) {
|
||||
if (file != null && file.exists()) {
|
||||
if (file.delete()) {
|
||||
log.debug("删除临时文件成功: {}", file.getAbsolutePath());
|
||||
} else {
|
||||
log.warn("无法删除临时文件: {}", file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取文本
|
||||
*/
|
||||
public String extract(MultipartFile file) throws Exception {
|
||||
String name = file.getOriginalFilename();
|
||||
if (name == null ||
|
||||
(!name.endsWith(".txt") && !name.endsWith(".docx"))) {
|
||||
throw new IllegalArgumentException("仅支持 .txt 或 .docx");
|
||||
}
|
||||
if (file.getSize() > MAX_AUDIO_SIZE) {
|
||||
throw new IllegalArgumentException("文件超过5MB");
|
||||
}
|
||||
|
||||
String text;
|
||||
/* 全程流式,不落地磁盘,不一次性读字节数组 */
|
||||
try (InputStream in = file.getInputStream()) {
|
||||
if (name.endsWith(".txt")) {
|
||||
text = readTxt(in);
|
||||
} else {
|
||||
text = readDocx(in);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/* ---------- txt:按行读,StringBuilder 复用 ---------- */
|
||||
private String readTxt(InputStream in) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
StringBuilder sb = new StringBuilder(4096);
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line).append('\n');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/* ---------- docx:ZipInputStream 只扫 document.xml ---------- */
|
||||
private String readDocx(InputStream in) throws IOException {
|
||||
ZipInputStream zin = new ZipInputStream(in);
|
||||
ZipEntry e;
|
||||
while ((e = zin.getNextEntry()) != null) {
|
||||
if ("word/document.xml".equals(e.getName())) {
|
||||
return staxExtract(zin); // 流式读 XML
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/* ---------- StAX 流式提取 <w:t> ---------- */
|
||||
private String staxExtract(InputStream xml) throws IOException {
|
||||
XMLStreamReader r = null;
|
||||
StringBuilder sb = new StringBuilder(4096);
|
||||
try {
|
||||
//System.out.println(new String(xml.readAllBytes()));
|
||||
r = XMLInputFactory.newInstance().createXMLStreamReader(xml);
|
||||
while (r.hasNext()) {
|
||||
if (r.next() == XMLStreamConstants.START_ELEMENT &&
|
||||
"t".equals(r.getLocalName())) {
|
||||
String elementText = r.getElementText();
|
||||
sb.append(elementText);
|
||||
}
|
||||
}
|
||||
} catch (XMLStreamException ex) {
|
||||
throw new IOException(ex);
|
||||
} finally {
|
||||
if (r != null) try { r.close(); } catch (XMLStreamException ignore) {}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
|
||||
import com.fuyuanshen.web.util.VideoProcessUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 视频处理服务
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class VideoProcessService {
|
||||
|
||||
// 配置参数
|
||||
private static final int MAX_VIDEO_SIZE = 10 * 1024 * 1024;
|
||||
private static final List<String> SUPPORTED_FORMATS = Arrays.asList(".mp4", ".avi", ".mov", ".mkv");
|
||||
private static final int FRAME_RATE = 15;
|
||||
private static final int DURATION = 2;
|
||||
private static final int WIDTH = 160;
|
||||
private static final int HEIGHT = 80;
|
||||
|
||||
private final VideoProcessUtil videoProcessUtil;
|
||||
|
||||
public List<String> processVideo(MultipartFile file, int code) {
|
||||
// 1. 参数校验
|
||||
validateVideoFile(file);
|
||||
|
||||
File tempFile = null;
|
||||
try {
|
||||
// 2. 创建临时文件
|
||||
tempFile = videoProcessUtil.createTempVideoFile(file);
|
||||
|
||||
// 3. 处理视频并提取帧数据
|
||||
List<String> hexList = videoProcessUtil.processVideoToHex(
|
||||
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());
|
||||
return hexList;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("视频处理失败", e);
|
||||
throw new RuntimeException("视频处理失败", e);
|
||||
} finally {
|
||||
// 4. 清理临时文件
|
||||
videoProcessUtil.deleteTempFile(tempFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证视频文件
|
||||
*/
|
||||
private void validateVideoFile(MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new IllegalArgumentException("上传文件不能为空");
|
||||
}
|
||||
|
||||
if (!isVideoFile(file.getOriginalFilename())) {
|
||||
throw new IllegalArgumentException("只允许上传视频文件");
|
||||
}
|
||||
|
||||
if (file.getSize() > MAX_VIDEO_SIZE) {
|
||||
throw new IllegalArgumentException("视频大小不能超过10MB");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是支持的视频格式
|
||||
*/
|
||||
private boolean isVideoFile(String filename) {
|
||||
if (filename == null || filename.lastIndexOf('.') == -1) {
|
||||
return false;
|
||||
}
|
||||
String ext = filename.substring(filename.lastIndexOf('.')).toLowerCase();
|
||||
return SUPPORTED_FORMATS.contains(ext);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
}
|
||||
@ -21,26 +21,31 @@ public class MqttRuleEngine {
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
private final LinkedHashMap<String, MqttMessageRule> rulesMap = new LinkedHashMap<>();
|
||||
|
||||
|
||||
public MqttRuleEngine(List<MqttMessageRule> rules) {
|
||||
// 按优先级排序
|
||||
rules.sort(Comparator.comparing(MqttMessageRule::getPriority));
|
||||
rules.forEach(rule -> rulesMap.put(rule.getCommandType(), rule)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 执行匹配
|
||||
*
|
||||
* @param context 处理上下文
|
||||
* @return
|
||||
*/
|
||||
public boolean executeRule(MqttRuleContext context) {
|
||||
int commandType = context.getCommandType();
|
||||
MqttMessageRule mqttMessageRule = rulesMap.get("Light_"+commandType);
|
||||
MqttMessageRule mqttMessageRule = rulesMap.get("Light_" + commandType);
|
||||
if (mqttMessageRule != null) {
|
||||
threadPoolTaskExecutor.execute(() -> mqttMessageRule.execute(context));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -10,22 +10,43 @@ import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
|
||||
|
||||
@Configuration
|
||||
public class MqttConfiguration {
|
||||
|
||||
@Autowired
|
||||
private MqttPropertiesConfig mqttPropertiesConfig;
|
||||
/** 创建连接工厂 **/
|
||||
|
||||
|
||||
/**
|
||||
* 创建连接工厂
|
||||
**/
|
||||
@Bean
|
||||
public MqttPahoClientFactory mqttPahoClientFactory(){
|
||||
public MqttPahoClientFactory mqttPahoClientFactory() {
|
||||
DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setCleanSession(true); //设置新会话
|
||||
options.setUserName(mqttPropertiesConfig.getUsername());
|
||||
options.setPassword(mqttPropertiesConfig.getPassword().toCharArray());
|
||||
options.setServerURIs(new String[]{mqttPropertiesConfig.getUrl()});
|
||||
options.setCleanSession(true); // 设置新会话
|
||||
|
||||
// 修复用户名为null时的空指针异常
|
||||
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.setConnectionTimeout(10); // 设置连接超时时间
|
||||
options.setKeepAliveInterval(60); // 设置心跳间隔
|
||||
factory.setConnectionOptions(options);
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -39,8 +39,14 @@ public class MqttInboundConfiguration {
|
||||
public MessageProducer messageProducer(){
|
||||
// 生成一个不重复的随机数
|
||||
String clientId = mqttPropertiesConfig.getSubClientId() + "_" + UUID.fastUUID();
|
||||
// 修复URL为null时的空指针异常
|
||||
String url = mqttPropertiesConfig.getUrl();
|
||||
if (url == null) {
|
||||
throw new IllegalStateException("MQTT服务器URL未配置");
|
||||
}
|
||||
|
||||
MqttPahoMessageDrivenChannelAdapter mqttPahoMessageDrivenChannelAdapter = new MqttPahoMessageDrivenChannelAdapter(
|
||||
mqttPropertiesConfig.getUrl(),
|
||||
url,
|
||||
clientId,
|
||||
mqttPahoClientFactory,
|
||||
mqttPropertiesConfig.getSubTopic().split(",")
|
||||
|
||||
@ -15,11 +15,14 @@ import org.springframework.messaging.MessageHandler;
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class MqttOutboundConfiguration {
|
||||
|
||||
@Autowired
|
||||
private MqttPropertiesConfig mqttPropertiesConfig;
|
||||
|
||||
@Autowired
|
||||
private MqttPahoClientFactory mqttPahoClientFactory;
|
||||
|
||||
|
||||
|
||||
// 消息通道
|
||||
@Bean
|
||||
public MessageChannel mqttOutboundChannel(){
|
||||
@ -32,8 +35,14 @@ public class MqttOutboundConfiguration {
|
||||
@ServiceActivator(inputChannel = "mqttOutboundChannel") // 指定处理器针对哪个通道的消息进行处理
|
||||
public MessageHandler mqttOutboundMessageHandler(){
|
||||
String clientId = mqttPropertiesConfig.getPubClientId() + "_" + UUID.fastUUID();
|
||||
// 修复URL为null时的空指针异常
|
||||
String url = mqttPropertiesConfig.getUrl();
|
||||
if (url == null) {
|
||||
throw new IllegalStateException("MQTT服务器URL未配置");
|
||||
}
|
||||
|
||||
MqttPahoMessageHandler mqttPahoMessageHandler = new MqttPahoMessageHandler(
|
||||
mqttPropertiesConfig.getUrl(),
|
||||
url,
|
||||
clientId,
|
||||
mqttPahoClientFactory
|
||||
);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.fuyuanshen.global.mqtt.constants;
|
||||
|
||||
public class DeviceRedisKeyConstants {
|
||||
|
||||
public static final String DEVICE_KEY_PREFIX = "device:";
|
||||
// 设备上报状态
|
||||
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";
|
||||
|
||||
}
|
||||
|
||||
@ -36,7 +36,6 @@ public class LightingCommandTypeConstants {
|
||||
*/
|
||||
public static final String SEND_MESSAGE = "Light_6";
|
||||
|
||||
|
||||
/**
|
||||
* 报警模式
|
||||
*/
|
||||
|
||||
@ -3,7 +3,6 @@ package com.fuyuanshen.global.mqtt.constants;
|
||||
|
||||
public interface MqttConstants {
|
||||
|
||||
|
||||
/**
|
||||
* 全局发布消息的key
|
||||
*/
|
||||
@ -13,4 +12,5 @@ public interface MqttConstants {
|
||||
* 全局订阅消息的key
|
||||
*/
|
||||
String GLOBAL_SUB_KEY = "A/";
|
||||
|
||||
}
|
||||
|
||||
@ -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(爆闪),6(SOS)
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,279 @@
|
||||
package com.fuyuanshen.global.mqtt.receiver;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleEngine;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttXinghanCommandType;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.queue.MqttMessageQueueConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 6075
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-11-05 17:41
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DeviceMessageHandler implements MessageHandler {
|
||||
|
||||
@Autowired
|
||||
private MqttRuleEngine ruleEngine;
|
||||
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
Object payload = message.getPayload();
|
||||
MessageHeaders headers = message.getHeaders();
|
||||
String receivedTopic = Objects.requireNonNull(headers.get("mqtt_receivedTopic")).toString();
|
||||
String receivedQos = Objects.requireNonNull(headers.get("mqtt_receivedQos")).toString();
|
||||
String timestamp = Objects.requireNonNull(headers.get("timestamp")).toString();
|
||||
|
||||
log.info("MQTT payload= {} \n receivedTopic = {} \n receivedQos = {} \n timestamp = {}",
|
||||
payload, receivedTopic, receivedQos, timestamp);
|
||||
|
||||
Dict payloadDict = JsonUtils.parseMap(payload.toString());
|
||||
if (receivedTopic == null || payloadDict == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析设备IMEI
|
||||
String[] subStr = receivedTopic.split("/");
|
||||
String deviceImei = subStr[1];
|
||||
|
||||
// 处理设备在线状态
|
||||
handleDeviceOnlineStatus(deviceImei);
|
||||
|
||||
// 处理不同类型的设备信息
|
||||
processDeviceInformation(payloadDict, deviceImei);
|
||||
|
||||
// 执行规则引擎处理
|
||||
executeRuleEngine(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理设备在线状态
|
||||
*/
|
||||
private void handleDeviceOnlineStatus(String deviceImei) {
|
||||
if (StringUtils.isNotBlank(deviceImei)) {
|
||||
// 添加去重队列
|
||||
String queueKey = MqttMessageQueueConstants.MQTT_MESSAGE_QUEUE_KEY;
|
||||
String dedupKey = MqttMessageQueueConstants.MQTT_MESSAGE_DEDUP_KEY;
|
||||
RedisUtils.offerDeduplicated(queueKey, dedupKey, deviceImei, Duration.ofSeconds(900));
|
||||
|
||||
// 设置设备在线状态
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY +
|
||||
DEVICE_KEY_PREFIX + deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1", Duration.ofSeconds(360));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理不同类型的设备信息
|
||||
*/
|
||||
private void processDeviceInformation(Dict payloadDict, String deviceImei) {
|
||||
// 开机画面
|
||||
if (payloadDict.containsKey("bootScreen")) {
|
||||
handleBootScreen(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 人员信息
|
||||
if (payloadDict.containsKey("personInfo")) {
|
||||
handlePersonInfo(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 设备信息
|
||||
if (payloadDict.containsKey("deviceInfo")) {
|
||||
handleDeviceInfo(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 经纬度
|
||||
if (payloadDict.containsKey("latitude") && payloadDict.containsKey("longitude")) {
|
||||
handleLocation(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 电子地图
|
||||
if (payloadDict.containsKey("mapData")) {
|
||||
handleMapData(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 电池电量
|
||||
if (payloadDict.containsKey("batteryLevel")) {
|
||||
handleBatteryLevel(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 开启/关闭状态
|
||||
if (payloadDict.containsKey("powerState")) {
|
||||
handlePowerState(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 海拔高度
|
||||
if (payloadDict.containsKey("altitude")) {
|
||||
handleAltitude(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 相对高度
|
||||
if (payloadDict.containsKey("relativeHeight")) {
|
||||
handleRelativeHeight(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 群呼/单呼
|
||||
if (payloadDict.containsKey("callType")) {
|
||||
handleCallType(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 文字信息
|
||||
if (payloadDict.containsKey("textMessage")) {
|
||||
handleTextMessage(payloadDict, deviceImei);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理开机画面
|
||||
*/
|
||||
private void handleBootScreen(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的开机画面信息", deviceImei);
|
||||
// 实现具体的开机画面处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理人员信息
|
||||
*/
|
||||
private void handlePersonInfo(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的人员信息", deviceImei);
|
||||
// 实现具体的人员信息处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理设备信息
|
||||
*/
|
||||
private void handleDeviceInfo(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的设备信息", deviceImei);
|
||||
// 实现具体的设备信息处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理位置信息
|
||||
*/
|
||||
private void handleLocation(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的位置信息: 纬度={}, 经度={}",
|
||||
deviceImei, payloadDict.getStr("latitude"), payloadDict.getStr("longitude"));
|
||||
// 实现具体的位置信息处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理电子地图数据
|
||||
*/
|
||||
private void handleMapData(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的电子地图数据", deviceImei);
|
||||
// 实现具体的电子地图数据处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理电池电量
|
||||
*/
|
||||
private void handleBatteryLevel(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的电池电量: {}", deviceImei, payloadDict.getStr("batteryLevel"));
|
||||
// 实现具体的电池电量处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理开关状态
|
||||
*/
|
||||
private void handlePowerState(Dict payloadDict, String deviceImei) {
|
||||
String powerState = payloadDict.getStr("powerState");
|
||||
log.info("处理设备{}的开关状态: {}", deviceImei, powerState);
|
||||
// 实现具体的开关状态处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理海拔高度
|
||||
*/
|
||||
private void handleAltitude(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的海拔高度: {}", deviceImei, payloadDict.getStr("altitude"));
|
||||
// 实现具体的海拔高度处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理相对高度
|
||||
*/
|
||||
private void handleRelativeHeight(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的相对高度: {}", deviceImei, payloadDict.getStr("relativeHeight"));
|
||||
// 实现具体的相对高度处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理呼叫类型
|
||||
*/
|
||||
private void handleCallType(Dict payloadDict, String deviceImei) {
|
||||
String callType = payloadDict.getStr("callType");
|
||||
log.info("处理设备{}的呼叫类型: {}", deviceImei, callType);
|
||||
// 实现具体的呼叫类型处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理文字信息
|
||||
*/
|
||||
private void handleTextMessage(Dict payloadDict, String deviceImei) {
|
||||
String textMessage = payloadDict.getStr("textMessage");
|
||||
log.info("处理设备{}的文字信息: {}", deviceImei, textMessage);
|
||||
// 实现具体的文字信息处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行规则引擎处理
|
||||
*/
|
||||
private void executeRuleEngine(Dict payloadDict, String deviceImei) {
|
||||
String state = payloadDict.getStr("state");
|
||||
Object[] convertArr = ImageToCArrayConverter.convertByteStringToMixedObjectArray(state);
|
||||
|
||||
if (convertArr.length > 0) {
|
||||
Byte val1 = (Byte) convertArr[0];
|
||||
MqttRuleContext context = new MqttRuleContext();
|
||||
context.setCommandType(val1);
|
||||
context.setConvertArr(convertArr);
|
||||
context.setDeviceImei(deviceImei);
|
||||
context.setPayloadDict(payloadDict);
|
||||
|
||||
boolean ruleExecuted = ruleEngine.executeRule(context);
|
||||
|
||||
if (!ruleExecuted) {
|
||||
log.warn("未找到匹配的规则来处理命令类型: {}", val1);
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 追加:根据报文内容识别格式并统一解析 ===== */
|
||||
int intType = MqttXinghanCommandType.computeVirtualCommandType(payloadDict);
|
||||
if (intType > 0) {
|
||||
MqttRuleContext newCtx = new MqttRuleContext();
|
||||
newCtx.setCommandType((byte) intType);
|
||||
newCtx.setDeviceImei(deviceImei);
|
||||
newCtx.setPayloadDict(payloadDict);
|
||||
|
||||
boolean ok = ruleEngine.executeRule(newCtx);
|
||||
if (!ok) {
|
||||
log.warn("新规则引擎未命中, imei={}", deviceImei);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -53,7 +53,7 @@ public class ReceiverMessageHandler implements MessageHandler {
|
||||
if(StringUtils.isNotBlank(deviceImei)){
|
||||
String queueKey = MqttMessageQueueConstants.MQTT_MESSAGE_QUEUE_KEY;
|
||||
String dedupKey = MqttMessageQueueConstants.MQTT_MESSAGE_DEDUP_KEY;
|
||||
RedisUtils.offerDeduplicated(queueKey,dedupKey,deviceImei, Duration.ofHours(24));
|
||||
RedisUtils.offerDeduplicated(queueKey,dedupKey,deviceImei, Duration.ofSeconds(900));
|
||||
//在线状态
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1", Duration.ofSeconds(360));
|
||||
@ -90,4 +90,5 @@ public class ReceiverMessageHandler implements MessageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -57,12 +57,12 @@ public class BjqAlarmRule implements MqttMessageRule {
|
||||
if (StringUtils.isNotBlank(convertValue)) {
|
||||
// 将设备状态信息存储到Redis中
|
||||
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)) {
|
||||
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, "1");
|
||||
}else if ("0".equals(convertValue)){
|
||||
} else if ("0".equals(convertValue)) {
|
||||
RedisUtils.deleteObject(sendMessageIng);
|
||||
RedisUtils.deleteObject(deviceRedisKey);
|
||||
}
|
||||
|
||||
@ -71,5 +71,4 @@ public class BjqLaserModeSettingsRule implements MqttMessageRule {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -45,6 +45,7 @@ public class BjqModeRule implements MqttMessageRule {
|
||||
return LightingCommandTypeConstants.LIGHT_MODE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
|
||||
|
||||
@ -1,32 +1,18 @@
|
||||
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.equipment.utils.map.GetAddressFromLatUtil;
|
||||
import com.fuyuanshen.equipment.utils.map.LngLonUtil;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
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.MqttConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
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.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
/**
|
||||
* 定位数据命令处理
|
||||
@ -55,4 +41,5 @@ public class BjqPersonnelInfoDataRule implements MqttMessageRule {
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(30));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.xinghan;
|
||||
|
||||
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 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.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
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.redis.utils.RedisUtils;
|
||||
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.DeviceFenceAccessRecordBo;
|
||||
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.DeviceFenceAccessRecordMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceGeoFenceMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
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.LngLonUtil;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
@ -30,13 +44,16 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
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.GLOBAL_REDIS_KEY;
|
||||
@ -72,6 +89,12 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
private final IDeviceAlarmService deviceAlarmService;
|
||||
private final DeviceService deviceService;
|
||||
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
|
||||
public void execute(MqttRuleContext context) {
|
||||
@ -127,16 +150,20 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
* 入口:保存报警(SOS 与 Shake 完全独立)
|
||||
*/
|
||||
public void saveAlarm(String deviceImei, MqttXinghanJson status) {
|
||||
int sos = Optional.ofNullable(status.getStaSOSGrade()).orElse(0);
|
||||
// 1. 处理 SOS 报警
|
||||
handleSingleAlarm(deviceImei,
|
||||
sos > 0,
|
||||
AlarmTypeEnum.SOS);
|
||||
int shake = Optional.ofNullable(status.getStaShakeBit()).orElse(0);
|
||||
// 2. 处理 Shake 报警
|
||||
handleSingleAlarm(deviceImei,
|
||||
shake > 0,
|
||||
AlarmTypeEnum.SHAKE);
|
||||
try {
|
||||
int sos = Optional.ofNullable(status.getStaSOSGrade()).orElse(0);
|
||||
// 1. 处理 SOS 报警
|
||||
handleSingleAlarm(deviceImei,
|
||||
sos > 0,
|
||||
AlarmTypeEnum.SOS);
|
||||
int shake = Optional.ofNullable(status.getStaShakeBit()).orElse(0);
|
||||
// 2. 处理 Shake 报警
|
||||
handleSingleAlarm(deviceImei,
|
||||
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(
|
||||
GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX);
|
||||
if (StrUtil.isNotBlank(location)) {
|
||||
bo.setLocation(JSONObject.parseObject(location).getString("address"));
|
||||
bo.setLocation(com.alibaba.fastjson2.JSONObject.parseObject(location).getString("address"));
|
||||
}
|
||||
return bo;
|
||||
}
|
||||
@ -259,63 +286,312 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
public void asyncSendLocationToRedisWithFuture(String deviceImei, String latitude, String longitude) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
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;
|
||||
}
|
||||
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");
|
||||
String cacheLongitude = jsonOBj.getString("wgs84_longitude");
|
||||
String[] latArr1 = cacheLatitude.split("\\.");
|
||||
String[] lonArr1 = cacheLongitude.split("\\.");
|
||||
// 2. 读取 Redis 中缓存的上一次位置
|
||||
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX;
|
||||
String cachedJson = RedisUtils.getCacheObject(redisKey);
|
||||
|
||||
String cacheStr1 = latArr1[0] +"."+ latArr1[1].substring(0,4);
|
||||
String cacheStr2 = lonArr1[0] +"."+ lonArr1[1].substring(0,4);
|
||||
if(str1.equals(cacheStr1) && str2.equals(cacheStr2)){
|
||||
log.info("位置信息未发生变化: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
|
||||
return;
|
||||
if (StringUtils.isNotBlank(cachedJson)) {
|
||||
com.alibaba.fastjson2.JSONObject cachedObj = com.alibaba.fastjson2.JSONObject.parseObject(cachedJson);
|
||||
String cachedWgs84Lat = cachedObj.getString("wgs84_latitude");
|
||||
String cachedWgs84Lon = cachedObj.getString("wgs84_longitude");
|
||||
|
||||
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("位置未发生明显变化({}米 <= {}米),不更新 Redis,deviceImei={}, lat={}, lon={}",
|
||||
distance, MOVEMENT_THRESHOLD_METER, deviceImei, latitude, longitude);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 构造位置信息对象
|
||||
Map<String, Object> locationInfo = new LinkedHashMap<>();
|
||||
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());
|
||||
// 3. 位置有明显变化,执行保存
|
||||
doSaveLocation(deviceImei, latitude, longitude);
|
||||
|
||||
|
||||
|
||||
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) {
|
||||
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("位置信息已更新 Redis,deviceImei={}, 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)
|
||||
*/
|
||||
@ -358,4 +634,6 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,18 @@
|
||||
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.databind.ObjectMapper;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
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.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
@ -21,6 +30,8 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
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.GLOBAL_REDIS_KEY;
|
||||
@ -40,6 +51,18 @@ public class XinghanSendAlarmMessageRule implements MqttMessageRule {
|
||||
|
||||
private final MqttGateway mqttGateway;
|
||||
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
|
||||
public String getCommandType() {
|
||||
@ -62,9 +85,36 @@ public class XinghanSendAlarmMessageRule implements MqttMessageRule {
|
||||
log.warn("重复消息丢弃 {}", dedupKey);
|
||||
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! —— 成功标记
|
||||
if ("cover!".equalsIgnoreCase(respText)) {
|
||||
if (BREAK_NEWS_SUCCESS.equalsIgnoreCase(respText)) {
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
log.info("设备 {} 发送紧急通知完成", ctx.getDeviceImei());
|
||||
return;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -27,11 +27,12 @@ public class MqttMessageConsumer {
|
||||
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
|
||||
|
||||
// 创建两个线程池:一个用于消息获取,一个用于业务处理
|
||||
private ExecutorService messageConsumerPool = Executors.newFixedThreadPool(3);
|
||||
private ExecutorService messageProcessorPool = Executors.newFixedThreadPool(10);
|
||||
|
||||
|
||||
// 初始化方法,启动消息监听
|
||||
@PostConstruct
|
||||
public void start() {
|
||||
@ -130,4 +131,5 @@ public class MqttMessageConsumer {
|
||||
log.error("业务处理线程 {} 处理消息时发生错误: {}", threadName, message, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.vo.OnlineStatusVo;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -21,23 +22,22 @@ public class OnlineStatusTask {
|
||||
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
|
||||
|
||||
// 使用cron表达式,每分钟的第0秒执行
|
||||
@Scheduled(cron = "0 */3 * * * ?")
|
||||
public void cronTask() {
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||
devices.forEach(item -> {
|
||||
List<OnlineStatusVo> onlineStatusVos = deviceMapper.queryOnlineStatusList();
|
||||
onlineStatusVos.forEach(item -> {
|
||||
String onlineStatusKey = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||
String status = RedisUtils.getCacheObject(onlineStatusKey);
|
||||
String onlineStatus = item.getOnlineStatus()==null?"0" : item.getOnlineStatus().toString();
|
||||
if("1".equals(onlineStatus) || "2".equals(onlineStatus)){
|
||||
if(StringUtils.isBlank(status) || "0".equals(status)){
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", item.getId());
|
||||
updateWrapper.set("online_status", 0);
|
||||
deviceMapper.update(updateWrapper);
|
||||
}
|
||||
if(StringUtils.isBlank(status) || "0".equals(status)){
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", item.getId());
|
||||
updateWrapper.set("online_status", 0);
|
||||
deviceMapper.update(updateWrapper);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -63,10 +63,6 @@ import java.util.Map;
|
||||
@RequestMapping("/mp")
|
||||
public class MPAuthController {
|
||||
|
||||
private final AppLoginService loginService;
|
||||
private final SysRegisterService registerService;
|
||||
private final ISysConfigService configService;
|
||||
private final ISysTenantService tenantService;
|
||||
private final ISysClientService clientService;
|
||||
private final MPAuthService mpAuthService;
|
||||
private final MPService mpService;
|
||||
@ -74,7 +70,7 @@ public class MPAuthController {
|
||||
|
||||
@Operation(summary = "小程序登录授权")
|
||||
@PostMapping(value = "/login")
|
||||
public ResponseEntity<Object> login(@RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception {
|
||||
public ResponseEntity<Object> login(@RequestBody AuthUserDto authUser) throws Exception {
|
||||
|
||||
Long phoneNumber = authUser.getPhoneNumber();
|
||||
// 判断小程序用户是否存在,不存在创建
|
||||
|
||||
@ -60,9 +60,9 @@ import java.util.function.Supplier;
|
||||
@Service
|
||||
public class MPAuthService {
|
||||
|
||||
private final ISysUserService userService;
|
||||
private final AppUserService appUserService;
|
||||
|
||||
|
||||
/**
|
||||
* 小程序注册
|
||||
*/
|
||||
@ -128,6 +128,7 @@ public class MPAuthService {
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建登录用户
|
||||
*/
|
||||
@ -160,5 +161,4 @@ public class MPAuthService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -10,11 +10,8 @@ import org.springframework.stereotype.Service;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
||||
|
||||
public interface MPService {
|
||||
|
||||
|
||||
/**
|
||||
* 获取小程序用户信息
|
||||
*
|
||||
@ -23,4 +20,5 @@ public interface MPService {
|
||||
UserApp getMpUser(Long phoneNumber);
|
||||
|
||||
UserApp loadUserByUsername(String username);
|
||||
|
||||
}
|
||||
|
||||
@ -8,5 +8,4 @@ package com.fuyuanshen.mp.service.impl;
|
||||
|
||||
public class MPAuthServiceImpl {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -19,11 +19,9 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class MPServiceImpl implements MPService {
|
||||
|
||||
|
||||
private final AppUserService appUserService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取小程序用户信息
|
||||
*
|
||||
|
||||
@ -101,13 +101,13 @@ public class AuthController {
|
||||
// 登录
|
||||
LoginVo loginVo = IAuthStrategy.login(body, client, grantType);
|
||||
|
||||
Long userId = LoginHelper.getUserId();
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
SseMessageDto dto = new SseMessageDto();
|
||||
dto.setMessage("欢迎登录fys-Vue-Plus后台管理系统");
|
||||
dto.setUserIds(List.of(userId));
|
||||
SseMessageUtils.publishMessage(dto);
|
||||
}, 5, TimeUnit.SECONDS);
|
||||
// Long userId = LoginHelper.getUserId();
|
||||
// scheduledExecutorService.schedule(() -> {
|
||||
// SseMessageDto dto = new SseMessageDto();
|
||||
// dto.setMessage("欢迎登录fys-Vue-Plus后台管理系统");
|
||||
// dto.setUserIds(List.of(userId));
|
||||
// SseMessageUtils.publishMessage(dto);
|
||||
// }, 5, TimeUnit.SECONDS);
|
||||
return R.ok(loginVo);
|
||||
}
|
||||
|
||||
|
||||
@ -51,6 +51,7 @@ public class CaptchaController {
|
||||
private final CaptchaProperties captchaProperties;
|
||||
private final MailProperties mailProperties;
|
||||
|
||||
|
||||
/**
|
||||
* 短信验证码
|
||||
*
|
||||
@ -156,4 +157,4 @@ public class CaptchaController {
|
||||
return captchaVo;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -28,6 +28,7 @@ public class DeviceBJQController extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
@ -35,10 +36,11 @@ public class DeviceBJQController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDeviceDetailVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
@ -74,7 +76,7 @@ public class DeviceBJQController extends BaseController {
|
||||
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if(file.getSize()>1024*1024*2){
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.uploadDeviceLogo(bo);
|
||||
@ -90,7 +92,7 @@ public class DeviceBJQController extends BaseController {
|
||||
public R<Void> batchUploadLogo(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if(file.getSize()>1024*1024*2){
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.batchUploadLogo(bo);
|
||||
@ -112,7 +114,6 @@ public class DeviceBJQController extends BaseController {
|
||||
|
||||
/**
|
||||
* 灯光亮度设置
|
||||
*
|
||||
*/
|
||||
// @FunctionAccessAnnotation("lightBrightnessSettings")
|
||||
@PostMapping("/lightBrightnessSettings")
|
||||
@ -123,7 +124,6 @@ public class DeviceBJQController extends BaseController {
|
||||
|
||||
/**
|
||||
* 激光模式设置
|
||||
*
|
||||
*/
|
||||
@PostMapping("/laserModeSettings")
|
||||
// @FunctionAccessAnnotation("laserModeSettings")
|
||||
|
||||
@ -29,7 +29,7 @@ import java.util.Map;
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/device")
|
||||
public class DeviceControlCenterController extends BaseController {
|
||||
public class DeviceControlCenterController extends BaseController {
|
||||
|
||||
private final DeviceBizService appDeviceService;
|
||||
|
||||
@ -42,6 +42,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return appDeviceService.queryWebDeviceList(bo, pageQuery);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 绑定设备
|
||||
*/
|
||||
@ -59,6 +60,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return toAjax(appDeviceService.unBindDevice(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备类型列表
|
||||
*/
|
||||
@ -68,6 +70,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return R.ok(typeList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重命名设备
|
||||
*
|
||||
@ -95,14 +98,16 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return R.ok(appDeviceService.getDeviceInfo(deviceMac));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 指令下发记录
|
||||
*/
|
||||
@GetMapping("/instructionRecord")
|
||||
public TableDataInfo<InstructionRecordVo> getInstructionRecord(InstructionRecordDto dto, PageQuery pageQuery) {
|
||||
return appDeviceService.getInstructionRecord(dto,pageQuery);
|
||||
return appDeviceService.getInstructionRecord(dto, pageQuery);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*/
|
||||
@ -111,7 +116,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
pageQuery.setPageNum(1);
|
||||
pageQuery.setPageSize(2000);
|
||||
TableDataInfo<InstructionRecordVo> instructionRecord = appDeviceService.getInstructionRecord(dto, pageQuery);
|
||||
if(instructionRecord.getRows() == null){
|
||||
if (instructionRecord.getRows() == null) {
|
||||
return;
|
||||
}
|
||||
ExcelUtil.exportExcel(instructionRecord.getRows(), "设备操作日志", InstructionRecordVo.class, response);
|
||||
@ -123,7 +128,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/locationHistory")
|
||||
public TableDataInfo<LocationHistoryVo> getLocationHistory(InstructionRecordDto dto, PageQuery pageQuery) {
|
||||
return appDeviceService.getLocationHistory(dto,pageQuery);
|
||||
return appDeviceService.getLocationHistory(dto, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,7 +139,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
pageQuery.setPageNum(1);
|
||||
pageQuery.setPageSize(2000);
|
||||
TableDataInfo<LocationHistoryVo> result = appDeviceService.getLocationHistory(dto, pageQuery);
|
||||
if(result.getRows() == null){
|
||||
if (result.getRows() == null) {
|
||||
return;
|
||||
}
|
||||
ExcelUtil.exportExcel(result.getRows(), "历史轨迹记录", LocationHistoryVo.class, response);
|
||||
@ -147,4 +152,5 @@ public class DeviceControlCenterController extends BaseController {
|
||||
public R<List<LocationHistoryDetailVo>> getLocationHistoryDetail(Long id) {
|
||||
return R.ok(appDeviceService.getLocationHistoryDetail(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -160,4 +160,5 @@ public class DeviceXinghanController extends BaseController {
|
||||
RedisUtils.setCacheObject(versionKey, json, Duration.ofDays(30));
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,140 @@
|
||||
package com.fuyuanshen.web.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.AppDeviceDetailVo;
|
||||
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.DeviceBJQBizService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* web后台:设备控制类
|
||||
* 6075
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/bjq6075/device")
|
||||
public class DeviceBJQ6075Controller extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDeviceDetailVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
@PostMapping(value = "/registerPersonInfo")
|
||||
// @FunctionAccessAnnotation("registerPersonInfo")
|
||||
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
|
||||
return toAjax(appDeviceService.registerPersonInfo(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
*/
|
||||
@PostMapping(value = "/sendMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
|
||||
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService.sendMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送报警信息
|
||||
*/
|
||||
@PostMapping(value = "/sendAlarmMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
|
||||
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService.sendAlarmMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传设备logo图片
|
||||
*/
|
||||
@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");
|
||||
}
|
||||
appDeviceService.uploadDeviceLogo(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传设备logo图片
|
||||
*/
|
||||
@PostMapping("/batchUploadLogo")
|
||||
@FunctionAccessAnnotation("batchUploadLogo")
|
||||
public R<Void> batchUploadLogo(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.batchUploadLogo(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
||||
*/
|
||||
// @FunctionAccessAnnotation("lightModeSettings")
|
||||
@PostMapping("/lightModeSettings")
|
||||
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.lightModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光亮度设置
|
||||
*/
|
||||
// @FunctionAccessAnnotation("lightBrightnessSettings")
|
||||
@PostMapping("/lightBrightnessSettings")
|
||||
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService.lightBrightnessSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 激光模式设置
|
||||
*/
|
||||
@PostMapping("/laserModeSettings")
|
||||
// @FunctionAccessAnnotation("laserModeSettings")
|
||||
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService.laserModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@ -59,6 +59,7 @@ public class DeviceFenceAccessRecordController extends BaseController {
|
||||
ExcelUtil.exportExcel(list, "围栏进出记录", DeviceFenceAccessRecordVo.class, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取围栏进出记录详细信息
|
||||
*
|
||||
|
||||
@ -3,6 +3,7 @@ package com.fuyuanshen.web.controller.device.fence;
|
||||
import java.util.List;
|
||||
|
||||
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.query.FenceCheckRequest;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceGeoFenceVo;
|
||||
@ -59,9 +60,15 @@ public class DeviceGeoFenceController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(DeviceGeoFenceBo bo, HttpServletResponse response) {
|
||||
List<DeviceGeoFenceVo> list = deviceGeoFenceService.queryList(bo);
|
||||
// 设置区域类型名称
|
||||
list.forEach(item -> {
|
||||
item.setAreaTypeNameByAreaType();
|
||||
item.setIsActiveNameByIsActive(); // 添加这行来设置激活状态名称
|
||||
});
|
||||
ExcelUtil.exportExcel(list, "电子围栏", DeviceGeoFenceVo.class, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取电子围栏详细信息
|
||||
*
|
||||
@ -96,6 +103,7 @@ public class DeviceGeoFenceController extends BaseController {
|
||||
return toAjax(deviceGeoFenceService.updateByBo(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除电子围栏
|
||||
*
|
||||
@ -123,4 +131,26 @@ public class DeviceGeoFenceController extends BaseController {
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,107 @@
|
||||
package com.fuyuanshen.web.service.device;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
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.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoRecordsMapper;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.*;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.equipment.enums.LightModeEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.buildArr;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.generateFixedBitmapData;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
|
||||
@Service
|
||||
public interface DeviceBJQ6075BizService {
|
||||
|
||||
/**
|
||||
* 获取设备详情
|
||||
*
|
||||
* @param id 设备ID
|
||||
* @return 设备详情
|
||||
*/
|
||||
public AppDevice6075DetailVo getInfo(Long id);
|
||||
|
||||
public int sendMessage(AppDeviceSendMsgBo bo);
|
||||
|
||||
/**
|
||||
* 记录设备操作日志
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param content 日志内容
|
||||
* @param operator 操作人
|
||||
*/
|
||||
public void recordDeviceLog(Long deviceId, String deviceName, String deviceAction, String content, Long operator);
|
||||
|
||||
/**
|
||||
* 注册人员信息
|
||||
*
|
||||
* @param bo 参数
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean registerPersonInfo(AppPersonnelInfoBo bo);
|
||||
|
||||
public void uploadDeviceLogo2(AppDeviceLogoUploadDto bo);
|
||||
|
||||
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo);
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* (主光模式)
|
||||
* 0(关闭灯光),1(强光),2(超强光), 3(工作光), 4(节能光),5(爆闪),6(SOS)
|
||||
*/
|
||||
public void lightModeSettings(DeviceInstructDto params);
|
||||
|
||||
// 灯光亮度设置
|
||||
public void lightBrightnessSettings(DeviceInstructDto params);
|
||||
|
||||
// 激光模式设置
|
||||
public void laserModeSettings(DeviceInstructDto params);
|
||||
|
||||
public String mapReverseGeocoding(DeviceInstructDto params);
|
||||
|
||||
public int sendAlarmMessage(AppDeviceSendMsgBo bo);
|
||||
|
||||
public void messageSending(String deviceImei);
|
||||
|
||||
public boolean getDeviceStatus(String deviceImei);
|
||||
|
||||
public void batchUploadLogo(AppDeviceLogoUploadDto bo);
|
||||
|
||||
}
|
||||
@ -59,6 +59,7 @@ public class DeviceBJQBizService {
|
||||
private final MqttGateway mqttGateway;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
|
||||
|
||||
public int sendMessage(AppDeviceSendMsgBo bo) {
|
||||
List<Long> deviceIds = bo.getDeviceIds();
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
@ -69,8 +70,8 @@ public class DeviceBJQBizService {
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在" + deviceId);
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
try {
|
||||
ClassPathResource resource = new ClassPathResource("image/background.png");
|
||||
@ -78,26 +79,26 @@ public class DeviceBJQBizService {
|
||||
|
||||
byte[] largeData = ImageWithTextGenerate.generate160x80ImageWithText2(bo.getSendMsg(), inputStream, 25600);
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data" , Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data", Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data");
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data");
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
log.info("发送信息第0块数据大小: {} 字节",specificChunk.length);
|
||||
log.info("发送信息第0块数据大小: {} 字节", specificChunk.length);
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(6);
|
||||
intData.add(1);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk),intData);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
|
||||
intData.add(0);
|
||||
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));
|
||||
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));
|
||||
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", deviceId)
|
||||
@ -106,10 +107,10 @@ public class DeviceBJQBizService {
|
||||
|
||||
recordDeviceLog(deviceId, device.getDeviceName(), "发送信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
log.info("发送信息设备发送信息失败:{}" ,deviceId);
|
||||
log.info("发送信息设备发送信息失败:{}", deviceId);
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
//发送消息
|
||||
// 发送消息
|
||||
messageSending(device.getDeviceImei());
|
||||
}
|
||||
|
||||
@ -119,11 +120,12 @@ public class DeviceBJQBizService {
|
||||
|
||||
/**
|
||||
* 记录设备操作日志
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param content 日志内容
|
||||
* @param content 日志内容
|
||||
* @param operator 操作人
|
||||
*/
|
||||
private void recordDeviceLog(Long deviceId,String deviceName, String deviceAction, String content, Long operator) {
|
||||
private void recordDeviceLog(Long deviceId, String deviceName, String deviceAction, String content, Long operator) {
|
||||
try {
|
||||
// 创建设备日志实体
|
||||
com.fuyuanshen.equipment.domain.DeviceLog deviceLog = new com.fuyuanshen.equipment.domain.DeviceLog();
|
||||
@ -171,62 +173,62 @@ public class DeviceBJQBizService {
|
||||
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
|
||||
vo.setPersonnelInfo(personnelInfoVo);
|
||||
}
|
||||
//设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei()+ DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
//设备在线状态
|
||||
if("1".equals(onlineStatus)){
|
||||
vo.setOnlineStatus(1);
|
||||
}else if("2".equals(onlineStatus)){
|
||||
vo.setOnlineStatus(2);
|
||||
}else{
|
||||
vo.setOnlineStatus(0);
|
||||
// 设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
// 设备在线状态
|
||||
if ("1".equals(onlineStatus)) {
|
||||
vo.setOnlineStatus(1);
|
||||
} else if ("2".equals(onlineStatus)) {
|
||||
vo.setOnlineStatus(2);
|
||||
} else {
|
||||
vo.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX);
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
vo.setMainLightMode(jsonObject.getString("mainLightMode"));
|
||||
vo.setLaserLightMode(jsonObject.getString("laserLightMode"));
|
||||
vo.setBatteryPercentage(jsonObject.getString("batteryPercentage"));
|
||||
vo.setChargeState(jsonObject.getString("chargeState"));
|
||||
vo.setBatteryRemainingTime(jsonObject.getString("batteryRemainingTime"));
|
||||
}else{
|
||||
} else {
|
||||
vo.setBatteryPercentage("0");
|
||||
}
|
||||
|
||||
String lightModeStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_MODE_KEY_PREFIX);
|
||||
String lightModeStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_MODE_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
vo.setMainLightMode(lightModeStatus);
|
||||
}
|
||||
|
||||
String lightBrightnessStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(lightBrightnessStatus)){
|
||||
String lightBrightnessStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(lightBrightnessStatus)) {
|
||||
vo.setLightBrightness(lightBrightnessStatus);
|
||||
}
|
||||
|
||||
String laserLightMode = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LASER_MODE_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(laserLightMode)){
|
||||
String laserLightMode = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LASER_MODE_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(laserLightMode)) {
|
||||
vo.setLaserLightMode(laserLightMode);
|
||||
}
|
||||
|
||||
// 获取经度纬度
|
||||
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
|
||||
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
|
||||
String locationInfo = RedisUtils.getCacheObject(locationKey);
|
||||
if(StringUtils.isNotBlank(locationInfo)){
|
||||
if (StringUtils.isNotBlank(locationInfo)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
|
||||
vo.setLongitude(jsonObject.get("longitude").toString());
|
||||
vo.setLatitude(jsonObject.get("latitude").toString());
|
||||
vo.setAddress((String)jsonObject.get("address"));
|
||||
vo.setAddress((String) jsonObject.get("address"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ device.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(alarmStatus)){
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
vo.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
|
||||
String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ device.getDeviceImei()+ DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(lightBrightness)){
|
||||
String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(lightBrightness)) {
|
||||
vo.setLightBrightness(lightBrightness);
|
||||
}
|
||||
|
||||
@ -234,15 +236,14 @@ public class DeviceBJQBizService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
||||
Long deviceId = bo.getDeviceId();
|
||||
Device deviceObj = deviceMapper.selectById(deviceId);
|
||||
if (deviceObj == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
if(getDeviceStatus(deviceObj.getDeviceImei())){
|
||||
throw new ServiceException(deviceObj.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(deviceObj.getDeviceImei())) {
|
||||
throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
||||
.eq("device_id", deviceId);
|
||||
@ -266,7 +267,7 @@ public class DeviceBJQBizService {
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo);
|
||||
String logContent = "单位:"+bo.getUnitName()+",职位:"+bo.getPosition()+",姓名:"+bo.getName()+",ID:"+bo.getCode();
|
||||
String logContent = "单位:" + bo.getUnitName() + ",职位:" + bo.getPosition() + ",姓名:" + bo.getName() + ",ID:" + bo.getCode();
|
||||
recordDeviceLog(deviceId, deviceObj.getDeviceName(), "人员信息登记", logContent, AppLoginHelper.getUserId());
|
||||
if (ObjectUtils.length(appPersonnelInfoVos) == 0) {
|
||||
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
@ -297,6 +298,7 @@ public class DeviceBJQBizService {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void uploadDeviceLogo2(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
@ -322,25 +324,26 @@ public class DeviceBJQBizService {
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("instruct", combinedData);
|
||||
String[] specificChunk = ImageToCArrayConverter.getChunk2(hexArray, 0, bo.getChunkSize());
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , Arrays.toString(specificChunk));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),Arrays.toString(specificChunk));
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, Arrays.toString(specificChunk));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), Arrays.toString(specificChunk));
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
// throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
log.info(device.getDeviceName()+",设备已断开连接");
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", device.getDeviceName()+",设备已断开连接", AppLoginHelper.getUserId());
|
||||
log.info(device.getDeviceName() + ",设备已断开连接");
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", device.getDeviceName() + ",设备已断开连接", AppLoginHelper.getUserId());
|
||||
return;
|
||||
}
|
||||
MultipartFile file = bo.getFile();
|
||||
@ -351,9 +354,9 @@ public class DeviceBJQBizService {
|
||||
log.info("原始数据大小: {} 字节", largeData.length);
|
||||
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() +DEVICE_BOOT_LOGO_KEY_PREFIX, Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX, Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX);
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX);
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
@ -363,18 +366,18 @@ public class DeviceBJQBizService {
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(3);
|
||||
intData.add(1);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk),intData);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
|
||||
intData.add(0);
|
||||
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));
|
||||
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));
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
@ -389,13 +392,13 @@ public class DeviceBJQBizService {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(1);
|
||||
intData.add(instructValue);
|
||||
@ -404,26 +407,26 @@ public class DeviceBJQBizService {
|
||||
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));
|
||||
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){
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "灯光模式", modeEnum != null ? modeEnum.getName() : null, AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
//灯光亮度设置
|
||||
// 灯光亮度设置
|
||||
public void lightBrightnessSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
String instructValue = params.getInstructValue();
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
@ -431,10 +434,10 @@ public class DeviceBJQBizService {
|
||||
String[] values = instructValue.split("\\.");
|
||||
String value1 = values[0];
|
||||
String value2 = values[1];
|
||||
if(StringUtils.isNoneBlank(value1)){
|
||||
if (StringUtils.isNoneBlank(value1)) {
|
||||
intData.add(Integer.parseInt(value1));
|
||||
}
|
||||
if(StringUtils.isNoneBlank(value2)){
|
||||
if (StringUtils.isNoneBlank(value2)) {
|
||||
intData.add(Integer.parseInt(value2));
|
||||
}
|
||||
intData.add(0);
|
||||
@ -442,25 +445,25 @@ public class DeviceBJQBizService {
|
||||
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));
|
||||
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));
|
||||
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
//激光模式设置
|
||||
// 激光模式设置
|
||||
public void laserModeSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
@ -471,15 +474,15 @@ public class DeviceBJQBizService {
|
||||
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));
|
||||
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));
|
||||
// 1代表开启激光灯,此时主灯关闭,主灯控件为关机状态,为0代表关闭激光灯
|
||||
if("1".equals(params.getInstructValue())){
|
||||
if ("1".equals(params.getInstructValue())) {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "激光模式设置", "开启激光灯", AppLoginHelper.getUserId());
|
||||
}else{
|
||||
} else {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "激光模式设置", "关闭激光灯", AppLoginHelper.getUserId());
|
||||
}
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
@ -489,7 +492,7 @@ public class DeviceBJQBizService {
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("device_imei", params.getDeviceImei());
|
||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||
if(ObjectUtils.length( devices) ==0){
|
||||
if (ObjectUtils.length(devices) == 0) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
|
||||
@ -507,8 +510,8 @@ public class DeviceBJQBizService {
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在" + deviceId);
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
try {
|
||||
|
||||
@ -521,39 +524,39 @@ public class DeviceBJQBizService {
|
||||
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));
|
||||
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));
|
||||
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", deviceId)
|
||||
.set("send_msg", bo.getSendMsg());
|
||||
deviceMapper.update(updateWrapper);
|
||||
if("0".equals(bo.getInstructValue())){
|
||||
if ("0".equals(bo.getInstructValue())) {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "解除告警信息", "关闭设备", AppLoginHelper.getUserId());
|
||||
}else{
|
||||
} else {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "发送告警信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("设备发送告警信息信息失败:{}" ,deviceId);
|
||||
log.info("设备发送告警信息信息失败:{}", deviceId);
|
||||
throw new ServiceException("设备发送告警信息信息失败");
|
||||
}
|
||||
messageSending(device.getDeviceImei());
|
||||
}
|
||||
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送告警信息指令失败");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private void messageSending(String deviceImei){
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + deviceImei + ":messageSending";
|
||||
private void messageSending(String deviceImei) {
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + ":messageSending";
|
||||
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
|
||||
}
|
||||
|
||||
private boolean getDeviceStatus(String deviceImei) {
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||
return RedisUtils.getCacheObject(deviceOnlineStatusRedisKey) == null;
|
||||
}
|
||||
|
||||
@ -571,4 +574,5 @@ public class DeviceBJQBizService {
|
||||
uploadDeviceLogo(dto);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -59,8 +59,8 @@ public class DeviceBizService {
|
||||
private final RealTimeStatusEngine realTimeStatusEngine;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
private final AppDeviceShareMapper appDeviceShareMapper;
|
||||
private final AppUserMapper appUserMapper;;
|
||||
|
||||
private final AppUserMapper appUserMapper;
|
||||
;
|
||||
|
||||
|
||||
public List<APPDeviceTypeVo> getTypeList() {
|
||||
@ -84,37 +84,37 @@ public class DeviceBizService {
|
||||
}
|
||||
Page<AppDeviceVo> result = deviceMapper.queryAppBindDeviceList(pageQuery.build(), bo);
|
||||
List<AppDeviceVo> records = result.getRecords();
|
||||
if(records != null && !records.isEmpty()){
|
||||
if (records != null && !records.isEmpty()) {
|
||||
records.forEach(item -> {
|
||||
if(item.getCommunicationMode()!=null && item.getCommunicationMode() == 0){
|
||||
if (item.getCommunicationMode() != null && item.getCommunicationMode() == 0) {
|
||||
|
||||
//设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if("1".equals(onlineStatus)){
|
||||
// 设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if ("1".equals(onlineStatus)) {
|
||||
item.setOnlineStatus(1);
|
||||
}else if("2".equals(onlineStatus)){
|
||||
} else if ("2".equals(onlineStatus)) {
|
||||
item.setOnlineStatus(2);
|
||||
}else{
|
||||
} else {
|
||||
item.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
item.setBattery(jsonObject.getString("batteryPercentage"));
|
||||
}else{
|
||||
} else {
|
||||
item.setBattery("0");
|
||||
}
|
||||
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_LOCATION_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(location)){
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_LOCATION_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(location)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(location);
|
||||
item.setLatitude(jsonObject.getString("latitude"));
|
||||
item.setLongitude(jsonObject.getString("longitude"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(alarmStatus)){
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
item.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
}
|
||||
@ -126,11 +126,11 @@ public class DeviceBizService {
|
||||
public TableDataInfo<WebDeviceVo> queryWebDeviceList(DeviceQueryCriteria bo, PageQuery pageQuery) {
|
||||
Page<WebDeviceVo> result = deviceMapper.queryWebDeviceList(pageQuery.build(), bo);
|
||||
List<WebDeviceVo> records = result.getRecords();
|
||||
if(records != null && !records.isEmpty()){
|
||||
if (records != null && !records.isEmpty()) {
|
||||
records.forEach(item -> {
|
||||
if(item.getCommunicationMode()!=null && Ints.asList(0, 2).contains(item.getCommunicationMode())){
|
||||
if (item.getCommunicationMode() != null && Ints.asList(0, 2).contains(item.getCommunicationMode())) {
|
||||
|
||||
//设备在线状态
|
||||
// 设备在线状态
|
||||
// String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
// if("1".equals(onlineStatus)){
|
||||
// item.setOnlineStatus(1);
|
||||
@ -139,24 +139,24 @@ public class DeviceBizService {
|
||||
// }else{
|
||||
// item.setOnlineStatus(0);
|
||||
// }
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
item.setBattery(jsonObject.getString("batteryPercentage"));
|
||||
}else{
|
||||
} else {
|
||||
item.setBattery("0");
|
||||
}
|
||||
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_LOCATION_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(location)){
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_LOCATION_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(location)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(location);
|
||||
item.setLatitude(jsonObject.getString("latitude"));
|
||||
item.setLongitude(jsonObject.getString("longitude"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(alarmStatus)){
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
item.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
}
|
||||
@ -165,6 +165,7 @@ public class DeviceBizService {
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
|
||||
public int bindDevice(AppDeviceBo bo) {
|
||||
Integer mode = bo.getCommunicationMode();
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
@ -179,7 +180,7 @@ public class DeviceBizService {
|
||||
}
|
||||
Device device = devices.get(0);
|
||||
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
|
||||
throw new RuntimeException("设备已绑定");
|
||||
throw new RuntimeException("设备已经被绑定!");
|
||||
}
|
||||
|
||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
@ -189,7 +190,6 @@ public class DeviceBizService {
|
||||
if (appDeviceBindRecord != null) {
|
||||
UpdateWrapper<AppDeviceBindRecord> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("device_id", device.getId())
|
||||
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
||||
.set("binding_user_id", userId)
|
||||
.set("communication_mode", 0)
|
||||
.set("update_time", new Date())
|
||||
@ -275,7 +275,7 @@ public class DeviceBizService {
|
||||
if (count == 0) {
|
||||
throw new RuntimeException("请先绑定设备!!!");
|
||||
}
|
||||
if(count<2){
|
||||
if (count < 2) {
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_user_id", null)
|
||||
@ -283,7 +283,26 @@ public class DeviceBizService {
|
||||
.set("binding_time", null);
|
||||
deviceMapper.update(null, deviceUpdateWrapper);
|
||||
}
|
||||
}else{
|
||||
QueryWrapper<AppDeviceBindRecord> brqWrapper = new QueryWrapper<>();
|
||||
brqWrapper.eq("device_id", device.getId());
|
||||
brqWrapper.eq("binding_user_id", userId);
|
||||
List<AppDeviceBindRecord> appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(brqWrapper);
|
||||
if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) {
|
||||
appDeviceBindRecordList.forEach(appDeviceBindRecord ->
|
||||
appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()));
|
||||
}
|
||||
AppUserVo appUserVo = appUserMapper.selectVoById(userId);
|
||||
if (appUserVo != null) {
|
||||
QueryWrapper<AppDeviceShare> appDeviceShareQueryWrapper = new QueryWrapper<>();
|
||||
appDeviceShareQueryWrapper.eq("device_id", device.getId());
|
||||
appDeviceShareQueryWrapper.eq("phonenumber", appUserVo.getPhonenumber());
|
||||
List<AppDeviceShare> appDeviceShareList = appDeviceShareMapper.selectList(appDeviceShareQueryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(appDeviceShareList)) {
|
||||
appDeviceShareList.forEach(appDeviceShare ->
|
||||
appDeviceShareMapper.deleteById(appDeviceShare.getId()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||
Long count = appDeviceBindRecordMapper.selectCount(bindRecordQueryWrapper);
|
||||
@ -296,25 +315,17 @@ public class DeviceBizService {
|
||||
.set("binding_status", BindingStatusEnum.UNBOUND.getCode())
|
||||
.set("binding_time", null);
|
||||
deviceMapper.update(null, deviceUpdateWrapper);
|
||||
}
|
||||
|
||||
QueryWrapper<AppDeviceBindRecord> brqWrapper = new QueryWrapper<>();
|
||||
brqWrapper.eq("device_id", device.getId());
|
||||
if(userId != null){
|
||||
brqWrapper.eq("binding_user_id", userId);
|
||||
}
|
||||
QueryWrapper<AppDeviceBindRecord> brqWrapper = new QueryWrapper<>();
|
||||
brqWrapper.eq("device_id", device.getId());
|
||||
List<AppDeviceBindRecord> appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(brqWrapper);
|
||||
if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) {
|
||||
appDeviceBindRecordList.forEach(appDeviceBindRecord ->
|
||||
appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()));
|
||||
}
|
||||
|
||||
List<AppDeviceBindRecord> appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(brqWrapper);
|
||||
if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) {
|
||||
appDeviceBindRecordList.forEach(appDeviceBindRecord ->
|
||||
appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()));
|
||||
}
|
||||
|
||||
AppUserVo appUserVo = appUserMapper.selectVoById(userId);
|
||||
if(appUserVo != null){
|
||||
QueryWrapper<AppDeviceShare> appDeviceShareQueryWrapper = new QueryWrapper<>();
|
||||
appDeviceShareQueryWrapper.eq("device_id", device.getId());
|
||||
appDeviceShareQueryWrapper.eq("phonenumber", appUserVo.getPhonenumber());
|
||||
List<AppDeviceShare> appDeviceShareList = appDeviceShareMapper.selectList(appDeviceShareQueryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(appDeviceShareList)) {
|
||||
appDeviceShareList.forEach(appDeviceShare ->
|
||||
@ -331,7 +342,7 @@ public class DeviceBizService {
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("device_imei", params.getDeviceImei());
|
||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||
if(ObjectUtils.length( devices) ==0){
|
||||
if (ObjectUtils.length(devices) == 0) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
|
||||
@ -340,12 +351,12 @@ public class DeviceBizService {
|
||||
public Map<String, Object> getRealTimeStatus(AppRealTimeStatusDto statusDto) {
|
||||
try {
|
||||
// String commandType = statusDto.getTypeName()+"_" + statusDto.getFunctionMode();"FunctionAccessBatchStatusRule"
|
||||
DeviceStatusRule rule = realTimeStatusEngine.getDeviceStatusRule(statusDto.getTypeName());
|
||||
if(rule == null){
|
||||
DeviceStatusRule rule = realTimeStatusEngine.getDeviceStatusRule(statusDto.getTypeName());
|
||||
if (rule == null) {
|
||||
throw new ServiceException("未匹配到处理命令");
|
||||
}
|
||||
return rule.getStatus(statusDto);
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
@ -383,20 +394,20 @@ public class DeviceBizService {
|
||||
long endTime = today.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
|
||||
String deviceImei = device.getDeviceImei();
|
||||
String a = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX + ":history";
|
||||
Collection<String> list = RedisUtils.zRangeByScore(a, startTime, endTime);
|
||||
String a = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX + ":history";
|
||||
Collection<String> list = RedisUtils.zRangeByScoreDesc(a, startTime, endTime);
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Map<String, List<JSONObject>> map = new LinkedHashMap<>();
|
||||
for (String obj : list){
|
||||
for (String obj : list) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(obj);
|
||||
Long timestamp = jsonObject.getLong("timestamp");
|
||||
LocalDate date = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()).toLocalDate();
|
||||
String address = jsonObject.getString("address");
|
||||
if(StringUtils.isBlank( address) || "[]".equals(address)){
|
||||
if (StringUtils.isBlank(address) || "[]".equals(address)) {
|
||||
continue;
|
||||
}
|
||||
if (map.containsKey(date.toString())) {
|
||||
@ -414,7 +425,7 @@ public class DeviceBizService {
|
||||
detailVo.setDate(entry.getKey());
|
||||
detailVo.setDeviceName(device.getDeviceName());
|
||||
detailVo.setStartLocation(entry.getValue().get(0).getString("address"));
|
||||
detailVo.setEndLocation(entry.getValue().get(entry.getValue().size()-1).getString("address"));
|
||||
detailVo.setEndLocation(entry.getValue().get(entry.getValue().size() - 1).getString("address"));
|
||||
String jsonString = JSONArray.toJSONString(entry.getValue());
|
||||
List<Object> strings = JSONArray.parseArray(jsonString);
|
||||
detailVo.setDetailList(strings);
|
||||
|
||||
@ -39,6 +39,7 @@ public class DeviceDebugService {
|
||||
private final IAppBusinessFileService appBusinessFileService;
|
||||
private final IAppOperationVideoService appOperationVideoService;
|
||||
private final DeviceService deviceService;
|
||||
private final FileHashUtil fileHashUtil;
|
||||
|
||||
/**
|
||||
* 文件上传并添加文件信息哈希去重
|
||||
@ -62,26 +63,12 @@ public class DeviceDebugService {
|
||||
Map<String, Long> hash2OssId = new LinkedHashMap<>(files.length);
|
||||
for (MultipartFile file : files) {
|
||||
// 1. 计算文件哈希
|
||||
String hash = FileHashUtil.hash(file);
|
||||
String hash = fileHashUtil.hash(file);
|
||||
|
||||
// 2. 先根据 hash 查库(秒传)
|
||||
SysOssVo exist = sysOssService.selectByHash(hash);
|
||||
Long ossId;
|
||||
if (exist != null) {
|
||||
// 2.1 已存在,直接复用
|
||||
ossId = exist.getOssId();
|
||||
hash2OssId.putIfAbsent(hash, ossId);
|
||||
} else {
|
||||
// 2.2 不存在,真正上传
|
||||
SysOssVo upload = sysOssService.upload(file);
|
||||
if (upload == null) {
|
||||
return false;
|
||||
}
|
||||
ossId = upload.getOssId();
|
||||
hash2OssId.putIfAbsent(hash, ossId);
|
||||
// 2.3 把 hash 写回记录(供下次去重)
|
||||
sysOssService.updateHashById(ossId, hash);
|
||||
}
|
||||
SysOssVo exist = sysOssService.updateHash(file, hash);
|
||||
// 2.1 已存在,直接复用
|
||||
long ossId = exist.getOssId();
|
||||
hash2OssId.putIfAbsent(hash, ossId);
|
||||
}
|
||||
// 4. 组装业务中间表
|
||||
List<AppBusinessFile> bizList = new ArrayList<>(bo.getDeviceIds().length * hash2OssId.size());
|
||||
|
||||
@ -633,7 +633,7 @@ public class DeviceXinghanBizService {
|
||||
if (!"ins_SOSGrade".equals(payloadKey) || value == 0) {
|
||||
return;
|
||||
}
|
||||
AlarmTypeEnum type = value == 1 ? AlarmTypeEnum.SOS : AlarmTypeEnum.SHAKE;
|
||||
AlarmTypeEnum type = AlarmTypeEnum.SOS;
|
||||
String redisKey = buildAlarmRedisKey(deviceImei, type);
|
||||
Long alarmId = RedisUtils.getCacheObject(redisKey);
|
||||
// 已存在未结束报警 -> 什么都不做(同一条报警)
|
||||
|
||||
@ -0,0 +1,665 @@
|
||||
package com.fuyuanshen.web.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
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.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoRecordsMapper;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.*;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.equipment.enums.LightModeEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
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.constants.DeviceRedisKeyConstants;
|
||||
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 lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.buildArr;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.generateFixedBitmapData;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
|
||||
private final AppPersonnelInfoRecordsMapper appPersonnelInfoRecordsMapper;
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
private final MqttGateway mqttGateway;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
|
||||
private final IotMqttService iotMqttService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AppDevice6075DetailVo getInfo(Long id) {
|
||||
Device device = deviceMapper.selectById(id);
|
||||
if (device == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
|
||||
AppDevice6075DetailVo vo = new AppDevice6075DetailVo();
|
||||
vo.setDeviceId(device.getId());
|
||||
vo.setDeviceName(device.getDeviceName());
|
||||
vo.setDevicePic(device.getDevicePic());
|
||||
vo.setDeviceImei(device.getDeviceImei());
|
||||
vo.setDeviceMac(device.getDeviceMac());
|
||||
vo.setDeviceStatus(device.getDeviceStatus());
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
if (deviceType != null) {
|
||||
vo.setCommunicationMode(Integer.valueOf(deviceType.getCommunicationMode()));
|
||||
vo.setTypeName(deviceType.getTypeName());
|
||||
}
|
||||
vo.setBluetoothName(device.getBluetoothName());
|
||||
|
||||
vo.setSendMsg(device.getSendMsg());
|
||||
|
||||
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
||||
.eq("device_id", device.getId());
|
||||
AppPersonnelInfo appPersonnelInfo = appPersonnelInfoMapper.selectOne(qw);
|
||||
if (appPersonnelInfo != null) {
|
||||
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
|
||||
vo.setPersonnelInfo(personnelInfoVo);
|
||||
}
|
||||
// 设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
// 设备在线状态
|
||||
if ("1".equals(onlineStatus)) {
|
||||
vo.setOnlineStatus(1);
|
||||
} else if ("2".equals(onlineStatus)) {
|
||||
vo.setOnlineStatus(2);
|
||||
} else {
|
||||
vo.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
vo.setMainLightMode(jsonObject.getString("mainLightMode"));
|
||||
vo.setLaserLightMode(jsonObject.getString("laserLightMode"));
|
||||
vo.setBatteryPercentage(jsonObject.getString("batteryPercentage"));
|
||||
vo.setChargeState(jsonObject.getString("chargeState"));
|
||||
vo.setBatteryRemainingTime(jsonObject.getString("batteryRemainingTime"));
|
||||
} else {
|
||||
vo.setBatteryPercentage("0");
|
||||
}
|
||||
|
||||
String lightModeStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_MODE_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
vo.setMainLightMode(lightModeStatus);
|
||||
}
|
||||
|
||||
String lightBrightnessStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(lightBrightnessStatus)) {
|
||||
vo.setLightBrightness(lightBrightnessStatus);
|
||||
}
|
||||
|
||||
String laserLightMode = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LASER_MODE_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(laserLightMode)) {
|
||||
vo.setLaserLightMode(laserLightMode);
|
||||
}
|
||||
|
||||
// 获取经度纬度
|
||||
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
|
||||
String locationInfo = RedisUtils.getCacheObject(locationKey);
|
||||
if (StringUtils.isNotBlank(locationInfo)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
|
||||
vo.setLongitude(jsonObject.get("longitude").toString());
|
||||
vo.setLatitude(jsonObject.get("latitude").toString());
|
||||
vo.setAddress((String) jsonObject.get("address"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
vo.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
|
||||
String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(lightBrightness)) {
|
||||
vo.setLightBrightness(lightBrightness);
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int sendMessage(AppDeviceSendMsgBo bo) {
|
||||
List<Long> deviceIds = bo.getDeviceIds();
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
throw new ServiceException("请选择设备");
|
||||
}
|
||||
for (Long deviceId : deviceIds) {
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在" + deviceId);
|
||||
}
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
try {
|
||||
ClassPathResource resource = new ClassPathResource("image/background.png");
|
||||
InputStream inputStream = resource.getInputStream();
|
||||
|
||||
byte[] largeData = ImageWithTextGenerate.generate160x80ImageWithText2(bo.getSendMsg(), inputStream, 25600);
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data", Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data");
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
log.info("发送信息第0块数据大小: {} 字节", specificChunk.length);
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(6);
|
||||
intData.add(1);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
|
||||
intData.add(0);
|
||||
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));
|
||||
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", deviceId)
|
||||
.set("send_msg", bo.getSendMsg());
|
||||
deviceMapper.update(updateWrapper);
|
||||
|
||||
recordDeviceLog(deviceId, device.getDeviceName(), "发送信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
log.info("发送信息设备发送信息失败:{}", deviceId);
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
// 发送消息
|
||||
messageSending(device.getDeviceImei());
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录设备操作日志
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param content 日志内容
|
||||
* @param operator 操作人
|
||||
*/
|
||||
@Override
|
||||
public void recordDeviceLog(Long deviceId, String deviceName, String deviceAction, String content, Long operator) {
|
||||
try {
|
||||
// 创建设备日志实体
|
||||
com.fuyuanshen.equipment.domain.DeviceLog deviceLog = new com.fuyuanshen.equipment.domain.DeviceLog();
|
||||
deviceLog.setDeviceId(deviceId);
|
||||
deviceLog.setDeviceAction(deviceAction);
|
||||
deviceLog.setContent(content);
|
||||
deviceLog.setCreateBy(operator);
|
||||
deviceLog.setDeviceName(deviceName);
|
||||
deviceLog.setCreateTime(new Date());
|
||||
|
||||
// 插入日志记录
|
||||
deviceLogMapper.insert(deviceLog);
|
||||
} catch (Exception e) {
|
||||
log.error("记录设备操作日志失败: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注册人员信息
|
||||
*
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
||||
Long deviceId = bo.getDeviceId();
|
||||
Device deviceObj = deviceMapper.selectById(deviceId);
|
||||
if (deviceObj == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
if (getDeviceStatus(deviceObj.getDeviceImei())) {
|
||||
throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
||||
.eq("device_id", deviceId);
|
||||
List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw);
|
||||
// 生成固定长度的点阵数据
|
||||
byte[] unitName = generateFixedBitmapData(bo.getUnitName(), 120);
|
||||
byte[] position = generateFixedBitmapData(bo.getPosition(), 120);
|
||||
byte[] name = generateFixedBitmapData(bo.getName(), 120);
|
||||
byte[] id = generateFixedBitmapData(bo.getCode(), 120);
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(2);
|
||||
buildArr(convertHexToDecimal(unitName), intData);
|
||||
buildArr(convertHexToDecimal(name), intData);
|
||||
buildArr(convertHexToDecimal(position), intData);
|
||||
buildArr(convertHexToDecimal(id), intData);
|
||||
intData.add(0);
|
||||
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 + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo);
|
||||
String logContent = "单位:" + bo.getUnitName() + ",职位:" + bo.getPosition() + ",姓名:" + bo.getName() + ",ID:" + bo.getCode();
|
||||
recordDeviceLog(deviceId, deviceObj.getDeviceName(), "人员信息登记", logContent, AppLoginHelper.getUserId());
|
||||
if (ObjectUtils.length(appPersonnelInfoVos) == 0) {
|
||||
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo);
|
||||
|
||||
AppPersonnelInfoRecords appPersonnelInfoRecords = new AppPersonnelInfoRecords();
|
||||
BeanUtil.copyProperties(appPersonnelInfo, appPersonnelInfoRecords);
|
||||
appPersonnelInfoRecords.setId(null);
|
||||
appPersonnelInfoRecords.setPersonnelId(appPersonnelInfo.getId());
|
||||
|
||||
appPersonnelInfoRecordsMapper.insert(appPersonnelInfoRecords);
|
||||
} else {
|
||||
UpdateWrapper<AppPersonnelInfo> uw = new UpdateWrapper<>();
|
||||
uw.eq("device_id", deviceId)
|
||||
.set("name", bo.getName())
|
||||
.set("position", bo.getPosition())
|
||||
.set("unit_name", bo.getUnitName())
|
||||
.set("code", bo.getCode());
|
||||
appPersonnelInfoMapper.update(null, uw);
|
||||
|
||||
AppPersonnelInfoVo personnelInfoVo = appPersonnelInfoVos.get(0);
|
||||
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
AppPersonnelInfoRecords appPersonnelInfoRecords = new AppPersonnelInfoRecords();
|
||||
BeanUtil.copyProperties(appPersonnelInfo, appPersonnelInfoRecords);
|
||||
appPersonnelInfoRecords.setId(null);
|
||||
appPersonnelInfoRecords.setPersonnelId(personnelInfoVo.getId());
|
||||
appPersonnelInfoRecordsMapper.insert(appPersonnelInfoRecords);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadDeviceLogo2(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
MultipartFile file = bo.getFile();
|
||||
|
||||
byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600);
|
||||
|
||||
log.info("长度:" + largeData.length);
|
||||
// 在获取 largeData 后,将其与前缀合并
|
||||
byte[] prefix = new byte[]{0x50, 0x49, 0x43, 0x54, 0x55, 0x52, 0x45}; // "PICTURE"
|
||||
byte[] combinedData = new byte[prefix.length + largeData.length];
|
||||
System.arraycopy(prefix, 0, combinedData, 0, prefix.length);
|
||||
System.arraycopy(largeData, 0, combinedData, prefix.length, largeData.length);
|
||||
|
||||
// 将 combinedData 转换为十六进制表示
|
||||
String[] hexArray = new String[combinedData.length];
|
||||
for (int i = 0; i < combinedData.length; i++) {
|
||||
hexArray[i] = String.format("0x%02X", combinedData[i]);
|
||||
}
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("instruct", combinedData);
|
||||
String[] specificChunk = ImageToCArrayConverter.getChunk2(hexArray, 0, bo.getChunkSize());
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, Arrays.toString(specificChunk));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), Arrays.toString(specificChunk));
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
// throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
log.info(device.getDeviceName() + ",设备已断开连接");
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", device.getDeviceName() + ",设备已断开连接", AppLoginHelper.getUserId());
|
||||
return;
|
||||
}
|
||||
MultipartFile file = bo.getFile();
|
||||
|
||||
byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600);
|
||||
log.info("长度:" + largeData.length);
|
||||
|
||||
log.info("原始数据大小: {} 字节", largeData.length);
|
||||
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX, Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX);
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
log.info("第0块数据大小: {} 字节", specificChunk.length);
|
||||
// log.info("第0块数据: {}", Arrays.toString(specificChunk));
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(3);
|
||||
intData.add(1);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
|
||||
intData.add(0);
|
||||
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));
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* (主光模式)
|
||||
* 0(关闭灯光),1(强光),2(超强光), 3(工作光), 4(节能光),5(爆闪),6(SOS)
|
||||
*/
|
||||
@Override
|
||||
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 {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
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("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 灯光亮度设置
|
||||
@Override
|
||||
public void lightBrightnessSettings(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 instructValue = params.getInstructValue();
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(5);
|
||||
String[] values = instructValue.split("\\.");
|
||||
String value1 = values[0];
|
||||
String value2 = values[1];
|
||||
if (StringUtils.isNoneBlank(value1)) {
|
||||
intData.add(Integer.parseInt(value1));
|
||||
}
|
||||
if (StringUtils.isNoneBlank(value2)) {
|
||||
intData.add(Integer.parseInt(value2));
|
||||
}
|
||||
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));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 激光模式设置
|
||||
@Override
|
||||
public void laserModeSettings(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() + ",设备已断开连接");
|
||||
}
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(4);
|
||||
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));
|
||||
// 1代表开启激光灯,此时主灯关闭,主灯控件为关机状态,为0代表关闭激光灯
|
||||
if ("1".equals(params.getInstructValue())) {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "激光模式设置", "开启激光灯", AppLoginHelper.getUserId());
|
||||
} else {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "激光模式设置", "关闭激光灯", AppLoginHelper.getUserId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapReverseGeocoding(DeviceInstructDto params) {
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("device_imei", params.getDeviceImei());
|
||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||
if (ObjectUtils.length(devices) == 0) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int sendAlarmMessage(AppDeviceSendMsgBo bo) {
|
||||
try {
|
||||
List<Long> deviceIds = bo.getDeviceIds();
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
throw new ServiceException("请选择设备");
|
||||
}
|
||||
|
||||
for (Long deviceId : deviceIds) {
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在" + deviceId);
|
||||
}
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
try {
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(7);
|
||||
intData.add(Integer.parseInt(bo.getInstructValue()));
|
||||
intData.add(0);
|
||||
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));
|
||||
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", deviceId)
|
||||
.set("send_msg", bo.getSendMsg());
|
||||
deviceMapper.update(updateWrapper);
|
||||
if ("0".equals(bo.getInstructValue())) {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "解除告警信息", "关闭设备", AppLoginHelper.getUserId());
|
||||
} else {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "发送告警信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("设备发送告警信息信息失败:{}", deviceId);
|
||||
throw new ServiceException("设备发送告警信息信息失败");
|
||||
}
|
||||
messageSending(device.getDeviceImei());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送告警信息指令失败");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageSending(String deviceImei) {
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + ":messageSending";
|
||||
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDeviceStatus(String deviceImei) {
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||
return RedisUtils.getCacheObject(deviceOnlineStatusRedisKey) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchUploadLogo(AppDeviceLogoUploadDto bo) {
|
||||
|
||||
List<Long> deviceIds = bo.getDeviceIds();
|
||||
MultipartFile file = bo.getFile();
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
throw new ServiceException("请选择设备");
|
||||
}
|
||||
for (Long deviceId : deviceIds) {
|
||||
AppDeviceLogoUploadDto dto = new AppDeviceLogoUploadDto();
|
||||
dto.setDeviceId(deviceId);
|
||||
dto.setFile(file);
|
||||
uploadDeviceLogo(dto);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,358 @@
|
||||
package com.fuyuanshen.web.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bytedeco.javacv.FFmpegFrameGrabber;
|
||||
import org.bytedeco.javacv.Frame;
|
||||
import org.bytedeco.javacv.Java2DFrameUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 视频处理工具类
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class VideoProcessUtil {
|
||||
|
||||
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
/**
|
||||
* 创建临时视频文件
|
||||
*/
|
||||
public File createTempVideoFile(MultipartFile file) throws Exception {
|
||||
File tempFile = Files.createTempFile("upload-", ".mp4").toFile();
|
||||
file.transferTo(tempFile);
|
||||
log.debug("创建临时视频文件: {}", tempFile.getAbsolutePath());
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理视频并转换为Hex字符串列表
|
||||
*/
|
||||
public List<String> processVideoToHex(File videoFile, int frameRate, int duration, int width, int height, int code) throws Exception {
|
||||
// 1. 提取视频帧
|
||||
List<BufferedImage> frames = extractFramesFromVideo(videoFile, frameRate, duration, width, height);
|
||||
|
||||
if (code == 1) {
|
||||
// 1. 转换为RGB565格式
|
||||
byte[] binaryData = convertFramesToRGB565(frames);
|
||||
|
||||
// 2. 转换为Hex字符串列表
|
||||
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 {
|
||||
// 初始化帧列表
|
||||
List<BufferedImage> frames = new ArrayList<>();
|
||||
// 计算需要提取的总帧数 = 帧率 × 时长
|
||||
int totalFramesToExtract = frameRate * duration;
|
||||
|
||||
// 使用FFmpegFrameGrabber从视频文件中抓取帧
|
||||
try (FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(videoFile)) {
|
||||
// 启动抓取器
|
||||
grabber.start();
|
||||
|
||||
// 获取视频总帧数
|
||||
long totalFramesInVideo = grabber.getLengthInFrames();
|
||||
// 获取视频帧率,如果获取不到则默认为30fps
|
||||
int fps = (int) Math.round(grabber.getFrameRate());
|
||||
if (fps <= 0) fps = 30;
|
||||
|
||||
// 计算视频总时长(秒)
|
||||
double durationSeconds = (double) totalFramesInVideo / fps;
|
||||
// 检查视频时长是否满足要求
|
||||
if (durationSeconds < duration) {
|
||||
throw new IllegalArgumentException("视频太短,至少需要 " + duration + " 秒");
|
||||
}
|
||||
|
||||
// 计算帧间隔,用于均匀分布提取的帧
|
||||
double frameInterval = (double) totalFramesInVideo / totalFramesToExtract;
|
||||
|
||||
// 循环提取指定数量的帧
|
||||
for (int i = 0; i < totalFramesToExtract; i++) {
|
||||
// 计算目标帧号
|
||||
int targetFrameNumber = (int) Math.round(i * frameInterval);
|
||||
|
||||
// 检查目标帧号是否超出视频范围
|
||||
if (targetFrameNumber >= totalFramesInVideo) {
|
||||
throw new IllegalArgumentException("目标帧超出范围: " + targetFrameNumber);
|
||||
}
|
||||
|
||||
// 设置抓取器到目标帧
|
||||
grabber.setFrameNumber(targetFrameNumber);
|
||||
// 抓取当前帧
|
||||
Frame frame = grabber.grab();
|
||||
|
||||
// 如果成功抓取到帧且帧图像不为空
|
||||
if (frame != null && frame.image != null) {
|
||||
// 将帧转换为BufferedImage并裁剪到指定尺寸
|
||||
BufferedImage bufferedImage = Java2DFrameUtils.toBufferedImage(frame);
|
||||
frames.add(cropImage(bufferedImage, width, height));
|
||||
} else {
|
||||
// 如果无法获取帧则抛出异常
|
||||
throw new IllegalArgumentException("无法获取第 " + targetFrameNumber + "帧");
|
||||
}
|
||||
}
|
||||
|
||||
// 停止抓取器
|
||||
grabber.stop();
|
||||
}
|
||||
|
||||
// 记录提取的帧数
|
||||
log.debug("从视频中提取了 {} 帧", frames.size());
|
||||
// 返回提取的帧列表
|
||||
return frames;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将所有帧转换为 RGB565 格式字节数组
|
||||
*/
|
||||
private byte[] convertFramesToRGB565(List<BufferedImage> frames) throws Exception {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
|
||||
for (BufferedImage image : frames) {
|
||||
byte[] rgb565Bytes = convertToRGB565(image);
|
||||
byteArrayOutputStream.write(rgb565Bytes);
|
||||
}
|
||||
|
||||
byte[] result = byteArrayOutputStream.toByteArray();
|
||||
log.debug("转换RGB565数据完成,总字节数: {}", result.length);
|
||||
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字符串列表
|
||||
*/
|
||||
private List<String> bytesToHexList(byte[] bytes) {
|
||||
List<String> hexList = new ArrayList<>();
|
||||
for (byte b : bytes) {
|
||||
int value = b & 0xFF;
|
||||
char high = HEX_ARRAY[value >>> 4];
|
||||
char low = HEX_ARRAY[value & 0x0F];
|
||||
hexList.add(String.valueOf(high) + low);
|
||||
}
|
||||
return hexList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除临时文件
|
||||
*/
|
||||
public void deleteTempFile(File file) {
|
||||
if (file != null && file.exists()) {
|
||||
if (file.delete()) {
|
||||
log.debug("删除临时文件成功: {}", file.getAbsolutePath());
|
||||
} else {
|
||||
log.warn("无法删除临时文件: {}", file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 裁剪图像到目标尺寸
|
||||
*/
|
||||
private BufferedImage cropImage(BufferedImage img, int targetWidth, int targetHeight) {
|
||||
int w = Math.min(img.getWidth(), targetWidth);
|
||||
int h = Math.min(img.getHeight(), targetHeight);
|
||||
return img.getSubimage(0, 0, w, h);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 BufferedImage 转换为 RGB565 格式的字节数组
|
||||
*/
|
||||
private byte[] convertToRGB565(BufferedImage image) {
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
byte[] result = 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);
|
||||
int r = ((rgb >> 16) & 0xFF) >> 3;
|
||||
int g = ((rgb >> 8) & 0xFF) >> 2;
|
||||
int b = (rgb & 0xFF) >> 3;
|
||||
short pixel = (short) ((r << 11) | (g << 5) | b);
|
||||
|
||||
result[index++] = (byte) (pixel >> 8);
|
||||
result[index++] = (byte) pixel;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存帧到本地(用于调试)
|
||||
*/
|
||||
public void saveFramesToLocal(List<BufferedImage> frames, String prefix) {
|
||||
File outputDir = new File("output_frames");
|
||||
if (!outputDir.exists()) {
|
||||
outputDir.mkdirs();
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (BufferedImage frame : frames) {
|
||||
try {
|
||||
File outputImage = new File(outputDir, prefix + "_" + (index++) + ".png");
|
||||
ImageIO.write(frame, "png", outputImage);
|
||||
log.debug("保存帧图片成功: {}", outputImage.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
log.error("保存帧图片失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把 BGR565 字节流直接写成 MP4(H.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,32 +52,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
|
||||
username: root
|
||||
password: Jq_123456#
|
||||
# # 从库数据源
|
||||
# slave:
|
||||
# lazy: true
|
||||
# type: ${spring.datasource.type}
|
||||
# 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
|
||||
# username:
|
||||
# password:
|
||||
# oracle:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: oracle.jdbc.OracleDriver
|
||||
# url: jdbc:oracle:thin:@//localhost:1521/XE
|
||||
# username: ROOT
|
||||
# password: root
|
||||
# postgres:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: org.postgresql.Driver
|
||||
# url: jdbc:postgresql://localhost:5432/postgres?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
# username: root
|
||||
# password: root
|
||||
# sqlserver:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
# url: jdbc:sqlserver://localhost:1433;DatabaseName=tempdb;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true
|
||||
# username: SA
|
||||
# password: root
|
||||
# # 从库数据源
|
||||
# slave:
|
||||
# lazy: true
|
||||
# type: ${spring.datasource.type}
|
||||
# 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
|
||||
# username:
|
||||
# password:
|
||||
# oracle:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: oracle.jdbc.OracleDriver
|
||||
# url: jdbc:oracle:thin:@//localhost:1521/XE
|
||||
# username: ROOT
|
||||
# password: root
|
||||
# postgres:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: org.postgresql.Driver
|
||||
# url: jdbc:postgresql://localhost:5432/postgres?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
# username: root
|
||||
# password: root
|
||||
# sqlserver:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
# url: jdbc:sqlserver://localhost:1433;DatabaseName=tempdb;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true
|
||||
# username: SA
|
||||
# password: root
|
||||
hikari:
|
||||
# 最大连接池数量
|
||||
maxPoolSize: 20
|
||||
@ -177,12 +177,12 @@ sms:
|
||||
access-key-id: LTAI5tJdDNpZootsPQ5hdELx
|
||||
# 称为accessSecret有些称之为apiSecret
|
||||
access-key-secret: mU4WtffcCXpHPz5tLwQpaGtLsJXONt
|
||||
#模板ID 非必须配置,如果使用sendMessage的快速发送需此配置
|
||||
#模板ID 非必须配置,如果使用sendMessage的快速发送需此配置
|
||||
template-id: SMS_322180518
|
||||
#模板变量 上述模板的变量
|
||||
#模板变量 上述模板的变量
|
||||
templateName: code
|
||||
signature: 湖北星汉研创科技
|
||||
# sdk-app-id: 您的sdkAppId
|
||||
signature: 湖北星汉研创科技
|
||||
# sdk-app-id: 您的sdkAppId
|
||||
config2:
|
||||
# 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||
supplier: tencent
|
||||
@ -210,7 +210,7 @@ justauth:
|
||||
client-id: 449c4*********937************759
|
||||
client-secret: ac7***********1e0************28d
|
||||
redirect-uri: ${justauth.address}/social-callback?source=topiam
|
||||
scopes: [openid, email, phone, profile]
|
||||
scopes: [ openid, email, phone, profile ]
|
||||
qq:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
@ -276,33 +276,20 @@ justauth:
|
||||
redirect-uri: ${justauth.address}/social-callback?source=gitea
|
||||
|
||||
|
||||
# 文件存储路径
|
||||
file:
|
||||
mac:
|
||||
path: ~/file/
|
||||
avatar: ~/avatar/
|
||||
linux:
|
||||
path: /home/eladmin/file/
|
||||
avatar: /home/eladmin/avatar/
|
||||
windows:
|
||||
path: C:\eladmin\file\
|
||||
avatar: C:\eladmin\avatar\
|
||||
# 文件大小 /M
|
||||
maxSize: 100
|
||||
avatarMaxSize: 5
|
||||
device:
|
||||
pic: C:\eladmin\file\ #设备图片存储路径
|
||||
ip: http://fuyuanshen.com:81/ #服务器地址
|
||||
app_avatar:
|
||||
pic: C:\eladmin\file\ #设备图片存储路径
|
||||
#ip: http://fuyuanshen.com:81/ #服务器地址
|
||||
ip: https://fuyuanshen.com/ #服务器地址
|
||||
# MQTT配置
|
||||
mqtt:
|
||||
username: admin
|
||||
password: #YtvpSfCNG
|
||||
url: tcp://www.cnxhyc.com:2883
|
||||
password: fys123456
|
||||
url: tcp://47.107.152.87:1883
|
||||
subClientId: fys_subClient
|
||||
subTopic: A/#
|
||||
pubTopic: B/#
|
||||
pubClientId: fys_pubClient
|
||||
subTopic: A/#,status/tenantCode/#,report/tenantCode/#
|
||||
pubTopic: B/#,command/tenantCode/#
|
||||
pubClientId: fys_pubClient
|
||||
|
||||
|
||||
# TTS语音交互配置
|
||||
alibaba:
|
||||
tts:
|
||||
appKey: KTwSUKMrf2olFfjC
|
||||
akId: LTAI5t6RsfCvQh57qojzbEoe
|
||||
akSecret: MTqvK2mXYeCRkl1jVPndiNumyaad0R
|
||||
@ -8,8 +8,8 @@ spring.boot.admin.client:
|
||||
metadata:
|
||||
username: ${spring.boot.admin.client.username}
|
||||
userpassword: ${spring.boot.admin.client.password}
|
||||
username: @monitor.username@
|
||||
password: @monitor.password@
|
||||
username: ${monitor.username}
|
||||
password: ${monitor.password}
|
||||
|
||||
--- # snail-job 配置
|
||||
snail-job:
|
||||
|
||||
@ -11,8 +11,8 @@ spring.boot.admin.client:
|
||||
metadata:
|
||||
username: ${spring.boot.admin.client.username}
|
||||
userpassword: ${spring.boot.admin.client.password}
|
||||
username: @monitor.username@
|
||||
password: @monitor.password@
|
||||
username: ${monitor.username}
|
||||
password: ${monitor.password}
|
||||
|
||||
--- # snail-job 配置
|
||||
snail-job:
|
||||
@ -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
|
||||
username: root
|
||||
password: Jq_123456#
|
||||
# # 从库数据源
|
||||
# slave:
|
||||
# lazy: true
|
||||
# type: ${spring.datasource.type}
|
||||
# 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
|
||||
# username:
|
||||
# password:
|
||||
# oracle:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: oracle.jdbc.OracleDriver
|
||||
# url: jdbc:oracle:thin:@//localhost:1521/XE
|
||||
# username: ROOT
|
||||
# password: root
|
||||
# postgres:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: org.postgresql.Driver
|
||||
# url: jdbc:postgresql://localhost:5432/postgres?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
# username: root
|
||||
# password: root
|
||||
# sqlserver:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
# url: jdbc:sqlserver://localhost:1433;DatabaseName=tempdb;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true
|
||||
# username: SA
|
||||
# password: root
|
||||
# # 从库数据源
|
||||
# slave:
|
||||
# lazy: true
|
||||
# type: ${spring.datasource.type}
|
||||
# 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
|
||||
# username:
|
||||
# password:
|
||||
# oracle:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: oracle.jdbc.OracleDriver
|
||||
# url: jdbc:oracle:thin:@//localhost:1521/XE
|
||||
# username: ROOT
|
||||
# password: root
|
||||
# postgres:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: org.postgresql.Driver
|
||||
# url: jdbc:postgresql://localhost:5432/postgres?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
# username: root
|
||||
# password: root
|
||||
# sqlserver:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
# url: jdbc:sqlserver://localhost:1433;DatabaseName=tempdb;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true
|
||||
# username: SA
|
||||
# password: root
|
||||
hikari:
|
||||
# 最大连接池数量
|
||||
maxPoolSize: 20
|
||||
@ -281,31 +281,16 @@ justauth:
|
||||
mqtt:
|
||||
username: admin
|
||||
password: #YtvpSfCNG
|
||||
url: tcp://47.120.79.150:2883
|
||||
url: tcp://47.120.79.150:3883
|
||||
subClientId: fys_subClient
|
||||
subTopic: A/#,B/#,worker/location/#
|
||||
pubTopic: B/#
|
||||
subTopic: A/#,status/tenantCode/#,report/tenantCode/#
|
||||
pubTopic: B/#,command/tenantCode/#
|
||||
pubClientId: fys_pubClient
|
||||
|
||||
# TTS语音交互配置
|
||||
alibaba:
|
||||
tts:
|
||||
appKey: KTwSUKMrf2olFfjC
|
||||
akId: LTAI5t6RsfCvQh57qojzbEoe
|
||||
akSecret: MTqvK2mXYeCRkl1jVPndiNumyaad0R
|
||||
|
||||
# 文件存储路径
|
||||
file:
|
||||
mac:
|
||||
path: ~/file/
|
||||
avatar: ~/avatar/
|
||||
linux:
|
||||
path: /home/eladmin/file/
|
||||
avatar: /home/eladmin/avatar/
|
||||
windows:
|
||||
path: C:\eladmin\file\
|
||||
avatar: C:\eladmin\avatar\
|
||||
# 文件大小 /M
|
||||
maxSize: 100
|
||||
avatarMaxSize: 5
|
||||
device:
|
||||
pic: C:\eladmin\file\ #设备图片存储路径
|
||||
ip: http://fuyuanshen.com:81/ #服务器地址
|
||||
app_avatar:
|
||||
pic: C:\eladmin\file\ #设备图片存储路径
|
||||
#ip: http://fuyuanshen.com:81/ #服务器地址
|
||||
ip: https://fuyuanshen.com/ #服务器地址
|
||||
@ -269,4 +269,4 @@ justauth:
|
||||
server-url: https://demo.gitea.com
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=gitea
|
||||
redirect-uri: ${justauth.address}/social-callback?source=gitea
|
||||
@ -69,9 +69,9 @@ spring:
|
||||
servlet:
|
||||
multipart:
|
||||
# 单个文件大小
|
||||
max-file-size: 10MB
|
||||
max-file-size: 100MB
|
||||
# 设置总上传的文件大小
|
||||
max-request-size: 20MB
|
||||
max-request-size: 200MB
|
||||
mvc:
|
||||
# 设置静态资源路径 防止所有请求都去查静态资源
|
||||
static-path-pattern: /static/**
|
||||
@ -132,6 +132,8 @@ tenant:
|
||||
- app_menu
|
||||
- app_user_role
|
||||
- app_role_menu
|
||||
- track_service
|
||||
- device_fence_terminal
|
||||
|
||||
# MyBatisPlus配置
|
||||
# https://baomidou.com/config/
|
||||
|
||||
10
fys-admin/src/main/resources/josn
Normal file
10
fys-admin/src/main/resources/josn
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"requestId": "123456789",
|
||||
"imei": "864865082081523",
|
||||
"timestamp": 1761025080000,
|
||||
"funcType": "1",
|
||||
"data": {
|
||||
"mainLightMode": 1,
|
||||
"mainLightBrightness": 100
|
||||
}
|
||||
}
|
||||
@ -77,4 +77,9 @@ public interface SystemConstants {
|
||||
*/
|
||||
String ROOT_DEPT_ANCESTORS = "0";
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
public static final Long RESTRICTED_MENU_ID = 102L;
|
||||
|
||||
}
|
||||
|
||||
@ -27,14 +27,14 @@ public class Bitmap80x12Generator {
|
||||
BufferedImage image = convertByteArrayToImage(bytes, 12, 80);
|
||||
ImageIO.write(image, "PNG", new File("D:\\bitmap_preview.png"));
|
||||
System.out.println("成功生成预览图片: D:\\bitmap_preview.png");
|
||||
|
||||
|
||||
// 打印十六进制数据
|
||||
// System.out.println("生成的点阵数据2:");
|
||||
// printHexData(bitmapData);
|
||||
// int[] ints = convertHexToDecimal(bitmapData);
|
||||
System.out.println("打印十进制无符号:"+Arrays.toString(ints));
|
||||
System.out.println("打印十进制无符号:" + Arrays.toString(ints));
|
||||
// printDecimalData(bitmapData);
|
||||
|
||||
|
||||
// 生成C文件
|
||||
generateCFile(bitmapData, "bitmap_data.c", "chinese_text");
|
||||
}
|
||||
@ -125,7 +125,7 @@ public class Bitmap80x12Generator {
|
||||
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) {
|
||||
intData.add(datum);
|
||||
}
|
||||
@ -133,8 +133,8 @@ public class Bitmap80x12Generator {
|
||||
|
||||
/**
|
||||
* 生成固定长度的点阵数据
|
||||
*
|
||||
* @param text 要转换的文本
|
||||
*
|
||||
* @param text 要转换的文本
|
||||
* @param fixedLength 固定长度(字节)
|
||||
* @return 固定长度的点阵数据
|
||||
*/
|
||||
@ -157,10 +157,11 @@ public class Bitmap80x12Generator {
|
||||
int copyLength = Math.min(rawData.length, fixedLength);
|
||||
System.arraycopy(rawData, 0, result, 0, copyLength);
|
||||
// 剩余部分自动初始化为0
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建文本图像
|
||||
*/
|
||||
@ -185,14 +186,14 @@ public class Bitmap80x12Generator {
|
||||
|
||||
// 获取字体度量
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
|
||||
|
||||
// 计算文本绘制位置(居中)
|
||||
int textWidth = metrics.stringWidth(text);
|
||||
// int x = Math.max(0, (width - textWidth) / 2); // 水平居中
|
||||
// 左对齐
|
||||
int x = 0;
|
||||
int y = (height - metrics.getHeight()) / 2 + metrics.getAscent(); // 垂直居中
|
||||
|
||||
|
||||
// 绘制文本
|
||||
g.drawString(text, x, y);
|
||||
|
||||
@ -242,6 +243,7 @@ public class Bitmap80x12Generator {
|
||||
return byteListToArray(byteList);
|
||||
}
|
||||
|
||||
|
||||
public static byte[] byteListToArray(List<Byte> byteList) {
|
||||
byte[] result = new byte[byteList.size()];
|
||||
for (int i = 0; i < byteList.size(); i++) {
|
||||
@ -282,7 +284,7 @@ public class Bitmap80x12Generator {
|
||||
}
|
||||
}
|
||||
bitIndex++;
|
||||
|
||||
|
||||
// 如果已经处理完所有像素,则退出
|
||||
if (bitIndex >= width * height) {
|
||||
return image;
|
||||
@ -313,6 +315,7 @@ public class Bitmap80x12Generator {
|
||||
sb.append("\n};");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印十六进制数据
|
||||
*/
|
||||
@ -320,7 +323,7 @@ public class Bitmap80x12Generator {
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
int value = data[i] & 0xFF;
|
||||
System.out.printf("0x%02X", value);
|
||||
|
||||
|
||||
if (i < data.length - 1) {
|
||||
System.out.print(", ");
|
||||
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 {
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
int value = data[i] & 0xFF;
|
||||
@ -359,4 +363,6 @@ public class Bitmap80x12Generator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -39,8 +39,8 @@ public class EncryptUtilsTest {
|
||||
loginBody.setClientId("e5cd7e4891bf95d1d19206ce24a7b32e");
|
||||
loginBody.setGrantType("password");
|
||||
loginBody.setTenantId("894078");
|
||||
loginBody.setCode("0");
|
||||
loginBody.setUuid("1d6615668c7f410da77c4e002c601073");
|
||||
loginBody.setCode("15");
|
||||
loginBody.setUuid("28ecf3d396ce4e6db8eb414992235fad");
|
||||
// loginBody.setUsername("admin");
|
||||
// loginBody.setPassword("admin123");
|
||||
loginBody.setUsername("dyf");
|
||||
|
||||
@ -74,6 +74,7 @@ public class ExcelUtil {
|
||||
return listener.getExcelResult();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
@ -92,6 +93,7 @@ public class ExcelUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出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) {
|
||||
exportExcel(list, sheetName, clazz, false, os, options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
@ -187,13 +190,13 @@ public class ExcelUtil {
|
||||
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, boolean merge,
|
||||
OutputStream os, List<DropDownOptions> options) {
|
||||
ExcelWriterSheetBuilder builder = FastExcel.write(os, clazz)
|
||||
.autoCloseStream(false)
|
||||
// 自动适配
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||
// 大数值自动转换 防止失真
|
||||
.registerConverter(new ExcelBigNumberConvert())
|
||||
.registerWriteHandler(new DataWriteHandler(clazz))
|
||||
.sheet(sheetName);
|
||||
.autoCloseStream(false)
|
||||
// 自动适配
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||
// 大数值自动转换 防止失真
|
||||
.registerConverter(new ExcelBigNumberConvert())
|
||||
.registerWriteHandler(new DataWriteHandler(clazz))
|
||||
.sheet(sheetName);
|
||||
if (merge) {
|
||||
// 合并处理器
|
||||
builder.registerWriteHandler(new CellMergeStrategy(list, true));
|
||||
@ -203,6 +206,7 @@ public class ExcelUtil {
|
||||
builder.doWrite(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 单表多数据模板导出 模板格式为 {.属性}
|
||||
*
|
||||
@ -238,12 +242,12 @@ public class ExcelUtil {
|
||||
public static <T> void exportTemplate(List<T> data, String templatePath, OutputStream os) {
|
||||
ClassPathResource templateResource = new ClassPathResource(templatePath);
|
||||
ExcelWriter excelWriter = FastExcel.write(os)
|
||||
.withTemplate(templateResource.getStream())
|
||||
.autoCloseStream(false)
|
||||
// 大数值自动转换 防止失真
|
||||
.registerConverter(new ExcelBigNumberConvert())
|
||||
.registerWriteHandler(new DataWriteHandler(data.get(0).getClass()))
|
||||
.build();
|
||||
.withTemplate(templateResource.getStream())
|
||||
.autoCloseStream(false)
|
||||
// 大数值自动转换 防止失真
|
||||
.registerConverter(new ExcelBigNumberConvert())
|
||||
.registerWriteHandler(new DataWriteHandler(data.get(0).getClass()))
|
||||
.build();
|
||||
WriteSheet writeSheet = FastExcel.writerSheet().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) {
|
||||
ClassPathResource templateResource = new ClassPathResource(templatePath);
|
||||
ExcelWriter excelWriter = FastExcel.write(os)
|
||||
.withTemplate(templateResource.getStream())
|
||||
.autoCloseStream(false)
|
||||
// 大数值自动转换 防止失真
|
||||
.registerConverter(new ExcelBigNumberConvert())
|
||||
.build();
|
||||
.withTemplate(templateResource.getStream())
|
||||
.autoCloseStream(false)
|
||||
// 大数值自动转换 防止失真
|
||||
.registerConverter(new ExcelBigNumberConvert())
|
||||
.build();
|
||||
WriteSheet writeSheet = FastExcel.writerSheet().build();
|
||||
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) {
|
||||
ClassPathResource templateResource = new ClassPathResource(templatePath);
|
||||
ExcelWriter excelWriter = FastExcel.write(os)
|
||||
.withTemplate(templateResource.getStream())
|
||||
.autoCloseStream(false)
|
||||
// 大数值自动转换 防止失真
|
||||
.registerConverter(new ExcelBigNumberConvert())
|
||||
.build();
|
||||
.withTemplate(templateResource.getStream())
|
||||
.autoCloseStream(false)
|
||||
// 大数值自动转换 防止失真
|
||||
.registerConverter(new ExcelBigNumberConvert())
|
||||
.build();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
WriteSheet writeSheet = FastExcel.writerSheet(i).build();
|
||||
for (Map.Entry<String, Object> map : data.get(i).entrySet()) {
|
||||
|
||||
@ -216,4 +216,5 @@ public class LogAspect {
|
||||
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|
||||
|| o instanceof BindingResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -394,6 +394,26 @@ public class RedisUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 根据时间范围查询Sorted Set中的元素并降序排列
|
||||
*
|
||||
* @param key 键
|
||||
* @param startTime 开始时间戳
|
||||
* @param endTime 结束时间戳
|
||||
* @return 指定时间范围内的元素集合(降序)
|
||||
*/
|
||||
public static Collection<String> zRangeByScoreDesc(String key, Long startTime, Long endTime) {
|
||||
try {
|
||||
RScoredSortedSet<String> sortedSet = CLIENT.getScoredSortedSet(key);
|
||||
// 使用 valueRangeReversed 方法获取降序排列的结果
|
||||
return sortedSet.valueRangeReversed(startTime, true, endTime, true);
|
||||
} catch (Exception e) {
|
||||
// 记录错误日志(如果项目中有日志工具的话)
|
||||
// log.error("根据时间范围查询Sorted Set中的元素失败: key={}, startTime={}, endTime={}, error={}",
|
||||
// key, startTime, endTime, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
}
|
||||
@ -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;
|
||||
|
||||
}
|
||||
@ -64,4 +64,5 @@ public class AppPersonnelInfoBo extends BaseEntity {
|
||||
* ID号
|
||||
*/
|
||||
private String code;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,120 @@
|
||||
package com.fuyuanshen.app.domain.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@Data
|
||||
public class AppDevice6075DetailVo {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@ExcelProperty(value = "设备ID")
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 设备MAC
|
||||
*/
|
||||
private String deviceMac;
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G;1:蓝牙,2 4G&蓝牙
|
||||
*/
|
||||
private Integer communicationMode;
|
||||
|
||||
/**
|
||||
* 设备图片
|
||||
*/
|
||||
private String devicePic;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 蓝牙名称
|
||||
*/
|
||||
private String bluetoothName;
|
||||
|
||||
/**
|
||||
* 设备状态
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
private Integer deviceStatus;
|
||||
|
||||
/**
|
||||
* 人员信息
|
||||
*/
|
||||
private AppPersonnelInfoVo personnelInfo;
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
*/
|
||||
private String sendMsg;
|
||||
|
||||
//"{\"deviceImei\":\"AA\",\"mainLightMode\":\"1\",\"laserLightMode\":\"0\",\"batteryPercentage\":\"60\",\"chargeState\":\"1\",\"batteryRemainingTime\":\"200\",\"timestamp\":1753871635241}"
|
||||
// 设备主灯档位
|
||||
private String mainLightMode;
|
||||
|
||||
// 激光灯档位
|
||||
private String laserLightMode;
|
||||
|
||||
// 电量百分比
|
||||
private String batteryPercentage;
|
||||
|
||||
// 充电状态(0没有充电,1正在充电,2为已充满)
|
||||
private String chargeState;
|
||||
|
||||
// 电池剩余续航时间200分钟
|
||||
private String batteryRemainingTime;
|
||||
|
||||
/**
|
||||
* 在线状态(0离线,1在线)
|
||||
*/
|
||||
private Integer onlineStatus;
|
||||
|
||||
// 经度
|
||||
private String longitude;
|
||||
|
||||
// 纬度
|
||||
private String latitude;
|
||||
|
||||
// 逆解析地址
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 告警状态(0解除告警,1告警)
|
||||
*/
|
||||
private String alarmStatus;
|
||||
|
||||
// 灯光亮度
|
||||
private String lightBrightness;
|
||||
|
||||
/**
|
||||
* 海拔高度
|
||||
*/
|
||||
private Double altitude;
|
||||
|
||||
/**
|
||||
* 相对高度
|
||||
*/
|
||||
private Double relativeAltitude;
|
||||
|
||||
}
|
||||
@ -45,8 +45,7 @@ public class AppDeviceShareDetailVo implements Serializable {
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
* 功能权限(1:灯光模式;2:激光模式;3:开机画面;4:人员信息登记;5:发送信息;6:产品信息)
|
||||
以逗号分隔
|
||||
* 功能权限(1:灯光模式;2:激光模式;3:开机画面;4:人员信息登记;5:发送信息;6:产品信息)以逗号分隔
|
||||
*/
|
||||
@ExcelProperty(value = "功能权限", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "1=:灯光模式;2:激光模式;3:开机画面;4:人员信息登记;5:发送信息;6:产品信息")
|
||||
@ -83,7 +82,7 @@ public class AppDeviceShareDetailVo implements Serializable {
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 蓝牙名称
|
||||
* 蓝牙名称
|
||||
*/
|
||||
private String bluetoothName;
|
||||
|
||||
@ -105,19 +104,19 @@ public class AppDeviceShareDetailVo implements Serializable {
|
||||
*/
|
||||
private String sendMsg;
|
||||
|
||||
//设备主灯档位
|
||||
// 设备主灯档位
|
||||
private String mainLightMode;
|
||||
|
||||
//激光灯档位
|
||||
// 激光灯档位
|
||||
private String laserLightMode;
|
||||
|
||||
//电量百分比
|
||||
// 电量百分比
|
||||
private String batteryPercentage;
|
||||
|
||||
//充电状态(0没有充电,1正在充电,2为已充满)
|
||||
// 充电状态(0没有充电,1正在充电,2为已充满)
|
||||
private String chargeState;
|
||||
|
||||
//电池剩余续航时间200分钟
|
||||
// 电池剩余续航时间200分钟
|
||||
private String batteryRemainingTime;
|
||||
|
||||
/**
|
||||
|
||||
@ -64,5 +64,4 @@ public class AppPersonnelInfoVo implements Serializable {
|
||||
@ExcelProperty(value = "ID号")
|
||||
private String code;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ package com.fuyuanshen.app.mapper;
|
||||
import com.fuyuanshen.app.domain.AppDeviceBindRecord;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo;
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 设备绑定关系Mapper接口
|
||||
@ -12,4 +13,5 @@ import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
*/
|
||||
public interface AppDeviceBindRecordMapper extends BaseMapperPlus<AppDeviceBindRecord, AppDeviceBindRecordVo> {
|
||||
|
||||
Long checkDeviceExistBindRecord(@Param("deviceId") Long deviceId);
|
||||
}
|
||||
|
||||
@ -9,6 +9,9 @@ import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 设备分享Mapper接口
|
||||
*
|
||||
@ -27,4 +30,6 @@ public interface AppDeviceShareMapper extends BaseMapperPlus<AppDeviceShare, App
|
||||
* @return 设备分享
|
||||
*/
|
||||
Page<AppDeviceShareVo> selectWebDeviceShareList(@Param("bo") AppDeviceShareBo bo, Page<AppDeviceShareVo> page);
|
||||
|
||||
void deleteByDeviceIds(@Param("deviceIds") Set<Long> deviceIds);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
}
|
||||
@ -4,6 +4,7 @@ import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceBindRecordBo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -65,4 +66,6 @@ public interface IAppDeviceBindRecordService {
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
Long checkDeviceExistBindRecord(Long deviceId);
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 设备分享Service接口
|
||||
@ -67,4 +68,6 @@ public interface IAppDeviceShareService {
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery);
|
||||
|
||||
void deleteByDeviceIds(Set<Long> deviceIds);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -130,4 +130,9 @@ public class AppDeviceBindRecordServiceImpl implements IAppDeviceBindRecordServi
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long checkDeviceExistBindRecord(Long deviceId) {
|
||||
return baseMapper.checkDeviceExistBindRecord(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ import com.fuyuanshen.app.service.IAppDeviceShareService;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 设备分享Service业务层处理
|
||||
@ -166,4 +167,9 @@ public class AppDeviceShareServiceImpl implements IAppDeviceShareService {
|
||||
});
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByDeviceIds(Set<Long> deviceIds) {
|
||||
baseMapper.deleteByDeviceIds(deviceIds);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user