Java Code Examples for org.jeecg.common.api.vo.Result#error()

The following examples show how to use org.jeecg.common.api.vo.Result#error() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SysDepartRoleController.java    From jeecg-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * 保存数据规则至角色菜单关联表
 */
@PostMapping(value = "/datarule")
public Result<?> saveDatarule(@RequestBody JSONObject jsonObject) {
 try {
	 String permissionId = jsonObject.getString("permissionId");
	 String roleId = jsonObject.getString("roleId");
	 String dataRuleIds = jsonObject.getString("dataRuleIds");
	 log.info("保存数据规则>>"+"菜单ID:"+permissionId+"角色ID:"+ roleId+"数据权限ID:"+dataRuleIds);
	 LambdaQueryWrapper<SysDepartRolePermission> query = new LambdaQueryWrapper<SysDepartRolePermission>()
			 .eq(SysDepartRolePermission::getPermissionId, permissionId)
			 .eq(SysDepartRolePermission::getRoleId,roleId);
	 SysDepartRolePermission sysRolePermission = sysDepartRolePermissionService.getOne(query);
	 if(sysRolePermission==null) {
		 return Result.error("请先保存角色菜单权限!");
	 }else {
		 sysRolePermission.setDataRuleIds(dataRuleIds);
		 this.sysDepartRolePermissionService.updateById(sysRolePermission);
	 }
 } catch (Exception e) {
	 log.error("SysRoleController.saveDatarule()发生异常:" + e.getMessage(),e);
	 return Result.error("保存失败");
 }
 return Result.ok("保存成功!");
}
 
Example 2
Source File: SysRoleController.java    From teaching with Apache License 2.0 6 votes vote down vote up
/**
 * 查询数据规则数据
 */
@GetMapping(value = "/datarule/{permissionId}/{roleId}")
public Result<?> loadDatarule(@PathVariable("permissionId") String permissionId,@PathVariable("roleId") String roleId) {
	List<SysPermissionDataRule> list = sysPermissionDataRuleService.getPermRuleListByPermId(permissionId);
	if(list==null || list.size()==0) {
		return Result.error("未找到权限配置信息");
	}else {
		Map<String,Object> map = new HashMap<>();
		map.put("datarule", list);
		LambdaQueryWrapper<SysRolePermission> query = new LambdaQueryWrapper<SysRolePermission>()
				.eq(SysRolePermission::getPermissionId, permissionId)
				.isNotNull(SysRolePermission::getDataRuleIds)
				.eq(SysRolePermission::getRoleId,roleId);
		SysRolePermission sysRolePermission = sysRolePermissionService.getOne(query);
		if(sysRolePermission==null) {
			//return Result.error("未找到角色菜单配置信息");
		}else {
			String drChecked = sysRolePermission.getDataRuleIds();
			if(oConvertUtils.isNotEmpty(drChecked)) {
				map.put("drChecked", drChecked.endsWith(",")?drChecked.substring(0, drChecked.length()-1):drChecked);
			}
		}
		return Result.ok(map);
		//TODO 以后按钮权限的查询也走这个请求 无非在map中多加两个key
	}
}
 
Example 3
Source File: SysRoleController.java    From jeecg-boot-with-activiti with MIT License 6 votes vote down vote up
/**
 * 查询数据规则数据
 */
@GetMapping(value = "/datarule/{permissionId}/{roleId}")
public Result<?> loadDatarule(@PathVariable("permissionId") String permissionId,@PathVariable("roleId") String roleId) {
	List<SysPermissionDataRule> list = sysPermissionDataRuleService.getPermRuleListByPermId(permissionId);
	if(list==null || list.size()==0) {
		return Result.error("未找到权限配置信息");
	}else {
		Map<String,Object> map = new HashMap<>();
		map.put("datarule", list);
		LambdaQueryWrapper<SysRolePermission> query = new LambdaQueryWrapper<SysRolePermission>()
				.eq(SysRolePermission::getPermissionId, permissionId)
				.eq(SysRolePermission::getRoleId,roleId);
		SysRolePermission sysRolePermission = sysRolePermissionService.getOne(query);
		if(sysRolePermission==null) {
			//return Result.error("未找到角色菜单配置信息");
		}else {
			String drChecked = sysRolePermission.getDataRuleIds();
			if(oConvertUtils.isNotEmpty(drChecked)) {
				map.put("drChecked", drChecked.endsWith(",")?drChecked.substring(0, drChecked.length()-1):drChecked);
			}
		}
		return Result.ok(map);
		//TODO 以后按钮权限的查询也走这个请求 无非在map中多加两个key
	}
}
 
