1
0

Merge branch 'dyf-device'

This commit is contained in:
2025-07-19 10:21:11 +08:00
5 changed files with 57 additions and 27 deletions

View File

@ -21,6 +21,9 @@ import java.util.Date;
@JsonInclude(JsonInclude.Include.ALWAYS) // 关键注解
public class Device extends TenantEntity {
/**
* id
*/
@TableId(value = "id", type = IdType.AUTO)
@Schema(name = "ID")
private Long id;
@ -29,6 +32,9 @@ public class Device extends TenantEntity {
@TableField(exist = false)
private Long assignId;
/**
* device_type
*/
@Schema(name = "设备类型")
private Long deviceType;
@ -100,8 +106,6 @@ public class Device extends TenantEntity {
private Integer deviceStatus;
/**
* 绑定状态
* 0 未绑定

View File

@ -25,6 +25,7 @@ public class DeviceAssignments extends TenantEntity {
/**
* 设备id
* device_id
*/
private Long deviceId;

View File

@ -58,7 +58,9 @@ public class DeviceExcelImportDTO {
private String remark;
@ExcelProperty("设备类型名称")
@ColumnWidth(20)
private String typeName;
@ExcelProperty("蓝牙名称")
private String bluetoothName;
}

View File

@ -44,7 +44,6 @@ import com.fuyuanshen.system.domain.vo.SysOssVo;
import com.fuyuanshen.system.service.ISysOssService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -101,6 +100,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
public TableDataInfo<Device> queryAll(DeviceQueryCriteria criteria, Page<Device> page) throws IOException {
criteria.setCurrentOwnerId(LoginHelper.getUserId());
if (criteria.getDeviceType() != null) {
DeviceTypeGrants deviceTypeGrant = deviceTypeGrantsMapper.selectById(criteria.getDeviceType());
if (deviceTypeGrant != null) {
criteria.setDeviceType(deviceTypeGrant.getDeviceTypeId());
}
}
IPage<Device> devices = deviceMapper.findAll(criteria, page);
List<Device> records = devices.getRecords();
@ -142,6 +147,16 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
@Override
@Transactional(rollbackFor = Exception.class)
public void addDevice(DeviceForm deviceForm) throws Exception {
Device device1 = deviceMapper.selectOne(new QueryWrapper<Device>().eq("device_mac", deviceForm.getDeviceMac()));
if (device1 != null) {
throw new BadRequestException("设备MAC已存在");
}
Device device2 = deviceMapper.selectOne(new QueryWrapper<Device>().eq("device_imei", deviceForm.getDeviceImei()));
if (device2 != null) {
throw new BadRequestException("设备IMEI已存在");
}
DeviceTypeQueryCriteria queryCriteria = new DeviceTypeQueryCriteria();
queryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
queryCriteria.setCustomerId(LoginHelper.getUserId());

View File

@ -1,6 +1,8 @@
package com.fuyuanshen.equipment.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -10,11 +12,13 @@ import com.fuyuanshen.common.core.utils.PageUtil;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.DeviceAssignments;
import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.DeviceTypeGrants;
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.DeviceAssignmentsMapper;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
@ -41,6 +45,7 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
private final DeviceMapper deviceMapper;
private final DeviceTypeGrantsMapper deviceTypeGrantsMapper;
private final DeviceAssignmentsMapper deviceAssignmentsMapper;
/**
@ -155,30 +160,33 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
@Transactional(rollbackFor = Exception.class)
public void deleteAll(List<Long> ids) {
List<Long> deviceTypeId = new ArrayList<>();
for (Long id : ids) {
DeviceTypeGrants deviceTypeGrant = deviceTypeGrantsMapper.selectById(id);
// List<DeviceTypeGrants> deviceTypeGrants = deviceTypeGrantsMapper.selectList(new QueryWrapper<DeviceTypeGrants>()
// .eq("device_type_id", deviceTypeGrant.getDeviceTypeId()));
// List<DeviceTypeGrants> deviceAssignments = deviceTypeGrantsMapper.selectList(new QueryWrapper<DeviceTypeGrants>()
// .eq("device_id", deviceTypeGrant.getDeviceTypeId()));
// if (CollectionUtil.isNotEmpty(deviceAssignments)) {
// throw new RuntimeException("该设备类型已绑定设备,无法删除");
// }
// Device device = deviceMapper.selectById(deviceTypeGrant.getDeviceTypeId());
List<Device> devices = deviceMapper.selectList(new QueryWrapper<Device>()
.eq("device_type", deviceTypeGrant.getDeviceTypeId()));
if (CollectionUtil.isNotEmpty(devices)) {
throw new RuntimeException("该设备类型已绑定设备,无法删除");
}
deviceTypeId.add(deviceTypeGrant.getDeviceTypeId());
}
deviceTypeGrantsMapper.deleteByIds(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.getOwnerCustomerId(), LoginHelper.getUserId())) {
// invalidIds.add(id);
// }
// DeviceQueryCriteria deviceQueryCriteria = new DeviceQueryCriteria();
// deviceQueryCriteria.setDeviceType(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);
deviceTypeMapper.deleteByIds(deviceTypeId);
}