Compare commits

16 Commits

Author SHA1 Message Date
447aa73ae9 Merge branch 'dyf-device' 2025-08-14 14:22:43 +08:00
9c9d18cddc 查询设备分组列表 2025-08-14 14:21:47 +08:00
1af4b165f2 新增设备分组 2025-08-13 19:29:04 +08:00
bc165f5d60 分享管理 2025-08-09 17:09:26 +08:00
af64984623 修改分享功能 2025-08-09 08:49:37 +08:00
0c932c686d 修改分享查看 2025-08-08 16:32:40 +08:00
47dbd33d56 修改在线上报状态 2025-08-08 15:09:59 +08:00
72cab138a7 设备控制中心 2025-08-08 10:44:49 +08:00
3abee42b07 设备控制中心 2025-08-08 10:43:53 +08:00
9fb72e5ac0 设备分组 2025-08-08 09:49:08 +08:00
41c6cb935d Merge branch 'dyf-device' 2025-08-07 18:08:12 +08:00
9de55857bc 晶全日志配置 2025-08-07 18:07:04 +08:00
efed6f3683 修改包名 2025-08-07 15:56:12 +08:00
f67e848256 晶全6710 2025-08-07 15:41:57 +08:00
825e9b329c Merge remote-tracking branch 'origin/main' 2025-08-06 10:39:01 +08:00
67764a733e 设备列表电量显示问题,打印日志优化 2025-08-06 10:38:21 +08:00
53 changed files with 3357 additions and 685 deletions

119
aa.conf Normal file
View File

@ -0,0 +1,119 @@
#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;
}
}
}

View File

@ -0,0 +1,96 @@
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());
}
}
}

View File

@ -1,31 +1,20 @@
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.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.dto.AppDeviceBo;
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
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;
/**
* APP设备信息管理
@ -83,95 +72,4 @@ public class AppDeviceController extends BaseController {
appDeviceService.reName(reNameDTO);
return R.ok("重命名成功!!!");
}
/**
* 获取设备详细信息
*
* @param id 主键
*/
@GetMapping("/{id}")
public R<AppDeviceDetailVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(appDeviceService.getInfo(id));
}
/**
* 人员信息登记
*/
@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));
}
/**
* 发送报警信息
*/
@PostMapping(value = "/sendAlarmMessage")
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService.sendAlarmMessage(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);
}
}

View File

@ -52,7 +52,7 @@ public class AppDeviceShareController extends BaseController {
*/
@GetMapping("/deviceShareList")
public TableDataInfo<AppDeviceShareVo> list(AppDeviceShareBo bo, PageQuery pageQuery) {
return deviceShareService.queryPageList(bo, pageQuery);
return appDeviceShareService.queryPageList(bo, pageQuery);
}
/**
@ -60,7 +60,7 @@ public class AppDeviceShareController extends BaseController {
*/
@GetMapping("/otherDeviceShareList")
public TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery) {
return deviceShareService.otherDeviceShareList(bo, pageQuery);
return appDeviceShareService.otherDeviceShareList(bo, pageQuery);
}
/**

View File

@ -0,0 +1,119 @@
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.app.service.device.AppDeviceBJQBizService;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
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 AppDeviceBJQBizService appDeviceService;
/**
* 获取设备详细信息
*
* @param id 主键
*/
@GetMapping("/{id}")
public R<AppDeviceDetailVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(appDeviceService.getInfo(id));
}
/**
* 人员信息登记
*/
@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));
}
/**
* 发送报警信息
*/
@PostMapping(value = "/sendAlarmMessage")
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService.sendAlarmMessage(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);
}
}

View File

@ -0,0 +1,112 @@
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.app.service.AppDeviceBizService;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
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;
/**
* HBY210设备控制类
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/hby/device")
public class AppDeviceHBYController extends BaseController {
private final AppDeviceBizService appDeviceService;
/**
* 获取设备详细信息
*
* @param id 主键
*/
@GetMapping("/{id}")
public R<AppDeviceDetailVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(appDeviceService.getInfo(id));
}
/**
* 人员信息登记
*/
@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);
}
}

View File

@ -54,6 +54,7 @@ import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_K
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
@ -101,14 +102,14 @@ public class AppDeviceBizService {
// String backgroundImagePath = "D:\\background.png"; // 替换为实际背景图片路径
byte[] largeData = ImageWithTextGenerate.generate160x80ImageWithText2(bo.getSendMsg(), inputStream, 25600);
int[] ints = convertHexToDecimal(largeData);
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+"app_send_message_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_SEND_MESSAGE_KEY_PREFIX , Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+"app_send_message_data:" + device.getDeviceImei());
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_SEND_MESSAGE_KEY_PREFIX);
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));
log.info("发送信息第0块数据大小: {} 字节",specificChunk.length);
// log.info("第0块数据: {}", Arrays.toString(specificChunk));
ArrayList<Integer> intData = new ArrayList<>();
intData.add(6);
@ -121,7 +122,7 @@ public class AppDeviceBizService {
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));
log.info("发送信息点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", deviceId)
@ -129,7 +130,7 @@ public class AppDeviceBizService {
.set("send_msg", bo.getSendMsg());
deviceMapper.update(updateWrapper);
} catch (Exception e) {
log.info("设备发送信息失败:{}" ,deviceId);
log.info("发送信息设备发送信息失败:{}" ,deviceId);
}
}
@ -149,14 +150,14 @@ public class AppDeviceBizService {
if(item.getCommunicationMode()!=null && item.getCommunicationMode() == 0){
//设备在线状态
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + item.getDeviceImei());
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+DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX + item.getDeviceImei());
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);
@ -165,14 +166,16 @@ public class AppDeviceBizService {
item.setBattery("0");
}
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + item.getDeviceImei());
// 获取电量
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"));
}else{
item.setBattery("0");
}
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
if(StringUtils.isNotBlank(alarmStatus)){
item.setAlarmStatus(alarmStatus);
}
}
});
@ -336,13 +339,13 @@ public class AppDeviceBizService {
vo.setPersonnelInfo(personnelInfoVo);
}
//设备在线状态
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + device.getDeviceImei());
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+DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX + device.getDeviceImei());
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
// 获取电量
if(StringUtils.isNotBlank(deviceStatus)){
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
@ -356,7 +359,7 @@ public class AppDeviceBizService {
}
// 获取经度纬度
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + device.getDeviceImei();
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_LOCATION_KEY_PREFIX;
String locationInfo = RedisUtils.getCacheObject(locationKey);
if(StringUtils.isNotBlank(locationInfo)){
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
@ -433,19 +436,19 @@ public class AppDeviceBizService {
MultipartFile file = bo.getFile();
byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600);
System.out.println("长度:" + largeData.length);
log.info("长度:" + largeData.length);
System.out.println("原始数据大小: " + largeData.length + " 字节");
log.info("原始数据大小: {} 字节", largeData.length);
int[] ints = convertHexToDecimal(largeData);
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX, Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei());
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);
System.out.println("第0块数据大小: " + specificChunk.length + " 字节");
System.out.println("第0块数据: " + Arrays.toString(specificChunk));
log.info("第0块数据大小: {} 字节", specificChunk.length);
// log.info("第0块数据: {}", Arrays.toString(specificChunk));
ArrayList<Integer> intData = new ArrayList<>();
intData.add(3);

