Ver código fonte

1.优化支付成功后的逻辑;
2.部分高频访问数据加入缓存;

codingliang 1 ano atrás
pai
commit
c3ff2c0952

+ 26 - 8
src/main/java/com/sqx/SqxApplication.java

@@ -1,21 +1,39 @@
 package com.sqx;
 
+import com.sqx.common.utils.MyGlobalThreadPool;
+import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextClosedEvent;
 
 @SpringBootApplication
-public class SqxApplication {
+public class SqxApplication implements CommandLineRunner, ApplicationListener<ApplicationEvent> {
 
 	public static void main(String[] args) {
 		SpringApplication.run(SqxApplication.class, args);
-		System.out.println("(♥◠‿◠)ノ゙  同城外卖项目启动成功   ლ(´ڡ`ლ)゙  \n"+
-							"       _    \n" +
-							"      | |   \n" +
-							"  ___ | | __\n" +
-							" / _ \\| |/ /\n" +
-							"| (_) |   < \n" +
-							" \\___/|_|\\_\\");
+	}
+
+	@Override
+	public void run(String... args) throws Exception {
+		// 初始化公共线程池
+		MyGlobalThreadPool.init();
 
+		System.out.println("(♥◠‿◠)ノ゙  同城外卖项目启动成功   ლ(´ڡ`ლ)゙  \n"+
+				"       _    \n" +
+				"      | |   \n" +
+				"  ___ | | __\n" +
+				" / _ \\| |/ /\n" +
+				"| (_) |   < \n" +
+				" \\___/|_|\\_\\");
 	}
 
+	@Override
+	public void onApplicationEvent(ApplicationEvent event) {
+		if (event instanceof ContextClosedEvent) {
+			// 应用停止时的操作
+			MyGlobalThreadPool.shutdown(false);
+		}
+	}
 }

+ 1 - 1
src/main/java/com/sqx/common/aspect/RedisAspect.java

@@ -18,7 +18,7 @@ import org.springframework.context.annotation.Configuration;
 public class RedisAspect {
     private Logger logger = LoggerFactory.getLogger(getClass());
     //是否开启redis缓存  true开启   false关闭
-    @Value("${spring.redis.open: false}")
+    @Value("${sqx.redis.open:false}")
     private boolean open;
 
     @Around("execution(* com.sqx.common.utils.RedisUtils.*(..))")

+ 26 - 0
src/main/java/com/sqx/common/constant/RedisKey.java

@@ -57,4 +57,30 @@ public interface RedisKey {
      * 用户购买vip锁
      */
     String USER_BUY_VIP_LOCK = "wm:lock:vip:buy:%s";
+
+    /**
+     * 公共配置缓存key
+     */
+    String COMMON_INFO_CACHE_KEY = "wm:data:common:%s";
+
+    /**
+     * 店铺缓存信息
+     */
+    String SHOP_INFO_CACHE_KEY = "wm:data:shop:%s";
+
+    /**
+     * 用户端小程序token
+     */
+    String MP_TOKEN_CACHE_KEY = "wm:data:wx:user-mp:token";
+
+    /**
+     * 骑手端端小程序token
+     */
+    String MP_OF_RIDER_TOKEN_CACHE_KEY = "wm:data:wx:rider-mp:token";
+
+    /**
+     * 商家端小程序token
+     */
+    String MP_OF_SHOP_TOKEN_CACHE_KEY = "wm:data:wx:shop-mp:token";
+
 }

+ 95 - 0
src/main/java/com/sqx/common/utils/MyGlobalThreadPool.java

@@ -0,0 +1,95 @@
+package com.sqx.common.utils;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import cn.hutool.core.exceptions.UtilException;
+
+/**
+ * 全局公共线程池
+ */
+public class MyGlobalThreadPool {
+	private static ExecutorService executor;
+
+	private MyGlobalThreadPool() {
+	}
+
+	static {
+		init();
+	}
+
+	/**
+	 * 初始化全局线程池
+	 */
+	synchronized public static void init() {
+		if (null != executor) {
+			executor.shutdownNow();
+		}
+		executor = new ThreadPoolExecutor(2, 10, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
+	}
+
+	/**
+	 * 关闭公共线程池
+	 * 
+	 * @param isNow 是否立即关闭而不等待正在执行的线程
+	 */
+	synchronized public static void shutdown(boolean isNow) {
+		if (null != executor) {
+			if (isNow) {
+				executor.shutdownNow();
+			} else {
+				executor.shutdown();
+			}
+		}
+	}
+
+	/**
+	 * 获得 {@link ExecutorService}
+	 * 
+	 * @return {@link ExecutorService}
+	 */
+	public static ExecutorService getExecutor() {
+		return executor;
+	}
+
+	/**
+	 * 直接在公共线程池中执行线程
+	 * 
+	 * @param runnable 可运行对象
+	 */
+	public static void execute(Runnable runnable) {
+		try {
+			executor.execute(runnable);
+		} catch (Exception e) {
+			throw new UtilException(e, "Exception when running task!");
+		}
+	}
+
+	/**
+	 * 执行有返回值的异步方法<br>
+	 * Future代表一个异步执行的操作,通过get()方法可以获得操作的结果,如果异步操作还没有完成,则,get()会使当前线程阻塞
+	 * 
+	 * @param <T> 执行的Task
+	 * @param task {@link Callable}
+	 * @return Future
+	 */
+	public static <T> Future<T> submit(Callable<T> task) {
+		return executor.submit(task);
+	}
+
+	/**
+	 * 执行有返回值的异步方法<br>
+	 * Future代表一个异步执行的操作,通过get()方法可以获得操作的结果,如果异步操作还没有完成,则,get()会使当前线程阻塞
+	 * 
+	 * @param runnable 可运行对象
+	 * @return {@link Future}
+	 * @since 3.0.5
+	 */
+	public static Future<?> submit(Runnable runnable) {
+		return executor.submit(runnable);
+	}
+}

+ 118 - 50
src/main/java/com/sqx/common/utils/RedisUtils.java

@@ -1,10 +1,14 @@
 package com.sqx.common.utils;
 
-import com.google.gson.Gson;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.*;
+import org.springframework.data.redis.core.HashOperations;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -13,78 +17,142 @@ import java.util.concurrent.TimeUnit;
  */
 @Component
 public class RedisUtils {
-    @Autowired
+    @Resource
     private RedisTemplate<String, Object> redisTemplate;
-    @Autowired
-    private ValueOperations<String, String> valueOperations;
-    @Autowired
-    private HashOperations<String, String, Object> hashOperations;
-    @Autowired
-    private ListOperations<String, Object> listOperations;
-    @Autowired
-    private SetOperations<String, Object> setOperations;
-    @Autowired
-    private ZSetOperations<String, Object> zSetOperations;
-    /**  默认过期时长,单位:秒 */
+
+    /**
+     * 默认过期时长为24小时,单位:秒
+     */
     public final static long DEFAULT_EXPIRE = 60 * 60 * 24;
+
+    /**
+     * 过期时长为6小时,单位:秒
+     */
+    public final static long HOUR_SIX_EXPIRE = 60 * 60 * 6L;
+
+    /**
+     * 过期时长为1小时,单位:秒
+     */
+    public final static long HOUR_ONE_EXPIRE = 60 * 60 * 1L;
+
+    /**
+     * 过期时长为半小时,单位:秒
+     */
+    public final static long HALF_HOUR_ONE_EXPIRE = 30 * 60 * 1L;
+
+    /**
+     * 过期时长为10分钟时,单位:秒
+     */
+    public final static long TEN_MINUTE_ONE_EXPIRE = 10 * 60 * 1L;
+
     /**  不设置过期时长 */
     public final static long NOT_EXPIRE = -1;
-    private final static Gson Gson = new Gson();
 
-    public void set(String key, Object value, long expire){
-        valueOperations.set(key, toJson(value));
-        if(expire != NOT_EXPIRE){
-            redisTemplate.expire(key, expire, TimeUnit.SECONDS);
+    public void set(String key, Object value, long expire) {
+        redisTemplate.opsForValue().set(key, value);
+        if (expire != NOT_EXPIRE) {
+            expire(key, expire);
         }
     }
 
-    public void set(String key, Object value){
-        set(key, value, DEFAULT_EXPIRE);
+    public void set(String key, Object value) {
+        redisTemplate.opsForValue().set(key, value);
     }
 
-    public <T> T get(String key, Class<T> clazz, long expire) {
-        String value = valueOperations.get(key);
-        if(expire != NOT_EXPIRE){
-            redisTemplate.expire(key, expire, TimeUnit.SECONDS);
+    public Object get(String key, long expire) {
+        Object value = redisTemplate.opsForValue().get(key);
+        if (expire != NOT_EXPIRE) {
+            expire(key, expire);
         }
-        return value == null ? null : fromJson(value, clazz);
+        return value;
     }
 
-    public <T> T get(String key, Class<T> clazz) {
-        return get(key, clazz, NOT_EXPIRE);
+    public Object get(String key) {
+        return get(key, NOT_EXPIRE);
     }
 
-    public String get(String key, long expire) {
-        String value = valueOperations.get(key);
-        if(expire != NOT_EXPIRE){
-            redisTemplate.expire(key, expire, TimeUnit.SECONDS);
-        }
-        return value;
+    public Long increment(String key) {
+        return redisTemplate.opsForValue().increment(key);
     }
 
-    public String get(String key) {
-        return get(key, NOT_EXPIRE);
+    public Boolean hasKey(String key) {
+        return redisTemplate.hasKey(key);
+    }
+
+    public Set<String> keys(String pattern) {
+        return redisTemplate.keys(pattern);
     }
 
     public void delete(String key) {
         redisTemplate.delete(key);
     }
 
-    /**
-     * Object转成JSON数据
-     */
-    private String toJson(Object object){
-        if(object instanceof Integer || object instanceof Long || object instanceof Float ||
-                object instanceof Double || object instanceof Boolean || object instanceof String){
-            return String.valueOf(object);
+    public void delete(Collection<String> keys) {
+        redisTemplate.delete(keys);
+    }
+
+    public Object hGet(String key, String field) {
+        return redisTemplate.opsForHash().get(key, field);
+    }
+
+    public Map<String, Object> hGetAll(String key) {
+        HashOperations<String, String, Object> hashOperations = redisTemplate.opsForHash();
+        return hashOperations.entries(key);
+    }
+
+    public void hMSet(String key, Map<String, Object> map) {
+        hMSet(key, map, DEFAULT_EXPIRE);
+    }
+
+    public void hMSet(String key, Map<String, Object> map, long expire) {
+        redisTemplate.opsForHash().putAll(key, map);
+
+        if (expire != NOT_EXPIRE) {
+            expire(key, expire);
         }
-        return Gson.toJson(object);
     }
 
-    /**
-     * JSON数据,转成Object
-     */
-    private <T> T fromJson(String json, Class<T> clazz){
-        return Gson.fromJson(json, clazz);
+    public void hSet(String key, String field, Object value) {
+        hSet(key, field, value, DEFAULT_EXPIRE);
+    }
+
+    public void hSet(String key, String field, Object value, long expire) {
+        redisTemplate.opsForHash().put(key, field, value);
+
+        if (expire != NOT_EXPIRE) {
+            expire(key, expire);
+        }
+    }
+
+    public void expire(String key, long expire) {
+        redisTemplate.expire(key, expire, TimeUnit.SECONDS);
+    }
+
+    public void expireAt(String key, Date expire) {
+        redisTemplate.expireAt(key, expire);
+    }
+
+    public Long getExpire(String key) {
+        return redisTemplate.getExpire(key, TimeUnit.SECONDS);
+    }
+
+    public void hDel(String key, Object... fields) {
+        redisTemplate.opsForHash().delete(key, fields);
+    }
+
+    public void leftPush(String key, Object value) {
+        leftPush(key, value, DEFAULT_EXPIRE);
+    }
+
+    public void leftPush(String key, Object value, long expire) {
+        redisTemplate.opsForList().leftPush(key, value);
+
+        if (expire != NOT_EXPIRE) {
+            expire(key, expire);
+        }
+    }
+
+    public Object rightPop(String key) {
+        return redisTemplate.opsForList().rightPop(key);
     }
 }

+ 24 - 32
src/main/java/com/sqx/config/RedisConfig.java

@@ -1,11 +1,15 @@
 package com.sqx.config;
 
-import org.springframework.beans.factory.annotation.Autowired;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.core.*;
-import org.springframework.data.redis.serializer.StringRedisSerializer;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.RedisSerializer;
 
 /**
  * Redis配置
@@ -13,42 +17,30 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
  */
 @Configuration
 public class RedisConfig {
-    @Autowired
-    private RedisConnectionFactory factory;
 
-    @Bean
-    public RedisTemplate<String, Object> redisTemplate() {
-        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
-        redisTemplate.setKeySerializer(new StringRedisSerializer());
-        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
-        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
-        redisTemplate.setValueSerializer(new StringRedisSerializer());
-        redisTemplate.setConnectionFactory(factory);
-        return redisTemplate;
-    }
+    public GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer() {
+        ObjectMapper objectMapper = new ObjectMapper();
+        objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+        objectMapper.registerModule(new JavaTimeModule());
+        objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
 
-    @Bean
-    public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
-        return redisTemplate.opsForHash();
+        return new GenericJackson2JsonRedisSerializer(objectMapper);
     }
 
     @Bean
-    public ValueOperations<String, String> valueOperations(RedisTemplate<String, String> redisTemplate) {
-        return redisTemplate.opsForValue();
-    }
+    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
+        RedisTemplate<String, Object> template = new RedisTemplate<>();
+        // Key HashKey使用String序列化
+        template.setKeySerializer(RedisSerializer.string());
+        template.setHashKeySerializer(RedisSerializer.string());
 
-    @Bean
-    public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
-        return redisTemplate.opsForList();
-    }
+        // Value HashValue使用Json序列化
+        template.setValueSerializer(genericJackson2JsonRedisSerializer());
+        template.setHashValueSerializer(genericJackson2JsonRedisSerializer());
 
-    @Bean
-    public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {
-        return redisTemplate.opsForSet();
-    }
+        template.setConnectionFactory(factory);
 
-    @Bean
-    public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
-        return redisTemplate.opsForZSet();
+        template.afterPropertiesSet();
+        return template;
     }
 }

+ 14 - 7
src/main/java/com/sqx/modules/common/service/impl/CommonInfoServiceImpl.java

@@ -1,11 +1,14 @@
 package com.sqx.modules.common.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sqx.common.constant.RedisKey;
+import com.sqx.common.utils.RedisUtils;
 import com.sqx.common.utils.Result;
 import com.sqx.modules.common.dao.CommonInfoDao;
 import com.sqx.modules.common.entity.CommonInfo;
 import com.sqx.modules.common.service.CommonInfoService;
-import org.springframework.beans.factory.annotation.Autowired;
+import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
 import java.text.SimpleDateFormat;
@@ -16,15 +19,12 @@ import java.util.Date;
  * @date 2020/7/8
  */
 @Service
+@RequiredArgsConstructor
 public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo> implements CommonInfoService {
 
-
     private final CommonInfoDao commonInfoDao;
 
-    @Autowired
-    public CommonInfoServiceImpl(CommonInfoDao commonInfoDao) {
-        this.commonInfoDao = commonInfoDao;
-    }
+    private final RedisUtils redisUtils;
 
     @Override
     public Result update(CommonInfo commonInfo) {
@@ -38,7 +38,14 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
 
     @Override
     public CommonInfo findOne(int id) {
-        return commonInfoDao.findOne(id);
+        String key = String.format(RedisKey.COMMON_INFO_CACHE_KEY, id);
+        CommonInfo commonInfo = (CommonInfo) redisUtils.get(key);
+        if (ObjectUtil.isNull(commonInfo)) {
+            commonInfo = commonInfoDao.findOne(id);
+
+            redisUtils.set(key, commonInfo);
+        }
+        return commonInfo;
     }
 
     @Override

+ 4 - 1
src/main/java/com/sqx/modules/errand/service/impl/TbIndentServiceImpl.java

@@ -51,6 +51,7 @@ import com.sqx.modules.pay.controller.app.AliPayController;
 import com.sqx.modules.pay.dao.PayDetailsDao;
 import com.sqx.modules.pay.entity.PayDetails;
 import com.sqx.modules.pay.service.WxService;
+import com.sqx.modules.shop.service.ShopMessageService;
 import com.sqx.modules.utils.HttpClientUtil;
 import com.sqx.modules.utils.SenInfoCheckUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -110,6 +111,8 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
     private MessageService messageService;
     @Autowired
     private GoodsShopRelevancyDao goodsShopRelevancyDao;
+    @Autowired
+    private ShopMessageService shopMessageService;
 
     @Resource
     private TbIndentSmsTemplateService smsTemplateService;
@@ -234,7 +237,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         if(integer >= 1){
             return Result.error("请勿重复生成订单!");
         }
-        GoodsShop goodsShop = goodsShopDao.selectById(order.getShopId());
+        GoodsShop goodsShop = shopMessageService.getShopInfoById(order.getShopId());
         Address address = addressDao.selectById(order.getAddressId());
         TbIndent tbIndent = new TbIndent();
         tbIndent.setItemCodeFlag(1);

+ 36 - 28
src/main/java/com/sqx/modules/order/service/impl/AppAppOrderServiceImpl.java

@@ -17,6 +17,7 @@ import com.sqx.common.sms.SmsSendResult;
 import com.sqx.common.utils.Constant;
 import com.sqx.common.utils.DateUtils;
 import com.sqx.common.utils.DistanceUtil;
+import com.sqx.common.utils.MyGlobalThreadPool;
 import com.sqx.common.utils.PageUtils;
 import com.sqx.common.utils.Result;
 import com.sqx.modules.activity.entity.ActivityPartRecord;
@@ -556,14 +557,22 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         order.setPayTime(currentTimeStr);
 
         // 店铺信息
-        GoodsShop goodsShop = goodsShopDao.selectById(order.getShopId());
+        GoodsShop goodsShop = shopMessageService.getShopInfoById(order.getShopId());
+
         // 小程序推送设置
         CommonInfo mpPushConfig = commonInfoService.findOne(269);
+
         // 用户信息
         UserEntity userEntity = userDao.selectById(order.getUserId());
 
         // 添加消息记录并且进行推送
-        addOrderMessageAndPush(order, goodsShop, mpPushConfig, userEntity);
+        MyGlobalThreadPool.execute(() -> {
+            try {
+                addOrderMessageAndPush(order, goodsShop, mpPushConfig, userEntity);
+            } catch (Exception e) {
+                log.error("订单:{},订单支付成功通知发送失败,失败原因:{}", e);
+            }
+        });
 
         // 是否自动接单
         boolean autoAccept = goodsShop.getAutoAcceptOrder() != null && goodsShop.getAutoAcceptOrder() == 0;
@@ -601,21 +610,34 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
             tbIndentService.insertIndent(order);
 
             // 发送商家接单通知
-            sendOrderAcceptMessage(order, goodsShop, mpPushConfig, userEntity);
+            MyGlobalThreadPool.execute(() -> {
+                try {
+                    sendOrderAcceptMessage(order, goodsShop, mpPushConfig, userEntity);
+                } catch (Exception e) {
+                    log.error("订单:{},商家接单通知发送失败,失败原因:{}", e);
+                }
+            });
+
         }
 
         // 订单已接单或者当前订单为预约订单时打印小票
         if (order.getStatus() == 6 || reservationFlag) {
             // 打印小票
             if (StringUtils.isNotEmpty(goodsShop.getSnCode())) {
-                // 设置订单商品
-                List<OrderGoods> orderGoodsList = orderGoodsDao.selectList(new QueryWrapper<OrderGoods>().eq("order_id", order.getOrderId()));
-                order.setOrderGoodsList(orderGoodsList);
-
-                // 设置店铺名称
-                order.setShopName(goodsShop.getShopName());
-
-                FeiYunUtils.print(goodsShop.getSnCode(), null, order);
+                MyGlobalThreadPool.execute(() -> {
+                    try {
+                        // 设置订单商品
+                        List<OrderGoods> orderGoodsList = orderGoodsDao.selectList(new QueryWrapper<OrderGoods>().eq("order_id", order.getOrderId()));
+                        order.setOrderGoodsList(orderGoodsList);
+
+                        // 设置店铺名称
+                        order.setShopName(goodsShop.getShopName());
+
+                        FeiYunUtils.print(goodsShop.getSnCode(), null, order);
+                    } catch (Exception e) {
+                        log.error("订单:{},小票打印失败,失败原因:{}", e);
+                    }
+                });
             }
         }
     }
@@ -805,7 +827,9 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         userMsgList.add(goodsShop.getShopName());
         userMsgList.add(currentDateStr);
         SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), mpPushConfig.getValue(), userMsgList,1);
-        userService.pushToSingle("下单成功", "亲爱的用户您好,您已下单成功,请等待商家接单!", userEntity.getClientid());
+
+        // 无个推
+        // userService.pushToSingle("下单成功", "亲爱的用户您好,您已下单成功,请等待商家接单!", userEntity.getClientid());
 
         // 商户端消息推送
         List<String> shopMsgShopList=new ArrayList<>();
@@ -2434,22 +2458,6 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
      * @return 支付顺序
      */
     private int selectCurrentOrderSequenceByShopId(TbOrder order, Long shopId) {
-        // if (Integer.valueOf(Constant.YES).equals(order.getIsPay())) {
-        //     List<Long> orderIds = appOrderDao.selectCurrentOrderSequenceByShopId(shopId, order.getPayTime());
-        //
-        //     int index = orderIds.indexOf(order.getOrderId());
-        //
-        //     if (index != -1) {
-        //         return index + 1;
-        //     }
-        //
-        //     int count = appOrderDao.countCurDayPayByShopId(shopId);
-        //
-        //     return count + 1;
-        // }
-        //
-        // return -1;
-
         int count = appOrderDao.countCurDayPayByShopId(shopId, order.getPayTime());
 
         return count + 1;

+ 2 - 0
src/main/java/com/sqx/modules/shop/service/ShopMessageService.java

@@ -51,4 +51,6 @@ public interface ShopMessageService extends IService<GoodsShop> {
      * @param dto 修改信息
      */
     void updateShopAuthentication(Long shopId, ShopAuditUpdateDTO dto);
+
+    GoodsShop getShopInfoById(Long shopId);
 }

+ 20 - 0
src/main/java/com/sqx/modules/shop/service/impl/ShopMessageServiceImpl.java

@@ -2,6 +2,7 @@ package com.sqx.modules.shop.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -13,6 +14,7 @@ import com.sqx.common.constant.RedisKey;
 import com.sqx.common.exception.SqxException;
 import com.sqx.common.utils.Constant;
 import com.sqx.common.utils.PageUtils;
+import com.sqx.common.utils.RedisUtils;
 import com.sqx.common.utils.Result;
 import com.sqx.modules.app.dao.MsgDao;
 import com.sqx.modules.app.dao.UserBrowseDao;
@@ -106,6 +108,9 @@ public class ShopMessageServiceImpl extends ServiceImpl<ShopMessageDao, GoodsSho
     @Resource
     private RedissonClient redissonClient;
 
+    @Autowired
+    private RedisUtils redisUtils;
+
     @Transactional
     @Override
     public Result insertShopAuthentication(GoodsShop goodsShop) {
@@ -554,6 +559,21 @@ public class ShopMessageServiceImpl extends ServiceImpl<ShopMessageDao, GoodsSho
     }
 
     @Override
+    public GoodsShop getShopInfoById(Long shopId) {
+        String key = String.format(RedisKey.SHOP_INFO_CACHE_KEY, shopId);
+        String data = (String) redisUtils.get(key);
+        if (StrUtil.isNotBlank(data)) {
+            return JSONUtil.toBean(data, GoodsShop.class);
+        } else {
+            GoodsShop goodsShop = getById(shopId);
+
+            redisUtils.set(key, JSONUtil.toJsonStr(goodsShop), RedisUtils.TEN_MINUTE_ONE_EXPIRE);
+
+            return goodsShop;
+        }
+    }
+
+    @Override
     public Result sendMsgs(String phone, String state) {
         return userService.sendMsg(phone,"ruzhu");
     }

+ 2 - 1
src/main/java/com/sqx/modules/sys/redis/SysConfigRedis.java

@@ -31,6 +31,7 @@ public class SysConfigRedis {
 
     public SysConfigEntity get(String configKey){
         String key = RedisKeys.getSysConfigKey(configKey);
-        return redisUtils.get(key, SysConfigEntity.class);
+        Object o = redisUtils.get(key);
+        return (SysConfigEntity) o;
     }
 }

+ 28 - 12
src/main/java/com/sqx/modules/utils/SenInfoCheckUtil.java

@@ -1,8 +1,11 @@
 package com.sqx.modules.utils;
 
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Maps;
+import com.sqx.common.constant.RedisKey;
+import com.sqx.common.utils.RedisUtils;
 import com.sqx.modules.common.entity.CommonInfo;
 import com.sqx.modules.common.service.CommonInfoService;
 import lombok.extern.slf4j.Slf4j;
@@ -34,15 +37,16 @@ public class SenInfoCheckUtil {
 
     private static Logger logger = LoggerFactory.getLogger(SenInfoCheckUtil.class);
 
-    private static String MpAccessToken;
-
     // 这里使用静态,让 service 属于类
     private static CommonInfoService commonInfoService;
 
+    private static RedisUtils redisUtils;
+
     // 注入的时候,给类的 service 注入
     @Autowired
-    public void setWxChatContentService(CommonInfoService commonInfoService) {
+    public void setWxChatContentService(CommonInfoService commonInfoService, RedisUtils redisUtils) {
         SenInfoCheckUtil.commonInfoService = commonInfoService;
+        SenInfoCheckUtil.redisUtils = redisUtils;
     }
 
 
@@ -53,10 +57,13 @@ public class SenInfoCheckUtil {
      * @return AccessToken
      */
     public static String getMpToken(){
-        /*if(StringUtils.isEmpty(MpAccessToken)){
-            getMpAccessToken();
-        }*/
-        return getMpAccessToken();
+        String token = (String) redisUtils.get(RedisKey.MP_TOKEN_CACHE_KEY);
+        if (StrUtil.isBlank(token)) {
+            token = getMpAccessToken();
+
+            redisUtils.set(RedisKey.MP_TOKEN_CACHE_KEY, token, RedisUtils.HOUR_ONE_EXPIRE);
+        }
+        return token;
     }
 
     /**
@@ -66,14 +73,23 @@ public class SenInfoCheckUtil {
      * @return AccessToken
      */
     public static String getRiderMpToken(){
-        /*if(StringUtils.isEmpty(MpAccessToken)){
-            getMpAccessToken();
-        }*/
-        return getRiderMpAccessToken();
+        String token = (String) redisUtils.get(RedisKey.MP_OF_RIDER_TOKEN_CACHE_KEY);
+        if (StrUtil.isBlank(token)) {
+            token = getRiderMpAccessToken();
+
+            redisUtils.set(RedisKey.MP_OF_RIDER_TOKEN_CACHE_KEY, token, RedisUtils.HOUR_ONE_EXPIRE);
+        }
+        return token;
     }
 
     public static String getShopMpToken(){
-        return getShopMpAccessToken();
+        String token = (String) redisUtils.get(RedisKey.MP_OF_SHOP_TOKEN_CACHE_KEY);
+        if (StrUtil.isBlank(token)) {
+            token = getShopMpAccessToken();
+
+            redisUtils.set(RedisKey.MP_OF_SHOP_TOKEN_CACHE_KEY, token, RedisUtils.HOUR_ONE_EXPIRE);
+        }
+        return token;
     }
 
 

+ 2 - 14
src/main/resources/application.yml

@@ -29,19 +29,7 @@ spring:
       max-file-size: 1024MB
       max-request-size: 1024MB
       enabled: true
-  redis:
-    open: false  # 是否开启redis缓存  true开启   false关闭
-    database: 0
-    host: 103.131.169.54
-    port: 6379
-    password: dev@redis@1234    # 密码(默认为空)
-    timeout: 6000ms  # 连接超时时长(毫秒)
-    jedis:
-      pool:
-        max-active: 1000  # 连接池最大连接数(使用负值表示没有限制)
-        max-wait: -1ms      # 连接池最大阻塞等待时间(使用负值表示没有限制)
-        max-idle: 10      # 连接池中的最大空闲连接
-        min-idle: 5       # 连接池中的最小空闲连接
+
   mvc:
     throw-exception-if-no-handler-found: true
     pathmatch:
@@ -76,7 +64,7 @@ mybatis-plus:
 
 sqx:
   redis:
-    open: false
+    open: true
   shiro:
     redis: false
   # APP模块,是通过jwt认证的,如果要使用APP模块,则需要修改【加密秘钥】