提交代码

dev-discount
胡锐 2 years ago
parent a22061ce9b
commit e4e226583e
  1. 2
      hai-cweb/src/main/java/com/cweb/controller/HighTestController.java
  2. 4
      hai-cweb/src/main/resources/dev/application.yml
  3. 4
      hai-order/src/main/java/com/OrderApplication.java
  4. 2
      hai-order/src/main/java/com/web/config/AuthConfig.java
  5. 2
      hai-order/src/main/java/com/web/config/ConfigListener.java
  6. 2
      hai-order/src/main/java/com/web/config/CorsConfig.java
  7. 2
      hai-order/src/main/java/com/web/config/MultipartConfig.java
  8. 2
      hai-order/src/main/java/com/web/config/RedisConfig.java
  9. 2
      hai-order/src/main/java/com/web/config/SentinelFilterConfig.java
  10. 2
      hai-order/src/main/java/com/web/config/SwaggerConfig.java
  11. 2
      hai-order/src/main/java/com/web/config/SysConfig.java
  12. 2
      hai-order/src/main/java/com/web/config/SysConst.java
  13. 2
      hai-order/src/main/java/com/web/controller/LoginController.java
  14. 21
      hai-order/src/main/java/com/web/controller/OrderController.java
  15. 1
      hai-order/src/main/java/com/web/controller/TestController.java
  16. 3
      hai-order/src/main/java/com/web/rocketmq/consumer/OrderCancelConsumer.java
  17. 14
      hai-order/src/main/java/com/web/rocketmq/consumer/OrderCreateConsumer.java
  18. 33
      hai-order/src/main/resources/dev/application.yml
  19. 8
      hai-order/src/main/resources/dev/web.xml
  20. 6
      hai-service/pom.xml
  21. 16
      hai-service/src/main/java/com/hai/order/service/OrderService.java
  22. 25
      hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java

File diff suppressed because one or more lines are too long

@ -68,6 +68,10 @@ mybatis:
- classpath*:sqlmap*/*.xml
type-aliases-package:
org.springboot.sample.entity
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#开启MyBatis的二级缓存
cache-enabled: true
pagehelper:
helperDialect: mysql

@ -1,5 +1,7 @@
package com;
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
import com.alicp.jetcache.anno.config.EnableMethodCache;
import com.hai.common.utils.SpringContextUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
@ -13,6 +15,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
//@ComponentScan
@EnableTransactionManagement
@EnableScheduling
@EnableMethodCache(basePackages = "com.hai")
@EnableCreateCacheAnnotation
@ServletComponentScan
@MapperScan("com.hai.dao")
public class OrderApplication

@ -1,4 +1,4 @@
package com.cweb.config;
package com.web.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;

@ -1,4 +1,4 @@
package com.cweb.config;
package com.web.config;
import javax.annotation.Resource;
import javax.servlet.ServletContextEvent;

@ -1,4 +1,4 @@
package com.cweb.config;
package com.web.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@ -1,4 +1,4 @@
package com.cweb.config;
package com.web.config;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;

@ -1,4 +1,4 @@
package com.cweb.config;
package com.web.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;

@ -1,4 +1,4 @@
package com.cweb.config;
package com.web.config;
import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;

@ -1,4 +1,4 @@
package com.cweb.config;
package com.web.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@ -1,4 +1,4 @@
package com.cweb.config;
package com.web.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;

@ -1,4 +1,4 @@
package com.cweb.config;
package com.web.config;
public class SysConst {

@ -1,4 +1,4 @@
package com.cweb.controller;
package com.web.controller;
import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;

@ -1,16 +1,10 @@
package com.cweb.controller;
package com.web.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.Base64Util;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.security.AESEncodeUtil;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighDiscountAgentCode;
import com.hai.entity.HighDiscountAgentRel;
import com.hai.model.ResponseData;
import com.hai.order.model.CreateOrderModel;
import com.hai.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
@ -18,6 +12,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@Controller
@RequestMapping(value = "")
@Api(value = "订单业务")
@ -25,10 +21,13 @@ public class OrderController {
private static Logger log = LoggerFactory.getLogger(OrderController.class);
@RequestMapping(value="/create",method = RequestMethod.GET)
@Resource
private OrderService orderService;
@RequestMapping(value="/create",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "创建订单")
public ResponseData create(@RequestBody JSONObject body) {
public ResponseData create(@RequestBody CreateOrderModel body) {
try {
if (body == null) {

@ -0,0 +1 @@
package com.web.controller; import com.hai.common.utils.*; import com.hai.entity.HighOrder; import com.hai.model.ResponseData; import com.hai.order.service.OrderService; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class TestController { private static Logger log = LoggerFactory.getLogger(TestController.class); @Autowired private RocketMQTemplate rocketMQTemplate; @Resource private OrderService orderService; @Resource private RedisUtil redisUtil; @Autowired private RedisTemplate redisTemplate; @RequestMapping(value = "/rocketMq", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "") public ResponseData rocketMq(@RequestParam(name = "topicGroup", required = true) String topicGroup, @RequestParam(name = "body", required = true) String body) { try { long startTime = System.currentTimeMillis(); String couponKey = "123"; List<HighOrder> list = new ArrayList<>(); for (int i = 0; i <= 1000;i++) { orderService.getDetailByOrderNo("HF2022080918014365701"); /* list.add(orderService.getDetailByOrderNo("HF2022080918014365701"));*/ /* updateUserWithRedisLock("coupon_" + couponKey, i+""); new Thread(() -> {*/ /* redisTemplate.opsForValue().setIfAbsent("coupon_" + couponKey, i); System.out.println("加入数据" + i);*/ // redisTemplate.delete("coupon" + couponKey); // System.out.println("释放数据" + index); /* });*/ } System.out.println(System.currentTimeMillis() - startTime); return ResponseMsgUtil.success(list); } catch (Exception e) { log.error("HighUserCardController --> rocketMq() error!", e); return ResponseMsgUtil.exception(e); } } public void updateUserWithRedisLock(String couponKey, String value) throws InterruptedException { // 占分布式锁,去redis占坑 // 1. 分布式锁占坑 Boolean lock = redisTemplate.opsForValue().setIfAbsent("coupon" + couponKey, value); if(lock) { //加锁成功... // todo business System.out.println("加锁成功: " + value); redisTemplate.delete("coupon" + couponKey); //删除key,释放锁 } else { System.out.println("加锁失败"); /* Thread.sleep(100); // 加锁失败,重试 updateUserWithRedisLock("sysUser");*/ } } }

