Commit af2b9ce7 authored by 技术部-任文超's avatar 技术部-任文超

Merge branch '20180301-Fixed_LogException' into 20180316-UserStatistics

parents 9f290dbd 5b800aeb
......@@ -470,7 +470,7 @@ public class MotanUserServiceImpl implements UserMotanService {
if (userId == null || userId < 1) {
return returnErrorValue("用户id不能为空");
}
WechatUserInfo wechatUserInfo = wechatService.queryOpenIdByUserId(userId);
WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId);
if (wechatUserInfo == null) {
return returnErrorValue("wechat信息为空");
}
......
......@@ -594,7 +594,7 @@ public class InnerController implements IBaseController {
if (userId == null) {
return JsonResult.buildErrorStateResult("userId不能为空", null);
}
WechatUserInfo wechatUserInfo = wechatService.queryOpenIdByUserId(userId);
WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId);
if (wechatUserInfo == null) {
return JsonResult.buildErrorStateResult(null, null);
}
......
......@@ -478,7 +478,7 @@ public class UserController implements IBaseController {
LOGGER.info("微信关联openId,user:[{}],openId:[{}],wechatUserInfo:[{}]",user,openId,userInfo);
if (Objects.isNull(userInfo) && !Objects.isNull(userId)) {
userInfo = wechatService.queryOpenIdByUserId(userId);
userInfo = wechatService.queryByUserId(userId);
}
if (userInfo == null || StringUtils.isNotEmpty(userInfo.getPhoneNo())) {
return JsonResult.buildSuccessResult(null, null);
......
......@@ -16,6 +16,8 @@ public interface IWeChatUserRepository extends JpaRepository<WechatUserInfo, Lon
WechatUserInfo findByUserId(Long userId);
long countByOpenId(String openId);
@Transactional
@Modifying
int removeByUserId(Long userId);
......
......@@ -17,7 +17,7 @@ public interface IWechatService {
WechatUserInfo saveWechatUserInfo(WechatUserInfo userInfo);
WechatUserInfo queryOpenIdByUserId(Long userId);
WechatUserInfo queryByUserId(Long userId);
int forbiddenUserWeChat(Long userId);
}
......@@ -5,24 +5,32 @@ import cn.quantgroup.xyqb.model.webchat.AccessTokenResponse;
import cn.quantgroup.xyqb.repository.IWeChatUserRepository;
import cn.quantgroup.xyqb.service.http.IHttpService;
import cn.quantgroup.xyqb.service.wechat.IWechatService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Example;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
* Created by Miraculous on 2017/1/19.
*/
@Slf4j
@Service
public class WechatServiceImpl implements IWechatService {
private static final String WECHAT_TOKEN_KEY_PREFIX = "wechat:token:";
private static final String WECHAT_USERINFO_KEY_PREFIX = "wechat:userinfo:";
@Autowired
private IHttpService httpService;
@Autowired
......@@ -101,13 +109,23 @@ public class WechatServiceImpl implements IWechatService {
}
@Override
@Cacheable(value = "WechatUserInfo", key = "'openId:' + #openId", unless = "#result == null", cacheManager = "cacheManager")
public WechatUserInfo findWechatUserInfoFromDb(String openId) {
return weChatUserRepository.findByOpenId(openId);
}
@Override
@CacheEvict(value = "WechatUserInfo", key = "'openId:' + #userInfo.openId", cacheManager = "cacheManager")
@Transactional
public WechatUserInfo saveWechatUserInfo(WechatUserInfo userInfo) {
if(Objects.isNull(userInfo) || Objects.isNull(userInfo.getOpenId())){
return null;
}
long count = weChatUserRepository.countByOpenId(userInfo.getOpenId());
if(count > 0){
//注意,这里会抛异常(5000/total),Controller中已捕获处理
return weChatUserRepository.findByOpenId(userInfo.getOpenId());
}
if (null == userInfo.getPhoneNo()) {
userInfo.setPhoneNo("");
}
......@@ -135,12 +153,14 @@ public class WechatServiceImpl implements IWechatService {
}
@Override
public WechatUserInfo queryOpenIdByUserId(Long userId) {
@Cacheable(value = "WechatUserInfo", key = "'userId:' + #userId", unless = "#result == null", cacheManager = "cacheManager")
public WechatUserInfo queryByUserId(Long userId) {
return weChatUserRepository.findByUserId(userId);
}
@Override
@CacheEvict(value = "WechatUserInfo", key = "'userId:' + #userId", cacheManager = "cacheManager")
public int forbiddenUserWeChat(Long userId) {
return weChatUserRepository.removeByUserId(userId);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment