创建admin用户有两种方式:
业务流程:
@Override public GraceJSONResult addNewAdmin(AdminBO adminBO, BindingResult bindingResult) { // 1. 判断字段是否有错 if (bindingResult.hasErrors()) { Map<String, String> bindResultErrors = super.getBindResultErrors(bindingResult); return GraceJSONResult.errorMap(bindResultErrors); } // 2. 判断是否有base64图片 若有base64图片表示人脸识别注册 可以无需输入密码 if (StringUtils.isBlank(adminBO.getImg64())) { if (StringUtils.isBlank(adminBO.getPassword()) || StringUtils.isBlank(adminBO.getConfirmPassword())) { GraceException.display(ResponseStatusEnum.ADMIN_PASSWORD_ERROR); } // 判断密码和确认密码是否一致 if (!adminBO.getPassword().equals(adminBO.getConfirmPassword())) { GraceException.display(ResponseStatusEnum.ADMIN_PASSWORD_ERROR); } } // 校验用户是否存在 this.checkAdminExits(adminBO.getUsername()); adminService.addAdminUser(adminBO); return GraceJSONResult.ok(); }
service
业务流程:
@Override @Transactional public void addAdminUser(AdminBO adminBO) { AdminUser adminUser = new AdminUser(); adminUser.setAdminName(adminBO.getAdminName()); adminUser.setUsername(adminBO.getUsername()); if (StringUtils.isNotBlank(adminBO.getPassword()) && StringUtils.isNotBlank(adminBO.getConfirmPassword())) { String password = BCrypt.hashpw(adminBO.getPassword(), BCrypt.gensalt()); adminUser.setPassword(password); } if (StringUtils.isNotBlank(adminBO.getFaceId())) { adminUser.setFaceId(adminBO.getFaceId()); } adminUser.setCreatedTime(new Date()); adminUser.setUpdatedTime(new Date()); int result = adminMapper.insert(adminUser); if (result != 1) { GraceException.display(ResponseStatusEnum.ADMIN_CREATE_ERROR); } }