|
@@ -1,18 +1,25 @@
|
|
|
package cn.newfeifan.mall.sale.service.merchant;
|
|
|
|
|
|
import cn.newfeifan.mall.framework.common.pojo.PageResult;
|
|
|
+import cn.newfeifan.mall.framework.common.util.json.JsonUtils;
|
|
|
import cn.newfeifan.mall.module.product.service.sku.ProductSkuService;
|
|
|
+import cn.newfeifan.mall.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
|
|
|
import cn.newfeifan.mall.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
import cn.newfeifan.mall.module.system.dal.mysql.user.AdminUserMapper;
|
|
|
+import cn.newfeifan.mall.module.system.dal.redis.oauth2.OAuth2AccessTokenRedisDAO;
|
|
|
+import cn.newfeifan.mall.module.system.mq.message.login.LoginSendMessage;
|
|
|
import cn.newfeifan.mall.module.system.service.user.AdminUserService;
|
|
|
import cn.newfeifan.mall.module.trade.service.order.TradeOrderQueryService;
|
|
|
import cn.newfeifan.mall.sale.controller.admin.merchant.vo.MerchantPageReqVO;
|
|
|
import cn.newfeifan.mall.sale.controller.admin.merchant.vo.MerchantRespVO;
|
|
|
import cn.newfeifan.mall.sale.controller.admin.merchant.vo.MerchantSaveReqVO;
|
|
|
+import cn.newfeifan.mall.sale.controller.admin.shop.vo.ShopRespVO;
|
|
|
import cn.newfeifan.mall.sale.controller.admin.shop.vo.ShopSaveReqVO;
|
|
|
import cn.newfeifan.mall.sale.dal.dataobject.merchant.MerchantDO;
|
|
|
import cn.newfeifan.mall.sale.dal.mysql.merchant.MerchantMapper;
|
|
|
+import cn.newfeifan.mall.sale.dal.redis.ShopMessage;
|
|
|
import cn.newfeifan.mall.sale.service.shop.ShopService;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -27,6 +34,7 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
@@ -130,4 +138,42 @@ public class MerchantServiceImpl implements MerchantService {
|
|
|
return new ArrayList<>(map.values());
|
|
|
}
|
|
|
|
|
|
+ @Resource
|
|
|
+ private OAuth2AccessTokenRedisDAO oauth2AccessTokenRedisDAO;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doSendMail(LoginSendMessage message) {
|
|
|
+
|
|
|
+ // 查询用户的商户信息,并且缓存到redis中
|
|
|
+ OAuth2AccessTokenDO oAuth2AccessTokenDO = message.getOAuth2AccessTokenDO();
|
|
|
+ ShopMessage shopMessage = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get("shop:" + message.getOAuth2AccessTokenDO().getAccessToken()), ShopMessage.class);
|
|
|
+ if (shopMessage != null) {
|
|
|
+ // 刷新时间
|
|
|
+ stringRedisTemplate.opsForValue().set("shop:" + oAuth2AccessTokenDO.getUserId(), JsonUtils.toJsonString(shopMessage), 3600 * 24, TimeUnit.SECONDS);
|
|
|
+ } else {
|
|
|
+ // 查询数据库
|
|
|
+ AdminUserDO adminUserDO = userMapper.selectById(message.getOAuth2AccessTokenDO().getUserId());
|
|
|
+ if (adminUserDO.getShopId() != null) {
|
|
|
+ ShopMessage addRedis = new ShopMessage().setShopId(adminUserDO.getShopId()).setMerId(adminUserDO.getMerchantId());
|
|
|
+ stringRedisTemplate.opsForValue().set("shop:" + oAuth2AccessTokenDO.getUserId(), JsonUtils.toJsonString(addRedis), 3600 * 24, TimeUnit.SECONDS);
|
|
|
+ } else {
|
|
|
+ // 获取随机店铺
|
|
|
+ List<ShopRespVO> merchantAllShop = shopService.getMerchantAllShop(adminUserDO.getMerchantId());
|
|
|
+ oAuth2AccessTokenDO.setMerchantId(adminUserDO.getMerchantId());
|
|
|
+ Long shopId = null;
|
|
|
+ if (merchantAllShop.size() > 0) {
|
|
|
+ shopId = merchantAllShop.get(0).getId();
|
|
|
+ oAuth2AccessTokenDO.setShopId(shopId);
|
|
|
+ }
|
|
|
+ //存储redis
|
|
|
+ ShopMessage addRedis = new ShopMessage().setShopId(shopId).setMerId(adminUserDO.getMerchantId());
|
|
|
+ stringRedisTemplate.opsForValue().set("shop:" + oAuth2AccessTokenDO.getUserId(), JsonUtils.toJsonString(addRedis), 3600 * 24, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|