feat:实现特殊情况的保存
This commit is contained in:
parent
617098577e
commit
d68c2b2300
@ -148,7 +148,10 @@ public final class CriteriaBuilder<T extends Domain> {
|
||||
// 添加自定义criteria
|
||||
if (CollectionUtils.isNotEmpty(criterias)) {
|
||||
for (Supplier<Criteria> builder : criterias) {
|
||||
criteria.add(builder.get());
|
||||
Criteria built = builder.get();
|
||||
if (null != built) {
|
||||
criteria.add(built);
|
||||
}
|
||||
}
|
||||
}
|
||||
return combine(criteria);
|
||||
|
@ -4,6 +4,7 @@ import com.flyfish.framework.builder.CriteriaBuilder;
|
||||
import com.flyfish.framework.domain.base.NameLikeQo;
|
||||
import com.flyfish.framework.domain.po.Department;
|
||||
import com.flyfish.framework.enums.UserType;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
@ -22,6 +23,7 @@ import java.util.Set;
|
||||
public abstract class AuthorizedQo<T extends AuthorizedDomain> extends NameLikeQo<T> {
|
||||
|
||||
// 是否已发布
|
||||
@Getter(AccessLevel.NONE)
|
||||
private Boolean published;
|
||||
|
||||
/**
|
||||
@ -40,21 +42,43 @@ public abstract class AuthorizedQo<T extends AuthorizedDomain> extends NameLikeQ
|
||||
public CriteriaBuilder<T> criteriaBuilder() {
|
||||
// 超级管理员拥有查看所有草稿的权限
|
||||
if (user.getType() == UserType.SUPER_ADMIN) {
|
||||
return super.criteriaBuilder().with("published");
|
||||
return super.criteriaBuilder().with(this::withPublished);
|
||||
}
|
||||
// 查询草稿,只查询自己的
|
||||
if (BooleanUtils.isFalse(published)) {
|
||||
return super.criteriaBuilder().with("published").with(() -> Criteria.where("creatorId").is(user.getId()));
|
||||
return super.criteriaBuilder()
|
||||
.with(this::withPublished)
|
||||
.with(() -> Criteria.where("creatorId").is(user.getId()));
|
||||
}
|
||||
// 普通查询,根据权限配置查询
|
||||
return super.criteriaBuilder()
|
||||
.with(this::withPublished)
|
||||
.with(() -> Criteria.where("$or").is(
|
||||
CriteriaBuilder.createCriteriaList(
|
||||
Criteria.where("authorizeId").in(authorizeIds()),
|
||||
Criteria.where("creatorId").is(user.getId())
|
||||
.and("authorizeId").in(((AuthorizedUserDetails) user).getVisibleDeparts())
|
||||
)
|
||||
))
|
||||
.with("published");
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造发布状态查询
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
private Criteria withPublished() {
|
||||
if (null != published) {
|
||||
if (BooleanUtils.isTrue(published)) {
|
||||
return Criteria.where("published").is(true);
|
||||
}
|
||||
return Criteria.where("$or").is(
|
||||
CriteriaBuilder.createCriteriaList(
|
||||
Criteria.where("published").isNull(),
|
||||
Criteria.where("published").is(false)
|
||||
)
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user