设备分类添加设备数量

This commit is contained in:
2024-03-19 10:52:54 +08:00
parent 22a759bc8e
commit b1ccbf7176
3 changed files with 32 additions and 0 deletions

View File

@@ -4,7 +4,14 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import java.util.List;
@Data
public class DeviceCategoryDto extends OrgCommonDto {
private String parent;
private List<String> allDeviceIds;
private List<String> childrenDeviceIds;
private List<String> selfDeviceIds;
}

View File

@@ -8,6 +8,12 @@ import java.util.List;
@Data
public class DeviceCategoryTreeDto extends OrgCommonDto {
private List<String> allDeviceIds;
private List<String> childrenDeviceIds;
private List<String> selfDeviceIds;
private List<DeviceCategoryTreeDto> children;
private String parent;

View File

@@ -2,6 +2,8 @@ package cn.lihongjie.coal.deviceCategory.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import io.hypersistence.utils.hibernate.type.array.ListArrayType;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
@@ -9,11 +11,28 @@ import jakarta.persistence.OneToMany;
import lombok.Data;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.Type;
import java.util.List;
@Data
@Entity
public class DeviceCategoryEntity extends OrgCommonEntity {
@Type(ListArrayType.class)
@Formula("(select array_agg(e.id) from t_device e where e.category_id = any(self_and_children_ids('t_device_category', id, true)))")
private List<String> allDeviceIds;
@Type(ListArrayType.class)
@Formula("(select array_agg(e.id) from t_device e where e.category_id = any(self_and_children_ids('t_device_category', id, false)))")
private List<String> childrenDeviceIds;
@Type(ListArrayType.class)
@Formula("(select array_agg(e.id) from t_device e where e.category_id = id)")
private List<String> selfDeviceIds;
@ManyToOne private DeviceCategoryEntity parent;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)