feat(REQ-2649): 增加黑名单批量创建 和 分页查询接口

This commit is contained in:
周敏 2024-08-21 11:13:12 +08:00
parent c332098ee5
commit 3b55f1d19f
12 changed files with 327 additions and 57 deletions

View File

@ -34,5 +34,12 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
<dependency>
<groupId>cn.axzo.foundation</groupId>
<artifactId>dao-support-lib</artifactId>
<version>2.0.0-SNAPSHOT</version>
<!-- 如果需要使用该特性,请自行引入依赖 -->
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,10 +1,11 @@
package cn.axzo.nanopart.api;
import cn.axzo.framework.domain.web.result.ApiPageResult;
import cn.axzo.framework.domain.web.result.ApiResult;
import cn.axzo.nanopart.api.annotation.CheckSign;
import cn.axzo.nanopart.api.constant.enums.ListTypeEnum;
import cn.axzo.nanopart.api.request.BlackAndWhiteListExcelImportReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListBatchCreateReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListInternalSyncReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListPageReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListPlatformSyncReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListReq;
import cn.axzo.nanopart.api.request.BlackListReq;
@ -17,14 +18,12 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.List;
/**
@ -46,6 +45,15 @@ public interface BlackAndWhiteListApi {
@PostMapping("api/black-white-list/create")
ApiResult<Long> create(@RequestBody @Validated BlackAndWhiteListReq req);
/**
* 批量创建黑名单或白名单
*
* @param req
* @return 记录id
*/
@PostMapping("api/black-white-list/batch-create")
ApiResult<Void> batchCreate(@RequestBody @Validated BlackAndWhiteListBatchCreateReq req);
/**
* 删除黑名单或白名单
*
@ -73,6 +81,15 @@ public interface BlackAndWhiteListApi {
@PostMapping("api/black-white-list/query")
ApiResult<List<BlackAndWhiteListResp>> detail(@RequestBody @Validated BlackAndWhiteListReq req);
/**
* 分页查询黑名单
*
* @param req 包含type,module,params三个字段
* @return 黑白名单记录列表
*/
@PostMapping("/api/black-white-list/page")
ApiPageResult<BlackAndWhiteListResp> page(@RequestBody @Validated BlackAndWhiteListPageReq req);
/**
* 判断指定模块指定参数记录是否在黑名单或白名单中
*

View File

@ -44,7 +44,10 @@ public enum BlackModuleEnum {
* 企业黑名单
*/
GXJG_BLACKCOMPANY("gxjg-blackcompany","企业黑名单"),
/**
* 项目人员黑名单
*/
PROJECT_PERSON_BLACK_LIST("project-person-black-list", "项目人员黑名单")
;
private final String value;

View File

