|
|
|
@ -3,7 +3,6 @@ package com.fuyuanshen.equipment.service.impl;
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
|
|
import cn.hutool.core.lang.generator.SnowflakeGenerator;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
@ -32,7 +31,6 @@ 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.DeviceAssignmentsMapper;
|
|
|
|
|
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
|
|
|
|
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
|
|
|
|
@ -42,7 +40,6 @@ import com.fuyuanshen.equipment.service.DeviceService;
|
|
|
|
|
import com.fuyuanshen.equipment.service.DeviceTypeGrantsService;
|
|
|
|
|
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
|
|
|
|
import com.fuyuanshen.system.service.ISysOssService;
|
|
|
|
|
import com.fuyuanshen.system.service.ISysUserService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
@ -54,7 +51,9 @@ import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description:
|
|
|
|
@ -207,16 +206,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|
|
|
|
if (deviceTypes.isEmpty()) {
|
|
|
|
|
throw new Exception("设备类型不存在!!!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceQueryCriteria queryCriteria = new DeviceQueryCriteria();
|
|
|
|
|
queryCriteria.setDeviceId(deviceAssignments.getDeviceId());
|
|
|
|
|
queryCriteria.setCustomerId(LoginHelper.getUserId());
|
|
|
|
|
queryCriteria.setCurrentOwnerId(LoginHelper.getUserId());
|
|
|
|
|
List<Device> devices = deviceMapper.findAll(queryCriteria);
|
|
|
|
|
if (devices.isEmpty()) {
|
|
|
|
|
Device device = deviceMapper.selectById(deviceAssignments.getDeviceId());
|
|
|
|
|
if (device == null) {
|
|
|
|
|
throw new Exception("设备不存在!!!");
|
|
|
|
|
}
|
|
|
|
|
Device device = devices.get(0);
|
|
|
|
|
// 设备类型
|
|
|
|
|
Long deviceType = device.getDeviceType();
|
|
|
|
|
|
|
|
|
|
// 处理上传的图片
|
|
|
|
|
if (deviceForm.getFile() != null) {
|
|
|
|
@ -228,6 +223,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|
|
|
|
// 更新字段
|
|
|
|
|
BeanUtil.copyProperties(deviceForm, device, true);
|
|
|
|
|
device.setId(deviceAssignments.getDeviceId());
|
|
|
|
|
device.setDeviceType(deviceType);
|
|
|
|
|
device.setUpdateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
|
|
deviceMapper.updateById(device);
|
|
|
|
|
}
|
|
|
|
@ -312,6 +308,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|
|
|
|
// 批量更新设备状态
|
|
|
|
|
List<DeviceTypeGrants> deviceTypeGrants = new ArrayList<>();
|
|
|
|
|
for (DeviceAssignments assignment : assignments) {
|
|
|
|
|
|
|
|
|
|
if (assignment.getToCustomerId() != null) {
|
|
|
|
|
log.info("设备已经分配客户!!!");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Device device = deviceMapper.selectById(assignment.getDeviceId());
|
|
|
|
|
|
|
|
|
|
// 如果设备已分配给需要分配的客户,则跳过
|
|
|
|
@ -326,6 +328,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|
|
|
|
|
|
|
|
|
// 更改分配客户
|
|
|
|
|
assignment.setAssigneeName(assignUser.getNickName());
|
|
|
|
|
assignment.setToCustomerId(customerVo.getCustomerId());
|
|
|
|
|
deviceAssignmentsMapper.updateById(assignment);
|
|
|
|
|
|
|
|
|
|
// 设备失效
|
|
|
|
@ -356,7 +359,9 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|
|
|
|
deviceAssignmentsService.save(dam);
|
|
|
|
|
|
|
|
|
|
// 判断设备类型是否存在
|
|
|
|
|
DeviceTypeGrants dtg = deviceTypeGrantsMapper.selectOne(new LambdaQueryWrapper<DeviceTypeGrants>().eq(DeviceTypeGrants::getDeviceTypeId, device.getId()));
|
|
|
|
|
DeviceTypeGrants dtg = deviceTypeGrantsMapper.selectOne(new LambdaQueryWrapper<DeviceTypeGrants>()
|
|
|
|
|
.eq(DeviceTypeGrants::getDeviceTypeId, device.getDeviceType())
|
|
|
|
|
.eq(DeviceTypeGrants::getCustomerId, assignUser.getCustomerId()));
|
|
|
|
|
if (dtg != null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -397,51 +402,82 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 撤回设备
|
|
|
|
|
*
|
|
|
|
|
* @param ids
|
|
|
|
|
*/
|
|
|
|
|
// @Override
|
|
|
|
|
// public void withdrawDevice(List<Long> ids) {
|
|
|
|
|
// ids.forEach((id) -> {
|
|
|
|
|
// List<Device> deviceChain = getDeviceChain(id);
|
|
|
|
|
// deviceChain.forEach((device) -> {
|
|
|
|
|
// device.setDeviceStatus(DeviceStatusEnum.INVALID.getCode());
|
|
|
|
|
// deviceMapper.updateById(device);
|
|
|
|
|
// });
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// ids.forEach((id) -> {
|
|
|
|
|
// Device device = new Device();
|
|
|
|
|
// device.setId(id);
|
|
|
|
|
// device.setCustomerId(null);
|
|
|
|
|
// device.setCustomerName("");
|
|
|
|
|
// deviceMapper.updateById(device);
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// public List<Device> getDeviceChain(Long originalDeviceId) {
|
|
|
|
|
// List<Device> chain = new ArrayList<>();
|
|
|
|
|
// Set<Long> visited = new HashSet<>(); // 防止循环引用
|
|
|
|
|
// findNext(chain, visited, originalDeviceId);
|
|
|
|
|
// return chain;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// private void findNext(List<Device> chain, Set<Long> visited, Long currentOriginalDeviceId) {
|
|
|
|
|
// if (visited.contains(currentOriginalDeviceId)) {
|
|
|
|
|
// log.info("检测到循环引用,终止递归");
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// visited.add(currentOriginalDeviceId);
|
|
|
|
|
//
|
|
|
|
|
// List<Device> devices = deviceMapper.findByOriginalDeviceId(currentOriginalDeviceId);
|
|
|
|
|
// for (Device device : devices) {
|
|
|
|
|
// chain.add(device);
|
|
|
|
|
// findNext(chain, visited, device.getId());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 撤回设备
|
|
|
|
|
*
|
|
|
|
|
* @param ids
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void withdrawDevice(List<Long> ids) {
|
|
|
|
|
ids.forEach((id) -> {
|
|
|
|
|
List<Device> deviceChain = getDeviceChain(id);
|
|
|
|
|
deviceChain.forEach((device) -> {
|
|
|
|
|
device.setDeviceStatus(DeviceStatusEnum.INVALID.getCode());
|
|
|
|
|
deviceMapper.updateById(device);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ids.forEach((id) -> {
|
|
|
|
|
Device device = new Device();
|
|
|
|
|
device.setId(id);
|
|
|
|
|
device.setCustomerId(null);
|
|
|
|
|
device.setCustomerName("");
|
|
|
|
|
deviceMapper.updateById(device);
|
|
|
|
|
});
|
|
|
|
|
for (Long id : ids) {
|
|
|
|
|
DeviceAssignments assignment = deviceAssignmentsMapper.selectById(id);
|
|
|
|
|
Device device = deviceMapper.selectById(assignment.getDeviceId());
|
|
|
|
|
// 接收者
|
|
|
|
|
assignment.setAssigneeName("");
|
|
|
|
|
assignment.setToCustomerId(null);
|
|
|
|
|
deviceAssignmentsMapper.updateById(assignment);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<Device> getDeviceChain(Long originalDeviceId) {
|
|
|
|
|
List<Device> chain = new ArrayList<>();
|
|
|
|
|
Set<Long> visited = new HashSet<>(); // 防止循环引用
|
|
|
|
|
findNext(chain, visited, originalDeviceId);
|
|
|
|
|
return chain;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void findNext(List<Device> chain, Set<Long> visited, Long currentOriginalDeviceId) {
|
|
|
|
|
if (visited.contains(currentOriginalDeviceId)) {
|
|
|
|
|
log.info("检测到循环引用,终止递归");
|
|
|
|
|
return;
|
|
|
|
|
// 获取所有已分配的设备
|
|
|
|
|
DeviceAssignmentQuery dq = DeviceAssignmentQuery.builder().deviceId(device.getId())
|
|
|
|
|
.active(DeviceActiveStatusEnum.ACTIVE.getCode()).lever(assignment.getLever() + USER_ID_SEPARATOR).build();
|
|
|
|
|
// 查询分配
|
|
|
|
|
List<DeviceAssignments> assignmentsList = deviceAssignmentsMapper.deviceAssignmentsMapper(dq);
|
|
|
|
|
for (DeviceAssignments assignments : assignmentsList) {
|
|
|
|
|
assignments.setActive(DeviceActiveStatusEnum.INACTIVE.getCode());
|
|
|
|
|
deviceAssignmentsMapper.updateById(assignments);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
visited.add(currentOriginalDeviceId);
|
|
|
|
|
|
|
|
|
|
List<Device> devices = deviceMapper.findByOriginalDeviceId(currentOriginalDeviceId);
|
|
|
|
|
for (Device device : devices) {
|
|
|
|
|
chain.add(device);
|
|
|
|
|
findNext(chain, visited, device.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|