forked from dyf/fys-Multi-tenant
用户注销
This commit is contained in:
@ -92,7 +92,14 @@ public class AppAuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户注销
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/cancelAccount")
|
||||||
|
public R<Void> cancelAccount() {
|
||||||
|
loginService.cancelAccount();
|
||||||
|
return R.ok("用户注销成功");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出登录
|
* 退出登录
|
||||||
|
@ -11,6 +11,6 @@ public class DeviceInstructDto {
|
|||||||
/**
|
/**
|
||||||
* 下发指令
|
* 下发指令
|
||||||
*/
|
*/
|
||||||
private Object instructValue;
|
private String instructValue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ import com.fuyuanshen.app.domain.AppDeviceBindRecord;
|
|||||||
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
||||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||||
import com.fuyuanshen.app.domain.dto.APPReNameDTO;
|
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.APPDeviceTypeVo;
|
||||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||||
@ -16,10 +18,13 @@ import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper;
|
|||||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||||
import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper;
|
import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper;
|
||||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||||
|
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
|
||||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||||
import com.fuyuanshen.common.core.utils.ObjectUtils;
|
import com.fuyuanshen.common.core.utils.ObjectUtils;
|
||||||
|
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||||
|
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||||
import com.fuyuanshen.equipment.domain.Device;
|
import com.fuyuanshen.equipment.domain.Device;
|
||||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||||
@ -32,16 +37,18 @@ import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
|||||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||||
import com.fuyuanshen.equipment.utils.c.ReliableTextToBitmap;
|
import com.fuyuanshen.equipment.utils.c.ReliableTextToBitmap;
|
||||||
import com.fuyuanshen.system.mqtt.config.MqttGateway;
|
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||||
import com.fuyuanshen.system.mqtt.constants.MqttConstants;
|
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.time.Duration;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||||
|
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -283,5 +290,139 @@ public class AppDeviceBizService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) {
|
||||||
|
try {
|
||||||
|
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||||
|
if (device == null) {
|
||||||
|
throw new ServiceException("设备不存在");
|
||||||
|
}
|
||||||
|
MultipartFile file = bo.getFile();
|
||||||
|
|
||||||
|
byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600);
|
||||||
|
System.out.println("长度:" + largeData.length);
|
||||||
|
|
||||||
|
System.out.println("原始数据大小: " + largeData.length + " 字节");
|
||||||
|
|
||||||
|
int[] ints = convertHexToDecimal(largeData);
|
||||||
|
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
|
||||||
|
|
||||||
|
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei());
|
||||||
|
|
||||||
|
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||||
|
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||||
|
System.out.println("第0块数据大小: " + specificChunk.length + " 字节");
|
||||||
|
System.out.println("第0块数据: " + Arrays.toString(specificChunk));
|
||||||
|
|
||||||
|
ArrayList<Integer> intData = new ArrayList<>();
|
||||||
|
intData.add(3);
|
||||||
|
intData.add(1);
|
||||||
|
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk),intData);
|
||||||
|
intData.add(0);
|
||||||
|
intData.add(0);
|
||||||
|
intData.add(0);
|
||||||
|
intData.add(0);
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("instruct", intData);
|
||||||
|
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
|
||||||
|
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 灯光模式
|
||||||
|
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
||||||
|
*/
|
||||||
|
public void lightModeSettings(DeviceInstructDto params) {
|
||||||
|
try {
|
||||||
|
Long deviceId = params.getDeviceId();
|
||||||
|
Device device = deviceMapper.selectById(deviceId);
|
||||||
|
if(device == null){
|
||||||
|
throw new ServiceException("设备不存在");
|
||||||
|
}
|
||||||
|
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||||
|
ArrayList<Integer> intData = new ArrayList<>();
|
||||||
|
intData.add(1);
|
||||||
|
intData.add(instructValue);
|
||||||
|
intData.add(0);
|
||||||
|
intData.add(0);
|
||||||
|
intData.add(0);
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("instruct", intData);
|
||||||
|
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
|
||||||
|
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//灯光亮度设置
|
||||||
|
public void lightBrightnessSettings(DeviceInstructDto params) {
|
||||||
|
try {
|
||||||
|
Long deviceId = params.getDeviceId();
|
||||||
|
Device device = deviceMapper.selectById(deviceId);
|
||||||
|
if(device == null){
|
||||||
|
throw new ServiceException("设备不存在");
|
||||||
|
}
|
||||||
|
String instructValue = params.getInstructValue();
|
||||||
|
ArrayList<Integer> intData = new ArrayList<>();
|
||||||
|
intData.add(5);
|
||||||
|
String[] values = instructValue.split("\\.");
|
||||||
|
String value1 = values[0];
|
||||||
|
String value2 = values[1];
|
||||||
|
if(StringUtils.isNoneBlank(value1)){
|
||||||
|
intData.add(Integer.parseInt(value1));
|
||||||
|
}
|
||||||
|
if(StringUtils.isNoneBlank(value2)){
|
||||||
|
intData.add(Integer.parseInt(value2));
|
||||||
|
}
|
||||||
|
intData.add(0);
|
||||||
|
intData.add(0);
|
||||||
|
intData.add(0);
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("instruct", intData);
|
||||||
|
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
|
||||||
|
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//激光模式设置
|
||||||
|
public void laserModeSettings(DeviceInstructDto params) {
|
||||||
|
try {
|
||||||
|
Long deviceId = params.getDeviceId();
|
||||||
|
Device device = deviceMapper.selectById(deviceId);
|
||||||
|
if(device == null){
|
||||||
|
throw new ServiceException("设备不存在");
|
||||||
|
}
|
||||||
|
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||||
|
ArrayList<Integer> intData = new ArrayList<>();
|
||||||
|
intData.add(4);
|
||||||
|
intData.add(instructValue);
|
||||||
|
intData.add(0);
|
||||||
|
intData.add(0);
|
||||||
|
intData.add(0);
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("instruct", intData);
|
||||||
|
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
|
||||||
|
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String mapReverseGeocoding(DeviceInstructDto params) {
|
||||||
|
// Long deviceId = params.getDeviceId();
|
||||||
|
// Device device = deviceMapper.selectById(deviceId);
|
||||||
|
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("device_imei", params.getDeviceImei());
|
||||||
|
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||||
|
if(ObjectUtils.length( devices) ==0){
|
||||||
|
throw new ServiceException("设备不存在");
|
||||||
|
}
|
||||||
|
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,10 +28,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +48,7 @@ public class AppLoginService {
|
|||||||
private Integer lockTime;
|
private Integer lockTime;
|
||||||
|
|
||||||
private final ISysTenantService tenantService;
|
private final ISysTenantService tenantService;
|
||||||
private final IAppRoleService roleService;
|
private final IAppUserService appUserService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,5 +181,24 @@ public class AppLoginService {
|
|||||||
throw new TenantException("tenant.expired");
|
throw new TenantException("tenant.expired");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user