diff --git a/netty-pad/src/main/java/com/sv/netty/config/ClientChannelCache.java b/netty-pad/src/main/java/com/sv/netty/config/ClientChannelCache.java new file mode 100644 index 0000000..9bbbe33 --- /dev/null +++ b/netty-pad/src/main/java/com/sv/netty/config/ClientChannelCache.java @@ -0,0 +1,42 @@ +package com.sv.netty.config; + +import io.netty.channel.Channel; +import io.netty.util.internal.PlatformDependent; + +import java.util.concurrent.ConcurrentMap; + +public class ClientChannelCache { + /** + * 存储用户和通道类型 + * value: 1Tcp 2WebSocket + */ + public static final ConcurrentMap channelTypes = PlatformDependent.newConcurrentHashMap(); + + /** + * 缓存通道 + */ + public static void putChannelType(String clientId, Channel channel) { + channelTypes.put(clientId, channel); + } + + /** + * 获取通道 + */ + public static Channel getChannelType(String clientId) { + return channelTypes.get(clientId); + } + + /** + * 判断通道是否存在 + */ + public static boolean contains(Integer clientId) { + return channelTypes.containsKey(clientId); + } + + /** + * 移除通道 + */ + public static void removeChannelType(Integer clientId) { + channelTypes.remove(clientId); + } +} diff --git a/netty-pad/src/main/java/com/sv/netty/config/ErrorCode.java b/netty-pad/src/main/java/com/sv/netty/config/ErrorCode.java new file mode 100644 index 0000000..a05ca71 --- /dev/null +++ b/netty-pad/src/main/java/com/sv/netty/config/ErrorCode.java @@ -0,0 +1,31 @@ +package com.sv.netty.config; + +public enum ErrorCode { + MEMBER_NOT_EXIST(10001,"用户校验失败"), + NO_ENOUGH_AMOUNT(10002,"余额不足"); + + + private int code; + private String msg; + + ErrorCode(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } +} diff --git a/netty-pad/src/main/java/com/sv/netty/controller/QRCodeControler.java b/netty-pad/src/main/java/com/sv/netty/controller/QRCodeControler.java new file mode 100644 index 0000000..93bbca7 --- /dev/null +++ b/netty-pad/src/main/java/com/sv/netty/controller/QRCodeControler.java @@ -0,0 +1,39 @@ +package com.sv.netty.controller; + +import com.sv.entity.face.FaceRecognizeResponse; +import com.sv.netty.config.ErrorCode; +import com.sv.netty.netty.ResponseDTO; +import com.sv.netty.service.impl.TcpMessageHandlerAdapter; +import com.sv.service.oms.DeviceService; +import com.sv.service.oms.VenueService; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +@RestController +public class QRCodeControler { + + /** + * 微信小程序扫码之后,通知对应的线程进入加载界面,然后随即开始判断逻辑 + * @return + */ + @RequestMapping("/scanQRCode") + public ResponseDTO scanQRCode(@RequestParam String venueId, + @RequestParam String cardType,@RequestParam String memberId) { + // 1、获取到请求,说明扫码成功,预校验余额成功,通知客户端(Android)进行加载状态。 + + // 2、进行预校验,判断是否可以进行扫码通行 // TODO check余额方法 + boolean checkResult = true; + + if(checkResult){ + // 如果是成功的 通知客户端(Android)进行开门 + return ResponseDTO.ok(); + }else { + return new ResponseDTO(ErrorCode.MEMBER_NOT_EXIST.getCode(), + ErrorCode.MEMBER_NOT_EXIST.getMsg(),System.currentTimeMillis()); + } + } + +}