master
fanghao 2024-04-13 10:21:50 +08:00
parent fba688b503
commit 460a68fcfa
8 changed files with 61 additions and 14 deletions

View File

@ -68,9 +68,15 @@ public class SysLoginService {
Result<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER); Result<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) { if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在"); if (username.contains("@")){
throw new ServiceException("登录用户:" + username + " 不存在"); recordLogService.recordLogininfor(username,Constants.LOGIN_FAIL,"登录邮箱不存在");
throw new ServiceException("登录邮箱"+username+"不存在");
}else {
recordLogService.recordLogininfor(username,Constants.LOGIN_FAIL,"登录用户不存在");
throw new ServiceException("登录用户"+username+"不存在");
}
} }
if (Result.FAIL == userResult.getCode()) { if (Result.FAIL == userResult.getCode()) {
throw new ServiceException(userResult.getMsg()); throw new ServiceException(userResult.getMsg());
} }
@ -84,8 +90,15 @@ public class SysLoginService {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
throw new ServiceException("对不起,您的账号:" + username + " 已停用"); throw new ServiceException("对不起,您的账号:" + username + " 已停用");
} }
if (username.contains("@")){
user.setEmail(null);
}
passwordService.validate(user, password); passwordService.validate(user, password);
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功"); if (username.contains("@")){
recordLogService.recordLogininfor(username,Constants.LOGIN_SUCCESS,"邮箱登录成功");
}else {
recordLogService.recordLogininfor(username,Constants.LOGIN_SUCCESS,"用户登录成功");
}
return userInfo; return userInfo;
} }
@ -99,7 +112,8 @@ public class SysLoginService {
public void register (String username, String password) { public void register (String username, String password) {
// 用户名或密码为空 错误 // 用户名或密码为空 错误
if (StringUtils.isAnyBlank(username, password)) { if (StringUtils.isAnyBlank(username, password)) {
throw new ServiceException("用户/密码必须填写"); // throw new ServiceException("用户/密码必须填写");
throw new ServiceException("用户/邮箱/密码必须填写");
} }
if (username.length() < UserConstants.USERNAME_MIN_LENGTH if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) { || username.length() > UserConstants.USERNAME_MAX_LENGTH) {

View File

@ -58,7 +58,12 @@ public class SysPasswordService {
retryCount = retryCount + 1; retryCount = retryCount + 1;
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, String.format("密码输入错误%s次", retryCount)); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, String.format("密码输入错误%s次", retryCount));
redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES); redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
throw new ServiceException("用户不存在/密码错误"); if (user.getEmail()==null){
throw new ServiceException("邮箱不存在/密码错误");
}else {
throw new ServiceException("用户不存在/密码错误");
}
} else { } else {
clearLoginRecordCache(username); clearLoginRecordCache(username);
} }

View File

@ -135,4 +135,6 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
* @return * @return
*/ */
public SysMenu checkMenuNameUnique (@Param("menuName") String menuName, @Param("parentId") Long parentId); public SysMenu checkMenuNameUnique (@Param("menuName") String menuName, @Param("parentId") Long parentId);
List<SysMenu> selectSysMenuList(List<Long> longs);
} }

View File

@ -46,8 +46,8 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
queryWrapper.gt(SysConfig::getCreateTime, beginDate); queryWrapper.gt(SysConfig::getCreateTime, beginDate);
} }
Object endTime = config.getParams().get("endTime"); Object endTime = config.getParams().get("endTime");
if (Objects.nonNull(endTime) && endTime instanceof Date endDate){ if (Objects.nonNull(endTime)&& endTime instanceof Date endDate){
queryWrapper.lt(SysConfig::getCreateTime, endDate); queryWrapper.lt(SysConfig::getCreateTime,endDate);
} }
return this.list(queryWrapper); return this.list(queryWrapper);
} }

View File

@ -82,6 +82,16 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
return dictDatas; return dictDatas;
} }
return null; return null;
// List<SysDictData> dictDatas = DictUtils.getDictCache(dictType);
// if (StringUtils.isNotEmpty(dictDatas)){
// return dictDatas;
// }
// dictDatas = dictDataMapper.selectDictDataByType(dictType);
// if (StringUtils.isNotEmpty(dictDatas)) {
// DictUtils.setDictCache(dictType,dictDatas);
// return dictDatas;
// }
// return null;
} }
/** /**

View File

@ -27,7 +27,7 @@ import java.util.stream.Collectors;
* @author muyu * @author muyu
*/ */
@Service @Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService { public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
public static final String PREMISSION_STRING = "perms[\"{0}\"]"; public static final String PREMISSION_STRING = "perms[\"{0}\"]";
@Autowired @Autowired
@ -51,6 +51,22 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
return selectMenuList(new SysMenu(), userId); return selectMenuList(new SysMenu(), userId);
} }
public List<SysMenu> selectSysMenuList(List<SysMenu> menuList){
List<Long> longs = menuList.stream()
.map(menu -> menu.getParentId())
.filter(parentId -> parentId != 0)
.distinct()
.toList();
if (longs.size()==0){
return null;
}
List<SysMenu> sysMenus = menuMapper.selectSysMenuList(longs);
List<SysMenu> sysMenus1 = selectSysMenuList(sysMenus);
if (sysMenus1 != null){
sysMenus.addAll(sysMenus1);
}
return sysMenus;
}
/** /**
* *
* *
@ -93,7 +109,6 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
/** /**
* ID * ID
* *
* @param roleId ID
* *
* @return * @return
*/ */

View File

@ -183,12 +183,12 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
*/ */
@Override @Override
public void checkRoleDataScope (Long roleId) { public void checkRoleDataScope (Long roleId) {
if (!SysUser.isAdmin(SecurityUtils.getUserId())) { if (!SysUser.isAdmin(SecurityUtils.getUserId())){
SysRole role = new SysRole(); SysRole role = new SysRole();
role.setRoleId(roleId); role.setRoleId(roleId);
List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role); List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
if (StringUtils.isEmpty(roles)) { if (StringUtils.isEmpty(roles)){
throw new ServiceException("没有权限访问角色数据"); throw new ServiceException("没有权限访问角色数据");
} }
} }
} }
@ -386,8 +386,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
*/ */
@Override @Override
public int insertAuthUsers (Long roleId, Long[] userIds) { public int insertAuthUsers (Long roleId, Long[] userIds) {
// 新增用户与角色管理
List<SysUserRole> list = new ArrayList<SysUserRole>(); ArrayList<SysUserRole> list = new ArrayList<>();
for (Long userId : userIds) { for (Long userId : userIds) {
SysUserRole ur = new SysUserRole(); SysUserRole ur = new SysUserRole();
ur.setUserId(userId); ur.setUserId(userId);

View File

@ -185,6 +185,7 @@
<include refid="selectMenuVo"/> <include refid="selectMenuVo"/>
where menu_name=#{menuName} and parent_id = #{parentId} limit 1 where menu_name=#{menuName} and parent_id = #{parentId} limit 1
</select> </select>
<select id="selectSysMenuList" resultType="com.muyu.system.domain.SysMenu"></select>
<update id="updateMenu" parameterType="com.muyu.system.domain.SysMenu"> <update id="updateMenu" parameterType="com.muyu.system.domain.SysMenu">
update sys_menu update sys_menu