新增设备

This commit is contained in:
2025-11-20 16:15:15 +08:00
parent 2376a3b42a
commit 00a4394b43

View File

@ -192,10 +192,21 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
throw new BadRequestException("设备IMEI已存在"); throw new BadRequestException("设备IMEI已存在");
} }
DeviceTypeGrants typeGrants = new DeviceTypeGrants();
if (deviceForm.getDeviceType() != null) {
DeviceTypeQueryCriteria queryCriteria = new DeviceTypeQueryCriteria();
queryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
typeGrants = deviceTypeGrantsMapper.selectById(queryCriteria.getDeviceTypeId());
if (typeGrants == null) {
throw new Exception("设备类型不存在!!!");
}
}
// 检查设备类型是否存在,如果不存在则创建 // 检查设备类型是否存在,如果不存在则创建
DeviceType deviceType = null; DeviceType deviceType = null;
if (deviceForm.getDeviceType() != null) { if (deviceForm.getDeviceType() != null) {
deviceType = deviceTypeMapper.selectById(deviceForm.getDeviceType()); deviceType = deviceTypeMapper.selectById(typeGrants.getDeviceTypeId());
} else if (deviceForm.getTypeName() != null) { } else if (deviceForm.getTypeName() != null) {
deviceType = deviceTypeMapper.selectOne(new QueryWrapper<DeviceType>().eq("type_name", deviceForm.getTypeName())); deviceType = deviceTypeMapper.selectOne(new QueryWrapper<DeviceType>().eq("type_name", deviceForm.getTypeName()));
} }
@ -278,7 +289,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
// 保存图片并获取URL // 保存图片并获取URL
if (deviceForm.getFile() != null) { if (deviceForm.getFile() != null) {
String fileHash = fileHashUtil.hash(deviceForm.getFile()); String fileHash = fileHashUtil.hash(deviceForm.getFile());
SysOssVo upload = ossService.updateHash(deviceForm.getFile(),fileHash); SysOssVo upload = ossService.updateHash(deviceForm.getFile(), fileHash);
// 设置图片路径 // 设置图片路径
deviceForm.setDevicePic(upload.getUrl()); deviceForm.setDevicePic(upload.getUrl());
} }
@ -353,7 +364,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
// 处理上传的图片 // 处理上传的图片
if (deviceForm.getFile() != null) { if (deviceForm.getFile() != null) {
String fileHash = fileHashUtil.hash(deviceForm.getFile()); String fileHash = fileHashUtil.hash(deviceForm.getFile());
SysOssVo oss = ossService.updateHash(deviceForm.getFile(),fileHash); SysOssVo oss = ossService.updateHash(deviceForm.getFile(), fileHash);
// 强制将HTTP替换为HTTPS // 强制将HTTP替换为HTTPS
if (oss.getUrl() != null && oss.getUrl().startsWith("http://")) { if (oss.getUrl() != null && oss.getUrl().startsWith("http://")) {
oss.setUrl(oss.getUrl().replaceFirst("^http://", "https://")); oss.setUrl(oss.getUrl().replaceFirst("^http://", "https://"));