ContentController.java
3.67 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
package com.bootdo.blog.controller;
import com.bootdo.blog.domain.ContentDO;
import com.bootdo.blog.service.ContentService;
import com.bootdo.common.config.Constant;
import com.bootdo.common.controller.BaseController;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 文章内容
*
* @author chglee
* @email 1992lcg@163.com
* @date 2017-09-09 10:03:34
*/
@Controller
@RequestMapping("/blog/bContent")
public class ContentController extends BaseController {
@Autowired
ContentService bContentService;
@GetMapping()
@RequiresPermissions("blog:bContent:bContent")
String bContent() {
return "blog/bContent/bContent";
}
@ResponseBody
@GetMapping("/list")
@RequiresPermissions("blog:bContent:bContent")
public PageUtils list(@RequestParam Map<String, Object> params) {
Query query = new Query(params);
List<ContentDO> bContentList = bContentService.list(query);
int total = bContentService.count(query);
PageUtils pageUtils = new PageUtils(bContentList, total);
return pageUtils;
}
@GetMapping("/add")
@RequiresPermissions("blog:bContent:add")
String add() {
return "blog/bContent/add";
}
@GetMapping("/edit/{cid}")
@RequiresPermissions("blog:bContent:edit")
String edit(@PathVariable("cid") Long cid, Model model) {
ContentDO bContentDO = bContentService.get(cid);
model.addAttribute("bContent", bContentDO);
return "blog/bContent/edit";
}
/**
* 保存
*/
@ResponseBody
@RequiresPermissions("blog:bContent:add")
@PostMapping("/save")
public R save(ContentDO bContent) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
if (bContent.getAllowComment() == null) {
bContent.setAllowComment(0);
}
if (bContent.getAllowFeed() == null) {
bContent.setAllowFeed(0);
}
if(null==bContent.getType()) {
bContent.setType("article");
}
bContent.setGtmCreate(new Date());
bContent.setGtmModified(new Date());
int count;
if (bContent.getCid() == null || "".equals(bContent.getCid())) {
count = bContentService.save(bContent);
} else {
count = bContentService.update(bContent);
}
if (count > 0) {
return R.ok().put("cid", bContent.getCid());
}
return R.error();
}
/**
* 修改
*/
@RequiresPermissions("blog:bContent:edit")
@ResponseBody
@RequestMapping("/update")
public R update( ContentDO bContent) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
bContent.setGtmCreate(new Date());
bContentService.update(bContent);
return R.ok();
}
/**
* 删除
*/
@RequiresPermissions("blog:bContent:remove")
@PostMapping("/remove")
@ResponseBody
public R remove(Long id) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
if (bContentService.remove(id) > 0) {
return R.ok();
}
return R.error();
}
/**
* 删除
*/
@RequiresPermissions("blog:bContent:batchRemove")
@PostMapping("/batchRemove")
@ResponseBody
public R remove(@RequestParam("ids[]") Long[] cids) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
bContentService.batchRemove(cids);
return R.ok();
}
}