ソースを参照

feat(business): 新增新闻信息模块

- 添加新闻信息相关的实体类、BO、VO
- 实现新闻信息的增删查改功能
- 新增新闻分类查询接口
- 添加发布新闻功能
fugui001 3 ヶ月 前
コミット
40de5a513d

+ 8 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/controller/NewsCategoryController.java

@@ -7,6 +7,7 @@ import jakarta.servlet.http.HttpServletResponse;
 import jakarta.validation.constraints.*;
 import cn.dev33.satoken.annotation.SaCheckPermission;
 import org.dromara.business.domain.bo.NewsCategoryBo;
+import org.dromara.business.domain.vo.ItemsVo;
 import org.dromara.business.domain.vo.NewsCategoryVo;
 import org.dromara.business.service.INewsCategoryService;
 import org.springframework.web.bind.annotation.*;
@@ -102,4 +103,11 @@ public class NewsCategoryController extends BaseController {
                           @PathVariable Long[] ids) {
         return toAjax(newsCategoryService.deleteWithValidByIds(List.of(ids), true));
     }
+
+    @GetMapping("/selectCategorySelList")
+    public R<List<NewsCategoryVo>> selectCategorySelList() {
+        return R.ok(newsCategoryService.selectCategorySelList());
+    }
+
+
 }

+ 120 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/controller/NewsInfoController.java

@@ -0,0 +1,120 @@
+package org.dromara.business.controller;
+
+import java.util.List;
+
+import lombok.RequiredArgsConstructor;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.constraints.*;
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import org.dromara.business.domain.bo.NewsInfo2Bo;
+import org.dromara.business.domain.bo.NewsInfoBo;
+import org.dromara.business.domain.vo.NewsInfoVo;
+import org.dromara.business.service.INewsInfoService;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.validation.annotation.Validated;
+import org.dromara.common.idempotent.annotation.RepeatSubmit;
+import org.dromara.common.log.annotation.Log;
+import org.dromara.common.web.core.BaseController;
+import org.dromara.common.mybatis.core.page.PageQuery;
+import org.dromara.common.core.domain.R;
+import org.dromara.common.core.validate.AddGroup;
+import org.dromara.common.core.validate.EditGroup;
+import org.dromara.common.log.enums.BusinessType;
+import org.dromara.common.excel.utils.ExcelUtil;
+import org.dromara.common.mybatis.core.page.TableDataInfo;
+
+/**
+ * 新闻信息
+ *
+ * @author Lion Li
+ * @date 2025-09-15
+ */
+@Validated
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/business/info")
+public class NewsInfoController extends BaseController {
+
+    private final INewsInfoService newsInfoService;
+
+    /**
+     * 查询新闻信息列表
+     */
+    @SaCheckPermission("business:info:list")
+    @GetMapping("/list")
+    public TableDataInfo<NewsInfoVo> list(NewsInfoBo bo, PageQuery pageQuery) {
+        return newsInfoService.queryPageList(bo, pageQuery);
+    }
+
+    /**
+     * 导出新闻信息列表
+     */
+    @SaCheckPermission("business:info:export")
+    @Log(title = "新闻信息", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(NewsInfoBo bo, HttpServletResponse response) {
+        List<NewsInfoVo> list = newsInfoService.queryList(bo);
+        ExcelUtil.exportExcel(list, "新闻信息", NewsInfoVo.class, response);
+    }
+
+    /**
+     * 获取新闻信息详细信息
+     *
+     * @param id 主键
+     */
+    @SaCheckPermission("business:info:query")
+    @GetMapping("/{id}")
+    public R<NewsInfoVo> getInfo(@NotNull(message = "主键不能为空")
+                                     @PathVariable Long id) {
+        return R.ok(newsInfoService.queryById(id));
+    }
+
+    /**
+     * 新增新闻信息
+     */
+    @SaCheckPermission("business:info:add")
+    @Log(title = "新闻信息", businessType = BusinessType.INSERT)
+    @RepeatSubmit()
+    @PostMapping()
+    public R<Void> add(@Validated(AddGroup.class) @RequestBody NewsInfoBo bo) {
+        return toAjax(newsInfoService.insertByBo(bo));
+    }
+
+    /**
+     * 修改新闻信息
+     */
+    @SaCheckPermission("business:info:edit")
+    @Log(title = "新闻信息", businessType = BusinessType.UPDATE)
+    @RepeatSubmit()
+    @PutMapping()
+    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NewsInfoBo bo) {
+        return toAjax(newsInfoService.updateByBo(bo));
+    }
+
+    /**
+     * 删除新闻信息
+     *
+     * @param ids 主键串
+     */
+    @SaCheckPermission("business:info:remove")
+    @Log(title = "新闻信息", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ids}")
+    public R<Void> remove(@NotEmpty(message = "主键不能为空")
+                          @PathVariable Long[] ids) {
+        return toAjax(newsInfoService.deleteWithValidByIds(List.of(ids), true));
+    }
+
+
+    /**
+     * 发布新闻
+     */
+    @SaCheckPermission("business:info:publishNews")
+    @Log(title = "发布新闻", businessType = BusinessType.UPDATE)
+    @RepeatSubmit()
+    @PutMapping("/publishNews")
+    public R<Void> publishNews(@Validated(EditGroup.class) @RequestBody NewsInfo2Bo bo) {
+        return toAjax(newsInfoService.publishNews(bo));
+    }
+
+
+}

