124 lines
3.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<CaseExchangeVoteOptionDto> caseExchangeVoteOption;
/**
* 列表
*/
public static List<CaseExchangeVoteDto> GetListDto(List<CaseExchangeVoteModel> 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<CaseExchangeVoteOptionDto> 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<CaseExchangeVoteOptionDto> caseExchangeVoteOptionListDto = CaseExchangeVoteOptionDto.GetListDto(model.getCaseExchangeVoteOption());
dto.setCaseExchangeVoteOption(caseExchangeVoteOptionListDto);
}
return dto;
}
}