新增置顶功能

This commit is contained in:
aoli.qu 2023-10-26 17:12:05 +08:00
parent 295327fcd7
commit a65993f8aa
5 changed files with 52 additions and 2 deletions

View File

@ -80,4 +80,17 @@ public class BcHonorShowController extends BaseController {
}
/**
* 设置置顶
*/
@PostMapping("/setTop")
@PreAuthorize("@ss.hasPermi('honor:show:add')")
@Log(title = "荣誉橱窗展示置顶", businessType = BusinessType.UPDATE)
public AjaxResult setTop(@Validated @RequestBody IdParams params) {
log.info("BcHonorShowController - setTop params:{}", params);
bcHonorShowService.setTop(params.getId());
return AjaxResult.success();
}
}

View File

@ -40,5 +40,10 @@ public class BcHonorShow extends BaseEntity {
*/
private String files;
/**
* 是否置顶 1- 0-
*/
private Integer ifTop;
public BcHonorShow() {}
}

View File

@ -3,7 +3,9 @@ package com.org.web.honor.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.org.web.honor.domain.BcHonorShow;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
@ -19,8 +21,19 @@ public interface BcHonorShowMapper extends BaseMapper<BcHonorShow> {
" and title like concat('%', #{title}, '%') " +
" </if> " +
" order by create_time desc " +
" order by if_top desc,create_time desc " +
"</script>")
List<BcHonorShow> queryList(BcHonorShow params);
// 置顶
@Update("<script>" +
"update bc_honor_show " +
"set if_top = #{ifTop} " +
"where 1 = 1 " +
" <if test = \"id != null \"> " +
" AND id = #{id} " +
" </if>" +
"</script>")
void setTop(@Param("id") Long id, @Param("ifTop") Integer ifTop);
}

View File

@ -58,4 +58,23 @@ public class BcHonorShowService extends ServiceImpl<BcHonorShowMapper, BcHonorSh
return baseMapper.queryList(params);
}
/**
* 置顶操作
*/
public void setTop(Long id) {
log.info("BcHonorShowService - setTop id:{}", id);
BcHonorShow bcHonorShow = getById(id);
if (ObjectUtil.isEmpty(bcHonorShow)) {
throw new CustomException("数据不存在");
}
// 取消 其他数据的 置顶状态
baseMapper.setTop(null, 0);
// 设置当前数据 为置顶
baseMapper.setTop(id, 1);
}
}