diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/config/ApplicationContextRegister.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/config/ApplicationContextRegister.java new file mode 100644 index 00000000..b37b93fb --- /dev/null +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/config/ApplicationContextRegister.java @@ -0,0 +1,30 @@ +package com.xhpc.order.config; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +/** + * @author yuyang + * @date 2021/8/9 20:31 + */ +@Component +@Lazy(false) +public class ApplicationContextRegister implements ApplicationContextAware { + + private static ApplicationContext APPLICATION_CONTEXT; + + /** + * 设置spring上下文 * * @param applicationContext spring上下文 * @throws BeansException + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + APPLICATION_CONTEXT = applicationContext; + } + + public static ApplicationContext getApplicationContext() { + return APPLICATION_CONTEXT; + } +} diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/WebSocketController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/WebSocketController.java index d2b277e4..18c95314 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/WebSocketController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/WebSocketController.java @@ -1,6 +1,13 @@ package com.xhpc.order.controller; +import com.xhpc.common.core.web.domain.AjaxResult; +import com.xhpc.common.redis.service.RedisService; +import com.xhpc.order.config.ApplicationContextRegister; +import com.xhpc.order.service.IHxpcChargeOrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; +import org.springframework.web.socket.server.standard.SpringConfigurator; import java.io.IOException; import java.util.concurrent.CopyOnWriteArraySet; @@ -19,22 +26,28 @@ import javax.websocket.server.ServerEndpoint; @ServerEndpoint(value="/websocket/{userId}") public class WebSocketController { - //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。 + /** + * 静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。 + */ private static int onlineCount = 0; - - //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。若要实现服务端与单一客户端通信的话,可以使用Map来存放,其中Key可以为用户标识 + /** + * concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。若要实现服务端与单一客户端通信的话,可以使用Map来存放,其中Key可以为用户标识 + */ private static CopyOnWriteArraySet webSocketSet = new CopyOnWriteArraySet(); - - //与某个客户端的连接会话,需要通过它来给客户端发送数据 + /** + * 与某个客户端的连接会话,需要通过它来给客户端发送数据 + */ private Session session; //连接用户id - private String userId; + private Long userId; + + /** * 连接建立成功调用的方法 * @param session 可选的参数。session为与某个客户端的连接会话,需要通过它来给客户端发送数据 */ @OnOpen - public void onOpen(@PathParam("userId") String userId,Session session){ + public void onOpen(@PathParam("userId") Long userId,Session session){ this.userId =userId; this.session = session; webSocketSet.add(this); //加入set中 @@ -80,6 +93,11 @@ public class WebSocketController { " \"remainingTime\": \"45\"\n" + " }\n" + "}"; + ApplicationContext act = ApplicationContextRegister.getApplicationContext(); + RedisService redisService = act.getBean(RedisService.class); + Object cacheObject = redisService.getCacheObject("gun:1472583698524602.seqdec"); + System.out.println("cacheObject:"+cacheObject); + this.session.getBasicRemote().sendText(message); } catch (IOException e) { @@ -98,16 +116,6 @@ public class WebSocketController { error.printStackTrace(); } - /** - * 这个方法与上面几个方法不一样。没有用注解,是根据自己需要添加的方法。 - * @param message - * @throws IOException - */ - public void sendMessage(String message) throws IOException{ - this.session.getBasicRemote().sendText(message); - //this.session.getAsyncRemote().sendText(message); - } - public static synchronized int getOnlineCount() { return onlineCount; } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java index 183d9c80..c0363224 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java @@ -43,12 +43,10 @@ public class XhpcHistoryOrderController extends BaseController { * 用户订单详情接口 * @param userId 用户id * @param historyOrderId 历史订单id - * @param type 1 历史订单id 2 充电订单id - * @param chargingOrderId 充电订单id * @return */ @GetMapping("/gethistotyOrderMessage") - public AjaxResult gethistotyOrderMessage(@RequestParam Long userId,@RequestParam Long historyOrderId,Integer type,Long chargingOrderId) + public AjaxResult gethistotyOrderMessage(@RequestParam Long userId,@RequestParam Long historyOrderId) { return xhpcHistoryOrderService.gethistotyOrderMessage(userId,historyOrderId); } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcRealTimeOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcRealTimeOrderController.java new file mode 100644 index 00000000..8a8975f5 --- /dev/null +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcRealTimeOrderController.java @@ -0,0 +1,17 @@ +package com.xhpc.order.controller; + +import com.xhpc.common.core.web.controller.BaseController; +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author yuyang + * @date 2021/8/9 21:15 + */ +@RestController +@RequestMapping("/realTimeOrder") +@Api(value = "实时订单接口", tags = "实时订单接口") +public class XhpcRealTimeOrderController extends BaseController { + +} diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/HxpcChargeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/HxpcChargeOrderServiceImpl.java index 5a45059d..0b671e48 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/HxpcChargeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/HxpcChargeOrderServiceImpl.java @@ -50,8 +50,7 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService { @Override public AjaxResult getHistotyChargeOrderStatusList(Long userId) { - - return null; + return AjaxResult.success(hxpcChargeOrderMapper.getHistotyChargeOrderStatusList(userId)); } @Override diff --git a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml index 9a38dd42..91c68f00 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcChargeOrderMapper.xml @@ -206,7 +206,23 @@ \ No newline at end of file diff --git a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml index 32209d98..4e15512e 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml @@ -300,7 +300,7 @@ ho.history_order_id as historyOrderId, ho.serial_number as serialNumber, ho.create_time as createTime, - ho.type as type, + co.status as status, cs.name as chargingStationName, te.name as terminalName, ho.act_price as actPrice,