瀏覽代碼

Merge branch 'develop' of gitadmin/tuoheng_freeway into release

tags/v1.0.0^2
wanjing 1 年之前
父節點
當前提交
117129cdd3
共有 7 個檔案被更改,包括 254 行新增127 行删除
  1. +1
    -48
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateFlightStatusService.java
  2. +2
    -33
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateWaittStatusService.java
  3. +17
    -46
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/DspServiceImpl.java
  4. +19
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/IDspService.java
  5. +65
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/SendPost.java
  6. +83
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StartAIService.java
  7. +67
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StopAIService.java

+ 1
- 48
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateFlightStatusService.java 查看文件

@@ -46,13 +46,10 @@ public class UpdateFlightStatusService {
@Autowired
private IDspService dspService;

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

public JsonResult updateFlightStatus(Inspection inspection, MissionStatusRequest missionStatusRequest) {
Inspection inspectionUpdate = new Inspection();
inspectionUpdate.setId(inspection.getId());
JsonResult result = startAI(missionStatusRequest);
JsonResult result = dspService.startAI(missionStatusRequest);
if (0 != result.getCode()) {
//如果调用DSP失败就直接失败!
log.info("修改任务状态业务接口:调用DSP数据失败:{}", result.getMsg());
@@ -85,50 +82,6 @@ public class UpdateFlightStatusService {
return JsonResult.success();
}

/**
* 调用DSP接口
*
* @param missionStatusRequest
* @return
*/
private JsonResult startAI(MissionStatusRequest missionStatusRequest) {
log.info("进入调用DSP接口方法");
JSONObject request = new JSONObject();
JSONArray configList = new JSONArray();
JSONObject instConfigMode = new JSONObject();
instConfigMode.put("ename", "service_mode");
instConfigMode.put("evalue", "1");
configList.add(instConfigMode);
JSONObject instConfigUrl = new JSONObject();
instConfigUrl.put("ename", "callback_url");
instConfigUrl.put("evalue", dspCallbackUrl);
configList.add(instConfigUrl);
request.put("serviceInstConfigList", configList);

JSONArray reqList = new JSONArray();

JSONObject instReqUrlPush = new JSONObject();
instReqUrlPush.put("ename", "push_url");
instReqUrlPush.put("evalue", missionStatusRequest.getPushUrl());
reqList.add(instReqUrlPush);

JSONObject instReqUrlPull = new JSONObject();
instReqUrlPull.put("ename", "pull_url");
instReqUrlPull.put("evalue", missionStatusRequest.getPullUrl());
reqList.add(instReqUrlPull);

request.put("serviceInstReqList", reqList);
JSONObject responseJson = dspService.serviceInstApplication(request);
if (responseJson.getIntValue("code") == 0) {
String requestId = responseJson.getJSONObject("data").getString("requestId");
log.info("dsp实时调用响应requestId:{}", requestId);
} else {
log.error("dsp实时调用失败:{}", responseJson);
return JsonResult.error(EditInspectionStatusCodeEnum.TASK_ANALYSIS_FAILED.getCode(), EditInspectionStatusCodeEnum.TASK_ANALYSIS_FAILED.getMsg());
}
return JsonResult.success(responseJson);
}

/**
* 处理通道数据
*

+ 2
- 33
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateWaittStatusService.java 查看文件

@@ -66,8 +66,8 @@ public class UpdateWaittStatusService {
return;
}

//硬件停止后,停止AI分析
stopAI(businessList.get(0).getMsgId(), inspection.getId());
// 硬件停止后,停止AI分析
dspService.stopAI(businessList.get(0).getMsgId(), inspection.getId());

//获取天气信息
//查询业务对应的租户信息
@@ -104,37 +104,6 @@ public class UpdateWaittStatusService {
inspectionMapper.updateById(inspectionUpdate);
}

private JsonResult stopAI(String msgId, String inspectionId) {
//任务调用完成之后,调用发送通道,请求DSP关闭请求
//调用DSP接口
JSONObject jsonObject = new JSONObject();
jsonObject.put("requestId", msgId);
JSONObject responseJson = new JSONObject();
Inspection inspectionUpdate = new Inspection();
inspectionUpdate.setId(inspectionId);
try {
responseJson = dspService.serviceStopApplication(jsonObject);
if (responseJson.getIntValue("code") == 0) {
if (responseJson.containsKey("data") && ObjectUtil.isNotEmpty(responseJson.get("data"))) {
String requestId = responseJson.getJSONObject("data").getString("requestId");
log.info("dsp实时调用响应requestId:{}", requestId);
} else {
log.info("dsp实时调用响应:{}", responseJson);
}
return JsonResult.success();
} else {
log.error("dsp实时调用失败:{}", responseJson);
inspectionUpdate.setAnalyseStatus(AiAnalyseStatusEnum.FAILED.getCode());
}
inspectionMapper.updateById(inspectionUpdate);
} catch (Exception e) {
log.error("dsp实时调用失败:{}", responseJson);
inspectionUpdate.setAnalyseStatus(AiAnalyseStatusEnum.FAILED.getCode());
inspectionMapper.updateById(inspectionUpdate);
}
return JsonResult.success();
}

public JsonResult getWeather(String airportUrl, Integer airportId) {
String url = airportUrl + SystemConstant.API_AIRPORT_GET_WEATHER;
String param = "airportId=" + airportId;

+ 17
- 46
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/DspServiceImpl.java 查看文件

@@ -1,8 +1,11 @@
package com.tuoheng.admin.service.third.dsp;

import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.request.inspection.MissionStatusRequest;
import com.tuoheng.common.core.utils.HttpUtils;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@@ -19,6 +22,12 @@ import java.util.Map;
@Service
public class DspServiceImpl implements IDspService {

@Autowired
private StartAIService startAIService;

@Autowired
private StopAIService stopAIService;

/**
* DSP服务API接口域名
*/
@@ -33,7 +42,7 @@ public class DspServiceImpl implements IDspService {
String url = String.format(Locale.ENGLISH, "%s/api/web/serviceInst/%s/application", dspDomainUrl, dspServiceInstId);
log.info("调用DSP服务, url:{}", url);
log.info("调用DSP服务, jsonObject:{}", jsonObject);
String result = doPost(url, jsonObject, null);
String result = SendPost.doPost(url, jsonObject, null);
log.info("调用DSP服务, result:{}", result);
return JSONObject.parseObject(result);
}
@@ -45,51 +54,13 @@ public class DspServiceImpl implements IDspService {
return JSONObject.parseObject(result);
}

/**
* 处理post请求
* @param urlStr 请求url
* @param data 请求体数据
* @param properties 请求头参数
* @return
*/
public static String doPost(String urlStr, JSONObject data, Map<String, String> properties){
try {
log.info("请求url={}", urlStr);
log.info("请求体数据data={}", data.toJSONString());
log.info("请求头参数properties={}", properties);
URL url = new URL(urlStr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();

connection.setDoInput(true); // 设置可输入
connection.setDoOutput(true); // 设置该连接是可以输出的
//设置连接超时时间和读取超时时间
connection.setConnectTimeout(15000);
connection.setReadTimeout(60000);
//设置请求方式
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
if(null != properties && !properties.isEmpty()){
for (String key:properties.keySet()){
connection.setRequestProperty(key, properties.get(key));
}
}

PrintWriter pw = new PrintWriter(new BufferedOutputStream(connection.getOutputStream()));
pw.write(data.toJSONString());
pw.flush();
pw.close();
@Override
public JsonResult startAI(MissionStatusRequest missionStatusRequest) {
return startAIService.startAI(missionStatusRequest)
}

BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
String line = null;
StringBuilder result = new StringBuilder();
while ((line = br.readLine()) != null) { // 读取数据
result.append(line + "\n");
}
connection.disconnect();
return result.toString();
} catch (Exception e) {
log.error("post请求失败");
return "post请求失败!";
}
@Override
public JsonResult stopAI(String msgId, String inspectionId) {
return stopAIService.stopAI(msgId, inspectionId);
}
}

+ 19
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/IDspService.java 查看文件

@@ -1,9 +1,28 @@
package com.tuoheng.admin.service.third.dsp;

import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.request.inspection.MissionStatusRequest;
import com.tuoheng.common.core.utils.JsonResult;

public interface IDspService {
JSONObject serviceInstApplication(JSONObject jsonObject);

JSONObject serviceStopApplication(JSONObject jsonObject);

/**
*
* 调用DSP进行AI分析
*
* @param missionStatusRequest
* @return
*/
JsonResult startAI(MissionStatusRequest missionStatusRequest);

/**
* 硬件停止后,停止AI分析
* @param msgId
* @param inspectionId
* @return
*/
JsonResult stopAI(String msgId, String inspectionId);
}

+ 65
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/SendPost.java 查看文件

@@ -0,0 +1,65 @@
package com.tuoheng.admin.service.third.dsp;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;

@Slf4j
public class SendPost {

/**
* 处理post请求
* @param urlStr 请求url
* @param data 请求体数据
* @param properties 请求头参数
* @return
*/
public static String doPost(String urlStr, JSONObject data, Map<String, String> properties){
try {
log.info("请求url={}", urlStr);
log.info("请求体数据data={}", data.toJSONString());
log.info("请求头参数properties={}", properties);
URL url = new URL(urlStr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();

connection.setDoInput(true); // 设置可输入
connection.setDoOutput(true); // 设置该连接是可以输出的
//设置连接超时时间和读取超时时间
connection.setConnectTimeout(15000);
connection.setReadTimeout(60000);
//设置请求方式
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
if(null != properties && !properties.isEmpty()){
for (String key:properties.keySet()){
connection.setRequestProperty(key, properties.get(key));
}
}

PrintWriter pw = new PrintWriter(new BufferedOutputStream(connection.getOutputStream()));
pw.write(data.toJSONString());
pw.flush();
pw.close();

BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
String line = null;
StringBuilder result = new StringBuilder();
while ((line = br.readLine()) != null) { // 读取数据
result.append(line + "\n");
}
connection.disconnect();
return result.toString();
} catch (Exception e) {
log.error("post请求失败");
return "post请求失败!";
}
}

}

+ 83
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StartAIService.java 查看文件

@@ -0,0 +1,83 @@
package com.tuoheng.admin.service.third.dsp;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.enums.code.inspection.EditInspectionStatusCodeEnum;
import com.tuoheng.admin.request.inspection.MissionStatusRequest;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Locale;

@Slf4j
@Service
public class StartAIService {

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

@Value("${tuoheng.dsp-service-inst-id:}")
private String dspServiceInstId;

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

/**
* 调用DSP接口
*
* @param missionStatusRequest
* @return
*/
public JsonResult startAI(MissionStatusRequest missionStatusRequest) {
log.info("进入调用DSP接口方法");
JSONObject request = new JSONObject();
JSONArray configList = new JSONArray();
JSONObject instConfigMode = new JSONObject();
instConfigMode.put("ename", "service_mode");
instConfigMode.put("evalue", "1");
configList.add(instConfigMode);
JSONObject instConfigUrl = new JSONObject();
instConfigUrl.put("ename", "callback_url");
instConfigUrl.put("evalue", dspCallbackUrl);
configList.add(instConfigUrl);
request.put("serviceInstConfigList", configList);

JSONArray reqList = new JSONArray();

JSONObject instReqUrlPush = new JSONObject();
instReqUrlPush.put("ename", "push_url");
instReqUrlPush.put("evalue", missionStatusRequest.getPushUrl());
reqList.add(instReqUrlPush);

JSONObject instReqUrlPull = new JSONObject();
instReqUrlPull.put("ename", "pull_url");
instReqUrlPull.put("evalue", missionStatusRequest.getPullUrl());
reqList.add(instReqUrlPull);

request.put("serviceInstReqList", reqList);
JSONObject responseJson = this.serviceInstApplication(request);
if (responseJson.getIntValue("code") == 0) {
String requestId = responseJson.getJSONObject("data").getString("requestId");
log.info("dsp实时调用响应requestId:{}", requestId);
} else {
log.error("dsp实时调用失败:{}", responseJson);
return JsonResult.error(EditInspectionStatusCodeEnum.TASK_ANALYSIS_FAILED.getCode(), EditInspectionStatusCodeEnum.TASK_ANALYSIS_FAILED.getMsg());
}
return JsonResult.success(responseJson);
}

private JSONObject serviceInstApplication(JSONObject jsonObject) {
String url = String.format(Locale.ENGLISH, "%s/api/web/serviceInst/%s/application", dspDomainUrl, dspServiceInstId);
log.info("调用DSP服务, url:{}", url);
log.info("调用DSP服务, jsonObject:{}", jsonObject);
String result = SendPost.doPost(url, jsonObject, null);
log.info("调用DSP服务, result:{}", result);
return JSONObject.parseObject(result);
}

}

+ 67
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StopAIService.java 查看文件

@@ -0,0 +1,67 @@
package com.tuoheng.admin.service.third.dsp;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.entity.Inspection;
import com.tuoheng.admin.enums.AiAnalyseStatusEnum;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.common.core.utils.HttpUtils;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class StopAIService {

@Autowired
private InspectionMapper inspectionMapper;

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

@Value("${tuoheng.dsp-service-inst-id:}")
private String dspServiceInstId;

public JsonResult stopAI(String msgId, String inspectionId) {
//任务调用完成之后,调用发送通道,请求DSP关闭请求
//调用DSP接口
JSONObject jsonObject = new JSONObject();
jsonObject.put("requestId", msgId);
JSONObject responseJson = new JSONObject();
Inspection inspectionUpdate = new Inspection();
inspectionUpdate.setId(inspectionId);
try {
responseJson = this.serviceStopApplication(jsonObject);
if (responseJson.getIntValue("code") == 0) {
if (responseJson.containsKey("data") && ObjectUtil.isNotEmpty(responseJson.get("data"))) {
String requestId = responseJson.getJSONObject("data").getString("requestId");
log.info("dsp实时调用响应requestId:{}", requestId);
} else {
log.info("dsp实时调用响应:{}", responseJson);
}
return JsonResult.success();
} else {
log.error("dsp实时调用失败:{}", responseJson);
inspectionUpdate.setAnalyseStatus(AiAnalyseStatusEnum.FAILED.getCode());
}
inspectionMapper.updateById(inspectionUpdate);
} catch (Exception e) {
log.error("dsp实时调用失败:{}", responseJson);
inspectionUpdate.setAnalyseStatus(AiAnalyseStatusEnum.FAILED.getCode());
inspectionMapper.updateById(inspectionUpdate);
}
return JsonResult.success();
}

private JSONObject serviceStopApplication(JSONObject jsonObject) {
String url = dspDomainUrl + "api/web/serviceInst/" + jsonObject.getString("requestId") + "/stop";
String result = HttpUtils.doSend(url, jsonObject, null, "PUT");
return JSONObject.parseObject(result);
}
}

Loading…
取消
儲存