forked from dyf/fys-Multi-tenant
Compare commits
3 Commits
20251013-版
...
fc3626e1a1
| Author | SHA1 | Date | |
|---|---|---|---|
| fc3626e1a1 | |||
| 3450b025b4 | |||
| 5b3ea9faf5 |
119
aa.conf
119
aa.conf
@ -1,119 +0,0 @@
|
||||
|
||||
#user nobody;
|
||||
worker_processes 1;
|
||||
|
||||
#error_log logs/error.log;
|
||||
#error_log logs/error.log notice;
|
||||
#error_log logs/error.log info;
|
||||
|
||||
#pid logs/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
# '$status $body_bytes_sent "$http_referer" '
|
||||
# '"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
#access_log logs/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
#keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name cnxhyc.com;
|
||||
|
||||
#charset koi8-r;
|
||||
|
||||
#access_log logs/host.access.log main;
|
||||
|
||||
location / {
|
||||
root html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
#error_page 404 /404.html;
|
||||
|
||||
# redirect server error pages to the static page /50x.html
|
||||
#
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root html;
|
||||
}
|
||||
|
||||
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# proxy_pass http://127.0.0.1;
|
||||
#}
|
||||
|
||||
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# root html;
|
||||
# fastcgi_pass 127.0.0.1:9000;
|
||||
# fastcgi_index index.php;
|
||||
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
||||
# include fastcgi_params;
|
||||
#}
|
||||
|
||||
# deny access to .htaccess files, if Apache's document root
|
||||
# concurs with nginx's one
|
||||
#
|
||||
#location ~ /\.ht {
|
||||
# deny all;
|
||||
#}
|
||||
}
|
||||
|
||||
|
||||
# another virtual host using mix of IP-, name-, and port-based configuration
|
||||
#
|
||||
#server {
|
||||
# listen 8000;
|
||||
# listen somename:8080;
|
||||
# server_name somename alias another.alias;
|
||||
|
||||
# location / {
|
||||
# root html;
|
||||
# index index.html index.htm;
|
||||
# }
|
||||
#}
|
||||
|
||||
|
||||
# HTTPS server
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name cnxhyc.com;
|
||||
|
||||
ssl_certificate /cert/cnxhyc.com.pem;
|
||||
ssl_certificate_key /cert/cnxhyc.com.key;
|
||||
|
||||
# 使用更现代的 SSL 配置
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers TLS_AES_256_GCM_SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
|
||||
ssl_prefer_server_ciphers off;
|
||||
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
location / {
|
||||
root html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -94,10 +94,10 @@
|
||||
</dependency>
|
||||
|
||||
<!-- demo模块 -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>com.fuyuanshen</groupId> -->
|
||||
<!-- <artifactId>fys-demo</artifactId> -->
|
||||
<!-- </dependency> -->
|
||||
<!--<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-demo</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<!-- 工作流模块 -->
|
||||
<dependency>
|
||||
|
||||
@ -1,96 +0,0 @@
|
||||
package com.fuyuanshen;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class CorrectVCardGenerator {
|
||||
public static void main(String[] args) {
|
||||
// // 定义江西上饶的134号段(共22个)
|
||||
// String[] prefixes = {
|
||||
// "1340703", "1340793", "1342650", "1342651", "1342663",
|
||||
// "1342664", "1342665", "1343703", "1343793", "1347901",
|
||||
// "1347902", "1347903", "1347930", "1347931", "1347932",
|
||||
// "1347933", "1347934", "1347935", "1347936", "1347937",
|
||||
// "1347938", "1347939"
|
||||
// }; 1340700 号段(移动)
|
||||
// 1340708 号段(移动)
|
||||
// 1340709 号段(移动)
|
||||
// 1340791 号段(移动)
|
||||
// 1342668 号段(移动)
|
||||
// 1343700 号段(移动)
|
||||
// 1343708 号段(移动)
|
||||
// 1343709 号段(移动)
|
||||
// 1343790 号段(移动)
|
||||
// 1343791 号段(移动)
|
||||
// 1347910 号段(移动)
|
||||
// 1347911 号段(移动)
|
||||
// 1347912 号段(移动)
|
||||
// 1347913 号段(移动)
|
||||
// 1347914 号段(移动)
|
||||
// 1347915 号段(移动)
|
||||
// 1347916 号段(移动)
|
||||
// 1347917 号段(移动)
|
||||
// 1347918 号段(移动)
|
||||
// 1347919 号段(移动)
|
||||
|
||||
// 定义江西南昌的134号段(共22个)
|
||||
String[] prefixes = {
|
||||
"1340700", "1340708", "1340709", "1340791", "1342668",
|
||||
"1343700", "1343708", "1343709", "1343790", "1343791",
|
||||
"1347910", "1347911", "1347912", "1347913", "1347914",
|
||||
"1347915", "1347916", "1347917", "1347918", "1347919"
|
||||
};
|
||||
|
||||
// 创建.vcf文件
|
||||
String filename = "南昌联系人.vcf";
|
||||
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
|
||||
// 生成所有联系人
|
||||
int count = 0;
|
||||
for (String prefix : prefixes) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String middle = String.format("%02d", i);
|
||||
String phoneNumber = prefix + middle + "51";
|
||||
|
||||
// 每个联系人以BEGIN:VCARD开始
|
||||
writer.write("BEGIN:VCARD");
|
||||
writer.newLine();
|
||||
writer.write("VERSION:3.0");
|
||||
writer.newLine();
|
||||
|
||||
// 中文姓名(用户+序号)
|
||||
writer.write("FN:用户" + (count + 1));
|
||||
writer.newLine();
|
||||
|
||||
// 手机号码
|
||||
writer.write("TEL;TYPE=CELL;TYPE=VOICE:" + phoneNumber);
|
||||
writer.newLine();
|
||||
|
||||
// 添加唯一标识符
|
||||
writer.write("UID:" + phoneNumber + "@shangrao");
|
||||
writer.newLine();
|
||||
|
||||
// 添加备注信息
|
||||
writer.write("NOTE:生成于" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
||||
writer.newLine();
|
||||
|
||||
// 每个联系人以END:VCARD结束
|
||||
writer.write("END:VCARD");
|
||||
writer.newLine();
|
||||
writer.newLine(); // 联系人之间空一行
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("成功生成 " + count + " 个联系人");
|
||||
System.out.println("文件已保存为: " + filename);
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("文件写入错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,14 +92,7 @@ public class AppAuthController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户注销
|
||||
*/
|
||||
@DeleteMapping("/cancelAccount")
|
||||
public R<Void> cancelAccount() {
|
||||
loginService.cancelAccount();
|
||||
return R.ok("用户注销成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
|
||||
@ -1,20 +1,28 @@
|
||||
package com.fuyuanshen.app.controller;
|
||||
|
||||
import cn.hutool.json.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.APPReNameDTO;
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.app.service.AppDeviceBizService;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.web.service.device.DeviceBizService;
|
||||
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.util.List;
|
||||
import java.util.Map;
|
||||
@ -28,7 +36,7 @@ import java.util.Map;
|
||||
@RequestMapping("/app/device")
|
||||
public class AppDeviceController extends BaseController {
|
||||
|
||||
private final DeviceBizService appDeviceService;
|
||||
private final AppDeviceBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
@ -76,18 +84,86 @@ public class AppDeviceController extends BaseController {
|
||||
return R.ok("重命名成功!!!");
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/realTimeStatus")
|
||||
public R<Map<String, Object>> getRealTimeStatus(AppRealTimeStatusDto statusDto) {
|
||||
Map<String, Object> status = appDeviceService.getRealTimeStatus(statusDto);
|
||||
return R.ok(status);
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDeviceDetailVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService.getInfo(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据mac查询设备信息
|
||||
* 人员信息登记
|
||||
*/
|
||||
@GetMapping("/getDeviceInfoByDeviceMac")
|
||||
public R<AppDeviceVo> getDeviceInfo(String deviceMac) {
|
||||
return R.ok(appDeviceService.getDeviceInfo(deviceMac));
|
||||
@PostMapping(value = "/registerPersonInfo")
|
||||
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
|
||||
return toAjax(appDeviceService.registerPersonInfo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
*/
|
||||
@PostMapping(value = "/sendMessage")
|
||||
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService.sendMessage(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传设备logo图片
|
||||
*/
|
||||
@PostMapping("/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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
||||
*/
|
||||
@PostMapping("/lightModeSettings")
|
||||
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.lightModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光亮度设置
|
||||
*
|
||||
*/
|
||||
@PostMapping("/lightBrightnessSettings")
|
||||
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService.lightBrightnessSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 激光模式设置
|
||||
*
|
||||
*/
|
||||
@PostMapping("/laserModeSettings")
|
||||
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService.laserModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 地图逆解析
|
||||
*
|
||||
*/
|
||||
@PostMapping("/mapReverseGeocoding")
|
||||
public R<Void> mapReverseGeocoding(@RequestBody DeviceInstructDto params) {
|
||||
String mapJson = appDeviceService.mapReverseGeocoding(params);
|
||||
return R.ok(mapJson);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceShareBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceShareDetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
|
||||
import com.fuyuanshen.app.service.AppDeviceShareService;
|
||||
import com.fuyuanshen.app.service.IAppDeviceShareService;
|
||||
import com.fuyuanshen.common.core.constant.Constants;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
@ -15,7 +16,6 @@ import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.RateLimiter;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.web.service.DeviceShareService;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@ -45,14 +45,14 @@ public class AppDeviceShareController extends BaseController {
|
||||
|
||||
private final IAppDeviceShareService deviceShareService;
|
||||
|
||||
private final DeviceShareService appDeviceShareService;
|
||||
private final AppDeviceShareService appDeviceShareService;
|
||||
|
||||
/**
|
||||
* 分享管理列表
|
||||
*/
|
||||
@GetMapping("/deviceShareList")
|
||||
public TableDataInfo<AppDeviceShareVo> list(AppDeviceShareBo bo, PageQuery pageQuery) {
|
||||
return appDeviceShareService.queryPageList(bo, pageQuery);
|
||||
return deviceShareService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,7 +60,7 @@ public class AppDeviceShareController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/otherDeviceShareList")
|
||||
public TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery) {
|
||||
return appDeviceShareService.otherDeviceShareList(bo, pageQuery);
|
||||
return deviceShareService.otherDeviceShareList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,119 +0,0 @@
|
||||
package com.fuyuanshen.app.controller.device;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* BJQ6170设备控制类
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/app/bjq/device")
|
||||
public class AppDeviceBJQController 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,96 +0,0 @@
|
||||
package com.fuyuanshen.app.controller.device;
|
||||
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
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.web.core.BaseController;
|
||||
import com.fuyuanshen.web.service.device.DeviceBJQBizService;
|
||||
import com.fuyuanshen.web.service.device.DeviceXinghanBizService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* HBY670设备控制类
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/app/xinghan/device")
|
||||
public class AppDeviceXinghanController extends BaseController {
|
||||
|
||||
private final DeviceXinghanBizService appDeviceService;
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
@PostMapping(value = "/registerPersonInfo")
|
||||
// @FunctionAccessAnnotation("registerPersonInfo")
|
||||
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
|
||||
return toAjax(appDeviceService.registerPersonInfo(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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 静电预警档位
|
||||
* 3,2,1,0,分别表示高档/中档/低挡/关闭
|
||||
*/
|
||||
@PostMapping("/DetectGradeSettings")
|
||||
public R<Void> DetectGradeSettings(@RequestBody DeviceInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.upDetectGradeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 照明档位
|
||||
* 照明档位,2,1,0,分别表示弱光/强光/关闭
|
||||
*/
|
||||
@PostMapping("/LightGradeSettings")
|
||||
public R<Void> LightGradeSettings(@RequestBody DeviceInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.upLightGradeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* SOS档位
|
||||
* SOS档位,2,1,0, 分别表示红蓝模式/爆闪模式/关闭
|
||||
*/
|
||||
@PostMapping("/SOSGradeSettings")
|
||||
public R<Void> SOSGradeSettings(@RequestBody DeviceInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.upSOSGradeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 静止报警状态
|
||||
* 静止报警状态,0-未静止报警,1-正在静止报警。
|
||||
*/
|
||||
@PostMapping("/ShakeBitSettings")
|
||||
public R<Void> ShakeBitSettings(@RequestBody DeviceInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.upShakeBitSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package com.fuyuanshen.app.controller.device;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* BJQ6170设备控制类
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class TestController extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
/**
|
||||
* 上传设备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.uploadDeviceLogo2(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@ -8,11 +8,9 @@ public class AppDeviceLogoUploadDto {
|
||||
|
||||
private Long deviceId;
|
||||
|
||||
private String deviceImei;
|
||||
/**
|
||||
* 文件
|
||||
*/
|
||||
private MultipartFile file;
|
||||
|
||||
private Integer chunkSize;
|
||||
}
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
package com.fuyuanshen.app.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 设备实时状态
|
||||
*/
|
||||
@Data
|
||||
public class AppRealTimeStatusDto {
|
||||
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 功能类型
|
||||
*/
|
||||
private String functionMode;
|
||||
|
||||
/**
|
||||
* 批次号
|
||||
*/
|
||||
private String batchId;
|
||||
}
|
||||
@ -11,6 +11,6 @@ public class DeviceInstructDto {
|
||||
/**
|
||||
* 下发指令
|
||||
*/
|
||||
private String instructValue;
|
||||
private Object instructValue;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,496 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
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.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.app.domain.AppDeviceBindRecord;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.APPReNameDTO;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.fuyuanshen.common.core.utils.ObjectUtils;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
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.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
||||
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.*;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
|
||||
import com.fuyuanshen.equipment.utils.c.ReliableTextToBitmap;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AppDeviceBizService {
|
||||
|
||||
private final APPDeviceMapper appDeviceMapper;
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
private final MqttGateway mqttGateway;
|
||||
private final AppDeviceBindRecordMapper appDeviceBindRecordMapper;
|
||||
|
||||
|
||||
public List<APPDeviceTypeVo> getTypeList() {
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
return appDeviceMapper.getTypeList(userId);
|
||||
}
|
||||
|
||||
public void reName(APPReNameDTO reNameDTO) {
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", reNameDTO.getId())
|
||||
.eq("binding_user_id", AppLoginHelper.getUserId())
|
||||
.set("device_name", reNameDTO.getDeviceName());
|
||||
deviceMapper.update(updateWrapper);
|
||||
}
|
||||
|
||||
|
||||
public int sendMessage(AppDeviceSendMsgBo bo) {
|
||||
List<Long> deviceIds = bo.getDeviceIds();
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
throw new ServiceException("请选择设备");
|
||||
}
|
||||
for (Long deviceId : deviceIds) {
|
||||
Device deviceObj = deviceMapper.selectById(deviceId);
|
||||
if (deviceObj == null) {
|
||||
throw new ServiceException("设备不存在" + deviceId);
|
||||
}
|
||||
|
||||
byte[] msg = ReliableTextToBitmap.textToBitmapBytes(bo.getSendMsg());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(2);
|
||||
buildArr(convertHexToDecimal(msg), intData);
|
||||
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.getSendMsg());
|
||||
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", deviceId)
|
||||
.eq("binding_user_id", AppLoginHelper.getUserId())
|
||||
.set("send_msg", bo.getSendMsg());
|
||||
deviceMapper.update(updateWrapper);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
public TableDataInfo<AppDeviceVo> queryAppDeviceList(DeviceQueryCriteria bo, PageQuery pageQuery) {
|
||||
if (bo.getBindingUserId() == null) {
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
bo.setBindingUserId(userId);
|
||||
}
|
||||
Page<AppDeviceVo> result = deviceMapper.queryAppBindDeviceList(pageQuery.build(), bo);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
public int bindDevice(AppDeviceBo bo) {
|
||||
Integer mode = bo.getCommunicationMode();
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
if (mode == CommunicationModeEnum.FOUR_G.getValue()) {
|
||||
|
||||
String deviceImei = bo.getDeviceImei();
|
||||
QueryWrapper<Device> qw = new QueryWrapper<Device>()
|
||||
.eq("device_imei", deviceImei);
|
||||
List<Device> devices = deviceMapper.selectList(qw);
|
||||
if (devices.isEmpty()) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
Device device = devices.get(0);
|
||||
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
|
||||
throw new RuntimeException("设备已绑定");
|
||||
}
|
||||
|
||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||
AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper);
|
||||
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("update_time", new Date())
|
||||
.set("binding_time", new Date());
|
||||
return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper);
|
||||
} else {
|
||||
AppDeviceBindRecord bindRecord = new AppDeviceBindRecord();
|
||||
bindRecord.setDeviceId(device.getId());
|
||||
bindRecord.setBindingUserId(userId);
|
||||
bindRecord.setBindingTime(new Date());
|
||||
bindRecord.setCreateBy(userId);
|
||||
appDeviceBindRecordMapper.insert(bindRecord);
|
||||
}
|
||||
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
||||
.set("binding_user_id", userId)
|
||||
.set("binding_time", new Date());
|
||||
return deviceMapper.update(null, deviceUpdateWrapper);
|
||||
} else if (mode == CommunicationModeEnum.BLUETOOTH.getValue()) {
|
||||
String deviceMac = bo.getDeviceMac();
|
||||
QueryWrapper<Device> qw = new QueryWrapper<Device>()
|
||||
.eq("device_mac", deviceMac);
|
||||
List<Device> devices = deviceMapper.selectList(qw);
|
||||
if (devices.isEmpty()) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
Device device = devices.get(0);
|
||||
|
||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||
bindRecordQueryWrapper.eq("binding_user_id", userId);
|
||||
AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper);
|
||||
if (appDeviceBindRecord != null) {
|
||||
UpdateWrapper<AppDeviceBindRecord> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("device_id", device.getId())
|
||||
.eq("binding_user_id", userId)
|
||||
.set("binding_user_id", userId)
|
||||
.set("binding_time", new Date());
|
||||
return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper);
|
||||
} else {
|
||||
AppDeviceBindRecord bindRecord = new AppDeviceBindRecord();
|
||||
bindRecord.setDeviceId(device.getId());
|
||||
bindRecord.setBindingUserId(userId);
|
||||
bindRecord.setBindingTime(new Date());
|
||||
bindRecord.setCreateBy(userId);
|
||||
appDeviceBindRecordMapper.insert(bindRecord);
|
||||
}
|
||||
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
||||
.set("binding_user_id", userId)
|
||||
.set("binding_time", new Date());
|
||||
return deviceMapper.update(null, deviceUpdateWrapper);
|
||||
} else {
|
||||
throw new RuntimeException("通讯方式错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int unBindDevice(Long id) {
|
||||
return unBindDevice(id, null, 1);
|
||||
}
|
||||
|
||||
public int unBindDevice(Long id, Long userId, int type) {
|
||||
Device device = deviceMapper.selectById(id);
|
||||
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) {
|
||||
bindRecordQueryWrapper.eq("binding_user_id", userId);
|
||||
}
|
||||
|
||||
// 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()));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
public AppDeviceDetailVo getInfo(Long id) {
|
||||
Device device = deviceMapper.selectById(id);
|
||||
if (device == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
AppDeviceDetailVo vo = new AppDeviceDetailVo();
|
||||
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);
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
byte[] unitName = generateFixedBitmapData("富源晟科技", 120);
|
||||
byte[] position = generateFixedBitmapData("研发", 120);
|
||||
byte[] name = generateFixedBitmapData("张三", 120);
|
||||
byte[] id = generateFixedBitmapData("123456", 120);
|
||||
// int[] intUnitNames = Bitmap80x12Generator.convertHexToDecimal(unitName);
|
||||
// int[] intPosition = Bitmap80x12Generator.convertHexToDecimal(position);
|
||||
// int[] intNames = Bitmap80x12Generator.convertHexToDecimal(position);
|
||||
// int[] intIds = Bitmap80x12Generator.convertHexToDecimal(position);
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("instruct", 2);
|
||||
// System.out.println(JSON.toJSONString( map));
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.append("[")
|
||||
// buildStr(unitName, sb);
|
||||
// System.out.println(sb.toString());
|
||||
// Object[] arr = new Object[]{2, Bitmap80x12Generator , Arrays.toString(name), Arrays.toString(id)};
|
||||
|
||||
// System.out.println(Arrays.deepToString(arr));
|
||||
// int[] a = new int[]{6,6,6,6,6,6};
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(2);
|
||||
buildArr(convertHexToDecimal(unitName), intData);
|
||||
buildArr(convertHexToDecimal(position), intData);
|
||||
buildArr(convertHexToDecimal(name), 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);
|
||||
System.out.println(JSON.toJSONString(map));
|
||||
}
|
||||
|
||||
|
||||
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
||||
Long deviceId = bo.getDeviceId();
|
||||
Device deviceObj = deviceMapper.selectById(deviceId);
|
||||
if (deviceObj == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
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(position), intData);
|
||||
buildArr(convertHexToDecimal(name), 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);
|
||||
|
||||
if (ObjectUtils.length(appPersonnelInfoVos) == 0) {
|
||||
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
return appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo);
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void uploadDeviceLogo(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);
|
||||
System.out.println("长度:" + largeData.length);
|
||||
|
||||
System.out.println("原始数据大小: " + largeData.length + " 字节");
|
||||
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject("app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject("app_logo_data:" + device.getDeviceImei());
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
System.out.println("第0块数据大小: " + specificChunk.length + " 字节");
|
||||
System.out.println("第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));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
||||
*/
|
||||
public void lightModeSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
Integer instructValue = (Integer) 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));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//灯光亮度设置
|
||||
public void lightBrightnessSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
String instructValue = (String)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();
|
||||
}
|
||||
}
|
||||
|
||||
//激光模式设置
|
||||
public void laserModeSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
Integer instructValue = (Integer) 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));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String mapReverseGeocoding(DeviceInstructDto params) {
|
||||
// Long deviceId = params.getDeviceId();
|
||||
// Device device = deviceMapper.selectById(deviceId);
|
||||
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());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,135 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.app.domain.AppDeviceShare;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceShareBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceShareDetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceShareMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.common.core.constant.Constants;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.exception.user.CaptchaExpireException;
|
||||
import com.fuyuanshen.common.core.utils.MessageUtils;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
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.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AppDeviceShareService {
|
||||
|
||||
private final AppDeviceShareMapper appDeviceShareMapper;
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
|
||||
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
|
||||
|
||||
public AppDeviceShareDetailVo getInfo(Long id) {
|
||||
|
||||
LambdaQueryWrapper<AppDeviceShare> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AppDeviceShare::getDeviceId, id);
|
||||
List<AppDeviceShareVo> appDeviceShareVos = appDeviceShareMapper.selectVoList(queryWrapper);
|
||||
if(appDeviceShareVos==null || appDeviceShareVos.isEmpty()){
|
||||
return null;
|
||||
}
|
||||
|
||||
AppDeviceShareVo shareVo = appDeviceShareVos.get(0);
|
||||
AppDeviceShareDetailVo shareDetailVo = new AppDeviceShareDetailVo();
|
||||
shareDetailVo.setId(shareVo.getId());
|
||||
shareDetailVo.setDeviceId(shareVo.getDeviceId());
|
||||
shareDetailVo.setPhonenumber(shareVo.getPhonenumber());
|
||||
shareDetailVo.setPermission(shareVo.getPermission());
|
||||
|
||||
Device device = deviceMapper.selectById(shareVo.getDeviceId());
|
||||
shareDetailVo.setDeviceName(device.getDeviceName());
|
||||
shareDetailVo.setDeviceImei(device.getDeviceImei());
|
||||
shareDetailVo.setDeviceMac(device.getDeviceMac());
|
||||
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
if(deviceType!=null){
|
||||
shareDetailVo.setCommunicationMode(Integer.valueOf(deviceType.getCommunicationMode()));
|
||||
}
|
||||
shareDetailVo.setDevicePic(device.getDevicePic());
|
||||
shareDetailVo.setTypeName(deviceType.getTypeName());
|
||||
shareDetailVo.setBluetoothName(device.getBluetoothName());
|
||||
shareDetailVo.setDeviceStatus(device.getDeviceStatus());
|
||||
shareDetailVo.setSendMsg(device.getSendMsg());
|
||||
|
||||
LambdaQueryWrapper<AppPersonnelInfo> qw = new LambdaQueryWrapper<>();
|
||||
qw.eq(AppPersonnelInfo::getDeviceId, device.getId());
|
||||
List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw);
|
||||
if(appPersonnelInfoVos!=null && !appPersonnelInfoVos.isEmpty()){
|
||||
shareDetailVo.setPersonnelInfo(appPersonnelInfoVos.get(0));
|
||||
}
|
||||
|
||||
return shareDetailVo;
|
||||
}
|
||||
/**
|
||||
* 校验短信验证码
|
||||
*/
|
||||
private boolean validateSmsCode(String tenantId, String phonenumber, String smsCode) {
|
||||
String code = RedisUtils.getCacheObject(GlobalConstants.DEVICE_SHARE_CODES_KEY + phonenumber);
|
||||
if (StringUtils.isBlank(code)) {
|
||||
throw new ServiceException("验证码失效");
|
||||
}
|
||||
return code.equals(smsCode);
|
||||
}
|
||||
public int deviceShare(AppDeviceShareBo bo) {
|
||||
boolean flag = validateSmsCode(AppLoginHelper.getTenantId(), bo.getPhonenumber(), bo.getSmsCode());
|
||||
if(!flag){
|
||||
throw new ServiceException("验证码错误");
|
||||
}
|
||||
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
if(device==null){
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
LambdaQueryWrapper<AppDeviceShare> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(AppDeviceShare::getDeviceId, bo.getDeviceId());
|
||||
lqw.eq(AppDeviceShare::getPhonenumber, bo.getPhonenumber());
|
||||
Long count = appDeviceShareMapper.selectCount(lqw);
|
||||
if(count>0){
|
||||
|
||||
UpdateWrapper<AppDeviceShare> uw = new UpdateWrapper<>();
|
||||
uw.eq("device_id", bo.getDeviceId());
|
||||
uw.eq("phonenumber", bo.getPhonenumber());
|
||||
uw.set("permission", bo.getPermission());
|
||||
uw.set("update_by", userId);
|
||||
uw.set("update_time", new Date());
|
||||
|
||||
return appDeviceShareMapper.update(uw);
|
||||
}else {
|
||||
AppDeviceShare appDeviceShare = new AppDeviceShare();
|
||||
appDeviceShare.setDeviceId(bo.getDeviceId());
|
||||
appDeviceShare.setPhonenumber(bo.getPhonenumber());
|
||||
appDeviceShare.setPermission(bo.getPermission());
|
||||
appDeviceShare.setCreateBy(userId);
|
||||
return appDeviceShareMapper.insert(appDeviceShare);
|
||||
}
|
||||
}
|
||||
|
||||
public int remove(Long[] ids) {
|
||||
return appDeviceShareMapper.deleteByIds(Arrays.asList(ids));
|
||||
}
|
||||
}
|
||||
@ -2,14 +2,11 @@ package com.fuyuanshen.app.service;
|
||||
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.fuyuanshen.app.domain.vo.AppRoleVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppUserVo;
|
||||
import com.fuyuanshen.common.core.constant.Constants;
|
||||
import com.fuyuanshen.common.core.constant.SystemConstants;
|
||||
import com.fuyuanshen.common.core.constant.TenantConstants;
|
||||
import com.fuyuanshen.common.core.domain.dto.RoleDTO;
|
||||
import com.fuyuanshen.common.core.domain.model.AppLoginUser;
|
||||
import com.fuyuanshen.common.core.enums.LoginType;
|
||||
import com.fuyuanshen.common.core.exception.user.UserException;
|
||||
@ -31,7 +28,10 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@ -51,7 +51,7 @@ public class AppLoginService {
|
||||
private Integer lockTime;
|
||||
|
||||
private final ISysTenantService tenantService;
|
||||
private final IAppUserService appUserService;
|
||||
private final IAppRoleService roleService;
|
||||
|
||||
|
||||
/**
|
||||
@ -185,24 +185,4 @@ public class AppLoginService {
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelAccount() {
|
||||
try {
|
||||
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
|
||||
if (ObjectUtil.isNull(loginUser)) {
|
||||
return;
|
||||
}
|
||||
appUserService.deleteWithValidByIds(Collections.singletonList(loginUser.getUserId()),true);
|
||||
if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) {
|
||||
// 超级管理员 登出清除动态租户
|
||||
TenantHelper.clearDynamic();
|
||||
}
|
||||
recordLogininfor(loginUser.getTenantId(), loginUser.getUsername(), Constants.LOGOUT, "用户注销成功");
|
||||
} catch (NotLoginException ignored) {
|
||||
} finally {
|
||||
try {
|
||||
StpUtil.logout();
|
||||
} catch (NotLoginException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
package com.fuyuanshen.global.mqtt.base;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Comparator;
|
||||
@ -15,10 +11,7 @@ import java.util.List;
|
||||
*/
|
||||
@Component
|
||||
public class MqttRuleEngine {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("threadPoolTaskExecutor")
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
|
||||
private final LinkedHashMap<String, MqttMessageRule> rulesMap = new LinkedHashMap<>();
|
||||
public MqttRuleEngine(List<MqttMessageRule> rules) {
|
||||
@ -37,7 +30,7 @@ public class MqttRuleEngine {
|
||||
int commandType = context.getCommandType();
|
||||
MqttMessageRule mqttMessageRule = rulesMap.get("Light_"+commandType);
|
||||
if (mqttMessageRule != null) {
|
||||
threadPoolTaskExecutor.execute(() -> mqttMessageRule.execute(context));
|
||||
mqttMessageRule.execute(context);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -1,65 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.base;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Collections;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component
|
||||
public final class MqttXinghanCommandType {
|
||||
private MqttXinghanCommandType() {}
|
||||
|
||||
public enum XinghanCommandTypeEnum {
|
||||
/**
|
||||
* 星汉设备主动上报数据
|
||||
*/
|
||||
GRADE_INFO(101),
|
||||
/**
|
||||
* 星汉开机LOGO
|
||||
*/
|
||||
PIC_TRANS(102),
|
||||
/**
|
||||
* 星汉设备发送消息 (XingHan send msg)
|
||||
*/
|
||||
TEX_TRANS(103),
|
||||
BREAK_NEWS(104),
|
||||
UNKNOWN(0);
|
||||
|
||||
private final int value;
|
||||
XinghanCommandTypeEnum(int value) { this.value = value; }
|
||||
public int getValue() { return value; }
|
||||
}
|
||||
|
||||
private static final Map<String, XinghanCommandTypeEnum> KEY_TO_TYPE;
|
||||
static {
|
||||
LinkedHashMap<String, XinghanCommandTypeEnum> map = new LinkedHashMap<>();
|
||||
map.put("sta_DetectGrade", XinghanCommandTypeEnum.GRADE_INFO);
|
||||
map.put("sta_PowerTime", XinghanCommandTypeEnum.GRADE_INFO);
|
||||
map.put("sta_longitude", XinghanCommandTypeEnum.GRADE_INFO);
|
||||
map.put("sta_latitude", XinghanCommandTypeEnum.GRADE_INFO);
|
||||
map.put("sta_PicTrans", XinghanCommandTypeEnum.PIC_TRANS);
|
||||
map.put("sta_TexTrans", XinghanCommandTypeEnum.TEX_TRANS);
|
||||
map.put("sta_BreakNews", XinghanCommandTypeEnum.BREAK_NEWS);
|
||||
KEY_TO_TYPE = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
public static int computeVirtualCommandType(Dict payloadDict) {
|
||||
if (payloadDict == null) {
|
||||
return XinghanCommandTypeEnum.UNKNOWN.getValue();
|
||||
}
|
||||
try {
|
||||
for (String key : KEY_TO_TYPE.keySet()) {
|
||||
if (payloadDict.containsKey(key)) {
|
||||
return KEY_TO_TYPE.get(key).getValue();
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
return XinghanCommandTypeEnum.UNKNOWN.getValue();
|
||||
}
|
||||
|
||||
return XinghanCommandTypeEnum.UNKNOWN.getValue();
|
||||
}
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.base;
|
||||
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@Data
|
||||
public class MqttXinghanJson {
|
||||
|
||||
/**
|
||||
* 第一键值对,静电预警档位:3,2,1,0,分别表示高档/中档/低挡/关闭.
|
||||
*/
|
||||
@JsonProperty("sta_DetectGrade")
|
||||
private Integer staDetectGrade;
|
||||
/**
|
||||
* 第二键值对,照明档位,2,1,0,分别表示弱光/强光/关闭
|
||||
*/
|
||||
@JsonProperty("sta_LightGrade")
|
||||
private Integer staLightGrade;
|
||||
/**
|
||||
* 第三键值对,SOS档位,2,1,0, 分别表示红蓝模式/爆闪模式/关闭
|
||||
*/
|
||||
@JsonProperty("sta_SOSGrade")
|
||||
public Integer staSOSGrade;
|
||||
/**
|
||||
* 第四键值对,剩余照明时间,0-5999,单位分钟。
|
||||
*/
|
||||
@JsonProperty("sta_PowerTime")
|
||||
public Integer staPowerTime;
|
||||
/**
|
||||
* 第五键值对,剩余电量百分比,0-100
|
||||
*/
|
||||
@JsonProperty("sta_PowerPercent")
|
||||
public Integer staPowerPercent;
|
||||
/**
|
||||
* 第六键值对, 近电预警级别, 0-无预警,1-弱预警,2-中预警,3-强预警,4-非常强预警。
|
||||
*/
|
||||
@JsonProperty("sta_DetectResult")
|
||||
public Integer staDetectResult;
|
||||
/**
|
||||
* 第七键值对, 静止报警状态,0-未静止报警,1-正在静止报警。
|
||||
*/
|
||||
@JsonProperty("staShakeBit")
|
||||
public Integer sta_ShakeBit;
|
||||
/**
|
||||
* 第八键值对, 4G信号强度,0-32,数值越大,信号越强。
|
||||
*/
|
||||
@JsonProperty("sta_4gSinal")
|
||||
public Integer sta4gSinal;
|
||||
/**
|
||||
* 第九键值对,IMIE卡号
|
||||
*/
|
||||
@JsonProperty("sta_imei")
|
||||
public String staimei;
|
||||
/**
|
||||
* 第十键值对,经度
|
||||
*/
|
||||
@JsonProperty("sta_longitude")
|
||||
public String stalongitude;
|
||||
/**
|
||||
* 第十一键值对,纬度
|
||||
*/
|
||||
@JsonProperty("sta_latitude")
|
||||
public String stalatitude;
|
||||
|
||||
}
|
||||
@ -4,6 +4,12 @@ import org.springframework.integration.annotation.MessagingGateway;
|
||||
import org.springframework.integration.mqtt.support.MqttHeaders;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
|
||||
/**
|
||||
* @Author: HarryLin
|
||||
* @Date: 2025/3/20 17:06
|
||||
* @Company: 北京红山信息科技研究院有限公司
|
||||
* @Email: linyun@***.com.cn
|
||||
**/
|
||||
@MessagingGateway(defaultRequestChannel = "mqttOutboundChannel")
|
||||
public interface MqttGateway {
|
||||
public abstract void sendMsgToMqtt(@Header(value = MqttHeaders.TOPIC) String topic, String payload);
|
||||
|
||||
@ -16,5 +16,4 @@ public class MqttPropertiesConfig {
|
||||
private String subTopic;
|
||||
private String pubClientId;
|
||||
private String pubTopic;
|
||||
private String enabled;
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.constants;
|
||||
|
||||
public class DeviceRedisKeyConstants {
|
||||
public static final String DEVICE_KEY_PREFIX = "device:";
|
||||
// 设备上报状态
|
||||
public static final String DEVICE_STATUS_KEY_PREFIX = ":status";
|
||||
// 在线状态
|
||||
public static final String DEVICE_ONLINE_STATUS_KEY_PREFIX = ":onlineStatus";
|
||||
// 设备状态信息存储到Redis中
|
||||
public static final String DEVICE_LOCATION_KEY_PREFIX = ":location";
|
||||
// 存储到一个列表中,保留历史位置信息
|
||||
public static final String DEVICE_LOCATION_HISTORY_KEY_PREFIX = ":location:history";
|
||||
|
||||
// 存储设备活跃上报信息
|
||||
public static final String DEVICE_ACTIVE_REPORTING_KEY_PREFIX = ":activeReporting";
|
||||
|
||||
// 存储设备人员信息
|
||||
public static final String DEVICE_PERSONNEL_INFO_KEY_PREFIX = ":personnelInfo";
|
||||
|
||||
// 存储设备发送消息
|
||||
public static final String DEVICE_SEND_MESSAGE_KEY_PREFIX = ":sendMessage";
|
||||
|
||||
// 存储设备启动logo
|
||||
public static final String DEVICE_BOOT_LOGO_KEY_PREFIX = ":bootLogo";
|
||||
|
||||
/**
|
||||
* 灯模式
|
||||
*/
|
||||
public static final String DEVICE_LIGHT_MODE_KEY_PREFIX = ":lightMode";
|
||||
|
||||
/**
|
||||
* 亮度模式
|
||||
*/
|
||||
public static final String DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX = ":lightBrightness";
|
||||
|
||||
/**
|
||||
* 激光模式
|
||||
*/
|
||||
public static final String DEVICE_LASER_MODE_KEY_PREFIX = ":laserMode";
|
||||
|
||||
/**
|
||||
* 地图逆地理编码
|
||||
*/
|
||||
public static final String DEVICE_MAP_REVERSE_GEOCODING_KEY_PREFIX = ":mapReverseGeocoding";
|
||||
|
||||
/**
|
||||
* 告警
|
||||
*/
|
||||
public static final String DEVICE_ALARM_KEY_PREFIX = ":alarm";
|
||||
}
|
||||
@ -30,17 +30,6 @@ public class LightingCommandTypeConstants {
|
||||
* 主灯亮度 (Main Light Brightness)
|
||||
*/
|
||||
public static final String MAIN_LIGHT_BRIGHTNESS = "Light_5";
|
||||
|
||||
/**
|
||||
* 设备发送消息
|
||||
*/
|
||||
public static final String SEND_MESSAGE = "Light_6";
|
||||
|
||||
|
||||
/**
|
||||
* 报警模式
|
||||
*/
|
||||
public static final String ALARM_MESSAGE = "Light_7";
|
||||
|
||||
/**
|
||||
* 定位数据 (Location Data)
|
||||
@ -51,5 +40,37 @@ public class LightingCommandTypeConstants {
|
||||
* 主动上报设备数据 (Active Reporting Device Data)
|
||||
*/
|
||||
public static final String ACTIVE_REPORTING_DEVICE_DATA = "Light_12";
|
||||
|
||||
|
||||
/**
|
||||
* 获取命令类型描述
|
||||
*
|
||||
* @param commandType 命令类型
|
||||
* @return 命令类型描述
|
||||
*/
|
||||
public static String getCommandTypeDescription(String commandType) {
|
||||
return switch (commandType) {
|
||||
case LIGHT_MODE -> "灯光模式 (Light Mode)";
|
||||
case PERSONNEL_INFO -> "人员信息 (Personnel Information)";
|
||||
case BOOT_LOGO -> "开机LOGO (Boot Logo)";
|
||||
case LASER_LIGHT -> "激光灯 (Laser Light)";
|
||||
case MAIN_LIGHT_BRIGHTNESS -> "主灯亮度 (Main Light Brightness)";
|
||||
case LOCATION_DATA -> "定位数据 (Location Data)";
|
||||
default -> "未知命令类型 (Unknown Command Type)";
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否为有效命令类型
|
||||
*
|
||||
* @param commandType 命令类型
|
||||
* @return 是否有效
|
||||
*/
|
||||
public static boolean isValidCommandType(String commandType) {
|
||||
return commandType.equals(LIGHT_MODE) ||
|
||||
commandType.equals(PERSONNEL_INFO) ||
|
||||
commandType.equals(BOOT_LOGO) ||
|
||||
commandType.equals(LASER_LIGHT) ||
|
||||
commandType.equals(MAIN_LIGHT_BRIGHTNESS) ||
|
||||
commandType.equals(LOCATION_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.constants;
|
||||
|
||||
/**
|
||||
* 租户常量定义类
|
||||
* 包含系统中使用的各种租户标识
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-08-05 10:46
|
||||
*/
|
||||
public class TenantsConstant {
|
||||
|
||||
/**
|
||||
* 晶全租户
|
||||
*/
|
||||
public static final String JING_QUAN = "014443";
|
||||
|
||||
/**
|
||||
* 富源晟租户
|
||||
*/
|
||||
public static final String FU_YUAN_SHENG = "894078";
|
||||
|
||||
/**
|
||||
* 管理员租户
|
||||
*/
|
||||
public static final String ADMIN = "000000";
|
||||
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.constants;
|
||||
|
||||
public class XingHanCommandTypeConstants {
|
||||
/**
|
||||
* 星汉设备主动上报数据 (XingHan Device Data)
|
||||
*/
|
||||
public static final String XingHan_DEVICE_DATA = "Light_101";
|
||||
/**
|
||||
* 星汉开机LOGO (XingHan Boot Logo)
|
||||
*/
|
||||
public static final String XingHan_BOOT_LOGO = "Light_102";
|
||||
/**
|
||||
* 星汉设备发送消息 (XingHan send msg)
|
||||
*/
|
||||
public static final String XingHan_ESEND_MSG = "Light_103";
|
||||
/**
|
||||
* 星汉设备发送紧急通知 (XingHan break news)
|
||||
*/
|
||||
public static final String XingHan_BREAK_NEWS = "Light_104";
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.listener;
|
||||
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_TIMEOUT_KEY;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RedisKeyExpirationListener implements MessageListener {
|
||||
|
||||
@Override
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
String expiredKey = new String(message.getBody());
|
||||
|
||||
if (expiredKey.startsWith(FUNCTION_ACCESS_KEY)) {
|
||||
String element = expiredKey.substring(FUNCTION_ACCESS_KEY.length());
|
||||
handleFunctionAccessExpired(element);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问key过期事件
|
||||
* @param element 批次ID
|
||||
*/
|
||||
private void handleFunctionAccessExpired(String element) {
|
||||
RedisUtils.setCacheObject(FUNCTION_ACCESS_TIMEOUT_KEY + element, FunctionAccessStatus.TIMEOUT.getCode(), Duration.ofSeconds(30L));
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.listener.config;
|
||||
|
||||
import com.fuyuanshen.global.mqtt.listener.RedisKeyExpirationListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.listener.PatternTopic;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
|
||||
@Configuration
|
||||
public class RedisListenerConfig {
|
||||
|
||||
@Bean
|
||||
RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory,
|
||||
RedisKeyExpirationListener redisKeyExpirationListener) {
|
||||
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
||||
container.setConnectionFactory(connectionFactory);
|
||||
|
||||
// 监听过期事件
|
||||
container.addMessageListener(redisKeyExpirationListener, new PatternTopic("__keyevent@*__:expired"));
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@ -1,96 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.listener.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 功能访问状态对象
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FunctionAccessResult {
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 消息描述
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private Long timestamp;
|
||||
|
||||
/**
|
||||
* 设备IMEI(可选)
|
||||
*/
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 批次ID(可选)
|
||||
*/
|
||||
private String batchId;
|
||||
|
||||
public FunctionAccessResult(String status, String message) {
|
||||
this.status = status;
|
||||
this.message = message;
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建失败状态对象
|
||||
* @param message 消息
|
||||
* @return FunctionAccessResult
|
||||
*/
|
||||
public static FunctionAccessResult failed(String message) {
|
||||
return new FunctionAccessResult("FAILED", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建成功状态对象
|
||||
* @param message 消息
|
||||
* @return FunctionAccessResult
|
||||
*/
|
||||
public static FunctionAccessResult ok(String message) {
|
||||
return new FunctionAccessResult("OK", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建超时状态对象
|
||||
* @param message 消息
|
||||
* @return FunctionAccessResult
|
||||
*/
|
||||
public static FunctionAccessResult timeout(String message) {
|
||||
return new FunctionAccessResult("TIMEOUT", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为失败状态
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isFailed() {
|
||||
return "FAILED".equals(this.status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为成功状态
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isOk() {
|
||||
return "OK".equals(this.status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为超时状态
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isTimeout() {
|
||||
return "TIMEOUT".equals(this.status);
|
||||
}
|
||||
}
|
||||
@ -1,62 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.listener.domain;
|
||||
|
||||
/**
|
||||
* 功能访问状态枚举
|
||||
*/
|
||||
public enum FunctionAccessStatus {
|
||||
|
||||
/**
|
||||
* 失败状态
|
||||
*/
|
||||
FAILED("FAILED", "失败"),
|
||||
|
||||
/**
|
||||
* 成功状态
|
||||
*/
|
||||
OK("OK", "成功"),
|
||||
|
||||
/**
|
||||
* 激活中状态
|
||||
*/
|
||||
ACTIVE("ACTIVE", "处理中"),
|
||||
|
||||
/**
|
||||
* 超时状态
|
||||
*/
|
||||
TIMEOUT("TIMEOUT", "超时");
|
||||
|
||||
private final String code;
|
||||
private final String description;
|
||||
|
||||
FunctionAccessStatus(String code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据代码获取状态枚举
|
||||
* @param code 状态代码
|
||||
* @return 对应的状态枚举
|
||||
*/
|
||||
public static FunctionAccessStatus fromCode(String code) {
|
||||
for (FunctionAccessStatus status : FunctionAccessStatus.values()) {
|
||||
if (status.getCode().equals(code)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("未知的状态代码: " + code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,12 @@ import org.springframework.integration.mqtt.support.MqttHeaders;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* @Author: HarryLin
|
||||
* @Date: 2025/3/20 16:16
|
||||
* @Company: 北京红山信息科技研究院有限公司
|
||||
* @Email: linyun@***.com.cn
|
||||
**/
|
||||
@Service
|
||||
public class MqttMessageSender {
|
||||
@Autowired
|
||||
|
||||
@ -1,15 +1,10 @@
|
||||
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.core.utils.StringUtils;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.Message;
|
||||
@ -18,11 +13,8 @@ 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;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ReceiverMessageHandler implements MessageHandler {
|
||||
@ -45,19 +37,16 @@ public class ReceiverMessageHandler implements MessageHandler {
|
||||
if (receivedTopic == null || payloadDict == null) {
|
||||
return;
|
||||
}
|
||||
String[] subStr = receivedTopic.split("/");
|
||||
String deviceImei = subStr[1];
|
||||
if(StringUtils.isNotBlank(deviceImei)){
|
||||
//在线状态
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1", Duration.ofSeconds(62));
|
||||
}
|
||||
|
||||
|
||||
String state = payloadDict.getStr("state");
|
||||
Object[] convertArr = ImageToCArrayConverter.convertByteStringToMixedObjectArray(state);
|
||||
|
||||
if (convertArr.length > 0) {
|
||||
Byte val1 = (Byte) convertArr[0];
|
||||
String[] subStr = receivedTopic.split("/");
|
||||
System.out.println("收到设备id: " + subStr[1]);
|
||||
String deviceImei = subStr[1];
|
||||
|
||||
MqttRuleContext context = new MqttRuleContext();
|
||||
context.setCommandType(val1);
|
||||
context.setConvertArr(convertArr);
|
||||
@ -70,19 +59,5 @@ public class ReceiverMessageHandler implements MessageHandler {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.bjq;
|
||||
package com.fuyuanshen.global.mqtt.rule;
|
||||
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -17,9 +15,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 主动上报设备数据命令处理
|
||||
* "第1位为12表示设备主动上报设备硬件状态,第2为表示当时设备主灯档位,第3位表示当时激光灯档位,第4位电量百分比,第5位为充电状态(0没有充电,1正在充电,2为已充满)
|
||||
@ -28,7 +23,10 @@ import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVIC
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BjqActiveReportingDeviceDataRule implements MqttMessageRule {
|
||||
public class ActiveReportingDeviceDataRule implements MqttMessageRule {
|
||||
|
||||
private final MqttGateway mqttGateway;
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
@ -47,16 +45,16 @@ public class BjqActiveReportingDeviceDataRule implements MqttMessageRule {
|
||||
String chargeState = convertArr[4].toString();
|
||||
String batteryRemainingTime = convertArr[5].toString();
|
||||
|
||||
// 发送设备状态和位置信息到Redis
|
||||
// 异步发送设备状态和位置信息到Redis
|
||||
asyncSendDeviceDataToRedisWithFuture(context.getDeviceImei(), mainLightMode, laserLightMode,
|
||||
batteryPercentage, chargeState, batteryRemainingTime);
|
||||
} catch (Exception e) {
|
||||
log.error("处理上报数据命令时出错", e);
|
||||
log.error("处理定位数据命令时出错", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送设备状态信息和位置信息到Redis
|
||||
* 异步发送设备状态信息和位置信息到Redis(使用CompletableFuture)
|
||||
*
|
||||
* @param deviceImei 设备IMEI
|
||||
* @param mainLightMode 主灯档位
|
||||
@ -80,11 +78,11 @@ public class BjqActiveReportingDeviceDataRule implements MqttMessageRule {
|
||||
deviceInfo.put("timestamp", System.currentTimeMillis());
|
||||
|
||||
// 将设备状态信息存储到Redis中
|
||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + deviceImei + DEVICE_STATUS_KEY_PREFIX;
|
||||
String deviceRedisKey = "device:status:" + deviceImei;
|
||||
String deviceInfoJson = JsonUtils.toJsonString(deviceInfo);
|
||||
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, deviceInfoJson);
|
||||
// 存储到Redis,设置过期时间(例如24小时)
|
||||
RedisUtils.setCacheObject(deviceRedisKey, deviceInfoJson, Duration.ofSeconds(24 * 60 * 60));
|
||||
|
||||
log.info("设备状态信息已异步发送到Redis: device={}, mainLightMode={}, laserLightMode={}, batteryPercentage={}",
|
||||
deviceImei, mainLightMode, laserLightMode, batteryPercentage);
|
||||
@ -94,6 +92,4 @@ public class BjqActiveReportingDeviceDataRule implements MqttMessageRule {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,7 +1,5 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.bjq;
|
||||
package com.fuyuanshen.global.mqtt.rule;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
@ -10,10 +8,8 @@ import com.fuyuanshen.equipment.utils.map.LngLonUtil;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -25,17 +21,13 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 定位数据命令处理
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BjqLocationDataRule implements MqttMessageRule {
|
||||
public class LocationDataRule implements MqttMessageRule {
|
||||
|
||||
private final MqttGateway mqttGateway;
|
||||
|
||||
@ -47,7 +39,6 @@ public class BjqLocationDataRule implements MqttMessageRule {
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
|
||||
try {
|
||||
Object[] convertArr = context.getConvertArr();
|
||||
// Latitude, longitude
|
||||
@ -62,10 +53,8 @@ public class BjqLocationDataRule implements MqttMessageRule {
|
||||
log.info("发送定位数据到设备=>topic:{},payload:{}",
|
||||
MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(),
|
||||
JsonUtils.toJsonString(map));
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
} catch (Exception e) {
|
||||
log.error("处理定位数据命令时出错", e);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,86 +103,33 @@ 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.isNotBlank(latitude) || StringUtils.isNotBlank(longitude)){
|
||||
return;
|
||||
}
|
||||
String[] latArr = latitude.split("\\.");
|
||||
String[] lonArr = longitude.split("\\.");
|
||||
// 将位置信息存储到Redis中
|
||||
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX;
|
||||
String redisObj = RedisUtils.getCacheObject(redisKey);
|
||||
JSONObject jsonOBj = JSONObject.parseObject(redisObj);
|
||||
if(jsonOBj != null){
|
||||
String str1 = latArr[0] +"."+ latArr[1].substring(0,4);
|
||||
String str2 = lonArr[0] +"."+ lonArr[1].substring(0,4);
|
||||
|
||||
String cacheLatitude = jsonOBj.getString("wgs84_latitude");
|
||||
String cacheLongitude = jsonOBj.getString("wgs84_longitude");
|
||||
String[] latArr1 = cacheLatitude.split("\\.");
|
||||
String[] lonArr1 = cacheLongitude.split("\\.");
|
||||
|
||||
String cacheStr1 = latArr1[0] +"."+ latArr1[1].substring(0,4);
|
||||
String cacheStr2 = lonArr1[0] +"."+ lonArr1[1].substring(0,4);
|
||||
if(str1.equals(cacheStr1) && str2.equals(cacheStr2)){
|
||||
log.info("位置信息未发生变化: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 构造位置信息对象
|
||||
Map<String, Object> locationInfo = new LinkedHashMap<>();
|
||||
double[] doubles = LngLonUtil.gps84_To_Gcj02(Double.parseDouble(latitude), Double.parseDouble(longitude));
|
||||
locationInfo.put("deviceImei", deviceImei);
|
||||
locationInfo.put("latitude", doubles[0]);
|
||||
locationInfo.put("longitude", doubles[1]);
|
||||
locationInfo.put("wgs84_latitude", latitude);
|
||||
locationInfo.put("wgs84_longitude", longitude);
|
||||
String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
|
||||
locationInfo.put("address", address);
|
||||
locationInfo.put("timestamp", System.currentTimeMillis());
|
||||
|
||||
|
||||
|
||||
// 将位置信息存储到Redis中
|
||||
String redisKey = "device:location:" + deviceImei;
|
||||
String locationJson = JsonUtils.toJsonString(locationInfo);
|
||||
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(redisKey, locationJson);
|
||||
RedisUtils.setCacheObject(redisKey, locationJson, Duration.ofSeconds(24 * 60 * 60));
|
||||
|
||||
// 存储到一个列表中,保留历史位置信息
|
||||
// String locationHistoryKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX + deviceImei;
|
||||
// RedisUtils.addCacheList(locationHistoryKey, locationJson);
|
||||
// RedisUtils.expire(locationHistoryKey, Duration.ofDays(90));
|
||||
storeDeviceTrajectoryWithSortedSet(deviceImei, locationJson);
|
||||
log.info("位置信息已异步发送到Redis: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
|
||||
} catch (Exception e) {
|
||||
log.error("异步发送位置信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储设备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 = "device:trajectory:zset:" + deviceImei;
|
||||
// String locationJson = JsonUtils.toJsonString(locationInfo);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
// 添加到Sorted Set,使用时间戳作为score
|
||||
RedisUtils.zAdd(trajectoryKey, locationJson, timestamp);
|
||||
|
||||
// // 设置30天过期时间
|
||||
// RedisUtils.expire(trajectoryKey, Duration.ofDays(30));
|
||||
|
||||
// 清理30天前的数据(冗余保护)
|
||||
long thirtyDaysAgo = System.currentTimeMillis() - (7L * 24 * 60 * 60 * 1000);
|
||||
RedisUtils.zRemoveRangeByScore(trajectoryKey, 0, thirtyDaysAgo);
|
||||
} catch (Exception e) {
|
||||
log.error("存储设备轨迹到Redis(ZSet)失败: device={}, error={}", deviceImei, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> buildLocationDataMap(String latitude, String longitude) {
|
||||
String[] latArr = latitude.split("\\.");
|
||||
@ -202,11 +138,9 @@ public class BjqLocationDataRule implements MqttMessageRule {
|
||||
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)));
|
||||
String str2 = lonArr[1];
|
||||
intData.add(Integer.parseInt(latArr[1]));
|
||||
intData.add(Integer.parseInt(lonArr[0]));
|
||||
intData.add(Integer.parseInt(str2.substring(0,4)));
|
||||
intData.add(Integer.parseInt(lonArr[1]));
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
@ -1,4 +1,4 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.bjq;
|
||||
package com.fuyuanshen.global.mqtt.rule;
|
||||
|
||||
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
@ -9,20 +9,16 @@ import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 人员信息命令处理
|
||||
@ -30,37 +26,35 @@ import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVIC
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BjqSendMessageRule implements MqttMessageRule {
|
||||
public class PersonnelInfoRule implements MqttMessageRule {
|
||||
|
||||
private final MqttGateway mqttGateway;
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return LightingCommandTypeConstants.SEND_MESSAGE;
|
||||
return LightingCommandTypeConstants.PERSONNEL_INFO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
|
||||
try {
|
||||
Byte val2 = (Byte) context.getConvertArr()[1];
|
||||
if (val2 == 100) {
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
return;
|
||||
}
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":app_send_message_data");
|
||||
String data = RedisUtils.getCacheObject("894078:app_logo_data:" + context.getDeviceImei());
|
||||
if (StringUtils.isEmpty(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, (val2 - 1), 512);
|
||||
log.info("第{}块数据大小: {} 字节", val2, specificChunk.length);
|
||||
// System.out.println("第" + val2 + "块数据: " + Arrays.toString(specificChunk));
|
||||
System.out.println("第" + val2 + "块数据大小: " + specificChunk.length + " 字节");
|
||||
System.out.println("第" + val2 + "块数据: " + Arrays.toString(specificChunk));
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(6);
|
||||
intData.add(3);
|
||||
intData.add((int) val2);
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
|
||||
intData.add(0);
|
||||
@ -72,13 +66,11 @@ public class BjqSendMessageRule implements MqttMessageRule {
|
||||
map.put("instruct", intData);
|
||||
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), 1, JsonUtils.toJsonString(map));
|
||||
log.info("发送设备信息数据到设备消息=>topic:{},payload:{}",
|
||||
log.info("发送人员信息点阵数据到设备消息=>topic:{},payload:{}",
|
||||
MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(),
|
||||
JsonUtils.toJsonString(map));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理发送设备信息时出错", e);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
log.error("处理人员信息命令时出错", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.bjq;
|
||||
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
/**
|
||||
* 灯光模式订阅设备回传消息
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BjqAlarmRule implements MqttMessageRule {
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return LightingCommandTypeConstants.ALARM_MESSAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
|
||||
try {
|
||||
Object[] convertArr = context.getConvertArr();
|
||||
|
||||
String convertValue = convertArr[1].toString();
|
||||
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);
|
||||
}
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
} catch (Exception e) {
|
||||
log.error("处理告警命令时出错", e);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,84 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.bjq;
|
||||
|
||||
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_BOOT_LOGO_KEY_PREFIX;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 上传开机图片命令处理
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BjqBootLogoRule implements MqttMessageRule {
|
||||
|
||||
private final MqttGateway mqttGateway;
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return LightingCommandTypeConstants.BOOT_LOGO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
|
||||
try {
|
||||
Byte val2 = (Byte) context.getConvertArr()[1];
|
||||
if (val2 == 100) {
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
return;
|
||||
}
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() +DEVICE_BOOT_LOGO_KEY_PREFIX);
|
||||
if (StringUtils.isEmpty(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, (val2 - 1), 512);
|
||||
log.info("第{}块数据大小: {} 字节", val2, specificChunk.length);
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(3);
|
||||
intData.add((int) val2);
|
||||
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 + context.getDeviceImei(), 1, JsonUtils.toJsonString(map));
|
||||
log.info("发送开机LOGO点阵数据到设备消息=>topic:{},payload:{}",
|
||||
MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(),
|
||||
JsonUtils.toJsonString(map));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理开机LOGO时出错", e);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,75 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.bjq;
|
||||
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
/**
|
||||
* 灯光模式订阅设备回传消息
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BjqLaserModeSettingsRule implements MqttMessageRule {
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return LightingCommandTypeConstants.LASER_LIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
|
||||
try {
|
||||
Object[] convertArr = context.getConvertArr();
|
||||
|
||||
String mode = convertArr[1].toString();
|
||||
if(StringUtils.isNotBlank(mode)){
|
||||
// 发送设备状态和位置信息到Redis
|
||||
syncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),mode);
|
||||
}
|
||||
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(30));
|
||||
} catch (Exception e) {
|
||||
log.error("处理激光模式命令时出错", e);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(30));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送设备状态信息和位置信息到Redis
|
||||
*
|
||||
* @param deviceImei 设备IMEI
|
||||
*/
|
||||
public void syncSendDeviceDataToRedisWithFuture(String deviceImei,Object convertValue) {
|
||||
// CompletableFuture.runAsync(() -> {
|
||||
//
|
||||
// });
|
||||
try {
|
||||
// 将设备状态信息存储到Redis中
|
||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + deviceImei + DEVICE_LASER_MODE_KEY_PREFIX;
|
||||
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, convertValue.toString());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("异步发送设备信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.bjq;
|
||||
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
/**
|
||||
* 灯光模式订阅设备回传消息
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BjqLightBrightnessRule implements MqttMessageRule {
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return LightingCommandTypeConstants.MAIN_LIGHT_BRIGHTNESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
|
||||
try {
|
||||
Object[] convertArr = context.getConvertArr();
|
||||
|
||||
String convertValue = convertArr[1].toString();
|
||||
// 将设备状态信息存储到Redis中
|
||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX;
|
||||
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, convertValue);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
} catch (Exception e) {
|
||||
log.error("处理灯光亮度命令时出错", e);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,84 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.bjq;
|
||||
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
/**
|
||||
* 灯光模式订阅设备回传消息
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BjqModeRule implements MqttMessageRule {
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return LightingCommandTypeConstants.LIGHT_MODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
|
||||
try {
|
||||
Object[] convertArr = context.getConvertArr();
|
||||
|
||||
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));
|
||||
}
|
||||
// 发送设备状态和位置信息到Redis
|
||||
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);
|
||||
}
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
} catch (Exception e) {
|
||||
log.error("处理灯光模式命令时出错", e);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送设备状态信息和位置信息到Redis
|
||||
*
|
||||
* @param deviceImei 设备IMEI
|
||||
*/
|
||||
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;
|
||||
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, convertValue.toString());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("异步发送设备信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.bjq;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
|
||||
import com.fuyuanshen.equipment.utils.map.LngLonUtil;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
/**
|
||||
* 定位数据命令处理
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BjqPersonnelInfoDataRule implements MqttMessageRule {
|
||||
|
||||
private final MqttGateway mqttGateway;
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return LightingCommandTypeConstants.PERSONNEL_INFO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
|
||||
try {
|
||||
Object[] convertArr = context.getConvertArr();
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(30));
|
||||
} catch (Exception e) {
|
||||
log.error("处理定位数据命令时出错", e);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(30));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,143 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.xinghan;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.XingHanCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_BOOT_LOGO_KEY_PREFIX;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 星汉设备开机 LOGO 下发规则:
|
||||
* <p>
|
||||
* 1. 设备上行 sta_PicTarns=great! => 仅标记成功<br>
|
||||
* 2. 设备上行 sta_PicTarns=数字 => 下发第 N 块数据(256B/块,带 CRC32)
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class XinghanBootLogoRule implements MqttMessageRule {
|
||||
|
||||
private final MqttGateway mqttGateway;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return XingHanCommandTypeConstants.XingHan_BOOT_LOGO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext ctx) {
|
||||
final String functionAccessKey = FUNCTION_ACCESS_KEY + ctx.getDeviceImei();
|
||||
try {
|
||||
MqttXinghanLogoJson payload = objectMapper.convertValue(
|
||||
ctx.getPayloadDict(), MqttXinghanLogoJson.class);
|
||||
|
||||
String respText = payload.getStaPicTrans();
|
||||
log.warn("设备上报LOGO:{}", respText);
|
||||
|
||||
// 1. great! —— 成功标记
|
||||
if ("great!".equalsIgnoreCase(respText)) {
|
||||
RedisUtils.setCacheObject(functionAccessKey,
|
||||
FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
log.info("设备 {} 开机 LOGO 写入成功", ctx.getDeviceImei());
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 数字 —— 下发数据块
|
||||
int blockIndex;
|
||||
try {
|
||||
blockIndex = Integer.parseInt(respText);
|
||||
} catch (NumberFormatException ex) {
|
||||
log.warn("设备 {} LOGO 上报非法块号:{}", ctx.getDeviceImei(), respText);
|
||||
return;
|
||||
}
|
||||
String hexImage = RedisUtils.getCacheObject(
|
||||
GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + ctx.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX);
|
||||
if (StringUtils.isEmpty(hexImage)) {
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] fullBin = ImageToCArrayConverter.convertStringToByteArray(hexImage);
|
||||
byte[] chunk = ImageToCArrayConverter.getChunk(fullBin, blockIndex - 1, CHUNK_SIZE);
|
||||
log.info("设备 {} 第 {} 块数据长度: {} bytes", ctx.getDeviceImei(), blockIndex, chunk.length);
|
||||
|
||||
// 组装下发数据
|
||||
ArrayList<Integer> dataFrame = new ArrayList<>();
|
||||
dataFrame.add(blockIndex); // 块号
|
||||
ImageToCArrayConverter.buildArr(convertHexToDecimal(chunk), dataFrame);
|
||||
dataFrame.addAll(crc32AsList(chunk)); // CRC32
|
||||
|
||||
Map<String, Object> pub = new HashMap<>();
|
||||
pub.put("ins_PicTrans", dataFrame);
|
||||
|
||||
String topic = MqttConstants.GLOBAL_PUB_KEY + ctx.getDeviceImei();
|
||||
String json = JsonUtils.toJsonString(pub);
|
||||
mqttGateway.sendMsgToMqtt(topic, 1, json);
|
||||
|
||||
log.info("下发开机 LOGO 数据 => topic:{}, payload:{}", topic, json);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理设备 {} 开机 LOGO 失败", ctx.getDeviceImei(), e);
|
||||
RedisUtils.setCacheObject(functionAccessKey,
|
||||
FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 内部工具 ---------- */
|
||||
|
||||
private static final int CHUNK_SIZE = 256;
|
||||
|
||||
private static ArrayList<Integer> crc32AsList(byte[] data) {
|
||||
CRC32 crc = new CRC32();
|
||||
crc.update(data);
|
||||
byte[] crcBytes = ByteBuffer.allocate(4)
|
||||
.order(ByteOrder.BIG_ENDIAN)
|
||||
.putInt((int) crc.getValue())
|
||||
.array();
|
||||
ArrayList<Integer> list = new ArrayList<>(4);
|
||||
for (byte b : crcBytes) {
|
||||
list.add(Byte.toUnsignedInt(b));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/* ---------- DTO ---------- */
|
||||
|
||||
@Data
|
||||
private static class MqttXinghanLogoJson {
|
||||
/**
|
||||
* 设备上行:
|
||||
* 数字 -> 请求对应块号
|
||||
* great! -> 写入成功
|
||||
*/
|
||||
@JsonProperty("sta_PicTrans")
|
||||
private String staPicTrans;
|
||||
}
|
||||
}
|
||||
@ -1,212 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.xinghan;
|
||||
|
||||
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.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
|
||||
import com.fuyuanshen.equipment.utils.map.LngLonUtil;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttXinghanJson;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.XingHanCommandTypeConstants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 主动上报设备数据命令处理
|
||||
* 第一键值对,静电预警档位:3,2,1,0,分别表示高档/中档/低挡/关闭.
|
||||
* 第二键值对,照明档位,2,1,0,分别表示弱光/强光/关闭
|
||||
* 第三键值对,SOS档位,2,1,0, 分别表示红蓝模式/爆闪模式/关闭
|
||||
* 第四键值对,剩余照明时间,0-5999,单位分钟。
|
||||
* 第五键值对, 剩余电量百分比,0-100。
|
||||
* 第六键值对, 近电预警级别, 0-无预警,1-弱预警,2-中预警,3-强预警,4-非常强预警。
|
||||
* 第七键值对, 静止报警状态,0-未静止报警,1-正在静止报警。
|
||||
* 第八键值对, 4G信号强度,0-32,数值越大,信号越强。
|
||||
* 第九键值对,IMIE卡号
|
||||
* 第十键值对,经度
|
||||
* 第十一键值对,纬度
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return XingHanCommandTypeConstants.XingHan_DEVICE_DATA;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
try {
|
||||
// Latitude, longitude
|
||||
//主灯档位,激光灯档位,电量百分比,充电状态,电池剩余续航时间
|
||||
MqttXinghanJson deviceStatus = objectMapper.convertValue(context.getPayloadDict(), MqttXinghanJson.class);
|
||||
|
||||
// 发送设备状态和位置信息到Redis
|
||||
asyncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),deviceStatus);
|
||||
} catch (Exception e) {
|
||||
log.error("处理上报数据命令时出错", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送设备状态信息和位置信息到Redis
|
||||
*
|
||||
* @param deviceImei 设备IMEI
|
||||
* @param deviceStatus 机器主动上报的状态信息
|
||||
*/
|
||||
public void asyncSendDeviceDataToRedisWithFuture(String deviceImei, MqttXinghanJson deviceStatus) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
|
||||
// 将设备状态信息存储到Redis中
|
||||
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + deviceImei + DEVICE_STATUS_KEY_PREFIX;
|
||||
String deviceInfoJson = JsonUtils.toJsonString(deviceStatus);
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(deviceRedisKey, deviceInfoJson);
|
||||
|
||||
log.info("设备状态信息已异步发送到Redis: device={}, deviceInfoJson={}",
|
||||
deviceImei, deviceInfoJson);
|
||||
|
||||
//设备坐标缓存KEY
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + deviceImei;
|
||||
// 异步发送经纬度到Redis
|
||||
asyncSendLocationToRedisWithFuture(deviceImei, deviceStatus.getStalatitude(), deviceStatus.getStalongitude());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("异步发送设备信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步发送位置信息到Redis(使用CompletableFuture)
|
||||
*
|
||||
* @param deviceImei 设备IMEI
|
||||
* @param latitude 纬度
|
||||
* @param longitude 经度
|
||||
*/
|
||||
public void asyncSendLocationToRedisWithFuture(String deviceImei, String latitude, String longitude) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
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 redisObj = RedisUtils.getCacheObject(redisKey);
|
||||
JSONObject jsonOBj = JSONObject.parseObject(redisObj);
|
||||
if(jsonOBj != null){
|
||||
String str1 = latArr[0] +"."+ latArr[1].substring(0,4);
|
||||
String str2 = lonArr[0] +"."+ lonArr[1].substring(0,4);
|
||||
|
||||
String cacheLatitude = jsonOBj.getString("wgs84_latitude");
|
||||
String cacheLongitude = jsonOBj.getString("wgs84_longitude");
|
||||
String[] latArr1 = cacheLatitude.split("\\.");
|
||||
String[] lonArr1 = cacheLongitude.split("\\.");
|
||||
|
||||
String cacheStr1 = latArr1[0] +"."+ latArr1[1].substring(0,4);
|
||||
String cacheStr2 = lonArr1[0] +"."+ lonArr1[1].substring(0,4);
|
||||
if(str1.equals(cacheStr1) && str2.equals(cacheStr2)){
|
||||
log.info("位置信息未发生变化: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 构造位置信息对象
|
||||
Map<String, Object> locationInfo = new LinkedHashMap<>();
|
||||
double[] doubles = LngLonUtil.gps84_To_Gcj02(Double.parseDouble(latitude), Double.parseDouble(longitude));
|
||||
locationInfo.put("deviceImei", deviceImei);
|
||||
locationInfo.put("latitude", doubles[0]);
|
||||
locationInfo.put("longitude", doubles[1]);
|
||||
locationInfo.put("wgs84_latitude", latitude);
|
||||
locationInfo.put("wgs84_longitude", longitude);
|
||||
String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
|
||||
locationInfo.put("address", address);
|
||||
locationInfo.put("timestamp", System.currentTimeMillis());
|
||||
|
||||
|
||||
|
||||
String locationJson = JsonUtils.toJsonString(locationInfo);
|
||||
|
||||
// 存储到Redis
|
||||
RedisUtils.setCacheObject(redisKey, locationJson);
|
||||
|
||||
// 存储到一个列表中,保留历史位置信息
|
||||
// String locationHistoryKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX + deviceImei;
|
||||
// RedisUtils.addCacheList(locationHistoryKey, locationJson);
|
||||
// RedisUtils.expire(locationHistoryKey, Duration.ofDays(90));
|
||||
storeDeviceTrajectoryWithSortedSet(deviceImei, locationJson);
|
||||
log.info("位置信息已异步发送到Redis: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
|
||||
} catch (Exception e) {
|
||||
log.error("异步发送位置信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储设备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 = "device:trajectory:zset:" + deviceImei;
|
||||
// String locationJson = JsonUtils.toJsonString(locationInfo);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
// 添加到Sorted Set,使用时间戳作为score
|
||||
RedisUtils.zAdd(trajectoryKey, locationJson, timestamp);
|
||||
|
||||
// // 设置30天过期时间
|
||||
// RedisUtils.expire(trajectoryKey, Duration.ofDays(30));
|
||||
|
||||
// 清理30天前的数据(冗余保护)
|
||||
long thirtyDaysAgo = System.currentTimeMillis() - (7L * 24 * 60 * 60 * 1000);
|
||||
RedisUtils.zRemoveRangeByScore(trajectoryKey, 0, thirtyDaysAgo);
|
||||
} catch (Exception e) {
|
||||
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)));
|
||||
String str2 = lonArr[1];
|
||||
intData.add(Integer.parseInt(lonArr[0]));
|
||||
intData.add(Integer.parseInt(str2.substring(0,4)));
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,117 +0,0 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.xinghan;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.XingHanCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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 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.DEVICE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 星汉设备发送消息 下发规则:
|
||||
* <p>
|
||||
* 1. 设备上行 sta_TexTarns=genius! => 仅标记成功<br>
|
||||
* 2. 设备上行 sta_TexTarns=数字 => GBK编码,每行文字为一包,一共4包,第一字节为包序号
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class XinghanSendMsgRule implements MqttMessageRule {
|
||||
|
||||
private final MqttGateway mqttGateway;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return XingHanCommandTypeConstants.XingHan_ESEND_MSG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext ctx) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + ctx.getDeviceImei();
|
||||
try {
|
||||
XinghanSendMsgRule.MqttXinghanMsgJson payload = objectMapper.convertValue(
|
||||
ctx.getPayloadDict(), XinghanSendMsgRule.MqttXinghanMsgJson.class);
|
||||
|
||||
String respText = payload.getStaTexTrans();
|
||||
log.info("设备上报人员信息: {} ", respText);
|
||||
|
||||
// 1. genius! —— 成功标记
|
||||
if ("genius!".equalsIgnoreCase(respText)) {
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
log.info("设备 {} 发送消息完成", ctx.getDeviceImei());
|
||||
return;
|
||||
}
|
||||
// 2. 数字 —— 下发数据块
|
||||
int blockIndex;
|
||||
try {
|
||||
blockIndex = Integer.parseInt(respText);
|
||||
} catch (NumberFormatException ex) {
|
||||
log.warn("设备 {} 消息上报非法块号:{}", ctx.getDeviceImei(), respText);
|
||||
return;
|
||||
}
|
||||
// 将发送的信息原文本以List<String>形式存储在Redis中
|
||||
List<String> data = RedisUtils.getCacheList(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + ctx.getDeviceImei() + ":app_send_message_data");
|
||||
if (data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
//
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(blockIndex);
|
||||
// 获取块原内容 转成GBK 再转成无符号十进制整数
|
||||
String blockTxt = data.get(blockIndex-1);
|
||||
// 再按 GBK 编码把字符串转成字节数组,并逐个转为无符号十进制整数
|
||||
for (byte b : blockTxt.getBytes(GBK)) {
|
||||
intData.add(b & 0xFF); // b & 0xFF 得到 0~255 的整数
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("ins_TexTrans", intData);
|
||||
|
||||
String topic = MqttConstants.GLOBAL_PUB_KEY + ctx.getDeviceImei();
|
||||
String json = JsonUtils.toJsonString(map);
|
||||
mqttGateway.sendMsgToMqtt(topic, 1, json);
|
||||
log.info("发送设备信息数据到设备消息=>topic:{},payload:{}",
|
||||
MqttConstants.GLOBAL_PUB_KEY + ctx.getDeviceImei(),
|
||||
JsonUtils.toJsonString(map));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理发送设备信息时出错", e);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
}
|
||||
}
|
||||
|
||||
private static final Charset GBK = Charset.forName("GBK");
|
||||
|
||||
/* ---------- DTO ---------- */
|
||||
|
||||
@Data
|
||||
private static class MqttXinghanMsgJson {
|
||||
/**
|
||||
* 设备上行:
|
||||
* 数字 -> 请求对应块号
|
||||
* genius! -> 写入成功
|
||||
*/
|
||||
@JsonProperty("sta_TexTrans")
|
||||
private String staTexTrans;
|
||||
}
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
package com.fuyuanshen.web;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class ChineseVCardGenerator {
|
||||
public static void main(String[] args) {
|
||||
// 定义江西上饶的134号段(共22个)
|
||||
String[] prefixes = {
|
||||
"1340703", "1340793", "1342650", "1342651", "1342663",
|
||||
"1342664", "1342665", "1343703", "1343793", "1347901",
|
||||
"1347902", "1347903", "1347930", "1347931", "1347932",
|
||||
"1347933", "1347934", "1347935", "1347936", "1347937",
|
||||
"1347938", "1347939"
|
||||
};
|
||||
|
||||
// 创建.vcf文件
|
||||
String filename = "上饶联系人.vcf";
|
||||
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename, true))) {
|
||||
// 添加文件头信息(包含中文)
|
||||
writer.write("BEGIN:VCARD");
|
||||
writer.newLine();
|
||||
writer.write("VERSION:3.0");
|
||||
writer.newLine();
|
||||
writer.write("X-GENERATOR:Java VCard Generator");
|
||||
writer.newLine();
|
||||
writer.write("PRODID:-//Apple Inc.//iPhone OS 15.6//EN");
|
||||
writer.newLine();
|
||||
writer.newLine();
|
||||
|
||||
// 生成所有联系人
|
||||
int count = 0;
|
||||
for (String prefix : prefixes) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String middle = String.format("%02d", i);
|
||||
String phoneNumber = prefix + middle + "51";
|
||||
|
||||
// 写入单个联系人(使用中文)
|
||||
writer.write("FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:用户" + (count + 1)); // 中文姓名
|
||||
writer.newLine();
|
||||
writer.write("TEL;TYPE=CELL;CHARSET=UTF-8:" + phoneNumber); // 手机号
|
||||
writer.newLine();
|
||||
writer.write("NOTE;CHARSET=UTF-8:生成时间 " + new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
||||
writer.newLine();
|
||||
writer.write("END:VCARD");
|
||||
writer.newLine();
|
||||
writer.newLine();
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("成功生成 " + count + " 个中文联系人");
|
||||
System.out.println("文件已保存为: " + filename);
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("文件写入错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package com.fuyuanshen.web;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PhoneNumberGenerator {
|
||||
public static void main(String[] args) {
|
||||
// 定义江西上饶的134号段(共22个)
|
||||
String[] prefixes = {
|
||||
"1340703", "1340793", "1342650", "1342651", "1342663",
|
||||
"1342664", "1342665", "1343703", "1343793", "1347901",
|
||||
"1347902", "1347903", "1347930", "1347931", "1347932",
|
||||
"1347933", "1347934", "1347935", "1347936", "1347937",
|
||||
"1347938", "1347939"
|
||||
};
|
||||
|
||||
// 输出到控制台
|
||||
System.out.println("江西上饶134号段完整手机号码(共2200个):");
|
||||
for (String prefix : prefixes) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String middle = String.format("%02d", i); // 生成00-99的中间数字
|
||||
System.out.println(prefix + middle + "51");
|
||||
}
|
||||
}
|
||||
|
||||
// 同时输出到文件(可选)
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter("shangrao_phones.txt"))) {
|
||||
for (String prefix : prefixes) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String middle = String.format("%02d", i);
|
||||
writer.write(prefix + middle + "51");
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
System.out.println("\n同时已保存到文件:shangrao_phones.txt");
|
||||
} catch (IOException e) {
|
||||
System.err.println("文件写入错误:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
package com.fuyuanshen.web;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class VCardGenerator {
|
||||
public static void main(String[] args) {
|
||||
// 定义江西上饶的134号段(共22个)
|
||||
String[] prefixes = {
|
||||
"1340703", "1340793", "1342650", "1342651", "1342663",
|
||||
"1342664", "1342665", "1343703", "1343793", "1347901",
|
||||
"1347902", "1347903", "1347930", "1347931", "1347932",
|
||||
"1347933", "1347934", "1347935", "1347936", "1347937",
|
||||
"1347938", "1347939"
|
||||
};
|
||||
|
||||
// 创建.vcf文件
|
||||
String filename = "shangrao_contacts.vcf";
|
||||
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
|
||||
// 写入文件头
|
||||
writer.write("BEGIN:VCARD");
|
||||
writer.newLine();
|
||||
writer.write("VERSION:3.0");
|
||||
writer.newLine();
|
||||
writer.newLine();
|
||||
|
||||
// 生成所有联系人
|
||||
int count = 0;
|
||||
for (String prefix : prefixes) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String middle = String.format("%02d", i);
|
||||
String phoneNumber = prefix + middle + "51";
|
||||
|
||||
// 写入单个联系人
|
||||
writer.write("FN:" + phoneNumber); // 姓名字段使用手机号
|
||||
writer.newLine();
|
||||
writer.write("TEL;TYPE=CELL:" + phoneNumber); // 电话字段使用手机号
|
||||
writer.newLine();
|
||||
writer.write("END:VCARD");
|
||||
writer.newLine();
|
||||
writer.newLine();
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
// 写入文件尾
|
||||
writer.write("END:VCARD");
|
||||
|
||||
System.out.println("成功生成 " + count + " 个联系人");
|
||||
System.out.println("文件已保存为: " + filename);
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("文件写入错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,61 +0,0 @@
|
||||
//package com.fuyuanshen.web.config;
|
||||
//
|
||||
//import cn.hutool.core.lang.UUID;
|
||||
//import com.fuyuanshen.global.mqtt.config.MqttPropertiesConfig;
|
||||
//import com.fuyuanshen.web.handler.mqtt.DeviceReceiverMessageHandler;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.integration.annotation.ServiceActivator;
|
||||
//import org.springframework.integration.channel.DirectChannel;
|
||||
//import org.springframework.integration.core.MessageProducer;
|
||||
//import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
|
||||
//import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
|
||||
//import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
|
||||
//import org.springframework.messaging.MessageChannel;
|
||||
//import org.springframework.messaging.MessageHandler;
|
||||
//
|
||||
///**
|
||||
// * @author: 默苍璃
|
||||
// * @date: 2025-08-0110:46
|
||||
// */
|
||||
//@Configuration
|
||||
//public class CustomMqttInboundConfiguration {
|
||||
//
|
||||
// @Autowired
|
||||
// private MqttPropertiesConfig mqttPropertiesConfig;
|
||||
// @Autowired
|
||||
// private MqttPahoClientFactory mqttPahoClientFactory;
|
||||
// @Autowired
|
||||
// private DeviceReceiverMessageHandler deviceReceiverMessageHandler;
|
||||
//
|
||||
//
|
||||
// @Bean
|
||||
// public MessageChannel customMqttChannel(){
|
||||
// return new DirectChannel();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Bean
|
||||
// public MessageProducer customMessageProducer(){
|
||||
// String clientId = "custom_client_" + UUID.fastUUID();
|
||||
// MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(
|
||||
// mqttPropertiesConfig.getUrl(),
|
||||
// clientId,
|
||||
// mqttPahoClientFactory,
|
||||
// "A/#", "B/#" // 直接指定这两个主题
|
||||
// );
|
||||
// adapter.setQos(1);
|
||||
// adapter.setConverter(new DefaultPahoMessageConverter());
|
||||
// adapter.setOutputChannel(customMqttChannel());
|
||||
// return adapter;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Bean
|
||||
// @ServiceActivator(inputChannel = "customMqttChannel")
|
||||
// public MessageHandler customMessageHandler(){
|
||||
// return deviceReceiverMessageHandler;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@ -1,119 +0,0 @@
|
||||
package com.fuyuanshen.web.controller.device;
|
||||
|
||||
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后台:设备控制类
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/bjq/device")
|
||||
public class DeviceBJQController 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,104 +0,0 @@
|
||||
package com.fuyuanshen.web.controller.device;
|
||||
|
||||
import com.fuyuanshen.app.domain.dto.APPReNameDTO;
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.dto.InstructionRecordDto;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.InstructionRecordVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.WebDeviceVo;
|
||||
import com.fuyuanshen.web.service.device.DeviceBizService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* web后台:设备控制中心
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/device")
|
||||
public class DeviceControlCenterController extends BaseController {
|
||||
|
||||
private final DeviceBizService appDeviceService;
|
||||
/**
|
||||
* 查询设备列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<WebDeviceVo> list(DeviceQueryCriteria bo, PageQuery pageQuery) {
|
||||
return appDeviceService.queryWebDeviceList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定设备
|
||||
*/
|
||||
@PostMapping("/bind")
|
||||
public R<Void> bind(@RequestBody AppDeviceBo bo) {
|
||||
return toAjax(appDeviceService.bindDevice(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解绑设备
|
||||
*/
|
||||
@DeleteMapping("/unBind")
|
||||
public R<Void> unBind(Long id) {
|
||||
return toAjax(appDeviceService.unBindDevice(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备类型列表
|
||||
*/
|
||||
@GetMapping(value = "/typeList")
|
||||
public R<List<APPDeviceTypeVo>> getTypeList() {
|
||||
List<APPDeviceTypeVo> typeList = appDeviceService.getTypeList();
|
||||
return R.ok(typeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重命名设备
|
||||
*
|
||||
* @param reNameDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/reName")
|
||||
public R<String> reName(@Validated @RequestBody APPReNameDTO reNameDTO) {
|
||||
appDeviceService.reName(reNameDTO);
|
||||
return R.ok("重命名成功!!!");
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/realTimeStatus")
|
||||
public R<Map<String, Object>> getRealTimeStatus(AppRealTimeStatusDto statusDto) {
|
||||
Map<String, Object> status = appDeviceService.getRealTimeStatus(statusDto);
|
||||
return R.ok(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据mac查询设备信息
|
||||
*/
|
||||
@GetMapping("/getDeviceInfoByDeviceMac")
|
||||
public R<AppDeviceVo> getDeviceInfo(String deviceMac) {
|
||||
return R.ok(appDeviceService.getDeviceInfo(deviceMac));
|
||||
}
|
||||
|
||||
/**
|
||||
* 指令下发记录
|
||||
*/
|
||||
@GetMapping("/instructionRecord")
|
||||
public TableDataInfo<InstructionRecordVo> getInstructionRecord(InstructionRecordDto dto, PageQuery pageQuery) {
|
||||
return appDeviceService.getInstructionRecord(dto,pageQuery);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,134 +0,0 @@
|
||||
package com.fuyuanshen.web.controller.device;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.*;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
||||
import com.fuyuanshen.common.log.annotation.Log;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.log.enums.BusinessType;
|
||||
import com.fuyuanshen.common.excel.utils.ExcelUtil;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceGroupVo;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceGroupBo;
|
||||
import com.fuyuanshen.equipment.service.IDeviceGroupService;
|
||||
|
||||
/**
|
||||
* 设备分组
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-08-08
|
||||
*/
|
||||
@Tag(name = "web:设备分组", description = "web:设备分组")
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/device/group")
|
||||
public class DeviceGroupController extends BaseController {
|
||||
|
||||
private final IDeviceGroupService deviceGroupService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备分组列表
|
||||
*/
|
||||
@Operation(summary = "查询设备分组列表")
|
||||
@SaCheckPermission("fys-equipment:group:list")
|
||||
@GetMapping("/list")
|
||||
public R<List<DeviceGroupVo>> list(DeviceGroupBo bo) {
|
||||
List<DeviceGroupVo> list = deviceGroupService.queryList(bo);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出设备分组列表
|
||||
*/
|
||||
@SaCheckPermission("fys-equipment:group:export")
|
||||
@Log(title = "设备分组", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(DeviceGroupBo bo, HttpServletResponse response) {
|
||||
List<DeviceGroupVo> list = deviceGroupService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "设备分组", DeviceGroupVo.class, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备分组详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@Operation(summary = "获取设备分组详细信息")
|
||||
@SaCheckPermission("fys-equipment:group:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<DeviceGroupVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||
return R.ok(deviceGroupService.queryById(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增设备分组
|
||||
*/
|
||||
@Operation(summary = "新增设备分组")
|
||||
@SaCheckPermission("fys-equipment:group:add")
|
||||
@Log(title = "设备分组", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody DeviceGroupBo bo) {
|
||||
return toAjax(deviceGroupService.insertByBo(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改设备分组
|
||||
*/
|
||||
@Operation(summary = "修改设备分组")
|
||||
@SaCheckPermission("fys-equipment:group:edit")
|
||||
@Log(title = "设备分组", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody DeviceGroupBo bo) {
|
||||
return toAjax(deviceGroupService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备分组
|
||||
*
|
||||
* @param ids 主键串
|
||||
*/
|
||||
@Operation(summary = "删除设备分组")
|
||||
@SaCheckPermission("fys-equipment:group:remove")
|
||||
@Log(title = "设备分组", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
|
||||
return toAjax(deviceGroupService.deleteWithValidByIds(List.of(ids), true));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 绑定设备分组
|
||||
*
|
||||
* @param groupId 分组id
|
||||
* @param deviceId 设备id
|
||||
*/
|
||||
@Operation(summary = "绑定设备分组")
|
||||
// @SaCheckPermission("fys-equipment:group:remove")
|
||||
@Log(title = "绑定设备分组", businessType = BusinessType.DELETE)
|
||||
@GetMapping("/groupId/{deviceId}")
|
||||
public R<Void> bindingDevice(@NotEmpty(message = "分组id 不能为空") @PathVariable Long groupId,
|
||||
@NotEmpty(message = "设备id 不能为空") @PathVariable Long[] deviceId) {
|
||||
return toAjax(deviceGroupService.bindingDevice(groupId, deviceId));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,18 +1,16 @@
|
||||
package com.fuyuanshen.web.controller.device;
|
||||
|
||||
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.vo.WebDeviceVo;
|
||||
import com.fuyuanshen.web.service.WEBDeviceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -43,34 +41,6 @@ public class WEBDeviceController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设备详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "设备详情")
|
||||
@GetMapping(value = "/pc/detail/{id}")
|
||||
public R<WebDeviceVo> getDevice(@PathVariable Long id) {
|
||||
WebDeviceVo device = deviceService.getDevice(id);
|
||||
return R.ok(device);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设备用户详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "设备详情")
|
||||
@GetMapping(value = "/getDeviceUser/{id}")
|
||||
public R<List<AppPersonnelInfoRecords>> getDeviceUser(@PathVariable Long id) {
|
||||
List<AppPersonnelInfoRecords> device = deviceService.getDeviceUser(id);
|
||||
return R.ok(device);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,50 +0,0 @@
|
||||
package com.fuyuanshen.web.enums;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-08-0114:14
|
||||
*/
|
||||
public enum InstructType6170 {
|
||||
|
||||
EQUIPMENT_REPORTING(0, "设备启动"),
|
||||
LIGHT_MODE(1, "灯光模式"),
|
||||
/**
|
||||
* 设备信息
|
||||
* 单位/姓名/职位
|
||||
*/
|
||||
UNIT_INFO(2, "设备信息"),
|
||||
BOOT_IMAGE(3, "开机图片"),
|
||||
LASER_LIGHT(4, "激光灯"),
|
||||
BRIGHTNESS(5, "亮度调节"),
|
||||
LOCATION_DATA(11, "定位数据"),
|
||||
|
||||
|
||||
UNKNOWN(-1, "未知操作");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
InstructType6170(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static InstructType6170 fromCode(int code) {
|
||||
for (InstructType6170 type : values()) {
|
||||
if (type.getCode() == code) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
// throw new IllegalArgumentException("未知的指令类型代码: " + code);
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
package com.fuyuanshen.web.enums;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-08-0114:30
|
||||
*/
|
||||
public enum LightModeEnum6170 {
|
||||
|
||||
OFF(0, "关灯"),
|
||||
HIGH_BEAM(1, "强光模式"),
|
||||
LOW_BEAM(2, "弱光模式"),
|
||||
STROBE(3, "爆闪模式"),
|
||||
FLOOD(4, "泛光模式"),
|
||||
|
||||
UNKNOWN(-1, "未知的灯光模式");
|
||||
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
|
||||
LightModeEnum6170(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static LightModeEnum6170 fromCode(int code) {
|
||||
for (LightModeEnum6170 mode : values()) {
|
||||
if (mode.getCode() == code) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
// throw new IllegalArgumentException("未知的灯光模式代码: " + code);
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,318 +0,0 @@
|
||||
//package com.fuyuanshen.web.handler.mqtt;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.fasterxml.jackson.databind.JsonNode;
|
||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
//import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
//import com.fuyuanshen.equipment.domain.Device;
|
||||
//import com.fuyuanshen.equipment.domain.DeviceLog;
|
||||
//import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
|
||||
//import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
//import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
|
||||
//import com.fuyuanshen.equipment.utils.map.LngLonUtil;
|
||||
//import com.fuyuanshen.global.mqtt.constants.TenantsConstant;
|
||||
//import com.fuyuanshen.web.enums.InstructType6170;
|
||||
//import com.fuyuanshen.web.enums.LightModeEnum6170;
|
||||
//import lombok.AllArgsConstructor;
|
||||
//import lombok.Data;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.messaging.Message;
|
||||
//import org.springframework.messaging.MessageHandler;
|
||||
//import org.springframework.messaging.MessageHeaders;
|
||||
//import org.springframework.messaging.MessagingException;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
///**
|
||||
// * 定义监听主题消息的处理器
|
||||
// *
|
||||
// * @author: 默苍璃
|
||||
// * @date: 2025-08-0110:19
|
||||
// */
|
||||
//@Component
|
||||
//@Data
|
||||
//@AllArgsConstructor
|
||||
//@Slf4j
|
||||
//public class DeviceReceiverMessageHandler implements MessageHandler {
|
||||
//
|
||||
// private final DeviceMapper deviceMapper;
|
||||
// private final DeviceLogMapper deviceLogMapper;
|
||||
//
|
||||
// // 使用Jackson解析JSON
|
||||
// private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 处理接收的消息
|
||||
// *
|
||||
// * @param message
|
||||
// * @throws MessagingException
|
||||
// */
|
||||
// @Override
|
||||
// public void handleMessage(Message<?> message) throws MessagingException {
|
||||
// // System.out.println("接收到的消息:" + message.getPayload());
|
||||
// MessageHeaders headers = message.getHeaders();
|
||||
// String receivedTopicName = (String) headers.get("mqtt_receivedTopic");
|
||||
// System.out.println("消息来自主题:" + receivedTopicName);
|
||||
//
|
||||
// // String tenantId = LoginHelper.getTenantId();
|
||||
// String tenantId = TenantsConstant.FU_YUAN_SHENG;
|
||||
// String payload = message.getPayload().toString();
|
||||
//
|
||||
// if (receivedTopicName != null) {
|
||||
// // 1. 提取设备ID (从主题中获取)
|
||||
// String deviceImei = extractDeviceId(receivedTopicName);
|
||||
// Device device = deviceMapper.selectOne(new QueryWrapper<Device>()
|
||||
// .eq("tenant_id", tenantId)
|
||||
// .eq("device_imei", deviceImei));
|
||||
// if (device == null) {
|
||||
// log.info("不存在的设备IMEI: {}", deviceImei);
|
||||
// } else {
|
||||
//
|
||||
// try {
|
||||
// JsonNode root = objectMapper.readTree(payload);
|
||||
//
|
||||
// DeviceLog record = new DeviceLog();
|
||||
// // 手动设置租户ID
|
||||
// record.setTenantId(device.getTenantId()); // 从设备信息中获取租户ID
|
||||
// // 设备ID
|
||||
// record.setDeviceId(device.getId());
|
||||
// // 设备名称
|
||||
// record.setDeviceName(device.getDeviceName());
|
||||
//
|
||||
// // 2. 处理instruct消息
|
||||
// if (root.has("instruct")) {
|
||||
// JsonNode instructNode = root.get("instruct");
|
||||
// if (instructNode.isArray()) {
|
||||
// boolean b = receivedTopicName.startsWith("B/");
|
||||
// record = parseInstruct(device, instructNode, b);
|
||||
// // 根据不同主题进行不同处理
|
||||
// if (receivedTopicName.startsWith("A/")) {
|
||||
// // 处理A主题的消息(设备上传)
|
||||
// record.setDataSource("设备上报");
|
||||
// } else if (receivedTopicName.startsWith("B/")) {
|
||||
// // 处理B主题的消息 (手动上传)
|
||||
// record.setDataSource("客户端操作");
|
||||
// }
|
||||
// }
|
||||
// // 确保在插入前设置tenantId和deviceId
|
||||
// record.setTenantId(device.getTenantId());
|
||||
// record.setDeviceId(device.getId());
|
||||
// deviceLogMapper.insert(record);
|
||||
// }
|
||||
//
|
||||
// // 2. 处理 state 消息
|
||||
// if (root.has("state")) {
|
||||
// JsonNode instructNode = root.get("state");
|
||||
// if (instructNode.isArray()) {
|
||||
// boolean b = receivedTopicName.startsWith("B/");
|
||||
// record = parseState(device, instructNode, b);
|
||||
// // 根据不同主题进行不同处理
|
||||
// if (receivedTopicName.startsWith("A/")) {
|
||||
// // 处理A主题的消息(设备上传)
|
||||
// record.setDataSource("设备上报");
|
||||
// } else if (receivedTopicName.startsWith("B/")) {
|
||||
// // 处理B主题的消息 (手动上传)
|
||||
// record.setDataSource("客户端操作");
|
||||
// }
|
||||
// }
|
||||
// // 确保在插入前设置tenantId和deviceId
|
||||
// record.setTenantId(device.getTenantId());
|
||||
// record.setDeviceId(device.getId());
|
||||
// deviceLogMapper.insert(record);
|
||||
// }
|
||||
//
|
||||
// if (root.has("imei")) {
|
||||
// // 设备行为
|
||||
// record.setDeviceAction(InstructType6170.fromCode(0).getDescription());
|
||||
// record.setDataSource("设备上报");
|
||||
// record.setContent("设备启动");
|
||||
// // 确保在插入前设置tenantId和deviceId
|
||||
// record.setTenantId(device.getTenantId());
|
||||
// record.setDeviceId(device.getId());
|
||||
// deviceLogMapper.insert(record);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // 3. 处理state消息
|
||||
// // else if (root.has("state")) {
|
||||
// // JsonNode stateNode = root.get("state");
|
||||
// // if (stateNode.isArray()) {
|
||||
// // StateRecord record = parseState(device, stateNode);
|
||||
// // stateRepo.save(record);
|
||||
// // }
|
||||
// // }
|
||||
// } catch (Exception e) {
|
||||
// log.error("消息解析失败: {}", payload, e);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 从主题中提取设备ID(IMEI)
|
||||
// *
|
||||
// * @param topic
|
||||
// * @return
|
||||
// */
|
||||
// private String extractDeviceId(String topic) {
|
||||
// // 处理 A/# 或 B/# 格式的主题,例如 B/861556078765285 或 A/861556078765285
|
||||
// String[] segments = topic.split("/");
|
||||
// if (segments.length >= 2) {
|
||||
// // 返回第二个段,即 / 后面的部分
|
||||
// return segments[1];
|
||||
// }
|
||||
// // 如果格式不符合预期,返回原主题
|
||||
// return topic;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 解析instruct消息
|
||||
// *
|
||||
// * @param device
|
||||
// * @param array
|
||||
// * @param b
|
||||
// * @return
|
||||
// */
|
||||
// private DeviceLog parseInstruct(Device device, JsonNode array, boolean b) {
|
||||
// DeviceLog record = new DeviceLog();
|
||||
// record.setDeviceName(device.getDeviceName());
|
||||
// // 设备行为
|
||||
// record.setDeviceAction(InstructType6170.fromCode(array.get(0).asInt()).getDescription());
|
||||
//
|
||||
// switch (array.get(0).asInt()) {
|
||||
// case 1: // 灯光模式
|
||||
// LightModeEnum6170 lightModeEnum6170 = LightModeEnum6170.fromCode(array.get(1).asInt());
|
||||
// record.setContent(lightModeEnum6170.getDescription());
|
||||
// break;
|
||||
//
|
||||
// case 2: // 单位/姓名/职位
|
||||
// byte[] unitBytes = new byte[480];
|
||||
// for (int i = 1; i <= 480; i++) {
|
||||
// unitBytes[i - 1] = (byte) array.get(i).asInt();
|
||||
// }
|
||||
// // record.setUnitData(unitBytes);
|
||||
// break;
|
||||
//
|
||||
// case 3: // 开机图片
|
||||
// // record.setImagePage(array.get(1).asInt());
|
||||
// byte[] imageBytes = new byte[512];
|
||||
// for (int i = 2; i <= 513; i++) {
|
||||
// imageBytes[i - 2] = (byte) array.get(i).asInt();
|
||||
// }
|
||||
// // record.setImageData(imageBytes);
|
||||
// break;
|
||||
//
|
||||
// case 4: // 激光灯
|
||||
// int anInt = array.get(1).asInt();
|
||||
// if (anInt == 0) {
|
||||
// record.setContent("关闭激光灯");
|
||||
// } else if (anInt == 1) {
|
||||
// record.setContent("开启激光灯");
|
||||
// } else {
|
||||
// record.setContent("未知操作");
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case 5: // 亮度调节
|
||||
// record.setContent(+array.get(1).asInt() + "%");
|
||||
// break;
|
||||
//
|
||||
// case 11: // 定位数据
|
||||
// if (b) {
|
||||
// break;
|
||||
// }
|
||||
// int i1 = array.get(1).asInt();
|
||||
// int i2 = array.get(2).asInt();
|
||||
// int i3 = array.get(3).asInt();
|
||||
// int i4 = array.get(4).asInt();
|
||||
//
|
||||
// // 优雅的转换方式 Longitude and latitude
|
||||
// double latitude = i1 + i2 / 10.0;
|
||||
// double Longitude = i3 + i4 / 10.0;
|
||||
// // 84 ==》 高德
|
||||
// double[] doubles = LngLonUtil.gps84_To_Gcj02(latitude, Longitude);
|
||||
// String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
|
||||
// record.setContent(address);
|
||||
// break;
|
||||
// }
|
||||
// return record;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 解析 state 消息
|
||||
// *
|
||||
// * @param device
|
||||
// * @param array
|
||||
// * @return
|
||||
// */
|
||||
// private DeviceLog parseState(Device device, JsonNode array, boolean b) {
|
||||
// DeviceLog record = new DeviceLog();
|
||||
// record.setDeviceName(device.getDeviceName());
|
||||
// // 设备行为
|
||||
// record.setDeviceAction(InstructType6170.fromCode(array.get(0).asInt()).getDescription());
|
||||
//
|
||||
// switch (array.get(0).asInt()) {
|
||||
// case 1: // 灯光模式
|
||||
// LightModeEnum6170 lightModeEnum6170 = LightModeEnum6170.fromCode(array.get(1).asInt());
|
||||
// record.setContent(lightModeEnum6170.getDescription());
|
||||
// break;
|
||||
//
|
||||
// case 2: // 单位/姓名/职位
|
||||
// byte[] unitBytes = new byte[480];
|
||||
// for (int i = 1; i <= 480; i++) {
|
||||
// unitBytes[i - 1] = (byte) array.get(i).asInt();
|
||||
// }
|
||||
// // record.setUnitData(unitBytes);
|
||||
// break;
|
||||
//
|
||||
// case 3: // 开机图片
|
||||
// // record.setImagePage(array.get(1).asInt());
|
||||
// byte[] imageBytes = new byte[512];
|
||||
// for (int i = 2; i <= 513; i++) {
|
||||
// imageBytes[i - 2] = (byte) array.get(i).asInt();
|
||||
// }
|
||||
// // record.setImageData(imageBytes);
|
||||
// break;
|
||||
//
|
||||
// case 4: // 激光灯
|
||||
// int anInt = array.get(1).asInt();
|
||||
// if (anInt == 0) {
|
||||
// record.setContent("关闭激光灯");
|
||||
// } else if (anInt == 1) {
|
||||
// record.setContent("开启激光灯");
|
||||
// } else {
|
||||
// record.setContent("未知操作");
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case 5: // 亮度调节
|
||||
// record.setContent(+array.get(1).asInt() + "%");
|
||||
// break;
|
||||
//
|
||||
// case 11: // 定位数据
|
||||
// if (b) {
|
||||
// break;
|
||||
// }
|
||||
// int i1 = array.get(1).asInt();
|
||||
// int i2 = array.get(2).asInt();
|
||||
// int i3 = array.get(3).asInt();
|
||||
// int i4 = array.get(4).asInt();
|
||||
//
|
||||
// // 优雅的转换方式 Longitude and latitude
|
||||
// double latitude = i1 + i2 / 10.0;
|
||||
// double Longitude = i3 + i4 / 10.0;
|
||||
// // 84 ==》 高德
|
||||
// double[] doubles = LngLonUtil.gps84_To_Gcj02(latitude, Longitude);
|
||||
// String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
|
||||
// record.setContent(address);
|
||||
// break;
|
||||
// }
|
||||
// return record;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@ -1,163 +1,163 @@
|
||||
//package com.fuyuanshen.web.listener;
|
||||
//
|
||||
//import cn.dev33.satoken.listener.SaTokenListener;
|
||||
//import cn.dev33.satoken.stp.StpUtil;
|
||||
//import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
||||
//import cn.hutool.core.convert.Convert;
|
||||
//import cn.hutool.http.useragent.UserAgent;
|
||||
//import cn.hutool.http.useragent.UserAgentUtil;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import com.fuyuanshen.common.core.constant.CacheConstants;
|
||||
//import com.fuyuanshen.common.core.constant.Constants;
|
||||
//import com.fuyuanshen.common.core.domain.dto.UserOnlineDTO;
|
||||
//import com.fuyuanshen.common.core.utils.MessageUtils;
|
||||
//import com.fuyuanshen.common.core.utils.ServletUtils;
|
||||
//import com.fuyuanshen.common.core.utils.SpringUtils;
|
||||
//import com.fuyuanshen.common.core.utils.ip.AddressUtils;
|
||||
//import com.fuyuanshen.common.log.event.LogininforEvent;
|
||||
//import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
//import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
//import com.fuyuanshen.common.tenant.helper.TenantHelper;
|
||||
//import com.fuyuanshen.web.service.SysLoginService;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.time.Duration;
|
||||
//
|
||||
///**
|
||||
// * 用户行为 侦听器的实现
|
||||
// *
|
||||
// * @author Lion Li
|
||||
// */
|
||||
//@RequiredArgsConstructor
|
||||
//@Component
|
||||
//@Slf4j
|
||||
//public class UserActionListener implements SaTokenListener {
|
||||
//
|
||||
// private final SysLoginService loginService;
|
||||
//
|
||||
// /**
|
||||
// * 每次登录时触发
|
||||
// */
|
||||
// @Override
|
||||
// public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginParameter loginParameter) {
|
||||
// UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
|
||||
// String ip = ServletUtils.getClientIP();
|
||||
// UserOnlineDTO dto = new UserOnlineDTO();
|
||||
// dto.setIpaddr(ip);
|
||||
// dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
|
||||
// dto.setBrowser(userAgent.getBrowser().getName());
|
||||
// dto.setOs(userAgent.getOs().getName());
|
||||
// dto.setLoginTime(System.currentTimeMillis());
|
||||
// dto.setTokenId(tokenValue);
|
||||
// String username = (String) loginParameter.getExtra(LoginHelper.USER_NAME_KEY);
|
||||
// String tenantId = (String) loginParameter.getExtra(LoginHelper.TENANT_KEY);
|
||||
// dto.setUserName(username);
|
||||
// dto.setClientKey((String) loginParameter.getExtra(LoginHelper.CLIENT_KEY));
|
||||
// dto.setDeviceType(loginParameter.getDeviceType());
|
||||
// dto.setDeptName((String) loginParameter.getExtra(LoginHelper.DEPT_NAME_KEY));
|
||||
// TenantHelper.dynamic(tenantId, () -> {
|
||||
// if(loginParameter.getTimeout() == -1) {
|
||||
// RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto);
|
||||
// } else {
|
||||
// RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto, Duration.ofSeconds(loginParameter.getTimeout()));
|
||||
// }
|
||||
// });
|
||||
// // 记录登录日志
|
||||
// LogininforEvent logininforEvent = new LogininforEvent();
|
||||
// logininforEvent.setTenantId(tenantId);
|
||||
// logininforEvent.setUsername(username);
|
||||
// logininforEvent.setStatus(Constants.LOGIN_SUCCESS);
|
||||
// logininforEvent.setMessage(MessageUtils.message("user.login.success"));
|
||||
// logininforEvent.setRequest(ServletUtils.getRequest());
|
||||
// SpringUtils.context().publishEvent(logininforEvent);
|
||||
// // 更新登录信息
|
||||
// loginService.recordLoginInfo((Long) loginParameter.getExtra(LoginHelper.USER_KEY), ip);
|
||||
// log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 每次注销时触发
|
||||
// */
|
||||
// @Override
|
||||
// public void doLogout(String loginType, Object loginId, String tokenValue) {
|
||||
// String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
|
||||
// TenantHelper.dynamic(tenantId, () -> {
|
||||
// RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
// });
|
||||
// log.info("user doLogout, userId:{}, token:{}", loginId, tokenValue);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 每次被踢下线时触发
|
||||
// */
|
||||
// @Override
|
||||
// public void doKickout(String loginType, Object loginId, String tokenValue) {
|
||||
// String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
|
||||
// TenantHelper.dynamic(tenantId, () -> {
|
||||
// RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
// });
|
||||
// log.info("user doKickout, userId:{}, token:{}", loginId, tokenValue);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 每次被顶下线时触发
|
||||
// */
|
||||
// @Override
|
||||
// public void doReplaced(String loginType, Object loginId, String tokenValue) {
|
||||
// String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
|
||||
// TenantHelper.dynamic(tenantId, () -> {
|
||||
// RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
// });
|
||||
// log.info("user doReplaced, userId:{}, token:{}", loginId, tokenValue);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 每次被封禁时触发
|
||||
// */
|
||||
// @Override
|
||||
// public void doDisable(String loginType, Object loginId, String service, int level, long disableTime) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 每次被解封时触发
|
||||
// */
|
||||
// @Override
|
||||
// public void doUntieDisable(String loginType, Object loginId, String service) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 每次打开二级认证时触发
|
||||
// */
|
||||
// @Override
|
||||
// public void doOpenSafe(String loginType, String tokenValue, String service, long safeTime) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 每次创建Session时触发
|
||||
// */
|
||||
// @Override
|
||||
// public void doCloseSafe(String loginType, String tokenValue, String service) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 每次创建Session时触发
|
||||
// */
|
||||
// @Override
|
||||
// public void doCreateSession(String id) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 每次注销Session时触发
|
||||
// */
|
||||
// @Override
|
||||
// public void doLogoutSession(String id) {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 每次Token续期时触发
|
||||
// */
|
||||
// @Override
|
||||
// public void doRenewTimeout(String tokenValue, Object loginId, long timeout) {
|
||||
// }
|
||||
//}
|
||||
package com.fuyuanshen.web.listener;
|
||||
|
||||
import cn.dev33.satoken.listener.SaTokenListener;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.fuyuanshen.common.core.constant.CacheConstants;
|
||||
import com.fuyuanshen.common.core.constant.Constants;
|
||||
import com.fuyuanshen.common.core.domain.dto.UserOnlineDTO;
|
||||
import com.fuyuanshen.common.core.utils.MessageUtils;
|
||||
import com.fuyuanshen.common.core.utils.ServletUtils;
|
||||
import com.fuyuanshen.common.core.utils.SpringUtils;
|
||||
import com.fuyuanshen.common.core.utils.ip.AddressUtils;
|
||||
import com.fuyuanshen.common.log.event.LogininforEvent;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.common.tenant.helper.TenantHelper;
|
||||
import com.fuyuanshen.web.service.SysLoginService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* 用户行为 侦听器的实现
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Component
|
||||
@Slf4j
|
||||
public class UserActionListener implements SaTokenListener {
|
||||
|
||||
private final SysLoginService loginService;
|
||||
|
||||
/**
|
||||
* 每次登录时触发
|
||||
*/
|
||||
@Override
|
||||
public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginParameter loginParameter) {
|
||||
UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
|
||||
String ip = ServletUtils.getClientIP();
|
||||
UserOnlineDTO dto = new UserOnlineDTO();
|
||||
dto.setIpaddr(ip);
|
||||
dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
|
||||
dto.setBrowser(userAgent.getBrowser().getName());
|
||||
dto.setOs(userAgent.getOs().getName());
|
||||
dto.setLoginTime(System.currentTimeMillis());
|
||||
dto.setTokenId(tokenValue);
|
||||
String username = (String) loginParameter.getExtra(LoginHelper.USER_NAME_KEY);
|
||||
String tenantId = (String) loginParameter.getExtra(LoginHelper.TENANT_KEY);
|
||||
dto.setUserName(username);
|
||||
dto.setClientKey((String) loginParameter.getExtra(LoginHelper.CLIENT_KEY));
|
||||
dto.setDeviceType(loginParameter.getDeviceType());
|
||||
dto.setDeptName((String) loginParameter.getExtra(LoginHelper.DEPT_NAME_KEY));
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
if(loginParameter.getTimeout() == -1) {
|
||||
RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto);
|
||||
} else {
|
||||
RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto, Duration.ofSeconds(loginParameter.getTimeout()));
|
||||
}
|
||||
});
|
||||
// 记录登录日志
|
||||
LogininforEvent logininforEvent = new LogininforEvent();
|
||||
logininforEvent.setTenantId(tenantId);
|
||||
logininforEvent.setUsername(username);
|
||||
logininforEvent.setStatus(Constants.LOGIN_SUCCESS);
|
||||
logininforEvent.setMessage(MessageUtils.message("user.login.success"));
|
||||
logininforEvent.setRequest(ServletUtils.getRequest());
|
||||
SpringUtils.context().publishEvent(logininforEvent);
|
||||
// 更新登录信息
|
||||
loginService.recordLoginInfo((Long) loginParameter.getExtra(LoginHelper.USER_KEY), ip);
|
||||
log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次注销时触发
|
||||
*/
|
||||
@Override
|
||||
public void doLogout(String loginType, Object loginId, String tokenValue) {
|
||||
String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
});
|
||||
log.info("user doLogout, userId:{}, token:{}", loginId, tokenValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次被踢下线时触发
|
||||
*/
|
||||
@Override
|
||||
public void doKickout(String loginType, Object loginId, String tokenValue) {
|
||||
String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
});
|
||||
log.info("user doKickout, userId:{}, token:{}", loginId, tokenValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次被顶下线时触发
|
||||
*/
|
||||
@Override
|
||||
public void doReplaced(String loginType, Object loginId, String tokenValue) {
|
||||
String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
});
|
||||
log.info("user doReplaced, userId:{}, token:{}", loginId, tokenValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次被封禁时触发
|
||||
*/
|
||||
@Override
|
||||
public void doDisable(String loginType, Object loginId, String service, int level, long disableTime) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次被解封时触发
|
||||
*/
|
||||
@Override
|
||||
public void doUntieDisable(String loginType, Object loginId, String service) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次打开二级认证时触发
|
||||
*/
|
||||
@Override
|
||||
public void doOpenSafe(String loginType, String tokenValue, String service, long safeTime) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次创建Session时触发
|
||||
*/
|
||||
@Override
|
||||
public void doCloseSafe(String loginType, String tokenValue, String service) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次创建Session时触发
|
||||
*/
|
||||
@Override
|
||||
public void doCreateSession(String id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次注销Session时触发
|
||||
*/
|
||||
@Override
|
||||
public void doLogoutSession(String id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次Token续期时触发
|
||||
*/
|
||||
@Override
|
||||
public void doRenewTimeout(String tokenValue, Object loginId, long timeout) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ import com.fuyuanshen.app.mapper.AppUserMapper;
|
||||
import com.fuyuanshen.common.core.constant.Constants;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.domain.model.AppSmsRegisterBody;
|
||||
import com.fuyuanshen.common.core.enums.UserType;
|
||||
import com.fuyuanshen.common.core.exception.BadRequestException;
|
||||
import com.fuyuanshen.common.core.exception.user.CaptchaException;
|
||||
import com.fuyuanshen.common.core.exception.user.CaptchaExpireException;
|
||||
@ -48,7 +47,6 @@ public class AppRegisterService {
|
||||
String phoneNumber = registerBody.getPhoneNumber();
|
||||
LambdaQueryWrapper<AppUser> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AppUser::getPhonenumber, phoneNumber);
|
||||
wrapper.eq(AppUser::getUserType, UserType.APP_USER.getUserType());
|
||||
AppUserVo appUserVo = appUserMapper.selectVoOne(wrapper);
|
||||
if (appUserVo != null) {
|
||||
throw new BadRequestException("该手机号已被注册");
|
||||
@ -69,7 +67,7 @@ public class AppRegisterService {
|
||||
appUser.setNickName(username);
|
||||
appUser.setPhonenumber(phoneNumber);
|
||||
appUser.setPassword(password);
|
||||
appUser.setUserType(UserType.APP_USER.getUserType());
|
||||
appUser.setUserType("app_user");
|
||||
appUser.setTenantId(tenantId);
|
||||
appUser.setLoginIp(ServletUtils.getClientIP());
|
||||
appUser.setStatus("0");
|
||||
@ -79,8 +77,7 @@ public class AppRegisterService {
|
||||
|
||||
boolean exist = TenantHelper.dynamic(tenantId, () -> {
|
||||
return appUserMapper.exists(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getUserName, appUser.getUserName())
|
||||
.eq(AppUser::getUserType, UserType.APP_USER.getUserType()));
|
||||
.eq(AppUser::getUserName, appUser.getUserName()));
|
||||
});
|
||||
if (exist) {
|
||||
throw new UserException("user.register.save.error", username);
|
||||
|
||||
@ -1,235 +0,0 @@
|
||||
package com.fuyuanshen.web.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.app.domain.AppDeviceShare;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceShareBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceShareDetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceShareMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
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.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DeviceShareService {
|
||||
|
||||
private final AppDeviceShareMapper appDeviceShareMapper;
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
|
||||
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
|
||||
|
||||
public TableDataInfo<AppDeviceShareVo> queryPageList(AppDeviceShareBo bo, PageQuery pageQuery) {
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
bo.setCreateBy(userId);
|
||||
Page<AppDeviceShareVo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
|
||||
Page<AppDeviceShareVo> result = appDeviceShareMapper.selectAppDeviceShareList(bo, page);
|
||||
List<AppDeviceShareVo> records = result.getRecords();
|
||||
records.forEach(DeviceShareService::buildDeviceStatus);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
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)){
|
||||
|
||||
item.setOnlineStatus(1);
|
||||
}else{
|
||||
item.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
item.setBattery(jsonObject.getString("batteryPercentage"));
|
||||
}else{
|
||||
item.setBattery("0");
|
||||
}
|
||||
|
||||
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)){
|
||||
item.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
}
|
||||
|
||||
public AppDeviceShareDetailVo getInfo(Long id) {
|
||||
|
||||
LambdaQueryWrapper<AppDeviceShare> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AppDeviceShare::getId, id);
|
||||
List<AppDeviceShareVo> appDeviceShareVos = appDeviceShareMapper.selectVoList(queryWrapper);
|
||||
if(appDeviceShareVos==null || appDeviceShareVos.isEmpty()){
|
||||
return null;
|
||||
}
|
||||
|
||||
AppDeviceShareVo shareVo = appDeviceShareVos.get(0);
|
||||
AppDeviceShareDetailVo shareDetailVo = new AppDeviceShareDetailVo();
|
||||
shareDetailVo.setId(shareVo.getId());
|
||||
shareDetailVo.setDeviceId(shareVo.getDeviceId());
|
||||
shareDetailVo.setPhonenumber(shareVo.getPhonenumber());
|
||||
shareDetailVo.setPermission(shareVo.getPermission());
|
||||
|
||||
Device device = deviceMapper.selectById(shareVo.getDeviceId());
|
||||
shareDetailVo.setDeviceName(device.getDeviceName());
|
||||
shareDetailVo.setDeviceImei(device.getDeviceImei());
|
||||
shareDetailVo.setDeviceMac(device.getDeviceMac());
|
||||
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
if(deviceType!=null){
|
||||
shareDetailVo.setCommunicationMode(Integer.valueOf(deviceType.getCommunicationMode()));
|
||||
}
|
||||
shareDetailVo.setDevicePic(device.getDevicePic());
|
||||
shareDetailVo.setTypeName(deviceType.getTypeName());
|
||||
shareDetailVo.setBluetoothName(device.getBluetoothName());
|
||||
shareDetailVo.setDeviceStatus(device.getDeviceStatus());
|
||||
shareDetailVo.setSendMsg(device.getSendMsg());
|
||||
|
||||
LambdaQueryWrapper<AppPersonnelInfo> qw = new LambdaQueryWrapper<>();
|
||||
qw.eq(AppPersonnelInfo::getDeviceId, device.getId());
|
||||
List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw);
|
||||
if(appPersonnelInfoVos!=null && !appPersonnelInfoVos.isEmpty()){
|
||||
shareDetailVo.setPersonnelInfo(appPersonnelInfoVos.get(0));
|
||||
}
|
||||
//设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei()+ DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(onlineStatus)){
|
||||
shareDetailVo.setOnlineStatus(1);
|
||||
}else{
|
||||
shareDetailVo.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);
|
||||
shareDetailVo.setMainLightMode(jsonObject.getString("mainLightMode"));
|
||||
shareDetailVo.setLaserLightMode(jsonObject.getString("laserLightMode"));
|
||||
shareDetailVo.setBatteryPercentage(jsonObject.getString("batteryPercentage"));
|
||||
shareDetailVo.setChargeState(jsonObject.getString("chargeState"));
|
||||
shareDetailVo.setBatteryRemainingTime(jsonObject.getString("batteryRemainingTime"));
|
||||
}else{
|
||||
shareDetailVo.setBatteryPercentage("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);
|
||||
shareDetailVo.setLongitude(jsonObject.get("longitude").toString());
|
||||
shareDetailVo.setLatitude(jsonObject.get("latitude").toString());
|
||||
shareDetailVo.setAddress((String)jsonObject.get("address"));
|
||||
}
|
||||
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ device.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(alarmStatus)){
|
||||
shareDetailVo.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
|
||||
String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ device.getDeviceImei()+ DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(lightBrightness)){
|
||||
shareDetailVo.setLightBrightness(lightBrightness);
|
||||
}
|
||||
|
||||
return shareDetailVo;
|
||||
}
|
||||
/**
|
||||
* 校验短信验证码
|
||||
*/
|
||||
private boolean validateSmsCode(String tenantId, String phonenumber, String smsCode) {
|
||||
String code = RedisUtils.getCacheObject(GlobalConstants.DEVICE_SHARE_CODES_KEY + phonenumber);
|
||||
if (StringUtils.isBlank(code)) {
|
||||
throw new ServiceException("验证码失效");
|
||||
}
|
||||
return code.equals(smsCode);
|
||||
}
|
||||
public int deviceShare(AppDeviceShareBo bo) {
|
||||
boolean flag = validateSmsCode(AppLoginHelper.getTenantId(), bo.getPhonenumber(), bo.getSmsCode());
|
||||
if(!flag){
|
||||
throw new ServiceException("验证码错误");
|
||||
}
|
||||
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
if(device==null){
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
LambdaQueryWrapper<AppDeviceShare> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(AppDeviceShare::getDeviceId, bo.getDeviceId());
|
||||
lqw.eq(AppDeviceShare::getPhonenumber, bo.getPhonenumber());
|
||||
Long count = appDeviceShareMapper.selectCount(lqw);
|
||||
if(count>0){
|
||||
|
||||
UpdateWrapper<AppDeviceShare> uw = new UpdateWrapper<>();
|
||||
uw.eq("device_id", bo.getDeviceId());
|
||||
uw.eq("phonenumber", bo.getPhonenumber());
|
||||
uw.set("permission", bo.getPermission());
|
||||
uw.set("update_by", userId);
|
||||
uw.set("update_time", new Date());
|
||||
|
||||
return appDeviceShareMapper.update(uw);
|
||||
}else {
|
||||
AppDeviceShare appDeviceShare = new AppDeviceShare();
|
||||
appDeviceShare.setDeviceId(bo.getDeviceId());
|
||||
appDeviceShare.setPhonenumber(bo.getPhonenumber());
|
||||
appDeviceShare.setPermission(bo.getPermission());
|
||||
appDeviceShare.setCreateBy(userId);
|
||||
return appDeviceShareMapper.insert(appDeviceShare);
|
||||
}
|
||||
}
|
||||
|
||||
public int remove(Long[] ids) {
|
||||
return appDeviceShareMapper.deleteByIds(Arrays.asList(ids));
|
||||
}
|
||||
|
||||
public TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery) {
|
||||
String username = AppLoginHelper.getUsername();
|
||||
bo.setPhonenumber(username);
|
||||
Page<AppDeviceShareVo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
|
||||
IPage<AppDeviceShareVo> result = appDeviceShareMapper.otherDeviceShareList(bo, page);
|
||||
List<AppDeviceShareVo> records = result.getRecords();
|
||||
|
||||
records.forEach(DeviceShareService::buildDeviceStatus);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -2,7 +2,6 @@ package com.fuyuanshen.web.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
@ -11,7 +10,6 @@ import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.WebDeviceVo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@ -31,20 +29,4 @@ public interface WEBDeviceService extends IService<Device> {
|
||||
*/
|
||||
int webUnBindDevice(Long id, Long userId);
|
||||
|
||||
/**
|
||||
* WEB端设备详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
WebDeviceVo getDevice(Long id);
|
||||
|
||||
/**
|
||||
* 设备用户详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
List<AppPersonnelInfoRecords> getDeviceUser(Long id);
|
||||
|
||||
}
|
||||
|
||||
@ -1,543 +0,0 @@
|
||||
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.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.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceBJQBizService {
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
|
||||
private final AppPersonnelInfoRecordsMapper appPersonnelInfoRecordsMapper;
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
private final MqttGateway mqttGateway;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
|
||||
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)
|
||||
.eq("binding_user_id", AppLoginHelper.getUserId())
|
||||
.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("发送指令失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录设备操作日志
|
||||
* @param deviceId 设备ID
|
||||
* @param content 日志内容
|
||||
* @param 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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public AppDeviceDetailVo getInfo(Long id) {
|
||||
Device device = deviceMapper.selectById(id);
|
||||
if (device == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
|
||||
AppDeviceDetailVo vo = new AppDeviceDetailVo();
|
||||
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(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)){
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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(position), intData);
|
||||
buildArr(convertHexToDecimal(name), 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;
|
||||
}
|
||||
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("发送指令失败");
|
||||
}
|
||||
}
|
||||
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()+",设备已断开连接");
|
||||
}
|
||||
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(泛光模式)
|
||||
*/
|
||||
|
||||
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()+",设备已断开连接");
|
||||
}
|
||||
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 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("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
//激光模式设置
|
||||
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("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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)
|
||||
.eq("binding_user_id", AppLoginHelper.getUserId())
|
||||
.set("send_msg", bo.getSendMsg());
|
||||
deviceMapper.update(updateWrapper);
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "发送告警信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
log.info("设备发送告警信息信息失败:{}" ,deviceId);
|
||||
throw new ServiceException("设备发送告警信息信息失败");
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送告警信息指令失败");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private boolean getDeviceStatus(String deviceImei) {
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
return StringUtils.isBlank(deviceOnlineStatusRedisKey);
|
||||
}
|
||||
}
|
||||
@ -1,339 +0,0 @@
|
||||
package com.fuyuanshen.web.service.device;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
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.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.app.domain.AppDeviceBindRecord;
|
||||
import com.fuyuanshen.app.domain.AppDeviceShare;
|
||||
import com.fuyuanshen.app.domain.dto.APPReNameDTO;
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppUserVo;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceShareMapper;
|
||||
import com.fuyuanshen.app.mapper.AppUserMapper;
|
||||
import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.ObjectUtils;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
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.dto.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.dto.InstructionRecordDto;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.InstructionRecordVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.WebDeviceVo;
|
||||
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
||||
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
|
||||
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 lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceBizService {
|
||||
|
||||
private final APPDeviceMapper appDeviceMapper;
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final AppDeviceBindRecordMapper appDeviceBindRecordMapper;
|
||||
private final RealTimeStatusEngine realTimeStatusEngine;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
private final AppDeviceShareMapper appDeviceShareMapper;
|
||||
private final AppUserMapper appUserMapper;;
|
||||
|
||||
|
||||
|
||||
public List<APPDeviceTypeVo> getTypeList() {
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
return appDeviceMapper.getTypeList(userId);
|
||||
}
|
||||
|
||||
public void reName(APPReNameDTO reNameDTO) {
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", reNameDTO.getId())
|
||||
.eq("binding_user_id", AppLoginHelper.getUserId())
|
||||
.set("device_name", reNameDTO.getDeviceName());
|
||||
deviceMapper.update(updateWrapper);
|
||||
}
|
||||
|
||||
|
||||
public TableDataInfo<AppDeviceVo> queryAppDeviceList(DeviceQueryCriteria bo, PageQuery pageQuery) {
|
||||
if (bo.getBindingUserId() == null) {
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
bo.setBindingUserId(userId);
|
||||
}
|
||||
Page<AppDeviceVo> result = deviceMapper.queryAppBindDeviceList(pageQuery.build(), bo);
|
||||
List<AppDeviceVo> records = result.getRecords();
|
||||
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)){
|
||||
|
||||
item.setOnlineStatus(1);
|
||||
}else{
|
||||
item.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
item.setBattery(jsonObject.getString("batteryPercentage"));
|
||||
}else{
|
||||
item.setBattery("0");
|
||||
}
|
||||
|
||||
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)){
|
||||
item.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
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()){
|
||||
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)){
|
||||
|
||||
item.setOnlineStatus(1);
|
||||
}else{
|
||||
item.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
item.setBattery(jsonObject.getString("batteryPercentage"));
|
||||
}else{
|
||||
item.setBattery("0");
|
||||
}
|
||||
|
||||
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)){
|
||||
item.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
public int bindDevice(AppDeviceBo bo) {
|
||||
Integer mode = bo.getCommunicationMode();
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
if (mode == CommunicationModeEnum.FOUR_G.getValue()) {
|
||||
|
||||
String deviceImei = bo.getDeviceImei();
|
||||
QueryWrapper<Device> qw = new QueryWrapper<Device>()
|
||||
.eq("device_imei", deviceImei);
|
||||
List<Device> devices = deviceMapper.selectList(qw);
|
||||
if (devices.isEmpty()) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
Device device = devices.get(0);
|
||||
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
|
||||
throw new RuntimeException("设备已绑定");
|
||||
}
|
||||
|
||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||
AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper);
|
||||
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("update_time", new Date())
|
||||
.set("binding_time", new Date());
|
||||
return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper);
|
||||
} else {
|
||||
AppDeviceBindRecord bindRecord = new AppDeviceBindRecord();
|
||||
bindRecord.setDeviceId(device.getId());
|
||||
bindRecord.setBindingUserId(userId);
|
||||
bindRecord.setBindingTime(new Date());
|
||||
bindRecord.setCreateBy(userId);
|
||||
appDeviceBindRecordMapper.insert(bindRecord);
|
||||
}
|
||||
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
||||
.set("binding_user_id", userId)
|
||||
.set("binding_time", new Date());
|
||||
return deviceMapper.update(null, deviceUpdateWrapper);
|
||||
} else if (mode == CommunicationModeEnum.BLUETOOTH.getValue()) {
|
||||
String deviceMac = bo.getDeviceMac();
|
||||
QueryWrapper<Device> qw = new QueryWrapper<Device>()
|
||||
.eq("device_mac", deviceMac);
|
||||
List<Device> devices = deviceMapper.selectList(qw);
|
||||
if (devices.isEmpty()) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
Device device = devices.get(0);
|
||||
|
||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||
bindRecordQueryWrapper.eq("binding_user_id", userId);
|
||||
AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper);
|
||||
if (appDeviceBindRecord != null) {
|
||||
UpdateWrapper<AppDeviceBindRecord> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("device_id", device.getId())
|
||||
.eq("binding_user_id", userId)
|
||||
.set("binding_user_id", userId)
|
||||
.set("binding_time", new Date());
|
||||
return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper);
|
||||
} else {
|
||||
AppDeviceBindRecord bindRecord = new AppDeviceBindRecord();
|
||||
bindRecord.setDeviceId(device.getId());
|
||||
bindRecord.setBindingUserId(userId);
|
||||
bindRecord.setBindingTime(new Date());
|
||||
bindRecord.setCreateBy(userId);
|
||||
appDeviceBindRecordMapper.insert(bindRecord);
|
||||
}
|
||||
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
||||
.set("binding_user_id", userId)
|
||||
.set("binding_time", new Date());
|
||||
return deviceMapper.update(null, deviceUpdateWrapper);
|
||||
} else {
|
||||
throw new RuntimeException("通讯方式错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int unBindDevice(Long id) {
|
||||
return unBindDevice(id, null, 1);
|
||||
}
|
||||
|
||||
public int unBindDevice(Long id, Long userId, int type) {
|
||||
Device device = deviceMapper.selectById(id);
|
||||
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) {
|
||||
bindRecordQueryWrapper.eq("binding_user_id", userId);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
public String mapReverseGeocoding(DeviceInstructDto params) {
|
||||
// Long deviceId = params.getDeviceId();
|
||||
// Device device = deviceMapper.selectById(deviceId);
|
||||
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());
|
||||
}
|
||||
|
||||
public Map<String, Object> getRealTimeStatus(AppRealTimeStatusDto statusDto) {
|
||||
try {
|
||||
String commandType = statusDto.getTypeName()+"_" + statusDto.getFunctionMode();
|
||||
DeviceStatusRule rule = realTimeStatusEngine.getDeviceStatusRule(commandType);
|
||||
if(rule == null){
|
||||
throw new ServiceException("未匹配到处理命令");
|
||||
}
|
||||
return rule.getStatus(statusDto);
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public AppDeviceVo getDeviceInfo(String deviceMac) {
|
||||
// QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.eq("device_mac", deviceMac);
|
||||
// List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||
return deviceMapper.getDeviceInfo(deviceMac);
|
||||
}
|
||||
|
||||
public TableDataInfo<InstructionRecordVo> getInstructionRecord(InstructionRecordDto bo, PageQuery pageQuery) {
|
||||
Page<InstructionRecordVo> result = deviceLogMapper.getInstructionRecord(pageQuery.build(), bo);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
}
|
||||
@ -1,269 +0,0 @@
|
||||
package com.fuyuanshen.web.service.device;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
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.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.fuyuanshen.common.core.utils.ObjectUtils;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
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.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
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.DEVICE_BOOT_LOGO_KEY_PREFIX;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceXinghanBizService {
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
private final MqttGateway mqttGateway;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
|
||||
/**
|
||||
* 所有档位的描述表
|
||||
* key : 指令类型,如 "ins_DetectGrade"、"ins_LightGrade" ……
|
||||
* value : Map<Integer,String> 值 -> 描述
|
||||
*/
|
||||
private static final Map<String, Map<Integer, String>> GRADE_DESC = Map.of(
|
||||
"ins_DetectGrade", Map.of(1, "低档", 2, "中档", 3, "高档"),
|
||||
"ins_LightGrade", Map.of(1, "强光", 2, "弱光"),
|
||||
"ins_SOSGrade", Map.of(1, "爆闪模式", 2, "红蓝模式"),
|
||||
"ins_ShakeBit", Map.of(0, "未静止报警", 1, "正在静止报警")
|
||||
// 再加 4、5、6…… 档,直接往 Map 里塞即可
|
||||
);
|
||||
|
||||
/**
|
||||
* 根据指令类型和值,返回中文描述
|
||||
*/
|
||||
private static String resolveGradeDesc(String type, int value) {
|
||||
return GRADE_DESC.getOrDefault(type, Map.of())
|
||||
.getOrDefault(value, "关闭");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置静电预警档位
|
||||
*/
|
||||
public void upDetectGradeSettings(DeviceInstructDto dto) {
|
||||
sendCommand(dto, "ins_DetectGrade","静电预警档位");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置照明档位
|
||||
*/
|
||||
public void upLightGradeSettings(DeviceInstructDto dto) {
|
||||
sendCommand(dto, "ins_LightGrade","照明档位");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置SOS档位
|
||||
*/
|
||||
public void upSOSGradeSettings(DeviceInstructDto dto) {
|
||||
sendCommand(dto, "ins_SOSGrade","SOS档位");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置强制报警
|
||||
*/
|
||||
public void upShakeBitSettings(DeviceInstructDto dto) {
|
||||
sendCommand(dto, "ins_ShakeBit","强制报警");
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传设备logo
|
||||
*/
|
||||
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if (isDeviceOffline(device.getDeviceImei())) {
|
||||
throw new ServiceException("设备已断开连接:" + device.getDeviceName());
|
||||
}
|
||||
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));
|
||||
|
||||
Map<String, Object> payload = Map.of("ins_PicTrans",
|
||||
Collections.singletonList(0));
|
||||
String topic = MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei();
|
||||
String json = JsonUtils.toJsonString(payload);
|
||||
|
||||
try {
|
||||
mqttGateway.sendMsgToMqtt(topic, 1, json);
|
||||
} catch (Exception e) {
|
||||
log.error("上传开机画面失败, topic={}, payload={}", topic, json, e);
|
||||
throw new ServiceException("上传LOGO失败:" + e.getMessage());
|
||||
}
|
||||
log.info("发送上传开机画面到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),json);
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e){
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 人员登记
|
||||
* @param bo
|
||||
*/
|
||||
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
||||
Long deviceId = bo.getDeviceId();
|
||||
Device deviceObj = deviceMapper.selectById(deviceId);
|
||||
if (deviceObj == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
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.getCode());
|
||||
RedisUtils.setCacheList(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + deviceObj.getDeviceImei() + ":app_send_message_data", list);
|
||||
|
||||
Map<String, Object> payload = Map.of("ins_TexTrans",
|
||||
Collections.singletonList(0));
|
||||
String topic = MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei();
|
||||
String json = JsonUtils.toJsonString(payload);
|
||||
|
||||
try {
|
||||
mqttGateway.sendMsgToMqtt(topic, 1, json);
|
||||
} catch (Exception e) {
|
||||
log.error("人员信息登记失败, topic={}, payload={}", topic, json, e);
|
||||
throw new ServiceException("人员信息登记失败:" + e.getMessage());
|
||||
}
|
||||
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);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------- 私有通用方法 ---------------------------------- */
|
||||
|
||||
private void sendCommand(DeviceInstructDto dto,
|
||||
String payloadKey,String deviceAction) {
|
||||
long deviceId = dto.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if (isDeviceOffline(device.getDeviceImei())) {
|
||||
throw new ServiceException("设备已断开连接:" + device.getDeviceName());
|
||||
}
|
||||
|
||||
Integer value = Integer.parseInt(dto.getInstructValue());
|
||||
|
||||
Map<String, Object> payload = Map.of(payloadKey,
|
||||
Collections.singletonList(value));
|
||||
|
||||
String topic = MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei();
|
||||
String json = JsonUtils.toJsonString(payload);
|
||||
|
||||
try {
|
||||
mqttGateway.sendMsgToMqtt(topic, 1, json);
|
||||
} catch (Exception e) {
|
||||
log.error("发送指令失败, topic={}, payload={}", topic, json, e);
|
||||
throw new ServiceException("发送指令失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
log.info("发送指令成功 => topic:{}, payload:{}", topic, json);
|
||||
String content = resolveGradeDesc("ins_DetectGrade", value);
|
||||
recordDeviceLog(device.getId(),
|
||||
device.getDeviceName(),
|
||||
deviceAction,
|
||||
content,
|
||||
AppLoginHelper.getUserId());
|
||||
}
|
||||
|
||||
private boolean isDeviceOffline(String imei) {
|
||||
// 原方法名语义相反,这里取反,使含义更清晰
|
||||
return getDeviceStatus(imei);
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录设备操作日志
|
||||
* @param deviceId 设备ID
|
||||
* @param content 日志内容
|
||||
* @param 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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getDeviceStatus(String deviceImei) {
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
return StringUtils.isBlank(deviceOnlineStatusRedisKey);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,75 +0,0 @@
|
||||
package com.fuyuanshen.web.service.device.status;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import com.fuyuanshen.web.service.device.status.base.DeviceStatusRule;
|
||||
import com.fuyuanshen.web.service.device.status.constants.DeviceTypeConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class FunctionAccessBatchStatusRule implements DeviceStatusRule {
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return DeviceTypeConstants.TYPE_BJQ6170+"_2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(String deviceType) {
|
||||
return true; // 适用于所有设备类型
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getStatus(AppRealTimeStatusDto dto) {
|
||||
Map<String, Object> status = new HashMap<>();
|
||||
String functionAccess = RedisUtils.getCacheObject(
|
||||
FUNCTION_ACCESS_KEY + dto.getBatchId());
|
||||
log.info("FunctionAccessBatchStatusRule:{}",functionAccess);
|
||||
if(StringUtils.isBlank(functionAccess)){
|
||||
status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
return status;
|
||||
}
|
||||
List<String> cachedDeviceImeiList = JSONUtil.toList(functionAccess, String.class);
|
||||
if(cachedDeviceImeiList.isEmpty()){
|
||||
status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
return status;
|
||||
}
|
||||
for (String key : cachedDeviceImeiList) {
|
||||
String item = RedisUtils.getCacheObject(FUNCTION_ACCESS_KEY + key);
|
||||
if("ACTIVE".equals(item)){
|
||||
status.put("functionAccess", FunctionAccessStatus.ACTIVE.getCode());
|
||||
break;
|
||||
}else {
|
||||
status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
}
|
||||
// if (StringUtils.isBlank(item)) {
|
||||
// String timeOut = RedisUtils.getCacheObject(FUNCTION_ACCESS_TIMEOUT_KEY + dto.getDeviceImei());
|
||||
// if ("TIMEOUT".equals(timeOut)) {
|
||||
// status.put("functionAccess", FunctionAccessStatus.TIMEOUT.getCode());
|
||||
// break;
|
||||
// } else {
|
||||
// status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
// }
|
||||
// } else {
|
||||
// if (!FunctionAccessStatus.OK.getCode().equals(item)) {
|
||||
// status.put("functionAccess", FunctionAccessStatus.FAILED.getCode());
|
||||
// break;
|
||||
// } else {
|
||||
// status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
package com.fuyuanshen.web.service.device.status;
|
||||
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import com.fuyuanshen.web.service.device.status.base.DeviceStatusRule;
|
||||
import com.fuyuanshen.web.service.device.status.constants.DeviceTypeConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_TIMEOUT_KEY;
|
||||
|
||||
// 上传开机图片
|
||||
@Slf4j
|
||||
@Component
|
||||
public class FunctionAccessStatusRule implements DeviceStatusRule {
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return DeviceTypeConstants.TYPE_BJQ6170+"_1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(String deviceType) {
|
||||
return true; // 适用于所有设备类型
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getStatus(AppRealTimeStatusDto dto) {
|
||||
Map<String, Object> status = new HashMap<>();
|
||||
String functionAccess = RedisUtils.getCacheObject(
|
||||
FUNCTION_ACCESS_KEY + dto.getDeviceImei());
|
||||
log.info("FunctionAccessStatusRule:{}",functionAccess);
|
||||
if(StringUtils.isBlank(functionAccess)){
|
||||
String timeOut = RedisUtils.getCacheObject(FUNCTION_ACCESS_TIMEOUT_KEY + dto.getDeviceImei());
|
||||
if("TIMEOUT".equals(timeOut)){
|
||||
status.put("functionAccess", FunctionAccessStatus.TIMEOUT.getCode());
|
||||
RedisUtils.deleteObject(FUNCTION_ACCESS_TIMEOUT_KEY + dto.getDeviceImei());
|
||||
}else{
|
||||
status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
}
|
||||
}else{
|
||||
status.put("functionAccess", functionAccess);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package com.fuyuanshen.web.service.device.status.base;
|
||||
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
// 规则接口
|
||||
public interface DeviceStatusRule {
|
||||
|
||||
/**
|
||||
* 获取命令类型
|
||||
* @return 命令类型
|
||||
*/
|
||||
String getCommandType();
|
||||
|
||||
boolean supports(String deviceType);
|
||||
|
||||
Map<String, Object> getStatus(AppRealTimeStatusDto statusDto);
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
package com.fuyuanshen.web.service.device.status.base;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Component
|
||||
public class RealTimeStatusEngine {
|
||||
|
||||
|
||||
private final LinkedHashMap<String, DeviceStatusRule> rulesMap = new LinkedHashMap<>();
|
||||
public RealTimeStatusEngine(List<DeviceStatusRule> rules) {
|
||||
rules.forEach(rule -> rulesMap.put(rule.getCommandType(), rule)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public DeviceStatusRule getDeviceStatusRule(String commandType) {
|
||||
return rulesMap.get(commandType);
|
||||
}
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
package com.fuyuanshen.web.service.device.status.constants;
|
||||
|
||||
public class DeviceTypeConstants {
|
||||
public static final String TYPE_BJQ6170 = "BJQ6170";
|
||||
|
||||
}
|
||||
@ -1,30 +1,15 @@
|
||||
package com.fuyuanshen.web.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuyuanshen.app.domain.AppDeviceBindRecord;
|
||||
import com.fuyuanshen.app.domain.AppDeviceShare;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceShareMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoRecordsMapper;
|
||||
import com.fuyuanshen.app.service.AppDeviceBizService;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceAssignments;
|
||||
import com.fuyuanshen.equipment.domain.vo.WebDeviceVo;
|
||||
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.web.service.WEBDeviceService;
|
||||
import com.fuyuanshen.web.service.device.DeviceBizService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -36,14 +21,10 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class WEBDeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements WEBDeviceService {
|
||||
|
||||
private final AppDeviceBizService appDeviceService;
|
||||
|
||||
private final DeviceAssignmentsMapper deviceAssignmentsMapper;
|
||||
|
||||
private final AppDeviceBindRecordMapper appDeviceBindRecordMapper;
|
||||
private final AppPersonnelInfoRecordsMapper infoRecordsMapper;
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final AppDeviceShareMapper appDeviceShareMapper;
|
||||
|
||||
|
||||
/**
|
||||
* WEB端解绑设备
|
||||
@ -52,7 +33,6 @@ public class WEBDeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impl
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int webUnBindDevice(Long id, Long userId) {
|
||||
// 设备端解绑 0:设备端解绑 1:web端解绑
|
||||
int type = 1;
|
||||
@ -64,54 +44,7 @@ public class WEBDeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impl
|
||||
id = deviceAssignments.getDeviceId();
|
||||
type = 0;
|
||||
}
|
||||
|
||||
QueryWrapper<AppDeviceBindRecord> deviceId = new QueryWrapper<AppDeviceBindRecord>().eq("device_id", id);
|
||||
|
||||
// appDeviceService.unBindDevice(id, userId, type);
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", id)
|
||||
.set("binding_user_id", null)
|
||||
.set("binding_status", BindingStatusEnum.UNBOUND.getCode())
|
||||
.set("binding_time", null);
|
||||
deviceMapper.update(null, deviceUpdateWrapper);
|
||||
|
||||
return appDeviceBindRecordMapper.delete(deviceId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* WEB端设备详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public WebDeviceVo getDevice(Long id) {
|
||||
Device device = deviceMapper.selectById(id);
|
||||
if (device != null) {
|
||||
WebDeviceVo webDeviceVo = new WebDeviceVo();
|
||||
BeanUtil.copyProperties(device, webDeviceVo);
|
||||
// 查询分享用户数
|
||||
Long count = appDeviceShareMapper.selectCount(new QueryWrapper<AppDeviceShare>().eq("device_id", id));
|
||||
webDeviceVo.setShareUsersNumber(Math.toIntExact(count));
|
||||
return webDeviceVo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设备用户详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<AppPersonnelInfoRecords> getDeviceUser(Long id) {
|
||||
List<AppPersonnelInfoRecords> appPersonnelInfoRecords = infoRecordsMapper.selectList(
|
||||
new QueryWrapper<AppPersonnelInfoRecords>().eq("device_id", id)
|
||||
.orderByDesc("create_time"));
|
||||
return appPersonnelInfoRecords;
|
||||
return appDeviceService.unBindDevice(id, userId, type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
--- # 临时文件存储位置 避免临时文件被系统清理报错
|
||||
spring.servlet.multipart.location: /fys/server/temp
|
||||
|
||||
--- # 监控中心配置
|
||||
spring.boot.admin.client:
|
||||
# 增加客户端开关
|
||||
@ -19,7 +16,7 @@ snail-job:
|
||||
enabled: false
|
||||
# 需要在 SnailJob 后台组管理创建对应名称的组,然后创建任务的时候选择对应的组,才能正确分派任务
|
||||
group: "fys_group"
|
||||
# SnailJob 接入验证令牌 详见 script/sql/ry_job.sql `sj_group_config`表
|
||||
# SnailJob 接入验证令牌 详见 script/sql/ry_job.sql `sj_group_config` 表
|
||||
token: "SJ_cKqBTPzCsWA3VyuCfFoccmuIEGXjr5KT"
|
||||
server:
|
||||
host: 127.0.0.1
|
||||
@ -40,7 +37,7 @@ spring:
|
||||
# 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content
|
||||
dynamic:
|
||||
# 性能分析插件(有性能损耗 不建议生产环境使用)
|
||||
p6spy: false
|
||||
p6spy: true
|
||||
# 设置默认的数据源或者数据源组,默认值即为 master
|
||||
primary: master
|
||||
# 严格模式 匹配不到数据源则报错
|
||||
@ -52,35 +49,35 @@ spring:
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
|
||||
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
|
||||
url: jdbc:mysql://47.107.152.87:3306/fys-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
url: jdbc:mysql://120.79.224.186:3366/fys-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
username: root
|
||||
password: Jz_5623_cl1
|
||||
# # 从库数据源
|
||||
# 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
|
||||
password: 1fys@QWER..
|
||||
# # 从库数据源
|
||||
# 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
|
||||
@ -101,13 +98,13 @@ spring:
|
||||
spring.data:
|
||||
redis:
|
||||
# 地址
|
||||
host: 47.107.152.87
|
||||
host: 120.79.224.186
|
||||
# 端口,默认为6379
|
||||
port: 6379
|
||||
port: 26379
|
||||
# 数据库索引
|
||||
database: 1
|
||||
database: 2
|
||||
# redis 密码必须配置
|
||||
password: re_fs_11520631
|
||||
password: 1fys@QWER..
|
||||
# 连接超时时间
|
||||
timeout: 10s
|
||||
# 是否开启ssl
|
||||
@ -118,17 +115,17 @@ redisson:
|
||||
# redis key前缀
|
||||
keyPrefix:
|
||||
# 线程池数量
|
||||
threads: 16
|
||||
threads: 4
|
||||
# Netty线程池数量
|
||||
nettyThreads: 32
|
||||
nettyThreads: 8
|
||||
# 单节点配置
|
||||
singleServerConfig:
|
||||
# 客户端名称 不能用中文
|
||||
clientName: fys-Vue-Plus
|
||||
# 最小空闲连接数
|
||||
connectionMinimumIdleSize: 32
|
||||
connectionMinimumIdleSize: 8
|
||||
# 连接池大小
|
||||
connectionPoolSize: 64
|
||||
connectionPoolSize: 32
|
||||
# 连接空闲超时,单位:毫秒
|
||||
idleConnectionTimeout: 10000
|
||||
# 命令等待超时,单位:毫秒
|
||||
@ -177,14 +174,15 @@ sms:
|
||||
# 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||
supplier: alibaba
|
||||
# 有些称为accessKey有些称之为apiKey,也有称为sdkKey或者appId。
|
||||
access-key-id: LTAI5tDGfJd4kMvrGtvyzCHz
|
||||
access-key-id: LTAI5tJdDNpZootsPQ5hdELx
|
||||
# 称为accessSecret有些称之为apiSecret
|
||||
access-key-secret: a4ZlVHVSYeMQHn0p1R18thA6xCdHQh
|
||||
#模板ID 非必须配置,如果使用sendMessage的快速发送需此配置
|
||||
template-id: SMS_324526343
|
||||
#模板变量 上述模板的变量
|
||||
access-key-secret: mU4WtffcCXpHPz5tLwQpaGtLsJXONt
|
||||
#模板ID 非必须配置,如果使用sendMessage的快速发送需此配置
|
||||
template-id: SMS_322180518
|
||||
#模板变量 上述模板的变量
|
||||
templateName: code
|
||||
signature: 深圳市富源晟科技
|
||||
signature: 湖北星汉研创科技
|
||||
# sdk-app-id: 您的sdkAppId
|
||||
config2:
|
||||
# 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||
supplier: tencent
|
||||
@ -193,6 +191,7 @@ sms:
|
||||
signature: 您的短信签名
|
||||
sdk-app-id: 您的sdkAppId
|
||||
|
||||
|
||||
--- # 三方授权
|
||||
justauth:
|
||||
# 前端外网访问地址
|
||||
@ -207,11 +206,11 @@ justauth:
|
||||
redirect-uri: ${justauth.address}/social-callback?source=maxkey
|
||||
topiam:
|
||||
# topiam 服务器地址
|
||||
server-url: http://127.0.0.1:1989/api/v1/authorize/y0q************spq***********8ol
|
||||
server-url: http://127.0.0.1:1898/api/v1/authorize/y0q************spq***********8ol
|
||||
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
|
||||
@ -277,18 +276,6 @@ justauth:
|
||||
redirect-uri: ${justauth.address}/social-callback?source=gitea
|
||||
|
||||
|
||||
# MQTT配置
|
||||
mqtt:
|
||||
username: admin
|
||||
password: fys123456
|
||||
url: tcp://47.107.152.87:1883
|
||||
subClientId: fys_subClient
|
||||
subTopic: worker/location/#
|
||||
pubTopic: B/#
|
||||
pubClientId: fys_pubClient
|
||||
enabled: false
|
||||
|
||||
|
||||
# 文件存储路径
|
||||
file:
|
||||
mac:
|
||||
@ -309,4 +296,13 @@ file:
|
||||
app_avatar:
|
||||
pic: C:\eladmin\file\ #设备图片存储路径
|
||||
#ip: http://fuyuanshen.com:81/ #服务器地址
|
||||
ip: https://fuyuanshen.com/ #服务器地址
|
||||
ip: https://fuyuanshen.com/ #服务器地址
|
||||
# MQTT配置
|
||||
mqtt:
|
||||
username: admin
|
||||
password: fys123456
|
||||
url: tcp://47.107.152.87:1883
|
||||
subClientId: fys_subClient
|
||||
subTopic: A/#,worker/location/#
|
||||
pubTopic: B/#
|
||||
pubClientId: fys_pubClient
|
||||
@ -52,7 +52,7 @@ spring:
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
|
||||
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
|
||||
url: jdbc:mysql://47.107.152.87:3306/fys-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
url: jdbc:mysql://localhost: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: Jz_5623_cl1
|
||||
# # 从库数据源
|
||||
@ -101,7 +101,7 @@ spring:
|
||||
spring.data:
|
||||
redis:
|
||||
# 地址
|
||||
host: 47.107.152.87
|
||||
host: localhost
|
||||
# 端口,默认为6379
|
||||
port: 6379
|
||||
# 数据库索引
|
||||
@ -177,14 +177,11 @@ sms:
|
||||
# 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||
supplier: alibaba
|
||||
# 有些称为accessKey有些称之为apiKey,也有称为sdkKey或者appId。
|
||||
access-key-id: LTAI5tDGfJd4kMvrGtvyzCHz
|
||||
access-key-id: 您的accessKey
|
||||
# 称为accessSecret有些称之为apiSecret
|
||||
access-key-secret: a4ZlVHVSYeMQHn0p1R18thA6xCdHQh
|
||||
#模板ID 非必须配置,如果使用sendMessage的快速发送需此配置
|
||||
template-id: SMS_324526343
|
||||
#模板变量 上述模板的变量
|
||||
templateName: code
|
||||
signature: 深圳市富源晟科技
|
||||
access-key-secret: 您的accessKeySecret
|
||||
signature: 您的短信签名
|
||||
sdk-app-id: 您的sdkAppId
|
||||
config2:
|
||||
# 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
|
||||
supplier: tencent
|
||||
@ -280,13 +277,12 @@ justauth:
|
||||
# MQTT配置
|
||||
mqtt:
|
||||
username: admin
|
||||
password: fys123456
|
||||
url: tcp://47.107.152.87:1883
|
||||
password: #YtvpSfCNG
|
||||
url: tcp://47.120.79.150:2883
|
||||
subClientId: fys_subClient
|
||||
subTopic: A/#,worker/location/#
|
||||
pubTopic: B/#
|
||||
subTopic: worker/alert/#,worker/location/#
|
||||
pubTopic: worker/location
|
||||
pubClientId: fys_pubClient
|
||||
enabled: false
|
||||
|
||||
|
||||
# 文件存储路径
|
||||
|
||||
@ -35,8 +35,7 @@ captcha:
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
#com.fuyuanshen: @logging.level@
|
||||
com.fuyuanshen: ${logging.level}
|
||||
com.fuyuanshen: @logging.level@
|
||||
org.springframework: warn
|
||||
org.mybatis.spring.mapper: error
|
||||
org.apache.fury: warn
|
||||
@ -64,7 +63,7 @@ spring:
|
||||
# 国际化资源文件路径
|
||||
basename: i18n/messages
|
||||
profiles:
|
||||
active: ${profiles.active}
|
||||
active: @profiles.active@
|
||||
# 文件上传
|
||||
servlet:
|
||||
multipart:
|
||||
@ -219,8 +218,6 @@ springdoc:
|
||||
packages-to-scan: com.fuyuanshen.customer
|
||||
- group: APP模块
|
||||
packages-to-scan: com.fuyuanshen.app
|
||||
- group: 设备分组
|
||||
packages-to-scan: com.fuyuanshen.web.controller.device
|
||||
|
||||
# 防止XSS攻击
|
||||
xss:
|
||||
@ -234,7 +231,7 @@ xss:
|
||||
# 如使用JDK21请直接使用虚拟线程 不要开启此配置
|
||||
thread-pool:
|
||||
# 是否开启线程池
|
||||
enabled: true
|
||||
enabled: false
|
||||
# 队列最大长度
|
||||
queueCapacity: 128
|
||||
# 线程池维护线程所允许的空闲时间
|
||||
@ -257,7 +254,7 @@ management:
|
||||
health:
|
||||
show-details: ALWAYS
|
||||
logfile:
|
||||
external-file: ./logs/sys-admin-console.log
|
||||
external-file: ./logs/sys-console.log
|
||||
|
||||
--- # 默认/推荐使用sse推送
|
||||
sse:
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 263 B |
@ -15,13 +15,13 @@
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="file_console" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/sys-admin-console.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/sys-admin-console.log.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大 1天 -->
|
||||
<maxHistory>1</maxHistory>
|
||||
</rollingPolicy>
|
||||
<file>${log.path}/sys-console.log</file>
|
||||
<!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> -->
|
||||
<!-- <!– 日志文件名格式 –> -->
|
||||
<!-- <fileNamePattern>${log.path}/sys-console.%d{yyyy-MM-dd}.log</fileNamePattern> -->
|
||||
<!-- <!– 日志最大 1天 –> -->
|
||||
<!-- <maxHistory>1</maxHistory> -->
|
||||
<!-- </rollingPolicy> -->
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
<charset>utf-8</charset>
|
||||
|
||||
@ -41,9 +41,4 @@ public interface GlobalConstants {
|
||||
* 三方认证 redis key
|
||||
*/
|
||||
String SOCIAL_AUTH_CODE_KEY = GLOBAL_REDIS_KEY + "social_auth_codes:";
|
||||
|
||||
|
||||
String FUNCTION_ACCESS_KEY = GLOBAL_REDIS_KEY + "device:function_access:";
|
||||
|
||||
String FUNCTION_ACCESS_TIMEOUT_KEY = GLOBAL_REDIS_KEY + "device:function_access_timeout:";
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ public class Bitmap80x12Generator {
|
||||
return byteListToArray(byteList);
|
||||
}
|
||||
|
||||
public static byte[] byteListToArray(List<Byte> byteList) {
|
||||
private static byte[] byteListToArray(List<Byte> byteList) {
|
||||
byte[] result = new byte[byteList.size()];
|
||||
for (int i = 0; i < byteList.size(); i++) {
|
||||
result[i] = byteList.get(i);
|
||||
|
||||
@ -33,7 +33,7 @@ public class ImageToCArrayConverter {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
byte[] largeData = convertImageToCArray("E:\\workspace\\demo.png", 160, 80,25600);
|
||||
byte[] largeData = convertImageToCArray("E:\\workspace\\6170_强光_160_80_2.jpg", 160, 80,25600);
|
||||
System.out.println("长度:"+largeData.length);
|
||||
|
||||
System.out.println("原始数据大小: " + largeData.length + " 字节");
|
||||
@ -88,24 +88,6 @@ public class ImageToCArrayConverter {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public static String[] getChunk2(String[] data, int chunkIndex, int chunkSize) {
|
||||
if (data == null || chunkSize <= 0 || chunkIndex < 0) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
int start = chunkIndex * chunkSize;
|
||||
if (start >= data.length) {
|
||||
return new String[0]; // 索引超出范围
|
||||
}
|
||||
|
||||
int end = Math.min(start + chunkSize, data.length);
|
||||
int length = end - start;
|
||||
|
||||
String[] chunk = new String[length];
|
||||
System.arraycopy(data, start, chunk, 0, length);
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public static void buildArr(int[] data,List<Integer> intData){
|
||||
for (int datum : data) {
|
||||
intData.add(datum);
|
||||
|
||||
@ -1,429 +0,0 @@
|
||||
package com.fuyuanshen.common.core.utils;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ImageWithTextGenerate {
|
||||
|
||||
/**
|
||||
* 生成160*80画布,嵌入背景图片并居中显示文字(支持自动换行),输出RGB565格式数据
|
||||
*
|
||||
* @param text 要显示的文字
|
||||
* @param fixedLength 固定输出长度(字节数)
|
||||
* @return RGB565格式的图像数据
|
||||
*/
|
||||
public static byte[] generate160x80ImageWithText2(String text, InputStream backgroundImageInputStream, int fixedLength) throws IOException {
|
||||
// 创建160*80的图像
|
||||
BufferedImage image = new BufferedImage(160, 80, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = image.createGraphics();
|
||||
|
||||
// 绘制白色背景
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(0, 0, 160, 80);
|
||||
|
||||
// 如果提供了背景图片,则绘制背景
|
||||
if (backgroundImageInputStream != null ) {
|
||||
BufferedImage backgroundImage = ImageIO.read(backgroundImageInputStream);
|
||||
// 缩放并绘制背景图片以适应160*80画布
|
||||
g.drawImage(backgroundImage, 0, 0, 160, 80, null);
|
||||
}
|
||||
|
||||
// 设置文字属性
|
||||
Font font = new Font("宋体", Font.PLAIN, 12); // 可根据需要调整字体大小
|
||||
g.setFont(font);
|
||||
g.setColor(new Color(255, 255, 255, (int)(0.6 * 255)));
|
||||
|
||||
// 关闭抗锯齿以获得清晰的点阵效果
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
g.setRenderingHint(RenderingHints.KEY_RENDERING,
|
||||
RenderingHints.VALUE_RENDER_QUALITY);
|
||||
|
||||
// 获取字体度量信息
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
int lineHeight = metrics.getHeight();
|
||||
|
||||
// 文本换行处理
|
||||
ArrayList<String> lines = wrapText(text, metrics, 120); // 160为画布宽度
|
||||
|
||||
// 计算垂直居中起始位置
|
||||
int totalTextHeight = lines.size() * lineHeight;
|
||||
int startY = (80 - totalTextHeight) / 2 + metrics.getAscent();
|
||||
|
||||
// 绘制每一行文字
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String line = lines.get(i);
|
||||
int lineWidth = metrics.stringWidth(line);
|
||||
int x = (160 - lineWidth) / 2; // 水平居中
|
||||
int y = startY + i * lineHeight;
|
||||
g.drawString(line, x, y);
|
||||
}
|
||||
|
||||
g.dispose();
|
||||
|
||||
// 转换像素数据为RGB565格式(高位在前)
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
for (int yCoord = 0; yCoord < 80; yCoord++) {
|
||||
for (int xCoord = 0; xCoord < 160; xCoord++) {
|
||||
int rgb = image.getRGB(xCoord, yCoord);
|
||||
|
||||
// 提取RGB分量
|
||||
int r = (rgb >> 16) & 0xFF;
|
||||
int g1 = (rgb >> 8) & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
|
||||
// 转换为RGB565(5位红,6位绿,5位蓝)
|
||||
int r5 = (r >> 3) & 0x1F;
|
||||
int g6 = (g1 >> 2) & 0x3F;
|
||||
int b5 = (b >> 3) & 0x1F;
|
||||
|
||||
// 组合为16位值
|
||||
int rgb565 = (r5 << 11) | (g6 << 5) | b5;
|
||||
|
||||
// 高位在前(大端序)写入字节
|
||||
byteStream.write((rgb565 >> 8) & 0xFF); // 高字节
|
||||
byteStream.write(rgb565 & 0xFF); // 低字节
|
||||
}
|
||||
}
|
||||
|
||||
// 调整到固定长度
|
||||
byte[] rawData = byteStream.toByteArray();
|
||||
byte[] result = new byte[fixedLength];
|
||||
int copyLength = Math.min(rawData.length, fixedLength);
|
||||
System.arraycopy(rawData, 0, result, 0, copyLength);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 生成160*80画布,嵌入背景图片并居中显示文字(支持自动换行),输出RGB565格式数据
|
||||
*
|
||||
* @param text 要显示的文字
|
||||
* @param backgroundImagePath 背景图片路径
|
||||
* @param fixedLength 固定输出长度(字节数)
|
||||
* @return RGB565格式的图像数据
|
||||
*/
|
||||
public static byte[] generate160x80ImageWithText(String text, String backgroundImagePath, int fixedLength) throws IOException {
|
||||
// 创建160*80的图像
|
||||
BufferedImage image = new BufferedImage(160, 80, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = image.createGraphics();
|
||||
|
||||
// 绘制白色背景
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(0, 0, 160, 80);
|
||||
|
||||
// 如果提供了背景图片,则绘制背景
|
||||
if (backgroundImagePath != null && !backgroundImagePath.isEmpty()) {
|
||||
File backgroundFile = new File(backgroundImagePath);
|
||||
if (backgroundFile.exists()) {
|
||||
BufferedImage backgroundImage = ImageIO.read(backgroundFile);
|
||||
// 缩放并绘制背景图片以适应160*80画布
|
||||
g.drawImage(backgroundImage, 0, 0, 160, 80, null);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置文字属性
|
||||
Font font = new Font("宋体", Font.PLAIN, 12); // 可根据需要调整字体大小
|
||||
g.setFont(font);
|
||||
g.setColor(new Color(255, 255, 255, (int)(0.6 * 255)));
|
||||
|
||||
// 关闭抗锯齿以获得清晰的点阵效果
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
g.setRenderingHint(RenderingHints.KEY_RENDERING,
|
||||
RenderingHints.VALUE_RENDER_QUALITY);
|
||||
|
||||
// 获取字体度量信息
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
int lineHeight = metrics.getHeight();
|
||||
|
||||
// 文本换行处理
|
||||
ArrayList<String> lines = wrapText(text, metrics, 120); // 160为画布宽度
|
||||
|
||||
// 计算垂直居中起始位置
|
||||
int totalTextHeight = lines.size() * lineHeight;
|
||||
int startY = (80 - totalTextHeight) / 2 + metrics.getAscent();
|
||||
|
||||
// 绘制每一行文字
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String line = lines.get(i);
|
||||
int lineWidth = metrics.stringWidth(line);
|
||||
int x = (160 - lineWidth) / 2; // 水平居中
|
||||
int y = startY + i * lineHeight;
|
||||
g.drawString(line, x, y);
|
||||
}
|
||||
|
||||
g.dispose();
|
||||
|
||||
// 转换像素数据为RGB565格式(高位在前)
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
for (int yCoord = 0; yCoord < 80; yCoord++) {
|
||||
for (int xCoord = 0; xCoord < 160; xCoord++) {
|
||||
int rgb = image.getRGB(xCoord, yCoord);
|
||||
|
||||
// 提取RGB分量
|
||||
int r = (rgb >> 16) & 0xFF;
|
||||
int g1 = (rgb >> 8) & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
|
||||
// 转换为RGB565(5位红,6位绿,5位蓝)
|
||||
int r5 = (r >> 3) & 0x1F;
|
||||
int g6 = (g1 >> 2) & 0x3F;
|
||||
int b5 = (b >> 3) & 0x1F;
|
||||
|
||||
// 组合为16位值
|
||||
int rgb565 = (r5 << 11) | (g6 << 5) | b5;
|
||||
|
||||
// 高位在前(大端序)写入字节
|
||||
byteStream.write((rgb565 >> 8) & 0xFF); // 高字节
|
||||
byteStream.write(rgb565 & 0xFF); // 低字节
|
||||
}
|
||||
}
|
||||
|
||||
// 调整到固定长度
|
||||
byte[] rawData = byteStream.toByteArray();
|
||||
byte[] result = new byte[fixedLength];
|
||||
int copyLength = Math.min(rawData.length, fixedLength);
|
||||
System.arraycopy(rawData, 0, result, 0, copyLength);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文本换行处理
|
||||
*
|
||||
* @param text 原始文本
|
||||
* @param metrics 字体度量信息
|
||||
* @param maxWidth 最大宽度
|
||||
* @return 换行后的文本行列表
|
||||
*/
|
||||
private static ArrayList<String> wrapText(String text, FontMetrics metrics, int maxWidth) {
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
String[] paragraphs = text.split("\n");
|
||||
|
||||
for (String paragraph : paragraphs) {
|
||||
String[] words = paragraph.split("(?<=\\S)(?=\\s)|(?<=\\s)(?=\\S)");
|
||||
StringBuilder line = new StringBuilder();
|
||||
|
||||
for (String word : words) {
|
||||
String testLine = line.toString() + word;
|
||||
int lineWidth = metrics.stringWidth(testLine);
|
||||
|
||||
if (lineWidth <= maxWidth) {
|
||||
line.append(word);
|
||||
} else {
|
||||
if (line.length() > 0) {
|
||||
lines.add(line.toString());
|
||||
line = new StringBuilder(word);
|
||||
} else {
|
||||
// 单个词就超过宽度,需要进一步拆分
|
||||
lines.addAll(wrapWord(word, metrics, maxWidth));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (line.length() > 0) {
|
||||
lines.add(line.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// 限制最大行数以适应80像素高度
|
||||
if (lines.size() > 6) { // 假设每行最多13像素高,80/13约等于6
|
||||
return (ArrayList<String>) lines.subList(0, 6);
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对单个超长词进行拆分
|
||||
*
|
||||
* @param word 单词
|
||||
* @param metrics 字体度量信息
|
||||
* @param maxWidth 最大宽度
|
||||
* @return 拆分后的词列表
|
||||
*/
|
||||
private static ArrayList<String> wrapWord(String word, FontMetrics metrics, int maxWidth) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
StringBuilder current = new StringBuilder();
|
||||
|
||||
for (char c : word.toCharArray()) {
|
||||
String testStr = current.toString() + c;
|
||||
if (metrics.stringWidth(testStr) <= maxWidth) {
|
||||
current.append(c);
|
||||
} else {
|
||||
if (current.length() > 0) {
|
||||
result.add(current.toString());
|
||||
}
|
||||
current = new StringBuilder(String.valueOf(c));
|
||||
}
|
||||
}
|
||||
|
||||
if (current.length() > 0) {
|
||||
result.add(current.toString());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成160*80画布,嵌入背景图片并居中显示文字,输出RGB565格式数据(支持InputStream)
|
||||
*
|
||||
* @param text 要显示的文字
|
||||
* @param backgroundImageInputStream 背景图片输入流
|
||||
* @param fixedLength 固定输出长度(字节数)
|
||||
* @return RGB565格式的图像数据
|
||||
*/
|
||||
public static byte[] generate160x80ImageWithText(String text, InputStream backgroundImageInputStream, int fixedLength) throws IOException {
|
||||
// 创建160*80的图像
|
||||
BufferedImage image = new BufferedImage(160, 80, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = image.createGraphics();
|
||||
|
||||
// 绘制白色背景
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(0, 0, 160, 80);
|
||||
|
||||
// 如果提供了背景图片,则绘制背景
|
||||
if (backgroundImageInputStream != null) {
|
||||
BufferedImage backgroundImage = ImageIO.read(backgroundImageInputStream);
|
||||
// 缩放并绘制背景图片以适应160*80画布
|
||||
g.drawImage(backgroundImage, 0, 0, 160, 80, null);
|
||||
}
|
||||
|
||||
// 设置文字属性
|
||||
Font font = new Font("宋体", Font.PLAIN, 16); // 可根据需要调整字体大小
|
||||
g.setFont(font);
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
// 关闭抗锯齿以获得清晰的点阵效果
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
g.setRenderingHint(RenderingHints.KEY_RENDERING,
|
||||
RenderingHints.VALUE_RENDER_QUALITY);
|
||||
|
||||
// 获取字体度量信息
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
|
||||
// 计算文字的宽度和高度
|
||||
int textWidth = metrics.stringWidth(text);
|
||||
int textHeight = metrics.getHeight();
|
||||
|
||||
// 计算居中位置
|
||||
int x = (160 - textWidth) / 2; // 水平居中
|
||||
int y = (80 - textHeight) / 2 + metrics.getAscent(); // 垂直居中
|
||||
|
||||
// 绘制文字
|
||||
g.drawString(text, x, y);
|
||||
|
||||
g.dispose();
|
||||
|
||||
// 转换像素数据为RGB565格式(高位在前)
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
for (int yCoord = 0; yCoord < 80; yCoord++) {
|
||||
for (int xCoord = 0; xCoord < 160; xCoord++) {
|
||||
int rgb = image.getRGB(xCoord, yCoord);
|
||||
|
||||
// 提取RGB分量
|
||||
int r = (rgb >> 16) & 0xFF;
|
||||
int g1 = (rgb >> 8) & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
|
||||
// 转换为RGB565(5位红,6位绿,5位蓝)
|
||||
int r5 = (r >> 3) & 0x1F;
|
||||
int g6 = (g1 >> 2) & 0x3F;
|
||||
int b5 = (b >> 3) & 0x1F;
|
||||
|
||||
// 组合为16位值
|
||||
int rgb565 = (r5 << 11) | (g6 << 5) | b5;
|
||||
|
||||
// 高位在前(大端序)写入字节
|
||||
byteStream.write((rgb565 >> 8) & 0xFF); // 高字节
|
||||
byteStream.write(rgb565 & 0xFF); // 低字节
|
||||
}
|
||||
}
|
||||
|
||||
// 调整到固定长度
|
||||
byte[] rawData = byteStream.toByteArray();
|
||||
byte[] result = new byte[fixedLength];
|
||||
int copyLength = Math.min(rawData.length, fixedLength);
|
||||
System.arraycopy(rawData, 0, result, 0, copyLength);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 将RGB565格式的字节数组转换为BufferedImage
|
||||
*
|
||||
* @param data RGB565格式的数据
|
||||
* @param height 图像高度
|
||||
* @param width 图像宽度
|
||||
* @return 转换后的BufferedImage
|
||||
*/
|
||||
public static BufferedImage convertByteArrayToImage(byte[] data, int height, int width) {
|
||||
if (data == null || data.length == 0) {
|
||||
return new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
|
||||
}
|
||||
|
||||
// 创建图像
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
// 处理RGB565数据
|
||||
int dataIndex = 0;
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
// 每个像素占2个字节
|
||||
if (dataIndex + 1 >= data.length) {
|
||||
return image;
|
||||
}
|
||||
|
||||
// 读取两个字节组成RGB565值
|
||||
int highByte = data[dataIndex++] & 0xFF;
|
||||
int lowByte = data[dataIndex++] & 0xFF;
|
||||
int rgb565 = (highByte << 8) | lowByte;
|
||||
|
||||
// 将RGB565转换为RGB888
|
||||
int r = ((rgb565 >> 11) & 0x1F) << 3;
|
||||
int g = ((rgb565 >> 5) & 0x3F) << 2;
|
||||
int b = (rgb565 & 0x1F) << 3;
|
||||
|
||||
int rgb = (r << 16) | (g << 8) | b;
|
||||
image.setRGB(x, y, rgb);
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// ... 原有代码 ...
|
||||
|
||||
// 测试生成160*80画布,嵌入背景图片并居中显示文字
|
||||
// String text = "现在危险,停止救援紧急撤离至安全区域";
|
||||
String text = "现在危险,停止救援,紧急撤离至安全区域!";
|
||||
String backgroundImagePath = "D:\\background.png"; // 替换为实际背景图片路径
|
||||
byte[] imageData = generate160x80ImageWithText(text, backgroundImagePath, 25600);
|
||||
|
||||
System.out.println("生成的160*80 RGB565图像数据:");
|
||||
System.out.println("数据长度: " + imageData.length + " 字节");
|
||||
// 生成预览图片
|
||||
// 生成预览图片
|
||||
BufferedImage image160x80 = convertByteArrayToImage(imageData, 80, 160);
|
||||
ImageIO.write(image160x80, "PNG", new File("D:\\bitmap_160x80_preview.png"));
|
||||
// System.out.println("成功生成160*80预览图片: D:\\bitmap_160x80_preview.png");
|
||||
// 转换为十进制数组
|
||||
// int[] decimalArray = convertHexToDecimal(imageData);
|
||||
// System.out.println("生成的十进制数据(前50个):");
|
||||
// System.out.println(Arrays.toString(Arrays.copyOf(decimalArray, Math.min(50, decimalArray.length))));
|
||||
//
|
||||
// // 将数据分割成512字节的块
|
||||
// List<byte[]> chunks = splitByteArrayIntoChunks(imageData, 512);
|
||||
// printChunkInfo(chunks);
|
||||
//
|
||||
// // 示例:获取特定块的数据
|
||||
// byte[] specificChunk = getChunk(imageData, 0, 512); // 获取第1块(索引0)
|
||||
// System.out.println("第1块数据大小: " + specificChunk.length + " 字节");
|
||||
}
|
||||
|
||||
}
|
||||
@ -24,13 +24,6 @@ public class DecryptRequestBodyWrapper extends HttpServletRequestWrapper {
|
||||
|
||||
private final byte[] body;
|
||||
|
||||
|
||||
/**
|
||||
* @param request
|
||||
* @param privateKey
|
||||
* @param headerFlag encrypt-key
|
||||
* @throws IOException
|
||||
*/
|
||||
public DecryptRequestBodyWrapper(HttpServletRequest request, String privateKey, String headerFlag) throws IOException {
|
||||
super(request);
|
||||
// 获取 AES 密码 采用 RSA 加密
|
||||
|
||||
@ -19,36 +19,31 @@ public class EncryptUtilsTest {
|
||||
String s = "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKNPuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gAkM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWowcSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99EcvDQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthhYhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3UP8iWi1Qw0Y=";
|
||||
|
||||
|
||||
/**
|
||||
* encrypt-key
|
||||
*/
|
||||
String s1 = EncryptUtils.encryptByRsa("MTIzNDU2Nzg5MGFiY2RlZg==", g);
|
||||
System.out.println(s1);
|
||||
System.out.println("-------------s1--------------");
|
||||
|
||||
String s2 = EncryptUtils.decryptByRsa("jJPaW7hgFXD/gjdkrfBOEUdXpPZnQg/LZUASoOJAOLU/XRVXO/5666CzyALjw7neK1ujvRuys4MdKCvr9cRARw==", s);
|
||||
System.out.println(s2);
|
||||
System.out.println("-------------s2--------------");
|
||||
|
||||
String s3 = EncryptUtils.decryptByBase64(s2);
|
||||
System.out.println(s3);
|
||||
System.out.println("-------------s2--------------");
|
||||
|
||||
String s4 = EncryptUtils.encryptByAes("123456", s3);
|
||||
System.out.println(s4);
|
||||
System.out.println("-------------s2--------------");
|
||||
|
||||
String s5 = EncryptUtils.decryptByAes(s4, s3);
|
||||
System.out.println(s5);
|
||||
System.out.println("-------------s2--------------");
|
||||
|
||||
|
||||
// 1. 构造 LoginBody 对象
|
||||
PasswordLoginBody loginBody = new PasswordLoginBody();
|
||||
loginBody.setClientId("e5cd7e4891bf95d1d19206ce24a7b32e");
|
||||
loginBody.setGrantType("password");
|
||||
loginBody.setTenantId("894078");
|
||||
loginBody.setCode("2");
|
||||
loginBody.setUuid("d339659cea5245aab7df92642326218e");
|
||||
loginBody.setCode("0");
|
||||
loginBody.setUuid("1c285b27f516486f9535face77023aeb");
|
||||
// loginBody.setUsername("admin");
|
||||
// loginBody.setPassword("admin123");
|
||||
loginBody.setUsername("fel");
|
||||
loginBody.setUsername("dyf");
|
||||
loginBody.setPassword("123456");
|
||||
|
||||
// 2. 使用更清晰的方式拼接 JSON 字符串
|
||||
@ -72,12 +67,9 @@ public class EncryptUtilsTest {
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* body
|
||||
*/
|
||||
String S5 = EncryptUtils.encryptByAes(jsonLoginBody, s3);
|
||||
System.out.println(S5);
|
||||
System.out.println("-------------s5--------------");
|
||||
|
||||
String S6 = EncryptUtils.decryptByAes(S5, s3);
|
||||
System.out.println(S6);
|
||||
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
package com.fuyuanshen.common.ratelimiter.annotation;// DeviceRedisKeyAnnotation.java
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface FunctionAccessAnnotation {
|
||||
String value() default "";
|
||||
long timeOut() default 30;
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package com.fuyuanshen.common.ratelimiter.annotation;// DeviceRedisKeyAnnotation.java
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface FunctionAccessBatcAnnotation {
|
||||
String value() default "";
|
||||
long timeOut() default 30;
|
||||
long batchMaxTimeOut() default 40;
|
||||
}
|
||||
@ -1,104 +0,0 @@
|
||||
package com.fuyuanshen.common.ratelimiter.aspectj;// DeviceRedisKeyAspect.java
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_TIMEOUT_KEY;
|
||||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class FunctionAccessAspect {
|
||||
|
||||
// 定义切点,拦截带有DeviceRedisKeyAnnotation注解的方法
|
||||
@Around("@annotation(functionAccessAnnotation)")
|
||||
public Object addDeviceRedisKey(ProceedingJoinPoint joinPoint, FunctionAccessAnnotation functionAccessAnnotation) throws Throwable {
|
||||
Object result;
|
||||
String deviceImei = null;
|
||||
|
||||
// 获取方法参数,查找设备ID
|
||||
Object[] args = joinPoint.getArgs();
|
||||
deviceImei = extractDeviceImei(args);
|
||||
long timeout = functionAccessAnnotation.timeOut();
|
||||
|
||||
if (StringUtils.isNotBlank(deviceImei)) {
|
||||
// 生成全局Redis key
|
||||
String redisKey = generateDeviceRedisKey(deviceImei);
|
||||
String cacheKey = RedisUtils.getCacheObject(redisKey);
|
||||
if(StringUtils.isNotBlank(cacheKey) && "ACTIVE".equals(cacheKey)){
|
||||
throw new ServiceException("设备已存在访问限制,请稍后再试", 500);
|
||||
}
|
||||
//
|
||||
RedisUtils.setCacheObject(redisKey, "ACTIVE", Duration.ofSeconds(timeout));
|
||||
}
|
||||
|
||||
// 执行原方法
|
||||
result = joinPoint.proceed();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从方法参数中提取设备ID
|
||||
*/
|
||||
private String extractDeviceImei(Object[] args) {
|
||||
if (args == null || args.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Object arg : args) {
|
||||
if (arg == null) continue;
|
||||
|
||||
// 如果参数本身就是设备ID (Long类型)
|
||||
if (arg instanceof Long) {
|
||||
return arg.toString();
|
||||
}
|
||||
|
||||
// 如果参数是对象,尝试获取deviceId字段
|
||||
try {
|
||||
// 使用反射获取deviceId字段
|
||||
java.lang.reflect.Field[] fields = arg.getClass().getDeclaredFields();
|
||||
for (java.lang.reflect.Field field : fields) {
|
||||
if ("deviceImei".equalsIgnoreCase(field.getName()) ||
|
||||
"device_imei".equalsIgnoreCase(field.getName())) {
|
||||
field.setAccessible(true);
|
||||
Object value = field.get(arg);
|
||||
if (value != null) {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试获取getId方法
|
||||
try {
|
||||
java.lang.reflect.Method getIdMethod = arg.getClass().getMethod("getDeviceImei");
|
||||
Object value = getIdMethod.invoke(arg);
|
||||
if (value != null) {
|
||||
return value.toString();
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.debug("从参数中提取设备ID时出错: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备的全局Redis key
|
||||
*/
|
||||
private String generateDeviceRedisKey(String deviceImei) {
|
||||
return FUNCTION_ACCESS_KEY + deviceImei;
|
||||
}
|
||||
}
|
||||
@ -1,183 +0,0 @@
|
||||
package com.fuyuanshen.common.ratelimiter.aspectj;// DeviceRedisKeyAspect.java
|
||||
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class FunctionAccessBatchAspect {
|
||||
|
||||
// 定义切点,拦截带有DeviceRedisKeyAnnotation注解的方法
|
||||
@Around("@annotation(functionAccessBatchAspect)")
|
||||
public Object addDeviceRedisKey(ProceedingJoinPoint joinPoint, FunctionAccessBatcAnnotation functionAccessBatchAspect) throws Throwable {
|
||||
Object result;
|
||||
String batchId = null;
|
||||
List<String> deviceImeiList = null;
|
||||
|
||||
// 获取方法参数,查找设备ID
|
||||
Object[] args = joinPoint.getArgs();
|
||||
batchId = extractDeviceBatchId(args);
|
||||
deviceImeiList = extractDeviceImeiList(args);
|
||||
if (StringUtils.isNotBlank(batchId)) {
|
||||
// 生成全局Redis key
|
||||
String redisKey = generateDeviceRedisKey(batchId);
|
||||
String cacheKey = RedisUtils.getCacheObject(redisKey);
|
||||
if(StringUtils.isNotBlank(cacheKey) && "ACTIVE".equals(cacheKey)){
|
||||
throw new ServiceException("设备已存在访问限制,请稍后再试", 500);
|
||||
}
|
||||
deviceImeiList.forEach(item->{
|
||||
RedisUtils.setCacheObject(FUNCTION_ACCESS_KEY + item, "ACTIVE", Duration.ofSeconds(functionAccessBatchAspect.timeOut()));
|
||||
});
|
||||
String deviceImeiListStr = JSONUtil.toJsonStr(deviceImeiList);
|
||||
RedisUtils.setCacheObject(redisKey, deviceImeiListStr , Duration.ofSeconds(functionAccessBatchAspect.batchMaxTimeOut()));
|
||||
}
|
||||
|
||||
// 执行原方法
|
||||
result = joinPoint.proceed();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从方法参数中提取设备IMEI列表
|
||||
*/
|
||||
private List<String> extractDeviceImeiList(Object[] args) {
|
||||
if (args == null || args.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Object arg : args) {
|
||||
if (arg == null) continue;
|
||||
|
||||
// 如果参数本身就是List<String>类型
|
||||
if (arg instanceof List) {
|
||||
List<?> list = (List<?>) arg;
|
||||
if (!list.isEmpty() && list.get(0) instanceof String) {
|
||||
// 检查是否为deviceImeiList
|
||||
return (List<String>) list;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果参数是对象,尝试获取deviceImeiList字段
|
||||
try {
|
||||
// 使用反射获取deviceImeiList字段
|
||||
java.lang.reflect.Field[] fields = arg.getClass().getDeclaredFields();
|
||||
for (java.lang.reflect.Field field : fields) {
|
||||
if ("deviceImeiList".equalsIgnoreCase(field.getName()) ||
|
||||
"device_imei_list".equalsIgnoreCase(field.getName()) ||
|
||||
"deviceImeis".equalsIgnoreCase(field.getName()) ||
|
||||
"device_imeis".equalsIgnoreCase(field.getName())) {
|
||||
field.setAccessible(true);
|
||||
Object value = field.get(arg);
|
||||
if (value instanceof List) {
|
||||
List<?> list = (List<?>) value;
|
||||
if (!list.isEmpty() && list.get(0) instanceof String) {
|
||||
return (List<String>) list;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试获取getDeviceImeiList方法
|
||||
try {
|
||||
java.lang.reflect.Method getDeviceImeiListMethod = arg.getClass().getMethod("getDeviceImeiList");
|
||||
Object value = getDeviceImeiListMethod.invoke(arg);
|
||||
if (value instanceof List) {
|
||||
List<?> list = (List<?>) value;
|
||||
if (!list.isEmpty() && list.get(0) instanceof String) {
|
||||
return (List<String>) list;
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
// 尝试获取getDeviceImeis方法
|
||||
try {
|
||||
java.lang.reflect.Method getDeviceImeisMethod = arg.getClass().getMethod("getDeviceImeis");
|
||||
Object value = getDeviceImeisMethod.invoke(arg);
|
||||
if (value instanceof List) {
|
||||
List<?> list = (List<?>) value;
|
||||
if (!list.isEmpty() && list.get(0) instanceof String) {
|
||||
return (List<String>) list;
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.debug("从参数中提取设备IMEI列表时出错: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从方法参数中提取设备ID
|
||||
*/
|
||||
private String extractDeviceBatchId(Object[] args) {
|
||||
if (args == null || args.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Object arg : args) {
|
||||
if (arg == null) continue;
|
||||
|
||||
// 如果参数本身就是设备ID (Long类型)
|
||||
if (arg instanceof Long) {
|
||||
return arg.toString();
|
||||
}
|
||||
|
||||
// 如果参数是对象,尝试获取deviceId字段
|
||||
try {
|
||||
// 使用反射获取deviceId字段
|
||||
java.lang.reflect.Field[] fields = arg.getClass().getDeclaredFields();
|
||||
for (java.lang.reflect.Field field : fields) {
|
||||
if ("batchId".equalsIgnoreCase(field.getName()) ||
|
||||
"batch_id".equalsIgnoreCase(field.getName())) {
|
||||
field.setAccessible(true);
|
||||
Object value = field.get(arg);
|
||||
if (value != null) {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试获取getId方法
|
||||
try {
|
||||
java.lang.reflect.Method getIdMethod = arg.getClass().getMethod("batchId");
|
||||
Object value = getIdMethod.invoke(arg);
|
||||
if (value != null) {
|
||||
return value.toString();
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.debug("从参数中提取批次号时出错: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备的全局Redis key
|
||||
*/
|
||||
private String generateDeviceRedisKey(String batchId) {
|
||||
return FUNCTION_ACCESS_KEY + batchId;
|
||||
}
|
||||
}
|
||||
@ -339,40 +339,7 @@ public class RedisUtils {
|
||||
RSet<T> rSet = CLIENT.getSet(key);
|
||||
return rSet.addAll(dataSet);
|
||||
}
|
||||
/**
|
||||
* 向Sorted Set添加元素
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param score 分数
|
||||
* @return 添加成功返回true,否则返回false
|
||||
*/
|
||||
public static boolean zAdd(String key, Object value, double score) {
|
||||
try {
|
||||
RScoredSortedSet<Object> sortedSet = CLIENT.getScoredSortedSet(key);
|
||||
return sortedSet.add(score, value);
|
||||
} catch (Exception e) {
|
||||
// log.error("向Sorted Set添加元素失败: key={}, value={}, score={}, error={}", key, value, score, e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除Sorted Set中指定范围的元素(按分数)
|
||||
*
|
||||
* @param key 键
|
||||
* @param min 最小分数
|
||||
* @param max 最大分数
|
||||
* @return 移除的元素数量
|
||||
*/
|
||||
public static int zRemoveRangeByScore(String key, double min, double max) {
|
||||
try {
|
||||
RScoredSortedSet<Object> sortedSet = CLIENT.getScoredSortedSet(key);
|
||||
return sortedSet.removeRangeByScore(min, true, max, true);
|
||||
} catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 追加缓存Set数据
|
||||
*
|
||||
|
||||
@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class TestSMSController {
|
||||
|
||||
|
||||
@GetMapping("/test")
|
||||
public void testSend() {
|
||||
// 在创建完SmsBlend实例后,再未手动调用注销的情况下框架会持有该实例,可以直接通过指定configId来获取想要的配置,如果你想使用
|
||||
|
||||
@ -1,105 +0,0 @@
|
||||
package com.fuyuanshen.app.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.*;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
||||
import com.fuyuanshen.common.log.annotation.Log;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.log.enums.BusinessType;
|
||||
import com.fuyuanshen.common.excel.utils.ExcelUtil;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoRecordsVo;
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoRecordsBo;
|
||||
import com.fuyuanshen.app.service.IAppPersonnelInfoRecordsService;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 人员信息登记记录
|
||||
*
|
||||
* @author CYT
|
||||
* @date 2025-08-22
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/app/personnelInfoRecords")
|
||||
public class AppPersonnelInfoRecordsController extends BaseController {
|
||||
|
||||
private final IAppPersonnelInfoRecordsService appPersonnelInfoRecordsService;
|
||||
|
||||
/**
|
||||
* 查询人员信息登记记录列表
|
||||
*/
|
||||
@SaCheckPermission("app:personnelInfoRecords:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<AppPersonnelInfoRecordsVo> list(AppPersonnelInfoRecordsBo bo, PageQuery pageQuery) {
|
||||
return appPersonnelInfoRecordsService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出人员信息登记记录列表
|
||||
*/
|
||||
@SaCheckPermission("app:personnelInfoRecords:export")
|
||||
@Log(title = "人员信息登记记录", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(AppPersonnelInfoRecordsBo bo, HttpServletResponse response) {
|
||||
List<AppPersonnelInfoRecordsVo> list = appPersonnelInfoRecordsService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "人员信息登记记录", AppPersonnelInfoRecordsVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取人员信息登记记录详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@SaCheckPermission("app:personnelInfoRecords:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<AppPersonnelInfoRecordsVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appPersonnelInfoRecordsService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增人员信息登记记录
|
||||
*/
|
||||
@SaCheckPermission("app:personnelInfoRecords:add")
|
||||
@Log(title = "人员信息登记记录", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoRecordsBo bo) {
|
||||
return toAjax(appPersonnelInfoRecordsService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改人员信息登记记录
|
||||
*/
|
||||
@SaCheckPermission("app:personnelInfoRecords:edit")
|
||||
@Log(title = "人员信息登记记录", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppPersonnelInfoRecordsBo bo) {
|
||||
return toAjax(appPersonnelInfoRecordsService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除人员信息登记记录
|
||||
*
|
||||
* @param ids 主键串
|
||||
*/
|
||||
@SaCheckPermission("app:personnelInfoRecords:remove")
|
||||
@Log(title = "人员信息登记记录", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(appPersonnelInfoRecordsService.deleteWithValidByIds(List.of(ids), true));
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,7 @@ import com.fuyuanshen.app.service.IAppUserService;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* WebApp用户信息
|
||||
* APP用户信息
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-06-27
|
||||
@ -32,14 +32,14 @@ import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/WebApp/user")
|
||||
public class WebAppUserController extends BaseController {
|
||||
@RequestMapping("/app/user")
|
||||
public class AppUserController extends BaseController {
|
||||
|
||||
private final IAppUserService appUserService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询APP用户信息列表
|
||||
* 查询APP用户信息列表
|
||||
*/
|
||||
// @SaCheckPermission("app:user:list")
|
||||
@GetMapping("/list")
|
||||
@ -67,7 +67,7 @@ public class WebAppUserController extends BaseController {
|
||||
@SaCheckPermission("app:user:query")
|
||||
@GetMapping("/{userId}")
|
||||
public R<AppUserVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long userId) {
|
||||
@PathVariable Long userId) {
|
||||
return R.ok(appUserService.queryById(userId));
|
||||
}
|
||||
|
||||
@ -105,5 +105,4 @@ public class WebAppUserController extends BaseController {
|
||||
@PathVariable Long[] userIds) {
|
||||
return toAjax(appUserService.deleteWithValidByIds(List.of(userIds), true));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,13 +1,14 @@
|
||||
package com.fuyuanshen.app.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 设备绑定关系对象 app_device_bind_record
|
||||
|
||||
@ -1,66 +0,0 @@
|
||||
package com.fuyuanshen.app.domain;
|
||||
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 人员信息登记记录对象 app_personnel_info_records
|
||||
*
|
||||
* @author CYT
|
||||
* @date 2025-08-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("app_personnel_info_records")
|
||||
public class AppPersonnelInfoRecords extends TenantEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备id
|
||||
*/
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long personnelId;
|
||||
|
||||
/**
|
||||
* 人员姓名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 职位
|
||||
*/
|
||||
private String position;
|
||||
|
||||
/**
|
||||
* 单位名称
|
||||
*/
|
||||
private String unitName;
|
||||
|
||||
/**
|
||||
* ID号
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
*/
|
||||
private String sendMsg;
|
||||
|
||||
|
||||
}
|
||||
@ -99,6 +99,6 @@ public class AppUser extends TenantEntity {
|
||||
/**
|
||||
* 地区
|
||||
*/
|
||||
// private String region;
|
||||
private String region;
|
||||
|
||||
}
|
||||
|
||||
@ -25,11 +25,6 @@ public class AppPersonnelInfoBo extends BaseEntity {
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 设备id
|
||||
*/
|
||||
|
||||
@ -1,67 +0,0 @@
|
||||
package com.fuyuanshen.app.domain.bo;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* 人员信息登记记录业务对象 app_personnel_info_records
|
||||
*
|
||||
* @author CYT
|
||||
* @date 2025-08-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = AppPersonnelInfoRecords.class, reverseConvertGenerate = false)
|
||||
public class AppPersonnelInfoRecordsBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@NotNull(message = "主键不能为空", groups = { EditGroup.class })
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备id
|
||||
*/
|
||||
@NotNull(message = "设备id不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@NotNull(message = "主键不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Long personnelId;
|
||||
|
||||
/**
|
||||
* 人员姓名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 职位
|
||||
*/
|
||||
private String position;
|
||||
|
||||
/**
|
||||
* 单位名称
|
||||
*/
|
||||
private String unitName;
|
||||
|
||||
/**
|
||||
* ID号
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
*/
|
||||
private String sendMsg;
|
||||
|
||||
|
||||
}
|
||||
@ -16,6 +16,11 @@ public class AppDeviceDetailVo {
|
||||
@ExcelProperty(value = "设备ID")
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@ExcelProperty(value = "手机号")
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
@ -69,42 +74,4 @@ public class AppDeviceDetailVo {
|
||||
* 发送信息
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
@ -104,41 +104,4 @@ public class AppDeviceShareDetailVo implements Serializable {
|
||||
* 发送信息
|
||||
*/
|
||||
private String sendMsg;
|
||||
|
||||
//设备主灯档位
|
||||
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;
|
||||
}
|
||||
|
||||
@ -57,12 +57,6 @@ public class AppDeviceShareVo implements Serializable {
|
||||
@ExcelProperty(value = "手机号")
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
* 他人分享手机号
|
||||
*/
|
||||
@ExcelProperty(value = "手机号")
|
||||
private String otherPhonenumber;
|
||||
|
||||
/**
|
||||
* 功能权限(1:灯光模式;2:激光模式;3:开机画面;4:人员信息登记;5:发送信息;6:产品信息)
|
||||
以逗号分隔
|
||||
@ -71,11 +65,6 @@ public class AppDeviceShareVo implements Serializable {
|
||||
@ExcelDictFormat(readConverterExp = "1=:灯光模式;2:激光模式;3:开机画面;4:人员信息登记;5:发送信息;6:产品信息")
|
||||
private String permission;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ -84,29 +73,4 @@ public class AppDeviceShareVo implements Serializable {
|
||||
|
||||
// 设备图片
|
||||
private String devicePic;
|
||||
|
||||
/**
|
||||
* 在线状态(0离线,1在线)
|
||||
*/
|
||||
private Integer onlineStatus;
|
||||
|
||||
/**
|
||||
* 电量 百分比
|
||||
*/
|
||||
private String battery;
|
||||
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
private String latitude;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private String longitude;
|
||||
|
||||
/**
|
||||
* 告警状态(0解除告警,1告警)
|
||||
*/
|
||||
private String alarmStatus;
|
||||
}
|
||||
|
||||
@ -1,80 +0,0 @@
|
||||
package com.fuyuanshen.app.domain.vo;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import com.fuyuanshen.common.excel.annotation.ExcelDictFormat;
|
||||
import com.fuyuanshen.common.excel.convert.ExcelDictConvert;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记记录视图对象 app_personnel_info_records
|
||||
*
|
||||
* @author CYT
|
||||
* @date 2025-08-22
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@AutoMapper(target = AppPersonnelInfoRecords.class)
|
||||
public class AppPersonnelInfoRecordsVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ExcelProperty(value = "主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备id
|
||||
*/
|
||||
@ExcelProperty(value = "设备id")
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ExcelProperty(value = "主键")
|
||||
private Long personnelId;
|
||||
|
||||
/**
|
||||
* 人员姓名
|
||||
*/
|
||||
@ExcelProperty(value = "人员姓名")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 职位
|
||||
*/
|
||||
@ExcelProperty(value = "职位")
|
||||
private String position;
|
||||
|
||||
/**
|
||||
* 单位名称
|
||||
*/
|
||||
@ExcelProperty(value = "单位名称")
|
||||
private String unitName;
|
||||
|
||||
/**
|
||||
* ID号
|
||||
*/
|
||||
@ExcelProperty(value = "ID号")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
*/
|
||||
@ExcelProperty(value = "发送信息")
|
||||
private String sendMsg;
|
||||
|
||||
|
||||
}
|
||||
@ -5,8 +5,6 @@ import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fuyuanshen.app.domain.AppUser;
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
@ -89,8 +87,6 @@ public class AppUserVo implements Serializable {
|
||||
* 密码
|
||||
*/
|
||||
@ExcelProperty(value = "密码")
|
||||
@JsonIgnore
|
||||
@JsonProperty
|
||||
private String password;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.fuyuanshen.app.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.app.domain.AppDeviceShare;
|
||||
@ -17,6 +16,4 @@ import org.apache.ibatis.annotations.Param;
|
||||
*/
|
||||
public interface AppDeviceShareMapper extends BaseMapperPlus<AppDeviceShare, AppDeviceShareVo> {
|
||||
IPage<AppDeviceShareVo> otherDeviceShareList(@Param("bo") AppDeviceShareBo bo, Page<AppDeviceShareVo> page);
|
||||
|
||||
Page<AppDeviceShareVo> selectAppDeviceShareList(@Param("bo") AppDeviceShareBo bo,Page<AppDeviceShareVo> page);
|
||||
}
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
package com.fuyuanshen.app.mapper;
|
||||
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoRecordsVo;
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
|
||||
/**
|
||||
* 人员信息登记记录Mapper接口
|
||||
*
|
||||
* @author CYT
|
||||
* @date 2025-08-22
|
||||
*/
|
||||
public interface AppPersonnelInfoRecordsMapper extends BaseMapperPlus<AppPersonnelInfoRecords, AppPersonnelInfoRecordsVo> {
|
||||
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoRecordsVo;
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoRecordsBo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 人员信息登记记录Service接口
|
||||
*
|
||||
* @author CYT
|
||||
* @date 2025-08-22
|
||||
*/
|
||||
public interface IAppPersonnelInfoRecordsService {
|
||||
|
||||
/**
|
||||
* 查询人员信息登记记录
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 人员信息登记记录
|
||||
*/
|
||||
AppPersonnelInfoRecordsVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 分页查询人员信息登记记录列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param pageQuery 分页参数
|
||||
* @return 人员信息登记记录分页列表
|
||||
*/
|
||||
TableDataInfo<AppPersonnelInfoRecordsVo> queryPageList(AppPersonnelInfoRecordsBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询符合条件的人员信息登记记录列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return 人员信息登记记录列表
|
||||
*/
|
||||
List<AppPersonnelInfoRecordsVo> queryList(AppPersonnelInfoRecordsBo bo);
|
||||
|
||||
/**
|
||||
* 新增人员信息登记记录
|
||||
*
|
||||
* @param bo 人员信息登记记录
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
Boolean insertByBo(AppPersonnelInfoRecordsBo bo);
|
||||
|
||||
/**
|
||||
* 修改人员信息登记记录
|
||||
*
|
||||
* @param bo 人员信息登记记录
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
Boolean updateByBo(AppPersonnelInfoRecordsBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除人员信息登记记录信息
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
}
|
||||
@ -1,138 +0,0 @@
|
||||
package com.fuyuanshen.app.service.impl;
|
||||
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoRecordsBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoRecordsVo;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoRecordsMapper;
|
||||
import com.fuyuanshen.app.service.IAppPersonnelInfoRecordsService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 人员信息登记记录Service业务层处理
|
||||
*
|
||||
* @author CYT
|
||||
* @date 2025-08-22
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class AppPersonnelInfoRecordsServiceImpl implements IAppPersonnelInfoRecordsService {
|
||||
|
||||
private final AppPersonnelInfoRecordsMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询人员信息登记记录
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 人员信息登记记录
|
||||
*/
|
||||
@Override
|
||||
public AppPersonnelInfoRecordsVo queryById(Long id){
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询人员信息登记记录列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param pageQuery 分页参数
|
||||
* @return 人员信息登记记录分页列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<AppPersonnelInfoRecordsVo> queryPageList(AppPersonnelInfoRecordsBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<AppPersonnelInfoRecords> lqw = buildQueryWrapper(bo);
|
||||
Page<AppPersonnelInfoRecordsVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询符合条件的人员信息登记记录列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return 人员信息登记记录列表
|
||||
*/
|
||||
@Override
|
||||
public List<AppPersonnelInfoRecordsVo> queryList(AppPersonnelInfoRecordsBo bo) {
|
||||
LambdaQueryWrapper<AppPersonnelInfoRecords> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<AppPersonnelInfoRecords> buildQueryWrapper(AppPersonnelInfoRecordsBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<AppPersonnelInfoRecords> lqw = Wrappers.lambdaQuery();
|
||||
lqw.orderByAsc(AppPersonnelInfoRecords::getId);
|
||||
lqw.eq(bo.getDeviceId() != null, AppPersonnelInfoRecords::getDeviceId, bo.getDeviceId());
|
||||
lqw.eq(bo.getPersonnelId() != null, AppPersonnelInfoRecords::getPersonnelId, bo.getPersonnelId());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getName()), AppPersonnelInfoRecords::getName, bo.getName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getPosition()), AppPersonnelInfoRecords::getPosition, bo.getPosition());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getUnitName()), AppPersonnelInfoRecords::getUnitName, bo.getUnitName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getCode()), AppPersonnelInfoRecords::getCode, bo.getCode());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getSendMsg()), AppPersonnelInfoRecords::getSendMsg, bo.getSendMsg());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增人员信息登记记录
|
||||
*
|
||||
* @param bo 人员信息登记记录
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(AppPersonnelInfoRecordsBo bo) {
|
||||
AppPersonnelInfoRecords add = MapstructUtils.convert(bo, AppPersonnelInfoRecords.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改人员信息登记记录
|
||||
*
|
||||
* @param bo 人员信息登记记录
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(AppPersonnelInfoRecordsBo bo) {
|
||||
AppPersonnelInfoRecords update = MapstructUtils.convert(bo, AppPersonnelInfoRecords.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(AppPersonnelInfoRecords entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验并批量删除人员信息登记记录信息
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
@ -1,43 +1,37 @@
|
||||
package com.fuyuanshen.app.service.impl;
|
||||
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.app.domain.AppUser;
|
||||
import com.fuyuanshen.app.domain.bo.AppUserBo;
|
||||
import com.fuyuanshen.app.domain.dto.APPForgotPasswordDTO;
|
||||
import com.fuyuanshen.app.domain.dto.APPForgotPasswordSmsDTO;
|
||||
import com.fuyuanshen.app.domain.dto.APPUpdateUserDTO;
|
||||
import com.fuyuanshen.app.domain.vo.APPUserInfoVo;
|
||||
import com.fuyuanshen.common.core.constant.Constants;
|
||||
import com.fuyuanshen.app.domain.vo.AppUserVo;
|
||||
import com.fuyuanshen.app.mapper.AppUserMapper;
|
||||
import com.fuyuanshen.app.service.IAppUserService;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.domain.model.AppLoginUser;
|
||||
import com.fuyuanshen.common.core.exception.BadRequestException;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.common.tenant.helper.TenantHelper;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import com.fuyuanshen.system.service.ISysOssService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.fuyuanshen.app.domain.bo.AppUserBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppUserVo;
|
||||
import com.fuyuanshen.app.domain.AppUser;
|
||||
import com.fuyuanshen.app.mapper.AppUserMapper;
|
||||
import com.fuyuanshen.app.service.IAppUserService;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Service业务层处理
|
||||
@ -53,6 +47,7 @@ public class AppUserServiceImpl implements IAppUserService {
|
||||
private final AppUserMapper baseMapper;
|
||||
|
||||
private final ISysOssService sysOssService;
|
||||
|
||||
/**
|
||||
* 查询APP用户信息
|
||||
*
|
||||
@ -177,7 +172,7 @@ public class AppUserServiceImpl implements IAppUserService {
|
||||
appUserVo.setNickName(user.getNickName());
|
||||
appUserVo.setGender(user.getSex());
|
||||
appUserVo.setPhone(user.getPhonenumber());
|
||||
// appUserVo.setRegion(user.getRegion());
|
||||
appUserVo.setRegion(user.getRegion());
|
||||
if(user.getAvatar() != null){
|
||||
SysOssVo oss = sysOssService.getById(user.getAvatar());
|
||||
if(oss != null){
|
||||
@ -203,7 +198,7 @@ public class AppUserServiceImpl implements IAppUserService {
|
||||
updUser.setAvatar(oss.getOssId());
|
||||
}
|
||||
|
||||
// updUser.setRegion(bo.getRegion());
|
||||
updUser.setRegion(bo.getRegion());
|
||||
updUser.setSex(bo.getGender());
|
||||
return baseMapper.update(updUser, new LambdaQueryWrapper<AppUser>().eq(AppUser::getUserId, appUser.getUserId()));
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user