Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -3,6 +3,7 @@ package com.solution.web.controller.behaviour;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.solution.system.domain.PlatFormDTO;
|
||||
import com.solution.web.core.BehaviortreeProcessor;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -153,13 +154,12 @@ public class BehaviortreeController extends BaseController
|
||||
|
||||
/**
|
||||
* 修改平台关联的行为树id
|
||||
* @param behaviortreeId
|
||||
* @param platFormDTO
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("修改平台关联的行为树id")
|
||||
@PutMapping("/{behaviortreeId}")
|
||||
public AjaxResult updateBehaviortreeId(@PathVariable Integer behaviortreeId,
|
||||
@RequestParam(required = false) Integer id){
|
||||
return toAjax(behaviortreeService.updateBehaviortreeId(behaviortreeId,id));
|
||||
@PutMapping("/behaviortreeId")
|
||||
public AjaxResult updateBehaviortreeId(@RequestBody PlatFormDTO platFormDTO){
|
||||
return toAjax(behaviortreeService.updateBehaviortreeId(platFormDTO));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.solution.system.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlatFormDTO {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Integer behaviortreeId;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.solution.system.mapper;
|
||||
|
||||
import com.solution.system.domain.PlatFormDTO;
|
||||
import com.solution.system.domain.PlatformTree;
|
||||
import com.solution.system.domain.PlatformVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -35,8 +36,8 @@ public interface PlatformMapper {
|
||||
|
||||
/**
|
||||
* 修改平台关联的行为树id
|
||||
* @param behaviortreeId
|
||||
* @param platFormDTO
|
||||
* @return
|
||||
*/
|
||||
Integer updateBehaviortreeId(@Param("behaviortreeId") Integer behaviortreeId,@Param("id") Integer id);
|
||||
Integer updateBehaviortreeId(PlatFormDTO platFormDTO);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.solution.system.service;
|
||||
import java.util.List;
|
||||
|
||||
import com.solution.system.domain.Behaviortree;
|
||||
import com.solution.system.domain.PlatFormDTO;
|
||||
import com.solution.system.domain.PlatformChiefCommander;
|
||||
import com.solution.system.domain.PlatformVO;
|
||||
|
||||
@@ -87,8 +88,8 @@ public interface IBehaviortreeService
|
||||
|
||||
/**
|
||||
* 修改平台关联的行为树id
|
||||
* @param behaviortreeId
|
||||
* @param platFormDTO
|
||||
* @return
|
||||
*/
|
||||
Integer updateBehaviortreeId(Integer behaviortreeId,Integer id);
|
||||
Integer updateBehaviortreeId(PlatFormDTO platFormDTO);
|
||||
}
|
||||
|
||||
@@ -5,15 +5,12 @@ import java.util.List;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.solution.common.constant.ExceptionConstants;
|
||||
import com.solution.system.domain.PlatformChiefCommander;
|
||||
import com.solution.system.domain.PlatformTree;
|
||||
import com.solution.system.domain.PlatformVO;
|
||||
import com.solution.system.domain.*;
|
||||
import com.solution.system.mapper.PlatformCommunicationMapper;
|
||||
import com.solution.system.mapper.PlatformMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.solution.system.mapper.BehaviortreeMapper;
|
||||
import com.solution.system.domain.Behaviortree;
|
||||
import com.solution.system.service.IBehaviortreeService;
|
||||
|
||||
/**
|
||||
@@ -159,14 +156,14 @@ public class BehaviortreeServiceImpl implements IBehaviortreeService
|
||||
|
||||
/**
|
||||
* 修改平台关联的行为树id
|
||||
* @param behaviortreeId
|
||||
* @param platFormDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Integer updateBehaviortreeId(Integer behaviortreeId,Integer id) {
|
||||
if(ObjectUtil.isEmpty(behaviortreeId) || ObjectUtil.isEmpty(id)){
|
||||
public Integer updateBehaviortreeId(PlatFormDTO platFormDTO) {
|
||||
if(ObjectUtil.isEmpty(platFormDTO)){
|
||||
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||
}
|
||||
return platformMapper.updateBehaviortreeId(behaviortreeId,id);
|
||||
return platformMapper.updateBehaviortreeId(platFormDTO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.solution.rule.controller;
|
||||
|
||||
import com.solution.rule.domain.tasks.Kj3PostResult;
|
||||
import com.solution.rule.service.Kj3TaskDataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/rule/kj3")
|
||||
public class Kj3TaskDataController {
|
||||
|
||||
@Autowired
|
||||
private Kj3TaskDataService kj3TaskDataService;
|
||||
|
||||
/**
|
||||
* 接收外部传入的 kj-3 JSON,筛选红方任务并转换后 POST 到目标地址。
|
||||
*
|
||||
* @param kj3Json 外部请求体 JSON
|
||||
* @return 处理结果
|
||||
*/
|
||||
@PostMapping("/parse-and-post")
|
||||
public Kj3PostResult parseAndPost(@RequestBody String kj3Json) {
|
||||
return kj3TaskDataService.parseAndPostRedTasks(kj3Json);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class AssignTargetItem {
|
||||
|
||||
private String task;
|
||||
|
||||
private String type;
|
||||
|
||||
private List<String> target = new ArrayList<>();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DataOutput {
|
||||
|
||||
@JsonProperty("assign_target")
|
||||
private List<AssignTargetItem> assignTarget = new ArrayList<>();
|
||||
|
||||
private List<TaskItem> task = new ArrayList<>();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3ExecuteBlock {
|
||||
|
||||
private List<Kj3TargetItem> targetList;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3ForceSide {
|
||||
|
||||
@JsonProperty("ObjectHandle")
|
||||
private String objectHandle;
|
||||
|
||||
@JsonProperty("ForceSideName")
|
||||
private String forceSideName;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3MilitaryItem {
|
||||
|
||||
@JsonProperty("Name")
|
||||
private String name;
|
||||
|
||||
@JsonProperty("OwnerForceSide")
|
||||
private String ownerForceSide;
|
||||
|
||||
@JsonProperty("EquipmentID")
|
||||
private String equipmentId;
|
||||
|
||||
@JsonProperty("Platform_type")
|
||||
private String platformType;
|
||||
|
||||
@JsonProperty("SubComponents")
|
||||
private Kj3SubComponents subComponents;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3MilitaryPlatformComponent {
|
||||
|
||||
@JsonProperty("TrackParamId")
|
||||
private String trackParamId;
|
||||
|
||||
private List<Double> positions;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3MilitaryScenario {
|
||||
|
||||
@JsonProperty("Tasks")
|
||||
private List<Kj3TaskNode> tasks;
|
||||
|
||||
@JsonProperty("ForceSides")
|
||||
private List<Kj3ForceSide> forceSides;
|
||||
|
||||
@JsonProperty("Military")
|
||||
private List<Kj3MilitaryItem> military;
|
||||
|
||||
@JsonProperty("RefAttributeObject")
|
||||
private Kj3RefAttributeObject refAttributeObject;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Kj3PostResult {
|
||||
|
||||
private boolean success;
|
||||
|
||||
private String statusMessage;
|
||||
|
||||
private String postUrl;
|
||||
|
||||
private int taskCount;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3RefAttributeObject {
|
||||
|
||||
@JsonProperty("TrackParam")
|
||||
private Map<String, Kj3TrackParam> trackParam;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3Root {
|
||||
|
||||
@JsonProperty("MilitaryScenario")
|
||||
private Kj3MilitaryScenario militaryScenario;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3SubComponents {
|
||||
|
||||
private List<Kj3MilitaryPlatformComponent> platform;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3TargetItem {
|
||||
|
||||
private String targetId;
|
||||
|
||||
@JsonProperty("cruiseRouteId")
|
||||
private String cruiseRouteId;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3TaskNode {
|
||||
|
||||
private String name;
|
||||
|
||||
private String side;
|
||||
|
||||
private Kj3TaskPayload task;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3TaskPayload {
|
||||
|
||||
private String name;
|
||||
|
||||
private String side;
|
||||
|
||||
private String type;
|
||||
|
||||
@JsonProperty("at_time")
|
||||
private String atTime;
|
||||
|
||||
private List<Kj3ExecuteBlock> execute;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3TrackParam {
|
||||
|
||||
@JsonProperty("TrackPoints")
|
||||
private List<Kj3TrackPoint> trackPoints;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Kj3TrackPoint {
|
||||
|
||||
private String longitude;
|
||||
|
||||
private String latitude;
|
||||
|
||||
private String height;
|
||||
|
||||
private String speed;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PlatformItem {
|
||||
|
||||
private String name;
|
||||
|
||||
@JsonProperty("platform_type")
|
||||
private String platformType;
|
||||
|
||||
private String longitude;
|
||||
|
||||
private String latitude;
|
||||
|
||||
private Integer altitude;
|
||||
|
||||
private List<RoutePoint> route = new ArrayList<>();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RoutePoint {
|
||||
|
||||
private String longitude;
|
||||
|
||||
private String latitude;
|
||||
|
||||
private Integer altitude;
|
||||
|
||||
private Integer speed;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TaskItem {
|
||||
|
||||
@JsonProperty("task_name")
|
||||
private String taskName;
|
||||
|
||||
private List<PlatformItem> platform = new ArrayList<>();
|
||||
|
||||
private TaskTime time;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.solution.rule.domain.tasks;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TaskTime {
|
||||
|
||||
private Integer begin;
|
||||
|
||||
private Integer end;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.solution.rule.service;
|
||||
|
||||
import com.solution.rule.domain.tasks.Kj3PostResult;
|
||||
import com.solution.rule.domain.tasks.Kj3Root;
|
||||
|
||||
public interface Kj3TaskDataService {
|
||||
|
||||
/**
|
||||
* 解析接口入参 JSON,仅提取红方任务,转换为 data 结构后发送 HTTP POST。
|
||||
*
|
||||
* @param kj3Json 传入的 kj-3 JSON 字符串
|
||||
* @return 发送结果
|
||||
*/
|
||||
Kj3PostResult parseAndPostRedTasks(String kj3Json);
|
||||
|
||||
/**
|
||||
* 解析接口入参对象,仅提取红方任务,转换为 data 结构后发送 HTTP POST。
|
||||
*
|
||||
* @param root 传入的 kj-3 对象
|
||||
* @return 发送结果
|
||||
*/
|
||||
Kj3PostResult parseAndPostRedTasks(Kj3Root root);
|
||||
}
|
||||
@@ -0,0 +1,418 @@
|
||||
package com.solution.rule.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.solution.rule.domain.tasks.AssignTargetItem;
|
||||
import com.solution.rule.domain.tasks.DataOutput;
|
||||
import com.solution.rule.domain.tasks.Kj3ExecuteBlock;
|
||||
import com.solution.rule.domain.tasks.Kj3ForceSide;
|
||||
import com.solution.rule.domain.tasks.Kj3MilitaryItem;
|
||||
import com.solution.rule.domain.tasks.Kj3MilitaryPlatformComponent;
|
||||
import com.solution.rule.domain.tasks.Kj3MilitaryScenario;
|
||||
import com.solution.rule.domain.tasks.Kj3PostResult;
|
||||
import com.solution.rule.domain.tasks.Kj3RefAttributeObject;
|
||||
import com.solution.rule.domain.tasks.Kj3Root;
|
||||
import com.solution.rule.domain.tasks.Kj3TaskNode;
|
||||
import com.solution.rule.domain.tasks.Kj3TaskPayload;
|
||||
import com.solution.rule.domain.tasks.Kj3TrackParam;
|
||||
import com.solution.rule.domain.tasks.Kj3TrackPoint;
|
||||
import com.solution.rule.domain.tasks.Kj3TargetItem;
|
||||
import com.solution.rule.domain.tasks.PlatformItem;
|
||||
import com.solution.rule.domain.tasks.RoutePoint;
|
||||
import com.solution.rule.domain.tasks.TaskItem;
|
||||
import com.solution.rule.domain.tasks.TaskTime;
|
||||
import com.solution.rule.service.Kj3TaskDataService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class Kj3TaskDataServiceImpl implements Kj3TaskDataService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Kj3TaskDataServiceImpl.class);
|
||||
|
||||
private static final String DATA_POST_URL = "http://localhost:5000/bhtree/zhitangCompanyData";
|
||||
private static final String URL_PLACEHOLDER = "http://TODO-REPLACE";
|
||||
|
||||
private static final String RED_SIDE = "红方";
|
||||
|
||||
private static final String DEFAULT_ASSIGN_TYPE = "fire";
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public Kj3PostResult parseAndPostRedTasks(String kj3Json) {
|
||||
if (ObjectUtil.isEmpty(kj3Json)) {
|
||||
throw new IllegalArgumentException("kj3Json 不能为空");
|
||||
}
|
||||
Kj3Root root = parseKj3Json(kj3Json);
|
||||
return parseAndPostRedTasks(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kj3PostResult parseAndPostRedTasks(Kj3Root root) {
|
||||
if (ObjectUtil.isEmpty(root)) {
|
||||
throw new IllegalArgumentException("kj3 入参对象不能为空");
|
||||
}
|
||||
DataOutput output = transformToDataOutput(root);
|
||||
String payload = writeJson(output);
|
||||
log.info("kj3 转换后的 data 输出: {}", payload);
|
||||
Kj3PostResult result = new Kj3PostResult();
|
||||
result.setPostUrl(DATA_POST_URL);
|
||||
result.setTaskCount(output.getTask().size());
|
||||
if (!isPostUrlConfigured()) {
|
||||
result.setSuccess(false);
|
||||
result.setStatusMessage("POST URL 未配置,请将 DATA_POST_URL 从占位值替换为真实地址");
|
||||
return result;
|
||||
}
|
||||
try {
|
||||
String response = postJson(payload);
|
||||
result.setSuccess(true);
|
||||
result.setStatusMessage(response);
|
||||
} catch (RuntimeException ex) {
|
||||
result.setSuccess(false);
|
||||
result.setStatusMessage(ex.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isPostUrlConfigured() {
|
||||
return ObjectUtil.isNotEmpty(DATA_POST_URL) && !URL_PLACEHOLDER.equalsIgnoreCase(DATA_POST_URL);
|
||||
}
|
||||
|
||||
private Kj3Root parseKj3Json(String kj3Json) {
|
||||
try {
|
||||
return objectMapper.readValue(kj3Json, Kj3Root.class);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("解析接口入参 kj-3 JSON 失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private DataOutput transformToDataOutput(Kj3Root root) {
|
||||
DataOutput output = new DataOutput();
|
||||
Kj3MilitaryScenario scenario = root == null ? null : root.getMilitaryScenario();
|
||||
List<Kj3TaskNode> tasks = scenario == null ? Collections.emptyList() : scenario.getTasks();
|
||||
if (CollUtil.isEmpty(tasks)) {
|
||||
return output;
|
||||
}
|
||||
String redForceSideId = getRedForceSideId(scenario);
|
||||
|
||||
List<Kj3TaskNode> redTasks = tasks.stream()
|
||||
.filter(this::isRedTask)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (Kj3TaskNode redTask : redTasks) {
|
||||
String taskName = resolveTaskName(redTask);
|
||||
Kj3TaskPayload payload = redTask.getTask();
|
||||
|
||||
TaskItem taskItem = new TaskItem();
|
||||
taskItem.setTaskName(taskName);
|
||||
taskItem.setTime(buildTaskTime(payload));
|
||||
taskItem.setPlatform(buildPlatformsForTask(scenario, redForceSideId, payload));
|
||||
output.getTask().add(taskItem);
|
||||
|
||||
AssignTargetItem assignTargetItem = new AssignTargetItem();
|
||||
assignTargetItem.setTask(taskName);
|
||||
assignTargetItem.setType(resolveTaskType(payload));
|
||||
assignTargetItem.setTarget(extractTargets(payload));
|
||||
output.getAssignTarget().add(assignTargetItem);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
private boolean isRedTask(Kj3TaskNode taskNode) {
|
||||
if (taskNode == null) {
|
||||
return false;
|
||||
}
|
||||
if (RED_SIDE.equals(taskNode.getSide())) {
|
||||
return true;
|
||||
}
|
||||
Kj3TaskPayload payload = taskNode.getTask();
|
||||
return payload != null && RED_SIDE.equals(payload.getSide());
|
||||
}
|
||||
|
||||
private String resolveTaskName(Kj3TaskNode taskNode) {
|
||||
Kj3TaskPayload payload = taskNode.getTask();
|
||||
if (payload != null && ObjectUtil.isNotEmpty(payload.getName())) {
|
||||
return payload.getName();
|
||||
}
|
||||
return taskNode.getName();
|
||||
}
|
||||
|
||||
private String resolveTaskType(Kj3TaskPayload payload) {
|
||||
if (payload != null && ObjectUtil.isNotEmpty(payload.getType())) {
|
||||
return payload.getType();
|
||||
}
|
||||
return DEFAULT_ASSIGN_TYPE;
|
||||
}
|
||||
|
||||
private String getRedForceSideId(Kj3MilitaryScenario scenario) {
|
||||
if (scenario == null || CollUtil.isEmpty(scenario.getForceSides())) {
|
||||
return "";
|
||||
}
|
||||
for (Kj3ForceSide forceSide : scenario.getForceSides()) {
|
||||
if (forceSide != null && RED_SIDE.equals(forceSide.getForceSideName())) {
|
||||
return forceSide.getObjectHandle();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private List<PlatformItem> buildRedPlatforms(Kj3MilitaryScenario scenario, String redForceSideId) {
|
||||
if (scenario == null || CollUtil.isEmpty(scenario.getMilitary()) || ObjectUtil.isEmpty(redForceSideId)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Map<String, Kj3TrackParam> trackParamMap = getTrackParamMap(scenario);
|
||||
List<PlatformItem> platforms = new ArrayList<>();
|
||||
for (Kj3MilitaryItem militaryItem : scenario.getMilitary()) {
|
||||
if (militaryItem == null || !redForceSideId.equals(militaryItem.getOwnerForceSide())) {
|
||||
continue;
|
||||
}
|
||||
PlatformItem platformItem = mapMilitaryToPlatform(militaryItem, trackParamMap);
|
||||
platforms.add(platformItem);
|
||||
}
|
||||
return platforms;
|
||||
}
|
||||
|
||||
private List<PlatformItem> buildPlatformsForTask(Kj3MilitaryScenario scenario, String redForceSideId, Kj3TaskPayload payload) {
|
||||
List<PlatformItem> redPlatforms = buildRedPlatforms(scenario, redForceSideId);
|
||||
if (CollUtil.isEmpty(redPlatforms)) {
|
||||
return redPlatforms;
|
||||
}
|
||||
Map<String, Kj3TrackParam> trackParamMap = getTrackParamMap(scenario);
|
||||
String fallbackRouteId = resolveFallbackRouteId(payload);
|
||||
if (ObjectUtil.isEmpty(fallbackRouteId)) {
|
||||
return redPlatforms;
|
||||
}
|
||||
for (PlatformItem platform : redPlatforms) {
|
||||
if (CollUtil.isNotEmpty(platform.getRoute())) {
|
||||
continue;
|
||||
}
|
||||
platform.setRoute(buildRoute(fallbackRouteId, trackParamMap));
|
||||
}
|
||||
return redPlatforms;
|
||||
}
|
||||
|
||||
private Map<String, Kj3TrackParam> getTrackParamMap(Kj3MilitaryScenario scenario) {
|
||||
Kj3RefAttributeObject refAttributeObject = scenario.getRefAttributeObject();
|
||||
if (refAttributeObject == null || refAttributeObject.getTrackParam() == null) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return refAttributeObject.getTrackParam();
|
||||
}
|
||||
|
||||
private PlatformItem mapMilitaryToPlatform(Kj3MilitaryItem militaryItem, Map<String, Kj3TrackParam> trackParamMap) {
|
||||
PlatformItem platformItem = new PlatformItem();
|
||||
platformItem.setName(militaryItem.getName());
|
||||
platformItem.setPlatformType(militaryItem.getPlatformType());
|
||||
|
||||
Kj3MilitaryPlatformComponent positionSourceComponent = resolvePositionSourceComponent(militaryItem);
|
||||
fillPosition(platformItem, positionSourceComponent);
|
||||
String trackParamId = resolveTrackParamId(militaryItem);
|
||||
platformItem.setRoute(buildRoute(trackParamId, trackParamMap));
|
||||
return platformItem;
|
||||
}
|
||||
|
||||
private String resolveFallbackRouteId(Kj3TaskPayload payload) {
|
||||
if (payload == null || CollUtil.isEmpty(payload.getExecute())) {
|
||||
return "";
|
||||
}
|
||||
for (Kj3ExecuteBlock executeBlock : payload.getExecute()) {
|
||||
if (executeBlock == null || CollUtil.isEmpty(executeBlock.getTargetList())) {
|
||||
continue;
|
||||
}
|
||||
for (Kj3TargetItem targetItem : executeBlock.getTargetList()) {
|
||||
if (targetItem != null && ObjectUtil.isNotEmpty(targetItem.getCruiseRouteId())) {
|
||||
return targetItem.getCruiseRouteId();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private Kj3MilitaryPlatformComponent resolvePositionSourceComponent(Kj3MilitaryItem militaryItem) {
|
||||
if (militaryItem.getSubComponents() == null || CollUtil.isEmpty(militaryItem.getSubComponents().getPlatform())) {
|
||||
return null;
|
||||
}
|
||||
for (Kj3MilitaryPlatformComponent component : militaryItem.getSubComponents().getPlatform()) {
|
||||
if (component != null && CollUtil.isNotEmpty(component.getPositions())) {
|
||||
return component;
|
||||
}
|
||||
}
|
||||
return militaryItem.getSubComponents().getPlatform().get(0);
|
||||
}
|
||||
|
||||
private String resolveTrackParamId(Kj3MilitaryItem militaryItem) {
|
||||
if (militaryItem.getSubComponents() == null || CollUtil.isEmpty(militaryItem.getSubComponents().getPlatform())) {
|
||||
return "";
|
||||
}
|
||||
for (Kj3MilitaryPlatformComponent component : militaryItem.getSubComponents().getPlatform()) {
|
||||
if (component != null && ObjectUtil.isNotEmpty(component.getTrackParamId())) {
|
||||
return component.getTrackParamId();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private void fillPosition(PlatformItem platformItem, Kj3MilitaryPlatformComponent component) {
|
||||
if (component == null || CollUtil.isEmpty(component.getPositions())) {
|
||||
return;
|
||||
}
|
||||
List<Double> positions = component.getPositions();
|
||||
if (positions.size() > 0 && positions.get(0) != null) {
|
||||
platformItem.setLongitude(String.valueOf(positions.get(0)));
|
||||
}
|
||||
if (positions.size() > 1 && positions.get(1) != null) {
|
||||
platformItem.setLatitude(String.valueOf(positions.get(1)));
|
||||
}
|
||||
if (positions.size() > 2 && positions.get(2) != null) {
|
||||
platformItem.setAltitude((int) Math.round(positions.get(2)));
|
||||
}
|
||||
}
|
||||
|
||||
private List<RoutePoint> buildRoute(String trackParamId, Map<String, Kj3TrackParam> trackParamMap) {
|
||||
if (ObjectUtil.isEmpty(trackParamId)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Kj3TrackParam trackParam = trackParamMap.get(trackParamId);
|
||||
if (trackParam == null || CollUtil.isEmpty(trackParam.getTrackPoints())) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<RoutePoint> routes = new ArrayList<>();
|
||||
for (Kj3TrackPoint trackPoint : trackParam.getTrackPoints()) {
|
||||
if (trackPoint == null) {
|
||||
continue;
|
||||
}
|
||||
RoutePoint routePoint = new RoutePoint();
|
||||
routePoint.setLongitude(trackPoint.getLongitude());
|
||||
routePoint.setLatitude(trackPoint.getLatitude());
|
||||
routePoint.setAltitude(parseInteger(trackPoint.getHeight()));
|
||||
routePoint.setSpeed(parseInteger(trackPoint.getSpeed()));
|
||||
routes.add(routePoint);
|
||||
}
|
||||
return routes;
|
||||
}
|
||||
|
||||
private TaskTime buildTaskTime(Kj3TaskPayload payload) {
|
||||
int begin = parseAtTime(payload);
|
||||
TaskTime taskTime = new TaskTime();
|
||||
taskTime.setBegin(begin);
|
||||
taskTime.setEnd(begin);
|
||||
return taskTime;
|
||||
}
|
||||
|
||||
private int parseAtTime(Kj3TaskPayload payload) {
|
||||
if (payload == null || ObjectUtil.isEmpty(payload.getAtTime())) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(payload.getAtTime().trim());
|
||||
} catch (NumberFormatException ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private Integer parseInteger(String value) {
|
||||
if (ObjectUtil.isEmpty(value)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return (int) Math.round(Double.parseDouble(value.trim()));
|
||||
} catch (NumberFormatException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> extractTargets(Kj3TaskPayload payload) {
|
||||
if (payload == null || CollUtil.isEmpty(payload.getExecute())) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Set<String> uniqueTargets = new LinkedHashSet<>();
|
||||
for (Kj3ExecuteBlock executeBlock : payload.getExecute()) {
|
||||
if (executeBlock == null || CollUtil.isEmpty(executeBlock.getTargetList())) {
|
||||
continue;
|
||||
}
|
||||
for (Kj3TargetItem targetItem : executeBlock.getTargetList()) {
|
||||
if (targetItem == null || ObjectUtil.isEmpty(targetItem.getTargetId())) {
|
||||
continue;
|
||||
}
|
||||
uniqueTargets.add(targetItem.getTargetId());
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(uniqueTargets);
|
||||
}
|
||||
|
||||
private String writeJson(DataOutput output) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(output);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("序列化 data 输出失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private String postJson(String payload) {
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
URL url = new URL(DATA_POST_URL);
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
||||
connection.setConnectTimeout(10000);
|
||||
connection.setReadTimeout(10000);
|
||||
connection.setDoOutput(true);
|
||||
|
||||
try (OutputStream outputStream = connection.getOutputStream()) {
|
||||
outputStream.write(payload.getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
}
|
||||
|
||||
int status = connection.getResponseCode();
|
||||
try (InputStream responseStream = status >= 400 ? connection.getErrorStream() : connection.getInputStream()) {
|
||||
String responseBody = readResponse(responseStream);
|
||||
return "HTTP " + status + " " + responseBody;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (e instanceof UnknownHostException) {
|
||||
throw new RuntimeException("POST data 输出失败: 无法解析主机,请检查 DATA_POST_URL=" + DATA_POST_URL, e);
|
||||
}
|
||||
throw new RuntimeException("POST data 输出失败: " + e.getMessage(), e);
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String readResponse(InputStream inputStream) throws IOException {
|
||||
if (inputStream == null) {
|
||||
return "";
|
||||
}
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||
StringBuilder response = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
response.append(line);
|
||||
}
|
||||
return response.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user