@ -17,7 +17,8 @@ public enum MQEventEnum {
GXJG_BLACKUSER_TEAMLEADER("plat-blacklist", "plat-blackuser-teamleader-list", "班组管理人员黑名单"),
GXJG_BLACKUSER_EMPLOYEE("plat-blacklist", "plat-blackuser-employee-list", "项目管理人员黑名单"),
// 统一消息
BLACK_WHITE_LIST_UPSERTED("nanopart", "black-white-list-upserted", "黑名单变更")
;
private final String model;
private final String tag;

View File

@ -0,0 +1,22 @@
package cn.axzo.nanopart.api.request;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotEmpty;
import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
public class BlackAndWhiteListBatchCreateReq {
@NotEmpty(message = "名单不能为空")
private List<BlackAndWhiteListReq> list;
/**
* 如果有失败的回滚所有默认为true如果为false则不回滚且继续处理其他的名单
*/
private Boolean rollbackWhileOneFailed;
}

View File

@ -0,0 +1,66 @@
package cn.axzo.nanopart.api.request;
import cn.axzo.foundation.dao.support.mysql.MybatisPlusOperatorProcessor;
import cn.axzo.foundation.dao.support.wrapper.CriteriaField;
import cn.axzo.foundation.dao.support.wrapper.Operator;
import cn.axzo.nanopart.api.constant.enums.ListTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BlackAndWhiteListPageReq {
/**
* 名单类型0为黑名单1为白名单
*/
@NotNull(message = "名单类型错误")
@CriteriaField(ignore = true)
private ListTypeEnum type;
/**
* 模块名自主定义cms-login
*/
@NotBlank(message = "模块名不能为空")
@CriteriaField
private String module;
@CriteriaField(field = "id", operator = Operator.IN)
private Set<Long> ids;
/**
* 限制条件phone:13698745673
*/
@CriteriaField(operator = Operator.JSON_QUERY, field = "param")
private List<MybatisPlusOperatorProcessor.JSONQuery> paramQueries;
/**
* 页码
*/
@CriteriaField(ignore = true)
private Long pageNumber;
/**
* 每页条数
*/
@CriteriaField(ignore = true)
private Long pageSize;
public Long getPageNumber() {
return pageNumber == null || pageNumber < 1L ? 1L : pageNumber;
}
public Long getPageSize() {
return pageSize == null || pageSize < 1L ? 20L : pageSize;
}
}

View File

@ -19,6 +19,10 @@
<groupId>cn.axzo.framework</groupId>
<artifactId>axzo-mybatisplus-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>cn.axzo.framework</groupId>
<artifactId>axzo-web-spring-boot-starter</artifactId>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
@ -46,5 +50,10 @@
<artifactId>xxl-job-core</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>cn.axzo.foundation</groupId>
<artifactId>dao-support-lib</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -1,11 +1,14 @@
package cn.axzo.nanopart.server.controller;
import cn.axzo.framework.domain.web.result.ApiPageResult;
import cn.axzo.framework.domain.web.result.ApiResult;
import cn.axzo.nanopart.api.BlackAndWhiteListApi;
import cn.axzo.nanopart.api.annotation.CheckSign;
import cn.axzo.nanopart.api.constant.enums.ListTypeEnum;
import cn.axzo.nanopart.api.request.BlackAndWhiteListBatchCreateReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListInternalSyncReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListPageReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListPlatformSyncReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListReq;
import cn.axzo.nanopart.api.request.BlackListReq;
@ -13,6 +16,7 @@ import cn.axzo.nanopart.api.response.BlackAndWhiteListExcelImportResp;
import cn.axzo.nanopart.api.response.BlackAndWhiteListResp;
import cn.axzo.nanopart.server.service.BlackAndWhiteListService;
import cn.hutool.json.JSONUtil;
import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;
@ -39,6 +43,12 @@ public class BlackAndWhiteListController implements BlackAndWhiteListApi {
return ApiResult.ok(blackAndWhiteListService.create(req));
}
@Override
public ApiResult<Void> batchCreate(BlackAndWhiteListBatchCreateReq req) {
blackAndWhiteListService.batchCreate(req);
return ApiResult.ok();
}
@Override
public ApiResult<Void> delete(BlackAndWhiteListReq req) {
return ApiResult.ok(blackAndWhiteListService.delete(req));
@ -54,6 +64,11 @@ public class BlackAndWhiteListController implements BlackAndWhiteListApi {
return ApiResult.ok(blackAndWhiteListService.detail(req));
}
@Override
public ApiPageResult<BlackAndWhiteListResp> page(BlackAndWhiteListPageReq req) {
return ApiPageResult.ok(blackAndWhiteListService.page(req));
}
@Override
public ApiResult<Boolean> isInBlackOrWhiteList(BlackAndWhiteListReq req) {
return ApiResult.ok(blackAndWhiteListService.isInBlackListExist(req));

View File

@ -1,25 +1,33 @@
package cn.axzo.nanopart.server.dao.repository;
import cn.axzo.basics.common.BeanMapper;
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
import cn.axzo.foundation.dao.support.mysql.QueryWrapperHelper;
import cn.axzo.framework.rocketmq.EventProducer;
import cn.axzo.nanopart.api.constant.enums.BlackModuleEnum;
import cn.axzo.nanopart.api.request.BlackAndWhiteListPageReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListReq;
import cn.axzo.nanopart.api.request.BlackListReq;
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteList;
import cn.axzo.nanopart.server.dao.mapper.BlackAndWhiteListMapper;
import cn.axzo.nanopart.server.mq.payload.BlackWhiteListUpsertedPayload;
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
import cn.azxo.framework.common.utils.StringUtils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author chenwenjian
@ -34,13 +42,29 @@ import java.util.Set;
public class BlackAndWhiteListRepository extends ServiceImpl<BlackAndWhiteListMapper, SaasBlackWhiteList> {
private final BlackAndWhiteListMapper blackAndWhiteListMapper;
private final EventProducer eventProducer;
@Transactional(rollbackFor = Throwable.class)
public Long create(BlackAndWhiteListReq req) {
SaasBlackWhiteList blackWhiteList = BeanMapper.copyBean(req, SaasBlackWhiteList.class, (req1, saasBlackWhiteList) -> saasBlackWhiteList.setType(req1.getType().getValue()));
blackAndWhiteListMapper.insert(blackWhiteList);
SaasBlackWhiteList saasBlackWhiteList = blackAndWhiteListMapper.selectById(blackWhiteList.getId());
// MQ
eventProducer.send(BlackWhiteListUpsertedPayload.from(saasBlackWhiteList, BlackWhiteListUpsertedPayload.OpType.ADD));
return blackWhiteList.getId();
}
@Transactional(rollbackFor = Throwable.class)
public boolean batchCreate(List<SaasBlackWhiteList> list) {
boolean saved = saveBatch(list);
List<Long> insertIds = list.stream().map(BaseEntity::getId).collect(Collectors.toList());
List<SaasBlackWhiteList> insertedLists = listByIds(insertIds);
insertedLists.stream().map(b -> BlackWhiteListUpsertedPayload.from(b, BlackWhiteListUpsertedPayload.OpType.ADD))
.forEach(eventProducer::send);
return saved;
}
@Transactional(rollbackFor = Throwable.class)
public Void delete(BlackAndWhiteListReq req) {
List<SaasBlackWhiteList> blackWhiteLists = detail(req);
if (CollectionUtil.isNotEmpty(blackWhiteLists)) {
@ -50,6 +74,9 @@ public class BlackAndWhiteListRepository extends ServiceImpl<BlackAndWhiteListMa
.set(SaasBlackWhiteList::getIsDelete, saasBlackWhiteList.getId())
.update();
log.info("deleted record:{}", JSONUtil.toJsonStr(saasBlackWhiteList));
// 发送MQ
blackWhiteLists.stream().map(b -> BlackWhiteListUpsertedPayload.from(b, BlackWhiteListUpsertedPayload.OpType.REMOVE))
.forEach(eventProducer::send);
});
}
return null;
@ -65,6 +92,14 @@ public class BlackAndWhiteListRepository extends ServiceImpl<BlackAndWhiteListMa
return blackAndWhiteListMapper.selectList(queryWrapper);
}
public Page<SaasBlackWhiteList> page(BlackAndWhiteListPageReq req) {
QueryWrapper<SaasBlackWhiteList> queryWrapper = QueryWrapperHelper.fromBean(req, SaasBlackWhiteList.class)
.eq(req.getType() != null, "type", req.getType().getValue())
.eq("is_delete", 0)
.orderByDesc("id");
return blackAndWhiteListMapper.selectPage(new Page<>(req.getPageNumber(), req.getPageSize()), queryWrapper);
}
private void buildQueryWrapper(QueryWrapper<SaasBlackWhiteList> queryWrapper, Map<String, Object> params, String prefix) {
params.forEach((key, value) -> {
String fullKey = prefix.isEmpty() ? key : prefix + "." + key;
@ -76,11 +111,19 @@ public class BlackAndWhiteListRepository extends ServiceImpl<BlackAndWhiteListMa
});
}
@Transactional(rollbackFor = Throwable.class)
public Boolean deleteByIds(Set<Long> idSet) {
return lambdaUpdate()
List<SaasBlackWhiteList> toDeletes = list(lambdaUpdate()
.in(SaasBlackWhiteList::getId, idSet)
.eq(SaasBlackWhiteList::getIsDelete, TableIsDeleteEnum.NORMAL.value));
boolean result = lambdaUpdate()
.in(SaasBlackWhiteList::getId, idSet)
.set(SaasBlackWhiteList::getIsDelete, 1)
.update();
// MQ
toDeletes.stream().map(b -> BlackWhiteListUpsertedPayload.from(b, BlackWhiteListUpsertedPayload.OpType.REMOVE))
.forEach(eventProducer::send);
return result;
}
/**
@ -90,28 +133,23 @@ public class BlackAndWhiteListRepository extends ServiceImpl<BlackAndWhiteListMa
* @param module 模块名
* @return 删除结果true删除成功false删除失败
*/
@Transactional(rollbackFor = Throwable.class)
public Boolean deleteByModule(Integer type, String module) {
return lambdaUpdate()
List<SaasBlackWhiteList> toDeletes = list(lambdaUpdate()
.eq(SaasBlackWhiteList::getType, type)
.eq(SaasBlackWhiteList::getModule, module)
.eq(SaasBlackWhiteList::getIsDelete, TableIsDeleteEnum.NORMAL.value));
boolean result = lambdaUpdate()
.eq(SaasBlackWhiteList::getType, type)
.eq(SaasBlackWhiteList::getModule, module)
.eq(SaasBlackWhiteList::getIsDelete, 0)
.set(SaasBlackWhiteList::getIsDelete, 1)
.update();
}
/**
* 更新名单参数
*
* @param id 名单id
* @param param 名单参数
* @return 更新结果true更新成功false更新失败
*/
public boolean updateParamById(Long id, Map<String, Object> param) {
return lambdaUpdate()
.eq(SaasBlackWhiteList::getId, id)
.eq(SaasBlackWhiteList::getIsDelete, 0)
.set(SaasBlackWhiteList::getParam, JSONUtil.toJsonStr(param))
.update();
// MQ
toDeletes.stream().map(b -> BlackWhiteListUpsertedPayload.from(b, BlackWhiteListUpsertedPayload.OpType.REMOVE))
.forEach(eventProducer::send);
return result;
}
/**
@ -132,7 +170,7 @@ public class BlackAndWhiteListRepository extends ServiceImpl<BlackAndWhiteListMa
/**
* 根据模块名获取名单
*
* @param type 名单类型
* @param type 名单类型
* @param modules 模块名
* @return 名单列表
*/
@ -140,7 +178,7 @@ public class BlackAndWhiteListRepository extends ServiceImpl<BlackAndWhiteListMa
public List<SaasBlackWhiteList> listByModule(Integer type, List<String> modules) {
return lambdaQuery()
.eq(SaasBlackWhiteList::getType, type)
.in(CollUtil.isNotEmpty(modules),SaasBlackWhiteList::getModule, modules)
.in(CollUtil.isNotEmpty(modules), SaasBlackWhiteList::getModule, modules)
.eq(SaasBlackWhiteList::getIsDelete, 0)
.list();
}
@ -160,7 +198,7 @@ public class BlackAndWhiteListRepository extends ServiceImpl<BlackAndWhiteListMa
String fullKey = prefix.isEmpty() ? key : prefix + "." + key;
if (value instanceof Map) {
buildListQueryWrapper(queryWrapper, (Map<String, Object>) value, fullKey);
}else if(value instanceof List){
} else if (value instanceof List) {
queryWrapper.in("param->>'$." + fullKey + "'", ((List<?>) value).toArray());
} else {
queryWrapper.eq("param->>'$." + fullKey + "'", value);

View File

@ -0,0 +1,66 @@
package cn.axzo.nanopart.server.mq.payload;
import cn.axzo.framework.rocketmq.Event;
import cn.axzo.nanopart.api.constant.enums.MQEventEnum;
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteList;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.util.TypeUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.io.Serializable;
import java.util.Map;
@Slf4j
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
public class BlackWhiteListUpsertedPayload implements Serializable {
private String module;
private Integer type;
private OpType opType;
private Long personId;
private Long workspaceId;
private Map<String, Object> param;
public static Event from(SaasBlackWhiteList saasBlackWhiteList, OpType opType) {
Map<String, Object> param = saasBlackWhiteList.getParam();
Long personId = getParam(param, "personId", Long.class);
Long workspaceId = getParam(param, "workspaceId", Long.class);
BlackWhiteListUpsertedPayload payload = BlackWhiteListUpsertedPayload.builder()
.type(saasBlackWhiteList.getType())
.module(saasBlackWhiteList.getModule())
.opType(opType)
.personId(personId)
.workspaceId(workspaceId)
.param(param)
.build();
return Event.builder()
.eventCode(MQEventEnum.BLACK_WHITE_LIST_UPSERTED.getEventCode())
// 目前数量不大暂时以module作为shardingKey后续可以调整为根据personId之类的
.shardingKey(saasBlackWhiteList.getModule())
.operatorId("-1")
.operatorType("-1")
.targetId(String.format("%s_%s", personId, workspaceId))
.targetType("personId_WorkspaceId")
.data(payload)
.build();
}
private static <T> T getParam(Map<String, Object> param, String key, Class<T> tClass) {
try {
return param == null ? null : TypeUtils.cast(param.get(key), tClass, ParserConfig.getGlobalInstance());
} catch (Throwable e) {
log.warn("BlackWhiteListUpsertedPayload getParam exception, return null, key = {}, param = {}", key, param, e);
return null;
}
}
public enum OpType {
ADD, REMOVE;
}
}

View File

@ -1,13 +1,16 @@
package cn.axzo.nanopart.server.service;
import cn.axzo.nanopart.api.constant.enums.ListTypeEnum;
import cn.axzo.nanopart.api.request.BlackAndWhiteListBatchCreateReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListInternalSyncReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListPageReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListPlatformSyncReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListReq;
import cn.axzo.nanopart.api.request.BlackListReq;
import cn.axzo.nanopart.api.response.BlackAndWhiteListExcelImportResp;
import cn.axzo.nanopart.api.response.BlackAndWhiteListResp;
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteList;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@ -22,7 +25,9 @@ import java.util.List;
*/
public interface BlackAndWhiteListService {
Long create(BlackAndWhiteListReq req);
Long create(BlackAndWhiteListReq req);
void batchCreate(BlackAndWhiteListBatchCreateReq req);
Void delete(BlackAndWhiteListReq req);
@ -55,4 +60,6 @@ public interface BlackAndWhiteListService {
List<BlackAndWhiteListResp> isInBlackListExistList(BlackListReq req);
List<SaasBlackWhiteList> listModuleBlackUser(BlackListReq req);
IPage<BlackAndWhiteListResp> page(BlackAndWhiteListPageReq req);
}

View File

@ -4,7 +4,9 @@ import cn.axzo.basics.common.BeanMapper;
import cn.axzo.basics.common.exception.ServiceException;
import cn.axzo.nanopart.api.constant.enums.BlackModuleEnum;
import cn.axzo.nanopart.api.constant.enums.ListTypeEnum;
import cn.axzo.nanopart.api.request.BlackAndWhiteListBatchCreateReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListInternalSyncReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListPageReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListPlatformSyncReq;
import cn.axzo.nanopart.api.request.BlackAndWhiteListReq;
import cn.axzo.nanopart.api.request.BlackListReq;
@ -18,12 +20,15 @@ import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
@ -69,6 +74,7 @@ public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
* @return 记录id
*/
@Override
@Transactional(rollbackFor = Throwable.class)
public Long create(BlackAndWhiteListReq req) {
// 黑白名单创建互斥,若存在于黑名单中则不允许存在于白名单中反之亦然
BlackAndWhiteListReq reverseReq = BeanMapper.copyBean(req, BlackAndWhiteListReq.class, (req1, req2) -> req2.setType((req1.getType().equals(ListTypeEnum.BLACK_LIST)) ? ListTypeEnum.WHITE_LIST : ListTypeEnum.BLACK_LIST));
@ -82,6 +88,22 @@ public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
return blackAndWhiteListRepository.create(req);
}
@Override
@Transactional(rollbackFor = Throwable.class)
public void batchCreate(BlackAndWhiteListBatchCreateReq req) {
req.getList().forEach(r -> {
try {
create(r);
} catch (Throwable e) {
log.warn("batchCreate, one item caught exception , msg={}, r = {}", e.getMessage(), r, e);
// 如果不忽略
if (BooleanUtils.isTrue(req.getRollbackWhileOneFailed())) {
throw e;
}
}
});
}
/**
* 删除指定条件的所有黑白名单记录
*
@ -89,6 +111,7 @@ public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
* @return null
*/
@Override
@Transactional(rollbackFor = Throwable.class)
public Void delete(BlackAndWhiteListReq req) {
return blackAndWhiteListRepository.delete(req);
}
@ -152,6 +175,7 @@ public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
* @return true-删除成功false-删除失败
*/
@Override
@Transactional(rollbackFor = Throwable.class)
public Boolean deleteByIds(List<Long> ids) {
if (CollectionUtil.isNotEmpty(ids)) {
Set<Long> idSet = new HashSet<>(ids);
@ -175,18 +199,18 @@ public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
throw new ServiceException("请主动进行分片多次同步,单次同步数小于" + fragmentSize + "条数据");
}
// 第一个分片需要先删除所有对应模块的名单再新增
if (req.getFragment() == 1 ){
deleteByModule(req.getType(),req.getModule());
if (req.getFragment() == 1) {
deleteByModule(req.getType(), req.getModule());
}
// 新增
List<SaasBlackWhiteList> collect = req.getParams().stream().map(param -> SaasBlackWhiteList.builder()
.type(req.getType().getValue())
.module(req.getModule())
.param(param)
.build()).collect(Collectors.toList());
boolean saved = blackAndWhiteListRepository.saveBatch(collect);
.type(req.getType().getValue())
.module(req.getModule())
.param(param)
.build()).collect(Collectors.toList());
boolean saved = blackAndWhiteListRepository.batchCreate(collect);
// 同步至登录黑名单
if (Objects.nonNull(req.getIsSyncLogin()) && req.getIsSyncLogin()){
if (Objects.nonNull(req.getIsSyncLogin()) && req.getIsSyncLogin()) {
internalSync(BlackAndWhiteListInternalSyncReq.builder()
.type(req.getType())
.sourceModule(req.getModule())
@ -194,12 +218,12 @@ public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
.targetModule(BlackAndWhiteListConstant.ALL_LOGIN).build());
}
// 同步至注册黑名单
if (Objects.nonNull(req.getIsSyncRegister()) && req.getIsSyncRegister()){
if (Objects.nonNull(req.getIsSyncRegister()) && req.getIsSyncRegister()) {
internalSync(BlackAndWhiteListInternalSyncReq.builder()
.type(req.getType())
.sourceModule(req.getModule())
.sourceFields(Collections.singletonList(req.getSyncRegisterField()))
.targetModule(BlackAndWhiteListConstant.OU_REGISTER_BLACK_LIST).build());
.type(req.getType())
.sourceModule(req.getModule())
.sourceFields(Collections.singletonList(req.getSyncRegisterField()))
.targetModule(BlackAndWhiteListConstant.OU_REGISTER_BLACK_LIST).build());
}
return saved;
}
@ -249,17 +273,6 @@ public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
return BeanMapper.copyList(blackAndWhiteListRepository.getListByModule(type.getValue(), module), BlackAndWhiteListResp.class);
}
/**
* 更新指定id的黑白名单记录
*
* @param id 记录id
* @param param 记录参数
* @return true-更新成功false-更新失败
*/
public boolean updateParamById(Long id, Map<String, Object> param) {
return blackAndWhiteListRepository.updateParamById(id, param);
}
/**
* 删除指定模块名的所有黑/白名单记录
*
@ -375,32 +388,38 @@ public class BlackAndWhiteListServiceImpl implements BlackAndWhiteListService {
blackWhiteList.setParam(map);
return blackWhiteList;
}).collect(Collectors.toList());
return blackAndWhiteListRepository.saveBatch(list);
return blackAndWhiteListRepository.batchCreate(list);
}
@Override
public List<SaasBlackWhiteList> listModuleBlackUser(){
public List<SaasBlackWhiteList> listModuleBlackUser() {
// 同步到RockerMQ
ArrayList<BlackModuleEnum> models = Lists.newArrayList(BlackModuleEnum.GXJG_BLACKUSER_WORKER, BlackModuleEnum.GXJG_BLACKUSER_TEAMLEADER, BlackModuleEnum.GXJG_BLACKUSER_EMPLOYEE);
return blackAndWhiteListRepository.listByModule(ListTypeEnum.BLACK_LIST.getValue(), BlackModuleEnum.getValueList(models));
}
@Override
public Boolean isInBlackListExist(BlackListReq req){
public Boolean isInBlackListExist(BlackListReq req) {
List<SaasBlackWhiteList> whiteLists = blackAndWhiteListRepository.blackWhiteLists(req);
return CollectionUtil.isNotEmpty(whiteLists);
}
@Override
public List<BlackAndWhiteListResp> isInBlackListExistList(BlackListReq req){
public List<BlackAndWhiteListResp> isInBlackListExistList(BlackListReq req) {
List<SaasBlackWhiteList> detail = blackAndWhiteListRepository.blackWhiteLists(req);
return BeanMapper.copyList(detail, BlackAndWhiteListResp.class);
}
@Override
public List<SaasBlackWhiteList> listModuleBlackUser(BlackListReq req){
public List<SaasBlackWhiteList> listModuleBlackUser(BlackListReq req) {
// 同步到RockerMQ
return blackAndWhiteListRepository.blackWhiteLists(req);
}
@Override
public IPage<BlackAndWhiteListResp> page(BlackAndWhiteListPageReq req) {
IPage<SaasBlackWhiteList> page = blackAndWhiteListRepository.page(req);
return page.convert(e -> BeanMapper.copyBean(e, BlackAndWhiteListResp.class));
}
}