dev
liuguijing 1 year ago
commit 500e44fb47

@ -6,6 +6,7 @@ import com.shxy.xymanager_common.bean.ServiceBody;
import com.shxy.xymanager_common.bean.ServiceStatus; import com.shxy.xymanager_common.bean.ServiceStatus;
import com.shxy.xymanager_common.entity.TbPermission; import com.shxy.xymanager_common.entity.TbPermission;
import com.shxy.xymanager_common.entity.TbRole; import com.shxy.xymanager_common.entity.TbRole;
import com.shxy.xymanager_common.exception.ApiException;
import com.shxy.xymanager_common.model.DyLineTreeListModel; import com.shxy.xymanager_common.model.DyLineTreeListModel;
import com.shxy.xymanager_common.model.PermissionDyLineTreeListModel; import com.shxy.xymanager_common.model.PermissionDyLineTreeListModel;
import com.shxy.xymanager_common.model.PermissionModel; import com.shxy.xymanager_common.model.PermissionModel;
@ -48,7 +49,7 @@ public class RoleController extends BaseController {
@ApiOperation("更新") @ApiOperation("更新")
public ResponseReult<String> update(@Validated @RequestBody TbRole item) throws Exception { public ResponseReult<String> update(@Validated @RequestBody TbRole item) throws Exception {
if (item.getId() == null) { if (item.getId() == null) {
throw new Exception("ID不能为空!"); throw new ApiException("id不能为空!");
} }
service.update(item); service.update(item);
return ResponseReult.success("OK"); return ResponseReult.success("OK");
@ -56,14 +57,17 @@ public class RoleController extends BaseController {
@PostMapping("delete") @PostMapping("delete")
@ApiOperation("删除") @ApiOperation("删除")
public ResponseReult<String> delete(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception { public ResponseReult<String> delete(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception {
if (id == null) {
throw new ApiException("id不能为空!");
}
service.delete(id); service.delete(id);
return ResponseReult.success("OK"); return ResponseReult.success("OK");
} }
@GetMapping("getPermission") @GetMapping("getPermission")
@ApiOperation("查询权限") @ApiOperation("查询权限")
public ResponseReult<List<TbPermission>> getPermission(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception { public ResponseReult<List<TbPermission>> getPermission(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception {
List<TbPermission> result = service.getPermission(id); List<TbPermission> result = service.getPermission(id);
return ResponseReult.success(result); return ResponseReult.success(result);
} }

@ -203,5 +203,6 @@ public class Constants {
* *
*/ */
public static int SUPER_ADMIN = 0; public static int SUPER_ADMIN = 0;
public static String SUPER_ADMIN_NAME = "超级管理员";
} }

@ -28,6 +28,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import static com.shxy.xymanager_common.constant.Constants.SUPER_ADMIN; import static com.shxy.xymanager_common.constant.Constants.SUPER_ADMIN;
import static com.shxy.xymanager_common.constant.Constants.SUPER_ADMIN_NAME;
@Service @Service
@Slf4j @Slf4j
@ -47,11 +48,25 @@ public class RoleServiceImpl implements RoleService {
TbRoleExample example = new TbRoleExample(); TbRoleExample example = new TbRoleExample();
TbRoleExample.Criteria criteria = example.createCriteria(); TbRoleExample.Criteria criteria = example.createCriteria();
List<TbRole> list = roleMapper.selectByExample(example); List<TbRole> list = roleMapper.selectByExample(example);
TbRole item = new TbRole();
item.setId(SUPER_ADMIN);
item.setName(SUPER_ADMIN_NAME);
list.add(0, item);
return list; return list;
} }
@Override @Override
public boolean add(TbRole item) throws Exception { public boolean add(TbRole item) throws Exception {
if (SUPER_ADMIN_NAME.equals(item.getName())) {
throw new ApiException("名称不能使用" + SUPER_ADMIN_NAME);
}
TbRoleExample example = new TbRoleExample();
TbRoleExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(item.getName());
List<TbRole> list = roleMapper.selectByExample(example);
if (list.size() > 0) {
throw new ApiException("名称已存在");
}
item.setCreateTime(new Date()); item.setCreateTime(new Date());
int r = roleMapper.insertSelective(item); int r = roleMapper.insertSelective(item);
return r > 0; return r > 0;
@ -59,8 +74,19 @@ public class RoleServiceImpl implements RoleService {
@Override @Override
public void update(TbRole item) throws Exception { public void update(TbRole item) throws Exception {
if (SUPER_ADMIN_NAME.equals(item.getName())) {
throw new ApiException("名称不能使用" + SUPER_ADMIN_NAME);
}
if (item.getId() == SUPER_ADMIN) { if (item.getId() == SUPER_ADMIN) {
throw new ApiException("不能修改超级管理员"); throw new ApiException("不能修改" + SUPER_ADMIN_NAME);
}
TbRoleExample example = new TbRoleExample();
TbRoleExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(item.getName());
criteria.andIdNotEqualTo(item.getId());
List<TbRole> list = roleMapper.selectByExample(example);
if (list.size() > 0) {
throw new ApiException("名称已存在");
} }
roleMapper.updateByPrimaryKey(item); roleMapper.updateByPrimaryKey(item);
} }
@ -68,9 +94,13 @@ public class RoleServiceImpl implements RoleService {
@Override @Override
public void delete(Integer id) throws Exception { public void delete(Integer id) throws Exception {
if (id == SUPER_ADMIN) { if (id == SUPER_ADMIN) {
throw new ApiException("不能删除超级管理员"); throw new ApiException("不能删除" + SUPER_ADMIN_NAME);
} }
roleMapper.deleteByPrimaryKey(id); roleMapper.deleteByPrimaryKey(id);
TbPermissionExample example = new TbPermissionExample();
TbPermissionExample.Criteria criteria = example.createCriteria();
criteria.andRoleIdEqualTo(id);
permissionMapper.deleteByExample(example);
} }
@Override @Override
@ -112,7 +142,7 @@ public class RoleServiceImpl implements RoleService {
@Override @Override
public void changePermission(Integer roleId, List<TbPermission> list) throws Exception { public void changePermission(Integer roleId, List<TbPermission> list) throws Exception {
if (roleId == SUPER_ADMIN) { if (roleId == SUPER_ADMIN) {
throw new ApiException("不能修改超级管理员的权限"); throw new ApiException("不能修改" + SUPER_ADMIN_NAME + "的权限");
} }
TbPermissionExample example = new TbPermissionExample(); TbPermissionExample example = new TbPermissionExample();
TbPermissionExample.Criteria criteria = example.createCriteria(); TbPermissionExample.Criteria criteria = example.createCriteria();

Loading…
Cancel
Save