web:设备管理

This commit is contained in:
2025-07-08 14:46:05 +08:00
parent b5ae17c3e3
commit 64daff1647
9 changed files with 226 additions and 45 deletions

View File

@ -44,7 +44,7 @@ import java.util.List;
* @Date: 2025/5/16
**/
@Slf4j
@Tag(name = "设备管理", description = "设备:设备管理")
@Tag(name = "web:设备管理", description = "web:设备管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/device")

View File

@ -0,0 +1,18 @@
package com.fuyuanshen.equipment.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fuyuanshen.equipment.domain.DeviceAssignments;
import org.apache.ibatis.annotations.Mapper;
/**
* @author 97433
* @description 针对表【device_assignments】的数据库操作Mapper
* @createDate 2025-06-19 18:19:13
* @Entity system.domain.DeviceAssignments
*/
@Mapper
public interface DeviceAssignmentsMapper extends BaseMapper<DeviceAssignments> {
}

View File

@ -0,0 +1,13 @@
package com.fuyuanshen.equipment.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fuyuanshen.equipment.domain.DeviceAssignments;
/**
* @author 97433
* @description 针对表【device_assignments】的数据库操作Service
* @createDate 2025-06-19 18:19:13
*/
public interface DeviceAssignmentsService extends IService<DeviceAssignments> {
}

View File

@ -0,0 +1,17 @@
package com.fuyuanshen.equipment.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuyuanshen.equipment.domain.DeviceAssignments;
import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper;
import com.fuyuanshen.equipment.service.DeviceAssignmentsService;
import org.springframework.stereotype.Service;
/**
* @author 97433
* @description 针对表【device_assignments】的数据库操作Service实现
* @createDate 2025-06-19 18:19:13
*/
@Service
public class DeviceAssignmentsServiceImpl extends ServiceImpl<DeviceAssignmentsMapper, DeviceAssignments> implements DeviceAssignmentsService {
}

View File

