forked from dyf/fys-Multi-tenant
WEB:分页查询设备列表
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.generator.SnowflakeGenerator;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@ -113,7 +114,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addDevice(DeviceForm deviceForm) throws Exception {
|
||||
DeviceTypeQueryCriteria queryCriteria = new DeviceTypeQueryCriteria();
|
||||
queryCriteria.setDeviceTypeId(deviceForm.getId());
|
||||
queryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
|
||||
queryCriteria.setCustomerId(LoginHelper.getUserId());
|
||||
List<DeviceType> deviceTypes = deviceTypeMapper.findAll(queryCriteria);
|
||||
if (deviceTypes.isEmpty()) {
|
||||
@ -152,7 +153,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
public void update(DeviceForm deviceForm) throws Exception {
|
||||
|
||||
DeviceTypeQueryCriteria deviceTypeQueryCriteria = new DeviceTypeQueryCriteria();
|
||||
deviceTypeQueryCriteria.setDeviceTypeId(deviceForm.getId());
|
||||
deviceTypeQueryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
|
||||
deviceTypeQueryCriteria.setCustomerId(LoginHelper.getUserId());
|
||||
List<DeviceType> deviceTypes = deviceTypeMapper.findAll(deviceTypeQueryCriteria);
|
||||
if (deviceTypes.isEmpty()) {
|
||||
@ -258,6 +259,11 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
invalidIds.add(id);
|
||||
continue;
|
||||
}
|
||||
Device assignCustomer = deviceMapper.getAssignCustomer(device.getId());
|
||||
if (assignCustomer != null) {
|
||||
invalidIds.add(id);
|
||||
continue;
|
||||
}
|
||||
device.setCustomerId(customerId);
|
||||
device.setCustomerName(customer.getNickName());
|
||||
devices.add(device);
|
||||
@ -268,14 +274,24 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
}
|
||||
|
||||
devices.forEach((device) -> {
|
||||
deviceMapper.updateById(device);
|
||||
device.setId(null);
|
||||
device.setCurrentOwnerId(customerId);
|
||||
deviceMapper.insert(device);
|
||||
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
deviceType.setId(null);
|
||||
deviceMapper.updateById(device);
|
||||
device.setCurrentOwnerId(customerId);
|
||||
if (device.getDeviceType() == null) {
|
||||
throw new RuntimeException("设备类型有问题!!! ");
|
||||
}
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator();
|
||||
device.setOriginalOwnerId(device.getId());
|
||||
Long next = snowflakeGenerator.next();
|
||||
device.setId(next);
|
||||
device.setDeviceType(next);
|
||||
|
||||
deviceType.setOriginalOwnerId(deviceType.getId());
|
||||
deviceType.setId(next);
|
||||
deviceType.setOwnerCustomerId(customerId);
|
||||
|
||||
deviceMapper.insert(device);
|
||||
deviceTypeMapper.insert(deviceType);
|
||||
|
||||
});
|
||||
|
@ -125,11 +125,11 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
List<Long> invalidId2 = new ArrayList<>();
|
||||
for (Long id : ids) {
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(id);
|
||||
if (deviceType == null || !Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
|
||||
if (deviceType == null || !Objects.equals(deviceType.getOwnerCustomerId(), LoginHelper.getUserId())) {
|
||||
invalidIds.add(id);
|
||||
}
|
||||
DeviceQueryCriteria deviceQueryCriteria = new DeviceQueryCriteria();
|
||||
deviceQueryCriteria.setDeviceTypeId(id);
|
||||
deviceQueryCriteria.setDeviceType(id);
|
||||
List<Device> devices = deviceMapper.findAll(deviceQueryCriteria);
|
||||
if (!devices.isEmpty()) {
|
||||
invalidId2.add(id);
|
||||
|
Reference in New Issue
Block a user