package com.example.caseData.dto.caseExchangeVote; import cn.hutool.core.bean.BeanUtil; import com.example.caseData.dto.caseClinicalArticleAuthor.CaseClinicalArticleAuthorDto; import com.example.caseData.dto.caseExchange.CaseExchangeDto; import com.example.caseData.dto.caseExchangeVoteOption.CaseExchangeVoteOptionDto; import com.example.caseData.model.CaseExchangeModel; import com.example.caseData.model.CaseExchangeVoteModel; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import java.time.LocalDateTime; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @Data public class CaseExchangeVoteDto { /** * 主键id */ @JsonProperty("vote_id") private String voteId; /** * 病例交流id */ @JsonProperty("exchange_id") private String exchangeId; /** * 选项标题 */ @JsonProperty("vote_title") private String voteTitle; /** * 结束投票时间 */ @JsonProperty("end_time") private LocalDateTime endTime; /** * 是否开启中(0:否 1:是)过期状态 */ @JsonProperty("is_enabled") private Integer isEnabled; /** * 是否已投票(0: 否 1:是) */ @JsonProperty("is_have_voted") private Integer isHaveVoted = 0; /** * 创建时间 */ @JsonProperty("created_at") private LocalDateTime createdAt; /** * 修改时间 */ @JsonProperty("updated_at") private LocalDateTime updatedAt; /** * 选项 */ @JsonProperty("case_exchange_vote_option") private List caseExchangeVoteOption; /** * 列表 */ public static List GetListDto(List models) { if (models == null || models.isEmpty()) { return Collections.emptyList(); } return models.stream() .map(model -> { CaseExchangeVoteDto dto = BeanUtil.copyProperties(model, CaseExchangeVoteDto.class); // 示例:手动处理字段类型不一致 if (model.getVoteId() != null) { dto.setVoteId(String.valueOf(model.getVoteId())); // Long -> String } // 选项 if (model.getCaseExchangeVoteOption() != null && !model.getCaseExchangeVoteOption().isEmpty()) { List caseExchangeVoteOptionListDto = CaseExchangeVoteOptionDto.GetListDto(model.getCaseExchangeVoteOption()); dto.setCaseExchangeVoteOption(caseExchangeVoteOptionListDto); } return dto; }) .collect(Collectors.toList()); } /** * 详情 */ public static CaseExchangeVoteDto GetDto(CaseExchangeVoteModel model) { if (model == null) { return null; } CaseExchangeVoteDto dto = BeanUtil.copyProperties(model, CaseExchangeVoteDto.class); // 类型转换示例 if (model.getVoteId() != null) { dto.setVoteId(String.valueOf(model.getVoteId())); // Long -> String } // 选项 if (model.getCaseExchangeVoteOption() != null && !model.getCaseExchangeVoteOption().isEmpty()) { List caseExchangeVoteOptionListDto = CaseExchangeVoteOptionDto.GetListDto(model.getCaseExchangeVoteOption()); dto.setCaseExchangeVoteOption(caseExchangeVoteOptionListDto); } return dto; } }