View File

@ -1,7 +1,11 @@
package com.fuyuanshen.app.service;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.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;
@ -16,12 +20,15 @@ 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.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;
@ -30,6 +37,9 @@ 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
@ -44,10 +54,51 @@ public class AppDeviceShareService {
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(AppDeviceShareService::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::getDeviceId, id);
queryWrapper.eq(AppDeviceShare::getId, id);
List<AppDeviceShareVo> appDeviceShareVos = appDeviceShareMapper.selectVoList(queryWrapper);
if(appDeviceShareVos==null || appDeviceShareVos.isEmpty()){
return null;
@ -81,7 +132,35 @@ public class AppDeviceShareService {
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"));
}
return shareDetailVo;
}
/**
@ -132,4 +211,17 @@ public class AppDeviceShareService {
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(AppDeviceShareService::buildDeviceStatus);
return TableDataInfo.build(result);
}
}

View File

@ -0,0 +1,388 @@
package com.fuyuanshen.app.service.device;
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.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.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.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.DEVICE_BOOT_LOGO_KEY_PREFIX;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
@Slf4j
@Service
@RequiredArgsConstructor
public class AppDeviceBJQBizService {
private final DeviceMapper deviceMapper;
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
private final DeviceTypeMapper deviceTypeMapper;
private final MqttGateway mqttGateway;
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);
}
try {
ClassPathResource resource = new ClassPathResource("image/background.png");
InputStream inputStream = resource.getInputStream();
// String backgroundImagePath = "D:\\background.png"; // 替换为实际背景图片路径
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(30 * 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);
// log.info("第0块数据: {}", Arrays.toString(specificChunk));
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);
} catch (Exception e) {
log.info("发送信息设备发送信息失败:{}" ,deviceId);
}
}
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);
}
//设备在线状态
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 locationKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
String locationInfo = RedisUtils.getCacheObject(locationKey);
if(StringUtils.isNotBlank(locationInfo)){
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
vo.setLongitude(jsonObject.get("longitude").toString());
vo.setLatitude(jsonObject.get("latitude").toString());
vo.setAddress((String)jsonObject.get("address"));
}
return vo;
}
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);
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(30 * 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));
} 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.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));
} 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 = 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.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));
} catch (Exception e){
e.printStackTrace();
}
}
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);
}
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);
} catch (Exception e) {
log.info("设备发送信息失败:{}" ,deviceId);
}
}
} catch (Exception e){
e.printStackTrace();
}
return 1;
}
}

View File

@ -4,12 +4,6 @@ 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);

View File

@ -1,12 +1,50 @@
package com.fuyuanshen.global.mqtt.constants;
public class DeviceRedisKeyConstants {
// 将设备上报状态
public static final String DEVICE_STATUS_KEY_PREFIX = "device:status:";
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 = "device:onlineStatus:";
// 设备状态信息存储到Redis中
public static final String DEVICE_LOCATION_KEY_PREFIX = "device:location:";
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 = "device:location:history:";
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";
}

View File

@ -6,12 +6,7 @@ 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

View File

@ -20,6 +20,8 @@ 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 {
@ -46,7 +48,7 @@ public class ReceiverMessageHandler implements MessageHandler {
String deviceImei = subStr[1];
if(StringUtils.isNotBlank(deviceImei)){
//在线状态
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + deviceImei;
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1", Duration.ofSeconds(60*15));
}

View File

@ -1,22 +1,22 @@
package com.fuyuanshen.global.mqtt.rule;
package com.fuyuanshen.global.mqtt.rule.bjq;
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.config.MqttGateway;
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.time.Duration;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX;
/**
* 主动上报设备数据命令处理
* "第1位为12表示设备主动上报设备硬件状态第2为表示当时设备主灯档位第3位表示当时激光灯档位第4位电量百分比第5位为充电状态0没有充电1正在充电2为已充满
@ -25,10 +25,7 @@ import java.util.concurrent.CompletableFuture;
@Component
@RequiredArgsConstructor
@Slf4j
public class ActiveReportingDeviceDataRule implements MqttMessageRule {
private final MqttGateway mqttGateway;
public class BjqActiveReportingDeviceDataRule implements MqttMessageRule {
@Override
public String getCommandType() {
@ -80,10 +77,10 @@ public class ActiveReportingDeviceDataRule implements MqttMessageRule {
deviceInfo.put("timestamp", System.currentTimeMillis());
// 将设备状态信息存储到Redis中
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX + deviceImei;
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + deviceImei + DEVICE_STATUS_KEY_PREFIX;
String deviceInfoJson = JsonUtils.toJsonString(deviceInfo);
// 存储到Redis设置过期时间例如24小时
// 存储到Redis
RedisUtils.setCacheObject(deviceRedisKey, deviceInfoJson);
log.info("设备状态信息已异步发送到Redis: device={}, mainLightMode={}, laserLightMode={}, batteryPercentage={}",

View File

@ -0,0 +1,69 @@
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
/**
* 灯光模式订阅设备回传消息
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class BjqAlarmRule implements MqttMessageRule {
@Override
public String getCommandType() {
return LightingCommandTypeConstants.LIGHT_MODE;
}
@Override
public void execute(MqttRuleContext context) {
try {
Object[] convertArr = context.getConvertArr();
String mainLightMode = convertArr[1].toString();
if(StringUtils.isNotBlank(mainLightMode)){
// 异步发送设备状态和位置信息到Redis
asyncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),mainLightMode);
}
} catch (Exception e) {
log.error("处理灯光模式命令时出错", e);
}
}
/**
* 异步发送设备状态信息和位置信息到Redis使用CompletableFuture
*
* @param deviceImei 设备IMEI
*/
public void asyncSendDeviceDataToRedisWithFuture(String deviceImei,Object convertValue) {
CompletableFuture.runAsync(() -> {
try {
// 将设备状态信息存储到Redis中
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + deviceImei + DEVICE_ALARM_KEY_PREFIX;
// 存储到Redis
RedisUtils.setCacheObject(deviceRedisKey, convertValue.toString());
} catch (Exception e) {
log.error("异步发送设备信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e);
}
});
}
}

View File

@ -1,6 +1,5 @@
package com.fuyuanshen.global.mqtt.rule;
package com.fuyuanshen.global.mqtt.rule.bjq;
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;
@ -15,11 +14,13 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
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;
/**
* 人员信息命令处理
@ -27,7 +28,7 @@ import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHex
@Component
@RequiredArgsConstructor
@Slf4j
public class DeviceBootLogoRule implements MqttMessageRule {
public class BjqBootLogoRule implements MqttMessageRule {
private final MqttGateway mqttGateway;
@ -44,14 +45,14 @@ public class DeviceBootLogoRule implements MqttMessageRule {
return;
}
String data = RedisUtils.getCacheObject(GlobalConstants.GLOBAL_REDIS_KEY+"app_logo_data:" + context.getDeviceImei());
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);
System.out.println("" + val2 + "块数据大小: " + specificChunk.length + " 字节");
log.info("第{}块数据大小: {} 字节", val2, specificChunk.length);
// System.out.println("" + val2 + "块数据: " + Arrays.toString(specificChunk));
ArrayList<Integer> intData = new ArrayList<>();
@ -71,7 +72,7 @@ public class DeviceBootLogoRule implements MqttMessageRule {
MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(),
JsonUtils.toJsonString(map));
} catch (Exception e) {
log.error("处理人员信息命令时出错", e);
log.error("处理开机LOGO时出错", e);
}
}
}

View File

@ -1,6 +1,5 @@
package com.fuyuanshen.global.mqtt.rule;
package com.fuyuanshen.global.mqtt.rule.bjq;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.utils.StringUtils;
@ -18,20 +17,22 @@ 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.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
/**
* 定位数据命令处理
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class LocationDataRule implements MqttMessageRule {
public class BjqLocationDataRule implements MqttMessageRule {
private final MqttGateway mqttGateway;
@ -113,7 +114,7 @@ public class LocationDataRule implements MqttMessageRule {
String[] latArr = latitude.split("\\.");
String[] lonArr = longitude.split("\\.");
// 将位置信息存储到Redis中
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + deviceImei;
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){
@ -169,7 +170,7 @@ public class LocationDataRule implements MqttMessageRule {
*/
public void storeDeviceTrajectoryWithSortedSet(String deviceImei, String locationJson) {
try {
String trajectoryKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX + deviceImei;
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();
@ -181,7 +182,7 @@ public class LocationDataRule implements MqttMessageRule {
// RedisUtils.expire(trajectoryKey, Duration.ofDays(30));
// 清理30天前的数据冗余保护
long thirtyDaysAgo = System.currentTimeMillis() - (90L * 24 * 60 * 60 * 1000);
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);

View File

@ -0,0 +1,75 @@
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 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.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_LIGHT_MODE_KEY_PREFIX;
/**
* 灯光模式订阅设备回传消息
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class BjqModeRule implements MqttMessageRule {
@Override
public String getCommandType() {
return LightingCommandTypeConstants.LIGHT_MODE;
}
@Override
public void execute(MqttRuleContext context) {
try {
Object[] convertArr = context.getConvertArr();
String mainLightMode = convertArr[1].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
asyncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),mainLightMode);
}
} catch (Exception e) {
log.error("处理灯光模式命令时出错", e);
}
}
/**
* 异步发送设备状态信息和位置信息到Redis使用CompletableFuture
*
* @param deviceImei 设备IMEI
*/
public void asyncSendDeviceDataToRedisWithFuture(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);
}
});
}
}

