package com.lqkj.business.controller; import java.util.List; import com.lqkj.common.utils.StringUtils; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.lqkj.common.annotation.Log; import com.lqkj.common.core.controller.BaseController; import com.lqkj.common.core.model.ResultUtil; import com.lqkj.common.enums.BusinessType; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import com.lqkj.business.entity.CmsNews; import com.lqkj.business.service.CmsNewsService; import com.lqkj.common.utils.poi.ExcelUtil; import com.github.pagehelper.PageInfo; import org.springframework.web.util.HtmlUtils; /** * 信息管理Controller * * @author lqkj * @date 2023-02-16 */ @Api(tags = {"信息管理"}) @RestController @RequestMapping("/business/cmsNews") public class CmsNewsController extends BaseController { @Autowired private CmsNewsService cmsNewsService; /** * 查询信息管理列表 */ @ApiOperation("查询信息列表") @PreAuthorize("@ss.hasPermi('business:cmsNews:list')") @GetMapping("/list") public ResultUtil list(CmsNews cmsNews) { startPage( cmsNews); PageInfo pageInfo = new PageInfo<>(cmsNewsService.selectCmsNewsList(cmsNews)); return ResultUtil.success(pageInfo); } @ApiOperation("按分类查询列表(前端用)") @GetMapping("/front/list") public ResultUtil listByCategory(CmsNews cmsNews){ startPage( cmsNews); PageInfo pageInfo = new PageInfo<>(cmsNewsService.selectCmsNewsList(cmsNews)); return ResultUtil.success(pageInfo); } @ApiOperation("查看详情信息(前端用)") @GetMapping(value = "/front/{newsId}") public ResultUtil view(@PathVariable("newsId") String newsId) { cmsNewsService.plusViewCount(newsId); return ResultUtil.success(cmsNewsService.selectCmsNewsByNewsId(newsId)); } @ApiOperation("根据分类ID查看详情信息(前端用)") @GetMapping(value = "/front/category/{categoryId}") public ResultUtil viewByCategoryId(@PathVariable("categoryId") Long categoryId) { return ResultUtil.success(cmsNewsService.selectCmsNewsByCategoryId(categoryId)); } /** * 导出信息列表 */ @ApiOperation("导出信息列表") @PreAuthorize("@ss.hasPermi('business:cmsNews:export')") @Log(title = "信息管理", businessType = BusinessType.EXPORT) @GetMapping("/export") public ResultUtil export(CmsNews cmsNews) { List list = cmsNewsService.selectCmsNewsList(cmsNews); ExcelUtil util = new ExcelUtil(CmsNews.class); return util.exportExcel(list, "信息数据"); } /** * 获取信息详细信息 */ @ApiOperation("获取信息详细信息") @PreAuthorize("@ss.hasPermi('business:cmsNews:query')") @GetMapping(value = "/{newsId}") public ResultUtil getInfo(@PathVariable("newsId") String newsId) { return ResultUtil.success(cmsNewsService.selectCmsNewsByNewsId(newsId)); } /** * 获取信息详细信息 */ @ApiOperation("根据分类编号获取信息详细信息") @PreAuthorize("@ss.hasPermi('business:cmsNews:query')") @GetMapping(value = "/getInfoByCategoryId/{categoryId}") public ResultUtil getInfoByCategoryId(@PathVariable("categoryId") Long categoryId) { return ResultUtil.success(cmsNewsService.selectCmsNewsByCategoryId(categoryId)); } /** * 新增信息 */ @ApiOperation("新增信息") @PreAuthorize("@ss.hasPermi('business:cmsNews:add')") @Log(title = "信息管理", businessType = BusinessType.INSERT) @PostMapping public ResultUtil add(@RequestBody CmsNews cmsNews) { if(StringUtils.isNotEmpty(cmsNews.getContent())){ cmsNews.setContent(HtmlUtils.htmlUnescape(cmsNews.getContent())); } cmsNews.setCreateBy(getNickName()); return resultByRows(cmsNewsService.insertCmsNews(cmsNews)); } /** * 修改信息 */ @ApiOperation("修改信息") @PreAuthorize("@ss.hasPermi('business:cmsNews:edit')") @Log(title = "信息管理", businessType = BusinessType.UPDATE) @PutMapping public ResultUtil edit(@RequestBody CmsNews cmsNews) { if(StringUtils.isNotEmpty(cmsNews.getContent())){ cmsNews.setContent(HtmlUtils.htmlUnescape(cmsNews.getContent())); } cmsNews.setUpdateBy(getNickName()); return resultByRows(cmsNewsService.updateCmsNews(cmsNews)); } /** * 置顶操作 */ @ApiOperation("置顶状态") @PreAuthorize("@ss.hasPermi('business:cmsNews:edit')") @Log(title = "信息管理", businessType = BusinessType.UPDATE) @PutMapping("/updateTopStatus") public ResultUtil updateTopStatus(@RequestBody CmsNews cmsNews){ return resultByRows(cmsNewsService.updateTopStatus(cmsNews)); } /** * 删除信息 */ @ApiOperation("删除信息") @PreAuthorize("@ss.hasPermi('business:cmsNews:remove')") @Log(title = "信息管理", businessType = BusinessType.DELETE) @DeleteMapping("/{newsIds}") public ResultUtil remove(@PathVariable String[] newsIds) { return resultByRows(cmsNewsService.deleteCmsNewsByNewsIds(newsIds)); } }