diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/config/AppConfig.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/config/AppConfig.java index 63a41c7..ea5df32 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/config/AppConfig.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/config/AppConfig.java @@ -2,8 +2,14 @@ package com.ruoyi.cms.config; import cn.hutool.core.lang.Snowflake; import cn.hutool.core.util.IdUtil; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; /** * 新增工具Config @@ -15,11 +21,31 @@ import org.springframework.context.annotation.Configuration; public class AppConfig { /** - * 用雪花算法算成ID,需要在实体类用到的字段上加上@JsonSerialize(using = ToStringSerializer.class)注解,不然会丢失精度 + * 用雪花算法算成ID * @return */ @Bean public Snowflake snowflake(){ return IdUtil.getSnowflake(1,1); } + + /** + * 解决雪花ID精度丢失问题 + * @param builder + * @return + */ + @Bean + @Primary + @ConditionalOnMissingBean(ObjectMapper.class) + public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) + { + ObjectMapper objectMapper = builder.createXmlMapper(false).build(); + + // 全局配置序列化返回 JSON 处理 + SimpleModule simpleModule = new SimpleModule(); + //JSON Long ==> String + simpleModule.addSerializer(Long.class, ToStringSerializer.instance); + objectMapper.registerModule(simpleModule); + return objectMapper; + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/CmsCategoryController.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/CmsCategoryController.java index 0c5ef46..5699208 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/CmsCategoryController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/CmsCategoryController.java @@ -127,4 +127,12 @@ public class CmsCategoryController extends BaseController } return toAjax(cmsCategoryService.deleteCmsCategoryById(id)); } + + /** + * 根据栏目ID查其所有的文章 + */ + @GetMapping("/content/{id}") + public AjaxResult getContentByCategoryId(@PathVariable Long id){ + return success(cmsCategoryService.getContentById(id)); + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/CmsContentController.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/CmsContentController.java index fb59d56..226d916 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/CmsContentController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/controller/CmsContentController.java @@ -1,11 +1,13 @@ package com.ruoyi.cms.controller; +import java.security.Principal; import java.util.List; import javax.servlet.http.HttpServletResponse; import com.ruoyi.cms.domain.CmsCategory; import com.ruoyi.cms.service.ICmsCategoryService; import com.ruoyi.common.core.domain.entity.SysDept; +import org.apache.ibatis.annotations.Delete; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -104,9 +106,9 @@ public class CmsContentController extends BaseController @PreAuthorize("@ss.hasPermi('cms:content:remove')") @Log(title = "文章", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") - public AjaxResult remove(@PathVariable Long[] ids) + public AjaxResult remove(@PathVariable Long[] ids, Principal principal) { - return toAjax(cmsContentService.deleteCmsContentByIds(ids)); + return toAjax(cmsContentService.deleteCmsContentByIds(ids, principal.getName())); } /** @@ -118,4 +120,26 @@ public class CmsContentController extends BaseController { return success(cmsCategoryService.selectCmsCategoryTreeList(category)); } + + /** + * 恢复记录 + */ + @Log(title = "文章", businessType = BusinessType.DELETE) + @PutMapping("/{ids}") + public AjaxResult recoverContentByIds(@PathVariable Long[] ids, Principal principal) + { + return toAjax(cmsContentService.recoverContentByIds(ids, principal.getName())); + } + + /** + * 发布文章,改变文章状态时用 + * @param ids + * @param principal + * @return + */ + @Log(title = "文章", businessType = BusinessType.UPDATE) + @PutMapping("/changeStatus/{ids}") + public AjaxResult changeContentByIds(@PathVariable Long[] ids, Principal principal){ + return toAjax(cmsContentService.changeContentByIds(ids, principal.getName())); + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/domain/CmsCategory.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/domain/CmsCategory.java index a3e0cf5..0cb5750 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/domain/CmsCategory.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/domain/CmsCategory.java @@ -1,6 +1,8 @@ package com.ruoyi.cms.domain; +import com.alibaba.fastjson2.annotation.JSONField; import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import lombok.Data; @@ -21,7 +23,6 @@ public class CmsCategory extends BaseEntity { private static final long serialVersionUID = 1L; - @JsonSerialize(using = ToStringSerializer.class) /** 栏目ID */ private Long id; @@ -37,7 +38,6 @@ public class CmsCategory extends BaseEntity @Excel(name = "栏目路径") private String categoryUrl; - @JsonSerialize(using = ToStringSerializer.class) /** 父栏目ID */ @Excel(name = "父栏目ID") private Long parentId; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/domain/CmsContent.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/domain/CmsContent.java index d681fb2..f1ed36b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/domain/CmsContent.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/domain/CmsContent.java @@ -1,5 +1,6 @@ package com.ruoyi.cms.domain; +import com.alibaba.fastjson2.annotation.JSONField; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; @@ -22,11 +23,9 @@ public class CmsContent extends BaseEntity { private static final long serialVersionUID = 1L; - @JsonSerialize(using = ToStringSerializer.class) /** 主键ID */ private Long id; - @JsonSerialize(using = ToStringSerializer.class) /** 所属栏目ID */ @Excel(name = "所属栏目ID") private Long categoryId; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/mapper/CmsContentMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/mapper/CmsContentMapper.java index 833f91e..318dd26 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/mapper/CmsContentMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/mapper/CmsContentMapper.java @@ -4,6 +4,7 @@ import java.util.List; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ruoyi.cms.domain.CmsContent; +import org.apache.ibatis.annotations.Param; /** * 文章Mapper接口 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/ICmsContentService.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/ICmsContentService.java index 69e39df..022c6d5 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/ICmsContentService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/ICmsContentService.java @@ -51,7 +51,7 @@ public interface ICmsContentService extends IService * @param ids 需要删除的文章主键集合 * @return 结果 */ - public int deleteCmsContentByIds(Long[] ids); + public int deleteCmsContentByIds(Long[] ids, String username); /** * 删除文章信息 @@ -60,4 +60,16 @@ public interface ICmsContentService extends IService * @return 结果 */ public int deleteCmsContentById(Long id); + + /** + * 恢复记录 + */ + int recoverContentByIds(Long[] ids, String username); + + /** + * 发布文章,改变文章状态时用 + * @param ids + * @return + */ + int changeContentByIds(Long[] ids, String username); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/CmsCategoryServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/CmsCategoryServiceImpl.java index 85b90ea..5815d23 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/CmsCategoryServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/CmsCategoryServiceImpl.java @@ -30,13 +30,12 @@ import javax.annotation.Resource; /** * 栏目Service业务层处理 - * + * * @author 点亮信息 * @date 2024-07-18 */ @Service -public class CmsCategoryServiceImpl extends ServiceImpl implements ICmsCategoryService -{ +public class CmsCategoryServiceImpl extends ServiceImpl implements ICmsCategoryService { @Autowired private Snowflake snowflake; @@ -45,37 +44,34 @@ public class CmsCategoryServiceImpl extends ServiceImpl selectCmsCategoryList(CmsCategory cmsCategory) - { + public List selectCmsCategoryList(CmsCategory cmsCategory) { return baseMapper.selectCmsCategoryList(cmsCategory); } /** * 新增栏目 - * + * * @param cmsCategory 栏目 * @return 结果 */ @Override - public int insertCmsCategory(CmsCategory cmsCategory) - { + public int insertCmsCategory(CmsCategory cmsCategory) { cmsCategory.setId(snowflake.nextId()); cmsCategory.setCreateTime(DateUtils.getNowDate()); return baseMapper.insertCmsCategory(cmsCategory); @@ -83,26 +79,24 @@ public class CmsCategoryServiceImpl extends ServiceImpl 0; } @@ -144,8 +135,7 @@ public class CmsCategoryServiceImpl extends ServiceImpl selectCmsCategoryTreeList(CmsCategory category) - { + public List selectCmsCategoryTreeList(CmsCategory category) { List categorys = SpringUtils.getAopProxy(this).selectCmsCategoryList(category); return buildCmsCategoryTreeSelect(categorys); } @@ -157,20 +147,17 @@ public class CmsCategoryServiceImpl extends ServiceImpl buildCmsCategoryTree(List categorys){ + public List buildCmsCategoryTree(List categorys) { List returnList = new ArrayList(); List tempList = categorys.stream().map(CmsCategory::getId).collect(Collectors.toList()); - for (CmsCategory category : categorys) - { + for (CmsCategory category : categorys) { // 如果是顶级节点, 遍历该父节点的所有子节点 - if (!tempList.contains(category.getParentId())) - { + if (!tempList.contains(category.getParentId())) { recursionFn(categorys, category); returnList.add(category); } } - if (returnList.isEmpty()) - { + if (returnList.isEmpty()) { returnList = categorys; } return returnList; @@ -183,7 +170,7 @@ public class CmsCategoryServiceImpl extends ServiceImpl buildCmsCategoryTreeSelect(List categorys){ + public List buildCmsCategoryTreeSelect(List categorys) { List categoryTrees = buildCmsCategoryTree(categorys); return categoryTrees.stream().map(NewTreeSelect::new).collect(Collectors.toList()); } @@ -191,15 +178,12 @@ public class CmsCategoryServiceImpl extends ServiceImpl list, CmsCategory t) - { + private void recursionFn(List list, CmsCategory t) { // 得到子节点列表 List childList = getChildList(list, t); t.setChildren(childList); - for (CmsCategory tChild : childList) - { - if (hasChild(list, tChild)) - { + for (CmsCategory tChild : childList) { + if (hasChild(list, tChild)) { recursionFn(list, tChild); } } @@ -208,15 +192,12 @@ public class CmsCategoryServiceImpl extends ServiceImpl getChildList(List list, CmsCategory t) - { + private List getChildList(List list, CmsCategory t) { List tlist = new ArrayList(); Iterator it = list.iterator(); - while (it.hasNext()) - { + while (it.hasNext()) { CmsCategory n = (CmsCategory) it.next(); - if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) - { + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) { tlist.add(n); } } @@ -226,46 +207,53 @@ public class CmsCategoryServiceImpl extends ServiceImpl list, CmsCategory t) - { + private boolean hasChild(List list, CmsCategory t) { return getChildList(list, t).size() > 0; } /** * 获取栏目下的子栏目及文章 + * * @param id 顶层栏目ID */ @Override public List selectCmsCategoryAndContentTreeList(Long id) { List categories = baseMapper.selectList(new QueryWrapper().eq("parent_id", id)); - List categoryVoList = new ArrayList<>(); - for (CmsCategory category : categories){ + List categoryVoList = categories.stream().map(category -> { CMSCategoryVo categoryVo = new CMSCategoryVo(); BeanUtil.copyProperties(category, categoryVo); categoryVo.setChildren(getContentById(category.getId())); - categoryVoList.add(categoryVo); - } + return categoryVo; + }).collect(Collectors.toList()); return categoryVoList; } /** * 按ID查文章 + * * @param id * @return */ @Override - public PageInfo getContentById(Long id){ + public PageInfo getContentById(Long id) { PageHelper.startPage(1, 10); - List contents = contentMapper.selectList(new QueryWrapper().eq("category_id", id)); + List contents = contentMapper.selectList(new QueryWrapper() + .and(item -> { + item.eq("category_id", id) + .eq("status", "1"); + }) + .orderByDesc("create_time") + ); return new PageInfo(contents); } /** * 获取所有的叶子节点 + * * @return */ @Override - public List getLeavesCategoryList(){ + public List getLeavesCategoryList() { return baseMapper.selectList(new QueryWrapper().ne("parent_id", 0)); } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/CmsContentServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/CmsContentServiceImpl.java index 5867e8c..84128dc 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/CmsContentServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/cms/service/impl/CmsContentServiceImpl.java @@ -1,10 +1,13 @@ package com.ruoyi.cms.service.impl; +import java.util.ArrayList; +import java.util.Date; import java.util.List; import cn.hutool.core.lang.Snowflake; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.utils.DateUtils; +import io.swagger.models.auth.In; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.cms.mapper.CmsContentMapper; @@ -81,8 +84,21 @@ public class CmsContentServiceImpl extends ServiceImpl - select id, category_id, content_type,image_url, video_url content_title, content_img, content_detail, source, source_url, original, author, editor, summary, status, publish_date, offline_date, is_accessory, accessory_url, remark, del_flag, create_time, create_by, update_time, update_by from cms_content + select id, category_id, content_type,image_url, video_url, content_title, content_img, content_detail, source, source_url, original, author, editor, summary, status, publish_date, offline_date, is_accessory, accessory_url, remark, del_flag, create_time, create_by, update_time, update_by from cms_content @@ -146,6 +147,7 @@ where id = #{id} + delete from cms_content where id = #{id} diff --git a/ruoyi-ui/src/api/cms/content.js b/ruoyi-ui/src/api/cms/content.js index f01ad9c..bec1e20 100644 --- a/ruoyi-ui/src/api/cms/content.js +++ b/ruoyi-ui/src/api/cms/content.js @@ -50,3 +50,19 @@ export function categoryTreeSelect() { method: 'get' }) } + +// 恢复文章 +export function recoverContentByIds(id) { + return request({ + url: "/cms/content/" + id, + method: "put" + }) +} + +// 发布文章 +export function changeContentByIds(id) { + return request({ + url: "/cms/content/changeStatus/" + id, + method: "put" + }) +} diff --git a/ruoyi-ui/src/assets/icons/svg/image.svg b/ruoyi-ui/src/assets/icons/svg/image.svg new file mode 100644 index 0000000..0090d37 --- /dev/null +++ b/ruoyi-ui/src/assets/icons/svg/image.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ruoyi-ui/src/assets/icons/svg/video.svg b/ruoyi-ui/src/assets/icons/svg/video.svg new file mode 100644 index 0000000..4a63d3f --- /dev/null +++ b/ruoyi-ui/src/assets/icons/svg/video.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ruoyi-ui/src/views/cms/content/contentList.vue b/ruoyi-ui/src/views/cms/content/contentList.vue index 0f956c5..ba05a86 100644 --- a/ruoyi-ui/src/views/cms/content/contentList.vue +++ b/ruoyi-ui/src/views/cms/content/contentList.vue @@ -52,7 +52,8 @@ - +
+ @keyup.enter.native="handleQuery"/> + :value="dict.value"/> @@ -97,24 +98,30 @@
- -
- - - - - + + + + + + + + 发布 @@ -135,15 +143,16 @@ size="small" type="text" icon="el-icon-download" + :disabled="scope.row.status !== '1'" @click="handleOffline(scope.row)">下线 - 修改 + 修改 - 删除 + 删除 @@ -155,15 +164,22 @@ :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" - @pagination="getList" /> + @pagination="getList"/> -