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;
|
}
|
}
|