View File

@ -1,6 +1,5 @@
package com.fuyuanshen.global.mqtt.rule;
package com.fuyuanshen.global.mqtt.rule.bjq;
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;
@ -18,7 +17,9 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
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;
/**
* 人员信息命令处理
@ -26,7 +27,7 @@ import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHex
@Component
@RequiredArgsConstructor
@Slf4j
public class DeviceSendMessageRule implements MqttMessageRule {
public class BjqSendMessageRule implements MqttMessageRule {
private final MqttGateway mqttGateway;
@ -43,14 +44,14 @@ public class DeviceSendMessageRule implements MqttMessageRule {
return;
}
String data = RedisUtils.getCacheObject(GlobalConstants.GLOBAL_REDIS_KEY+"app_send_message_data:" + context.getDeviceImei());
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":app_send_message_data");
if (StringUtils.isEmpty(data)) {
return;
}
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, (val2 - 1), 512);
System.out.println("" + val2 + "块数据大小: " + specificChunk.length + " 字节");
log.info("第{}块数据大小: {} 字节", val2, specificChunk.length);
// System.out.println("" + val2 + "块数据: " + Arrays.toString(specificChunk));
ArrayList<Integer> intData = new ArrayList<>();
@ -70,7 +71,7 @@ public class DeviceSendMessageRule implements MqttMessageRule {
MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(),
JsonUtils.toJsonString(map));
} catch (Exception e) {
log.error("处理人员信息命令时出错", e);
log.error("处理发送设备信息时出错", e);
}
}
}

View File

@ -0,0 +1,64 @@
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());
}
}
}

View File

@ -0,0 +1,41 @@
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());
}
}
}

View File

@ -0,0 +1,59 @@
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());
}
}
}

View File

@ -1,61 +1,61 @@
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;
}
}
//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;
// }
//
//}

View File

@ -0,0 +1,210 @@
package com.fuyuanshen.web.controller.device;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author: 默苍璃
* @date: 2025-08-0810:40
*/
@Slf4j
@Tag(name = "web后台:设备控制中心", description = "web后台:设备控制中心")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/device/controlCenter")
public class DeviceControlCenterController {
/**
* 获取设备基本信息
* @param deviceId 设备ID
* @return 设备基本信息
*/
@GetMapping("/info/{deviceId}")
public ResponseEntity<Map<String, Object>> getDeviceInfo(@PathVariable String deviceId) {
// 实际应用中这里会从数据库查询设备信息
Map<String, Object> deviceInfo = new HashMap<>();
deviceInfo.put("deviceName", "6170零零一");
deviceInfo.put("deviceModel", "BJQ6170");
deviceInfo.put("deviceId", deviceId);
deviceInfo.put("status", "在线");
deviceInfo.put("batteryLevel", 85);
return ResponseEntity.ok(deviceInfo);
}
/**
* 设置灯光模式
* @param lightModeRequest 灯光模式请求
* @return 操作结果
*/
@PostMapping("/light-mode")
public ResponseEntity<Map<String, Object>> setLightMode(@RequestBody LightModeRequest lightModeRequest) {
// 实际应用中这里会控制设备灯光
Map<String, Object> response = new HashMap<>();
response.put("code", 200);
// response.put("message", "灯光模式已设置为: " + lightModeRequest.getMode());
// response.put("deviceId", lightModeRequest.getDeviceId());
// response.put("mode", lightModeRequest.getMode());
return ResponseEntity.ok(response);
}
/**
* 更新人员信息
* @param personInfo 人员信息
* @return 操作结果
*/
@PostMapping("/person-info")
public ResponseEntity<Map<String, Object>> updatePersonInfo(@RequestBody PersonInfo personInfo) {
// 实际应用中这里会更新数据库
Map<String, Object> response = new HashMap<>();
response.put("code", 200);
response.put("message", "人员信息已更新");
// response.put("unit", personInfo.getUnit());
// response.put("position", personInfo.getPosition());
return ResponseEntity.ok(response);
}
/**
* 管理开机画面内容
* @param bootScreenRequest 开机画面请求
* @return 操作结果
*/
@PostMapping("/boot-screen")
public ResponseEntity<Map<String, Object>> manageBootScreen(@RequestBody BootScreenRequest bootScreenRequest) {
// 实际应用中这里会更新设备开机画面
Map<String, Object> response = new HashMap<>();
response.put("code", 200);
response.put("message", "开机画面内容已更新");
// response.put("deviceId", bootScreenRequest.getDeviceId());
// response.put("screens", bootScreenRequest.getScreens());
return ResponseEntity.ok(response);
}
/**
* 设置灯光亮度
* @param brightnessRequest 亮度请求
* @return 操作结果
*/
@PostMapping("/brightness")
public ResponseEntity<Map<String, Object>> setBrightness(@RequestBody BrightnessRequest brightnessRequest) {
// 实际应用中这里会控制设备亮度
Map<String, Object> response = new HashMap<>();
response.put("code", 200);
// response.put("message", "灯光亮度已设置为: " + brightnessRequest.getBrightness() + "%");
// response.put("deviceId", brightnessRequest.getDeviceId());
// response.put("brightness", brightnessRequest.getBrightness());
// response.put("forceAlarm", brightnessRequest.isForceAlarm());
return ResponseEntity.ok(response);
}
/**
* 获取设备位置信息
* @param deviceId 设备ID
* @return 位置信息
*/
@GetMapping("/location/{deviceId}")
public ResponseEntity<Map<String, Object>> getLocation(@PathVariable String deviceId) {
// 实际应用中这里会从设备获取实时位置
Map<String, Object> locationInfo = new HashMap<>();
locationInfo.put("deviceId", deviceId);
locationInfo.put("longitude", "114°7'E");
locationInfo.put("latitude", "30'28'N");
locationInfo.put("address", "湖北省武汉市洪山区光谷大道国际企业中心");
locationInfo.put("timestamp", new Date());
return ResponseEntity.ok(locationInfo);
}
/**
* 发送紧急消息
* @param messageRequest 消息请求
* @return 操作结果
*/
@PostMapping("/send-message")
public ResponseEntity<Map<String, Object>> sendMessage(@RequestBody MessageRequest messageRequest) {
// 实际应用中这里会向设备发送消息
Map<String, Object> response = new HashMap<>();
response.put("code", 200);
response.put("message", "消息已发送");
// response.put("deviceId", messageRequest.getDeviceId());
// response.put("content", messageRequest.getContent());
response.put("timestamp", new Date());
return ResponseEntity.ok(response);
}
/**
* 管理操作视频
* @param videoRequest 视频请求
* @return 操作结果
*/
@PostMapping("/operation-video")
public ResponseEntity<Map<String, Object>> manageOperationVideo(@RequestBody VideoRequest videoRequest) {
// 实际应用中这里会更新设备操作视频
Map<String, Object> response = new HashMap<>();
response.put("code", 200);
response.put("message", "操作视频已更新");
// response.put("deviceId", videoRequest.getDeviceId());
// response.put("videoUrl", videoRequest.getVideoUrl());
return ResponseEntity.ok(response);
}
// 请求对象类定义
public static class LightModeRequest {
private String deviceId;
private String mode; // 强光、弱光、爆闪、泛光、激光
// Getters and Setters
}
public static class PersonInfo {
private String deviceId;
private String unit; // 单位
private String position; // 职位
// Getters and Setters
}
public static class BootScreenRequest {
private String deviceId;
private List<String> screens; // 产品参数、操作说明等
// Getters and Setters
}
public static class BrightnessRequest {
private String deviceId;
private int brightness; // 0-100
private boolean forceAlarm; // 强制报警
// Getters and Setters
}
public static class MessageRequest {
private String deviceId;
private String content; // 消息内容
// Getters and Setters
}
public static class VideoRequest {
private String deviceId;
private String videoUrl; // 视频链接
// Getters and Setters
}
}