+ 88 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/NewsInfo.java

@@ -0,0 +1,88 @@
+package org.dromara.business.domain;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Data;
+import java.util.Date;
+import java.io.Serial;
+
+/**
+ * 新闻信息对象 news_info
+ *
+ * @author Lion Li
+ * @date 2025-09-15
+ */
+@Data
+@TableName("news_info")
+public class NewsInfo {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     *
+     */
+    @TableId(value = "id")
+    private Long id;
+
+    /**
+     * 新闻标题
+     */
+    private String title;
+
+    /**
+     * 引言/摘要
+     */
+    private String summary;
+
+    /**
+     * 分类ID(外键,可选)
+     */
+    private Long categoryId;
+
+    /**
+     * 正文内容
+     */
+    private String content;
+
+    /**
+     * 封面图URL
+     */
+    private String imageUrl;
+
+    /**
+     * 外部链接
+     */
+    private String externalLink;
+
+    /**
+     * 是否默认:0=否,1=是
+     */
+    private Long isDefault;
+
+    /**
+     * 新闻类型 internal 内部编写  external 外部链接
+     */
+    private String newsType;
+
+    /**
+     * 位置编码(字典code)
+     */
+    private String positionCode;
+
+    /**
+     * 状态  draft 草稿  published 已发布  archived 已归档
+     */
+    private String status;
+
+    /**
+     *
+     */
+    private Date createdAt;
+
+    /**
+     *
+     */
+    private Date updatedAt;
+
+
+}

+ 97 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/bo/NewsInfo2Bo.java

@@ -0,0 +1,97 @@
+package org.dromara.business.domain.bo;
+
+import io.github.linpeilie.annotations.AutoMapper;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.dromara.business.domain.NewsInfo;
+import org.dromara.common.core.validate.AddGroup;
+import org.dromara.common.core.validate.EditGroup;
+import org.dromara.common.mybatis.core.domain.BaseEntity;
+
+import java.util.Date;
+
+/**
+ * 新闻信息业务对象 news_info
+ *
+ * @author Lion Li
+ * @date 2025-09-15
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@AutoMapper(target = NewsInfo.class, reverseConvertGenerate = false)
+public class NewsInfo2Bo extends BaseEntity {
+
+    /**
+     *
+     */
+    @NotNull(message = "不能为空", groups = { EditGroup.class })
+    private Long id;
+
+    /**
+     * 新闻标题
+     */
+    //@NotBlank(message = "新闻标题不能为空", groups = { AddGroup.class, EditGroup.class })
+    private String title;
+
+    /**
+     * 引言/摘要
+     */
+    private String summary;
+
+    /**
+     * 分类ID(外键,可选)
+     */
+    private Long categoryId;
+
+    /**
+     * 正文内容
+     */
+    private String content;
+
+    /**
+     * 封面图URL
+     */
+    private String imageUrl;
+
+    /**
+     * 外部链接
+     */
+    private String externalLink;
+
+    /**
+     * 是否默认:0=否,1=是
+     */
+    //@NotNull(message = "是否默认,不能为空", groups = { AddGroup.class, EditGroup.class })
+    private Long isDefault;
+
+    /**
+     * 新闻类型 internal 内部编写  external 外部链接
+     */
+    //@NotBlank(message = "新闻类型", groups = { AddGroup.class, EditGroup.class })
+    private String newsType;
+
+    /**
+     * 位置编码(字典code)
+     */
+    private String positionCode;
+
+    /**
+     * 状态  draft 草稿  published 已发布  archived 已归档
+     */
+    //@NotBlank(message = "状态  draft 草稿  published 已发布  archived 已归档不能为空", groups = { AddGroup.class, EditGroup.class })
+    private String status;
+
+    /**
+     *
+     */
+    private Date createdAt;
+
+    /**
+     *
+     */
+    private Date updatedAt;
+
+
+}

