RestLinkController.java 3.1 KB
Newer Older
Y
yadong.zhang 已提交
1 2 3
package com.zyd.blog.controller;

import com.github.pagehelper.PageInfo;
智布道's avatar
智布道 已提交
4
import com.zyd.blog.business.annotation.BussinessLog;
Y
yadong.zhang 已提交
5 6 7 8 9 10 11 12 13 14
import com.zyd.blog.business.entity.Link;
import com.zyd.blog.business.enums.LinkSourceEnum;
import com.zyd.blog.business.enums.ResponseStatus;
import com.zyd.blog.business.enums.TemplateKeyEnum;
import com.zyd.blog.business.service.MailService;
import com.zyd.blog.business.service.SysLinkService;
import com.zyd.blog.business.vo.LinkConditionVO;
import com.zyd.blog.framework.object.PageResult;
import com.zyd.blog.framework.object.ResponseVO;
import com.zyd.blog.util.ResultUtil;
15 16
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
Y
yadong.zhang 已提交
17 18 19 20 21 22 23 24 25 26 27
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 友情链接
 *
 * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
 * @version 1.0
28
 * @website https://docs.zhyd.me
Y
yadong.zhang 已提交
29 30 31 32 33 34 35 36 37 38 39
 * @date 2018/4/24 14:37
 * @since 1.0
 */
@RestController
@RequestMapping("/link")
public class RestLinkController {
    @Autowired
    private SysLinkService linkService;
    @Autowired
    private MailService mailService;

40
    @RequiresPermissions("links")
Y
yadong.zhang 已提交
41 42 43 44 45 46
    @PostMapping("/list")
    public PageResult list(LinkConditionVO vo) {
        PageInfo<Link> pageInfo = linkService.findPageBreakByCondition(vo);
        return ResultUtil.tablePage(pageInfo);
    }

47
    @RequiresPermissions("link:add")
Y
yadong.zhang 已提交
48
    @PostMapping(value = "/add")
智布道's avatar
智布道 已提交
49
    @BussinessLog("添加友情链接")
Y
yadong.zhang 已提交
50 51 52 53 54 55 56
    public ResponseVO add(Link link) {
        link.setSource(LinkSourceEnum.ADMIN);
        linkService.insert(link);
        mailService.send(link, TemplateKeyEnum.TM_LINKS);
        return ResultUtil.success("成功");
    }

57
    @RequiresPermissions(value = {"link:batchDelete", "link:delete"}, logical = Logical.OR)
Y
yadong.zhang 已提交
58
    @PostMapping(value = "/remove")
智布道's avatar
智布道 已提交
59
    @BussinessLog("删除友情链接")
Y
yadong.zhang 已提交
60 61 62 63 64 65 66 67 68 69
    public ResponseVO remove(Long[] ids) {
        if (null == ids) {
            return ResultUtil.error(500, "请至少选择一条记录");
        }
        for (Long id : ids) {
            linkService.removeByPrimaryKey(id);
        }
        return ResultUtil.success("成功删除 [" + ids.length + "] 个友情链接");
    }

Y
yadong.zhang 已提交
70
    @RequiresPermissions("link:get")
Y
yadong.zhang 已提交
71
    @PostMapping("/get/{id}")
智布道's avatar
智布道 已提交
72
    @BussinessLog("获取友情链接详情")
Y
yadong.zhang 已提交
73 74 75 76
    public ResponseVO get(@PathVariable Long id) {
        return ResultUtil.success(null, this.linkService.getByPrimaryKey(id));
    }

77
    @RequiresPermissions("link:edit")
Y
yadong.zhang 已提交
78
    @PostMapping("/edit")
智布道's avatar
智布道 已提交
79
    @BussinessLog("编辑友情链接")
Y
yadong.zhang 已提交
80 81 82 83 84 85 86 87 88 89 90
    public ResponseVO edit(Link link) {
        try {
            linkService.updateSelective(link);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("友情链接修改失败!");
        }
        return ResultUtil.success(ResponseStatus.SUCCESS);
    }

}