View File

@ -0,0 +1,109 @@
package com.fuyuanshen.web.controller.device;
import java.util.List;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
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
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/device/group")
public class DeviceGroupController extends BaseController {
private final IDeviceGroupService deviceGroupService;
/**
* 查询设备分组列表
*/
@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 主键
*/
@SaCheckPermission("fys-equipment:group:query")
@GetMapping("/{id}")
public R<DeviceGroupVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
return R.ok(deviceGroupService.queryById(id));
}
/**
* 新增设备分组
*/
@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));
}
/**
* 修改设备分组
*/
@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 主键串
*/
@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));
}
}

View File

@ -1,270 +1,318 @@
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("客户端操作");
}
}
deviceLogMapper.insert(record);
}
if (root.has("imei")) {
// 设备行为
record.setDeviceAction(InstructType6170.fromCode(0).getDescription());
record.setDataSource("设备上报");
record.setContent("设备启动");
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 StateRecord parseState(Device device, JsonNode array) {
// StateRecord record = new StateRecord();
// record.setDevice(device);
// record.setStateType(array.get(0).asInt());
//
// switch (record.getStateType()) {
// case 1: // 灯光状态
// record.setLightMode(array.get(1).asInt());
// record.setBrightness(array.get(2).asInt());
// break;
//
// case 2: // 设置结果
// record.setSetResult(array.get(1).asInt() == 1);
// break;
//
// case 3: // 图片更新状态
// record.setImagePage(array.get(1).asInt());
// break;
//
// case 4: // 激光灯状态
// record.setLaserStatus(array.get(1).asInt() == 1);
// break;
//
// case 5: // 亮度状态
// record.setBrightness(array.get(1).asInt());
// break;
//
// case 11: // 定位上报
// record.setLatitude(array.get(1).asDouble());
// record.setLongitude(array.get(2).asDouble());
// break;
//
// case 12: // 设备状态
// record.setMainLightGear(array.get(1).asInt());
// record.setLaserLightGear(array.get(2).asInt());
// record.setBattery(array.get(3).asInt());
// record.setChargeStatus(array.get(4).asInt());
// record.setDuration(array.get(5).asInt());
// break;
// }
// return record;
// }
}
//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;
// }
//
//}

View File

@ -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) {
// }
//}

View File

@ -1,7 +1,7 @@
--- # 监控中心配置
spring.boot.admin.client:
# 增加客户端开关
enabled: true
enabled: false
url: http://localhost:9090/admin
instance:
service-host-type: IP

View File

@ -4,7 +4,7 @@ spring.servlet.multipart.location: /fys/server/temp
--- # 监控中心配置
spring.boot.admin.client:
# 增加客户端开关
enabled: true
enabled: false
url: http://localhost:9090/admin
instance:
service-host-type: IP
@ -16,7 +16,7 @@ spring.boot.admin.client:
--- # snail-job 配置
snail-job:
enabled: true
enabled: false
# 需要在 SnailJob 后台组管理创建对应名称的组,然后创建任务的时候选择对应的组,才能正确分派任务
group: "fys_group"
# SnailJob 接入验证令牌 详见 script/sql/ry_job.sql `sj_group_config`表
@ -52,9 +52,9 @@ spring:
driverClassName: com.mysql.cj.jdbc.Driver
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
# rewriteBatchedStatements=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
url: jdbc:mysql://47.120.79.150:3306/fys-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
username: root
password: Jz_5623_cl1
password: Jq_123456#
# # 从库数据源
# slave:
# lazy: true
@ -101,13 +101,13 @@ spring:
spring.data:
redis:
# 地址
host: localhost
host: 47.120.79.150
# 端口默认为6379
port: 6379
# 数据库索引
database: 1
# redis 密码必须配置
password: re_fs_11520631
password: xhYc_djkl382^#780!
# 连接超时时间
timeout: 10s
# 是否开启ssl
@ -177,11 +177,14 @@ sms:
# 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
supplier: alibaba
# 有些称为accessKey有些称之为apiKey也有称为sdkKey或者appId。
access-key-id: 您的accessKey
access-key-id: LTAI5tJdDNpZootsPQ5hdELx
# 称为accessSecret有些称之为apiSecret
access-key-secret: 您的accessKeySecret
signature: 您的短信签名
sdk-app-id: 您的sdkAppId
access-key-secret: mU4WtffcCXpHPz5tLwQpaGtLsJXONt
#模板ID 非必须配置如果使用sendMessage的快速发送需此配置
template-id: SMS_322180518
#模板变量 上述模板的变量
templateName: code
signature: 湖北星汉研创科技
config2:
# 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
supplier: tencent
@ -280,8 +283,8 @@ mqtt:
password: #YtvpSfCNG
url: tcp://47.120.79.150:2883
subClientId: fys_subClient
subTopic: worker/alert/#,worker/location/#
pubTopic: worker/location
subTopic: A/#,B/#,worker/location/#
pubTopic: B/#
pubClientId: fys_pubClient

View File

@ -64,7 +64,7 @@ spring:
# 国际化资源文件路径
basename: i18n/messages
profiles:
active: @profiles.active@
active: ${profiles.active}
# 文件上传
servlet:
multipart:

View File

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

View File

@ -99,4 +99,9 @@ public class AppDeviceDetailVo {
// 逆解析地址
private String address;
/**
* 告警状态(0解除告警1告警)
*/
private String alarmStatus;
}

View File

@ -104,4 +104,38 @@ 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;
}

