dev:代码规范
This commit is contained in:
@@ -41,7 +41,9 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
@Override
|
||||
public IPage<Dict> queryAll(Map whereJson, PageQuery page) {
|
||||
String blurry = null;
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("blurry"))) blurry = whereJson.get("blurry").toString();
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("blurry"))) {
|
||||
blurry = whereJson.get("blurry").toString();
|
||||
}
|
||||
IPage<Dict> pages = new Page<>(page.getPage() + 1, page.getSize());
|
||||
QueryWrapper<Dict> lam = new QueryWrapper<>();
|
||||
lam.select("MAX(dict_id) AS dictId, code, name")
|
||||
@@ -63,7 +65,9 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
String date = DateUtil.now();
|
||||
List<Dict> oldDict = sysDictMapper.selectList(new LambdaQueryWrapper<Dict>()
|
||||
.eq(ObjectUtil.isNotEmpty(dict.getCode()), Dict::getCode, dict.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(oldDict)) throw new BadRequestException("字典[" + dict.getCode() + "]已存在");
|
||||
if (ObjectUtil.isNotEmpty(oldDict)) {
|
||||
throw new BadRequestException("字典[" + dict.getCode() + "]已存在");
|
||||
}
|
||||
dict.setDictId(IdUtil.getSnowflake(1, 1).nextIdStr());
|
||||
dict.setCreateId(currentUserId);
|
||||
dict.setCreateName(nickName);
|
||||
@@ -79,8 +83,9 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
public void updateDict(Dict dto) {
|
||||
Dict dict = sysDictMapper.selectById(dto.getDictId());
|
||||
List<Dict> dictList = sysDictMapper.selectList(new LambdaQueryWrapper<Dict>().eq(Dict::getCode, dto.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(dictList) && !dto.getCode().equals(dict.getCode()))
|
||||
if (ObjectUtil.isNotEmpty(dictList) && !dto.getCode().equals(dict.getCode())) {
|
||||
throw new BadRequestException("字典[" + dto.getCode() + "]已存在");
|
||||
}
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String currentNickName = SecurityUtils.getCurrentNickName();
|
||||
// 根据code获取所有字典
|
||||
@@ -131,7 +136,9 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
// 校验是否已经有标签
|
||||
Dict one = sysDictMapper.selectOne(new LambdaQueryWrapper<Dict>().eq(Dict::getLabel, dict.getLabel())
|
||||
.eq(Dict::getCode, dict.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(one)) throw new BadRequestException("标签[" + dict.getLabel() + "]已存在");
|
||||
if (ObjectUtil.isNotEmpty(one)) {
|
||||
throw new BadRequestException("标签[" + dict.getLabel() + "]已存在");
|
||||
}
|
||||
// 判断是否有空的值
|
||||
List<Dict> selectOne = sysDictMapper.selectList(new LambdaQueryWrapper<Dict>().eq(Dict::getCode, dict.getCode()));
|
||||
Dict dic = selectOne.get(0);
|
||||
@@ -165,11 +172,15 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDetail(Dict resources) {
|
||||
Dict dict = sysDictMapper.selectById(resources.getDictId());
|
||||
if (ObjectUtil.isEmpty(dict)) throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
if (ObjectUtil.isEmpty(dict)) {
|
||||
throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
}
|
||||
// 校验是否已经有标签
|
||||
List<Dict> dictList = sysDictMapper.selectList(new LambdaQueryWrapper<Dict>().eq(Dict::getLabel, resources.getLabel())
|
||||
.eq(Dict::getCode, resources.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(dictList) && !resources.getLabel().equals(dict.getLabel())) throw new BadRequestException("标签[" + dict.getLabel() + "]已存在");
|
||||
if (ObjectUtil.isNotEmpty(dictList) && !resources.getLabel().equals(dict.getLabel())) {
|
||||
throw new BadRequestException("标签[" + dict.getLabel() + "]已存在");
|
||||
}
|
||||
resources.setUpdateId(SecurityUtils.getCurrentUserId());
|
||||
resources.setUpdateName(SecurityUtils.getCurrentNickName());
|
||||
resources.setUpdateTime(DateUtil.now());
|
||||
|
||||
@@ -251,7 +251,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
if (menuId != null) {
|
||||
int count = baseMapper.findByPid(menuId).size();
|
||||
SysMenu sysMenu = baseMapper.selectById(menuId);
|
||||
if (ObjectUtil.isEmpty(sysMenu)) return;
|
||||
if (ObjectUtil.isEmpty(sysMenu)) {
|
||||
return;
|
||||
}
|
||||
sysMenu.setSubCount(count);
|
||||
baseMapper.updateById(sysMenu);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,9 @@ public class SysParamServiceImpl extends ServiceImpl<SysParamMapper, Param> impl
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(Param param) {
|
||||
List code = paramMapper.selectByMap(MapOf.of("code", param.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(code)) throw new BadRequestException("编码不能一致");
|
||||
if (ObjectUtil.isNotEmpty(code)) {
|
||||
throw new BadRequestException("编码不能一致");
|
||||
}
|
||||
param.setId(IdUtil.getSnowflake(1, 1).nextIdStr());
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
@@ -67,7 +69,9 @@ public class SysParamServiceImpl extends ServiceImpl<SysParamMapper, Param> impl
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(Param param) {
|
||||
Param paramObj = paramMapper.selectById(param.getId());
|
||||
if (ObjectUtil.isEmpty(paramObj)) throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
if (ObjectUtil.isEmpty(paramObj)) {
|
||||
throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
}
|
||||
param.setUpdateId(SecurityUtils.getCurrentUserId());
|
||||
param.setUpdateName(SecurityUtils.getCurrentNickName());
|
||||
param.setUpdateTime(DateUtil.now());
|
||||
|
||||
@@ -54,7 +54,9 @@ public class SysDataPermissionServiceImpl extends ServiceImpl<SysDataPermissionM
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(SysDataPermission permission) {
|
||||
SysDataPermission sysDataPermission = dataPermissionMapper.selectOne(new LambdaQueryWrapper<SysDataPermission>().eq(SysDataPermission::getCode, permission.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(sysDataPermission)) throw new BadRequestException("编码为[" + permission.getCode() + "]的数据权限已存在");
|
||||
if (ObjectUtil.isNotEmpty(sysDataPermission)) {
|
||||
throw new BadRequestException("编码为[" + permission.getCode() + "]的数据权限已存在");
|
||||
}
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
@@ -73,7 +75,9 @@ public class SysDataPermissionServiceImpl extends ServiceImpl<SysDataPermissionM
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(SysDataPermission permission) {
|
||||
SysDataPermission dataPermission = dataPermissionMapper.selectById(permission.getPermissionId());
|
||||
if (ObjectUtil.isEmpty(dataPermission)) throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
if (ObjectUtil.isEmpty(dataPermission)) {
|
||||
throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
}
|
||||
permission.setUpdateTime(DateUtil.now());
|
||||
permission.setUpdateId(SecurityUtils.getCurrentUserId());
|
||||
permission.setUpdateName(SecurityUtils.getCurrentNickName());
|
||||
@@ -85,7 +89,9 @@ public class SysDataPermissionServiceImpl extends ServiceImpl<SysDataPermissionM
|
||||
public void deleteAll(Set<String> ids) {
|
||||
ids.forEach(id -> {
|
||||
List<UserDataPermissionDto> permissions = userService.getUserDataPermissionByPermissionId(id);
|
||||
if (ObjectUtil.isNotEmpty(permissions)) throw new BadRequestException("存在相关联的数据权限,请解除关联后删除");
|
||||
if (ObjectUtil.isNotEmpty(permissions)) {
|
||||
throw new BadRequestException("存在相关联的数据权限,请解除关联后删除");
|
||||
}
|
||||
dataPermissionMapper.deleteById(id);
|
||||
});
|
||||
}
|
||||
@@ -107,13 +113,19 @@ public class SysDataPermissionServiceImpl extends ServiceImpl<SysDataPermissionM
|
||||
SysDataPermission sysDataPermission = dataPermissionMapper.selectOne(new LambdaQueryWrapper<SysDataPermission>().eq(SysDataPermission::getPermissionId, userDataPermissionDto.getPermissionId()));
|
||||
if (sysDataPermission.getCode().equals(DataScopeEnum.USER.getCode())) { // 用户权限
|
||||
List<String> userIds = dataPermissionMapper.findDataScopeUserIdBySelfUserIdAndScopeType(userId, userDataPermissionDto.getPermissionScopeType());
|
||||
if (ObjectUtil.isNotEmpty(userIds)) userDataPermissionDto.setUsers(userIds);
|
||||
if (ObjectUtil.isNotEmpty(userIds)) {
|
||||
userDataPermissionDto.setUsers(userIds);
|
||||
}
|
||||
} else if (sysDataPermission.getCode().equals(DataScopeEnum.DEPT.getCode())) { // 部门权限
|
||||
List<String> deptIds = dataPermissionMapper.findDataScopeDeptIdBySelfUserIdAndScopeType(userId, userDataPermissionDto.getPermissionScopeType());
|
||||
if (ObjectUtil.isNotEmpty(deptIds)) userDataPermissionDto.setDepts(deptIds);
|
||||
if (ObjectUtil.isNotEmpty(deptIds)) {
|
||||
userDataPermissionDto.setDepts(deptIds);
|
||||
}
|
||||
} else if (sysDataPermission.getCode().equals(DataScopeEnum.SELF.getCode())) { // 自身
|
||||
List<String> userIds = dataPermissionMapper.findDataScopeUserIdBySelfUserIdAndScopeType(userId, userDataPermissionDto.getPermissionScopeType());
|
||||
if (ObjectUtil.isNotEmpty(userIds)) userDataPermissionDto.setUsers(userIds);
|
||||
if (ObjectUtil.isNotEmpty(userIds)) {
|
||||
userDataPermissionDto.setUsers(userIds);
|
||||
}
|
||||
}
|
||||
// 其他不做处理
|
||||
});
|
||||
@@ -125,7 +137,9 @@ public class SysDataPermissionServiceImpl extends ServiceImpl<SysDataPermissionM
|
||||
public void savePermission(JSONObject datas) {
|
||||
String user_id = datas.getString("userId");
|
||||
JSONArray data = datas.getJSONArray("datas");
|
||||
if (ObjectUtil.isEmpty(user_id)) throw new BadRequestException("用户不能为空");
|
||||
if (ObjectUtil.isEmpty(user_id)) {
|
||||
throw new BadRequestException("用户不能为空");
|
||||
}
|
||||
// 删除用户绑定的数据
|
||||
userService.deleteDataPermissionById(user_id);
|
||||
dataPermissionMapper.deleteScopeBySelfUserId(user_id);
|
||||
|
||||
@@ -48,7 +48,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
@Override
|
||||
public IPage<SysRole> query(Map param, PageQuery page) {
|
||||
String blurry = null;
|
||||
if (ObjectUtil.isNotEmpty(param.get("blurry"))) blurry = param.get("blurry").toString();
|
||||
if (ObjectUtil.isNotEmpty(param.get("blurry"))) {
|
||||
blurry = param.get("blurry").toString();
|
||||
}
|
||||
LambdaQueryWrapper<SysRole> lam = new LambdaQueryWrapper<>();
|
||||
lam.like(ObjectUtil.isNotEmpty(blurry), SysRole::getName, blurry);
|
||||
IPage<SysRole> pages = new Page<>(page.getPage() + 1, page.getSize());
|
||||
@@ -63,12 +65,16 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
public void create(JSONObject param) {
|
||||
//判断角色名字是否存在
|
||||
String name = param.getString("name");
|
||||
if (StrUtil.isEmpty(name)) throw new BadRequestException("角色名字不能为空!");
|
||||
if (StrUtil.isEmpty(name)) {
|
||||
throw new BadRequestException("角色名字不能为空!");
|
||||
}
|
||||
SysRole sysRole = JSONObject.parseObject(JSONObject.toJSONString(param), SysRole.class);
|
||||
|
||||
//判断角色名字是否存在
|
||||
SysRole role = roleMapper.selectOne(new LambdaQueryWrapper<SysRole>().eq(SysRole::getName, sysRole.getName()));
|
||||
if (ObjectUtil.isNotEmpty(role)) throw new BadRequestException("角色【" + name + "】已存在!");
|
||||
if (ObjectUtil.isNotEmpty(role)) {
|
||||
throw new BadRequestException("角色【" + name + "】已存在!");
|
||||
}
|
||||
String userId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
@@ -89,12 +95,16 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
SysRole sysRole = JSONObject.parseObject(JSONObject.toJSONString(param), SysRole.class);
|
||||
//判断角色名字是否存在
|
||||
String name = sysRole.getName();
|
||||
if (StrUtil.isEmpty(name)) throw new BadRequestException("角色名字不能为空!");
|
||||
if (StrUtil.isEmpty(name)) {
|
||||
throw new BadRequestException("角色名字不能为空!");
|
||||
}
|
||||
|
||||
//判断角色名字是否存在
|
||||
SysRole role = roleMapper.selectOne(new LambdaQueryWrapper<SysRole>().eq(SysRole::getName, sysRole.getName())
|
||||
.ne(SysRole::getRoleId, sysRole.getRoleId()));
|
||||
if (ObjectUtil.isNotEmpty(role)) throw new BadRequestException("角色【" + name + "】已存在!");
|
||||
if (ObjectUtil.isNotEmpty(role)) {
|
||||
throw new BadRequestException("角色【" + name + "】已存在!");
|
||||
}
|
||||
String userId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
@@ -135,7 +145,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
// 查看是否为管理员
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserId, currentUserId));
|
||||
if ( ObjectUtil.isNotEmpty(sysUser.getIsAdmin()) && sysUser.getIsAdmin()) permission.add("admin");
|
||||
if ( ObjectUtil.isNotEmpty(sysUser.getIsAdmin()) && sysUser.getIsAdmin()) {
|
||||
permission.add("admin");
|
||||
}
|
||||
permission.addAll(sysMenuMapper.getPermissionByUserId(userDto.getString("userId")));
|
||||
return permission;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user