forked from dyf/fys-Multi-tenant
新增客户
This commit is contained in:
@ -27,7 +27,9 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -44,7 +46,6 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
@Value("${file.device.ip}")
|
||||
private String ip;
|
||||
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
|
||||
@ -129,10 +130,22 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(DeviceForm deviceForm) throws Exception {
|
||||
|
||||
Device device = getById(deviceForm.getId());
|
||||
if (device == null) {
|
||||
DeviceTypeQueryCriteria deviceTypeQueryCriteria = new DeviceTypeQueryCriteria();
|
||||
deviceTypeQueryCriteria.setDeviceTypeId(deviceForm.getId());
|
||||
deviceTypeQueryCriteria.setCustomerId(LoginHelper.getUserId());
|
||||
List<DeviceType> deviceTypes = deviceTypeMapper.findAll(deviceTypeQueryCriteria);
|
||||
if (deviceTypes.isEmpty()) {
|
||||
throw new Exception("设备类型不存在!!!");
|
||||
}
|
||||
|
||||
DeviceQueryCriteria queryCriteria = new DeviceQueryCriteria();
|
||||
queryCriteria.setDeviceId(deviceForm.getId());
|
||||
queryCriteria.setCustomerId(LoginHelper.getUserId());
|
||||
List<Device> devices = deviceMapper.findAll(queryCriteria);
|
||||
if (devices.isEmpty()) {
|
||||
throw new Exception("设备不存在!!!");
|
||||
}
|
||||
Device device = devices.get(0);
|
||||
|
||||
// 处理上传的图片
|
||||
String imageUrl = saveDeviceImage(deviceForm.getFile(), device.getDeviceName());
|
||||
@ -182,6 +195,18 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(List<Long> ids) {
|
||||
List<Long> invalidIds = new ArrayList<>();
|
||||
|
||||
for (Long id : ids) {
|
||||
Device deviceType = deviceMapper.selectById(id);
|
||||
if (deviceType == null || !Objects.equals(deviceType.getCurrentOwnerId(), LoginHelper.getUserId())) {
|
||||
invalidIds.add(id);
|
||||
}
|
||||
}
|
||||
if (!invalidIds.isEmpty()) {
|
||||
throw new RuntimeException("以下设备无法删除(ID 不存在或无权限): " + invalidIds);
|
||||
}
|
||||
|
||||
deviceMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,10 @@ 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.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
@ -114,17 +116,25 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
public void deleteAll(List<Long> ids) {
|
||||
|
||||
List<Long> invalidIds = new ArrayList<>();
|
||||
|
||||
List<Long> invalidId2 = new ArrayList<>();
|
||||
for (Long id : ids) {
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(id);
|
||||
if (deviceType == null || !Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
|
||||
invalidIds.add(id);
|
||||
}
|
||||
DeviceQueryCriteria deviceQueryCriteria = new DeviceQueryCriteria();
|
||||
deviceQueryCriteria.setDeviceTypeId(id);
|
||||
List<Device> devices = deviceMapper.findAll(deviceQueryCriteria);
|
||||
if (!devices.isEmpty()) {
|
||||
invalidId2.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!invalidIds.isEmpty()) {
|
||||
throw new RuntimeException("以下设备类型无法删除(ID 不存在或无权限): " + invalidIds);
|
||||
}
|
||||
if (!invalidId2.isEmpty()) {
|
||||
throw new RuntimeException("以下设备类型无法删除(已绑定设备): " + invalidId2);
|
||||
}
|
||||
|
||||
deviceTypeMapper.deleteByIds(ids);
|
||||
}
|
||||
|
Reference in New Issue
Block a user