Merge branch 'main' into prod

This commit is contained in:
2025-08-04 09:08:34 +08:00
29 changed files with 1297 additions and 212 deletions

View File

@ -104,6 +104,15 @@ public class AppAuthController {
return R.ok("退出成功");
}
/**
* 用户注销
*/
@PostMapping("/cancelAccount")
public R<Void> cancelAccount() {
loginService.cancelAccount();
return R.ok("用户注销成功");
}
/**
* 用户注册
*/

View File

@ -11,6 +11,6 @@ public class DeviceInstructDto {
/**
* 下发指令
*/
private Object instructValue;
private String instructValue;
}

View File

@ -13,12 +13,12 @@ import com.fuyuanshen.app.domain.dto.APPReNameDTO;
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo;
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper;
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.exception.ServiceException;
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
import com.fuyuanshen.common.core.utils.MapstructUtils;
@ -38,12 +38,9 @@ import com.fuyuanshen.equipment.enums.BindingStatusEnum;
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.*;
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
import com.fuyuanshen.equipment.utils.c.ReliableTextToBitmap;
import com.fuyuanshen.global.mqtt.config.MqttGateway;
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -53,6 +50,11 @@ import org.springframework.web.multipart.MultipartFile;
import java.time.Duration;
import java.util.*;
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.buildArr;
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.generateFixedBitmapData;
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
@Slf4j
@Service
@ -117,6 +119,40 @@ public class AppDeviceBizService {
bo.setBindingUserId(userId);
}
Page<AppDeviceVo> result = deviceMapper.queryAppBindDeviceList(pageQuery.build(), bo);
List<AppDeviceVo> records = result.getRecords();
if(records != null && !records.isEmpty()){
records.forEach(item -> {
if(item.getCommunicationMode()!=null && item.getCommunicationMode() == 0){
//设备在线状态
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + item.getDeviceImei());
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());
// 获取电量
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+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + item.getDeviceImei());
// 获取电量
if(StringUtils.isNotBlank(location)){
JSONObject jsonObject = JSONObject.parseObject(location);
item.setLatitude(jsonObject.getString("latitude"));
item.setLongitude(jsonObject.getString("longitude"));
}else{
item.setBattery("0");
}
}
});
}
return TableDataInfo.build(result);
}
@ -275,44 +311,39 @@ public class AppDeviceBizService {
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
vo.setPersonnelInfo(personnelInfoVo);
}
//设备在线状态
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + device.getDeviceImei());
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());
// 获取电量
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+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + device.getDeviceImei();
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 static void main(String[] args) {
byte[] unitName = generateFixedBitmapData("富源晟科技", 120);
byte[] position = generateFixedBitmapData("研发", 120);
byte[] name = generateFixedBitmapData("张三", 120);
byte[] id = generateFixedBitmapData("123456", 120);
// int[] intUnitNames = Bitmap80x12Generator.convertHexToDecimal(unitName);
// int[] intPosition = Bitmap80x12Generator.convertHexToDecimal(position);
// int[] intNames = Bitmap80x12Generator.convertHexToDecimal(position);
// int[] intIds = Bitmap80x12Generator.convertHexToDecimal(position);
// Map<String, Object> map = new HashMap<>();
// map.put("instruct", 2);
// System.out.println(JSON.toJSONString( map));
// StringBuilder sb = new StringBuilder();
// sb.append("[")
// buildStr(unitName, sb);
// System.out.println(sb.toString());
// Object[] arr = new Object[]{2, Bitmap80x12Generator , Arrays.toString(name), Arrays.toString(id)};
// System.out.println(Arrays.deepToString(arr));
// int[] a = new int[]{6,6,6,6,6,6};
ArrayList<Integer> intData = new ArrayList<>();
intData.add(2);
buildArr(convertHexToDecimal(unitName), intData);
buildArr(convertHexToDecimal(position), intData);
buildArr(convertHexToDecimal(name), intData);
buildArr(convertHexToDecimal(id), intData);
intData.add(0);
intData.add(0);
intData.add(0);
intData.add(0);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
System.out.println(JSON.toJSONString(map));
}
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
Long deviceId = bo.getDeviceId();
@ -373,9 +404,9 @@ public class AppDeviceBizService {
System.out.println("原始数据大小: " + largeData.length + " 字节");
int[] ints = convertHexToDecimal(largeData);
RedisUtils.setCacheObject("app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
String data = RedisUtils.getCacheObject("app_logo_data:" + device.getDeviceImei());
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei());
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
@ -410,7 +441,7 @@ public class AppDeviceBizService {
if(device == null){
throw new ServiceException("设备不存在");
}
Integer instructValue = (Integer) params.getInstructValue();
Integer instructValue = Integer.parseInt(params.getInstructValue());
ArrayList<Integer> intData = new ArrayList<>();
intData.add(1);
intData.add(instructValue);
@ -434,7 +465,7 @@ public class AppDeviceBizService {
if(device == null){
throw new ServiceException("设备不存在");
}
String instructValue = (String)params.getInstructValue();
String instructValue = params.getInstructValue();
ArrayList<Integer> intData = new ArrayList<>();
intData.add(5);
String[] values = instructValue.split("\\.");
@ -466,7 +497,7 @@ public class AppDeviceBizService {
if(device == null){
throw new ServiceException("设备不存在");
}
Integer instructValue = (Integer) params.getInstructValue();
Integer instructValue = Integer.parseInt(params.getInstructValue());
ArrayList<Integer> intData = new ArrayList<>();
intData.add(4);
intData.add(instructValue);

View File

@ -51,7 +51,7 @@ public class AppLoginService {
private Integer lockTime;
private final ISysTenantService tenantService;
private final IAppRoleService roleService;
private final IAppUserService appUserService;
/**
@ -185,4 +185,24 @@ public class AppLoginService {
}
}
public void cancelAccount() {
try {
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
if (ObjectUtil.isNull(loginUser)) {
return;
}
appUserService.deleteWithValidByIds(Collections.singletonList(loginUser.getUserId()),true);
if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) {
// 超级管理员 登出清除动态租户
TenantHelper.clearDynamic();
}
recordLogininfor(loginUser.getTenantId(), loginUser.getUsername(), Constants.LOGOUT, "用户注销成功");
} catch (NotLoginException ignored) {
} finally {
try {
StpUtil.logout();
} catch (NotLoginException ignored) {
}
}
}
}

View File

@ -0,0 +1,12 @@
package com.fuyuanshen.global.mqtt.constants;
public class DeviceRedisKeyConstants {
// 将设备上报状态
public static final String DEVICE_STATUS_KEY_PREFIX = "device: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_LOCATION_HISTORY_KEY_PREFIX = "device:location:history:";
}

View File

@ -40,37 +40,5 @@ public class LightingCommandTypeConstants {
* 主动上报设备数据 (Active Reporting Device Data)
*/
public static final String ACTIVE_REPORTING_DEVICE_DATA = "Light_12";
/**
* 获取命令类型描述
*
* @param commandType 命令类型
* @return 命令类型描述
*/
public static String getCommandTypeDescription(String commandType) {
return switch (commandType) {
case LIGHT_MODE -> "灯光模式 (Light Mode)";
case PERSONNEL_INFO -> "人员信息 (Personnel Information)";
case BOOT_LOGO -> "开机LOGO (Boot Logo)";
case LASER_LIGHT -> "激光灯 (Laser Light)";
case MAIN_LIGHT_BRIGHTNESS -> "主灯亮度 (Main Light Brightness)";
case LOCATION_DATA -> "定位数据 (Location Data)";
default -> "未知命令类型 (Unknown Command Type)";
};
}
/**
* 检查是否为有效命令类型
*
* @param commandType 命令类型
* @return 是否有效
*/
public static boolean isValidCommandType(String commandType) {
return commandType.equals(LIGHT_MODE) ||
commandType.equals(PERSONNEL_INFO) ||
commandType.equals(BOOT_LOGO) ||
commandType.equals(LASER_LIGHT) ||
commandType.equals(MAIN_LIGHT_BRIGHTNESS) ||
commandType.equals(LOCATION_DATA);
}
}

View File

@ -1,10 +1,14 @@
package com.fuyuanshen.global.mqtt.receiver;
import cn.hutool.core.lang.Dict;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.json.utils.JsonUtils;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
import com.fuyuanshen.global.mqtt.base.MqttRuleEngine;
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
@ -13,6 +17,7 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Service;
import java.time.Duration;
import java.util.Objects;
@Service
@ -37,16 +42,19 @@ public class ReceiverMessageHandler implements MessageHandler {
if (receivedTopic == null || payloadDict == null) {
return;
}
String[] subStr = receivedTopic.split("/");
String deviceImei = subStr[1];
if(StringUtils.isNotBlank(deviceImei)){
//在线状态
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + deviceImei;
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1", Duration.ofSeconds(60*15));
}
String state = payloadDict.getStr("state");
Object[] convertArr = ImageToCArrayConverter.convertByteStringToMixedObjectArray(state);
if (convertArr.length > 0) {
Byte val1 = (Byte) convertArr[0];
String[] subStr = receivedTopic.split("/");
System.out.println("收到设备id: " + subStr[1]);
String deviceImei = subStr[1];
MqttRuleContext context = new MqttRuleContext();
context.setCommandType(val1);
context.setConvertArr(convertArr);

View File

@ -1,10 +1,12 @@
package com.fuyuanshen.global.mqtt.rule;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.json.utils.JsonUtils;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
import com.fuyuanshen.global.mqtt.config.MqttGateway;
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -78,11 +80,11 @@ public class ActiveReportingDeviceDataRule implements MqttMessageRule {
deviceInfo.put("timestamp", System.currentTimeMillis());
// 将设备状态信息存储到Redis中
String deviceRedisKey = "device:status:" + deviceImei;
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX + deviceImei;
String deviceInfoJson = JsonUtils.toJsonString(deviceInfo);
// 存储到Redis设置过期时间例如24小时
RedisUtils.setCacheObject(deviceRedisKey, deviceInfoJson, Duration.ofSeconds(24 * 60 * 60));
RedisUtils.setCacheObject(deviceRedisKey, deviceInfoJson);
log.info("设备状态信息已异步发送到Redis: device={}, mainLightMode={}, laserLightMode={}, batteryPercentage={}",
deviceImei, mainLightMode, laserLightMode, batteryPercentage);
@ -92,4 +94,6 @@ public class ActiveReportingDeviceDataRule implements MqttMessageRule {
});
}
}

View File

@ -1,5 +1,6 @@
package com.fuyuanshen.global.mqtt.rule;
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;
@ -26,13 +27,13 @@ import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHex
@Component
@RequiredArgsConstructor
@Slf4j
public class PersonnelInfoRule implements MqttMessageRule {
public class DeviceBootLogoRule implements MqttMessageRule {
private final MqttGateway mqttGateway;
@Override
public String getCommandType() {
return LightingCommandTypeConstants.PERSONNEL_INFO;
return LightingCommandTypeConstants.BOOT_LOGO;
}
@Override
@ -43,7 +44,7 @@ public class PersonnelInfoRule implements MqttMessageRule {
return;
}
String data = RedisUtils.getCacheObject("894078:app_logo_data:" + context.getDeviceImei());
String data = RedisUtils.getCacheObject(GlobalConstants.GLOBAL_REDIS_KEY+"app_logo_data:" + context.getDeviceImei());
if (StringUtils.isEmpty(data)) {
return;
}
@ -51,7 +52,7 @@ public class PersonnelInfoRule implements MqttMessageRule {
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, (val2 - 1), 512);
System.out.println("" + val2 + "块数据大小: " + specificChunk.length + " 字节");
System.out.println("" + val2 + "块数据: " + Arrays.toString(specificChunk));
// System.out.println("" + val2 + "块数据: " + Arrays.toString(specificChunk));
ArrayList<Integer> intData = new ArrayList<>();
intData.add(3);

View File

@ -1,5 +1,8 @@
package com.fuyuanshen.global.mqtt.rule;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.json.utils.JsonUtils;
import com.fuyuanshen.common.redis.utils.RedisUtils;
@ -8,6 +11,7 @@ import com.fuyuanshen.equipment.utils.map.LngLonUtil;
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
import com.fuyuanshen.global.mqtt.config.MqttGateway;
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
import lombok.RequiredArgsConstructor;
@ -103,33 +107,86 @@ public class LocationDataRule implements MqttMessageRule {
public void asyncSendLocationToRedisWithFuture(String deviceImei, String latitude, String longitude) {
CompletableFuture.runAsync(() -> {
try {
if(StringUtils.isNotBlank(latitude) || StringUtils.isNotBlank(longitude)){
if(StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)){
return;
}
String[] latArr = latitude.split("\\.");
String[] lonArr = longitude.split("\\.");
// 将位置信息存储到Redis中
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + deviceImei;
String redisObj = RedisUtils.getCacheObject(redisKey);
JSONObject jsonOBj = JSONObject.parseObject(redisObj);
if(jsonOBj != null){
String str1 = latArr[0] +"."+ latArr[1].substring(0,4);
String str2 = lonArr[0] +"."+ lonArr[1].substring(0,4);
String cacheLatitude = jsonOBj.getString("wgs84_latitude");
String cacheLongitude = jsonOBj.getString("wgs84_longitude");
String[] latArr1 = cacheLatitude.split("\\.");
String[] lonArr1 = cacheLongitude.split("\\.");
String cacheStr1 = latArr1[0] +"."+ latArr1[1].substring(0,4);
String cacheStr2 = lonArr1[0] +"."+ lonArr1[1].substring(0,4);
if(str1.equals(cacheStr1) && str2.equals(cacheStr2)){
log.info("位置信息未发生变化: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
return;
}
}
// 构造位置信息对象
Map<String, Object> locationInfo = new LinkedHashMap<>();
double[] doubles = LngLonUtil.gps84_To_Gcj02(Double.parseDouble(latitude), Double.parseDouble(longitude));
locationInfo.put("deviceImei", deviceImei);
locationInfo.put("latitude", doubles[0]);
locationInfo.put("longitude", doubles[1]);
locationInfo.put("wgs84_latitude", latitude);
locationInfo.put("wgs84_longitude", longitude);
String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
locationInfo.put("address", address);
locationInfo.put("timestamp", System.currentTimeMillis());
// 将位置信息存储到Redis中
String redisKey = "device:location:" + deviceImei;
String locationJson = JsonUtils.toJsonString(locationInfo);
// 存储到Redis
RedisUtils.setCacheObject(redisKey, locationJson, Duration.ofSeconds(24 * 60 * 60));
RedisUtils.setCacheObject(redisKey, locationJson);
// 存储到一个列表中,保留历史位置信息
// String locationHistoryKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX + deviceImei;
// RedisUtils.addCacheList(locationHistoryKey, locationJson);
// RedisUtils.expire(locationHistoryKey, Duration.ofDays(90));
storeDeviceTrajectoryWithSortedSet(deviceImei, locationJson);
log.info("位置信息已异步发送到Redis: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
} catch (Exception e) {
log.error("异步发送位置信息到Redis时出错: device={}, error={}", deviceImei, e.getMessage(), e);
}
});
}
/**
* 存储设备30天历史轨迹到Redis (使用Sorted Set)
*/
public void storeDeviceTrajectoryWithSortedSet(String deviceImei, String locationJson) {
try {
String trajectoryKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX + deviceImei;
// String trajectoryKey = "device:trajectory:zset:" + deviceImei;
// String locationJson = JsonUtils.toJsonString(locationInfo);
long timestamp = System.currentTimeMillis();
// 添加到Sorted Set使用时间戳作为score
RedisUtils.zAdd(trajectoryKey, locationJson, timestamp);
// // 设置30天过期时间
// RedisUtils.expire(trajectoryKey, Duration.ofDays(30));
// 清理30天前的数据冗余保护
long thirtyDaysAgo = System.currentTimeMillis() - (90L * 24 * 60 * 60 * 1000);
RedisUtils.zRemoveRangeByScore(trajectoryKey, 0, thirtyDaysAgo);
} catch (Exception e) {
log.error("存储设备轨迹到Redis(ZSet)失败: device={}, error={}", deviceImei, e.getMessage(), e);
}
}
private Map<String, Object> buildLocationDataMap(String latitude, String longitude) {
String[] latArr = latitude.split("\\.");
@ -138,9 +195,11 @@ public class LocationDataRule implements MqttMessageRule {
ArrayList<Integer> intData = new ArrayList<>();
intData.add(11);
intData.add(Integer.parseInt(latArr[0]));
intData.add(Integer.parseInt(latArr[1]));
String str1 = latArr[1];
intData.add(Integer.parseInt(str1.substring(0,4)));
String str2 = lonArr[1];
intData.add(Integer.parseInt(lonArr[0]));
intData.add(Integer.parseInt(lonArr[1]));
intData.add(Integer.parseInt(str2.substring(0,4)));
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);

View File

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

View File

@ -0,0 +1,50 @@
package com.fuyuanshen.web.enums;
/**
* @author: 默苍璃
* @date: 2025-08-0114:14
*/
public enum InstructType6170 {
EQUIPMENT_REPORTING(0, "设备启动"),
LIGHT_MODE(1, "灯光模式"),
/**
* 设备信息
* 单位/姓名/职位
*/
UNIT_INFO(2, "设备信息"),
BOOT_IMAGE(3, "开机图片"),
LASER_LIGHT(4, "激光灯"),
BRIGHTNESS(5, "亮度调节"),
LOCATION_DATA(11, "定位数据"),
UNKNOWN(-1, "未知操作");
private final int code;
private final String description;
InstructType6170(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static InstructType6170 fromCode(int code) {
for (InstructType6170 type : values()) {
if (type.getCode() == code) {
return type;
}
}
// throw new IllegalArgumentException("未知的指令类型代码: " + code);
return UNKNOWN;
}
}

View File

@ -0,0 +1,45 @@
package com.fuyuanshen.web.enums;
/**
* @author: 默苍璃
* @date: 2025-08-0114:30
*/
public enum LightModeEnum6170 {
OFF(0, "关灯"),
HIGH_BEAM(1, "强光模式"),
LOW_BEAM(2, "弱光模式"),
STROBE(3, "爆闪模式"),
FLOOD(4, "泛光模式"),
UNKNOWN(-1, "未知的灯光模式");
private final int code;
private final String description;
LightModeEnum6170(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static LightModeEnum6170 fromCode(int code) {
for (LightModeEnum6170 mode : values()) {
if (mode.getCode() == code) {
return mode;
}
}
// throw new IllegalArgumentException("未知的灯光模式代码: " + code);
return UNKNOWN;
}
}

View File

@ -0,0 +1,264 @@
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.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.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 payload = message.getPayload().toString();
if (receivedTopicName != null) {
// 1. 提取设备ID (从主题中获取)
String deviceImei = extractDeviceId(receivedTopicName);
Device device = deviceMapper.selectOne(new QueryWrapper<Device>().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;
// }
}

View File

@ -303,6 +303,6 @@ mqtt:
password: #YtvpSfCNG
url: tcp://47.120.79.150:2883
subClientId: fys_subClient
subTopic: A/#,worker/location/#
subTopic: A/#,B/#,worker/location/#
pubTopic: B/#
pubClientId: fys_pubClient

View File

@ -339,7 +339,40 @@ public class RedisUtils {
RSet<T> rSet = CLIENT.getSet(key);
return rSet.addAll(dataSet);
}
/**
* 向Sorted Set添加元素
*
* @param key 键
* @param value 值
* @param score 分数
* @return 添加成功返回true否则返回false
*/
public static boolean zAdd(String key, Object value, double score) {
try {
RScoredSortedSet<Object> sortedSet = CLIENT.getScoredSortedSet(key);
return sortedSet.add(score, value);
} catch (Exception e) {
// log.error("向Sorted Set添加元素失败: key={}, value={}, score={}, error={}", key, value, score, e.getMessage(), e);
return false;
}
}
/**
* 移除Sorted Set中指定范围的元素按分数
*
* @param key 键
* @param min 最小分数
* @param max 最大分数
* @return 移除的元素数量
*/
public static int zRemoveRangeByScore(String key, double min, double max) {
try {
RScoredSortedSet<Object> sortedSet = CLIENT.getScoredSortedSet(key);
return sortedSet.removeRangeByScore(min, true, max, true);
} catch (Exception e) {
return 0;
}
}
/**
* 追加缓存Set数据
*

View File

@ -16,11 +16,6 @@ public class AppDeviceDetailVo {
@ExcelProperty(value = "设备ID")
private Long deviceId;
/**
* 手机号
*/
@ExcelProperty(value = "手机号")
private String phonenumber;
/**
* 设备名称
@ -74,4 +69,34 @@ public class AppDeviceDetailVo {
* 发送信息
*/
private String sendMsg;
//"{\"deviceImei\":\"AA\",\"mainLightMode\":\"1\",\"laserLightMode\":\"0\",\"batteryPercentage\":\"60\",\"chargeState\":\"1\",\"batteryRemainingTime\":\"200\",\"timestamp\":1753871635241}"
//设备主灯档位
private String mainLightMode;
//激光灯档位
private String laserLightMode;
//电量百分比
private String batteryPercentage;
//充电状态0没有充电1正在充电2为已充满
private String chargeState;
//电池剩余续航时间200分钟
private String batteryRemainingTime;
/**
* 在线状态(0离线1在线)
*/
private Integer onlineStatus;
// 经度
private String longitude;
// 纬度
private String latitude;
// 逆解析地址
private String address;
}

View File

@ -1,5 +1,10 @@
package com.fuyuanshen.app.service.impl;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fuyuanshen.common.core.constant.Constants;
import com.fuyuanshen.common.core.domain.model.AppLoginUser;
import com.fuyuanshen.common.core.utils.MapstructUtils;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
@ -7,6 +12,9 @@ import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.common.tenant.helper.TenantHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -16,6 +24,7 @@ import com.fuyuanshen.app.domain.AppUser;
import com.fuyuanshen.app.mapper.AppUserMapper;
import com.fuyuanshen.app.service.IAppUserService;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Collection;

View File

@ -5,6 +5,7 @@ import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuyuanshen.common.core.domain.model.LoginUser;
import com.fuyuanshen.common.core.enums.UserType;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
@ -95,7 +96,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
customer.setUserLevel((byte) (loginUser.getUserLevel() + 1));
customer.setPid(loginUser.getUserId());
customer.setStatus("0");
customer.setUserType(UserType.SYS_USER.getUserType());
save(customer);
// 新增用户与角色管理
@ -117,6 +118,9 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
@Transactional(rollbackFor = Exception.class)
public void updateCustomer(Customer customer) throws Exception {
// 获取当前会话账号id, 如果未登录,则抛出异常:`NotLoginException`
Object loginId = StpUtil.getLoginId();
UserQueryCriteria userQueryCriteria = new UserQueryCriteria();
if (StringUtils.isNotEmpty(customer.getUserName())) {
userQueryCriteria.setCustomerName(customer.getUserName());
@ -130,17 +134,19 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
customer.setStatus("0");
} else {
// 强制下线
// StpUtil.logout(customer.getCustomerId());
// String tokenId = customer.getUserType() + ":" + customer.getCustomerId();
String tokenId = UserType.SYS_USER.getUserType() + ":" + customer.getCustomerId();
StpUtil.logout(tokenId);
// StpUtil.kickout(customer.getCustomerId());
customer.setStatus("1");
// 检查目标用户是否有有效的登录状态
if (StpUtil.isLogin(customer.getCustomerId())) {
// 用户已登录,可以执行踢出操作
StpUtil.kickout(customer.getCustomerId());
} else {
// 用户未登录,无法踢出
System.out.println("目标用户未登录,无法执行踢出操作");
}
// if (StpUtil.isLogin(customer.getCustomerId())) {
// // 用户已登录,可以执行踢出操作
// StpUtil.kickout(customer.getCustomerId());
// } else {
// // 用户未登录,无法踢出
// System.out.println("目标用户未登录,无法执行踢出操作");
// }
}
saveOrUpdate(customer);
}

View File

@ -82,6 +82,10 @@ public class Device extends TenantEntity {
@Schema(name = "蓝牙名称")
private String bluetoothName;
/**
* 设备IMEI
* device_imei
*/
@Schema(name = "设备IMEI")
private String deviceImei;

View File

@ -2,6 +2,7 @@ package com.fuyuanshen.equipment.domain;
import com.baomidou.mybatisplus.annotation.*;
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
import com.fuyuanshen.common.tenant.core.TenantEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -16,7 +17,7 @@ import java.io.Serial;
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("device_log")
public class DeviceLog extends BaseEntity {
public class DeviceLog extends TenantEntity {
@Serial
private static final long serialVersionUID = 1L;
@ -27,10 +28,16 @@ public class DeviceLog extends BaseEntity {
@TableId(value = "id")
private Long id;
/**
* 设备ID
*/
private Long deviceId;
/**
* 设备行为
*/
private String deviceAction;
// private Integer deviceActionInt;
/**
* 设备名称
@ -47,5 +54,4 @@ public class DeviceLog extends BaseEntity {
*/
private String content;
}

View File

@ -8,6 +8,8 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import java.util.List;
/**
* 设备日志业务对象 device_log
*
@ -22,9 +24,14 @@ public class DeviceLogBo extends BaseEntity {
/**
* ID
*/
@NotNull(message = "ID不能为空", groups = { EditGroup.class })
@NotNull(message = "ID不能为空", groups = {EditGroup.class})
private Long id;
/**
* 设备编号
*/
private List<Long> deviceIds;
/**
* 设备行为
*/

View File

@ -57,4 +57,23 @@ public class AppDeviceVo implements Serializable {
*/
private Date bindingTime;
/**
* 在线状态(0离线1在线)
*/
private Integer onlineStatus;
/**
* 电量 百分比
*/
private String battery;
/**
* 纬度
*/
private String latitude;
/**
* 经度
*/
private String longitude;
}

View File

@ -1,5 +1,7 @@
package com.fuyuanshen.equipment.domain.vo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fuyuanshen.equipment.domain.DeviceLog;
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
@ -58,5 +60,10 @@ public class DeviceLogVo implements Serializable {
@ExcelProperty(value = "内容")
private String content;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
}

View File

@ -1,11 +1,16 @@
package com.fuyuanshen.equipment.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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 com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.equipment.domain.DeviceAssignments;
import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ -19,6 +24,7 @@ import com.fuyuanshen.equipment.service.IDeviceLogService;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.stream.Collectors;
/**
* 设备日志Service业务层处理
@ -33,6 +39,9 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
private final DeviceLogMapper baseMapper;
private final DeviceAssignmentsMapper deviceAssignmentsMapper;
/**
* 查询设备日志
*
@ -40,7 +49,7 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
* @return 设备日志
*/
@Override
public DeviceLogVo queryById(Long id){
public DeviceLogVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
@ -53,6 +62,8 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
*/
@Override
public TableDataInfo<DeviceLogVo> queryPageList(DeviceLogBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<DeviceLog> lqw = buildQueryWrapper(bo);
Page<DeviceLogVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
@ -71,16 +82,27 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
}
private LambdaQueryWrapper<DeviceLog> buildQueryWrapper(DeviceLogBo bo) {
Long userId = LoginHelper.getUserId();
List<DeviceAssignments> assignments = deviceAssignmentsMapper.selectList(new QueryWrapper<DeviceAssignments>().eq("assignee_id", userId));
List<Long> deviceIds = assignments.stream().map(DeviceAssignments::getDeviceId).collect(Collectors.toList());
if (deviceIds.isEmpty()) {
deviceIds.add(-1L);
}
bo.setDeviceIds(deviceIds);
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<DeviceLog> lqw = Wrappers.lambdaQuery();
lqw.orderByAsc(DeviceLog::getId);
lqw.eq(StringUtils.isNotBlank(bo.getDeviceAction()), DeviceLog::getDeviceAction, bo.getDeviceAction());
lqw.orderByDesc(DeviceLog::getCreateTime);
lqw.like(StringUtils.isNotBlank(bo.getDeviceAction()), DeviceLog::getDeviceAction, bo.getDeviceAction());
lqw.like(StringUtils.isNotBlank(bo.getDeviceName()), DeviceLog::getDeviceName, bo.getDeviceName());
lqw.eq(StringUtils.isNotBlank(bo.getDataSource()), DeviceLog::getDataSource, bo.getDataSource());
lqw.eq(StringUtils.isNotBlank(bo.getContent()), DeviceLog::getContent, bo.getContent());
lqw.like(StringUtils.isNotBlank(bo.getContent()), DeviceLog::getContent, bo.getContent());
lqw.in(CollectionUtil.isNotEmpty(bo.getDeviceIds()), DeviceLog::getDeviceId, bo.getDeviceIds());
return lqw;
}
/**
* 新增设备日志
*
@ -114,8 +136,8 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(DeviceLog entity){
//TODO 做一些数据校验,如唯一约束
private void validEntityBeforeSave(DeviceLog entity) {
// TODO 做一些数据校验,如唯一约束
}
/**
@ -127,8 +149,8 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
if (isValid) {
// TODO 做一些业务上的校验,判断是否需要校验
}
return baseMapper.deleteByIds(ids) > 0;
}

View File

@ -6,17 +6,13 @@ 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuyuanshen.common.core.domain.PageResult;
import com.fuyuanshen.common.core.domain.model.LoginUser;
import com.fuyuanshen.common.core.utils.PageUtil;
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.DeviceAssignments;
import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.DeviceTypeGrants;
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
@ -107,6 +103,13 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
@Override
@Transactional(rollbackFor = Exception.class)
public void create(DeviceType resources) {
// 校验设备类型名称
List<DeviceType> typeName = deviceTypeMapper.selectList(new QueryWrapper<DeviceType>().eq("type_name", resources.getTypeName()));
if (CollectionUtil.isNotEmpty(typeName)) {
throw new RuntimeException("设备类型名称已存在,无法新增!!!");
}
LoginUser loginUser = LoginHelper.getLoginUser();
resources.setCustomerId(loginUser.getUserId());
resources.setOwnerCustomerId(loginUser.getUserId());
@ -141,11 +144,23 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
if (deviceType == null) {
throw new RuntimeException("设备类型不存在");
}
List<Device> devices = deviceMapper.selectList(new QueryWrapper<Device>()
.eq("device_type", deviceTypeGrants.getDeviceTypeId()));
if (CollectionUtil.isNotEmpty(devices)) {
throw new RuntimeException("该设备类型已绑定设备,无法修改!!!");
}
// 校验设备类型名称
DeviceType dt = deviceTypeMapper.selectOne(new QueryWrapper<DeviceType>().eq("type_name", resources.getTypeName()));
if (dt != null && !dt.getId().equals(deviceType.getId())) {
throw new RuntimeException("设备类型名称已存在,无法修改!!!");
}
if (!Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
throw new RuntimeException("无权修改该设备类型");
}
// if (deviceMapper.countByTypeId(resources.getId()) > 0)
// throw new RuntimeException("该设备类型已被使用,无法删除");
BeanUtil.copyProperties(resources, deviceType);
deviceTypeMapper.updateById(deviceType);
}

View File

@ -0,0 +1,204 @@
package com.fuyuanshen.equipment.utils.c;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.util.Arrays;
public class DotMatrixDisplaySimulator extends JFrame {
private static final int WIDTH = 160;
private static final int HEIGHT = 80;
private static final int SCALE = 4; // 显示缩放比例
private JComboBox<Integer> fontSizeCombo;
private JComboBox<String> exampleCombo;
private JTextArea textInput;
private DotMatrixPanel displayPanel;
private final String[] examples = {
"紧急通知:现场危险,请立即撤离!",
"警告:高温区域,禁止入内!",
"系统故障:请立即联系技术人员处理",
"安全提示:请佩戴防护装备进入作业区",
"欢迎使用点阵显示屏模拟系统",
"现场危险,停止救援,紧急撤离至安全区域!"
};
public DotMatrixDisplaySimulator() {
super("160x80点阵显示屏模拟器");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800, 600);
setLayout(new BorderLayout());
// 创建控制面板
JPanel controlPanel = new JPanel(new GridLayout(1, 4, 10, 10));
controlPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// 字体大小选择
controlPanel.add(new JLabel("字体大小:"));
fontSizeCombo = new JComboBox<>(new Integer[]{8, 10, 12, 14, 16, 18, 20, 24});
fontSizeCombo.setSelectedItem(14);
controlPanel.add(fontSizeCombo);
// 示例选择
controlPanel.add(new JLabel("示例文本:"));
exampleCombo = new JComboBox<>(examples);
exampleCombo.addActionListener(e -> textInput.setText(examples[exampleCombo.getSelectedIndex()]));
controlPanel.add(exampleCombo);
// 文本输入
textInput = new JTextArea(examples[0]);
textInput.setLineWrap(true);
textInput.setWrapStyleWord(true);
JScrollPane textScroll = new JScrollPane(textInput);
textScroll.setBorder(BorderFactory.createTitledBorder("输入文本"));
// 点阵显示面板
displayPanel = new DotMatrixPanel();
// 添加组件
add(controlPanel, BorderLayout.NORTH);
add(textScroll, BorderLayout.CENTER);
add(displayPanel, BorderLayout.SOUTH);
// 添加事件监听器
fontSizeCombo.addActionListener(e -> displayPanel.repaint());
textInput.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
public void changedUpdate(javax.swing.event.DocumentEvent e) { update(); }
public void removeUpdate(javax.swing.event.DocumentEvent e) { update(); }
public void insertUpdate(javax.swing.event.DocumentEvent e) { update(); }
private void update() {
displayPanel.repaint();
}
});
setLocationRelativeTo(null);
}
class DotMatrixPanel extends JPanel {
private final int panelWidth = WIDTH * SCALE;
private final int panelHeight = HEIGHT * SCALE;
public DotMatrixPanel() {
setPreferredSize(new Dimension(panelWidth, panelHeight + 50));
setBorder(BorderFactory.createTitledBorder("点阵预览 (160x80)"));
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// 绘制点阵背景
g.setColor(Color.WHITE);
g.fillRect(0, 0, panelWidth, panelHeight);
// 绘制网格
g.setColor(new Color(240, 240, 240));
for (int x = 0; x <= WIDTH; x++) {
int xPos = x * SCALE;
g.drawLine(xPos, 0, xPos, panelHeight);
}
for (int y = 0; y <= HEIGHT; y++) {
int yPos = y * SCALE;
g.drawLine(0, yPos, panelWidth, yPos);
}
// 绘制文本
String text = textInput.getText();
int fontSize = (Integer) fontSizeCombo.getSelectedItem();
Font font = new Font("黑体", Font.PLAIN, fontSize);
// 创建虚拟点阵图像
BufferedImage img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_BYTE_BINARY);
Graphics2D imgG = img.createGraphics();
imgG.setColor(Color.WHITE);
imgG.fillRect(0, 0, WIDTH, HEIGHT);
imgG.setColor(Color.BLACK);
imgG.setFont(font);
imgG.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// 绘制文本到虚拟点阵
FontMetrics metrics = imgG.getFontMetrics();
int lineHeight = metrics.getHeight();
int yPos = metrics.getAscent();
String[] lines = text.split("\n");
int maxLines = HEIGHT / lineHeight;
int actualLines = Math.min(lines.length, maxLines);
int totalChars = 0;
for (int i = 0; i < actualLines; i++) {
String line = lines[i];
int lineWidth = metrics.stringWidth(line);
int maxChars = WIDTH / metrics.stringWidth(""); // 估算每行字数
// 截断超过宽度的文本
if (lineWidth > WIDTH) {
while (metrics.stringWidth(line) > WIDTH) {
line = line.substring(0, line.length() - 1);
}
line += "...";
}
// 居中显示文本
int xPos = (WIDTH - metrics.stringWidth(line)) / 2;
imgG.drawString(line, xPos, yPos);
totalChars += line.length();
yPos += lineHeight;
if (yPos + lineHeight > HEIGHT) break;
}
imgG.dispose();
// 绘制到预览面板
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
int rgb = img.getRGB(x, y) & 0xFFFFFF;
if (rgb != 0xFFFFFF) { // 黑色像素
g.setColor(Color.BLACK);
g.fillRect(x * SCALE, y * SCALE, SCALE, SCALE);
}
}
}
// 显示统计信息
g.setColor(Color.BLACK);
g.setFont(new Font("宋体", Font.PLAIN, 12));
String info = String.format("字体大小: %dpt | 显示行数: %d/%d | 显示字数: %d",
fontSize, actualLines, maxLines, totalChars);
g.drawString(info, 10, panelHeight + 20);
String capacity = String.format("容量分析: %d×80点阵可显示%d-%d个汉字%dpt字体",
WIDTH,
(int)(WIDTH*HEIGHT/(fontSize*fontSize*1.2)),
(int)(WIDTH*HEIGHT/(fontSize*fontSize*0.8)),
fontSize);
g.drawString(capacity, 10, panelHeight + 35);
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
DotMatrixDisplaySimulator frame = new DotMatrixDisplaySimulator();
frame.setVisible(true);
// 显示使用提示
String message = "<html><div style='text-align:center;'><b>160×80点阵显示屏文字容量分析</b><br><br>"
+ "• 使用上方下拉菜单选择字体大小和示例文本<br>"
+ "• 在文本区域输入自定义内容<br>"
+ "• 点阵预览区域实时显示效果<br><br>"
+ "<b>容量参考:</b><br>"
+ "8-9pt约20字/行 × 10行 = 200字<br>"
+ "10-11pt约16字/行 × 8行 = 128字<br>"
+ "12-13pt约13字/行 × 6行 = 78字<br>"
+ "14-15pt约11字/行 × 5行 = 55字<br>"
+ "16-18pt约9字/行 × 4行 = 36字<br>"
+ "20-24pt约7字/行 × 3行 = 21字</div></html>";
JOptionPane.showMessageDialog(frame, message, "使用说明", JOptionPane.INFORMATION_MESSAGE);
});
}
}

View File

@ -0,0 +1,185 @@
package com.fuyuanshen.equipment.utils.c;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class TextToDotMatrix {
public static void main(String[] args) {
String text = "现场危险,停止救援,\n紧急撤离至安全区域";
int width = 160; // 点阵宽度
int height = 80; // 点阵高度
try {
// 1. 创建点阵图片
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g = image.createGraphics();
// 设置背景为白色
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
// 设置字体并居中显示文本
g.setColor(Color.BLACK);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// 自动调整字体大小以适应区域
Font font = findBestFitFont(text, width, height, g);
g.setFont(font);
// 计算文本位置并绘制
drawCenteredText(g, text, width, height);
g.dispose();
// 2. 生成二进制数组
List<Byte> byteList = new ArrayList<>();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += 8) {
byte b = 0;
for (int bit = 0; bit < 8; bit++) {
int xPos = x + bit;
if (xPos < width) {
int rgb = image.getRGB(xPos, y) & 0xFFFFFF;
if (rgb != 0xFFFFFF) { // 黑色像素
b |= (1 << (7 - bit));
}
}
}
byteList.add(b);
}
}
// 转换为字节数组
byte[] dotMatrixData = new byte[byteList.size()];
for (int i = 0; i < byteList.size(); i++) {
dotMatrixData[i] = byteList.get(i);
}
// 3. 保存预览图片
ImageIO.write(image, "png", new File("warning_display.png"));
System.out.println("预览图片已生成: warning_display.png");
// 4. 打印点阵数据信息
System.out.println("\n点阵数据信息:");
System.out.println("尺寸: " + width + "x" + height + " 像素");
System.out.println("数据大小: " + dotMatrixData.length + " 字节");
System.out.println("每行字节数: " + (width / 8));
System.out.println("总行数: " + height);
// 5. 打印二进制数组(十六进制格式)
System.out.println("\n点阵数据字节数组 (HEX):");
System.out.print("byte[] dotMatrixData = {");
for (int i = 0; i < dotMatrixData.length; i++) {
System.out.printf("0x%02X", dotMatrixData[i] & 0xFF);
if (i < dotMatrixData.length - 1) System.out.print(", ");
if (i % 16 == 15) System.out.println();
}
System.out.println("};\n");
// 6. 打印点阵图预览
System.out.println("点阵图预览 (缩小版):");
printTextPreview(image);
} catch (IOException e) {
e.printStackTrace();
}
}
// 自动寻找最佳字体大小
private static Font findBestFitFont(String text, int width, int height, Graphics2D g) {
int fontSize = 20; // 初始字体大小
Font bestFont = null;
int bestHeight = 0;
while (fontSize > 8) {
Font font = new Font("黑体", Font.BOLD, fontSize);
g.setFont(font);
FontMetrics metrics = g.getFontMetrics();
// 计算文本所需高度
String[] lines = text.split("\n");
int textHeight = metrics.getHeight() * lines.length;
// 检查是否超出高度
if (textHeight < height * 0.8) {
bestFont = font;
bestHeight = textHeight;
break;
}
fontSize--;
}
// 如果没有找到合适字体,使用最小字体
if (bestFont == null) {
bestFont = new Font("黑体", Font.BOLD, 8);
}
System.out.println("使用字体: " + bestFont.getSize() + "pt");
return bestFont;
}
// 居中绘制文本
private static void drawCenteredText(Graphics g, String text, int width, int height) {
FontMetrics metrics = g.getFontMetrics();
String[] lines = text.split("\n");
// 计算总文本高度
int totalHeight = metrics.getHeight() * lines.length;
// 计算起始Y位置
int y = (height - totalHeight) / 2 + metrics.getAscent();
for (String line : lines) {
// 计算X位置使文本居中
int x = (width - metrics.stringWidth(line)) / 2;
g.drawString(line, x, y);
y += metrics.getHeight();
}
}
// 打印文本预览
private static void printTextPreview(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
// 缩小预览比例
int scale = 4;
int previewWidth = width / scale;
int previewHeight = height / scale;
for (int y = 0; y < previewHeight; y++) {
for (int x = 0; x < previewWidth; x++) {
int pixelCount = 0;
for (int dy = 0; dy < scale; dy++) {
for (int dx = 0; dx < scale; dx++) {
int origX = x * scale + dx;
int origY = y * scale + dy;
if (origX < width && origY < height) {
int rgb = image.getRGB(origX, origY) & 0xFFFFFF;
if (rgb != 0xFFFFFF) { // 黑色像素
pixelCount++;
}
}
}
}
// 根据黑色像素密度选择字符
if (pixelCount > scale * scale * 0.7) {
System.out.print("██");
} else if (pixelCount > scale * scale * 0.4) {
System.out.print("▓▓");
} else if (pixelCount > scale * scale * 0.1) {
System.out.print("░░");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}

View File

@ -1,5 +1,6 @@
package com.fuyuanshen.system.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
@ -11,6 +12,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.common.core.enums.UserStatus;
import com.fuyuanshen.common.core.enums.UserType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.fuyuanshen.common.core.constant.CacheNames;
@ -76,20 +79,20 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
Map<String, Object> params = user.getParams();
QueryWrapper<SysUser> wrapper = Wrappers.query();
wrapper.eq("u.del_flag", SystemConstants.NORMAL)
.eq(ObjectUtil.isNotNull(user.getUserId()), "u.user_id", user.getUserId())
.in(StringUtils.isNotBlank(user.getUserIds()), "u.user_id", StringUtils.splitTo(user.getUserIds(), Convert::toLong))
.like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName())
.like(StringUtils.isNotBlank(user.getNickName()), "u.nick_name", user.getNickName())
.eq(StringUtils.isNotBlank(user.getStatus()), "u.status", user.getStatus())
.like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber())
.between(params.get("beginTime") != null && params.get("endTime") != null,
"u.create_time", params.get("beginTime"), params.get("endTime"))
.and(ObjectUtil.isNotNull(user.getDeptId()), w -> {
List<SysDept> deptList = deptMapper.selectListByParentId(user.getDeptId());
List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId);
ids.add(user.getDeptId());
w.in("u.dept_id", ids);
}).orderByAsc("u.user_id");
.eq(ObjectUtil.isNotNull(user.getUserId()), "u.user_id", user.getUserId())
.in(StringUtils.isNotBlank(user.getUserIds()), "u.user_id", StringUtils.splitTo(user.getUserIds(), Convert::toLong))
.like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName())
.like(StringUtils.isNotBlank(user.getNickName()), "u.nick_name", user.getNickName())
.eq(StringUtils.isNotBlank(user.getStatus()), "u.status", user.getStatus())
.like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber())
.between(params.get("beginTime") != null && params.get("endTime") != null,
"u.create_time", params.get("beginTime"), params.get("endTime"))
.and(ObjectUtil.isNotNull(user.getDeptId()), w -> {
List<SysDept> deptList = deptMapper.selectListByParentId(user.getDeptId());
List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId);
ids.add(user.getDeptId());
w.in("u.dept_id", ids);
}).orderByAsc("u.user_id");
if (StringUtils.isNotBlank(user.getExcludeUserIds())) {
wrapper.notIn("u.user_id", StringUtils.splitTo(user.getExcludeUserIds(), Convert::toLong));
}
@ -106,11 +109,11 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
public TableDataInfo<SysUserVo> selectAllocatedList(SysUserBo user, PageQuery pageQuery) {
QueryWrapper<SysUser> wrapper = Wrappers.query();
wrapper.eq("u.del_flag", SystemConstants.NORMAL)
.eq(ObjectUtil.isNotNull(user.getRoleId()), "r.role_id", user.getRoleId())
.like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName())
.eq(StringUtils.isNotBlank(user.getStatus()), "u.status", user.getStatus())
.like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber())
.orderByAsc("u.user_id");
.eq(ObjectUtil.isNotNull(user.getRoleId()), "r.role_id", user.getRoleId())
.like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName())
.eq(StringUtils.isNotBlank(user.getStatus()), "u.status", user.getStatus())
.like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber())
.orderByAsc("u.user_id");
Page<SysUserVo> page = baseMapper.selectAllocatedList(pageQuery.build(), wrapper);
return TableDataInfo.build(page);
}
@ -126,11 +129,11 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
List<Long> userIds = userRoleMapper.selectUserIdsByRoleId(user.getRoleId());
QueryWrapper<SysUser> wrapper = Wrappers.query();
wrapper.eq("u.del_flag", SystemConstants.NORMAL)
.and(w -> w.ne("r.role_id", user.getRoleId()).or().isNull("r.role_id"))
.notIn(CollUtil.isNotEmpty(userIds), "u.user_id", userIds)
.like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName())
.like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber())
.orderByAsc("u.user_id");
.and(w -> w.ne("r.role_id", user.getRoleId()).or().isNull("r.role_id"))
.notIn(CollUtil.isNotEmpty(userIds), "u.user_id", userIds)
.like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName())
.like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber())
.orderByAsc("u.user_id");
Page<SysUserVo> page = baseMapper.selectUnallocatedList(pageQuery.build(), wrapper);
return TableDataInfo.build(page);
}
@ -183,10 +186,10 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public List<SysUserVo> selectUserByIds(List<Long> userIds, Long deptId) {
return baseMapper.selectUserList(new LambdaQueryWrapper<SysUser>()
.select(SysUser::getUserId, SysUser::getUserName, SysUser::getNickName)
.eq(SysUser::getStatus, SystemConstants.NORMAL)
.eq(ObjectUtil.isNotNull(deptId), SysUser::getDeptId, deptId)
.in(CollUtil.isNotEmpty(userIds), SysUser::getUserId, userIds));
.select(SysUser::getUserId, SysUser::getUserName, SysUser::getNickName)
.eq(SysUser::getStatus, SystemConstants.NORMAL)
.eq(ObjectUtil.isNotNull(deptId), SysUser::getDeptId, deptId)
.in(CollUtil.isNotEmpty(userIds), SysUser::getUserId, userIds));
}
/**
@ -228,8 +231,8 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public boolean checkUserNameUnique(SysUserBo user) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getUserName, user.getUserName())
.ne(ObjectUtil.isNotNull(user.getUserId()), SysUser::getUserId, user.getUserId()));
.eq(SysUser::getUserName, user.getUserName())
.ne(ObjectUtil.isNotNull(user.getUserId()), SysUser::getUserId, user.getUserId()));
return !exist;
}
@ -241,8 +244,8 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public boolean checkPhoneUnique(SysUserBo user) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getPhonenumber, user.getPhonenumber())
.ne(ObjectUtil.isNotNull(user.getUserId()), SysUser::getUserId, user.getUserId()));
.eq(SysUser::getPhonenumber, user.getPhonenumber())
.ne(ObjectUtil.isNotNull(user.getUserId()), SysUser::getUserId, user.getUserId()));
return !exist;
}
@ -254,8 +257,8 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public boolean checkEmailUnique(SysUserBo user) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getEmail, user.getEmail())
.ne(ObjectUtil.isNotNull(user.getUserId()), SysUser::getUserId, user.getUserId()));
.eq(SysUser::getEmail, user.getEmail())
.ne(ObjectUtil.isNotNull(user.getUserId()), SysUser::getUserId, user.getUserId()));
return !exist;
}
@ -359,6 +362,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
insertUserRole(userId, roleIds, true);
}
/**
* 修改用户状态
*
@ -368,12 +372,19 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
*/
@Override
public int updateUserStatus(Long userId, String status) {
if (UserStatus.DISABLE.getCode().equals(status)) {
// 强制下线
String tokenId = UserType.SYS_USER.getUserType() + ":" + userId;
StpUtil.logout(tokenId);
}
return baseMapper.update(null,
new LambdaUpdateWrapper<SysUser>()
.set(SysUser::getStatus, status)
.eq(SysUser::getUserId, userId));
new LambdaUpdateWrapper<SysUser>()
.set(SysUser::getStatus, status)
.eq(SysUser::getUserId, userId));
}
/**
* 修改用户基本信息
*
@ -384,12 +395,12 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public int updateUserProfile(SysUserBo user) {
return baseMapper.update(null,
new LambdaUpdateWrapper<SysUser>()
.set(ObjectUtil.isNotNull(user.getNickName()), SysUser::getNickName, user.getNickName())
.set(SysUser::getPhonenumber, user.getPhonenumber())
.set(SysUser::getEmail, user.getEmail())
.set(SysUser::getSex, user.getSex())
.eq(SysUser::getUserId, user.getUserId()));
new LambdaUpdateWrapper<SysUser>()
.set(ObjectUtil.isNotNull(user.getNickName()), SysUser::getNickName, user.getNickName())
.set(SysUser::getPhonenumber, user.getPhonenumber())
.set(SysUser::getEmail, user.getEmail())
.set(SysUser::getSex, user.getSex())
.eq(SysUser::getUserId, user.getUserId()));
}
/**
@ -402,9 +413,9 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public boolean updateUserAvatar(Long userId, Long avatar) {
return baseMapper.update(null,
new LambdaUpdateWrapper<SysUser>()
.set(SysUser::getAvatar, avatar)
.eq(SysUser::getUserId, userId)) > 0;
new LambdaUpdateWrapper<SysUser>()
.set(SysUser::getAvatar, avatar)
.eq(SysUser::getUserId, userId)) > 0;
}
/**
@ -417,9 +428,9 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public int resetUserPwd(Long userId, String password) {
return baseMapper.update(null,
new LambdaUpdateWrapper<SysUser>()
.set(SysUser::getPassword, password)
.eq(SysUser::getUserId, userId));
new LambdaUpdateWrapper<SysUser>()
.set(SysUser::getPassword, password)
.eq(SysUser::getUserId, userId));
}
/**
@ -471,7 +482,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
}
// 判断是否具有此角色的操作权限
List<SysRoleVo> roles = roleMapper.selectRoleList(
new QueryWrapper<SysRole>().in("r.role_id", roleList));
new QueryWrapper<SysRole>().in("r.role_id", roleList));
if (CollUtil.isEmpty(roles)) {
throw new ServiceException("没有权限访问角色的数据");
}
@ -561,7 +572,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public String selectUserNameById(Long userId) {
SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
.select(SysUser::getUserName).eq(SysUser::getUserId, userId));
.select(SysUser::getUserName).eq(SysUser::getUserId, userId));
return ObjectUtils.notNullGetter(sysUser, SysUser::getUserName);
}
@ -575,7 +586,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Cacheable(cacheNames = CacheNames.SYS_NICKNAME, key = "#userId")
public String selectNicknameById(Long userId) {
SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
.select(SysUser::getNickName).eq(SysUser::getUserId, userId));
.select(SysUser::getNickName).eq(SysUser::getUserId, userId));
return ObjectUtils.notNullGetter(sysUser, SysUser::getNickName);
}
@ -606,7 +617,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public String selectPhonenumberById(Long userId) {
SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
.select(SysUser::getPhonenumber).eq(SysUser::getUserId, userId));
.select(SysUser::getPhonenumber).eq(SysUser::getUserId, userId));
return ObjectUtils.notNullGetter(sysUser, SysUser::getPhonenumber);
}
@ -619,7 +630,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public String selectEmailById(Long userId) {
SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
.select(SysUser::getEmail).eq(SysUser::getUserId, userId));
.select(SysUser::getEmail).eq(SysUser::getUserId, userId));
return ObjectUtils.notNullGetter(sysUser, SysUser::getEmail);
}
@ -635,9 +646,9 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
return List.of();
}
List<SysUserVo> list = baseMapper.selectVoList(new LambdaQueryWrapper<SysUser>()
.select(SysUser::getUserId, SysUser::getUserName, SysUser::getNickName, SysUser::getEmail, SysUser::getPhonenumber)
.eq(SysUser::getStatus, SystemConstants.NORMAL)
.in(SysUser::getUserId, userIds));
.select(SysUser::getUserId, SysUser::getUserName, SysUser::getNickName, SysUser::getEmail, SysUser::getPhonenumber)
.eq(SysUser::getStatus, SystemConstants.NORMAL)
.in(SysUser::getUserId, userIds));
return BeanUtil.copyToList(list, UserDTO.class);
}
@ -653,7 +664,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
return List.of();
}
List<SysUserRole> userRoles = userRoleMapper.selectList(
new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getRoleId, roleIds));
new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getRoleId, roleIds));
return StreamUtils.toList(userRoles, SysUserRole::getUserId);
}
@ -671,7 +682,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
// 通过角色ID获取用户角色信息
List<SysUserRole> userRoles = userRoleMapper.selectList(
new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getRoleId, roleIds));
new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getRoleId, roleIds));
// 获取用户ID列表
Set<Long> userIds = StreamUtils.toSet(userRoles, SysUserRole::getUserId);
@ -691,9 +702,9 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
return List.of();
}
List<SysUserVo> list = baseMapper.selectVoList(new LambdaQueryWrapper<SysUser>()
.select(SysUser::getUserId, SysUser::getUserName, SysUser::getNickName, SysUser::getEmail, SysUser::getPhonenumber)
.eq(SysUser::getStatus, SystemConstants.NORMAL)
.in(SysUser::getDeptId, deptIds));
.select(SysUser::getUserId, SysUser::getUserName, SysUser::getNickName, SysUser::getEmail, SysUser::getPhonenumber)
.eq(SysUser::getStatus, SystemConstants.NORMAL)
.in(SysUser::getDeptId, deptIds));
return BeanUtil.copyToList(list, UserDTO.class);
}
@ -711,7 +722,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
// 通过岗位ID获取用户岗位信息
List<SysUserPost> userPosts = userPostMapper.selectList(
new LambdaQueryWrapper<SysUserPost>().in(SysUserPost::getPostId, postIds));
new LambdaQueryWrapper<SysUserPost>().in(SysUserPost::getPostId, postIds));
// 获取用户ID列表
Set<Long> userIds = StreamUtils.toSet(userPosts, SysUserPost::getUserId);
@ -731,11 +742,11 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
return Collections.emptyMap();
}
return baseMapper.selectList(
new LambdaQueryWrapper<SysUser>()
.select(SysUser::getUserId, SysUser::getNickName)
.in(SysUser::getUserId, userIds)
).stream()
.collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName));
new LambdaQueryWrapper<SysUser>()
.select(SysUser::getUserId, SysUser::getNickName)
.in(SysUser::getUserId, userIds)
).stream()
.collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName));
}
/**
@ -750,11 +761,11 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
return Collections.emptyMap();
}
return roleMapper.selectList(
new LambdaQueryWrapper<SysRole>()
.select(SysRole::getRoleId, SysRole::getRoleName)
.in(SysRole::getRoleId, roleIds)
).stream()
.collect(Collectors.toMap(SysRole::getRoleId, SysRole::getRoleName));
new LambdaQueryWrapper<SysRole>()
.select(SysRole::getRoleId, SysRole::getRoleName)
.in(SysRole::getRoleId, roleIds)
).stream()
.collect(Collectors.toMap(SysRole::getRoleId, SysRole::getRoleName));
}
/**
@ -769,11 +780,11 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
return Collections.emptyMap();
}
return deptMapper.selectList(
new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId, SysDept::getDeptName)
.in(SysDept::getDeptId, deptIds)
).stream()
.collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId, SysDept::getDeptName)
.in(SysDept::getDeptId, deptIds)
).stream()
.collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
}
/**
@ -788,11 +799,11 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
return Collections.emptyMap();
}
return postMapper.selectList(
new LambdaQueryWrapper<SysPost>()
.select(SysPost::getPostId, SysPost::getPostName)
.in(SysPost::getPostId, postIds)
).stream()
.collect(Collectors.toMap(SysPost::getPostId, SysPost::getPostName));
new LambdaQueryWrapper<SysPost>()
.select(SysPost::getPostId, SysPost::getPostName)
.in(SysPost::getPostId, postIds)
).stream()
.collect(Collectors.toMap(SysPost::getPostId, SysPost::getPostName));
}
}