修改在线上报状态

This commit is contained in:
2025-08-08 15:09:59 +08:00
parent 41c6cb935d
commit 47dbd33d56
5 changed files with 557 additions and 554 deletions

View File

@ -134,13 +134,13 @@ public class AppDeviceBJQBizService {
vo.setPersonnelInfo(personnelInfoVo); 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)){ if(StringUtils.isNotBlank(onlineStatus)){
vo.setOnlineStatus(1); vo.setOnlineStatus(1);
}else{ }else{
vo.setOnlineStatus(0); 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_STATUS_KEY_PREFIX);
// 获取电量 // 获取电量
if(StringUtils.isNotBlank(deviceStatus)){ if(StringUtils.isNotBlank(deviceStatus)){
JSONObject jsonObject = JSONObject.parseObject(deviceStatus); JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
@ -154,7 +154,7 @@ public class AppDeviceBJQBizService {
} }
// 获取经度纬度 // 获取经度纬度
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + device.getDeviceImei(); String locationKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
String locationInfo = RedisUtils.getCacheObject(locationKey); String locationInfo = RedisUtils.getCacheObject(locationKey);
if(StringUtils.isNotBlank(locationInfo)){ if(StringUtils.isNotBlank(locationInfo)){
JSONObject jsonObject = JSONObject.parseObject(locationInfo); JSONObject jsonObject = JSONObject.parseObject(locationInfo);

View File

@ -1,61 +1,61 @@
package com.fuyuanshen.web.config; //package com.fuyuanshen.web.config;
//
import cn.hutool.core.lang.UUID; //import cn.hutool.core.lang.UUID;
import com.fuyuanshen.global.mqtt.config.MqttPropertiesConfig; //import com.fuyuanshen.global.mqtt.config.MqttPropertiesConfig;
import com.fuyuanshen.web.handler.mqtt.DeviceReceiverMessageHandler; //import com.fuyuanshen.web.handler.mqtt.DeviceReceiverMessageHandler;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; //import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.ServiceActivator; //import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel; //import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.core.MessageProducer; //import org.springframework.integration.core.MessageProducer;
import org.springframework.integration.mqtt.core.MqttPahoClientFactory; //import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter; //import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter; //import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
import org.springframework.messaging.MessageChannel; //import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler; //import org.springframework.messaging.MessageHandler;
//
/** ///**
* @author: 默苍璃 // * @author: 默苍璃
* @date: 2025-08-0110:46 // * @date: 2025-08-0110:46
*/ // */
@Configuration //@Configuration
public class CustomMqttInboundConfiguration { //public class CustomMqttInboundConfiguration {
//
@Autowired // @Autowired
private MqttPropertiesConfig mqttPropertiesConfig; // private MqttPropertiesConfig mqttPropertiesConfig;
@Autowired // @Autowired
private MqttPahoClientFactory mqttPahoClientFactory; // private MqttPahoClientFactory mqttPahoClientFactory;
@Autowired // @Autowired
private DeviceReceiverMessageHandler deviceReceiverMessageHandler; // private DeviceReceiverMessageHandler deviceReceiverMessageHandler;
//
//
@Bean // @Bean
public MessageChannel customMqttChannel(){ // public MessageChannel customMqttChannel(){
return new DirectChannel(); // return new DirectChannel();
} // }
//
//
@Bean // @Bean
public MessageProducer customMessageProducer(){ // public MessageProducer customMessageProducer(){
String clientId = "custom_client_" + UUID.fastUUID(); // String clientId = "custom_client_" + UUID.fastUUID();
MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter( // MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(
mqttPropertiesConfig.getUrl(), // mqttPropertiesConfig.getUrl(),
clientId, // clientId,
mqttPahoClientFactory, // mqttPahoClientFactory,
"A/#", "B/#" // 直接指定这两个主题 // "A/#", "B/#" // 直接指定这两个主题
); // );
adapter.setQos(1); // adapter.setQos(1);
adapter.setConverter(new DefaultPahoMessageConverter()); // adapter.setConverter(new DefaultPahoMessageConverter());
adapter.setOutputChannel(customMqttChannel()); // adapter.setOutputChannel(customMqttChannel());
return adapter; // return adapter;
} // }
//
//
@Bean // @Bean
@ServiceActivator(inputChannel = "customMqttChannel") // @ServiceActivator(inputChannel = "customMqttChannel")
public MessageHandler customMessageHandler(){ // public MessageHandler customMessageHandler(){
return deviceReceiverMessageHandler; // return deviceReceiverMessageHandler;
} // }
//
} //}

View File

@ -1,318 +1,318 @@
package com.fuyuanshen.web.handler.mqtt; //package com.fuyuanshen.web.handler.mqtt;
//
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; //import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.JsonNode; //import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; //import com.fasterxml.jackson.databind.ObjectMapper;
import com.fuyuanshen.common.satoken.utils.LoginHelper; //import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.equipment.domain.Device; //import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.DeviceLog; //import com.fuyuanshen.equipment.domain.DeviceLog;
import com.fuyuanshen.equipment.mapper.DeviceLogMapper; //import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
import com.fuyuanshen.equipment.mapper.DeviceMapper; //import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil; //import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
import com.fuyuanshen.equipment.utils.map.LngLonUtil; //import com.fuyuanshen.equipment.utils.map.LngLonUtil;
import com.fuyuanshen.global.mqtt.constants.TenantsConstant; //import com.fuyuanshen.global.mqtt.constants.TenantsConstant;
import com.fuyuanshen.web.enums.InstructType6170; //import com.fuyuanshen.web.enums.InstructType6170;
import com.fuyuanshen.web.enums.LightModeEnum6170; //import com.fuyuanshen.web.enums.LightModeEnum6170;
import lombok.AllArgsConstructor; //import lombok.AllArgsConstructor;
import lombok.Data; //import lombok.Data;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.Message; //import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler; //import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHeaders; //import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException; //import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
/** ///**
* 定义监听主题消息的处理器 // * 定义监听主题消息的处理器
* // *
* @author: 默苍璃 // * @author: 默苍璃
* @date: 2025-08-0110:19 // * @date: 2025-08-0110:19
*/ // */
@Component //@Component
@Data //@Data
@AllArgsConstructor //@AllArgsConstructor
@Slf4j //@Slf4j
public class DeviceReceiverMessageHandler implements MessageHandler { //public class DeviceReceiverMessageHandler implements MessageHandler {
//
private final DeviceMapper deviceMapper; // private final DeviceMapper deviceMapper;
private final DeviceLogMapper deviceLogMapper; // private final DeviceLogMapper deviceLogMapper;
//
// 使用Jackson解析JSON // // 使用Jackson解析JSON
private static final ObjectMapper objectMapper = new ObjectMapper(); // private static final ObjectMapper objectMapper = new ObjectMapper();
//
//
/** // /**
* 处理接收的消息 // * 处理接收的消息
* // *
* @param message // * @param message
* @throws MessagingException // * @throws MessagingException
*/ // */
@Override // @Override
public void handleMessage(Message<?> message) throws MessagingException { // public void handleMessage(Message<?> message) throws MessagingException {
// System.out.println("接收到的消息:" + message.getPayload()); // // System.out.println("接收到的消息:" + message.getPayload());
MessageHeaders headers = message.getHeaders(); // MessageHeaders headers = message.getHeaders();
String receivedTopicName = (String) headers.get("mqtt_receivedTopic"); // String receivedTopicName = (String) headers.get("mqtt_receivedTopic");
System.out.println("消息来自主题:" + receivedTopicName); // System.out.println("消息来自主题:" + receivedTopicName);
//
// String tenantId = LoginHelper.getTenantId(); // // String tenantId = LoginHelper.getTenantId();
String tenantId = TenantsConstant.FU_YUAN_SHENG; // String tenantId = TenantsConstant.FU_YUAN_SHENG;
String payload = message.getPayload().toString(); // String payload = message.getPayload().toString();
//
if (receivedTopicName != null) { // if (receivedTopicName != null) {
// 1. 提取设备ID (从主题中获取) // // 1. 提取设备ID (从主题中获取)
String deviceImei = extractDeviceId(receivedTopicName); // String deviceImei = extractDeviceId(receivedTopicName);
Device device = deviceMapper.selectOne(new QueryWrapper<Device>() // Device device = deviceMapper.selectOne(new QueryWrapper<Device>()
.eq("tenant_id", tenantId) // .eq("tenant_id", tenantId)
.eq("device_imei", deviceImei)); // .eq("device_imei", deviceImei));
if (device == null) { // if (device == null) {
log.info("不存在的设备IMEI: {}", deviceImei); // log.info("不存在的设备IMEI: {}", deviceImei);
} else { // } else {
//
try { // try {
JsonNode root = objectMapper.readTree(payload); // JsonNode root = objectMapper.readTree(payload);
//
DeviceLog record = new DeviceLog(); // DeviceLog record = new DeviceLog();
// 手动设置租户ID // // 手动设置租户ID
record.setTenantId(device.getTenantId()); // 从设备信息中获取租户ID // record.setTenantId(device.getTenantId()); // 从设备信息中获取租户ID
// 设备ID // // 设备ID
record.setDeviceId(device.getId()); // record.setDeviceId(device.getId());
// 设备名称 // // 设备名称
record.setDeviceName(device.getDeviceName()); // record.setDeviceName(device.getDeviceName());
//
// 2. 处理instruct消息 // // 2. 处理instruct消息
if (root.has("instruct")) { // if (root.has("instruct")) {
JsonNode instructNode = root.get("instruct"); // JsonNode instructNode = root.get("instruct");
if (instructNode.isArray()) { // if (instructNode.isArray()) {
boolean b = receivedTopicName.startsWith("B/"); // boolean b = receivedTopicName.startsWith("B/");
record = parseInstruct(device, instructNode, b); // record = parseInstruct(device, instructNode, b);
// 根据不同主题进行不同处理 // // 根据不同主题进行不同处理
if (receivedTopicName.startsWith("A/")) { // if (receivedTopicName.startsWith("A/")) {
// 处理A主题的消息设备上传 // // 处理A主题的消息设备上传
record.setDataSource("设备上报"); // record.setDataSource("设备上报");
} else if (receivedTopicName.startsWith("B/")) { // } else if (receivedTopicName.startsWith("B/")) {
// 处理B主题的消息 (手动上传) // // 处理B主题的消息 (手动上传)
record.setDataSource("客户端操作"); // record.setDataSource("客户端操作");
} // }
} // }
// 确保在插入前设置tenantId和deviceId // // 确保在插入前设置tenantId和deviceId
record.setTenantId(device.getTenantId()); // record.setTenantId(device.getTenantId());
record.setDeviceId(device.getId()); // record.setDeviceId(device.getId());
deviceLogMapper.insert(record); // deviceLogMapper.insert(record);
} // }
//
// 2. 处理 state 消息 // // 2. 处理 state 消息
if (root.has("state")) { // if (root.has("state")) {
JsonNode instructNode = root.get("state"); // JsonNode instructNode = root.get("state");
if (instructNode.isArray()) { // if (instructNode.isArray()) {
boolean b = receivedTopicName.startsWith("B/"); // boolean b = receivedTopicName.startsWith("B/");
record = parseState(device, instructNode, b); // record = parseState(device, instructNode, b);
// 根据不同主题进行不同处理 // // 根据不同主题进行不同处理
if (receivedTopicName.startsWith("A/")) { // if (receivedTopicName.startsWith("A/")) {
// 处理A主题的消息设备上传 // // 处理A主题的消息设备上传
record.setDataSource("设备上报"); // record.setDataSource("设备上报");
} else if (receivedTopicName.startsWith("B/")) { // } else if (receivedTopicName.startsWith("B/")) {
// 处理B主题的消息 (手动上传) // // 处理B主题的消息 (手动上传)
record.setDataSource("客户端操作"); // record.setDataSource("客户端操作");
} // }
} // }
// 确保在插入前设置tenantId和deviceId // // 确保在插入前设置tenantId和deviceId
record.setTenantId(device.getTenantId()); // record.setTenantId(device.getTenantId());
record.setDeviceId(device.getId()); // record.setDeviceId(device.getId());
deviceLogMapper.insert(record); // deviceLogMapper.insert(record);
} // }
//
if (root.has("imei")) { // if (root.has("imei")) {
// 设备行为 // // 设备行为
record.setDeviceAction(InstructType6170.fromCode(0).getDescription()); // record.setDeviceAction(InstructType6170.fromCode(0).getDescription());
record.setDataSource("设备上报"); // record.setDataSource("设备上报");
record.setContent("设备启动"); // record.setContent("设备启动");
// 确保在插入前设置tenantId和deviceId // // 确保在插入前设置tenantId和deviceId
record.setTenantId(device.getTenantId()); // record.setTenantId(device.getTenantId());
record.setDeviceId(device.getId()); // record.setDeviceId(device.getId());
deviceLogMapper.insert(record); // deviceLogMapper.insert(record);
} // }
//
//
// 3. 处理state消息 // // 3. 处理state消息
// else if (root.has("state")) { // // else if (root.has("state")) {
// JsonNode stateNode = root.get("state"); // // JsonNode stateNode = root.get("state");
// if (stateNode.isArray()) { // // if (stateNode.isArray()) {
// StateRecord record = parseState(device, stateNode); // // StateRecord record = parseState(device, stateNode);
// stateRepo.save(record); // // stateRepo.save(record);
// } // // }
// } // // }
} catch (Exception e) { // } catch (Exception e) {
log.error("消息解析失败: {}", payload, e); // log.error("消息解析失败: {}", payload, e);
} // }
//
} // }
//
} // }
} // }
//
//
/** // /**
* 从主题中提取设备ID(IMEI) // * 从主题中提取设备ID(IMEI)
* // *
* @param topic // * @param topic
* @return // * @return
*/ // */
private String extractDeviceId(String topic) { // private String extractDeviceId(String topic) {
// 处理 A/# 或 B/# 格式的主题,例如 B/861556078765285 或 A/861556078765285 // // 处理 A/# 或 B/# 格式的主题,例如 B/861556078765285 或 A/861556078765285
String[] segments = topic.split("/"); // String[] segments = topic.split("/");
if (segments.length >= 2) { // if (segments.length >= 2) {
// 返回第二个段,即 / 后面的部分 // // 返回第二个段,即 / 后面的部分
return segments[1]; // return segments[1];
} // }
// 如果格式不符合预期,返回原主题 // // 如果格式不符合预期,返回原主题
return topic; // return topic;
} // }
//
//
/** // /**
* 解析instruct消息 // * 解析instruct消息
* // *
* @param device // * @param device
* @param array // * @param array
* @param b // * @param b
* @return // * @return
*/ // */
private DeviceLog parseInstruct(Device device, JsonNode array, boolean b) { // private DeviceLog parseInstruct(Device device, JsonNode array, boolean b) {
DeviceLog record = new DeviceLog(); // DeviceLog record = new DeviceLog();
record.setDeviceName(device.getDeviceName()); // record.setDeviceName(device.getDeviceName());
// 设备行为 // // 设备行为
record.setDeviceAction(InstructType6170.fromCode(array.get(0).asInt()).getDescription()); // record.setDeviceAction(InstructType6170.fromCode(array.get(0).asInt()).getDescription());
//
switch (array.get(0).asInt()) { // switch (array.get(0).asInt()) {
case 1: // 灯光模式 // case 1: // 灯光模式
LightModeEnum6170 lightModeEnum6170 = LightModeEnum6170.fromCode(array.get(1).asInt()); // LightModeEnum6170 lightModeEnum6170 = LightModeEnum6170.fromCode(array.get(1).asInt());
record.setContent(lightModeEnum6170.getDescription()); // record.setContent(lightModeEnum6170.getDescription());
break; // break;
//
case 2: // 单位/姓名/职位 // case 2: // 单位/姓名/职位
byte[] unitBytes = new byte[480]; // byte[] unitBytes = new byte[480];
for (int i = 1; i <= 480; i++) { // for (int i = 1; i <= 480; i++) {
unitBytes[i - 1] = (byte) array.get(i).asInt(); // unitBytes[i - 1] = (byte) array.get(i).asInt();
} // }
// record.setUnitData(unitBytes); // // record.setUnitData(unitBytes);
break; // break;
//
case 3: // 开机图片 // case 3: // 开机图片
// record.setImagePage(array.get(1).asInt()); // // record.setImagePage(array.get(1).asInt());
byte[] imageBytes = new byte[512]; // byte[] imageBytes = new byte[512];
for (int i = 2; i <= 513; i++) { // for (int i = 2; i <= 513; i++) {
imageBytes[i - 2] = (byte) array.get(i).asInt(); // imageBytes[i - 2] = (byte) array.get(i).asInt();
} // }
// record.setImageData(imageBytes); // // record.setImageData(imageBytes);
break; // break;
//
case 4: // 激光灯 // case 4: // 激光灯
int anInt = array.get(1).asInt(); // int anInt = array.get(1).asInt();
if (anInt == 0) { // if (anInt == 0) {
record.setContent("关闭激光灯"); // record.setContent("关闭激光灯");
} else if (anInt == 1) { // } else if (anInt == 1) {
record.setContent("开启激光灯"); // record.setContent("开启激光灯");
} else { // } else {
record.setContent("未知操作"); // record.setContent("未知操作");
} // }
break; // break;
//
case 5: // 亮度调节 // case 5: // 亮度调节
record.setContent(+array.get(1).asInt() + "%"); // record.setContent(+array.get(1).asInt() + "%");
break; // break;
//
case 11: // 定位数据 // case 11: // 定位数据
if (b) { // if (b) {
break; // break;
} // }
int i1 = array.get(1).asInt(); // int i1 = array.get(1).asInt();
int i2 = array.get(2).asInt(); // int i2 = array.get(2).asInt();
int i3 = array.get(3).asInt(); // int i3 = array.get(3).asInt();
int i4 = array.get(4).asInt(); // int i4 = array.get(4).asInt();
//
// 优雅的转换方式 Longitude and latitude // // 优雅的转换方式 Longitude and latitude
double latitude = i1 + i2 / 10.0; // double latitude = i1 + i2 / 10.0;
double Longitude = i3 + i4 / 10.0; // double Longitude = i3 + i4 / 10.0;
// 84 ==》 高德 // // 84 ==》 高德
double[] doubles = LngLonUtil.gps84_To_Gcj02(latitude, Longitude); // double[] doubles = LngLonUtil.gps84_To_Gcj02(latitude, Longitude);
String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0])); // String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
record.setContent(address); // record.setContent(address);
break; // break;
} // }
return record; // return record;
} // }
//
//
/** // /**
* 解析 state 消息 // * 解析 state 消息
* // *
* @param device // * @param device
* @param array // * @param array
* @return // * @return
*/ // */
private DeviceLog parseState(Device device, JsonNode array, boolean b) { // private DeviceLog parseState(Device device, JsonNode array, boolean b) {
DeviceLog record = new DeviceLog(); // DeviceLog record = new DeviceLog();
record.setDeviceName(device.getDeviceName()); // record.setDeviceName(device.getDeviceName());
// 设备行为 // // 设备行为
record.setDeviceAction(InstructType6170.fromCode(array.get(0).asInt()).getDescription()); // record.setDeviceAction(InstructType6170.fromCode(array.get(0).asInt()).getDescription());
//
switch (array.get(0).asInt()) { // switch (array.get(0).asInt()) {
case 1: // 灯光模式 // case 1: // 灯光模式
LightModeEnum6170 lightModeEnum6170 = LightModeEnum6170.fromCode(array.get(1).asInt()); // LightModeEnum6170 lightModeEnum6170 = LightModeEnum6170.fromCode(array.get(1).asInt());
record.setContent(lightModeEnum6170.getDescription()); // record.setContent(lightModeEnum6170.getDescription());
break; // break;
//
case 2: // 单位/姓名/职位 // case 2: // 单位/姓名/职位
byte[] unitBytes = new byte[480]; // byte[] unitBytes = new byte[480];
for (int i = 1; i <= 480; i++) { // for (int i = 1; i <= 480; i++) {
unitBytes[i - 1] = (byte) array.get(i).asInt(); // unitBytes[i - 1] = (byte) array.get(i).asInt();
} // }
// record.setUnitData(unitBytes); // // record.setUnitData(unitBytes);
break; // break;
//
case 3: // 开机图片 // case 3: // 开机图片
// record.setImagePage(array.get(1).asInt()); // // record.setImagePage(array.get(1).asInt());
byte[] imageBytes = new byte[512]; // byte[] imageBytes = new byte[512];
for (int i = 2; i <= 513; i++) { // for (int i = 2; i <= 513; i++) {
imageBytes[i - 2] = (byte) array.get(i).asInt(); // imageBytes[i - 2] = (byte) array.get(i).asInt();
} // }
// record.setImageData(imageBytes); // // record.setImageData(imageBytes);
break; // break;
//
case 4: // 激光灯 // case 4: // 激光灯
int anInt = array.get(1).asInt(); // int anInt = array.get(1).asInt();
if (anInt == 0) { // if (anInt == 0) {
record.setContent("关闭激光灯"); // record.setContent("关闭激光灯");
} else if (anInt == 1) { // } else if (anInt == 1) {
record.setContent("开启激光灯"); // record.setContent("开启激光灯");
} else { // } else {
record.setContent("未知操作"); // record.setContent("未知操作");
} // }
break; // break;
//
case 5: // 亮度调节 // case 5: // 亮度调节
record.setContent(+array.get(1).asInt() + "%"); // record.setContent(+array.get(1).asInt() + "%");
break; // break;
//
case 11: // 定位数据 // case 11: // 定位数据
if (b) { // if (b) {
break; // break;
} // }
int i1 = array.get(1).asInt(); // int i1 = array.get(1).asInt();
int i2 = array.get(2).asInt(); // int i2 = array.get(2).asInt();
int i3 = array.get(3).asInt(); // int i3 = array.get(3).asInt();
int i4 = array.get(4).asInt(); // int i4 = array.get(4).asInt();
//
// 优雅的转换方式 Longitude and latitude // // 优雅的转换方式 Longitude and latitude
double latitude = i1 + i2 / 10.0; // double latitude = i1 + i2 / 10.0;
double Longitude = i3 + i4 / 10.0; // double Longitude = i3 + i4 / 10.0;
// 84 ==》 高德 // // 84 ==》 高德
double[] doubles = LngLonUtil.gps84_To_Gcj02(latitude, Longitude); // double[] doubles = LngLonUtil.gps84_To_Gcj02(latitude, Longitude);
String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0])); // String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
record.setContent(address); // record.setContent(address);
break; // break;
} // }
return record; // return record;
} // }
//
} //}

