package com.rongyichuang.news.dto;
|
|
import com.rongyichuang.news.entity.News;
|
import com.rongyichuang.config.CosConfig;
|
|
import java.time.LocalDateTime;
|
|
public class NewsResponse {
|
|
private Long id;
|
private String title;
|
private String content;
|
private String summary;
|
private String coverImage;
|
private String author;
|
private Integer viewCount = 0;
|
private Integer state = 1;
|
private String stateName;
|
private LocalDateTime createTime;
|
private LocalDateTime updateTime;
|
|
// 构造函数
|
public NewsResponse() {}
|
|
public NewsResponse(News news) {
|
this.id = news.getId();
|
this.title = news.getTitle();
|
this.content = news.getContent();
|
this.summary = news.getSummary();
|
this.coverImage = news.getCoverImage();
|
this.author = news.getAuthor();
|
this.viewCount = news.getViewCount();
|
this.state = news.getState();
|
this.createTime = news.getCreateTime();
|
this.updateTime = news.getUpdateTime();
|
this.stateName = getStateNameByValue(news.getState());
|
}
|
|
// 状态名称映射
|
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 String getTitle() {
|
return title;
|
}
|
|
public void setTitle(String title) {
|
this.title = title;
|
}
|
|
public String getContent() {
|
// 处理富文本内容,确保图片具有响应式样式
|
if (content != null) {
|
// 为所有img标签添加样式属性,确保图片不会超出容器
|
return content.replaceAll("<img([^>]*?)>", "<img$1 style=\"max-width:100%;height:auto;display:block;margin:10px 0;\" />");
|
}
|
return content;
|
}
|
|
public void setContent(String content) {
|
this.content = content;
|
}
|
|
public String getSummary() {
|
return summary;
|
}
|
|
public void setSummary(String summary) {
|
this.summary = summary;
|
}
|
|
public String getCoverImage() {
|
return coverImage;
|
}
|
|
public void setCoverImage(String coverImage) {
|
this.coverImage = coverImage;
|
}
|
|
public String getAuthor() {
|
return author;
|
}
|
|
public void setAuthor(String author) {
|
this.author = author;
|
}
|
|
public Integer getViewCount() {
|
return viewCount;
|
}
|
|
public void setViewCount(Integer viewCount) {
|
this.viewCount = viewCount;
|
}
|
|
public Integer getState() {
|
return state;
|
}
|
|
public void setState(Integer state) {
|
this.state = state;
|
}
|
|
public String getStateName() {
|
return stateName;
|
}
|
|
public void setStateName(String stateName) {
|
this.stateName = stateName;
|
}
|
|
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;
|
}
|
}
|