diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/constant/ResponseMessageConstants.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/constant/ResponseMessageConstants.java new file mode 100644 index 0000000..6b7d033 --- /dev/null +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/constant/ResponseMessageConstants.java @@ -0,0 +1,28 @@ +package com.fuyuanshen.modules.system.constant; + +/** + * 响应消息常量类 + * + * @author: 默苍璃 + * @date: 2025-06-2117:21 + */ +public class ResponseMessageConstants { + + /** + * 删除操作成功提示 + */ + public static final String DELETE_SUCCESS = "删除成功!"; + + /** + * 新增操作成功提示 + */ + public static final String SAVE_SUCCESS = "新增成功!"; + + /** + * 更新操作成功提示 + */ + public static final String UPDATE_SUCCESS = "更新成功!"; + + // 可根据业务需求继续扩展其他常用提示信息 + +} diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/Device.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/Device.java index 8ba3ebd..b0610fe 100644 --- a/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/Device.java +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/Device.java @@ -26,6 +26,10 @@ public class Device extends BaseEntity implements Serializable { @ApiModelProperty(value = "ID") private Long id; + @ApiModelProperty(value = "设备记录ID") + @TableField(exist = false) + private Long assignId; + @ApiModelProperty(value = "设备类型") private Long deviceType; diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/dto/DeviceExcelExportDTO.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/dto/DeviceExcelExportDTO.java index 2ec14f1..f161d40 100644 --- a/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/dto/DeviceExcelExportDTO.java +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/domain/dto/DeviceExcelExportDTO.java @@ -46,9 +46,9 @@ public class DeviceExcelExportDTO { @ColumnWidth(20) private String deviceMac; - @ExcelProperty("设备SN") + @ExcelProperty("设备IMEI") @ColumnWidth(20) - private String deviceSn; + private String deviceImei; @ExcelProperty("经度") private String longitude; diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/rest/DeviceController.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/rest/DeviceController.java index c23ca8e..db8d896 100644 --- a/fys-system/src/main/java/com/fuyuanshen/modules/system/rest/DeviceController.java +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/rest/DeviceController.java @@ -2,6 +2,7 @@ package com.fuyuanshen.modules.system.rest; import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fuyuanshen.modules.system.constant.ResponseMessageConstants; import com.fuyuanshen.modules.system.constant.UserConstants; import com.fuyuanshen.modules.system.domain.User; import com.fuyuanshen.modules.system.listener.excel.DeviceImportParams; @@ -158,13 +159,9 @@ public class DeviceController { @ApiOperation("删除设备") @DeleteMapping(value = "/delete") public ResponseVO deleteDevice(@ApiParam(value = "传ID数组[]") @RequestBody List ids) { - try { - deviceService.deleteAll(ids); - } catch (Exception e) { - log.error("deleteDevice error: " + e.getMessage()); - return ResponseVO.fail(e.getMessage()); - } - return ResponseVO.success(null); + // deviceService.deleteAll(ids); + deviceService.deleteAssign(ids); + return ResponseVO.success(ResponseMessageConstants.DELETE_SUCCESS); } @@ -176,7 +173,8 @@ public class DeviceController { // 只能看到自己的创建的设备,以及被分配的设备。 if (onlineuser.getTenantId() != null && !onlineuser.getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) { - criteria.setTenantId(onlineuser.getTenantId()); + // criteria.setTenantId(onlineuser.getTenantId()); + criteria.setCurrentOwnerId(onlineuser.getId()); } exportService.export(deviceService.queryAll(criteria), response); } @@ -236,7 +234,6 @@ public class DeviceController { try { // 解码Base64字符串 byte[] data = Base64.getDecoder().decode(errorData); - return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"import_errors.xlsx\"").contentType(MediaType.APPLICATION_OCTET_STREAM).body(data); } catch (Exception e) { log.error("下载错误报告失败", e); diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/service/DeviceService.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/service/DeviceService.java index a7e17f2..1c44879 100644 --- a/fys-system/src/main/java/com/fuyuanshen/modules/system/service/DeviceService.java +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/service/DeviceService.java @@ -80,6 +80,13 @@ public interface DeviceService extends IService { */ void deleteAll(List ids); + /** + * 删除设备分配记录 + * + * @param ids + */ + void deleteAssign(List ids); + /** * 导出数据 * @@ -103,4 +110,6 @@ public interface DeviceService extends IService { */ void unbindDevice(DeviceForm deviceForm); + + } diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/service/impl/DeviceExportService.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/service/impl/DeviceExportService.java index 0f71389..13b410c 100644 --- a/fys-system/src/main/java/com/fuyuanshen/modules/system/service/impl/DeviceExportService.java +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/service/impl/DeviceExportService.java @@ -41,7 +41,8 @@ public class DeviceExportService { dto.setCustomerName(device.getCustomerName()); dto.setDeviceName(device.getDeviceName()); dto.setDeviceMac(device.getDeviceMac()); - dto.setDeviceSn(device.getDeviceSn()); + // 设备IMEI + dto.setDeviceImei(device.getDeviceImei()); dto.setLongitude(device.getLongitude()); dto.setLatitude(device.getLatitude()); dto.setRemark(device.getRemark()); diff --git a/fys-system/src/main/java/com/fuyuanshen/modules/system/service/impl/DeviceServiceImpl.java b/fys-system/src/main/java/com/fuyuanshen/modules/system/service/impl/DeviceServiceImpl.java index 65f5408..7bba729 100644 --- a/fys-system/src/main/java/com/fuyuanshen/modules/system/service/impl/DeviceServiceImpl.java +++ b/fys-system/src/main/java/com/fuyuanshen/modules/system/service/impl/DeviceServiceImpl.java @@ -2,11 +2,9 @@ package com.fuyuanshen.modules.system.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; -import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fuyuanshen.constants.DeviceConstants; @@ -14,7 +12,10 @@ import com.fuyuanshen.constants.ExceptionMessages; import com.fuyuanshen.exception.BadRequestException; import com.fuyuanshen.modules.security.service.UserCacheManager; import com.fuyuanshen.modules.system.constant.UserConstants; -import com.fuyuanshen.modules.system.domain.*; +import com.fuyuanshen.modules.system.domain.Device; +import com.fuyuanshen.modules.system.domain.DeviceAssignments; +import com.fuyuanshen.modules.system.domain.DeviceTypeGrants; +import com.fuyuanshen.modules.system.domain.User; import com.fuyuanshen.modules.system.domain.app.APPDevice; import com.fuyuanshen.modules.system.domain.dto.CustomerVo; import com.fuyuanshen.modules.system.domain.dto.DeviceForm; @@ -484,18 +485,17 @@ public class DeviceServiceImpl extends ServiceImpl impleme @Transactional(rollbackFor = Exception.class) public void deleteAll(List ids) { + SecurityUtils.getCurrentUserId(); + // Step 1: 查询所有传入的设备(根据 ID) List allDevices = deviceMapper.selectBatchIds(ids); - // Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备 Set nonNullCustomerIds = allDevices.stream().filter(device -> device.getCustomerId() != null && device.getDeviceStatus() == 1).map(Device::getId).collect(Collectors.toSet()); - // Step 3: 从原始 ids 中“去掉”这些非空 customer_id 的设备 ID List remainingIds = ids.stream().filter(id -> !nonNullCustomerIds.contains(id)).collect(Collectors.toList()); if (CollectionUtil.isEmpty(remainingIds)) { throw new BadRequestException("已分配的设备不允许删除!!!"); } - List devices = deviceMapper.selectBatchIds(remainingIds); for (Device device : devices) { String devicePic = device.getDevicePic(); @@ -514,6 +514,28 @@ public class DeviceServiceImpl extends ServiceImpl impleme deviceMapper.deleteBatchIds(ids); } + + /** + * 删除设备分配记录 + * + * @param ids + */ + @Override + public void deleteAssign(List ids) { + + // Step 1: 查询所有传入的设备(根据 ID) + List deviceAssignments = deviceAssignmentsMapper.selectBatchIds(ids); + // Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备 + Set nonNullCustomerIds = deviceAssignments.stream().filter(device -> device.getActive() == 1).map(DeviceAssignments::getId).collect(Collectors.toSet()); + // Step 3: 从原始 ids 中“去掉”这些非空 customer_id 的设备 ID + List remainingIds = ids.stream().filter(id -> !nonNullCustomerIds.contains(id)).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(remainingIds)) { + throw new BadRequestException("已分配的设备不允许删除!!!"); + } + deviceAssignmentsMapper.deleteBatchIds(ids); + } + + @Override public void download(List all, HttpServletResponse response) throws IOException { List> list = new ArrayList<>(); diff --git a/fys-system/src/main/resources/mapper/system/DeviceMapper.xml b/fys-system/src/main/resources/mapper/system/DeviceMapper.xml index cb419ce..23d4261 100644 --- a/fys-system/src/main/resources/mapper/system/DeviceMapper.xml +++ b/fys-system/src/main/resources/mapper/system/DeviceMapper.xml @@ -43,7 +43,7 @@ d.device_pic, d.device_mac, d.device_sn, d.update_by,d.device_imei, d.update_time, d.device_type, d.remark, d.binding_status,t.type_name, da.assignee_id AS customerId, da.assignee_name AS customerName, da.active AS deviceStatus, - da.assigned_at AS create_time , da.assigner_name AS create_by + da.assigned_at AS create_time , da.assigner_name AS create_by , da.id AS assignId from device d LEFT JOIN device_type t ON d.device_type = t.id LEFT JOIN device_assignments da ON da.device_id = d.id