View File

@ -57,6 +57,12 @@ public class AppDeviceShareVo implements Serializable {
@ExcelProperty(value = "手机号")
private String phonenumber;
/**
* 他人分享手机号
*/
@ExcelProperty(value = "手机号")
private String otherPhonenumber;
/**
* 功能权限1灯光模式2激光模式3开机画面4人员信息登记5发送信息6产品信息
以逗号分隔
@ -73,4 +79,29 @@ 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;
}

View File

@ -1,5 +1,6 @@
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;
@ -16,4 +17,6 @@ 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);
}

View File

@ -5,6 +5,47 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace="com.fuyuanshen.app.mapper.AppDeviceShareMapper">
<select id="otherDeviceShareList" resultType="com.fuyuanshen.app.domain.vo.AppDeviceShareVo">
SELECT * FROM app_device_share a where a.phonenumber = #{bo.phonenumber}
select d.device_name, d.device_name,
d.device_name,
d.device_mac,
d.device_sn,
d.device_imei,
d.device_pic,
dt.type_name,
dt.communication_mode,
d.bluetooth_name,
c.binding_time,
ad.*,u.user_name otherPhonenumber
from
app_device_share ad
left join device d on ad.device_id = d.id
left join app_user u on ad.create_by = u.user_id
inner join device_type dt on d.device_type = dt.id
inner join app_device_bind_record c on d.id = c.device_id
where ad.phonenumber = #{bo.phonenumber}
</select>
<select id="selectAppDeviceShareList" resultType="com.fuyuanshen.app.domain.vo.AppDeviceShareVo">
select d.device_name, d.device_name,
d.device_name,
d.device_mac,
d.device_sn,
d.device_imei,
d.device_pic,
dt.type_name,
dt.communication_mode,
d.bluetooth_name,
c.binding_time,
ad.*,u.user_name otherPhonenumber
from
app_device_share ad
left join device d on ad.device_id = d.id
left join app_user u on ad.create_by = u.user_id
inner join device_type dt on d.device_type = dt.id
inner join app_device_bind_record c on d.id = c.device_id
where ad.create_by = #{bo.createBy}
<if test="bo.deviceId != null">
and ad.device_id = #{bo.deviceId}
</if>
</select>
</mapper>

View File

@ -0,0 +1,105 @@
package com.fuyuanshen.equipment.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.equipment.domain.vo.DeviceRepairRecordsVo;
import com.fuyuanshen.equipment.domain.bo.DeviceRepairRecordsBo;
import com.fuyuanshen.equipment.service.IDeviceRepairRecordsService;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
/**
* 设备维修记录
*
* @author Lion Li
* @date 2025-08-08
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/equipment/repairRecords")
public class DeviceRepairRecordsController extends BaseController {
private final IDeviceRepairRecordsService deviceRepairRecordsService;
/**
* 查询设备维修记录列表
*/
@SaCheckPermission("equipment:repairRecords:list")
@GetMapping("/list")
public TableDataInfo<DeviceRepairRecordsVo> list(DeviceRepairRecordsBo bo, PageQuery pageQuery) {
return deviceRepairRecordsService.queryPageList(bo, pageQuery);
}
/**
* 导出设备维修记录列表
*/
@SaCheckPermission("equipment:repairRecords:export")
@Log(title = "设备维修记录", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(DeviceRepairRecordsBo bo, HttpServletResponse response) {
List<DeviceRepairRecordsVo> list = deviceRepairRecordsService.queryList(bo);
ExcelUtil.exportExcel(list, "设备维修记录", DeviceRepairRecordsVo.class, response);
}
/**
* 获取设备维修记录详细信息
*
* @param recordId 主键
*/
@SaCheckPermission("equipment:repairRecords:query")
@GetMapping("/{recordId}")
public R<DeviceRepairRecordsVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long recordId) {
return R.ok(deviceRepairRecordsService.queryById(recordId));
}
/**
* 新增设备维修记录
*/
@SaCheckPermission("equipment:repairRecords:add")
@Log(title = "设备维修记录", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody DeviceRepairRecordsBo bo) {
return toAjax(deviceRepairRecordsService.insertByBo(bo));
}
/**
* 修改设备维修记录
*/
@SaCheckPermission("equipment:repairRecords:edit")
@Log(title = "设备维修记录", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody DeviceRepairRecordsBo bo) {
return toAjax(deviceRepairRecordsService.updateByBo(bo));
}
/**
* 删除设备维修记录
*
* @param recordIds 主键串
*/
@SaCheckPermission("equipment:repairRecords:remove")
@Log(title = "设备维修记录", businessType = BusinessType.DELETE)
@DeleteMapping("/{recordIds}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] recordIds) {
return toAjax(deviceRepairRecordsService.deleteWithValidByIds(List.of(recordIds), true));
}
}

