RenderController.java 7.4 KB
Newer Older
Y
yadong.zhang 已提交
1 2 3 4 5 6 7
package com.zyd.blog.controller;

/**
 * 页面渲染相关 -- 页面跳转
 *
 * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
 * @version 1.0
8
 * @website https://docs.zhyd.me
Y
yadong.zhang 已提交
9 10 11
 * @date 2018/4/24 14:37
 * @since 1.0
 */
12

Y
yadong.zhang 已提交
13
import com.zyd.blog.business.annotation.BussinessLog;
Y
yadong.zhang 已提交
14
import com.zyd.blog.business.entity.Article;
智布道's avatar
智布道 已提交
15 16
import com.zyd.blog.business.enums.AdPositionEnum;
import com.zyd.blog.business.enums.AdTypeEnum;
Y
yadong.zhang 已提交
17
import com.zyd.blog.business.service.BizArticleService;
18
import com.zyd.blog.core.BlogHunterConfigProvider;
19
import com.zyd.blog.core.websocket.server.ZydWebsocketServer;
20
import com.zyd.blog.framework.exception.ZhydException;
Y
yadong.zhang 已提交
21
import com.zyd.blog.util.ResultUtil;
22 23
import me.zhyd.hunter.config.platform.Platform;
import me.zhyd.hunter.enums.ExitWayEnum;
24 25 26
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
27
import org.apache.shiro.authz.annotation.RequiresUser;
Y
yadong.zhang 已提交
28
import org.springframework.beans.factory.annotation.Autowired;
Y
yadong.zhang 已提交
29 30 31 32 33 34
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;

35 36
import java.util.Arrays;

Y
yadong.zhang 已提交
37 38 39 40 41
/**
 * 页面跳转类
 *
 * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
 * @version 1.0
42
 * @website https://docs.zhyd.me
Y
yadong.zhang 已提交
43 44 45 46 47 48
 * @date 2018/4/24 14:37
 * @since 1.0
 */
@Controller
public class RenderController {

Y
yadong.zhang 已提交
49 50
    @Autowired
    private BizArticleService articleService;
51 52
    @Autowired
    private ZydWebsocketServer websocketServer;
53 54
    @Autowired
    private BlogHunterConfigProvider blogHunterConfigProvider;
Y
yadong.zhang 已提交
55

56
    @RequiresAuthentication
Y
yadong.zhang 已提交
57
    @BussinessLog("进入首页")
Y
yadong.zhang 已提交
58
    @GetMapping(value = {""})
Y
yadong.zhang 已提交
59 60 61 62
    public ModelAndView home() {
        return ResultUtil.view("index");
    }

63
    @RequiresPermissions("users")
Y
yadong.zhang 已提交
64 65 66 67 68 69
    @BussinessLog("进入用户列表页")
    @GetMapping("/users")
    public ModelAndView user() {
        return ResultUtil.view("user/list");
    }

70
    @RequiresPermissions("resources")
Y
yadong.zhang 已提交
71 72 73 74 75 76
    @BussinessLog("进入资源列表页")
    @GetMapping("/resources")
    public ModelAndView resources() {
        return ResultUtil.view("resources/list");
    }

77
    @RequiresPermissions("roles")
Y
yadong.zhang 已提交
78 79 80 81 82 83
    @BussinessLog("进入角色列表页")
    @GetMapping("/roles")
    public ModelAndView roles() {
        return ResultUtil.view("role/list");
    }

84
    @RequiresPermissions("articles")
Y
yadong.zhang 已提交
85 86 87 88 89 90
    @BussinessLog("进入文章列表页")
    @GetMapping("/articles")
    public ModelAndView articles() {
        return ResultUtil.view("article/list");
    }

91
    @RequiresPermissions("article:publish")
92 93 94 95 96 97 98
    @BussinessLog(value = "进入发表文章页[{1}]")
    @GetMapping("/article/publish-{type}")
    public ModelAndView publish(@PathVariable("type") String type) {
        if (!Arrays.asList("we", "md", "tiny").contains(type)) {
            throw new ZhydException("不支持的编辑器类型");
        }
        return ResultUtil.view("article/publish-" + type);
Y
yadong.zhang 已提交
99 100 101
    }

