Browse Source

重构飞手平台回调接口

tags/v1.0.0^2
wanjing 1 year ago
parent
commit
09560d0989
6 changed files with 60 additions and 111 deletions
  1. +1
    -16
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/DeliverStreamingService.java
  2. +1
    -6
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/GetLiveStatusService.java
  3. +20
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/LiveChannelConstant.java
  4. +1
    -9
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/OnlineCompleteService.java
  5. +7
    -49
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/OnlineIdentifService.java
  6. +30
    -31
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/UpdateFlyerService.java

+ 1
- 16
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/DeliverStreamingService.java View File

@@ -31,21 +31,6 @@ public class DeliverStreamingService {
@Value("${tuoheng.live-channel-domain-url:}")
private String channel_url;

/**
* 根据通道编码获取
*/
private final static String GET_LIVE_CHANNEL_INFO = "streaming/getInfo/{code}";

/**
* 直播通道占用设置地址
*/
public final static String LIVE_CHANNEL_USELIVECHANNEL_URL = "streaming/setUseing";

/**
* 释放通道URL请求地址
*/
private final static String STREAMING_DELIVER_URL = "streaming/setDeliver";

/**
* 释放小程序选择的通道
*
@@ -58,7 +43,7 @@ public class DeliverStreamingService {
|| ChannelStatusEnum.DEACTIVATING.getCode() == streaming.getStatus()) {
return;
}
String url = String.format(Locale.ENGLISH, "%s%s", channel_url, STREAMING_DELIVER_URL);
String url = String.format(Locale.ENGLISH, "%s%s", channel_url, LiveChannelConstant.STREAMING_DELIVER_URL);
StreamingDto streamingDto = new StreamingDto();
streamingDto.setCode(code);
HttpEntity<StreamingDto> httpEntity = new HttpEntity<>(streamingDto);

+ 1
- 6
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/GetLiveStatusService.java View File

@@ -27,16 +27,11 @@ public class GetLiveStatusService {
@Value("${tuoheng.live-channel-domain-url:}")
private String channel_url;

/**
* 根据通道编码获取
*/
private final static String GET_LIVE_CHANNEL_INFO = "streaming/getInfo/{code}";

public StreamingDto getLiveStatus(String code) {
if (org.apache.commons.lang3.StringUtils.isEmpty(code)) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "通道编码不能为空!");
}
String url = String.format(Locale.ENGLISH, "%s%s", channel_url, GET_LIVE_CHANNEL_INFO);
String url = String.format(Locale.ENGLISH, "%s%s", channel_url, LiveChannelConstant.GET_LIVE_CHANNEL_INFO);
ParameterizedTypeReference<JsonResult<StreamingDto>> parameterizedTypeReference =
new ParameterizedTypeReference<JsonResult<StreamingDto>>() {
};

+ 20
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/LiveChannelConstant.java View File

@@ -0,0 +1,20 @@
package com.tuoheng.admin.service.inspection.update.flyer;

public interface LiveChannelConstant {

/**
* 根据通道编码获取
*/
String GET_LIVE_CHANNEL_INFO = "streaming/getInfo/{code}";

/**
* 直播通道占用设置地址
*/
String LIVE_CHANNEL_USELIVECHANNEL_URL = "streaming/setUseing";

/**
* 释放通道URL请求地址
*/
String STREAMING_DELIVER_URL = "streaming/setDeliver";

}

+ 1
- 9
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/OnlineCompleteService.java View File

