186 lines
5.0 KiB
Java
186 lines
5.0 KiB
Java
package com.example.caseData.dto.caseClinicalArticle;
|
||
|
||
import cn.hutool.core.bean.BeanUtil;
|
||
import com.baomidou.mybatisplus.annotation.TableField;
|
||
import com.example.caseData.dto.caseClinicalArticleAuthor.CaseClinicalArticleAuthorDto;
|
||
import com.example.caseData.dto.caseClinicalArticleLabel.CaseClinicalArticleLabelDto;
|
||
import com.example.caseData.model.CaseClinicalArticleLabelModel;
|
||
import com.example.caseData.model.CaseClinicalArticleModel;
|
||
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 CaseClinicalArticleDto {
|
||
/**
|
||
* 主键id
|
||
*/
|
||
@JsonProperty("article_id")
|
||
private String articleId;
|
||
|
||
/**
|
||
* 标题
|
||
*/
|
||
@JsonProperty("article_title")
|
||
private String articleTitle;
|
||
|
||
/**
|
||
* 状态(1:正常 2:禁用)
|
||
*/
|
||
@JsonProperty("article_status")
|
||
private Integer articleStatus;
|
||
|
||
/**
|
||
* 删除状态(0:否 1:是)
|
||
*/
|
||
@JsonProperty("delete_status")
|
||
private Integer deleteStatus;
|
||
|
||
/**
|
||
* 阅读量
|
||
*/
|
||
@JsonProperty("read_num")
|
||
private Integer readNum;
|
||
|
||
/**
|
||
* 收藏量
|
||
*/
|
||
@JsonProperty("collect_num")
|
||
private Integer collectNum;
|
||
|
||
/**
|
||
* 评论量
|
||
*/
|
||
@JsonProperty("comment_num")
|
||
private Integer commentNum;
|
||
|
||
/**
|
||
* 发表时间
|
||
*/
|
||
@JsonProperty("push_date")
|
||
private LocalDateTime pushDate;
|
||
|
||
/**
|
||
* 证书图片
|
||
*/
|
||
@JsonProperty("cert_image")
|
||
private String certImage;
|
||
|
||
/**
|
||
* 是否外部链接(0:否 1:是)
|
||
*/
|
||
@JsonProperty("is_link")
|
||
private Integer isLink;
|
||
|
||
/**
|
||
* 外部链接地址
|
||
*/
|
||
@JsonProperty("is_link_url")
|
||
private String isLinkUrl;
|
||
|
||
/**
|
||
* 内容
|
||
*/
|
||
@JsonProperty("article_content")
|
||
private String articleContent;
|
||
|
||
/**
|
||
* 创建时间
|
||
*/
|
||
@JsonProperty("created_at")
|
||
private LocalDateTime createdAt;
|
||
|
||
/**
|
||
* 修改时间
|
||
*/
|
||
@JsonProperty("updated_at")
|
||
private LocalDateTime updatedAt;
|
||
|
||
/**
|
||
* 作者
|
||
*/
|
||
@JsonProperty("author")
|
||
private List<CaseClinicalArticleAuthorDto> author;
|
||
|
||
/**
|
||
* 标签
|
||
*/
|
||
@JsonProperty("label")
|
||
private List<CaseClinicalArticleLabelDto> label;
|
||
|
||
/**
|
||
* 收藏状态
|
||
*/
|
||
@JsonProperty("is_collect")
|
||
private boolean isCollect;
|
||
|
||
/**
|
||
* 列表
|
||
*/
|
||
public static List<CaseClinicalArticleDto> GetListDto(List<CaseClinicalArticleModel> models) {
|
||
if (models == null || models.isEmpty()) {
|
||
return Collections.emptyList();
|
||
}
|
||
|
||
return models.stream()
|
||
.map(model -> {
|
||
CaseClinicalArticleDto dto = BeanUtil.copyProperties(model, CaseClinicalArticleDto.class);
|
||
|
||
// 示例:手动处理字段类型不一致
|
||
if (model.getArticleId() != null) {
|
||
dto.setArticleId(String.valueOf(model.getArticleId())); // Long -> String
|
||
}
|
||
|
||
// 作者
|
||
if (model.getAuthor() != null && !model.getAuthor().isEmpty()) {
|
||
List<CaseClinicalArticleAuthorDto> caseClinicalArticleAuthorListDto = CaseClinicalArticleAuthorDto.GetListDto(model.getAuthor());
|
||
dto.setAuthor(caseClinicalArticleAuthorListDto);
|
||
}
|
||
|
||
// 标签
|
||
if (model.getLabel() != null && !model.getLabel().isEmpty()) {
|
||
List<CaseClinicalArticleLabelDto> caseClinicalArticleLabelListDto = CaseClinicalArticleLabelDto.GetListDto(model.getLabel());
|
||
dto.setLabel(caseClinicalArticleLabelListDto);
|
||
}
|
||
|
||
dto.setArticleContent("");
|
||
return dto;
|
||
})
|
||
.collect(Collectors.toList());
|
||
}
|
||
|
||
/**
|
||
* 详情
|
||
*/
|
||
public static CaseClinicalArticleDto GetDto(CaseClinicalArticleModel model) {
|
||
if (model == null) {
|
||
return null;
|
||
}
|
||
|
||
CaseClinicalArticleDto dto = BeanUtil.copyProperties(model, CaseClinicalArticleDto.class);
|
||
|
||
// 类型转换示例
|
||
if (model.getArticleId() != null) {
|
||
dto.setArticleId(String.valueOf(model.getArticleId())); // Long -> String
|
||
}
|
||
|
||
// 作者
|
||
if (model.getAuthor() != null && !model.getAuthor().isEmpty()) {
|
||
List<CaseClinicalArticleAuthorDto> caseClinicalArticleAuthorListDto = CaseClinicalArticleAuthorDto.GetListDto(model.getAuthor());
|
||
dto.setAuthor(caseClinicalArticleAuthorListDto);
|
||
}
|
||
|
||
// 标签
|
||
if (model.getLabel() != null && !model.getLabel().isEmpty()) {
|
||
List<CaseClinicalArticleLabelDto> caseClinicalArticleLabelListDto = CaseClinicalArticleLabelDto.GetListDto(model.getLabel());
|
||
dto.setLabel(caseClinicalArticleLabelListDto);
|
||
}
|
||
|
||
return dto;
|
||
}
|
||
}
|