Compare commits
114 Commits
630c6a8a35
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d58268874 | |||
| 56dbfbde71 | |||
| 77626673e9 | |||
| 1be80be309 | |||
| 92df1c8668 | |||
| cc2b7664a8 | |||
| 33d6108172 | |||
| ee85961eeb | |||
| 004079f7f4 | |||
| 264d0135d9 | |||
| 4961ec47f8 | |||
| f25afe0e9d | |||
| e265dea0ec | |||
| c7ff118bfe | |||
| 1dc3386284 | |||
| c4957aa3aa | |||
| 07e60cf7f0 | |||
| 5d42f8a1e1 | |||
| f2a5e63a41 | |||
| 467a7befb1 | |||
| 107ddf8851 | |||
| a85e74c5e6 | |||
| 9bbddee1d5 | |||
| da0833a400 | |||
| 418fb55bf0 | |||
| 1d50981a84 | |||
| 2f80c450c5 | |||
| 09cbdf267b | |||
| 156fdbb53b | |||
| 3246127893 | |||
| dab0440128 | |||
| 740a638444 | |||
| a3d44a157a | |||
| cc23f082a6 | |||
| 1bc7dc676e | |||
| 5cdacad468 | |||
| 62af38cbf0 | |||
| 04a21567aa | |||
| 5b4fa38dbd | |||
| 2c3effa683 | |||
| 7b8c626cb6 | |||
| 9642908035 | |||
| 85b2e2b976 | |||
| 88ac0236bd | |||
| 609a3e4058 | |||
| 68cf78f3f2 | |||
| c9857a679c | |||
| 6439a96e3d | |||
| 9f0155a6e3 | |||
| 6c99cef65d | |||
| 840c4fd68f | |||
| dc0fe96652 | |||
| cf883bfa00 | |||
| 6a6397da23 | |||
| d701a834b3 | |||
| e1ac87e5f2 | |||
| 5c3a35c83e | |||
| 2c0eff2b2c | |||
| 37e07d2706 | |||
| 5c0c4e40e4 | |||
| eceedae676 | |||
| dfa5b446f9 | |||
| 9afc0222d5 | |||
| 2cfcea65f1 | |||
| 9b72a6ebd2 | |||
| 13db094336 | |||
| a1d6604520 | |||
| b0e51e73c7 | |||
| dba537b83f | |||
| d9b69ddc4e | |||
| 6cec86bafe | |||
| 608aa8449a | |||
| 6084f11e62 | |||
| 994e63bcde | |||
| d6520d777a | |||
| 1898fe5db9 | |||
| 7d56e2e80e | |||
| 233e0e32b0 | |||
| cb2acdb3f4 | |||
| a4596b9c90 | |||
| 5230a95865 | |||
| 4d2b7c6adf | |||
| 461fd9364c | |||
| ad81647939 | |||
| 2d59397de5 | |||
| b7c81419a4 | |||
| 3859c20081 | |||
| 3bdabb04e2 | |||
| e124694e67 | |||
| e528cd04e9 | |||
| 735199b9e0 | |||
| a69c665d8b | |||
| 5a52129fd0 | |||
| 7eb5e6095a | |||
| 91f0241181 | |||
| baa341c2bf | |||
| 9c98fa9077 | |||
| 89f08c2d91 | |||
| 135e6d6899 | |||
| 49e9066033 | |||
| e2821566c8 | |||
| 5b3a92c80d | |||
| 9d642f4913 | |||
| f07ec53645 | |||
| 74b0059aca | |||
| 8e66f1ca28 | |||
| 1b33356a2a | |||
| 5f36c25550 | |||
| 9058dcfcb1 | |||
| 3e19cd9db2 | |||
| 397f227bfb | |||
| 1b2bf542fa | |||
| 7d4bc1f8ad | |||
| 4d9038567f |
@ -123,6 +123,17 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bytedeco</groupId>
|
||||
<artifactId>javacv-platform</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bytedeco</groupId>
|
||||
<artifactId>javacv</artifactId>
|
||||
<version>1.5.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- skywalking 整合 logback -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.skywalking</groupId>-->
|
||||
|
||||
@ -1,22 +1,24 @@
|
||||
package com.fuyuanshen;
|
||||
package com.fuyuanshen;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class DromaraApplication {
|
||||
/**
|
||||
* 启动程序
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class DromaraApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication application = new SpringApplication(DromaraApplication.class);
|
||||
application.setApplicationStartup(new BufferingApplicationStartup(2048));
|
||||
application.run(args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ fys-Vue-Plus启动成功 ლ(´ڡ`ლ)゙");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication application = new SpringApplication(DromaraApplication.class);
|
||||
application.setApplicationStartup(new BufferingApplicationStartup(2048));
|
||||
application.run(args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ fys-Vue-Plus启动成功 ლ(´ڡ`ლ)゙");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fuyuanshen.app.model.AppRegisterBody;
|
||||
import com.fuyuanshen.app.model.AppSmsLoginBody;
|
||||
import com.fuyuanshen.app.service.AppLoginService;
|
||||
@ -26,10 +27,13 @@ import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.common.tenant.helper.TenantHelper;
|
||||
import com.fuyuanshen.system.domain.bo.SysTenantBo;
|
||||
import com.fuyuanshen.system.domain.vo.SysClientVo;
|
||||
import com.fuyuanshen.system.domain.vo.SysDictDataVo;
|
||||
import com.fuyuanshen.system.domain.vo.SysTenantVo;
|
||||
import com.fuyuanshen.system.service.ISysClientService;
|
||||
import com.fuyuanshen.system.service.ISysConfigService;
|
||||
import com.fuyuanshen.system.service.ISysDictTypeService;
|
||||
import com.fuyuanshen.system.service.ISysTenantService;
|
||||
import com.fuyuanshen.web.domain.Dto.SystemVersionDto;
|
||||
import com.fuyuanshen.web.domain.vo.LoginTenantVo;
|
||||
import com.fuyuanshen.web.domain.vo.LoginVo;
|
||||
import com.fuyuanshen.web.domain.vo.TenantListVo;
|
||||
@ -48,9 +52,11 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.DEVICE_SHARE_CODES_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
|
||||
/**
|
||||
* APP认证
|
||||
@ -66,7 +72,6 @@ public class AppAuthController {
|
||||
|
||||
private final AppLoginService loginService;
|
||||
private final AppRegisterService registerService;
|
||||
private final ISysConfigService configService;
|
||||
private final ISysTenantService tenantService;
|
||||
private final ISysClientService clientService;
|
||||
|
||||
@ -252,4 +257,20 @@ public class AppAuthController {
|
||||
SmsResponse smsResponse = smsBlend.sendMessage("18656573389", "123");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取app版本
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/version")
|
||||
public R<List<SystemVersionDto>> getAppVersion() {
|
||||
String versionKey = GLOBAL_REDIS_KEY + "System:Version:Xinghan";
|
||||
// 缓存告警消息到Redis
|
||||
String versionJson = RedisUtils.getCacheObject(versionKey);
|
||||
if (StringUtils.isBlank(versionJson)) { // hutool 工具,可用 StringUtils.isBlank 代替
|
||||
return R.fail(versionJson);
|
||||
}
|
||||
List<SystemVersionDto> list = JSON.parseArray(versionJson, SystemVersionDto.class);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
||||
@ -53,7 +54,8 @@ public class AppDeviceController extends BaseController {
|
||||
*/
|
||||
@DeleteMapping("/unBind")
|
||||
public R<Void> unBind(Long id) {
|
||||
return toAjax(appDeviceService.unBindDevice(id));
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
return toAjax(appDeviceService.unBindDevice(id,userId,0));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,4 +92,5 @@ public class AppDeviceController extends BaseController {
|
||||
public R<AppDeviceVo> getDeviceInfo(String deviceMac) {
|
||||
return R.ok(appDeviceService.getDeviceInfo(deviceMac));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -44,10 +44,9 @@ import static com.fuyuanshen.common.core.constant.GlobalConstants.DEVICE_SHARE_C
|
||||
@RequestMapping("/app/deviceShare")
|
||||
public class AppDeviceShareController extends BaseController {
|
||||
|
||||
private final IAppDeviceShareService deviceShareService;
|
||||
|
||||
private final AppDeviceShareService appDeviceShareService;
|
||||
|
||||
|
||||
/**
|
||||
* 分享管理列表
|
||||
*/
|
||||
@ -95,6 +94,7 @@ public class AppDeviceShareController extends BaseController {
|
||||
return toAjax(appDeviceShareService.remove(ids));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 短信验证码
|
||||
*
|
||||
@ -116,4 +116,5 @@ public class AppDeviceShareController extends BaseController {
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ public class AppFileController extends BaseController {
|
||||
|
||||
private final AppFileService appFileService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询文件列表
|
||||
*/
|
||||
@ -33,6 +34,7 @@ public class AppFileController extends BaseController {
|
||||
return R.ok(appFileService.list(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*/
|
||||
@ -52,4 +54,5 @@ public class AppFileController extends BaseController {
|
||||
}
|
||||
return toAjax(appFileService.delete(ids));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ public class AppOperationVideoController extends BaseController {
|
||||
|
||||
private final IAppOperationVideoService appOperationVideoService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询操作视频列表
|
||||
*/
|
||||
@ -68,4 +69,5 @@ public class AppOperationVideoController extends BaseController {
|
||||
public R<Void> deleteOperationVideo(@PathVariable Long id) {
|
||||
return toAjax(appOperationVideoService.deleteWithValidByIds(List.of(id), true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.fuyuanshen.app.controller;
|
||||
|
||||
import com.fuyuanshen.app.model.AppRegisterBody;
|
||||
import com.fuyuanshen.app.model.AppUpdatePasswordBody;
|
||||
import com.fuyuanshen.app.service.AppLoginService;
|
||||
import com.fuyuanshen.app.service.AppRegisterService;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
@ -38,7 +39,7 @@ public class AppUserCenterController {
|
||||
* 修改密码
|
||||
*/
|
||||
@PostMapping("/updatePassword")
|
||||
public R<Void> updatePassword(@Validated @RequestBody AppRegisterBody body) {
|
||||
public R<Void> updatePassword(@Validated @RequestBody AppUpdatePasswordBody body) {
|
||||
registerService.updatePassword(body);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@ -0,0 +1,64 @@
|
||||
package com.fuyuanshen.app.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import com.fuyuanshen.app.service.AudioProcessService;
|
||||
import com.fuyuanshen.app.service.VideoProcessService;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* APP 视频处理控制器
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/app/video")
|
||||
public class AppVideoController extends BaseController {
|
||||
|
||||
private final VideoProcessService videoProcessService;
|
||||
private final AudioProcessService audioProcessService;
|
||||
|
||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<List<String>> uploadVideo(@RequestParam("file") MultipartFile file) {
|
||||
return R.ok(videoProcessService.processVideo(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传音频文件并转码
|
||||
*/
|
||||
@PostMapping(value = "/audio", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<List<String>> uploadAudio(@RequestParam("file") MultipartFile file) {
|
||||
return R.ok(audioProcessService.processAudio(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字转音频TTS服务
|
||||
*/
|
||||
@GetMapping("/audioTTS")
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<List<String>> uploadAudioTTS(@RequestParam String text) throws IOException {
|
||||
return R.ok(audioProcessService.generateStandardPcmData(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取文本内容(只支持txt/docx)
|
||||
*/
|
||||
@PostMapping(value = "/extract", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<String> extract(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
return R.ok("Success",audioProcessService.extract(file));
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@ import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
@ -17,6 +18,8 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* BJQ6170设备控制类
|
||||
*/
|
||||
@ -28,6 +31,7 @@ public class AppDeviceBJQController extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
@ -82,6 +86,7 @@ public class AppDeviceBJQController extends BaseController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
||||
|
||||
@ -28,6 +28,7 @@ public class AppDeviceHBYController extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
|
||||
@ -9,14 +9,24 @@ import com.fuyuanshen.common.log.annotation.Log;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.customer.mapper.CustomerMapper;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import com.fuyuanshen.equipment.service.DeviceTypeService;
|
||||
import com.fuyuanshen.web.domain.Dto.DeviceXinghanInstructDto;
|
||||
import com.fuyuanshen.web.service.device.DeviceBJQBizService;
|
||||
import com.fuyuanshen.web.service.device.DeviceXinghanBizService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* HBY670设备控制类
|
||||
*/
|
||||
@ -27,6 +37,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
public class AppDeviceXinghanController extends BaseController {
|
||||
|
||||
private final DeviceXinghanBizService appDeviceService;
|
||||
private final DeviceService deviceService;
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
@ -70,7 +81,7 @@ public class AppDeviceXinghanController extends BaseController {
|
||||
*/
|
||||
@Log(title = "xinghan指令-静电预警档位")
|
||||
@PostMapping("/DetectGradeSettings")
|
||||
public R<Void> DetectGradeSettings(@RequestBody DeviceInstructDto params) {
|
||||
public R<Void> DetectGradeSettings(@RequestBody DeviceXinghanInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.upDetectGradeSettings(params);
|
||||
return R.ok();
|
||||
@ -82,7 +93,7 @@ public class AppDeviceXinghanController extends BaseController {
|
||||
*/
|
||||
@Log(title = "xinghan指令-照明档位")
|
||||
@PostMapping("/LightGradeSettings")
|
||||
public R<Void> LightGradeSettings(@RequestBody DeviceInstructDto params) {
|
||||
public R<Void> LightGradeSettings(@RequestBody DeviceXinghanInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.upLightGradeSettings(params);
|
||||
return R.ok();
|
||||
@ -94,7 +105,7 @@ public class AppDeviceXinghanController extends BaseController {
|
||||
*/
|
||||
@Log(title = "xinghan指令-SOS档位s")
|
||||
@PostMapping("/SOSGradeSettings")
|
||||
public R<Void> SOSGradeSettings(@RequestBody DeviceInstructDto params) {
|
||||
public R<Void> SOSGradeSettings(@RequestBody DeviceXinghanInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.upSOSGradeSettings(params);
|
||||
return R.ok();
|
||||
@ -106,10 +117,29 @@ public class AppDeviceXinghanController extends BaseController {
|
||||
*/
|
||||
@Log(title = "xinghan指令-静止报警状态")
|
||||
@PostMapping("/ShakeBitSettings")
|
||||
public R<Void> ShakeBitSettings(@RequestBody DeviceInstructDto params) {
|
||||
public R<Void> ShakeBitSettings(@RequestBody DeviceXinghanInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.upShakeBitSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/typeAll")
|
||||
@Operation(summary = "查询所有设备类型")
|
||||
public R<List<DeviceType>> queryDeviceTypes() {
|
||||
List<DeviceType> deviceTypes = appDeviceService.queryDeviceTypes();
|
||||
return R.ok(deviceTypes);
|
||||
}
|
||||
|
||||
// @Log("新增设备")
|
||||
@Operation(summary = "新增设备")
|
||||
@PostMapping(value = "/add")
|
||||
public R<Void> addDevice(@RequestBody DeviceForm deviceForm) {
|
||||
try {
|
||||
appDeviceService.addDevice(deviceForm);
|
||||
} catch (Exception e) {
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ public class TestController extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 上传设备logo图片
|
||||
*/
|
||||
|
||||
@ -0,0 +1,156 @@
|
||||
package com.fuyuanshen.app.controller.device.bjq;
|
||||
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDevice6075DetailVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* BJQ6075 设备控制类
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/app/bjq6075/device")
|
||||
public class AppDeviceBJQ6075Controller extends BaseController {
|
||||
|
||||
private final DeviceBJQ6075BizService appDeviceService6075;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDevice6075DetailVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService6075.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记 1
|
||||
*/
|
||||
@PostMapping(value = "/registerPersonInfo")
|
||||
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
|
||||
return toAjax(appDeviceService6075.registerPersonInfo(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送信息 2
|
||||
*/
|
||||
@PostMapping(value = "/sendMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
|
||||
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService6075.sendMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送报警信息 3
|
||||
*/
|
||||
@PostMapping(value = "/sendAlarmMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
|
||||
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService6075.sendAlarmMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传设备logo图片 4
|
||||
*/
|
||||
@PostMapping("/uploadLogo")
|
||||
@FunctionAccessAnnotation("uploadLogo")
|
||||
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService6075.uploadDeviceLogo(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光模式 5
|
||||
* (主光模式)
|
||||
* 0(关闭灯光),1(强光),2(超强光), 3(工作光), 4(节能光),5(爆闪),6(SOS)
|
||||
*/
|
||||
@PostMapping("/lightModeSettings")
|
||||
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.lightModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光模式 6
|
||||
* (辅光模式)
|
||||
* 0(关闭灯光),1(泛光),2(泛光爆闪), 3(警示灯), 4(警示灯/泛光)
|
||||
*/
|
||||
@PostMapping("/auxiliaryLightModeSettings")
|
||||
public R<Void> auxiliaryLightModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.lightModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光亮度设置 7
|
||||
*/
|
||||
@PostMapping("/lightBrightnessSettings")
|
||||
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.lightBrightnessSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 激光模式设置 8
|
||||
*/
|
||||
@PostMapping("/laserModeSettings")
|
||||
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.laserModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 声光报警模式设置 9
|
||||
* Sound and light alarm
|
||||
*/
|
||||
@PostMapping("/salaModeSettings")
|
||||
public R<Void> salaModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.laserModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备分享详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/getShareInfo/{id}")
|
||||
public R<AppDevice6075DetailVo> getShareInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService6075.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,155 @@
|
||||
package com.fuyuanshen.app.controller.device.bjq;
|
||||
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDevice6075DetailVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* BJQ6331便携式工作灯
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/app/BJQ6331/device")
|
||||
public class AppDeviceBJQ6331Controller extends BaseController {
|
||||
|
||||
private final DeviceBJQ6075BizService appDeviceService6075;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDevice6075DetailVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
return R.ok(appDeviceService6075.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记 1
|
||||
*/
|
||||
@PostMapping(value = "/registerPersonInfo")
|
||||
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
|
||||
return toAjax(appDeviceService6075.registerPersonInfo(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送信息 2
|
||||
*/
|
||||
@PostMapping(value = "/sendMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
|
||||
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService6075.sendMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送报警信息 3
|
||||
*/
|
||||
@PostMapping(value = "/sendAlarmMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
|
||||
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService6075.sendAlarmMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传设备logo图片 4
|
||||
*/
|
||||
@PostMapping("/uploadLogo")
|
||||
@FunctionAccessAnnotation("uploadLogo")
|
||||
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService6075.uploadDeviceLogo(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光模式 5
|
||||
* (主光模式)
|
||||
* 0(关闭灯光),1(强光),2(超强光), 3(工作光), 4(节能光),5(爆闪),6(SOS)
|
||||
*/
|
||||
@PostMapping("/lightModeSettings")
|
||||
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.lightModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光模式 6
|
||||
* (辅光模式)
|
||||
* 0(关闭灯光),1(泛光),2(泛光爆闪), 3(警示灯), 4(警示灯/泛光)
|
||||
*/
|
||||
@PostMapping("/auxiliaryLightModeSettings")
|
||||
public R<Void> auxiliaryLightModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.lightModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光亮度设置 7
|
||||
*/
|
||||
@PostMapping("/lightBrightnessSettings")
|
||||
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.lightBrightnessSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 激光模式设置 8
|
||||
*/
|
||||
@PostMapping("/laserModeSettings")
|
||||
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.laserModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 声光报警模式设置 9
|
||||
* Sound and light alarm
|
||||
*/
|
||||
@PostMapping("/salaModeSettings")
|
||||
public R<Void> salaModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.laserModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备分享详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/getShareInfo/{id}")
|
||||
public R<AppDevice6075DetailVo> getShareInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService6075.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,156 @@
|
||||
package com.fuyuanshen.app.controller.device.bjq;
|
||||
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDevice6075DetailVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* HBY335(LED救生照明线)
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/app/HBY335/device")
|
||||
public class AppDeviceHBY335Controller extends BaseController {
|
||||
|
||||
private final DeviceBJQ6075BizService appDeviceService6075;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDevice6075DetailVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService6075.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记 1
|
||||
*/
|
||||
@PostMapping(value = "/registerPersonInfo")
|
||||
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
|
||||
return toAjax(appDeviceService6075.registerPersonInfo(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送信息 2
|
||||
*/
|
||||
@PostMapping(value = "/sendMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
|
||||
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService6075.sendMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送报警信息 3
|
||||
*/
|
||||
@PostMapping(value = "/sendAlarmMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
|
||||
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService6075.sendAlarmMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传设备logo图片 4
|
||||
*/
|
||||
@PostMapping("/uploadLogo")
|
||||
@FunctionAccessAnnotation("uploadLogo")
|
||||
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService6075.uploadDeviceLogo(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光模式 5
|
||||
* (主光模式)
|
||||
* 0(关闭灯光),1(强光),2(超强光), 3(工作光), 4(节能光),5(爆闪),6(SOS)
|
||||
*/
|
||||
@PostMapping("/lightModeSettings")
|
||||
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.lightModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光模式 6
|
||||
* (辅光模式)
|
||||
* 0(关闭灯光),1(泛光),2(泛光爆闪), 3(警示灯), 4(警示灯/泛光)
|
||||
*/
|
||||
@PostMapping("/auxiliaryLightModeSettings")
|
||||
public R<Void> auxiliaryLightModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.lightModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光亮度设置 7
|
||||
*/
|
||||
@PostMapping("/lightBrightnessSettings")
|
||||
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.lightBrightnessSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 激光模式设置 8
|
||||
*/
|
||||
@PostMapping("/laserModeSettings")
|
||||
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.laserModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 声光报警模式设置 9
|
||||
* Sound and light alarm
|
||||
*/
|
||||
@PostMapping("/salaModeSettings")
|
||||
public R<Void> salaModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService6075.laserModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备分享详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/getShareInfo/{id}")
|
||||
public R<AppDevice6075DetailVo> getShareInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService6075.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -3,16 +3,28 @@ package com.fuyuanshen.app.domain.dto;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class AppDeviceLogoUploadDto {
|
||||
|
||||
private Long deviceId;
|
||||
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 文件
|
||||
* 文件
|
||||
*/
|
||||
private MultipartFile file;
|
||||
|
||||
// /**
|
||||
// * 文件
|
||||
// */
|
||||
// private List<MultipartFile> files;
|
||||
|
||||
|
||||
private List<Long> deviceIds;
|
||||
|
||||
private Integer chunkSize;
|
||||
|
||||
}
|
||||
|
||||
@ -8,9 +8,15 @@ public class DeviceInstructDto {
|
||||
private Long deviceId;
|
||||
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 下发指令
|
||||
* 下发指令
|
||||
*/
|
||||
private String instructValue;
|
||||
|
||||
/**
|
||||
* 下发指令类型
|
||||
*/
|
||||
private String instructType;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
package com.fuyuanshen.app.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AppUpdatePasswordBody {
|
||||
|
||||
/**
|
||||
* 登录密码
|
||||
*/
|
||||
private String password;
|
||||
}
|
||||
@ -73,10 +73,11 @@ public class AppDeviceShareService {
|
||||
private static void buildDeviceStatus(AppDeviceShareVo item) {
|
||||
// 设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(onlineStatus)) {
|
||||
|
||||
if("1".equals(onlineStatus)){
|
||||
item.setOnlineStatus(1);
|
||||
} else {
|
||||
}else if("2".equals(onlineStatus)){
|
||||
item.setOnlineStatus(2);
|
||||
}else{
|
||||
item.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
|
||||
@ -32,7 +32,7 @@ public class AppFileService {
|
||||
private final IAppBusinessFileService appBusinessFileService;
|
||||
|
||||
public List<AppFileVo> list(AppBusinessFileBo bo) {
|
||||
bo.setCreateBy(AppLoginHelper.getUserId());
|
||||
// bo.setCreateBy(AppLoginHelper.getUserId());
|
||||
return appBusinessFileService.queryAppFileList(bo);
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ public class AppFileService {
|
||||
|
||||
public Boolean delete(Long[] ids) {
|
||||
AppBusinessFileBo bo = new AppBusinessFileBo();
|
||||
bo.setCreateBy(AppLoginHelper.getUserId());
|
||||
// bo.setCreateBy(AppLoginHelper.getUserId());
|
||||
bo.setIds(List.of(ids));
|
||||
List<AppBusinessFileVo> appBusinessFileVos = appBusinessFileService.queryList(bo);
|
||||
List<Long> fileIds = appBusinessFileVos.stream().map(AppBusinessFileVo::getFileId).toList();
|
||||
|
||||
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.app.domain.AppUser;
|
||||
import com.fuyuanshen.app.mapper.AppUserMapper;
|
||||
import com.fuyuanshen.app.model.AppRegisterBody;
|
||||
import com.fuyuanshen.app.model.AppUpdatePasswordBody;
|
||||
import com.fuyuanshen.common.core.constant.Constants;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.domain.model.RegisterBody;
|
||||
@ -144,7 +145,7 @@ public class AppRegisterService {
|
||||
userMapper.update(updateWrapper);
|
||||
}
|
||||
|
||||
public void updatePassword(AppRegisterBody body) {
|
||||
public void updatePassword(AppUpdatePasswordBody body) {
|
||||
String username = AppLoginHelper.getUsername();
|
||||
String password = body.getPassword();
|
||||
UpdateWrapper<AppUser> updateWrapper = new UpdateWrapper<>();
|
||||
|
||||
@ -0,0 +1,308 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
|
||||
import com.fuyuanshen.equipment.utils.AlibabaTTSUtil;
|
||||
import com.fuyuanshen.equipment.utils.AudioProcessUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
/**
|
||||
* 音频处理服务
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AudioProcessService {
|
||||
|
||||
// 配置参数
|
||||
private static final int MAX_AUDIO_SIZE = 5 * 1024 * 1024; // 5MB
|
||||
private static final List<String> SUPPORTED_FORMATS = Arrays.asList(
|
||||
".wav", ".mp3", ".aac", ".flac", ".m4a", ".ogg"
|
||||
);
|
||||
|
||||
private final AudioProcessUtil audioProcessUtil;
|
||||
private final AlibabaTTSUtil alibabaTTSUtil;
|
||||
|
||||
/**
|
||||
* 处理上传的音频文件
|
||||
*/
|
||||
public List<String> processAudio(MultipartFile file) {
|
||||
// 1. 参数校验
|
||||
validateAudioFile(file);
|
||||
|
||||
File tempFile = null;
|
||||
try {
|
||||
// 2. 创建临时文件
|
||||
tempFile = createTempAudioFile(file);
|
||||
|
||||
// 3. 转码为标准PCM-WAV格式
|
||||
byte[] pcmData = audioProcessUtil.convertToStandardWav(tempFile);
|
||||
log.info("音频处理成功,输出数据大小: {} bytes", pcmData.length);
|
||||
|
||||
// 获取音频信息
|
||||
// String audioInfo = audioProcessUtil.getAudioInfo(pcmData);
|
||||
// log.info("音频处理成功,音频信息: {}", audioInfo);
|
||||
//
|
||||
// // 保存测试文件(用于验证)
|
||||
// String savedPath = audioProcessUtil.saveWavToFile(pcmData, "test_output.wav");
|
||||
// if (savedPath != null) {
|
||||
// log.info("测试文件已保存: {}", savedPath);
|
||||
// }
|
||||
|
||||
// 将byte[]转换为16进制字符串列表
|
||||
List<String> hexList = audioProcessUtil.bytesToHexList(pcmData);
|
||||
|
||||
log.info("音频处理完成,原始数据大小: {} bytes, 16进制数据长度: {}",
|
||||
pcmData.length, hexList.size());
|
||||
|
||||
return hexList;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("音频处理失败", e);
|
||||
throw new RuntimeException("音频处理失败", e);
|
||||
} finally {
|
||||
// 4. 清理临时文件
|
||||
deleteTempFile(tempFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成标准PCM数据(单声道,16K采样率,16bit深度,包含44字节WAV头)
|
||||
* 数据总大小不超过2MB,如果超过将抛出异常
|
||||
* @param text 要转换的文本内容
|
||||
* @return 标准PCM数据字节数组(WAV格式)
|
||||
* @throws IOException 处理失败时抛出
|
||||
* @throws IllegalArgumentException 如果生成的数据超过2MB
|
||||
*/
|
||||
public List<String> generateStandardPcmData(String text) throws IOException {
|
||||
// 参数校验
|
||||
if (text == null || text.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("文本内容不能为空");
|
||||
}
|
||||
if (text.length() > 100) {
|
||||
throw new IllegalArgumentException("文本长度超过限制(最大100字符)");
|
||||
}
|
||||
log.info("输入文本长度: {}", text.length());
|
||||
try {
|
||||
byte[] rawPcmData = alibabaTTSUtil.generateStandardPcmData(text);
|
||||
|
||||
// 使用AudioProcessUtil转换成带头44字节 PCM
|
||||
byte[] pcmData = audioProcessUtil.rawPcmToStandardWav(rawPcmData);
|
||||
|
||||
// String savedPath = audioProcessUtil.saveWavToFile(pcmData, "test_output.wav");
|
||||
// if (savedPath != null) {
|
||||
// log.info("测试文件已保存: {}", savedPath);
|
||||
// }
|
||||
|
||||
// 保存WAV文件到本地
|
||||
String savedPath = saveByteArrayToFile(pcmData, "tts_output.wav");
|
||||
if (savedPath != null) {
|
||||
log.info("WAV文件已保存: {}", savedPath);
|
||||
}
|
||||
|
||||
// 将byte[]转换为16进制字符串列表
|
||||
List<String> hexList = audioProcessUtil.bytesToHexList(pcmData);
|
||||
|
||||
log.info("generateStandardPcmData音频处理完成,原始数据大小: {} bytes, 16进制数据长度: {}",
|
||||
pcmData.length, hexList.size());
|
||||
|
||||
return hexList;
|
||||
} finally {
|
||||
// 4. 清理临时文件
|
||||
}
|
||||
}
|
||||
|
||||
public String saveWavFileLocally(String text, String filename) throws IOException {
|
||||
// 参数校验
|
||||
if (text == null || text.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("文本内容不能为空");
|
||||
}
|
||||
|
||||
if (filename == null || filename.trim().isEmpty()) {
|
||||
filename = "tts_output.wav"; // 默认文件名
|
||||
}
|
||||
|
||||
try {
|
||||
// 生成PCM数据
|
||||
byte[] rawPcmData = alibabaTTSUtil.generateStandardPcmData(text);
|
||||
|
||||
// 转换为标准WAV格式(添加44字节头部)
|
||||
byte[] wavData = audioProcessUtil.rawPcmToStandardWav(rawPcmData);
|
||||
|
||||
// 保存到本地文件
|
||||
String filePath = saveByteArrayToFile(wavData, filename);
|
||||
|
||||
log.info("WAV文件已保存: {}", filePath);
|
||||
return filePath;
|
||||
} catch (Exception e) {
|
||||
log.error("保存WAV文件失败: {}", e.getMessage(), e);
|
||||
throw new IOException("保存WAV文件失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private String saveByteArrayToFile(byte[] data, String filename) throws IOException {
|
||||
// 确定保存路径(可以是临时目录或指定目录)
|
||||
String directory = System.getProperty("java.io.tmpdir"); // 使用系统临时目录
|
||||
File dir = new File(directory);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
// 创建完整文件路径
|
||||
File file = new File(dir, filename);
|
||||
|
||||
// 写入文件
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
fos.write(data);
|
||||
}
|
||||
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 验证音频文件
|
||||
*/
|
||||
private void validateAudioFile(MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new IllegalArgumentException("上传文件不能为空");
|
||||
}
|
||||
|
||||
if (!isAudioFile(file.getOriginalFilename())) {
|
||||
throw new IllegalArgumentException("只允许上传音频文件");
|
||||
}
|
||||
|
||||
if (file.getSize() > MAX_AUDIO_SIZE) {
|
||||
throw new IllegalArgumentException("音频大小不能超过5MB");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是支持的音频格式
|
||||
*/
|
||||
private boolean isAudioFile(String filename) {
|
||||
if (filename == null || filename.lastIndexOf('.') == -1) {
|
||||
return false;
|
||||
}
|
||||
String ext = filename.substring(filename.lastIndexOf('.')).toLowerCase();
|
||||
return SUPPORTED_FORMATS.contains(ext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时音频文件
|
||||
*/
|
||||
private File createTempAudioFile(MultipartFile file) throws IOException {
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String extension = "";
|
||||
if (originalFilename != null && originalFilename.contains(".")) {
|
||||
extension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
}
|
||||
|
||||
File tempFile = File.createTempFile("audio-", extension);
|
||||
file.transferTo(tempFile);
|
||||
log.debug("创建临时音频文件: {}", tempFile.getAbsolutePath());
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除临时文件
|
||||
*/
|
||||
private void deleteTempFile(File file) {
|
||||
if (file != null && file.exists()) {
|
||||
if (file.delete()) {
|
||||
log.debug("删除临时文件成功: {}", file.getAbsolutePath());
|
||||
} else {
|
||||
log.warn("无法删除临时文件: {}", file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取文本
|
||||
*/
|
||||
public String extract(MultipartFile file) throws Exception {
|
||||
String name = file.getOriginalFilename();
|
||||
if (name == null ||
|
||||
(!name.endsWith(".txt") && !name.endsWith(".docx"))) {
|
||||
throw new IllegalArgumentException("仅支持 .txt 或 .docx");
|
||||
}
|
||||
if (file.getSize() > MAX_AUDIO_SIZE) {
|
||||
throw new IllegalArgumentException("文件超过5MB");
|
||||
}
|
||||
|
||||
String text;
|
||||
/* 全程流式,不落地磁盘,不一次性读字节数组 */
|
||||
try (InputStream in = file.getInputStream()) {
|
||||
if (name.endsWith(".txt")) {
|
||||
text = readTxt(in);
|
||||
} else {
|
||||
text = readDocx(in);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/* ---------- txt:按行读,StringBuilder 复用 ---------- */
|
||||
private String readTxt(InputStream in) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
StringBuilder sb = new StringBuilder(4096);
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line).append('\n');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/* ---------- docx:ZipInputStream 只扫 document.xml ---------- */
|
||||
private String readDocx(InputStream in) throws IOException {
|
||||
ZipInputStream zin = new ZipInputStream(in);
|
||||
ZipEntry e;
|
||||
while ((e = zin.getNextEntry()) != null) {
|
||||
if ("word/document.xml".equals(e.getName())) {
|
||||
return staxExtract(zin); // 流式读 XML
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/* ---------- StAX 流式提取 <w:t> ---------- */
|
||||
private String staxExtract(InputStream xml) throws IOException {
|
||||
XMLStreamReader r = null;
|
||||
StringBuilder sb = new StringBuilder(4096);
|
||||
try {
|
||||
//System.out.println(new String(xml.readAllBytes()));
|
||||
r = XMLInputFactory.newInstance().createXMLStreamReader(xml);
|
||||
while (r.hasNext()) {
|
||||
if (r.next() == XMLStreamConstants.START_ELEMENT &&
|
||||
"t".equals(r.getLocalName())) {
|
||||
String elementText = r.getElementText();
|
||||
sb.append(elementText);
|
||||
}
|
||||
}
|
||||
} catch (XMLStreamException ex) {
|
||||
throw new IOException(ex);
|
||||
} finally {
|
||||
if (r != null) try { r.close(); } catch (XMLStreamException ignore) {}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
|
||||
import com.fuyuanshen.web.util.VideoProcessUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 视频处理服务
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class VideoProcessService {
|
||||
|
||||
// 配置参数
|
||||
private static final int MAX_VIDEO_SIZE = 10 * 1024 * 1024;
|
||||
private static final List<String> SUPPORTED_FORMATS = Arrays.asList(".mp4", ".avi", ".mov", ".mkv");
|
||||
private static final int FRAME_RATE = 15;
|
||||
private static final int DURATION = 2;
|
||||
private static final int WIDTH = 160;
|
||||
private static final int HEIGHT = 80;
|
||||
|
||||
private final VideoProcessUtil videoProcessUtil;
|
||||
|
||||
public List<String> processVideo(MultipartFile file) {
|
||||
// 1. 参数校验
|
||||
validateVideoFile(file);
|
||||
|
||||
File tempFile = null;
|
||||
try {
|
||||
// 2. 创建临时文件
|
||||
tempFile = videoProcessUtil.createTempVideoFile(file);
|
||||
|
||||
// 3. 处理视频并提取帧数据
|
||||
List<String> hexList = videoProcessUtil.processVideoToHex(
|
||||
tempFile, FRAME_RATE, DURATION, WIDTH, HEIGHT
|
||||
);
|
||||
|
||||
log.info("视频处理成功,生成Hex数据长度: {}", hexList.size());
|
||||
return hexList;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("视频处理失败", e);
|
||||
throw new RuntimeException("视频处理失败", e);
|
||||
} finally {
|
||||
// 4. 清理临时文件
|
||||
videoProcessUtil.deleteTempFile(tempFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证视频文件
|
||||
*/
|
||||
private void validateVideoFile(MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new IllegalArgumentException("上传文件不能为空");
|
||||
}
|
||||
|
||||
if (!isVideoFile(file.getOriginalFilename())) {
|
||||
throw new IllegalArgumentException("只允许上传视频文件");
|
||||
}
|
||||
|
||||
if (file.getSize() > MAX_VIDEO_SIZE) {
|
||||
throw new IllegalArgumentException("视频大小不能超过10MB");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是支持的视频格式
|
||||
*/
|
||||
private boolean isVideoFile(String filename) {
|
||||
if (filename == null || filename.lastIndexOf('.') == -1) {
|
||||
return false;
|
||||
}
|
||||
String ext = filename.substring(filename.lastIndexOf('.')).toLowerCase();
|
||||
return SUPPORTED_FORMATS.contains(ext);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.fuyuanshen.global.mqtt.base;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* MQTT消息基础模型
|
||||
*/
|
||||
@Data
|
||||
public class MqttMessage {
|
||||
|
||||
/**
|
||||
* 请求ID,用于匹配请求和响应
|
||||
*/
|
||||
private String requestId;
|
||||
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String imei;
|
||||
|
||||
/**
|
||||
* 时间戳(毫秒)
|
||||
*/
|
||||
private Long timestamp;
|
||||
|
||||
/**
|
||||
* 功能类型
|
||||
*/
|
||||
private Integer funcType;
|
||||
|
||||
/**
|
||||
* 数据内容
|
||||
*/
|
||||
private Object data;
|
||||
|
||||
/**
|
||||
* 状态(响应时使用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 批量数据(设备上报时使用)
|
||||
*/
|
||||
private List<SensorData> batch;
|
||||
|
||||
}
|
||||
@ -21,26 +21,31 @@ public class MqttRuleEngine {
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
private final LinkedHashMap<String, MqttMessageRule> rulesMap = new LinkedHashMap<>();
|
||||
|
||||
|
||||
public MqttRuleEngine(List<MqttMessageRule> rules) {
|
||||
// 按优先级排序
|
||||
rules.sort(Comparator.comparing(MqttMessageRule::getPriority));
|
||||
rules.forEach(rule -> rulesMap.put(rule.getCommandType(), rule)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 执行匹配
|
||||
*
|
||||
* @param context 处理上下文
|
||||
* @return
|
||||
*/
|
||||
public boolean executeRule(MqttRuleContext context) {
|
||||
int commandType = context.getCommandType();
|
||||
MqttMessageRule mqttMessageRule = rulesMap.get("Light_"+commandType);
|
||||
MqttMessageRule mqttMessageRule = rulesMap.get("Light_" + commandType);
|
||||
if (mqttMessageRule != null) {
|
||||
threadPoolTaskExecutor.execute(() -> mqttMessageRule.execute(context));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
package com.fuyuanshen.global.mqtt.base;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* MQTT主题信息模型
|
||||
*/
|
||||
@Data
|
||||
public class MqttTopicInfo {
|
||||
/**
|
||||
* 操作类型 (command/status/report)
|
||||
*/
|
||||
private String operation;
|
||||
|
||||
/**
|
||||
* 租户编码
|
||||
*/
|
||||
private String tenantCode;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String imei;
|
||||
}
|
||||
@ -39,8 +39,8 @@ public class MqttXinghanJson {
|
||||
/**
|
||||
* 第七键值对, 静止报警状态,0-未静止报警,1-正在静止报警。
|
||||
*/
|
||||
@JsonProperty("staShakeBit")
|
||||
public Integer sta_ShakeBit;
|
||||
@JsonProperty("sta_ShakeBit")
|
||||
public Integer staShakeBit;
|
||||
/**
|
||||
* 第八键值对, 4G信号强度,0-32,数值越大,信号越强。
|
||||
*/
|
||||
@ -61,5 +61,14 @@ public class MqttXinghanJson {
|
||||
*/
|
||||
@JsonProperty("sta_latitude")
|
||||
public String stalatitude;
|
||||
/**
|
||||
* 第十二键值对,系统现状,0关机,1仅充电,2开机未充电,3,开机且充电
|
||||
*/
|
||||
@JsonProperty("sta_system")
|
||||
public String stasystem;
|
||||
/**
|
||||
* 电量百分比(适配控制列表显示)
|
||||
*/
|
||||
public String batteryPercentage;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
package com.fuyuanshen.global.mqtt.base;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 传感器数据模型
|
||||
*/
|
||||
@Data
|
||||
public class SensorData {
|
||||
/**
|
||||
* 传感器名称
|
||||
*/
|
||||
private String sensor;
|
||||
|
||||
/**
|
||||
* 传感器值
|
||||
*/
|
||||
private Object value;
|
||||
|
||||
/**
|
||||
* 时间戳(毫秒)
|
||||
*/
|
||||
private Long timestamp;
|
||||
}
|
||||
@ -3,7 +3,6 @@ package com.fuyuanshen.global.mqtt.constants;
|
||||
|
||||
public interface MqttConstants {
|
||||
|
||||
|
||||
/**
|
||||
* 全局发布消息的key
|
||||
*/
|
||||
@ -13,4 +12,5 @@ public interface MqttConstants {
|
||||
* 全局订阅消息的key
|
||||
*/
|
||||
String GLOBAL_SUB_KEY = "A/";
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,82 @@
|
||||
package com.fuyuanshen.global.mqtt.enums;
|
||||
|
||||
/**
|
||||
* 设备功能类型枚举
|
||||
* 基于AppDeviceBJQ6075Controller中的功能注释1-9设计
|
||||
*/
|
||||
public enum DeviceFunctionType6075 {
|
||||
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
REGISTER_PERSON_INFO(1, "REGISTER_PERSON_INFO", "人员信息登记"),
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
*/
|
||||
SEND_MESSAGE(2, "SEND_MESSAGE", "发送信息"),
|
||||
|
||||
/**
|
||||
* 发送报警信息
|
||||
*/
|
||||
SEND_ALARM_MESSAGE(3, "SEND_ALARM_MESSAGE", "发送报警信息"),
|
||||
|
||||
/**
|
||||
* 上传设备logo图片
|
||||
*/
|
||||
UPLOAD_LOGO(4, "UPLOAD_LOGO", "上传设备logo图片"),
|
||||
|
||||
/**
|
||||
* 灯光模式(主光模式)
|
||||
* 0(关闭灯光),1(强光),2(超强光), 3(工作光), 4(节能光),5(爆闪),6(SOS)
|
||||
*/
|
||||
LIGHT_MODE(5, "LIGHT_MODE", "灯光模式"),
|
||||
|
||||
/**
|
||||
* 灯光模式(辅光模式)
|
||||
* 0(关闭灯光),1(泛光),2(泛光爆闪), 3(警示灯), 4(警示灯/泛光)
|
||||
*/
|
||||
AUXILIARY_LIGHT_MODE(6, "AUXILIARY_LIGHT_MODE", "辅光模式"),
|
||||
|
||||
/**
|
||||
* 灯光亮度设置
|
||||
*/
|
||||
LIGHT_BRIGHTNESS(7, "LIGHT_BRIGHTNESS", "灯光亮度设置"),
|
||||
|
||||
/**
|
||||
* 激光模式设置
|
||||
*/
|
||||
LASER_MODE(8, "LASER_MODE", "激光模式设置"),
|
||||
|
||||
/**
|
||||
* 声光报警模式设置
|
||||
*/
|
||||
SOUND_AND_LIGHT_ALARM(9, "SOUND_AND_LIGHT_ALARM", "声光报警模式设置");
|
||||
|
||||
private final int number;
|
||||
private final String code;
|
||||
private final String description;
|
||||
|
||||
DeviceFunctionType6075(int number, String code, String description) {
|
||||
this.number = number;
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,136 @@
|
||||
package com.fuyuanshen.global.mqtt.handler;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttTopicInfo;
|
||||
import com.fuyuanshen.global.mqtt.service.IotMqttService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* IoT设备MQTT消息处理器
|
||||
* 用于处理设备上报的数据和响应消息
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class IotMqttMessageHandler {
|
||||
|
||||
private final IotMqttService iotMqttService;
|
||||
|
||||
/**
|
||||
* 处理MQTT消息
|
||||
*
|
||||
* @param topic 主题
|
||||
* @param payload 消息内容
|
||||
*/
|
||||
public void handleMessage(String topic, String payload) {
|
||||
try {
|
||||
// 解析主题
|
||||
MqttTopicInfo topicInfo = parseTopic(topic);
|
||||
if (topicInfo == null) {
|
||||
log.warn("无法解析MQTT主题: topic={}", topic);
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析消息内容
|
||||
JSONObject message = JSON.parseObject(payload);
|
||||
|
||||
// 根据主题类型处理消息
|
||||
switch (topicInfo.getOperation()) {
|
||||
case "command":
|
||||
// 处理下发指令(设备端不会主动发送command类型消息)
|
||||
log.warn("收到非法的MQTT消息类型: operation={}", topicInfo.getOperation());
|
||||
break;
|
||||
case "status":
|
||||
// 处理设备对指令的响应
|
||||
iotMqttService.handleCommandResponse(
|
||||
topicInfo.getTenantCode(),
|
||||
topicInfo.getDeviceType(),
|
||||
topicInfo.getImei(),
|
||||
message);
|
||||
break;
|
||||
case "report":
|
||||
// 处理设备主动上报的数据
|
||||
handleDeviceReport(topicInfo, message);
|
||||
break;
|
||||
default:
|
||||
log.warn("未知的MQTT主题操作类型: operation={}", topicInfo.getOperation());
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理MQTT消息时发生错误: topic={}, payload={}", topic, payload, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析MQTT主题
|
||||
*
|
||||
* @param topic 主题字符串
|
||||
* @return 主题信息对象
|
||||
*/
|
||||
MqttTopicInfo parseTopic(String topic) {
|
||||
if (topic == null || topic.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] parts = topic.split("/");
|
||||
if (parts.length != 4) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MqttTopicInfo info = new MqttTopicInfo();
|
||||
info.setOperation(parts[0]);
|
||||
info.setTenantCode(parts[1]);
|
||||
info.setDeviceType(parts[2]);
|
||||
info.setImei(parts[3]);
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理设备上报数据
|
||||
*
|
||||
* @param topicInfo 主题信息
|
||||
* @param message 消息内容
|
||||
*/
|
||||
private void handleDeviceReport(MqttTopicInfo topicInfo, JSONObject message) {
|
||||
// 获取时间戳
|
||||
Long timestamp = message.getLong("timestamp");
|
||||
|
||||
// 处理批量数据上报
|
||||
if (message.containsKey("batch")) {
|
||||
JSONObject batchData = message.getJSONObject("batch");
|
||||
iotMqttService.handleBatchReport(
|
||||
topicInfo.getTenantCode(),
|
||||
topicInfo.getDeviceType(),
|
||||
topicInfo.getImei(),
|
||||
batchData,
|
||||
timestamp);
|
||||
}
|
||||
// 处理单个数据上报
|
||||
else if (message.containsKey("sensor") && message.containsKey("value")) {
|
||||
String sensor = message.getString("sensor");
|
||||
Object value = message.get("value");
|
||||
iotMqttService.handleSingleReport(
|
||||
topicInfo.getTenantCode(),
|
||||
topicInfo.getDeviceType(),
|
||||
topicInfo.getImei(),
|
||||
sensor,
|
||||
value,
|
||||
timestamp);
|
||||
}
|
||||
// 处理其他格式的数据
|
||||
else {
|
||||
// 将整个消息作为批量数据处理
|
||||
iotMqttService.handleBatchReport(
|
||||
topicInfo.getTenantCode(),
|
||||
topicInfo.getDeviceType(),
|
||||
topicInfo.getImei(),
|
||||
message,
|
||||
timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package com.fuyuanshen.global.mqtt.handler;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessage;
|
||||
import com.fuyuanshen.global.mqtt.service.MqttMessageService;
|
||||
import com.fuyuanshen.global.mqtt.utils.MqttTopicUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttTopicInfo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* MQTT消息处理器
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class MqttMessageHandler {
|
||||
|
||||
private final MqttMessageService mqttMessageService;
|
||||
|
||||
|
||||
/**
|
||||
* 处理MQTT消息
|
||||
* @param topic 主题
|
||||
* @param payload 消息内容
|
||||
*/
|
||||
public void handleMessage(String topic, String payload) {
|
||||
try {
|
||||
// 解析主题
|
||||
MqttTopicInfo topicInfo = MqttTopicUtils.parseTopic(topic);
|
||||
if (topicInfo == null) {
|
||||
log.warn("无法解析MQTT主题: topic={}", topic);
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析消息内容
|
||||
MqttMessage message = JSON.parseObject(payload, MqttMessage.class);
|
||||
|
||||
// 根据主题类型处理消息
|
||||
switch (topicInfo.getOperation()) {
|
||||
case "command":
|
||||
// 处理下发指令(设备端不会主动发送command类型消息)
|
||||
log.warn("收到非法的MQTT消息类型: operation={}", topicInfo.getOperation());
|
||||
break;
|
||||
case "status":
|
||||
// 处理设备对指令的响应
|
||||
mqttMessageService.handleCommandResponse(
|
||||
topicInfo.getTenantCode(),
|
||||
topicInfo.getDeviceType(),
|
||||
topicInfo.getImei(),
|
||||
message);
|
||||
break;
|
||||
case "report":
|
||||
// 处理设备主动上报的数据
|
||||
mqttMessageService.handleDeviceReport(
|
||||
topicInfo.getTenantCode(),
|
||||
topicInfo.getDeviceType(),
|
||||
topicInfo.getImei(),
|
||||
message);
|
||||
break;
|
||||
default:
|
||||
log.warn("未知的MQTT主题操作类型: operation={}", topicInfo.getOperation());
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理MQTT消息时发生错误: topic={}, payload={}", topic, payload, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -65,12 +65,23 @@ public class RedisKeyExpirationListener implements MessageListener {
|
||||
if (lockInfo != null) {
|
||||
try {
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ message + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
// String deviceOnlineStatusRedis = RedisUtils.getCacheObject(deviceOnlineStatusRedisKey);
|
||||
// if(StringUtils.isBlank(deviceOnlineStatusRedis)){
|
||||
// UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
// deviceUpdateWrapper.eq("device_imei", element);
|
||||
// deviceUpdateWrapper.set("online_status", 0);
|
||||
// deviceMapper.update(deviceUpdateWrapper);
|
||||
// }else{
|
||||
// RedisUtils.deleteObject(deviceOnlineStatusRedisKey);
|
||||
// }
|
||||
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("device_imei", element);
|
||||
deviceUpdateWrapper.set("online_status", 0);
|
||||
deviceMapper.update(deviceUpdateWrapper);
|
||||
String deviceOnlineStatusRedis = RedisUtils.getCacheObject(deviceOnlineStatusRedisKey);
|
||||
if(StringUtils.isBlank(deviceOnlineStatusRedis)){
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("device_imei", element);
|
||||
deviceUpdateWrapper.set("online_status", 0);
|
||||
deviceMapper.update(deviceUpdateWrapper);
|
||||
if(StringUtils.isNotBlank(deviceOnlineStatusRedis)){
|
||||
RedisUtils.deleteObject(deviceOnlineStatusRedisKey);
|
||||
}
|
||||
} finally {
|
||||
//释放锁
|
||||
|
||||
@ -0,0 +1,279 @@
|
||||
package com.fuyuanshen.global.mqtt.receiver;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleEngine;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttXinghanCommandType;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.queue.MqttMessageQueueConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 6075
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-11-05 17:41
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DeviceMessageHandler implements MessageHandler {
|
||||
|
||||
@Autowired
|
||||
private MqttRuleEngine ruleEngine;
|
||||
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
Object payload = message.getPayload();
|
||||
MessageHeaders headers = message.getHeaders();
|
||||
String receivedTopic = Objects.requireNonNull(headers.get("mqtt_receivedTopic")).toString();
|
||||
String receivedQos = Objects.requireNonNull(headers.get("mqtt_receivedQos")).toString();
|
||||
String timestamp = Objects.requireNonNull(headers.get("timestamp")).toString();
|
||||
|
||||
log.info("MQTT payload= {} \n receivedTopic = {} \n receivedQos = {} \n timestamp = {}",
|
||||
payload, receivedTopic, receivedQos, timestamp);
|
||||
|
||||
Dict payloadDict = JsonUtils.parseMap(payload.toString());
|
||||
if (receivedTopic == null || payloadDict == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析设备IMEI
|
||||
String[] subStr = receivedTopic.split("/");
|
||||
String deviceImei = subStr[1];
|
||||
|
||||
// 处理设备在线状态
|
||||
handleDeviceOnlineStatus(deviceImei);
|
||||
|
||||
// 处理不同类型的设备信息
|
||||
processDeviceInformation(payloadDict, deviceImei);
|
||||
|
||||
// 执行规则引擎处理
|
||||
executeRuleEngine(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理设备在线状态
|
||||
*/
|
||||
private void handleDeviceOnlineStatus(String deviceImei) {
|
||||
if (StringUtils.isNotBlank(deviceImei)) {
|
||||
// 添加去重队列
|
||||
String queueKey = MqttMessageQueueConstants.MQTT_MESSAGE_QUEUE_KEY;
|
||||
String dedupKey = MqttMessageQueueConstants.MQTT_MESSAGE_DEDUP_KEY;
|
||||
RedisUtils.offerDeduplicated(queueKey, dedupKey, deviceImei, Duration.ofSeconds(900));
|
||||
|
||||
// 设置设备在线状态
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY +
|
||||
DEVICE_KEY_PREFIX + deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1", Duration.ofSeconds(360));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理不同类型的设备信息
|
||||
*/
|
||||
private void processDeviceInformation(Dict payloadDict, String deviceImei) {
|
||||
// 开机画面
|
||||
if (payloadDict.containsKey("bootScreen")) {
|
||||
handleBootScreen(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 人员信息
|
||||
if (payloadDict.containsKey("personInfo")) {
|
||||
handlePersonInfo(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 设备信息
|
||||
if (payloadDict.containsKey("deviceInfo")) {
|
||||
handleDeviceInfo(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 经纬度
|
||||
if (payloadDict.containsKey("latitude") && payloadDict.containsKey("longitude")) {
|
||||
handleLocation(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 电子地图
|
||||
if (payloadDict.containsKey("mapData")) {
|
||||
handleMapData(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 电池电量
|
||||
if (payloadDict.containsKey("batteryLevel")) {
|
||||
handleBatteryLevel(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 开启/关闭状态
|
||||
if (payloadDict.containsKey("powerState")) {
|
||||
handlePowerState(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 海拔高度
|
||||
if (payloadDict.containsKey("altitude")) {
|
||||
handleAltitude(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 相对高度
|
||||
if (payloadDict.containsKey("relativeHeight")) {
|
||||
handleRelativeHeight(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 群呼/单呼
|
||||
if (payloadDict.containsKey("callType")) {
|
||||
handleCallType(payloadDict, deviceImei);
|
||||
}
|
||||
|
||||
// 文字信息
|
||||
if (payloadDict.containsKey("textMessage")) {
|
||||
handleTextMessage(payloadDict, deviceImei);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理开机画面
|
||||
*/
|
||||
private void handleBootScreen(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的开机画面信息", deviceImei);
|
||||
// 实现具体的开机画面处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理人员信息
|
||||
*/
|
||||
private void handlePersonInfo(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的人员信息", deviceImei);
|
||||
// 实现具体的人员信息处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理设备信息
|
||||
*/
|
||||
private void handleDeviceInfo(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的设备信息", deviceImei);
|
||||
// 实现具体的设备信息处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理位置信息
|
||||
*/
|
||||
private void handleLocation(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的位置信息: 纬度={}, 经度={}",
|
||||
deviceImei, payloadDict.getStr("latitude"), payloadDict.getStr("longitude"));
|
||||
// 实现具体的位置信息处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理电子地图数据
|
||||
*/
|
||||
private void handleMapData(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的电子地图数据", deviceImei);
|
||||
// 实现具体的电子地图数据处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理电池电量
|
||||
*/
|
||||
private void handleBatteryLevel(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的电池电量: {}", deviceImei, payloadDict.getStr("batteryLevel"));
|
||||
// 实现具体的电池电量处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理开关状态
|
||||
*/
|
||||
private void handlePowerState(Dict payloadDict, String deviceImei) {
|
||||
String powerState = payloadDict.getStr("powerState");
|
||||
log.info("处理设备{}的开关状态: {}", deviceImei, powerState);
|
||||
// 实现具体的开关状态处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理海拔高度
|
||||
*/
|
||||
private void handleAltitude(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的海拔高度: {}", deviceImei, payloadDict.getStr("altitude"));
|
||||
// 实现具体的海拔高度处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理相对高度
|
||||
*/
|
||||
private void handleRelativeHeight(Dict payloadDict, String deviceImei) {
|
||||
log.info("处理设备{}的相对高度: {}", deviceImei, payloadDict.getStr("relativeHeight"));
|
||||
// 实现具体的相对高度处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理呼叫类型
|
||||
*/
|
||||
private void handleCallType(Dict payloadDict, String deviceImei) {
|
||||
String callType = payloadDict.getStr("callType");
|
||||
log.info("处理设备{}的呼叫类型: {}", deviceImei, callType);
|
||||
// 实现具体的呼叫类型处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理文字信息
|
||||
*/
|
||||
private void handleTextMessage(Dict payloadDict, String deviceImei) {
|
||||
String textMessage = payloadDict.getStr("textMessage");
|
||||
log.info("处理设备{}的文字信息: {}", deviceImei, textMessage);
|
||||
// 实现具体的文字信息处理逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行规则引擎处理
|
||||
*/
|
||||
private void executeRuleEngine(Dict payloadDict, String deviceImei) {
|
||||
String state = payloadDict.getStr("state");
|
||||
Object[] convertArr = ImageToCArrayConverter.convertByteStringToMixedObjectArray(state);
|
||||
|
||||
if (convertArr.length > 0) {
|
||||
Byte val1 = (Byte) convertArr[0];
|
||||
MqttRuleContext context = new MqttRuleContext();
|
||||
context.setCommandType(val1);
|
||||
context.setConvertArr(convertArr);
|
||||
context.setDeviceImei(deviceImei);
|
||||
context.setPayloadDict(payloadDict);
|
||||
|
||||
boolean ruleExecuted = ruleEngine.executeRule(context);
|
||||
|
||||
if (!ruleExecuted) {
|
||||
log.warn("未找到匹配的规则来处理命令类型: {}", val1);
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 追加:根据报文内容识别格式并统一解析 ===== */
|
||||
int intType = MqttXinghanCommandType.computeVirtualCommandType(payloadDict);
|
||||
if (intType > 0) {
|
||||
MqttRuleContext newCtx = new MqttRuleContext();
|
||||
newCtx.setCommandType((byte) intType);
|
||||
newCtx.setDeviceImei(deviceImei);
|
||||
newCtx.setPayloadDict(payloadDict);
|
||||
|
||||
boolean ok = ruleEngine.executeRule(newCtx);
|
||||
if (!ok) {
|
||||
log.warn("新规则引擎未命中, imei={}", deviceImei);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -48,17 +48,18 @@ public class ReceiverMessageHandler implements MessageHandler {
|
||||
}
|
||||
String[] subStr = receivedTopic.split("/");
|
||||
String deviceImei = subStr[1];
|
||||
String state = payloadDict.getStr("state");
|
||||
Object[] convertArr = ImageToCArrayConverter.convertByteStringToMixedObjectArray(state);
|
||||
if(StringUtils.isNotBlank(deviceImei)){
|
||||
String queueKey = MqttMessageQueueConstants.MQTT_MESSAGE_QUEUE_KEY;
|
||||
String dedupKey = MqttMessageQueueConstants.MQTT_MESSAGE_DEDUP_KEY;
|
||||
RedisUtils.offerDeduplicated(queueKey,dedupKey,deviceImei, Duration.ofHours(24));
|
||||
RedisUtils.offerDeduplicated(queueKey,dedupKey,deviceImei, Duration.ofSeconds(900));
|
||||
//在线状态
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1", Duration.ofSeconds(62));
|
||||
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1", Duration.ofSeconds(360));
|
||||
}
|
||||
|
||||
String state = payloadDict.getStr("state");
|
||||
Object[] convertArr = ImageToCArrayConverter.convertByteStringToMixedObjectArray(state);
|
||||
|
||||
|
||||
if (convertArr.length > 0) {
|
||||
Byte val1 = (Byte) convertArr[0];
|
||||
@ -89,4 +90,5 @@ public class ReceiverMessageHandler implements MessageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,7 +38,6 @@ import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
@Slf4j
|
||||
public class BjqAlarmRule implements MqttMessageRule {
|
||||
|
||||
|
||||
private final IDeviceAlarmService deviceAlarmService;
|
||||
private final DeviceService deviceService;
|
||||
|
||||
@ -58,12 +57,17 @@ public class BjqAlarmRule implements MqttMessageRule {
|
||||
if (StringUtils.isNotBlank(convertValue)) {
|
||||
// 将设备状态信息存储到Redis中
|
||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX;
|
||||
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, convertValue);
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
|
||||
if ("1".equals(convertValue)) {
|
||||
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, "1");
|
||||
}else if ("0".equals(convertValue)){
|
||||
RedisUtils.deleteObject(sendMessageIng);
|
||||
RedisUtils.deleteObject(deviceRedisKey);
|
||||
}
|
||||
}
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
|
||||
// 保存告警信息
|
||||
String deviceImei = context.getDeviceImei();
|
||||
// 设备告警状态 0:解除告警 1:报警产生
|
||||
@ -89,6 +93,10 @@ public class BjqAlarmRule implements MqttMessageRule {
|
||||
deviceAlarmBo.setFinishTime(new Date());
|
||||
String durationBetween = DurationUtils.getDurationBetween(deviceAlarmVo.getStartTime(), deviceAlarmBo.getFinishTime());
|
||||
deviceAlarmBo.setDurationTime(durationBetween);
|
||||
// 0已处理,1未处理
|
||||
deviceAlarmBo.setTreatmentState(0);
|
||||
// 告警状态,0 解除告警, 1 告警中
|
||||
deviceAlarmBo.setAlarmState(0);
|
||||
deviceAlarmService.updateByBo(deviceAlarmBo);
|
||||
}
|
||||
}
|
||||
@ -106,6 +114,8 @@ public class BjqAlarmRule implements MqttMessageRule {
|
||||
deviceAlarmBo.setStartTime(new Date());
|
||||
// 0已处理,1未处理
|
||||
deviceAlarmBo.setTreatmentState(1);
|
||||
// 告警状态,0 解除告警, 1 告警中
|
||||
deviceAlarmBo.setAlarmState(1);
|
||||
|
||||
// LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
// deviceAlarmBo.setCreateBy(loginUser.getUserId());
|
||||
|
||||
@ -5,6 +5,8 @@ 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.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
|
||||
import com.fuyuanshen.equipment.utils.map.LngLonUtil;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
@ -36,8 +38,9 @@ import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVIC
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BjqLocationDataRule implements MqttMessageRule {
|
||||
|
||||
|
||||
private final MqttGateway mqttGateway;
|
||||
private final DeviceService deviceService;
|
||||
|
||||
|
||||
@Override
|
||||
@ -53,9 +56,15 @@ public class BjqLocationDataRule implements MqttMessageRule {
|
||||
// Latitude, longitude
|
||||
String latitude = convertArr[1].toString();
|
||||
String longitude = convertArr[2].toString();
|
||||
|
||||
// 判断 latitude 和 longitude 是否都为 0
|
||||
if ("0".equals(latitude) && "0".equals(longitude)) {
|
||||
log.info("位置信息为0,不存储到Redis: device={}, lat={}, lon={}", context.getDeviceImei(), latitude, longitude);
|
||||
return;
|
||||
}
|
||||
// 异步发送经纬度到Redis
|
||||
asyncSendLocationToRedisWithFuture(context.getDeviceImei(), latitude, longitude);
|
||||
// 异步保存数据
|
||||
asyncSaveLocationToMySQLWithFuture(context.getDeviceImei(), latitude, longitude);
|
||||
|
||||
Map<String, Object> map = buildLocationDataMap(latitude, longitude);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), 1, JsonUtils.toJsonString(map));
|
||||
@ -114,13 +123,14 @@ public class BjqLocationDataRule implements MqttMessageRule {
|
||||
public void asyncSendLocationToRedisWithFuture(String deviceImei, String latitude, String longitude) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
if(StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)){
|
||||
if (StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// String[] latArr = latitude.split("\\.");
|
||||
// String[] lonArr = longitude.split("\\.");
|
||||
// // 将位置信息存储到Redis中
|
||||
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX;
|
||||
String 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){
|
||||
@ -153,7 +163,6 @@ public class BjqLocationDataRule implements MqttMessageRule {
|
||||
locationInfo.put("timestamp", System.currentTimeMillis());
|
||||
|
||||
|
||||
|
||||
String locationJson = JsonUtils.toJsonString(locationInfo);
|
||||
|
||||
// 存储到Redis
|
||||
@ -171,12 +180,38 @@ public class BjqLocationDataRule implements MqttMessageRule {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 异步保存位置信息到MySQL数据库
|
||||
*
|
||||
* @param deviceImei 设备IMEI
|
||||
* @param latitude 纬度
|
||||
* @param longitude 经度
|
||||
*/
|
||||
public void asyncSaveLocationToMySQLWithFuture(String deviceImei, String latitude, String longitude) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
if (StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用服务层方法更新设备位置信息
|
||||
deviceService.updateDeviceLocationByImei(deviceImei, longitude, latitude);
|
||||
|
||||
log.info("位置信息已异步保存到MySQL: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
|
||||
} catch (Exception e) {
|
||||
log.error("异步保存位置信息到MySQL时出错: device={}, error={}", deviceImei, e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 存储设备30天历史轨迹到Redis (使用Sorted Set)
|
||||
*/
|
||||
public void storeDeviceTrajectoryWithSortedSet(String deviceImei, String locationJson) {
|
||||
try {
|
||||
String trajectoryKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + deviceImei + DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX;
|
||||
String trajectoryKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX;
|
||||
// String trajectoryKey = "device:trajectory:zset:" + deviceImei;
|
||||
// String locationJson = JsonUtils.toJsonString(locationInfo);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
@ -194,20 +229,20 @@ public class BjqLocationDataRule implements MqttMessageRule {
|
||||
log.error("存储设备轨迹到Redis(ZSet)失败: device={}, error={}", deviceImei, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Map<String, Object> buildLocationDataMap(String latitude, String longitude) {
|
||||
String[] latArr = latitude.split("\\.");
|
||||
String[] lonArr = longitude.split("\\.");
|
||||
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(11);
|
||||
intData.add(Integer.parseInt(latArr[0]));
|
||||
String str1 = latArr[1];
|
||||
intData.add(Integer.parseInt(str1.substring(0,4)));
|
||||
intData.add(Integer.parseInt(str1.substring(0, 4)));
|
||||
String str2 = lonArr[1];
|
||||
intData.add(Integer.parseInt(lonArr[0]));
|
||||
intData.add(Integer.parseInt(str2.substring(0,4)));
|
||||
|
||||
intData.add(Integer.parseInt(str2.substring(0, 4)));
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
return map;
|
||||
|
||||
@ -1,8 +1,16 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.bjq;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.core.utils.date.DurationUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import com.fuyuanshen.equipment.service.IDeviceAlarmService;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
@ -13,9 +21,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
/**
|
||||
@ -26,6 +36,10 @@ import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
@Slf4j
|
||||
public class BjqModeRule implements MqttMessageRule {
|
||||
|
||||
private final DeviceService deviceService;
|
||||
private final IDeviceAlarmService deviceAlarmService;
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return LightingCommandTypeConstants.LIGHT_MODE;
|
||||
@ -39,14 +53,36 @@ public class BjqModeRule implements MqttMessageRule {
|
||||
|
||||
String mainLightMode = convertArr[1].toString();
|
||||
String batteryRemainingTime = convertArr[2].toString();
|
||||
if(StringUtils.isNotBlank(mainLightMode)){
|
||||
if("0".equals(mainLightMode)){
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ context.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "0", Duration.ofSeconds(60*15));
|
||||
if (StringUtils.isNotBlank(mainLightMode)) {
|
||||
log.info("设备离线mainLightMode:{}", mainLightMode);
|
||||
if ("0".equals(mainLightMode)) {
|
||||
|
||||
// 设备离线
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + context.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "0");
|
||||
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
|
||||
String messageSendingValue = RedisUtils.getCacheObject(sendMessageIng);
|
||||
if ("1".equals(messageSendingValue)) {
|
||||
// 设置为故障状态
|
||||
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "2");
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("device_imei", context.getDeviceImei());
|
||||
updateWrapper.set("online_status", 2);
|
||||
deviceService.update(updateWrapper);
|
||||
RedisUtils.deleteObject(sendMessageIng);
|
||||
|
||||
// 解除告警
|
||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX;
|
||||
if (RedisUtils.getCacheObject(deviceRedisKey) != null) {
|
||||
RedisUtils.deleteObject(deviceRedisKey);
|
||||
}
|
||||
cancelAlarm(context.getDeviceImei());
|
||||
}
|
||||
}
|
||||
// 发送设备状态和位置信息到Redis
|
||||
syncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),mainLightMode);
|
||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX;
|
||||
syncSendDeviceDataToRedisWithFuture(context.getDeviceImei(), mainLightMode);
|
||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX;
|
||||
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, batteryRemainingTime);
|
||||
@ -63,13 +99,13 @@ public class BjqModeRule implements MqttMessageRule {
|
||||
*
|
||||
* @param deviceImei 设备IMEI
|
||||
*/
|
||||
public void syncSendDeviceDataToRedisWithFuture(String deviceImei,Object convertValue) {
|
||||
public void syncSendDeviceDataToRedisWithFuture(String deviceImei, Object convertValue) {
|
||||
// CompletableFuture.runAsync(() -> {
|
||||
//
|
||||
// });
|
||||
try {
|
||||
// 将设备状态信息存储到Redis中
|
||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + deviceImei + DEVICE_LIGHT_MODE_KEY_PREFIX;
|
||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + deviceImei + DEVICE_LIGHT_MODE_KEY_PREFIX;
|
||||
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, convertValue.toString());
|
||||
@ -80,5 +116,29 @@ public class BjqModeRule implements MqttMessageRule {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解除告警
|
||||
*
|
||||
* @param deviceImei 设备IMEI
|
||||
*/
|
||||
|
||||
public void cancelAlarm(String deviceImei) {
|
||||
DeviceAlarmVo deviceAlarmVo = deviceAlarmService.queryLatestByDeviceImei(deviceImei);
|
||||
DeviceAlarmBo deviceAlarmBo = new DeviceAlarmBo();
|
||||
if (deviceAlarmVo != null) {
|
||||
if (deviceAlarmVo.getFinishTime() == null) {
|
||||
BeanUtil.copyProperties(deviceAlarmVo, deviceAlarmBo);
|
||||
deviceAlarmBo.setFinishTime(new Date());
|
||||
String durationBetween = DurationUtils.getDurationBetween(deviceAlarmVo.getStartTime(), deviceAlarmBo.getFinishTime());
|
||||
deviceAlarmBo.setDurationTime(durationBetween);
|
||||
// 0已处理,1未处理
|
||||
deviceAlarmBo.setTreatmentState(0);
|
||||
// 告警状态,0 解除告警, 1 告警中
|
||||
deviceAlarmBo.setAlarmState(0);
|
||||
deviceAlarmService.updateByBo(deviceAlarmBo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -43,17 +43,28 @@ public class BjqSendMessageRule implements MqttMessageRule {
|
||||
public void execute(MqttRuleContext context) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
|
||||
try {
|
||||
Byte val2 = (Byte) context.getConvertArr()[1];
|
||||
|
||||
// Byte val2 = (Byte) context.getConvertArr()[1];
|
||||
String val2Str = context.getConvertArr()[1].toString();
|
||||
int val2 = Integer.parseInt(val2Str);
|
||||
System.out.println("收到设备信息命令:"+val2);
|
||||
if (val2 == 100) {
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
return;
|
||||
}
|
||||
|
||||
if(val2==200){
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
|
||||
RedisUtils.deleteObject(sendMessageIng);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":app_send_message_data");
|
||||
if (StringUtils.isEmpty(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, (val2 - 1), 512);
|
||||
log.info("第{}块数据大小: {} 字节", val2, specificChunk.length);
|
||||
@ -61,7 +72,7 @@ public class BjqSendMessageRule implements MqttMessageRule {
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(6);
|
||||
intData.add((int) val2);
|
||||
intData.add(val2);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
|
||||
@ -62,6 +62,14 @@ public class XinghanBootLogoRule implements MqttMessageRule {
|
||||
String respText = payload.getStaPicTrans();
|
||||
log.warn("设备上报LOGO:{}", respText);
|
||||
|
||||
// --- 去重 START ---
|
||||
String dedupKey = "xd:MSG:LOGO:" + ctx.getDeviceImei() + ":" + respText;
|
||||
boolean first = RedisUtils.setObjectIfAbsent(dedupKey, "1", Duration.ofSeconds(3));
|
||||
if (!first) {
|
||||
log.warn("重复消息丢弃 {}", dedupKey);
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. great! —— 成功标记
|
||||
if ("great!".equalsIgnoreCase(respText)) {
|
||||
RedisUtils.setCacheObject(functionAccessKey,
|
||||
|
||||
@ -1,33 +1,45 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.xinghan;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
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.bo.DeviceAlarmBo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceAlarmMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import com.fuyuanshen.equipment.service.IDeviceAlarmService;
|
||||
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.base.MqttXinghanJson;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.XingHanCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import com.fuyuanshen.web.enums.AlarmTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
@ -57,6 +69,9 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
private final IDeviceAlarmService deviceAlarmService;
|
||||
private final DeviceService deviceService;
|
||||
private final DeviceAlarmMapper deviceAlarmMapper;
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
@ -65,7 +80,7 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
// Latitude, longitude
|
||||
//主灯档位,激光灯档位,电量百分比,充电状态,电池剩余续航时间
|
||||
MqttXinghanJson deviceStatus = objectMapper.convertValue(context.getPayloadDict(), MqttXinghanJson.class);
|
||||
|
||||
deviceStatus.setBatteryPercentage(deviceStatus.getStaPowerPercent().toString());
|
||||
// 发送设备状态和位置信息到Redis
|
||||
asyncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),deviceStatus);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
@ -99,12 +114,141 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
// 异步发送经纬度到Redis
|
||||
asyncSendLocationToRedisWithFuture(deviceImei, deviceStatus.getStalatitude(), deviceStatus.getStalongitude());
|
||||
|
||||
// 保存报警信息
|
||||
saveAlarm(deviceImei,deviceStatus);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("异步发送设备信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 入口:保存报警(SOS 与 Shake 完全独立)
|
||||
*/
|
||||
public void saveAlarm(String deviceImei, MqttXinghanJson status) {
|
||||
int sos = Optional.ofNullable(status.getStaSOSGrade()).orElse(0);
|
||||
// 1. 处理 SOS 报警
|
||||
handleSingleAlarm(deviceImei,
|
||||
sos > 0,
|
||||
AlarmTypeEnum.SOS);
|
||||
int shake = Optional.ofNullable(status.getStaShakeBit()).orElse(0);
|
||||
// 2. 处理 Shake 报警
|
||||
handleSingleAlarm(deviceImei,
|
||||
shake > 0,
|
||||
AlarmTypeEnum.SHAKE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用:对单个报警源的“开始/结束”生命周期管理
|
||||
*/
|
||||
private void handleSingleAlarm(String deviceImei, boolean nowAlarming, AlarmTypeEnum type) {
|
||||
String redisKey = buildAlarmRedisKey(deviceImei, type);
|
||||
|
||||
Long alarmId = RedisUtils.getCacheObject(redisKey);
|
||||
|
||||
String lockKey = redisKey + ":lock"; // 分布式锁 key
|
||||
RedissonClient client = RedisUtils.getClient(); // 唯一用到的“旧”入口
|
||||
RLock lock = client.getLock(lockKey);
|
||||
|
||||
// ---------- 情况 1:当前正在报警 ----------
|
||||
if (nowAlarming) {
|
||||
// 已存在未结束报警 -> 什么都不做(同一条报警)
|
||||
if (alarmId != null) {
|
||||
// key 还在 -> 同一条报警,只续期
|
||||
RedisUtils.setCacheObject(redisKey, alarmId, Duration.ofMinutes(10));
|
||||
return;
|
||||
}
|
||||
// 需要新建,抢锁
|
||||
boolean locked = false;
|
||||
try {
|
||||
locked = lock.tryLock(3, TimeUnit.SECONDS); // 最多等 3 s
|
||||
if (!locked) { // 抢不到直接放弃
|
||||
return;
|
||||
}
|
||||
// 锁内二次校验(double-check)
|
||||
alarmId = RedisUtils.getCacheObject(redisKey);
|
||||
if (alarmId != null) {
|
||||
return; // 并发线程已建好
|
||||
}
|
||||
|
||||
// 不存在 -> 新建
|
||||
DeviceAlarmBo bo = createAlarmBo(deviceImei, type);
|
||||
if (bo == null){
|
||||
return;
|
||||
}
|
||||
deviceAlarmService.insertByBo(bo);
|
||||
RedisUtils.setCacheObject(redisKey, bo.getId(), Duration.ofMinutes(10)); // 5分钟后结束过期
|
||||
}catch (InterruptedException ignore) {
|
||||
// 立即中断并退出,禁止继续往下走
|
||||
Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
if (locked && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// ---------- 情况 2:当前不报警 ----------
|
||||
if (alarmId != null) {
|
||||
// 结束它
|
||||
finishAlarm(alarmId);
|
||||
RedisUtils.deleteObject(redisKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束报警:写库
|
||||
*/
|
||||
private void finishAlarm(Long alarmId) {
|
||||
DeviceAlarmVo vo = deviceAlarmService.queryById(alarmId);
|
||||
if (vo == null || vo.getTreatmentState() == 0) {
|
||||
return; // 已处理或已被删
|
||||
}
|
||||
DeviceAlarmBo bo = BeanUtil.toBean(vo, DeviceAlarmBo.class);
|
||||
bo.setFinishTime(new Date());
|
||||
bo.setDurationTime(DurationUtils.getDurationBetween(vo.getStartTime(), bo.getFinishTime()));
|
||||
bo.setTreatmentState(0); // 已处理
|
||||
deviceAlarmService.updateByBo(bo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建报警 Bo
|
||||
*/
|
||||
private DeviceAlarmBo createAlarmBo(String deviceImei, AlarmTypeEnum type) {
|
||||
Device device = deviceService.selectDeviceByImei(deviceImei);
|
||||
if (device == null) {
|
||||
return null;
|
||||
}
|
||||
DeviceAlarmBo bo = new DeviceAlarmBo();
|
||||
bo.setDeviceId(device.getId());
|
||||
bo.setDeviceImei(deviceImei);
|
||||
bo.setDeviceAction(2); // 自动报警
|
||||
bo.setStartTime(new Date());
|
||||
bo.setTreatmentState(1); // 未处理
|
||||
bo.setTenantId(device.getTenantId());
|
||||
|
||||
// 报警内容
|
||||
bo.setContent("自动报警:" + type.getDesc());
|
||||
|
||||
// 位置
|
||||
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"));
|
||||
}
|
||||
return bo;
|
||||
}
|
||||
|
||||
/**
|
||||
* key 构建
|
||||
*/
|
||||
private String buildAlarmRedisKey(String deviceImei, AlarmTypeEnum type) {
|
||||
return StrUtil.format("{}{}{}{}:alarm_id",
|
||||
GLOBAL_REDIS_KEY, DEVICE_KEY_PREFIX, deviceImei, type.getSuffix());
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步发送位置信息到Redis(使用CompletableFuture)
|
||||
*
|
||||
|
||||
@ -55,6 +55,13 @@ public class XinghanSendAlarmMessageRule implements MqttMessageRule {
|
||||
|
||||
String respText = payload.getStaBreakNews();
|
||||
log.info("设备上报紧急通知握手: {} ", respText);
|
||||
// --- 去重 START ---
|
||||
String dedupKey = "xd:ALARM:dedup:" + ctx.getDeviceImei() + ":" + respText;
|
||||
boolean first = RedisUtils.setObjectIfAbsent(dedupKey, "1", Duration.ofSeconds(3));
|
||||
if (!first) {
|
||||
log.warn("重复消息丢弃 {}", dedupKey);
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. cover! —— 成功标记
|
||||
if ("cover!".equalsIgnoreCase(respText)) {
|
||||
|
||||
@ -17,10 +17,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
@ -42,6 +39,12 @@ public class XinghanSendMsgRule implements MqttMessageRule {
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
|
||||
|
||||
// 三种等价的写法
|
||||
Integer[] array1 = list.toArray(new Integer[0]);
|
||||
Integer[] array2 = list.toArray(size -> new Integer[size]);
|
||||
|
||||
return XingHanCommandTypeConstants.XingHan_ESEND_MSG;
|
||||
}
|
||||
|
||||
@ -55,6 +58,14 @@ public class XinghanSendMsgRule implements MqttMessageRule {
|
||||
String respText = payload.getStaTexTrans();
|
||||
log.info("设备上报人员信息: {} ", respText);
|
||||
|
||||
// --- 去重 START ---
|
||||
String dedupKey = "xd:MSG:dedup:" + ctx.getDeviceImei() + ":" + respText;
|
||||
boolean first = RedisUtils.setObjectIfAbsent(dedupKey, "1", Duration.ofSeconds(3));
|
||||
if (!first) {
|
||||
log.warn("重复消息丢弃 {}", dedupKey);
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. genius! —— 成功标记
|
||||
if ("genius!".equalsIgnoreCase(respText)) {
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
|
||||
@ -0,0 +1,106 @@
|
||||
package com.fuyuanshen.global.mqtt.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessage;
|
||||
|
||||
/**
|
||||
* 通用IoT设备MQTT协议服务接口
|
||||
* 遵循统一的MQTT通信协议规范
|
||||
*/
|
||||
public interface IotMqttService {
|
||||
|
||||
/**
|
||||
* 构建下发指令主题
|
||||
*
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @return 指令主题
|
||||
*/
|
||||
String buildCommandTopic(String tenantCode, Long deviceType, String imei);
|
||||
|
||||
/**
|
||||
* 构建响应数据主题
|
||||
*
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @return 响应主题
|
||||
*/
|
||||
String buildStatusTopic(String tenantCode, String deviceType, String imei);
|
||||
|
||||
/**
|
||||
* 构建设备上报数据主题
|
||||
*
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @return 上报主题
|
||||
*/
|
||||
String buildReportTopic(String tenantCode, String deviceType, String imei);
|
||||
|
||||
/**
|
||||
* 发送指令到设备
|
||||
*
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param message 指令消息 (JSON格式)
|
||||
*/
|
||||
void sendCommand(String tenantCode, Long deviceType, String imei, MqttMessage message);
|
||||
|
||||
/**
|
||||
* 发送响应消息到设备
|
||||
*
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param message 响应消息 (JSON格式)
|
||||
*/
|
||||
void sendStatus(String tenantCode, String deviceType, String imei, JSONObject message);
|
||||
|
||||
/**
|
||||
* 发送设备上报数据的确认消息
|
||||
*
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param message 确认消息 (JSON格式)
|
||||
*/
|
||||
void sendReportAck(String tenantCode, String deviceType, String imei, JSONObject message);
|
||||
|
||||
/**
|
||||
* 处理设备上报的单个传感器数据
|
||||
*
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param sensor 传感器名称
|
||||
* @param value 传感器值
|
||||
* @param timestamp 时间戳
|
||||
*/
|
||||
void handleSingleReport(String tenantCode, String deviceType, String imei,
|
||||
String sensor, Object value, Long timestamp);
|
||||
|
||||
/**
|
||||
* 处理设备上报的批量传感器数据
|
||||
*
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param batchData 批量数据
|
||||
* @param timestamp 时间戳
|
||||
*/
|
||||
void handleBatchReport(String tenantCode, String deviceType, String imei,
|
||||
JSONObject batchData, Long timestamp);
|
||||
|
||||
/**
|
||||
* 处理设备对指令的响应
|
||||
*
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param message 响应消息 (JSON格式)
|
||||
*/
|
||||
void handleCommandResponse(String tenantCode, String deviceType, String imei, JSONObject message);
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.fuyuanshen.global.mqtt.service;
|
||||
|
||||
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessage;
|
||||
|
||||
/**
|
||||
* MQTT消息处理服务接口
|
||||
*/
|
||||
public interface MqttMessageService {
|
||||
|
||||
/**
|
||||
* 处理下发指令的响应消息
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param message 响应消息
|
||||
*/
|
||||
void handleCommandResponse(String tenantCode, String deviceType, String imei, MqttMessage message);
|
||||
|
||||
/**
|
||||
* 处理设备主动上报的数据
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param message 上报消息
|
||||
*/
|
||||
void handleDeviceReport(String tenantCode, String deviceType, String imei, MqttMessage message);
|
||||
|
||||
/**
|
||||
* 发送指令到设备
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param message 指令消息
|
||||
*/
|
||||
void sendCommand(String tenantCode, String deviceType, String imei, MqttMessage message);
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
package com.fuyuanshen.global.mqtt.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessage;
|
||||
import com.fuyuanshen.global.mqtt.service.IotMqttService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 通用IoT设备MQTT协议服务实现类
|
||||
* 遵循统一的MQTT通信协议规范
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class IotMqttServiceImpl implements IotMqttService {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
// MQTT主题前缀
|
||||
private static final String COMMAND_PREFIX = "command";
|
||||
private static final String STATUS_PREFIX = "status";
|
||||
private static final String REPORT_PREFIX = "report";
|
||||
|
||||
@Override
|
||||
public String buildCommandTopic(String tenantCode, Long deviceType, String imei) {
|
||||
return String.format("%s/%s/%s/%s", COMMAND_PREFIX, tenantCode, deviceType, imei);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildStatusTopic(String tenantCode, String deviceType, String imei) {
|
||||
return String.format("%s/%s/%s/%s", STATUS_PREFIX, tenantCode, deviceType, imei);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildReportTopic(String tenantCode, String deviceType, String imei) {
|
||||
return String.format("%s/%s/%s/%s", REPORT_PREFIX, tenantCode, deviceType, imei);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCommand(String tenantCode, Long deviceType, String imei, MqttMessage message) {
|
||||
String topic = buildCommandTopic(tenantCode, deviceType, imei);
|
||||
String payload = JSON.toJSONString(message);
|
||||
sendMqttMessage(topic, 1, payload);
|
||||
log.info("发送指令到设备: topic={}, payload={}", topic, payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStatus(String tenantCode, String deviceType, String imei, JSONObject message) {
|
||||
String topic = buildStatusTopic(tenantCode, deviceType, imei);
|
||||
String payload = message.toJSONString();
|
||||
sendMqttMessage(topic, 1, payload);
|
||||
log.info("发送响应消息到设备: topic={}, payload={}", topic, payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendReportAck(String tenantCode, String deviceType, String imei, JSONObject message) {
|
||||
String topic = buildReportTopic(tenantCode, deviceType, imei);
|
||||
String payload = message.toJSONString();
|
||||
sendMqttMessage(topic, 1, payload);
|
||||
log.info("发送设备上报数据确认消息: topic={}, payload={}", topic, payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSingleReport(String tenantCode, String deviceType, String imei,
|
||||
String sensor, Object value, Long timestamp) {
|
||||
log.info("处理设备上报的单个传感器数据: tenantCode={}, deviceType={}, imei={}, sensor={}, value={}, timestamp={}",
|
||||
tenantCode, deviceType, imei, sensor, value, timestamp);
|
||||
|
||||
// TODO: 实现具体的业务逻辑,如更新设备状态、存储传感器数据等
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleBatchReport(String tenantCode, String deviceType, String imei,
|
||||
JSONObject batchData, Long timestamp) {
|
||||
log.info("处理设备上报的批量传感器数据: tenantCode={}, deviceType={}, imei={}, batchData={}, timestamp={}",
|
||||
tenantCode, deviceType, imei, JSON.toJSONString(batchData), timestamp);
|
||||
|
||||
// TODO: 实现具体的业务逻辑,如批量更新设备状态、存储传感器数据等
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommandResponse(String tenantCode, String deviceType, String imei, JSONObject message) {
|
||||
log.info("处理设备对指令的响应: tenantCode={}, deviceType={}, imei={}, message={}",
|
||||
tenantCode, deviceType, imei, JSON.toJSONString(message));
|
||||
|
||||
// TODO: 实现具体的业务逻辑,如更新指令执行状态等
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过反射方式发送MQTT消息
|
||||
*
|
||||
* @param topic 主题
|
||||
* @param qos 服务质量等级
|
||||
* @param payload 消息内容
|
||||
*/
|
||||
private void sendMqttMessage(String topic, int qos, String payload) {
|
||||
try {
|
||||
Object mqttGateway = applicationContext.getBean("mqttGateway");
|
||||
Method sendMethod = mqttGateway.getClass().getMethod("sendMsgToMqtt", String.class, int.class, String.class);
|
||||
sendMethod.invoke(mqttGateway, topic, qos, payload);
|
||||
} catch (Exception e) {
|
||||
log.error("发送MQTT消息失败: topic={}, payload={}", topic, payload, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,163 @@
|
||||
package com.fuyuanshen.global.mqtt.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessage;
|
||||
import com.fuyuanshen.global.mqtt.base.SensorData;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.service.MqttMessageService;
|
||||
import com.fuyuanshen.global.mqtt.utils.MqttTopicUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* MQTT消息处理服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MqttMessageServiceImpl implements MqttMessageService {
|
||||
|
||||
private final MqttGateway mqttGateway;
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
|
||||
public MqttMessageServiceImpl(MqttGateway mqttGateway, DeviceMapper deviceMapper) {
|
||||
this.mqttGateway = mqttGateway;
|
||||
this.deviceMapper = deviceMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理下发指令的响应消息
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param message 响应消息
|
||||
*/
|
||||
@Override
|
||||
public void handleCommandResponse(String tenantCode, String deviceType, String imei, MqttMessage message) {
|
||||
log.info("处理设备响应消息: tenantCode={}, deviceType={}, imei={}, message={}",
|
||||
tenantCode, deviceType, imei, JSON.toJSONString(message));
|
||||
|
||||
// 根据requestId更新指令执行状态
|
||||
// TODO: 实现具体的业务逻辑,比如更新指令执行结果等
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理设备主动上报的数据
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param message 上报消息
|
||||
*/
|
||||
@Override
|
||||
public void handleDeviceReport(String tenantCode, String deviceType, String imei, MqttMessage message) {
|
||||
log.info("处理设备上报数据: tenantCode={}, deviceType={}, imei={}, message={}",
|
||||
tenantCode, deviceType, imei, JSON.toJSONString(message));
|
||||
|
||||
// 查找设备
|
||||
Device device = deviceMapper.selectDeviceByImei(imei);
|
||||
if (device == null) {
|
||||
log.warn("未找到对应设备: imei={}", imei);
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理批量数据上报
|
||||
if (message.getBatch() != null && !message.getBatch().isEmpty()) {
|
||||
for (int i = 0; i < message.getBatch().size(); i++) {
|
||||
processSensorData(device, message.getBatch().get(i));
|
||||
}
|
||||
}
|
||||
// 处理单个数据上报
|
||||
else if (message.getData() != null) {
|
||||
// 如果data是一个SensorData对象,则处理它
|
||||
// 这里可以根据实际的数据结构做相应处理
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送指令到设备
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @param message 指令消息
|
||||
*/
|
||||
@Override
|
||||
public void sendCommand(String tenantCode, String deviceType, String imei, MqttMessage message) {
|
||||
// 构建下发指令主题
|
||||
String topic = MqttTopicUtils.buildCommandTopic(tenantCode, deviceType, imei);
|
||||
|
||||
// 设置时间戳
|
||||
if (message.getTimestamp() == null) {
|
||||
message.setTimestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
// 发送消息到MQTT
|
||||
String payload = JSON.toJSONString(message);
|
||||
mqttGateway.sendMsgToMqtt(topic, 1, payload);
|
||||
|
||||
log.info("发送指令到设备: topic={}, payload={}", topic, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理传感器数据
|
||||
* @param device 设备对象
|
||||
* @param sensorData 传感器数据
|
||||
*/
|
||||
private void processSensorData(Device device, SensorData sensorData) {
|
||||
log.info("处理传感器数据: deviceId={}, sensor={}, value={}",
|
||||
device.getId(), sensorData.getSensor(), sensorData.getValue());
|
||||
|
||||
String sensor = sensorData.getSensor();
|
||||
Object value = sensorData.getValue();
|
||||
|
||||
// 根据不同的传感器类型处理数据
|
||||
switch (sensor) {
|
||||
case "mainLightMode":
|
||||
// 处理主灯模式数据
|
||||
updateDeviceMainLightMode(device, value);
|
||||
break;
|
||||
case "mainLightBrightness":
|
||||
// 处理主灯亮度数据
|
||||
updateDeviceMainLightBrightness(device, value);
|
||||
break;
|
||||
case "batteryPercent":
|
||||
// 处理电池电量数据
|
||||
updateDeviceBatteryPercent(device, value);
|
||||
break;
|
||||
default:
|
||||
log.warn("未知的传感器类型: sensor={}", sensor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设备主灯模式
|
||||
* @param device 设备对象
|
||||
* @param value 主灯模式值
|
||||
*/
|
||||
private void updateDeviceMainLightMode(Device device, Object value) {
|
||||
// TODO: 实现具体的业务逻辑
|
||||
log.info("更新设备主灯模式: deviceId={}, value={}", device.getId(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设备主灯亮度
|
||||
* @param device 设备对象
|
||||
* @param value 主灯亮度值
|
||||
*/
|
||||
private void updateDeviceMainLightBrightness(Device device, Object value) {
|
||||
// TODO: 实现具体的业务逻辑
|
||||
log.info("更新设备主灯亮度: deviceId={}, value={}", device.getId(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设备电池电量
|
||||
* @param device 设备对象
|
||||
* @param value 电池电量值
|
||||
*/
|
||||
private void updateDeviceBatteryPercent(Device device, Object value) {
|
||||
// TODO: 实现具体的业务逻辑
|
||||
log.info("更新设备电池电量: deviceId={}, value={}", device.getId(), value);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package com.fuyuanshen.global.mqtt.utils;
|
||||
|
||||
import com.fuyuanshen.global.mqtt.base.MqttTopicInfo;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* MQTT主题处理工具类
|
||||
*/
|
||||
@UtilityClass
|
||||
public class MqttTopicUtils {
|
||||
|
||||
public static final String COMMAND_PREFIX = "command";
|
||||
public static final String STATUS_PREFIX = "status";
|
||||
public static final String REPORT_PREFIX = "report";
|
||||
|
||||
/**
|
||||
* 构建下发指令主题
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @return 主题字符串
|
||||
*/
|
||||
public static String buildCommandTopic(String tenantCode, String deviceType, String imei) {
|
||||
return String.format("%s/%s/%s/%s", COMMAND_PREFIX, tenantCode, deviceType, imei);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建响应数据主题
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @return 主题字符串
|
||||
*/
|
||||
public static String buildStatusTopic(String tenantCode, String deviceType, String imei) {
|
||||
return String.format("%s/%s/%s/%s", STATUS_PREFIX, tenantCode, deviceType, imei);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建设备上报数据主题
|
||||
* @param tenantCode 租户编码
|
||||
* @param deviceType 设备类型
|
||||
* @param imei 设备IMEI
|
||||
* @return 主题字符串
|
||||
*/
|
||||
public static String buildReportTopic(String tenantCode, String deviceType, String imei) {
|
||||
return String.format("%s/%s/%s/%s", REPORT_PREFIX, tenantCode, deviceType, imei);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析MQTT主题
|
||||
* @param topic 主题字符串
|
||||
* @return 主题信息对象
|
||||
*/
|
||||
public static MqttTopicInfo parseTopic(String topic) {
|
||||
if (topic == null || topic.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] parts = topic.split("/");
|
||||
if (parts.length != 4) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MqttTopicInfo info = new MqttTopicInfo();
|
||||
info.setOperation(parts[0]);
|
||||
info.setTenantCode(parts[1]);
|
||||
info.setDeviceType(parts[2]);
|
||||
info.setImei(parts[3]);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
@ -98,21 +98,30 @@ public class MqttMessageConsumer {
|
||||
String threadName = Thread.currentThread().getName();
|
||||
try {
|
||||
log.info("业务处理线程 {} 开始处理消息: {}", threadName, message);
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ message + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
String deviceOnlineStatusRedis = RedisUtils.getCacheObject(deviceOnlineStatusRedisKey);
|
||||
if(StringUtils.isBlank(deviceOnlineStatusRedis)){
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("device_imei", message)
|
||||
.set("online_status", 1);
|
||||
deviceMapper.update(updateWrapper);
|
||||
}
|
||||
// String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ message + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
// String deviceOnlineStatusRedis = RedisUtils.getCacheObject(deviceOnlineStatusRedisKey);
|
||||
// if(StringUtils.isBlank(deviceOnlineStatusRedis)){
|
||||
// UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
// updateWrapper.eq("device_imei", message)
|
||||
// .set("online_status", 1);
|
||||
// deviceMapper.update(updateWrapper);
|
||||
// }
|
||||
// QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.eq("device_imei", message);
|
||||
// queryWrapper.eq("online_status", 1);
|
||||
// Long count = deviceMapper.selectCount(queryWrapper);
|
||||
// if(count == 0){
|
||||
//
|
||||
// UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
// updateWrapper.eq("device_imei", message)
|
||||
// .eq("online_status", 0)
|
||||
// .set("online_status", 1);
|
||||
// deviceMapper.update(updateWrapper);
|
||||
// }
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("device_imei", message)
|
||||
.in("online_status", 0,2)
|
||||
.set("online_status", 1);
|
||||
int update = deviceMapper.update(updateWrapper);
|
||||
// 模拟业务处理耗时
|
||||
// Thread.sleep(200);
|
||||
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
package com.fuyuanshen.global.queue;// ScheduledTasks.java
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.vo.OnlineStatusVo;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
@Component
|
||||
public class OnlineStatusTask {
|
||||
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
// 使用cron表达式,每分钟的第0秒执行
|
||||
@Scheduled(cron = "0 */3 * * * ?")
|
||||
public void cronTask() {
|
||||
List<OnlineStatusVo> onlineStatusVos = deviceMapper.queryOnlineStatusList();
|
||||
onlineStatusVos.forEach(item -> {
|
||||
String onlineStatusKey = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||
String status = RedisUtils.getCacheObject(onlineStatusKey);
|
||||
if(StringUtils.isBlank(status) || "0".equals(status)){
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", item.getId());
|
||||
updateWrapper.set("online_status", 0);
|
||||
deviceMapper.update(updateWrapper);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -63,10 +63,6 @@ import java.util.Map;
|
||||
@RequestMapping("/mp")
|
||||
public class MPAuthController {
|
||||
|
||||
private final AppLoginService loginService;
|
||||
private final SysRegisterService registerService;
|
||||
private final ISysConfigService configService;
|
||||
private final ISysTenantService tenantService;
|
||||
private final ISysClientService clientService;
|
||||
private final MPAuthService mpAuthService;
|
||||
private final MPService mpService;
|
||||
@ -74,7 +70,7 @@ public class MPAuthController {
|
||||
|
||||
@Operation(summary = "小程序登录授权")
|
||||
@PostMapping(value = "/login")
|
||||
public ResponseEntity<Object> login(@RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception {
|
||||
public ResponseEntity<Object> login(@RequestBody AuthUserDto authUser) throws Exception {
|
||||
|
||||
Long phoneNumber = authUser.getPhoneNumber();
|
||||
// 判断小程序用户是否存在,不存在创建
|
||||
|
||||
@ -60,9 +60,9 @@ import java.util.function.Supplier;
|
||||
@Service
|
||||
public class MPAuthService {
|
||||
|
||||
private final ISysUserService userService;
|
||||
private final AppUserService appUserService;
|
||||
|
||||
|
||||
/**
|
||||
* 小程序注册
|
||||
*/
|
||||
@ -128,6 +128,7 @@ public class MPAuthService {
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建登录用户
|
||||
*/
|
||||
@ -160,5 +161,4 @@ public class MPAuthService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -10,11 +10,8 @@ import org.springframework.stereotype.Service;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
||||
|
||||
public interface MPService {
|
||||
|
||||
|
||||
/**
|
||||
* 获取小程序用户信息
|
||||
*
|
||||
@ -23,4 +20,5 @@ public interface MPService {
|
||||
UserApp getMpUser(Long phoneNumber);
|
||||
|
||||
UserApp loadUserByUsername(String username);
|
||||
|
||||
}
|
||||
|
||||
@ -8,5 +8,4 @@ package com.fuyuanshen.mp.service.impl;
|
||||
|
||||
public class MPAuthServiceImpl {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -19,11 +19,9 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class MPServiceImpl implements MPService {
|
||||
|
||||
|
||||
private final AppUserService appUserService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取小程序用户信息
|
||||
*
|
||||
|
||||
@ -51,6 +51,7 @@ public class CaptchaController {
|
||||
private final CaptchaProperties captchaProperties;
|
||||
private final MailProperties mailProperties;
|
||||
|
||||
|
||||
/**
|
||||
* 短信验证码
|
||||
*
|
||||
|
||||
@ -0,0 +1,142 @@
|
||||
package com.fuyuanshen.web.controller;
|
||||
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.equipment.domain.vo.*;
|
||||
import com.fuyuanshen.equipment.service.IDeviceAlarmService;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import com.fuyuanshen.equipment.service.IWeatherService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 大屏数据
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-09-27 08:42
|
||||
*/
|
||||
@Tag(name = "大屏数据", description = "大屏数据")
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/largeScreen")
|
||||
public class LargeScreenController {
|
||||
|
||||
private final IDeviceAlarmService deviceAlarmService;
|
||||
private final DeviceService deviceService;
|
||||
private final IWeatherService weatherService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备总览信息
|
||||
* 包含设备总数、在线设备数量、设备型号数量
|
||||
*/
|
||||
@GetMapping("/getDeviceOverview")
|
||||
public R<DeviceOverviewVo> getDeviceOverview() {
|
||||
return R.ok(deviceService.getDeviceOverview());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 实时报警信息
|
||||
* RealtimeAlarm
|
||||
*/
|
||||
@GetMapping("/getRealtimeAlarm")
|
||||
public R<List<DeviceAlarmVo>> getRealtimeAlarm() {
|
||||
return R.ok(deviceAlarmService.getRealtimeAlarm());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取报警统计数据
|
||||
* 包括正在报警数量、报警总数、已处理报警数量
|
||||
*/
|
||||
@GetMapping("/getAlarmStatistics")
|
||||
public R<AlarmStatisticsVo> getAlarmStatistics() {
|
||||
return R.ok(deviceAlarmService.getAlarmStatistics());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取最近一年每月告警统计数据
|
||||
*/
|
||||
@GetMapping("/getMonthlyAlarmStatistics")
|
||||
public R<MonthlyAlarmStatisticsVo> getMonthlyAlarmStatistics() {
|
||||
return R.ok(deviceAlarmService.getMonthlyAlarmStatistics());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备通讯方式统计数据
|
||||
* 包含通讯方式名称、设备总数、异常设备数
|
||||
*/
|
||||
@GetMapping("/getDeviceCommunicationModeStatistics")
|
||||
public R<List<DeviceCommunicationModeStatisticsVo>> getDeviceCommunicationModeStatistics() {
|
||||
return R.ok(deviceService.getDeviceCommunicationModeStatistics());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备使用频次统计数据
|
||||
*
|
||||
* @param days 天数(近一个月传30,近半年传180)
|
||||
*/
|
||||
@GetMapping("/getDeviceUsageFrequency")
|
||||
public R<List<DeviceUsageFrequencyVo>> getDeviceUsageFrequency(@RequestParam int days) {
|
||||
return R.ok(deviceService.getDeviceUsageFrequency(days));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据条件查询设备位置信息
|
||||
*
|
||||
* @param groupId 设备分组ID
|
||||
* @param deviceType 设备类型
|
||||
* @param deviceImei 设备IMEI
|
||||
* @return 设备位置信息列表
|
||||
*/
|
||||
@GetMapping("/getDeviceLocationInfo")
|
||||
public R<List<DeviceLocationVo>> getDeviceLocationInfo(
|
||||
@RequestParam(required = false) Long groupId,
|
||||
@RequestParam(required = false) Long deviceType,
|
||||
@RequestParam(required = false) String deviceImei) {
|
||||
return R.ok(deviceService.getDeviceLocationInfo(groupId, deviceType, deviceImei));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据经纬度获取天气信息
|
||||
*
|
||||
* @param latitude 纬度
|
||||
* @param longitude 经度
|
||||
* @return 天气信息
|
||||
*/
|
||||
@GetMapping("/weather")
|
||||
public R<WeatherInfoVo> getWeatherInfo(
|
||||
@RequestParam Double latitude,
|
||||
@RequestParam Double longitude) {
|
||||
if (latitude == null || longitude == null) {
|
||||
return R.fail("经纬度参数不能为空");
|
||||
}
|
||||
|
||||
// 简单的经纬度范围校验
|
||||
if (latitude < -90 || latitude > 90 || longitude < -180 || longitude > 180) {
|
||||
return R.fail("经纬度参数范围不正确");
|
||||
}
|
||||
|
||||
WeatherInfoVo weatherInfo = weatherService.getWeatherByCoordinates(latitude, longitude);
|
||||
if (weatherInfo != null) {
|
||||
return R.ok(weatherInfo);
|
||||
} else {
|
||||
return R.fail("获取天气信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -28,6 +28,7 @@ public class DeviceBJQController extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
@ -35,10 +36,11 @@ public class DeviceBJQController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDeviceDetailVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
@ -74,7 +76,7 @@ public class DeviceBJQController extends BaseController {
|
||||
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if(file.getSize()>1024*1024*2){
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.uploadDeviceLogo(bo);
|
||||
@ -82,6 +84,22 @@ public class DeviceBJQController extends BaseController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量上传设备logo图片
|
||||
*/
|
||||
@PostMapping("/batchUploadLogo")
|
||||
@FunctionAccessAnnotation("batchUploadLogo")
|
||||
public R<Void> batchUploadLogo(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.batchUploadLogo(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
||||
@ -96,7 +114,6 @@ public class DeviceBJQController extends BaseController {
|
||||
|
||||
/**
|
||||
* 灯光亮度设置
|
||||
*
|
||||
*/
|
||||
// @FunctionAccessAnnotation("lightBrightnessSettings")
|
||||
@PostMapping("/lightBrightnessSettings")
|
||||
@ -107,7 +124,6 @@ public class DeviceBJQController extends BaseController {
|
||||
|
||||
/**
|
||||
* 激光模式设置
|
||||
*
|
||||
*/
|
||||
@PostMapping("/laserModeSettings")
|
||||
// @FunctionAccessAnnotation("laserModeSettings")
|
||||
|
||||
@ -29,7 +29,7 @@ import java.util.Map;
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/device")
|
||||
public class DeviceControlCenterController extends BaseController {
|
||||
public class DeviceControlCenterController extends BaseController {
|
||||
|
||||
private final DeviceBizService appDeviceService;
|
||||
|
||||
@ -42,6 +42,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return appDeviceService.queryWebDeviceList(bo, pageQuery);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 绑定设备
|
||||
*/
|
||||
@ -59,6 +60,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return toAjax(appDeviceService.unBindDevice(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备类型列表
|
||||
*/
|
||||
@ -68,6 +70,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return R.ok(typeList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重命名设备
|
||||
*
|
||||
@ -100,7 +103,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/instructionRecord")
|
||||
public TableDataInfo<InstructionRecordVo> getInstructionRecord(InstructionRecordDto dto, PageQuery pageQuery) {
|
||||
return appDeviceService.getInstructionRecord(dto,pageQuery);
|
||||
return appDeviceService.getInstructionRecord(dto, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +114,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
pageQuery.setPageNum(1);
|
||||
pageQuery.setPageSize(2000);
|
||||
TableDataInfo<InstructionRecordVo> instructionRecord = appDeviceService.getInstructionRecord(dto, pageQuery);
|
||||
if(instructionRecord.getRows() == null){
|
||||
if (instructionRecord.getRows() == null) {
|
||||
return;
|
||||
}
|
||||
ExcelUtil.exportExcel(instructionRecord.getRows(), "设备操作日志", InstructionRecordVo.class, response);
|
||||
@ -123,7 +126,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/locationHistory")
|
||||
public TableDataInfo<LocationHistoryVo> getLocationHistory(InstructionRecordDto dto, PageQuery pageQuery) {
|
||||
return appDeviceService.getLocationHistory(dto,pageQuery);
|
||||
return appDeviceService.getLocationHistory(dto, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,7 +137,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
pageQuery.setPageNum(1);
|
||||
pageQuery.setPageSize(2000);
|
||||
TableDataInfo<LocationHistoryVo> result = appDeviceService.getLocationHistory(dto, pageQuery);
|
||||
if(result.getRows() == null){
|
||||
if (result.getRows() == null) {
|
||||
return;
|
||||
}
|
||||
ExcelUtil.exportExcel(result.getRows(), "历史轨迹记录", LocationHistoryVo.class, response);
|
||||
@ -147,4 +150,5 @@ public class DeviceControlCenterController extends BaseController {
|
||||
public R<List<LocationHistoryDetailVo>> getLocationHistoryDetail(Long id) {
|
||||
return R.ok(appDeviceService.getLocationHistoryDetail(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ public class DeviceDebugController extends BaseController {
|
||||
@Log(title = "批量上传文件")
|
||||
@PostMapping("/addFile")
|
||||
public R<Void> uploadFile(@Validated @ModelAttribute AppFileDto bo) throws IOException {
|
||||
return toAjax(deviceDebugService.addFileHash(bo));
|
||||
return toAjax(deviceDebugService.addFileHash(bo,true));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,7 +113,7 @@ public class DeviceDebugController extends BaseController {
|
||||
appFileDto.setDeviceIds(new Long[]{ bo.getDeviceId() });
|
||||
appFileDto.setFileType(1L);
|
||||
appFileDto.setFiles(bo.getExplanationFiles());
|
||||
deviceDebugService.addFileHash(appFileDto);
|
||||
deviceDebugService.addFileHash(appFileDto,false);
|
||||
}
|
||||
// 修改上传设备参数
|
||||
if (bo.getParameterFiles() != null) {
|
||||
@ -121,8 +121,9 @@ public class DeviceDebugController extends BaseController {
|
||||
appFileDto.setDeviceIds(new Long[]{ bo.getDeviceId() });
|
||||
appFileDto.setFileType(2L);
|
||||
appFileDto.setFiles(bo.getParameterFiles());
|
||||
deviceDebugService.addFileHash(appFileDto);
|
||||
deviceDebugService.addFileHash(appFileDto,false);
|
||||
}
|
||||
deviceDebugService.delFile(bo.getFileIds());
|
||||
// 修改操作视频
|
||||
if (bo.getVideoUrl().isEmpty()) {
|
||||
AppOperationVideoBo appOperationVideoBo = new AppOperationVideoBo();
|
||||
|
||||
@ -1,20 +1,36 @@
|
||||
package com.fuyuanshen.web.controller.device;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.web.domain.Dto.DeviceXinghanInstructDto;
|
||||
import com.fuyuanshen.web.domain.Dto.SystemVersionDto;
|
||||
import com.fuyuanshen.web.domain.vo.DeviceXinghanDetailVo;
|
||||
import com.fuyuanshen.web.service.device.DeviceXinghanBizService;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_ALARM_MESSAGE_KEY_PREFIX;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 设备控制类 HBY670
|
||||
*/
|
||||
@ -26,6 +42,18 @@ public class DeviceXinghanController extends BaseController {
|
||||
|
||||
private final DeviceXinghanBizService deviceXinghanBizService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<DeviceXinghanDetailVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(deviceXinghanBizService.getInfo(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
@ -65,7 +93,7 @@ public class DeviceXinghanController extends BaseController {
|
||||
* 3,2,1,0,分别表示高档/中档/低挡/关闭
|
||||
*/
|
||||
@PostMapping("/DetectGradeSettings")
|
||||
public R<Void> DetectGradeSettings(@RequestBody DeviceInstructDto params) {
|
||||
public R<Void> DetectGradeSettings(@RequestBody DeviceXinghanInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
deviceXinghanBizService.upDetectGradeSettings(params);
|
||||
return R.ok();
|
||||
@ -76,7 +104,7 @@ public class DeviceXinghanController extends BaseController {
|
||||
* 照明档位,2,1,0,分别表示弱光/强光/关闭
|
||||
*/
|
||||
@PostMapping("/LightGradeSettings")
|
||||
public R<Void> LightGradeSettings(@RequestBody DeviceInstructDto params) {
|
||||
public R<Void> LightGradeSettings(@RequestBody DeviceXinghanInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
deviceXinghanBizService.upLightGradeSettings(params);
|
||||
return R.ok();
|
||||
@ -87,20 +115,50 @@ public class DeviceXinghanController extends BaseController {
|
||||
* SOS档位,2,1,0, 分别表示红蓝模式/爆闪模式/关闭
|
||||
*/
|
||||
@PostMapping("/SOSGradeSettings")
|
||||
public R<Void> SOSGradeSettings(@RequestBody DeviceInstructDto params) {
|
||||
public R<Void> SOSGradeSettings(@RequestBody DeviceXinghanInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
deviceXinghanBizService.upSOSGradeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* SOS档位 批量
|
||||
* SOS档位,2,1,0, 分别表示红蓝模式/爆闪模式/关闭
|
||||
*/
|
||||
@PostMapping("/SOSGradeSettingsBatch")
|
||||
public R<Void> SOSGradeSettingsBatch(@RequestBody DeviceXinghanInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
deviceXinghanBizService.sendCommandBatch(params,"ins_SOSGrade","SOS档位");
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 静止报警状态
|
||||
* 静止报警状态,0-未静止报警,1-正在静止报警。
|
||||
*/
|
||||
@PostMapping("/ShakeBitSettings")
|
||||
public R<Void> ShakeBitSettings(@RequestBody DeviceInstructDto params) {
|
||||
public R<Void> ShakeBitSettings(@RequestBody DeviceXinghanInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
deviceXinghanBizService.upShakeBitSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本更新
|
||||
*/
|
||||
@SaCheckPermission("system:appVersion:up")
|
||||
@PostMapping("/UpVersion")
|
||||
public R<Void> VersionSettings(@RequestBody List<SystemVersionDto> params) {
|
||||
// params 已经是 List<SystemVersionDto>
|
||||
// 2. 转 JSON 并写 Redis,key 自己定,带个过期时间
|
||||
String versionKey = GLOBAL_REDIS_KEY + "System:Version:Xinghan";
|
||||
String json = JSON.toJSONString(params); // fastjson
|
||||
if (StringUtils.isBlank(json)) { // hutool 工具,可用 StringUtils.isBlank 代替
|
||||
return R.fail("信息无效");
|
||||
}
|
||||
// 缓存告警消息到Redis
|
||||
RedisUtils.setCacheObject(versionKey, json, Duration.ofDays(30));
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,140 @@
|
||||
package com.fuyuanshen.web.controller.device.bjq;
|
||||
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.web.service.device.DeviceBJQBizService;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* web后台:设备控制类
|
||||
* 6075
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/bjq6075/device")
|
||||
public class DeviceBJQ6075Controller extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDeviceDetailVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
@PostMapping(value = "/registerPersonInfo")
|
||||
// @FunctionAccessAnnotation("registerPersonInfo")
|
||||
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
|
||||
return toAjax(appDeviceService.registerPersonInfo(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
*/
|
||||
@PostMapping(value = "/sendMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
|
||||
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService.sendMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送报警信息
|
||||
*/
|
||||
@PostMapping(value = "/sendAlarmMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
|
||||
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService.sendAlarmMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传设备logo图片
|
||||
*/
|
||||
@PostMapping("/uploadLogo")
|
||||
@FunctionAccessAnnotation("uploadLogo")
|
||||
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.uploadDeviceLogo(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传设备logo图片
|
||||
*/
|
||||
@PostMapping("/batchUploadLogo")
|
||||
@FunctionAccessAnnotation("batchUploadLogo")
|
||||
public R<Void> batchUploadLogo(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.batchUploadLogo(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
||||
*/
|
||||
// @FunctionAccessAnnotation("lightModeSettings")
|
||||
@PostMapping("/lightModeSettings")
|
||||
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.lightModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光亮度设置
|
||||
*/
|
||||
// @FunctionAccessAnnotation("lightBrightnessSettings")
|
||||
@PostMapping("/lightBrightnessSettings")
|
||||
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService.lightBrightnessSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 激光模式设置
|
||||
*/
|
||||
@PostMapping("/laserModeSettings")
|
||||
// @FunctionAccessAnnotation("laserModeSettings")
|
||||
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService.laserModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@ -59,9 +59,15 @@ public class DeviceGeoFenceController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(DeviceGeoFenceBo bo, HttpServletResponse response) {
|
||||
List<DeviceGeoFenceVo> list = deviceGeoFenceService.queryList(bo);
|
||||
// 设置区域类型名称
|
||||
list.forEach(item -> {
|
||||
item.setAreaTypeNameByAreaType();
|
||||
item.setIsActiveNameByIsActive(); // 添加这行来设置激活状态名称
|
||||
});
|
||||
ExcelUtil.exportExcel(list, "电子围栏", DeviceGeoFenceVo.class, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取电子围栏详细信息
|
||||
*
|
||||
|
||||
@ -31,4 +31,6 @@ public class DeviceDebugEditDto {
|
||||
* 视频链接
|
||||
*/
|
||||
private String videoUrl;
|
||||
|
||||
private List<Long> fileIds;
|
||||
}
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
package com.fuyuanshen.web.domain.Dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DeviceXinghanInstructDto {
|
||||
private Long deviceId;
|
||||
|
||||
private String deviceImei;
|
||||
/**
|
||||
* 下发指令
|
||||
*/
|
||||
private String instructValue;
|
||||
private Boolean isBluetooth = false;
|
||||
private List<Long> deviceIds;
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.fuyuanshen.web.domain.Dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SystemVersionDto {
|
||||
private String dictValue;
|
||||
private String dictLabel;
|
||||
private String remark;
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
package com.fuyuanshen.web.domain.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DeviceXinghanDetailVo {
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@ExcelProperty(value = "设备ID")
|
||||
private Long deviceId;
|
||||
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 设备MAC
|
||||
*/
|
||||
private String deviceMac;
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G;1:蓝牙
|
||||
*/
|
||||
private Integer communicationMode;
|
||||
|
||||
/**
|
||||
* 设备图片
|
||||
*/
|
||||
private String devicePic;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 蓝牙名称
|
||||
*/
|
||||
private String bluetoothName;
|
||||
|
||||
/**
|
||||
* 设备状态
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
private Integer deviceStatus;
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息
|
||||
*/
|
||||
private AppPersonnelInfoVo personnelInfo;
|
||||
|
||||
/**
|
||||
* 在线状态(0离线,1在线)
|
||||
*/
|
||||
private Integer onlineStatus;
|
||||
|
||||
// 经度
|
||||
private String longitude;
|
||||
|
||||
// 纬度
|
||||
private String latitude;
|
||||
|
||||
// 逆解析地址
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 第一键值对,静电预警档位:3,2,1,0,分别表示高档/中档/低挡/关闭.
|
||||
*/
|
||||
private Integer staDetectGrade;
|
||||
/**
|
||||
* 第二键值对,照明档位,2,1,0,分别表示弱光/强光/关闭
|
||||
*/
|
||||
private Integer staLightGrade;
|
||||
/**
|
||||
* 第三键值对,SOS档位,2,1,0, 分别表示红蓝模式/爆闪模式/关闭
|
||||
*/
|
||||
public Integer staSOSGrade;
|
||||
/**
|
||||
* 第四键值对,剩余照明时间,0-5999,单位分钟。
|
||||
*/
|
||||
public Integer staPowerTime;
|
||||
/**
|
||||
* 第五键值对,剩余电量百分比,0-100
|
||||
*/
|
||||
public Integer staPowerPercent;
|
||||
/**
|
||||
* 第六键值对, 近电预警级别, 0-无预警,1-弱预警,2-中预警,3-强预警,4-非常强预警。
|
||||
*/
|
||||
public Integer staDetectResult;
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.fuyuanshen.web.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 报警类型枚举
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum AlarmTypeEnum {
|
||||
SOS("_sos", "SOS报警"),
|
||||
SHAKE("_shake", "静止报警");
|
||||
|
||||
private final String suffix;
|
||||
private final String desc;
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
package com.fuyuanshen.web.service.device;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDevice6075DetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoRecordsMapper;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.*;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.equipment.enums.LightModeEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.buildArr;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.generateFixedBitmapData;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
|
||||
@Service
|
||||
public interface DeviceBJQ6075BizService {
|
||||
|
||||
/**
|
||||
* 获取设备详情
|
||||
*
|
||||
* @param id 设备ID
|
||||
* @return 设备详情
|
||||
*/
|
||||
public AppDevice6075DetailVo getInfo(Long id);
|
||||
|
||||
public int sendMessage(AppDeviceSendMsgBo bo);
|
||||
|
||||
/**
|
||||
* 记录设备操作日志
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param content 日志内容
|
||||
* @param operator 操作人
|
||||
*/
|
||||
public void recordDeviceLog(Long deviceId, String deviceName, String deviceAction, String content, Long operator);
|
||||
|
||||
public boolean registerPersonInfo(AppPersonnelInfoBo bo);
|
||||
|
||||
public void uploadDeviceLogo2(AppDeviceLogoUploadDto bo);
|
||||
|
||||
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo);
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* (主光模式)
|
||||
* 0(关闭灯光),1(强光),2(超强光), 3(工作光), 4(节能光),5(爆闪),6(SOS)
|
||||
*/
|
||||
public void lightModeSettings(DeviceInstructDto params);
|
||||
|
||||
// 灯光亮度设置
|
||||
public void lightBrightnessSettings(DeviceInstructDto params);
|
||||
|
||||
// 激光模式设置
|
||||
public void laserModeSettings(DeviceInstructDto params);
|
||||
|
||||
public String mapReverseGeocoding(DeviceInstructDto params);
|
||||
|
||||
public int sendAlarmMessage(AppDeviceSendMsgBo bo);
|
||||
|
||||
public void messageSending(String deviceImei);
|
||||
|
||||
public boolean getDeviceStatus(String deviceImei);
|
||||
|
||||
public void batchUploadLogo(AppDeviceLogoUploadDto bo);
|
||||
|
||||
}
|
||||
@ -15,6 +15,7 @@ import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoRecordsMapper;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.*;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
@ -58,6 +59,7 @@ public class DeviceBJQBizService {
|
||||
private final MqttGateway mqttGateway;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
|
||||
|
||||
public int sendMessage(AppDeviceSendMsgBo bo) {
|
||||
List<Long> deviceIds = bo.getDeviceIds();
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
@ -68,8 +70,8 @@ public class DeviceBJQBizService {
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在" + deviceId);
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
try {
|
||||
ClassPathResource resource = new ClassPathResource("image/background.png");
|
||||
@ -77,26 +79,26 @@ public class DeviceBJQBizService {
|
||||
|
||||
byte[] largeData = ImageWithTextGenerate.generate160x80ImageWithText2(bo.getSendMsg(), inputStream, 25600);
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data" , Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data", Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data");
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data");
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
log.info("发送信息第0块数据大小: {} 字节",specificChunk.length);
|
||||
log.info("发送信息第0块数据大小: {} 字节", specificChunk.length);
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(6);
|
||||
intData.add(1);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk),intData);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
|
||||
log.info("发送信息点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送信息点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", deviceId)
|
||||
@ -105,10 +107,11 @@ public class DeviceBJQBizService {
|
||||
|
||||
recordDeviceLog(deviceId, device.getDeviceName(), "发送信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
log.info("发送信息设备发送信息失败:{}" ,deviceId);
|
||||
log.info("发送信息设备发送信息失败:{}", deviceId);
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
|
||||
// 发送消息
|
||||
messageSending(device.getDeviceImei());
|
||||
}
|
||||
|
||||
|
||||
@ -117,11 +120,12 @@ public class DeviceBJQBizService {
|
||||
|
||||
/**
|
||||
* 记录设备操作日志
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param content 日志内容
|
||||
* @param content 日志内容
|
||||
* @param operator 操作人
|
||||
*/
|
||||
private void recordDeviceLog(Long deviceId,String deviceName, String deviceAction, String content, Long operator) {
|
||||
private void recordDeviceLog(Long deviceId, String deviceName, String deviceAction, String content, Long operator) {
|
||||
try {
|
||||
// 创建设备日志实体
|
||||
com.fuyuanshen.equipment.domain.DeviceLog deviceLog = new com.fuyuanshen.equipment.domain.DeviceLog();
|
||||
@ -169,59 +173,62 @@ public class DeviceBJQBizService {
|
||||
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
|
||||
vo.setPersonnelInfo(personnelInfoVo);
|
||||
}
|
||||
//设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei()+ DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(onlineStatus)){
|
||||
// 设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
// 设备在线状态
|
||||
if ("1".equals(onlineStatus)) {
|
||||
vo.setOnlineStatus(1);
|
||||
}else{
|
||||
} else if ("2".equals(onlineStatus)) {
|
||||
vo.setOnlineStatus(2);
|
||||
} else {
|
||||
vo.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX);
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
vo.setMainLightMode(jsonObject.getString("mainLightMode"));
|
||||
vo.setLaserLightMode(jsonObject.getString("laserLightMode"));
|
||||
vo.setBatteryPercentage(jsonObject.getString("batteryPercentage"));
|
||||
vo.setChargeState(jsonObject.getString("chargeState"));
|
||||
vo.setBatteryRemainingTime(jsonObject.getString("batteryRemainingTime"));
|
||||
}else{
|
||||
} else {
|
||||
vo.setBatteryPercentage("0");
|
||||
}
|
||||
|
||||
String lightModeStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_MODE_KEY_PREFIX);
|
||||
String lightModeStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_MODE_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
vo.setMainLightMode(lightModeStatus);
|
||||
}
|
||||
|
||||
String lightBrightnessStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(lightBrightnessStatus)){
|
||||
String lightBrightnessStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(lightBrightnessStatus)) {
|
||||
vo.setLightBrightness(lightBrightnessStatus);
|
||||
}
|
||||
|
||||
String laserLightMode = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LASER_MODE_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(laserLightMode)){
|
||||
String laserLightMode = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LASER_MODE_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(laserLightMode)) {
|
||||
vo.setLaserLightMode(laserLightMode);
|
||||
}
|
||||
|
||||
// 获取经度纬度
|
||||
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
|
||||
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
|
||||
String locationInfo = RedisUtils.getCacheObject(locationKey);
|
||||
if(StringUtils.isNotBlank(locationInfo)){
|
||||
if (StringUtils.isNotBlank(locationInfo)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
|
||||
vo.setLongitude(jsonObject.get("longitude").toString());
|
||||
vo.setLatitude(jsonObject.get("latitude").toString());
|
||||
vo.setAddress((String)jsonObject.get("address"));
|
||||
vo.setAddress((String) jsonObject.get("address"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ device.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(alarmStatus)){
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
vo.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
|
||||
String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ device.getDeviceImei()+ DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(lightBrightness)){
|
||||
String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(lightBrightness)) {
|
||||
vo.setLightBrightness(lightBrightness);
|
||||
}
|
||||
|
||||
@ -229,15 +236,14 @@ public class DeviceBJQBizService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
||||
Long deviceId = bo.getDeviceId();
|
||||
Device deviceObj = deviceMapper.selectById(deviceId);
|
||||
if (deviceObj == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
if(getDeviceStatus(deviceObj.getDeviceImei())){
|
||||
throw new ServiceException(deviceObj.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(deviceObj.getDeviceImei())) {
|
||||
throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
||||
.eq("device_id", deviceId);
|
||||
@ -250,8 +256,8 @@ public class DeviceBJQBizService {
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(2);
|
||||
buildArr(convertHexToDecimal(unitName), intData);
|
||||
buildArr(convertHexToDecimal(position), intData);
|
||||
buildArr(convertHexToDecimal(name), intData);
|
||||
buildArr(convertHexToDecimal(position), intData);
|
||||
buildArr(convertHexToDecimal(id), intData);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
@ -261,7 +267,7 @@ public class DeviceBJQBizService {
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo);
|
||||
String logContent = "单位:"+bo.getUnitName()+",职位:"+bo.getPosition()+",姓名:"+bo.getName()+",ID:"+bo.getCode();
|
||||
String logContent = "单位:" + bo.getUnitName() + ",职位:" + bo.getPosition() + ",姓名:" + bo.getName() + ",ID:" + bo.getCode();
|
||||
recordDeviceLog(deviceId, deviceObj.getDeviceName(), "人员信息登记", logContent, AppLoginHelper.getUserId());
|
||||
if (ObjectUtils.length(appPersonnelInfoVos) == 0) {
|
||||
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
@ -292,6 +298,7 @@ public class DeviceBJQBizService {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void uploadDeviceLogo2(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
@ -317,23 +324,27 @@ public class DeviceBJQBizService {
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("instruct", combinedData);
|
||||
String[] specificChunk = ImageToCArrayConverter.getChunk2(hexArray, 0, bo.getChunkSize());
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , Arrays.toString(specificChunk));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),Arrays.toString(specificChunk));
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, Arrays.toString(specificChunk));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), Arrays.toString(specificChunk));
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
// throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
log.info(device.getDeviceName() + ",设备已断开连接");
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", device.getDeviceName() + ",设备已断开连接", AppLoginHelper.getUserId());
|
||||
return;
|
||||
}
|
||||
MultipartFile file = bo.getFile();
|
||||
|
||||
@ -343,9 +354,9 @@ public class DeviceBJQBizService {
|
||||
log.info("原始数据大小: {} 字节", largeData.length);
|
||||
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() +DEVICE_BOOT_LOGO_KEY_PREFIX, Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX, Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX);
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX);
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
@ -355,18 +366,18 @@ public class DeviceBJQBizService {
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(3);
|
||||
intData.add(1);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk),intData);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
@ -381,13 +392,13 @@ public class DeviceBJQBizService {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(1);
|
||||
intData.add(instructValue);
|
||||
@ -396,26 +407,26 @@ public class DeviceBJQBizService {
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
LightModeEnum modeEnum = LightModeEnum.getByCode(instructValue);
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "灯光模式", modeEnum!=null?modeEnum.getName():null, AppLoginHelper.getUserId());
|
||||
} catch (Exception e){
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "灯光模式", modeEnum != null ? modeEnum.getName() : null, AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
//灯光亮度设置
|
||||
// 灯光亮度设置
|
||||
public void lightBrightnessSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
String instructValue = params.getInstructValue();
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
@ -423,10 +434,10 @@ public class DeviceBJQBizService {
|
||||
String[] values = instructValue.split("\\.");
|
||||
String value1 = values[0];
|
||||
String value2 = values[1];
|
||||
if(StringUtils.isNoneBlank(value1)){
|
||||
if (StringUtils.isNoneBlank(value1)) {
|
||||
intData.add(Integer.parseInt(value1));
|
||||
}
|
||||
if(StringUtils.isNoneBlank(value2)){
|
||||
if (StringUtils.isNoneBlank(value2)) {
|
||||
intData.add(Integer.parseInt(value2));
|
||||
}
|
||||
intData.add(0);
|
||||
@ -434,25 +445,25 @@ public class DeviceBJQBizService {
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
//激光模式设置
|
||||
// 激光模式设置
|
||||
public void laserModeSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
@ -463,15 +474,15 @@ public class DeviceBJQBizService {
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
// 1代表开启激光灯,此时主灯关闭,主灯控件为关机状态,为0代表关闭激光灯
|
||||
if("1".equals(params.getInstructValue())){
|
||||
if ("1".equals(params.getInstructValue())) {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "激光模式设置", "开启激光灯", AppLoginHelper.getUserId());
|
||||
}else{
|
||||
} else {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "激光模式设置", "关闭激光灯", AppLoginHelper.getUserId());
|
||||
}
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
@ -481,7 +492,7 @@ public class DeviceBJQBizService {
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("device_imei", params.getDeviceImei());
|
||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||
if(ObjectUtils.length( devices) ==0){
|
||||
if (ObjectUtils.length(devices) == 0) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
|
||||
@ -499,8 +510,8 @@ public class DeviceBJQBizService {
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在" + deviceId);
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
try {
|
||||
|
||||
@ -513,30 +524,55 @@ public class DeviceBJQBizService {
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", deviceId)
|
||||
.eq("binding_user_id", AppLoginHelper.getUserId())
|
||||
.set("send_msg", bo.getSendMsg());
|
||||
deviceMapper.update(updateWrapper);
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "发送告警信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
if ("0".equals(bo.getInstructValue())) {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "解除告警信息", "关闭设备", AppLoginHelper.getUserId());
|
||||
} else {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "发送告警信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("设备发送告警信息信息失败:{}" ,deviceId);
|
||||
log.info("设备发送告警信息信息失败:{}", deviceId);
|
||||
throw new ServiceException("设备发送告警信息信息失败");
|
||||
}
|
||||
|
||||
messageSending(device.getDeviceImei());
|
||||
}
|
||||
} catch (Exception e){
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送告警信息指令失败");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private void messageSending(String deviceImei) {
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + ":messageSending";
|
||||
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
|
||||
}
|
||||
|
||||
private boolean getDeviceStatus(String deviceImei) {
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||
return RedisUtils.getCacheObject(deviceOnlineStatusRedisKey) == null;
|
||||
}
|
||||
|
||||
public void batchUploadLogo(AppDeviceLogoUploadDto bo) {
|
||||
|
||||
List<Long> deviceIds = bo.getDeviceIds();
|
||||
MultipartFile file = bo.getFile();
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
throw new ServiceException("请选择设备");
|
||||
}
|
||||
for (Long deviceId : deviceIds) {
|
||||
AppDeviceLogoUploadDto dto = new AppDeviceLogoUploadDto();
|
||||
dto.setDeviceId(deviceId);
|
||||
dto.setFile(file);
|
||||
uploadDeviceLogo(dto);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -36,6 +36,7 @@ import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.web.service.device.status.base.DeviceStatusRule;
|
||||
import com.fuyuanshen.web.service.device.status.base.RealTimeStatusEngine;
|
||||
import com.google.common.primitives.Ints;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -58,8 +59,8 @@ public class DeviceBizService {
|
||||
private final RealTimeStatusEngine realTimeStatusEngine;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
private final AppDeviceShareMapper appDeviceShareMapper;
|
||||
private final AppUserMapper appUserMapper;;
|
||||
|
||||
private final AppUserMapper appUserMapper;
|
||||
;
|
||||
|
||||
|
||||
public List<APPDeviceTypeVo> getTypeList() {
|
||||
@ -83,36 +84,37 @@ public class DeviceBizService {
|
||||
}
|
||||
Page<AppDeviceVo> result = deviceMapper.queryAppBindDeviceList(pageQuery.build(), bo);
|
||||
List<AppDeviceVo> records = result.getRecords();
|
||||
if(records != null && !records.isEmpty()){
|
||||
if (records != null && !records.isEmpty()) {
|
||||
records.forEach(item -> {
|
||||
if(item.getCommunicationMode()!=null && item.getCommunicationMode() == 0){
|
||||
|
||||
//设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(onlineStatus)){
|
||||
if (item.getCommunicationMode() != null && item.getCommunicationMode() == 0) {
|
||||
|
||||
// 设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if ("1".equals(onlineStatus)) {
|
||||
item.setOnlineStatus(1);
|
||||
}else{
|
||||
} else if ("2".equals(onlineStatus)) {
|
||||
item.setOnlineStatus(2);
|
||||
} else {
|
||||
item.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
item.setBattery(jsonObject.getString("batteryPercentage"));
|
||||
}else{
|
||||
} else {
|
||||
item.setBattery("0");
|
||||
}
|
||||
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_LOCATION_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(location)){
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_LOCATION_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(location)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(location);
|
||||
item.setLatitude(jsonObject.getString("latitude"));
|
||||
item.setLongitude(jsonObject.getString("longitude"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(alarmStatus)){
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
item.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
}
|
||||
@ -124,36 +126,37 @@ public class DeviceBizService {
|
||||
public TableDataInfo<WebDeviceVo> queryWebDeviceList(DeviceQueryCriteria bo, PageQuery pageQuery) {
|
||||
Page<WebDeviceVo> result = deviceMapper.queryWebDeviceList(pageQuery.build(), bo);
|
||||
List<WebDeviceVo> records = result.getRecords();
|
||||
if(records != null && !records.isEmpty()){
|
||||
if (records != null && !records.isEmpty()) {
|
||||
records.forEach(item -> {
|
||||
if(item.getCommunicationMode()!=null && (item.getCommunicationMode() == 0 || item.getCommunicationMode() == 2)){
|
||||
if (item.getCommunicationMode() != null && Ints.asList(0, 2).contains(item.getCommunicationMode())) {
|
||||
|
||||
//设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(onlineStatus)){
|
||||
|
||||
item.setOnlineStatus(1);
|
||||
}else{
|
||||
item.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
// 设备在线状态
|
||||
// String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
// if("1".equals(onlineStatus)){
|
||||
// item.setOnlineStatus(1);
|
||||
// }else if("2".equals(onlineStatus)){
|
||||
// item.setOnlineStatus(2);
|
||||
// }else{
|
||||
// item.setOnlineStatus(0);
|
||||
// }
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
item.setBattery(jsonObject.getString("batteryPercentage"));
|
||||
}else{
|
||||
} else {
|
||||
item.setBattery("0");
|
||||
}
|
||||
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_LOCATION_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(location)){
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_LOCATION_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(location)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(location);
|
||||
item.setLatitude(jsonObject.getString("latitude"));
|
||||
item.setLongitude(jsonObject.getString("longitude"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(alarmStatus)){
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
item.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
}
|
||||
@ -162,6 +165,7 @@ public class DeviceBizService {
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
|
||||
public int bindDevice(AppDeviceBo bo) {
|
||||
Integer mode = bo.getCommunicationMode();
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
@ -176,7 +180,7 @@ public class DeviceBizService {
|
||||
}
|
||||
Device device = devices.get(0);
|
||||
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
|
||||
throw new RuntimeException("设备已绑定");
|
||||
throw new RuntimeException("设备已经被绑定!");
|
||||
}
|
||||
|
||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
@ -186,7 +190,6 @@ public class DeviceBizService {
|
||||
if (appDeviceBindRecord != null) {
|
||||
UpdateWrapper<AppDeviceBindRecord> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("device_id", device.getId())
|
||||
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
||||
.set("binding_user_id", userId)
|
||||
.set("communication_mode", 0)
|
||||
.set("update_time", new Date())
|
||||
@ -262,43 +265,74 @@ public class DeviceBizService {
|
||||
if (device == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_user_id", null)
|
||||
.set("binding_status", BindingStatusEnum.UNBOUND.getCode())
|
||||
.set("binding_time", null);
|
||||
deviceMapper.update(null, deviceUpdateWrapper);
|
||||
|
||||
if (userId == null) {
|
||||
userId = AppLoginHelper.getUserId();
|
||||
}
|
||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||
// 设备端解绑 0:设备端解绑 1:web端解绑
|
||||
if (type == 1) {
|
||||
// type: 0 app,1 web
|
||||
if (type == 0) {
|
||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||
bindRecordQueryWrapper.eq("binding_user_id", userId);
|
||||
Long count = appDeviceBindRecordMapper.selectCount(bindRecordQueryWrapper);
|
||||
if (count == 0) {
|
||||
throw new RuntimeException("请先绑定设备!!!");
|
||||
}
|
||||
if (count < 2) {
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_user_id", null)
|
||||
.set("binding_status", BindingStatusEnum.UNBOUND.getCode())
|
||||
.set("binding_time", null);
|
||||
deviceMapper.update(null, deviceUpdateWrapper);
|
||||
}
|
||||
QueryWrapper<AppDeviceBindRecord> brqWrapper = new QueryWrapper<>();
|
||||
brqWrapper.eq("device_id", device.getId());
|
||||
brqWrapper.eq("binding_user_id", userId);
|
||||
List<AppDeviceBindRecord> appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(brqWrapper);
|
||||
if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) {
|
||||
appDeviceBindRecordList.forEach(appDeviceBindRecord ->
|
||||
appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()));
|
||||
}
|
||||
AppUserVo appUserVo = appUserMapper.selectVoById(userId);
|
||||
if (appUserVo != null) {
|
||||
QueryWrapper<AppDeviceShare> appDeviceShareQueryWrapper = new QueryWrapper<>();
|
||||
appDeviceShareQueryWrapper.eq("device_id", device.getId());
|
||||
appDeviceShareQueryWrapper.eq("phonenumber", appUserVo.getPhonenumber());
|
||||
List<AppDeviceShare> appDeviceShareList = appDeviceShareMapper.selectList(appDeviceShareQueryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(appDeviceShareList)) {
|
||||
appDeviceShareList.forEach(appDeviceShare ->
|
||||
appDeviceShareMapper.deleteById(appDeviceShare.getId()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||
Long count = appDeviceBindRecordMapper.selectCount(bindRecordQueryWrapper);
|
||||
if (count == 0) {
|
||||
throw new RuntimeException("请先绑定设备!!!");
|
||||
}
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_user_id", null)
|
||||
.set("binding_status", BindingStatusEnum.UNBOUND.getCode())
|
||||
.set("binding_time", null);
|
||||
deviceMapper.update(null, deviceUpdateWrapper);
|
||||
|
||||
QueryWrapper<AppDeviceBindRecord> brqWrapper = new QueryWrapper<>();
|
||||
brqWrapper.eq("device_id", device.getId());
|
||||
List<AppDeviceBindRecord> appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(brqWrapper);
|
||||
if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) {
|
||||
appDeviceBindRecordList.forEach(appDeviceBindRecord ->
|
||||
appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()));
|
||||
}
|
||||
|
||||
QueryWrapper<AppDeviceShare> appDeviceShareQueryWrapper = new QueryWrapper<>();
|
||||
appDeviceShareQueryWrapper.eq("device_id", device.getId());
|
||||
List<AppDeviceShare> appDeviceShareList = appDeviceShareMapper.selectList(appDeviceShareQueryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(appDeviceShareList)) {
|
||||
appDeviceShareList.forEach(appDeviceShare ->
|
||||
appDeviceShareMapper.deleteById(appDeviceShare.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
// AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper);
|
||||
// if (appDeviceBindRecord != null) {
|
||||
// return appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId());
|
||||
// }
|
||||
|
||||
List<AppDeviceBindRecord> appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(bindRecordQueryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) {
|
||||
appDeviceBindRecordList.forEach(appDeviceBindRecord ->
|
||||
appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()));
|
||||
}
|
||||
|
||||
AppUserVo appUserVo = appUserMapper.selectVoById(userId);
|
||||
QueryWrapper<AppDeviceShare> appDeviceShareQueryWrapper = new QueryWrapper<>();
|
||||
appDeviceShareQueryWrapper.eq("device_id", device.getId());
|
||||
appDeviceShareQueryWrapper.eq("phonenumber", appUserVo.getPhonenumber());
|
||||
List<AppDeviceShare> appDeviceShareList = appDeviceShareMapper.selectList(appDeviceShareQueryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(appDeviceShareList)) {
|
||||
appDeviceShareList.forEach(appDeviceShare ->
|
||||
appDeviceShareMapper.deleteById(appDeviceShare.getId()));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -308,7 +342,7 @@ public class DeviceBizService {
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("device_imei", params.getDeviceImei());
|
||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||
if(ObjectUtils.length( devices) ==0){
|
||||
if (ObjectUtils.length(devices) == 0) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
|
||||
@ -317,12 +351,12 @@ public class DeviceBizService {
|
||||
public Map<String, Object> getRealTimeStatus(AppRealTimeStatusDto statusDto) {
|
||||
try {
|
||||
// String commandType = statusDto.getTypeName()+"_" + statusDto.getFunctionMode();"FunctionAccessBatchStatusRule"
|
||||
DeviceStatusRule rule = realTimeStatusEngine.getDeviceStatusRule(statusDto.getTypeName());
|
||||
if(rule == null){
|
||||
DeviceStatusRule rule = realTimeStatusEngine.getDeviceStatusRule(statusDto.getTypeName());
|
||||
if (rule == null) {
|
||||
throw new ServiceException("未匹配到处理命令");
|
||||
}
|
||||
return rule.getStatus(statusDto);
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
@ -360,18 +394,22 @@ public class DeviceBizService {
|
||||
long endTime = today.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
|
||||
String deviceImei = device.getDeviceImei();
|
||||
String a = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX + ":history";
|
||||
Collection<String> list = RedisUtils.zRangeByScore(a, startTime, endTime);
|
||||
String a = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX + ":history";
|
||||
Collection<String> list = RedisUtils.zRangeByScoreDesc(a, startTime, endTime);
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Map<String, List<JSONObject>> map = new LinkedHashMap<>();
|
||||
for (String obj : list){
|
||||
for (String obj : list) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(obj);
|
||||
Long timestamp = jsonObject.getLong("timestamp");
|
||||
LocalDate date = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()).toLocalDate();
|
||||
String address = jsonObject.getString("address");
|
||||
if (StringUtils.isBlank(address) || "[]".equals(address)) {
|
||||
continue;
|
||||
}
|
||||
if (map.containsKey(date.toString())) {
|
||||
map.get(date.toString()).add(jsonObject);
|
||||
} else {
|
||||
@ -387,7 +425,7 @@ public class DeviceBizService {
|
||||
detailVo.setDate(entry.getKey());
|
||||
detailVo.setDeviceName(device.getDeviceName());
|
||||
detailVo.setStartLocation(entry.getValue().get(0).getString("address"));
|
||||
detailVo.setEndLocation(entry.getValue().get(entry.getValue().size()-1).getString("address"));
|
||||
detailVo.setEndLocation(entry.getValue().get(entry.getValue().size() - 1).getString("address"));
|
||||
String jsonString = JSONArray.toJSONString(entry.getValue());
|
||||
List<Object> strings = JSONArray.parseArray(jsonString);
|
||||
detailVo.setDetailList(strings);
|
||||
|
||||
@ -10,18 +10,15 @@ import com.fuyuanshen.app.service.IAppBusinessFileService;
|
||||
import com.fuyuanshen.app.service.IAppOperationVideoService;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import com.fuyuanshen.system.service.ISysOssService;
|
||||
import com.fuyuanshen.web.domain.vo.DeviceInfoVo;
|
||||
import com.fuyuanshen.web.util.FileHashUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.fuyuanshen.equipment.utils.FileHashUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -42,6 +39,7 @@ public class DeviceDebugService {
|
||||
private final IAppBusinessFileService appBusinessFileService;
|
||||
private final IAppOperationVideoService appOperationVideoService;
|
||||
private final DeviceService deviceService;
|
||||
private final FileHashUtil fileHashUtil;
|
||||
|
||||
/**
|
||||
* 文件上传并添加文件信息哈希去重
|
||||
@ -50,7 +48,7 @@ public class DeviceDebugService {
|
||||
* @throws IOException
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean addFileHash(AppFileDto bo) throws IOException {
|
||||
public Boolean addFileHash(AppFileDto bo,Boolean isBatch) throws IOException {
|
||||
MultipartFile[] files = bo.getFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
throw new ServiceException("请选择要上传的文件");
|
||||
@ -65,26 +63,12 @@ public class DeviceDebugService {
|
||||
Map<String, Long> hash2OssId = new LinkedHashMap<>(files.length);
|
||||
for (MultipartFile file : files) {
|
||||
// 1. 计算文件哈希
|
||||
String hash = FileHashUtil.hash(file);
|
||||
String hash = fileHashUtil.hash(file);
|
||||
|
||||
// 2. 先根据 hash 查库(秒传)
|
||||
SysOssVo exist = sysOssService.selectByHash(hash);
|
||||
Long ossId;
|
||||
if (exist != null) {
|
||||
// 2.1 已存在,直接复用
|
||||
ossId = exist.getOssId();
|
||||
hash2OssId.putIfAbsent(hash, ossId);
|
||||
} else {
|
||||
// 2.2 不存在,真正上传
|
||||
SysOssVo upload = sysOssService.upload(file);
|
||||
if (upload == null) {
|
||||
return false;
|
||||
}
|
||||
ossId = upload.getOssId();
|
||||
hash2OssId.putIfAbsent(hash, ossId);
|
||||
// 2.3 把 hash 写回记录(供下次去重)
|
||||
sysOssService.updateHashById(ossId, hash);
|
||||
}
|
||||
SysOssVo exist = sysOssService.updateHash(file, hash);
|
||||
// 2.1 已存在,直接复用
|
||||
long ossId = exist.getOssId();
|
||||
hash2OssId.putIfAbsent(hash, ossId);
|
||||
}
|
||||
// 4. 组装业务中间表
|
||||
List<AppBusinessFile> bizList = new ArrayList<>(bo.getDeviceIds().length * hash2OssId.size());
|
||||
@ -103,7 +87,7 @@ public class DeviceDebugService {
|
||||
if (CollUtil.isEmpty(bizList)) { // 空集合直接返回
|
||||
throw new ServiceException("请选择要上传的文件");
|
||||
}
|
||||
return appBusinessFileService.insertBatch(bizList);
|
||||
return appBusinessFileService.insertBatch(bizList,isBatch);
|
||||
}
|
||||
|
||||
public Boolean addVideoList(AppOperationVideoBo bo){
|
||||
@ -127,6 +111,13 @@ public class DeviceDebugService {
|
||||
}
|
||||
return appOperationVideoService.insertBatch(bizList);
|
||||
}
|
||||
// 删除文件
|
||||
public void delFile(List<Long> ids) {
|
||||
// 3. 删除旧图片
|
||||
if(ids != null){
|
||||
appBusinessFileService.deleteWithValidByIds(ids, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备详情
|
||||
|
||||
@ -1,16 +1,30 @@
|
||||
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.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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.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;
|
||||
@ -19,31 +33,48 @@ import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.*;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceAlarmBo;
|
||||
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;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceAssignmentsService;
|
||||
import com.fuyuanshen.equipment.service.IDeviceAlarmService;
|
||||
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 lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.Bitmap80x12Generator.buildArr;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.generateFixedBitmapData;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
import static com.fuyuanshen.equipment.service.impl.DeviceServiceImpl.USER_ID_SEPARATOR;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
@Slf4j
|
||||
@ -56,6 +87,12 @@ public class DeviceXinghanBizService {
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
private final MqttGateway mqttGateway;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
private final AppPersonnelInfoRecordsMapper appPersonnelInfoRecordsMapper;
|
||||
private final IDeviceAlarmService deviceAlarmService;
|
||||
private final DeviceTypeGrantsMapper deviceTypeGrantsMapper;
|
||||
private final DeviceAssignmentsService deviceAssignmentsService;
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* 所有档位的描述表
|
||||
@ -81,31 +118,107 @@ public class DeviceXinghanBizService {
|
||||
/**
|
||||
* 设置静电预警档位
|
||||
*/
|
||||
public void upDetectGradeSettings(DeviceInstructDto dto) {
|
||||
public void upDetectGradeSettings(DeviceXinghanInstructDto dto) {
|
||||
sendCommand(dto, "ins_DetectGrade","静电预警档位");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置照明档位
|
||||
*/
|
||||
public void upLightGradeSettings(DeviceInstructDto dto) {
|
||||
public void upLightGradeSettings(DeviceXinghanInstructDto dto) {
|
||||
sendCommand(dto, "ins_LightGrade","照明档位");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置SOS档位
|
||||
*/
|
||||
public void upSOSGradeSettings(DeviceInstructDto dto) {
|
||||
sendCommand(dto, "ins_SOSGrade","SOS档位");
|
||||
public void upSOSGradeSettings(DeviceXinghanInstructDto dto) {
|
||||
if(dto.getIsBluetooth()){
|
||||
long deviceId = dto.getDeviceId();
|
||||
|
||||
// 1. 使用Optional简化空值检查,使代码更简洁
|
||||
Device device = Optional.ofNullable(deviceMapper.selectById(deviceId))
|
||||
.orElseThrow(() -> new ServiceException("设备不存在"));
|
||||
int sosGrade = Integer.parseInt(dto.getInstructValue());
|
||||
// 6. 新建报警信息
|
||||
createAlarm(device.getId(),device.getDeviceImei(),"ins_SOSGrade",sosGrade);
|
||||
}else {
|
||||
sendCommand(dto, "ins_SOSGrade","SOS档位");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置强制报警
|
||||
*/
|
||||
public void upShakeBitSettings(DeviceInstructDto dto) {
|
||||
public void upShakeBitSettings(DeviceXinghanInstructDto dto) {
|
||||
sendCommand(dto, "ins_ShakeBit","强制报警");
|
||||
}
|
||||
|
||||
public DeviceXinghanDetailVo getInfo(Long id) {
|
||||
Device device = deviceMapper.selectById(id);
|
||||
if (device == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
|
||||
DeviceXinghanDetailVo vo = new DeviceXinghanDetailVo();
|
||||
vo.setDeviceId(device.getId());
|
||||
vo.setDeviceName(device.getDeviceName());
|
||||
vo.setDevicePic(device.getDevicePic());
|
||||
vo.setDeviceImei(device.getDeviceImei());
|
||||
vo.setDeviceMac(device.getDeviceMac());
|
||||
vo.setDeviceStatus(device.getDeviceStatus());
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
if (deviceType != null) {
|
||||
vo.setCommunicationMode(Integer.valueOf(deviceType.getCommunicationMode()));
|
||||
vo.setTypeName(deviceType.getTypeName());
|
||||
}
|
||||
vo.setBluetoothName(device.getBluetoothName());
|
||||
|
||||
|
||||
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
||||
.eq("device_id", device.getId());
|
||||
AppPersonnelInfo appPersonnelInfo = appPersonnelInfoMapper.selectOne(qw);
|
||||
if (appPersonnelInfo != null) {
|
||||
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
|
||||
vo.setPersonnelInfo(personnelInfoVo);
|
||||
}
|
||||
//设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei()+ DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(onlineStatus)){
|
||||
vo.setOnlineStatus(1);
|
||||
}else{
|
||||
vo.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取设备上报的设备状态
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
try {
|
||||
MqttXinghanJson deviceJson = objectMapper.readValue(deviceStatus, MqttXinghanJson.class);
|
||||
vo.setStaLightGrade(deviceJson.getStaLightGrade());
|
||||
vo.setStaPowerPercent(deviceJson.getStaPowerPercent());
|
||||
vo.setStaSOSGrade(deviceJson.getStaSOSGrade());
|
||||
vo.setStaDetectGrade(deviceJson.getStaDetectGrade());
|
||||
vo.setStaPowerTime(deviceJson.getStaPowerTime());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("设备状态缓存格式非法", e);
|
||||
}
|
||||
}else{
|
||||
vo.setStaPowerPercent(0);
|
||||
}
|
||||
|
||||
// 获取经度纬度
|
||||
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
|
||||
String locationInfo = RedisUtils.getCacheObject(locationKey);
|
||||
if(StringUtils.isNotBlank(locationInfo)){
|
||||
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
|
||||
vo.setLongitude(jsonObject.get("longitude").toString());
|
||||
vo.setLatitude(jsonObject.get("latitude").toString());
|
||||
vo.setAddress((String)jsonObject.get("address"));
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传设备logo
|
||||
*/
|
||||
@ -212,26 +325,29 @@ public class DeviceXinghanBizService {
|
||||
* 人员登记
|
||||
* @param bo
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class) // 1. 事务
|
||||
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
||||
Long deviceId = bo.getDeviceId();
|
||||
Device deviceObj = deviceMapper.selectById(deviceId);
|
||||
if (deviceObj == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
if (deviceObj.getDeviceImei() == null) {
|
||||
return saveOrUpdatePersonnelInfo(bo, deviceId);
|
||||
}
|
||||
if (isDeviceOffline(deviceObj.getDeviceImei())) {
|
||||
throw new ServiceException("设备已断开连接:" + deviceObj.getDeviceName());
|
||||
}
|
||||
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
||||
.eq("device_id", deviceId);
|
||||
List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw);
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(bo.getUnitName());
|
||||
list.add(bo.getName());
|
||||
list.add(bo.getPosition());
|
||||
list.add(bo.getUnitName());
|
||||
list.add(bo.getCode());
|
||||
RedisUtils.setCacheList(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + deviceObj.getDeviceImei() + ":app_send_message_data", list);
|
||||
RedisUtils.expire(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + deviceObj.getDeviceImei() + ":app_send_message_data", Duration.ofSeconds(5 * 60L));
|
||||
String key = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceObj.getDeviceImei() + ":app_send_message_data";
|
||||
RedisUtils.deleteObject(key); // 先整体删掉
|
||||
RedisUtils.setCacheList(key, list); // 再重新写入
|
||||
RedisUtils.expire(key, Duration.ofSeconds(5*60));
|
||||
|
||||
Map<String, Object> payload = Map.of("ins_TexTrans",
|
||||
Collections.singletonList(0));
|
||||
@ -247,18 +363,47 @@ public class DeviceXinghanBizService {
|
||||
log.info("发送人员信息登记到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo);
|
||||
|
||||
recordDeviceLog(deviceId, deviceObj.getDeviceName(), "人员信息登记", JSON.toJSONString(bo), AppLoginHelper.getUserId());
|
||||
if (ObjectUtils.length(appPersonnelInfoVos) == 0) {
|
||||
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
return appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo);
|
||||
|
||||
return saveOrUpdatePersonnelInfo(bo, deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅内部调用,已处于 @Transactional 内
|
||||
*/
|
||||
private Boolean saveOrUpdatePersonnelInfo(AppPersonnelInfoBo bo, Long deviceId) {
|
||||
// 1. 先查主表有没有
|
||||
AppPersonnelInfo main = appPersonnelInfoMapper.selectOne(
|
||||
Wrappers.<AppPersonnelInfo>lambdaQuery()
|
||||
.eq(AppPersonnelInfo::getDeviceId, deviceId));
|
||||
|
||||
if (main == null) {
|
||||
/* ====== 新增场景 ====== */
|
||||
main = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
main.setDeviceId(deviceId);
|
||||
// 1.1 主表插入 -> 主键回写
|
||||
appPersonnelInfoMapper.insert(main); // 执行后 main.getId() 一定有值
|
||||
} else {
|
||||
UpdateWrapper<AppPersonnelInfo> uw = new UpdateWrapper<>();
|
||||
uw.eq("device_id", deviceId)
|
||||
.set("name", bo.getName())
|
||||
.set("position", bo.getPosition())
|
||||
.set("unit_name", bo.getUnitName())
|
||||
.set("code", bo.getCode());
|
||||
return appPersonnelInfoMapper.update(null, uw) > 0;
|
||||
/* ====== 更新场景 ====== */
|
||||
// 1.2 把 bo 的新值刷到主表
|
||||
appPersonnelInfoMapper.update(null,
|
||||
Wrappers.<AppPersonnelInfo>update()
|
||||
.eq("device_id", deviceId)
|
||||
.set("name", bo.getName())
|
||||
.set("position", bo.getPosition())
|
||||
.set("unit_name", bo.getUnitName())
|
||||
.set("code", bo.getCode())
|
||||
.set("update_time", new Date()));
|
||||
}
|
||||
|
||||
// 2. 无论新增/更新,都插入一条履历
|
||||
AppPersonnelInfoRecords record = new AppPersonnelInfoRecords();
|
||||
// 只拷业务字段,不拷时间、id、操作人
|
||||
BeanUtil.copyProperties(main, record, "id", "createTime", "updateTime", "createBy", "updateBy");
|
||||
record.setId(null); // 让自增
|
||||
record.setPersonnelId(main.getId()); // 关键:主键已回写,不会为 null
|
||||
appPersonnelInfoRecordsMapper.insert(record);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -273,6 +418,10 @@ public class DeviceXinghanBizService {
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
throw new ServiceException("请选择设备");
|
||||
}
|
||||
if(!StringUtils.isNotEmpty(bo.getSendMsg()))
|
||||
{
|
||||
throw new ServiceException("请输入发送内容");
|
||||
}
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
// 使用 in 语句根据id集合查询
|
||||
queryWrapper.in("id", deviceIds);
|
||||
@ -325,9 +474,11 @@ public class DeviceXinghanBizService {
|
||||
*/
|
||||
private void sendSingleAlarmMessage(Device device, String message) {
|
||||
String deviceImei = device.getDeviceImei();
|
||||
|
||||
int msgLen = message.length() / 2;
|
||||
StringBuilder msgBuilder = new StringBuilder(message);
|
||||
msgBuilder.insert(msgLen, '|');
|
||||
// 缓存告警消息到Redis
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_ALARM_MESSAGE_KEY_PREFIX, message, Duration.ofSeconds(5 * 60L));
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_ALARM_MESSAGE_KEY_PREFIX, msgBuilder.toString(), Duration.ofSeconds(5 * 60L));
|
||||
|
||||
// 构建并发送MQTT消息
|
||||
Map<String, Object> payload = Map.of("ins_BreakNews", Collections.singletonList(0));
|
||||
@ -350,7 +501,7 @@ public class DeviceXinghanBizService {
|
||||
* @param payloadKey 指令负载数据的键名
|
||||
* @param deviceAction 设备操作类型描述
|
||||
*/
|
||||
private void sendCommand(DeviceInstructDto dto, String payloadKey, String deviceAction) {
|
||||
private void sendCommand(DeviceXinghanInstructDto dto, String payloadKey, String deviceAction) {
|
||||
long deviceId = dto.getDeviceId();
|
||||
|
||||
// 1. 使用Optional简化空值检查,使代码更简洁
|
||||
@ -394,13 +545,127 @@ public class DeviceXinghanBizService {
|
||||
deviceAction,
|
||||
content,
|
||||
AppLoginHelper.getUserId());
|
||||
|
||||
// 6. 新建报警信息
|
||||
createAlarm(device.getId(),deviceImei,payloadKey,value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量发送设备控制指令
|
||||
*
|
||||
* @param dto 设备ID列表
|
||||
* @param payloadKey 指令负载数据的键名
|
||||
* @param deviceAction 设备操作类型描述
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class) // 1. 事务注解
|
||||
public void sendCommandBatch(DeviceXinghanInstructDto dto, String payloadKey, String deviceAction) {
|
||||
List<String> errorMessages = Collections.synchronizedList(new ArrayList<>());
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt(dto.getInstructValue());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("指令值格式不正确,必须为整数。", e);
|
||||
}
|
||||
Map<String, List<Integer>> payload = Map.of(payloadKey, List.of(value));
|
||||
|
||||
// 一次性查询所有设备信息
|
||||
List<Device> devices = deviceMapper.selectList(
|
||||
new QueryWrapper<Device>().lambda().in(Device::getId, dto.getDeviceIds())
|
||||
);
|
||||
// 日志信息
|
||||
String contentText = resolveGradeDesc(payloadKey, value);
|
||||
|
||||
List<DeviceLog> logs = new ArrayList<>();
|
||||
try {
|
||||
for (Device device : devices) {
|
||||
String deviceImei = device.getDeviceImei();
|
||||
String deviceName = device.getDeviceName();
|
||||
|
||||
// 2. 提前进行设备状态检查,逻辑更清晰
|
||||
if (isDeviceOffline(deviceImei)) {
|
||||
throw new ServiceException("设备已断开连接:" + deviceName);
|
||||
}
|
||||
|
||||
String topic = MqttConstants.GLOBAL_PUB_KEY + deviceImei;
|
||||
String json = JsonUtils.toJsonString(payload);
|
||||
|
||||
mqttGateway.sendMsgToMqtt(topic, 1, json);
|
||||
log.info("发送指令成功 => topic:{}, payload:{}", topic, json);
|
||||
|
||||
// 创建设备日志实体
|
||||
DeviceLog deviceLog = new DeviceLog();
|
||||
deviceLog.setDeviceId(device.getId());
|
||||
deviceLog.setDeviceAction(deviceAction);
|
||||
deviceLog.setContent(contentText);
|
||||
deviceLog.setCreateBy(AppLoginHelper.getUserId());
|
||||
deviceLog.setDeviceName(deviceName);
|
||||
deviceLog.setCreateTime(new Date());
|
||||
logs.add(deviceLog);
|
||||
|
||||
createAlarm(device.getId(), deviceImei, payloadKey, value);
|
||||
}
|
||||
deviceLogMapper.insertBatch(logs);
|
||||
} catch (ServiceException e) {
|
||||
// 捕获并重新抛出自定义异常,避免内层异常被外层泛化捕获
|
||||
log.error("批量发送指令失败: {}", e.getMessage(), e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("批量发送指令发生未知错误", e);
|
||||
throw new ServiceException("批量发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查设备是否离线
|
||||
*/
|
||||
|
||||
// private boolean isDeviceOffline(String imei) {
|
||||
// // 原方法名语义相反,这里取反,使含义更清晰
|
||||
// return getDeviceStatus(imei);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 新建报警 Bo
|
||||
*/
|
||||
private void createAlarm(Long deviceId, String deviceImei,
|
||||
String payloadKey, int value) {
|
||||
// 这里直接放你原来的 createAlarmBo 全部逻辑
|
||||
if (!"ins_SOSGrade".equals(payloadKey) || value == 0) {
|
||||
return;
|
||||
}
|
||||
AlarmTypeEnum type = AlarmTypeEnum.SOS;
|
||||
String redisKey = buildAlarmRedisKey(deviceImei, type);
|
||||
Long alarmId = RedisUtils.getCacheObject(redisKey);
|
||||
// 已存在未结束报警 -> 什么都不做(同一条报警)
|
||||
if (alarmId != null) {
|
||||
// key 还在 -> 同一条报警,只续期
|
||||
RedisUtils.setCacheObject(redisKey, alarmId, Duration.ofMinutes(10));
|
||||
return;
|
||||
}
|
||||
// 不存在 -> 新建
|
||||
DeviceAlarmBo bo = new DeviceAlarmBo();
|
||||
bo.setDeviceId(deviceId);
|
||||
bo.setDeviceImei(deviceImei);
|
||||
bo.setDeviceAction(0); // 强制报警
|
||||
bo.setStartTime(new Date());
|
||||
bo.setTreatmentState(1); // 未处理
|
||||
bo.setContent("强制报警:" + type.getDesc());
|
||||
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"));
|
||||
}
|
||||
deviceAlarmService.insertByBo(bo);
|
||||
RedisUtils.setCacheObject(redisKey, bo.getId(), Duration.ofMinutes(10));
|
||||
}
|
||||
|
||||
/**
|
||||
* key 构建
|
||||
*/
|
||||
private String buildAlarmRedisKey(String deviceImei, AlarmTypeEnum type) {
|
||||
return StrUtil.format("{}{}{}{}:alarm_id",
|
||||
GLOBAL_REDIS_KEY, DEVICE_KEY_PREFIX, deviceImei, type.getSuffix());
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录设备操作日志
|
||||
* @param deviceId 设备ID
|
||||
@ -430,4 +695,76 @@ public class DeviceXinghanBizService {
|
||||
return RedisUtils.getCacheObject(deviceOnlineStatusRedisKey)==null;
|
||||
}
|
||||
|
||||
public List<DeviceType> queryDeviceTypes() {
|
||||
DeviceTypeQueryCriteria criteria = new DeviceTypeQueryCriteria();
|
||||
|
||||
return deviceTypeMapper.findAll(criteria);
|
||||
}
|
||||
|
||||
// @Log("新增设备")
|
||||
public void addDevice(DeviceForm deviceForm) {
|
||||
if (deviceForm.getDeviceMac() != null && deviceForm.getBluetoothName() == null) {
|
||||
throw new BadRequestException("请填写蓝牙名称!!!");
|
||||
}
|
||||
|
||||
Device device1 = deviceMapper.selectOne(new QueryWrapper<Device>().eq("device_mac", deviceForm.getDeviceMac()));
|
||||
if (device1 != null) {
|
||||
throw new BadRequestException("设备MAC已存在!!!");
|
||||
}
|
||||
Device device2 = deviceMapper.selectOne(new QueryWrapper<Device>().eq("device_imei", deviceForm.getDeviceImei()));
|
||||
if (device2 != null) {
|
||||
throw new BadRequestException("设备IMEI已存在!!!");
|
||||
}
|
||||
|
||||
DeviceTypeQueryCriteria queryCriteria = new DeviceTypeQueryCriteria();
|
||||
queryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
|
||||
queryCriteria.setCustomerId(LoginHelper.getUserId());
|
||||
DeviceTypeGrants typeGrants = deviceTypeGrantsMapper.selectById(queryCriteria.getDeviceTypeId());
|
||||
if (typeGrants == null) {
|
||||
throw new ServiceException("设备类型不存在!!!");
|
||||
}
|
||||
DeviceType deviceTypes = deviceTypeMapper.selectById(typeGrants.getDeviceTypeId());
|
||||
if (deviceTypes == null) {
|
||||
throw new ServiceException("设备类型不存在!!!");
|
||||
}
|
||||
|
||||
// 转换对象并插入数据库
|
||||
Device device = new Device();
|
||||
|
||||
BeanUtil.copyProperties(deviceForm, device, true);
|
||||
device.setDeviceNo(createDeviceNo());
|
||||
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
|
||||
device.setCurrentOwnerId(loginUser.getUserId());
|
||||
device.setOriginalOwnerId(loginUser.getUserId());
|
||||
device.setCreateByName(loginUser.getNickname());
|
||||
device.setTypeName(deviceTypes.getTypeName());
|
||||
device.setDeviceType(deviceTypes.getId());
|
||||
if (device.getDeviceImei() != null) {
|
||||
device.setPubTopic("A/" + device.getDeviceImei());
|
||||
device.setSubTopic("B/" + device.getDeviceImei());
|
||||
}
|
||||
// 0 未绑定
|
||||
device.setBindingStatus(0);
|
||||
deviceMapper.insert(device);
|
||||
|
||||
// 新增设备类型记录
|
||||
DeviceAssignments assignments = new DeviceAssignments();
|
||||
assignments.setDeviceId(device.getId());
|
||||
assignments.setAssignedAt(LocalDateTime.now());
|
||||
// 分配者
|
||||
assignments.setAssignerId(loginUser.getUserId());
|
||||
assignments.setAssignerName(loginUser.getUsername());
|
||||
// 接收者
|
||||
assignments.setAssigneeId(loginUser.getUserId());
|
||||
assignments.setActive(DeviceActiveStatusEnum.ACTIVE.getCode());
|
||||
String lever = USER_ID_SEPARATOR + loginUser.getUserId();
|
||||
assignments.setLever(lever);
|
||||
deviceAssignmentsService.save(assignments);
|
||||
}
|
||||
|
||||
private String createDeviceNo() {
|
||||
String uuidStr = UUID.fastUUID().toString(); // 获取带 - 的标准格式字符串
|
||||
return uuidStr.replaceAll("-", "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -126,9 +126,8 @@ public class AppPasswordAuthStrategy implements IAuthStrategy {
|
||||
.eq(AppUser::getUserType, UserType.APP_USER.getUserType()));
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", username);
|
||||
// throw new UserException("user.not.exists", phonenumber);
|
||||
// 新增AppUser用户
|
||||
return null;
|
||||
throw new UserException("user.not.exists", username);
|
||||
|
||||
} else if (SystemConstants.DISABLE.equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", username);
|
||||
throw new UserException("user.blocked", username);
|
||||
|
||||
@ -0,0 +1,659 @@
|
||||
package com.fuyuanshen.web.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDevice6075DetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoRecordsMapper;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.*;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.equipment.enums.LightModeEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessage;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import com.fuyuanshen.global.mqtt.enums.DeviceFunctionType6075;
|
||||
import com.fuyuanshen.global.mqtt.service.IotMqttService;
|
||||
import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.buildArr;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.generateFixedBitmapData;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
|
||||
private final AppPersonnelInfoRecordsMapper appPersonnelInfoRecordsMapper;
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
private final MqttGateway mqttGateway;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
|
||||
private final IotMqttService iotMqttService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AppDevice6075DetailVo getInfo(Long id) {
|
||||
Device device = deviceMapper.selectById(id);
|
||||
if (device == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
|
||||
AppDevice6075DetailVo vo = new AppDevice6075DetailVo();
|
||||
vo.setDeviceId(device.getId());
|
||||
vo.setDeviceName(device.getDeviceName());
|
||||
vo.setDevicePic(device.getDevicePic());
|
||||
vo.setDeviceImei(device.getDeviceImei());
|
||||
vo.setDeviceMac(device.getDeviceMac());
|
||||
vo.setDeviceStatus(device.getDeviceStatus());
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
if (deviceType != null) {
|
||||
vo.setCommunicationMode(Integer.valueOf(deviceType.getCommunicationMode()));
|
||||
vo.setTypeName(deviceType.getTypeName());
|
||||
}
|
||||
vo.setBluetoothName(device.getBluetoothName());
|
||||
|
||||
vo.setSendMsg(device.getSendMsg());
|
||||
|
||||
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
||||
.eq("device_id", device.getId());
|
||||
AppPersonnelInfo appPersonnelInfo = appPersonnelInfoMapper.selectOne(qw);
|
||||
if (appPersonnelInfo != null) {
|
||||
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
|
||||
vo.setPersonnelInfo(personnelInfoVo);
|
||||
}
|
||||
// 设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
// 设备在线状态
|
||||
if ("1".equals(onlineStatus)) {
|
||||
vo.setOnlineStatus(1);
|
||||
} else if ("2".equals(onlineStatus)) {
|
||||
vo.setOnlineStatus(2);
|
||||
} else {
|
||||
vo.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
vo.setMainLightMode(jsonObject.getString("mainLightMode"));
|
||||
vo.setLaserLightMode(jsonObject.getString("laserLightMode"));
|
||||
vo.setBatteryPercentage(jsonObject.getString("batteryPercentage"));
|
||||
vo.setChargeState(jsonObject.getString("chargeState"));
|
||||
vo.setBatteryRemainingTime(jsonObject.getString("batteryRemainingTime"));
|
||||
} else {
|
||||
vo.setBatteryPercentage("0");
|
||||
}
|
||||
|
||||
String lightModeStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_MODE_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
vo.setMainLightMode(lightModeStatus);
|
||||
}
|
||||
|
||||
String lightBrightnessStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(lightBrightnessStatus)) {
|
||||
vo.setLightBrightness(lightBrightnessStatus);
|
||||
}
|
||||
|
||||
String laserLightMode = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LASER_MODE_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(laserLightMode)) {
|
||||
vo.setLaserLightMode(laserLightMode);
|
||||
}
|
||||
|
||||
// 获取经度纬度
|
||||
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
|
||||
String locationInfo = RedisUtils.getCacheObject(locationKey);
|
||||
if (StringUtils.isNotBlank(locationInfo)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
|
||||
vo.setLongitude(jsonObject.get("longitude").toString());
|
||||
vo.setLatitude(jsonObject.get("latitude").toString());
|
||||
vo.setAddress((String) jsonObject.get("address"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
vo.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
|
||||
String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(lightBrightness)) {
|
||||
vo.setLightBrightness(lightBrightness);
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int sendMessage(AppDeviceSendMsgBo bo) {
|
||||
List<Long> deviceIds = bo.getDeviceIds();
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
throw new ServiceException("请选择设备");
|
||||
}
|
||||
for (Long deviceId : deviceIds) {
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在" + deviceId);
|
||||
}
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
try {
|
||||
ClassPathResource resource = new ClassPathResource("image/background.png");
|
||||
InputStream inputStream = resource.getInputStream();
|
||||
|
||||
byte[] largeData = ImageWithTextGenerate.generate160x80ImageWithText2(bo.getSendMsg(), inputStream, 25600);
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data", Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data");
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
log.info("发送信息第0块数据大小: {} 字节", specificChunk.length);
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(6);
|
||||
intData.add(1);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送信息点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", deviceId)
|
||||
.set("send_msg", bo.getSendMsg());
|
||||
deviceMapper.update(updateWrapper);
|
||||
|
||||
recordDeviceLog(deviceId, device.getDeviceName(), "发送信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
log.info("发送信息设备发送信息失败:{}", deviceId);
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
// 发送消息
|
||||
messageSending(device.getDeviceImei());
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录设备操作日志
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param content 日志内容
|
||||
* @param operator 操作人
|
||||
*/
|
||||
@Override
|
||||
public void recordDeviceLog(Long deviceId, String deviceName, String deviceAction, String content, Long operator) {
|
||||
try {
|
||||
// 创建设备日志实体
|
||||
com.fuyuanshen.equipment.domain.DeviceLog deviceLog = new com.fuyuanshen.equipment.domain.DeviceLog();
|
||||
deviceLog.setDeviceId(deviceId);
|
||||
deviceLog.setDeviceAction(deviceAction);
|
||||
deviceLog.setContent(content);
|
||||
deviceLog.setCreateBy(operator);
|
||||
deviceLog.setDeviceName(deviceName);
|
||||
deviceLog.setCreateTime(new Date());
|
||||
|
||||
// 插入日志记录
|
||||
deviceLogMapper.insert(deviceLog);
|
||||
} catch (Exception e) {
|
||||
log.error("记录设备操作日志失败: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
||||
Long deviceId = bo.getDeviceId();
|
||||
Device deviceObj = deviceMapper.selectById(deviceId);
|
||||
if (deviceObj == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
if (getDeviceStatus(deviceObj.getDeviceImei())) {
|
||||
throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
||||
.eq("device_id", deviceId);
|
||||
List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw);
|
||||
// unitName,position,name,id
|
||||
byte[] unitName = generateFixedBitmapData(bo.getUnitName(), 120);
|
||||
byte[] position = generateFixedBitmapData(bo.getPosition(), 120);
|
||||
byte[] name = generateFixedBitmapData(bo.getName(), 120);
|
||||
byte[] id = generateFixedBitmapData(bo.getCode(), 120);
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(2);
|
||||
buildArr(convertHexToDecimal(unitName), intData);
|
||||
buildArr(convertHexToDecimal(name), intData);
|
||||
buildArr(convertHexToDecimal(position), intData);
|
||||
buildArr(convertHexToDecimal(id), intData);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo);
|
||||
String logContent = "单位:" + bo.getUnitName() + ",职位:" + bo.getPosition() + ",姓名:" + bo.getName() + ",ID:" + bo.getCode();
|
||||
recordDeviceLog(deviceId, deviceObj.getDeviceName(), "人员信息登记", logContent, AppLoginHelper.getUserId());
|
||||
if (ObjectUtils.length(appPersonnelInfoVos) == 0) {
|
||||
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo);
|
||||
|
||||
AppPersonnelInfoRecords appPersonnelInfoRecords = new AppPersonnelInfoRecords();
|
||||
BeanUtil.copyProperties(appPersonnelInfo, appPersonnelInfoRecords);
|
||||
appPersonnelInfoRecords.setId(null);
|
||||
appPersonnelInfoRecords.setPersonnelId(appPersonnelInfo.getId());
|
||||
|
||||
appPersonnelInfoRecordsMapper.insert(appPersonnelInfoRecords);
|
||||
} else {
|
||||
UpdateWrapper<AppPersonnelInfo> uw = new UpdateWrapper<>();
|
||||
uw.eq("device_id", deviceId)
|
||||
.set("name", bo.getName())
|
||||
.set("position", bo.getPosition())
|
||||
.set("unit_name", bo.getUnitName())
|
||||
.set("code", bo.getCode());
|
||||
appPersonnelInfoMapper.update(null, uw);
|
||||
|
||||
AppPersonnelInfoVo personnelInfoVo = appPersonnelInfoVos.get(0);
|
||||
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
AppPersonnelInfoRecords appPersonnelInfoRecords = new AppPersonnelInfoRecords();
|
||||
BeanUtil.copyProperties(appPersonnelInfo, appPersonnelInfoRecords);
|
||||
appPersonnelInfoRecords.setId(null);
|
||||
appPersonnelInfoRecords.setPersonnelId(personnelInfoVo.getId());
|
||||
appPersonnelInfoRecordsMapper.insert(appPersonnelInfoRecords);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadDeviceLogo2(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
MultipartFile file = bo.getFile();
|
||||
|
||||
byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600);
|
||||
|
||||
log.info("长度:" + largeData.length);
|
||||
// 在获取 largeData 后,将其与前缀合并
|
||||
byte[] prefix = new byte[]{0x50, 0x49, 0x43, 0x54, 0x55, 0x52, 0x45}; // "PICTURE"
|
||||
byte[] combinedData = new byte[prefix.length + largeData.length];
|
||||
System.arraycopy(prefix, 0, combinedData, 0, prefix.length);
|
||||
System.arraycopy(largeData, 0, combinedData, prefix.length, largeData.length);
|
||||
|
||||
// 将 combinedData 转换为十六进制表示
|
||||
String[] hexArray = new String[combinedData.length];
|
||||
for (int i = 0; i < combinedData.length; i++) {
|
||||
hexArray[i] = String.format("0x%02X", combinedData[i]);
|
||||
}
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("instruct", combinedData);
|
||||
String[] specificChunk = ImageToCArrayConverter.getChunk2(hexArray, 0, bo.getChunkSize());
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, Arrays.toString(specificChunk));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), Arrays.toString(specificChunk));
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
// throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
log.info(device.getDeviceName() + ",设备已断开连接");
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", device.getDeviceName() + ",设备已断开连接", AppLoginHelper.getUserId());
|
||||
return;
|
||||
}
|
||||
MultipartFile file = bo.getFile();
|
||||
|
||||
byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600);
|
||||
log.info("长度:" + largeData.length);
|
||||
|
||||
log.info("原始数据大小: {} 字节", largeData.length);
|
||||
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX, Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX);
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
log.info("第0块数据大小: {} 字节", specificChunk.length);
|
||||
// log.info("第0块数据: {}", Arrays.toString(specificChunk));
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(3);
|
||||
intData.add(1);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* (主光模式)
|
||||
* 0(关闭灯光),1(强光),2(超强光), 3(工作光), 4(节能光),5(爆闪),6(SOS)
|
||||
*/
|
||||
@Override
|
||||
public void lightModeSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
|
||||
String deviceImei = device.getDeviceImei();
|
||||
Long deviceType = device.getDeviceType();
|
||||
String tenantCode = device.getTenantId();
|
||||
|
||||
// 构建发送强光模式的MqttMessage对象
|
||||
MqttMessage message = new MqttMessage();
|
||||
message.setRequestId(UUID.randomUUID().toString()); // 生成唯一的请求ID
|
||||
message.setImei(device.getDeviceImei()); // 设备IMEI
|
||||
message.setTimestamp(System.currentTimeMillis()); // 当前时间戳
|
||||
message.setFuncType(DeviceFunctionType6075.LIGHT_MODE.getNumber()); // 功能类型,这里假设为灯光模式
|
||||
|
||||
// 构建数据内容 - 强光模式参数
|
||||
Map<String, Object> lightData = new HashMap<>();
|
||||
lightData.put("mode", 1); // 1表示强光模式
|
||||
lightData.put("type", "mainLight"); // 主灯类型
|
||||
// 可以根据需要添加更多参数
|
||||
lightData.put("brightness", 100); // 亮度设置为100%
|
||||
|
||||
message.setData(lightData);
|
||||
|
||||
// 调用sendCommand方法发送指令
|
||||
iotMqttService.sendCommand(tenantCode, deviceType, deviceImei, message);
|
||||
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(1);
|
||||
intData.add(instructValue);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
LightModeEnum modeEnum = LightModeEnum.getByCode(instructValue);
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "灯光模式", modeEnum != null ? modeEnum.getName() : null, AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
public void lightModeSettings1(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(1);
|
||||
intData.add(instructValue);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
LightModeEnum modeEnum = LightModeEnum.getByCode(instructValue);
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "灯光模式", modeEnum != null ? modeEnum.getName() : null, AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 灯光亮度设置
|
||||
@Override
|
||||
public void lightBrightnessSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
String instructValue = params.getInstructValue();
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(5);
|
||||
String[] values = instructValue.split("\\.");
|
||||
String value1 = values[0];
|
||||
String value2 = values[1];
|
||||
if (StringUtils.isNoneBlank(value1)) {
|
||||
intData.add(Integer.parseInt(value1));
|
||||
}
|
||||
if (StringUtils.isNoneBlank(value2)) {
|
||||
intData.add(Integer.parseInt(value2));
|
||||
}
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 激光模式设置
|
||||
@Override
|
||||
public void laserModeSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(4);
|
||||
intData.add(instructValue);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
// 1代表开启激光灯,此时主灯关闭,主灯控件为关机状态,为0代表关闭激光灯
|
||||
if ("1".equals(params.getInstructValue())) {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "激光模式设置", "开启激光灯", AppLoginHelper.getUserId());
|
||||
} else {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "激光模式设置", "关闭激光灯", AppLoginHelper.getUserId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapReverseGeocoding(DeviceInstructDto params) {
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("device_imei", params.getDeviceImei());
|
||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||
if (ObjectUtils.length(devices) == 0) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int sendAlarmMessage(AppDeviceSendMsgBo bo) {
|
||||
try {
|
||||
List<Long> deviceIds = bo.getDeviceIds();
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
throw new ServiceException("请选择设备");
|
||||
}
|
||||
|
||||
for (Long deviceId : deviceIds) {
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在" + deviceId);
|
||||
}
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
try {
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(7);
|
||||
intData.add(Integer.parseInt(bo.getInstructValue()));
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
|
||||
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", deviceId)
|
||||
.set("send_msg", bo.getSendMsg());
|
||||
deviceMapper.update(updateWrapper);
|
||||
if ("0".equals(bo.getInstructValue())) {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "解除告警信息", "关闭设备", AppLoginHelper.getUserId());
|
||||
} else {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "发送告警信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("设备发送告警信息信息失败:{}", deviceId);
|
||||
throw new ServiceException("设备发送告警信息信息失败");
|
||||
}
|
||||
messageSending(device.getDeviceImei());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送告警信息指令失败");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageSending(String deviceImei) {
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + ":messageSending";
|
||||
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDeviceStatus(String deviceImei) {
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||
return RedisUtils.getCacheObject(deviceOnlineStatusRedisKey) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchUploadLogo(AppDeviceLogoUploadDto bo) {
|
||||
|
||||
List<Long> deviceIds = bo.getDeviceIds();
|
||||
MultipartFile file = bo.getFile();
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
throw new ServiceException("请选择设备");
|
||||
}
|
||||
for (Long deviceId : deviceIds) {
|
||||
AppDeviceLogoUploadDto dto = new AppDeviceLogoUploadDto();
|
||||
dto.setDeviceId(deviceId);
|
||||
dto.setFile(file);
|
||||
uploadDeviceLogo(dto);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
package com.fuyuanshen.web.util;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HexFormat;
|
||||
|
||||
/**
|
||||
* 文件哈希工具类
|
||||
*/
|
||||
public class FileHashUtil {
|
||||
private static final String ALGORITHM = "SHA-256";
|
||||
|
||||
public static String hash(MultipartFile file) throws IOException {
|
||||
MessageDigest digest = DigestUtils.getDigest(ALGORITHM);
|
||||
try (InputStream in = file.getInputStream()) {
|
||||
byte[] buf = new byte[8192];
|
||||
int len;
|
||||
while ((len = in.read(buf)) != -1) {
|
||||
digest.update(buf, 0, len);
|
||||
}
|
||||
}
|
||||
return HexFormat.of().formatHex(digest.digest());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,194 @@
|
||||
package com.fuyuanshen.web.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bytedeco.javacv.FFmpegFrameGrabber;
|
||||
import org.bytedeco.javacv.Frame;
|
||||
import org.bytedeco.javacv.Java2DFrameUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 视频处理工具类
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class VideoProcessUtil {
|
||||
|
||||
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
/**
|
||||
* 创建临时视频文件
|
||||
*/
|
||||
public File createTempVideoFile(MultipartFile file) throws Exception {
|
||||
File tempFile = Files.createTempFile("upload-", ".mp4").toFile();
|
||||
file.transferTo(tempFile);
|
||||
log.debug("创建临时视频文件: {}", tempFile.getAbsolutePath());
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理视频并转换为Hex字符串列表
|
||||
*/
|
||||
public List<String> processVideoToHex(File videoFile, int frameRate, int duration, int width, int height) throws Exception {
|
||||
// 1. 提取视频帧
|
||||
List<BufferedImage> frames = extractFramesFromVideo(videoFile, frameRate, duration, width, height);
|
||||
|
||||
// 2. 转换为RGB565格式
|
||||
byte[] binaryData = convertFramesToRGB565(frames);
|
||||
|
||||
// 3. 转换为Hex字符串列表
|
||||
return bytesToHexList(binaryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从视频中提取帧
|
||||
*/
|
||||
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;
|
||||
|
||||
try (FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(videoFile)) {
|
||||
grabber.start();
|
||||
|
||||
long totalFramesInVideo = grabber.getLengthInFrames();
|
||||
int fps = (int) Math.round(grabber.getFrameRate());
|
||||
if (fps <= 0) fps = 30;
|
||||
|
||||
double durationSeconds = (double) totalFramesInVideo / fps;
|
||||
if (durationSeconds < duration) {
|
||||
throw new IllegalArgumentException("视频太短,至少需要 " + duration + " 秒");
|
||||
}
|
||||
|
||||
double frameInterval = (double) totalFramesInVideo / 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 = Java2DFrameUtils.toBufferedImage(frame);
|
||||
frames.add(cropImage(bufferedImage, width, height));
|
||||
} else {
|
||||
throw new IllegalArgumentException("无法获取第 " + targetFrameNumber + "帧");
|
||||
}
|
||||
}
|
||||
|
||||
grabber.stop();
|
||||
}
|
||||
|
||||
log.debug("从视频中提取了 {} 帧", frames.size());
|
||||
return frames;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将所有帧转换为 RGB565 格式字节数组
|
||||
*/
|
||||
private byte[] convertFramesToRGB565(List<BufferedImage> frames) throws Exception {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
|
||||
for (BufferedImage image : frames) {
|
||||
byte[] rgb565Bytes = convertToRGB565(image);
|
||||
byteArrayOutputStream.write(rgb565Bytes);
|
||||
}
|
||||
|
||||
byte[] result = byteArrayOutputStream.toByteArray();
|
||||
log.debug("转换RGB565数据完成,总字节数: {}", result.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字节数组转换为Hex字符串列表
|
||||
*/
|
||||
private List<String> bytesToHexList(byte[] bytes) {
|
||||
List<String> hexList = new ArrayList<>();
|
||||
for (byte b : bytes) {
|
||||
int value = b & 0xFF;
|
||||
char high = HEX_ARRAY[value >>> 4];
|
||||
char low = HEX_ARRAY[value & 0x0F];
|
||||
hexList.add(String.valueOf(high) + low);
|
||||
}
|
||||
return hexList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除临时文件
|
||||
*/
|
||||
public void deleteTempFile(File file) {
|
||||
if (file != null && file.exists()) {
|
||||
if (file.delete()) {
|
||||
log.debug("删除临时文件成功: {}", file.getAbsolutePath());
|
||||
} else {
|
||||
log.warn("无法删除临时文件: {}", file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 裁剪图像到目标尺寸
|
||||
*/
|
||||
private BufferedImage cropImage(BufferedImage img, int targetWidth, int targetHeight) {
|
||||
int w = Math.min(img.getWidth(), targetWidth);
|
||||
int h = Math.min(img.getHeight(), targetHeight);
|
||||
return img.getSubimage(0, 0, w, h);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 BufferedImage 转换为 RGB565 格式的字节数组
|
||||
*/
|
||||
private byte[] convertToRGB565(BufferedImage image) {
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
byte[] result = new byte[width * height * 2];
|
||||
int index = 0;
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int rgb = image.getRGB(x, y);
|
||||
int r = ((rgb >> 16) & 0xFF) >> 3;
|
||||
int g = ((rgb >> 8) & 0xFF) >> 2;
|
||||
int b = (rgb & 0xFF) >> 3;
|
||||
short pixel = (short) ((r << 11) | (g << 5) | b);
|
||||
|
||||
result[index++] = (byte) (pixel >> 8);
|
||||
result[index++] = (byte) pixel;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存帧到本地(用于调试)
|
||||
*/
|
||||
public void saveFramesToLocal(List<BufferedImage> frames, String prefix) {
|
||||
File outputDir = new File("output_frames");
|
||||
if (!outputDir.exists()) {
|
||||
outputDir.mkdirs();
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (BufferedImage frame : frames) {
|
||||
try {
|
||||
File outputImage = new File(outputDir, prefix + "_" + (index++) + ".png");
|
||||
ImageIO.write(frame, "png", outputImage);
|
||||
log.debug("保存帧图片成功: {}", outputImage.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
log.error("保存帧图片失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,32 +52,32 @@ spring:
|
||||
url: jdbc:mysql://47.120.79.150:3306/fys-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
username: root
|
||||
password: Jq_123456#
|
||||
# # 从库数据源
|
||||
# slave:
|
||||
# lazy: true
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
# username:
|
||||
# password:
|
||||
# oracle:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: oracle.jdbc.OracleDriver
|
||||
# url: jdbc:oracle:thin:@//localhost:1521/XE
|
||||
# username: ROOT
|
||||
# password: root
|
||||
# postgres:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: org.postgresql.Driver
|
||||
# url: jdbc:postgresql://localhost:5432/postgres?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
# username: root
|
||||
# password: root
|
||||
# sqlserver:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
# url: jdbc:sqlserver://localhost:1433;DatabaseName=tempdb;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true
|
||||
# username: SA
|
||||
# password: root
|
||||
# # 从库数据源
|
||||
# slave:
|
||||
# lazy: true
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
# username:
|
||||
# password:
|
||||
# oracle:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: oracle.jdbc.OracleDriver
|
||||
# url: jdbc:oracle:thin:@//localhost:1521/XE
|
||||
# username: ROOT
|
||||
# password: root
|
||||
# postgres:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: org.postgresql.Driver
|
||||
# url: jdbc:postgresql://localhost:5432/postgres?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
# username: root
|
||||
# password: root
|
||||
# sqlserver:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
# url: jdbc:sqlserver://localhost:1433;DatabaseName=tempdb;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true
|
||||
# username: SA
|
||||
# password: root
|
||||
hikari:
|
||||
# 最大连接池数量
|
||||
maxPoolSize: 20
|
||||
@ -177,12 +177,12 @@ sms:
|
||||
access-key-id: LTAI5tJdDNpZootsPQ5hdELx
|
||||
# 称为accessSecret有些称之为apiSecret
|
||||
access-key-secret: mU4WtffcCXpHPz5tLwQpaGtLsJXONt
|
||||
#模板ID 非必须配置,如果使用sendMessage的快速发送需此配置
|
||||
#模板ID 非必须配置,如果使用sendMessage的快速发送需此配置
|
||||
template-id: SMS_322180518
|
||||
#模板变量 上述模板的变量
|
||||
#模板变量 上述模板的变量
|
||||
templateName: code
|
||||
signature: 湖北星汉研创科技
|
||||
# sdk-app-id: 您的sdkAppId
|
||||
signature: 湖北星汉研创科技
|
||||
# sdk-app-id: 您的sdkAppId
|
||||
config2:
|
||||
# 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||
supplier: tencent
|
||||
@ -210,7 +210,7 @@ justauth:
|
||||
client-id: 449c4*********937************759
|
||||
client-secret: ac7***********1e0************28d
|
||||
redirect-uri: ${justauth.address}/social-callback?source=topiam
|
||||
scopes: [openid, email, phone, profile]
|
||||
scopes: [ openid, email, phone, profile ]
|
||||
qq:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
@ -276,33 +276,20 @@ justauth:
|
||||
redirect-uri: ${justauth.address}/social-callback?source=gitea
|
||||
|
||||
|
||||
# 文件存储路径
|
||||
file:
|
||||
mac:
|
||||
path: ~/file/
|
||||
avatar: ~/avatar/
|
||||
linux:
|
||||
path: /home/eladmin/file/
|
||||
avatar: /home/eladmin/avatar/
|
||||
windows:
|
||||
path: C:\eladmin\file\
|
||||
avatar: C:\eladmin\avatar\
|
||||
# 文件大小 /M
|
||||
maxSize: 100
|
||||
avatarMaxSize: 5
|
||||
device:
|
||||
pic: C:\eladmin\file\ #设备图片存储路径
|
||||
ip: http://fuyuanshen.com:81/ #服务器地址
|
||||
app_avatar:
|
||||
pic: C:\eladmin\file\ #设备图片存储路径
|
||||
#ip: http://fuyuanshen.com:81/ #服务器地址
|
||||
ip: https://fuyuanshen.com/ #服务器地址
|
||||
# MQTT配置
|
||||
mqtt:
|
||||
username: admin
|
||||
password: #YtvpSfCNG
|
||||
url: tcp://47.120.79.150:2883
|
||||
password: fys123456
|
||||
url: tcp://47.107.152.87:1883
|
||||
subClientId: fys_subClient
|
||||
subTopic: A/#
|
||||
pubTopic: B/#
|
||||
pubClientId: fys_pubClient
|
||||
subTopic: A/#,status/tenantCode/#,report/tenantCode/#
|
||||
pubTopic: B/#,command/tenantCode/#
|
||||
pubClientId: fys_pubClient
|
||||
|
||||
|
||||
# TTS语音交互配置
|
||||
alibaba:
|
||||
tts:
|
||||
appKey: KTwSUKMrf2olFfjC
|
||||
akId: LTAI5t6RsfCvQh57qojzbEoe
|
||||
akSecret: MTqvK2mXYeCRkl1jVPndiNumyaad0R
|
||||
@ -55,32 +55,32 @@ spring:
|
||||
url: jdbc:mysql://47.120.79.150:3306/fys-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
username: root
|
||||
password: Jq_123456#
|
||||
# # 从库数据源
|
||||
# slave:
|
||||
# lazy: true
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
# username:
|
||||
# password:
|
||||
# oracle:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: oracle.jdbc.OracleDriver
|
||||
# url: jdbc:oracle:thin:@//localhost:1521/XE
|
||||
# username: ROOT
|
||||
# password: root
|
||||
# postgres:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: org.postgresql.Driver
|
||||
# url: jdbc:postgresql://localhost:5432/postgres?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
# username: root
|
||||
# password: root
|
||||
# sqlserver:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
# url: jdbc:sqlserver://localhost:1433;DatabaseName=tempdb;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true
|
||||
# username: SA
|
||||
# password: root
|
||||
# # 从库数据源
|
||||
# slave:
|
||||
# lazy: true
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
# username:
|
||||
# password:
|
||||
# oracle:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: oracle.jdbc.OracleDriver
|
||||
# url: jdbc:oracle:thin:@//localhost:1521/XE
|
||||
# username: ROOT
|
||||
# password: root
|
||||
# postgres:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: org.postgresql.Driver
|
||||
# url: jdbc:postgresql://localhost:5432/postgres?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
|
||||
# username: root
|
||||
# password: root
|
||||
# sqlserver:
|
||||
# type: ${spring.datasource.type}
|
||||
# driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
# url: jdbc:sqlserver://localhost:1433;DatabaseName=tempdb;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true
|
||||
# username: SA
|
||||
# password: root
|
||||
hikari:
|
||||
# 最大连接池数量
|
||||
maxPoolSize: 20
|
||||
@ -281,31 +281,16 @@ justauth:
|
||||
mqtt:
|
||||
username: admin
|
||||
password: #YtvpSfCNG
|
||||
url: tcp://47.120.79.150:2883
|
||||
url: tcp://47.120.79.150:3883
|
||||
subClientId: fys_subClient
|
||||
subTopic: A/#,B/#,worker/location/#
|
||||
pubTopic: B/#
|
||||
subTopic: A/#,status/tenantCode/#,report/tenantCode/#
|
||||
pubTopic: B/#,command/tenantCode/#
|
||||
pubClientId: fys_pubClient
|
||||
|
||||
# TTS语音交互配置
|
||||
alibaba:
|
||||
tts:
|
||||
appKey: KTwSUKMrf2olFfjC
|
||||
akId: LTAI5t6RsfCvQh57qojzbEoe
|
||||
akSecret: MTqvK2mXYeCRkl1jVPndiNumyaad0R
|
||||
|
||||
# 文件存储路径
|
||||
file:
|
||||
mac:
|
||||
path: ~/file/
|
||||
avatar: ~/avatar/
|
||||
linux:
|
||||
path: /home/eladmin/file/
|
||||
avatar: /home/eladmin/avatar/
|
||||
windows:
|
||||
path: C:\eladmin\file\
|
||||
avatar: C:\eladmin\avatar\
|
||||
# 文件大小 /M
|
||||
maxSize: 100
|
||||
avatarMaxSize: 5
|
||||
device:
|
||||
pic: C:\eladmin\file\ #设备图片存储路径
|
||||
ip: http://fuyuanshen.com:81/ #服务器地址
|
||||
app_avatar:
|
||||
pic: C:\eladmin\file\ #设备图片存储路径
|
||||
#ip: http://fuyuanshen.com:81/ #服务器地址
|
||||
ip: https://fuyuanshen.com/ #服务器地址
|
||||
10
fys-admin/src/main/resources/josn
Normal file
10
fys-admin/src/main/resources/josn
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"requestId": "123456789",
|
||||
"imei": "864865082081523",
|
||||
"timestamp": 1761025080000,
|
||||
"funcType": "1",
|
||||
"data": {
|
||||
"mainLightMode": 1,
|
||||
"mainLightBrightness": 100
|
||||
}
|
||||
}
|
||||
@ -394,6 +394,26 @@ public class RedisUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 根据时间范围查询Sorted Set中的元素并降序排列
|
||||
*
|
||||
* @param key 键
|
||||
* @param startTime 开始时间戳
|
||||
* @param endTime 结束时间戳
|
||||
* @return 指定时间范围内的元素集合(降序)
|
||||
*/
|
||||
public static Collection<String> zRangeByScoreDesc(String key, Long startTime, Long endTime) {
|
||||
try {
|
||||
RScoredSortedSet<String> sortedSet = CLIENT.getScoredSortedSet(key);
|
||||
// 使用 valueRangeReversed 方法获取降序排列的结果
|
||||
return sortedSet.valueRangeReversed(startTime, true, endTime, true);
|
||||
} catch (Exception e) {
|
||||
// 记录错误日志(如果项目中有日志工具的话)
|
||||
// log.error("根据时间范围查询Sorted Set中的元素失败: key={}, startTime={}, endTime={}, error={}",
|
||||
// key, startTime, endTime, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,79 @@
|
||||
package com.fuyuanshen.app.controller;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppDeviceVoice;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo;
|
||||
import com.fuyuanshen.app.service.IAppDeviceVoiceService;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.core.validate.QueryGroup;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 设备语音Controller
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-07-02
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/app/device/voice")
|
||||
public class AppDeviceVoiceController extends BaseController {
|
||||
|
||||
private final IAppDeviceVoiceService appDeviceVoiceService;
|
||||
|
||||
/**
|
||||
* 查询设备语音列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<AppDeviceVoice> list(AppDeviceVoiceBo bo, PageQuery pageQuery) {
|
||||
return appDeviceVoiceService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备语音详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDeviceVoice> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
return R.ok(appDeviceVoiceService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备语音
|
||||
*/
|
||||
@PostMapping()
|
||||
public R<Void> add(@RequestPart("bo") @Validated(AddGroup.class) AppDeviceVoiceBo bo,
|
||||
@RequestPart(value = "file", required = false) MultipartFile file) {
|
||||
return toAjax(appDeviceVoiceService.insertByBo(bo, file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备语音
|
||||
*/
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppDeviceVoiceBo bo) {
|
||||
return toAjax(appDeviceVoiceService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备语音
|
||||
*
|
||||
* @param ids 主键串
|
||||
*/
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Void> remove(@NotNull(message = "主键不能为空") @PathVariable Long[] ids) {
|
||||
return toAjax(appDeviceVoiceService.deleteWithValidByIds(Arrays.asList(ids), true));
|
||||
}
|
||||
}
|
||||
@ -49,7 +49,7 @@ public class APPDeviceType extends TenantEntity {
|
||||
@Schema(name = "联网方式", example = "0:无;1:4G;2:WIFI")
|
||||
private String networkWay;
|
||||
|
||||
@Schema(name = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
@Schema(name = "通讯方式", example = "通讯方式 0:4G;1:蓝牙,2 4G&蓝牙")
|
||||
private String communicationMode;
|
||||
|
||||
|
||||
|
||||
@ -50,6 +50,9 @@ public class AppDeviceBindRecord extends TenantEntity {
|
||||
*/
|
||||
private Date bindingTime;
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G;1:蓝牙,2 4G&蓝牙
|
||||
*/
|
||||
private Integer communicationMode;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
package com.fuyuanshen.app.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 设备语音
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-07-02
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("app_device_voice")
|
||||
public class AppDeviceVoice extends TenantEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 视频名称
|
||||
*/
|
||||
private String videoName;
|
||||
|
||||
/**
|
||||
* 视频链接
|
||||
*/
|
||||
private String videoUrl;
|
||||
|
||||
/**
|
||||
* 设备di
|
||||
*/
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 文件类型
|
||||
* audio/mp3, audio/wav 等
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 时长(秒)
|
||||
*/
|
||||
private Integer duration;
|
||||
|
||||
/**
|
||||
* 文件大小(字节)
|
||||
*/
|
||||
private Long size;
|
||||
|
||||
/**
|
||||
* 封面图URL
|
||||
*/
|
||||
private String cover;
|
||||
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package com.fuyuanshen.app.domain.bo;
|
||||
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* 设备语音业务对象 app_device_voice
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-07-02
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AppDeviceVoiceBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@NotNull(message = "主键id不能为空", groups = { EditGroup.class })
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 视频名称
|
||||
*/
|
||||
@NotBlank(message = "视频名称不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private String videoName;
|
||||
|
||||
/**
|
||||
* 视频链接
|
||||
*/
|
||||
@NotBlank(message = "视频链接不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private String videoUrl;
|
||||
|
||||
/**
|
||||
* 设备di
|
||||
*/
|
||||
@NotNull(message = "设备di不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 文件类型
|
||||
* audio/mp3, audio/wav 等
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 时长(秒)
|
||||
*/
|
||||
private Integer duration;
|
||||
|
||||
/**
|
||||
* 文件大小(字节)
|
||||
*/
|
||||
private Long size;
|
||||
|
||||
/**
|
||||
* 封面图URL
|
||||
*/
|
||||
private String cover;
|
||||
|
||||
}
|
||||
@ -59,7 +59,7 @@ public class APPDeviceQueryCriteria {
|
||||
@Schema(name = "租户ID")
|
||||
private Long tenantId;
|
||||
|
||||
@Schema(name = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
@Schema(name = "通讯方式", example = "通讯方式 0:4G;1:蓝牙,2 4G&蓝牙")
|
||||
private Integer communicationMode;
|
||||
|
||||
}
|
||||
|
||||
@ -10,6 +10,9 @@ public class APPDeviceTypeVo {
|
||||
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G;1:蓝牙,2 4G&蓝牙
|
||||
*/
|
||||
private String communicationMode;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,120 @@
|
||||
package com.fuyuanshen.app.domain.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@Data
|
||||
public class AppDevice6075DetailVo {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@ExcelProperty(value = "设备ID")
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 设备MAC
|
||||
*/
|
||||
private String deviceMac;
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G;1:蓝牙,2 4G&蓝牙
|
||||
*/
|
||||
private Integer communicationMode;
|
||||
|
||||
/**
|
||||
* 设备图片
|
||||
*/
|
||||
private String devicePic;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 蓝牙名称
|
||||
*/
|
||||
private String bluetoothName;
|
||||
|
||||
/**
|
||||
* 设备状态
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
private Integer deviceStatus;
|
||||
|
||||
/**
|
||||
* 人员信息
|
||||
*/
|
||||
private AppPersonnelInfoVo personnelInfo;
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
*/
|
||||
private String sendMsg;
|
||||
|
||||
//"{\"deviceImei\":\"AA\",\"mainLightMode\":\"1\",\"laserLightMode\":\"0\",\"batteryPercentage\":\"60\",\"chargeState\":\"1\",\"batteryRemainingTime\":\"200\",\"timestamp\":1753871635241}"
|
||||
// 设备主灯档位
|
||||
private String mainLightMode;
|
||||
|
||||
// 激光灯档位
|
||||
private String laserLightMode;
|
||||
|
||||
// 电量百分比
|
||||
private String batteryPercentage;
|
||||
|
||||
// 充电状态(0没有充电,1正在充电,2为已充满)
|
||||
private String chargeState;
|
||||
|
||||
// 电池剩余续航时间200分钟
|
||||
private String batteryRemainingTime;
|
||||
|
||||
/**
|
||||
* 在线状态(0离线,1在线)
|
||||
*/
|
||||
private Integer onlineStatus;
|
||||
|
||||
// 经度
|
||||
private String longitude;
|
||||
|
||||
// 纬度
|
||||
private String latitude;
|
||||
|
||||
// 逆解析地址
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 告警状态(0解除告警,1告警)
|
||||
*/
|
||||
private String alarmStatus;
|
||||
|
||||
// 灯光亮度
|
||||
private String lightBrightness;
|
||||
|
||||
/**
|
||||
* 海拔高度
|
||||
*/
|
||||
private Double altitude;
|
||||
|
||||
/**
|
||||
* 相对高度
|
||||
*/
|
||||
private Double relativeAltitude;
|
||||
|
||||
}
|
||||
@ -33,7 +33,7 @@ public class AppDeviceDetailVo {
|
||||
private String deviceMac;
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G;1:蓝牙
|
||||
* 通讯方式 0:4G;1:蓝牙,2 4G&蓝牙
|
||||
*/
|
||||
private Integer communicationMode;
|
||||
|
||||
|
||||
@ -45,8 +45,7 @@ public class AppDeviceShareDetailVo implements Serializable {
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
* 功能权限(1:灯光模式;2:激光模式;3:开机画面;4:人员信息登记;5:发送信息;6:产品信息)
|
||||
以逗号分隔
|
||||
* 功能权限(1:灯光模式;2:激光模式;3:开机画面;4:人员信息登记;5:发送信息;6:产品信息)以逗号分隔
|
||||
*/
|
||||
@ExcelProperty(value = "功能权限", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "1=:灯光模式;2:激光模式;3:开机画面;4:人员信息登记;5:发送信息;6:产品信息")
|
||||
@ -68,7 +67,7 @@ public class AppDeviceShareDetailVo implements Serializable {
|
||||
private String deviceMac;
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G;1:蓝牙
|
||||
* 通讯方式 0:4G;1:蓝牙,2 4G&蓝牙
|
||||
*/
|
||||
private Integer communicationMode;
|
||||
|
||||
@ -83,7 +82,7 @@ public class AppDeviceShareDetailVo implements Serializable {
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 蓝牙名称
|
||||
* 蓝牙名称
|
||||
*/
|
||||
private String bluetoothName;
|
||||
|
||||
@ -105,19 +104,19 @@ public class AppDeviceShareDetailVo implements Serializable {
|
||||
*/
|
||||
private String sendMsg;
|
||||
|
||||
//设备主灯档位
|
||||
// 设备主灯档位
|
||||
private String mainLightMode;
|
||||
|
||||
//激光灯档位
|
||||
// 激光灯档位
|
||||
private String laserLightMode;
|
||||
|
||||
//电量百分比
|
||||
// 电量百分比
|
||||
private String batteryPercentage;
|
||||
|
||||
//充电状态(0没有充电,1正在充电,2为已充满)
|
||||
// 充电状态(0没有充电,1正在充电,2为已充满)
|
||||
private String chargeState;
|
||||
|
||||
//电池剩余续航时间200分钟
|
||||
// 电池剩余续航时间200分钟
|
||||
private String batteryRemainingTime;
|
||||
|
||||
/**
|
||||
|
||||
@ -114,4 +114,9 @@ public class AppDeviceShareVo implements Serializable {
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 设备详情页面
|
||||
*/
|
||||
private String detailPageUrl;
|
||||
}
|
||||
|
||||
@ -64,5 +64,4 @@ public class AppPersonnelInfoVo implements Serializable {
|
||||
@ExcelProperty(value = "ID号")
|
||||
private String code;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
package com.fuyuanshen.app.domain.vo;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
String[] availableIDs = TimeZone.getAvailableIDs();
|
||||
for (String id : availableIDs) {
|
||||
System.out.println(id);
|
||||
}
|
||||
|
||||
byte[] data = "hello, world!".getBytes(StandardCharsets.UTF_8);
|
||||
try (CountInputStream input = new CountInputStream(new ByteArrayInputStream(data))) {
|
||||
int n;
|
||||
while ((n = input.read()) != -1) {
|
||||
System.out.println((char)n);
|
||||
}
|
||||
System.out.println("Total read " + input.getBytesRead() + " bytes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CountInputStream extends FilterInputStream {
|
||||
private int count = 0;
|
||||
|
||||
CountInputStream(InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
public int getBytesRead() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
int n = in.read();
|
||||
if (n != -1) {
|
||||
this.count ++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
int n = in.read(b, off, len);
|
||||
if (n != -1) {
|
||||
this.count += n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package com.fuyuanshen.app.mapper;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppDeviceVoice;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo;
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备语音Mapper接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-07-02
|
||||
*/
|
||||
public interface AppDeviceVoiceMapper extends BaseMapperPlus<AppDeviceVoice, AppDeviceVoice> {
|
||||
|
||||
/**
|
||||
* 分页查询设备语音列表
|
||||
*/
|
||||
Page<AppDeviceVoice> selectPage(AppDeviceVoiceBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询设备语音列表
|
||||
*/
|
||||
List<AppDeviceVoice> selectList(AppDeviceVoiceBo bo);
|
||||
|
||||
}
|
||||
@ -57,7 +57,7 @@ public interface IAppBusinessFileService {
|
||||
* @param bo 批量新增app业务文件
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
Boolean insertBatch(Collection<AppBusinessFile> bo);
|
||||
Boolean insertBatch(Collection<AppBusinessFile> bo,Boolean isBatch);
|
||||
|
||||
/**
|
||||
* 修改app业务文件
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppDeviceVoice;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备语音Service接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-07-02
|
||||
*/
|
||||
public interface IAppDeviceVoiceService {
|
||||
|
||||
/**
|
||||
* 查询设备语音
|
||||
*/
|
||||
AppDeviceVoice queryById(Long id);
|
||||
|
||||
/**
|
||||
* 查询设备语音列表
|
||||
*/
|
||||
TableDataInfo<AppDeviceVoice> queryPageList(AppDeviceVoiceBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询设备语音列表
|
||||
*/
|
||||
List<AppDeviceVoice> queryList(AppDeviceVoiceBo bo);
|
||||
|
||||
/**
|
||||
* 根据新增业务对象插入设备语音
|
||||
*/
|
||||
Boolean insertByBo(AppDeviceVoiceBo bo, MultipartFile file);
|
||||
|
||||
/**
|
||||
* 根据编辑业务对象更新设备语音
|
||||
*/
|
||||
Boolean updateByBo(AppDeviceVoiceBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除设备语音信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
}
|
||||
@ -102,16 +102,18 @@ public class AppBusinessFileServiceImpl implements IAppBusinessFileService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean insertBatch(Collection<AppBusinessFile> bo) {
|
||||
public Boolean insertBatch(Collection<AppBusinessFile> bo,Boolean isBatch) {
|
||||
// 1. 去重后的 businessId 集合
|
||||
List<Long> businessIds = bo.stream()
|
||||
.map(AppBusinessFile::getBusinessId)
|
||||
.distinct()
|
||||
.toList();
|
||||
QueryWrapper<AppBusinessFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("business_id", businessIds);
|
||||
queryWrapper.eq("file_type", bo.stream().findFirst().orElseThrow().getFileType());
|
||||
baseMapper.delete(queryWrapper);
|
||||
if(isBatch){
|
||||
List<Long> businessIds = bo.stream()
|
||||
.map(AppBusinessFile::getBusinessId)
|
||||
.distinct()
|
||||
.toList();
|
||||
QueryWrapper<AppBusinessFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("business_id", businessIds);
|
||||
queryWrapper.eq("file_type", bo.stream().findFirst().orElseThrow().getFileType());
|
||||
baseMapper.delete(queryWrapper);
|
||||
}
|
||||
return baseMapper.insertBatch(bo);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,130 @@
|
||||
package com.fuyuanshen.app.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.app.domain.AppDeviceVoice;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceVoiceMapper;
|
||||
import com.fuyuanshen.app.service.IAppDeviceVoiceService;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.oss.core.OssClient;
|
||||
import com.fuyuanshen.common.oss.entity.UploadResult;
|
||||
import com.fuyuanshen.common.oss.factory.OssFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备语音Service业务层处理
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-07-02
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class AppDeviceVoiceServiceImpl implements IAppDeviceVoiceService {
|
||||
|
||||
private final AppDeviceVoiceMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询设备语音
|
||||
*/
|
||||
@Override
|
||||
public AppDeviceVoice queryById(Long id) {
|
||||
return baseMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备语音列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<AppDeviceVoice> queryPageList(AppDeviceVoiceBo bo, PageQuery pageQuery) {
|
||||
Page<AppDeviceVoice> page = baseMapper.selectPage(bo, pageQuery);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备语音列表
|
||||
*/
|
||||
@Override
|
||||
public List<AppDeviceVoice> queryList(AppDeviceVoiceBo bo) {
|
||||
return baseMapper.selectList(bo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据新增业务对象插入设备语音
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(AppDeviceVoiceBo bo, MultipartFile file) {
|
||||
// 上传文件到MinIO
|
||||
String videoUrl = "";
|
||||
String coverUrl = "";
|
||||
Long size = 0L;
|
||||
Integer duration = 0;
|
||||
String type = "";
|
||||
|
||||
if (file != null && !file.isEmpty()) {
|
||||
try {
|
||||
OssClient storage = OssFactory.instance();
|
||||
String suffix = "";
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
if (originalFilename != null && originalFilename.lastIndexOf(".") > 0) {
|
||||
suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
}
|
||||
UploadResult result = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
|
||||
videoUrl = result.getUrl();
|
||||
size = file.getSize();
|
||||
type = file.getContentType();
|
||||
// TODO: 可以通过其他方式获取音频时长,这里暂时设置为默认值
|
||||
duration = 0;
|
||||
// TODO: 可以生成封面图,这里暂时设置为空
|
||||
coverUrl = "";
|
||||
} catch (Exception e) {
|
||||
// 文件上传失败处理
|
||||
throw new RuntimeException("文件上传失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
AppDeviceVoice add = new AppDeviceVoice();
|
||||
add.setVideoName(bo.getVideoName());
|
||||
add.setVideoUrl(videoUrl);
|
||||
add.setDeviceId(bo.getDeviceId());
|
||||
add.setRemark(bo.getRemark());
|
||||
add.setType(type);
|
||||
add.setDuration(duration);
|
||||
add.setSize(size);
|
||||
add.setCover(coverUrl);
|
||||
return baseMapper.insert(add) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编辑业务对象更新设备语音
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(AppDeviceVoiceBo bo) {
|
||||
AppDeviceVoice update = new AppDeviceVoice();
|
||||
update.setId(bo.getId());
|
||||
update.setVideoName(bo.getVideoName());
|
||||
update.setDeviceId(bo.getDeviceId());
|
||||
update.setRemark(bo.getRemark());
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验并批量删除设备语音信息
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
// TODO: 可以在这里添加删除MinIO文件的逻辑
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user