+ 95 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/bo/NewsInfoBo.java

@@ -0,0 +1,95 @@
+package org.dromara.business.domain.bo;
+
+import org.dromara.business.domain.NewsInfo;
+import org.dromara.common.mybatis.core.domain.BaseEntity;
+import org.dromara.common.core.validate.AddGroup;
+import org.dromara.common.core.validate.EditGroup;
+import io.github.linpeilie.annotations.AutoMapper;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import jakarta.validation.constraints.*;
+import java.util.Date;
+
+/**
+ * 新闻信息业务对象 news_info
+ *
+ * @author Lion Li
+ * @date 2025-09-15
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@AutoMapper(target = NewsInfo.class, reverseConvertGenerate = false)
+public class NewsInfoBo extends BaseEntity {
+
+    /**
+     *
+     */
+    @NotNull(message = "不能为空", groups = { EditGroup.class })
+    private Long id;
+
+    /**
+     * 新闻标题
+     */
+    @NotBlank(message = "新闻标题不能为空", groups = { AddGroup.class, EditGroup.class })
+    private String title;
+
+    /**
+     * 引言/摘要
+     */
+    private String summary;
+
+    /**
+     * 分类ID(外键,可选)
+     */
+    private Long categoryId;
+
+    /**
+     * 正文内容
+     */
+    private String content;
+
+    /**
+     * 封面图URL
+     */
+    private String imageUrl;
+
+    /**
+     * 外部链接
+     */
+    private String externalLink;
+
+    /**
+     * 是否默认:0=否,1=是
+     */
+    @NotNull(message = "是否默认,不能为空", groups = { AddGroup.class, EditGroup.class })
+    private Long isDefault;
+
+    /**
+     * 新闻类型 internal 内部编写  external 外部链接
+     */
+    @NotBlank(message = "新闻类型", groups = { AddGroup.class, EditGroup.class })
+    private String newsType;
+
+    /**
+     * 位置编码(字典code)
+     */
+    private String positionCode;
+
+    /**
+     * 状态  draft 草稿  published 已发布  archived 已归档
+     */
+    //@NotBlank(message = "状态  draft 草稿  published 已发布  archived 已归档不能为空", groups = { AddGroup.class, EditGroup.class })
+    private String status;
+
+    /**
+     *
+     */
+    private Date createdAt;
+
+    /**
+     *
+     */
+    private Date updatedAt;
+
+
+}

+ 122 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/vo/NewsInfoVo.java