    @RequiresPermissions("article:publish")
智布道's avatar
智布道 已提交
102
    @BussinessLog(value = "进入修改文章页[id={1}]")
Y
yadong.zhang 已提交
103 104 105
    @GetMapping("/article/update/{id}")
    public ModelAndView edit(@PathVariable("id") Long id, Model model) {
        model.addAttribute("id", id);
Y
yadong.zhang 已提交
106
        Article article = articleService.getByPrimaryKey(id);
107 108 109

        if (!Arrays.asList("we", "md", "tiny").contains(article.getEditorType())) {
            throw new ZhydException("文章异常,未知的编辑器类型");
Y
yadong.zhang 已提交
110
        }
111
        return ResultUtil.view("article/publish-" + article.getEditorType());
Y
yadong.zhang 已提交
112 113
    }

114
    @RequiresPermissions("types")
Y
yadong.zhang 已提交
115 116 117 118 119 120
    @BussinessLog("进入分类列表页")
    @GetMapping("/article/types")
    public ModelAndView types() {
        return ResultUtil.view("article/types");
    }

121
    @RequiresPermissions("tags")
Y
yadong.zhang 已提交
122 123 124 125 126 127
    @BussinessLog("进入标签列表页")
    @GetMapping("/article/tags")
    public ModelAndView tags() {
        return ResultUtil.view("article/tags");
    }

128
    @RequiresPermissions("links")
Y
yadong.zhang 已提交
129 130 131 132 133 134
    @BussinessLog("进入链接页")
    @GetMapping("/links")
    public ModelAndView links() {
        return ResultUtil.view("link/list");
    }

135
    @RequiresPermissions("comments")
Y
yadong.zhang 已提交
136 137 138 139 140 141
    @BussinessLog("进入评论页")
    @GetMapping("/comments")
    public ModelAndView comments() {
        return ResultUtil.view("comment/list");
    }

142
    @RequiresPermissions("notices")
Y
yadong.zhang 已提交
143 144 145 146 147 148
    @BussinessLog("进入系统通知页")
    @GetMapping("/notices")
    public ModelAndView notices() {
        return ResultUtil.view("notice/list");
    }

149
    @RequiresRoles("role:root")
Y
yadong.zhang 已提交
150 151 152 153 154 155
    @BussinessLog("进入系统配置页")
    @GetMapping("/config")
    public ModelAndView config() {
        return ResultUtil.view("config");
    }

156
    @RequiresPermissions("templates")
Y
yadong.zhang 已提交
157 158 159 160 161 162
    @BussinessLog("进入模板管理页")
    @GetMapping("/templates")
    public ModelAndView templates() {
        return ResultUtil.view("template/list");
    }

163
    @RequiresPermissions("updateLogs")
Y
yadong.zhang 已提交
164 165 166 167 168 169
    @BussinessLog("进入更新记录管理页")
    @GetMapping("/updates")
    public ModelAndView updates() {
        return ResultUtil.view("update/list");
    }

170
    @RequiresPermissions("icons")
智布道's avatar
智布道 已提交
171
    @BussinessLog(value = "进入icons页")
Y
yadong.zhang 已提交
172 173
    @GetMapping("/icons")
    public ModelAndView icons(Model model) {
174
        return ResultUtil.view("other/icons");
Y
yadong.zhang 已提交
175 176
    }

177
    @RequiresPermissions("shiro")
智布道's avatar
智布道 已提交
178
    @BussinessLog(value = "进入shiro示例页")
Y
yadong.zhang 已提交
179 180
    @GetMapping("/shiro")
    public ModelAndView shiro(Model model) {
181 182 183 184 185 186 187 188
        return ResultUtil.view("other/shiro");
    }

    @RequiresUser
    @BussinessLog("进入编辑器测试用例页面")
    @GetMapping("/editor")
    public ModelAndView editor(Model model) {
        return ResultUtil.view("other/editor");
Y
yadong.zhang 已提交
189
    }
190 191

    @RequiresPermissions("notice")
192
    @BussinessLog("进入通知管理页")
193 194 195
    @GetMapping("/notice")
    public ModelAndView notice(Model model) {
        model.addAttribute("online", websocketServer.getOnlineUserCount());
196
        return ResultUtil.view("laboratory/notification");
197
    }
198 199 200 201 202

    @RequiresUser
    @BussinessLog("进入搬运工页面")
    @GetMapping("/remover")
    public ModelAndView remover(Model model) {
智布道's avatar
智布道 已提交
203
        model.addAttribute("exitWayList", ExitWayEnum.values());
204
        model.addAttribute("spiderConfig", blogHunterConfigProvider.getBlogHunterConfig());
205
        model.addAttribute("platforms", Platform.values());
206
        return ResultUtil.view("laboratory/remover");
207
    }
208 209 210 211 212 213 214

    @RequiresPermissions("files")
    @BussinessLog("进入文件管理页面")
    @GetMapping("/files")
    public ModelAndView files(Model model) {
        return ResultUtil.view("file/list");
    }
215 216 217 218 219 220 221

    @RequiresPermissions("socials")
    @BussinessLog("进入社会化登录配置管理页面")
    @GetMapping("/socials")
    public ModelAndView socials(Model model) {
        return ResultUtil.view("social/list");
    }
222 223 224 225 226 227 228

    @RequiresPermissions("page")
    @BussinessLog("进入配置自定义页面")
    @GetMapping("/page")
    public ModelAndView page(Model model) {
        return ResultUtil.view("page/page");
    }
智布道's avatar
智布道 已提交
229 230 231 232 233 234 235 236 237 238

    @RequiresPermissions("bizAds")
    @BussinessLog("进入广告页面")
    @GetMapping("/bizAd")
    public ModelAndView bizAd(Model model) {
        model.addAttribute("positions", AdPositionEnum.toListMap());
        model.addAttribute("types", AdTypeEnum.toListMap());
        return ResultUtil.view("bizAd/bizAd");
    }

Y
yadong.zhang 已提交
239
}