|
@@ -95,27 +95,46 @@ public class HouseController extends BaseController {
|
|
|
List<String> userRoles = userUtils.getRolesByToken(token);
|
|
|
UserEntity user = userUtils.getUserByToken(token);
|
|
|
Long userId = user.getId();
|
|
|
-
|
|
|
- PageInfo<HouseResponse> page = null;
|
|
|
- if (userRoles.contains("admin")) {
|
|
|
+ PageInfo<HouseResponse> page = null;
|
|
|
+ if(CollectionUtils.isEmpty(userRoles)){
|
|
|
+ log.info("用户权限为空,无法获取房源列表");
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "权限不足");
|
|
|
+ }
|
|
|
+ if(userRoles.size() == 3){
|
|
|
+ //管理员获取全部房源列表
|
|
|
page = new PageInfo<>(houseService2.findBySearchKeyForEditOrUploader(param, null, null));
|
|
|
- } else if (userRoles.contains("edit")){
|
|
|
-
|
|
|
- if (userRoles.size() == 2) {
|
|
|
- log.info("有edit、upload权限");
|
|
|
- // 有edit、upload
|
|
|
-// page = new PageInfo<>(houseService2.findAllBySearchKey(param, userId, userId));
|
|
|
+ }else if(userRoles.size() == 2){
|
|
|
+ if(userRoles.contains("edit") && userRoles.contains("upload")){
|
|
|
+ //同时拥有编辑和上传权限
|
|
|
+ page = new PageInfo<>(houseService2.findBySearchKeyForEditOrUploader(param, userId ,userId));
|
|
|
+ }else if(userRoles.contains("edit") && !userRoles.contains("upload")){
|
|
|
+ //只拥有编辑权限
|
|
|
+ page = new PageInfo<>(houseService2.findBySearchKeyForEditOrUploader(param, userId ,null));
|
|
|
+ }else if (!userRoles.contains("edit") && userRoles.contains("upload")){
|
|
|
+ //只拥有上传权限
|
|
|
page = new PageInfo<>(houseService2.findBySearchKeyForEditOrUploader(param, null ,userId));
|
|
|
-
|
|
|
- } else {
|
|
|
- // 只有edit
|
|
|
- log.info("只有edit权限");
|
|
|
- page = new PageInfo<>(houseService2.findBySearchKeyForEditOrUploader(param, userId , null));
|
|
|
-
|
|
|
+ }else{
|
|
|
+ //理论上不存在此分支情况
|
|
|
+ log.error("上传的权限超出了当前有效权限范围");
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "存在无效权限");
|
|
|
}
|
|
|
|
|
|
- } else {
|
|
|
- page = new PageInfo<>(houseService2.findAllBySearchKey(param, userId, null));
|
|
|
+ }else if(userRoles.size() == 1){
|
|
|
+ if(userRoles.contains("edit")){
|
|
|
+ //只拥有编辑权限
|
|
|
+ page = new PageInfo<>(houseService2.findBySearchKeyForEditOrUploader(param, userId ,null));
|
|
|
+ }else if (userRoles.contains("upload")){
|
|
|
+ //只拥有上传权限
|
|
|
+ page = new PageInfo<>(houseService2.findBySearchKeyForEditOrUploader(param, null ,userId));
|
|
|
+ }else{
|
|
|
+ //只有管理用户的权限,理论不应该单独给这种角色
|
|
|
+ log.warn("用户[{}]只单独给了用户管理权限" ,userId);
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "当前权限不能查看数据");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.info("用户[{}]的权限超过3个,默认给拉取所有房源");
|
|
|
+ //默认获取全部
|
|
|
+ page = new PageInfo<>(houseService2.findBySearchKeyForEditOrUploader(param, null, null));
|
|
|
}
|
|
|
|
|
|
return new R(2000, page);
|
|
@@ -413,17 +432,21 @@ public class HouseController extends BaseController {
|
|
|
@RequiresRoles(value = {"admin", "edit", "upload"}, logical = Logical.OR)
|
|
|
@ApiOperation("删除房源(软删除)")
|
|
|
@GetMapping("removes/{ids}")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public R removes(@PathVariable String ids){
|
|
|
|
|
|
List<String> userRoles = userUtils.getRolesByToken(getToken());
|
|
|
- UserEntity user = userUtils.getUserByToken(getToken());
|
|
|
- Long loginUserId = user.getId();
|
|
|
-
|
|
|
-
|
|
|
String roleKey = null;
|
|
|
- // 只有一个权限时
|
|
|
if (userRoles.size() == 1) {
|
|
|
+ // 只有一个权限时
|
|
|
roleKey = (String)userRoles.get(0);
|
|
|
+ if (!"upload".equals(roleKey)) {
|
|
|
+ log.warn("只有一个权限的非上传者角色,不能删除房源");
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "权限不足,不能删除房源");
|
|
|
+ }
|
|
|
+ }else if(userRoles.size() != 3){
|
|
|
+ log.warn("多于一个权限的角色,非管理员,不能删除房源");
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "权限不足,不能删除房源");
|
|
|
}
|
|
|
|
|
|
String[] split = ids.split(",");
|
|
@@ -434,31 +457,20 @@ public class HouseController extends BaseController {
|
|
|
return new R(MsgCode.e_COMMON_3002,"没有存在的房源");
|
|
|
}
|
|
|
|
|
|
+ if(null != houseEntity.getStatus() && (houseEntity.getStatus().compareTo(0) == 0) || houseEntity.getStatus().compareTo(3) == 0){
|
|
|
+ log.error("只有upload, 房源id!=0,房源计算中不能删除");
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "房源计算中不能删除");
|
|
|
|
|
|
-
|
|
|
- if ("upload".equals(roleKey)) {
|
|
|
- if(null != houseEntity.getAuditResult() && houseEntity.getAuditResult().compareTo(1) == 0){
|
|
|
- log.error("只有upload, 房源id!=0,审批通过的房源不能删除");
|
|
|
- return new R(MsgCode.e_COMMON_3002,"审批通过的房源不能删除");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ("edit".equals(roleKey)) {
|
|
|
- log.error("只有edit,没有权限删除房源");
|
|
|
- return new R(MsgCode.e_COMMON_3002,"没有权限删除房源");
|
|
|
- }
|
|
|
-
|
|
|
- if (!loginUserId.equals(houseEntity.getUserId()) && !userRoles.contains("admin")) {
|
|
|
- log.error("userId: {}, loginUserId: {}", houseEntity.getUserId(), loginUserId);
|
|
|
- log.error("用户不相等时, edit,upload不能删除他人房源");
|
|
|
- return new R(MsgCode.e_COMMON_3002,"没有权限删除房源");
|
|
|
}
|
|
|
|
|
|
houseEntity.setRecStatus("I");
|
|
|
houseEntity.setUpdateTime(new Date());
|
|
|
- houseService2.update(houseEntity);
|
|
|
+ int update = houseService2.update(houseEntity);
|
|
|
+ if(update != 1){
|
|
|
+ log.error( "删除房源失败[{}]" , houseEntity.getId());
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "删除房源失败");
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
return new R(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
|
|
|
}
|
|
|
|