From 491e44b0b2296d9df748f27bb5bb0c30487a89d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E5=9C=A3=E5=8D=8E?= <852955+jishenghua@users.noreply.gitee.com> Date: Sat, 13 Apr 2019 20:21:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=81=E6=AD=A2=E6=B3=A8=E5=86=8C=E5=92=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0admin=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- erp_web/register.html | 2 +- .../jsh/erp/constants/BusinessConstants.java | 5 + .../jsh/erp/constants/ExceptionConstants.java | 3 + .../com/jsh/erp/service/user/UserService.java | 202 ++++++++++-------- 4 files changed, 117 insertions(+), 95 deletions(-) diff --git a/erp_web/register.html b/erp_web/register.html index 08517044..636853a9 100644 --- a/erp_web/register.html +++ b/erp_web/register.html @@ -75,7 +75,7 @@ if (res && res.code === 200) { alert("注册成功!"); } else { - alert("注册失败!"); + alert(res.msg); } }, //此处添加错误处理 diff --git a/src/main/java/com/jsh/erp/constants/BusinessConstants.java b/src/main/java/com/jsh/erp/constants/BusinessConstants.java index 1cc8e540..702e956c 100644 --- a/src/main/java/com/jsh/erp/constants/BusinessConstants.java +++ b/src/main/java/com/jsh/erp/constants/BusinessConstants.java @@ -208,6 +208,11 @@ public class BusinessConstants { public static final String DELETE_TYPE_NORMAL = "1"; public static final String DELETE_TYPE_FORCE = "2"; + /** + * 默认管理员账号 + */ + public static final String DEFAULT_MANAGER = "admin"; + diff --git a/src/main/java/com/jsh/erp/constants/ExceptionConstants.java b/src/main/java/com/jsh/erp/constants/ExceptionConstants.java index 0aa1e458..2602e2e9 100644 --- a/src/main/java/com/jsh/erp/constants/ExceptionConstants.java +++ b/src/main/java/com/jsh/erp/constants/ExceptionConstants.java @@ -56,6 +56,9 @@ public class ExceptionConstants { //用户录入数量超出限制 public static final int USER_OVER_LIMIT_FAILED_CODE = 500004; 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 = "此用户名限制使用"; /** * 角色信息 diff --git a/src/main/java/com/jsh/erp/service/user/UserService.java b/src/main/java/com/jsh/erp/service/user/UserService.java index 0d1016f3..966a09f6 100644 --- a/src/main/java/com/jsh/erp/service/user/UserService.java +++ b/src/main/java/com/jsh/erp/service/user/UserService.java @@ -223,38 +223,43 @@ public class UserService { } @Transactional(value = "transactionManager", rollbackFor = Exception.class) public void addUserAndOrgUserRel(UserEx ue) throws Exception{ - logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER, - BusinessConstants.LOG_OPERATION_TYPE_ADD, - ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); - //检查用户名和登录名 - checkUserNameAndLoginName(ue); - //新增用户信息 - ue= this.addUser(ue); - if(ue==null){ - logger.error("异常码[{}],异常提示[{}],参数,[{}]", - ExceptionConstants.USER_ADD_FAILED_CODE,ExceptionConstants.USER_ADD_FAILED_MSG); - throw new BusinessRunTimeException(ExceptionConstants.USER_ADD_FAILED_CODE, - ExceptionConstants.USER_ADD_FAILED_MSG); - } - if(ue.getOrgaId()==null){ - //如果没有选择机构,就不建机构和用户的关联关系 - return; - } - //新增用户和机构关联关系 - OrgaUserRel oul=new OrgaUserRel(); - //机构id - oul.setOrgaId(ue.getOrgaId()); - //用户id - oul.setUserId(ue.getId()); - //用户在机构中的排序 - oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq()); + if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) { + throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE, + ExceptionConstants.USER_NAME_LIMIT_USE_MSG); + } else { + logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER, + BusinessConstants.LOG_OPERATION_TYPE_ADD, + ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); + //检查用户名和登录名 + checkUserNameAndLoginName(ue); + //新增用户信息 + ue= this.addUser(ue); + if(ue==null){ + logger.error("异常码[{}],异常提示[{}],参数,[{}]", + ExceptionConstants.USER_ADD_FAILED_CODE,ExceptionConstants.USER_ADD_FAILED_MSG); + throw new BusinessRunTimeException(ExceptionConstants.USER_ADD_FAILED_CODE, + ExceptionConstants.USER_ADD_FAILED_MSG); + } + if(ue.getOrgaId()==null){ + //如果没有选择机构,就不建机构和用户的关联关系 + return; + } + //新增用户和机构关联关系 + OrgaUserRel oul=new OrgaUserRel(); + //机构id + oul.setOrgaId(ue.getOrgaId()); + //用户id + oul.setUserId(ue.getId()); + //用户在机构中的排序 + oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq()); - oul=orgaUserRelService.addOrgaUserRel(oul); - if(oul==null){ - logger.error("异常码[{}],异常提示[{}],参数,[{}]", - ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG); - throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE, - ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG); + oul=orgaUserRelService.addOrgaUserRel(oul); + if(oul==null){ + logger.error("异常码[{}],异常提示[{}],参数,[{}]", + ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG); + throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE, + ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG); + } } } @Transactional(value = "transactionManager", rollbackFor = Exception.class) @@ -288,30 +293,35 @@ public class UserService { * description: * 多次创建事务,事物之间无法协同,应该在入口处创建一个事务以做协调 */ - ue.setPassword(Tools.md5Encryp(ue.getPassword())); - ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM); - if(ue.getIsmanager()==null){ - ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER); + if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) { + throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE, + ExceptionConstants.USER_NAME_LIMIT_USE_MSG); + } else { + ue.setPassword(Tools.md5Encryp(ue.getPassword())); + ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM); + if (ue.getIsmanager() == null) { + ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER); + } + ue.setStatus(BusinessConstants.USER_STATUS_NORMAL); + int i = userMapperEx.addUser(ue); + //更新租户id + User user = new User(); + user.setId(ue.getId()); + user.setTenantId(ue.getId()); + userService.updateUserTenant(user); + //新增用户与角色的关系 + JSONObject ubObj = new JSONObject(); + ubObj.put("type", "UserRole"); + ubObj.put("keyid", ue.getId()); + JSONArray ubArr = new JSONArray(); + ubArr.add(manageRoleId); + ubObj.put("value", ubArr.toString()); + userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); + if (i > 0) { + return ue; + } + return null; } - ue.setStatus(BusinessConstants.USER_STATUS_NORMAL); - int i=userMapperEx.addUser(ue); - //更新租户id - User user = new User(); - user.setId(ue.getId()); - user.setTenantId(ue.getId()); - userService.updateUserTenant(user); - //新增用户与角色的关系 - JSONObject ubObj = new JSONObject(); - ubObj.put("type", "UserRole"); - ubObj.put("keyid", ue.getId()); - JSONArray ubArr = new JSONArray(); - ubArr.add(manageRoleId); - ubObj.put("value", ubArr.toString()); - userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); - if(i>0){ - return ue; - } - return null; } @Transactional(value = "transactionManager", rollbackFor = Exception.class) @@ -323,47 +333,51 @@ public class UserService { @Transactional(value = "transactionManager", rollbackFor = Exception.class) public void updateUserAndOrgUserRel(UserEx ue) throws Exception{ - logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER, - new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(), - ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); - //检查用户名和登录名 - checkUserNameAndLoginName(ue); - //更新用户信息 - ue=this.updateUser(ue); - if(ue==null){ - logger.error("异常码[{}],异常提示[{}],参数,[{}]", - ExceptionConstants.USER_EDIT_FAILED_CODE,ExceptionConstants.USER_EDIT_FAILED_MSG); - throw new BusinessRunTimeException(ExceptionConstants.USER_EDIT_FAILED_CODE, - ExceptionConstants.USER_EDIT_FAILED_MSG); + if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) { + throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE, + ExceptionConstants.USER_NAME_LIMIT_USE_MSG); + } else { + logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER, + new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(), + ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); + //检查用户名和登录名 + checkUserNameAndLoginName(ue); + //更新用户信息 + ue = this.updateUser(ue); + if (ue == null) { + logger.error("异常码[{}],异常提示[{}],参数,[{}]", + ExceptionConstants.USER_EDIT_FAILED_CODE, ExceptionConstants.USER_EDIT_FAILED_MSG); + throw new BusinessRunTimeException(ExceptionConstants.USER_EDIT_FAILED_CODE, + ExceptionConstants.USER_EDIT_FAILED_MSG); + } + if (ue.getOrgaId() == null) { + //如果没有选择机构,就不建机构和用户的关联关系 + return; + } + //更新用户和机构关联关系 + OrgaUserRel oul = new OrgaUserRel(); + //机构和用户关联关系id + oul.setId(ue.getOrgaUserRelId()); + //机构id + oul.setOrgaId(ue.getOrgaId()); + //用户id + oul.setUserId(ue.getId()); + //用户在机构中的排序 + oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq()); + if (oul.getId() != null) { + //已存在机构和用户的关联关系,更新 + oul = orgaUserRelService.updateOrgaUserRel(oul); + } else { + //不存在机构和用户的关联关系,新建 + oul = orgaUserRelService.addOrgaUserRel(oul); + } + 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); + } } - if(ue.getOrgaId()==null){ - //如果没有选择机构,就不建机构和用户的关联关系 - return; - } - //更新用户和机构关联关系 - OrgaUserRel oul=new OrgaUserRel(); - //机构和用户关联关系id - oul.setId(ue.getOrgaUserRelId()); - //机构id - oul.setOrgaId(ue.getOrgaId()); - //用户id - oul.setUserId(ue.getId()); - //用户在机构中的排序 - oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq()); - if(oul.getId()!=null){ - //已存在机构和用户的关联关系,更新 - oul=orgaUserRelService.updateOrgaUserRel(oul); - }else{ - //不存在机构和用户的关联关系,新建 - oul=orgaUserRelService.addOrgaUserRel(oul); - } - 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) public UserEx updateUser(UserEx ue){