新增客户
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.fuyuanshen.equipment.domain.query;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
@ -16,19 +17,22 @@ import java.util.Set;
|
||||
@Data
|
||||
public class DeviceQueryCriteria {
|
||||
|
||||
// @Schema(value = "设备名称")
|
||||
@Schema(name = "设备id")
|
||||
private Long deviceId;
|
||||
|
||||
@Schema(name = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
// @Schema(value = "设备类型")
|
||||
private Long deviceType;
|
||||
@Schema(name = "设备类型")
|
||||
private Long deviceTypeId;
|
||||
|
||||
// @Schema(value = "设备MAC")
|
||||
@Schema(name = "设备MAC")
|
||||
private String deviceMac;
|
||||
|
||||
// @Schema(value = "设备IMEI")
|
||||
@Schema(name = "设备IMEI")
|
||||
private String deviceImei;
|
||||
|
||||
// @Schema(value = "设备SN")
|
||||
@Schema(name = "设备SN")
|
||||
private String deviceSn;
|
||||
|
||||
/**
|
||||
@ -36,29 +40,29 @@ public class DeviceQueryCriteria {
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
// @Schema(value = "设备状态 0 失效 1 正常 ")
|
||||
@Schema(name = "设备状态 0 失效 1 正常 ")
|
||||
private Integer deviceStatus;
|
||||
|
||||
// @Schema(value = "创建时间")
|
||||
@Schema(name = "创建时间")
|
||||
private List<Timestamp> createTime;
|
||||
|
||||
// @Schema(value = "页码", example = "1")
|
||||
@Schema(name = "页码", example = "1")
|
||||
private Integer page = 1;
|
||||
|
||||
// @Schema(value = "每页数据量", example = "10")
|
||||
@Schema(name = "每页数据量", example = "10")
|
||||
private Integer size = 10;
|
||||
|
||||
// @Schema(value = "客户id")
|
||||
@Schema(name = "客户id")
|
||||
private Long customerId;
|
||||
private Set<Long> customerIds;
|
||||
|
||||
// @Schema(value = "当前所有者")
|
||||
@Schema(name = "当前所有者")
|
||||
private Long currentOwnerId;
|
||||
|
||||
// @Schema(value = "租户ID")
|
||||
@Schema(name = "租户ID")
|
||||
private Long tenantId;
|
||||
|
||||
// @Schema(value = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
@Schema(name = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
private Integer communicationMode;
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -55,8 +55,8 @@
|
||||
<if test="criteria.deviceImei != null">
|
||||
and d.device_imei = #{criteria.deviceImei}
|
||||
</if>
|
||||
<if test="criteria.deviceType != null">
|
||||
and d.device_type = #{criteria.deviceType}
|
||||
<if test="criteria.deviceTypeId != null">
|
||||
and d.device_type = #{criteria.deviceTypeId}
|
||||
</if>
|
||||
<if test="criteria.deviceStatus != null">
|
||||
-- and da.active = #{criteria.deviceStatus}
|
||||
@ -148,8 +148,8 @@
|
||||
<if test="criteria.deviceMac != null">
|
||||
and d.device_mac = #{criteria.deviceMac}
|
||||
</if>
|
||||
<if test="criteria.deviceType != null">
|
||||
and d.device_type = #{criteria.deviceType}
|
||||
<if test="criteria.deviceTypeId != null">
|
||||
and d.device_type = #{criteria.deviceTypeId}
|
||||
</if>
|
||||
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
|
||||
and d.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
|
||||
|
Reference in New Issue
Block a user