代码优化

This commit is contained in:
xy
2024-10-21 20:00:51 +08:00
parent 4a20892ab3
commit 6d7000ddc2
7 changed files with 76 additions and 27 deletions

View File

@@ -6,6 +6,7 @@ import com.njcn.mq.message.AppEventMessage;
import com.njcn.zlevent.api.fallback.WaveClientFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author xy
@@ -15,4 +16,7 @@ public interface WaveFeignClient {
@PostMapping("/analysis")
HttpResult<String> analysis(AppEventMessage appEventMessage);
@PostMapping("/channelWave")
HttpResult<String> channelWave(@RequestParam("nDid") String nDid);
}

View File

@@ -4,7 +4,6 @@ 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.mq.message.AppEventMessage;
import com.njcn.zlevent.api.EventFeignClient;
import com.njcn.zlevent.api.WaveFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
@@ -31,6 +30,12 @@ public class WaveClientFallbackFactory implements FallbackFactory<WaveFeignClien
log.error("{}异常,降级处理,异常为:{}","波形报文解析",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<String> channelWave(String nDid) {
log.error("{}异常,降级处理,异常为:{}","处理录波事件",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -13,10 +13,7 @@ import io.swagger.annotations.ApiImplicitParam;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* 类的介绍:
@@ -44,4 +41,14 @@ public class WaveController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/channelWave")
@ApiOperation("处理录波事件")
@ApiImplicitParam(name = "nDid", value = "nDid", required = true)
public HttpResult<String> channelWave(@RequestParam("nDid") String nDid){
String methodDescribe = getMethodDescribe("channelWave");
csWaveService.channelWave(nDid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -54,6 +54,7 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
private final DicDataFeignClient dicDataFeignClient;
private final ChannelObjectUtil channelObjectUtil;
private final MqttUtil mqttUtil;
private static Integer mid = 1;
@Override
public void analysis(AppEventMessage appEventMessage) {
@@ -112,8 +113,18 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
if (Objects.isNull(obj)) {
List<WaveTimeDto> list = channelObjectUtil.objectToList( redisUtil.getObjectByKey("eventFile:" + nDid),WaveTimeDto.class);
if (CollectionUtil.isNotEmpty(list)) {
Object object = channelObjectUtil.getDeviceMid(nDid);
if (!Objects.isNull(object)) {
mid = (Integer) object;
}
WaveTimeDto dto = list.get(0);
askFileInfo(nDid,1,dto.getFileName());
redisUtil.saveByKeyWithExpire("fileMid:" + nDid,mid + "concat" +dto.getFileName(),60L);
askFileInfo(nDid,mid,dto.getFileName());
mid = mid + 1;
if (mid > 10000) {
mid = 1;
}
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
}
} else {
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOADING);