|
|
@ -11,6 +11,7 @@ import org.apache.dubbo.config.annotation.DubboReference; |
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
|
import org.apache.http.client.methods.HttpGet; |
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
import org.apache.http.client.utils.URIBuilder; |
|
|
|
import org.apache.http.entity.StringEntity; |
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
@ -34,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import static org.apache.commons.compress.utils.ArchiveUtils.sanitize; |
|
|
@ -54,6 +56,64 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService |
|
|
|
@DubboReference |
|
|
|
private RemoteConfigService remoteConfigService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> extractType(Map<String, Object> objectMap) { |
|
|
|
EngineRecordEntity record = new EngineRecordEntity(); |
|
|
|
//获取token
|
|
|
|
//设置请求Header和Body(如JSON)
|
|
|
|
String md5 = Md5Utils.hash("xuzhou_ai"); |
|
|
|
JSONObject jsonObj = new JSONObject(); |
|
|
|
jsonObj.put("username", sanitize("xuzhou_ai")); // sanitize函数见下文
|
|
|
|
jsonObj.put("password", sanitize(md5)); |
|
|
|
//{"code":200,"message":"操作成功","data":{"token":"eyJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE3NDc5NjY2NzksImV4cCI6MTc1MDU1ODY3OSwidWlkIjoiT2tUV0NyWWxZSSIsInRoaXJkIjoxfQ.lkOSgcWES1ViKmeVht6b1AKuw6MbxPxsmGVeuahy4QZfWkv8y8Ac80bkvZMVBQD_-DmcwK3HXOslrWI5_uHDuBRO2phB6BGXzqkb4GKvLsZMGI-Wrc4tHyZ-ojQ67uhWVUgnjFK4OnMsf5U9LxAxe0XJZQWwrm8KAh9Zb0iD4gY"}}
|
|
|
|
String responseBody = PostRequest(jsonObj, "http://60.204.247.65:8100/Third/Login",""); |
|
|
|
JSONObject jsonObject = new JSONObject(responseBody); |
|
|
|
// 逐层获取 data -> token
|
|
|
|
JSONObject data = jsonObject.getJSONObject("data"); |
|
|
|
String token = data.getString("token"); |
|
|
|
String sceneResponseBody = null; |
|
|
|
String algorithmResponseBody = null; |
|
|
|
//查询用户开通的场景
|
|
|
|
if (StringUtils.isNotEmpty(token)){ |
|
|
|
try { |
|
|
|
URI uri = new URIBuilder("http://60.204.247.65:8100/V2/AI/WX/User/Scene") |
|
|
|
.build(); |
|
|
|
//{"code":200,"message":"操作成功","data":[{"scene":"可见光","id":2}]}
|
|
|
|
sceneResponseBody = GetRequest(uri, token); |
|
|
|
} catch (URISyntaxException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
JSONObject jsonObject1 = new JSONObject(sceneResponseBody); |
|
|
|
// 逐层获取 data -> token
|
|
|
|
JSONObject data1 = jsonObject.getJSONObject("data"); |
|
|
|
// String scene = data1.getString("scene");
|
|
|
|
// String scene = jsonObject1.getJSONArray("data").getJSONObject(0).getString("scene");
|
|
|
|
|
|
|
|
//查询场景算法
|
|
|
|
List<String> extra_type_list = new ArrayList<>(); |
|
|
|
try { |
|
|
|
URI uri = new URIBuilder("http://60.204.247.65:8100/V2/AI/WX/User/ExtraType/Get") |
|
|
|
.addParameter("scene","可见光") |
|
|
|
.addParameter("if_open","1") |
|
|
|
.build(); |
|
|
|
algorithmResponseBody = GetRequest(uri, token); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
//ExtraTypeResponse(code=200, message=操作成功, data=[ExtraType(id=2022, sence=可见光, type=秸秆焚烧(烟、火、焚后痕迹), extra_type=2010_12, model=01, user=xuzhou_ai, difficult=0, if_open=1, sence_id=2022, conf=0.7, aiConfig=0), ExtraType(id=2023, sence=可见光, type=烟火识别, extra_type=2010_13, model=01, user=xuzhou_ai, difficult=0, if_open=1, sence_id=2023, conf=0.7, aiConfig=0), ExtraType(id=2003, sence=可见光, type=是否佩戴安全绳, extra_type=2003_ext, model=01, user=xuzhou_ai, difficult=0, if_open=1, sence_id=2003, conf=0.7, aiConfig=0), ExtraType(id=2004, sence=可见光, type=是否佩戴安全帽, extra_type=2004_ext, model=01, user=xuzhou_ai, difficult=0, if_open=1, sence_id=2004, conf=0.7, aiConfig=1), ExtraType(id=2034, sence=可见光, type=路面车辆计数, extra_type=2010_24, model=01, user=xuzhou_ai, difficult=0, if_open=1, sence_id=2034, conf=0.7, aiConfig=0), ExtraType(id=2015, sence=可见光, type=多类型车辆计数, extra_type=2010_5, model=01, user=xuzhou_ai, difficult=0, if_open=1, sence_id=2015, conf=0.7, aiConfig=0), ExtraType(id=2016, sence=可见光, type=多类型车辆拥堵聚集, extra_type=2010_6, model=01, user=xuzhou_ai, difficult=0, if_open=1, sence_id=2016, conf=0.7, aiConfig=0)])
|
|
|
|
ExtraTypeResponse response = mapper.readValue(algorithmResponseBody,ExtraTypeResponse.class); |
|
|
|
System.out.println(response); |
|
|
|
List<ExtraType> list = response.getData(); |
|
|
|
for (ExtraType extraType : list) { |
|
|
|
extra_type_list.add(extraType.getExtra_type()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} catch (URISyntaxException | JsonProcessingException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> startEngine(Map<String, Object> objectMap){ |
|
|
|
EngineRecordEntity record = new EngineRecordEntity(); |
|
|
@ -138,12 +198,13 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService |
|
|
|
@Override |
|
|
|
public void closeEngine(Map<String, Object> objectMap) { |
|
|
|
JSONObject jsonObj2 = new JSONObject(); |
|
|
|
String taskId = (String)objectMap.get("taskId"); |
|
|
|
// String taskId = (String)objectMap.get("taskId");
|
|
|
|
String deviceSn = (String)objectMap.get("deviceSn"); |
|
|
|
LambdaQueryWrapper<EngineRecordEntity> engineRecordQW = new LambdaQueryWrapper<EngineRecordEntity>(); |
|
|
|
engineRecordQW.eq(EngineRecordEntity::getTaskId, taskId); |
|
|
|
// engineRecordQW.eq(EngineRecordEntity::getTaskId, taskId);
|
|
|
|
engineRecordQW.eq(EngineRecordEntity::getDeviceSn,deviceSn); |
|
|
|
engineRecordQW.orderByDesc(EngineRecordEntity::getCreateTime); |
|
|
|
engineRecordQW.last("limit 1"); |
|
|
|
EngineRecordEntity record = engineRecordMapper.selectOne(engineRecordQW); |
|
|
|
if (record == null){ |
|
|
|
// throw new RuntimeException("关闭引擎失败!");
|
|
|
|