提交 654ae019 authored 作者: liupengfei's avatar liupengfei

--no commit message

上级 c03f4308
......@@ -247,49 +247,90 @@ public abstract class BaseServiceImpl<M, ID extends Serializable> implements Bas
@Override
public M notNull(ID id) {
M m = selectByPrimaryKey(id);
if (m == null) {
throw new BaseException("id:" + id + ",在:" + entityClass + ",不存在");
}
return m;
return this.ofNullable(id).orElseThrow(() -> new BaseException("id:" + id + ",在:" + entityClass + ",不存在")) ;
}
@Override
public M notNull(ID id, Consumer<M> consumer) {
M m = this.initParams(id, consumer);
return this.notNull(m);
}
private M initParams(ID id, Consumer<M> consumer) {
M m = this.initParams(consumer);
try {
this.idSetMethod.invoke(m, id);
} catch (Exception e) {
throw new BaseException("notNull创建搜索条件失败:" + entityClass + ", setId失败", e);
}
return m;
}
private M initParams(Consumer<M> consumer) {
M m = null;
try {
m = entityClass.newInstance();
this.idSetMethod.invoke(m, id);
consumer.accept(m);
} catch (Exception e) {
throw new BaseException("notNull创建搜索条件失败:" + entityClass, e);
}
M result = this.selectOne(m);
if (result == null) {
throw new BaseException("Record:" + m + ",在:" + entityClass + ",不存在");
}
return result;
return m;
}
@Override
public M notNull(M m) {
M result = this.selectOne(m);
if (result == null) {
throw new BaseException("Record:" + m + ",在:" + entityClass + ",不存在");
}
return result;
return this.ofNullable(m).orElseThrow(() -> new BaseException("Record:" + m + ",在:" + entityClass + ",不存在"));
}
@Override
public M notNull(Consumer<M> consumer) {
M m = null;
try {
m = entityClass.newInstance();
consumer.accept(m);
} catch (Exception e) {
throw new BaseException("notNull创建搜索条件失败:" + entityClass, e);
}
M m = this.initParams(consumer);
return this.notNull(m);
}
@Override
public Optional<M> ofNullable(ID id) {
M m = selectByPrimaryKey(id);
return Optional.ofNullable(m);
}
@Override
public Optional<M> ofNullable(ID id, Consumer<M> consumer) {
M m = this.initParams(id, consumer);
return this.ofNullable(m);
}
@Override
public Optional<M> ofNullable(M record) {
M result = this.selectOne(record);
return Optional.ofNullable(result);
}
@Override
public Optional<M> ofNullable(Consumer<M> consumer) {
M m = this.initParams(consumer);
return this.ofNullable(m);
}
@Override
public void ifPresent(ID id, Consumer<M> result) {
this.ofNullable(id).ifPresent(result);
}
@Override
public void ifPresent(ID id, Consumer<M> consumer, Consumer<M> result) {
this.ofNullable(id, consumer).ifPresent(result);
}
@Override
public void ifPresent(M record, Consumer<M> result) {
this.ofNullable(record).ifPresent(result);
}
@Override
public void ifPresent(Consumer<M> consumer, Consumer<M> result) {
this.ofNullable(consumer).ifPresent(result);
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论