use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.
the class ThirdAppWechatEnterpriseServiceImpl method syncLocalUserToThirdApp.
@Override
public SyncInfoVo syncLocalUserToThirdApp(String ids) {
SyncInfoVo syncInfo = new SyncInfoVo();
String accessToken = this.getAccessToken();
if (accessToken == null) {
syncInfo.addFailInfo("accessToken获取失败!");
return syncInfo;
}
// 获取企业微信所有的用户
List<User> qwUsers = JwUserAPI.getDetailUsersByDepartid("1", null, null, accessToken);
if (qwUsers == null) {
syncInfo.addFailInfo("企业微信用户列表查询失败!");
return syncInfo;
}
List<SysUser> sysUsers;
if (StringUtils.isNotBlank(ids)) {
String[] idList = ids.split(",");
LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(SysUser::getId, (Object[]) idList);
// 获取本地指定用户
sysUsers = sysUserService.list(queryWrapper);
} else {
// 获取本地所有用户
sysUsers = sysUserService.list();
}
// 循环判断新用户和需要更新的用户
for1: for (SysUser sysUser : sysUsers) {
// 外部模拟登陆临时账号,不同步
if ("_reserve_user_external".equals(sysUser.getUsername())) {
continue;
}
/*
* 判断是否同步过的逻辑:
* 1. 查询 sys_third_account(第三方账号表)是否有数据,如果有代表已同步
* 2. 本地表里没有,就先用手机号判断,不通过再用username判断。
*/
User qwUser;
SysThirdAccount sysThirdAccount = sysThirdAccountService.getOneBySysUserId(sysUser.getId(), THIRD_TYPE);
for (User qwUserTemp : qwUsers) {
if (sysThirdAccount == null || oConvertUtils.isEmpty(sysThirdAccount.getThirdUserId()) || !sysThirdAccount.getThirdUserId().equals(qwUserTemp.getUserid())) {
// sys_third_account 表匹配失败,尝试用手机号匹配
String phone = sysUser.getPhone();
if (!(oConvertUtils.isEmpty(phone) || phone.equals(qwUserTemp.getMobile()))) {
// 手机号匹配失败,再尝试用username匹配
String username = sysUser.getUsername();
if (!(oConvertUtils.isEmpty(username) || username.equals(qwUserTemp.getUserid()))) {
// username 匹配失败,直接跳到下一次循环继续
continue;
}
}
}
// 循环到此说明用户匹配成功,进行更新操作
qwUser = this.sysUserToQwUser(sysUser, qwUserTemp);
int errCode = JwUserAPI.updateUser(qwUser, accessToken);
// 收集错误信息
this.syncUserCollectErrInfo(errCode, sysUser, syncInfo);
this.thirdAccountSaveOrUpdate(sysThirdAccount, sysUser.getId(), qwUser.getUserid());
// 更新完成,直接跳到下一次外部循环继续
continue for1;
}
// 循环到此说明是新用户,直接调接口创建
qwUser = this.sysUserToQwUser(sysUser);
int errCode = JwUserAPI.createUser(qwUser, accessToken);
// 收集错误信息
boolean apiSuccess = this.syncUserCollectErrInfo(errCode, sysUser, syncInfo);
if (apiSuccess) {
this.thirdAccountSaveOrUpdate(sysThirdAccount, sysUser.getId(), qwUser.getUserid());
}
}
return syncInfo;
}
use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.
the class SysThirdAccountServiceImpl method createUser.
@Override
public SysUser createUser(String phone, String thirdUserUuid) {
// 先查询第三方,获取登录方式
LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
query.eq(SysThirdAccount::getThirdUserUuid, thirdUserUuid);
SysThirdAccount account = sysThirdAccountMapper.selectOne(query);
// 通过用户名查询数据库是否已存在
SysUser userByName = sysUserMapper.getUserByName(thirdUserUuid);
if (null != userByName) {
// 如果账号存在的话,则自动加上一个时间戳
String format = DateUtils.yyyymmddhhmmss.get().format(new Date());
thirdUserUuid = thirdUserUuid + format;
}
// 添加用户
SysUser user = new SysUser();
user.setActivitiSync(CommonConstant.ACT_SYNC_0);
user.setDelFlag(CommonConstant.DEL_FLAG_0);
user.setStatus(1);
user.setUsername(thirdUserUuid);
user.setPhone(phone);
// 设置初始密码
String salt = oConvertUtils.randomGen(8);
user.setSalt(salt);
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), "123456", salt);
user.setPassword(passwordEncode);
user.setRealname(account.getRealname());
user.setAvatar(account.getAvatar());
String s = this.saveThirdUser(user);
// 更新用户第三方账户表的userId
SysThirdAccount sysThirdAccount = new SysThirdAccount();
sysThirdAccount.setSysUserId(s);
sysThirdAccountMapper.update(sysThirdAccount, query);
return user;
}
use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.
the class SysThirdAccountServiceImpl method updateThirdUserId.
@Override
public void updateThirdUserId(SysUser sysUser, String thirdUserUuid) {
// 修改第三方登录账户表使其进行添加用户id
LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
query.eq(SysThirdAccount::getThirdUserUuid, thirdUserUuid);
SysThirdAccount account = sysThirdAccountMapper.selectOne(query);
SysThirdAccount sysThirdAccount = new SysThirdAccount();
sysThirdAccount.setSysUserId(sysUser.getId());
// 根据当前用户id和登录方式查询第三方登录表
LambdaQueryWrapper<SysThirdAccount> thirdQuery = new LambdaQueryWrapper<>();
thirdQuery.eq(SysThirdAccount::getSysUserId, sysUser.getId());
thirdQuery.eq(SysThirdAccount::getThirdType, account.getThirdType());
SysThirdAccount sysThirdAccounts = sysThirdAccountMapper.selectOne(thirdQuery);
if (sysThirdAccounts != null) {
sysThirdAccount.setThirdUserId(sysThirdAccounts.getThirdUserId());
sysThirdAccountMapper.deleteById(sysThirdAccounts.getId());
}
// 更新用户账户表sys_user_id
sysThirdAccountMapper.update(sysThirdAccount, query);
}
use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.
the class SysUserDepartServiceImpl method queryDepartIdsOfUser.
/**
* 根据用户id查询部门信息
*/
@Override
public List<DepartIdModel> queryDepartIdsOfUser(String userId) {
LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
LambdaQueryWrapper<SysDepart> queryDep = new LambdaQueryWrapper<SysDepart>();
try {
queryUDep.eq(SysUserDepart::getUserId, userId);
List<String> depIdList = new ArrayList<>();
List<DepartIdModel> depIdModelList = new ArrayList<>();
List<SysUserDepart> userDepList = this.list(queryUDep);
if (userDepList != null && userDepList.size() > 0) {
for (SysUserDepart userDepart : userDepList) {
depIdList.add(userDepart.getDepId());
}
queryDep.in(SysDepart::getId, depIdList);
List<SysDepart> depList = sysDepartService.list(queryDep);
if (depList != null || depList.size() > 0) {
for (SysDepart depart : depList) {
depIdModelList.add(new DepartIdModel().convertByUserDepart(depart));
}
}
return depIdModelList;
}
} catch (Exception e) {
e.fillInStackTrace();
}
return null;
}
use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.
the class SysUserDepartServiceImpl method queryUserByDepId.
/**
* 根据部门id查询用户信息
*/
@Override
public List<SysUser> queryUserByDepId(String depId) {
LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
queryUDep.eq(SysUserDepart::getDepId, depId);
List<String> userIdList = new ArrayList<>();
List<SysUserDepart> uDepList = this.list(queryUDep);
if (uDepList != null && uDepList.size() > 0) {
for (SysUserDepart uDep : uDepList) {
userIdList.add(uDep.getUserId());
}
List<SysUser> userList = (List<SysUser>) sysUserService.listByIds(userIdList);
// update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
for (SysUser sysUser : userList) {
sysUser.setSalt("");
sysUser.setPassword("");
}
// update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
return userList;
}
return new ArrayList<SysUser>();
}
Aggregations