Search in sources :

Example 1 with CurrentUser

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);
}
Also used : Group(com.topcom.cms.domain.Group) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) SearchWord(com.topcom.cms.domain.SearchWord) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with CurrentUser

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;
}
Also used : BusinessException(com.topcom.cms.exception.BusinessException) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) PublicResource(com.topcom.cms.perm.annotation.PublicResource) Resource(com.topcom.cms.domain.Resource) Application(com.topcom.cms.domain.Application) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with CurrentUser

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;
}
Also used : CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) UnLoginException(com.topcom.cms.perm.exception.UnLoginException)

Example 4 with CurrentUser

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);
}
Also used : CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with CurrentUser

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);
}
Also used : Group(com.topcom.cms.domain.Group) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

CurrentUser (com.topcom.cms.web.bind.annotation.CurrentUser)8 User (com.topcom.cms.domain.User)7 ApiOperation (io.swagger.annotations.ApiOperation)4 Group (com.topcom.cms.domain.Group)3 Resource (com.topcom.cms.domain.Resource)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 SearchWord (com.topcom.cms.domain.SearchWord)2 PublicResource (com.topcom.cms.perm.annotation.PublicResource)2 PageRequest (org.springframework.data.domain.PageRequest)2 Pageable (org.springframework.data.domain.Pageable)2 Sort (org.springframework.data.domain.Sort)2 Application (com.topcom.cms.domain.Application)1 BusinessException (com.topcom.cms.exception.BusinessException)1 UnLoginException (com.topcom.cms.perm.exception.UnLoginException)1 ViewLogDto (com.topcom.cms.vo.ViewLogDto)1 ViewLogRequest (com.topcom.cms.vo.ViewLogRequest)1 ArrayList (java.util.ArrayList)1