web:撤回设备
This commit is contained in:
@ -3,7 +3,6 @@ package com.fuyuanshen.equipment.service.impl;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.lang.UUID;
|
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.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
@ -42,7 +41,6 @@ import com.fuyuanshen.equipment.service.DeviceService;
|
|||||||
import com.fuyuanshen.equipment.service.DeviceTypeGrantsService;
|
import com.fuyuanshen.equipment.service.DeviceTypeGrantsService;
|
||||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||||
import com.fuyuanshen.system.service.ISysOssService;
|
import com.fuyuanshen.system.service.ISysOssService;
|
||||||
import com.fuyuanshen.system.service.ISysUserService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@ -312,6 +310,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
// 批量更新设备状态
|
// 批量更新设备状态
|
||||||
List<DeviceTypeGrants> deviceTypeGrants = new ArrayList<>();
|
List<DeviceTypeGrants> deviceTypeGrants = new ArrayList<>();
|
||||||
for (DeviceAssignments assignment : assignments) {
|
for (DeviceAssignments assignment : assignments) {
|
||||||
|
|
||||||
|
if (assignment.getToCustomerId() != null) {
|
||||||
|
log.info("设备已经分配客户!!!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Device device = deviceMapper.selectById(assignment.getDeviceId());
|
Device device = deviceMapper.selectById(assignment.getDeviceId());
|
||||||
|
|
||||||
// 如果设备已分配给需要分配的客户,则跳过
|
// 如果设备已分配给需要分配的客户,则跳过
|
||||||
@ -326,6 +330,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
|
|
||||||
// 更改分配客户
|
// 更改分配客户
|
||||||
assignment.setAssigneeName(assignUser.getNickName());
|
assignment.setAssigneeName(assignUser.getNickName());
|
||||||
|
assignment.setToCustomerId(customerVo.getCustomerId());
|
||||||
deviceAssignmentsMapper.updateById(assignment);
|
deviceAssignmentsMapper.updateById(assignment);
|
||||||
|
|
||||||
// 设备失效
|
// 设备失效
|
||||||
@ -356,7 +361,9 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
deviceAssignmentsService.save(dam);
|
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) {
|
if (dtg != null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -397,51 +404,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
|
* @param ids
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void withdrawDevice(List<Long> ids) {
|
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) -> {
|
for (Long id : ids) {
|
||||||
Device device = new Device();
|
DeviceAssignments assignment = deviceAssignmentsMapper.selectById(id);
|
||||||
device.setId(id);
|
Device device = deviceMapper.selectById(assignment.getDeviceId());
|
||||||
device.setCustomerId(null);
|
// 接收者
|
||||||
device.setCustomerName("");
|
assignment.setAssigneeName("");
|
||||||
deviceMapper.updateById(device);
|
assignment.setToCustomerId(null);
|
||||||
});
|
deviceAssignmentsMapper.updateById(assignment);
|
||||||
|
|
||||||
}
|
// 获取所有已分配的设备
|
||||||
|
DeviceAssignmentQuery dq = DeviceAssignmentQuery.builder().deviceId(device.getId())
|
||||||
|
.active(DeviceActiveStatusEnum.ACTIVE.getCode()).lever(assignment.getLever() + USER_ID_SEPARATOR).build();
|
||||||
public List<Device> getDeviceChain(Long originalDeviceId) {
|
// 查询分配
|
||||||
List<Device> chain = new ArrayList<>();
|
List<DeviceAssignments> assignmentsList = deviceAssignmentsMapper.deviceAssignmentsMapper(dq);
|
||||||
Set<Long> visited = new HashSet<>(); // 防止循环引用
|
for (DeviceAssignments assignments : assignmentsList) {
|
||||||
findNext(chain, visited, originalDeviceId);
|
assignments.setActive(DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||||
return chain;
|
deviceAssignmentsMapper.updateById(assignments);
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@
|
|||||||
and da.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
and da.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
||||||
</if>
|
</if>
|
||||||
AND da.assignee_id = #{criteria.currentOwnerId}
|
AND da.assignee_id = #{criteria.currentOwnerId}
|
||||||
|
AND dg.customer_id = #{criteria.currentOwnerId}
|
||||||
</where>
|
</where>
|
||||||
ORDER BY da.create_time DESC
|
ORDER BY da.create_time DESC
|
||||||
</select>
|
</select>
|
||||||
|
Reference in New Issue
Block a user