diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..14c2a87
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,242 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.7.3
+
+
+ com.chaozhangui.system.cashservice
+ cashier-service
+ 1.0-SNAPSHOT
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+
+ org.apache.commons
+ commons-lang3
+
+
+
+ commons-io
+ commons-io
+ 2.4
+
+
+
+
+ org.apache.httpcomponents
+ httpclient
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ 2.4.0
+
+
+
+ cn.hutool
+ hutool-all
+ 5.7.21
+
+
+ com.alibaba
+ fastjson
+ 1.2.9
+
+
+ org.projectlombok
+ lombok
+
+
+
+ org.apache.commons
+ commons-lang3
+
+
+
+
+
+
+
+ commons-beanutils
+ commons-beanutils
+ 1.9.4
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 2.1.1
+
+
+ org.mybatis.generator
+ mybatis-generator-core
+ 1.3.5
+
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+ mysql
+ mysql-connector-java
+ runtime
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.5
+
+
+
+ org.aspectj
+ aspectjweaver
+ 1.9.5
+
+
+
+ org.springframework.boot
+ spring-boot-starter-webflux
+
+
+
+
+ com.google.guava
+ guava
+ 20.0
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.6
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.2
+
+
+
+ org.apache.httpcomponents
+ httpmime
+ 4.5.2
+
+
+
+ com.alibaba
+ fastjson
+ 1.2.48
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.2
+
+
+
+
+ io.jsonwebtoken
+ jjwt
+ 0.9.1
+
+
+
+
+ redis.clients
+ jedis
+
+
+ org.springframework.data
+ spring-data-redis
+
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
+
+
+ org.springframework.boot
+ spring-boot-starter-amqp
+ 1.5.2.RELEASE
+
+
+
+ com.github.binarywang
+ weixin-java-miniapp
+ 3.8.0
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.7.0
+
+ UTF-8
+ 1.8
+ 1.8
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ 1.4.2.RELEASE
+
+ com.chaozhanggui.system.cashierservice.Shell
+ ./
+ true
+ true
+
+
+
+
+ repackage
+
+
+
+
+
+
+
+ org.mybatis.generator
+ mybatis-generator-maven-plugin
+ 1.3.7
+
+
+ false
+
+ false
+
+ src/main/resources/generator-mapper/generatorConfig.xml
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.17
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/Shell.java b/src/main/java/com/chaozhanggui/system/cashierservice/Shell.java
new file mode 100644
index 0000000..08e4839
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/Shell.java
@@ -0,0 +1,62 @@
+package com.chaozhanggui.system.cashierservice;
+
+
+import lombok.extern.slf4j.Slf4j;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.context.ApplicationContext;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.socket.config.annotation.EnableWebSocket;
+
+import java.net.ServerSocket;
+import java.net.Socket;
+
+@SpringBootApplication
+@EnableScheduling
+@EntityScan(basePackageClasses = {Shell.class})
+@MapperScan(basePackageClasses ={Shell.class} )
+@ComponentScan(basePackageClasses ={Shell.class})
+@EnableTransactionManagement
+@EnableAspectJAutoProxy(proxyTargetClass = true)
+@Slf4j
+@EnableWebSocket
+public class Shell {
+
+ private static Logger logger = LoggerFactory.getLogger(Shell.class);
+
+ public static void main(String[] args) {
+ SpringApplication springApplication = new SpringApplication(Shell.class);
+ springApplication.run(args);
+ }
+ @Bean
+ RestTemplate restTemplate(){
+ return new RestTemplate();
+ }
+
+ @Bean
+ public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
+ return (args) -> {
+ logger.info("=========================启动完成==========================");
+ };
+ }
+
+
+ @Bean
+ public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
+ PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
+ propertySourcesPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true);
+ return propertySourcesPlaceholderConfigurer;
+ }
+
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/annotation/OpLog.java b/src/main/java/com/chaozhanggui/system/cashierservice/annotation/OpLog.java
new file mode 100644
index 0000000..1d443bb
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/annotation/OpLog.java
@@ -0,0 +1,32 @@
+package com.chaozhanggui.system.cashierservice.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author DJH
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface OpLog {
+
+ /**
+ * 操作日志code
+ * @return 操作code
+ */
+ String opCode() default "";
+
+ /**
+ * 操作日志-详情
+ * @return 操作详情
+ */
+ String opDetail() default "";
+
+ /**
+ * 操作日志名称
+ * @return 操作名称
+ */
+ String opName() default "";
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/annotation/ResultCode.java b/src/main/java/com/chaozhanggui/system/cashierservice/annotation/ResultCode.java
new file mode 100644
index 0000000..b54f9b3
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/annotation/ResultCode.java
@@ -0,0 +1,41 @@
+package com.chaozhanggui.system.cashierservice.annotation;
+
+/**
+ * 响应码枚举,参考HTTP状态码的语义
+ */
+public enum ResultCode {
+ //成功
+ SUCCESS(200),
+ //失败
+ FAIL(400),
+ //未认证(签名错误)
+ UNAUTHORIZED(401),
+ //未认证(签名错误)
+ PARAM_ERROR(422),
+ // 403
+ FORBIDDEN(403),
+ //接口不存在
+ NOT_FOUND(404),
+ //服务器内部错误
+ INTERNAL_SERVER_ERROR(500),
+ // 服务不可达
+ SERVICE_UNAVAILABLE(503),
+ //未认证(签名错误)
+ NOT_TOKEN(401),
+ //无数据
+ UNDEFINDE(201),
+ /**
+ * 交易未知 查询交易结果
+ */
+ TRANSUNKNOW(202);
+
+ private final int code;
+
+ ResultCode(int code) {
+ this.code = code;
+ }
+
+ public int code() {
+ return code;
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/config/ChangeHandler.java b/src/main/java/com/chaozhanggui/system/cashierservice/config/ChangeHandler.java
new file mode 100644
index 0000000..969a880
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/config/ChangeHandler.java
@@ -0,0 +1,35 @@
+package com.chaozhanggui.system.cashierservice.config;
+
+import com.alibaba.fastjson.JSONObject;
+import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+//处理前端改变购物车的行为,并记录
+public class ChangeHandler extends Handler {
+
+ @Override
+ public void handleRequest(ConcurrentHashMap> webSocketMap,
+ JSONObject jsonObject, ConcurrentHashMap> recordMap,
+ AppWebSocketServer webSocke) throws IOException {
+
+ if (jsonObject.containsKey("change")) {
+ ArrayList jsonObjects = new ArrayList<>();
+ jsonObjects.add(jsonObject);
+// producerMq.syncShopCar(jsonObjects);
+ //记录每一次购物车变化的记录
+ List objects = recordMap.get(webSocke.getTableId());
+ objects.add(jsonObject);
+ } else {
+ // 无法处理,传递给下一个处理器
+ if (nextHandler != null) {
+ nextHandler.handleRequest(webSocketMap,jsonObject,recordMap,webSocke);
+ }
+ }
+ }
+}
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/config/ClearHandler.java b/src/main/java/com/chaozhanggui/system/cashierservice/config/ClearHandler.java
new file mode 100644
index 0000000..c5b8981
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/config/ClearHandler.java
@@ -0,0 +1,33 @@
+package com.chaozhanggui.system.cashierservice.config;
+
+import com.alibaba.fastjson.JSONObject;
+import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+//处理前端订单已完成,把订单标志位置为false
+public class ClearHandler extends Handler{
+
+ @Override
+ public void handleRequest(ConcurrentHashMap> webSocketMap,
+ JSONObject jsonObject, ConcurrentHashMap> recordMap,
+ AppWebSocketServer webSocke) throws IOException {
+ if (jsonObject.containsKey("clear")) {
+ if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
+ List serverList = webSocketMap.get(webSocke.getTableId());
+ //遍历所有对象,把订单都改为未提交,为了下一次点餐
+ serverList.forEach(m -> m.getCreateOrder().set(false));
+
+ }
+ } else {
+ // 无法处理,传递给下一个处理器
+ if (nextHandler != null) {
+ nextHandler.handleRequest(webSocketMap,jsonObject,recordMap,webSocke);
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/config/CreateOrderHandler.java b/src/main/java/com/chaozhanggui/system/cashierservice/config/CreateOrderHandler.java
new file mode 100644
index 0000000..ef2c04c
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/config/CreateOrderHandler.java
@@ -0,0 +1,79 @@
+package com.chaozhanggui.system.cashierservice.config;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+//处理前端创建订单
+public class CreateOrderHandler extends Handler{
+
+ @Override
+ public void handleRequest(ConcurrentHashMap> webSocketMap,
+ JSONObject jsonObject, ConcurrentHashMap> recordMap,
+ AppWebSocketServer webSocke) throws IOException {
+
+
+ if (jsonObject.containsKey("createOrdwebSockeer")) {
+ if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
+ List serverList = webSocketMap.get(webSocke.getTableId());
+ //有一个为true就说明已经有订单了
+ if (serverList.stream().anyMatch(m -> m.getCreateOrder().get())) {
+ webSocke.sendMessage("已有人提交订单,请稍后");
+ return;
+ }
+ }
+ synchronized (webSocke) {
+ if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
+ List serverList = webSocketMap.get(webSocke.getTableId());
+ //有一个为true就说明已经有订单了
+ if (serverList.stream().anyMatch(m -> m.getCreateOrder().get())) {
+ webSocke.sendMessage("已有人提交订单,请稍后");
+ return;
+ }
+
+ BigDecimal amount = new BigDecimal((Integer) jsonObject.get("amount"));
+ JSONArray shopCarList = jsonObject.getJSONArray("shopCarList");
+ String remark = jsonObject.get("remark").toString();
+
+
+// List list=shopCarList.toJavaList(ShopListDto.class);
+// //TODO 加个拦截加个shopid,抛出异常,前端展示
+// setShopId(list.get(0).getShopId());
+// try {
+// Result order = orderFeign.createOrder(new CreateOrderDto(Long.parseLong(webSocke.getTableId()), amount, list, remark));
+// if (order.getCode() == 200){
+// //通知清空购物车
+// AppSendInfo("订单提交成功", webSocke.getTableId());
+// //清空本地的购物记录
+// recordMap.get(webSocke.getTableId()).clear();
+// webSocke.getCreateOrder().set(true);
+// }else {
+// AppSendInfo("订单提交失败",webSocke.getTableId());
+// }
+//
+//
+// }catch (Exception e){
+// e.printStackTrace();
+// AppSendInfo("订单提交失败",webSocke.getTableId());
+// }
+
+
+
+ }
+ }
+
+ } else {
+ // 无法处理,传递给下一个处理器
+ if (nextHandler != null) {
+ nextHandler.handleRequest(webSocketMap,jsonObject,recordMap,webSocke);
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/config/Handler.java b/src/main/java/com/chaozhanggui/system/cashierservice/config/Handler.java
new file mode 100644
index 0000000..9529bc3
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/config/Handler.java
@@ -0,0 +1,26 @@
+package com.chaozhanggui.system.cashierservice.config;
+
+import com.alibaba.fastjson.JSONObject;
+import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+public abstract class Handler {
+ protected Handler nextHandler;
+
+
+ public Handler addNextHandler(Handler handler) {
+ this.nextHandler = handler;
+ return handler;
+ }
+
+
+
+
+ public abstract void handleRequest(ConcurrentHashMap> webSocketMap,
+ JSONObject jsonObject, ConcurrentHashMap> recordMap,
+ AppWebSocketServer webSocke) throws IOException;
+}
\ No newline at end of file
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/config/OtherHandler.java b/src/main/java/com/chaozhanggui/system/cashierservice/config/OtherHandler.java
new file mode 100644
index 0000000..8fd78ee
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/config/OtherHandler.java
@@ -0,0 +1,30 @@
+package com.chaozhanggui.system.cashierservice.config;
+
+import com.alibaba.fastjson.JSONObject;
+import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer.AppSendInfo;
+
+
+//兜底处理器
+public class OtherHandler extends Handler{
+ @Override
+ public void handleRequest(ConcurrentHashMap> webSocketMap,
+ JSONObject jsonObject,
+ ConcurrentHashMap> recordMap,
+ AppWebSocketServer webSocke) throws IOException {
+
+ //传送给对应tableId用户的websocket
+ if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) {
+ AppSendInfo("1", webSocke.getTableId(),false);
+
+ } else {
+ System.out.println("请求的tableId:" + webSocke.getTableId() + "不在该服务器上");
+ }
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/config/SyncHandler.java b/src/main/java/com/chaozhanggui/system/cashierservice/config/SyncHandler.java
new file mode 100644
index 0000000..44a0298
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/config/SyncHandler.java
@@ -0,0 +1,46 @@
+package com.chaozhanggui.system.cashierservice.config;
+
+import com.alibaba.fastjson.JSONObject;
+import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+//处理前端初次扫码同步购物车
+public class SyncHandler extends Handler {
+
+ @Override
+ public void handleRequest(ConcurrentHashMap> webSocketMap,
+ JSONObject jsonObject, ConcurrentHashMap> recordMap,
+ AppWebSocketServer webSocke) throws IOException {
+ if (jsonObject.containsKey("sync")) {
+ //这个是判断是否有这个桌号,也就是 是否有人点过餐
+
+ List recordList = recordMap.get(webSocke.getTableId());
+ //指定发送对象
+ if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId()) && recordList != null) {
+ List serverList = webSocketMap.get(webSocke.getTableId());
+ for (AppWebSocketServer server : serverList) {
+ if (server.getSync().get()) {
+ server.sendMessage(recordList);
+ }
+
+ }
+ } else {
+ ArrayList objects = new ArrayList<>();
+ recordMap.put(webSocke.getTableId(), objects);
+ }
+ webSocke.getSync().set(!webSocke.getSync().get());
+
+ } else {
+ // 无法处理,传递给下一个处理器
+ if (nextHandler != null) {
+ nextHandler.handleRequest(webSocketMap, jsonObject, recordMap, webSocke);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/config/WebSocketCustomEncoding.java b/src/main/java/com/chaozhanggui/system/cashierservice/config/WebSocketCustomEncoding.java
new file mode 100644
index 0000000..33a7658
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/config/WebSocketCustomEncoding.java
@@ -0,0 +1,31 @@
+package com.chaozhanggui.system.cashierservice.config;
+
+
+import com.alibaba.fastjson.JSON;
+
+import javax.websocket.Encoder;
+import javax.websocket.EndpointConfig;
+
+/**
+ * 为了websocket发送对象
+ */
+
+public class WebSocketCustomEncoding implements Encoder.Text