From 5c50e18fc9f62d79981a0e4927db4b9189199af5 Mon Sep 17 00:00:00 2001 From: xy <748613696@qq.com> Date: Fri, 8 Nov 2024 14:05:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BDbug?= =?UTF-8?q?=E6=B6=88=E7=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../equipment/DeviceFtpController.java | 9 ++--- .../service/impl/DeviceFtpServiceImpl.java | 33 +++++++++++-------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/DeviceFtpController.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/DeviceFtpController.java index 9d5fffb..c7a2c78 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/DeviceFtpController.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/DeviceFtpController.java @@ -1,18 +1,16 @@ package com.njcn.csdevice.controller.equipment; -import cn.hutool.core.collection.CollectionUtil; import com.github.tocrhz.mqtt.publisher.MqttPublisher; import com.njcn.common.pojo.annotation.OperateInfo; import com.njcn.common.pojo.enums.common.LogEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum; -import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.HttpResultUtil; -import com.njcn.csdevice.enums.AlgorithmResponseEnum; import com.njcn.csdevice.service.DeviceFtpService; import com.njcn.csharmonic.pojo.vo.MakeUpVo; import com.njcn.redis.utils.RedisUtil; import com.njcn.web.controller.BaseController; +import com.njcn.web.utils.RequestUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -25,7 +23,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; -import java.util.Objects; /** * @author xy @@ -63,9 +60,6 @@ public class DeviceFtpController extends BaseController { public HttpResult> askDeviceFileOrDir(@RequestParam("nDid") String nDid, @RequestParam("name") String name, @RequestParam("type") String type){ String methodDescribe = getMethodDescribe("askDeviceFileOrDir"); List list = deviceFtpService.askDeviceFileOrDir(nDid,name,type); - if (CollectionUtil.isEmpty(list) && Objects.equals(type,"file")) { - throw new BusinessException(AlgorithmResponseEnum.ASK_DEVICE_DIR_ERROR); - } return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); } @@ -79,6 +73,7 @@ public class DeviceFtpController extends BaseController { @ApiImplicitParam(name = "fileCheck", value = "文件校验码", required = true) }) public HttpResult downloadFile(@RequestParam("nDid") String nDid, @RequestParam("name") String name, @RequestParam("size") Integer size, @RequestParam("fileCheck") String fileCheck){ + redisUtil.saveByKeyWithExpire("fileDownUserId"+nDid+name,RequestUtil.getUserIndex(),600L); deviceFtpService.downloadFile(nDid,name,size,fileCheck); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, "文件下载中,请稍等"); } diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/DeviceFtpServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/DeviceFtpServiceImpl.java index 42f13ed..548de6a 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/DeviceFtpServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/DeviceFtpServiceImpl.java @@ -45,7 +45,10 @@ public class DeviceFtpServiceImpl implements DeviceFtpService { public MakeUpVo askDeviceRootPath(String nDid) { MakeUpVo makeUpVo = new MakeUpVo(); try { - judgeClientOnline(nDid); + boolean mqttClient = judgeClientOnline(nDid); + if (!mqttClient){ + throw new BusinessException(AccessResponseEnum.MISSING_CLIENT); + } redisUtil.delete(AppRedisKey.DEVICE_ROOT_PATH + nDid); askDeviceDataFeignClient.askDeviceRootPath(nDid); Thread.sleep(3000); @@ -55,7 +58,7 @@ public class DeviceFtpServiceImpl implements DeviceFtpService { makeUpVo.setType("dir"); } } catch (Exception e) { - throw new BusinessException(AlgorithmResponseEnum.ASK_DEVICE_DIR_ROOT_ERROR); + throw new BusinessException(e.getMessage()); } return makeUpVo; } @@ -64,7 +67,10 @@ public class DeviceFtpServiceImpl implements DeviceFtpService { public List askDeviceFileOrDir(String nDid, String name, String type) { List result = new ArrayList<>(); try { - judgeClientOnline(nDid); + boolean mqttClient = judgeClientOnline(nDid); + if (!mqttClient){ + throw new BusinessException(AccessResponseEnum.MISSING_CLIENT); + } // 删除旧的缓存信息 redisUtil.delete(AppRedisKey.PROJECT_INFO + nDid); // 请求设备文件或目录信息 @@ -78,7 +84,7 @@ public class DeviceFtpServiceImpl implements DeviceFtpService { } } catch (Exception e) { // 捕获特定异常并抛出运行时异常 - throw new BusinessException(AlgorithmResponseEnum.ASK_DEVICE_DIR_ERROR); + throw new BusinessException(e.getMessage()); } if (CollUtil.isNotEmpty(result)) { result.stream().sorted(Comparator.comparing(MakeUpVo::getType)).collect(Collectors.toList()); @@ -89,7 +95,10 @@ public class DeviceFtpServiceImpl implements DeviceFtpService { @Override @Async public void downloadFile(String nDid, String name, Integer size, String fileCheck) { - judgeClientOnline(nDid); + boolean mqttClient = judgeClientOnline(nDid); + if (!mqttClient) { + throw new BusinessException(AccessResponseEnum.MISSING_CLIENT); + } Object task = redisUtil.getObjectByKey("fileDowning:"+nDid); if (Objects.nonNull(task)) { throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOADING); @@ -104,7 +113,7 @@ public class DeviceFtpServiceImpl implements DeviceFtpService { } catch (Exception e) { redisUtil.delete("fileDowning:"+nDid); redisUtil.delete("fileCheck"+nDid+name); - throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOADING); + throw new BusinessException(e.getMessage()); } } @@ -119,6 +128,7 @@ public class DeviceFtpServiceImpl implements DeviceFtpService { redisUtil.delete("fileCheck"+nDid+name); redisUtil.delete("fileDowning:"+nDid); redisUtil.delete(AppRedisKey.FILE_PART.concat(name)); + redisUtil.delete("fileDownUserId"+nDid+name); return result; } @@ -134,7 +144,7 @@ public class DeviceFtpServiceImpl implements DeviceFtpService { result = true; } } catch (InterruptedException e) { - throw new RuntimeException(e); + throw new RuntimeException(e.getMessage()); } return result; } @@ -151,7 +161,7 @@ public class DeviceFtpServiceImpl implements DeviceFtpService { result = true; } } catch (InterruptedException e) { - throw new RuntimeException(e); + throw new RuntimeException(e.getMessage()); } return result; } @@ -198,13 +208,10 @@ public class DeviceFtpServiceImpl implements DeviceFtpService { return vo; } - public void judgeClientOnline(String nDid) { + public boolean judgeClientOnline(String nDid) { //判断客户端是否在线 String clientName = "NJCN-" + nDid.substring(nDid.length() - 6); - boolean mqttClient = mqttUtil.judgeClientOnline(clientName); - if (!mqttClient){ - throw new BusinessException(AccessResponseEnum.MISSING_CLIENT); - } + return mqttUtil.judgeClientOnline(clientName); }