add:1.增加后台管理强制取消任务接口。2.修改设置车辆冰量和水量逻辑。3.增加OTA远程更新功能。4.补充国际化。5.增加调度任务不存在同步取消数据库任务。
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package org.nl.monitor.otaAgent.controller;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.logging.annotation.Log;
|
||||
import org.nl.monitor.otaAgent.params.ConfirmParam;
|
||||
import org.nl.monitor.otaAgent.params.PostponeParam;
|
||||
import org.nl.monitor.otaAgent.service.OTAAgentService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2026/4/30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/otaAgent")
|
||||
@Slf4j
|
||||
public class OTAAgentController {
|
||||
|
||||
@Resource
|
||||
private OTAAgentService otaAgentService;
|
||||
|
||||
@GetMapping("/getStatus")
|
||||
@Log("查看Agent状态")
|
||||
public ResponseEntity<Object> getStatus(@RequestParam String vehicleId){
|
||||
return new ResponseEntity<>(otaAgentService.getStatus(vehicleId), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/confirm")
|
||||
@Log("确认更新Agent")
|
||||
public ResponseEntity<Object> confirm(@RequestBody ConfirmParam confirmParam){
|
||||
return new ResponseEntity<>(otaAgentService.confirm(confirmParam), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/postpone")
|
||||
@Log("暂不更新Agent")
|
||||
public ResponseEntity<Object> postpone(@RequestBody PostponeParam postponeParam){
|
||||
return new ResponseEntity<>(otaAgentService.postpone(postponeParam), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.nl.monitor.otaAgent.params;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2026/4/30
|
||||
*/
|
||||
@Data
|
||||
public class ConfirmParam {
|
||||
|
||||
/**
|
||||
* 车号
|
||||
*/
|
||||
@NotBlank
|
||||
private String vehicleId;
|
||||
|
||||
/**
|
||||
* 确认人
|
||||
*/
|
||||
@NotBlank
|
||||
private String confirmed_by;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.nl.monitor.otaAgent.params;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2026/4/30
|
||||
*/
|
||||
@Data
|
||||
public class PostponeParam {
|
||||
|
||||
/**
|
||||
* 车号
|
||||
*/
|
||||
@NotBlank
|
||||
private String vehicleId;
|
||||
|
||||
/**
|
||||
* 原因
|
||||
*/
|
||||
@NotBlank
|
||||
private String reason;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.nl.monitor.otaAgent.service;
|
||||
|
||||
import org.nl.monitor.otaAgent.params.ConfirmParam;
|
||||
import org.nl.monitor.otaAgent.params.PostponeParam;
|
||||
import org.nl.response.WebResponse;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2026/4/30
|
||||
*/
|
||||
public interface OTAAgentService {
|
||||
|
||||
/**
|
||||
* 获取otaAgent状态
|
||||
* @return
|
||||
*/
|
||||
WebResponse getStatus(String vehicleId);
|
||||
|
||||
/**
|
||||
* 确认otaAgent更新
|
||||
* @return
|
||||
*/
|
||||
WebResponse confirm(ConfirmParam confirmParam);
|
||||
|
||||
/**
|
||||
* 暂不更新otaAgent更新
|
||||
* @return
|
||||
*/
|
||||
WebResponse postpone(PostponeParam postponeParam);
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package org.nl.monitor.otaAgent.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.api.schedule.vehicle.api.ScheduleVehicleAPI;
|
||||
import org.nl.api.task.api.TaskAPI;
|
||||
import org.nl.config.language.LangProcess;
|
||||
import org.nl.exception.BadRequestException;
|
||||
import org.nl.monitor.otaAgent.params.ConfirmParam;
|
||||
import org.nl.monitor.otaAgent.params.PostponeParam;
|
||||
import org.nl.monitor.otaAgent.service.OTAAgentService;
|
||||
import org.nl.response.WebResponse;
|
||||
import org.nl.util.URLConstant;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author dsh
|
||||
* 2026/4/30
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OTAAgentServiceImpl implements OTAAgentService {
|
||||
|
||||
@Resource
|
||||
private ScheduleVehicleAPI vehicleAPI;
|
||||
|
||||
@Resource
|
||||
private TaskAPI taskAPI;
|
||||
|
||||
@Override
|
||||
public WebResponse getStatus(String vehicleId) {
|
||||
// JSONObject vehicleData = vehicleAPI.getVehicleIPByNumber(vehicleId);
|
||||
// if (vehicleData == null){
|
||||
// throw new BadRequestException(LangProcess.msg("otaAgentGetStatusFailed"));
|
||||
// }
|
||||
// String ip = vehicleData.getString("ip");
|
||||
// String agentUrl = ip + ":" + URLConstant.OTA_AGENT_PORT;
|
||||
// todo 测试用例暂时使用固定IP
|
||||
String agentUrl = "192.168.10.231:" + URLConstant.OTA_AGENT_PORT;
|
||||
log.info("查询otaAgent状态");
|
||||
HttpResponse result = null;
|
||||
try {
|
||||
result = HttpRequest
|
||||
.get(agentUrl+"/ota/status")
|
||||
.execute();
|
||||
|
||||
log.info("查询otaAgent状态响应结果:{}",result.body());
|
||||
}catch (Exception e){
|
||||
log.error("查询otaAgent状态失败:{}",e.getMessage());
|
||||
}
|
||||
if (result != null && result.isOk()) {
|
||||
return WebResponse.requestParamOk(JSONObject.parseObject(result.body()));
|
||||
}
|
||||
throw new BadRequestException(LangProcess.msg("otaAgentGetStatusFailed"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResponse confirm(ConfirmParam confirmParam) {
|
||||
// JSONObject vehicleData = vehicleAPI.getVehicleIPByNumber(confirmParam.getVehicleId());
|
||||
// if (vehicleData == null){
|
||||
// throw new BadRequestException(LangProcess.msg("otaAgentConfirmFailed"));
|
||||
// }
|
||||
// if (vehicleData.getInteger("batteryLevel") < 50 || !BeanUtil.isEmpty(taskAPI.queryCurrentTaskByVehicleNumber(confirmParam.getVehicleId()))){
|
||||
// throw new BadRequestException(LangProcess.msg("otaAgentConfirmCheckFailed"));
|
||||
// }
|
||||
// String ip = vehicleData.getString("ip");
|
||||
// String agentUrl = ip + ":" + URLConstant.OTA_AGENT_PORT;
|
||||
// todo 测试用例暂时使用固定IP
|
||||
String agentUrl = "192.168.10.231:" + URLConstant.OTA_AGENT_PORT;
|
||||
log.info("确认otaAgent更新参数:{}",confirmParam);
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("confirmed_by", confirmParam.getConfirmed_by());
|
||||
HttpResponse result = null;
|
||||
try {
|
||||
result = HttpRequest
|
||||
.post(agentUrl+"/ota/confirm")
|
||||
.body(String.valueOf(param))
|
||||
.execute();
|
||||
|
||||
log.info("确认otaAgent更新响应结果:{}",result.body());
|
||||
}catch (Exception e){
|
||||
log.error("确认otaAgent更新失败:{}",e.getMessage());
|
||||
}
|
||||
if (result != null && result.isOk()) {
|
||||
return WebResponse.requestParamOk(JSONObject.parseObject(result.body()));
|
||||
}
|
||||
throw new BadRequestException(LangProcess.msg("otaAgentConfirmFailed"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResponse postpone(PostponeParam postponeParam) {
|
||||
// JSONObject vehicleData = vehicleAPI.getVehicleIPByNumber(postponeParam.getVehicleId());
|
||||
// if (vehicleData == null){
|
||||
// throw new BadRequestException(LangProcess.msg("otaAgentPostponeFailed"));
|
||||
// }
|
||||
// String ip = vehicleData.getString("ip");
|
||||
// String agentUrl = ip + ":" + URLConstant.OTA_AGENT_PORT;
|
||||
// todo 测试用例暂时使用固定IP
|
||||
String agentUrl = "192.168.10.231:" + URLConstant.OTA_AGENT_PORT;
|
||||
log.info("推迟otaAgent更新参数:{}",postponeParam);
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("reason", postponeParam.getReason());
|
||||
HttpResponse result = null;
|
||||
try {
|
||||
result = HttpRequest
|
||||
.post(agentUrl+"/ota/postpone")
|
||||
.body(String.valueOf(param))
|
||||
.execute();
|
||||
|
||||
log.info("推迟otaAgent更新响应结果:{}",result.body());
|
||||
}catch (Exception e){
|
||||
log.error("推迟otaAgent更新失败:{}",e.getMessage());
|
||||
}
|
||||
if (result != null && result.isOk()) {
|
||||
return WebResponse.requestParamOk(JSONObject.parseObject(result.body()));
|
||||
}
|
||||
throw new BadRequestException(LangProcess.msg("otaAgentPostponeFailed"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user