fix[设备服务]:新增设备返回结果处理逻辑,新增订单逻辑更新逻辑
This commit is contained in:
+12
-7
@@ -1,11 +1,13 @@
|
||||
package com.central.device.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.device.feign.OrderCenterService;
|
||||
import com.central.device.message.ControlEnum;
|
||||
import com.central.device.message.ControlMessageConstant;
|
||||
import com.central.device.util.IotRequestResult;
|
||||
import com.central.device.util.MapUtil;
|
||||
import com.central.device.util.RequestUtils;
|
||||
import com.central.device.util.http.HeaderUtils;
|
||||
@@ -74,10 +76,6 @@ public class ApiDeviceController {
|
||||
String value = MapUtil.getStrValue(param, "order_no");
|
||||
Assert.notNull(value,"任务编号不能为空");
|
||||
|
||||
Result res = orderCenterService.getOrderExecStatus(value);
|
||||
if (res.getResp_code() != null && res.getResp_code() == 1){
|
||||
return Result.succeed("任务正在执行中");
|
||||
}
|
||||
try {
|
||||
if (ControlEnum.contains(ControlEnum.valueOf(property.toUpperCase()))) {
|
||||
jsonObject = gson.fromJson(controlMessageConstant.CONTROL_MESSAGE_MAP.get(property), JsonObject.class);
|
||||
@@ -89,9 +87,16 @@ public class ApiDeviceController {
|
||||
return Result.succeed("暂未开放控制权限");
|
||||
}
|
||||
Map<String, String> result = requestUtils.getPostRequestResultMap(url, jsonObject.toString());
|
||||
Result result1 = orderCenterService.updateOrderStatusDoing(value);
|
||||
if (result1.getResp_code() != null && result1.getResp_code() == 1){
|
||||
return Result.succeed(result,"设置成功");
|
||||
JSONObject object = JSONObject.parseObject(result.get(""));
|
||||
Assert.notNull(object,"请求IOT平台异常");
|
||||
IotRequestResult requestResult = IotRequestResult.getInstance(object);
|
||||
//500为设备回复超时
|
||||
if (requestResult.getStatus() == 200 || requestResult.getStatus() == 500) {
|
||||
//更新订单状态为进行中
|
||||
Result result1 = orderCenterService.updateOrderStatusDoing(value);
|
||||
if (result1.getResp_code() != null && result1.getResp_code() == 0){
|
||||
return Result.succeed(result1.getData(),"设置成功");
|
||||
}
|
||||
}
|
||||
return Result.failed("请重试");
|
||||
} catch (Exception e) {
|
||||
|
||||
+4
-8
@@ -4,9 +4,8 @@ import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.device.feign.fallback.OrderCenterServiceFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* user-center模块远程调用
|
||||
@@ -19,9 +18,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
@FeignClient(name = ServiceNameConstants.ORDER_SERVICE, fallbackFactory = OrderCenterServiceFallbackFactory.class, dismiss404 = true)
|
||||
public interface OrderCenterService {
|
||||
|
||||
@GetMapping("/status/{orderNo}")
|
||||
Result getOrderExecStatus(@PathVariable("orderNo") String orderNo);
|
||||
|
||||
@PatchMapping("/status/{orderNo}")
|
||||
Result updateOrderStatusDoing(@PathVariable("orderNo") String orderNo);
|
||||
@PostMapping("/status")
|
||||
Result updateOrderStatusDoing(@RequestBody String orderNo);
|
||||
}
|
||||
|
||||
-6
@@ -22,12 +22,6 @@ public class OrderCenterServiceFallbackFactory implements FallbackFactory<OrderC
|
||||
@Override
|
||||
public OrderCenterService create(Throwable cause) {
|
||||
return new OrderCenterService() {
|
||||
|
||||
@Override
|
||||
public Result getOrderExecStatus(String orderNo) {
|
||||
return Result.failed(orderNo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result updateOrderStatusDoing(String orderNo) {
|
||||
return null;
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.central.device.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* IOT request result model
|
||||
* @author lsl
|
||||
* @date 2025-02-25
|
||||
*
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
public class IotRequestResult {
|
||||
|
||||
private String message;
|
||||
private Integer status;
|
||||
private Long timestamp;
|
||||
private String code;
|
||||
private List<JSONObject> result;
|
||||
|
||||
public static IotRequestResult getInstance(JSONObject message) throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 将JSONObject转换为JsonNode,因为ObjectMapper不直接接受JSONObject
|
||||
JsonNode jsonNode = objectMapper.readTree(message.toString());
|
||||
|
||||
// 将JsonNode转换为指定的Java类
|
||||
return objectMapper.treeToValue(jsonNode, IotRequestResult.class);
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class RequestUtils {
|
||||
* @throws IOException
|
||||
*/
|
||||
public Map<String, String> getPostRequestResultMap(String url, JSONObject jsonObject) throws IOException {
|
||||
System.out.println(url);
|
||||
log.debug(url);
|
||||
HttpRequest request = new SimpleHttpRequest(url);
|
||||
request.headers(headerUtils.createHeadersOfJsonString(jsonObject.toJSONString()));
|
||||
request.requestBody(jsonObject.toJSONString());
|
||||
@@ -48,7 +48,7 @@ public class RequestUtils {
|
||||
* @throws IOException
|
||||
*/
|
||||
public Map<String, String> getPostRequestResultMap(String url, Map param) throws IOException {
|
||||
System.out.println(url);
|
||||
log.debug(url);
|
||||
HttpRequest request = new SimpleHttpRequest(url);
|
||||
request.headers(headerUtils.createHeadersOfJsonString(JSON.toJSONString(param)));
|
||||
request.requestBody(JSON.toJSONString(param));
|
||||
@@ -65,13 +65,13 @@ public class RequestUtils {
|
||||
* @throws IOException
|
||||
*/
|
||||
public Map<String, String> getPostRequestResultMap(String url, String body) throws IOException {
|
||||
System.out.println(url);
|
||||
log.debug(url);
|
||||
HttpRequest request = new SimpleHttpRequest(url);
|
||||
request.headers(headerUtils.createHeadersOfJsonString(body));
|
||||
request.requestBody(body);
|
||||
Response response = request.post();
|
||||
Map<String, String> result = Utils.queryStringToMap(new String(response.asBytes(), "utf8"), "utf8");
|
||||
System.out.println(result);
|
||||
log.debug(""+result.get(""));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,6 @@ public class RequestUtils {
|
||||
log.info("查询异常:{}",e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
// log.info("获取post请求result结果:{}" ,JSON.toJSONString(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user