simulation-backend/src/main/java/com/hivekion/scenario/service/impl/TaskLogicServiceImpl.java
2025-09-17 13:58:20 +08:00

168 lines
5.8 KiB
Java

package com.hivekion.scenario.service.impl;
import org.springframework.stereotype.Service;
/**
* [类的简要说明]
* <p>
* [详细描述,可选]
* <p>
*
* @author LiDongYU
* @since 2025/7/22
*/
@Service
public class TaskLogicServiceImpl {
// @Resource
// private RedisUtil redisUtil;
// @Value("${path.planning.url}")
// private String pathPlanningUrl;
// private final WebClient webClient = WebClient.create();
// @Resource
// private StatisticService statisticService;
// private final static double fuelUseUpPerSecond = 0.1;
// private final static double medicalUseUpPerSecond = 0.1;
// private final static double ammunitionUsePerSecond = 0.1;
//
// @Override
// public void handleMoveTask(ScenarioTask scenarioTask, Scenario currentScenario, String roomId,
// double speed, TaskFinishedCall call) {
// ResponseCmdInfo<Map<String, Object>> cmdInfo = new ResponseCmdInfo<>();
// Map<String, Object> dataMap = new HashMap<>();
// cmdInfo.setData(dataMap);
// dataMap.put("resourceId", scenarioTask.getResourceId());
// cmdInfo.setScenarioId(scenarioTask.getScenarioId());
// cmdInfo.setRoom(roomId);
// if ("init".equals(scenarioTask.getStatus())) {
// scenarioTask.setStatus("running");
//
// String url = pathPlanningUrl + "?profile=car&point=" + scenarioTask.getFromLat() + ","
// + scenarioTask.getFromLng()
// + "&point=" + scenarioTask.getToLat() + "," + scenarioTask.getToLng()
// + "&points_encoded=false&algorithm=alternative_route&alternative_route.max_paths=3";
// String result = webClient.get()
// .uri(url)
// .retrieve()
// .bodyToMono(String.class)
// .block();
// com.alibaba.fastjson2.JSONObject resultObject = JSON.parseObject(result);
// if (result != null) {
// cmdInfo.setCmdType("init_path_planning");
//
//
// dataMap.put("points", resultObject);
//
// redisUtil.hset(roomId + "_" + currentScenario.getId(),
// scenarioTask.getId() + "_path_points", result);
// }
//
// Global.sendCmdInfoQueue.add(cmdInfo);
// //设置获取物资信息
// StatisticBean statistic = statisticService.statistic(scenarioTask.getResourceId());
// redisUtil.hset(roomId + "_" + currentScenario.getId(),
// "resourceId_statistic_" + scenarioTask.getResourceId(), JSON.toJSONString(statistic));
// } else if ("running".equals(scenarioTask.getStatus())) {
//
// //消耗油料
// StatisticBean statistic = getStatistic(scenarioTask, currentScenario, roomId);
// //获取想定持续时间
// int duringTime = getCurrentDuringTime(currentScenario, roomId);
// long seconds =
// duringTime - Duration.between(scenarioTask.getStartTime(), currentScenario.getStartTime())
// .getSeconds();
// if (seconds > 0) {
// double useUp = seconds * fuelUseUpPerSecond;
// statistic.getFuel().setCurrent(statistic.getFuel().getTotal() - useUp);
// setStatistic(scenarioTask, currentScenario, roomId, statistic);
// }
//
// }
//
// }
//
// @Override
// public void handleBattleTask(ScenarioTask task, Scenario scenario, String roomId,
// List<Integer> injuredTime) {
// StatisticBean statistic = getStatistic(task, scenario, roomId);
// int duringTime = getCurrentDuringTime(scenario, roomId);
// long seconds =
// duringTime - Duration.between(task.getStartTime(), scenario.getStartTime())
// .getSeconds();
// if (seconds > 0) {
// statistic.getMedical()
// .setCurrent(statistic.getMedical().getTotal() - seconds * medicalUseUpPerSecond);
// statistic.getAmmunition()
// .setCurrent(statistic.getAmmunition().getTotal() - seconds * ammunitionUsePerSecond);
// setStatistic(task, scenario, roomId, statistic);
//
// }
// //受伤
// injuredTime.forEach(time -> {
// if (time == seconds) {
// if (statistic.getPerson().getCurrent() > 0) {
// statistic.getPerson().setCurrent(statistic.getPerson().getCurrent() - 1);
// }
//
// }
// });
// //产生任务
//
// setStatistic(task, scenario, roomId, statistic);
// }
//
//
// @Override
// public void supplierTask(ScenarioTask task, Scenario scenario, String roomId) {
//
// //运20速度
// handleMoveTask(task, scenario, roomId, 217, () -> {
// //更新想定的物资
// });
//
//
// }
//
// private StatisticBean getStatistic(ScenarioTask task, Scenario scenario, String roomId) {
// synchronized (this) {
// Object statisticObj = redisUtil.hget(roomId + "_" + scenario.getId(),
// "resourceId_statistic_" + task.getResourceId());
// if (statisticObj != null) {
// return JSON.parseObject(statisticObj.toString(), StatisticBean.class);
// }
// return new StatisticBean();
// }
// }
//
// private void setStatistic(ScenarioTask task, Scenario scenario, String roomId,
// StatisticBean bean) {
// redisUtil.hset(roomId + "_" + scenario.getId(),
// "resourceId_statistic_" + task.getResourceId(), JSON.toJSONString(bean));
// //推送到前端
// ResponseCmdInfo<Map<String, Object>> cmdInfo = new ResponseCmdInfo<>();
// Map<String, Object> dataMap = new HashMap<>();
// cmdInfo.setData(dataMap);
// cmdInfo.setScenarioId(scenario.getId());
// cmdInfo.setRoom(roomId);
// dataMap.put("resourceId", task.getResourceId());
// dataMap.put("statistic", bean);
// Global.sendCmdInfoQueue.add(cmdInfo);
// }
//
// /**
// * 获取当前想定从开始到现在时间
// *
// * @param scenario
// * @param roomId
// * @return
// */
// private int getCurrentDuringTime(Scenario scenario, String roomId) {
// Object duringTime = redisUtil.hget(roomId + "_" + scenario.getId(), "duringTime");
// if (duringTime != null) {
// return Integer.parseInt(duringTime.toString());
// }
// return 0;
// }
}