View File

@ -0,0 +1,56 @@
package com.fuyuanshen.equipment.domain;
import com.fuyuanshen.common.tenant.core.TenantEntity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
/**
* 设备分组对象 device_group
*
* @author Lion Li
* @date 2025-08-08
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("device_group")
public class DeviceGroup extends TenantEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 分组名称
*/
private String groupName;
/**
* 状态0-禁用1-正常
*/
private Long status;
/**
* 父分组ID
*/
private Long parentId;
/**
* 完整分组路径
*/
private String fullPath;
/**
* 删除标记0-未删除1-已删除
*/
private Long isDeleted;
}

View File

@ -0,0 +1,58 @@
package com.fuyuanshen.equipment.domain;
import com.fuyuanshen.common.tenant.core.TenantEntity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serial;
/**
* 设备维修记录对象 device_repair_records
*
* @author Lion Li
* @date 2025-08-08
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("device_repair_records")
public class DeviceRepairRecords extends TenantEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
* 维修记录ID
*/
@TableId(value = "record_id")
private Long recordId;
/**
* 设备ID
*/
private String deviceId;
/**
* 维修时间
*/
private Date repairTime;
/**
* 维修部位
*/
private String repairPart;
/**
* 维修原因
*/
private String repairReason;
/**
* 维修人员
*/
private String repairPerson;
}

View File

@ -0,0 +1,65 @@
package com.fuyuanshen.equipment.domain.bo;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.core.validate.EditGroup;
import com.fuyuanshen.equipment.domain.DeviceGroup;
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
import io.github.linpeilie.annotations.AutoMapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
/**
* 设备分组业务对象 device_group
*
* @author Lion Li
* @date 2025-08-08
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = DeviceGroup.class, reverseConvertGenerate = false)
public class DeviceGroupBo extends BaseEntity {
/**
* 主键ID
*/
// @NotNull(message = "主键ID不能为空", groups = { EditGroup.class })
private Long id;
/**
* 分组名称
*/
@NotBlank(message = "分组名称不能为空", groups = { AddGroup.class, EditGroup.class })
private String groupName;
/**
* 状态0-禁用1-正常
*/
// @NotNull(message = "状态0-禁用1-正常不能为空", groups = { AddGroup.class, EditGroup.class })
private Long status;
/**
* 父分组ID
*/
private Long parentId;
/**
* 完整分组路径
*/
private String fullPath;
/**
* 删除标记0-未删除1-已删除
*/
// @NotNull(message = "删除标记0-未删除1-已删除不能为空", groups = { AddGroup.class, EditGroup.class })
private Long isDeleted;
@Schema(name = "页码", example = "1")
private Integer pageNum = 1;
@Schema(name = "每页数据量", example = "10")
private Integer pageSize = 10;
}

View File

@ -0,0 +1,62 @@
package com.fuyuanshen.equipment.domain.bo;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.core.validate.EditGroup;
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
/**
* 设备维修记录业务对象 device_repair_records
*
* @author Lion Li
* @date 2025-08-08
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = DeviceRepairRecords.class, reverseConvertGenerate = false)
public class DeviceRepairRecordsBo extends BaseEntity {
/**
* 维修记录ID
*/
@NotNull(message = "维修记录ID不能为空", groups = { EditGroup.class })
private Long recordId;
/**
* 设备ID
*/
@NotBlank(message = "设备ID不能为空", groups = { AddGroup.class, EditGroup.class })
private String deviceId;
/**
* 维修时间
*/
@NotNull(message = "维修时间不能为空", groups = { AddGroup.class, EditGroup.class })
private Date repairTime;
/**
* 维修部位
*/
@NotBlank(message = "维修部位不能为空", groups = { AddGroup.class, EditGroup.class })
private String repairPart;
/**
* 维修原因
*/
@NotBlank(message = "维修原因不能为空", groups = { AddGroup.class, EditGroup.class })
private String repairReason;
/**
* 维修人员
*/
@NotBlank(message = "维修人员不能为空", groups = { AddGroup.class, EditGroup.class })
private String repairPerson;
}

View File

@ -76,4 +76,9 @@ public class AppDeviceVo implements Serializable {
* 经度
*/
private String longitude;
/**
* 告警状态(0解除告警1告警)
*/
private String alarmStatus;
}

View File

@ -0,0 +1,79 @@
package com.fuyuanshen.equipment.domain.vo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fuyuanshen.equipment.domain.DeviceGroup;
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;
import java.util.List;
/**
* 设备分组视图对象 device_group
*
* @author Lion Li
* @date 2025-08-08
*/
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = DeviceGroup.class)
public class DeviceGroupVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@ExcelProperty(value = "主键ID")
private Long id;
/**
* 分组名称
*/
@ExcelProperty(value = "分组名称")
private String groupName;
/**
* 状态0-禁用1-正常
*/
@ExcelProperty(value = "状态0-禁用1-正常")
private String status;
/**
* 父分组ID
*/
@ExcelProperty(value = "父分组ID")
private Long parentId;
/**
* 完整分组路径
*/
@ExcelProperty(value = "完整分组路径")
private String fullPath;
/**
* 删除标记0-未删除1-已删除
*/
@ExcelProperty(value = "删除标记0-未删除1-已删除")
private Long isDeleted;
/**
* 嵌套子分组
*/
private List<DeviceGroupVo> children;
/**
* 创建时间
*/
private String createTime;
}

View File

@ -0,0 +1,70 @@
package com.fuyuanshen.equipment.domain.vo;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import com.fuyuanshen.common.excel.annotation.ExcelDictFormat;
import com.fuyuanshen.common.excel.convert.ExcelDictConvert;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 设备维修记录视图对象 device_repair_records
*
* @author Lion Li
* @date 2025-08-08
*/
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = DeviceRepairRecords.class)
public class DeviceRepairRecordsVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 维修记录ID
*/
@ExcelProperty(value = "维修记录ID")
private Long recordId;
/**
* 设备ID
*/
@ExcelProperty(value = "设备ID")
private String deviceId;
/**
* 维修时间
*/
@ExcelProperty(value = "维修时间")
private Date repairTime;
/**
* 维修部位
*/
@ExcelProperty(value = "维修部位")
private String repairPart;
/**
* 维修原因
*/
@ExcelProperty(value = "维修原因")
private String repairReason;
/**
* 维修人员
*/
@ExcelProperty(value = "维修人员")
private String repairPerson;
}

View File

@ -0,0 +1,38 @@
package com.fuyuanshen.equipment.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.DeviceGroup;
import com.fuyuanshen.equipment.domain.bo.DeviceGroupBo;
import com.fuyuanshen.equipment.domain.vo.DeviceGroupVo;
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 设备分组Mapper接口
*
* @author Lion Li
* @date 2025-08-08
*/
public interface DeviceGroupMapper extends BaseMapperPlus<DeviceGroup, DeviceGroupVo> {
/**
* 查询设备分组列表
*
* @param bo 设备分组
* @return 设备分组
*/
IPage<DeviceGroup> selectRootGroups(@Param("bo") DeviceGroupBo bo, Page<Device> page);
/**
* 查询子分组
*
* @param id
* @return
*/
List<DeviceGroup> selectByParentId(Long id);
}

View File

@ -66,4 +66,5 @@ public interface DeviceMapper extends BaseMapper<Device> {
* @return
*/
List<Device> findByOriginalDeviceId(Long originalDeviceId);
}

View File

@ -0,0 +1,15 @@
package com.fuyuanshen.equipment.mapper;
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
import com.fuyuanshen.equipment.domain.vo.DeviceRepairRecordsVo;
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
/**
* 设备维修记录Mapper接口
*
* @author Lion Li
* @date 2025-08-08
*/
public interface DeviceRepairRecordsMapper extends BaseMapperPlus<DeviceRepairRecords, DeviceRepairRecordsVo> {
}

View File

