IndexPatternService几个重写的方法

@Override
@Transactional(rollbackFor = Exception.class)
public AddIndexPatternResponse newIndexPattern(AddIndexPatternRequest request) {
IndexPatternItem indexPatternItem = request.getIndexPatternItem();
AddIndexPatternResponse response = new AddIndexPatternResponse();

if (StringUtils.isEmpty(indexPatternItem.getSystemId())
        || StringUtils.isEmpty(indexPatternItem.getIndexPatternName())
        || StringUtils.isEmpty(indexPatternItem.getApplicationName())) {
    throw new TitanException("所传参数为空!");
}

long id = SnowFlakeSequence.nextId();
IndexPattern indexPattern = new IndexPattern();
indexPattern.setId(id);
indexPattern.setSystemId(indexPatternItem.getSystemId());
indexPattern.setIndexPatternName(indexPatternItem.getIndexPatternName());
indexPattern.setApplicationName(indexPatternItem.getApplicationName());
indexPattern.setDesensitizationFlag(false);
indexPattern.setCreateTime(new Date());
indexPattern.setUpdateTime(new Date());
indexPatternMapper.insert(indexPattern);

if (!CollectionUtils.isEmpty(request.getDepartmentIndexPatternDTOList())) {
    permissionService.addPermissionForIndexPattern(id, request.getDepartmentIndexPatternDTOList());
}

if (!CollectionUtils.isEmpty(request.getUserIndexPatternDTOList())) {
    userPermissionService.addUserPermissionForIndexPattern(id, request.getUserIndexPatternDTOList());
}

RespUtils.setSuccess(response);
return response;

}
@Transactional(rollbackFor = Exception.class)
@Override
public DelIndexPatternResponse deleteIndexPatternByName(DelIndexPatternRequest request) {
String indexName = request.getIndexPatternName();
DelIndexPatternResponse response = new DelIndexPatternResponse();

    if (StringUtils.isEmpty(indexName)) {
        throw new TitanException("所传参数为空!");
    }

    Example indexPatternExample = new Example(IndexPattern.class);
    indexPatternExample.createCriteria().andEqualTo("indexPatternName", indexName);

    Example userPermissionExample = new Example(UserPermission.class);
    userPermissionExample.createCriteria().andEqualTo("indexPatternId", getIndexPatternByName(indexName).getId());
    userPermissionMapper.deleteByExample(userPermissionExample);

    Example departmentPermissionExample = new Example(DepartmentPermission.class);
    departmentPermissionExample.createCriteria().andEqualTo("indexPatternId", getIndexPatternByName(indexName).getId());
    permissionMapper.deleteByExample(departmentPermissionExample);

    indexPatternMapper.deleteByExample(indexPatternExample);
    RespUtils.setSuccess(response);
    return response;
}

@Transactional(rollbackFor = Exception.class)
@Override
public ChangeIndexPatternResponse updateIndexPatternByName(ChangeIndexPatternRequest request) {
IndexPatternItem indexPatternItem = request.getIndexPatternItem();
ChangeIndexPatternResponse response = new ChangeIndexPatternResponse();

    if (indexPatternItem == null) {
        throw new TitanException("所传参数为空!");
    }

    IndexPattern indexPatternNew = indexPatternMapper.selectByPrimaryKey(indexPatternItem.getId());
    if (indexPatternNew == null) {
        RespUtils.setError(ErrorCodeEnum.INDEX_PATTERN_NOT_EXIST, response);
        return response;
    }

    indexPatternNew.setApplicationName(indexPatternItem.getApplicationName());
    indexPatternNew.setIndexPatternName(indexPatternItem.getIndexPatternName());
    indexPatternNew.setSystemId(indexPatternItem.getSystemId());
    indexPatternNew.setUpdateTime(new Date());
    indexPatternMapper.updateByPrimaryKeySelective(indexPatternNew);

    if (request.getDepartmentIndexPatternDTOList() != null) {
        permissionService.deletePermissionByIndexPatternId(indexPatternItem.getId());
        permissionService.addPermissionForIndexPattern(indexPatternItem.getId(), request.getDepartmentIndexPatternDTOList());
    }

    if (request.getUserIndexPatternDTOList() != null) {
        userPermissionService.deleteUserPermissionByIndexPatternId(indexPatternItem.getId());
        userPermissionService.addUserPermissionForIndexPattern(indexPatternItem.getId(), request.getUserIndexPatternDTOList());
    }

    RespUtils.setSuccess(response);
    return response;
}

