forked from dyf/fys-Multi-tenant
Compare commits
32 Commits
0457877c09
...
jingquan
| Author | SHA1 | Date | |
|---|---|---|---|
| 03f453f901 | |||
| e23c5267ee | |||
| 346792d5c1 | |||
| cb87871982 | |||
| b280038502 | |||
| 3e119b1dd8 | |||
| cab0884d7f | |||
| ca11ef0e35 | |||
| ef2dc6a6f6 | |||
| dff37b245a | |||
| d7c4d22de3 | |||
| 6a058318f2 | |||
| f2d74b8f17 | |||
| af42a2199c | |||
| aaf142ca67 | |||
| c0dfe36b59 | |||
| c480bda112 | |||
| 8c636d0484 | |||
| 0c474ae1f3 | |||
| b85664900e | |||
| 035b24fedd | |||
| e920cfb860 | |||
| b33ee00dbd | |||
| c8f9cc4f31 | |||
| 26d2f05c4e | |||
| d57d17dc50 | |||
| 20ddbf6e05 | |||
| 63a9d2f8f9 | |||
| 7753444f25 | |||
| bf182ebc89 | |||
| d5a29feca3 | |||
| 1e9e815314 |
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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
package com.fuyuanshen.app.controller;
|
||||
|
||||
import com.fuyuanshen.app.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppFileDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppFileVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppFileVo;
|
||||
import com.fuyuanshen.app.service.AppFileService;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
@ -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;
|
||||
|
||||
/**
|
||||
@ -39,7 +40,7 @@ public class AppFileController extends BaseController {
|
||||
* 上传文件
|
||||
*/
|
||||
@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));
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package com.fuyuanshen.app.controller;
|
||||
|
||||
import com.fuyuanshen.app.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppOperationVideoVo;
|
||||
import com.fuyuanshen.app.service.IAppOperationVideoService;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppOperationVideoVo;
|
||||
import com.fuyuanshen.equipment.service.IAppOperationVideoService;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.domain.model.AppLoginUser;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
|
||||
@ -64,4 +64,5 @@ public class AppVideoController extends BaseController {
|
||||
public R<String> extract(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
return R.ok("Success",audioProcessService.extract(file));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* HBY670设备控制类
|
||||
@ -133,7 +134,7 @@ public class AppDeviceXinghanController extends BaseController {
|
||||
}
|
||||
|
||||
// @Log("新增设备")
|
||||
@Operation(summary = "新增设备")
|
||||
@Log(title = "新增设备")
|
||||
@PostMapping(value = "/add")
|
||||
public R<Void> addDevice(@RequestBody DeviceForm deviceForm) {
|
||||
try {
|
||||
@ -144,4 +145,26 @@ public class AppDeviceXinghanController extends BaseController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/GetDeviceByName")
|
||||
@Operation(summary = "通过蓝牙名/设备名称查询设备")
|
||||
public R<Object> GetDeviceByName(@RequestBody DeviceForm deviceForm) {
|
||||
Object device = appDeviceService.GetDeviceByName(deviceForm);
|
||||
return R.ok(device);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/getEquipCountByType")
|
||||
@Operation(summary = "查询某个类型下的设备总数量")
|
||||
public R<Object> getEquipCountByType(@RequestBody DeviceForm deviceForm) {
|
||||
Object device = appDeviceService.getEquipCountByType(deviceForm);
|
||||
return R.ok(device);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/getEquipAllByType")
|
||||
@Operation(summary = "查询某个类型下的设备")
|
||||
public R<List<Map<String,Object>>> getEquipAllByType(@RequestBody DeviceForm deviceForm){
|
||||
List<Map<String,Object>> list=appDeviceService.getEquipAllByType(deviceForm);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
|
||||
import com.fuyuanshen.app.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppFileDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppBusinessFileVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppFileVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppBusinessFileVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppFileVo;
|
||||
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.service.IAppBusinessFileService;
|
||||
import com.fuyuanshen.equipment.utils.FileHashUtil;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import com.fuyuanshen.system.service.ISysOssService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -15,6 +17,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,12 +34,20 @@ 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) {
|
||||
@ -48,7 +59,13 @@ public class AppFileService {
|
||||
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 +83,7 @@ public class AppFileService {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public Boolean delete(Long[] ids) {
|
||||
AppBusinessFileBo bo = new AppBusinessFileBo();
|
||||
// bo.setCreateBy(AppLoginHelper.getUserId());
|
||||
@ -79,4 +97,5 @@ public class AppFileService {
|
||||
}
|
||||
return appBusinessFileService.deleteWithValidByIds(List.of(ids), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ 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;
|
||||
@ -27,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;
|
||||
@ -59,6 +62,7 @@ public class AppLoginService {
|
||||
private final IAppUserService appUserService;
|
||||
private final IAppDeviceShareService appDeviceShareService;
|
||||
private final IAppDeviceBindRecordService appDeviceBindRecordService;
|
||||
private final DeviceService deviceService;
|
||||
|
||||
|
||||
/**
|
||||
@ -209,8 +213,7 @@ public class AppLoginService {
|
||||
if(ObjectUtil.length(appDeviceBindRecordVos)>0){
|
||||
|
||||
|
||||
// 根据设备id批量删除
|
||||
List<Long> deviceIds = appDeviceBindRecordVos.stream().map(AppDeviceBindRecordVo::getDeviceId).toList();
|
||||
Set<Long> deviceIds = appDeviceBindRecordVos.stream().map(AppDeviceBindRecordVo::getDeviceId).collect(Collectors.toSet());
|
||||
appDeviceShareService.deleteByDeviceIds(deviceIds);
|
||||
|
||||
|
||||
@ -219,6 +222,21 @@ public class AppLoginService {
|
||||
.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()) {
|
||||
|
||||
@ -10,17 +10,38 @@ import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
|
||||
|
||||
@Configuration
|
||||
public class MqttConfiguration {
|
||||
|
||||
@Autowired
|
||||
private MqttPropertiesConfig mqttPropertiesConfig;
|
||||
/** 创建连接工厂 **/
|
||||
|
||||
|
||||
/**
|
||||
* 创建连接工厂
|
||||
**/
|
||||
@Bean
|
||||
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()});
|
||||
|
||||
// 修复用户名为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); // 设置心跳间隔
|
||||
|
||||
@ -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";
|
||||
|
||||
|
||||
/**
|
||||
* 报警模式
|
||||
*/
|
||||
|
||||
@ -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,6 +150,7 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
* 入口:保存报警(SOS 与 Shake 完全独立)
|
||||
*/
|
||||
public void saveAlarm(String deviceImei, MqttXinghanJson status) {
|
||||
try {
|
||||
int sos = Optional.ofNullable(status.getStaSOSGrade()).orElse(0);
|
||||
// 1. 处理 SOS 报警
|
||||
handleSingleAlarm(deviceImei,
|
||||
@ -137,6 +161,9 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
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;
|
||||
}
|
||||
String[] latArr = latitude.split("\\.");
|
||||
String[] lonArr = longitude.split("\\.");
|
||||
// 将位置信息存储到Redis中
|
||||
//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;
|
||||
}
|
||||
|
||||
// 2. 读取 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 cachedJson = RedisUtils.getCacheObject(redisKey);
|
||||
|
||||
String cacheLatitude = jsonOBj.getString("wgs84_latitude");
|
||||
String cacheLongitude = jsonOBj.getString("wgs84_longitude");
|
||||
String[] latArr1 = cacheLatitude.split("\\.");
|
||||
String[] lonArr1 = cacheLongitude.split("\\.");
|
||||
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");
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ public class XinghanSendAlarmMessageRule implements MqttMessageRule {
|
||||
dto.setMessage(String.format("%s设备已收到通知!", latestLog.getDeviceName()));
|
||||
dto.setUserIds(List.of(latestLog.getCreateBy()));
|
||||
SseMessageUtils.publishMessage(dto);
|
||||
}, 5, TimeUnit.SECONDS);
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
return;
|
||||
}
|
||||
// 1. cover! —— 成功标记
|
||||
|
||||
@ -32,6 +32,7 @@ public class MqttMessageConsumer {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,6 +22,8 @@ public class OnlineStatusTask {
|
||||
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
|
||||
|
||||
// 使用cron表达式,每分钟的第0秒执行
|
||||
@Scheduled(cron = "0 */3 * * * ?")
|
||||
public void cronTask() {
|
||||
@ -37,4 +39,5 @@ public class OnlineStatusTask {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -98,6 +98,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return R.ok(appDeviceService.getDeviceInfo(deviceMac));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 指令下发记录
|
||||
*/
|
||||
@ -106,6 +107,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return appDeviceService.getInstructionRecord(dto, pageQuery);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*/
|
||||
|
||||
@ -1,19 +1,15 @@
|
||||
package com.fuyuanshen.web.controller.device;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.fuyuanshen.app.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppFileDto;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.log.annotation.Log;
|
||||
import com.fuyuanshen.common.log.enums.BusinessType;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.WebDeviceVo;
|
||||
import com.fuyuanshen.web.domain.Dto.DeviceDebugEditDto;
|
||||
import com.fuyuanshen.web.domain.Dto.DeviceDebugLogoUploadDto;
|
||||
@ -28,8 +24,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 联调中心
|
||||
@ -125,7 +119,7 @@ public class DeviceDebugController extends BaseController {
|
||||
}
|
||||
deviceDebugService.delFile(bo.getFileIds());
|
||||
// 修改操作视频
|
||||
if (bo.getVideoUrl().isEmpty()) {
|
||||
if (!bo.getVideoUrl().isEmpty()) {
|
||||
AppOperationVideoBo appOperationVideoBo = new AppOperationVideoBo();
|
||||
appOperationVideoBo.setDeviceIds(new Long[]{ bo.getDeviceId() });
|
||||
appOperationVideoBo.setVideoUrl(bo.getVideoUrl());
|
||||
|
||||
@ -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;
|
||||
@ -102,6 +103,7 @@ public class DeviceGeoFenceController extends BaseController {
|
||||
return toAjax(deviceGeoFenceService.updateByBo(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除电子围栏
|
||||
*
|
||||
@ -129,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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
package com.fuyuanshen.web.domain.vo;
|
||||
|
||||
import com.fuyuanshen.app.domain.vo.AppBusinessFileVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppFileVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppOperationVideoVo;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppFileVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppOperationVideoVo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
package com.fuyuanshen.web.service.device;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.fuyuanshen.app.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.app.domain.AppOperationVideo;
|
||||
import com.fuyuanshen.app.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.app.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.equipment.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.equipment.domain.AppOperationVideo;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppFileDto;
|
||||
import com.fuyuanshen.app.service.IAppBusinessFileService;
|
||||
import com.fuyuanshen.app.service.IAppOperationVideoService;
|
||||
import com.fuyuanshen.equipment.service.IAppBusinessFileService;
|
||||
import com.fuyuanshen.equipment.service.IAppOperationVideoService;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package com.fuyuanshen.web.service.device;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
@ -15,20 +15,17 @@ 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.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoRecordsMapper;
|
||||
import com.fuyuanshen.equipment.service.IAppBusinessFileService;
|
||||
import com.fuyuanshen.equipment.service.IAppOperationVideoService;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.domain.model.AppLoginUser;
|
||||
import com.fuyuanshen.common.core.domain.model.LoginUser;
|
||||
import com.fuyuanshen.common.core.exception.BadRequestException;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.fuyuanshen.common.core.utils.ObjectUtils;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
@ -40,7 +37,6 @@ import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import com.fuyuanshen.equipment.enums.DeviceActiveStatusEnum;
|
||||
import com.fuyuanshen.equipment.enums.LightModeEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
|
||||
@ -51,26 +47,23 @@ import com.fuyuanshen.global.mqtt.base.MqttXinghanJson;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import com.fuyuanshen.system.domain.vo.SysRoleVo;
|
||||
import com.fuyuanshen.web.domain.Dto.DeviceDebugLogoUploadDto;
|
||||
import com.fuyuanshen.web.domain.Dto.DeviceXinghanInstructDto;
|
||||
import com.fuyuanshen.web.domain.vo.DeviceXinghanDetailVo;
|
||||
import com.fuyuanshen.web.enums.AlarmTypeEnum;
|
||||
import com.fuyuanshen.web.util.AliyunVoiceUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
@ -91,8 +84,11 @@ public class DeviceXinghanBizService {
|
||||
private final IDeviceAlarmService deviceAlarmService;
|
||||
private final DeviceTypeGrantsMapper deviceTypeGrantsMapper;
|
||||
private final DeviceAssignmentsService deviceAssignmentsService;
|
||||
private final IAppBusinessFileService appBusinessFileService;
|
||||
private final IAppOperationVideoService appOperationVideoService;
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
private final AliyunVoiceUtil voiceUtil;
|
||||
|
||||
/**
|
||||
* 所有档位的描述表
|
||||
@ -135,7 +131,6 @@ public class DeviceXinghanBizService {
|
||||
public void upSOSGradeSettings(DeviceXinghanInstructDto dto) {
|
||||
if(dto.getIsBluetooth()){
|
||||
long deviceId = dto.getDeviceId();
|
||||
|
||||
// 1. 使用Optional简化空值检查,使代码更简洁
|
||||
Device device = Optional.ofNullable(deviceMapper.selectById(deviceId))
|
||||
.orElseThrow(() -> new ServiceException("设备不存在"));
|
||||
@ -147,6 +142,24 @@ public class DeviceXinghanBizService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发异步报警
|
||||
* Spring 会自动调用 AsyncConfig.getAsyncExecutor() 来执行此方法
|
||||
*/
|
||||
@Async
|
||||
public void executeSosCall(String phone) {
|
||||
log.info("[SOS业务] 准备发起语音拨号 -> 目标: {}", phone);
|
||||
Map<String, String> params = Map.of("device", "670");
|
||||
String callId = voiceUtil.sendTtsSync(phone, "TTS_328730104", params);
|
||||
|
||||
if (callId != null) {
|
||||
log.info("[SOS业务] 拨号指令下发成功, callId: {}", callId);
|
||||
// 这里可以记录拨打日志到数据库
|
||||
} else {
|
||||
log.error("[SOS业务] 拨号指令下发失败,请检查配置或余额");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置强制报警
|
||||
*/
|
||||
@ -701,20 +714,31 @@ public class DeviceXinghanBizService {
|
||||
return deviceTypeMapper.findAll(criteria);
|
||||
}
|
||||
|
||||
// @Log("新增设备")
|
||||
public void addDevice(DeviceForm deviceForm) {
|
||||
if (deviceForm.getDeviceMac() != null && deviceForm.getBluetoothName() == null) {
|
||||
/**
|
||||
* 校验唯一性约束
|
||||
*/
|
||||
private void validateDeviceUnique(DeviceForm form) {
|
||||
if (form.getDeviceMac() != null && form.getBluetoothName() == null) {
|
||||
throw new BadRequestException("请填写蓝牙名称!!!");
|
||||
}
|
||||
|
||||
Device device1 = deviceMapper.selectOne(new QueryWrapper<Device>().eq("device_mac", deviceForm.getDeviceMac()));
|
||||
if (device1 != null) {
|
||||
// 使用 QueryWrapper 替代 lambdaQuery()
|
||||
Long macCount = deviceMapper.selectCount(new LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getDeviceMac, form.getDeviceMac()));
|
||||
if (macCount > 0) {
|
||||
throw new BadRequestException("设备MAC已存在!!!");
|
||||
}
|
||||
Device device2 = deviceMapper.selectOne(new QueryWrapper<Device>().eq("device_imei", deviceForm.getDeviceImei()));
|
||||
if (device2 != null) {
|
||||
|
||||
Long imeiCount = deviceMapper.selectCount(new LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getDeviceImei, form.getDeviceImei()));
|
||||
if (imeiCount > 0) {
|
||||
throw new BadRequestException("设备IMEI已存在!!!");
|
||||
}
|
||||
}
|
||||
|
||||
// @Log("新增设备")
|
||||
public void addDevice(DeviceForm deviceForm) {
|
||||
validateDeviceUnique(deviceForm);
|
||||
|
||||
DeviceTypeQueryCriteria queryCriteria = new DeviceTypeQueryCriteria();
|
||||
queryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
|
||||
@ -739,6 +763,7 @@ public class DeviceXinghanBizService {
|
||||
device.setCreateByName(loginUser.getNickname());
|
||||
device.setTypeName(deviceTypes.getTypeName());
|
||||
device.setDeviceType(deviceTypes.getId());
|
||||
device.setDevicePic(deviceTypes.getDevicePic());
|
||||
if (device.getDeviceImei() != null) {
|
||||
device.setPubTopic("A/" + device.getDeviceImei());
|
||||
device.setSubTopic("B/" + device.getDeviceImei());
|
||||
@ -747,6 +772,14 @@ public class DeviceXinghanBizService {
|
||||
device.setBindingStatus(0);
|
||||
deviceMapper.insert(device);
|
||||
|
||||
Long deviceId = device.getDeviceId();
|
||||
|
||||
// 查询设备类型的文件列表
|
||||
// 4. 核心优化:同步设备类型的文件列表 (一行代码)
|
||||
appBusinessFileService.cloneFiles(deviceTypes.getId(), device.getId());
|
||||
//同步设备类型的视频列表
|
||||
appOperationVideoService.cloneFiles(deviceTypes.getId(), device.getId());
|
||||
|
||||
// 新增设备类型记录
|
||||
DeviceAssignments assignments = new DeviceAssignments();
|
||||
assignments.setDeviceId(device.getId());
|
||||
@ -767,4 +800,23 @@ public class DeviceXinghanBizService {
|
||||
return uuidStr.replaceAll("-", "");
|
||||
}
|
||||
|
||||
public Map<String, Object> GetDeviceByName(DeviceForm deviceForm){
|
||||
List<Map<String, Object>> list= deviceMapper.GetDeviceByName(deviceForm);
|
||||
Map<String, Object> device=null;
|
||||
if(list!=null && list.size()>0){
|
||||
device=list.get(0);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
public int getEquipCountByType(DeviceForm form){
|
||||
var res=deviceMapper.getEquipCountByType(form);
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<Map<String,Object>> getEquipAllByType(DeviceForm deviceForm){
|
||||
List<Map<String, Object>> list= deviceMapper.getEquipAllByType(deviceForm);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,87 @@
|
||||
package com.fuyuanshen.web.util;
|
||||
|
||||
import com.aliyun.dyvmsapi20170525.Client;
|
||||
import com.aliyun.dyvmsapi20170525.models.SingleCallByTtsRequest;
|
||||
import com.aliyun.dyvmsapi20170525.models.SingleCallByTtsResponse;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AliyunVoiceUtil {
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Value("${alibaba.tts.akId}")
|
||||
private String akId;
|
||||
@Value("${alibaba.tts.akSecret}")
|
||||
private String akSecret;
|
||||
// @Value("${alibaba.tts.calledShowNumber:}")
|
||||
private String calledShowNumber;
|
||||
|
||||
// ========== 核心:单例客户端(类似 OkHttpClient) ==========
|
||||
private volatile Client client;
|
||||
|
||||
/**
|
||||
* 获取客户端(双重检查锁实现单例)
|
||||
* 只有在第一次调用时才会根据配置实例化,后续直接返回复用
|
||||
*/
|
||||
private Client getClient() throws Exception {
|
||||
if (client == null) {
|
||||
synchronized (this) {
|
||||
if (client == null) {
|
||||
log.info("[AliyunVoice] 正在初始化阿里云语音客户端...");
|
||||
Config config = new Config()
|
||||
.setAccessKeyId(akId)
|
||||
.setAccessKeySecret(akSecret)
|
||||
.setEndpoint("dyvmsapi.aliyuncs.com");
|
||||
this.client = new Client(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步发送方法:由异步架构调用
|
||||
*/
|
||||
public String sendTtsSync(String phone, String templateCode, Map<String, String> params) {
|
||||
|
||||
try {
|
||||
// 1. 获取(或初始化)单例客户端
|
||||
Client voiceClient = getClient();
|
||||
|
||||
SingleCallByTtsRequest request = new SingleCallByTtsRequest()
|
||||
.setCalledNumber(phone)
|
||||
.setTtsCode(templateCode)
|
||||
.setTtsParam(objectMapper.writeValueAsString(params));
|
||||
|
||||
if (StringUtils.hasText(calledShowNumber)) {
|
||||
request.setCalledShowNumber(calledShowNumber);
|
||||
}
|
||||
|
||||
// 生产级超时配置
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
runtime.setConnectTimeout(5000);
|
||||
runtime.setReadTimeout(10000);
|
||||
|
||||
SingleCallByTtsResponse response = voiceClient.singleCallByTtsWithOptions(request, runtime);
|
||||
|
||||
if ("OK".equalsIgnoreCase(response.getBody().getCode())) {
|
||||
return response.getBody().getCallId();
|
||||
} else {
|
||||
log.error("[AliyunVoice] 拨号失败: {}", response.getBody().getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[AliyunVoice] 接口异常", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -61,52 +61,82 @@ public class VideoProcessUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从视频中提取帧
|
||||
*
|
||||
* @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 格式字节数组
|
||||
*/
|
||||
|
||||
@ -132,6 +132,8 @@ tenant:
|
||||
- app_menu
|
||||
- app_user_role
|
||||
- app_role_menu
|
||||
- track_service
|
||||
- device_fence_terminal
|
||||
|
||||
# MyBatisPlus配置
|
||||
# https://baomidou.com/config/
|
||||
|
||||
@ -77,4 +77,9 @@ public interface SystemConstants {
|
||||
*/
|
||||
String ROOT_DEPT_ANCESTORS = "0";
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
public static final Long RESTRICTED_MENU_ID = 102L;
|
||||
|
||||
}
|
||||
|
||||
@ -72,13 +72,13 @@ public class ImageCompressUtil {
|
||||
}
|
||||
|
||||
// 先尝试质量压缩
|
||||
byte[] compressedData = compressImageQuality(originalImage, formatName, 0.8f);
|
||||
byte[] compressedData = compressImageQuality(originalImage, formatName, 0.7f);
|
||||
|
||||
// 如果质量压缩后仍大于目标大小,则进行尺寸压缩
|
||||
if (compressedData.length > maxSize) {
|
||||
// 计算缩放比例
|
||||
double scale = Math.sqrt((double) maxSize / compressedData.length);
|
||||
scale = Math.max(scale, 0.5); // 最小缩放到原来的一半
|
||||
scale = Math.max(scale, 0.2); // 最小缩放到原来的20%
|
||||
|
||||
// 尺寸压缩
|
||||
compressedData = compressImageByScale(originalImage, scale, formatName);
|
||||
@ -86,20 +86,36 @@ public class ImageCompressUtil {
|
||||
|
||||
// 如果压缩后还是太大,继续压缩
|
||||
int attempts = 0;
|
||||
while (compressedData.length > maxSize && attempts < 5) {
|
||||
while (compressedData.length > maxSize && attempts < 15) { // 增加尝试次数到15次
|
||||
// 优先降低质量
|
||||
float quality = Math.max(0.1f, 0.8f - attempts * 0.1f);
|
||||
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.9 - attempts * 0.1; // 逐步缩小尺寸
|
||||
scale = Math.max(scale, 0.5);
|
||||
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));
|
||||
@ -110,6 +126,12 @@ public class ImageCompressUtil {
|
||||
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);
|
||||
@ -117,6 +139,63 @@ public class ImageCompressUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制压缩到指定大小
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按比例缩放图片
|
||||
*
|
||||
@ -130,6 +209,10 @@ public class ImageCompressUtil {
|
||||
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);
|
||||
|
||||
@ -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
|
||||
*
|
||||
@ -175,6 +177,7 @@ public class ExcelUtil {
|
||||
exportExcel(list, sheetName, clazz, false, os, options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
@ -203,6 +206,7 @@ public class ExcelUtil {
|
||||
builder.doWrite(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 单表多数据模板导出 模板格式为 {.属性}
|
||||
*
|
||||
|
||||
@ -17,9 +17,9 @@ import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.log.enums.BusinessType;
|
||||
import com.fuyuanshen.common.excel.utils.ExcelUtil;
|
||||
import com.fuyuanshen.app.domain.vo.AppBusinessFileVo;
|
||||
import com.fuyuanshen.app.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.app.service.IAppBusinessFileService;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppBusinessFileVo;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.equipment.service.IAppBusinessFileService;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
|
||||
@ -17,9 +17,9 @@ import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.log.enums.BusinessType;
|
||||
import com.fuyuanshen.common.excel.utils.ExcelUtil;
|
||||
import com.fuyuanshen.app.domain.vo.AppOperationVideoVo;
|
||||
import com.fuyuanshen.app.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.app.service.IAppOperationVideoService;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppOperationVideoVo;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.equipment.service.IAppOperationVideoService;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 设备分享Mapper接口
|
||||
@ -30,5 +31,5 @@ public interface AppDeviceShareMapper extends BaseMapperPlus<AppDeviceShare, App
|
||||
*/
|
||||
Page<AppDeviceShareVo> selectWebDeviceShareList(@Param("bo") AppDeviceShareBo bo, Page<AppDeviceShareVo> page);
|
||||
|
||||
void deleteByDeviceIds(@Param("deviceIds") List<Long> deviceIds);
|
||||
void deleteByDeviceIds(@Param("deviceIds") Set<Long> deviceIds);
|
||||
}
|
||||
|
||||
@ -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接口
|
||||
@ -68,5 +69,5 @@ public interface IAppDeviceShareService {
|
||||
|
||||
TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery);
|
||||
|
||||
void deleteByDeviceIds(List<Long> deviceIds);
|
||||
void deleteByDeviceIds(Set<Long> deviceIds);
|
||||
}
|
||||
|
||||
@ -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业务层处理
|
||||
@ -168,7 +169,7 @@ public class AppDeviceShareServiceImpl implements IAppDeviceShareService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByDeviceIds(List<Long> deviceIds) {
|
||||
public void deleteByDeviceIds(Set<Long> deviceIds) {
|
||||
baseMapper.deleteByDeviceIds(deviceIds);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,4 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper">
|
||||
|
||||
<select id="checkDeviceExistBindRecord" resultType="java.lang.Long">
|
||||
select count(1) from app_device_bind_record where device_id = #{deviceId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@ -140,6 +140,18 @@
|
||||
<version>3.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 电话语音通知 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>dyvmsapi20170525</artifactId>
|
||||
<version>4.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-openapi</artifactId>
|
||||
<version>0.3.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- fastjson2 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
|
||||
@ -3,9 +3,7 @@ package com.fuyuanshen.equipment.controller;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.common.core.constant.ResponseMessageConstants;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.domain.ResponseVO;
|
||||
import com.fuyuanshen.common.core.domain.model.LoginUser;
|
||||
import com.fuyuanshen.common.core.utils.file.FileUtil;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
@ -18,7 +16,6 @@ import com.fuyuanshen.equipment.domain.dto.DeviceExcelImportDTO;
|
||||
import com.fuyuanshen.equipment.domain.dto.ImportResult;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
||||
import com.fuyuanshen.equipment.excel.DeviceImportParams;
|
||||
import com.fuyuanshen.equipment.excel.HeadValidateListener;
|
||||
import com.fuyuanshen.equipment.excel.UploadDeviceDataListener;
|
||||
@ -75,6 +72,12 @@ public class DeviceController extends BaseController {
|
||||
return deviceService.queryAll(criteria, page);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/pageTerminal")
|
||||
public TableDataInfo<Device> deviceFenecSelect(DeviceQueryCriteria criteria) throws IOException {
|
||||
Page<Device> page = new Page<>(criteria.getPageNum(), criteria.getPageSize());
|
||||
return deviceService.queryAllTerminal(criteria, page);
|
||||
}
|
||||
|
||||
|
||||
// @Log("新增设备")
|
||||
@Operation(summary = "新增设备")
|
||||
@ -314,8 +317,7 @@ public class DeviceController extends BaseController {
|
||||
// 定义必需的表头
|
||||
Set<String> requiredHeaders = new HashSet<>(Arrays.asList(
|
||||
"设备名称", "设备类型名称", "设备图片", "设备MAC", "蓝牙名称", "设备IMEI",
|
||||
"备注", "是否支持蓝牙", "定位方式", "通讯方式",
|
||||
"型号字典用于APP页面跳转", "型号字典用于PC页面跳转"
|
||||
"备注"
|
||||
));
|
||||
|
||||
// 检查必需的表头是否都存在
|
||||
|
||||
@ -41,6 +41,7 @@ public class DeviceRepairRecordsController extends BaseController {
|
||||
|
||||
private final IDeviceRepairRecordsService deviceRepairRecordsService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备维修记录列表
|
||||
*/
|
||||
@ -52,6 +53,7 @@ public class DeviceRepairRecordsController extends BaseController {
|
||||
return deviceRepairRecordsService.queryPageList(criteria, page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出设备维修记录列表
|
||||
*/
|
||||
@ -63,6 +65,7 @@ public class DeviceRepairRecordsController extends BaseController {
|
||||
ExcelUtil.exportExcel(list, "设备维修记录", DeviceRepairRecordsVo.class, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备维修记录详细信息
|
||||
*
|
||||
@ -75,6 +78,7 @@ public class DeviceRepairRecordsController extends BaseController {
|
||||
return R.ok(deviceRepairRecordsService.queryById(recordId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增设备维修记录
|
||||
*/
|
||||
@ -86,6 +90,7 @@ public class DeviceRepairRecordsController extends BaseController {
|
||||
return toAjax(deviceRepairRecordsService.insertByBo(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改设备维修记录
|
||||
*/
|
||||
@ -109,4 +114,5 @@ public class DeviceRepairRecordsController extends BaseController {
|
||||
@PathVariable Long[] recordIds) {
|
||||
return toAjax(deviceRepairRecordsService.deleteWithValidByIds(List.of(recordIds), true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -50,7 +51,7 @@ public class DeviceTypeController {
|
||||
// @Log("新增设备类型")
|
||||
@Operation(summary = "新增设备类型")
|
||||
@PostMapping(value = "/add")
|
||||
public R<Void> createDeviceType(@Validated @RequestBody DeviceType resources) {
|
||||
public R<Void> createDeviceType(@Validated @ModelAttribute DeviceTypeForm resources) throws IOException {
|
||||
deviceTypeService.create(resources);
|
||||
return R.ok();
|
||||
}
|
||||
@ -59,7 +60,7 @@ public class DeviceTypeController {
|
||||
// @Log("修改设备类型")
|
||||
@Operation(summary = "修改设备类型")
|
||||
@PutMapping(value = "/update")
|
||||
public R<Void> updateDeviceType(@Validated @RequestBody DeviceTypeForm resources) {
|
||||
public R<Void> updateDeviceType(@Validated @ModelAttribute DeviceTypeForm resources) throws IOException {
|
||||
deviceTypeService.update(resources);
|
||||
return R.ok();
|
||||
}
|
||||
@ -79,7 +80,6 @@ public class DeviceTypeController {
|
||||
public R<DeviceType> getCommunicationMode(@Parameter(name = "设备类型ID", required = true) Long id) {
|
||||
DeviceType communicationMode = deviceTypeService.getCommunicationMode(id);
|
||||
return R.ok(communicationMode);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,143 @@
|
||||
package com.fuyuanshen.equipment.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.bo.TerminalDelBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.TerminalDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.TerminalQueryBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.TrackServiceBo;
|
||||
import com.fuyuanshen.equipment.domain.dto.TerminalDeviceDto;
|
||||
import com.fuyuanshen.equipment.domain.vo.TrackServiceVo;
|
||||
import com.fuyuanshen.equipment.service.ITrackServiceService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.*;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
||||
import com.fuyuanshen.common.log.annotation.Log;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.log.enums.BusinessType;
|
||||
import com.fuyuanshen.common.excel.utils.ExcelUtil;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 轨迹服务
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-11-24
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/trackService")
|
||||
public class TrackServiceController extends BaseController {
|
||||
|
||||
private final ITrackServiceService trackServiceService;
|
||||
|
||||
/**
|
||||
* 查询轨迹服务列表
|
||||
*/
|
||||
// @SaCheckPermission("equipment:trackService:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<TrackServiceVo> list(TrackServiceBo bo, PageQuery pageQuery) {
|
||||
return trackServiceService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 轨迹服务列表
|
||||
*/
|
||||
// @SaCheckPermission("equipment:trackService:export")
|
||||
@Log(title = "轨迹服务", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(TrackServiceBo bo, HttpServletResponse response) {
|
||||
List<TrackServiceVo> list = trackServiceService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "轨迹服务", TrackServiceVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取轨迹服务详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<TrackServiceVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(trackServiceService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增轨迹服务
|
||||
*/
|
||||
// @SaCheckPermission("equipment:trackService:add")
|
||||
@Log(title = "轨迹服务", businessType = BusinessType.INSERT)
|
||||
@PostMapping(value = "/add")
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody TrackServiceBo bo) {
|
||||
return toAjax(trackServiceService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改轨迹服务
|
||||
*/
|
||||
// @SaCheckPermission("equipment:trackService:edit")
|
||||
@Log(title = "轨迹服务", businessType = BusinessType.UPDATE)
|
||||
@PostMapping(value = "/update")
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody TrackServiceBo bo) {
|
||||
return toAjax(trackServiceService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除轨迹服务
|
||||
*
|
||||
* @param ids 主键串
|
||||
*/
|
||||
// @SaCheckPermission("equipment:trackService:remove")
|
||||
@Log(title = "轨迹服务", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping(value = "/delete")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(trackServiceService.deleteWithValidByIds(List.of(ids), true));
|
||||
}
|
||||
|
||||
@Log(title = "高德添加终端设备")
|
||||
@PostMapping(value = "/terminal")
|
||||
public R<Void> terminalDevice(@RequestBody TerminalDeviceBo model) {
|
||||
trackServiceService.terminal(model);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@Log(title = "高德移除终端设备")
|
||||
@DeleteMapping(value = "/delTerminal/{ids}")
|
||||
public R<Void> delTerminalDevice(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(trackServiceService.delTerminalDevice(List.of(ids), true));
|
||||
}
|
||||
|
||||
@Log(title = "高德移除终端设备")
|
||||
@DeleteMapping(value = "/del/Terminal")
|
||||
public R<Void> delTerminalDevice(TerminalDelBo bo) {
|
||||
return toAjax(trackServiceService.delTerminalDevice(bo, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 高德终端设备列表
|
||||
*/
|
||||
@GetMapping("/listTerminal")
|
||||
public TableDataInfo<TerminalDeviceDto> listTerminal(TerminalQueryBo bo) {
|
||||
return trackServiceService.listTerminal(bo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 高德终端设备列表(关键字查询)
|
||||
*/
|
||||
@GetMapping("/searchTerminal")
|
||||
public TableDataInfo<TerminalDeviceDto> searchTerminal(TerminalQueryBo bo) {
|
||||
return trackServiceService.searchTerminal(bo);
|
||||
}
|
||||
}
|
||||
@ -17,6 +17,10 @@ import java.net.URLConnection;
|
||||
import java.util.Base64;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
@ -30,9 +34,9 @@ public class IgnoreFailedImageConverter implements Converter<URL> {
|
||||
// 指数退避初始延迟(毫秒)
|
||||
private static final int INITIAL_DELAY = 1000;
|
||||
// 图片压缩阈值(1MB)
|
||||
private static final int COMPRESSION_THRESHOLD = 1024 * 1024;
|
||||
// 压缩目标大小(100KB)
|
||||
private static final int COMPRESSION_TARGET = 100 * 1024;
|
||||
private static final int COMPRESSION_THRESHOLD = 100 * 1024;
|
||||
// 压缩目标大小(50KB)
|
||||
private static final int COMPRESSION_TARGET = 50 * 1024;
|
||||
// 用于跟踪本次任务中使用到的URL缓存键
|
||||
private static final ThreadLocal<Set<String>> USED_CACHE_KEYS = new ThreadLocal<Set<String>>() {
|
||||
@Override
|
||||
@ -41,12 +45,15 @@ public class IgnoreFailedImageConverter implements Converter<URL> {
|
||||
}
|
||||
};
|
||||
|
||||
// 创建线程池用于并发处理图片
|
||||
private static final ExecutorService IMAGE_PROCESSING_EXECUTOR = Executors.newFixedThreadPool(
|
||||
Runtime.getRuntime().availableProcessors() * 2);
|
||||
|
||||
@Override
|
||||
public Class<?> supportJavaTypeKey() {
|
||||
return URL.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public WriteCellData<?> convertToExcelData(URL value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
if (value == null) {
|
||||
@ -54,6 +61,32 @@ public class IgnoreFailedImageConverter implements Converter<URL> {
|
||||
return new WriteCellData<>(new byte[0]);
|
||||
}
|
||||
|
||||
try {
|
||||
// 使用CompletableFuture异步处理图片加载
|
||||
CompletableFuture<WriteCellData<?>> future = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return loadImageData(value);
|
||||
} catch (Exception e) {
|
||||
logger.error("异步加载图片失败: {}", value, e);
|
||||
return new WriteCellData<>(new byte[0]);
|
||||
}
|
||||
}, IMAGE_PROCESSING_EXECUTOR);
|
||||
|
||||
// 设置超时时间,防止长时间阻塞
|
||||
return future.get(30, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
logger.error("图片处理异常: {}", value, e);
|
||||
return new WriteCellData<>(new byte[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载图片数据的核心方法
|
||||
*
|
||||
* @param value 图片URL
|
||||
* @return WriteCellData对象
|
||||
*/
|
||||
private WriteCellData<?> loadImageData(URL value) {
|
||||
String cacheKey = "excel:image:" + value.toString();
|
||||
|
||||
// 将当前使用的缓存键添加到集合中
|
||||
@ -75,11 +108,13 @@ public class IgnoreFailedImageConverter implements Converter<URL> {
|
||||
logger.info("开始加载图片: {}, 尝试次数: {}", value, attempt);
|
||||
URLConnection conn = value.openConnection();
|
||||
// 增加连接和读取超时时间
|
||||
conn.setConnectTimeout(10000); // 10秒连接超时
|
||||
conn.setReadTimeout(30000); // 30秒读取超时
|
||||
conn.setConnectTimeout(5000); // 5秒连接超时
|
||||
conn.setReadTimeout(15000); // 15秒读取超时
|
||||
|
||||
// 添加User-Agent避免被服务器拦截
|
||||
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 ExcelExporter/1.0");
|
||||
// 添加Connection: close避免保持连接
|
||||
conn.setRequestProperty("Connection", "close");
|
||||
|
||||
// 如果是HTTP连接,设置一些额外的属性
|
||||
if (conn instanceof HttpURLConnection) {
|
||||
@ -152,9 +187,18 @@ public class IgnoreFailedImageConverter implements Converter<URL> {
|
||||
if (bytes.length > COMPRESSION_THRESHOLD) {
|
||||
logger.info("图片大小超过1MB ({} bytes),开始压缩", bytes.length);
|
||||
long beforeCompressSize = bytes.length;
|
||||
bytes = ImageCompressUtil.compressImage(bytes, COMPRESSION_TARGET);
|
||||
|
||||
// 先尝试质量压缩
|
||||
byte[] compressed = ImageCompressUtil.compressImage(bytes, COMPRESSION_TARGET);
|
||||
|
||||
// 如果压缩后变大了,使用原始数据
|
||||
if (compressed.length >= bytes.length) {
|
||||
compressed = bytes;
|
||||
}
|
||||
|
||||
bytes = compressed;
|
||||
long afterCompressSize = bytes.length;
|
||||
logger.info("图片压缩完成,压缩前大小: {} bytes, 压缩后大小: {} bytes, 压缩率: {}%",
|
||||
logger.info("图片压缩完成,压缩前大小: {} bytes, 压缩后大小: {} bytes, 压缩率: {}",
|
||||
beforeCompressSize, afterCompressSize,
|
||||
String.format("%.2f", (1.0 - (double) afterCompressSize / beforeCompressSize) * 100));
|
||||
}
|
||||
@ -209,7 +253,6 @@ public class IgnoreFailedImageConverter implements Converter<URL> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 等待重试,使用指数退避策略
|
||||
*
|
||||
@ -225,7 +268,6 @@ public class IgnoreFailedImageConverter implements Converter<URL> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 替代 FileUtils.readInputStream 的自定义方法
|
||||
*
|
||||
@ -253,4 +295,38 @@ public class IgnoreFailedImageConverter implements Converter<URL> {
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载图片到缓存
|
||||
*
|
||||
* @param imageUrls 图片URL列表
|
||||
*/
|
||||
public static void preloadImages(Set<URL> imageUrls) {
|
||||
if (imageUrls == null || imageUrls.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("开始预加载 {} 张图片", imageUrls.size());
|
||||
|
||||
// 使用并行流并发预加载图片
|
||||
imageUrls.parallelStream().forEach(url -> {
|
||||
try {
|
||||
String cacheKey = "excel:image:" + url.toString();
|
||||
// 如果缓存中没有,则异步加载
|
||||
if (!RedisUtils.hasKey(cacheKey)) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
// 简化版图片加载逻辑,只加载到缓存
|
||||
new IgnoreFailedImageConverter().loadImageData(url);
|
||||
} catch (Exception e) {
|
||||
logger.warn("预加载图片失败: {}", url, e);
|
||||
}
|
||||
}, IMAGE_PROCESSING_EXECUTOR);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("预加载图片异常: {}", url, e);
|
||||
}
|
||||
});
|
||||
|
||||
logger.info("图片预加载任务已提交");
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.fuyuanshen.app.domain;
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.fuyuanshen.app.domain;
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
@ -167,4 +167,20 @@ public class Device extends TenantEntity {
|
||||
*/
|
||||
private Integer onlineStatus;
|
||||
|
||||
/**
|
||||
* 高德服务ID
|
||||
*/
|
||||
@Schema(title = "服务ID(高德)")
|
||||
private Long sid;
|
||||
/**
|
||||
* 高德终端ID
|
||||
*/
|
||||
@Schema(title = "终端ID(高德)")
|
||||
private Long tid;
|
||||
/**
|
||||
* 高德轨迹ID
|
||||
*/
|
||||
@Schema(title = "轨迹ID(高德)")
|
||||
private Long trid;
|
||||
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import java.util.Date;
|
||||
@ -18,7 +19,7 @@ import java.io.Serial;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("device_fence_access_record")
|
||||
public class DeviceFenceAccessRecord extends BaseEntity {
|
||||
public class DeviceFenceAccessRecord extends TenantEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 围栏终端关联
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@TableName("device_fence_terminal")
|
||||
public class DeviceFenceTerminal {
|
||||
/**
|
||||
* 围栏ID
|
||||
*/
|
||||
@TableId(type = IdType.INPUT)
|
||||
private Long fenceId;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
private Long deviceId;
|
||||
}
|
||||
@ -58,6 +58,14 @@ public class DeviceGeoFence extends BaseEntity {
|
||||
* 是否激活
|
||||
*/
|
||||
private Long isActive;
|
||||
/**
|
||||
* 高德服务ID
|
||||
*/
|
||||
private Long sid;
|
||||
/**
|
||||
* 高德围栏ID
|
||||
*/
|
||||
private Long gfid;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -85,5 +85,8 @@ public class DeviceType extends TenantEntity {
|
||||
@Schema(title = "型号字典用于PC页面跳转")
|
||||
private String pcModelDictionary;
|
||||
|
||||
@Schema(title = "设备图片")
|
||||
private String devicePic;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 轨迹服务对象 track_service
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-11-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("track_service")
|
||||
public class TrackService extends BaseEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 猎鹰服务ID
|
||||
*/
|
||||
private Long sid;
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
private String sname;
|
||||
|
||||
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
package com.fuyuanshen.app.domain.bo;
|
||||
package com.fuyuanshen.equipment.domain.bo;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.equipment.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
@ -1,6 +1,6 @@
|
||||
package com.fuyuanshen.app.domain.bo;
|
||||
package com.fuyuanshen.equipment.domain.bo;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppOperationVideo;
|
||||
import com.fuyuanshen.equipment.domain.AppOperationVideo;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
@ -70,6 +70,14 @@ public class DeviceGeoFenceBo extends BaseEntity {
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 高德服务ID
|
||||
*/
|
||||
private Long sid;
|
||||
/**
|
||||
* 高德围栏ID
|
||||
*/
|
||||
private Long gfid;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package com.fuyuanshen.equipment.domain.bo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class FenceTerminalBo {
|
||||
/**
|
||||
* 围栏ID
|
||||
*/
|
||||
private Long fenceId;
|
||||
/**
|
||||
* 设备IDs
|
||||
*/
|
||||
private List<Long> deviceIds;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.fuyuanshen.equipment.domain.bo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TerminalDelBo {
|
||||
/**
|
||||
* 猎鹰服务ID
|
||||
*/
|
||||
private Long sid;
|
||||
/**
|
||||
* 轨迹ID
|
||||
*/
|
||||
private Long trid;
|
||||
/**
|
||||
* 终端ID
|
||||
*/
|
||||
private Long tid;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.fuyuanshen.equipment.domain.bo;
|
||||
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TerminalDeviceBo {
|
||||
/**
|
||||
* 猎鹰服务ID
|
||||
*/
|
||||
private Long sid;
|
||||
/**
|
||||
* 设备列表
|
||||
*/
|
||||
List<DeviceForm> deviceList;
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package com.fuyuanshen.equipment.domain.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Value;
|
||||
|
||||
@Data
|
||||
public class TerminalQueryBo {
|
||||
/**
|
||||
* 猎鹰服务ID
|
||||
*/
|
||||
private Long sid;
|
||||
/**
|
||||
* 名称查询
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 终端ID
|
||||
*/
|
||||
private Long tid;
|
||||
/**
|
||||
* 关键字搜索
|
||||
*/
|
||||
private String keywords;
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
private int page = 1;
|
||||
/**
|
||||
* 每页数量
|
||||
*/
|
||||
private int pagesize = 10;
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.fuyuanshen.equipment.domain.bo;
|
||||
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import com.fuyuanshen.equipment.domain.TrackService;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 轨迹服务业务对象 track_service
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-11-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = TrackService.class, reverseConvertGenerate = false)
|
||||
public class TrackServiceBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 猎鹰服务ID
|
||||
*/
|
||||
private Long sid;
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
private String sname;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package com.fuyuanshen.equipment.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor // 必须
|
||||
public class TerminalDeviceDto {
|
||||
/**
|
||||
* 终端设备名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 终端设备ID
|
||||
*/
|
||||
private Long tid;
|
||||
/**
|
||||
* 终端设备描述
|
||||
*/
|
||||
private String desc;
|
||||
/**
|
||||
* 终端设备创建时间
|
||||
*/
|
||||
private String createtime;
|
||||
/**
|
||||
* 终端设备最后定位时间
|
||||
*/
|
||||
private String locatetime;
|
||||
}
|
||||
@ -54,6 +54,9 @@ public class DeviceForm {
|
||||
@Schema(title = "备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(title = "商户号")
|
||||
private Long tenant_id;
|
||||
|
||||
|
||||
// 设备类型相关字段
|
||||
@Schema(title = "设备类型名称")
|
||||
|
||||
@ -2,6 +2,7 @@ package com.fuyuanshen.equipment.domain.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @Description: 设备类型
|
||||
@ -48,5 +49,10 @@ public class DeviceTypeForm {
|
||||
*/
|
||||
@Schema(title = "型号字典用于PC页面跳转")
|
||||
private String pcModelDictionary;
|
||||
@Schema(title = "设备图片")
|
||||
private String devicePic;
|
||||
|
||||
@Schema(title = "设备图片")
|
||||
private MultipartFile file;
|
||||
|
||||
}
|
||||
|
||||
@ -122,5 +122,25 @@ public class DeviceQueryCriteria extends BaseEntity {
|
||||
* online_status
|
||||
*/
|
||||
private Integer onlineStatus;
|
||||
/**
|
||||
* 高德终端ID是否存在
|
||||
*/
|
||||
private Boolean isTid;
|
||||
/**
|
||||
* 高德服务ID
|
||||
*/
|
||||
private String sid;
|
||||
/**
|
||||
* 围栏ID
|
||||
*/
|
||||
private Long fenceId;
|
||||
|
||||
/**
|
||||
* 绑定状态
|
||||
* 0 未绑定
|
||||
* 1 已绑定
|
||||
*/
|
||||
@Schema(title = "绑定状态")
|
||||
private Integer bindingStatus;
|
||||
|
||||
}
|
||||
|
||||
@ -1,17 +1,13 @@
|
||||
package com.fuyuanshen.app.domain.vo;
|
||||
package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.equipment.domain.AppBusinessFile;
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import com.fuyuanshen.common.excel.annotation.ExcelDictFormat;
|
||||
import com.fuyuanshen.common.excel.convert.ExcelDictConvert;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -1,4 +1,4 @@
|
||||
package com.fuyuanshen.app.domain.vo;
|
||||
package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@ -1,17 +1,13 @@
|
||||
package com.fuyuanshen.app.domain.vo;
|
||||
package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppOperationVideo;
|
||||
import com.fuyuanshen.equipment.domain.AppOperationVideo;
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import com.fuyuanshen.common.excel.annotation.ExcelDictFormat;
|
||||
import com.fuyuanshen.common.excel.convert.ExcelDictConvert;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -2,6 +2,7 @@ package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
@ -60,6 +61,13 @@ public class DeviceFenceAccessRecordVo implements Serializable {
|
||||
@ExcelProperty(value = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 事件时间
|
||||
*/
|
||||
@ExcelProperty(value = "事件时间")
|
||||
@ColumnWidth(120)
|
||||
private String eventTime;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@ -76,27 +84,21 @@ public class DeviceFenceAccessRecordVo implements Serializable {
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
@ExcelProperty(value = "纬度")
|
||||
// @ExcelProperty(value = "纬度")
|
||||
private Double latitude;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
@ExcelProperty(value = "经度")
|
||||
// @ExcelProperty(value = "经度")
|
||||
private Double longitude;
|
||||
|
||||
/**
|
||||
* 定位精度
|
||||
*/
|
||||
@ExcelProperty(value = "定位精度")
|
||||
// @ExcelProperty(value = "定位精度")
|
||||
private Long accuracy;
|
||||
|
||||
/**
|
||||
* 事件时间
|
||||
*/
|
||||
@ExcelProperty(value = "事件时间")
|
||||
private Date eventTime;
|
||||
|
||||
/**
|
||||
* 事件地址
|
||||
*/
|
||||
@ -106,8 +108,7 @@ public class DeviceFenceAccessRecordVo implements Serializable {
|
||||
/**
|
||||
* 记录创建时间
|
||||
*/
|
||||
@ExcelProperty(value = "记录创建时间")
|
||||
// @ExcelProperty(value = "记录创建时间")
|
||||
private Date createTime;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -101,6 +101,14 @@ public class DeviceGeoFenceVo implements Serializable {
|
||||
*/
|
||||
// @ExcelProperty(value = "更新时间")
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 高德服务ID
|
||||
*/
|
||||
private Long sid;
|
||||
/**
|
||||
* 高德围栏ID
|
||||
*/
|
||||
private Long gfid;
|
||||
|
||||
|
||||
public void setAreaTypeNameByAreaType() {
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import java.util.Date;
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import cn.idev.excel.annotation.write.style.ColumnWidth;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import com.fuyuanshen.common.excel.annotation.ExcelDictFormat;
|
||||
import com.fuyuanshen.common.excel.convert.ExcelDictConvert;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
@ -34,31 +32,39 @@ public class DeviceRepairRecordsVo extends TenantEntity implements Serializable
|
||||
/**
|
||||
* 维修记录ID
|
||||
*/
|
||||
@ExcelProperty(value = "维修记录ID")
|
||||
// @ExcelProperty(value = "维修记录ID")
|
||||
private Long recordId;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@ExcelProperty(value = "设备ID")
|
||||
// @ExcelProperty(value = "设备ID")
|
||||
private String deviceId;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
@ExcelProperty(value = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 维修时间
|
||||
*/
|
||||
@ExcelProperty(value = "维修时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ColumnWidth(value = 20)
|
||||
private Date repairTime;
|
||||
|
||||
/**
|
||||
* 维修部位
|
||||
* 损坏部位
|
||||
*/
|
||||
@ExcelProperty(value = "维修部位")
|
||||
@ExcelProperty(value = "损坏部位")
|
||||
private String repairPart;
|
||||
|
||||
/**
|
||||
* 维修原因
|
||||
* 损坏原因
|
||||
*/
|
||||
@ExcelProperty(value = "维修原因")
|
||||
@ExcelProperty(value = "损坏原因")
|
||||
private String repairReason;
|
||||
|
||||
/**
|
||||
@ -66,11 +72,7 @@ public class DeviceRepairRecordsVo extends TenantEntity implements Serializable
|
||||
*/
|
||||
@ExcelProperty(value = "维修人员")
|
||||
private String repairPerson;
|
||||
/**
|
||||
* 维修人员
|
||||
*/
|
||||
@ExcelProperty(value = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
|
||||
private List<DeviceRepairImagesVo> images;
|
||||
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import com.fuyuanshen.common.excel.annotation.ExcelDictFormat;
|
||||
import com.fuyuanshen.common.excel.convert.ExcelDictConvert;
|
||||
import com.fuyuanshen.equipment.domain.TrackService;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 轨迹服务视图对象 track_service
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-11-24
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@AutoMapper(target = TrackService.class)
|
||||
public class TrackServiceVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ExcelProperty(value = "")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 猎鹰服务ID
|
||||
*/
|
||||
@ExcelProperty(value = "猎鹰服务ID")
|
||||
private Long sid;
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
@ExcelProperty(value = "服务名称")
|
||||
private String sname;
|
||||
|
||||
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -103,5 +104,20 @@ public class WebDeviceVo implements Serializable {
|
||||
* 分享用户数量
|
||||
*/
|
||||
private Integer shareUsersNumber;
|
||||
/**
|
||||
* 高德服务ID
|
||||
*/
|
||||
@Schema(title = "服务ID(高德)")
|
||||
private Long sid;
|
||||
/**
|
||||
* 高德终端ID
|
||||
*/
|
||||
@Schema(title = "终端ID(高德)")
|
||||
private Long tid;
|
||||
/**
|
||||
* 高德轨迹ID
|
||||
*/
|
||||
@Schema(title = "轨迹ID(高德)")
|
||||
private Long trid;
|
||||
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceExcelImportDTO;
|
||||
import com.fuyuanshen.equipment.domain.dto.ImportResult;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
|
||||
import com.fuyuanshen.equipment.handler.ImageWriteHandler;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -437,8 +438,10 @@ public class UploadDeviceDataListener implements ReadListener<DeviceExcelImportD
|
||||
newDeviceType.setAppModelDictionary(originalDto.getAppModelDictionary());
|
||||
newDeviceType.setPcModelDictionary(originalDto.getPcModelDictionary());
|
||||
|
||||
DeviceTypeForm deviceTypeForm = new DeviceTypeForm();
|
||||
BeanUtil.copyProperties(newDeviceType, deviceTypeForm, true);
|
||||
// 创建新的设备类型
|
||||
params.getDeviceTypeService().create(newDeviceType);
|
||||
params.getDeviceTypeService().create(deviceTypeForm);
|
||||
|
||||
// 重新查询确保获取到正确的ID
|
||||
deviceType = params.getDeviceTypeService().queryByName(device.getTypeName());
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
package com.fuyuanshen.app.mapper;
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.app.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppBusinessFileVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppFileVo;
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import com.fuyuanshen.equipment.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppBusinessFileVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppFileVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package com.fuyuanshen.app.mapper;
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppOperationVideo;
|
||||
import com.fuyuanshen.app.domain.vo.AppOperationVideoVo;
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import com.fuyuanshen.equipment.domain.AppOperationVideo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppOperationVideoVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
@ -39,6 +39,8 @@ public interface DeviceFenceAccessRecordMapper extends BaseMapperPlus<DeviceFenc
|
||||
*/
|
||||
Page<DeviceFenceAccessRecordVo> selectVoPageByXml(Page<DeviceFenceAccessRecord> page, @Param("bo") DeviceFenceAccessRecordBo bo);
|
||||
|
||||
List<DeviceFenceAccessRecordVo> selectVoPageByXml(@Param("bo") DeviceFenceAccessRecordBo bo);
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备最新的围栏记录
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import com.fuyuanshen.equipment.domain.DeviceFenceTerminal;
|
||||
|
||||
public interface DeviceFenceTerminalMapper extends BaseMapperPlus<DeviceFenceTerminal, DeviceFenceTerminal> {
|
||||
}
|
||||
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.InstructionRecordDto;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.*;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -32,6 +33,8 @@ public interface DeviceMapper extends BaseMapper<Device> {
|
||||
|
||||
List<Device> findAll(@Param("criteria") DeviceQueryCriteria criteria);
|
||||
|
||||
IPage<Device> findAllTerminal(@Param("criteria") DeviceQueryCriteria criteria, Page<Device> page);
|
||||
|
||||
List<Device> findAllDevices(@Param("criteria") DeviceQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
@ -146,4 +149,10 @@ public interface DeviceMapper extends BaseMapper<Device> {
|
||||
*/
|
||||
int countByDeviceTypeId(@Param("deviceTypeId") Long deviceTypeId);
|
||||
|
||||
List<Map<String, Object>> GetDeviceByName(DeviceForm deviceForm);
|
||||
|
||||
int getEquipCountByType(DeviceForm deviceForm);
|
||||
|
||||
List<Map<String,Object>> getEquipAllByType(DeviceForm deviceForm);
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import com.fuyuanshen.equipment.domain.TrackService;
|
||||
import com.fuyuanshen.equipment.domain.vo.TrackServiceVo;
|
||||
|
||||
/**
|
||||
* 轨迹服务Mapper接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-11-24
|
||||
*/
|
||||
public interface TrackServiceMapper extends BaseMapperPlus<TrackService, TrackServiceVo> {
|
||||
|
||||
}
|
||||
@ -1,13 +1,10 @@
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fuyuanshen.common.core.domain.PageResult;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
@ -33,6 +30,8 @@ public interface DeviceService extends IService<Device> {
|
||||
*/
|
||||
TableDataInfo<Device> queryAll(DeviceQueryCriteria criteria, Page<Device> page) throws IOException;
|
||||
|
||||
TableDataInfo<Device> queryAllTerminal(DeviceQueryCriteria criteria, Page<Device> page) throws IOException;
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
*
|
||||
|
||||
@ -8,6 +8,7 @@ import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -63,14 +64,14 @@ public interface DeviceTypeService extends IService<DeviceType> {
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void create(DeviceType resources);
|
||||
void create(DeviceTypeForm resources) throws IOException;
|
||||
|
||||
/**
|
||||
* 修改设备类型
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void update(DeviceTypeForm resources);
|
||||
void update(DeviceTypeForm resources) throws IOException;
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.app.domain.vo.AppBusinessFileVo;
|
||||
import com.fuyuanshen.app.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppFileVo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.equipment.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppBusinessFileVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppFileVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -59,6 +59,8 @@ public interface IAppBusinessFileService {
|
||||
*/
|
||||
Boolean insertBatch(Collection<AppBusinessFile> bo, Boolean isBatch);
|
||||
|
||||
void cloneFiles(Long sourceId, Long targetId);
|
||||
|
||||
/**
|
||||
* 修改app业务文件
|
||||
*
|
||||
@ -1,11 +1,10 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.app.domain.AppOperationVideo;
|
||||
import com.fuyuanshen.app.domain.vo.AppOperationVideoVo;
|
||||
import com.fuyuanshen.app.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.equipment.domain.AppOperationVideo;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppOperationVideoVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -59,6 +58,8 @@ public interface IAppOperationVideoService {
|
||||
*/
|
||||
Boolean insertBatch(Collection<AppOperationVideo> bo);
|
||||
|
||||
void cloneFiles(Long sourceId, Long targetId);
|
||||
|
||||
/**
|
||||
* 修改操作视频
|
||||
*
|
||||
@ -6,6 +6,7 @@ import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceGeoFence;
|
||||
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;
|
||||
@ -78,4 +79,8 @@ public interface IDeviceGeoFenceService extends IService<DeviceGeoFence> {
|
||||
* @return 位置检查结果
|
||||
*/
|
||||
FenceCheckResponse checkPosition(FenceCheckRequest request);
|
||||
|
||||
Boolean addFenceTerminal(FenceTerminalBo bo);
|
||||
|
||||
Boolean delFenceTerminal(FenceTerminalBo bo);
|
||||
}
|
||||
|
||||
@ -32,8 +32,8 @@ public interface IDeviceRepairRecordsService extends IService<DeviceRepairRecord
|
||||
/**
|
||||
* 分页查询设备维修记录列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param pageQuery 分页参数
|
||||
* @param criteria 查询条件
|
||||
* @param page 分页参数
|
||||
* @return 设备维修记录分页列表
|
||||
*/
|
||||
TableDataInfo<DeviceRepairRecordsVo> queryPageList(DeviceRepairRecordsQueryCriteria criteria, Page<DeviceRepairRecords> page);
|
||||
@ -41,7 +41,7 @@ public interface IDeviceRepairRecordsService extends IService<DeviceRepairRecord
|
||||
/**
|
||||
* 查询符合条件的设备维修记录列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param criteria 查询条件
|
||||
* @return 设备维修记录列表
|
||||
*/
|
||||
List<DeviceRepairRecordsVo> queryList(DeviceRepairRecordsQueryCriteria criteria);
|
||||
@ -70,4 +70,5 @@ public interface IDeviceRepairRecordsService extends IService<DeviceRepairRecord
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,103 @@
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.equipment.domain.bo.TerminalDelBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.TerminalDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.TerminalQueryBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.TrackServiceBo;
|
||||
import com.fuyuanshen.equipment.domain.dto.TerminalDeviceDto;
|
||||
import com.fuyuanshen.equipment.domain.vo.TrackServiceVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 轨迹服务Service接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-11-24
|
||||
*/
|
||||
public interface ITrackServiceService {
|
||||
|
||||
/**
|
||||
* 查询轨迹服务
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 轨迹服务
|
||||
*/
|
||||
TrackServiceVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 分页查询轨迹服务列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param pageQuery 分页参数
|
||||
* @return 轨迹服务分页列表
|
||||
*/
|
||||
TableDataInfo<TrackServiceVo> queryPageList(TrackServiceBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询符合条件的轨迹服务列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return 轨迹服务列表
|
||||
*/
|
||||
List<TrackServiceVo> queryList(TrackServiceBo bo);
|
||||
|
||||
/**
|
||||
* 新增轨迹服务
|
||||
*
|
||||
* @param bo 轨迹服务
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
Boolean insertByBo(TrackServiceBo bo);
|
||||
|
||||
/**
|
||||
* 修改轨迹服务
|
||||
*
|
||||
* @param bo 轨迹服务
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
Boolean updateByBo(TrackServiceBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除轨迹服务信息
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 高德添加终端设备
|
||||
*
|
||||
* @param terminalDeviceBo 添加集合
|
||||
*/
|
||||
void terminal(TerminalDeviceBo terminalDeviceBo);
|
||||
/**
|
||||
* 高德移除终端设备
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean delTerminalDevice(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
Boolean delTerminalDevice(TerminalDelBo bo, Boolean isValid);
|
||||
/**
|
||||
* 查询设备列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return 设备列表
|
||||
*/
|
||||
TableDataInfo<TerminalDeviceDto> listTerminal(TerminalQueryBo bo);
|
||||
/**
|
||||
* 关键字查询设备
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return 设备列表
|
||||
*/
|
||||
TableDataInfo<TerminalDeviceDto> searchTerminal(TerminalQueryBo bo);
|
||||
}
|
||||
@ -1,27 +1,29 @@
|
||||
package com.fuyuanshen.app.service.impl;
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fuyuanshen.app.domain.vo.AppFileVo;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
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.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fuyuanshen.equipment.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppBusinessFileVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppFileVo;
|
||||
import com.fuyuanshen.equipment.mapper.AppBusinessFileMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.fuyuanshen.app.domain.bo.AppBusinessFileBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppBusinessFileVo;
|
||||
import com.fuyuanshen.app.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.app.mapper.AppBusinessFileMapper;
|
||||
import com.fuyuanshen.app.service.IAppBusinessFileService;
|
||||
import com.fuyuanshen.equipment.service.IAppBusinessFileService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* app业务文件Service业务层处理
|
||||
@ -117,6 +119,38 @@ public class AppBusinessFileServiceImpl implements IAppBusinessFileService {
|
||||
return baseMapper.insertBatch(bo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 克隆业务文件列表到新业务ID
|
||||
* @param sourceId 源业务ID(如设备类型ID)
|
||||
* @param targetId 目标业务ID(如新设备ID)
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void cloneFiles(Long sourceId, Long targetId) {
|
||||
// 1. 使用 Wrappers 替代 this.lambdaQuery()
|
||||
List<AppBusinessFile> sourceFiles = baseMapper.selectList(
|
||||
Wrappers.<AppBusinessFile>lambdaQuery().eq(AppBusinessFile::getBusinessId, sourceId)
|
||||
);
|
||||
|
||||
if (CollUtil.isEmpty(sourceFiles)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 批量转换并重置ID
|
||||
List<AppBusinessFile> newFiles = sourceFiles.stream().map(file -> {
|
||||
AppBusinessFile entity = new AppBusinessFile();
|
||||
// 建议使用你代码中已有的 MapstructUtils 或 BeanUtil
|
||||
BeanUtil.copyProperties(file, entity);
|
||||
entity.setId(null); // 确保主键自增
|
||||
entity.setBusinessId(targetId); // 绑定到新设备ID
|
||||
return entity;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 3. 使用你已有的 insertBatch 替代 saveBatch
|
||||
// 注意:这里第二个参数传 false,因为是新设备,不需要执行你 insertBatch 里的删除逻辑
|
||||
this.insertBatch(newFiles, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改app业务文件
|
||||
*
|
||||
@ -1,7 +1,8 @@
|
||||
package com.fuyuanshen.app.service.impl;
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fuyuanshen.app.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
@ -9,18 +10,20 @@ import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fuyuanshen.equipment.domain.AppOperationVideo;
|
||||
import com.fuyuanshen.equipment.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppOperationVideoVo;
|
||||
import com.fuyuanshen.equipment.mapper.AppOperationVideoMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.fuyuanshen.app.domain.bo.AppOperationVideoBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppOperationVideoVo;
|
||||
import com.fuyuanshen.app.domain.AppOperationVideo;
|
||||
import com.fuyuanshen.app.mapper.AppOperationVideoMapper;
|
||||
import com.fuyuanshen.app.service.IAppOperationVideoService;
|
||||
import com.fuyuanshen.equipment.service.IAppOperationVideoService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 操作视频Service业务层处理
|
||||
@ -125,6 +128,37 @@ public class AppOperationVideoServiceImpl implements IAppOperationVideoService {
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 克隆业务文件列表到新业务ID
|
||||
* @param sourceId 源业务ID(如设备类型ID)
|
||||
* @param targetId 目标业务ID(如新设备ID)
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void cloneFiles(Long sourceId, Long targetId) {
|
||||
// 1. 使用 Wrappers 替代 this.lambdaQuery()
|
||||
List<AppOperationVideo> sourceFiles = baseMapper.selectList(
|
||||
Wrappers.<AppOperationVideo>lambdaQuery().eq(AppOperationVideo::getDeviceId, sourceId)
|
||||
);
|
||||
|
||||
if (CollUtil.isEmpty(sourceFiles)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 批量转换并重置ID
|
||||
List<AppOperationVideo> newFiles = sourceFiles.stream().map(file -> {
|
||||
AppOperationVideo entity = new AppOperationVideo();
|
||||
// 建议使用你代码中已有的 MapstructUtils 或 BeanUtil
|
||||
BeanUtil.copyProperties(file, entity);
|
||||
entity.setId(null); // 确保主键自增
|
||||
entity.setDeviceId(targetId); // 绑定到新设备ID
|
||||
return entity;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 3. 使用你已有的 insertBatch 替代 saveBatch
|
||||
this.insertBatch(newFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
@ -33,6 +33,7 @@ public class DeviceFenceAccessRecordServiceImpl implements IDeviceFenceAccessRec
|
||||
|
||||
private final DeviceFenceAccessRecordMapper baseMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 查询围栏进出记录
|
||||
*
|
||||
@ -68,8 +69,8 @@ public class DeviceFenceAccessRecordServiceImpl implements IDeviceFenceAccessRec
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceFenceAccessRecordVo> queryList(DeviceFenceAccessRecordBo bo) {
|
||||
LambdaQueryWrapper<DeviceFenceAccessRecord> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoPageWithFenceAndDeviceName(lqw, bo.getFenceName());
|
||||
// LambdaQueryWrapper<DeviceFenceAccessRecord> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoPageByXml(bo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@ -10,14 +11,17 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceFenceTerminal;
|
||||
import com.fuyuanshen.equipment.domain.DeviceGeoFence;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceFenceAccessRecordBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceFenceStatusBo;
|
||||
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.DeviceFenceStatusVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceGeoFenceVo;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceFenceTerminalMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceGeoFenceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.service.IDeviceFenceAccessRecordService;
|
||||
@ -25,6 +29,7 @@ import com.fuyuanshen.equipment.service.IDeviceFenceStatusService;
|
||||
import com.fuyuanshen.equipment.service.IDeviceGeoFenceService;
|
||||
import com.fuyuanshen.equipment.utils.map.GeoFenceChecker;
|
||||
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
|
||||
import com.fuyuanshen.system.domain.SysRoleMenu;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -48,6 +53,7 @@ public class DeviceGeoFenceServiceImpl extends ServiceImpl<DeviceGeoFenceMapper
|
||||
private final IDeviceFenceStatusService fenceStatusService; // 添加此行
|
||||
|
||||
private final IDeviceFenceAccessRecordService fenceAccessRecordService; // 添加此行
|
||||
private final DeviceFenceTerminalMapper deviceFenceTerminalMapper;
|
||||
|
||||
|
||||
|
||||
@ -270,4 +276,32 @@ public class DeviceGeoFenceServiceImpl extends ServiceImpl<DeviceGeoFenceMapper
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean addFenceTerminal(FenceTerminalBo bo) {
|
||||
// 新增围栏与终端关联信息
|
||||
List<DeviceFenceTerminal> list = new ArrayList<>();
|
||||
for (Long deviceId : bo.getDeviceIds()) {
|
||||
DeviceFenceTerminal rm = new DeviceFenceTerminal();
|
||||
rm.setFenceId(bo.getFenceId());
|
||||
rm.setDeviceId(deviceId);
|
||||
list.add(rm);
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
return deviceFenceTerminalMapper.insertBatch(list);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delFenceTerminal(FenceTerminalBo bo) {
|
||||
if (bo.getFenceId() == null || bo.getDeviceIds() == null || bo.getDeviceIds().isEmpty()) {
|
||||
throw new IllegalArgumentException("围栏ID或设备ID不能为空");
|
||||
}
|
||||
LambdaUpdateWrapper<DeviceFenceTerminal> lambda = new LambdaUpdateWrapper<DeviceFenceTerminal>()
|
||||
.eq(DeviceFenceTerminal::getFenceId, bo.getFenceId())
|
||||
.in(DeviceFenceTerminal::getDeviceId, bo.getDeviceIds());
|
||||
return deviceFenceTerminalMapper.delete(lambda) > 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -52,6 +52,7 @@ public class DeviceRepairRecordsServiceImpl extends ServiceImpl<DeviceRepairReco
|
||||
private final ISysOssService ossService;
|
||||
private final FileHashUtil fileHashUtil;
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备维修记录
|
||||
*
|
||||
@ -76,6 +77,7 @@ public class DeviceRepairRecordsServiceImpl extends ServiceImpl<DeviceRepairReco
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询设备维修记录列表
|
||||
*
|
||||
@ -98,6 +100,7 @@ public class DeviceRepairRecordsServiceImpl extends ServiceImpl<DeviceRepairReco
|
||||
return new TableDataInfo<DeviceRepairRecordsVo>(deviceRepairRecordsIPage.getRecords(), deviceRepairRecordsIPage.getTotal());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询符合条件的设备维修记录列表
|
||||
*
|
||||
|
||||
@ -19,11 +19,8 @@ import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.customer.domain.Customer;
|
||||
import com.fuyuanshen.customer.mapper.CustomerMapper;
|
||||
import com.fuyuanshen.equipment.constants.DeviceConstants;
|
||||
import com.fuyuanshen.equipment.domain.*;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceFenceAccessRecordBo;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.dto.FenceCheckResponse;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceAssignmentQuery;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
@ -41,15 +38,11 @@ import com.fuyuanshen.system.service.ISysOssService;
|
||||
import com.fuyuanshen.system.service.ISysRoleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
@ -81,6 +74,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
|
||||
private final DeviceFenceAccessRecordMapper deviceFenceAccessRecordMapper;
|
||||
private final FileHashUtil fileHashUtil;
|
||||
private final IAppBusinessFileService appBusinessFileService;
|
||||
private final IAppOperationVideoService appOperationVideoService;
|
||||
|
||||
|
||||
/**
|
||||
@ -130,6 +125,26 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
return new TableDataInfo<Device>(records, devices.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<Device> queryAllTerminal(DeviceQueryCriteria criteria, Page<Device> page) throws IOException {
|
||||
// 角色管理员
|
||||
Long userId = LoginHelper.getUserId();
|
||||
List<SysRoleVo> roles = roleService.selectRolesAuthByUserId(userId);
|
||||
boolean isAdmin = false;
|
||||
if (CollectionUtil.isNotEmpty(roles)) {
|
||||
for (SysRoleVo role : roles) {
|
||||
if (role.getRoleKey().equals("admin")) {
|
||||
isAdmin = true;
|
||||
criteria.setIsAdmin(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IPage<Device> devices = deviceMapper.findAllTerminal(criteria, page);
|
||||
return new TableDataInfo<Device>(devices.getRecords(), devices.getTotal());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Device> queryAll(DeviceQueryCriteria criteria) {
|
||||
@ -290,6 +305,10 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
if (deviceForm.getFile() != null) {
|
||||
String fileHash = fileHashUtil.hash(deviceForm.getFile());
|
||||
SysOssVo upload = ossService.updateHash(deviceForm.getFile(), fileHash);
|
||||
// 强制将HTTP替换为HTTPS
|
||||
if (upload.getUrl() != null && upload.getUrl().startsWith("http://")) {
|
||||
upload.setUrl(upload.getUrl().replaceFirst("^http://", "https://"));
|
||||
}
|
||||
// 设置图片路径
|
||||
deviceForm.setDevicePic(upload.getUrl());
|
||||
}
|
||||
@ -305,6 +324,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
device.setCreateByName(loginUser.getNickname());
|
||||
device.setTypeName(deviceType.getTypeName());
|
||||
device.setDeviceType(deviceType.getId());
|
||||
device.setDevicePic(deviceType.getDevicePic());
|
||||
if (device.getDeviceImei() != null) {
|
||||
device.setPubTopic("A/" + device.getDeviceImei());
|
||||
device.setSubTopic("B/" + device.getDeviceImei());
|
||||
@ -313,6 +333,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
device.setBindingStatus(0);
|
||||
deviceMapper.insert(device);
|
||||
|
||||
// 查询设备类型的文件列表
|
||||
// 4. 核心优化:同步设备类型的文件列表 (一行代码)
|
||||
appBusinessFileService.cloneFiles(deviceType.getId(), device.getId());
|
||||
//同步设备类型的视频列表
|
||||
appOperationVideoService.cloneFiles(deviceType.getId(), device.getId());
|
||||
|
||||
// 新增设备类型记录
|
||||
DeviceAssignments assignments = new DeviceAssignments();
|
||||
assignments.setDeviceId(device.getId());
|
||||
|
||||
@ -19,12 +19,16 @@ import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceTypeService;
|
||||
import com.fuyuanshen.equipment.utils.FileHashUtil;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import com.fuyuanshen.system.domain.vo.SysRoleVo;
|
||||
import com.fuyuanshen.system.service.ISysOssService;
|
||||
import com.fuyuanshen.system.service.ISysRoleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -46,6 +50,8 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
private final DeviceAssignmentsMapper deviceAssignmentsMapper;
|
||||
|
||||
private final ISysRoleService roleService;
|
||||
private final ISysOssService ossService;
|
||||
private final FileHashUtil fileHashUtil;
|
||||
|
||||
|
||||
/**
|
||||
@ -181,24 +187,38 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(DeviceType resources) {
|
||||
public void create(DeviceTypeForm resources) throws IOException {
|
||||
|
||||
// 校验设备类型名称
|
||||
List<DeviceType> typeName = deviceTypeMapper.selectList(new QueryWrapper<DeviceType>().eq("type_name", resources.getTypeName()));
|
||||
if (CollectionUtil.isNotEmpty(typeName)) {
|
||||
throw new RuntimeException("设备类型名称已存在,无法新增!!!");
|
||||
}
|
||||
// 保存图片并获取URL
|
||||
if (resources.getFile() != null) {
|
||||
String fileHash = fileHashUtil.hash(resources.getFile());
|
||||
SysOssVo upload = ossService.updateHash(resources.getFile(), fileHash);
|
||||
// 强制将HTTP替换为HTTPS
|
||||
if (upload.getUrl() != null && upload.getUrl().startsWith("http://")) {
|
||||
upload.setUrl(upload.getUrl().replaceFirst("^http://", "https://"));
|
||||
}
|
||||
// 设置图片路径
|
||||
resources.setDevicePic(upload.getUrl());
|
||||
}
|
||||
|
||||
DeviceType deviceType = new DeviceType();
|
||||
BeanUtil.copyProperties(resources, deviceType, true);
|
||||
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
resources.setCustomerId(loginUser.getUserId());
|
||||
resources.setOwnerCustomerId(loginUser.getUserId());
|
||||
resources.setOriginalOwnerId(loginUser.getUserId());
|
||||
resources.setCreateByName(loginUser.getNickname());
|
||||
deviceTypeMapper.insert(resources);
|
||||
deviceType.setCustomerId(loginUser.getUserId());
|
||||
deviceType.setOwnerCustomerId(loginUser.getUserId());
|
||||
deviceType.setOriginalOwnerId(loginUser.getUserId());
|
||||
deviceType.setCreateByName(loginUser.getNickname());
|
||||
deviceTypeMapper.insert(deviceType);
|
||||
|
||||
// 自动授权给自己
|
||||
DeviceTypeGrants deviceTypeGrants = new DeviceTypeGrants();
|
||||
deviceTypeGrants.setDeviceTypeId(resources.getId());
|
||||
deviceTypeGrants.setDeviceTypeId(deviceType.getId());
|
||||
deviceTypeGrants.setCustomerId(loginUser.getUserId());
|
||||
deviceTypeGrants.setGrantorCustomerId(loginUser.getUserId());
|
||||
deviceTypeGrants.setGrantedAt(new Date());
|
||||
@ -213,7 +233,7 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(DeviceTypeForm resources) {
|
||||
public void update(DeviceTypeForm resources) throws IOException {
|
||||
DeviceTypeGrants deviceTypeGrants = deviceTypeGrantsMapper.selectById(resources.getId());
|
||||
if (deviceTypeGrants == null) {
|
||||
throw new RuntimeException("设备类型不存在");
|
||||
@ -224,22 +244,13 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
throw new RuntimeException("设备类型不存在");
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!deviceType.getTypeName().equals(resources.getTypeName())) {
|
||||
int count = deviceMapper.countByDeviceTypeId(deviceType.getId());
|
||||
if (count > 0) {
|
||||
throw new RuntimeException("该设备类型下已有绑定设备,无法修改设备类型名称!!!");
|
||||
throw new RuntimeException("该设备类型下已有设备,无法修改设备类型名称!!!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// List<Device> devices = deviceMapper.selectList(new QueryWrapper<Device>()
|
||||
// .eq("device_type", deviceTypeGrants.getDeviceTypeId()));
|
||||
// if (CollectionUtil.isNotEmpty(devices)) {
|
||||
// throw new RuntimeException("该设备类型已绑定设备,无法修改!!!");
|
||||
// }
|
||||
|
||||
// 校验设备类型名称
|
||||
DeviceType dt = deviceTypeMapper.selectOne(new QueryWrapper<DeviceType>().eq("type_name", resources.getTypeName()));
|
||||
if (dt != null && !dt.getId().equals(deviceType.getId())) {
|
||||
@ -253,6 +264,17 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
throw new RuntimeException("无权修改该设备类型");
|
||||
}
|
||||
}
|
||||
// 保存图片并获取URL
|
||||
if (resources.getFile() != null) {
|
||||
String fileHash = fileHashUtil.hash(resources.getFile());
|
||||
SysOssVo upload = ossService.updateHash(resources.getFile(), fileHash);
|
||||
// 强制将HTTP替换为HTTPS
|
||||
if (upload.getUrl() != null && upload.getUrl().startsWith("http://")) {
|
||||
upload.setUrl(upload.getUrl().replaceFirst("^http://", "https://"));
|
||||
}
|
||||
// 设置图片路径
|
||||
resources.setDevicePic(upload.getUrl());
|
||||
}
|
||||
|
||||
BeanUtil.copyProperties(resources, deviceType);
|
||||
deviceTypeMapper.updateById(deviceType);
|
||||
|
||||
@ -0,0 +1,404 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
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.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.TrackService;
|
||||
import com.fuyuanshen.equipment.domain.bo.TerminalDelBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.TerminalDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.TerminalQueryBo;
|
||||
import com.fuyuanshen.equipment.domain.bo.TrackServiceBo;
|
||||
import com.fuyuanshen.equipment.domain.dto.TerminalDeviceDto;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.vo.TrackServiceVo;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.TrackServiceMapper;
|
||||
import com.fuyuanshen.equipment.service.ITrackServiceService;
|
||||
import com.fuyuanshen.equipment.utils.map.AmapTrackUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 轨迹服务Service业务层处理
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-11-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class TrackServiceServiceImpl implements ITrackServiceService {
|
||||
|
||||
private final TrackServiceMapper baseMapper;
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final AmapTrackUtil amapTrackUtil;
|
||||
|
||||
/**
|
||||
* 查询轨迹服务
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 轨迹服务
|
||||
*/
|
||||
@Override
|
||||
public TrackServiceVo queryById(Long id){
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询轨迹服务列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param pageQuery 分页参数
|
||||
* @return 轨迹服务分页列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<TrackServiceVo> queryPageList(TrackServiceBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<TrackService> lqw = buildQueryWrapper(bo);
|
||||
Page<TrackServiceVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询符合条件的轨迹服务列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return 轨迹服务列表
|
||||
*/
|
||||
@Override
|
||||
public List<TrackServiceVo> queryList(TrackServiceBo bo) {
|
||||
LambdaQueryWrapper<TrackService> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<TrackService> buildQueryWrapper(TrackServiceBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<TrackService> lqw = Wrappers.lambdaQuery();
|
||||
lqw.orderByAsc(TrackService::getId);
|
||||
lqw.eq(bo.getSid() != null, TrackService::getSid, bo.getSid());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getSname()), TrackService::getSname, bo.getSname());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增轨迹服务
|
||||
*
|
||||
* @param bo 轨迹服务
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(TrackServiceBo bo) {
|
||||
TrackService add = MapstructUtils.convert(bo, TrackService.class);
|
||||
validEntityBeforeSave(add);
|
||||
/* 1. 先查高德侧是否已存在同名服务 */
|
||||
JSONObject listResult = amapTrackUtil.listService();
|
||||
if (listResult == null || listResult.getInt("errcode") != 10000) {
|
||||
throw new RuntimeException("查询高德轨迹服务列表失败");
|
||||
}
|
||||
log.warn("查询: {}", listResult);
|
||||
String serviceName = add.getSname();
|
||||
String sid = null;
|
||||
|
||||
// 取 data 数组,遍历匹配 name
|
||||
JSONArray serviceArray = listResult.getByPath("data.results", JSONArray.class);
|
||||
if (serviceArray != null) {
|
||||
for (int i = 0; i < serviceArray.size(); i++) {
|
||||
JSONObject item = serviceArray.getJSONObject(i);
|
||||
if (serviceName.equals(item.getStr("name"))) {
|
||||
sid = item.getStr("sid"); // 已存在,直接复用
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 2. 不存在才创建 */
|
||||
if (sid == null) {
|
||||
JSONObject createResult = amapTrackUtil.createService(serviceName);
|
||||
if (createResult == null || createResult.getInt("errcode") != 10000) {
|
||||
throw new RuntimeException("生成高德轨迹服务失败");
|
||||
}
|
||||
sid = createResult.getByPath("data.sid", String.class);
|
||||
}
|
||||
|
||||
add.setSid(Long.valueOf(sid));
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改轨迹服务
|
||||
*
|
||||
* @param bo 轨迹服务
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(TrackServiceBo bo) {
|
||||
TrackService update = MapstructUtils.convert(bo, TrackService.class);
|
||||
validEntityBeforeSave(update);
|
||||
if(update.getId() == null) {
|
||||
throw new RuntimeException("轨迹服务ID不能为空");
|
||||
}
|
||||
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(TrackService entity){
|
||||
if(entity == null) {
|
||||
throw new RuntimeException("请输入信息");
|
||||
}
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
if(!StringUtils.isNotEmpty(entity.getSname())) {
|
||||
throw new RuntimeException("轨迹服务名称不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验并批量删除轨迹服务信息
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean delTerminalDevice(Collection<Long> ids, Boolean isValid) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
throw new IllegalArgumentException("请选择要移除的设备");
|
||||
}
|
||||
|
||||
// 1. 批量查询(一次 SQL,性能提升 10 倍+)
|
||||
List<Device> deviceList = deviceMapper.selectList(
|
||||
new LambdaQueryWrapper<Device>()
|
||||
.in(Device::getId, ids)
|
||||
.select(Device::getId, Device::getSid, Device::getTid, Device::getTrid)
|
||||
);
|
||||
|
||||
if (CollectionUtils.isEmpty(deviceList)) {
|
||||
log.info("未找到要移除的设备,ids={}", ids);
|
||||
return true; // 幂等:没找到也算成功
|
||||
}
|
||||
|
||||
// 2. 业务校验(可插拔)
|
||||
if (isValid) {
|
||||
validateBeforeDelete(deviceList); // 你自己实现具体校验逻辑
|
||||
}
|
||||
|
||||
// 3. 批量清理高德资源 + 本地数据(精准对应,顺序正确)
|
||||
for (Device device : deviceList) {
|
||||
Long sid = device.getSid();
|
||||
Long tid = device.getTid();
|
||||
Long trid = device.getTrid();
|
||||
|
||||
if (sid == null) {
|
||||
log.warn("设备无高德服务ID,跳过高德清理,deviceId={}", device.getId());
|
||||
continue;
|
||||
}
|
||||
|
||||
// 先删轨迹(必须 tid + trid),再删终端(只需 tid)
|
||||
if (trid != null && tid != null) {
|
||||
safeDeleteTrack(sid, tid, trid);
|
||||
}
|
||||
if (tid != null) {
|
||||
safeDeleteTerminal(sid, tid);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 批量更新数据库(性能极高,避免 N+1 update)
|
||||
int updated = deviceMapper.update(null,
|
||||
new LambdaUpdateWrapper<Device>()
|
||||
.in(Device::getId, ids)
|
||||
.set(Device::getTid, null)
|
||||
.set(Device::getTrid, null)
|
||||
.set(Device::getSid, null)
|
||||
);
|
||||
|
||||
log.info("成功解绑高德终端,设备数量={},实际更新记录数={}", deviceList.size(), updated);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delTerminalDevice(TerminalDelBo bo, Boolean isValid) {
|
||||
var list = deviceMapper.selectList(new LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getSid, bo.getSid())
|
||||
.eq(Device::getTid, bo.getTid()));
|
||||
if (list.isEmpty()) {
|
||||
throw new IllegalArgumentException("本地设备已绑定不允许删除");
|
||||
}
|
||||
// 先删轨迹(必须 tid + trid),再删终端(只需 tid)
|
||||
if (bo.getSid() != null && bo.getTid() != null) {
|
||||
safeDeleteTrack(bo.getSid(), bo.getTid(), bo.getTrid());
|
||||
}
|
||||
if (bo.getTid() != null) {
|
||||
safeDeleteTerminal(bo.getSid(),bo.getTid());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询终端列表
|
||||
*
|
||||
* @param bo 查询参数
|
||||
* @return 终端列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<TerminalDeviceDto> listTerminal(TerminalQueryBo bo) {
|
||||
JSONObject terminalRes = amapTrackUtil.listTerminal(bo.getSid(), bo.getTid(), bo.getName(), bo.getPage());
|
||||
List<TerminalDeviceDto> list = terminalRes.getByPath("data.results", JSONArray.class)
|
||||
.toList(TerminalDeviceDto.class);
|
||||
Integer count = terminalRes.getByPath("data.count", Integer.class);
|
||||
return new TableDataInfo<TerminalDeviceDto>(list, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索终端列表
|
||||
*
|
||||
* @param bo 搜索参数
|
||||
* @return 终端列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<TerminalDeviceDto> searchTerminal(TerminalQueryBo bo) {
|
||||
JSONObject terminalRes = amapTrackUtil.searchTerminal(bo.getSid(), bo.getKeywords(), bo.getPage(), bo.getPagesize());
|
||||
log.info("终端列表:{}", terminalRes);
|
||||
List<TerminalDeviceDto> list = terminalRes.getByPath("data.results", JSONArray.class)
|
||||
.toList(TerminalDeviceDto.class);
|
||||
Integer count = terminalRes.getByPath("data.count", Integer.class);
|
||||
return new TableDataInfo<TerminalDeviceDto>(list, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务校验钩子
|
||||
*/
|
||||
private void validateBeforeDelete(List<Device> deviceList) {
|
||||
// 示例:校验设备是否在线、是否有未完成订单等
|
||||
// throw new BusinessException("xxx设备正在使用中,不能解绑");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void terminal(TerminalDeviceBo bo) {
|
||||
if (bo.getSid() == null) {
|
||||
throw new IllegalArgumentException("高德服务ID不能为空");
|
||||
}
|
||||
if (CollectionUtils.isEmpty(bo.getDeviceList())) {
|
||||
throw new IllegalArgumentException("请选择设备");
|
||||
}
|
||||
|
||||
Long sid = bo.getSid();
|
||||
|
||||
// 使用对象封装,便于补偿时知道 tid 和 trid 的对应关系(关键!)
|
||||
class CreatedResource {
|
||||
Long tid;
|
||||
Long trid;
|
||||
}
|
||||
List<CreatedResource> createdResources = new ArrayList<>();
|
||||
|
||||
try {
|
||||
for (DeviceForm form : bo.getDeviceList()) {
|
||||
String terminalName = String.format("%s_%s", form.getTypeName(), form.getDeviceImei());
|
||||
|
||||
// Step 1: 创建终端
|
||||
JSONObject terminalRes = amapTrackUtil.createTerminal(sid, terminalName);
|
||||
if (!isSuccess(terminalRes)) {
|
||||
throw new RuntimeException("创建设备终端失败:" + terminalRes);
|
||||
}
|
||||
Long tid = terminalRes.getByPath("data.tid", Long.class);
|
||||
|
||||
// Step 2: 创建轨迹
|
||||
JSONObject trackRes = amapTrackUtil.createTrace(sid, tid);
|
||||
if (!isSuccess(trackRes)) {
|
||||
throw new RuntimeException("创建轨迹失败:" + trackRes);
|
||||
}
|
||||
Long trid = trackRes.getByPath("data.trid", Long.class);
|
||||
|
||||
// 3. 更新本地设备
|
||||
Device device = new Device();
|
||||
device.setId(form.getId());
|
||||
device.setTid(tid);
|
||||
device.setTrid(trid);
|
||||
device.setSid(sid);
|
||||
deviceMapper.updateById(device);
|
||||
|
||||
// 记录本次创建的资源(用于精确补偿)
|
||||
CreatedResource resource = new CreatedResource();
|
||||
resource.tid = tid;
|
||||
resource.trid = trid;
|
||||
createdResources.add(resource);
|
||||
|
||||
// 可落盘日志(用于极端情况人工排查)
|
||||
log.warn("高德添加设备终端 sid={} tid={} trid={} deviceId={}",
|
||||
sid, tid, trid, form.getId());
|
||||
}
|
||||
|
||||
// 全部成功 → 清空内存集合
|
||||
createdResources.clear();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("绑定高德终端失败,正在执行补偿清理,已创建资源数={}", createdResources.size(), e);
|
||||
|
||||
// 精确补偿:先删轨迹(需要 sid + tid + trid),再删终端(需要 sid + tid)
|
||||
for (CreatedResource r : createdResources) {
|
||||
if (r.trid != null) {
|
||||
safeDeleteTrack(sid, r.tid, r.trid); // 现在传 3 个参数
|
||||
}
|
||||
if (r.tid != null) {
|
||||
safeDeleteTerminal(sid, r.tid);
|
||||
}
|
||||
}
|
||||
|
||||
throw e; // 抛异常让调用方知道失败
|
||||
}
|
||||
}
|
||||
|
||||
/** 安全删除轨迹 */
|
||||
private void safeDeleteTrack(Long sid, Long tid, Long trid) {
|
||||
try {
|
||||
// 假设你的工具方法是这样定义的:
|
||||
// amapTrackUtil.deleteTrack(sid, tid, trid);
|
||||
amapTrackUtil.deleteTrace(sid, tid, trid);
|
||||
log.info("补偿删除轨迹成功 sid={} tid={} trid={}", sid, tid, trid);
|
||||
} catch (Exception ex) {
|
||||
log.error("补偿删除轨迹失败 sid={} tid={} trid={},请人工介入或等定时任务处理", sid, tid, trid, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/** 安全删除终端 */
|
||||
private void safeDeleteTerminal(Long sid, Long tid) {
|
||||
try {
|
||||
amapTrackUtil.deleteTerminal(sid, tid);
|
||||
log.info("补偿删除终端成功 sid={} tid={}", sid, tid);
|
||||
} catch (Exception ex) {
|
||||
log.error("补偿删除终端失败 sid={} tid={},请人工介入或等定时任务处理", sid, tid, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSuccess(JSONObject json) {
|
||||
return json != null && Objects.equals(json.getInt("errcode"), 10000);
|
||||
}
|
||||
}
|
||||
@ -30,27 +30,45 @@ import static cn.dev33.satoken.SaManager.log;
|
||||
@Component
|
||||
public class AlibabaTTSUtil {
|
||||
// ========== 常量配置 ==========
|
||||
/** 阿里云TTS服务基础URL */
|
||||
/**
|
||||
* 阿里云TTS服务基础URL
|
||||
*/
|
||||
private static final String BASE_URL = "https://nls-gateway-cn-shanghai.aliyuncs.com/stream/v1/tts";
|
||||
/** 音频内容类型标识 */
|
||||
/**
|
||||
* 音频内容类型标识
|
||||
*/
|
||||
private static final String CONTENT_TYPE_AUDIO = "audio/mpeg";
|
||||
|
||||
// ========== 默认参数值 ==========
|
||||
/** 默认发音人 - 小云 */
|
||||
/**
|
||||
* 默认发音人 - 小云
|
||||
*/
|
||||
private static final String DEFAULT_VOICE = "xiaoyun";
|
||||
/** 默认音量 50% */
|
||||
/**
|
||||
* 默认音量 50%
|
||||
*/
|
||||
private static final int DEFAULT_VOLUME = 50;
|
||||
/** 默认语速 0(正常) */
|
||||
/**
|
||||
* 默认语速 0(正常)
|
||||
*/
|
||||
private static final int DEFAULT_SPEECH_RATE = 1;
|
||||
/** 默认语调 0(正常) */
|
||||
/**
|
||||
* 默认语调 0(正常)
|
||||
*/
|
||||
private static final int DEFAULT_PITCH_RATE = 0;
|
||||
/** 默认音频格式 pcm */
|
||||
/**
|
||||
* 默认音频格式 pcm
|
||||
*/
|
||||
private static final String DEFAULT_FORMAT = "pcm";
|
||||
/** 默认采样率 16000Hz */
|
||||
/**
|
||||
* 默认采样率 16000Hz
|
||||
*/
|
||||
private static final int DEFAULT_SAMPLE_RATE = 16000;
|
||||
|
||||
// ========== Token管理配置 ==========
|
||||
/** Token刷新缓冲时间(提前5分钟刷新,单位:毫秒) */
|
||||
/**
|
||||
* Token刷新缓冲时间(提前5分钟刷新,单位:毫秒)
|
||||
*/
|
||||
private static final long TOKEN_REFRESH_BUFFER = 5 * 60 * 1000L;
|
||||
|
||||
// ========== 配置参数(从配置文件读取) ==========
|
||||
@ -70,6 +88,7 @@ public class AlibabaTTSUtil {
|
||||
|
||||
/**
|
||||
* 生成语音文件 - 简化版(使用默认参数)
|
||||
*
|
||||
* @param text 要转换的文本内容
|
||||
* @param audioSaveFile 音频文件保存路径
|
||||
* @return true-成功 false-失败
|
||||
@ -80,6 +99,7 @@ public class AlibabaTTSUtil {
|
||||
|
||||
/**
|
||||
* 生成语音文件 - 标准版
|
||||
*
|
||||
* @param text 要转换的文本内容
|
||||
* @param audioSaveFile 音频文件保存路径
|
||||
* @param format 音频格式(如:mp3, wav等)
|
||||
@ -95,6 +115,7 @@ public class AlibabaTTSUtil {
|
||||
|
||||
/**
|
||||
* 生成语音文件 - 完整版(支持所有参数调节)
|
||||
*
|
||||
* @param text 要转换的文本内容
|
||||
* @param audioSaveFile 音频文件保存路径
|
||||
* @param format 音频格式
|
||||
@ -158,6 +179,7 @@ public class AlibabaTTSUtil {
|
||||
|
||||
/**
|
||||
* 获取有效的访问令牌(优先从缓存获取,缓存不存在则重新生成)
|
||||
*
|
||||
* @return 访问令牌,获取失败返回null
|
||||
*/
|
||||
private String getValidAccessToken() {
|
||||
@ -181,6 +203,7 @@ public class AlibabaTTSUtil {
|
||||
|
||||
/**
|
||||
* 刷新访问令牌(调用阿里云API获取新令牌并缓存)
|
||||
*
|
||||
* @return 新的访问令牌,获取失败返回null
|
||||
*/
|
||||
private String refreshAccessToken() {
|
||||
@ -202,6 +225,7 @@ public class AlibabaTTSUtil {
|
||||
|
||||
/**
|
||||
* 参数验证
|
||||
*
|
||||
* @throws IllegalArgumentException 参数不合法时抛出异常
|
||||
*/
|
||||
private void validateParameters(String text, String audioSaveFile, String format, int sampleRate) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user