Compare commits
2 Commits
d219105b73
...
c075c09ee7
Author | SHA1 | Date | |
---|---|---|---|
c075c09ee7 | |||
3fb692e7fb |
@ -32,7 +32,16 @@ public interface DeviceMapper extends BaseMapper<Device> {
|
|||||||
|
|
||||||
List<Device> findAllDevices(@Param("criteria") DeviceQueryCriteria criteria);
|
List<Device> findAllDevices(@Param("criteria") DeviceQueryCriteria criteria);
|
||||||
|
|
||||||
Page<AppDeviceVo> queryAppDeviceList(Page<AppDeviceVo> page,@Param("criteria") DeviceQueryCriteria criteria);
|
/**
|
||||||
|
* 根据条件查询
|
||||||
|
*
|
||||||
|
* @param criteria
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<Device> findDevices(@Param("criteria") DeviceQueryCriteria criteria);
|
||||||
|
|
||||||
|
Page<AppDeviceVo> queryAppDeviceList(Page<AppDeviceVo> page, @Param("criteria") DeviceQueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取分配设备的客户
|
* 获取分配设备的客户
|
||||||
*
|
*
|
||||||
|
@ -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;
|
||||||
@ -32,7 +31,6 @@ import com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
|||||||
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
||||||
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
||||||
import com.fuyuanshen.equipment.enums.DeviceActiveStatusEnum;
|
import com.fuyuanshen.equipment.enums.DeviceActiveStatusEnum;
|
||||||
import com.fuyuanshen.equipment.enums.DeviceStatusEnum;
|
|
||||||
import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper;
|
import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper;
|
||||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||||
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
|
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.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;
|
||||||
@ -54,7 +51,9 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description:
|
* @Description:
|
||||||
@ -207,16 +206,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
if (deviceTypes.isEmpty()) {
|
if (deviceTypes.isEmpty()) {
|
||||||
throw new Exception("设备类型不存在!!!");
|
throw new Exception("设备类型不存在!!!");
|
||||||
}
|
}
|
||||||
|
Device device = deviceMapper.selectById(deviceAssignments.getDeviceId());
|
||||||
DeviceQueryCriteria queryCriteria = new DeviceQueryCriteria();
|
if (device == null) {
|
||||||
queryCriteria.setDeviceId(deviceAssignments.getDeviceId());
|
|
||||||
queryCriteria.setCustomerId(LoginHelper.getUserId());
|
|
||||||
queryCriteria.setCurrentOwnerId(LoginHelper.getUserId());
|
|
||||||
List<Device> devices = deviceMapper.findAll(queryCriteria);
|
|
||||||
if (devices.isEmpty()) {
|
|
||||||
throw new Exception("设备不存在!!!");
|
throw new Exception("设备不存在!!!");
|
||||||
}
|
}
|
||||||
Device device = devices.get(0);
|
// 设备类型
|
||||||
|
Long deviceType = device.getDeviceType();
|
||||||
|
|
||||||
// 处理上传的图片
|
// 处理上传的图片
|
||||||
if (deviceForm.getFile() != null) {
|
if (deviceForm.getFile() != null) {
|
||||||
@ -228,6 +223,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
// 更新字段
|
// 更新字段
|
||||||
BeanUtil.copyProperties(deviceForm, device, true);
|
BeanUtil.copyProperties(deviceForm, device, true);
|
||||||
device.setId(deviceAssignments.getDeviceId());
|
device.setId(deviceAssignments.getDeviceId());
|
||||||
|
device.setDeviceType(deviceType);
|
||||||
device.setUpdateTime(new Timestamp(System.currentTimeMillis()));
|
device.setUpdateTime(new Timestamp(System.currentTimeMillis()));
|
||||||
deviceMapper.updateById(device);
|
deviceMapper.updateById(device);
|
||||||
}
|
}
|
||||||
@ -312,6 +308,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 +328,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 +359,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 +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
|
* @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>
|
||||||
@ -133,6 +133,38 @@
|
|||||||
order by d.id desc
|
order by d.id desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据条件查询 -->
|
||||||
|
<select id="findDevices" resultType="com.fuyuanshen.equipment.domain.Device"
|
||||||
|
parameterType="com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria">
|
||||||
|
SELECT d.*
|
||||||
|
FROM device d
|
||||||
|
<where>
|
||||||
|
<!-- 时间范围等其他条件保持原样 -->
|
||||||
|
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
||||||
|
and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%')
|
||||||
|
</if>
|
||||||
|
<if test="criteria.deviceMac != null">
|
||||||
|
and d.device_mac = #{criteria.deviceMac}
|
||||||
|
</if>
|
||||||
|
<if test="criteria.deviceImei != null">
|
||||||
|
and d.device_imei = #{criteria.deviceImei}
|
||||||
|
</if>
|
||||||
|
<if test="criteria.deviceType != null">
|
||||||
|
and d.device_type = #{criteria.deviceType}
|
||||||
|
</if>
|
||||||
|
<if test="criteria.deviceStatus != null">
|
||||||
|
and d.device_status = #{criteria.deviceStatus}
|
||||||
|
</if>
|
||||||
|
<if test="criteria.currentOwnerId != null">
|
||||||
|
and d.current_owner_id = #{criteria.currentOwnerId}
|
||||||
|
</if>
|
||||||
|
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
|
||||||
|
and d.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<select id="queryAppDeviceList" resultType="com.fuyuanshen.equipment.domain.vo.AppDeviceVo">
|
<select id="queryAppDeviceList" resultType="com.fuyuanshen.equipment.domain.vo.AppDeviceVo">
|
||||||
select d.id,
|
select d.id,
|
||||||
d.device_name,
|
d.device_name,
|
||||||
|
Reference in New Issue
Block a user