mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善
This commit is contained in:
@@ -18,6 +18,7 @@ import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/** */
|
||||
@@ -33,6 +34,14 @@ public class CoalWashingDailyAnalysisDto extends OrgCommonDto {
|
||||
@DictTranslate(dictKey = DictCode.ARCHIVESTATUS)
|
||||
private String archiveStatusName;
|
||||
|
||||
@Comment("开机时间")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Comment("停机时间")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Comment("皮带秤设备组")
|
||||
private String pdcDeviceGroup;
|
||||
|
||||
|
||||
@ElementCollection
|
||||
|
||||
130
src/main/java/cn/lihongjie/coal/common/SpecificationUtils.java
Normal file
130
src/main/java/cn/lihongjie/coal/common/SpecificationUtils.java
Normal file
@@ -0,0 +1,130 @@
|
||||
package cn.lihongjie.coal.common;
|
||||
|
||||
import jakarta.persistence.criteria.Expression;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@UtilityClass
|
||||
public class SpecificationUtils {
|
||||
|
||||
public static <T> Specification<T> like(String field, String value) {
|
||||
return (root, query, cb) -> cb.like(getExpression(root, field), "%" + value + "%");
|
||||
}
|
||||
|
||||
public static <T> Expression<T> getExpression(Root root, String field) {
|
||||
if (field.contains(".")) {
|
||||
String[] fields = field.split("\\.");
|
||||
Path expression = root.get(fields[0]);
|
||||
for (int i = 1; i < fields.length; i++) {
|
||||
expression = expression.get(fields[i]);
|
||||
}
|
||||
return expression;
|
||||
} else {
|
||||
return root.get(field);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Specification<T> llike(String field, String value) {
|
||||
return (root, query, cb) -> cb.like(getExpression(root, field), "%" + value);
|
||||
}
|
||||
|
||||
public static <T> Specification<T> rlike(String field, String value) {
|
||||
return (root, query, cb) -> cb.like(getExpression(root, field), value + "%");
|
||||
}
|
||||
|
||||
public static <T> Specification<T> eq(String field, Object value) {
|
||||
return (root, query, cb) -> cb.equal(getExpression(root, field), value);
|
||||
}
|
||||
|
||||
public static <T> Specification<T> in(String field, Collection<?> value) {
|
||||
return (root, query, cb) -> getExpression(root, field).in(value);
|
||||
}
|
||||
|
||||
public static <T> Specification<T> in(String field, Object... value) {
|
||||
return (root, query, cb) -> getExpression(root, field).in(value);
|
||||
}
|
||||
|
||||
public static <T> Specification<T> notIn(String field, Collection<?> value) {
|
||||
return (root, query, cb) -> cb.not(getExpression(root, field).in(value));
|
||||
}
|
||||
|
||||
public static <T> Specification<T> notIn(String field, Object... value) {
|
||||
return (root, query, cb) -> cb.not(getExpression(root, field).in(value));
|
||||
}
|
||||
|
||||
public static <T> Specification<T> isNull(String field) {
|
||||
return (root, query, cb) -> cb.isNull(getExpression(root, field));
|
||||
}
|
||||
|
||||
public static <T> Specification<T> isNotNull(String field) {
|
||||
return (root, query, cb) -> cb.isNotNull(getExpression(root, field));
|
||||
}
|
||||
|
||||
// lt
|
||||
public static <T> Specification<T> lt(String field, Object value) {
|
||||
return (root, query, cb) -> cb.lessThan(getExpression(root, field), (Comparable) value);
|
||||
}
|
||||
|
||||
// le
|
||||
public static <T> Specification<T> le(String field, Object value) {
|
||||
return (root, query, cb) -> cb.lessThanOrEqualTo(getExpression(root, field), (Comparable) value);
|
||||
}
|
||||
|
||||
// gt
|
||||
public static <T> Specification<T> gt(String field, Object value) {
|
||||
return (root, query, cb) -> cb.greaterThan(getExpression(root, field), (Comparable) value);
|
||||
}
|
||||
|
||||
// ge
|
||||
public static <T> Specification<T> ge(String field, Object value) {
|
||||
return (root, query, cb) ->
|
||||
cb.greaterThanOrEqualTo(getExpression(root, field), (Comparable) value);
|
||||
}
|
||||
|
||||
// is true
|
||||
public static <T> Specification<T> isTrue(String field) {
|
||||
return (root, query, cb) -> cb.isTrue(getExpression(root, field));
|
||||
}
|
||||
|
||||
// is false
|
||||
public static <T> Specification<T> isFalse(String field) {
|
||||
return (root, query, cb) -> cb.isFalse(getExpression(root, field));
|
||||
}
|
||||
|
||||
// is empty
|
||||
public static <T> Specification<T> isEmpty(String field) {
|
||||
return (root, query, cb) -> cb.isEmpty(getExpression(root, field));
|
||||
}
|
||||
|
||||
public static <T> Specification<T> or(Specification<T>... specs) {
|
||||
return Arrays.stream(specs)
|
||||
.reduce(
|
||||
(a, b) ->
|
||||
(root, query, cb) ->
|
||||
cb.or(
|
||||
a.toPredicate(root, query, cb),
|
||||
b.toPredicate(root, query, cb)))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static <T> Specification<T> and(Specification<T>... specs) {
|
||||
return Arrays.stream(specs)
|
||||
.reduce(
|
||||
(a, b) ->
|
||||
(root, query, cb) ->
|
||||
cb.and(
|
||||
a.toPredicate(root, query, cb),
|
||||
b.toPredicate(root, query, cb)))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static <T> Specification<T> not(Specification<T> spec) {
|
||||
return (root, query, cb) -> cb.not(spec.toPredicate(root, query, cb));
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
@Data
|
||||
public class DeviceCategoryDto extends OrgCommonDto {
|
||||
private String parent;
|
||||
private List<SimpleDto> user;
|
||||
private List<SimpleDto> users;
|
||||
private List<String> allDeviceIds;
|
||||
|
||||
private List<String> childrenDeviceIds;
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
@Data
|
||||
public class DeviceCategoryTreeDto extends OrgCommonDto {
|
||||
|
||||
private List<SimpleDto> user;
|
||||
private List<SimpleDto> users;
|
||||
private List<String> allDeviceIds;
|
||||
|
||||
private List<String> childrenDeviceIds;
|
||||
|
||||
@@ -3,10 +3,7 @@ package cn.lihongjie.coal.deviceCategory.entity;
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.user.entity.UserEntity;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -17,7 +14,7 @@ import java.util.List;
|
||||
public class DeviceCategoryEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
@OneToMany
|
||||
@ManyToMany
|
||||
private List<UserEntity> users;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user