第一步: 建立需要传入参数的 Vo 对象。
@ApiModelProperty(value = "身份证")
private String idcard;
@ApiModelProperty(value = "姓名")
private String name;
public Vo(){
super();
}
public Vo(Personnel personnel){
BeanUtils.copyProperties(personnel, this);
}
public void setIdcard(String idcard){
this.idcard = idcard;
}
public void setName(String name){
this.name = name;
}
第二步:实现建立Service
(1)接口: interface
List<ErrorVo> check(Vo vo);
(2)实现 @Service
@Override
public List<ErrorVo> submits(Validation validation, Vo vo) {
List<ErrorVo> Vos = null;
Object valservice = SpringUtil.getBean(validation.getClassName());
if (StrUtil.isNotEmpty(validation.getCheckMethod())) {
errorTypeVos = (List<ErrorVo>) Reflections.invokeMethodByName(valservice,
validation.getCheckMethod(), sysUserVo);
}
return errorTypeVos;
}
@Override
public List<Validation> queryChecks(QueryWrapper<DataValidation> query) {
return dataValidationMapper.selectList(query);
}
@Override
public List<ErrorVo> checkEmployee(Vo vo) {
QueryWrapper<Validation> query = new QueryWrapper<>();
query.lambda().eq(Validation::getType, "type");
List<DataValidation> checkVal = baseService.queryChecks(query);
List<ErrorVo> errorVos = new ArrayList<>();
List<CompletableFuture<List<ErrorVo>>> collect = checkVal.parallelStream()
.filter(waitSortBizData -> "submit".equals(waitSortBizData.getCheckMode()))
.map(validation -> CompletableFuture.supplyAsync(() ->
threadService.submits(check, vo), executor)
).collect(Collectors.toList());
List<List<ErrorVo>> list = collect.stream().map(CompletableFuture::join).collect(Collectors.toList());
for (List<ErrorVo> l : list) {
if (CollUtil.isNotEmpty(l)) {
errorVos .addAll(l);
}
}
return errorVos ;
}