View File

@ -1,163 +1,163 @@
package com.fuyuanshen.web.listener; //package com.fuyuanshen.web.listener;
//
import cn.dev33.satoken.listener.SaTokenListener; //import cn.dev33.satoken.listener.SaTokenListener;
import cn.dev33.satoken.stp.StpUtil; //import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.stp.parameter.SaLoginParameter; //import cn.dev33.satoken.stp.parameter.SaLoginParameter;
import cn.hutool.core.convert.Convert; //import cn.hutool.core.convert.Convert;
import cn.hutool.http.useragent.UserAgent; //import cn.hutool.http.useragent.UserAgent;
import cn.hutool.http.useragent.UserAgentUtil; //import cn.hutool.http.useragent.UserAgentUtil;
import lombok.RequiredArgsConstructor; //import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import com.fuyuanshen.common.core.constant.CacheConstants; //import com.fuyuanshen.common.core.constant.CacheConstants;
import com.fuyuanshen.common.core.constant.Constants; //import com.fuyuanshen.common.core.constant.Constants;
import com.fuyuanshen.common.core.domain.dto.UserOnlineDTO; //import com.fuyuanshen.common.core.domain.dto.UserOnlineDTO;
import com.fuyuanshen.common.core.utils.MessageUtils; //import com.fuyuanshen.common.core.utils.MessageUtils;
import com.fuyuanshen.common.core.utils.ServletUtils; //import com.fuyuanshen.common.core.utils.ServletUtils;
import com.fuyuanshen.common.core.utils.SpringUtils; //import com.fuyuanshen.common.core.utils.SpringUtils;
import com.fuyuanshen.common.core.utils.ip.AddressUtils; //import com.fuyuanshen.common.core.utils.ip.AddressUtils;
import com.fuyuanshen.common.log.event.LogininforEvent; //import com.fuyuanshen.common.log.event.LogininforEvent;
import com.fuyuanshen.common.redis.utils.RedisUtils; //import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.common.satoken.utils.LoginHelper; //import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.common.tenant.helper.TenantHelper; //import com.fuyuanshen.common.tenant.helper.TenantHelper;
import com.fuyuanshen.web.service.SysLoginService; //import com.fuyuanshen.web.service.SysLoginService;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import java.time.Duration; //import java.time.Duration;
//
/** ///**
* 用户行为 侦听器的实现 // * 用户行为 侦听器的实现
* // *
* @author Lion Li // * @author Lion Li
*/ // */
@RequiredArgsConstructor //@RequiredArgsConstructor
@Component //@Component
@Slf4j //@Slf4j
public class UserActionListener implements SaTokenListener { //public class UserActionListener implements SaTokenListener {
//
private final SysLoginService loginService; // private final SysLoginService loginService;
//
/** // /**
* 每次登录时触发 // * 每次登录时触发
*/ // */
@Override // @Override
public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginParameter loginParameter) { // public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginParameter loginParameter) {
UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent")); // UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
String ip = ServletUtils.getClientIP(); // String ip = ServletUtils.getClientIP();
UserOnlineDTO dto = new UserOnlineDTO(); // UserOnlineDTO dto = new UserOnlineDTO();
dto.setIpaddr(ip); // dto.setIpaddr(ip);
dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip)); // dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
dto.setBrowser(userAgent.getBrowser().getName()); // dto.setBrowser(userAgent.getBrowser().getName());
dto.setOs(userAgent.getOs().getName()); // dto.setOs(userAgent.getOs().getName());
dto.setLoginTime(System.currentTimeMillis()); // dto.setLoginTime(System.currentTimeMillis());
dto.setTokenId(tokenValue); // dto.setTokenId(tokenValue);
String username = (String) loginParameter.getExtra(LoginHelper.USER_NAME_KEY); // String username = (String) loginParameter.getExtra(LoginHelper.USER_NAME_KEY);
String tenantId = (String) loginParameter.getExtra(LoginHelper.TENANT_KEY); // String tenantId = (String) loginParameter.getExtra(LoginHelper.TENANT_KEY);
dto.setUserName(username); // dto.setUserName(username);
dto.setClientKey((String) loginParameter.getExtra(LoginHelper.CLIENT_KEY)); // dto.setClientKey((String) loginParameter.getExtra(LoginHelper.CLIENT_KEY));
dto.setDeviceType(loginParameter.getDeviceType()); // dto.setDeviceType(loginParameter.getDeviceType());
dto.setDeptName((String) loginParameter.getExtra(LoginHelper.DEPT_NAME_KEY)); // dto.setDeptName((String) loginParameter.getExtra(LoginHelper.DEPT_NAME_KEY));
TenantHelper.dynamic(tenantId, () -> { // TenantHelper.dynamic(tenantId, () -> {
if(loginParameter.getTimeout() == -1) { // if(loginParameter.getTimeout() == -1) {
RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto); // RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto);
} else { // } else {
RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto, Duration.ofSeconds(loginParameter.getTimeout())); // RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto, Duration.ofSeconds(loginParameter.getTimeout()));
} // }
}); // });
// 记录登录日志 // // 记录登录日志
LogininforEvent logininforEvent = new LogininforEvent(); // LogininforEvent logininforEvent = new LogininforEvent();
logininforEvent.setTenantId(tenantId); // logininforEvent.setTenantId(tenantId);
logininforEvent.setUsername(username); // logininforEvent.setUsername(username);
logininforEvent.setStatus(Constants.LOGIN_SUCCESS); // logininforEvent.setStatus(Constants.LOGIN_SUCCESS);
logininforEvent.setMessage(MessageUtils.message("user.login.success")); // logininforEvent.setMessage(MessageUtils.message("user.login.success"));
logininforEvent.setRequest(ServletUtils.getRequest()); // logininforEvent.setRequest(ServletUtils.getRequest());
SpringUtils.context().publishEvent(logininforEvent); // SpringUtils.context().publishEvent(logininforEvent);
// 更新登录信息 // // 更新登录信息
loginService.recordLoginInfo((Long) loginParameter.getExtra(LoginHelper.USER_KEY), ip); // loginService.recordLoginInfo((Long) loginParameter.getExtra(LoginHelper.USER_KEY), ip);
log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue); // log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue);
} // }
//
/** // /**
* 每次注销时触发 // * 每次注销时触发
*/ // */
@Override // @Override
public void doLogout(String loginType, Object loginId, String tokenValue) { // public void doLogout(String loginType, Object loginId, String tokenValue) {
String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY)); // String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
TenantHelper.dynamic(tenantId, () -> { // TenantHelper.dynamic(tenantId, () -> {
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue); // RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
}); // });
log.info("user doLogout, userId:{}, token:{}", loginId, tokenValue); // log.info("user doLogout, userId:{}, token:{}", loginId, tokenValue);
} // }
//
/** // /**
* 每次被踢下线时触发 // * 每次被踢下线时触发
*/ // */
@Override // @Override
public void doKickout(String loginType, Object loginId, String tokenValue) { // public void doKickout(String loginType, Object loginId, String tokenValue) {
String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY)); // String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
TenantHelper.dynamic(tenantId, () -> { // TenantHelper.dynamic(tenantId, () -> {
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue); // RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
}); // });
log.info("user doKickout, userId:{}, token:{}", loginId, tokenValue); // log.info("user doKickout, userId:{}, token:{}", loginId, tokenValue);
} // }
//
/** // /**
* 每次被顶下线时触发 // * 每次被顶下线时触发
*/ // */
@Override // @Override
public void doReplaced(String loginType, Object loginId, String tokenValue) { // public void doReplaced(String loginType, Object loginId, String tokenValue) {
String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY)); // String tenantId = Convert.toStr(StpUtil.getExtra(tokenValue, LoginHelper.TENANT_KEY));
TenantHelper.dynamic(tenantId, () -> { // TenantHelper.dynamic(tenantId, () -> {
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue); // RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
}); // });
log.info("user doReplaced, userId:{}, token:{}", loginId, tokenValue); // log.info("user doReplaced, userId:{}, token:{}", loginId, tokenValue);
} // }
//
/** // /**
* 每次被封禁时触发 // * 每次被封禁时触发
*/ // */
@Override // @Override
public void doDisable(String loginType, Object loginId, String service, int level, long disableTime) { // public void doDisable(String loginType, Object loginId, String service, int level, long disableTime) {
} // }
//
/** // /**
* 每次被解封时触发 // * 每次被解封时触发
*/ // */
@Override // @Override
public void doUntieDisable(String loginType, Object loginId, String service) { // public void doUntieDisable(String loginType, Object loginId, String service) {
} // }
//
/** // /**
* 每次打开二级认证时触发 // * 每次打开二级认证时触发
*/ // */
@Override // @Override
public void doOpenSafe(String loginType, String tokenValue, String service, long safeTime) { // public void doOpenSafe(String loginType, String tokenValue, String service, long safeTime) {
} // }
//
/** // /**
* 每次创建Session时触发 // * 每次创建Session时触发
*/ // */
@Override // @Override
public void doCloseSafe(String loginType, String tokenValue, String service) { // public void doCloseSafe(String loginType, String tokenValue, String service) {
} // }
//
/** // /**
* 每次创建Session时触发 // * 每次创建Session时触发
*/ // */
@Override // @Override
public void doCreateSession(String id) { // public void doCreateSession(String id) {
} // }
//
/** // /**
* 每次注销Session时触发 // * 每次注销Session时触发
*/ // */
@Override // @Override
public void doLogoutSession(String id) { // public void doLogoutSession(String id) {
} // }
//
/** // /**
* 每次Token续期时触发 // * 每次Token续期时触发
*/ // */
@Override // @Override
public void doRenewTimeout(String tokenValue, Object loginId, long timeout) { // public void doRenewTimeout(String tokenValue, Object loginId, long timeout) {
} // }
} //}

