ArticleAction.java
7.75 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
package com.cjs.cms.action.site;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.cjs.cms.biz.site.ArticleBiz;
import com.cjs.cms.biz.site.UploadBiz;
import com.cjs.cms.dao.site.ArticleUpdateRecordDao;
import com.cjs.cms.model.site.ArticleInfo;
import com.cjs.cms.model.site.ArticleUpdateRecordInfo;
import com.cjs.cms.model.user.UserInfo;
import com.cjs.cms.util.file.FileUtil;
import com.cjs.cms.util.lang.JsonUtil;
import com.cjs.cms.util.lang.PageUtils;
import com.cjs.cms.util.lang.StringUtil;
import com.cjs.cms.util.web.ActionUtil;
/**
* 文章操作
*
* @author tongxiaochuan
*
*/
@RestController
@RequestMapping("/character")
public class ArticleAction {
@Autowired
private ArticleBiz articleBiz;
@Autowired
private ArticleUpdateRecordDao recordDao;
@Autowired
private UploadBiz upload;
Logger log = LogManager.getLogger();
/**
* 新增文章
*
* @param params
*/
@RequestMapping("/addOrUpdateArticle")
public String addOrUpdateArticle(ArticleInfo article) {
String resultCode = "0";
// 获取当前登录人信息
UserInfo userInfo = ActionUtil.getUser();
if (StringUtils.isNotBlank(article.getTitleFile().getOriginalFilename())) {
// 图片名称
String imageName = FileUtil.QueryArticleImgPrefix()
+ FileUtil.getSuffix(article.getTitleFile().getOriginalFilename());
Map<String, String> map = upload.markFile();
// 图片上传路径
String imgTargetFile = map.get("uploadPath") + "/" + imageName;
article.setTitleImage(map.get("imageUrl") + "/" + imageName);
try {
FileUtil.transferFile(article.getTitleFile(), imgTargetFile);
} catch (IOException e) {
log.error("", e);
resultCode = "-1";
}
}
if (StringUtils.isNotBlank(article.getAttachFile().getOriginalFilename())) {
// 附件名称
String attachName = FileUtil.QueryArticleImgPrefix()
+ FileUtil.getSuffix(article.getAttachFile().getOriginalFilename());
// 附件上传路径
Map<String, String> map = upload.markFile();
String attachTargetFile = map.get("uploadPath") + attachName;
article.setAttachment(map.get("imageUrl") + attachName);
try {
FileUtil.transferFile(article.getAttachFile(), attachTargetFile);
} catch (IOException e) {
log.error("", e);
resultCode = "-2";
}
}
if (article.getTop() == null || article.getTop() == 0) {
article.setTop(null);
article.setTopSort(null);
} else {
System.out.println(article.getTop());
article.setTopSort(article.getTop());
}
if (StringUtils.isBlank(article.getSignTime())) {
article.setSignTime("2029-12-30 00:00:00");
}
// 修改
if (article.getId() != null && article.getId() != 0) {
// 删除article_enstrust关联数据
articleBiz.deleteArticle_entrust(article.getId());
// 添加修改记录
ArticleUpdateRecordInfo recordInfo = new ArticleUpdateRecordInfo();
recordInfo.setUserId(userInfo.getId());
recordInfo.setArticleId(article.getId());
String before = JsonUtil.toJson(articleBiz.searchById(article.getId()));
recordInfo.setBeforeUpdate(before);
// 修改文章
article.setUpdateBy(userInfo.getUsername());
articleBiz.updateArticle(article);
// 修改后记录
String after = JsonUtil.toJson(articleBiz.searchById(article.getId()));
recordInfo.setAfterUpdate(after);
recordDao.save(recordInfo);
// 增加
} else {
article.setCreateBy(userInfo.getUsername());
article.setUpdateBy(userInfo.getUsername());
articleBiz.addArticle(article);
}
// 添加article_enstrust关联数据
String entrustId[] = article.getEntrustId().split(",");
Map<String, Object> params = new HashMap<String, Object>();
for (String id : entrustId) {
params.put("id", article.getId());
params.put("entrustId", id);
articleBiz.addArticle_entrust(params);
}
return JsonUtil.toJson("resultCode", resultCode);
}
/**
* 删除文章
*
* @param params
*/
@RequestMapping("/deleteArticle")
public String deleteArticle(String id) {
int a = articleBiz.deleteArticle(id);
String resultCode = "0";
if (a < 0) {
resultCode = "-1";
}
return resultCode;
}
/**
* 查询文章
*
* @param params
* @return
*/
@RequestMapping("/getArticle")
public String getArticleList(@RequestParam Map<String, Object> params) {
if (StringUtil.isBlank(params.get("beginDate"))) {
params.put("beginDate", null);
}
if (StringUtil.isBlank(params.get("endDate"))) {
params.put("endDate", null);
}
PageUtils.processPage(params);
return JsonUtil.toPageJson(articleBiz.selectArticleList(params),
articleBiz.selectArticleCount(params));
}
/**
* 根据id查询文章信息
*
* @param id
* @return
*/
@RequestMapping("/getArticleInfo")
public ArticleInfo getArticleInfo(int id) {
ArticleInfo article = articleBiz.getArticleInfo(id);
String entrustId = "";
List<ArticleInfo> list = articleBiz.selectArticle_entrust(id);
if (list.size() > 0) {
for (ArticleInfo articleInfo : list) {
entrustId += articleInfo.getEntrustId() + ",";
}
entrustId = entrustId.substring(0, entrustId.length() - 1);
article.setEntrustId(entrustId);
}
return article;
}
/**
* 获取二级下拉列表的栏目信息
*
* @param request
* @param response
* @return
*/
@RequestMapping("/getCategory")
public List<Map<String, Object>> getCategory(Integer parentId) {
return articleBiz.getCategory(parentId);
}
/**
* 查询待更新文章
*
* @param request
* @param response
* @return
*/
@RequestMapping("/getArticleById")
public ArticleInfo getArticleById(Integer id) {
ArticleInfo article = articleBiz.getArticleById(id);
return article;
}
/**
* 审核通过文章
*
* @param request
* @param response
*/
@RequestMapping("/passArticle")
public String passArticle(Integer id) {
int count = articleBiz.passArticle(id);
if (count < 0) {
return "审核失败";
}
return "审核通过";
}
/**
* 文章类别
*
* @return
*/
@RequestMapping("/searchSort")
public List<ArticleInfo> searchSort() {
return articleBiz.searchSort();
}
/**
* 下线
*
* @return
*/
@RequestMapping("/downLine")
public String downLine(Integer id) {
articleBiz.downLine(id);
return JsonUtil.toJson("resultCode", "0");
}
}