@ -1,6 +1,5 @@
package com.cweb.msg;
package com.web.rocketmq.consumer;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.utils.DateUtil;
import com.hai.entity.HighOrder;
import lombok.extern.slf4j.Slf4j;

@ -1,35 +1,29 @@
package com.cweb.msg;
package com.web.rocketmq.consumer;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.utils.DateUtil;
import com.hai.entity.HighOrder;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "order-create-group", topic = "order-topic",selectorExpression = "create")
public class OrderCreateConsumer implements RocketMQListener<HighOrder> {
public class OrderCreateConsumer implements RocketMQListener<Object> {
@Resource
private RocketMQTemplate rocketMQTemplate;
@Override
public void onMessage(HighOrder order) {
public void onMessage(Object order) {
try {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户");
//throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户");
/* System.out.println(JSONObject.toJSONString(order));*/
// System.out.println(DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss") + " 创建订单:" + order.getOrderNo());

@ -53,11 +53,12 @@ spring:
#MQTT默认的消息推送主题,实际可在调用接口是指定
# default:
# topic: topic
rocketmq:
name-server: 127.0.0.1:9876
producer:
#必须指定group
group: test-group
rocketmq:
name-server: 139.159.177.244:9876
producer:
#必须指定group
group: default-group
#配置日期返回至前台为时间戳
jackson:
serialization:
@ -68,6 +69,28 @@ mybatis:
type-aliases-package:
org.springboot.sample.entity
jetcache:
statIntervalMinutes: 15
areaInCacheName: false
local:
default:
type: linkedhashmap
keyConvertor: fastjson
remote:
default:
type: redis
host: 139.159.177.244
port: 36379
password: HF123456.Redis
keyConvertor: fastjson
broadcastChannel: projectA
valueEncoder: java
valueDecoder: java
poolConfig:
minIdle: 5
maxIdle: 20
maxTotal: 50
pagehelper:
helperDialect: mysql
reasonable: true

@ -1,8 +0,0 @@
<filter>
<filter-name>SentinelCommonFilter</filter-name>
<filter-class>com.alibaba.csp.sentinel.adapter.servlet.CommonFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SentinelCommonFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

@ -81,7 +81,6 @@
<artifactId>mapper</artifactId>
<version>3.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
@ -353,6 +352,11 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.alicp.jetcache</groupId>
<artifactId>jetcache-starter-redis</artifactId>
<version>2.6.7</version>
</dependency>
</dependencies>
<build>
<resources>

@ -0,0 +1,16 @@
package com.hai.order.service;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.hai.entity.HighOrder;
/**
* @className: OrderService
* @author: HuRui
* @date: 2022/8/18
**/
public interface OrderService {
@Cached(cacheType = CacheType.REMOTE,name="OrderService.getDetailByOrderNo", expire = 3600)
HighOrder getDetailByOrderNo(String orderNo);
}

@ -0,0 +1,25 @@
package com.hai.order.service.impl;
import com.hai.entity.HighOrder;
import com.hai.order.service.OrderService;
import com.hai.service.HighOrderService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* @className: OrderServiceImpl
* @author: HuRui
* @date: 2022/8/18
**/
@Service("orderService123")
public class OrderServiceImpl implements OrderService {
@Resource
private HighOrderService highOrderService;
@Override
public HighOrder getDetailByOrderNo(String orderNo) {
return highOrderService.getOrderByOrderNo(orderNo);
}
}
Loading…
Cancel
Save