package com.example.caseData.dto.caseExchangeVoteOption; import cn.hutool.core.bean.BeanUtil; import com.example.caseData.dto.caseExchangeVote.CaseExchangeVoteDto; import com.example.caseData.model.CaseExchangeVoteModel; import com.example.caseData.model.CaseExchangeVoteOptionModel; 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 CaseExchangeVoteOptionDto { /** * 主键id */ @JsonProperty("option_id") private String optionId; /** * 投票id */ @JsonProperty("vote_id") private String voteId; /** * 选项 */ @JsonProperty("option_value") private String optionValue; /** * 票数 */ @JsonProperty("vote_num") private Integer voteNum; /** * 被选择占比 */ @JsonProperty("proportion") private Integer proportion; /** * 创建时间 */ @JsonProperty("created_at") private LocalDateTime createdAt; /** * 修改时间 */ @JsonProperty("updated_at") private LocalDateTime updatedAt; /** * 列表 */ public static List GetListDto(List models) { if (models == null || models.isEmpty()) { return Collections.emptyList(); } return models.stream() .map(model -> { CaseExchangeVoteOptionDto dto = BeanUtil.copyProperties(model, CaseExchangeVoteOptionDto.class); // 示例:手动处理字段类型不一致 if (model.getOptionId() != null) { dto.setOptionId(String.valueOf(model.getOptionId())); // Long -> String } return dto; }) .collect(Collectors.toList()); } /** * 详情 */ public static CaseExchangeVoteOptionDto GetDto(CaseExchangeVoteOptionModel model) { if (model == null) { return null; } CaseExchangeVoteOptionDto dto = BeanUtil.copyProperties(model, CaseExchangeVoteOptionDto.class); // 类型转换示例 if (model.getOptionId() != null) { dto.setOptionId(String.valueOf(model.getOptionId())); // Long -> String } return dto; } }