1
0

设备类型管理接口

This commit is contained in:
2025-07-01 09:32:22 +08:00
parent 933e74235f
commit 440aec266b
5 changed files with 28 additions and 111 deletions

View File

@ -32,7 +32,6 @@ public interface DeviceTypeService extends IService<DeviceType> {
*/
List<DeviceType> queryAll(DeviceTypeQueryCriteria criteria);
/**
* 查询所有设备类型
*
@ -48,7 +47,7 @@ public interface DeviceTypeService extends IService<DeviceType> {
void create(DeviceType resources);
/**
* 编辑
* 修改设备类型
*
* @param resources /
*/

View File

@ -4,6 +4,7 @@ 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.utils.PageUtil;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
@ -37,11 +38,16 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
*/
@Override
public PageResult<DeviceType> queryAll(DeviceTypeQueryCriteria criteria, Page<Object> page) {
return PageUtil.toPage(deviceTypeMapper.findAll(criteria, page));
}
@Override
public List<DeviceType> queryAll(DeviceTypeQueryCriteria criteria) {
return deviceTypeMapper.findAll(criteria);
}
/**
* 查询所有设备类型
*
@ -49,32 +55,9 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
*/
@Override
public List<DeviceType> queryDeviceTypes() {
// // JwtUserDto userCache = userCacheManager.getUserCache(SecurityUtils.getCurrentUsername());
// User currentUser = userMapper.findByUsername(SecurityUtils.getCurrentUsername());
// DeviceTypeQueryCriteria criteria = new DeviceTypeQueryCriteria();
// // 非超级管理员增加数据隔离(根据租户隔离)
// // if (userCache.getUser().getTenantId() != null && !userCache.getUser().getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
// // List<User> users = userMapper.findByTenantId(userCache.getUser().getTenantId());
// // Set<Long> userIds = users.stream().map(User::getId).collect(Collectors.toSet());
// // criteria.setCustomerIds(userIds);
// // }
//
// // 非超级管理员增加数据隔离(只能看到自己创建的设备类型)
// if (currentUser.getTenantId() != null && !currentUser.getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
// //
// QueryWrapper<User> wrapper = new QueryWrapper<>();
// wrapper.eq("username", SecurityUtils.getCurrentUsername());
// User user = userMapper.selectOne(wrapper);
// criteria.setCustomerId(user.getId());
// }
//
// return deviceTypeMapper.findAll(criteria);
return null;
}
@Override
public List<DeviceType> queryAll(DeviceTypeQueryCriteria criteria) {
DeviceTypeQueryCriteria criteria = new DeviceTypeQueryCriteria();
Long userId = LoginHelper.getUserId();
criteria.setCustomerId(userId);
return deviceTypeMapper.findAll(criteria);
}
@ -87,19 +70,10 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
@Override
@Transactional(rollbackFor = Exception.class)
public void create(DeviceType resources) {
// Long deviceTypeId = NanoId.generate(NanoIdLengthEnum.HIGH_CONCURRENCY.getLength());
// resources.setId(deviceTypeId);
// resources.setCustomerId(SecurityUtils.getCurrentUserId());
// resources.setOwnerCustomerId(SecurityUtils.getCurrentUserId());
// deviceTypeMapper.insert(resources);
//
// // 自动授权给自己
// DeviceTypeGrants deviceTypeGrants = new DeviceTypeGrants();
// deviceTypeGrants.setDeviceTypeId(deviceTypeId);
// deviceTypeGrants.setCustomerId(SecurityUtils.getCurrentUserId());
// deviceTypeGrants.setGrantorCustomerId(SecurityUtils.getCurrentUserId());
// deviceTypeGrants.setGrantedAt(new Date());
// deviceTypeGrantsMapper.insert(deviceTypeGrants);
Long userId = LoginHelper.getUserId();
resources.setCustomerId(userId);
resources.setOwnerCustomerId(userId);
deviceTypeMapper.insert(resources);
}
@ -111,17 +85,7 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
@Override
@Transactional(rollbackFor = Exception.class)
public void update(DeviceType resources) {
//
// List<Device> deviceList = deviceMapper.selectList(new QueryWrapper<Device>().eq("device_type", resources.getId()));
// if (CollectionUtil.isNotEmpty(deviceList)) {
// throw new BadRequestException("该设备类型下已有设备,请先解绑设备!!!");
// }
//
// DeviceType deviceType = getById(resources.getId());
// deviceType.copy(resources);
// Timestamp timestamp = new Timestamp(System.currentTimeMillis());
// deviceType.setUpdateTime(timestamp);
// deviceTypeMapper.updateById(deviceType);
deviceTypeMapper.updateById(resources);
}
@ -133,24 +97,7 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAll(List<Long> ids) {
// // 查询所有与 device 关联的 deviceType IDs
// List<Device> deviceList = deviceMapper.selectList(new QueryWrapper<Device>().in("device_type", ids));
// // 提取与 device 关联的 deviceType IDs
// List<Long> filteredIds = deviceList.stream()
// .map(Device::getDeviceType)
// .distinct()
// .collect(Collectors.toList());
// // 从原始 ids 中移除已关联 device 的 id即过滤掉能查到结果的 id
// List<Long> idsToBeDeleted = ids.stream()
// .filter(id -> !filteredIds.contains(id))
// .collect(Collectors.toList());
// if (idsToBeDeleted.isEmpty()) {
// throw new BadRequestException("选中设备类型已绑定设备,请先解绑设备!!!");
// }
// // 删除过滤后的 id 列表
// deviceTypeMapper.deleteBatchIds(idsToBeDeleted);
// deviceTypeGrantsMapper.delete(new QueryWrapper<DeviceTypeGrants>().in("device_type_id", idsToBeDeleted));
deviceTypeMapper.deleteByIds(ids);
}