用户导入初始密码

pull/63/MERGE
RuoYi 2019-01-11 10:14:31 +08:00
parent ca5b4bc852
commit 77550e2f11
7 changed files with 24 additions and 10 deletions

View File

@ -22,6 +22,7 @@ import com.ruoyi.framework.shiro.service.SysPasswordService;
import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.framework.web.base.BaseController; import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.SysUser; import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysPostService; import com.ruoyi.system.service.ISysPostService;
import com.ruoyi.system.service.ISysRoleService; import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.ISysUserService;
@ -45,6 +46,9 @@ public class SysUserController extends BaseController
@Autowired @Autowired
private ISysPostService postService; private ISysPostService postService;
@Autowired
private ISysConfigService configService;
@Autowired @Autowired
private SysPasswordService passwordService; private SysPasswordService passwordService;
@ -85,7 +89,9 @@ public class SysUserController extends BaseController
{ {
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
List<SysUser> userList = util.importExcel(file.getInputStream()); List<SysUser> userList = util.importExcel(file.getInputStream());
String message = userService.importUser(userList, updateSupport); String operName = getSysUser().getLoginName();
String password = configService.selectConfigByKey("sys.user.initPassword");
String message = userService.importUser(userList, updateSupport, operName, password);
return AjaxResult.success(message); return AjaxResult.success(message);
} }

View File

@ -6,8 +6,8 @@ user.password.not.match=用户不存在/密码错误
user.password.retry.limit.count=密码输入错误{0}次 user.password.retry.limit.count=密码输入错误{0}次
user.password.retry.limit.exceed=密码输入错误{0}次帐户锁定10分钟 user.password.retry.limit.exceed=密码输入错误{0}次帐户锁定10分钟
user.password.delete=对不起,您的账号已被删除 user.password.delete=对不起,您的账号已被删除
user.blocked=用户已封禁,原因:{0} user.blocked=用户已封禁,请联系管理员
role.blocked=角色已封禁,原因:{0} role.blocked=角色已封禁,请联系管理员
user.logout.success=退出成功 user.logout.success=退出成功
length.not.valid=长度必须在{min}到{max}个字符之间 length.not.valid=长度必须在{min}到{max}个字符之间

View File

@ -96,7 +96,7 @@ public class SysLoginService
if (UserStatus.DISABLE.getCode().equals(user.getStatus())) if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
{ {
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRemark()))); AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRemark())));
throw new UserBlockedException(user.getRemark()); throw new UserBlockedException();
} }
passwordService.validate(user, password); passwordService.validate(user, password);

View File

@ -9,8 +9,8 @@ public class RoleBlockedException extends UserException
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public RoleBlockedException(String reason) public RoleBlockedException()
{ {
super("role.blocked", new Object[] { reason }); super("role.blocked", null);
} }
} }

View File

@ -9,8 +9,8 @@ public class UserBlockedException extends UserException
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public UserBlockedException(String reason) public UserBlockedException()
{ {
super("user.blocked", new Object[] { reason }); super("user.blocked", null);
} }
} }

View File

@ -144,7 +144,9 @@ public interface ISysUserService
* *
* @param userList * @param userList
* @param isUpdateSupport * @param isUpdateSupport
* @param operName
* @param password
* @return * @return
*/ */
public String importUser(List<SysUser> userList, Boolean isUpdateSupport); public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName, String password);
} }

View File

@ -10,6 +10,7 @@ import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.support.Convert; import com.ruoyi.common.support.Convert;
import com.ruoyi.common.utils.Md5Utils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysPost; import com.ruoyi.system.domain.SysPost;
import com.ruoyi.system.domain.SysRole; import com.ruoyi.system.domain.SysRole;
@ -363,9 +364,11 @@ public class SysUserServiceImpl implements ISysUserService
* *
* @param userList * @param userList
* @param isUpdateSupport * @param isUpdateSupport
* @param operName
* @param password
* @return * @return
*/ */
public String importUser(List<SysUser> userList, Boolean isUpdateSupport) public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName, String password)
{ {
if (StringUtils.isNull(userList) || userList.size() == 0) if (StringUtils.isNull(userList) || userList.size() == 0)
{ {
@ -383,12 +386,15 @@ public class SysUserServiceImpl implements ISysUserService
SysUser u = userMapper.selectUserByLoginName(user.getLoginName()); SysUser u = userMapper.selectUserByLoginName(user.getLoginName());
if (StringUtils.isNull(u)) if (StringUtils.isNull(u))
{ {
user.setPassword(Md5Utils.hash(user.getLoginName() + password));
user.setCreateBy(operName);
this.insertUser(user); this.insertUser(user);
successNum++; successNum++;
successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginName() + " 导入成功"); successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginName() + " 导入成功");
} }
else if (isUpdateSupport) else if (isUpdateSupport)
{ {
user.setUpdateBy(operName);
this.updateUser(user); this.updateUser(user);
successNum++; successNum++;
successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginName() + " 更新成功"); successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginName() + " 更新成功");