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;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: device-center
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
ip: 81.70.164.178
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# ip: 81.70.164.178
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
|
||||
+24
-70
@@ -7,6 +7,7 @@ import com.central.common.model.LoginAppUser;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysUser;
|
||||
import com.central.log.annotation.AuditLog;
|
||||
import com.central.order.config.TencentPayProperties;
|
||||
import com.central.order.enums.OrderStatus;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
@@ -18,10 +19,11 @@ import com.central.order.service.IOrderFileService;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.service.IQrCodeService;
|
||||
import com.central.order.service.ITourismService;
|
||||
import com.wechat.pay.java.core.exception.ServiceException;
|
||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.*;
|
||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
@@ -301,85 +303,38 @@ public class OrderController {
|
||||
return Result.succeed("排队订单处理已启动");
|
||||
}
|
||||
|
||||
@Operation(summary = "更新订单支付完成状态")
|
||||
@PatchMapping("/update/{orderNo}")
|
||||
public Result<String> updateOrderStatusPaid(@PathVariable String orderNo) {
|
||||
Transaction transaction = queryOrderByOutTradeNo(orderNo);
|
||||
if (transaction != null && transaction.getTradeState().equals(Transaction.TradeStateEnum.SUCCESS)){
|
||||
Order order = orderService.getOrderByNumber(transaction.getOutTradeNo());
|
||||
order.setOrderStatus(OrderStatus.PAID.getId());
|
||||
boolean res = orderService.updateOrder(order);
|
||||
if (res){
|
||||
@Operation(summary = "更新订单正在服务中状态")
|
||||
@AuditLog(operation = "'下发任务更新订单正在服务中状态:' + #orderNo")
|
||||
@PostMapping("/status")
|
||||
public Result<String> updateOrderStatusDoing(@RequestBody String orderNo) {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
Assert.notNull(order,"订单数据不能为空");
|
||||
if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
||||
order.setOrderStatus(OrderStatus.DOING.getId());
|
||||
if (orderService.updateOrder(order)){
|
||||
return Result.succeed("更新成功");
|
||||
}
|
||||
}
|
||||
return Result.failed("未查询到订单数据");
|
||||
}
|
||||
|
||||
@Operation(summary = "更新订单正在服务中状态")
|
||||
@PatchMapping("/status/{orderNo}")
|
||||
public Result<String> updateOrderStatusDoing(@PathVariable String orderNo) {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order != null) {
|
||||
if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
||||
order.setOrderStatus(OrderStatus.DOING.getId());
|
||||
boolean res = orderService.updateOrder(order);
|
||||
if (res){
|
||||
return Result.succeed("更新成功");
|
||||
}
|
||||
}else {
|
||||
return Result.failed("已更新");
|
||||
}
|
||||
|
||||
}
|
||||
return Result.failed("未查询到订单数据");
|
||||
}
|
||||
|
||||
@Operation(summary = "机库更新订单完成状态")
|
||||
@AuditLog(operation = "'机库更新订单完成状态:' + #payload")
|
||||
@PutMapping("/update")
|
||||
public Result<String> updateOrderStatusCompleted(@RequestBody Map payload) {
|
||||
Order order = orderService.getOrderByNumber(payload.get("orderNo").toString());
|
||||
if (order != null) {
|
||||
if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
||||
order.setOrderStatus(OrderStatus.COMPLETE.getId());
|
||||
boolean res = orderService.updateOrder(order);
|
||||
if (res){
|
||||
return Result.succeed("更新成功");
|
||||
}
|
||||
}else {
|
||||
return Result.failed("已更新");
|
||||
Assert.notNull(order,"订单数据不能为空");
|
||||
if (order.getOrderStatus().equals(OrderStatus.DOING.getId())){
|
||||
order.setOrderStatus(OrderStatus.COMPLETE.getId());
|
||||
if (orderService.updateOrder(order)){
|
||||
return Result.succeed("更新成功");
|
||||
}
|
||||
|
||||
}else {
|
||||
return Result.failed("已更新");
|
||||
}
|
||||
return Result.failed("未查询到订单数据");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 商户订单号查询订单 */
|
||||
public Transaction queryOrderByOutTradeNo(String outTradeNo) {
|
||||
|
||||
QueryOrderByOutTradeNoRequest request = new QueryOrderByOutTradeNoRequest();
|
||||
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
||||
request.setOutTradeNo(outTradeNo);
|
||||
return service.queryOrderByOutTradeNo(request);
|
||||
}
|
||||
|
||||
public void getTencentOrderById(String setTransactionId) {
|
||||
QueryOrderByIdRequest queryRequest = new QueryOrderByIdRequest();
|
||||
queryRequest.setMchid("190000****");
|
||||
queryRequest.setTransactionId("4200001569202208304701234567");
|
||||
|
||||
try {
|
||||
Transaction result = service.queryOrderById(queryRequest);
|
||||
System.out.println(result.getTradeState());
|
||||
} catch (ServiceException e) {
|
||||
// API返回失败, 例如ORDER_NOT_EXISTS
|
||||
System.out.printf("code=[%s], message=[%s]\n", e.getErrorCode(), e.getErrorMessage());
|
||||
System.out.printf("reponse body=[%s]\n", e.getResponseBody());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "取消订单")
|
||||
@PutMapping("/{id}")
|
||||
public Result cancelOrder(@PathVariable("id") Long id) {
|
||||
@@ -394,13 +349,12 @@ public class OrderController {
|
||||
}
|
||||
|
||||
@Operation(summary = "机库查询订单执行情况")
|
||||
@AuditLog(operation = "'机库查询订单执行情况:' + #orderNo")
|
||||
@GetMapping("/status/{orderNo}")
|
||||
public Result getOrderExecStatus(@PathVariable("orderNo") String orderNo) {
|
||||
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null){
|
||||
return Result.failed("未查询到订单");
|
||||
}
|
||||
Assert.notNull(order,"订单数据为空");
|
||||
if (order.getOrderStatus().equals(OrderStatus.COMPLETE.getId())){
|
||||
return Result.failed("已执行");
|
||||
}else if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
||||
|
||||
@@ -4,10 +4,10 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: order-center
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
ip: 81.70.164.178
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# ip: 81.70.164.178
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
########################## bootstrap级别通用配置 ##########################
|
||||
# 默认开发环境
|
||||
spring.profiles.active=prod
|
||||
spring.profiles.active=dev
|
||||
|
||||
##### nacos(注册中心和配置中心)地址
|
||||
spring.cloud.nacos.server-addr=47.94.136.130:8848
|
||||
#spring.cloud.nacos.server-addr=127.0.0.1:8848
|
||||
#spring.cloud.nacos.server-addr=47.94.136.130:8848
|
||||
spring.cloud.nacos.server-addr=127.0.0.1:8848
|
||||
spring.cloud.nacos.username=nacos
|
||||
spring.cloud.nacos.password=nacos
|
||||
spring.cloud.nacos.config.file-extension=yml
|
||||
|
||||
Reference in New Issue
Block a user