package cn.stylefeng.guns.zjxl.cnotroller; import cn.stylefeng.guns.zjxl.model.ZjxlArticleContent; import cn.stylefeng.guns.zjxl.service.ZjxlArticleContentService; import cn.stylefeng.guns.zjxlUtil.BaseController; import cn.stylefeng.guns.zjxlUtil.PageUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; /*** * @ClassName: ZjxlArticleContentController * @Description:文章内容管理 * @Auther: shi kejing * @Date: 2020/11/3 17:40 */ @RestController @Api(description = "文章内容管理") @RequestMapping(value = "/zjxl/zjxlArticleContent") public class ZjxlArticleContentController extends BaseController { private Logger logger = (Logger) LoggerFactory.getLogger(ZjxlArticleContentController.class); @Autowired private ZjxlArticleContentService articleContentService; @RequestMapping(value = "/findArticleContentById", method = RequestMethod.GET) @ApiOperation(value = "查询文章管理列表") public String findArticleContentById(@ApiParam(name = "id", value = "文章id", required = false) @RequestParam(value = "id", required = false)String id, @ApiParam(name = "articleContentTitle", value = "文章标题", required = false) @RequestParam(value = "articleContentTitle", required = false)String articleContentTitle, @ApiParam(name = "systemDictType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们", required = false) @RequestParam(value = "systemDictType", required = false)Integer systemDictType, @ApiParam(name = "pageNo", value = "第几页", defaultValue = "1") @RequestParam(value = "pageNo", required = false) Integer pageNo, @ApiParam(name = "pageSize", value = "分页大小", defaultValue = "10") @RequestParam(value = "pageSize", required = false) Integer pageSize){ try { List articleContentList = articleContentService.findArticleContentById(id,articleContentTitle,systemDictType,pageNo-1,pageSize); return write(200,"查询成功","data", PageUtil.getPage(articleContentList,pageNo,pageSize,articleContentService.allCount())); }catch (Exception e){ e.printStackTrace(); return write(-1,"查询失败"); } } @RequestMapping(value = "/addArticleContent", method = RequestMethod.POST) @ApiOperation(value = "添加文章") public String addArticleContent( @ApiParam(name = "articleContentTitle", value = "文章标题", required = false) @RequestParam(value = "articleContentTitle", required = false)String articleContentTitle, @ApiParam(name = "articleContentCover", value = "封面", required = false) @RequestParam(value = "articleContentCover", required = false)String articleContentCover, @ApiParam(name = "articleContentAbstract", value = "摘要", required = false) @RequestParam(value = "articleContentAbstract", required = false) String articleContentAbstract, @ApiParam(name = "articleContentContent", value = "内容", required = false) @RequestParam(value = "articleContentContent", required = false) String articleContentContent, @ApiParam(name = "articleContentType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们", required = false) @RequestParam(value = "articleContentType", required = false)Integer articleContentType, @ApiParam(name = "articleContentClassify", value = "分类", required = false) @RequestParam(value = "articleContentClassify", required = false)String articleContentClassify, @ApiParam(name = "articleContentSubclassify", value = "子分类", required = false) @RequestParam(value = "articleContentSubclassify", required = false)String articleContentSubclassify, @ApiParam(name = "articleContentSort", value = "排序", required = false) @RequestParam(value = "articleContentSort", required = false)Integer articleContentSort, @ApiParam(name = "articleContentIsLine", value = "是否上线", required = false, defaultValue = "0") @RequestParam(value = "articleContentIsLine", required = false)Integer articleContentIsLine){ try { ZjxlArticleContent articleContent = new ZjxlArticleContent(); articleContent.setArticleContentTitle(articleContentTitle); articleContent.setArticleContentCover(articleContentCover); articleContent.setArticleContentAbstract(articleContentAbstract); articleContent.setArticleContentType(articleContentType); articleContent.setArticleContentClassify(articleContentClassify); articleContent.setArticleContentSubclassify(articleContentSubclassify); articleContent.setArticleContentSort(articleContentSort); articleContent.setArticleContentIsLine(articleContentIsLine); articleContent.setArticleContentContent(articleContentContent); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 articleContent.setArticleContentCreateTime(df.format(new Date()));// new Date()为获取当前系统时间 return write(200,"添加成功","data",articleContentService.addArticleContent(articleContent)); }catch (Exception e){ e.printStackTrace(); return write(-1,"添加失败"); } } @RequestMapping(value = "/deleteArticleContent", method = RequestMethod.POST) @ApiOperation(value = "删除文章管理") public String deleteArticleContent(@ApiParam(name = "id", value = "文章id") @RequestParam(value = "id") String id){ try { if (id == null){ logger.info("修改是否上线:id====="+id); return write(-1,"获取参数失败"); } logger.info("修改是否上线:id====="+id); return write(200,"删除成功","data",articleContentService.deleteArticleContent(id)); }catch (Exception e){ e.printStackTrace(); return write(-1,"删除失败"); } } @RequestMapping(value = "/updateArticleContent", method = RequestMethod.POST) @ApiOperation(value = "修改是否上线") public String updateArticleContent(@ApiParam(name = "id", value = "文章id") @RequestParam(value = "id") String id, @ApiParam(name = "isLine", value = "是否上线") @RequestParam(value = "isLine") Integer isLine){ try { if (id == null || isLine == null){ logger.info("修改是否上线:id====="+id+",isLine===="+isLine); return write(-1,"获取参数失败"); } logger.info("修改是否上线:id====="+id+",isLine===="+isLine); return write(200,"修改上线成功","data",articleContentService.updateArticleContent(id,isLine)); }catch (Exception e){ e.printStackTrace(); return write(-1,"修改上线失败"); } } @RequestMapping(value = "/getLeftTabs", method = RequestMethod.GET) @ApiOperation(value = "根据每个内容类型获取对应的分类") public String getLeftTabs(@ApiParam(name = "articleContentType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们") @RequestParam(value = "articleContentType") String articleContentType){ try { if (StringUtils.isEmpty(articleContentType)){ logger.info("内容类型:articleContentType====="+articleContentType); return write(-1,"获取参数失败"); } logger.info("内容类型:articleContentType====="+articleContentType); return write(200,"操作成功","data",articleContentService.getLeftTabs(articleContentType)); }catch (Exception e){ e.printStackTrace(); return write(-1,"操作失败"); } } @RequestMapping(value = "/getArticleContentSubclassify", method = RequestMethod.GET) @ApiOperation(value = "根据每个分类获取对应的子分类") public String getArticleContentSubclassify(@ApiParam(name = "articleContentType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们") @RequestParam(value = "articleContentType") String articleContentType, @ApiParam(name = "articleContentClassify", value = "分类") @RequestParam(value = "articleContentClassify") String articleContentClassify){ try { if (StringUtils.isEmpty(articleContentType) || StringUtils.isEmpty(articleContentClassify)){ logger.info("内容类型:articleContentType====="+articleContentType); logger.info("分类:articleContentClassify====="+articleContentClassify); return write(-1,"获取参数失败"); } logger.info("内容类型:articleContentType====="+articleContentType); logger.info("分类:articleContentClassify====="+articleContentClassify); return write(200,"操作成功","data",articleContentService.getArticleContentSubclassify(articleContentType,articleContentClassify)); }catch (Exception e){ e.printStackTrace(); return write(-1,"操作失败"); } } @RequestMapping(value = "/getArticleContent", method = RequestMethod.GET) @ApiOperation(value = "根据子分类获取对应的文章(排序最高的文章)") public String getArticleContent(@ApiParam(name = "articleContentType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们") @RequestParam(value = "articleContentType") String articleContentType, @ApiParam(name = "articleContentClassify", value = "分类") @RequestParam(value = "articleContentClassify") String articleContentClassify, @ApiParam(name = "articleContentSubclassify", value = "子分类") @RequestParam(value = "articleContentSubclassify") String articleContentSubclassify){ try { if (StringUtils.isEmpty(articleContentType) || StringUtils.isEmpty(articleContentClassify) || StringUtils.isEmpty(articleContentSubclassify)){ logger.info("内容类型:articleContentType====="+articleContentType); logger.info("分类:articleContentClassify====="+articleContentClassify); logger.info("子分类:articleContentSubclassify====="+articleContentSubclassify); return write(-1,"获取参数失败"); } logger.info("内容类型:articleContentType====="+articleContentType); logger.info("分类:articleContentClassify====="+articleContentClassify); logger.info("子分类:articleContentSubclassify====="+articleContentSubclassify); return write(200,"操作成功","data",articleContentService.getArticleContent(articleContentType,articleContentClassify,articleContentSubclassify)); }catch (Exception e){ e.printStackTrace(); return write(-1,"操作失败"); } } @RequestMapping(value = "/findNewsList", method = RequestMethod.GET) @ApiOperation(value = "查询新闻中心列表") public String findNewsList(@ApiParam(name = "id", value = "文章id", required = false) @RequestParam(value = "id", required = false)String id, // @ApiParam(name = "articleContentTitle", value = "文章标题", required = false) @RequestParam(value = "articleContentTitle", required = false)String articleContentTitle, // @ApiParam(name = "systemDictType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们", required = false, defaultValue = "3") @RequestParam(value = "systemDictType", required = false)Integer systemDictType, @ApiParam(name = "articleContentClassify", value = "分类: 公司动态 媒体报道 参观交流", defaultValue = "公司动态") @RequestParam(value = "articleContentClassify") String articleContentClassify, @ApiParam(name = "pageNo", value = "第几页", defaultValue = "1") @RequestParam(value = "pageNo", required = false) Integer pageNo, @ApiParam(name = "pageSize", value = "分页大小", defaultValue = "10") @RequestParam(value = "pageSize", required = false) Integer pageSize){ try { List articleContentList = articleContentService.findNewsList(id,articleContentClassify,3,pageNo-1,pageSize); return write(200,"查询成功","data", PageUtil.getPage(articleContentList,pageNo,pageSize,articleContentService.allNewsCount(articleContentClassify))); }catch (Exception e){ e.printStackTrace(); return write(-1,"查询失败"); } } }