Example 4
Source File: SysRoleController.java    From jeecg-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * 查询数据规则数据
 */
@GetMapping(value = "/datarule/{permissionId}/{roleId}")
public Result<?> loadDatarule(@PathVariable("permissionId") String permissionId,@PathVariable("roleId") String roleId) {
	List<SysPermissionDataRule> list = sysPermissionDataRuleService.getPermRuleListByPermId(permissionId);
	if(list==null || list.size()==0) {
		return Result.error("未找到权限配置信息");
	}else {
		Map<String,Object> map = new HashMap<>();
		map.put("datarule", list);
		LambdaQueryWrapper<SysRolePermission> query = new LambdaQueryWrapper<SysRolePermission>()
				.eq(SysRolePermission::getPermissionId, permissionId)
				.isNotNull(SysRolePermission::getDataRuleIds)
				.eq(SysRolePermission::getRoleId,roleId);
		SysRolePermission sysRolePermission = sysRolePermissionService.getOne(query);
		if(sysRolePermission==null) {
			//return Result.error("未找到角色菜单配置信息");
		}else {
			String drChecked = sysRolePermission.getDataRuleIds();
			if(oConvertUtils.isNotEmpty(drChecked)) {
				map.put("drChecked", drChecked.endsWith(",")?drChecked.substring(0, drChecked.length()-1):drChecked);
			}
		}
		return Result.ok(map);
		//TODO 以后按钮权限的查询也走这个请求 无非在map中多加两个key
	}
}
 
Example 5
Source File: LoginController.java    From jeecg-boot with Apache License 2.0 6 votes vote down vote up
/**
 * 退出登录
 * @param request
 * @param response
 * @return
 */
@RequestMapping(value = "/logout")
public Result<Object> logout(HttpServletRequest request,HttpServletResponse response) {
	//用户退出逻辑
    String token = request.getHeader(DefContants.X_ACCESS_TOKEN);
    if(oConvertUtils.isEmpty(token)) {
    	return Result.error("退出登录失败!");
    }
    String username = JwtUtil.getUsername(token);
	LoginUser sysUser = sysBaseAPI.getUserByName(username);
    if(sysUser!=null) {
    	sysBaseAPI.addLog("用户名: "+sysUser.getRealname()+",退出成功!", CommonConstant.LOG_TYPE_1, null);
    	log.info(" 用户名:  "+sysUser.getRealname()+",退出成功! ");
    	//清空用户登录Token缓存
    	redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
    	//清空用户登录Shiro权限缓存
		redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId());
		//清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username>
		redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername()));
		//调用shiro的logout
		SecurityUtils.getSubject().logout();
    	return Result.ok("退出登录成功!");
    }else {
    	return Result.error("Token无效!");
    }
}
 
Example 6
Source File: QuartzJobController.java    From teaching with Apache License 2.0 6 votes vote down vote up
/**
 * 暂停定时任务
 * 
 * @param jobClassName
 * @return
 */
@RequiresRoles("admin")
@GetMapping(value = "/pause")
@ApiOperation(value = "暂停定时任务")
public Result<Object> pauseJob(@RequestParam(name = "jobClassName", required = true) String jobClassName) {
	QuartzJob job = null;
	try {
		job = quartzJobService.getOne(new LambdaQueryWrapper<QuartzJob>().eq(QuartzJob::getJobClassName, jobClassName));
		if (job == null) {
			return Result.error("定时任务不存在!");
		}
		scheduler.pauseJob(JobKey.jobKey(jobClassName.trim()));
	} catch (SchedulerException e) {
		throw new JeecgBootException("暂停定时任务失败");
	}
	job.setStatus(CommonConstant.STATUS_DISABLE);
	quartzJobService.updateById(job);
	return Result.ok("暂停定时任务成功");
}
 
Example 7
Source File: TeachingCourseUnitController.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 通过id查询
 *
 * @param id
 * @return
 */
@AutoLog(value = "课程单元-通过id查询")
@ApiOperation(value="课程单元-通过id查询", notes="课程单元-通过id查询")
@GetMapping(value = "/queryById")
public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
	TeachingCourseUnit teachingCourseUnit = teachingCourseUnitService.getById(id);
	if(teachingCourseUnit==null) {
		return Result.error("未找到对应数据");
	}
	return Result.ok(teachingCourseUnit);
}
 
Example 8
Source File: SysPermissionController.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 查询子菜单
 *
 * @param parentIds 父ID(多个采用半角逗号分割)
 * @return 返回 key-value 的 Map
 */
@GetMapping("/getSystemSubmenuBatch")
public Result getSystemSubmenuBatch(@RequestParam("parentIds") String parentIds) {
	try {
		LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
		List<String> parentIdList = Arrays.asList(parentIds.split(","));
		query.in(SysPermission::getParentId, parentIdList);
		query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
		query.orderByAsc(SysPermission::getSortNo);
		List<SysPermission> list = sysPermissionService.list(query);
		Map<String, List<SysPermissionTree>> listMap = new HashMap<>();
		for (SysPermission item : list) {
			String pid = item.getParentId();
			if (parentIdList.contains(pid)) {
				List<SysPermissionTree> mapList = listMap.get(pid);
				if (mapList == null) {
					mapList = new ArrayList<>();
				}
				mapList.add(new SysPermissionTree(item));
				listMap.put(pid, mapList);
			}
		}
		return Result.ok(listMap);
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		return Result.error("批量查询子菜单失败:" + e.getMessage());
	}
}
 
Example 9
Source File: SysPermissionController.java    From jeecg-boot-with-activiti with MIT License 5 votes vote down vote up
/**
 * 查询用户拥有的菜单权限和按钮权限(根据TOKEN)
 * 
 * @return
 */
@RequestMapping(value = "/getUserPermissionByToken", method = RequestMethod.GET)
public Result<?> getUserPermissionByToken(@RequestParam(name = "token", required = true) String token) {
	Result<JSONObject> result = new Result<JSONObject>();
	try {
		if (oConvertUtils.isEmpty(token)) {
			return Result.error("TOKEN不允许为空!");
		}
		log.info(" ------ 通过令牌获取用户拥有的访问菜单 ---- TOKEN ------ " + token);
		String username = JwtUtil.getUsername(token);
		List<SysPermission> metaList = sysPermissionService.queryByUser(username);
		PermissionDataUtil.addIndexPage(metaList);
		JSONObject json = new JSONObject();
		JSONArray menujsonArray = new JSONArray();
		this.getPermissionJsonArray(menujsonArray, metaList, null);
		JSONArray authjsonArray = new JSONArray();
		this.getAuthJsonArray(authjsonArray, metaList);
		//查询所有的权限
		LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
		query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
		query.eq(SysPermission::getMenuType, CommonConstant.MENU_TYPE_2);
		//query.eq(SysPermission::getStatus, "1");
		List<SysPermission> allAuthList = sysPermissionService.list(query);
		JSONArray allauthjsonArray = new JSONArray();
		this.getAllAuthJsonArray(allauthjsonArray, allAuthList);
		json.put("menu", menujsonArray);
		json.put("auth", authjsonArray);
		json.put("allAuth", allauthjsonArray);
		result.setResult(json);
		result.success("查询成功");
	} catch (Exception e) {
		result.error500("查询失败:" + e.getMessage());  
		log.error(e.getMessage(), e);
	}
	return result;
}
 
Example 10
Source File: QuartzJobController.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 通过id删除
 * 
 * @param id
 * @return
 */
//@RequiresRoles({"admin"})
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
	QuartzJob quartzJob = quartzJobService.getById(id);
	if (quartzJob == null) {
		return Result.error("未找到对应实体");
	}
	quartzJobService.deleteAndStopJob(quartzJob);
       return Result.ok("删除成功!");

}
 
