|
@@ -1,6 +1,7 @@
|
|
|
package com.gis.admin.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONPath;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.gis.admin.entity.dto.WxUserDto;
|
|
@@ -11,6 +12,7 @@ import com.gis.common.base.exception.BaseRuntimeException;
|
|
|
import com.gis.common.base.service.IBaseService;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
|
import com.gis.common.constant.ErrorEnum;
|
|
|
+import com.gis.common.constant.TypeCode;
|
|
|
import com.gis.common.util.RedisUtil;
|
|
|
import com.gis.common.util.Result;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -19,8 +21,7 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -38,6 +39,8 @@ public class WxUserServiceImpl extends ServiceImpl<WxUserMapper, WxUserEntity> i
|
|
|
@Autowired
|
|
|
IBaseService iBaseService;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public WxUserEntity findByOpenId(String openId) {
|
|
|
LambdaQueryWrapper<WxUserEntity> wrapper = new LambdaQueryWrapper<>();
|
|
@@ -50,6 +53,11 @@ public class WxUserServiceImpl extends ServiceImpl<WxUserMapper, WxUserEntity> i
|
|
|
WxUserEntity entity = getById(param.getId());
|
|
|
BeanUtils.copyProperties(param, entity);
|
|
|
this.updateById(entity);
|
|
|
+
|
|
|
+ // 删除微信用户缓存
|
|
|
+ String wxUserKey = TypeCode.WX_USER_KEY + entity.getId();
|
|
|
+ redisUtil.delete(wxUserKey);
|
|
|
+
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
@@ -63,6 +71,24 @@ public class WxUserServiceImpl extends ServiceImpl<WxUserMapper, WxUserEntity> i
|
|
|
String redisWxTokenKey = configConstant.redisPrefix + token;
|
|
|
BaseRuntimeException.isTrue(!redisUtil.hasKey(redisWxTokenKey), ErrorEnum.FAILURE_CODE_3004.code(), ErrorEnum.FAILURE_CODE_3004.message());
|
|
|
|
|
|
- return Result.success();
|
|
|
+ Long userId = iBaseService.getUserId();
|
|
|
+
|
|
|
+ return Result.success(this.cacheWxUserById(userId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public WxUserEntity cacheWxUserById(Long userId){
|
|
|
+ String wxUserKey = TypeCode.WX_USER_KEY + userId;
|
|
|
+ WxUserEntity userEntity;
|
|
|
+ if (redisUtil.hasKey(wxUserKey)){
|
|
|
+ JSONObject data = (JSONObject)redisUtil.get(wxUserKey);
|
|
|
+ userEntity = JSON.parseObject(data.toJSONString(), WxUserEntity.class);
|
|
|
+ } else {
|
|
|
+ userEntity = this.getById(userId);
|
|
|
+ // 1小时有效
|
|
|
+ redisUtil.setCacheObject(wxUserKey, userEntity, 1, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ return userEntity;
|
|
|
+
|
|
|
}
|
|
|
}
|