@Override
public FuzzyQueryIndexPatternResponse fuzzyQuery(FuzzyQueryIndexPatternRequest request) {
Map<String, Object> map = new HashMap<>();
map.put("indexPatternName", request.getIndexPatternName());
map.put("systemIdList", request.getSystemIdList());
map.put("applicationName", request.getApplicationName());

FuzzyQueryIndexPatternResponse response = new FuzzyQueryIndexPatternResponse();

if (request.getPageIndex() <= 0) {
    request.setPageIndex(1);
}

if (request.getLimit() <= 0) {
    request.setLimit(10);
}

int offset = (request.getPageIndex() - 1) * request.getLimit();
Page<IndexPattern> indexPatternPage = PageHelper.offsetPage(offset, request.getLimit(), true).doSelectPage(() -> indexPatternMapper.fuzzySearch(map));

Page<IndexPatternItem> indexPatternItemPage = new Page<>();
BeanUtils.copyProperties(indexPatternPage, indexPatternItemPage);

for (IndexPattern indexPattern : indexPatternPage.getResult()) {
    indexPatternItemPage.add(getIndexPatternItem(indexPattern));
}

response.setPageInfo(indexPatternItemPage.toPageInfo());
RespUtils.setSuccess(response);

return response;

}
@Override
public GetIndexPatternUserAndDepartmentResponse getIndexPatternUserAndDepartment(GetIndexPatternUserAndDepartmentRequest request) {
String indexPatternName = request.getIndexPatternName();
String indexName = request.getIndexPatternName();

if (StringUtils.isEmpty(indexName)) {
    throw new TitanException("所传参数为空!");
}

// 创建查询条件,获取索引模式
Example example = new Example(IndexPattern.class);
Example.Criteria criteria = example.createCriteria();
criteria.orEqualTo("indexPatternName", indexPatternName);

IndexPattern indexPattern = indexPatternMapper.selectOneByExample(example);


// 获取索引模式下的用户权限
Example userExample = new Example(UserPermission.class);
Example.Criteria userCriteria = userExample.createCriteria();
userCriteria.orEqualTo("indexPatternId", indexPattern.getId());

List<UserPermission> userPermissionList = userPermissionMapper.selectByExample(userExample);
List<String> userNameList = new ArrayList<>();
for (UserPermission userPermission : userPermissionList) {
    if (Boolean.TRUE.equals(userPermission.getPermanentFlag()) ||
        (Boolean.FALSE.equals(userPermission.getPermanentFlag()) &&
         userPermission.getEffectiveDate() != null &&
         userPermission.getEffectiveDate().getTime() > new Date().getTime())) {
        userNameList.add(userPermission.getUserName());
    }
}

// 获取索引模式下的部门权限
Example departmentExample = new Example(DepartmentPermission.class);
Example.Criteria departmentCriteria = departmentExample.createCriteria();
departmentCriteria.orEqualTo("indexPatternId", indexPattern.getId());

List<DepartmentPermission> departmentPermissionList = permissionMapper.selectByExample(departmentExample);
List<String> departmentIdList = new ArrayList<>();
for (DepartmentPermission departmentPermission : departmentPermissionList) {
    if (Boolean.TRUE.equals(departmentPermission.getPermanentFlag()) ||
        (Boolean.FALSE.equals(departmentPermission.getPermanentFlag()) &&
         departmentPermission.getEffectiveDate() != null &&
         departmentPermission.getEffectiveDate().getTime() > new Date().getTime())) {
        departmentIdList.add(departmentPermission.getDepartmentId());
    }
}

// 构建响应对象
GetIndexPatternUserAndDepartmentResponse response = new GetIndexPatternUserAndDepartmentResponse();
response.setUserNameList(userNameList);
response.setDepartmentIdList(departmentIdList);
RespUtils.setSuccess(response);

return response;

}
@Override
Public QueryIndicesBySystemAndApplicationResponse queryIndicesBySystemAndApplication(QueryIndicesBySystemAndApplicationRequest request){QueryIndicesBySystemAndApplicationResponse response=new QueryIndicesBySystemAndApplicationResponse();
String userName= request. getUserName();
if(StringUtils. isEmpty(userName)){
log. error("查询用户关联索引请求参数 为 空 ");
throw newTitanException(" 所 传 参 数 为 空!");}
UserConfig user=userService.queryByUserName(userName);
if( user== null){RespUtils. setError(ErrorCodeEnum.USER_NOT_EXIST,response); return response;}
QueryFinTechUser Request userRequest=new QueryFinTechUserRequest(); List< String> userNameList=newArrayList<>();userNameList.add(userName);userRequest.setUserNameList(userNameList);//全 查 询 用 户
UserInfoResponse userInfoResponse=finTechDataProviderService. queryFinTechUserInfo(userRequest);
String departmentId=userInfoResponse.getUserList().get(0).getOrgId(); Depart ment department=departmentService.getDepartmentById(departmentId);
//如果是全查 询 用 户 就 不 要 in 只 需 要 模 糊 查 询
Int isGlobal=0;
if(user.getGlobalQuery()||( department!= null&& department. getGlobalQuer y())){isGlobal=1;}
PageHelper.startPage(request.getPageIndex(),request.getPageLimit()); PageInfo pageInfo=new PageInfo<>(indexPatternMapper. selectIndexByApplicationAndSystemId( request.getIndexName(),request. getApplicationName(),request.getSystemIdList(),isGlobal,userName,departmentId)); List indexPatternItemList=newArrayList<>();pageInfo.getList(). forEach(userIndex->{IndexPatternItem item=new IndexPatternItem(); item. setSystemId(userIndex.getSystemId()); item.setApplicationName(userIndex. getApplicationName()); item.setIndexPattemName(userIndex. getIndexPatternName()); item. setId(userIndex.getId());indexPatternItemList.add(item);}); response. setIndicesList(indexPatternItemList); response.setTotal(pageInfo.getTotal()); response. setSuccess(); retur nresponse;}

posted @ 2024-11-15 14:31  一曲微茫  阅读(2)  评论(0编辑  收藏  举报