|
@@ -0,0 +1,226 @@
|
|
1
|
+package com.yunzhi.shigongli.controller;
|
|
2
|
+
|
|
3
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
4
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
5
|
+import com.yunzhi.shigongli.common.BaseController;
|
|
6
|
+import com.yunzhi.shigongli.common.Constants;
|
|
7
|
+import com.yunzhi.shigongli.common.ResponseBean;
|
|
8
|
+import com.yunzhi.shigongli.entity.TaImage;
|
|
9
|
+import com.yunzhi.shigongli.entity.TaNote;
|
|
10
|
+import com.yunzhi.shigongli.entity.TaNoteResource;
|
|
11
|
+import com.yunzhi.shigongli.service.ITaImageService;
|
|
12
|
+import com.yunzhi.shigongli.service.ITaNoteResourceService;
|
|
13
|
+import com.yunzhi.shigongli.service.ITaNoteService;
|
|
14
|
+import com.yunzhi.shigongli.vo.NoteVO;
|
|
15
|
+import io.swagger.annotations.Api;
|
|
16
|
+import io.swagger.annotations.ApiOperation;
|
|
17
|
+import io.swagger.annotations.ApiParam;
|
|
18
|
+import org.slf4j.Logger;
|
|
19
|
+import org.slf4j.LoggerFactory;
|
|
20
|
+import org.springframework.beans.BeanUtils;
|
|
21
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
22
|
+import org.springframework.web.bind.annotation.*;
|
|
23
|
+
|
|
24
|
+import java.time.LocalDateTime;
|
|
25
|
+import java.util.List;
|
|
26
|
+
|
|
27
|
+/**
|
|
28
|
+ * <p>
|
|
29
|
+ * 笔记 前端控制器
|
|
30
|
+ * </p>
|
|
31
|
+ *
|
|
32
|
+ * @author yansen
|
|
33
|
+ * @since 2021-08-17
|
|
34
|
+ */
|
|
35
|
+
|
|
36
|
+@Api(tags = "笔记")
|
|
37
|
+@RestController
|
|
38
|
+@RequestMapping("/")
|
|
39
|
+public class TaNoteController extends BaseController {
|
|
40
|
+
|
|
41
|
+ private final Logger logger = LoggerFactory.getLogger(TaNoteController.class);
|
|
42
|
+
|
|
43
|
+ @Autowired
|
|
44
|
+ public ITaNoteService iTaNoteService;
|
|
45
|
+
|
|
46
|
+ @Autowired
|
|
47
|
+ public ITaImageService iTaImageService;
|
|
48
|
+
|
|
49
|
+ @Autowired
|
|
50
|
+ public ITaNoteResourceService iTaNoteResourceService;
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+ /**
|
|
54
|
+ * 分页查询列表
|
|
55
|
+ * @param pageNum
|
|
56
|
+ * @param pageSize
|
|
57
|
+ * @return
|
|
58
|
+ */
|
|
59
|
+ @RequestMapping(value="/admin/note",method= RequestMethod.GET)
|
|
60
|
+ @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = TaNote.class)
|
|
61
|
+ public ResponseBean taPvList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
|
|
62
|
+ @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
|
|
63
|
+ @ApiParam("笔记类型") @RequestParam(value ="noteType", required = false) String noteType,
|
|
64
|
+ @ApiParam("简介") @RequestParam(value ="summary", required = false) String summary) throws Exception{
|
|
65
|
+
|
|
66
|
+ IPage<TaNote> pg = new Page<>(pageNum, pageSize);
|
|
67
|
+
|
|
68
|
+ IPage<TaNote> result = iTaNoteService.getPageBy(pg, noteType, summary);
|
|
69
|
+ return ResponseBean.success(result);
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ /**
|
|
73
|
+ * 保存对象
|
|
74
|
+ * @param noteVO 实体对象
|
|
75
|
+ * @return
|
|
76
|
+ */
|
|
77
|
+ @RequestMapping(value="/admin/note",method= RequestMethod.POST)
|
|
78
|
+ @ApiOperation(value="保存笔记", notes = "保存笔记", httpMethod = "POST", response = TaNote.class)
|
|
79
|
+ public ResponseBean taPvAdd(@ApiParam("保存内容") @RequestBody NoteVO noteVO) throws Exception{
|
|
80
|
+ if (null == noteVO) {
|
|
81
|
+ return ResponseBean.error("没有找到保存内容", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ if (null == noteVO.getNoteType()) {
|
|
85
|
+ return ResponseBean.error("请设置笔记类型", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ // banner 图集
|
|
89
|
+ List<TaImage> imageList = noteVO.getImageList();
|
|
90
|
+ if ((null == imageList || imageList.size() == 0) && Constants.NOTE_TYPE_IMAGE.equals(noteVO.getNoteType())) {
|
|
91
|
+ return ResponseBean.error("请上传 banner 图片", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ // 关联地点
|
|
95
|
+ List<TaNoteResource> resourceList = noteVO.getResourceList();
|
|
96
|
+ if (null == resourceList || resourceList.size() == 0) {
|
|
97
|
+ // 暂时不处理
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ LocalDateTime now = LocalDateTime.now();
|
|
101
|
+ noteVO.setCreateDate(now);
|
|
102
|
+ if (null == noteVO.getStatus()) {
|
|
103
|
+ noteVO.setStatus(Constants.STATUS_NORMAL);
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ TaNote taNote = new TaNote();
|
|
107
|
+ BeanUtils.copyProperties(noteVO, taNote);
|
|
108
|
+
|
|
109
|
+ if (iTaNoteService.save(taNote)) {
|
|
110
|
+ noteVO.setNoteId(taNote.getNoteId());
|
|
111
|
+
|
|
112
|
+ // banner 图集
|
|
113
|
+ if (Constants.NOTE_TYPE_IMAGE.equals(noteVO.getNoteType())) {
|
|
114
|
+ for (TaImage image : imageList) {
|
|
115
|
+ image.setCreateDate(now);
|
|
116
|
+ image.setImageType("banner");
|
|
117
|
+ }
|
|
118
|
+ iTaImageService.updateImages(Constants.TARGET_NOTE, taNote.getNoteId(), imageList);
|
|
119
|
+ }
|
|
120
|
+
|
|
121
|
+ // 关联地点
|
|
122
|
+ if (null != resourceList && resourceList.size() > 0) {
|
|
123
|
+ iTaNoteResourceService.updateResource(taNote.getNoteId(), resourceList);
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ return ResponseBean.success(noteVO);
|
|
127
|
+ } else {
|
|
128
|
+ return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
129
|
+ }
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+ /**
|
|
133
|
+ * 根据id删除对象
|
|
134
|
+ * @param id 实体ID
|
|
135
|
+ */
|
|
136
|
+ @RequestMapping(value="/admin/note", method= RequestMethod.DELETE)
|
|
137
|
+ @ApiOperation(value="删除笔记", notes = "删除笔记", httpMethod = "DELETE", response = ResponseBean.class)
|
|
138
|
+ public ResponseBean taPvDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
|
|
139
|
+ if(iTaNoteService.removeLogicById(id)){
|
|
140
|
+ return ResponseBean.success("success");
|
|
141
|
+ }else {
|
|
142
|
+ return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
143
|
+ }
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ /**
|
|
147
|
+ * 修改对象
|
|
148
|
+ * @param id 实体ID
|
|
149
|
+ * @param noteVO 实体对象
|
|
150
|
+ * @return
|
|
151
|
+ */
|
|
152
|
+ @RequestMapping(value="/taPv/{id}",method= RequestMethod.PUT)
|
|
153
|
+ @ApiOperation(value="更新笔记", notes = "更新笔记", httpMethod = "PUT", response = ResponseBean.class)
|
|
154
|
+ public ResponseBean taPvUpdate(@ApiParam("对象ID") @PathVariable String id,
|
|
155
|
+ @ApiParam("更新内容") @RequestBody NoteVO noteVO) throws Exception {
|
|
156
|
+
|
|
157
|
+ TaNote taNote = iTaNoteService.getById(id);
|
|
158
|
+ if (null == taNote || Constants.STATUS_DELETED == taNote.getStatus()) {
|
|
159
|
+ return ResponseBean.error("没有找到更新内容", ResponseBean.ERROR_UNAVAILABLE);
|
|
160
|
+ }
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+ if (null == noteVO.getNoteType()) {
|
|
164
|
+ return ResponseBean.error("请设置笔记类型", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
165
|
+ }
|
|
166
|
+
|
|
167
|
+ // banner 图集
|
|
168
|
+ List<TaImage> imageList = noteVO.getImageList();
|
|
169
|
+ if ((null == imageList || imageList.size() == 0) && Constants.NOTE_TYPE_IMAGE.equals(noteVO.getNoteType())) {
|
|
170
|
+ return ResponseBean.error("请上传 banner 图片", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
171
|
+ }
|
|
172
|
+
|
|
173
|
+ // 关联地点
|
|
174
|
+ List<TaNoteResource> resourceList = noteVO.getResourceList();
|
|
175
|
+ if (null == resourceList || resourceList.size() == 0) {
|
|
176
|
+ // 暂时不处理
|
|
177
|
+ }
|
|
178
|
+
|
|
179
|
+ LocalDateTime now = LocalDateTime.now();
|
|
180
|
+ BeanUtils.copyProperties(noteVO, taNote);
|
|
181
|
+ taNote.setNoteId(id);
|
|
182
|
+
|
|
183
|
+ if (iTaNoteService.updateById(taNote)) {
|
|
184
|
+
|
|
185
|
+ // banner 图集
|
|
186
|
+ if (Constants.NOTE_TYPE_IMAGE.equals(noteVO.getNoteType())) {
|
|
187
|
+ for (TaImage image : imageList) {
|
|
188
|
+ image.setCreateDate(now);
|
|
189
|
+ image.setImageType("banner");
|
|
190
|
+ }
|
|
191
|
+ iTaImageService.updateImages(Constants.TARGET_NOTE, taNote.getNoteId(), imageList);
|
|
192
|
+ }
|
|
193
|
+
|
|
194
|
+ // 关联地点
|
|
195
|
+ if (null != resourceList && resourceList.size() > 0) {
|
|
196
|
+ iTaNoteResourceService.updateResource(taNote.getNoteId(), resourceList);
|
|
197
|
+ }
|
|
198
|
+
|
|
199
|
+ return ResponseBean.success(noteVO);
|
|
200
|
+ } else {
|
|
201
|
+ return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
202
|
+ }
|
|
203
|
+ }
|
|
204
|
+
|
|
205
|
+ /**
|
|
206
|
+ * 根据id查询对象
|
|
207
|
+ * @param id 实体ID
|
|
208
|
+ */
|
|
209
|
+ @RequestMapping(value="/admin/note/{id}",method= RequestMethod.GET)
|
|
210
|
+ @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
|
|
211
|
+ public ResponseBean taPvGet(@ApiParam("对象ID") @PathVariable String id) throws Exception {
|
|
212
|
+ TaNote taNote = iTaNoteService.getById(id);
|
|
213
|
+ if (null == taNote || Constants.STATUS_DELETED == taNote.getStatus()) {
|
|
214
|
+ return ResponseBean.error("没有找到更新内容", ResponseBean.ERROR_UNAVAILABLE);
|
|
215
|
+ }
|
|
216
|
+
|
|
217
|
+ NoteVO noteVO = new NoteVO();
|
|
218
|
+ BeanUtils.copyProperties(taNote, noteVO);
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+ noteVO.setImageList(iTaImageService.getListBy(Constants.TARGET_NOTE, id));
|
|
222
|
+ noteVO.setResourceList(iTaNoteResourceService.getListBy(id));
|
|
223
|
+
|
|
224
|
+ return ResponseBean.success(noteVO);
|
|
225
|
+ }
|
|
226
|
+}
|