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 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()); } } }