设备导出
This commit is contained in:
@ -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 = "更新成功!";
|
||||
|
||||
// 可根据业务需求继续扩展其他常用提示信息
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<Object> deleteDevice(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> 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);
|
||||
|
@ -80,6 +80,13 @@ public interface DeviceService extends IService<Device> {
|
||||
*/
|
||||
void deleteAll(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 删除设备分配记录
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
void deleteAssign(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
@ -103,4 +110,6 @@ public interface DeviceService extends IService<Device> {
|
||||
*/
|
||||
void unbindDevice(DeviceForm deviceForm);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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<DeviceMapper, Device> impleme
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(List<Long> ids) {
|
||||
|
||||
SecurityUtils.getCurrentUserId();
|
||||
|
||||
// Step 1: 查询所有传入的设备(根据 ID)
|
||||
List<Device> allDevices = deviceMapper.selectBatchIds(ids);
|
||||
|
||||
// Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
||||
Set<Long> nonNullCustomerIds = allDevices.stream().filter(device -> device.getCustomerId() != null && device.getDeviceStatus() == 1).map(Device::getId).collect(Collectors.toSet());
|
||||
|
||||
// Step 3: 从原始 ids 中“去掉”这些非空 customer_id 的设备 ID
|
||||
List<Long> remainingIds = ids.stream().filter(id -> !nonNullCustomerIds.contains(id)).collect(Collectors.toList());
|
||||
if (CollectionUtil.isEmpty(remainingIds)) {
|
||||
throw new BadRequestException("已分配的设备不允许删除!!!");
|
||||
}
|
||||
|
||||
List<Device> devices = deviceMapper.selectBatchIds(remainingIds);
|
||||
for (Device device : devices) {
|
||||
String devicePic = device.getDevicePic();
|
||||
@ -514,6 +514,28 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
deviceMapper.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除设备分配记录
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
@Override
|
||||
public void deleteAssign(List<Long> ids) {
|
||||
|
||||
// Step 1: 查询所有传入的设备(根据 ID)
|
||||
List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectBatchIds(ids);
|
||||
// Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
||||
Set<Long> nonNullCustomerIds = deviceAssignments.stream().filter(device -> device.getActive() == 1).map(DeviceAssignments::getId).collect(Collectors.toSet());
|
||||
// Step 3: 从原始 ids 中“去掉”这些非空 customer_id 的设备 ID
|
||||
List<Long> 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<Device> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user