lrj
2 天以前 c61d4fe27c97d2ecc907756aa571a4ef14a7b9b6
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package com.rongyichuang.activity.dto;
 
import com.rongyichuang.activity.entity.Activity;
import com.rongyichuang.rating.dto.response.RatingSchemeResponse;
 
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
 
public class ActivityResponse {
    
    private Long id;
    private Long pid;
    private String path;
    private String name;
    private String description;
    private LocalDateTime signupDeadline;
    private LocalDateTime matchTime;
    private String address;
    private Long ratingSchemeId;
    private Integer playerMax;
    private Integer state;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;
    
    // 关联数据
    private RatingSchemeResponse ratingScheme;
    private List<ActivityResponse> stages;
    private ActivityResponse parent;
    
    // 统计数据
    private Integer playerCount = 0; // 报名人数(实际人数)
    private String stateName; // 状态名称
    
    // 构造函数
    public ActivityResponse() {}
    
    public ActivityResponse(Activity activity) {
        this(activity, false);
    }
 
    // 引入浅映射标记:当 shallow=true 时,不再继续映射 stages/parent,避免递归
    private ActivityResponse(Activity activity, boolean shallow) {
        this.id = activity.getId();
        this.pid = activity.getPid();
        this.path = activity.getPath();
        this.name = activity.getName();
        this.description = activity.getDescription();
        this.signupDeadline = activity.getSignupDeadline();
        this.matchTime = activity.getMatchTime();
        this.address = activity.getAddress();
        this.ratingSchemeId = activity.getRatingSchemeId();
        this.playerMax = activity.getPlayerMax();
        this.state = activity.getState();
        this.createTime = activity.getCreateTime();
        this.updateTime = activity.getUpdateTime();
        
        // 设置状态名称
        this.stateName = getStateNameByValue(activity.getState());
        
        // 设置关联数据(仅浅映射评分模板,避免任何层级的活动递归)
        if (activity.getRatingScheme() != null) {
            this.ratingScheme = new RatingSchemeResponse(activity.getRatingScheme());
        }
        // 明确不在DTO构造中填充stages和parent,避免递归与懒加载环路
        this.stages = null;
        this.parent = null;
    }
    
    // 状态名称映射
    private String getStateNameByValue(Integer state) {
        if (state == null) return "未知";
        switch (state) {
            case 0: return "未发布";
            case 1: return "已发布";
            case 2: return "已关闭";
            default: return "未知";
        }
    }
    
    // Getters and Setters
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getPid() {
        return pid;
    }
    
    public void setPid(Long pid) {
        this.pid = pid;
    }
    
    public String getPath() {
        return path;
    }
    
    public void setPath(String path) {
        this.path = path;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public LocalDateTime getSignupDeadline() {
        return signupDeadline;
    }
    
    public void setSignupDeadline(LocalDateTime signupDeadline) {
        this.signupDeadline = signupDeadline;
    }
    
    public LocalDateTime getMatchTime() {
        return matchTime;
    }
    
    public void setMatchTime(LocalDateTime matchTime) {
        this.matchTime = matchTime;
    }
    
    public String getAddress() {
        return address;
    }
    
    public void setAddress(String address) {
        this.address = address;
    }
    
    public Long getRatingSchemeId() {
        return ratingSchemeId;
    }
    
    public void setRatingSchemeId(Long ratingSchemeId) {
        this.ratingSchemeId = ratingSchemeId;
    }
    
    public Integer getPlayerMax() {
        return playerMax;
    }
    
    public void setPlayerMax(Integer playerMax) {
        this.playerMax = playerMax;
    }
    
    public Integer getState() {
        return state;
    }
    
    public void setState(Integer state) {
        this.state = state;
    }
    
    public LocalDateTime getCreateTime() {
        return createTime;
    }
    
    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
    
    public LocalDateTime getUpdateTime() {
        return updateTime;
    }
    
    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }
    
    public RatingSchemeResponse getRatingScheme() {
        return ratingScheme;
    }
    
    public void setRatingScheme(RatingSchemeResponse ratingScheme) {
        this.ratingScheme = ratingScheme;
    }
    
    public List<ActivityResponse> getStages() {
        return stages;
    }
    
    public void setStages(List<ActivityResponse> stages) {
        this.stages = stages;
    }
    
    public ActivityResponse getParent() {
        return parent;
    }
    
    public void setParent(ActivityResponse parent) {
        this.parent = parent;
    }
    
    public Integer getPlayerCount() {
        return playerCount;
    }
    
    public void setPlayerCount(Integer playerCount) {
        this.playerCount = playerCount;
    }
    
    public String getStateName() {
        return stateName;
    }
    
    public void setStateName(String stateName) {
        this.stateName = stateName;
    }
    
    // 业务方法
    public boolean isCompetition() {
        return pid == 0;
    }
    
    public boolean isStage() {
        return pid > 0;
    }
}