peng
2025-11-07 858f515995fd1dca7cf825069ce38c32703298d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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;
    }
}