mirror of
https://github.com/kerwincui/FastBee.git
synced 2025-10-12 19:40:51 +08:00
新增App资讯相关接口
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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<News> list = newsService.selectNewsList(news);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询置顶的新闻资讯
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:news:list')")
|
||||
@GetMapping("/topList")
|
||||
@ApiOperation("置顶新闻列表")
|
||||
public AjaxResult topList()
|
||||
{
|
||||
List<CategoryNews> list = newsService.selectTopNewsList();
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出新闻资讯列表
|
||||
*/
|
||||
|
@@ -66,4 +66,12 @@ public interface NewsCategoryMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteNewsCategoryByCategoryIds(Long[] categoryIds);
|
||||
|
||||
/**
|
||||
* 分类下的新闻数量
|
||||
*
|
||||
* @param categoryIds 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int newsCountInCategorys(Long[] categoryIds);
|
||||
}
|
||||
|
@@ -27,6 +27,13 @@ public interface NewsMapper
|
||||
*/
|
||||
public List<News> selectNewsList(News news);
|
||||
|
||||
/**
|
||||
* 查询置顶新闻资讯列表
|
||||
*
|
||||
* @return 新闻资讯集合
|
||||
*/
|
||||
public List<News> selectTopNewsList();
|
||||
|
||||
/**
|
||||
* 新增新闻资讯
|
||||
*
|
||||
|
@@ -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<News> 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<News> getNewsList() {
|
||||
return newsList;
|
||||
}
|
||||
|
||||
public void setNewsList(List<News> newsList) {
|
||||
this.newsList = newsList;
|
||||
}
|
||||
}
|
@@ -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);
|
||||
|
||||
/**
|
||||
* 删除新闻分类信息
|
||||
|
@@ -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<News> selectNewsList(News news);
|
||||
|
||||
/**
|
||||
* 查询置顶新闻资讯列表
|
||||
*
|
||||
* @return 新闻资讯集合
|
||||
*/
|
||||
public List<CategoryNews> selectTopNewsList();
|
||||
|
||||
/**
|
||||
* 新增新闻资讯
|
||||
*
|
||||
|
@@ -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("删除失败");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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<CategoryNews> selectTopNewsList()
|
||||
{
|
||||
List<CategoryNews> categoryNewsList =new ArrayList<>();
|
||||
List<News> newsList=newsMapper.selectTopNewsList();
|
||||
for(int i=0;i<newsList.size();i++){
|
||||
boolean isAdd=false;
|
||||
for(int j=0;j<categoryNewsList.size();j++){
|
||||
if(newsList.get(i).getCategoryId().longValue()==categoryNewsList.get(j).getCategoryId().longValue()){
|
||||
categoryNewsList.get(j).getNewsList().add(newsList.get(i));
|
||||
isAdd=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!isAdd) {
|
||||
CategoryNews categoryNews = new CategoryNews();
|
||||
categoryNews.setCategoryId(newsList.get(i).getCategoryId());
|
||||
categoryNews.setCategoryName(newsList.get(i).getCategoryName());
|
||||
categoryNews.getNewsList().add(newsList.get(i));
|
||||
categoryNewsList.add(categoryNews);
|
||||
}
|
||||
}
|
||||
return categoryNewsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增新闻资讯
|
||||
*
|
||||
|
@@ -93,4 +93,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
#{categoryId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="newsCountInCategorys" parameterType="String" resultType="int">
|
||||
select count(*) from news where category_id in
|
||||
<foreach item="categoryId" collection="array" open="(" separator="," close=")">
|
||||
#{categoryId}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
@@ -24,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectNewsVo">
|
||||
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
|
||||
</sql>
|
||||
|
||||
<select id="selectNewsList" parameterType="News" resultMap="NewsResult">
|
||||
@@ -33,14 +33,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="title != null and title != ''"> and title = #{title}</if>
|
||||
<if test="isTop != null "> and is_top = #{isTop}</if>
|
||||
<if test="isBanner != null "> and is_banner = #{isBanner}</if>
|
||||
<if test="categoryName != null and categoryName != ''"> and catgory_name like concat('%', #{categoryName}, '%')</if>
|
||||
<if test="categoryName != null and categoryName != ''"> and category_name like concat('%', #{categoryName}, '%')</if>
|
||||
<if test="status != null "> and status = #{status}</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectTopNewsList" parameterType="News" resultMap="NewsResult">
|
||||
select n.news_id, n.title, n.img_url, n.is_top, n.is_banner, n.category_id, c.category_name, n.status, n.author, n.create_time, n.remark
|
||||
from news n left join news_category c on c.category_id=n.category_id
|
||||
where is_top=1 and status=1
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectNewsByNewsId" parameterType="Long" resultMap="NewsResult">
|
||||
<include refid="selectNewsVo"/>
|
||||
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
|
||||
where news_id = #{newsId}
|
||||
</select>
|
||||
|
||||
|
Reference in New Issue
Block a user