diff --git a/src/main/java/com/huoran/iasf/controller/SysContentController.java b/src/main/java/com/huoran/iasf/controller/SysContentController.java index 25672e7..4a5f8f1 100644 --- a/src/main/java/com/huoran/iasf/controller/SysContentController.java +++ b/src/main/java/com/huoran/iasf/controller/SysContentController.java @@ -3,13 +3,16 @@ package com.huoran.iasf.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; import com.huoran.iasf.entity.SysColumn; import com.huoran.iasf.entity.SysContentFile; import com.huoran.iasf.entity.SysFilesEntity; import com.huoran.iasf.service.SysColumnService; import com.huoran.iasf.service.SysContentFileService; import com.huoran.iasf.service.SysFilesService; +import com.huoran.iasf.vo.req.ArticleModifiedSortReq; import com.huoran.iasf.vo.req.ContentHeavyTitleReqVO; import com.huoran.iasf.vo.req.ContentReq; import com.huoran.iasf.vo.req.PageContentReqVO; @@ -30,7 +33,9 @@ import com.huoran.iasf.service.SysContentService; import com.huoran.iasf.entity.SysContent; import javax.validation.Valid; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** @@ -55,7 +60,6 @@ public class SysContentController { public SysFilesService sysFilesService; - @PostMapping("/pagingQuery") @ApiOperation(value = "分页查询文章列表", response = PageContentRespVO.class) public R pagingQuery(@RequestBody @Valid @ApiParam(name = "分页查询参数", value = "传入json格式", required = true) PageContentReqVO sysContent) { @@ -81,7 +85,18 @@ public class SysContentController { @PostMapping("/save") @ApiOperation(value = "新增", response = SysContent.class) public R save(@RequestBody @Valid @ApiParam(name = "文章管理对象", value = "传入json格式", required = true) SysContent sysContent) { + + QueryWrapper queryWrap = new QueryWrapper<>(); + queryWrap.eq("column_id", sysContent.getColumnId()); + queryWrap.eq("deleted", 1); + Integer count = service.count(queryWrap); + if (count == 0) { + count++; + } + sysContent.setSequence(count); boolean addState = service.save(sysContent); + + return addState ? R.success(sysContent.getId()) : R.fail("新增失败"); } @@ -98,9 +113,9 @@ public class SysContentController { @ApiOperation(value = "删除", response = SysContent.class) public R delete(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { UpdateWrapper queryWrapper = new UpdateWrapper<>(); - queryWrapper.eq("quote_id",id); - queryWrapper.eq("quote_type",0); - queryWrapper.set("is_del",1); + queryWrapper.eq("quote_id", id); + queryWrapper.eq("quote_type", 0); + queryWrapper.set("is_del", 1); sysFilesService.update(queryWrapper); boolean delState = service.removeById(id); return delState ? R.success() : R.fail("删除失败"); @@ -112,9 +127,9 @@ public class SysContentController { public R batchDeletion(@ApiParam(name = "ids", value = "主键", required = true) @RequestParam List ids) { for (Integer id : ids) { UpdateWrapper queryWrapper = new UpdateWrapper<>(); - queryWrapper.eq("quote_id",id); - queryWrapper.eq("quote_type",0); - queryWrapper.set("is_del",1); + queryWrapper.eq("quote_id", id); + queryWrapper.eq("quote_type", 0); + queryWrapper.set("is_del", 1); sysFilesService.update(queryWrapper); } boolean delState = service.removeByIds(ids); @@ -190,5 +205,110 @@ public class SysContentController { return service.siteSearchArticles(req); } + + + /*@PostMapping("/modifiedSort") + @ApiOperation(value = "修改排序", response = SysContent.class) + public R modifiedSort( + @ApiParam(name = "sequenceNumber", value = "要排序的序号", required = true) @RequestParam Integer sequenceNumber, + @ApiParam(name = "articleId", value = "文章Id", required = true) @RequestParam Integer articleId) { + if (sequenceNumber<=0){ + return R.fail("请输入正确的序号!"); + } + SysContent content = service.getById(articleId); + //获取当前排序的序号 + Integer currentSerialNumber = content.getSequence(); + + + + //获取当前文章所属栏目id + Integer columnId = content.getColumnId(); + + //获取当前栏目下的全部文章 + *//*QueryWrapper queryWrap = new QueryWrapper<>(); + queryWrap.eq("column_id", columnId); + queryWrap.eq("deleted", 1); + List contentList = service.list(queryWrap);*//* + + //判断排序是值改小还是改大,大改小比如53改5那就加一个语句“大于等于5并且小于53” + //如果是小改大比如3改50那就是“大于3并且小于等于50” + //改小那就是拿到的数据都减一,改大那就是加一 + + + //对剩余的 + UpdateWrapper updateWrapper1 = new UpdateWrapper<>(); + updateWrapper1.ne("id",articleId); + + if (currentSerialNumber >= sequenceNumber) { + //改小 + updateWrapper1.setSql(" sequence = sequence + 1"); + } else if (currentSerialNumber <= sequenceNumber) { + //改大 + updateWrapper1.setSql(" sequence = sequence - 1"); + } + + updateWrapper1.eq("column_id",columnId); + updateWrapper1.eq("deleted", 1); + service.update(new SysContent(),updateWrapper1); + + + //修改当前序号 + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.set("sequence",sequenceNumber); + updateWrapper.eq("id",articleId); + service.update(new SysContent(),updateWrapper); + + + return R.success(); + }*/ + + + @PostMapping("/modifiedSort") + @ApiOperation(value = "修改排序", response = SysContent.class) + public R modifiedSort( + @ApiParam(name = "sequenceNumber", value = "要排序的序号", required = true) @RequestParam Integer sequenceNumber, + @ApiParam(name = "articleId", value = "文章Id", required = true) @RequestParam Integer articleId) { + + return service.modifiedSort(sequenceNumber,articleId); + } + + + @PostMapping("/modifiedArticleSort") + @ApiOperation(value = "修改文章排序", response = SysContent.class) + public R modifiedSort(@RequestBody List reqList) { + return service.modifiedSort(reqList); + } + + + @PostMapping("/sort") + @ApiOperation(value = "排序(自设置排序号) 上线后注释", response = SysContent.class) + public R sort() { + + //获取当前栏目 + QueryWrapper queryWrap = new QueryWrapper<>(); + queryWrap.eq("deleted", 1); + queryWrap.groupBy("column_id"); + queryWrap.orderByAsc("sequence"); + List columnList = service.list(queryWrap); + + for (SysContent content : columnList) { + Integer columnId = content.getColumnId(); + QueryWrapper queryWrap1 = new QueryWrapper<>(); + queryWrap1.eq("column_id", columnId); + queryWrap1.eq("deleted", 1); + List list = service.list(queryWrap1); + + Integer count = 0; + for (SysContent c : list) { + ++count; + c.setSequence(count); + service.updateById(c); + } + } + + + return R.success(); + } + } diff --git a/src/main/java/com/huoran/iasf/entity/SysContent.java b/src/main/java/com/huoran/iasf/entity/SysContent.java index 2dd523d..9b938d3 100644 --- a/src/main/java/com/huoran/iasf/entity/SysContent.java +++ b/src/main/java/com/huoran/iasf/entity/SysContent.java @@ -172,4 +172,8 @@ public class SysContent implements Serializable { @ApiModelProperty(value = "文章关键字") private String articleKeyWord; + + @ApiModelProperty(value = "顺序(排序号)") + private Integer sequence; + } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/mapper/SysContentMapper.java b/src/main/java/com/huoran/iasf/mapper/SysContentMapper.java index 59c6a37..9e111c5 100644 --- a/src/main/java/com/huoran/iasf/mapper/SysContentMapper.java +++ b/src/main/java/com/huoran/iasf/mapper/SysContentMapper.java @@ -31,4 +31,12 @@ public interface SysContentMapper extends BaseMapper { List columnConditionsFilterArticles(@Param("columnId")String columnId); + + /*Integer selectNextId(@Param("content")SysContent sysContent); + + Integer updateSortById(@Param("content")SysContent sysContent); + + Integer selectPreviousId(@Param("content")SysContent sysContent);*/ + + } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/mapper/xml/SysContentMapper.xml b/src/main/java/com/huoran/iasf/mapper/xml/SysContentMapper.xml index 60b9b8a..7fa0445 100644 --- a/src/main/java/com/huoran/iasf/mapper/xml/SysContentMapper.xml +++ b/src/main/java/com/huoran/iasf/mapper/xml/SysContentMapper.xml @@ -6,7 +6,8 @@ (SELECT sys_column.column_name FROM sys_column WHERE sys_column.id = c.column_id) AS columnName, (SELECT u.real_name FROM sys_user u WHERE u.id = c.founder_id) AS founderName, (SELECT u.real_name FROM sys_user u WHERE u.id = c.editor_id) AS editorName, - (SELECT type_id from sys_column WHERE sys_column.id = c.column_id) as typeId + (SELECT type_id from sys_column WHERE sys_column.id = c.column_id) as typeId, + IFNULL( ( SELECT c1.classification_name FROM sys_content_classification c1 WHERE c1.id = c.classification_id ), '暂无' ) AS classificationName FROM sys_content c WHERE c.deleted = 1 and site_id = #{req.siteId} @@ -58,6 +59,14 @@ ORDER BY c.release_time asc + + ORDER BY sequence asc + + + + ORDER BY sequence desc + + @@ -179,5 +188,31 @@ ORDER BY t.release_time DESC + \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/service/SysContentService.java b/src/main/java/com/huoran/iasf/service/SysContentService.java index ccc5615..bf9bb07 100644 --- a/src/main/java/com/huoran/iasf/service/SysContentService.java +++ b/src/main/java/com/huoran/iasf/service/SysContentService.java @@ -3,9 +3,12 @@ package com.huoran.iasf.service; import com.huoran.iasf.common.utils.R; import com.huoran.iasf.entity.SysContent; import com.baomidou.mybatisplus.extension.service.IService; +import com.huoran.iasf.vo.req.ArticleModifiedSortReq; import com.huoran.iasf.vo.req.ContentHeavyTitleReqVO; import com.huoran.iasf.vo.req.PageContentReqVO; +import io.swagger.annotations.ApiParam; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -36,4 +39,8 @@ public interface SysContentService extends IService { R siteSearchArticles(PageContentReqVO req); + R modifiedSort(List reqList); + + R modifiedSort(Integer sequenceNumber, Integer articleId); + } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/service/impl/SysContentServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/SysContentServiceImpl.java index 3b12473..25cbc2d 100644 --- a/src/main/java/com/huoran/iasf/service/impl/SysContentServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/SysContentServiceImpl.java @@ -10,6 +10,7 @@ import com.huoran.iasf.common.utils.R; import com.huoran.iasf.entity.SysContent; import com.huoran.iasf.mapper.SysContentMapper; import com.huoran.iasf.service.SysContentService; +import com.huoran.iasf.vo.req.ArticleModifiedSortReq; import com.huoran.iasf.vo.req.ContentHeavyTitleReqVO; import com.huoran.iasf.vo.req.PageContentReqVO; import com.huoran.iasf.vo.resp.PageContentRespVO; @@ -58,9 +59,9 @@ public class SysContentServiceImpl extends ServiceImpl page = new Page(reqVO.getPageNum(), reqVO.getPageSize()); - if (reqVO.getModifiedTimeSort() == null && reqVO.getPublicationTimeSort() == null) { + /*if (reqVO.getModifiedTimeSort() == null && reqVO.getPublicationTimeSort() == null) { reqVO.setPublicationTimeSort(0); - } + }*/ /*if (reqVO.getIsDisable()!=null){ if (reqVO.getIsDisable() == 1) { //是否禁用(0默认,0启用 1禁用) @@ -133,6 +134,65 @@ public class SysContentServiceImpl extends ServiceImpl reqList) { + for (ArticleModifiedSortReq req : reqList) { + SysContent content = new SysContent(); + content.setId(req.getArticleId()); + content.setSequence(req.getSequence()); + baseMapper.updateById(content); + } + return R.success(); + } + + @Override + public R modifiedSort(Integer sequenceNumber, Integer articleId) { + + if (sequenceNumber <= 0) { + return R.fail("请输入正确的序号!"); + } + + + SysContent content = baseMapper.selectById(articleId); + //获取当前排序的序号 + Integer currentSerialNumber = content.getSequence(); + //获取当前文章所属栏目id + Integer columnId = content.getColumnId(); + + if (currentSerialNumber.equals(sequenceNumber)){ + return R.success(); + } + + + //修改当前序号 + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.set("sequence", sequenceNumber); + updateWrapper.eq("id", articleId); + baseMapper.update(new SysContent(), updateWrapper); + + UpdateWrapper updateWrapper1 = new UpdateWrapper<>(); + updateWrapper1.ne("id", articleId); + // 序号越小值越算大 + //currentSerialNumber 当前文章的序号 + //sequenceNumber 要更改的序号 + if (currentSerialNumber > sequenceNumber) { + //改大 gt > + updateWrapper1.setSql(" sequence = sequence + 1"); + updateWrapper1.last(" and sequence >= "+sequenceNumber+ " and sequence < "+currentSerialNumber); + } else if (currentSerialNumber < sequenceNumber) { + //改小 + updateWrapper1.le("sequence", sequenceNumber); + updateWrapper1.setSql(" sequence = sequence - 1"); + //用于判断序号为本身就为1时候就不减了 + updateWrapper1.ne("sequence", 1); + } + + updateWrapper1.eq("column_id", columnId); + updateWrapper1.eq("deleted", 1); + baseMapper.update(new SysContent(), updateWrapper1); + return R.success(); + } + } diff --git a/src/main/java/com/huoran/iasf/vo/req/ArticleModifiedSortReq.java b/src/main/java/com/huoran/iasf/vo/req/ArticleModifiedSortReq.java new file mode 100644 index 0000000..eb3d7c5 --- /dev/null +++ b/src/main/java/com/huoran/iasf/vo/req/ArticleModifiedSortReq.java @@ -0,0 +1,16 @@ +package com.huoran.iasf.vo.req; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +public class ArticleModifiedSortReq { + @ApiModelProperty(value = "顺序(排序号)") + private Integer sequence; + + @ApiModelProperty(value = "文章id") + private Integer articleId; + + +} diff --git a/src/main/java/com/huoran/iasf/vo/req/PageContentReqVO.java b/src/main/java/com/huoran/iasf/vo/req/PageContentReqVO.java index 0c9756e..1591e01 100644 --- a/src/main/java/com/huoran/iasf/vo/req/PageContentReqVO.java +++ b/src/main/java/com/huoran/iasf/vo/req/PageContentReqVO.java @@ -55,6 +55,9 @@ public class PageContentReqVO extends PageReqVO { @ApiModelProperty(value = "发布时间排序(0默认倒序 1升序)") private Integer publicationTimeSort; + @ApiModelProperty(value = "序号排序(0默认升序 1倒序)") + private Integer ordinalSort; + /* @ApiModelProperty(value = "模板状态(0禁用;1启用)") private Integer templateStatus;*/ diff --git a/src/main/java/com/huoran/iasf/vo/resp/PageContentRespVO.java b/src/main/java/com/huoran/iasf/vo/resp/PageContentRespVO.java index 0d3b244..b2d1807 100644 --- a/src/main/java/com/huoran/iasf/vo/resp/PageContentRespVO.java +++ b/src/main/java/com/huoran/iasf/vo/resp/PageContentRespVO.java @@ -99,8 +99,7 @@ public class PageContentRespVO { @ApiModelProperty(value = "标签名称") private String labelName; - - @ApiModelProperty(value = "是否禁用(0默认,0启用 1禁用)") + @ApiModelProperty(value = "分类名称(没有显示暂无)") private String classificationName; @@ -183,5 +182,6 @@ public class PageContentRespVO { @ApiModelProperty(value = "样式id(用于前端区分是会议还是文章跳转界面)") private Integer listStyleId; - + @ApiModelProperty(value = "顺序(排序号)") + private Integer sequence; } \ No newline at end of file