96 lines
3.6 KiB
Java
96 lines
3.6 KiB
Java
package com.upchina.common.service;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.upchina.common.handler.BizException;
|
|
import com.upchina.common.query.AppUserInfoQuery;
|
|
import com.upchina.common.result.ResponseStatus;
|
|
import com.upchina.common.util.JwtUtil;
|
|
import com.upchina.common.util.logger.LoggerUtil;
|
|
import com.upchina.common.vo.AppCUserInfoVO;
|
|
import com.upchina.common.vo.AuthResultVO;
|
|
import com.upchina.common.vo.FrontUserVO;
|
|
import com.upchina.rbac.entity.WxUser;
|
|
import com.upchina.rbac.mapper.WxUserMapper;
|
|
import com.upchina.rbac.service.UserBlackListService;
|
|
import com.upchina.video.service.admin.AdminVideoCustomerService;
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
@Service
|
|
public class AppUserService {
|
|
|
|
@Value("${jwt.key}")
|
|
private String jwtKey;
|
|
|
|
@Value("${jwt.secret}")
|
|
private String jwtSecret;
|
|
|
|
@Resource
|
|
private WxUserMapper wxUserMapper;
|
|
|
|
@Resource
|
|
private UserBlackListService userBlackListService;
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public AppCUserInfoVO getUserInfo(AppUserInfoQuery query) {
|
|
String userId = query.getUserId();
|
|
Integer clientType = query.getClientType();
|
|
AppCUserInfoVO userInfoVO = new AppCUserInfoVO();
|
|
userInfoVO.setUserId(userId);
|
|
userInfoVO.setClientType(clientType);
|
|
// TODO 对接前端健全
|
|
FrontUserVO frontUserVO = new FrontUserVO();
|
|
frontUserVO.setUserId(userId);
|
|
frontUserVO.setUserName(userId);
|
|
frontUserVO.setClientType(clientType);
|
|
if (frontUserVO != null) {
|
|
// 校验黑名单
|
|
if (userBlackListService.check(userId)) {
|
|
throw new BizException(ResponseStatus.USER_BLACK_LIST_ERROR);
|
|
}
|
|
userInfoVO.setUserId(userId);
|
|
userInfoVO.setUserName(frontUserVO.getUserName());
|
|
userInfoVO.setImgUrl(frontUserVO.getImgUrl());
|
|
String upToken = JwtUtil.encrypt(jwtSecret, jwtKey, frontUserVO);
|
|
userInfoVO.setUpToken(upToken);
|
|
//记录微信用户数据数据
|
|
try {
|
|
WxUser wxUser = new WxUser(frontUserVO);
|
|
// 隐藏手机号
|
|
wxUser.setNickName(AdminVideoCustomerService.filterMobile(wxUser.getNickName()));
|
|
LambdaQueryWrapper<WxUser> wrapper = Wrappers.<WxUser>lambdaQuery().eq(WxUser::getId, frontUserVO.getUserId());
|
|
if (wxUserMapper.exists(wrapper)) {
|
|
//修改
|
|
wxUserMapper.updateById(wxUser);
|
|
} else {
|
|
//新增
|
|
wxUserMapper.insert(wxUser);
|
|
}
|
|
} catch (Exception e) {
|
|
LoggerUtil.error("保存微信用户信息失败:", ExceptionUtils.getStackTrace(e));
|
|
}
|
|
}
|
|
return userInfoVO;
|
|
}
|
|
|
|
/**
|
|
* 校验用户是否有权限 true 有权限 false 无权限
|
|
*
|
|
* @param auth 权限字符串,“,”分隔
|
|
* @param frontUserVO 登录用户信息
|
|
*/
|
|
public AuthResultVO checkAuth(String auth, FrontUserVO frontUserVO) {
|
|
if (StrUtil.isBlank(auth) || frontUserVO == null) {
|
|
return new AuthResultVO(true);
|
|
}
|
|
return new AuthResultVO(false);
|
|
}
|
|
|
|
}
|