use of com.topcom.cms.web.bind.annotation.CurrentUser in project topcom-cloud by 545314690.
the class SearchWordController method findByType.
/**
* 热词查询 查询排名前 limit 的word
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/findByType", produces = "application/json")
@ResponseBody
public List<SearchWord> findByType(@CurrentUser User user, @ApiParam("limit") @RequestParam(required = true) Integer limit, @ApiParam("type") @RequestParam(required = true) Integer type) {
Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "wordCount"));
Pageable page = new PageRequest(0, limit, sort);
User user1 = this.userManager.findById(user.getId());
Set<Group> groups = user1.getGroups();
String groupId = SearchWord.groupIdBySet(groups);
List<String> groupIdList = new ArrayList<>();
groupIdList.add(groupId);
if (groupId.indexOf(",") != -1) {
String[] split = groupId.split(",");
for (String s : split) {
groupIdList.add(s);
}
}
Page<SearchWord> searchWords = this.searchWordManager.findByTypeAndGroupIdIn(page, type, groupIdList);
return filterNull(searchWords);
}
use of com.topcom.cms.web.bind.annotation.CurrentUser in project topcom-cloud by 545314690.
the class UserController method appResource.
/**
* 返回登录用户指定app的resource
*/
@ApiOperation("获取指定app的resource")
@RequestMapping(value = { "appResource" }, method = { RequestMethod.GET })
@ResponseBody
public Set<Resource> appResource(@CurrentUser User user, @RequestParam(required = false) Long appId, @RequestParam(required = false) String appName) throws Exception {
if (appId == null && StringUtils.isBlank(appName)) {
throw new BusinessException("appId 和 appName 不能同时为空!");
}
if (appId == null) {
Application app = applicationManager.findByName(appName);
appId = app.getId();
}
// 缓存user懒加载,没有resource,需要在数据库查询
User user1 = this.manager.findById(user.getId());
Set<Resource> resourceSet = user1.getResource();
if (resourceSet == null || resourceSet.size() == 0) {
return null;
}
Set<Resource> filteredResourceSet = new LinkedHashSet<>();
for (Resource resource : resourceSet) {
if (appId.equals(resource.getAppId())) {
filteredResourceSet.add(resource);
}
}
for (Resource resource : filteredResourceSet) {
resource.sortByChildId();
}
return filteredResourceSet;
}
use of com.topcom.cms.web.bind.annotation.CurrentUser in project topcom-cloud by 545314690.
the class CurrentUserMethodArgumentResolver method resolveArgument.
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
CurrentUser currentUserAnnotation = parameter.getParameterAnnotation(CurrentUser.class);
// 从Session 获取用户
Object object = webRequest.getAttribute(currentUserAnnotation.value(), NativeWebRequest.SCOPE_SESSION);
// 如果用户未登陆,抛出异常
if (object == null) {
// throw new UnLoginException();
// return new User(100L);
String token = webRequest.getHeader("Authorization");
if (token == null) {
token = webRequest.getParameter("accessToken");
}
if (token == null) {
throw new UnLoginException();
} else {
User obj = SubjectUtil.getCurrentUser(token);
if (obj == null) {
throw new UnLoginException();
} else {
return obj;
}
}
}
return object;
}
use of com.topcom.cms.web.bind.annotation.CurrentUser in project topcom-cloud by 545314690.
the class ResourceController method resource.
@ApiOperation("获取resource")
@RequestMapping(value = { "findByUser" }, method = { RequestMethod.GET })
@ResponseBody
public Page<Resource> resource(@CurrentUser User user, @RequestParam(required = false) String filterType, @RequestParam(required = false) String word, @RequestParam(required = false) Integer limit, @RequestParam(required = false) Integer page) {
// 缓存user懒加载,没有resource,需要在数据库查询
User user1 = this.userManager.findById(user.getId());
// user.getPermissionNames();
Set<Resource> resourceSet = user1.getResource();
Set<Group> groups = user1.getGroups();
if (resourceSet == null || resourceSet.size() == 0) {
return null;
}
for (Resource resource : resourceSet) {
resource.sortByChildId();
}
// 增加查询条数
searchWordManager.addClickCount(groups, word, 1);
return this.resourceManager.searchResource(resourceSet, word, limit, page, filterType);
}
use of com.topcom.cms.web.bind.annotation.CurrentUser in project topcom-cloud by 545314690.
the class SearchWordController method addClickCount.
/**
* 增加点击次数 对于单个搜索词 可以支持累加
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/add", produces = "application/json")
@ResponseBody
public SearchWord addClickCount(@CurrentUser User user, @ApiParam("Word") @RequestParam(required = true) String word, @ApiParam("type") @RequestParam(required = true) Integer type) {
User user1 = this.userManager.findById(user.getId());
Set<Group> groups = user1.getGroups();
return searchWordManager.addClickCount(groups, word, type);
}
Aggregations