|
@ -7,6 +7,7 @@ import cn.hutool.core.lang.Snowflake; |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
|
import cn.hutool.extra.servlet.ServletUtil; |
|
|
import com.ccsens.cloudutil.feign.HealthFeignClient; |
|
|
import com.ccsens.cloudutil.feign.HealthFeignClient; |
|
|
import com.ccsens.tall.bean.dto.ProjectDto; |
|
|
import com.ccsens.tall.bean.dto.ProjectDto; |
|
|
import com.ccsens.tall.bean.dto.UserDto; |
|
|
import com.ccsens.tall.bean.dto.UserDto; |
|
@ -72,7 +73,7 @@ public class UserService implements IUserService { |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public UserVo.UserSign signin(WebConstant.CLIENT_TYPE clientType, WebConstant.IDENTIFY_TYPE identifyType, |
|
|
public UserVo.UserSign signin(WebConstant.CLIENT_TYPE clientType, WebConstant.IDENTIFY_TYPE identifyType, |
|
|
String identifier, String credential, String clientIp,String redirect) throws Exception { |
|
|
String identifier, String credential, String clientIp, String redirect) throws Exception { |
|
|
UserVo.UserSign userSignVo = null; |
|
|
UserVo.UserSign userSignVo = null; |
|
|
//1.登陆
|
|
|
//1.登陆
|
|
|
userSignVo = __signin(identifyType, identifier, credential, redirect); |
|
|
userSignVo = __signin(identifyType, identifier, credential, redirect); |
|
@ -90,7 +91,7 @@ public class UserService implements IUserService { |
|
|
return wxEnterpriseLogin(identifier, credential, redirect); |
|
|
return wxEnterpriseLogin(identifier, credential, redirect); |
|
|
case Wxmp: |
|
|
case Wxmp: |
|
|
credential = credential == null ? "old" : credential; |
|
|
credential = credential == null ? "old" : credential; |
|
|
return wxmplogin(identifier,credential); |
|
|
return wxmplogin(identifier, credential); |
|
|
case OAUTH2_Wx: |
|
|
case OAUTH2_Wx: |
|
|
return wxLogin(identifyType, identifier); |
|
|
return wxLogin(identifyType, identifier); |
|
|
case Wx_H5: |
|
|
case Wx_H5: |
|
@ -112,6 +113,7 @@ public class UserService implements IUserService { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 企业登录 |
|
|
* 企业登录 |
|
|
|
|
|
* |
|
|
* @param identifier |
|
|
* @param identifier |
|
|
* @param credential |
|
|
* @param credential |
|
|
* @return |
|
|
* @return |
|
@ -384,35 +386,34 @@ public class UserService implements IUserService { |
|
|
/** |
|
|
/** |
|
|
* 微信小程序 |
|
|
* 微信小程序 |
|
|
*/ |
|
|
*/ |
|
|
private UserVo.UserSign wxmplogin(String code,String gameType) throws Exception { |
|
|
private UserVo.UserSign wxmplogin(String code, String gameType) throws Exception { |
|
|
//0.获取openid
|
|
|
//0.获取openid
|
|
|
WxXcxUtil.WechatUser wechatUser = WxXcxUtil.getUserInfo(code,gameType); |
|
|
WxXcxUtil.WechatUser wechatUser = WxXcxUtil.getUserInfo(code, gameType); |
|
|
String openId = wechatUser.openid; |
|
|
String openId = wechatUser.openid; |
|
|
String unionId = wechatUser.unionid; |
|
|
String unionId = wechatUser.unionid; |
|
|
log.info("小程序登录,openid:{} ,unionId:{}", openId, unionId); |
|
|
log.info("小程序登录,openid:{} ,unionId:{}", openId, unionId); |
|
|
UserVo.UserSign userSignVo = getUserSign(openId, unionId, (byte) WebConstant.IDENTIFY_TYPE.Wxmp.value,null); |
|
|
UserVo.UserSign userSignVo = getUserSign(openId, unionId, (byte) WebConstant.IDENTIFY_TYPE.Wxmp.value, null); |
|
|
return userSignVo; |
|
|
return userSignVo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Data |
|
|
@Data |
|
|
private static class WxEnterpriseParam{ |
|
|
private static class WxEnterpriseParam { |
|
|
private String suiteAccessToken; |
|
|
private String suiteAccessToken; |
|
|
private String userTicket; |
|
|
private String userTicket; |
|
|
private String redirect; |
|
|
private String redirect; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
|
|
|
* @param openId |
|
|
* @param openId |
|
|
* @param unionId |
|
|
* @param unionId |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
private UserVo.UserSign getUserSign(String openId, String unionId, |
|
|
private UserVo.UserSign getUserSign(String openId, String unionId, |
|
|
byte identifyType, WxEnterpriseParam param) { |
|
|
byte identifyType, WxEnterpriseParam param) { |
|
|
UserVo.UserSign userSignVo;//1.查找对应账户,不存在则注册
|
|
|
UserVo.UserSign userSignVo;//1.查找对应账户,不存在则注册
|
|
|
List<SysAuth> authList = null; |
|
|
List<SysAuth> authList = null; |
|
|
SysAuth theAuth = null; |
|
|
SysAuth theAuth = null; |
|
|
if(ObjectUtil.isNotNull(openId)) { |
|
|
if (ObjectUtil.isNotNull(openId)) { |
|
|
SysAuthExample authExample = new SysAuthExample(); |
|
|
SysAuthExample authExample = new SysAuthExample(); |
|
|
authExample.createCriteria().andIdentifyTypeEqualTo(identifyType) |
|
|
authExample.createCriteria().andIdentifyTypeEqualTo(identifyType) |
|
|
.andIdentifierEqualTo(openId); |
|
|
.andIdentifierEqualTo(openId); |
|
@ -420,7 +421,7 @@ public class UserService implements IUserService { |
|
|
} |
|
|
} |
|
|
if (CollectionUtil.isEmpty(authList)) { |
|
|
if (CollectionUtil.isEmpty(authList)) { |
|
|
List<SysAuth> sysAuthList = null; |
|
|
List<SysAuth> sysAuthList = null; |
|
|
if(ObjectUtil.isNotNull(unionId)) { |
|
|
if (ObjectUtil.isNotNull(unionId)) { |
|
|
SysAuthExample sysAuthExample = new SysAuthExample(); |
|
|
SysAuthExample sysAuthExample = new SysAuthExample(); |
|
|
sysAuthExample.createCriteria().andCredentialEqualTo(unionId); |
|
|
sysAuthExample.createCriteria().andCredentialEqualTo(unionId); |
|
|
sysAuthList = authDao.selectByExample(sysAuthExample); |
|
|
sysAuthList = authDao.selectByExample(sysAuthExample); |
|
@ -478,6 +479,7 @@ public class UserService implements IUserService { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取企业微信信息,并绑定用户 |
|
|
* 获取企业微信信息,并绑定用户 |
|
|
|
|
|
* |
|
|
* @param identifyType |
|
|
* @param identifyType |
|
|
* @param param |
|
|
* @param param |
|
|
* @param user |
|
|
* @param user |
|
@ -1032,6 +1034,7 @@ public class UserService implements IUserService { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 查询用户是否关注此项目 |
|
|
* 查询用户是否关注此项目 |
|
|
|
|
|
* |
|
|
* @param currentUserId |
|
|
* @param currentUserId |
|
|
* @param projectId |
|
|
* @param projectId |
|
|
* @return |
|
|
* @return |
|
@ -1039,14 +1042,14 @@ public class UserService implements IUserService { |
|
|
@Override |
|
|
@Override |
|
|
public Boolean getIsAttention(Long currentUserId, Long projectId) { |
|
|
public Boolean getIsAttention(Long currentUserId, Long projectId) { |
|
|
Boolean isAttention = false; |
|
|
Boolean isAttention = false; |
|
|
if(ObjectUtil.isNotNull(sysProjectDao.selectByPrimaryKey(projectId))){ |
|
|
if (ObjectUtil.isNotNull(sysProjectDao.selectByPrimaryKey(projectId))) { |
|
|
UserAttentionExample attentionExample = new UserAttentionExample(); |
|
|
UserAttentionExample attentionExample = new UserAttentionExample(); |
|
|
attentionExample.createCriteria().andProjectIdEqualTo(projectId).andUserIdEqualTo(currentUserId); |
|
|
attentionExample.createCriteria().andProjectIdEqualTo(projectId).andUserIdEqualTo(currentUserId); |
|
|
List<UserAttention> attentionList = userAttentionDao.selectByExample(attentionExample); |
|
|
List<UserAttention> attentionList = userAttentionDao.selectByExample(attentionExample); |
|
|
if(CollectionUtil.isNotEmpty(attentionList)){ |
|
|
if (CollectionUtil.isNotEmpty(attentionList)) { |
|
|
isAttention = true; |
|
|
isAttention = true; |
|
|
} |
|
|
} |
|
|
}else { |
|
|
} else { |
|
|
throw new BaseException(CodeEnum.NOT_PROJECT); |
|
|
throw new BaseException(CodeEnum.NOT_PROJECT); |
|
|
} |
|
|
} |
|
|
return isAttention; |
|
|
return isAttention; |
|
@ -1054,6 +1057,7 @@ public class UserService implements IUserService { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 用户关注某个项目 |
|
|
* 用户关注某个项目 |
|
|
|
|
|
* |
|
|
* @param currentUserId |
|
|
* @param currentUserId |
|
|
* @param projectIdDto |
|
|
* @param projectIdDto |
|
|
*/ |
|
|
*/ |
|
@ -1061,11 +1065,11 @@ public class UserService implements IUserService { |
|
|
public void userAttentionProject(Long currentUserId, ProjectDto.ProjectIdDto projectIdDto) { |
|
|
public void userAttentionProject(Long currentUserId, ProjectDto.ProjectIdDto projectIdDto) { |
|
|
//查找项目
|
|
|
//查找项目
|
|
|
SysProject project = sysProjectDao.selectByPrimaryKey(projectIdDto.getProjectId()); |
|
|
SysProject project = sysProjectDao.selectByPrimaryKey(projectIdDto.getProjectId()); |
|
|
if(ObjectUtil.isNotNull(project)){ |
|
|
if (ObjectUtil.isNotNull(project)) { |
|
|
UserAttentionExample attentionExample = new UserAttentionExample(); |
|
|
UserAttentionExample attentionExample = new UserAttentionExample(); |
|
|
attentionExample.createCriteria().andProjectIdEqualTo(projectIdDto.getProjectId()).andUserIdEqualTo(currentUserId); |
|
|
attentionExample.createCriteria().andProjectIdEqualTo(projectIdDto.getProjectId()).andUserIdEqualTo(currentUserId); |
|
|
List<UserAttention> attentionList = userAttentionDao.selectByExample(attentionExample); |
|
|
List<UserAttention> attentionList = userAttentionDao.selectByExample(attentionExample); |
|
|
if(CollectionUtil.isNotEmpty(attentionList)){ |
|
|
if (CollectionUtil.isNotEmpty(attentionList)) { |
|
|
throw new BaseException(CodeEnum.ALREADY_ATTENTION); |
|
|
throw new BaseException(CodeEnum.ALREADY_ATTENTION); |
|
|
} |
|
|
} |
|
|
UserAttention attention = new UserAttention(); |
|
|
UserAttention attention = new UserAttention(); |
|
@ -1073,7 +1077,7 @@ public class UserService implements IUserService { |
|
|
attention.setUserId(currentUserId); |
|
|
attention.setUserId(currentUserId); |
|
|
attention.setProjectId(projectIdDto.getProjectId()); |
|
|
attention.setProjectId(projectIdDto.getProjectId()); |
|
|
userAttentionDao.insertSelective(attention); |
|
|
userAttentionDao.insertSelective(attention); |
|
|
}else { |
|
|
} else { |
|
|
throw new BaseException(CodeEnum.NOT_PROJECT); |
|
|
throw new BaseException(CodeEnum.NOT_PROJECT); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -1245,7 +1249,7 @@ public class UserService implements IUserService { |
|
|
public UserVo.WxInfo updateUserInfo(Long currentUserId, UserDto.WxInfo userInfo) { |
|
|
public UserVo.WxInfo updateUserInfo(Long currentUserId, UserDto.WxInfo userInfo) { |
|
|
//通过userid查找到用户
|
|
|
//通过userid查找到用户
|
|
|
SysUser user = userDao.selectByPrimaryKey(currentUserId); |
|
|
SysUser user = userDao.selectByPrimaryKey(currentUserId); |
|
|
if(ObjectUtil.isNull(user)){ |
|
|
if (ObjectUtil.isNull(user)) { |
|
|
throw new BaseException(CodeEnum.NOT_LOGIN); |
|
|
throw new BaseException(CodeEnum.NOT_LOGIN); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1298,6 +1302,7 @@ public class UserService implements IUserService { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 更改绑定手机号(不要密码) |
|
|
* 更改绑定手机号(不要密码) |
|
|
|
|
|
* |
|
|
* @param userId |
|
|
* @param userId |
|
|
* @param phoneInfo |
|
|
* @param phoneInfo |
|
|
* @throws Exception |
|
|
* @throws Exception |
|
@ -1325,7 +1330,7 @@ public class UserService implements IUserService { |
|
|
userSign.setUserId(phoneAuth.getUserId()); |
|
|
userSign.setUserId(phoneAuth.getUserId()); |
|
|
userSign.setAuthId(phoneAuth.getId()); |
|
|
userSign.setAuthId(phoneAuth.getId()); |
|
|
|
|
|
|
|
|
}else { |
|
|
} else { |
|
|
//添加一条手机号认证信息
|
|
|
//添加一条手机号认证信息
|
|
|
SysAuth sysAuth = new SysAuth(); |
|
|
SysAuth sysAuth = new SysAuth(); |
|
|
sysAuth.setId(snowflake.nextId()); |
|
|
sysAuth.setId(snowflake.nextId()); |
|
@ -1347,4 +1352,48 @@ public class UserService implements IUserService { |
|
|
} |
|
|
} |
|
|
return userSign; |
|
|
return userSign; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 通过userId获取token |
|
|
|
|
|
* |
|
|
|
|
|
* @param userId |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public String getTokenByUserId(Long userId) { |
|
|
|
|
|
if (ObjectUtil.isNull(userId)) { |
|
|
|
|
|
throw new BaseException(CodeEnum.PARAM_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
Object object = redisUtil.get(RedisKeyManager.getTokenCachedKey(userId)); |
|
|
|
|
|
if (ObjectUtil.isNull(object)) { |
|
|
|
|
|
UserVo.UserSign userSignVo = null; |
|
|
|
|
|
|
|
|
|
|
|
SysAuthExample authExample = new SysAuthExample(); |
|
|
|
|
|
authExample.createCriteria().andUserIdEqualTo(userId); |
|
|
|
|
|
List<SysAuth> authList = authDao.selectByExample(authExample); |
|
|
|
|
|
if (CollectionUtil.isNotEmpty(authList)) { |
|
|
|
|
|
userSignVo = new UserVo.UserSign(); |
|
|
|
|
|
userSignVo.setUserId(authList.get(0).getUserId()); |
|
|
|
|
|
userSignVo.setAuthId(authList.get(0).getId()); |
|
|
|
|
|
} |
|
|
|
|
|
//3.生成token(access_token,refresh_token)
|
|
|
|
|
|
if (ObjectUtil.isNotNull(userSignVo)) { |
|
|
|
|
|
Map<String, Object> theMap = CollectionUtil.newHashMap(); |
|
|
|
|
|
theMap.put("authId", String.valueOf(userSignVo.getAuthId())); |
|
|
|
|
|
Long tokenExpired = 3600 * 1000L * 24 * 100; |
|
|
|
|
|
|
|
|
|
|
|
String token = |
|
|
|
|
|
JwtUtil.createJWT(userId + "", |
|
|
|
|
|
theMap, tokenExpired, |
|
|
|
|
|
WebConstant.JWT_ACCESS_TOKEN_SECERT); |
|
|
|
|
|
redisUtil.set(RedisKeyManager.getTokenCachedKey((Long) userId), |
|
|
|
|
|
token, tokenExpired / 1000); |
|
|
|
|
|
object = token; |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new BaseException(CodeEnum.PARAM_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return object.toString(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|