Example 11
Source File: SysDictController.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 取回
 * @param id
 * @return
 */
@RequestMapping(value = "/back/{id}", method = RequestMethod.PUT)
public Result<?> back(@PathVariable String id) {
	try {
		sysDictService.updateDictDelFlag(0,id);
		return Result.ok("操作成功!");
	} catch (Exception e) {
		e.printStackTrace();
		return Result.error("操作失败!");
	}
}
 
Example 12
Source File: SysDictController.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 物理删除
 * @param id
 * @return
 */
@RequestMapping(value = "/deletePhysic/{id}", method = RequestMethod.DELETE)
public Result<?> deletePhysic(@PathVariable String id) {
	try {
		sysDictService.deleteOneDictPhysically(id);
		return Result.ok("删除成功!");
	} catch (Exception e) {
		e.printStackTrace();
		return Result.error("删除失败!");
	}
}
 
Example 13
Source File: QuartzJobController.java    From jeecg-boot-with-activiti with MIT License 5 votes vote down vote up
/**
 * 更新定时任务
 * 
 * @param quartzJob
 * @return
 */
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
public Result<?> eidt(@RequestBody QuartzJob quartzJob) {
	try {
		quartzJobService.editAndScheduleJob(quartzJob);
	} catch (SchedulerException e) {
		log.error(e.getMessage(),e);
		return Result.error("更新定时任务失败!");
	}
    return Result.ok("更新定时任务成功!");
}
 
Example 14
Source File: QuartzJobController.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 通过id删除
 * 
 * @param id
 * @return
 */
@RequiresRoles("admin")
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
	QuartzJob quartzJob = quartzJobService.getById(id);
	if (quartzJob == null) {
		return Result.error("未找到对应实体");
	}
	quartzJobService.deleteAndStopJob(quartzJob);
       return Result.ok("删除成功!");

}
 
Example 15
Source File: QuartzJobController.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 添加定时任务
 * 
 * @param quartzJob
 * @return
 */
//@RequiresRoles({"admin"})
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result<?> add(@RequestBody QuartzJob quartzJob) {
	List<QuartzJob> list = quartzJobService.findByJobClassName(quartzJob.getJobClassName());
	if (list != null && list.size() > 0) {
		return Result.error("该定时任务类名已存在");
	}
	quartzJobService.saveAndScheduleJob(quartzJob);
	return Result.ok("创建定时任务成功");
}
 
Example 16
Source File: JeecgBootExceptionHandler.java    From jeecg-boot with Apache License 2.0 4 votes vote down vote up
@ExceptionHandler(Exception.class)
public Result<?> handleException(Exception e){
	log.error(e.getMessage(), e);
	return Result.error("操作失败,"+e.getMessage());
}
 
Example 17
Source File: JeecgBootExceptionHandler.java    From jeecg-boot with Apache License 2.0 4 votes vote down vote up
/**
 * 处理自定义异常
 */
@ExceptionHandler(JeecgBootException.class)
public Result<?> handleRRException(JeecgBootException e){
	log.error(e.getMessage(), e);
	return Result.error(e.getMessage());
}
 
Example 18
Source File: CommonController.java    From teaching with Apache License 2.0 4 votes vote down vote up
/**
 * @Author 政辉
 * @return
 */
@GetMapping("/403")
public Result<?> noauth()  {
	return Result.error("没有权限,请联系管理员授权");
}
 
Example 19
Source File: JeecgBootExceptionHandler.java    From jeecg-boot-with-activiti with MIT License 4 votes vote down vote up
@ExceptionHandler(DataIntegrityViolationException.class)
public Result<?> handleDataIntegrityViolationException(DataIntegrityViolationException e) {
	log.error(e.getMessage(), e);
    return Result.error("字段太长,超出数据库字段的长度");
}
 
Example 20
Source File: JeecgBootExceptionHandler.java    From teaching with Apache License 2.0 4 votes vote down vote up
@ExceptionHandler(NoHandlerFoundException.class)
public Result<?> handlerNoFoundException(Exception e) {
	log.error(e.getMessage(), e);
	return Result.error(404, "路径不存在,请检查路径是否正确");
}