@@ -0,0 +1,122 @@
+package org.dromara.business.domain.vo;
+
+import java.util.Date;
+import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
+import cn.idev.excel.annotation.ExcelProperty;
+import org.dromara.business.domain.NewsInfo;
+import org.dromara.common.excel.annotation.ExcelDictFormat;
+import org.dromara.common.excel.convert.ExcelDictConvert;
+import io.github.linpeilie.annotations.AutoMapper;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+
+
+/**
+ * 新闻信息视图对象 news_info
+ *
+ * @author Lion Li
+ * @date 2025-09-15
+ */
+@Data
+@ExcelIgnoreUnannotated
+@AutoMapper(target = NewsInfo.class)
+public class NewsInfoVo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     *
+     */
+    @ExcelProperty(value = "")
+    private Long id;
+
+    /**
+     * 新闻标题
+     */
+    @ExcelProperty(value = "新闻标题")
+    private String title;
+
+    /**
+     * 引言/摘要
+     */
+    @ExcelProperty(value = "引言/摘要")
+    private String summary;
+
+    /**
+     * 分类ID(外键,可选)
+     */
+    @ExcelProperty(value = "分类ID", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "外=键,可选")
+    private Long categoryId;
+
+    private String categoryName;
+
+    /**
+     * 正文内容
+     */
+    @ExcelProperty(value = "正文内容")
+    private String content;
+
+    private String contentText;
+
+    /**
+     * 封面图URL
+     */
+    @ExcelProperty(value = "封面图URL")
+    private String imageUrl;
+
+    /**
+     * 外部链接
+     */
+    @ExcelProperty(value = "外部链接")
+    private String externalLink;
+
+    /**
+     * 是否默认:0=否,1=是
+     */
+    @ExcelProperty(value = "是否默认:0=否,1=是")
+    private Long isDefault;
+
+    /**
+     * 新闻类型 internal 内部编写  external 外部链接
+     */
+    @ExcelProperty(value = "新闻类型 internal 内部编写  external 外部链接")
+    private String newsType;
+
+    private String newsTypeText;
+
+    /**
+     * 位置编码(字典code)
+     */
+    @ExcelProperty(value = "位置编码", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "字=典code")
+    private String positionCode;
+
+    private String positionText;
+
+    /**
+     * 状态  draft 草稿  published 已发布  archived 已归档
+     */
+    @ExcelProperty(value = "状态  draft 草稿  published 已发布  archived 已归档")
+    private String status;
+
+    private String statusText;
+
+    /**
+     *
+     */
+    @ExcelProperty(value = "")
+    private Date createdAt;
+
+    /**
+     *
+     */
+    @ExcelProperty(value = "")
+    private Date updatedAt;
+
+
+}

+ 4 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/mapper/NewsCategoryMapper.java

@@ -49,4 +49,8 @@ public interface NewsCategoryMapper extends BaseMapperPlus<NewsCategory, NewsCat
     @InterceptorIgnore(tenantLine = "true")
     int checkCategoryCodeUnique(@Param("code") String code, @Param("id") Long id);
 
+
+    @InterceptorIgnore(tenantLine = "true")
+    List<NewsCategoryVo> selectCategorySelList();
+
 }

+ 53 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/mapper/NewsInfoMapper.java

@@ -0,0 +1,53 @@
+package org.dromara.business.mapper;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.ibatis.annotations.Param;
+import org.dromara.business.domain.NewsInfo;
+import org.dromara.business.domain.vo.NewsInfoVo;
+import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 新闻信息Mapper接口
+ *
+ * @author Lion Li
+ * @date 2025-09-15
+ */
+@DS("mysql2")
+public interface NewsInfoMapper extends BaseMapperPlus<NewsInfo, NewsInfoVo> {
+
+    @InterceptorIgnore(tenantLine = "true")
+    Page<NewsInfoVo> selectNewsInfoListPage(@Param("page") Page<NewsInfo> page, @Param("ew") Wrapper<NewsInfo> wrapper);
+
+    @InterceptorIgnore(tenantLine = "true")
+    NewsInfoVo selectNewsInfoById(Long id);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int updateNewsInfoById(NewsInfo update);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int insertNewsInfo(NewsInfo insert);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int deleteNewsInfoById(@Param("ids") Collection<Long> ids);
+
+    @InterceptorIgnore(tenantLine = "true")
+    List<NewsInfoVo> selectNewsInfoList(@Param("ew") Wrapper<NewsInfo> wrapper);
+
+    @InterceptorIgnore(tenantLine = "true")
+    NewsInfoVo selectNewsInfoListByParam(@Param("map") Map<String, Object> map);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int updateDefaultNews(String positionCode);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int publishNews(NewsInfo update);
+
+
+}

+ 8 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/INewsCategoryService.java

@@ -65,4 +65,12 @@ public interface INewsCategoryService {
      * @return 是否删除成功
      */
     Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
+
+    /**
+     * 查询新闻分类列表 显示的
+     *
+     * @return 新闻分类列表
+     */
+    List<NewsCategoryVo> selectCategorySelList();
+
 }

+ 77 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/INewsInfoService.java

