fix[设备服务]:新增设备返回结果处理逻辑,新增订单逻辑更新逻辑
This commit is contained in:
+11
-6
@@ -1,11 +1,13 @@
|
|||||||
package com.central.device.controller;
|
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.Gson;
|
||||||
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
|
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import com.central.device.feign.OrderCenterService;
|
import com.central.device.feign.OrderCenterService;
|
||||||
import com.central.device.message.ControlEnum;
|
import com.central.device.message.ControlEnum;
|
||||||
import com.central.device.message.ControlMessageConstant;
|
import com.central.device.message.ControlMessageConstant;
|
||||||
|
import com.central.device.util.IotRequestResult;
|
||||||
import com.central.device.util.MapUtil;
|
import com.central.device.util.MapUtil;
|
||||||
import com.central.device.util.RequestUtils;
|
import com.central.device.util.RequestUtils;
|
||||||
import com.central.device.util.http.HeaderUtils;
|
import com.central.device.util.http.HeaderUtils;
|
||||||
@@ -74,10 +76,6 @@ public class ApiDeviceController {
|
|||||||
String value = MapUtil.getStrValue(param, "order_no");
|
String value = MapUtil.getStrValue(param, "order_no");
|
||||||
Assert.notNull(value,"任务编号不能为空");
|
Assert.notNull(value,"任务编号不能为空");
|
||||||
|
|
||||||
Result res = orderCenterService.getOrderExecStatus(value);
|
|
||||||
if (res.getResp_code() != null && res.getResp_code() == 1){
|
|
||||||
return Result.succeed("任务正在执行中");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
if (ControlEnum.contains(ControlEnum.valueOf(property.toUpperCase()))) {
|
if (ControlEnum.contains(ControlEnum.valueOf(property.toUpperCase()))) {
|
||||||
jsonObject = gson.fromJson(controlMessageConstant.CONTROL_MESSAGE_MAP.get(property), JsonObject.class);
|
jsonObject = gson.fromJson(controlMessageConstant.CONTROL_MESSAGE_MAP.get(property), JsonObject.class);
|
||||||
@@ -89,9 +87,16 @@ public class ApiDeviceController {
|
|||||||
return Result.succeed("暂未开放控制权限");
|
return Result.succeed("暂未开放控制权限");
|
||||||
}
|
}
|
||||||
Map<String, String> result = requestUtils.getPostRequestResultMap(url, jsonObject.toString());
|
Map<String, String> result = requestUtils.getPostRequestResultMap(url, jsonObject.toString());
|
||||||
|
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);
|
Result result1 = orderCenterService.updateOrderStatusDoing(value);
|
||||||
if (result1.getResp_code() != null && result1.getResp_code() == 1){
|
if (result1.getResp_code() != null && result1.getResp_code() == 0){
|
||||||
return Result.succeed(result,"设置成功");
|
return Result.succeed(result1.getData(),"设置成功");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Result.failed("请重试");
|
return Result.failed("请重试");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
+4
-8
@@ -4,9 +4,8 @@ import com.central.common.constant.ServiceNameConstants;
|
|||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import com.central.device.feign.fallback.OrderCenterServiceFallbackFactory;
|
import com.central.device.feign.fallback.OrderCenterServiceFallbackFactory;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.PatchMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* user-center模块远程调用
|
* user-center模块远程调用
|
||||||
@@ -19,9 +18,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
@FeignClient(name = ServiceNameConstants.ORDER_SERVICE, fallbackFactory = OrderCenterServiceFallbackFactory.class, dismiss404 = true)
|
@FeignClient(name = ServiceNameConstants.ORDER_SERVICE, fallbackFactory = OrderCenterServiceFallbackFactory.class, dismiss404 = true)
|
||||||
public interface OrderCenterService {
|
public interface OrderCenterService {
|
||||||
|
|
||||||
@GetMapping("/status/{orderNo}")
|
@PostMapping("/status")
|
||||||
Result getOrderExecStatus(@PathVariable("orderNo") String orderNo);
|
Result updateOrderStatusDoing(@RequestBody String orderNo);
|
||||||
|
|
||||||
@PatchMapping("/status/{orderNo}")
|
|
||||||
Result updateOrderStatusDoing(@PathVariable("orderNo") String orderNo);
|
|
||||||
}
|
}
|
||||||
|
|||||||
-6
@@ -22,12 +22,6 @@ public class OrderCenterServiceFallbackFactory implements FallbackFactory<OrderC
|
|||||||
@Override
|
@Override
|
||||||
public OrderCenterService create(Throwable cause) {
|
public OrderCenterService create(Throwable cause) {
|
||||||
return new OrderCenterService() {
|
return new OrderCenterService() {
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result getOrderExecStatus(String orderNo) {
|
|
||||||
return Result.failed(orderNo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result updateOrderStatusDoing(String orderNo) {
|
public Result updateOrderStatusDoing(String orderNo) {
|
||||||
return null;
|
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
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public Map<String, String> getPostRequestResultMap(String url, JSONObject jsonObject) 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);
|
HttpRequest request = new SimpleHttpRequest(url);
|
||||||
request.headers(headerUtils.createHeadersOfJsonString(jsonObject.toJSONString()));
|
request.headers(headerUtils.createHeadersOfJsonString(jsonObject.toJSONString()));
|
||||||
request.requestBody(jsonObject.toJSONString());
|
request.requestBody(jsonObject.toJSONString());
|
||||||
@@ -48,7 +48,7 @@ public class RequestUtils {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public Map<String, String> getPostRequestResultMap(String url, Map param) 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);
|
HttpRequest request = new SimpleHttpRequest(url);
|
||||||
request.headers(headerUtils.createHeadersOfJsonString(JSON.toJSONString(param)));
|
request.headers(headerUtils.createHeadersOfJsonString(JSON.toJSONString(param)));
|
||||||
request.requestBody(JSON.toJSONString(param));
|
request.requestBody(JSON.toJSONString(param));
|
||||||
@@ -65,13 +65,13 @@ public class RequestUtils {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public Map<String, String> getPostRequestResultMap(String url, String body) 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);
|
HttpRequest request = new SimpleHttpRequest(url);
|
||||||
request.headers(headerUtils.createHeadersOfJsonString(body));
|
request.headers(headerUtils.createHeadersOfJsonString(body));
|
||||||
request.requestBody(body);
|
request.requestBody(body);
|
||||||
Response response = request.post();
|
Response response = request.post();
|
||||||
Map<String, String> result = Utils.queryStringToMap(new String(response.asBytes(), "utf8"), "utf8");
|
Map<String, String> result = Utils.queryStringToMap(new String(response.asBytes(), "utf8"), "utf8");
|
||||||
System.out.println(result);
|
log.debug(""+result.get(""));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +111,6 @@ public class RequestUtils {
|
|||||||
log.info("查询异常:{}",e.getMessage());
|
log.info("查询异常:{}",e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
// log.info("获取post请求result结果:{}" ,JSON.toJSONString(result));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: device-center
|
name: device-center
|
||||||
cloud:
|
# cloud:
|
||||||
nacos:
|
# nacos:
|
||||||
discovery:
|
# discovery:
|
||||||
ip: 81.70.164.178
|
# ip: 81.70.164.178
|
||||||
# cloud:
|
# cloud:
|
||||||
# nacos:
|
# nacos:
|
||||||
# discovery:
|
# discovery:
|
||||||
|
|||||||
+16
-62
@@ -7,6 +7,7 @@ import com.central.common.model.LoginAppUser;
|
|||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import com.central.common.model.SysUser;
|
import com.central.common.model.SysUser;
|
||||||
|
import com.central.log.annotation.AuditLog;
|
||||||
import com.central.order.config.TencentPayProperties;
|
import com.central.order.config.TencentPayProperties;
|
||||||
import com.central.order.enums.OrderStatus;
|
import com.central.order.enums.OrderStatus;
|
||||||
import com.central.order.feign.FileCenterService;
|
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.IOrderService;
|
||||||
import com.central.order.service.IQrCodeService;
|
import com.central.order.service.IQrCodeService;
|
||||||
import com.central.order.service.ITourismService;
|
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.JsapiServiceExtension;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.*;
|
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
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.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.Parameters;
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
@@ -301,85 +303,38 @@ public class OrderController {
|
|||||||
return Result.succeed("排队订单处理已启动");
|
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){
|
|
||||||
return Result.succeed("更新成功");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Result.failed("未查询到订单数据");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "更新订单正在服务中状态")
|
@Operation(summary = "更新订单正在服务中状态")
|
||||||
@PatchMapping("/status/{orderNo}")
|
@AuditLog(operation = "'下发任务更新订单正在服务中状态:' + #orderNo")
|
||||||
public Result<String> updateOrderStatusDoing(@PathVariable String orderNo) {
|
@PostMapping("/status")
|
||||||
|
public Result<String> updateOrderStatusDoing(@RequestBody String orderNo) {
|
||||||
Order order = orderService.getOrderByNumber(orderNo);
|
Order order = orderService.getOrderByNumber(orderNo);
|
||||||
if (order != null) {
|
Assert.notNull(order,"订单数据不能为空");
|
||||||
if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
||||||
order.setOrderStatus(OrderStatus.DOING.getId());
|
order.setOrderStatus(OrderStatus.DOING.getId());
|
||||||
boolean res = orderService.updateOrder(order);
|
if (orderService.updateOrder(order)){
|
||||||
if (res){
|
|
||||||
return Result.succeed("更新成功");
|
return Result.succeed("更新成功");
|
||||||
}
|
}
|
||||||
}else {
|
|
||||||
return Result.failed("已更新");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return Result.failed("未查询到订单数据");
|
return Result.failed("未查询到订单数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "机库更新订单完成状态")
|
@Operation(summary = "机库更新订单完成状态")
|
||||||
|
@AuditLog(operation = "'机库更新订单完成状态:' + #payload")
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
public Result<String> updateOrderStatusCompleted(@RequestBody Map payload) {
|
public Result<String> updateOrderStatusCompleted(@RequestBody Map payload) {
|
||||||
Order order = orderService.getOrderByNumber(payload.get("orderNo").toString());
|
Order order = orderService.getOrderByNumber(payload.get("orderNo").toString());
|
||||||
if (order != null) {
|
Assert.notNull(order,"订单数据不能为空");
|
||||||
if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
if (order.getOrderStatus().equals(OrderStatus.DOING.getId())){
|
||||||
order.setOrderStatus(OrderStatus.COMPLETE.getId());
|
order.setOrderStatus(OrderStatus.COMPLETE.getId());
|
||||||
boolean res = orderService.updateOrder(order);
|
if (orderService.updateOrder(order)){
|
||||||
if (res){
|
|
||||||
return Result.succeed("更新成功");
|
return Result.succeed("更新成功");
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
return Result.failed("已更新");
|
return Result.failed("已更新");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
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 = "取消订单")
|
@Operation(summary = "取消订单")
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public Result cancelOrder(@PathVariable("id") Long id) {
|
public Result cancelOrder(@PathVariable("id") Long id) {
|
||||||
@@ -394,13 +349,12 @@ public class OrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "机库查询订单执行情况")
|
@Operation(summary = "机库查询订单执行情况")
|
||||||
|
@AuditLog(operation = "'机库查询订单执行情况:' + #orderNo")
|
||||||
@GetMapping("/status/{orderNo}")
|
@GetMapping("/status/{orderNo}")
|
||||||
public Result getOrderExecStatus(@PathVariable("orderNo") String orderNo) {
|
public Result getOrderExecStatus(@PathVariable("orderNo") String orderNo) {
|
||||||
|
|
||||||
Order order = orderService.getOrderByNumber(orderNo);
|
Order order = orderService.getOrderByNumber(orderNo);
|
||||||
if (order == null){
|
Assert.notNull(order,"订单数据为空");
|
||||||
return Result.failed("未查询到订单");
|
|
||||||
}
|
|
||||||
if (order.getOrderStatus().equals(OrderStatus.COMPLETE.getId())){
|
if (order.getOrderStatus().equals(OrderStatus.COMPLETE.getId())){
|
||||||
return Result.failed("已执行");
|
return Result.failed("已执行");
|
||||||
}else if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
}else if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: order-center
|
name: order-center
|
||||||
cloud:
|
# cloud:
|
||||||
nacos:
|
# nacos:
|
||||||
discovery:
|
# discovery:
|
||||||
ip: 81.70.164.178
|
# ip: 81.70.164.178
|
||||||
# cloud:
|
# cloud:
|
||||||
# nacos:
|
# nacos:
|
||||||
# discovery:
|
# discovery:
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
########################## bootstrap级别通用配置 ##########################
|
########################## bootstrap级别通用配置 ##########################
|
||||||
# 默认开发环境
|
# 默认开发环境
|
||||||
spring.profiles.active=prod
|
spring.profiles.active=dev
|
||||||
|
|
||||||
##### nacos(注册中心和配置中心)地址
|
##### nacos(注册中心和配置中心)地址
|
||||||
spring.cloud.nacos.server-addr=47.94.136.130:8848
|
#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=127.0.0.1:8848
|
||||||
spring.cloud.nacos.username=nacos
|
spring.cloud.nacos.username=nacos
|
||||||
spring.cloud.nacos.password=nacos
|
spring.cloud.nacos.password=nacos
|
||||||
spring.cloud.nacos.config.file-extension=yml
|
spring.cloud.nacos.config.file-extension=yml
|
||||||
|
|||||||
Reference in New Issue
Block a user