Search in sources :

Example 1 with ProjectPartnerRequest

use of cn.surveyking.server.domain.dto.ProjectPartnerRequest in project SurveyKing by javahuang.

the class ProjectPartnerServiceImpl method addProjectPartner.

@Override
public void addProjectPartner(ProjectPartnerRequest request) {
    // 过滤掉已存在的用户
    List<String> existUserIds = list(Wrappers.<ProjectPartner>lambdaQuery().in(ProjectPartner::getUserId, request.getUserIds()).eq(ProjectPartner::getProjectId, request.getProjectId())).stream().map(x -> x.getUserId()).collect(Collectors.toList());
    saveBatch(request.getUserIds().stream().filter(userId -> {
        if (existUserIds.contains(userId)) {
            return false;
        }
        cacheManager.getCache(CacheConsts.projectPermissionCacheName).evict(userId);
        return true;
    }).map(userId -> {
        ProjectPartner partner = new ProjectPartner();
        partner.setProjectId(request.getProjectId());
        partner.setUserId(userId);
        partner.setType(request.getType());
        return partner;
    }).collect(Collectors.toList()));
}
Also used : Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) BaseService(cn.surveyking.server.service.BaseService) SecurityContextUtils(cn.surveyking.server.core.uitls.SecurityContextUtils) ProjectPartnerRequest(cn.surveyking.server.domain.dto.ProjectPartnerRequest) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CacheConsts(cn.surveyking.server.core.constant.CacheConsts) UserService(cn.surveyking.server.service.UserService) ProjectPartnerView(cn.surveyking.server.domain.dto.ProjectPartnerView) Collectors(java.util.stream.Collectors) ProjectPartnerMapper(cn.surveyking.server.mapper.ProjectPartnerMapper) List(java.util.List) CacheManager(org.springframework.cache.CacheManager) Service(org.springframework.stereotype.Service) ProjectPartnerService(cn.surveyking.server.service.ProjectPartnerService) ProjectPartner(cn.surveyking.server.domain.model.ProjectPartner) Transactional(org.springframework.transaction.annotation.Transactional) ProjectPartner(cn.surveyking.server.domain.model.ProjectPartner)

Aggregations

CacheConsts (cn.surveyking.server.core.constant.CacheConsts)1 SecurityContextUtils (cn.surveyking.server.core.uitls.SecurityContextUtils)1 ProjectPartnerRequest (cn.surveyking.server.domain.dto.ProjectPartnerRequest)1 ProjectPartnerView (cn.surveyking.server.domain.dto.ProjectPartnerView)1 ProjectPartner (cn.surveyking.server.domain.model.ProjectPartner)1 ProjectPartnerMapper (cn.surveyking.server.mapper.ProjectPartnerMapper)1 BaseService (cn.surveyking.server.service.BaseService)1 ProjectPartnerService (cn.surveyking.server.service.ProjectPartnerService)1 UserService (cn.surveyking.server.service.UserService)1 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 CacheManager (org.springframework.cache.CacheManager)1 Service (org.springframework.stereotype.Service)1 Transactional (org.springframework.transaction.annotation.Transactional)1