@@ -0,0 +1,77 @@
+package org.dromara.business.service;
+
+import org.dromara.business.domain.bo.NewsInfo2Bo;
+import org.dromara.business.domain.bo.NewsInfoBo;
+import org.dromara.business.domain.vo.NewsInfoVo;
+import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.mybatis.core.page.PageQuery;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 新闻信息Service接口
+ *
+ * @author Lion Li
+ * @date 2025-09-15
+ */
+public interface INewsInfoService {
+
+    /**
+     * 查询新闻信息
+     *
+     * @param id 主键
+     * @return 新闻信息
+     */
+    NewsInfoVo queryById(Long id);
+
+    /**
+     * 分页查询新闻信息列表
+     *
+     * @param bo        查询条件
+     * @param pageQuery 分页参数
+     * @return 新闻信息分页列表
+     */
+    TableDataInfo<NewsInfoVo> queryPageList(NewsInfoBo bo, PageQuery pageQuery);
+
+    /**
+     * 查询符合条件的新闻信息列表
+     *
+     * @param bo 查询条件
+     * @return 新闻信息列表
+     */
+    List<NewsInfoVo> queryList(NewsInfoBo bo);
+
+    /**
+     * 新增新闻信息
+     *
+     * @param bo 新闻信息
+     * @return 是否新增成功
+     */
+    Boolean insertByBo(NewsInfoBo bo);
+
+    /**
+     * 修改新闻信息
+     *
+     * @param bo 新闻信息
+     * @return 是否修改成功
+     */
+    Boolean updateByBo(NewsInfoBo bo);
+
+    /**
+     * 校验并批量删除新闻信息信息
+     *
+     * @param ids     待删除的主键集合
+     * @param isValid 是否进行有效性校验
+     * @return 是否删除成功
+     */
+    Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
+
+    /**
+     * 发布新闻
+     *
+     * @param bo 新闻信息
+     * @return 是否发布成功
+     */
+    Boolean publishNews(NewsInfo2Bo bo);
+}

+ 5 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/NewsCategoryServiceImpl.java

@@ -142,4 +142,9 @@ public class NewsCategoryServiceImpl implements INewsCategoryService {
         }
         return baseMapper.deleteCategoryById(ids) > 0;
     }
+
+    @Override
+    public List<NewsCategoryVo> selectCategorySelList() {
+        return baseMapper.selectCategorySelList();
+    }
 }

+ 216 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/NewsInfoServiceImpl.java

@@ -0,0 +1,216 @@
+package org.dromara.business.service.impl;
+
+import org.dromara.business.domain.NewsInfo;
+import org.dromara.business.domain.bo.NewsInfo2Bo;
+import org.dromara.business.domain.bo.NewsInfoBo;
+import org.dromara.business.domain.vo.NewsCategoryVo;
+import org.dromara.business.domain.vo.NewsInfoVo;
+import org.dromara.business.mapper.NewsInfoMapper;
+import org.dromara.business.service.INewsCategoryService;
+import org.dromara.business.service.INewsInfoService;
+import org.dromara.common.core.domain.dto.DictTypeDTO;
+import org.dromara.common.core.service.DictService;
+import org.dromara.common.core.utils.MapstructUtils;
+import org.dromara.common.core.utils.StringUtils;
+import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.mybatis.core.page.PageQuery;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Collection;
+
+/**
+ * 新闻信息Service业务层处理
+ *
+ * @author Lion Li
+ * @date 2025-09-15
+ */
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class NewsInfoServiceImpl implements INewsInfoService {
+
+    private final NewsInfoMapper baseMapper;
+
+    private final INewsCategoryService newsCategoryService;
+
+    private final DictService dictService;
+
+    /**
+     * 查询新闻信息
+     *
+     * @param id 主键
+     * @return 新闻信息
+     */
+    @Override
+    public NewsInfoVo queryById(Long id){
+        return baseMapper.selectNewsInfoById(id);
+    }
+
+    /**
+     * 分页查询新闻信息列表
+     *
+     * @param bo        查询条件
+     * @param pageQuery 分页参数
+     * @return 新闻信息分页列表
+     */
+    @Override
+    public TableDataInfo<NewsInfoVo> queryPageList(NewsInfoBo bo, PageQuery pageQuery) {
+        LambdaQueryWrapper<NewsInfo> lqw = buildQueryWrapper(bo);
+        Page<NewsInfoVo> result = baseMapper.selectNewsInfoListPage(pageQuery.build(), lqw);
+        List<NewsInfoVo> resultRecords = result.getRecords();
+        for (NewsInfoVo resultRecord : resultRecords) {
+            NewsCategoryVo newsCategoryVo = newsCategoryService.queryById(resultRecord.getCategoryId());
+            if(newsCategoryVo!=null){
+                String newsCategoryVoName = newsCategoryVo.getName();
+                resultRecord.setCategoryName(newsCategoryVoName);
+            }
+            String newsTypeText = dictService.getDictLabel("news_type", resultRecord.getNewsType());
+            resultRecord.setNewsTypeText(newsTypeText);
+
+
+            String positionText= dictService.getDictLabel("new_config_place", resultRecord.getPositionCode());
+            resultRecord.setPositionText(positionText);
+
+            String statusText= dictService.getDictLabel("news_status", resultRecord.getStatus());
+            resultRecord.setStatusText(statusText);
+
+            String contentText=replaceHtml(resultRecord.getContent());
+            resultRecord.setContentText(contentText);
+        }
+        return TableDataInfo.build(result);
+    }
+
+    /**
+     * 查询符合条件的新闻信息列表
+     *
+     * @param bo 查询条件
+     * @return 新闻信息列表
+     */
+    @Override
+    public List<NewsInfoVo> queryList(NewsInfoBo bo) {
+        LambdaQueryWrapper<NewsInfo> lqw = buildQueryWrapper(bo);
+        return baseMapper.selectNewsInfoList(lqw);
+    }
+
+    private LambdaQueryWrapper<NewsInfo> buildQueryWrapper(NewsInfoBo bo) {
+        Map<String, Object> params = bo.getParams();
+        LambdaQueryWrapper<NewsInfo> lqw = Wrappers.lambdaQuery();
+        lqw.orderByAsc(NewsInfo::getId);
+        lqw.eq(StringUtils.isNotBlank(bo.getTitle()), NewsInfo::getTitle, bo.getTitle());
+        lqw.eq(StringUtils.isNotBlank(bo.getSummary()), NewsInfo::getSummary, bo.getSummary());
+        lqw.eq(bo.getCategoryId() != null, NewsInfo::getCategoryId, bo.getCategoryId());
+        lqw.eq(StringUtils.isNotBlank(bo.getContent()), NewsInfo::getContent, bo.getContent());
+        lqw.eq(StringUtils.isNotBlank(bo.getImageUrl()), NewsInfo::getImageUrl, bo.getImageUrl());
+        lqw.eq(StringUtils.isNotBlank(bo.getExternalLink()), NewsInfo::getExternalLink, bo.getExternalLink());
+        lqw.eq(bo.getIsDefault() != null, NewsInfo::getIsDefault, bo.getIsDefault());
+        lqw.eq(StringUtils.isNotBlank(bo.getNewsType()), NewsInfo::getNewsType, bo.getNewsType());
+        lqw.eq(StringUtils.isNotBlank(bo.getPositionCode()), NewsInfo::getPositionCode, bo.getPositionCode());
+        lqw.eq(StringUtils.isNotBlank(bo.getStatus()), NewsInfo::getStatus, bo.getStatus());
+        lqw.eq(bo.getCreatedAt() != null, NewsInfo::getCreatedAt, bo.getCreatedAt());
+        lqw.eq(bo.getUpdatedAt() != null, NewsInfo::getUpdatedAt, bo.getUpdatedAt());
+        return lqw;
+    }
+
+    /**
+     * 新增新闻信息
+     *
+     * @param bo 新闻信息
+     * @return 是否新增成功
+     */
+    @Override
+    public Boolean insertByBo(NewsInfoBo bo) {
+        NewsInfo add = MapstructUtils.convert(bo, NewsInfo.class);
+        validEntityBeforeSave(add);
+        if(bo.getIsDefault()==1L){
+            if(StringUtils.isEmpty(bo.getPositionCode())){
+                throw new RuntimeException("默认新闻请选择配置位置!");
+            }
+       }
+
+        //如果之前有主和副的 都进行覆盖 把之前的变为null
+        Map<String, Object> map=new HashMap<>();
+        map.put("positionCode",bo.getPositionCode());
+        NewsInfoVo newsInfoListByParam = baseMapper.selectNewsInfoListByParam(map);
+        if(newsInfoListByParam!=null){
+           baseMapper.updateDefaultNews(bo.getPositionCode());
+        }
+        boolean flag = baseMapper.insertNewsInfo(add) > 0;
+        if (flag) {
+            bo.setId(add.getId());
+        }
+        return flag;
+    }
+
+    /**
+     * 修改新闻信息
+     *
+     * @param bo 新闻信息
+     * @return 是否修改成功
+     */
+    @Override
+    public Boolean updateByBo(NewsInfoBo bo) {
+        NewsInfo update = MapstructUtils.convert(bo, NewsInfo.class);
+        validEntityBeforeSave(update);
+        if(bo.getIsDefault()==1L){
+            if(StringUtils.isEmpty(bo.getPositionCode())){
+                throw new RuntimeException("默认新闻请选择配置位置!");
+            }
+        }
+        Map<String, Object> map=new HashMap<>();
+        map.put("positionCode",bo.getPositionCode());
+        NewsInfoVo newsInfoListByParam = baseMapper.selectNewsInfoListByParam(map);
+        if(newsInfoListByParam!=null){
+            baseMapper.updateDefaultNews(bo.getPositionCode());
+        }
+        return baseMapper.updateNewsInfoById(update) > 0;
+    }
+
+    /**
+     * 保存前的数据校验
+     */
+    private void validEntityBeforeSave(NewsInfo entity){
+        //TODO 做一些数据校验,如唯一约束
+    }
+
+    /**
+     * 校验并批量删除新闻信息信息
+     *
+     * @param ids     待删除的主键集合
+     * @param isValid 是否进行有效性校验
+     * @return 是否删除成功
+     */
+    @Override
+    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
+        if(isValid){
+            //TODO 做一些业务上的校验,判断是否需要校验
+        }
+        return baseMapper.deleteNewsInfoById(ids) > 0;
+    }
+
+    @Override
+    public Boolean publishNews(NewsInfo2Bo bo) {
+        NewsInfo update = MapstructUtils.convert(bo, NewsInfo.class);
+        validEntityBeforeSave(update);
+        update.setStatus("published");
+        return baseMapper.publishNews(update) > 0;
+    }
+
+
+    public static String replaceHtml(String html) {
+        if (html == null || html.isEmpty()) {
+            return "";
+        }
+        // 正则表达式移除所有的HTML标签
+        return html.replaceAll("<[^>]*>", "");
+    }
+
+
+}