@@ -58,19 +58,13 @@ public class OnlineCompleteService {
@Qualifier("restTemplate")
private RestTemplate restTemplate;

@Value("${tuoheng.live-channel-domain-url:}")
private String channel_url;

/**
* DSP服务API接口域名
*/
@Value("${tuoheng.dsp-domain-url:}")
private String dspDomainUrl;

@Value("${tuoheng.dsp-callback-url:}")
private String dspCallbackUrl;

public void handle(UpdateTaskByCodeRequest request, Inspection inspection) {
public void handle(Inspection inspection) {
LiveChannel channel = liveChannelMapper.selectOne(new LambdaQueryWrapper<LiveChannel>()
.eq(LiveChannel::getInspectionId, inspection.getId())
.eq(LiveChannel::getMark, 1));
@@ -107,6 +101,4 @@ public class OnlineCompleteService {
deliverStreamingService.deliver(channel.getChannelCode());
}
}


}

+ 7
- 49
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/OnlineIdentifService.java View File

@@ -52,6 +52,9 @@ public class OnlineIdentifService {
@Autowired
private GetLiveStatusService getLiveStatusService;

@Autowired
private DeliverStreamingService deliverStreamingService;

@Autowired
@Qualifier("restTemplate")
private RestTemplate restTemplate;
@@ -68,21 +71,6 @@ public class OnlineIdentifService {
@Value("${tuoheng.dsp-callback-url:}")
private String dspCallbackUrl;

/**
* 根据通道编码获取
*/
private final static String GET_LIVE_CHANNEL_INFO = "streaming/getInfo/{code}";

/**
* 直播通道占用设置地址
*/
public final static String LIVE_CHANNEL_USELIVECHANNEL_URL = "streaming/setUseing";

/**
* 释放通道URL请求地址
*/
private final static String STREAMING_DELIVER_URL = "streaming/setDeliver";

public void handle(UpdateTaskByCodeRequest request, Inspection inspection) {
log.info("=========================在线识别开始=========================");
if (request.getChannelCode() == null) {
@@ -198,7 +186,7 @@ public class OnlineIdentifService {
} catch (Exception e) {
log.error("DSP服务调用失败", e);
// 释放小程序选择的通道
deliverStreaming(request.getChannelCode());
deliverStreamingService.deliver(request.getChannelCode());
throw e;

}
@@ -212,18 +200,18 @@ public class OnlineIdentifService {
log.error("通道状态不是空闲中,不能设置通道状态为占用状态!");
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "通道不是空闲状态,请稍后再试!");
}
String url = String.format(Locale.ENGLISH, "%s%s", channel_url, LIVE_CHANNEL_USELIVECHANNEL_URL);
String url = String.format(Locale.ENGLISH, "%s%s", channel_url, LiveChannelConstant.LIVE_CHANNEL_USELIVECHANNEL_URL);
HttpEntity httpEntity = new HttpEntity(liveChannelDto);
ResponseEntity<JsonResult> response;
try {
response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, JsonResult.class);
} catch (Exception e) {
deliverStreaming(liveChannelDto.getCode());
deliverStreamingService.deliver(liveChannelDto.getCode());
log.error("", e);
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "设置通道状态异常!");
}
if (response == null || !response.hasBody() || response.getBody().getCode() != JsonResult.SUCCESS) {
deliverStreaming(liveChannelDto.getCode());
deliverStreamingService.deliver(liveChannelDto.getCode());
log.error("设置占用通道状态失败!");
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "设置通道状态异常!");
}
@@ -259,34 +247,4 @@ public class OnlineIdentifService {
}
}

/**
* 释放小程序选择的通道
*
* @param code 通道编码
*/
private void deliverStreaming(String code) {
try {
StreamingDto streaming = getLiveStatusService.getLiveStatus(code);
if (ChannelStatusEnum.USING.getCode() != streaming.getStatus()
|| ChannelStatusEnum.DEACTIVATING.getCode() == streaming.getStatus()) {
return;
}
String url = String.format(Locale.ENGLISH, "%s%s", channel_url, STREAMING_DELIVER_URL);
StreamingDto streamingDto = new StreamingDto();
streamingDto.setCode(code);
HttpEntity<StreamingDto> httpEntity = new HttpEntity<>(streamingDto);
ResponseEntity<JsonResult> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, JsonResult.class);
if (response == null || !response.hasBody()) {
log.error("释放通道失败,响应体为空!");
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "释放通道失败,请重试");
}
if (response == null || !response.hasBody() || response.getBody().getCode() != JsonResult.SUCCESS) {
log.error("释放通道失败,响应状态码:{}", response.getBody().getCode());
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "释放通道失败,请重试");
}
} catch (Exception e) {
log.error("释放通道失败", e);
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "释放通道失败,请重试");
}
}
}