View File

@ -4,7 +4,7 @@ spring.servlet.multipart.location: /fys/server/temp
--- # 监控中心配置 --- # 监控中心配置
spring.boot.admin.client: spring.boot.admin.client:
# 增加客户端开关 # 增加客户端开关
enabled: true enabled: false
url: http://localhost:9090/admin url: http://localhost:9090/admin
instance: instance:
service-host-type: IP service-host-type: IP
@ -16,7 +16,7 @@ spring.boot.admin.client:
--- # snail-job 配置 --- # snail-job 配置
snail-job: snail-job:
enabled: true enabled: false
# 需要在 SnailJob 后台组管理创建对应名称的组,然后创建任务的时候选择对应的组,才能正确分派任务 # 需要在 SnailJob 后台组管理创建对应名称的组,然后创建任务的时候选择对应的组,才能正确分派任务
group: "fys_group" group: "fys_group"
# SnailJob 接入验证令牌 详见 script/sql/ry_job.sql `sj_group_config`表 # SnailJob 接入验证令牌 详见 script/sql/ry_job.sql `sj_group_config`表
@ -52,9 +52,9 @@ spring:
driverClassName: com.mysql.cj.jdbc.Driver driverClassName: com.mysql.cj.jdbc.Driver
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562 # jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题) # 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 username: root
password: Jz_5623_cl1 password: Jq_123456#
# # 从库数据源 # # 从库数据源
# slave: # slave:
# lazy: true # lazy: true
@ -101,7 +101,7 @@ spring:
spring.data: spring.data:
redis: redis:
# 地址 # 地址
host: localhost host: 47.120.79.150
# 端口默认为6379 # 端口默认为6379
port: 6379 port: 6379
# 数据库索引 # 数据库索引
@ -177,11 +177,14 @@ sms:
# 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分 # 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
supplier: alibaba supplier: alibaba
# 有些称为accessKey有些称之为apiKey也有称为sdkKey或者appId。 # 有些称为accessKey有些称之为apiKey也有称为sdkKey或者appId。
access-key-id: 您的accessKey access-key-id: LTAI5tJdDNpZootsPQ5hdELx
# 称为accessSecret有些称之为apiSecret # 称为accessSecret有些称之为apiSecret
access-key-secret: 您的accessKeySecret access-key-secret: mU4WtffcCXpHPz5tLwQpaGtLsJXONt
signature: 您的短信签名 #模板ID 非必须配置如果使用sendMessage的快速发送需此配置
sdk-app-id: 您的sdkAppId template-id: SMS_322180518
#模板变量 上述模板的变量
templateName: code
signature: 湖北星汉研创科技
config2: config2:
# 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分 # 厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
supplier: tencent supplier: tencent