123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package com.jkcredit.sysnews.resource.web.links;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.jkcredit.sysnews.model.dto.links.LinksDto;
- import com.jkcredit.sysnews.model.vo.links.LinksVo;
- import com.jkcredit.sysnews.resource.base.BaseResource;
- import com.jkcredit.sysnews.resource.base.WebResource;
- import com.jkcredit.sysnews.resource.web.links.fb.LinksAddFB;
- import com.jkcredit.sysnews.resource.web.links.fb.LinksEditFB;
- import com.jkcredit.sysnews.resource.web.links.fb.LinksQueryFB;
- import com.jkcredit.sysnews.service.links.LinksService;
- import com.jkcredit.sysnews.spi.lang.exception.ServiceException;
- import com.jkcredit.sysnews.spi.web.data.ResponseData;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.web.bind.annotation.*;
- /**
- * @description:
- * @author: xusonglin
- * @create: 2020/3/11 16:30
- * @version: V1.0
- **/
- @Slf4j
- @RestController
- public class LinksResource extends WebResource {
- @Autowired
- LinksService linksService;
- @PostMapping("/link")
- @PreAuthorize("hasPermission('link','edit')")
- @ApiOperation(value = "新增友情链接")
- public ResponseData saveLinks(LinksAddFB linksAddFB) {
- try {
- validate(linksAddFB);
- LinksDto linksDto = mapper.map(linksAddFB, LinksDto.class);
- linksService.saveLinks(linksDto);
- return ResponseData.success("新增友情链接成功");
- } catch (ServiceException e) {
- log.error(e.getMessage());
- return ResponseData.failed("新增友情链接失败, 失败原因:" + e.getMessage());
- }
- }
- @PutMapping("/link/{id}")
- @PreAuthorize("hasPermission('link','edit')")
- @ApiOperation(value = "删除友情链接")
- public ResponseData deleteLinks(@PathVariable Long id) {
- try {
- linksService.deleteLinks(id);
- return ResponseData.success("删除友情链接成功");
- } catch (ServiceException e) {
- log.error(e.getMessage());
- return ResponseData.failed("删除友情链接失败, 失败原因:" + e.getMessage());
- }
- }
- @PutMapping("/link")
- @PreAuthorize("hasPermission('link','edit')")
- @ApiOperation(value = "修改友情链接")
- public ResponseData editLinks(LinksEditFB linksEditFB) {
- try {
- validate(linksEditFB);
- LinksDto linksDto = mapper.map(linksEditFB, LinksDto.class);
- linksService.editLinks(linksDto);
- return ResponseData.success("修改友情链接成功");
- } catch (ServiceException e) {
- log.error(e.getMessage());
- return ResponseData.failed("修改友情链接失败, 失败原因:" + e.getMessage());
- }
- }
- @GetMapping("/page/links")
- @PreAuthorize("hasPermission('link','read')")
- @ApiOperation(value = "分页查询友情链接")
- public ResponseData getLinks(Page page, LinksQueryFB linksQueryFB) {
- try {
- LinksDto linksDto = mapper.map(linksQueryFB, LinksDto.class);
- IPage<LinksVo> linksVoIPage = linksService.getLinksPage(page, linksDto);
- return ResponseData.success(linksVoIPage);
- } catch (ServiceException e) {
- log.error(e.getMessage());
- return ResponseData.failed("分页查询友情链接失败, 失败原因:" + e.getMessage());
- }
- }
- @GetMapping("/link/{id}")
- @PreAuthorize("hasPermission('link','read')")
- @ApiOperation(value = "根据id获取友情链接详情")
- public ResponseData getLink(@PathVariable Long id) {
- try {
- LinksVo linksVo = linksService.getLinkById(id);
- return ResponseData.success(linksVo);
- } catch (ServiceException e) {
- log.error(e.getMessage());
- return ResponseData.failed("查询友情链接失败, 失败原因:" + e.getMessage());
- }
- }
- }
|