Commit 491e44b0 authored by 季圣华's avatar 季圣华
Browse files

禁止注册和添加admin用户

parent 40fc728e
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
if (res && res.code === 200) { if (res && res.code === 200) {
alert("注册成功!"); alert("注册成功!");
} else { } else {
alert("注册失败!"); alert(res.msg);
} }
}, },
//此处添加错误处理 //此处添加错误处理
......
...@@ -208,6 +208,11 @@ public class BusinessConstants { ...@@ -208,6 +208,11 @@ public class BusinessConstants {
public static final String DELETE_TYPE_NORMAL = "1"; public static final String DELETE_TYPE_NORMAL = "1";
public static final String DELETE_TYPE_FORCE = "2"; public static final String DELETE_TYPE_FORCE = "2";
/**
* 默认管理员账号
*/
public static final String DEFAULT_MANAGER = "admin";
......
...@@ -56,6 +56,9 @@ public class ExceptionConstants { ...@@ -56,6 +56,9 @@ public class ExceptionConstants {
//用户录入数量超出限制 //用户录入数量超出限制
public static final int USER_OVER_LIMIT_FAILED_CODE = 500004; public static final int USER_OVER_LIMIT_FAILED_CODE = 500004;
public static final String USER_OVER_LIMIT_FAILED_MSG = "用户录入数量超出限制,请联系管理员续费"; public static final String USER_OVER_LIMIT_FAILED_MSG = "用户录入数量超出限制,请联系管理员续费";
//此用户名限制使用
public static final int USER_NAME_LIMIT_USE_CODE = 500004;
public static final String USER_NAME_LIMIT_USE_MSG = "此用户名限制使用";
/** /**
* 角色信息 * 角色信息
......
...@@ -223,38 +223,43 @@ public class UserService { ...@@ -223,38 +223,43 @@ public class UserService {
} }
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void addUserAndOrgUserRel(UserEx ue) throws Exception{ public void addUserAndOrgUserRel(UserEx ue) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER, if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) {
BusinessConstants.LOG_OPERATION_TYPE_ADD, throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
//检查用户名和登录名 } else {
checkUserNameAndLoginName(ue); logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER,
//新增用户信息 BusinessConstants.LOG_OPERATION_TYPE_ADD,
ue= this.addUser(ue); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if(ue==null){ //检查用户名和登录名
logger.error("异常码[{}],异常提示[{}],参数,[{}]", checkUserNameAndLoginName(ue);
ExceptionConstants.USER_ADD_FAILED_CODE,ExceptionConstants.USER_ADD_FAILED_MSG); //新增用户信息
throw new BusinessRunTimeException(ExceptionConstants.USER_ADD_FAILED_CODE, ue= this.addUser(ue);
ExceptionConstants.USER_ADD_FAILED_MSG); if(ue==null){
} logger.error("异常码[{}],异常提示[{}],参数,[{}]",
if(ue.getOrgaId()==null){ ExceptionConstants.USER_ADD_FAILED_CODE,ExceptionConstants.USER_ADD_FAILED_MSG);
//如果没有选择机构,就不建机构和用户的关联关系 throw new BusinessRunTimeException(ExceptionConstants.USER_ADD_FAILED_CODE,
return; ExceptionConstants.USER_ADD_FAILED_MSG);
} }
//新增用户和机构关联关系 if(ue.getOrgaId()==null){
OrgaUserRel oul=new OrgaUserRel(); //如果没有选择机构,就不建机构和用户的关联关系
//机构id return;
oul.setOrgaId(ue.getOrgaId()); }
//用户id //新增用户和机构关联关系
oul.setUserId(ue.getId()); OrgaUserRel oul=new OrgaUserRel();
//用户在机构中的排序 //机构id
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq()); oul.setOrgaId(ue.getOrgaId());
//用户id
oul.setUserId(ue.getId());
//用户在机构中的排序
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq());
oul=orgaUserRelService.addOrgaUserRel(oul); oul=orgaUserRelService.addOrgaUserRel(oul);
if(oul==null){ if(oul==null){
logger.error("异常码[{}],异常提示[{}],参数,[{}]", logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG); ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE, throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,
ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG); ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG);
}
} }
} }
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
...@@ -288,30 +293,35 @@ public class UserService { ...@@ -288,30 +293,35 @@ public class UserService {
* description: * description:
* 多次创建事务,事物之间无法协同,应该在入口处创建一个事务以做协调 * 多次创建事务,事物之间无法协同,应该在入口处创建一个事务以做协调
*/ */
ue.setPassword(Tools.md5Encryp(ue.getPassword())); if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) {
ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM); throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
if(ue.getIsmanager()==null){ ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER); } else {
} ue.setPassword(Tools.md5Encryp(ue.getPassword()));
ue.setStatus(BusinessConstants.USER_STATUS_NORMAL); ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM);
int i=userMapperEx.addUser(ue); if (ue.getIsmanager() == null) {
//更新租户id ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER);
User user = new User(); }
user.setId(ue.getId()); ue.setStatus(BusinessConstants.USER_STATUS_NORMAL);
user.setTenantId(ue.getId()); int i = userMapperEx.addUser(ue);
userService.updateUserTenant(user); //更新租户id
//新增用户与角色的关系 User user = new User();
JSONObject ubObj = new JSONObject(); user.setId(ue.getId());
ubObj.put("type", "UserRole"); user.setTenantId(ue.getId());
ubObj.put("keyid", ue.getId()); userService.updateUserTenant(user);
JSONArray ubArr = new JSONArray(); //新增用户与角色的关系
ubArr.add(manageRoleId); JSONObject ubObj = new JSONObject();
ubObj.put("value", ubArr.toString()); ubObj.put("type", "UserRole");
userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ubObj.put("keyid", ue.getId());
if(i>0){ JSONArray ubArr = new JSONArray();
return ue; ubArr.add(manageRoleId);
ubObj.put("value", ubArr.toString());
userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if (i > 0) {
return ue;
}
return null;
} }
return null;
} }
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
...@@ -323,47 +333,51 @@ public class UserService { ...@@ -323,47 +333,51 @@ public class UserService {
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateUserAndOrgUserRel(UserEx ue) throws Exception{ public void updateUserAndOrgUserRel(UserEx ue) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER, if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) {
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(), throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
//检查用户名和登录名 } else {
checkUserNameAndLoginName(ue); logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER,
//更新用户信息 new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(),
ue=this.updateUser(ue); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if(ue==null){ //检查用户名和登录名
logger.error("异常码[{}],异常提示[{}],参数,[{}]", checkUserNameAndLoginName(ue);
ExceptionConstants.USER_EDIT_FAILED_CODE,ExceptionConstants.USER_EDIT_FAILED_MSG); //更新用户信息
throw new BusinessRunTimeException(ExceptionConstants.USER_EDIT_FAILED_CODE, ue = this.updateUser(ue);
ExceptionConstants.USER_EDIT_FAILED_MSG); if (ue == null) {
} logger.error("异常码[{}],异常提示[{}],参数,[{}]",
if(ue.getOrgaId()==null){ ExceptionConstants.USER_EDIT_FAILED_CODE, ExceptionConstants.USER_EDIT_FAILED_MSG);
//如果没有选择机构,就不建机构和用户的关联关系 throw new BusinessRunTimeException(ExceptionConstants.USER_EDIT_FAILED_CODE,
return; ExceptionConstants.USER_EDIT_FAILED_MSG);
} }
//更新用户和机构关联关系 if (ue.getOrgaId() == null) {
OrgaUserRel oul=new OrgaUserRel(); //如果没有选择机构,就不建机构和用户的关联关系
//机构和用户关联关系id return;
oul.setId(ue.getOrgaUserRelId()); }
//机构id //更新用户和机构关联关系
oul.setOrgaId(ue.getOrgaId()); OrgaUserRel oul = new OrgaUserRel();
//用户id //机构和用户关联关系id
oul.setUserId(ue.getId()); oul.setId(ue.getOrgaUserRelId());
//用户在机构中的排序 //机构id
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq()); oul.setOrgaId(ue.getOrgaId());
if(oul.getId()!=null){ //用户id
//已存在机构和用户的关联关系,更新 oul.setUserId(ue.getId());
oul=orgaUserRelService.updateOrgaUserRel(oul); //用户在机构中的排序
}else{ oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq());
//不存在机构和用户的关联关系,新建 if (oul.getId() != null) {
oul=orgaUserRelService.addOrgaUserRel(oul); //已存在机构和用户的关联关系,更新
} oul = orgaUserRelService.updateOrgaUserRel(oul);
if(oul==null){ } else {
logger.error("异常码[{}],异常提示[{}],参数,[{}]", //不存在机构和用户的关联关系,新建
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG); oul = orgaUserRelService.addOrgaUserRel(oul);
throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE, }
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG); if (oul == null) {
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE, ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE,
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG);
}
} }
} }
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public UserEx updateUser(UserEx ue){ public UserEx updateUser(UserEx ue){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment