forked from dyf/fys-Multi-tenant
分页查询设备
This commit is contained in:
@ -0,0 +1,108 @@
|
||||
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.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceQueryCriteria;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
public interface DeviceService extends IService<Device> {
|
||||
|
||||
/**
|
||||
* 查询设备数据分页
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param page 分页参数
|
||||
* @return PageResult
|
||||
*/
|
||||
PageResult<Device> queryAll(DeviceQueryCriteria criteria, Page<Object> page) throws IOException;
|
||||
|
||||
// /**
|
||||
// * 查询所有数据不分页
|
||||
// *
|
||||
// * @param criteria 条件参数
|
||||
// * @return List<DeviceDto>
|
||||
// */
|
||||
// List<Device> queryAll(DeviceQueryCriteria criteria);
|
||||
//
|
||||
// /**
|
||||
// * 查询所有设备信息
|
||||
// *
|
||||
// * @param criteria
|
||||
// * @return
|
||||
// */
|
||||
// List<Device> queryAllDevices(DeviceQueryCriteria criteria);
|
||||
//
|
||||
// /**
|
||||
// * 创建
|
||||
// *
|
||||
// * @param resources /
|
||||
// */
|
||||
// void create(Device resources);
|
||||
//
|
||||
// /**
|
||||
// * 新增设备
|
||||
// *
|
||||
// * @param resources
|
||||
// */
|
||||
// void addDevice(DeviceForm resources) throws Exception;
|
||||
//
|
||||
// /**
|
||||
// * 编辑
|
||||
// *
|
||||
// * @param resources /
|
||||
// */
|
||||
// void update(DeviceForm resources) throws Exception;
|
||||
//
|
||||
// /**
|
||||
// * 分配客户
|
||||
// */
|
||||
// void assignCustomer(CustomerVo customerVo);
|
||||
//
|
||||
// void withdrawDevice(DeviceForm deviceForm);
|
||||
//
|
||||
// /**
|
||||
// * 多选删除
|
||||
// *
|
||||
// * @param ids /
|
||||
// */
|
||||
// void deleteAll(List<Long> ids);
|
||||
//
|
||||
// /**
|
||||
// * 删除设备分配记录
|
||||
// *
|
||||
// * @param ids
|
||||
// */
|
||||
// void deleteAssign(List<Long> ids);
|
||||
//
|
||||
// /**
|
||||
// * 导出数据
|
||||
// *
|
||||
// * @param all 待导出的数据
|
||||
// * @param response /
|
||||
// * @throws IOException /
|
||||
// */
|
||||
// void download(List<Device> all, HttpServletResponse response) throws IOException;
|
||||
//
|
||||
// /**
|
||||
// * 导入设备数据
|
||||
// *
|
||||
// * @param file
|
||||
// */
|
||||
// void importData(MultipartFile file) throws IOException;
|
||||
//
|
||||
// /**
|
||||
// * 解绑设备
|
||||
// *
|
||||
// * @param deviceForm
|
||||
// */
|
||||
// void unbindDevice(DeviceForm deviceForm);
|
||||
|
||||
}
|
@ -0,0 +1,603 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
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.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询设备
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param page 分页参数
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public PageResult<Device> queryAll(DeviceQueryCriteria criteria, Page<Object> page) throws IOException {
|
||||
|
||||
IPage<Device> devices = deviceMapper.findAll(criteria, page);
|
||||
|
||||
List<Device> records = devices.getRecords();
|
||||
for (Device record : records) {
|
||||
if (record.getDevicePic() == null) {
|
||||
record.setDevicePic("");
|
||||
}
|
||||
}
|
||||
|
||||
return PageUtil.toPage(devices);
|
||||
}
|
||||
|
||||
//
|
||||
// @Override
|
||||
// public List<Device> queryAll(DeviceQueryCriteria criteria) {
|
||||
// return deviceMapper.findAll(criteria);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<Device> queryAllDevices(DeviceQueryCriteria criteria) {
|
||||
// return deviceMapper.findAllDevices(criteria);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void create(Device resources) {
|
||||
// deviceMapper.insert(resources);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 新增设备
|
||||
// *
|
||||
// * @param deviceForm
|
||||
// * @throws Exception
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void addDevice(DeviceForm deviceForm) throws Exception {
|
||||
//
|
||||
// // 获取当前登录用户信息
|
||||
// // Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
// // String username1 = authentication.getName();
|
||||
// // 从缓存获取
|
||||
// // UserDetails currentUser = SecurityUtils.getCurrentUser();
|
||||
// // String username = currentUser.getUsername();
|
||||
// // JwtUserDto jwtUserDto = userCacheManager.getUserCache(username);
|
||||
// User currentUser = userMapper.findByUsername(SecurityUtils.getCurrentUsername());
|
||||
//
|
||||
// if (StringUtils.isNotEmpty(deviceForm.getDeviceMac())) {
|
||||
// QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.eq("device_mac", deviceForm.getDeviceMac());
|
||||
// // queryWrapper.eq("tenant_id", currentUser.getTenantId());
|
||||
// if ((deviceMapper.selectOne(queryWrapper)) != null) {
|
||||
// throw new BadRequestException("设备 mac地址 有误,请仔细核对!!!");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// QueryWrapper<DeviceTypeGrants> deviceTypeGrantsQueryWrapper = new QueryWrapper<>();
|
||||
// deviceTypeGrantsQueryWrapper.eq("customer_id", currentUser.getId());
|
||||
// deviceTypeGrantsQueryWrapper.eq("device_type_id", deviceForm.getDeviceType());
|
||||
// Long count = deviceTypeGrantsMapper.selectCount(deviceTypeGrantsQueryWrapper);
|
||||
// if (count <= 0) {
|
||||
// throw new BadRequestException("请先授权设备类型!!!");
|
||||
// }
|
||||
//
|
||||
// // 保存图片并获取URL
|
||||
// String imageUrl = saveDeviceImage(deviceForm.getFile(), deviceForm.getDeviceMac());
|
||||
// // 设置图片路径
|
||||
// deviceForm.setDevicePic(imageUrl);
|
||||
//
|
||||
// // 转换对象并插入数据库
|
||||
// Device device = new Device();
|
||||
// BeanUtil.copyProperties(deviceForm, device, true);
|
||||
//
|
||||
// // 添加租户ID
|
||||
// device.setTenantId(currentUser.getTenantId());
|
||||
// // 默认状态正常
|
||||
// device.setDeviceStatus(DeviceStatusEnum.NORMAL.getCode());
|
||||
// // SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator();
|
||||
// // device.setId(snowflakeGenerator.next());
|
||||
// device.setCurrentOwnerId(currentUser.getId());
|
||||
// device.setOriginalOwnerId(currentUser.getId());
|
||||
// DeviceType deviceType = deviceTypeMapper.selectById(deviceForm.getDeviceType());
|
||||
// device.setTypeName(deviceType.getTypeName());
|
||||
//
|
||||
// deviceMapper.insert(device);
|
||||
//
|
||||
// // 新增设备类型记录
|
||||
// DeviceAssignments assignments = new DeviceAssignments();
|
||||
// assignments.setDeviceId(device.getId());
|
||||
// assignments.setAssignedAt(LocalDateTime.now());
|
||||
// // 分配者
|
||||
// assignments.setAssignerId(currentUser.getId());
|
||||
// assignments.setAssignerName(currentUser.getUsername());
|
||||
// // 接收者
|
||||
// assignments.setAssigneeId(currentUser.getId());
|
||||
// assignments.setActive(DeviceActiveStatusEnum.ACTIVE.getCode());
|
||||
// String lever = currentUser.getId() + ":";
|
||||
// assignments.setLever(lever);
|
||||
// deviceAssignmentsService.save(assignments);
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * 更新设备信息
|
||||
// *
|
||||
// * @param deviceForm /
|
||||
// * @throws Exception
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void update(DeviceForm deviceForm) throws Exception {
|
||||
// Device device = getById(deviceForm.getId());
|
||||
//
|
||||
// // 处理上传的图片
|
||||
// String imageUrl = saveDeviceImage(deviceForm.getFile(), device.getDeviceMac());
|
||||
// deviceForm.setDevicePic(imageUrl);
|
||||
//
|
||||
// // 更新字段
|
||||
// BeanUtil.copyProperties(deviceForm, device, true);
|
||||
// device.setUpdateTime(new Timestamp(System.currentTimeMillis()));
|
||||
// deviceMapper.updateById(device);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 保存设备图片并返回访问路径
|
||||
// *
|
||||
// * @param file MultipartFile
|
||||
// * @param deviceMac 设备MAC用于生成唯一文件名
|
||||
// * @return 文件存储路径 URL 形式
|
||||
// */
|
||||
// private String saveDeviceImage(MultipartFile file, String deviceMac) throws IOException {
|
||||
// if (file == null || file.isEmpty()) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// String originalFileName = file.getOriginalFilename();
|
||||
// String fileExtension = originalFileName.substring(originalFileName.lastIndexOf(".") + 1);
|
||||
// String newFileName = "PS_" + deviceMac + "." + fileExtension;
|
||||
//
|
||||
// File newFile = new File(filePath + DeviceConstants.FILE_ACCESS_ISOLATION + File.separator + newFileName);
|
||||
//
|
||||
// if (!newFile.getParentFile().exists()) {
|
||||
// newFile.getParentFile().mkdirs();
|
||||
// }
|
||||
//
|
||||
// log.info("图片保存路径: {}", newFile.getAbsolutePath());
|
||||
// file.transferTo(newFile);
|
||||
//
|
||||
// return ip + DeviceConstants.FILE_ACCESS_PREFIX + "/" + DeviceConstants.FILE_ACCESS_ISOLATION + "/" + newFileName;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 分配客户 历史记录版本
|
||||
// *
|
||||
// * @param customerVo
|
||||
// */
|
||||
//
|
||||
// public void assignCustomer1(CustomerVo customerVo) {
|
||||
//
|
||||
// // 防止管理员误操作
|
||||
// User currentUser = userService.findById(SecurityUtils.getCurrentUserId());
|
||||
// if (currentUser.getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
|
||||
// throw new BadRequestException(ExceptionMessages.ADMIN_OPERATION_NOT_ALLOWED);
|
||||
// }
|
||||
//
|
||||
// List<DeviceAssignments> assignments = new ArrayList<>();
|
||||
// List<DeviceTypeGrants> deviceTypeGrants = new ArrayList<>();
|
||||
// List<Device> devices = new ArrayList<>();
|
||||
// customerVo.getDeviceIds().forEach(deviceId -> {
|
||||
//
|
||||
// // 阻止重复分配
|
||||
// Device device = deviceMapper.selectById(deviceId);
|
||||
// if (device.getCustomerId() != null && device.getCustomerId().equals(customerVo.getCustomerId())) {
|
||||
// throw new BadRequestException("设备 " + device.getDeviceName() + " 已被分配给客户 " + device.getCustomerName());
|
||||
// }
|
||||
//
|
||||
// // 自定义16位id
|
||||
// Long generatedId = NanoId.generate(NanoIdLengthEnum.HIGH_CONCURRENCY.getLength());
|
||||
//
|
||||
// // -- 记录分配历史
|
||||
// DeviceAssignments deviceAssignments = new DeviceAssignments();
|
||||
// deviceAssignments.setId(generatedId);
|
||||
// deviceAssignments.setDeviceId(deviceId);
|
||||
// deviceAssignments.setFromCustomerId(currentUser.getId());
|
||||
// deviceAssignments.setToCustomerId(customerVo.getCustomerId());
|
||||
// deviceAssignments.setAssignedAt(LocalDateTime.now());
|
||||
// deviceAssignments.setDeviceTypeGranted(DeviceAuthorizationStatus.AUTHORIZED.getValue());
|
||||
// assignments.add(deviceAssignments);
|
||||
//
|
||||
// // -- 授权设备类型给客户
|
||||
// // QueryWrapper<DeviceTypeGrants> deviceTypeGrantsQueryWrapper = new QueryWrapper<>();
|
||||
// // Long count = deviceTypeGrantsMapper.selectCount(deviceTypeGrantsQueryWrapper);
|
||||
// DeviceTypeGrants deviceTypeGrant = new DeviceTypeGrants();
|
||||
// deviceTypeGrant.setGrantedAt(new Date());
|
||||
// // 设备类型
|
||||
// deviceTypeGrant.setDeviceTypeId(device.getDeviceType());
|
||||
// deviceTypeGrant.setAssignmentId(generatedId);
|
||||
// // 被授权的客户
|
||||
// deviceTypeGrant.setCustomerId(customerVo.getCustomerId());
|
||||
// // 授权方客户
|
||||
// deviceTypeGrant.setGrantorCustomerId(currentUser.getId());
|
||||
// deviceTypeGrants.add(deviceTypeGrant);
|
||||
//
|
||||
// // -- 更新设备所有者
|
||||
// device.setCurrentOwnerId(customerVo.getCustomerId());
|
||||
// devices.add(device);
|
||||
// });
|
||||
//
|
||||
// deviceAssignmentsService.saveBatch(assignments);
|
||||
// deviceTypeGrantsService.saveBatch(deviceTypeGrants);
|
||||
// this.updateBatchById(devices);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 分配客户
|
||||
// *
|
||||
// * @param customerVo
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void assignCustomer(CustomerVo customerVo) {
|
||||
//
|
||||
// // 获取当前登录用户
|
||||
// User currentUser = userService.findById(SecurityUtils.getCurrentUserId());
|
||||
// // 防止管理员误操作
|
||||
// AdminCheckUtil.checkIfSuperAdmin(currentUser);
|
||||
// // 获取分配用户信息
|
||||
// User assignUser = userService.findById(customerVo.getCustomerId());
|
||||
//
|
||||
// // 获取分配设备信息
|
||||
// List<Device> devices = deviceMapper.selectBatchIds(customerVo.getDeviceIds());
|
||||
//
|
||||
// // 批量更新设备状态
|
||||
// List<DeviceTypeGrants> deviceTypeGrants = new ArrayList<>();
|
||||
// for (Device device : devices) {
|
||||
//
|
||||
// // 如果设备已分配给需要分配的客户,则跳过
|
||||
// LambdaQueryWrapper<DeviceAssignments> wrapper = new LambdaQueryWrapper<>();
|
||||
// wrapper.eq(DeviceAssignments::getDeviceId, device.getId()).eq(DeviceAssignments::getAssigneeId, customerVo.getCustomerId()).ne(DeviceAssignments::getActive, DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectList(wrapper);
|
||||
// if (CollectionUtil.isNotEmpty(deviceAssignments)) {
|
||||
// log.info("设备 {} 已分配给客户 {}", device.getDeviceName(), device.getCustomerName());
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// // 更改分配客户
|
||||
// QueryWrapper<DeviceAssignments> q = new QueryWrapper<>();
|
||||
// q.eq("device_id", device.getId());
|
||||
// q.eq("assignee_id", currentUser.getId());
|
||||
// q.ne("active", DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// DeviceAssignments d = new DeviceAssignments();
|
||||
// d.setAssigneeName(assignUser.getUsername());
|
||||
// deviceAssignmentsMapper.update(d, q);
|
||||
//
|
||||
// // 设备失效
|
||||
// // 获取用户的设备记录
|
||||
// DeviceAssignments assignment = deviceAssignmentsMapper.selectOne(new LambdaQueryWrapper<DeviceAssignments>().eq(DeviceAssignments::getDeviceId, device.getId()).eq(DeviceAssignments::getAssigneeId, currentUser.getId()).eq(DeviceAssignments::getActive, DeviceActiveStatusEnum.ACTIVE.getCode()));
|
||||
//
|
||||
// LambdaQueryWrapper<DeviceAssignments> q1 = new LambdaQueryWrapper<>();
|
||||
// q1.eq(DeviceAssignments::getDeviceId, device.getId()).ne(DeviceAssignments::getAssigneeId, currentUser.getId()).like(DeviceAssignments::getLever, assignment.getLever());
|
||||
//
|
||||
// DeviceAssignments d1 = new DeviceAssignments();
|
||||
// d1.setActive(DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// deviceAssignmentsMapper.update(d1, q1);
|
||||
//
|
||||
// // device.setCustomerId(assignUser.getId());
|
||||
// // device.setCustomerName(assignUser.getUsername());
|
||||
//
|
||||
// // 新增设备类型记录
|
||||
// DeviceAssignments assignments = new DeviceAssignments();
|
||||
// assignments.setDeviceId(device.getId());
|
||||
// assignments.setAssignedAt(LocalDateTime.now());
|
||||
// // 分配者
|
||||
// assignments.setAssignerId(currentUser.getId());
|
||||
// assignments.setAssignerName(currentUser.getUsername());
|
||||
// // 接收者
|
||||
// assignments.setAssigneeId(assignUser.getId());
|
||||
// // assignments.setAssigneeName(assignUser.getUsername());
|
||||
// assignments.setActive(DeviceActiveStatusEnum.ACTIVE.getCode());
|
||||
// String lever = assignment.getLever() + ":" + assignUser.getId();
|
||||
// assignments.setLever(lever);
|
||||
// deviceAssignmentsService.save(assignments);
|
||||
//
|
||||
// // // 获取当前用户的所有祖先用户
|
||||
// // List<User> ancestorsById = userMapper.findAncestorsById(currentUser.getId());
|
||||
// // Set<Long> excludedTenantIds = new HashSet<>();
|
||||
// // if (CollectionUtil.isNotEmpty(ancestorsById)) {
|
||||
// // // 提取所有需要排除的 tenant_id
|
||||
// // excludedTenantIds = ancestorsById.stream().map(User::getTenantId).distinct().collect(Collectors.toSet());
|
||||
// // }
|
||||
// // excludedTenantIds.add(currentUser.getTenantId());
|
||||
// // // 构建查询条件:device_mac 相同,并且 tenant_id 不在 excludedTenantIds 列表中
|
||||
// // Wrapper<Device> wrapper = new QueryWrapper<Device>().eq("device_mac", device.getDeviceMac()).notIn("tenant_id", excludedTenantIds);
|
||||
// //
|
||||
// // // 构建要更新的数据
|
||||
// // Device updateDevice = new Device();
|
||||
// // updateDevice.setDeviceStatus(0);
|
||||
// // updateDevice.setUpdateTime(new Timestamp(System.currentTimeMillis()));
|
||||
//
|
||||
// // 根据条件批量更新
|
||||
// // deviceMapper.update(updateDevice, wrapper);
|
||||
//
|
||||
// // 创建并保存设备类型授权记录
|
||||
// createAndSaveDeviceTypeGrants(device, currentUser, customerVo, deviceTypeGrants);
|
||||
// }
|
||||
//
|
||||
// this.updateBatchById(devices);
|
||||
//
|
||||
// deviceTypeGrantsService.saveBatch(deviceTypeGrants);
|
||||
//
|
||||
// //
|
||||
// // // 批量分配
|
||||
// // Set<DeviceType> deviceTypes = new HashSet<>();
|
||||
// // for (Device device : devices) {
|
||||
// // device.setId(null);
|
||||
// // device.setCustomerName(null);
|
||||
// // device.setCustomerId(null);
|
||||
// // device.setTenantId(user.getTenantId());
|
||||
// // device.setCreateTime(timestamp);
|
||||
// // device.setCreateBy(currentUser.getUsername());
|
||||
// // device.setUpdateTime(timestamp);
|
||||
// //
|
||||
// // // 查询设备类型
|
||||
// // DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
// // // SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator();
|
||||
// // Long id = NanoId.generate(NanoIdLengthEnum.HIGH_CONCURRENCY.getLength());
|
||||
// // deviceType.setId(id);
|
||||
// // deviceType.setCreateTime(timestamp);
|
||||
// // deviceType.setCreateBy(currentUser.getUsername());
|
||||
// // deviceType.setCustomerId(customerVo.getCustomerId());
|
||||
// // deviceTypes.add(deviceType);
|
||||
// //
|
||||
// // device.setDeviceType(deviceType.getId());
|
||||
// // }
|
||||
// // this.saveBatch(devices);
|
||||
// // deviceTypeService.saveBatch(deviceTypes);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 撤回设备
|
||||
// *
|
||||
// * @param deviceForm
|
||||
// */
|
||||
// @Override
|
||||
// public void withdrawDevice(DeviceForm deviceForm) {
|
||||
// DeviceAssignments assignment = deviceAssignmentsMapper.selectById(deviceForm.getAssignId());
|
||||
// // 接收者
|
||||
// assignment.setAssigneeName("");
|
||||
// deviceAssignmentsMapper.updateById(assignment);
|
||||
//
|
||||
// LambdaQueryWrapper<DeviceAssignments> q1 = new LambdaQueryWrapper<>();
|
||||
// q1.eq(DeviceAssignments::getAssignerId, assignment.getAssigneeId())
|
||||
// .like(DeviceAssignments::getLever, assignment.getLever())
|
||||
// .ne(DeviceAssignments::getId, assignment.getId());
|
||||
//
|
||||
// DeviceAssignments d1 = new DeviceAssignments();
|
||||
// d1.setActive(DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// deviceAssignmentsMapper.update(d1, q1);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 创建并保存设备类型授权记录
|
||||
// *
|
||||
// * @param device 当前设备对象
|
||||
// * @param currentUser 当前登录用户
|
||||
// * @param customerVo 客户信息
|
||||
// * @param deviceTypeGrants 授权记录集合
|
||||
// */
|
||||
// private void createAndSaveDeviceTypeGrants(Device device, User currentUser, CustomerVo customerVo, List<DeviceTypeGrants> deviceTypeGrants) {
|
||||
// Long generatedId = NanoId.generate(NanoIdLengthEnum.HIGH_CONCURRENCY.getLength());
|
||||
// DeviceTypeGrants deviceTypeGrant = new DeviceTypeGrants();
|
||||
// deviceTypeGrant.setGrantedAt(new Date());
|
||||
// deviceTypeGrant.setDeviceTypeId(device.getDeviceType());
|
||||
// deviceTypeGrant.setAssignmentId(generatedId);
|
||||
// deviceTypeGrant.setCustomerId(customerVo.getCustomerId());
|
||||
// deviceTypeGrant.setGrantorCustomerId(currentUser.getId());
|
||||
// deviceTypeGrants.add(deviceTypeGrant);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 删除设备
|
||||
// *
|
||||
// * @param ids /
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void deleteAll(List<Long> ids) {
|
||||
//
|
||||
// SecurityUtils.getCurrentUserId();
|
||||
//
|
||||
// // Step 1: 查询所有传入的设备(根据 ID)
|
||||
// List<Device> allDevices = deviceMapper.selectBatchIds(ids);
|
||||
// // Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
||||
// Set<Long> nonNullCustomerIds = allDevices.stream().filter(device -> device.getCustomerId() != null && device.getDeviceStatus() == 1).map(Device::getId).collect(Collectors.toSet());
|
||||
// // Step 3: 从原始 ids 中“去掉”这些非空 customer_id 的设备 ID
|
||||
// List<Long> remainingIds = ids.stream().filter(id -> !nonNullCustomerIds.contains(id)).collect(Collectors.toList());
|
||||
// if (CollectionUtil.isEmpty(remainingIds)) {
|
||||
// throw new BadRequestException("已分配的设备不允许删除!!!");
|
||||
// }
|
||||
// List<Device> devices = deviceMapper.selectBatchIds(remainingIds);
|
||||
// for (Device device : devices) {
|
||||
// String devicePic = device.getDevicePic();
|
||||
// if (StringUtils.isNotBlank(devicePic)) {
|
||||
// File file = new File(devicePic);
|
||||
// if (file.exists()) {
|
||||
// if (file.delete()) {
|
||||
// log.info("设备图片删除成功");
|
||||
// } else {
|
||||
// log.error("设备图片删除失败");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// deviceMapper.deleteBatchIds(ids);
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * 删除设备分配记录(分配记录id)
|
||||
// *
|
||||
// * @param ids
|
||||
// */
|
||||
// public void deleteAssign1(List<Long> ids) {
|
||||
// Long currentUserId = SecurityUtils.getCurrentUserId();
|
||||
// // Step 1: 查询所有传入的设备(根据 ID)
|
||||
// // List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectBatchIds(ids);
|
||||
// QueryWrapper<DeviceAssignments> wrapper = new QueryWrapper<>();
|
||||
// // wrapper.eq("active", DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// wrapper.in("device_id", ids);
|
||||
// wrapper.eq("assigner_id", currentUserId);
|
||||
// List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectList(wrapper);
|
||||
// // Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
||||
// Set<Long> nonNullCustomerIds = deviceAssignments.stream().filter(device -> !StringUtils.isNotEmpty(device.getAssigneeName())).map(DeviceAssignments::getId).collect(Collectors.toSet());
|
||||
// if (CollectionUtil.isEmpty(nonNullCustomerIds)) {
|
||||
// throw new BadRequestException("已分配的设备不允许删除!!!");
|
||||
// }
|
||||
//
|
||||
// // QueryWrapper<DeviceAssignments> de = new QueryWrapper<>();
|
||||
// // wrapper.eq("active", DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// // wrapper.in("device_id", ids);
|
||||
// // wrapper.eq("assignee_id", currentUserId);
|
||||
// // deviceAssignmentsMapper.delete(de);
|
||||
//
|
||||
// deviceAssignmentsMapper.deleteBatchIds(nonNullCustomerIds);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 删除设备分配记录(分配记录id)
|
||||
// *
|
||||
// * @param ids
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void deleteAssign(List<Long> ids) {
|
||||
// // Step 1: 查询所有传入的设备(根据 ID)
|
||||
// List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectBatchIds(ids);
|
||||
// // Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
||||
// Set<Long> nonNullCustomerIds = deviceAssignments.stream()
|
||||
// .filter(device -> !StringUtils.isNotEmpty(device.getAssigneeName()))
|
||||
// .map(DeviceAssignments::getId).collect(Collectors.toSet());
|
||||
// if (CollectionUtil.isEmpty(nonNullCustomerIds)) {
|
||||
// throw new BadRequestException("已分配的设备不允许删除!!!");
|
||||
// }
|
||||
//
|
||||
// deviceAssignmentsMapper.deleteBatchIds(nonNullCustomerIds);
|
||||
// deviceTypeGrantsMapper.delete(new QueryWrapper<DeviceTypeGrants>().in("assignment_id", nonNullCustomerIds));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void download(List<Device> all, HttpServletResponse response) throws IOException {
|
||||
// List<Map<String, Object>> list = new ArrayList<>();
|
||||
// for (Device device : all) {
|
||||
// Map<String, Object> map = new LinkedHashMap<>();
|
||||
// map.put("设备类型", device.getTypeName());
|
||||
// map.put("客户号", device.getCustomerId());
|
||||
// // map.put("设备编号", device.getDeviceNo());
|
||||
// map.put("设备名称", device.getDeviceName());
|
||||
// // map.put("设备图片", device.getDevicePic());
|
||||
// map.put("设备MAC", device.getDeviceMac());
|
||||
// map.put("设备SN", device.getDeviceSn());
|
||||
// map.put("创建者", device.getCreateBy());
|
||||
// map.put("更新者", device.getUpdateBy());
|
||||
// map.put("创建时间", device.getCreateTime());
|
||||
// map.put("更新时间", device.getUpdateTime());
|
||||
// list.add(map);
|
||||
// }
|
||||
// FileUtil.downloadExcel(list, response);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void importData(MultipartFile file) throws IOException {
|
||||
// String line = "";
|
||||
// String csvSplitBy = ",";
|
||||
// List<Device> devices = new ArrayList<>();
|
||||
// User currentUser = userService.findByName(SecurityUtils.getCurrentUsername());
|
||||
//
|
||||
// InputStream inputStream = file.getInputStream();
|
||||
// InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "GB2312");
|
||||
// BufferedReader br = new BufferedReader(inputStreamReader);
|
||||
//
|
||||
// // BufferedReader br = new BufferedReader(new FileReader((File) file));
|
||||
// br.readLine(); // 跳过第一行
|
||||
// while ((line = br.readLine()) != null) {
|
||||
// // 使用分隔符分割并存储到List中
|
||||
// String[] values = line.split(csvSplitBy);
|
||||
// Device device = new Device();
|
||||
// device.setDeviceName(values[0]);
|
||||
// device.setDeviceMac(values[1]);
|
||||
// device.setDeviceSn(values[2]);
|
||||
// device.setCreateBy(currentUser.getUsername());
|
||||
// device.setUpdateBy(currentUser.getUsername());
|
||||
// devices.add(device);
|
||||
// }
|
||||
//
|
||||
// this.saveBatch(devices);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 解绑设备
|
||||
// *
|
||||
// * @param deviceForm
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional
|
||||
// public void unbindDevice(DeviceForm deviceForm) {
|
||||
//
|
||||
// QueryWrapper<APPDevice> queryWrapper = new QueryWrapper<>();
|
||||
// if (StringUtils.isNotEmpty(deviceForm.getDeviceMac())) {
|
||||
// queryWrapper.eq("device_mac", deviceForm.getDeviceMac());
|
||||
// }
|
||||
// if (StringUtils.isNotEmpty(deviceForm.getDeviceImei())) {
|
||||
// queryWrapper.eq("device_imei", deviceForm.getDeviceImei());
|
||||
// }
|
||||
// appDeviceMapper.delete(queryWrapper);
|
||||
// Device device = new Device();
|
||||
// device.setId(deviceForm.getId());
|
||||
// device.setBindingStatus(BindingStatusEnum.UNBOUND.getCode());
|
||||
// deviceMapper.updateById(device);
|
||||
// }
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user