1.移植程序软件接口;

2.返回文件上传、下载进度信息
This commit is contained in:
xy
2024-09-19 14:26:29 +08:00
parent 32520907d2
commit b59c85e791
11 changed files with 57 additions and 233 deletions

View File

@@ -1,20 +0,0 @@
package com.njcn.access.api;
import com.njcn.access.api.fallback.CsSoftInfoClientFallbackFactory;
import com.njcn.access.pojo.po.CsSoftInfoPO;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author xy
*/
@FeignClient(value = ServerInfo.ACCESS_BOOT, path = "/csSoftInfo", fallbackFactory = CsSoftInfoClientFallbackFactory.class,contextId = "csSoftInfo")
public interface CsSoftInfoFeignClient {
@PostMapping("/findSoftInfo")
HttpResult<CsSoftInfoPO> findSoftInfo(@RequestParam("id") String id);
}

View File

@@ -1,34 +0,0 @@
package com.njcn.access.api.fallback;
import com.njcn.access.api.CsSoftInfoFeignClient;
import com.njcn.access.pojo.po.CsSoftInfoPO;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author xy
*/
@Slf4j
@Component
public class CsSoftInfoClientFallbackFactory implements FallbackFactory<CsSoftInfoFeignClient> {
@Override
public CsSoftInfoFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (cause.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) cause.getCause();
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new CsSoftInfoFeignClient() {
@Override
public HttpResult<CsSoftInfoPO> findSoftInfo(String id) {
log.error("{}异常,降级处理,异常为:{}","获取装置软件信息",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -1,61 +0,0 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Date;
/**
* <p>
* 系统软件表
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
@Data
@TableName("cs_soft_info")
public class CsSoftInfoPO {
private static final long serialVersionUID = 1L;
private String id;
/**
* 读写操作属性“r”
*/
private String opAttr;
/**
* 操作系统名称裸机系统填Null
*/
private String osName;
/**
* 操作系统版本裸机系统填Null
*/
private String osVersion;
/**
* 应用程序版本号
*/
private String appVersion;
/**
* 应用程序发布日期
*/
private LocalDateTime appDate;
/**
* 应用程序校验码
*/
private String appCheck;
/**
* 是否支持远程升级程序
*/
private String softUpdate;
}

View File

@@ -1,52 +0,0 @@
package com.njcn.access.controller;
import com.njcn.access.mapper.CsSoftInfoMapper;
import com.njcn.access.pojo.po.CsSoftInfoPO;
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.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
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;
/**
* <p>
* 系统软件表 前端控制器
* </p>
*
* @author xuyang
* @since 2023-08-09
*/
@Slf4j
@RestController
@RequestMapping("/csSoftInfo")
@Api(tags = "装置程序信息")
@AllArgsConstructor
@Validated
public class CsSoftInfoController extends BaseController {
private final CsSoftInfoMapper csSoftInfoMapper;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/findSoftInfo")
@ApiOperation("获取程序软件信息")
@ApiImplicitParam(name = "id", value = "id", required = true)
public HttpResult<CsSoftInfoPO> findSoftInfo(@RequestParam String id){
String methodDescribe = getMethodDescribe("findSoftInfo");
CsSoftInfoPO po = csSoftInfoMapper.selectById(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
}
}

View File

@@ -21,17 +21,16 @@ import com.njcn.access.pojo.dto.file.FileRedisDto;
import com.njcn.access.pojo.param.ReqAndResParam;
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
import com.njcn.access.pojo.po.CsLineModel;
import com.njcn.access.pojo.po.CsSoftInfoPO;
import com.njcn.access.pojo.po.CsTopic;
import com.njcn.access.service.*;
import com.njcn.access.service.ICsDeviceOnlineLogsService;
import com.njcn.access.service.ICsEquipmentDeliveryService;
import com.njcn.access.service.ICsLineModelService;
import com.njcn.access.service.ICsTopicService;
import com.njcn.common.pojo.dto.DeviceLogDTO;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.*;
import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.pojo.po.CsDataSet;
import com.njcn.csdevice.pojo.po.CsDevCapacityPO;
import com.njcn.csdevice.pojo.po.CsDevModelPO;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csdevice.pojo.po.*;
import com.njcn.mq.message.AppAutoDataMessage;
import com.njcn.mq.message.AppEventMessage;
import com.njcn.mq.message.AppFileMessage;
@@ -53,8 +52,6 @@ import org.springframework.transaction.annotation.Transactional;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@@ -101,7 +98,8 @@ public class MqttMessageHandler {
private final ICsDeviceOnlineLogsService onlineLogsService;
private final ICsSoftInfoService csSoftInfoService;
@Autowired
private final CsSoftInfoFeignClient csSoftInfoFeignClient;
private final CsLineFeignClient csLineFeignClient;
@@ -394,12 +392,12 @@ public class MqttMessageHandler {
LocalDateTime localDateTime = LocalDateTime.parse(softInfo.getAppDate(), formatter);
assertThat(localDateTime).isNotNull();
csSoftInfoPo.setAppDate(localDateTime);
csSoftInfoService.save(csSoftInfoPo);
csSoftInfoFeignClient.saveSoftInfo(csSoftInfoPo);
//更新设备软件id 先看是否存在软件信息,删除 然后在录入
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
String soft = po.getSoftinfoId();
if (StringUtil.isNotBlank(soft)){
csSoftInfoService.removeById(soft);
csSoftInfoFeignClient.removeSoftInfo(soft);
}
equipmentFeignClient.updateSoftInfo(nDid,csSoftInfoPo.getId());
//询问设备容量信息

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.access.pojo.po.CsSoftInfoPO;
/**
* <p>
* 系统软件表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-08-09
*/
public interface CsSoftInfoMapper extends BaseMapper<CsSoftInfoPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.access.pojo.po.CsSoftInfoPO;
/**
* <p>
* 系统软件表 服务类
* </p>
*
* @author xuyang
* @since 2023-08-09
*/
public interface ICsSoftInfoService extends IService<CsSoftInfoPO> {
}

View File

@@ -1,5 +1,7 @@
package com.njcn.access.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.njcn.access.api.CsTopicFeignClient;
@@ -14,6 +16,7 @@ import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.zlevent.pojo.dto.FileStreamDto;
import com.njcn.zlevent.pojo.dto.NoticeUserDto;
import lombok.RequiredArgsConstructor;
import net.sf.json.JSONObject;
@@ -106,6 +109,13 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
if (!Objects.isNull(object2)) {
result = true;
break;
} else {
Object object3 = redisUtil.getObjectByKey(AppRedisKey.FILE_PART.concat(name));
if (!Objects.isNull(object3)) {
FileStreamDto dto = JSON.parseObject(JSON.toJSONString(object3), FileStreamDto.class);
String json = "{allStep:"+dto.getTotal()+",nowStep:"+ (CollectionUtil.isEmpty(dto.getList())?0:dto.getList().size())+"}";
publisher.send("/Web/Progress/" + nDid, new Gson().toJson(json), 1, false);
}
}
}
mid = mid + 1;

View File

@@ -191,8 +191,8 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
int times = bytes.length / cap + 1;
for (int i = 1; i <= times; i++) {
//发送数据给前端
String json = "{allStep:\""+times+"\",nowStep:"+i+"}";
publisher.send("/Web/Progress", new Gson().toJson(json), 1, false);
String json = "{allStep:"+times+",nowStep:"+i+"}";
publisher.send("/Web/Progress/" + id, new Gson().toJson(json), 1, false);
DeviceLogDTO logDto = new DeviceLogDTO();
byte[] lsBytes;
if (length > 50*1024) {

View File

@@ -1,20 +0,0 @@
package com.njcn.access.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.access.mapper.CsSoftInfoMapper;
import com.njcn.access.pojo.po.CsSoftInfoPO;
import com.njcn.access.service.ICsSoftInfoService;
import org.springframework.stereotype.Service;
/**
* <p>
* 系统软件表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-08-09
*/
@Service
public class CsSoftInfoServiceImpl extends ServiceImpl<CsSoftInfoMapper, CsSoftInfoPO> implements ICsSoftInfoService {
}

View File

@@ -138,7 +138,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
ReqAndResDto.Req reqAndResParam = getPojo(mid,name,i);
publisher.send("/Pfm/DevFileCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false);
//判断是否重发
sendNextStep(name,nDid,mid,i);
webSendNextStep(name,nDid,mid,i);
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.DOWNLOAD + name + mid);
//重发之后判断继续循环还是跳出循环
if (!Objects.isNull(fileRedisDto) && !Objects.equals(fileRedisDto.getCode(),200)) {
@@ -200,6 +200,41 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
return reqAndResParam;
}
/**
* web端根据装置响应来判断是否询问下一帧数据
*/
public void webSendNextStep(String fileName, String id, int mid,int step) {
try {
for (int i = 1; i <= 30; i++) {
if (step == 0 ){
Thread.sleep(5000);
} else {
Thread.sleep(2000);
}
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.DOWNLOAD + fileName + mid);
if (Objects.isNull(fileRedisDto)) {
FileRedisDto failDto = new FileRedisDto();
failDto.setCode(400);
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileName + mid,failDto,10L);
} else {
if (Objects.equals(fileRedisDto.getCode(),200)) {
break;
} else {
log.info("" +i+"次尝试");
//尝试失败则设置code为400如果装置响应了则会将code置为200
FileRedisDto failDto = new FileRedisDto();
failDto.setCode(400);
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileName + mid,failDto,10L);
ReqAndResDto.Req req = getPojo(mid,fileName,step);
publisher.send("/Pfm/DevFileCmd/V1/" + id, new Gson().toJson(req), 1, false);
}
}
}
} catch (Exception e) {
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
}
}
/**
* 根据装置响应来判断是否询问下一帧数据
*/