文件下载bug消缺
This commit is contained in:
@@ -1,18 +1,16 @@
|
|||||||
package com.njcn.csdevice.controller.equipment;
|
package com.njcn.csdevice.controller.equipment;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
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.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.HttpResultUtil;
|
import com.njcn.common.utils.HttpResultUtil;
|
||||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
|
||||||
import com.njcn.csdevice.service.DeviceFtpService;
|
import com.njcn.csdevice.service.DeviceFtpService;
|
||||||
import com.njcn.csharmonic.pojo.vo.MakeUpVo;
|
import com.njcn.csharmonic.pojo.vo.MakeUpVo;
|
||||||
import com.njcn.redis.utils.RedisUtil;
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
import com.njcn.web.controller.BaseController;
|
import com.njcn.web.controller.BaseController;
|
||||||
|
import com.njcn.web.utils.RequestUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
@@ -25,7 +23,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xy
|
* @author xy
|
||||||
@@ -63,9 +60,6 @@ public class DeviceFtpController extends BaseController {
|
|||||||
public HttpResult<List<MakeUpVo>> askDeviceFileOrDir(@RequestParam("nDid") String nDid, @RequestParam("name") String name, @RequestParam("type") String type){
|
public HttpResult<List<MakeUpVo>> askDeviceFileOrDir(@RequestParam("nDid") String nDid, @RequestParam("name") String name, @RequestParam("type") String type){
|
||||||
String methodDescribe = getMethodDescribe("askDeviceFileOrDir");
|
String methodDescribe = getMethodDescribe("askDeviceFileOrDir");
|
||||||
List<MakeUpVo> list = deviceFtpService.askDeviceFileOrDir(nDid,name,type);
|
List<MakeUpVo> 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);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +73,7 @@ public class DeviceFtpController extends BaseController {
|
|||||||
@ApiImplicitParam(name = "fileCheck", value = "文件校验码", required = true)
|
@ApiImplicitParam(name = "fileCheck", value = "文件校验码", required = true)
|
||||||
})
|
})
|
||||||
public HttpResult<String> downloadFile(@RequestParam("nDid") String nDid, @RequestParam("name") String name, @RequestParam("size") Integer size, @RequestParam("fileCheck") String fileCheck){
|
public HttpResult<String> 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);
|
deviceFtpService.downloadFile(nDid,name,size,fileCheck);
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, "文件下载中,请稍等");
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, "文件下载中,请稍等");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,10 @@ public class DeviceFtpServiceImpl implements DeviceFtpService {
|
|||||||
public MakeUpVo askDeviceRootPath(String nDid) {
|
public MakeUpVo askDeviceRootPath(String nDid) {
|
||||||
MakeUpVo makeUpVo = new MakeUpVo();
|
MakeUpVo makeUpVo = new MakeUpVo();
|
||||||
try {
|
try {
|
||||||
judgeClientOnline(nDid);
|
boolean mqttClient = judgeClientOnline(nDid);
|
||||||
|
if (!mqttClient){
|
||||||
|
throw new BusinessException(AccessResponseEnum.MISSING_CLIENT);
|
||||||
|
}
|
||||||
redisUtil.delete(AppRedisKey.DEVICE_ROOT_PATH + nDid);
|
redisUtil.delete(AppRedisKey.DEVICE_ROOT_PATH + nDid);
|
||||||
askDeviceDataFeignClient.askDeviceRootPath(nDid);
|
askDeviceDataFeignClient.askDeviceRootPath(nDid);
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
@@ -55,7 +58,7 @@ public class DeviceFtpServiceImpl implements DeviceFtpService {
|
|||||||
makeUpVo.setType("dir");
|
makeUpVo.setType("dir");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BusinessException(AlgorithmResponseEnum.ASK_DEVICE_DIR_ROOT_ERROR);
|
throw new BusinessException(e.getMessage());
|
||||||
}
|
}
|
||||||
return makeUpVo;
|
return makeUpVo;
|
||||||
}
|
}
|
||||||
@@ -64,7 +67,10 @@ public class DeviceFtpServiceImpl implements DeviceFtpService {
|
|||||||
public List<MakeUpVo> askDeviceFileOrDir(String nDid, String name, String type) {
|
public List<MakeUpVo> askDeviceFileOrDir(String nDid, String name, String type) {
|
||||||
List<MakeUpVo> result = new ArrayList<>();
|
List<MakeUpVo> result = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
judgeClientOnline(nDid);
|
boolean mqttClient = judgeClientOnline(nDid);
|
||||||
|
if (!mqttClient){
|
||||||
|
throw new BusinessException(AccessResponseEnum.MISSING_CLIENT);
|
||||||
|
}
|
||||||
// 删除旧的缓存信息
|
// 删除旧的缓存信息
|
||||||
redisUtil.delete(AppRedisKey.PROJECT_INFO + nDid);
|
redisUtil.delete(AppRedisKey.PROJECT_INFO + nDid);
|
||||||
// 请求设备文件或目录信息
|
// 请求设备文件或目录信息
|
||||||
@@ -78,7 +84,7 @@ public class DeviceFtpServiceImpl implements DeviceFtpService {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 捕获特定异常并抛出运行时异常
|
// 捕获特定异常并抛出运行时异常
|
||||||
throw new BusinessException(AlgorithmResponseEnum.ASK_DEVICE_DIR_ERROR);
|
throw new BusinessException(e.getMessage());
|
||||||
}
|
}
|
||||||
if (CollUtil.isNotEmpty(result)) {
|
if (CollUtil.isNotEmpty(result)) {
|
||||||
result.stream().sorted(Comparator.comparing(MakeUpVo::getType)).collect(Collectors.toList());
|
result.stream().sorted(Comparator.comparing(MakeUpVo::getType)).collect(Collectors.toList());
|
||||||
@@ -89,7 +95,10 @@ public class DeviceFtpServiceImpl implements DeviceFtpService {
|
|||||||
@Override
|
@Override
|
||||||
@Async
|
@Async
|
||||||
public void downloadFile(String nDid, String name, Integer size, String fileCheck) {
|
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);
|
Object task = redisUtil.getObjectByKey("fileDowning:"+nDid);
|
||||||
if (Objects.nonNull(task)) {
|
if (Objects.nonNull(task)) {
|
||||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOADING);
|
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOADING);
|
||||||
@@ -104,7 +113,7 @@ public class DeviceFtpServiceImpl implements DeviceFtpService {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
redisUtil.delete("fileDowning:"+nDid);
|
redisUtil.delete("fileDowning:"+nDid);
|
||||||
redisUtil.delete("fileCheck"+nDid+name);
|
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("fileCheck"+nDid+name);
|
||||||
redisUtil.delete("fileDowning:"+nDid);
|
redisUtil.delete("fileDowning:"+nDid);
|
||||||
redisUtil.delete(AppRedisKey.FILE_PART.concat(name));
|
redisUtil.delete(AppRedisKey.FILE_PART.concat(name));
|
||||||
|
redisUtil.delete("fileDownUserId"+nDid+name);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +144,7 @@ public class DeviceFtpServiceImpl implements DeviceFtpService {
|
|||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e.getMessage());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -151,7 +161,7 @@ public class DeviceFtpServiceImpl implements DeviceFtpService {
|
|||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e.getMessage());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -198,13 +208,10 @@ public class DeviceFtpServiceImpl implements DeviceFtpService {
|
|||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void judgeClientOnline(String nDid) {
|
public boolean judgeClientOnline(String nDid) {
|
||||||
//判断客户端是否在线
|
//判断客户端是否在线
|
||||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
return mqttUtil.judgeClientOnline(clientName);
|
||||||
if (!mqttClient){
|
|
||||||
throw new BusinessException(AccessResponseEnum.MISSING_CLIENT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user