feat(device): 优化设备数据推送频率并添加设备附件删除功能- 调整数据推送频率:将 DataPushTask 类中的 pushData 方法执行频率从 20000 毫秒改为 3000 毫秒

- 新增设备附件删除功能:在 DeviceController、DeviceService 和 DeviceServiceImpl 中添加 deleteIconOrPreview 方法,用于删除设备的图标或预览图
- 在设备创建时,如果产品有默认图标或预览图,自动关联到设备
This commit is contained in:
zhuangtianxiang 2025-03-25 20:43:57 +08:00
parent 11d972e875
commit a33ac271ab
6 changed files with 39 additions and 1 deletions

View File

@ -21,7 +21,7 @@ public class DataPushTask {
private final RecordWebSocketHandler recordHandler; private final RecordWebSocketHandler recordHandler;
private final ProductWebSocketHandler productHandler; private final ProductWebSocketHandler productHandler;
@Scheduled(fixedRate = 20000) @Scheduled(fixedRate = 3000)
public void pushData() { public void pushData() {
pushAndBroadcast(deviceService::status, deviceHandler); pushAndBroadcast(deviceService::status, deviceHandler);
pushAndBroadcast(recordDataService::recordDataStatus, recordHandler); pushAndBroadcast(recordDataService::recordDataStatus, recordHandler);

View File

@ -170,4 +170,13 @@ public class DeviceController {
public int toggle(@PathVariable("id") Long id) { public int toggle(@PathVariable("id") Long id) {
return service.toggle(id); return service.toggle(id);
} }
/**
* 删除图片或预览图
*/
@DeleteMapping("/attachment/{id}")
@OperationLogAnnotation(content = "'设备图片或预览图'", operationType = "删除")
public Boolean deleteIconOrPreview(@PathVariable("id") Long id, String attachmentId) {
return service.deleteIconOrPreview(id, attachmentId);
}
} }

View File

@ -38,4 +38,6 @@ public interface DeviceService extends IService<Device> {
List<Device> findByName(String name); List<Device> findByName(String name);
int toggle(Long id); int toggle(Long id);
boolean deleteIconOrPreview(Long id, String attachmentId);
} }

View File

@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.gateway.exception.ConstraintException; import com.zsc.edu.gateway.exception.ConstraintException;
import com.zsc.edu.gateway.exception.OutlineException; import com.zsc.edu.gateway.exception.OutlineException;
import com.zsc.edu.gateway.framework.redis.RedisUtils; import com.zsc.edu.gateway.framework.redis.RedisUtils;
import com.zsc.edu.gateway.modules.attachment.service.AttachmentService;
import com.zsc.edu.gateway.modules.iot.device.dto.BatchDeviceDto; import com.zsc.edu.gateway.modules.iot.device.dto.BatchDeviceDto;
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceDto; import com.zsc.edu.gateway.modules.iot.device.dto.DeviceDto;
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceServeDto; import com.zsc.edu.gateway.modules.iot.device.dto.DeviceServeDto;
@ -60,6 +61,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
private DeviceRepository deviceRepo; private DeviceRepository deviceRepo;
@Resource @Resource
private MqttConfig mqttConfig; private MqttConfig mqttConfig;
@Resource
private AttachmentService attachmentService;
/** /**
* 新建设备 * 新建设备
*/ */
@ -70,6 +73,13 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
throw new ConstraintException("该设备名称已存在!"); throw new ConstraintException("该设备名称已存在!");
} }
Device device = mapper.toEntity(dto); Device device = mapper.toEntity(dto);
Product product = productRepo.selectById(device.getProductId());
if (product.getIconId() != null) {
device.setIconId(product.getIconId());
}
if (product.getPreviewId() != null) {
device.setPreviewId(product.getPreviewId());
}
save(device); save(device);
return device; return device;
} }
@ -240,4 +250,21 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
device.setOnline(!device.getOnline()); device.setOnline(!device.getOnline());
return baseMapper.updateById(device); return baseMapper.updateById(device);
} }
/**
* 删除设备头像
*/
@Override
public boolean deleteIconOrPreview(Long id, String attachmentId) {
Device device = baseMapper.selectById(id);
if (device.getIconId().equals(attachmentId)) {
device.setIconId("");
}
if (device.getPreviewId().equals(attachmentId)) {
device.setPreviewId("");
}
attachmentService.delete(attachmentId);
baseMapper.updateById(device);
return true;
}
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB