LinksResource.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package com.jkcredit.sysnews.resource.web.links;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.jkcredit.sysnews.model.dto.links.LinksDto;
  5. import com.jkcredit.sysnews.model.vo.links.LinksVo;
  6. import com.jkcredit.sysnews.resource.base.BaseResource;
  7. import com.jkcredit.sysnews.resource.base.WebResource;
  8. import com.jkcredit.sysnews.resource.web.links.fb.LinksAddFB;
  9. import com.jkcredit.sysnews.resource.web.links.fb.LinksEditFB;
  10. import com.jkcredit.sysnews.resource.web.links.fb.LinksQueryFB;
  11. import com.jkcredit.sysnews.service.links.LinksService;
  12. import com.jkcredit.sysnews.spi.lang.exception.ServiceException;
  13. import com.jkcredit.sysnews.spi.web.data.ResponseData;
  14. import io.swagger.annotations.ApiOperation;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.security.access.prepost.PreAuthorize;
  18. import org.springframework.web.bind.annotation.*;
  19. /**
  20. * @description:
  21. * @author: xusonglin
  22. * @create: 2020/3/11 16:30
  23. * @version: V1.0
  24. **/
  25. @Slf4j
  26. @RestController
  27. public class LinksResource extends WebResource {
  28. @Autowired
  29. LinksService linksService;
  30. @PostMapping("/link")
  31. @PreAuthorize("hasPermission('link','edit')")
  32. @ApiOperation(value = "新增友情链接")
  33. public ResponseData saveLinks(LinksAddFB linksAddFB) {
  34. try {
  35. validate(linksAddFB);
  36. LinksDto linksDto = mapper.map(linksAddFB, LinksDto.class);
  37. linksService.saveLinks(linksDto);
  38. return ResponseData.success("新增友情链接成功");
  39. } catch (ServiceException e) {
  40. log.error(e.getMessage());
  41. return ResponseData.failed("新增友情链接失败, 失败原因:" + e.getMessage());
  42. }
  43. }
  44. @PutMapping("/link/{id}")
  45. @PreAuthorize("hasPermission('link','edit')")
  46. @ApiOperation(value = "删除友情链接")
  47. public ResponseData deleteLinks(@PathVariable Long id) {
  48. try {
  49. linksService.deleteLinks(id);
  50. return ResponseData.success("删除友情链接成功");
  51. } catch (ServiceException e) {
  52. log.error(e.getMessage());
  53. return ResponseData.failed("删除友情链接失败, 失败原因:" + e.getMessage());
  54. }
  55. }
  56. @PutMapping("/link")
  57. @PreAuthorize("hasPermission('link','edit')")
  58. @ApiOperation(value = "修改友情链接")
  59. public ResponseData editLinks(LinksEditFB linksEditFB) {
  60. try {
  61. validate(linksEditFB);
  62. LinksDto linksDto = mapper.map(linksEditFB, LinksDto.class);
  63. linksService.editLinks(linksDto);
  64. return ResponseData.success("修改友情链接成功");
  65. } catch (ServiceException e) {
  66. log.error(e.getMessage());
  67. return ResponseData.failed("修改友情链接失败, 失败原因:" + e.getMessage());
  68. }
  69. }
  70. @GetMapping("/page/links")
  71. @PreAuthorize("hasPermission('link','read')")
  72. @ApiOperation(value = "分页查询友情链接")
  73. public ResponseData getLinks(Page page, LinksQueryFB linksQueryFB) {
  74. try {
  75. LinksDto linksDto = mapper.map(linksQueryFB, LinksDto.class);
  76. IPage<LinksVo> linksVoIPage = linksService.getLinksPage(page, linksDto);
  77. return ResponseData.success(linksVoIPage);
  78. } catch (ServiceException e) {
  79. log.error(e.getMessage());
  80. return ResponseData.failed("分页查询友情链接失败, 失败原因:" + e.getMessage());
  81. }
  82. }
  83. @GetMapping("/link/{id}")
  84. @PreAuthorize("hasPermission('link','read')")
  85. @ApiOperation(value = "根据id获取友情链接详情")
  86. public ResponseData getLink(@PathVariable Long id) {
  87. try {
  88. LinksVo linksVo = linksService.getLinkById(id);
  89. return ResponseData.success(linksVo);
  90. } catch (ServiceException e) {
  91. log.error(e.getMessage());
  92. return ResponseData.failed("查询友情链接失败, 失败原因:" + e.getMessage());
  93. }
  94. }
  95. }