@ -0,0 +1,59 @@
package com.fuyuanshen.equipment.service;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.equipment.domain.vo.DeviceGroupVo;
import com.fuyuanshen.equipment.domain.bo.DeviceGroupBo;
import java.util.Collection;
import java.util.List;
/**
* 设备分组Service接口
*
* @author Lion Li
* @date 2025-08-08
*/
public interface IDeviceGroupService {
/**
* 查询设备分组
*
* @param id 主键
* @return 设备分组
*/
DeviceGroupVo queryById(Long id);
/**
* 查询符合条件的设备分组列表
*
* @param bo 查询条件
* @return 设备分组列表
*/
List<DeviceGroupVo> queryList(DeviceGroupBo bo);
/**
* 新增设备分组
*
* @param bo 设备分组
* @return 是否新增成功
*/
Boolean insertByBo(DeviceGroupBo bo);
/**
* 修改设备分组
*
* @param bo 设备分组
* @return 是否修改成功
*/
Boolean updateByBo(DeviceGroupBo bo);
/**
* 校验并批量删除设备分组信息
*
* @param ids 待删除的主键集合
* @param isValid 是否进行有效性校验
* @return 是否删除成功
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}

View File

@ -0,0 +1,68 @@
package com.fuyuanshen.equipment.service;
import com.fuyuanshen.equipment.domain.vo.DeviceRepairRecordsVo;
import com.fuyuanshen.equipment.domain.bo.DeviceRepairRecordsBo;
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 Lion Li
* @date 2025-08-08
*/
public interface IDeviceRepairRecordsService {
/**
* 查询设备维修记录
*
* @param recordId 主键
* @return 设备维修记录
*/
DeviceRepairRecordsVo queryById(Long recordId);
/**
* 分页查询设备维修记录列表
*
* @param bo 查询条件
* @param pageQuery 分页参数
* @return 设备维修记录分页列表
*/
TableDataInfo<DeviceRepairRecordsVo> queryPageList(DeviceRepairRecordsBo bo, PageQuery pageQuery);
/**
* 查询符合条件的设备维修记录列表
*
* @param bo 查询条件
* @return 设备维修记录列表
*/
List<DeviceRepairRecordsVo> queryList(DeviceRepairRecordsBo bo);
/**
* 新增设备维修记录
*
* @param bo 设备维修记录
* @return 是否新增成功
*/
Boolean insertByBo(DeviceRepairRecordsBo bo);
/**
* 修改设备维修记录
*
* @param bo 设备维修记录
* @return 是否修改成功
*/
Boolean updateByBo(DeviceRepairRecordsBo bo);
/**
* 校验并批量删除设备维修记录信息
*
* @param ids 待删除的主键集合
* @param isValid 是否进行有效性校验
* @return 是否删除成功
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}

View File

@ -0,0 +1,172 @@
package com.fuyuanshen.equipment.service.impl;
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.common.core.domain.R;
import com.fuyuanshen.common.core.utils.MapstructUtils;
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.satoken.utils.LoginHelper;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.DeviceTypeGrants;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.fuyuanshen.equipment.domain.bo.DeviceGroupBo;
import com.fuyuanshen.equipment.domain.vo.DeviceGroupVo;
import com.fuyuanshen.equipment.domain.DeviceGroup;
import com.fuyuanshen.equipment.mapper.DeviceGroupMapper;
import com.fuyuanshen.equipment.service.IDeviceGroupService;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.stream.Collectors;
/**
* 设备分组Service业务层处理
*
* @author Lion Li
* @date 2025-08-08
*/
@Slf4j
@RequiredArgsConstructor
@Service
public class DeviceGroupServiceImpl implements IDeviceGroupService {
private final DeviceGroupMapper baseMapper;
/**
* 查询设备分组
*
* @param id 主键
* @return 设备分组
*/
@Override
public DeviceGroupVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
/**
* 查询符合条件的设备分组列表
*
* @param bo 查询条件
* @return 设备分组列表
*/
@Override
public List<DeviceGroupVo> queryList(DeviceGroupBo bo) {
Page<Device> page = new Page<>(bo.getPageNum(), bo.getPageSize());
// 1. 查询顶级分组parent_id为null
IPage<DeviceGroup> rootGroups = baseMapper.selectRootGroups(bo, page);
List<DeviceGroup> records = rootGroups.getRecords();
// 2. 递归构建树形结构
return records.stream()
.map(this::buildGroupTree)
.collect(Collectors.toList());
}
private DeviceGroupVo buildGroupTree(DeviceGroup group) {
DeviceGroupVo vo = convertToVO(group);
// 递归查询子分组
List<DeviceGroup> children = baseMapper.selectByParentId(group.getId());
vo.setChildren(children.stream()
.map(this::buildGroupTree)
.collect(Collectors.toList()));
return vo;
}
private DeviceGroupVo convertToVO(DeviceGroup group) {
DeviceGroupVo vo = new DeviceGroupVo();
vo.setId(group.getId());
vo.setGroupName(group.getGroupName());
vo.setStatus(group.getStatus() == 1 ? "正常" : "禁用");
vo.setCreateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(group.getCreateTime()));
return vo;
}
private LambdaQueryWrapper<DeviceGroup> buildQueryWrapper(DeviceGroupBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<DeviceGroup> lqw = Wrappers.lambdaQuery();
lqw.orderByAsc(DeviceGroup::getId);
lqw.like(StringUtils.isNotBlank(bo.getGroupName()), DeviceGroup::getGroupName, bo.getGroupName());
lqw.eq(bo.getStatus() != null, DeviceGroup::getStatus, bo.getStatus());
lqw.eq(bo.getParentId() != null, DeviceGroup::getParentId, bo.getParentId());
lqw.eq(StringUtils.isNotBlank(bo.getFullPath()), DeviceGroup::getFullPath, bo.getFullPath());
lqw.eq(bo.getIsDeleted() != null, DeviceGroup::getIsDeleted, bo.getIsDeleted());
return lqw;
}
/**
* 新增设备分组
*
* @param bo 设备分组
* @return 是否新增成功
*/
@Override
public Boolean insertByBo(DeviceGroupBo bo) {
// 验证分组名称唯一性
DeviceGroup deviceGroup = baseMapper.selectOne(new QueryWrapper<DeviceGroup>().eq("group_name", bo.getGroupName()));
if (deviceGroup != null) {
throw new RuntimeException("分组名称已存在,请勿重复添加!!!");
}
// 验证父分组是否存在如果提供了parentId
DeviceGroup pDeviceGroup = baseMapper.selectById(bo.getParentId());
if (bo.getParentId() != null && pDeviceGroup == null) {
throw new RuntimeException("父分组不存在!!!");
}
DeviceGroup add = MapstructUtils.convert(bo, DeviceGroup.class);
// validEntityBeforeSave(add);
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setId(add.getId());
}
return flag;
}
/**
* 修改设备分组
*
* @param bo 设备分组
* @return 是否修改成功
*/
@Override
public Boolean updateByBo(DeviceGroupBo bo) {
DeviceGroup update = MapstructUtils.convert(bo, DeviceGroup.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(DeviceGroup entity) {
// TODO 做一些数据校验,如唯一约束
}
/**
* 校验并批量删除设备分组信息
*
* @param ids 待删除的主键集合
* @param isValid 是否进行有效性校验
* @return 是否删除成功
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) {
// TODO 做一些业务上的校验,判断是否需要校验
}
return baseMapper.deleteByIds(ids) > 0;
}
}

View File

@ -0,0 +1,136 @@
package com.fuyuanshen.equipment.service.impl;
import com.fuyuanshen.common.core.utils.MapstructUtils;
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.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.fuyuanshen.equipment.domain.bo.DeviceRepairRecordsBo;
import com.fuyuanshen.equipment.domain.vo.DeviceRepairRecordsVo;
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
import com.fuyuanshen.equipment.mapper.DeviceRepairRecordsMapper;
import com.fuyuanshen.equipment.service.IDeviceRepairRecordsService;
import java.util.List;
import java.util.Map;
import java.util.Collection;
/**
* 设备维修记录Service业务层处理
*
* @author Lion Li
* @date 2025-08-08
*/
@Slf4j
@RequiredArgsConstructor
@Service
public class DeviceRepairRecordsServiceImpl implements IDeviceRepairRecordsService {
private final DeviceRepairRecordsMapper baseMapper;
/**
* 查询设备维修记录
*
* @param recordId 主键
* @return 设备维修记录
*/
@Override
public DeviceRepairRecordsVo queryById(Long recordId){
return baseMapper.selectVoById(recordId);
}
/**
* 分页查询设备维修记录列表
*
* @param bo 查询条件
* @param pageQuery 分页参数
* @return 设备维修记录分页列表
*/
@Override
public TableDataInfo<DeviceRepairRecordsVo> queryPageList(DeviceRepairRecordsBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<DeviceRepairRecords> lqw = buildQueryWrapper(bo);
Page<DeviceRepairRecordsVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询符合条件的设备维修记录列表
*
* @param bo 查询条件
* @return 设备维修记录列表
*/
@Override
public List<DeviceRepairRecordsVo> queryList(DeviceRepairRecordsBo bo) {
LambdaQueryWrapper<DeviceRepairRecords> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<DeviceRepairRecords> buildQueryWrapper(DeviceRepairRecordsBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<DeviceRepairRecords> lqw = Wrappers.lambdaQuery();
lqw.orderByAsc(DeviceRepairRecords::getRecordId);
lqw.eq(StringUtils.isNotBlank(bo.getDeviceId()), DeviceRepairRecords::getDeviceId, bo.getDeviceId());
lqw.eq(bo.getRepairTime() != null, DeviceRepairRecords::getRepairTime, bo.getRepairTime());
lqw.eq(StringUtils.isNotBlank(bo.getRepairPart()), DeviceRepairRecords::getRepairPart, bo.getRepairPart());
lqw.eq(StringUtils.isNotBlank(bo.getRepairReason()), DeviceRepairRecords::getRepairReason, bo.getRepairReason());
lqw.eq(StringUtils.isNotBlank(bo.getRepairPerson()), DeviceRepairRecords::getRepairPerson, bo.getRepairPerson());
return lqw;
}
/**
* 新增设备维修记录
*
* @param bo 设备维修记录
* @return 是否新增成功
*/
@Override
public Boolean insertByBo(DeviceRepairRecordsBo bo) {
DeviceRepairRecords add = MapstructUtils.convert(bo, DeviceRepairRecords.class);
validEntityBeforeSave(add);
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setRecordId(add.getRecordId());
}
return flag;
}
/**
* 修改设备维修记录
*
* @param bo 设备维修记录
* @return 是否修改成功
*/
@Override
public Boolean updateByBo(DeviceRepairRecordsBo bo) {
DeviceRepairRecords update = MapstructUtils.convert(bo, DeviceRepairRecords.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(DeviceRepairRecords entity){
//TODO 做一些数据校验,如唯一约束
}
/**
* 校验并批量删除设备维修记录信息
*
* @param ids 待删除的主键集合
* @param isValid 是否进行有效性校验
* @return 是否删除成功
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
}
return baseMapper.deleteByIds(ids) > 0;
}
}

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuyuanshen.equipment.mapper.DeviceGroupMapper">
<!-- 查询顶级分组 -->
<select id="selectRootGroups" resultType="DeviceGroup">
SELECT * FROM device_group
WHERE parent_id IS NULL
<if test="bo.groupName != null and bo.groupName != ''">
AND group_name LIKE CONCAT('%', #{bo.groupName}, '%')
</if>
<if test="bo.status != null">
AND status = #{bo.status}
</if>
ORDER BY create_time DESC
</select>
<!-- 根据父ID查询子分组 -->
<select id="selectByParentId" resultType="DeviceGroup">
SELECT *
FROM device_group
WHERE parent_id = #{parentId}
ORDER BY create_time DESC
</select>
</mapper>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuyuanshen.equipment.mapper.DeviceRepairRecordsMapper">
</mapper>