@ -17,7 +17,9 @@ import com.fuyuanshen.customer.domain.Customer;
import com.fuyuanshen.customer.mapper.CustomerMapper;
import com.fuyuanshen.equipment.constants.DeviceConstants;
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.dto.AppDeviceBo;
import com.fuyuanshen.equipment.domain.form.DeviceForm;
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
@ -26,9 +28,12 @@ import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
import com.fuyuanshen.equipment.enums.DeviceActiveStatusEnum;
import com.fuyuanshen.equipment.enums.DeviceStatusEnum;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
import com.fuyuanshen.equipment.service.DeviceAssignmentsService;
import com.fuyuanshen.equipment.service.DeviceService;
import com.fuyuanshen.system.domain.vo.SysOssVo;
import com.fuyuanshen.system.service.ISysOssService;
@ -42,6 +47,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;
/**
@ -61,11 +67,13 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
private final DeviceMapper deviceMapper;
private final DeviceTypeMapper deviceTypeMapper;
private final CustomerMapper customerMapper;
private final ISysOssService ossService;
private final DeviceAssignmentsService deviceAssignmentsService;
private final DeviceTypeGrantsMapper deviceTypeGrantsMapper;
/**
* 分页查询设备
@ -112,6 +120,43 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
}
// /**
// * 新增设备
// *
// * @param deviceForm
// * @throws Exception
// */
// @Override
// @Transactional(rollbackFor = Exception.class)
// public void addDevice(DeviceForm deviceForm) throws Exception {
// DeviceTypeQueryCriteria queryCriteria = new DeviceTypeQueryCriteria();
// queryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
// queryCriteria.setCustomerId(LoginHelper.getUserId());
// List<DeviceType> deviceTypes = deviceTypeMapper.findAll(queryCriteria);
// if (deviceTypes.isEmpty()) {
// throw new Exception("设备类型不存在!!!");
// }
//
// // 保存图片并获取URL
// if (deviceForm.getFile() != null) {
// SysOssVo upload = ossService.upload(deviceForm.getFile());
// // 设置图片路径
// deviceForm.setDevicePic(upload.getUrl());
// }
//
// // 转换对象并插入数据库
// Device device = new Device();
// LoginUser loginUser = LoginHelper.getLoginUser();
// device.setCurrentOwnerId(loginUser.getUserId());
// device.setOriginalOwnerId(loginUser.getUserId());
// device.setCreateByName(loginUser.getNickname());
// device.setTypeName(deviceTypes.get(0).getTypeName());
// BeanUtil.copyProperties(deviceForm, device, true);
//
// deviceMapper.insert(device);
//
// }
/**
* 新增设备
*
@ -124,13 +169,13 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
DeviceTypeQueryCriteria queryCriteria = new DeviceTypeQueryCriteria();
queryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
queryCriteria.setCustomerId(LoginHelper.getUserId());
List<DeviceType> deviceTypes = deviceTypeMapper.findAll(queryCriteria);
if (deviceTypes.isEmpty()) {
DeviceTypeGrants typeGrants = deviceTypeGrantsMapper.selectById(queryCriteria.getDeviceTypeId());
DeviceType deviceTypes = deviceTypeMapper.selectById(typeGrants.getDeviceTypeId());
if (deviceTypes== null) {
throw new Exception("设备类型不存在!!!");
}
// 保存图片并获取URL
// String imageUrl = saveDeviceImage(deviceForm.getFile(), deviceForm.getDeviceName());
if (deviceForm.getFile() != null) {
SysOssVo upload = ossService.upload(deviceForm.getFile());
// 设置图片路径
@ -143,11 +188,26 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
device.setCurrentOwnerId(loginUser.getUserId());
device.setOriginalOwnerId(loginUser.getUserId());
device.setCreateByName(loginUser.getNickname());
device.setTypeName(deviceTypes.get(0).getTypeName());
device.setTypeName(deviceTypes.getTypeName());
device.setDeviceType(deviceTypes.getId());
BeanUtil.copyProperties(deviceForm, device, true);
deviceMapper.insert(device);
// 新增设备类型记录
DeviceAssignments assignments = new DeviceAssignments();
assignments.setDeviceId(device.getId());
assignments.setAssignedAt(LocalDateTime.now());
// 分配者
assignments.setAssignerId(loginUser.getUserId());
assignments.setAssignerName(loginUser.getUsername());
// 接收者
assignments.setAssigneeId(loginUser.getUserId());
assignments.setActive(DeviceActiveStatusEnum.ACTIVE.getCode());
String lever = loginUser.getUserId() + ":";
assignments.setLever(lever);
deviceAssignmentsService.save(assignments);
}
@ -232,17 +292,20 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
public void deleteAll(List<Long> ids) {
List<Long> invalidIds = new ArrayList<>();
for (Long id : ids) {
Device deviceType = deviceMapper.selectById(id);
if (deviceType == null || !Objects.equals(deviceType.getCurrentOwnerId(), LoginHelper.getUserId())) {
invalidIds.add(id);
}
}
if (!invalidIds.isEmpty()) {
throw new RuntimeException("以下设备无法删除ID 不存在或无权限): " + invalidIds);
}
deviceMapper.deleteByIds(ids);
deviceTypeGrantsMapper.deleteByIds(ids);
//
// for (Long id : ids) {
//
// Device deviceType = deviceMapper.selectById(id);
// if (deviceType == null || !Objects.equals(deviceType.getCurrentOwnerId(), LoginHelper.getUserId())) {
// invalidIds.add(id);
// }
// }
// if (!invalidIds.isEmpty()) {
// throw new RuntimeException("以下设备无法删除ID 不存在或无权限): " + invalidIds);
// }
//
// deviceMapper.deleteByIds(ids);
}

View File

@ -175,13 +175,20 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
*/
@Override
public DeviceType getCommunicationMode(Long id) {
DeviceType deviceType = deviceTypeMapper.selectById(id);
DeviceTypeGrants deviceTypeGrants = deviceTypeGrantsMapper.selectById(id);
if (deviceTypeGrants == null) {
throw new RuntimeException("设备类型不存在");
}
DeviceType deviceType = deviceTypeMapper.selectById(deviceTypeGrants.getDeviceTypeId());
if (deviceType == null) {
throw new RuntimeException("设备类型不存在");
}
if (!Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
throw new RuntimeException("无权获取该设备类型通讯方式");
}
//
// if (!Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
// throw new RuntimeException("无权获取该设备类型通讯方式");
// }
return deviceType;
}