feat: 设备分组导入监听判断数据为空处理;导入后返回数据使用Response

V0.5.x
gaoyoulong 2024-03-09 11:40:29 +08:00
parent b2524e67b4
commit 9cfcf2f132
2 changed files with 12 additions and 3 deletions

View File

@ -12,6 +12,7 @@ package cc.iotkit.manager.controller;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.api.Request;
import cc.iotkit.common.api.Response;
import cc.iotkit.common.excel.utils.ExcelUtil;
import cc.iotkit.common.thing.ThingModelMessage;
import cc.iotkit.manager.dto.bo.device.*;
@ -34,6 +35,7 @@ import cc.iotkit.model.device.DeviceGroup;
import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.device.message.DeviceProperty;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.IdUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@ -241,8 +243,8 @@ public class DeviceController {
@ApiOperation(value = "导入设备分组")
@SaCheckPermission("iot:deviceGroup:add")
@PostMapping("/group/importData")
public String importGroup(@RequestPart("file") MultipartFile file, @RequestParam("requestId") String requestId) {
return deviceServiceImpl.importGroup(file);
public Response importGroup(@RequestPart("file") MultipartFile file, @RequestParam("requestId") String requestId) {
return new Response(200, deviceServiceImpl.importGroup(file), null, requestId);
}
/**

View File

@ -5,6 +5,7 @@ import cc.iotkit.common.excel.core.ExcelResult;
import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.utils.SpringUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.manager.dto.bo.devicegroup.DeviceGroupBo;
import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupImportVo;
import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo;
@ -69,6 +70,12 @@ public class DeviceGroupImportListener extends AnalysisEventListener<DeviceGroup
@Override
public void invoke(DeviceGroupImportVo deviceGroupImportVo, AnalysisContext analysisContext) {
if ( StringUtils.isEmpty(deviceGroupImportVo.getId()) || StringUtils.isEmpty(deviceGroupImportVo.getName()) ) {
failureNum++;
String msg = "<br/>第" + failureNum + "条分组导入失败设备分组ID或名称不能为空";
return;
}
DeviceGroupVo deviceGroupVo = this.deviceManagerService.getDeviceGroup(deviceGroupImportVo.getId());
try {
if (ObjectUtil.isNull(deviceGroupVo)) {
@ -86,7 +93,7 @@ public class DeviceGroupImportListener extends AnalysisEventListener<DeviceGroup
}
} catch (Exception e) {
failureNum++;
String msg = "<br/>第" + failureNum + "条分组: " + deviceGroupImportVo.getName() + " 导入失败:";
String msg = "<br/>第" + failureNum + "条分组: " + deviceGroupImportVo.getId() + " 导入失败:";
failureMsg.append(msg).append(e.getMessage());
}
}