+ 13 - 0
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/NewsCategoryMapper.xml

@@ -103,4 +103,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </if>
     </select>
 
+
+    <select id="selectCategorySelList" resultType="org.dromara.business.domain.vo.NewsCategoryVo">
+        SELECT
+            `id`,
+            `name`,
+            `code`,
+            `sort`,
+            `is_show`,
+            `created_at`,
+            `updated_at`
+        FROM news_category  where is_show=1
+    </select>
+
 </mapper>

+ 196 - 0
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/NewsInfoMapper.xml

@@ -0,0 +1,196 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.dromara.business.mapper.NewsInfoMapper">
+
+
+    <!-- 条件查询:显式列出所有字段 -->
+    <select id="selectNewsInfoListPage" resultType="org.dromara.business.domain.vo.NewsInfoVo">
+        SELECT
+            id,
+            title,
+            summary,
+            category_id,
+            content,
+            image_url,
+            external_link,
+            is_default,
+            news_type,
+            position_code,
+            status,
+            created_at,
+            updated_at
+        FROM news_info ${ew.customSqlSegment}
+    </select>
+
+
+    <select id="selectNewsInfoList" resultType="org.dromara.business.domain.vo.NewsInfoVo">
+        SELECT
+            id,
+            title,
+            summary,
+            category_id,
+            content,
+            image_url,
+            external_link,
+            is_default,
+            news_type,
+            position_code,
+            status,
+            created_at,
+            updated_at
+        FROM news_info ${ew.customSqlSegment}
+    </select>
+    <!-- 查询:显式列出所有字段(不再用 SELECT *) -->
+    <select id="selectNewsInfoById" resultType="org.dromara.business.domain.vo.NewsInfoVo">
+        SELECT
+            id,
+            title,
+            summary,
+            category_id,
+            content,
+            image_url,
+            external_link,
+            is_default,
+            news_type,
+            position_code,
+            status,
+            created_at,
+            updated_at
+        FROM news_info
+        WHERE id = #{id}
+    </select>
+
+
+
+
+
+    <!-- 插入:字段非空才插入 -->
+    <insert id="insertNewsInfo"  useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO news_info (
+        <trim suffixOverrides=",">
+            <if test="title != null and title != ''">title,</if>
+            <if test="summary != null and summary != ''">summary,</if>
+            <if test="categoryId != null">category_id,</if>
+            <if test="content != null and content != ''">content,</if>
+            <if test="imageUrl != null and imageUrl != ''">image_url,</if>
+            <if test="externalLink != null and externalLink != ''">external_link,</if>
+            <if test="isDefault != null">is_default,</if>
+            <if test="newsType != null and newsType != ''">news_type,</if>
+            <if test="positionCode != null and positionCode != ''">position_code,</if>
+            <if test="status != null and status != ''">status,</if>
+            created_at,
+            updated_at
+        </trim>
+        )
+        VALUES (
+        <trim suffixOverrides=",">
+            <if test="title != null and title != ''">#{title},</if>
+            <if test="summary != null and summary != ''">#{summary},</if>
+            <if test="categoryId != null">#{categoryId},</if>
+            <if test="content != null and content != ''">#{content},</if>
+            <if test="imageUrl != null and imageUrl != ''">#{imageUrl},</if>
+            <if test="externalLink != null and externalLink != ''">#{externalLink},</if>
+            <if test="isDefault != null">#{isDefault},</if>
+            <if test="newsType != null and newsType != ''">#{newsType},</if>
+            <if test="positionCode != null and positionCode != ''">#{positionCode},</if>
+            <if test="status != null and status != ''">#{status},</if>
+            NOW(),
+            NOW()
+        </trim>
+        )
+    </insert>
+
+    <!-- 更新:只更新非空字段,但关键字段必须存在 -->
+    <update id="updateNewsInfoById">
+        UPDATE news_info
+        <set>
+            <!-- title 必须非空才更新 -->
+            <if test="title != null and title != ''">
+                title = #{title},
+            </if>
+
+            <if test="summary != null">summary = #{summary},</if>
+
+            <if test="categoryId != null">category_id = #{categoryId},</if>
+
+            <!-- 内部新闻才允许更新 content -->
+            <if test="newsType != null and newsType == 'internal' and content != null and content != ''">
+                content = #{content},
+            </if>
+
+            <if test="imageUrl != null and imageUrl != ''">image_url = #{imageUrl},</if>
+
+            <!-- 外部链接更新时必须非空 -->
+            <if test="externalLink != null and externalLink != ''">external_link = #{externalLink},</if>
+
+            <if test="isDefault != null">is_default = #{isDefault},</if>
+
+            <!-- news_type 非空才更新 -->
+            <if test="newsType != null and newsType != ''">news_type = #{newsType},</if>
+
+            <!-- position_code 可选 -->
+            position_code = #{positionCode},
+
+            <!-- status 非空才更新 -->
+            <if test="status != null and status != ''">status = #{status},</if>
+
+            updated_at = NOW()
+        </set>
+        WHERE id = #{id}
+    </update>
+
+    <delete id="deleteNewsInfoById">
+        DELETE FROM news_info
+        <where>
+            id IN
+            <foreach item="id" collection="ids" open="(" separator="," close=")">
+                <if test="id > 0">
+                    #{id}
+                </if>
+            </foreach>
+        </where>
+    </delete>
+
+    <select id="selectNewsInfoListByParam" resultType="org.dromara.business.domain.vo.NewsInfoVo">
+        SELECT
+            id,
+            title,
+            summary,
+            category_id,
+            content,
+            image_url,
+            external_link,
+            is_default,
+            news_type,
+            position_code,
+            status,
+            created_at,
+            updated_at
+        FROM news_info where  1=1
+        <if test="map.positionCode != null and map.positionCode != ''">AND position_code = #{map.positionCode}</if>
+        limit 1
+    </select>
+
+    <update id="updateDefaultNews">
+        UPDATE news_info
+        SET position_code = null
+        WHERE   position_code = #{positionCode}
+    </update>
+
+
+    <update id="publishNews">
+        UPDATE news_info
+        <set>
+        <!-- 内部新闻才允许更新 content -->
+             <!-- status 非空才更新 -->
+            <if test="status != null and status != ''">status = #{status},</if>
+             updated_at = NOW()
+        </set>
+        WHERE id = #{id}
+    </update>
+
+
+
+</mapper>