修改互联网端用户信息和用户权限

This commit is contained in:
sh
2025-11-17 16:21:13 +08:00
parent b86c9baadb
commit 7d488d9d12

View File

@@ -24,6 +24,7 @@ import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory; import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.framework.security.context.AuthenticationContextHolder; import com.ruoyi.framework.security.context.AuthenticationContextHolder;
import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.ISysUserService;
import io.jsonwebtoken.lang.Collections;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
@@ -32,6 +33,7 @@ import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Service @Service
@@ -109,13 +111,14 @@ public class OauthLoginHlwService {
String cacheKey = REDIS_KEY_PORTAL_USER_MAPPING + idCard; String cacheKey = REDIS_KEY_PORTAL_USER_MAPPING + idCard;
String localUsername = redisCache.getCacheObject(cacheKey); String localUsername = redisCache.getCacheObject(cacheKey);
if (StringUtils.isNotBlank(localUsername)) { if (StringUtils.isNotBlank(localUsername)) {
updateUserInfo(localUsername,wwTyInfo);
return localUsername; return localUsername;
} }
SysUser localUser=sysUserService.selectUserByIdCard(wwTyInfo.getIdno()); SysUser localUser=sysUserService.selectUserByIdCard(wwTyInfo.getIdno());
if (localUser == null) { if (localUser == null) {
// 本地无用户,自动创建 // 本地无用户,自动创建
localUser = createLocalUser(wwTyInfo); localUser = createLocalUser(cacheKey,wwTyInfo);
// 缓存门户UserID与本地用户名的映射有效期1天可调整 // 缓存门户UserID与本地用户名的映射有效期1天可调整
redisCache.setCacheObject(cacheKey, localUser.getUserName(), 1, TimeUnit.DAYS); redisCache.setCacheObject(cacheKey, localUser.getUserName(), 1, TimeUnit.DAYS);
return localUser.getUserName(); return localUser.getUserName();
@@ -140,20 +143,20 @@ public class OauthLoginHlwService {
/** /**
* 自动创建本地用户 * 自动创建本地用户
*/ */
private SysUser createLocalUser(WwTyInfo wwTyInfo) { private SysUser createLocalUser(String localUsername,WwTyInfo wwTyInfo) {
SysUser newUser = new SysUser(); SysUser newUser = new SysUser();
switch (wwTyInfo.getUsertype()) { switch (wwTyInfo.getUsertype()) {
case "1"://个人 case "1"://个人
newUser.setNickName(wwTyInfo.getName()); newUser.setNickName(wwTyInfo.getName());
newUser.setIdCard(wwTyInfo.getIdno()); newUser.setIdCard(wwTyInfo.getIdno());
newUser.setRoleIds(new Long[]{parseStringToLoing(StringUtil.SYS_QZZ)}); newUser.setRoleIds(new Long[]{parseStringToLoing(StringUtil.SYS_QZZ)});
newUser.setUserName(wwTyInfo.getName()); newUser.setUserName(localUsername);
break; break;
default://单位 default://单位
newUser.setNickName(wwTyInfo.getEnterprisename()); newUser.setNickName(wwTyInfo.getEnterprisename());
newUser.setIdCard(wwTyInfo.getEnterprisecode()); newUser.setIdCard(wwTyInfo.getEnterprisecode());
newUser.setRoleIds(new Long[]{parseStringToLoing(StringUtil.SYS_QY)}); newUser.setRoleIds(new Long[]{parseStringToLoing(StringUtil.SYS_QY)});
newUser.setUserName(wwTyInfo.getEnterprisename()); newUser.setUserName(localUsername);
//企业联系人->现根据社会信用代码查询企业信息 //企业联系人->现根据社会信用代码查询企业信息
Company company=companyService.queryCodeCompany(wwTyInfo.getEnterprisecode()); Company company=companyService.queryCodeCompany(wwTyInfo.getEnterprisecode());
if(company!=null){ if(company!=null){
@@ -241,4 +244,54 @@ public class OauthLoginHlwService {
throw new ServiceException("OAuth 登录失败:" + e.getMessage()); throw new ServiceException("OAuth 登录失败:" + e.getMessage());
} }
} }
/**
* 修改个人信息
* @param localUsername
* @param wwTyInfo
*/
private void updateUserInfo(String localUsername,WwTyInfo wwTyInfo){
SysUser sysUser=new SysUser();
switch (wwTyInfo.getUsertype()){
case "1":
sysUser.setNickName(wwTyInfo.getName());
sysUser.setIdCard(wwTyInfo.getIdno());
sysUser.setRoleIds(new Long[]{parseStringToLoing(StringUtil.SYS_QZZ)});
break;
default:
sysUser.setNickName(wwTyInfo.getEnterprisename());
sysUser.setIdCard(wwTyInfo.getEnterprisecode());
sysUser.setRoleIds(new Long[]{parseStringToLoing(StringUtil.SYS_QY)});
//企业联系人->现根据社会信用代码查询企业信息
updateCompanyContact(wwTyInfo);
}
//查询用户角色
sysUser.setUserName(localUsername);
//查询用户id
SysUser parmUser=sysUserService.selectUserByUserName(localUsername);
sysUser.setUserId(parmUser.getUserId());
sysUserService.updateUser(sysUser);
}
/**
* 修改联系人信息
* @param wwTyInfo
*/
public void updateCompanyContact(WwTyInfo wwTyInfo){
Company company=companyService.queryCodeCompany(wwTyInfo.getEnterprisecode());
if(company!=null){
CompanyContact parm=new CompanyContact();
parm.setContactPerson(wwTyInfo.getContactperson());
parm.setContactPersonPhone(wwTyInfo.getContactphone());
parm.setCompanyId(company.getCompanyId());
List<CompanyContact> companyContacts=companyContactService.getSelectList(parm);
if(Collections.isEmpty(companyContacts)){
CompanyContact companyContact=new CompanyContact();
companyContact.setContactPerson(wwTyInfo.getContactperson());
companyContact.setContactPersonPhone(wwTyInfo.getContactphone());
companyContact.setCompanyId(company.getCompanyId());
companyContactService.insertContact(companyContact);
}
}
}
} }