增加排序功能,以及其余接口增加参数

master
rong.liu 2 years ago
parent 0be522886a
commit 5e48be6055
  1. 124
      src/main/java/com/huoran/iasf/controller/SysContentController.java
  2. 4
      src/main/java/com/huoran/iasf/entity/SysContent.java
  3. 8
      src/main/java/com/huoran/iasf/mapper/SysContentMapper.java
  4. 37
      src/main/java/com/huoran/iasf/mapper/xml/SysContentMapper.xml
  5. 7
      src/main/java/com/huoran/iasf/service/SysContentService.java
  6. 64
      src/main/java/com/huoran/iasf/service/impl/SysContentServiceImpl.java
  7. 16
      src/main/java/com/huoran/iasf/vo/req/ArticleModifiedSortReq.java
  8. 3
      src/main/java/com/huoran/iasf/vo/req/PageContentReqVO.java
  9. 6
      src/main/java/com/huoran/iasf/vo/resp/PageContentRespVO.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<SysContent> 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("新增失败");
}
@ -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<SysContent> queryWrap = new QueryWrapper<>();
queryWrap.eq("column_id", columnId);
queryWrap.eq("deleted", 1);
List<SysContent> contentList = service.list(queryWrap);*//*
//判断排序是值改小还是改大,大改小比如53改5那就加一个语句“大于等于5并且小于53”
//如果是小改大比如3改50那就是“大于3并且小于等于50”
//改小那就是拿到的数据都减一,改大那就是加一
//对剩余的
UpdateWrapper<SysContent> 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<SysContent> 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<ArticleModifiedSortReq> reqList) {
return service.modifiedSort(reqList);
}
@PostMapping("/sort")
@ApiOperation(value = "排序(自设置排序号) 上线后注释", response = SysContent.class)
public R sort() {
//获取当前栏目
QueryWrapper<SysContent> queryWrap = new QueryWrapper<>();
queryWrap.eq("deleted", 1);
queryWrap.groupBy("column_id");
queryWrap.orderByAsc("sequence");
List<SysContent> columnList = service.list(queryWrap);
for (SysContent content : columnList) {
Integer columnId = content.getColumnId();
QueryWrapper<SysContent> queryWrap1 = new QueryWrapper<>();
queryWrap1.eq("column_id", columnId);
queryWrap1.eq("deleted", 1);
List<SysContent> list = service.list(queryWrap1);
Integer count = 0;
for (SysContent c : list) {
++count;
c.setSequence(count);
service.updateById(c);
}
}
return R.success();
}
}

@ -172,4 +172,8 @@ public class SysContent implements Serializable {
@ApiModelProperty(value = "文章关键字")
private String articleKeyWord;
@ApiModelProperty(value = "顺序(排序号)")
private Integer sequence;
}

@ -31,4 +31,12 @@ public interface SysContentMapper extends BaseMapper<SysContent> {
List<PageContentRespVO> columnConditionsFilterArticles(@Param("columnId")String columnId);
/*Integer selectNextId(@Param("content")SysContent sysContent);
Integer updateSortById(@Param("content")SysContent sysContent);
Integer selectPreviousId(@Param("content")SysContent sysContent);*/
}

@ -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}
<if test="req.columnIds != null and req.columnIds.size() > 0 ">
@ -58,6 +59,14 @@
ORDER BY c.release_time asc
</if>
<if test="req.ordinalSort ==0">
ORDER BY sequence asc
</if>
<if test="req.ordinalSort ==1">
ORDER BY sequence desc
</if>
</select>
@ -179,5 +188,31 @@
ORDER BY t.release_time DESC
</select>
<!-- &lt;!&ndash;根据 sequence 查询下一条记录主键&ndash;&gt;
<select id="selectNextId" resultType="java.lang.Integer">
SELECT
IFNULL(
( SELECT id FROM sys_content WHERE sequence &gt; #{content.sequence} AND column_id = #{content.columnId} AND deleted = 1
ORDER BY sequence ASC LIMIT 0, 1 ),
1
) AS nextTypeId
</select>
&lt;!&ndash;根据主键更新排序号&ndash;&gt;
<update id="updateSortById" parameterType="java.lang.Integer" >
update sys_content
set sequence = #{content.sequence},update_time = now()
where id = #{content.id}
</update>
&lt;!&ndash;根据 sequence 查询上一条记录主键&ndash;&gt;
<select id="selectPreviousId" resultType="java.lang.Integer" >
SELECT IFNULL(
(SELECT id FROM sys_content WHERE sequence &lt; #{content.sequence} AND column_id = #{content.columnId} AND deleted = 1
ORDER BY sequence DESC LIMIT 0,1),1
) AS preTypeId
</select>-->
</mapper>

@ -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<SysContent> {
R siteSearchArticles(PageContentReqVO req);
R modifiedSort(List<ArticleModifiedSortReq> reqList);
R modifiedSort(Integer sequenceNumber, Integer articleId);
}

@ -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<SysContentMapper, SysCont
public R articlePaginationList(PageContentReqVO reqVO) {
Page<PageContentRespVO> page = new Page<PageContentRespVO>(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<SysContentMapper, SysCont
return R.success(pageList);
}
@Override
public R modifiedSort(List<ArticleModifiedSortReq> 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<SysContent> updateWrapper = new UpdateWrapper<>();
updateWrapper.set("sequence", sequenceNumber);
updateWrapper.eq("id", articleId);
baseMapper.update(new SysContent(), updateWrapper);
UpdateWrapper<SysContent> 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();
}
}

@ -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;
}

@ -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;*/

@ -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;
}
Loading…
Cancel
Save