+ 30
- 31
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/UpdateFlyerService.java View File

@@ -31,9 +31,6 @@ public class UpdateFlyerService {
@Autowired
private InspectionMapper inspectionMapper;

@Autowired
private InspectionFileMapper inspectionFileMapper;

@Autowired
private OnlineIdentifService onlineIdentifService;

@@ -51,7 +48,6 @@ public class UpdateFlyerService {
@Transactional(rollbackFor = Exception.class)
public JsonResult update(UpdateTaskByCodeRequest request) {
log.info("进入修改任务状态和飞手信息业务接口", JacksonUtil.obj2StringPretty(request));
String tenantId = CurrentUserUtil.getTenantId();
JsonResult result = this.check(request);
if (0 != result.getCode()) {
log.info("修改任务状态和飞手信息业务接口:校验失败:{}", result.getMsg());
@@ -60,38 +56,18 @@ public class UpdateFlyerService {

Inspection inspection = (Inspection) result.getData();

//1 直播 2离线=非直播
Integer isLive = inspection.getIsLive();
Integer status = request.getStatus();
// 如果任务审核未通过,状态改为待审核
if (status == TaskStatusEnum.AUDITFAILED.getCode()) {
request.setStatus(1);
}

//开始飞行
if (status == TaskStatusEnum.INFLIGHT.getCode()) {
//直播填充盒子设备
if (1 == isLive) {
inspection.setCloudBoxId(request.getCloudBoxId());
inspection.setCloudBoxName(request.getCloudBoxName());
inspection.setBoxSn(request.getBoxSn());
}
inspection.setEquipmentId(request.getEquipmentId());
inspection.setEquipmentName(request.getEquipmentName());
inspection.setEquipmentMountId(request.getEquipmentMountId());
inspection.setEquipmentMountName(request.getEquipmentMountName());
inspection.setStatus(request.getStatus());
inspection.setFlightHand(request.getFlightHand());
inspection.setFlightHandName(request.getFlightHandName());
inspection.setExecutionStartTime(request.getFlightStartTime());
//更改
inspectionMapper.updateById(inspection);
}
//飞行完成
if (status == TaskStatusEnum.COMPLETE.getCode()) {
inspection.setStatus(request.getStatus());
inspection.setExecutionEndTime(request.getFlightEndTime());
inspectionMapper.updateById(inspection);
//开始飞行
this.updateInflight(request, inspection);
} else if (status == TaskStatusEnum.COMPLETE.getCode()) {
//飞行完成
this.updateComplete(request, inspection);
}

// 直播
@@ -109,9 +85,8 @@ public class UpdateFlyerService {
&& 4 != inspection.getAnalyseStatus()
&& 5 != inspection.getAnalyseStatus()
&& 6 != inspection.getAnalyseStatus()) {
onlineCompleteService.handle(request, inspection);
onlineCompleteService.handle(inspection);
}

return JsonResult.success();
}

@@ -138,4 +113,28 @@ public class UpdateFlyerService {
return JsonResult.success(inspection);
}

private void updateInflight(UpdateTaskByCodeRequest request, Inspection inspection) {
//直播填充盒子设备
if (1 == inspection.getIsLive()) {
inspection.setCloudBoxId(request.getCloudBoxId());
inspection.setCloudBoxName(request.getCloudBoxName());
inspection.setBoxSn(request.getBoxSn());
}
inspection.setEquipmentId(request.getEquipmentId());
inspection.setEquipmentName(request.getEquipmentName());
inspection.setEquipmentMountId(request.getEquipmentMountId());
inspection.setEquipmentMountName(request.getEquipmentMountName());
inspection.setStatus(request.getStatus());
inspection.setFlightHand(request.getFlightHand());
inspection.setFlightHandName(request.getFlightHandName());
inspection.setExecutionStartTime(request.getFlightStartTime());
//更改
inspectionMapper.updateById(inspection);
}

private void updateComplete(UpdateTaskByCodeRequest request, Inspection inspection) {
inspection.setStatus(request.getStatus());
inspection.setExecutionEndTime(request.getFlightEndTime());
inspectionMapper.updateById(inspection);
}
}

Loading…
Cancel
Save