1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package org.jeecg.modules.dnc.dto;
 
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.jeecg.modules.dnc.entity.DeviceGroup;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
 
import java.util.List;
 
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class DeviceGroupExt extends DeviceGroup {
    private DeviceGroupExt parent;
    private List<DeviceGroupExt> children;
 
    @JsonIgnore
    private String userId;
 
    public boolean hasChild() {
        boolean b = true;
        if(this.getChildren() == null || this.getChildren().size() < 1) {
            b = false;
        }
        return b;
    }
 
    public List<DeviceGroup> getAllChildren(List<DeviceGroup> groups) {
        if(this.hasChild()) {
            List<DeviceGroupExt> extList = this.getChildren();
            for(DeviceGroupExt ext : extList) {
                groups = ext.getAllChildren(groups);
            }
            DeviceGroup group = new DeviceGroup();
            BeanUtils.copyProperties(this, group);
            groups.add(group);
        }else {
            DeviceGroup group = new DeviceGroup();
            BeanUtils.copyProperties(this, group);
            groups.add(group);
        }
        return groups;
    }
 
}