whites = ignoreWhiteConfig.getWhites();
+
+ ServerHttpRequest request = exchange.getRequest();
+
+ String path = request.getURI().getPath();
+
+ if(StringUtils.matches(path,whites)){
+
+ chain.filter(exchange);
+
+ }
+
+ String first = request.getHeaders().getFirst("token");
+
+
+ if(StringUtils.isBlank(first)){
+
+ return GatewayUtils.errorResponse(exchange,"Token不可以为空");
+
+ }
+
+
+ try{
+ JwtUtils.parseToken(first);
+ }catch (Exception E){
+
+ return GatewayUtils.errorResponse(exchange,"Token不合法");
+
+ }
+
+ String userKey = JwtUtils.getUserKey(first);
+
+ String s = stringRedisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey);
+
+ if(StringUtils.isNotBlank(s)){
+ return GatewayUtils.errorResponse(exchange,"Token过期");
+ }
+
+ stringRedisTemplate.expire(TokenConstants.LOGIN_TOKEN_KEY+userKey,15,TimeUnit.MINUTES);
+
+ return chain.filter(exchange);
+ }
+
+ /**
+ * Get the order value of this object.
+ * Higher values are interpreted as lower priority. As a consequence,
+ * the object with the lowest value has the highest priority (somewhat
+ * analogous to Servlet {@code load-on-startup} values).
+ *
Same order values will result in arbitrary sort positions for the
+ * affected objects.
+ *
+ * @return the order value
+ * @see #HIGHEST_PRECEDENCE
+ * @see #LOWEST_PRECEDENCE
+ */
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+}
diff --git a/hamburg-gateway/src/main/java/com/hamburg/gateway/utils/GatewayUtils.java b/hamburg-gateway/src/main/java/com/hamburg/gateway/utils/GatewayUtils.java
new file mode 100644
index 0000000..253e013
--- /dev/null
+++ b/hamburg-gateway/src/main/java/com/hamburg/gateway/utils/GatewayUtils.java
@@ -0,0 +1,95 @@
+package com.hamburg.gateway.utils;
+
+import com.alibaba.fastjson.JSONObject;
+import com.hamburg.common.result.Result;
+import com.hamburg.common.utils.StringUtils;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.core.io.buffer.DataBuffer;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import org.springframework.http.server.reactive.ServerHttpResponse;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+
+@Log4j2
+public class GatewayUtils {
+ /**
+ * 添加请求头参数
+ * @param mutate 修改对象
+ * @param key 键
+ * @param value 值
+ */
+ public static void addHeader(ServerHttpRequest.Builder mutate, String key, Object value) {
+ if (StringUtils.isEmpty(key)){
+ log.warn("添加请求头参数键不可以为空");
+ return;
+ }
+ if (value == null) {
+ log.warn("添加请求头参数:[{}]值为空",key);
+ return;
+ }
+ String valueStr = value.toString();
+ mutate.header(key, valueStr);
+ log.info("添加请求头参数成功 - 键:[{}] , 值:[{}]", key , value);
+ }
+
+ /**
+ * 删除请求头参数
+ * @param mutate 修改对象
+ * @param key 键
+ */
+ public static void removeHeader(ServerHttpRequest.Builder mutate, String key) {
+ if (StringUtils.isEmpty(key)){
+ log.warn("删除请求头参数键不可以为空");
+ return;
+ }
+ mutate.headers(httpHeaders -> httpHeaders.remove(key)).build();
+ log.info("删除请求头参数 - 键:[{}]",key);
+ }
+
+ /**
+ * 错误结果响应
+ * @param exchange 响应上下文
+ * @param msg 响应消息
+ * @return
+ */
+ public static Mono errorResponse(ServerWebExchange exchange, String msg, HttpStatus httpStatus) {
+ ServerHttpResponse response = exchange.getResponse();
+ //设置HTTP响应头状态
+ response.setStatusCode(httpStatus);
+ //设置HTTP响应头文本格式
+ response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
+ //定义响应内容
+ Result> result = Result.error(msg);
+ String resultJson = JSONObject.toJSONString(result);
+ log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson);
+ DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes());
+ //进行响应
+ return response.writeWith(Mono.just(dataBuffer));
+ }
+
+ /**
+ * 错误结果响应
+ * @param exchange 响应上下文
+ * @param msg 响应消息
+ * @return
+ */
+ public static Mono errorResponse(ServerWebExchange exchange, String msg) {
+ ServerHttpResponse response = exchange.getResponse();
+ //设置HTTP响应头状态
+ response.setStatusCode(HttpStatus.OK);
+ //设置HTTP响应头文本格式
+ response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
+ //定义响应内容
+ Result> result = Result.error(msg);
+ String resultJson = JSONObject.toJSONString(result);
+ log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson);
+ DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes());
+ //进行响应
+ return response.writeWith(Mono.just(dataBuffer));
+ }
+
+
+}
diff --git a/hamburg-gateway/src/main/resources/bootstrap.yml b/hamburg-gateway/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..3c28634
--- /dev/null
+++ b/hamburg-gateway/src/main/resources/bootstrap.yml
@@ -0,0 +1,31 @@
+# Tomcat
+server:
+ port: 18080
+# Spring
+spring:
+ application:
+ # 应用名称
+ name: hamburg-gateway
+ profiles:
+ # 环境配置
+ active: dev
+ main:
+ # 允许使用循环引用
+ allow-circular-references: true
+ # 允许定义相同的bean对象 去覆盖原有的
+ allow-bean-definition-overriding: true
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ config:
+ # 配置中心地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
diff --git a/hamburg-modules/hamburg-coupon/pom.xml b/hamburg-modules/hamburg-coupon/pom.xml
new file mode 100644
index 0000000..115af1e
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ org.example
+ hamburg-modules
+ 1.0-SNAPSHOT
+
+
+ hamburg-coupon
+
+
+ 8
+ 8
+ UTF-8
+
+
+
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/CouponApplication.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/CouponApplication.java
new file mode 100644
index 0000000..e2640d5
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/CouponApplication.java
@@ -0,0 +1,24 @@
+package com.hamburg.coupon;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.coupon
+ * @Project:yk-8.12
+ * @name:CouponApplication
+ * @Date:2024/8/12 10:23
+ */
+@SpringBootApplication
+@EnableFeignClients
+public class CouponApplication {
+
+ public static void main(String[] args) {
+
+ SpringApplication.run(CouponApplication.class, args);
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/config/DelayedQueueUtil.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/config/DelayedQueueUtil.java
new file mode 100644
index 0000000..43eb5b9
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/config/DelayedQueueUtil.java
@@ -0,0 +1,82 @@
+package com.hamburg.coupon.config;
+
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.CustomExchange;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+
+
+@Component
+public class DelayedQueueUtil {
+
+ /**
+ * 延迟队列和延迟交换机绑定规则
+ */
+ private static final String DELAYED_ROUTING_KEY = "delayed.routingkey";
+
+ /**
+ * 延迟交换机的名称
+ */
+ private static final String DELAYED_EXCHANGE = "delayed.exchange";
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+ @Resource
+ private RabbitAdmin rabbitAdmin;
+
+ /**
+ * 发送延迟队列
+ *
+ * @param queueName 延迟队列名称
+ * @param params 消息内容
+ * @param delayedTime 延迟时间 毫秒
+ */
+ public void sendDelayedQueue(String queueName, Object params, Integer delayedTime) {
+ // 先创建一个队列
+ Queue queue = new Queue(queueName);
+ rabbitAdmin.declareQueue(queue);
+
+ // 创建延迟队列交换机
+ CustomExchange customExchange = createCustomExchange();
+ rabbitAdmin.declareExchange(customExchange);
+
+ // 将队列和交换机绑定
+ Binding binding = BindingBuilder.bind(queue).to(customExchange).with(DELAYED_ROUTING_KEY).noargs();
+ rabbitAdmin.declareBinding(binding);
+
+ // 发送延迟消息
+ rabbitTemplate.convertAndSend(DELAYED_EXCHANGE, DELAYED_ROUTING_KEY, params, msg -> {
+ // 发送消息的时候 延迟时长
+ msg.getMessageProperties().setDelay(delayedTime);
+ return msg;
+ });
+ }
+
+ /**
+ * 创建延迟交换机
+ */
+ private CustomExchange createCustomExchange() {
+ Map arguments = new HashMap<>();
+
+ /**
+ * 参数说明:
+ * 1.交换机的名称
+ * 2.交换机的类型
+ * 3.是否需要持久化
+ * 4.是否自动删除
+ * 5.其它参数
+ */
+ arguments.put("x-delayed-type", "direct");
+ return new CustomExchange(DELAYED_EXCHANGE, "x-delayed-message", true, false, arguments);
+ }
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/config/RabbitAdminConfig.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/config/RabbitAdminConfig.java
new file mode 100644
index 0000000..0aac3f1
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/config/RabbitAdminConfig.java
@@ -0,0 +1,53 @@
+package com.hamburg.coupon.config;
+
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * RabbitAdmin是RabbitMQ的一个Java客户端库,它提供了管理RabbitMQ资源的功能。它是通过与RabbitMQ服务器进行交互来执行管理操作的。
+ */
+@Configuration
+public class RabbitAdminConfig {
+
+ @Value("${spring.rabbitmq.host}")
+ private String host;
+ @Value("${spring.rabbitmq.username}")
+ private String username;
+ @Value("${spring.rabbitmq.password}")
+ private String password;
+ @Value("${spring.rabbitmq.virtualhost}")
+ private String virtualhost;
+
+ /**
+ * 构建 RabbitMQ的连接工厂
+ * @return
+ */
+ @Bean
+ public ConnectionFactory connectionFactory() {
+ CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
+ connectionFactory.setAddresses(host);
+ connectionFactory.setUsername(username);
+ connectionFactory.setPassword(password);
+ connectionFactory.setVirtualHost(virtualhost);
+ // 配置发送确认回调时,次配置必须配置,否则即使在RabbitTemplate配置了ConfirmCallback也不会生效
+ connectionFactory.setPublisherConfirmType(CachingConnectionFactory.ConfirmType.CORRELATED);
+ connectionFactory.setPublisherReturns(true);
+ return connectionFactory;
+ }
+
+ /**
+ * 自己初始化 RabbitAdmin
+ * @param connectionFactory
+ * @return
+ */
+ @Bean
+ public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
+ RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
+ rabbitAdmin.setAutoStartup(true);
+ return rabbitAdmin;
+ }
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/config/RabbitConverterConfig.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/config/RabbitConverterConfig.java
new file mode 100644
index 0000000..1a28523
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/config/RabbitConverterConfig.java
@@ -0,0 +1,18 @@
+package com.hamburg.coupon.config;
+import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
+import org.springframework.amqp.support.converter.MessageConverter;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RabbitConverterConfig {
+
+
+ //RabbitMQ 消息的转换设置
+ @Bean
+ public MessageConverter jsonMessageConverter() {
+ //SimpleMessageConverter 默认的消息转换器 String byte[] serializer
+ return new Jackson2JsonMessageConverter();
+ }
+
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/controller/CouponController.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/controller/CouponController.java
new file mode 100644
index 0000000..a282b5d
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/controller/CouponController.java
@@ -0,0 +1,59 @@
+package com.hamburg.coupon.controller;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.response.CouponResp;
+import com.hamburg.common.result.Result;
+import com.hamburg.coupon.service.CouponService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.coupon.controller
+ * @Project:yk-8.12
+ * @name:CouponController
+ * @Date:2024/8/12 10:24
+ */
+@RestController
+@RequestMapping("/coupon")
+public class CouponController {
+
+ @Autowired
+ private CouponService couponService;
+
+ /**
+ * 查询卷码的列表
+ * @return
+ */
+ @GetMapping("/findCouponList")
+ public Result> findCouponList() {
+ return Result.success(couponService.findCouponList());
+ }
+
+ /**
+ * 录入卷码
+ * @param coupon
+ * @return
+ */
+ @PostMapping("/addCoupon")
+ public Result addCoupon(@RequestBody Coupon coupon) {
+
+ return Result.success(couponService.addCoupon(coupon));
+
+ }
+
+ /**
+ * 我要卖卷 不能是别人的
+ * @return
+ */
+ @GetMapping("/sellRoll")
+ public Result> sellRoll() {
+
+ return Result.success(couponService.sellRoll());
+ }
+
+
+
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/customer/incrementalSyncCustomer.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/customer/incrementalSyncCustomer.java
new file mode 100644
index 0000000..729294f
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/customer/incrementalSyncCustomer.java
@@ -0,0 +1,68 @@
+package com.hamburg.coupon.customer;
+
+import cn.hutool.core.util.RandomUtil;
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.coupon.feign.EsServiceFeign;
+import com.rabbitmq.client.Channel;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.Queue;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.coupon.customer
+ * @Project:yk-8.12
+ * @name:incrementalSyncCustomer
+ * @Date:2024/8/12 14:33
+ */
+@Component
+public class incrementalSyncCustomer {
+
+ @Autowired
+ private EsServiceFeign esServiceFeign;
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+ @Autowired
+ private StringRedisTemplate redisTemplate;
+
+ @RabbitListener(queuesToDeclare = @Queue("coupon_add_8.12"))
+ public void sendCode(Coupon coupon, Message message, Channel channel){
+ //获取唯一的标识
+ String id = message.getMessageProperties().getMessageId();
+ //避免重复消费
+ Long key = redisTemplate.opsForSet().add("8.12_yk", id);
+ try{
+
+ if(key!=null && key==1){
+
+ System.out.println("添加的信息为哈哈哈哈哈哈:"+coupon);
+ esServiceFeign.incrementalSync(coupon);
+
+ //消息消费确认 消息插入到队列时的序号 不批量 ,只确认这单独的一条消息
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
+
+ }
+
+ }catch (IOException e){
+
+ try{
+ //删除缓存
+ redisTemplate.opsForSet().remove("8.12_yk",id);
+ //回退
+ channel.basicReject(message.getMessageProperties().getDeliveryTag(),true);
+ }catch (Exception exception){
+
+ }
+
+ }
+
+ }
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/feign/EsServiceFeign.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/feign/EsServiceFeign.java
new file mode 100644
index 0000000..82b0937
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/feign/EsServiceFeign.java
@@ -0,0 +1,26 @@
+package com.hamburg.coupon.feign;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.result.Result;
+import com.hamburg.coupon.feign.impl.EsServiceFeignImpl;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.coupon.feign
+ * @Project:yk-8.12
+ * @name:EsServiceFeign
+ * @Date:2024/8/12 14:31
+ */
+@FeignClient(name = "hamburg-es",fallback = EsServiceFeignImpl.class)
+public interface EsServiceFeign {
+ /**
+ * 异步同步到es中
+ * @param coupon
+ * @return
+ */
+ @PostMapping("/es/incrementalSync")
+ public Result incrementalSync(@RequestBody Coupon coupon);
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/feign/impl/EsServiceFeignImpl.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/feign/impl/EsServiceFeignImpl.java
new file mode 100644
index 0000000..2de9baf
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/feign/impl/EsServiceFeignImpl.java
@@ -0,0 +1,25 @@
+package com.hamburg.coupon.feign.impl;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.result.Result;
+import com.hamburg.coupon.feign.EsServiceFeign;
+import org.springframework.cloud.openfeign.FallbackFactory;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.coupon.feign.impl
+ * @Project:yk-8.12
+ * @name:EsServiceFeignImpl
+ * @Date:2024/8/12 14:32
+ */
+public class EsServiceFeignImpl implements FallbackFactory{
+ @Override
+ public EsServiceFeign create(Throwable cause) {
+ return new EsServiceFeign() {
+ @Override
+ public Result incrementalSync(Coupon coupon) {
+ return Result.error(cause.getMessage());
+ }
+ };
+ }
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/mapper/CouponMapper.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/mapper/CouponMapper.java
new file mode 100644
index 0000000..e8a2573
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/mapper/CouponMapper.java
@@ -0,0 +1,26 @@
+package com.hamburg.coupon.mapper;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.response.CouponResp;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.coupon.mapper
+ * @Project:yk-8.12
+ * @name:CouponMapper
+ * @Date:2024/8/12 10:25
+ */
+@Mapper
+public interface CouponMapper {
+
+ List findCouponList();
+
+ int addCoupon(Coupon coupon);
+
+ List sellRoll(@Param("userId") Integer userId);
+
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/service/CouponService.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/service/CouponService.java
new file mode 100644
index 0000000..20ff4cc
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/service/CouponService.java
@@ -0,0 +1,23 @@
+package com.hamburg.coupon.service;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.response.CouponResp;
+
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.coupon.service
+ * @Project:yk-8.12
+ * @name:CouponService
+ * @Date:2024/8/12 10:24
+ */
+public interface CouponService {
+
+ List findCouponList();
+
+ Integer addCoupon(Coupon coupon);
+
+ List sellRoll();
+
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/service/impl/CouponServiceImpl.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/service/impl/CouponServiceImpl.java
new file mode 100644
index 0000000..1a01fbc
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/service/impl/CouponServiceImpl.java
@@ -0,0 +1,94 @@
+package com.hamburg.coupon.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.hamburg.common.constants.TokenConstants;
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.User;
+import com.hamburg.common.domain.response.CouponResp;
+import com.hamburg.common.utils.JwtUtils;
+import com.hamburg.coupon.mapper.CouponMapper;
+import com.hamburg.coupon.service.CouponService;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Service;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.coupon.service.impl
+ * @Project:yk-8.12
+ * @name:CouponServiceImpl
+ * @Date:2024/8/12 10:24
+ */
+@Service
+public class CouponServiceImpl implements CouponService{
+
+ @Autowired
+ private CouponMapper couponMapper;
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+ @Autowired
+ private StringRedisTemplate stringRedisTemplate;
+
+
+ @Autowired
+ private HttpServletRequest httpServletRequest;
+
+
+ @Override
+ public List findCouponList() {
+ return couponMapper.findCouponList();
+ }
+
+ @Override
+ public Integer addCoupon(Coupon coupon) {
+
+ String string = JSONObject.toJSONString(coupon);
+ rabbitTemplate.convertAndSend("coupon_add_8.12",string, message -> {
+
+ message.getMessageProperties().setMessageId(UUID.randomUUID().toString().replace("-",""));
+ return message;
+
+ });
+
+ int add=couponMapper.addCoupon(coupon);
+
+ return add;
+ }
+
+ @Override
+ public List sellRoll() {
+
+ User user = getUser();
+
+ return couponMapper.sellRoll(user.getUserId());
+ }
+
+
+
+
+
+ public User getUser(){
+
+ String header = httpServletRequest.getHeader(TokenConstants.TOKEN);
+
+ String userKey = JwtUtils.getUserKey(header);
+
+
+ String s = stringRedisTemplate.opsForValue().get(TokenConstants.TOKEN+userKey);
+
+
+ User user = JSON.parseObject(s, User.class);
+
+ return user;
+ }
+
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/DLXQueue.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/DLXQueue.java
new file mode 100644
index 0000000..c1e3711
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/DLXQueue.java
@@ -0,0 +1,98 @@
+package com.hamburg.coupon.utils;
+
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.DirectExchange;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 发送TTL消息 , 消息到达指定的时间没有被消费,消息成为死信,这条死信消息 回到发送到死信交换机,死信队列跟死信交换交换机绑定
+ */
+@Component
+public class DLXQueue {
+ /**
+ * 发送死信消息 绑定规则 routingKey
+ */
+ private static final String DEAD_ROUTING_KEY = "dead.routing.key";
+
+ /**
+ * 发送ttl 消息的 绑定规则 routingKey
+ */
+ private static final String ROUTING_KEY = "routing.key";
+
+ /**
+ * 死信交换机的名称
+ */
+ private static final String DEAD_EXCHANGE = "dead.exchange";
+
+ /**
+ * ttl 交换机的名称
+ */
+ private static final String EXCHANGE = "common.exchange";
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+ @Resource
+ private RabbitAdmin rabbitAdmin;
+
+ /**
+ * 发送TTL消息,消息过期后进入死信交换机,进入死信队列
+ *
+ * @param queueName 队列名称
+ * @param deadQueueName 死信队列名称
+ * @param params 消息内容
+ * @param expiration 过期时间 毫秒
+ */
+ public void sendDLXQueue(String queueName, String deadQueueName, Object params, Integer expiration) {
+ /**
+ * ----------------------------------先创建一个ttl队列和死信队列--------------------------------------------
+ */
+ Map map = new HashMap<>();
+ // 队列设置存活时间,单位ms, 必须是整形数据。
+ map.put("x-message-ttl", expiration);
+ // 设置死信交换机
+ map.put("x-dead-letter-exchange", DEAD_EXCHANGE);
+ // 设置死信交换器路由
+ map.put("x-dead-letter-routing-key", DEAD_ROUTING_KEY);
+ /*参数1:队列名称 参数2:持久化 参数3:是否排他 参数4:自动删除队列 参数5:队列参数*/
+ Queue queue = new Queue(queueName, true, false, false, map);
+ rabbitAdmin.declareQueue(queue);
+ /**
+ * ---------------------------------创建交换机---------------------------------------------
+ */
+ DirectExchange directExchange = new DirectExchange(EXCHANGE, true, false);
+ rabbitAdmin.declareExchange(directExchange);
+ /**
+ * ---------------------------------队列绑定交换机---------------------------------------------
+ */
+ Binding binding = BindingBuilder.bind(queue).to(directExchange).with(ROUTING_KEY);
+ rabbitAdmin.declareBinding(binding);
+
+ /**
+ * ---------------------------------在创建一个死信交换机和队列,接收死信队列---------------------------------------------
+ */
+ DirectExchange deadExchange = new DirectExchange(DEAD_EXCHANGE, true, false);
+ rabbitAdmin.declareExchange(deadExchange);
+
+ Queue deadQueue = new Queue(deadQueueName, true, false, false);
+ rabbitAdmin.declareQueue(deadQueue);
+ /**
+ * ---------------------------------队列绑定死信交换机---------------------------------------------
+ */
+ // 将队列和交换机绑定
+ Binding deadbinding = BindingBuilder.bind(deadQueue).to(deadExchange).with(DEAD_ROUTING_KEY);
+ rabbitAdmin.declareBinding(deadbinding);
+
+ // 发送消息
+ rabbitTemplate.convertAndSend(EXCHANGE, ROUTING_KEY, params);
+ }
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/DelayedQueue.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/DelayedQueue.java
new file mode 100644
index 0000000..0ed541b
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/DelayedQueue.java
@@ -0,0 +1,98 @@
+package com.hamburg.coupon.utils;
+
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.CustomExchange;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 发送延迟消息
+ *
+ * @author Administrator
+ */
+@Component
+public class DelayedQueue {
+
+ /**
+ * routingKey 绑定规则
+ */
+ private static final String DELAYED_ROUTING_KEY = "delayed.routing.key";
+
+ /**
+ * 延迟队列交换机 名称
+ */
+ private static final String DELAYED_EXCHANGE = "delayed.exchange";
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+ @Autowired
+ private RabbitAdmin rabbitAdmin;
+
+ /**
+ * 发送延迟队列
+ *
+ * @param queueName 队列名称
+ * @param params 消息内容
+ * @param delayedTime 延迟时间 毫秒
+ */
+ public void sendDelayedQueue(String queueName, Object params, Integer delayedTime) {
+ // 先创建一个队列
+ Queue queue = new Queue(queueName);
+ rabbitAdmin.declareQueue(queue);
+
+ // 创建延迟队列交换机
+ CustomExchange customExchange = createCustomExchange();
+ rabbitAdmin.declareExchange(customExchange);
+
+ // 将队列和交换机绑定
+ Binding binding = BindingBuilder.bind(queue).to(customExchange).with(DELAYED_ROUTING_KEY).noargs();
+ rabbitAdmin.declareBinding(binding);
+
+ // 发送延迟消息
+ // 第四个参数: MessagePostProcessor 消息发送处理器 如果希望对发送的消息做包装 或者处理 需要用到 例如现在需要给发送的消息设置延迟时间
+ // 参数是一个接口: 那么需要给 当前接口的实现类 匿名内部类
+// MyMessagePostProcessor postProcessor = new MyMessagePostProcessor();
+// rabbitTemplate.convertAndSend(DELAYED_EXCHANGE, DELAYED_ROUTING_KEY, params, new MessagePostProcessor() {
+// @Override
+// public Message postProcessMessage(Message message) throws AmqpException {
+// // 设置消息的延迟时间
+// message.getMessageProperties().setDelay(2000);
+// return message;
+// }
+// });
+ rabbitTemplate.convertAndSend(DELAYED_EXCHANGE, DELAYED_ROUTING_KEY, params, message -> {
+ // 设置消息的延迟时间
+ message.getMessageProperties().setDelay(2000);
+ return message;
+ });
+ }
+
+ /**
+ * 构建延迟交换机
+ *
+ * @return
+ */
+ private CustomExchange createCustomExchange() {
+ Map arguments = new HashMap<>();
+ /**
+ * 参数说明:
+ * 1.交换机的名称
+ * 2.交换机的类型
+ * 3.是否需要持久化
+ * 4.是否自动删除
+ * 5.其它参数
+ */
+ arguments.put("x-delayed-type", "direct");
+ return new CustomExchange(DELAYED_EXCHANGE, "x-delayed-message", true, false, arguments);
+ }
+
+}
+
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/MyMessagePostProcessor.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/MyMessagePostProcessor.java
new file mode 100644
index 0000000..6ae7bd9
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/MyMessagePostProcessor.java
@@ -0,0 +1,14 @@
+package com.hamburg.coupon.utils;
+
+import org.springframework.amqp.AmqpException;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.core.MessagePostProcessor;
+
+public class MyMessagePostProcessor implements MessagePostProcessor {
+ @Override
+ public Message postProcessMessage(Message message) throws AmqpException {
+ // 设置消息的延迟时间
+ message.getMessageProperties().setDelay(2000);
+ return message;
+ }
+}
diff --git a/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/TtlQueue.java b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/TtlQueue.java
new file mode 100644
index 0000000..12c257e
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/java/com/hamburg/coupon/utils/TtlQueue.java
@@ -0,0 +1,67 @@
+package com.hamburg.coupon.utils;
+
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.DirectExchange;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 发送TTL消息 设置消息的过期时间
+ */
+@Component
+public class TtlQueue {
+
+ // routingKey
+ private static final String TTL_KEY = "ttl.routing.key";
+
+ private static final String TTL_EXCHANGE = "ttl.exchange";
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+ @Resource
+ RabbitAdmin rabbitAdmin;
+
+ /**
+ * 发送TTL队列
+ *
+ * @param queueName 队列名称
+ * @param params 消息内容
+ * @param expiration 过期时间 毫秒
+ */
+ public void sendTTLQueue(String queueName, Object params, Integer expiration) {
+ /**
+ * ----------------------------------先创建一个ttl队列--------------------------------------------
+ */
+ Map map = new HashMap<>();
+ // 队列设置存活时间,单位ms,必须是整形数据。
+ map.put("x-message-ttl", expiration);
+ /*参数1:队列名称 参数2:持久化 参数 3:是否排他 参数 4:自动删除队列 参数 5:队列参数*/
+ Queue queue = new Queue(queueName, true, false, false, map);
+ rabbitAdmin.declareQueue(queue);
+
+ /**
+ * ---------------------------------创建交换机---------------------------------------------
+ */
+ DirectExchange directExchange = new DirectExchange(TTL_EXCHANGE, true, false);
+ rabbitAdmin.declareExchange(directExchange);
+ /**
+ * ---------------------------------队列绑定交换机---------------------------------------------
+ */
+ // 将队列和交换机绑定
+ Binding binding = BindingBuilder.bind(queue).to(directExchange).with(TTL_KEY);
+ rabbitAdmin.declareBinding(binding);
+
+ // 发送消息
+ rabbitTemplate.convertAndSend(TTL_EXCHANGE, TTL_KEY, params);
+ }
+}
+
diff --git a/hamburg-modules/hamburg-coupon/src/main/resources/bootstrap.yml b/hamburg-modules/hamburg-coupon/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..995a1c3
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/resources/bootstrap.yml
@@ -0,0 +1,59 @@
+# Tomcat
+server:
+ port: 9005
+# Spring
+spring:
+ rabbitmq:
+ host: 124.70.191.180
+ port: 5672
+ username: guest
+ password: guest
+ virtual-host: /
+ listener:
+ simple:
+ prefetch: 1 # 每次取出一条消息消费消费完毕进行下一条
+ retry:
+ enabled: true
+ max-attempts: 3 # 重试次数
+ max-interval: 2000 # 重试间隔
+ acknowledge-mode: manual # 手动确认消息
+ publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
+ publisher-returns: true #确认消息已发送到队列(Queue)
+ main:
+ allow-circular-references: true
+ jackson:
+ date-format: yyyy-MM-dd HH:mm:ss
+ time-zone: GMT+8
+ application:
+ # 应用名称
+ name: hamburg-coupon
+ profiles:
+ # 环境配置
+ active: dev
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ config:
+ # 配置中心地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+fdfs:
+ so-timeout: 1500 # socket 连接时长
+ connect-timeout: 600 # 连接 tracker 服务器超时时长
+ # 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
+ tracker-list: 124.70.191.180:22122
+ web-server-url: 124.70.191.180:8888
+ pool:
+ jmx-enabled: false
+ # 生成缩略图
+ thumb-image:
+ height: 500
+ width: 500
diff --git a/hamburg-modules/hamburg-coupon/src/main/resources/mapper/ICouponMapper.xml b/hamburg-modules/hamburg-coupon/src/main/resources/mapper/ICouponMapper.xml
new file mode 100644
index 0000000..60ea688
--- /dev/null
+++ b/hamburg-modules/hamburg-coupon/src/main/resources/mapper/ICouponMapper.xml
@@ -0,0 +1,32 @@
+
+
+
+
+ INSERT INTO `812yk`.`t_coupon` ( `coupon_name`, `coupon_price`, `coupon_inventory`, `type_id`)
+ VALUES ( #{couponName}, #{couponPrice}, #{couponInventory}, #{typeId});
+
+
+
+ SELECT
+ t_coupon.*,
+ t_type.type_name
+ FROM
+ t_coupon
+ LEFT JOIN t_type ON t_type.type_id = t_coupon.coupon_id
+
+
+ SELECT
+ t_coupon.*,
+ t_middle.*,
+ t_user.user_id
+ FROM
+ t_middle
+ LEFT JOIN t_coupon ON t_coupon.coupon_id = t_middle.coupon_id
+ LEFT JOIN t_user ON t_user.user_id = t_user.user_id
+ WHERE
+ t_middle.user_id =#{userId}
+
+
+
diff --git a/hamburg-modules/hamburg-es/pom.xml b/hamburg-modules/hamburg-es/pom.xml
new file mode 100644
index 0000000..5ea206c
--- /dev/null
+++ b/hamburg-modules/hamburg-es/pom.xml
@@ -0,0 +1,34 @@
+
+
+ 4.0.0
+
+ org.example
+ hamburg-modules
+ 1.0-SNAPSHOT
+
+
+ hamburg-es
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+ org.example
+ hamburg-common
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.elasticsearch.client
+ elasticsearch-rest-high-level-client
+
+
+
+
diff --git a/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/EsApplication.java b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/EsApplication.java
new file mode 100644
index 0000000..297e448
--- /dev/null
+++ b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/EsApplication.java
@@ -0,0 +1,25 @@
+package com.hamburg.es;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.es
+ * @Project:yk-8.12
+ * @name:EsApplication
+ * @Date:2024/8/12 10:43
+ */
+@SpringBootApplication
+@EnableFeignClients
+public class EsApplication {
+
+ public static void main(String[] args) {
+
+ SpringApplication.run(EsApplication.class, args);
+
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/config/InitEsRes.java b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/config/InitEsRes.java
new file mode 100644
index 0000000..a588552
--- /dev/null
+++ b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/config/InitEsRes.java
@@ -0,0 +1,25 @@
+package com.hamburg.es.config;
+
+import lombok.Data;
+import org.apache.http.HttpHost;
+import org.elasticsearch.client.RestClient;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConfigurationProperties(prefix = "es")
+@Data
+public class InitEsRes {
+ private String host;
+ private int port;
+ private String scheme;
+
+ @Bean
+ public RestHighLevelClient restHighLevelClient(){
+ return new RestHighLevelClient(
+ RestClient.builder(new HttpHost(host,port,scheme))
+ );
+ }
+}
diff --git a/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/controller/EsController.java b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/controller/EsController.java
new file mode 100644
index 0000000..4013fe9
--- /dev/null
+++ b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/controller/EsController.java
@@ -0,0 +1,61 @@
+package com.hamburg.es.controller;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.request.CouponReq;
+import com.hamburg.common.domain.response.CouponResp;
+import com.hamburg.common.result.Result;
+import com.hamburg.es.service.EsService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.es.controller
+ * @Project:yk-8.12
+ * @name:EsController
+ * @Date:2024/8/12 10:45
+ */
+@RestController
+@RequestMapping("/es")
+public class EsController {
+
+ @Autowired
+ private EsService esService;
+
+ /**
+ * 查询es中列表
+ * @param couponReq 请求参数
+ * @return 返回结果
+ */
+ @PostMapping("/findCouponEsList")
+ public Result> findCouponEsList(@RequestBody CouponReq couponReq) {
+ return Result.success(esService.findCouponEsList(couponReq));
+ }
+
+ /**
+ * 批量添加
+ * @param couponList 请求参数
+ * @return 返回结果
+ */
+ @PostMapping("/batchAddEs")
+ public Result batchAddEs(@RequestBody List couponList) {
+ esService.batchAddEs(couponList);
+ return Result.success();
+ }
+
+ /**
+ * 单独添加到es中
+ * @param coupon
+ * @return
+ */
+ @PostMapping("/incrementalSync")
+ public Result incrementalSync(@RequestBody Coupon coupon) {
+
+ return Result.success(esService.incrementalSync(coupon));
+ }
+}
diff --git a/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/feign/CouponServiceFeign.java b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/feign/CouponServiceFeign.java
new file mode 100644
index 0000000..bb7d800
--- /dev/null
+++ b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/feign/CouponServiceFeign.java
@@ -0,0 +1,28 @@
+package com.hamburg.es.feign;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.response.CouponResp;
+import com.hamburg.common.result.Result;
+import com.hamburg.es.feign.impl.CouponServiceFeignImpl;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.es.feign
+ * @Project:yk-8.12
+ * @name:CouponServiceFeign
+ * @Date:2024/8/12 10:46
+ */
+@FeignClient(name = "hamburg-coupon",fallbackFactory = CouponServiceFeignImpl.class)
+public interface CouponServiceFeign {
+
+ /**
+ * 查询卷码的列表
+ * @return
+ */
+ @GetMapping("/coupon/findCouponList")
+ public Result> findCouponList();
+}
diff --git a/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/feign/impl/CouponServiceFeignImpl.java b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/feign/impl/CouponServiceFeignImpl.java
new file mode 100644
index 0000000..4a94e35
--- /dev/null
+++ b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/feign/impl/CouponServiceFeignImpl.java
@@ -0,0 +1,34 @@
+package com.hamburg.es.feign.impl;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.response.CouponResp;
+import com.hamburg.common.result.Result;
+import com.hamburg.es.feign.CouponServiceFeign;
+import org.springframework.cloud.openfeign.FallbackFactory;
+
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.es.service.impl
+ * @Project:yk-8.12
+ * @name:CouponServiceFeignImpl
+ * @Date:2024/8/12 10:47
+ */
+public class CouponServiceFeignImpl implements FallbackFactory{
+ @Override
+ public CouponServiceFeign create(Throwable cause) {
+ return new CouponServiceFeign() {
+
+ /**
+ * 查询卷码的列表
+ *
+ * @return
+ */
+ @Override
+ public Result> findCouponList() {
+ return Result.error(cause.getMessage());
+ }
+ };
+ }
+}
diff --git a/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/service/EsService.java b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/service/EsService.java
new file mode 100644
index 0000000..da7d8a2
--- /dev/null
+++ b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/service/EsService.java
@@ -0,0 +1,25 @@
+package com.hamburg.es.service;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.request.CouponReq;
+import com.hamburg.common.domain.response.CouponResp;
+
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.es.service
+ * @Project:yk-8.12
+ * @name:EsService
+ * @Date:2024/8/12 10:45
+ */
+public interface EsService {
+ List findCouponEsList(CouponReq couponReq);
+
+ void batchAddEs(List couponReqList);
+
+ void deleteIndex();
+
+ String incrementalSync(Coupon coupon);
+
+}
diff --git a/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/service/impl/EsServiceImpl.java b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/service/impl/EsServiceImpl.java
new file mode 100644
index 0000000..91acb6c
--- /dev/null
+++ b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/service/impl/EsServiceImpl.java
@@ -0,0 +1,206 @@
+package com.hamburg.es.service.impl;
+
+
+import com.alibaba.fastjson.JSONObject;
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.request.CouponReq;
+import com.hamburg.common.domain.response.CouponResp;
+import com.hamburg.common.utils.StringUtils;
+import com.hamburg.es.service.EsService;
+import org.elasticsearch.action.bulk.BulkRequest;
+import org.elasticsearch.action.index.IndexRequest;
+import org.elasticsearch.action.search.SearchRequest;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.client.RequestOptions;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.elasticsearch.common.text.Text;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.index.query.BoolQueryBuilder;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.index.reindex.DeleteByQueryRequest;
+import org.elasticsearch.search.SearchHit;
+import org.elasticsearch.search.SearchHits;
+import org.elasticsearch.search.builder.SearchSourceBuilder;
+import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
+import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.es.service.impl
+ * @Project:yk-8.12
+ * @name:EsServiceImpl
+ * @Date:2024/8/12 10:46
+ */
+@Service
+public class EsServiceImpl implements EsService{
+
+ @Autowired
+ private RestHighLevelClient restHighLevelClient;
+
+
+
+ @Override
+ public List findCouponEsList(CouponReq couponReq) {
+
+
+ List couponList = new ArrayList<>();
+
+ try {
+
+ SearchRequest request = new SearchRequest("812yk_coupon");
+
+ SearchSourceBuilder builder = new SearchSourceBuilder();
+
+ BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
+
+
+ if (StringUtils.isNotBlank(couponReq.getCouponName())) {
+
+ queryBuilder.must(QueryBuilders.matchQuery("couponName", couponReq.getCouponName()));
+
+ }
+
+ builder.query(queryBuilder);
+
+
+ builder.highlighter(
+ new HighlightBuilder()
+ .field("couponName")
+ .preTags("")
+ .postTags(" ")
+ );
+
+ request.source(builder);
+
+
+ SearchResponse search = restHighLevelClient.search(request, RequestOptions.DEFAULT);
+
+ SearchHits hits = search.getHits();
+
+
+ SearchHit[] hitsHits = hits.getHits();
+
+ for (SearchHit hitsHit : hitsHits) {
+
+ String source = hitsHit.getSourceAsString();
+
+ CouponResp coupon = JSONObject.parseObject(source, CouponResp.class);
+
+ coupon.setCouponId(Integer.valueOf(hitsHit.getId()));
+
+
+ Map highlightFields = hitsHit.getHighlightFields();
+
+ if (highlightFields != null) {
+
+ HighlightField couponName = highlightFields.get("couponName");
+
+ if (couponName != null) {
+
+ String str = "";
+
+ Text[] fragments = couponName.getFragments();
+
+
+ for (Text fragment : fragments) {
+
+ str += fragment;
+
+ }
+
+ coupon.setCouponName(str);
+
+ }
+ couponList.add(coupon);
+
+ }
+
+
+
+ }
+
+ } catch (IOException e) {
+
+
+ }
+ return couponList;
+ }
+
+
+ @Override
+ public void batchAddEs(List couponList) {
+ try{
+
+ BulkRequest bulkRequest = new BulkRequest();
+
+ couponList.forEach(coupon -> {
+ bulkRequest.add(
+ new IndexRequest("812yk_coupon")
+ .id(coupon.getCouponId()+"")
+ .source(JSONObject.toJSONString(coupon), XContentType.JSON)
+ );
+ });
+
+ restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
+
+
+ }catch (IOException e){
+
+
+ }
+
+
+ }
+
+ @Override
+ public void deleteIndex() {
+ try{
+
+ DeleteByQueryRequest request = new DeleteByQueryRequest();
+
+ BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
+
+
+ request.setQuery(queryBuilder);
+
+ restHighLevelClient.deleteByQuery(request,RequestOptions.DEFAULT);
+
+ }catch (IOException E){
+
+
+
+ }
+
+ }
+
+ @Override
+ public String incrementalSync(Coupon coupon) {
+
+ try{
+
+ IndexRequest request = new IndexRequest("812yk_coupon");
+
+ request.id(coupon.getCouponId()+"");
+
+ request.source(JSONObject.toJSONString(coupon), XContentType.JSON);
+
+ restHighLevelClient.index(request, RequestOptions.DEFAULT);
+
+ }catch (IOException E){
+
+
+ }
+
+ return "添加成功";
+ }
+
+}
diff --git a/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/sync/SyncEs.java b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/sync/SyncEs.java
new file mode 100644
index 0000000..ba6f43b
--- /dev/null
+++ b/hamburg-modules/hamburg-es/src/main/java/com/hamburg/es/sync/SyncEs.java
@@ -0,0 +1,49 @@
+package com.hamburg.es.sync;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.response.CouponResp;
+import com.hamburg.common.result.Result;
+import com.hamburg.es.feign.CouponServiceFeign;
+import com.hamburg.es.service.EsService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.es.sync
+ * @Project:yk-8.12
+ * @name:SyncEs
+ * @Date:2024/8/12 10:45
+ */
+@Component
+public class SyncEs {
+
+
+
+ @Autowired
+ private CouponServiceFeign couponServiceFeign;
+
+ @Autowired
+ private EsService esService;
+
+ @PostConstruct
+ public void init() {
+
+ Result> couponList = couponServiceFeign.findCouponList();
+
+ List data = couponList.getData();
+
+ if(data.size() > 0) {
+
+ esService.batchAddEs(data);
+
+ }
+
+
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-es/src/main/resources/bootstrap.yml b/hamburg-modules/hamburg-es/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..ef8ae39
--- /dev/null
+++ b/hamburg-modules/hamburg-es/src/main/resources/bootstrap.yml
@@ -0,0 +1,59 @@
+# Tomcat
+server:
+ port: 9006
+# Spring
+spring:
+ rabbitmq:
+ host: 124.70.191.180
+ port: 5672
+ username: guest
+ password: guest
+ virtual-host: /
+ listener:
+ simple:
+ prefetch: 1 # 每次取出一条消息消费消费完毕进行下一条
+ retry:
+ enabled: true
+ max-attempts: 3 # 重试次数
+ max-interval: 2000 # 重试间隔
+ acknowledge-mode: manual # 手动确认消息
+ publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
+ publisher-returns: true #确认消息已发送到队列(Queue)
+ main:
+ allow-circular-references: true
+ jackson:
+ date-format: yyyy-MM-dd HH:mm:ss
+ time-zone: GMT+8
+ application:
+ # 应用名称
+ name: hamburg-es
+ profiles:
+ # 环境配置
+ active: dev
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ config:
+ # 配置中心地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+fdfs:
+ so-timeout: 1500 # socket 连接时长
+ connect-timeout: 600 # 连接 tracker 服务器超时时长
+ # 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
+ tracker-list: 124.70.191.180:22122
+ web-server-url: 124.70.191.180:8888
+ pool:
+ jmx-enabled: false
+ # 生成缩略图
+ thumb-image:
+ height: 500
+ width: 500
diff --git a/hamburg-modules/hamburg-order/pom.xml b/hamburg-modules/hamburg-order/pom.xml
new file mode 100644
index 0000000..135bad0
--- /dev/null
+++ b/hamburg-modules/hamburg-order/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ org.example
+ hamburg-modules
+ 1.0-SNAPSHOT
+
+
+ hamburg-order
+
+
+ 8
+ 8
+ UTF-8
+
+
+
diff --git a/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/OrderApplication.java b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/OrderApplication.java
new file mode 100644
index 0000000..15ed25a
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/OrderApplication.java
@@ -0,0 +1,24 @@
+package com.hamburg.order;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.order
+ * @Project:yk-8.12
+ * @name:OrderApplication
+ * @Date:2024/8/12 15:45
+ */
+@EnableScheduling
+@SpringBootApplication
+public class OrderApplication {
+
+ public static void main(String[] args) {
+
+ SpringApplication.run(OrderApplication.class, args);
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/config/DelayedQueueUtil.java b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/config/DelayedQueueUtil.java
new file mode 100644
index 0000000..c5cada6
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/config/DelayedQueueUtil.java
@@ -0,0 +1,82 @@
+package com.hamburg.order.config;
+
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.CustomExchange;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+
+
+@Component
+public class DelayedQueueUtil {
+
+ /**
+ * 延迟队列和延迟交换机绑定规则
+ */
+ private static final String DELAYED_ROUTING_KEY = "delayed.routingkey";
+
+ /**
+ * 延迟交换机的名称
+ */
+ private static final String DELAYED_EXCHANGE = "delayed.exchange";
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+ @Resource
+ private RabbitAdmin rabbitAdmin;
+
+ /**
+ * 发送延迟队列
+ *
+ * @param queueName 延迟队列名称
+ * @param params 消息内容
+ * @param delayedTime 延迟时间 毫秒
+ */
+ public void sendDelayedQueue(String queueName, Object params, Integer delayedTime) {
+ // 先创建一个队列
+ Queue queue = new Queue(queueName);
+ rabbitAdmin.declareQueue(queue);
+
+ // 创建延迟队列交换机
+ CustomExchange customExchange = createCustomExchange();
+ rabbitAdmin.declareExchange(customExchange);
+
+ // 将队列和交换机绑定
+ Binding binding = BindingBuilder.bind(queue).to(customExchange).with(DELAYED_ROUTING_KEY).noargs();
+ rabbitAdmin.declareBinding(binding);
+
+ // 发送延迟消息
+ rabbitTemplate.convertAndSend(DELAYED_EXCHANGE, DELAYED_ROUTING_KEY, params, msg -> {
+ // 发送消息的时候 延迟时长
+ msg.getMessageProperties().setDelay(delayedTime);
+ return msg;
+ });
+ }
+
+ /**
+ * 创建延迟交换机
+ */
+ private CustomExchange createCustomExchange() {
+ Map arguments = new HashMap<>();
+
+ /**
+ * 参数说明:
+ * 1.交换机的名称
+ * 2.交换机的类型
+ * 3.是否需要持久化
+ * 4.是否自动删除
+ * 5.其它参数
+ */
+ arguments.put("x-delayed-type", "direct");
+ return new CustomExchange(DELAYED_EXCHANGE, "x-delayed-message", true, false, arguments);
+ }
+}
diff --git a/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/config/RabbitAdminConfig.java b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/config/RabbitAdminConfig.java
new file mode 100644
index 0000000..7dddd39
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/config/RabbitAdminConfig.java
@@ -0,0 +1,53 @@
+package com.hamburg.order.config;
+
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * RabbitAdmin是RabbitMQ的一个Java客户端库,它提供了管理RabbitMQ资源的功能。它是通过与RabbitMQ服务器进行交互来执行管理操作的。
+ */
+@Configuration
+public class RabbitAdminConfig {
+
+ @Value("${spring.rabbitmq.host}")
+ private String host;
+ @Value("${spring.rabbitmq.username}")
+ private String username;
+ @Value("${spring.rabbitmq.password}")
+ private String password;
+ @Value("${spring.rabbitmq.virtualhost}")
+ private String virtualhost;
+
+ /**
+ * 构建 RabbitMQ的连接工厂
+ * @return
+ */
+ @Bean
+ public ConnectionFactory connectionFactory() {
+ CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
+ connectionFactory.setAddresses(host);
+ connectionFactory.setUsername(username);
+ connectionFactory.setPassword(password);
+ connectionFactory.setVirtualHost(virtualhost);
+ // 配置发送确认回调时,次配置必须配置,否则即使在RabbitTemplate配置了ConfirmCallback也不会生效
+ connectionFactory.setPublisherConfirmType(CachingConnectionFactory.ConfirmType.CORRELATED);
+ connectionFactory.setPublisherReturns(true);
+ return connectionFactory;
+ }
+
+ /**
+ * 自己初始化 RabbitAdmin
+ * @param connectionFactory
+ * @return
+ */
+ @Bean
+ public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
+ RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
+ rabbitAdmin.setAutoStartup(true);
+ return rabbitAdmin;
+ }
+}
diff --git a/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/config/RabbitConverterConfig.java b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/config/RabbitConverterConfig.java
new file mode 100644
index 0000000..e40e65e
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/config/RabbitConverterConfig.java
@@ -0,0 +1,18 @@
+package com.hamburg.order.config;
+import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
+import org.springframework.amqp.support.converter.MessageConverter;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RabbitConverterConfig {
+
+
+ //RabbitMQ 消息的转换设置
+ @Bean
+ public MessageConverter jsonMessageConverter() {
+ //SimpleMessageConverter 默认的消息转换器 String byte[] serializer
+ return new Jackson2JsonMessageConverter();
+ }
+
+}
diff --git a/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/controller/OrderController.java b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/controller/OrderController.java
new file mode 100644
index 0000000..d115ec8
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/controller/OrderController.java
@@ -0,0 +1,125 @@
+package com.hamburg.order.controller;
+
+import com.hamburg.common.domain.Order;
+import com.hamburg.common.result.Result;
+import com.hamburg.order.service.OrderService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.order.controller
+ * @Project:yk-8.12
+ * @name:OrderController
+ * @Date:2024/8/12 15:45
+ */
+@RestController
+@RequestMapping("/order")
+public class OrderController {
+
+ @Autowired
+ private OrderService orderService;
+
+ /**
+ * 寄售后生成寄售订单
+ * @param order
+ * @return
+ */
+ @PostMapping("/orderConsignment")
+ public Result orderConsignment(@RequestBody Order order) {
+
+ return Result.success(orderService.orderConsignment(order));
+
+ }
+
+ /**
+ * 完成订单 给用户余额加钱
+ * @param orderId
+ * @return
+ */
+ @PostMapping("/completeOrder")
+ public Result completeOrder(@RequestParam("orderId") Integer orderId) {
+
+ return Result.success(orderService.completeOrder(orderId));
+
+ }
+
+ /**
+ * 根据选择的保质时长 计算价格 12
+ * @param orderPrice
+ * @return
+ */
+ @PostMapping("/warrantyDuration12")
+ public Result warrantyDuration12(@RequestParam("orderPrice") BigDecimal orderPrice) {
+
+ BigDecimal multiply = orderPrice.multiply(BigDecimal.valueOf((1+0.005)));
+
+ return Result.success(multiply);
+
+ }
+
+ /**
+ * 根据选择的保质时长 计算价格 24
+ * @param orderPrice
+ * @return
+ */
+ @PostMapping("/warrantyDuration24")
+ public Result warrantyDuration24(@RequestParam("orderPrice") BigDecimal orderPrice) {
+
+ BigDecimal multiply = orderPrice.multiply(BigDecimal.valueOf((1+0.01)));
+
+ return Result.success(multiply);
+ }
+
+ /**
+ * 根据选择的保质时长 计算价格 48
+ * @param orderPrice
+ * @return
+ */
+ @PostMapping("/warrantyDuration48")
+ public Result warrantyDuration48(@RequestParam("orderPrice") BigDecimal orderPrice) {
+
+ BigDecimal multiply = orderPrice.multiply(BigDecimal.valueOf((1+0.02)));
+ return Result.success(multiply);
+ }
+
+ /**
+ * 订单列表
+ * @return
+ */
+ @GetMapping("/findOrderList")
+ public Result> findOrderList() {
+
+ return Result.success(orderService.findOrderList());
+
+ }
+
+ /**
+ * 确认收货
+ * @param orderId 订单ID
+ * @return 返回结果
+ */
+ @PostMapping("/confirmReceiptOfGoods")
+ public Result confirmReceiptOfGoods(@RequestParam("orderId") Integer orderId) {
+
+ return Result.success(orderService.confirmReceiptOfGoods(orderId));
+ }
+
+
+ /**
+ *取消后买后,减少MySQL库存,并且异步更改redis当中的库存
+ * @param orderId
+ * @return
+ */
+ @PostMapping("/cancelPurchase")
+ public Result cancelPurchase(@RequestParam("orderId") Integer orderId) {
+
+
+ return Result.success(orderService.cancelPurchase(orderId));
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/customer/CancelOrder.java b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/customer/CancelOrder.java
new file mode 100644
index 0000000..48bf97b
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/customer/CancelOrder.java
@@ -0,0 +1,73 @@
+package com.hamburg.order.customer;
+
+import com.hamburg.common.domain.Order;
+import com.hamburg.order.mapper.OrderMapper;
+import com.rabbitmq.client.Channel;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.Queue;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.order.customer
+ * @Project:yk-8.12
+ * @name:cancelOrder
+ * @Date:2024/8/12 19:41
+ */
+@Component
+public class CancelOrder {
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+
+ @Autowired
+ private StringRedisTemplate redisTemplate;
+
+ @Autowired
+ private OrderMapper orderMapper;
+
+
+
+ @RabbitListener(queuesToDeclare = @Queue("changeRedisAsynchronously"))
+ public void sendCode(String couponName, Message message, Channel channel){
+ //获取唯一的标识
+ String id = message.getMessageProperties().getMessageId();
+ //避免重复消费
+ Long key = redisTemplate.opsForSet().add("changeRedisAsynchronously_decrement", id);
+ try{
+
+ if(key!=null && key==1){
+
+
+ //自减
+ redisTemplate.opsForValue().decrement(couponName);
+
+ //消息消费确认 消息插入到队列时的序号 不批量 ,只确认这单独的一条消息
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
+
+ }
+
+ }catch (IOException e){
+
+ try{
+ //删除缓存
+ redisTemplate.opsForSet().remove("changeRedisAsynchronously_decrement",id);
+ //回退
+ channel.basicReject(message.getMessageProperties().getDeliveryTag(),true);
+ }catch (Exception exception){
+
+ }
+
+ }
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/customer/OrderCustomer.java b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/customer/OrderCustomer.java
new file mode 100644
index 0000000..4c4846a
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/customer/OrderCustomer.java
@@ -0,0 +1,78 @@
+package com.hamburg.order.customer;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.Order;
+import com.hamburg.order.mapper.OrderMapper;
+import com.hamburg.order.service.OrderService;
+import com.rabbitmq.client.Channel;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.Queue;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.order.customer
+ * @Project:yk-8.12
+ * @name:OrderCustomer
+ * @Date:2024/8/12 18:24
+ */
+@Component
+public class OrderCustomer {
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+
+ @Autowired
+ private StringRedisTemplate redisTemplate;
+
+ @Autowired
+ private OrderMapper orderMapper;
+
+
+
+ @RabbitListener(queuesToDeclare = @Queue("8.12-yk-updStatus"))
+ public void sendCode(Order order, Message message, Channel channel){
+ //获取唯一的标识
+ String id = message.getMessageProperties().getMessageId();
+ //避免重复消费
+ Long key = redisTemplate.opsForSet().add("8.12_yk_upd_status", id);
+ try{
+
+ if(key!=null && key==1){
+
+ Integer userId = order.getUserId();
+
+ BigDecimal orderMoney = order.getOrderMoney();
+
+ orderMapper.updUserMoney(userId,orderMoney);
+
+
+ //消息消费确认 消息插入到队列时的序号 不批量 ,只确认这单独的一条消息
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
+
+ }
+
+ }catch (IOException e){
+
+ try{
+ //删除缓存
+ redisTemplate.opsForSet().remove("8.12_yk_upd_status",id);
+ //回退
+ channel.basicReject(message.getMessageProperties().getDeliveryTag(),true);
+ }catch (Exception exception){
+
+ }
+
+ }
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/mapper/OrderMapper.java b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/mapper/OrderMapper.java
new file mode 100644
index 0000000..e2d2001
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/mapper/OrderMapper.java
@@ -0,0 +1,41 @@
+package com.hamburg.order.mapper;
+
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.Order;
+import com.hamburg.common.domain.User;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.order.mapper
+ * @Project:yk-8.12
+ * @name:OrderMapper
+ * @Date:2024/8/12 15:47
+ */
+@Mapper
+public interface OrderMapper {
+ int orderConsignment(Order order);
+
+ Order findOrderId(@Param("orderId") Integer orderId);
+
+ int updUserMoney(@Param("userId") Integer userId, @Param("orderMoney") BigDecimal orderMoney);
+
+ User findUserId(@Param("userId") Integer userId);
+
+ List findOrderList();
+
+ int updOrderStatus(@Param("orderId") Integer orderId);
+
+ List unconfirmedList();
+
+ void confirmationState(@Param("orderId") Integer orderId);
+
+ Coupon findCouponList(@Param("couponId") Integer couponId);
+
+ int updOrderNum(@Param("couponId") Integer couponId);
+
+}
diff --git a/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/service/OrderService.java b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/service/OrderService.java
new file mode 100644
index 0000000..6b04a3d
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/service/OrderService.java
@@ -0,0 +1,32 @@
+package com.hamburg.order.service;
+
+import com.hamburg.common.domain.Order;
+import org.apache.ibatis.annotations.Param;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.order.service
+ * @Project:yk-8.12
+ * @name:OrderService
+ * @Date:2024/8/12 15:46
+ */
+public interface OrderService {
+ Integer orderConsignment(Order order);
+
+ Integer completeOrder(Integer orderId);
+
+ List findOrderList();
+
+ Integer confirmReceiptOfGoods(Integer orderId);
+
+
+ Integer cancelPurchase(Integer orderId);
+
+ List unconfirmedList();
+
+ void updOrderStatus(Integer orderId);
+
+}
diff --git a/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/service/impl/OrderServiceImpl.java b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/service/impl/OrderServiceImpl.java
new file mode 100644
index 0000000..1425aac
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/service/impl/OrderServiceImpl.java
@@ -0,0 +1,174 @@
+package com.hamburg.order.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.hamburg.common.constants.TokenConstants;
+import com.hamburg.common.domain.Coupon;
+import com.hamburg.common.domain.Order;
+import com.hamburg.common.domain.User;
+import com.hamburg.common.utils.JwtUtils;
+import com.hamburg.order.mapper.OrderMapper;
+import com.hamburg.order.service.OrderService;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Service;
+
+import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.order.service.impl
+ * @Project:yk-8.12
+ * @name:OrderServiceImpl
+ * @Date:2024/8/12 15:46
+ */
+@Service
+public class OrderServiceImpl implements OrderService{
+
+ @Autowired
+ private OrderMapper orderMapper;
+
+ @Autowired
+ private StringRedisTemplate stringRedisTemplate;
+
+ @Autowired
+ private HttpServletRequest httpServletRequest;
+
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+
+ @Override
+ public Integer orderConsignment(Order order) {
+
+ User user = getUser();
+ order.setUserId(user.getUserId());
+ int add=orderMapper.orderConsignment(order);
+
+ Coupon coupon=orderMapper.findCouponList(order.getCouponId());
+
+ stringRedisTemplate.opsForValue().set(order.getCouponName(),coupon.getCouponInventory());
+ if(add>0){
+
+ //自增
+ stringRedisTemplate.opsForValue().increment(order.getCouponName());
+
+ String orderString = JSONObject.toJSONString(order);
+
+ stringRedisTemplate.opsForValue().set(String.valueOf(order.getOrderId()),orderString);
+
+ }
+
+ return add;
+ }
+
+ @Override
+ public Integer completeOrder(Integer orderId) {
+
+ Order order=orderMapper.findOrderId(orderId);
+
+ int upd=0;
+ if(order!=null){
+
+ User user=orderMapper.findUserId(order.getUserId());
+
+ BigDecimal userBalance = user.getUserBalance();
+
+ BigDecimal orderMoney=userBalance.add(order.getOrderMoney());
+
+ upd=orderMapper.updUserMoney(user.getUserId(),orderMoney);
+
+ }
+
+ return upd;
+ }
+
+ @Override
+ public List findOrderList() {
+ return orderMapper.findOrderList();
+ }
+
+ @Override
+ public Integer confirmReceiptOfGoods(Integer orderId) {
+ Order order = orderMapper.findOrderId(orderId);
+
+
+ //修改订单状态为已完成
+ int upd=orderMapper.updOrderStatus(order.getOrderId());
+
+
+ if(upd>0){
+
+ //MQ异步给客户加款
+ rabbitTemplate.convertAndSend("8.12-yk-updStatus",order,message -> {
+
+
+ message.getMessageProperties().setMessageId(UUID.randomUUID().toString().replace("-",""));
+
+ return message;
+
+ });
+
+
+ }
+
+ return upd;
+ }
+
+ @Override
+ public Integer cancelPurchase(Integer orderId) {
+
+ Order order = orderMapper.findOrderId(orderId);
+
+ Coupon coupon=orderMapper.findCouponList(order.getCouponId());
+
+ int upd=orderMapper.updOrderNum(coupon.getCouponId());
+
+ if(upd>0){
+
+ //异步更改Redis里面的库存
+ rabbitTemplate.convertAndSend("changeRedisAsynchronously",order.getCouponName(),message -> {
+
+ message.getMessageProperties().setMessageId(UUID.randomUUID().toString().replace("-",""));
+
+ return message;
+ });
+
+ }
+
+ return upd;
+ }
+
+ @Override
+ public List unconfirmedList() {
+ return orderMapper.unconfirmedList();
+ }
+
+ @Override
+ public void updOrderStatus(Integer orderId) {
+ orderMapper.updOrderStatus(orderId);
+ }
+
+
+ public User getUser(){
+
+ String header = httpServletRequest.getHeader(TokenConstants.TOKEN);
+
+ String userKey = JwtUtils.getUserKey(header);
+
+
+ String s = stringRedisTemplate.opsForValue().get(TokenConstants.TOKEN+userKey);
+
+
+ User user = JSON.parseObject(s, User.class);
+
+ return user;
+ }
+}
diff --git a/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/task/scheduledTask.java b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/task/scheduledTask.java
new file mode 100644
index 0000000..ebfe68f
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/java/com/hamburg/order/task/scheduledTask.java
@@ -0,0 +1,44 @@
+package com.hamburg.order.task;
+
+import com.hamburg.common.domain.Order;
+import com.hamburg.order.service.OrderService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.order.task
+ * @Project:yk-8.12
+ * @name:scheduledTask
+ * @Date:2024/8/12 20:02
+ */
+@Component
+public class scheduledTask {
+
+ @Autowired
+ private OrderService orderService;
+
+ //秒 分 时 日 月 年
+ @Scheduled(cron = "* * * 2 * ?")
+ public void task(){
+
+ List orders = orderService.unconfirmedList();
+
+ if(orders.size() > 0){
+
+ orders.forEach(order -> {
+
+ orderService.updOrderStatus(order.getOrderId());
+
+ });
+
+ }
+
+
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-order/src/main/resources/bootstrap.yml b/hamburg-modules/hamburg-order/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..aae486d
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/resources/bootstrap.yml
@@ -0,0 +1,59 @@
+# Tomcat
+server:
+ port: 9008
+# Spring
+spring:
+ rabbitmq:
+ host: 124.70.191.180
+ port: 5672
+ username: guest
+ password: guest
+ virtual-host: /
+ listener:
+ simple:
+ prefetch: 1 # 每次取出一条消息消费消费完毕进行下一条
+ retry:
+ enabled: true
+ max-attempts: 3 # 重试次数
+ max-interval: 2000 # 重试间隔
+ acknowledge-mode: manual # 手动确认消息
+ publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
+ publisher-returns: true #确认消息已发送到队列(Queue)
+ main:
+ allow-circular-references: true
+ jackson:
+ date-format: yyyy-MM-dd HH:mm:ss
+ time-zone: GMT+8
+ application:
+ # 应用名称
+ name: hamburg-order
+ profiles:
+ # 环境配置
+ active: dev
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ config:
+ # 配置中心地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+fdfs:
+ so-timeout: 1500 # socket 连接时长
+ connect-timeout: 600 # 连接 tracker 服务器超时时长
+ # 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
+ tracker-list: 124.70.191.180:22122
+ web-server-url: 124.70.191.180:8888
+ pool:
+ jmx-enabled: false
+ # 生成缩略图
+ thumb-image:
+ height: 500
+ width: 500
diff --git a/hamburg-modules/hamburg-order/src/main/resources/mapper/IOrderMapper.xml b/hamburg-modules/hamburg-order/src/main/resources/mapper/IOrderMapper.xml
new file mode 100644
index 0000000..9dd776f
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/main/resources/mapper/IOrderMapper.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+ INSERT INTO `812yk`.`t_order` ( `order_details`, `order_status`, `order_money`, `coupon_id`, `user_id`, `order_time`, `order_validity`)
+ VALUES ( #{orderDetails}, 0, #{orderMoney}, #{couponId}, #{userId}, now(),#{orderValidity});
+
+
+ UPDATE t_user
+ SET user_balance = #{orderMoney}
+ WHERE
+ user_id = #{userId}
+
+
+ update t_order set order_status=1 where order_id=#{orderId}
+
+
+
+ update t_order set order_status=1 where order_id=#{orderId}
+
+
+ update t_coupon set coupon_inventory=coupon_inventory-1 where coupon_id=#{couponId}
+
+
+ select * from t_order where order_id=#{orderId}
+
+
+ select * from t_user where user_id=#{userId}
+
+
+ SELECT
+ t_order.*,
+ t_coupon.coupon_name
+ FROM
+ t_order
+ LEFT JOIN t_coupon ON t_coupon.coupon_id = t_order.coupon_id
+
+
+ SELECT * FROM t_order WHERE order_time > DATE_ADD( now(), INTERVAL 2 DAY )
+
+
+ select * from t_coupon where coupon_id=#{couponId}
+
+
+
diff --git a/hamburg-modules/hamburg-order/src/test/java/Tets.java b/hamburg-modules/hamburg-order/src/test/java/Tets.java
new file mode 100644
index 0000000..c45bbcd
--- /dev/null
+++ b/hamburg-modules/hamburg-order/src/test/java/Tets.java
@@ -0,0 +1,40 @@
+import java.math.BigDecimal;
+
+/**
+ * @Author:liuxinyue
+ * @Package:PACKAGE_NAME
+ * @Project:yk-8.12
+ * @name:Tets
+ * @Date:2024/8/12 16:12
+ */
+public class Tets {
+
+ public static void main(String[] args) {
+
+ BigDecimal a=BigDecimal.valueOf(12.2);
+ BigDecimal b=BigDecimal.valueOf((1+0.005));
+
+ //拼接
+ BigDecimal multiply = b.multiply(a);
+
+ System.out.println(multiply);
+
+
+ //相加
+ BigDecimal add = a.add(b);
+
+ System.out.println(add);
+
+
+ //除
+ BigDecimal divide = a.divide(b);
+ System.out.println(divide);
+
+ //
+
+
+
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-type/pom.xml b/hamburg-modules/hamburg-type/pom.xml
new file mode 100644
index 0000000..25dd6a4
--- /dev/null
+++ b/hamburg-modules/hamburg-type/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ org.example
+ hamburg-modules
+ 1.0-SNAPSHOT
+
+
+ hamburg-type
+
+
+ 8
+ 8
+ UTF-8
+
+
+
diff --git a/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/TypeApplication.java b/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/TypeApplication.java
new file mode 100644
index 0000000..4f28ee7
--- /dev/null
+++ b/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/TypeApplication.java
@@ -0,0 +1,22 @@
+package com.hamburg.type;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.type
+ * @Project:yk-8.12
+ * @name:TypeApplication
+ * @Date:2024/8/12 14:19
+ */
+@SpringBootApplication
+public class TypeApplication {
+
+ public static void main(String[] args) {
+
+ SpringApplication.run(TypeApplication.class, args);
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/controller/TypeController.java b/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/controller/TypeController.java
new file mode 100644
index 0000000..cbc6030
--- /dev/null
+++ b/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/controller/TypeController.java
@@ -0,0 +1,40 @@
+package com.hamburg.type.controller;
+
+import com.hamburg.common.domain.Type;
+import com.hamburg.common.result.Result;
+import com.hamburg.type.service.TypeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.type.controller
+ * @Project:yk-8.12
+ * @name:TypeController
+ * @Date:2024/8/12 14:19
+ */
+@RestController
+@RequestMapping("/type")
+public class TypeController {
+
+ @Autowired
+ private TypeService typeService;
+
+
+ /**
+ * 类型列表
+ * @return
+ */
+ @GetMapping("/findTypeList")
+ public Result> findTypeList() {
+
+ return Result.success(typeService.findTypeList());
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/mapper/TypeMapper.java b/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/mapper/TypeMapper.java
new file mode 100644
index 0000000..c1aff79
--- /dev/null
+++ b/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/mapper/TypeMapper.java
@@ -0,0 +1,19 @@
+package com.hamburg.type.mapper;
+
+import com.hamburg.common.domain.Type;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.type.mapper
+ * @Project:yk-8.12
+ * @name:TypeMapper
+ * @Date:2024/8/12 14:20
+ */
+@Mapper
+public interface TypeMapper {
+ List findTypeList();
+
+}
diff --git a/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/service/TypeService.java b/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/service/TypeService.java
new file mode 100644
index 0000000..a2366de
--- /dev/null
+++ b/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/service/TypeService.java
@@ -0,0 +1,17 @@
+package com.hamburg.type.service;
+
+import com.hamburg.common.domain.Type;
+
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.type.service
+ * @Project:yk-8.12
+ * @name:TypeService
+ * @Date:2024/8/12 14:19
+ */
+public interface TypeService {
+ List findTypeList();
+
+}
diff --git a/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/service/impl/TypeServiceImpl.java b/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/service/impl/TypeServiceImpl.java
new file mode 100644
index 0000000..73463bc
--- /dev/null
+++ b/hamburg-modules/hamburg-type/src/main/java/com/hamburg/type/service/impl/TypeServiceImpl.java
@@ -0,0 +1,30 @@
+package com.hamburg.type.service.impl;
+
+import com.hamburg.common.domain.Type;
+import com.hamburg.type.mapper.TypeMapper;
+import com.hamburg.type.service.TypeService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import org.springframework.stereotype.Service;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.type.service.impl
+ * @Project:yk-8.12
+ * @name:TypeServiceImpl
+ * @Date:2024/8/12 14:19
+ */
+@Service
+public class TypeServiceImpl implements TypeService {
+
+ @Autowired
+ private TypeMapper typeMapper;
+
+ @Override
+ public List findTypeList() {
+ return typeMapper.findTypeList();
+ }
+}
diff --git a/hamburg-modules/hamburg-type/src/main/resources/bootstrap.yml b/hamburg-modules/hamburg-type/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..3daf0fa
--- /dev/null
+++ b/hamburg-modules/hamburg-type/src/main/resources/bootstrap.yml
@@ -0,0 +1,43 @@
+# Tomcat
+server:
+ port: 9007
+# Spring
+spring:
+ main:
+ allow-circular-references: true
+ jackson:
+ date-format: yyyy-MM-dd HH:mm:ss
+ time-zone: GMT+8
+ application:
+ # 应用名称
+ name: hamburg-type
+ profiles:
+ # 环境配置
+ active: dev
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ config:
+ # 配置中心地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+fdfs:
+ so-timeout: 1500 # socket 连接时长
+ connect-timeout: 600 # 连接 tracker 服务器超时时长
+ # 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
+ tracker-list: 124.70.191.180:22122
+ web-server-url: 124.70.191.180:8888
+ pool:
+ jmx-enabled: false
+ # 生成缩略图
+ thumb-image:
+ height: 500
+ width: 500
diff --git a/hamburg-modules/hamburg-type/src/main/resources/mapper/ITypeMapper.xml b/hamburg-modules/hamburg-type/src/main/resources/mapper/ITypeMapper.xml
new file mode 100644
index 0000000..b9ad45b
--- /dev/null
+++ b/hamburg-modules/hamburg-type/src/main/resources/mapper/ITypeMapper.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+ select type_id,type_name from t_type
+
+
diff --git a/hamburg-modules/hamburg-user/pom.xml b/hamburg-modules/hamburg-user/pom.xml
new file mode 100644
index 0000000..b9820ce
--- /dev/null
+++ b/hamburg-modules/hamburg-user/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ org.example
+ hamburg-modules
+ 1.0-SNAPSHOT
+
+
+ hamburg-user
+
+
+ 8
+ 8
+ UTF-8
+
+
+
diff --git a/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/UserApplication.java b/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/UserApplication.java
new file mode 100644
index 0000000..4c3cc55
--- /dev/null
+++ b/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/UserApplication.java
@@ -0,0 +1,25 @@
+package com.hamburg.user;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.user
+ * @Project:yk-8.12
+ * @name:UserApplication
+ * @Date:2024/8/12 9:34
+ */
+@SpringBootApplication
+@EnableFeignClients
+public class UserApplication {
+
+ public static void main(String[] args) {
+
+ SpringApplication.run(UserApplication.class, args);
+
+
+ }
+
+}
diff --git a/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/controller/UserController.java b/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/controller/UserController.java
new file mode 100644
index 0000000..82e8d83
--- /dev/null
+++ b/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/controller/UserController.java
@@ -0,0 +1,51 @@
+package com.hamburg.user.controller;
+
+import com.hamburg.common.domain.User;
+import com.hamburg.common.domain.request.UserReq;
+import com.hamburg.common.result.Result;
+import com.hamburg.user.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.user.controller
+ * @Project:yk-8.12
+ * @name:UserController
+ * @Date:2024/8/12 9:40
+ */
+@RestController
+@RequestMapping("/user")
+public class UserController {
+
+ @Autowired
+ private UserService userService;
+
+
+ /**
+ * 根据手机号发送验证码
+ * @param userReq 参数
+ * @return 返回结果
+ */
+ @PostMapping("/sendCode")
+ public Result sendCode(@RequestBody UserReq userReq) {
+ return Result.success(userService.sendCode(userReq));
+ }
+
+
+ /**
+ * 用户注册
+ * @param userReq 参数
+ * @return 返回结果
+ */
+ @PostMapping("/userRegistration")
+ public Result userRegistration(@RequestBody UserReq userReq) {
+
+ int add=userService.userRegistration(userReq);
+ return Result.success();
+ }
+
+}
diff --git a/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/mapper/UserMapper.java b/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/mapper/UserMapper.java
new file mode 100644
index 0000000..0e4e6a7
--- /dev/null
+++ b/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/mapper/UserMapper.java
@@ -0,0 +1,22 @@
+package com.hamburg.user.mapper;
+
+import com.hamburg.common.domain.User;
+import com.hamburg.common.domain.request.UserReq;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.user.mapper
+ * @Project:yk-8.12
+ * @name:UserMapper
+ * @Date:2024/8/12 9:41
+ */
+@Mapper
+public interface UserMapper {
+
+ User sendCode(UserReq userReq);
+
+
+ int userRegistration(UserReq userReq);
+
+}
diff --git a/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/service/UserService.java b/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/service/UserService.java
new file mode 100644
index 0000000..f30d4f0
--- /dev/null
+++ b/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/service/UserService.java
@@ -0,0 +1,19 @@
+package com.hamburg.user.service;
+
+import com.hamburg.common.domain.User;
+import com.hamburg.common.domain.request.UserReq;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.user.service
+ * @Project:yk-8.12
+ * @name:UserService
+ * @Date:2024/8/12 9:40
+ */
+public interface UserService {
+ User sendCode(UserReq userReq);
+
+
+ int userRegistration(UserReq userReq);
+
+}
diff --git a/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/service/impl/UserServiceImpl.java b/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/service/impl/UserServiceImpl.java
new file mode 100644
index 0000000..67f179f
--- /dev/null
+++ b/hamburg-modules/hamburg-user/src/main/java/com/hamburg/user/service/impl/UserServiceImpl.java
@@ -0,0 +1,51 @@
+package com.hamburg.user.service.impl;
+
+import com.hamburg.common.domain.User;
+import com.hamburg.common.domain.request.UserReq;
+import com.hamburg.common.exception.ProjectException;
+import com.hamburg.user.mapper.UserMapper;
+import com.hamburg.user.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Author:liuxinyue
+ * @Package:com.hamburg.user.service.impl
+ * @Project:yk-8.12
+ * @name:UserServiceImpl
+ * @Date:2024/8/12 9:40
+ */
+@Service
+public class UserServiceImpl implements UserService {
+
+ @Autowired
+ private UserMapper userMapper;
+
+
+ /**
+ * 发送验证码
+ * @param userReq 请求参数
+ * @return 返回结果
+ */
+ @Override
+ public User sendCode(UserReq userReq) {
+ return userMapper.sendCode(userReq);
+ }
+
+ /**
+ * 注册
+ * @param userReq 请求参数
+ * @return 返回结果
+ */
+ @Override
+ public int userRegistration(UserReq userReq) {
+ User user = userMapper.sendCode(userReq);
+
+ if(null != user) {
+ throw new ProjectException("该手机号已经注册过!");
+ }
+ return userMapper.userRegistration(userReq);
+ }
+
+
+}
diff --git a/hamburg-modules/hamburg-user/src/main/resources/bootstrap.yml b/hamburg-modules/hamburg-user/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..51b69e7
--- /dev/null
+++ b/hamburg-modules/hamburg-user/src/main/resources/bootstrap.yml
@@ -0,0 +1,43 @@
+# Tomcat
+server:
+ port: 9004
+# Spring
+spring:
+ main:
+ allow-circular-references: true
+ jackson:
+ date-format: yyyy-MM-dd HH:mm:ss
+ time-zone: GMT+8
+ application:
+ # 应用名称
+ name: hamburg-user
+ profiles:
+ # 环境配置
+ active: dev
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ config:
+ # 配置中心地址
+ server-addr: 124.70.191.180:8848
+ namespace: High-five
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+fdfs:
+ so-timeout: 1500 # socket 连接时长
+ connect-timeout: 600 # 连接 tracker 服务器超时时长
+ # 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
+ tracker-list: 124.70.191.180:22122
+ web-server-url: 124.70.191.180:8888
+ pool:
+ jmx-enabled: false
+ # 生成缩略图
+ thumb-image:
+ height: 500
+ width: 500
diff --git a/hamburg-modules/hamburg-user/src/main/resources/mapper/IUserMapper.xml b/hamburg-modules/hamburg-user/src/main/resources/mapper/IUserMapper.xml
new file mode 100644
index 0000000..3641f5f
--- /dev/null
+++ b/hamburg-modules/hamburg-user/src/main/resources/mapper/IUserMapper.xml
@@ -0,0 +1,19 @@
+
+
+
+
+ INSERT INTO `812yk`.`t_user` ( `user_name`, `user_phone`) VALUES ( #{userName}, #{userPhone});
+
+
+
+ SELECT
+ user_id,
+ user_name,
+ user_phone
+ FROM
+ t_user where user_phone=#{userPhone}
+
+
+
diff --git a/hamburg-modules/pom.xml b/hamburg-modules/pom.xml
new file mode 100644
index 0000000..eae2144
--- /dev/null
+++ b/hamburg-modules/pom.xml
@@ -0,0 +1,83 @@
+
+
+ 4.0.0
+
+ org.example
+ yk-8.12
+ 1.0-SNAPSHOT
+
+
+ hamburg-modules
+ pom
+
+ hamburg-user
+ hamburg-coupon
+ hamburg-es
+ hamburg-type
+ hamburg-order
+
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+
+ com.baomidou
+ lock4j-redis-template-spring-boot-starter
+ 2.2.7
+
+
+
+ org.example
+ hamburg-common
+ 1.0-SNAPSHOT
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ com.alibaba
+ druid-spring-boot-starter
+ 1.2.8
+
+
+
+ mysql
+ mysql-connector-java
+
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 2.2.2
+
+
+
+ com.github.pagehelper
+ pagehelper-spring-boot-starter
+ 1.4.1
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ com.github.tobato
+ fastdfs-client
+ 1.26.5
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..287c4dc
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,67 @@
+
+
+ 4.0.0
+
+ org.example
+ yk-8.12
+ 1.0-SNAPSHOT
+ pom
+
+ hamburg-common
+ hamburg-auth
+ hamburg-gateway
+ hamburg-modules
+
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+
+ spring-boot-starter-parent
+ org.springframework.boot
+ 2.6.2
+
+
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ 2021.0.0
+ pom
+ import
+
+
+
+ com.alibaba.cloud
+ spring-cloud-alibaba-dependencies
+ 2021.1
+ pom
+ import
+
+
+
+ com.alibaba.nacos
+ nacos-client
+ 2.0.4
+
+
+
+
+ org.example
+ hamburg-common
+ 1.0-SNAPSHOT
+
+
+
+
+