给用户/角色/模块关系表增加租户字段

This commit is contained in:
季圣华
2021-11-05 21:50:09 +08:00
parent 69742cf392
commit c469520641
8 changed files with 180 additions and 59 deletions

View File

@@ -411,7 +411,7 @@ public class UserService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void addUserAndOrgUserRel(UserEx ue) throws Exception{
public void addUserAndOrgUserRel(UserEx ue, HttpServletRequest request) throws Exception{
if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginName())) {
throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
@@ -436,7 +436,7 @@ public class UserService {
ubObj.put("type", "UserRole");
ubObj.put("keyid", userId);
ubObj.put("value", "[" + ue.getRoleId() + "]");
userBusinessService.insertUserBusiness(ubObj, null);
userBusinessService.insertUserBusiness(ubObj, request);
}
if(ue.getOrgaId()==null){
//如果没有选择机构,就不建机构和用户的关联关系
@@ -522,7 +522,8 @@ public class UserService {
JSONArray ubArr = new JSONArray();
ubArr.add(manageRoleId);
ubObj.put("value", ubArr.toString());
userBusinessService.insertUserBusiness(ubObj, ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
ubObj.put("tenantId", ue.getId());
userBusinessService.insertUserBusiness(ubObj, null);
//创建租户信息
JSONObject tenantObj = new JSONObject();
tenantObj.put("tenantId", ue.getId());
@@ -551,7 +552,7 @@ public class UserService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateUserAndOrgUserRel(UserEx ue) throws Exception{
public void updateUserAndOrgUserRel(UserEx ue, HttpServletRequest request) throws Exception{
if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginName())) {
throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
@@ -583,9 +584,9 @@ public class UserService {
Long ubId = userBusinessService.checkIsValueExist("UserRole", ue.getId().toString());
if(ubId!=null) {
ubObj.put("id", ubId);
userBusinessService.updateUserBusiness(ubObj, null);
userBusinessService.updateUserBusiness(ubObj, request);
} else {
userBusinessService.insertUserBusiness(ubObj, null);
userBusinessService.insertUserBusiness(ubObj, request);
}
}
if (ue.getOrgaId() == null) {

View File

@@ -11,6 +11,7 @@ import com.jsh.erp.service.functions.FunctionService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -68,6 +69,14 @@ public class UserBusinessService {
UserBusiness userBusiness = JSONObject.parseObject(obj.toJSONString(), UserBusiness.class);
int result=0;
try{
String token = "";
if(request!=null) {
token = request.getHeader("X-Access-Token");
Long tenantId = Tools.getTenantIdByToken(token);
if(tenantId!=0L) {
userBusiness.setTenantId(tenantId);
}
}
String value = userBusiness.getValue();
String newValue = value.replaceAll(",","\\]\\[");
userBusiness.setValue(newValue);
@@ -138,6 +147,19 @@ public class UserBusinessService {
return list;
}
public List<UserBusiness> getListBy(String keyId, String type)throws Exception{
List<UserBusiness> list=null;
try{
UserBusinessExample example = new UserBusinessExample();
example.createCriteria().andKeyIdEqualTo(keyId).andTypeEqualTo(type)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
list= userBusinessMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public String getUBValueByTypeAndKeyId(String type, String keyId) throws Exception {
String ubValue = "";
List<UserBusiness> ubList = getBasicData(keyId, type);