文件下载、上传调整
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.njcn.csdevice.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.csdevice.api.fallback.WlRecordClientFallbackFactory;
|
||||
import com.njcn.csdevice.pojo.po.WlRecord;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.CS_DEVICE_BOOT, path = "/wlRecord", fallbackFactory = WlRecordClientFallbackFactory.class,contextId = "wlRecord")
|
||||
|
||||
public interface WlRecordFeignClient {
|
||||
|
||||
/**
|
||||
* 新增原始数据
|
||||
*/
|
||||
@PostMapping("/addBaseData")
|
||||
HttpResult<Boolean> addBaseData(@RequestBody @Validated WlRecord wlRecord);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.njcn.csdevice.api.fallback;
|
||||
|
||||
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.csdevice.api.WlRecordFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.WlRecord;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class WlRecordClientFallbackFactory implements FallbackFactory<WlRecordFeignClient> {
|
||||
@Override
|
||||
public WlRecordFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new WlRecordFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<Boolean> addBaseData(WlRecord wlRecord) {
|
||||
log.error("{}异常,降级处理,异常为:{}","新增原始数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,13 @@ public enum AlgorithmResponseEnum {
|
||||
|
||||
DATA_ARRAY_MISSING("A00515","详细数据为空"),
|
||||
UNKNOW_ROLE("A00515","角色无权限操作"),
|
||||
DATA_MISSING("A00516","数据缺失")
|
||||
DATA_MISSING("A00516","数据缺失"),
|
||||
ASK_DEVICE_DIR_ROOT_ERROR("A00516","读取装置根目录异常"),
|
||||
ASK_DEVICE_DIR_ERROR("A00516","读取装置文件异常,请重试"),
|
||||
FILE_DOWNLOAD_ERROR("A00516","下载失败"),
|
||||
FILE_DOWNLOADING("A00516","下载失败,系统正在响应其他下载任务,请稍后重试"),
|
||||
FILE_UPLOADING("A00516","上传失败,系统正在响应其他上传任务,请稍后重试"),
|
||||
FILE_BUSY("A00516","正在进行其他文件操作,请稍后重试"),
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -145,4 +145,9 @@ public class WlRecord extends BaseEntity {
|
||||
@TableField(value = "`describe`")
|
||||
private String describe;
|
||||
|
||||
/**
|
||||
* 工程路径
|
||||
*/
|
||||
private String gcDataPath;
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,9 @@ public class CsLedgerVO implements Serializable {
|
||||
@ApiModelProperty(name = "comFlag",value = "设备状态")
|
||||
private Integer comFlag;
|
||||
|
||||
@ApiModelProperty(name = "nDid",value = "nDid")
|
||||
private String nDId;
|
||||
|
||||
@ApiModelProperty(name = "children",value = "子节点")
|
||||
private List<CsLedgerVO> children = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -42,6 +42,16 @@ public class DeviceManagerVO {
|
||||
@ApiModelProperty(value = "装置数据标识")
|
||||
private String dataLevel;
|
||||
|
||||
@ApiModelProperty(value = "应用程序版本号")
|
||||
private String appVersion;
|
||||
|
||||
@ApiModelProperty(value = "应用程序发布日期")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||
private LocalDateTime appDate;
|
||||
|
||||
@ApiModelProperty(value = "应用程序校验码")
|
||||
private String appCheck;
|
||||
|
||||
@Data
|
||||
public static class DataSetVO {
|
||||
@ApiModelProperty(value = "数据集Id")
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.njcn.csdevice.controller.equipment;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
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 io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Api(tags = "装置文件管理")
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/deviceFile")
|
||||
public class DeviceFtpController extends BaseController {
|
||||
|
||||
private final DeviceFtpService deviceFtpService;
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/askDeviceRootPath")
|
||||
@ApiOperation("设备根目录询问")
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true)
|
||||
public HttpResult<MakeUpVo> askDeviceRootPath(@RequestParam("nDid") String nDid){
|
||||
String methodDescribe = getMethodDescribe("askDeviceRootPath");
|
||||
MakeUpVo vo = deviceFtpService.askDeviceRootPath(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/askDeviceFileOrDir")
|
||||
@ApiOperation("设备文件/目录信息询问")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true),
|
||||
@ApiImplicitParam(name = "name", value = "文件路径名", required = true),
|
||||
@ApiImplicitParam(name = "type", value = "文件类型", required = true)
|
||||
})
|
||||
public HttpResult<List<MakeUpVo>> askDeviceFileOrDir(@RequestParam("nDid") String nDid, @RequestParam("name") String name, @RequestParam("type") String type){
|
||||
String methodDescribe = getMethodDescribe("askDeviceFileOrDir");
|
||||
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);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/downloadFile")
|
||||
@ApiOperation("设备文件下载")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true),
|
||||
@ApiImplicitParam(name = "name", value = "文件路径名", required = true),
|
||||
@ApiImplicitParam(name = "size", value = "文件大小(单位byte)", 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){
|
||||
String methodDescribe = getMethodDescribe("downloadFile");
|
||||
String result = deviceFtpService.downloadFile(nDid,name,size,fileCheck);
|
||||
if (Objects.isNull(result)) {
|
||||
redisUtil.delete("downloadFilePath:"+name);
|
||||
redisUtil.delete("fileCheck"+name);
|
||||
redisUtil.delete("fileDowning");
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import com.njcn.csdevice.service.IMqttUserService;
|
||||
import com.njcn.csdevice.utils.ExcelStyleUtil;
|
||||
import com.njcn.poi.excel.ExcelUtil;
|
||||
import com.njcn.poi.util.PoiUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.web.advice.DeviceLog;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.*;
|
||||
@@ -284,4 +283,18 @@ public class EquipmentDeliveryController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/rebootDevice")
|
||||
@ApiOperation("重启设备")
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true)
|
||||
public HttpResult<String> rebootDevice(@RequestParam("nDid") String nDid){
|
||||
String methodDescribe = getMethodDescribe("rebootDevice");
|
||||
boolean result = csEquipmentDeliveryService.rebootDevice(nDid);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.csdevice.param.WlRecordPageParam;
|
||||
import com.njcn.csdevice.pojo.param.WlRecordParam;
|
||||
import com.njcn.csdevice.pojo.po.WlRecord;
|
||||
import com.njcn.csdevice.pojo.vo.RecordTreeVo;
|
||||
import com.njcn.csdevice.pojo.vo.RecordVo;
|
||||
import com.njcn.csdevice.service.IWlRecordService;
|
||||
@@ -83,6 +84,20 @@ public class WlRecordController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增原始数据
|
||||
*/
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||
@PostMapping("/addBaseData")
|
||||
@ApiOperation("新增原始数据")
|
||||
@ApiImplicitParam(name = "wlRecord", value = "装置原始数据", required = true)
|
||||
public HttpResult<Boolean> addBaseData(@RequestBody @Validated WlRecord wlRecord) {
|
||||
String methodDescribe = getMethodDescribe("addBaseData");
|
||||
LogUtil.njcnDebug(log, "{},装置原始数据为:{}", methodDescribe, wlRecord);
|
||||
wlRecordService.addBaseData(wlRecord);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改测试项
|
||||
*/
|
||||
|
||||
@@ -114,4 +114,6 @@ public interface CsEquipmentDeliveryService extends IService<CsEquipmentDelivery
|
||||
* @param number
|
||||
*/
|
||||
void updateModuleNumber(String nDid, Integer number);
|
||||
|
||||
boolean rebootDevice(String nDid);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.njcn.csdevice.service;
|
||||
|
||||
import com.njcn.csharmonic.pojo.vo.MakeUpVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DeviceFtpService {
|
||||
|
||||
MakeUpVo askDeviceRootPath(String nDid);
|
||||
|
||||
List<MakeUpVo> askDeviceFileOrDir(String nDid, String name, String type);
|
||||
|
||||
String downloadFile(String nDid, String name, Integer size, String fileCheck);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.njcn.csdevice.pojo.vo.RecordTreeVo;
|
||||
import com.njcn.csdevice.pojo.vo.RecordVo;
|
||||
import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
|
||||
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -41,6 +42,13 @@ public interface IWlRecordService extends IService<WlRecord> {
|
||||
*/
|
||||
void addRecord(WlRecordParam.AddRecord records);
|
||||
|
||||
/**
|
||||
* 新增原始数据
|
||||
* @param wlRecord
|
||||
* @return
|
||||
*/
|
||||
void addBaseData(WlRecord wlRecord);
|
||||
|
||||
/**
|
||||
* 修改测试项
|
||||
* @param record
|
||||
|
||||
@@ -11,14 +11,15 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.api.AskDeviceDataFeignClient;
|
||||
import com.njcn.access.api.CsSoftInfoFeignClient;
|
||||
import com.njcn.access.pojo.po.CsSoftInfoPO;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.constant.DataParam;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
@@ -35,10 +36,10 @@ import com.njcn.db.constant.DbConstant;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicTreeEnum;
|
||||
import com.njcn.system.pojo.vo.DictTreeVO;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
@@ -75,28 +76,20 @@ import java.util.stream.Collectors;
|
||||
public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliveryMapper, CsEquipmentDeliveryPO> implements CsEquipmentDeliveryService{
|
||||
|
||||
private final CsDevModelRelationService csDevModelRelationService;
|
||||
|
||||
private final ICsDataSetService csDataSetService;
|
||||
|
||||
private final ICsLedgerService csLedgerService;
|
||||
|
||||
private final RoleEngineerDevService roleEngineerDevService;
|
||||
|
||||
private final CsDeviceUserPOService csDeviceUserPOService;
|
||||
|
||||
private final AppLineTopologyDiagramService appLineTopologyDiagramService;
|
||||
|
||||
private final CsTouristDataPOService csTouristDataPOService;
|
||||
|
||||
private final CsLinePOService csLinePOService;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
private final CsEquipmentProcessPOService csEquipmentProcessPOService;
|
||||
private final IMqttUserService mqttUserService;
|
||||
private final AskDeviceDataFeignClient askDeviceDataFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final CsSoftInfoFeignClient csSoftInfoFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@@ -281,6 +274,14 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
DeviceManagerVO deviceManagerVo = new DeviceManagerVO();
|
||||
List<DeviceManagerVO.DataSetVO> dataSetList = new ArrayList<>();
|
||||
CsEquipmentDeliveryPO csEquipmentDeliveryPo = this.lambdaQuery().eq(CsEquipmentDeliveryPO::getId, deviceId).one();
|
||||
//获取装置版本信息
|
||||
String softInfoId = csEquipmentDeliveryPo.getSoftinfoId();
|
||||
if (StringUtils.isNotBlank(softInfoId) && ObjectUtil.isNotNull(softInfoId)) {
|
||||
CsSoftInfoPO po = csSoftInfoFeignClient.findSoftInfo(softInfoId).getData();
|
||||
deviceManagerVo.setAppVersion(po.getAppVersion());
|
||||
deviceManagerVo.setAppDate(po.getAppDate());
|
||||
deviceManagerVo.setAppCheck(po.getAppCheck());
|
||||
}
|
||||
if (lineId == null || lineId.isEmpty()) {
|
||||
List<CsDataSet> dataSet = new ArrayList<>();
|
||||
//如果没有传lineId(测点ID) 则根据设备ID获取对应的模板 select modelId from cs_dev_model_relation where dev_id = ?
|
||||
@@ -601,6 +602,23 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
this.update(lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rebootDevice(String nDid) {
|
||||
boolean result = false;
|
||||
try {
|
||||
askDeviceDataFeignClient.rebootDevice(nDid);
|
||||
Thread.sleep(3000);
|
||||
String key = AppRedisKey.CONTROL + nDid;
|
||||
String value = redisUtil.getObjectByKey(key).toString();
|
||||
if (Objects.equals(value,"success")) {
|
||||
result = true;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ndid生成二维码
|
||||
* @param ndid
|
||||
|
||||
@@ -201,6 +201,7 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
|
||||
temp->{
|
||||
CsEquipmentDeliveryPO csEquipmentDeliveryPO = csEquipmentDeliveryMapper.selectById(temp.getId());
|
||||
temp.setComFlag(csEquipmentDeliveryPO.getRunStatus());
|
||||
temp.setNDId(csEquipmentDeliveryPO.getNdid());
|
||||
return temp;
|
||||
}
|
||||
).
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.njcn.csdevice.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.njcn.access.api.AskDeviceDataFeignClient;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
import com.njcn.access.pojo.dto.file.FileDto;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.service.DeviceFtpService;
|
||||
import com.njcn.csharmonic.pojo.vo.MakeUpVo;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceFtpServiceImpl implements DeviceFtpService {
|
||||
|
||||
private final AskDeviceDataFeignClient askDeviceDataFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
private final MqttUtil mqttUtil;
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public MakeUpVo askDeviceRootPath(String nDid) {
|
||||
MakeUpVo makeUpVo = new MakeUpVo();
|
||||
try {
|
||||
judgeClientOnline(nDid);
|
||||
redisUtil.delete(AppRedisKey.DEVICE_ROOT_PATH + nDid);
|
||||
askDeviceDataFeignClient.askDeviceRootPath(nDid);
|
||||
Thread.sleep(3000);
|
||||
Object object = redisUtil.getObjectByKey(AppRedisKey.DEVICE_ROOT_PATH + nDid);
|
||||
if (Objects.nonNull(object)) {
|
||||
makeUpVo.setPrjDataPath(object.toString());
|
||||
makeUpVo.setType("dir");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(AlgorithmResponseEnum.ASK_DEVICE_DIR_ROOT_ERROR);
|
||||
}
|
||||
return makeUpVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MakeUpVo> askDeviceFileOrDir(String nDid, String name, String type) {
|
||||
List<MakeUpVo> result = new ArrayList<>();
|
||||
try {
|
||||
judgeClientOnline(nDid);
|
||||
// 删除旧的缓存信息
|
||||
redisUtil.delete(AppRedisKey.PROJECT_INFO + nDid);
|
||||
// 请求设备文件或目录信息
|
||||
askDeviceDataFeignClient.askDeviceFileOrDir(nDid, name);
|
||||
Thread.sleep(3000);
|
||||
// 从 Redis 获取对象
|
||||
Object object = redisUtil.getObjectByKey(AppRedisKey.PROJECT_INFO + nDid);
|
||||
if (object != null) {
|
||||
// 根据类型处理不同的数据
|
||||
processObject(result, object, type);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 捕获特定异常并抛出运行时异常
|
||||
throw new BusinessException(AlgorithmResponseEnum.ASK_DEVICE_DIR_ERROR);
|
||||
}
|
||||
if (CollUtil.isNotEmpty(result)) {
|
||||
result.stream().sorted(Comparator.comparing(MakeUpVo::getType)).collect(Collectors.toList());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String downloadFile(String nDid, String name, Integer size, String fileCheck) {
|
||||
String result = null;
|
||||
judgeClientOnline(nDid);
|
||||
Object task = redisUtil.getObjectByKey("fileDowning");
|
||||
if (Objects.nonNull(task)) {
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOADING);
|
||||
}
|
||||
Object task2 = redisUtil.getObjectByKey("uploading");
|
||||
if (Objects.nonNull(task2)) {
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_BUSY);
|
||||
}
|
||||
try {
|
||||
redisUtil.delete("downloadFilePath:"+name);
|
||||
boolean file = askDeviceDataFeignClient.downloadFile(nDid,name,size,fileCheck).getData();
|
||||
Thread.sleep(5000);
|
||||
if (!file) {
|
||||
redisUtil.delete("fileDowning");
|
||||
redisUtil.delete("fileCheck"+name);
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
|
||||
}
|
||||
Object object = redisUtil.getObjectByKey("downloadFilePath:"+name);
|
||||
if (Objects.nonNull(object)) {
|
||||
result = fileStorageUtil.getFileUrl((String) object);
|
||||
redisUtil.delete("downloadFilePath:"+name);
|
||||
redisUtil.delete("fileCheck"+name);
|
||||
redisUtil.delete("fileDowning");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
redisUtil.delete("fileDowning");
|
||||
redisUtil.delete("fileCheck"+name);
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOADING);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void processObject(List<MakeUpVo> result, Object object, String type) {
|
||||
if ("dir".equals(type)) {
|
||||
List<FileDto.DirInfo> projectInfoList = channelObjectUtil.objectToList(object, FileDto.DirInfo.class);
|
||||
projectInfoList.forEach(item -> {
|
||||
MakeUpVo vo = createMakeUpVoFromDir(item);
|
||||
result.add(vo);
|
||||
});
|
||||
} else {
|
||||
FileDto.FileInfo fileInfo = channelObjectUtil.objectToSingleObject(object, FileDto.FileInfo.class);
|
||||
MakeUpVo vo = createMakeUpVoFromFile(fileInfo);
|
||||
result.add(vo);
|
||||
}
|
||||
}
|
||||
|
||||
private MakeUpVo createMakeUpVoFromDir(FileDto.DirInfo item) {
|
||||
MakeUpVo vo = new MakeUpVo();
|
||||
vo.setPrjDataPath(item.getName());
|
||||
vo.setType(item.getType());
|
||||
vo.setSize(item.getSize());
|
||||
return vo;
|
||||
}
|
||||
|
||||
private MakeUpVo createMakeUpVoFromFile(FileDto.FileInfo fileInfo) {
|
||||
MakeUpVo vo = new MakeUpVo();
|
||||
vo.setPrjDataPath(fileInfo.getName());
|
||||
if (fileInfo.getFileTime() != 0) {
|
||||
LocalDateTime dateTime = Instant.ofEpochMilli((fileInfo.getFileTime() - 3600*8) * 1000).atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||
String formattedDate = dateTime.format(formatter);
|
||||
vo.setStartTime(formattedDate);
|
||||
vo.setSize(fileInfo.getFileSize());
|
||||
}
|
||||
vo.setFileCheck(fileInfo.getFileCheck());
|
||||
return vo;
|
||||
}
|
||||
|
||||
public void judgeClientOnline(String nDid) {
|
||||
//判断客户端是否在线
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (!mqttClient){
|
||||
throw new BusinessException(AccessResponseEnum.MISSING_CLIENT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -28,13 +28,13 @@ import com.njcn.influx.pojo.bo.CommonQueryParam;
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
import com.njcn.influx.service.CommonService;
|
||||
import com.njcn.system.api.CsStatisticalSetFeignClient;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -99,6 +99,11 @@ public class WlRecordServiceImpl extends ServiceImpl<WlRecordMapper, WlRecord> i
|
||||
this.saveBatch(insertList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBaseData(WlRecord wlRecord) {
|
||||
this.save(wlRecord);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateTestRecord(WlRecordParam.UpdateRecord record) {
|
||||
|
||||
@@ -33,6 +33,10 @@ spring:
|
||||
refresh: true
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 100MB
|
||||
max-request-size: 100MB
|
||||
|
||||
|
||||
#项目日志的配置
|
||||
|
||||
Reference in New Issue
Block a user