forked from dyf/fys-Multi-tenant
设备类型管理
This commit is contained in:
@ -0,0 +1,64 @@
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fuyuanshen.common.core.domain.PageResult;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/14
|
||||
**/
|
||||
public interface DeviceTypeService extends IService<DeviceType> {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param page 分页参数
|
||||
* @return PageResult
|
||||
*/
|
||||
PageResult<DeviceType> queryAll(DeviceTypeQueryCriteria criteria, Page<Object> page);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
*
|
||||
* @param criteria 条件参数
|
||||
* @return List<DeviceTypeDto>
|
||||
*/
|
||||
List<DeviceType> queryAll(DeviceTypeQueryCriteria criteria);
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有设备类型
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<DeviceType> queryDeviceTypes();
|
||||
|
||||
/**
|
||||
* 新增设备类型
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void create(DeviceType resources);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void update(DeviceType resources);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(List<Long> ids);
|
||||
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
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.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceTypeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/14
|
||||
**/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceType> implements DeviceTypeService {
|
||||
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
private final DeviceMapper deviceMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询设备类型
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param page 分页参数
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult<DeviceType> queryAll(DeviceTypeQueryCriteria criteria, Page<Object> page) {
|
||||
|
||||
return PageUtil.toPage(deviceTypeMapper.findAll(criteria, page));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有设备类型
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@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) {
|
||||
return deviceTypeMapper.findAll(criteria);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增设备类型
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改设备类型
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除设备类型
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
@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));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user