From 81f1ca8a2362ada94fb4b10e0805093ac7d13aec Mon Sep 17 00:00:00 2001 From: kerwincui <164770707@qq.com> Date: Thu, 14 Apr 2022 20:32:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EApp=E8=B5=84=E8=AE=AF?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NewsCategoryController.java | 2 +- .../ruoyi/iot/controller/NewsController.java | 28 +++++++++++ .../ruoyi/iot/mapper/NewsCategoryMapper.java | 8 +++ .../java/com/ruoyi/iot/mapper/NewsMapper.java | 7 +++ .../com/ruoyi/iot/model/CategoryNews.java | 49 +++++++++++++++++++ .../iot/service/INewsCategoryService.java | 4 +- .../com/ruoyi/iot/service/INewsService.java | 8 +++ .../service/impl/NewsCategoryServiceImpl.java | 13 ++++- .../iot/service/impl/NewsServiceImpl.java | 35 +++++++++++++ .../mapper/iot/NewsCategoryMapper.xml | 7 +++ .../main/resources/mapper/iot/NewsMapper.xml | 13 +++-- 11 files changed, 167 insertions(+), 7 deletions(-) create mode 100644 springboot/wumei-iot/src/main/java/com/ruoyi/iot/model/CategoryNews.java diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/NewsCategoryController.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/NewsCategoryController.java index 065e2f93..8aa2e851 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/NewsCategoryController.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/NewsCategoryController.java @@ -121,6 +121,6 @@ public class NewsCategoryController extends BaseController @ApiOperation("删除新闻分类") public AjaxResult remove(@PathVariable Long[] categoryIds) { - return toAjax(newsCategoryService.deleteNewsCategoryByCategoryIds(categoryIds)); + return newsCategoryService.deleteNewsCategoryByCategoryIds(categoryIds); } } diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/NewsController.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/NewsController.java index d2cfd962..65c6c5ca 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/NewsController.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/NewsController.java @@ -3,6 +3,7 @@ package com.ruoyi.iot.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.ruoyi.iot.model.CategoryNews; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; @@ -51,6 +52,33 @@ public class NewsController extends BaseController return getDataTable(list); } + /** + * 查询轮播的新闻资讯 + */ + @PreAuthorize("@ss.hasPermi('iot:news:list')") + @GetMapping("/bannerList") + @ApiOperation("轮播新闻列表") + public AjaxResult bannerList() + { + News news=new News(); + news.setIsBanner(1); + news.setStatus(1); + List list = newsService.selectNewsList(news); + return AjaxResult.success(list); + } + + /** + * 查询置顶的新闻资讯 + */ + @PreAuthorize("@ss.hasPermi('iot:news:list')") + @GetMapping("/topList") + @ApiOperation("置顶新闻列表") + public AjaxResult topList() + { + List list = newsService.selectTopNewsList(); + return AjaxResult.success(list); + } + /** * 导出新闻资讯列表 */ diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/NewsCategoryMapper.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/NewsCategoryMapper.java index 16ca10fa..d44a595a 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/NewsCategoryMapper.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/NewsCategoryMapper.java @@ -66,4 +66,12 @@ public interface NewsCategoryMapper * @return 结果 */ public int deleteNewsCategoryByCategoryIds(Long[] categoryIds); + + /** + * 分类下的新闻数量 + * + * @param categoryIds 需要删除的数据主键集合 + * @return 结果 + */ + public int newsCountInCategorys(Long[] categoryIds); } diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/NewsMapper.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/NewsMapper.java index 824faf7a..2e0f6229 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/NewsMapper.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/NewsMapper.java @@ -27,6 +27,13 @@ public interface NewsMapper */ public List selectNewsList(News news); + /** + * 查询置顶新闻资讯列表 + * + * @return 新闻资讯集合 + */ + public List selectTopNewsList(); + /** * 新增新闻资讯 * diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/model/CategoryNews.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/model/CategoryNews.java new file mode 100644 index 00000000..a1d4111d --- /dev/null +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/model/CategoryNews.java @@ -0,0 +1,49 @@ +package com.ruoyi.iot.model; + +import com.ruoyi.iot.domain.News; + +import java.util.ArrayList; +import java.util.List; + +/** + * 产品分类的Id和名称输出 + * + * @author kerwincui + * @date 2021-12-16 + */ +public class CategoryNews +{ + private Long categoryId; + + private String categoryName; + + private List newsList; + + public CategoryNews(){ + this.newsList=new ArrayList<>(); + } + + public Long getCategoryId() { + return categoryId; + } + + public void setCategoryId(Long categoryId) { + this.categoryId = categoryId; + } + + public String getCategoryName() { + return categoryName; + } + + public void setCategoryName(String categoryName) { + this.categoryName = categoryName; + } + + public List getNewsList() { + return newsList; + } + + public void setNewsList(List newsList) { + this.newsList = newsList; + } +} diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/INewsCategoryService.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/INewsCategoryService.java index a74c6af1..c7d0cf8a 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/INewsCategoryService.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/INewsCategoryService.java @@ -1,6 +1,8 @@ package com.ruoyi.iot.service; import java.util.List; + +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.iot.domain.NewsCategory; import com.ruoyi.iot.model.IdAndName; @@ -57,7 +59,7 @@ public interface INewsCategoryService * @param categoryIds 需要删除的新闻分类主键集合 * @return 结果 */ - public int deleteNewsCategoryByCategoryIds(Long[] categoryIds); + public AjaxResult deleteNewsCategoryByCategoryIds(Long[] categoryIds); /** * 删除新闻分类信息 diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/INewsService.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/INewsService.java index 45b6f0fa..9b872c1b 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/INewsService.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/INewsService.java @@ -2,6 +2,7 @@ package com.ruoyi.iot.service; import java.util.List; import com.ruoyi.iot.domain.News; +import com.ruoyi.iot.model.CategoryNews; /** * 新闻资讯Service接口 @@ -27,6 +28,13 @@ public interface INewsService */ public List selectNewsList(News news); + /** + * 查询置顶新闻资讯列表 + * + * @return 新闻资讯集合 + */ + public List selectTopNewsList(); + /** * 新增新闻资讯 * diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/NewsCategoryServiceImpl.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/NewsCategoryServiceImpl.java index 0b281b39..66f100c0 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/NewsCategoryServiceImpl.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/NewsCategoryServiceImpl.java @@ -1,6 +1,8 @@ package com.ruoyi.iot.service.impl; import java.util.List; + +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.iot.model.IdAndName; import org.springframework.beans.factory.annotation.Autowired; @@ -89,9 +91,16 @@ public class NewsCategoryServiceImpl implements INewsCategoryService * @return 结果 */ @Override - public int deleteNewsCategoryByCategoryIds(Long[] categoryIds) + public AjaxResult deleteNewsCategoryByCategoryIds(Long[] categoryIds) { - return newsCategoryMapper.deleteNewsCategoryByCategoryIds(categoryIds); + int productCount=newsCategoryMapper.newsCountInCategorys(categoryIds); + if(productCount>0){ + return AjaxResult.error("删除失败,请先删除对应分类下的新闻资讯"); + } + if(newsCategoryMapper.deleteNewsCategoryByCategoryIds(categoryIds)>0){ + return AjaxResult.success("删除成功"); + } + return AjaxResult.error("删除失败"); } /** diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/NewsServiceImpl.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/NewsServiceImpl.java index 17fad709..28a10e1c 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/NewsServiceImpl.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/NewsServiceImpl.java @@ -1,7 +1,12 @@ package com.ruoyi.iot.service.impl; +import java.util.ArrayList; import java.util.List; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.iot.mapper.NewsCategoryMapper; +import com.ruoyi.iot.model.CategoryNews; +import com.ruoyi.iot.model.IdAndName; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.iot.mapper.NewsMapper; @@ -44,6 +49,36 @@ public class NewsServiceImpl implements INewsService return newsMapper.selectNewsList(news); } + /** + * 查询置顶新闻资讯列表 + * + * @return 新闻资讯 + */ + @Override + public List selectTopNewsList() + { + List categoryNewsList =new ArrayList<>(); + List newsList=newsMapper.selectTopNewsList(); + for(int i=0;i + + \ No newline at end of file diff --git a/springboot/wumei-iot/src/main/resources/mapper/iot/NewsMapper.xml b/springboot/wumei-iot/src/main/resources/mapper/iot/NewsMapper.xml index 7e82a990..df37b90d 100644 --- a/springboot/wumei-iot/src/main/resources/mapper/iot/NewsMapper.xml +++ b/springboot/wumei-iot/src/main/resources/mapper/iot/NewsMapper.xml @@ -24,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select news_id, title, content, img_url, is_top, is_banner, category_id, category_name, status, author, del_flag, create_by, create_time, update_by, update_time, remark from news + select news_id, title, img_url, is_top, is_banner, category_id, category_name, status, author, del_flag, create_by, create_time, update_by, update_time, remark from news + +