@Test public void addAdmin() throws Exception { String name ="18075854632"; String phone = "18075854632"; String realName = "laizi"; String password = "123456"; adminService.addAdmin(name,password,phone,realName,1); }
public boolean addAdmin(String name, String password, String phone, String realName ,Integer adminId) throws InvalidArgumentException { if (StringUtils.isBlank(name)) throw new InvalidArgumentException("用户名不能为空!"); if (StringUtils.isBlank(phone)) throw new InvalidArgumentException("手机号不能为空!"); Admin admin = getAdminByName(name); if (admin != null) throw new InvalidArgumentException("改账号已存在!"); admin = new Admin(); admin.setName(name); admin.setPhone(phone); admin.setRealName(realName); admin.setCreatedBy(adminId); admin.setUpdatedBy(adminId); admin.setCreatedAt(new Date()); if (StringUtils.isBlank(password)){ password = BCrypt.hashpw(INIT_PWD, BCrypt.gensalt()); }else{ password = BCrypt.hashpw(password, BCrypt.gensalt()); } admin.setPassword(password); int insert = adminMapper.insertSelective(admin); return (insert>0)?true:false; }
AdminService { public boolean addAdmin(String name, String password, String phone, String realName ,Integer adminId) throws InvalidArgumentException { if (StringUtils.isBlank(name)) throw new InvalidArgumentException("用户名不能为空!"); if (StringUtils.isBlank(phone)) throw new InvalidArgumentException("手机号不能为空!"); Admin admin = getAdminByName(name); if (admin != null) throw new InvalidArgumentException("改账号已存在!"); admin = new Admin(); admin.setName(name); admin.setPhone(phone); admin.setRealName(realName); admin.setCreatedBy(adminId); admin.setUpdatedBy(adminId); admin.setCreatedAt(new Date()); if (StringUtils.isBlank(password)){ password = BCrypt.hashpw(INIT_PWD, BCrypt.gensalt()); }else{ password = BCrypt.hashpw(password, BCrypt.gensalt()); } admin.setPassword(password); int insert = adminMapper.insertSelective(admin); return (insert>0)?true:false; } }
AdminService { public boolean addAdmin(String name, String password, String phone, String realName ,Integer adminId) throws InvalidArgumentException { if (StringUtils.isBlank(name)) throw new InvalidArgumentException("用户名不能为空!"); if (StringUtils.isBlank(phone)) throw new InvalidArgumentException("手机号不能为空!"); Admin admin = getAdminByName(name); if (admin != null) throw new InvalidArgumentException("改账号已存在!"); admin = new Admin(); admin.setName(name); admin.setPhone(phone); admin.setRealName(realName); admin.setCreatedBy(adminId); admin.setUpdatedBy(adminId); admin.setCreatedAt(new Date()); if (StringUtils.isBlank(password)){ password = BCrypt.hashpw(INIT_PWD, BCrypt.gensalt()); }else{ password = BCrypt.hashpw(password, BCrypt.gensalt()); } admin.setPassword(password); int insert = adminMapper.insertSelective(admin); return (insert>0)?true:false; }  }
AdminService { public boolean addAdmin(String name, String password, String phone, String realName ,Integer adminId) throws InvalidArgumentException { if (StringUtils.isBlank(name)) throw new InvalidArgumentException("用户名不能为空!"); if (StringUtils.isBlank(phone)) throw new InvalidArgumentException("手机号不能为空!"); Admin admin = getAdminByName(name); if (admin != null) throw new InvalidArgumentException("改账号已存在!"); admin = new Admin(); admin.setName(name); admin.setPhone(phone); admin.setRealName(realName); admin.setCreatedBy(adminId); admin.setUpdatedBy(adminId); admin.setCreatedAt(new Date()); if (StringUtils.isBlank(password)){ password = BCrypt.hashpw(INIT_PWD, BCrypt.gensalt()); }else{ password = BCrypt.hashpw(password, BCrypt.gensalt()); } admin.setPassword(password); int insert = adminMapper.insertSelective(admin); return (insert>0)?true:false; }  TokenVo login(String name, String password); Admin getAdminByName(String name); boolean addAdmin(String name, String password, String phone, String realName ,Integer adminId); boolean resetPassword(Integer adminId, String password,String name); Admin getAdminById(Integer adminId); Page getUsers(AdminReq admin); }
AdminService { public boolean addAdmin(String name, String password, String phone, String realName ,Integer adminId) throws InvalidArgumentException { if (StringUtils.isBlank(name)) throw new InvalidArgumentException("用户名不能为空!"); if (StringUtils.isBlank(phone)) throw new InvalidArgumentException("手机号不能为空!"); Admin admin = getAdminByName(name); if (admin != null) throw new InvalidArgumentException("改账号已存在!"); admin = new Admin(); admin.setName(name); admin.setPhone(phone); admin.setRealName(realName); admin.setCreatedBy(adminId); admin.setUpdatedBy(adminId); admin.setCreatedAt(new Date()); if (StringUtils.isBlank(password)){ password = BCrypt.hashpw(INIT_PWD, BCrypt.gensalt()); }else{ password = BCrypt.hashpw(password, BCrypt.gensalt()); } admin.setPassword(password); int insert = adminMapper.insertSelective(admin); return (insert>0)?true:false; }  TokenVo login(String name, String password); Admin getAdminByName(String name); boolean addAdmin(String name, String password, String phone, String realName ,Integer adminId); boolean resetPassword(Integer adminId, String password,String name); Admin getAdminById(Integer adminId); Page getUsers(AdminReq admin); static String INIT_PWD; }