维护标签排序功能,支持浮点排序

This commit is contained in:
2023-04-19 10:22:14 +08:00
parent c59d6fa2bc
commit 5c57f9b26a
7 changed files with 64 additions and 19 deletions
@@ -37,12 +37,28 @@ public class TreeLabelManagerController {
* @param treeLabelVo
* @return
*/
@ApiOperation("新增或编辑标签")
@ApiOperation("新增标签")
@PostMapping("/add")
public ResponseMessage add(@Valid @RequestBody TreeLabelVo treeLabelVo) {
TreeLabelEntity treeLabelEntity = Convert.convert(TreeLabelEntity.class, treeLabelVo);
iTreeLabelService.saveOrUpdateTag(treeLabelEntity);
return Result.success();
}
/**
* 新增或编辑标签
*
* @param treeLabelVo
* @return
*/
@ApiOperation("编辑标签")
@PostMapping("/update")
public ResponseMessage update(@Valid @RequestBody TreeLabelVo treeLabelVo) {
TreeLabelEntity treeLabelEntity = Convert.convert(TreeLabelEntity.class, treeLabelVo);
iTreeLabelService.saveOrUpdateTag(treeLabelEntity);
return Result.success();
}
/**
@@ -55,7 +71,7 @@ public class TreeLabelManagerController {
@ApiOperation("标签列表")
@GetMapping("/list")
public ResponseMessage list(@RequestParam(value = "like", required = false) String like
) throws ExecutionException, InterruptedException {
) throws ExecutionException, InterruptedException {
List<TreeLabelVo> rootLabel = iTreeLabelService.getTreeLabellist(like);
return Result.success(rootLabel);
}
@@ -16,7 +16,7 @@ public interface TreeLabelDao extends BaseMapper<TreeLabelEntity> {
* @param parentId
* @return
*/
int getMaxNum(String parentId);
double getMaxNum(String parentId);
}
@@ -51,12 +51,7 @@ public class TreeLabelEntity implements Serializable {
/**
*
*/
private Integer orderNum;
/**
* 0代表未删除,1代表已删除
*/
private Integer delFlag;
private Double orderNum;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@@ -14,8 +14,9 @@ import java.util.List;
public interface ITreeLabelService extends IService<TreeLabelEntity> {
/**
* 返回树形结构
* 获取标签树形结构
*
* @param like 模糊查询字段
* @return
*/
List<TreeLabelVo> getTreeLabellist(String like);
@@ -28,7 +29,10 @@ public interface ITreeLabelService extends IService<TreeLabelEntity> {
void saveOrUpdateTag(TreeLabelEntity treeLabelEntity);
/**
* 自动维护顺序的删除标签方法
* 删除标签
*
* @param id 标签id
* @return
*/
boolean deleteByIdAutoOrder(String id);
@@ -38,4 +42,5 @@ public interface ITreeLabelService extends IService<TreeLabelEntity> {
* @return
*/
boolean deleteById(String id);
}
@@ -36,10 +36,8 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
@Override
public List<TreeLabelVo> getTreeLabellist(String like) {
//查询所有未删除的标签
LambdaQueryWrapper<TreeLabelEntity> treeLabelEntityWrapper = new LambdaQueryWrapper<>();
treeLabelEntityWrapper.eq(TreeLabelEntity::getDelFlag, TreeLabelConstants.UNDELETE);
List<TreeLabelEntity> treeLabelEntities = treeLabelDao.selectList(treeLabelEntityWrapper);
//查询所有标签
List<TreeLabelEntity> treeLabelEntities = list();
//找出根节点
TreeLabelEntity rootTag = treeLabelEntities.stream().
filter(treeLabelEntity ->
@@ -93,10 +91,19 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
if (StringUtils.isEmpty(entity.getId())) {
entity.setId(UUID.randomUUID10());
entity.setCreateDate(format.format(new Date()));
if (Objects.isNull(entity.getOrderNum())) {
double maxNum = treeLabelDao.getMaxNum(entity.getParentId());
entity.setOrderNum(maxNum + 1);
}
treeLabelDao.insert(entity);
} else {
//编辑标签
treeLabelDao.updateById(entity);
TreeLabelEntity treeLabelEntity = treeLabelDao.selectById(entity.getId());
if (Objects.nonNull(treeLabelEntity)) {
treeLabelDao.updateById(entity);
} else {
throw new AdcDaBaseException("标签id无效");
}
}
}
@@ -104,8 +111,8 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
public boolean deleteByIdAutoOrder(String id) {
TreeLabelEntity labelEntity = treeLabelDao.selectById(id);
String parentId = labelEntity.getParentId();
int currentNum = labelEntity.getOrderNum();
int maxNum = treeLabelDao.getMaxNum(parentId);
double currentNum = labelEntity.getOrderNum();
double maxNum = treeLabelDao.getMaxNum(parentId);
//删除标签
treeLabelDao.delete(new QueryWrapper<TreeLabelEntity>().eq("id", id));
//如果删除的不是最后一个标签,需要移动前面的标签
@@ -37,12 +37,13 @@ public class TreeLabelVo {
/**
* 父id
*/
@NotBlank(message = "上级标签不能为空")
private String parentId;
/**
*
*/
private Integer orderNum;
private Double orderNum;
/**
* 子标签
@@ -0,0 +1,21 @@
<?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="com.adc.da.report.dao.mysql.TreeLabelDao">
<resultMap id="BaseResultMap" type="com.adc.da.report.eo.TreeLabelEntity">
<id property="id" column="id" jdbcType="VARCHAR"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="parentid" column="parent_id" jdbcType="VARCHAR"/>
<result property="createdate" column="create_date" jdbcType="VARCHAR"/>
<result property="ordernum" column="order_num" jdbcType="DOUBLE"/>
<result property="remark" column="remark" jdbcType="VARCHAR"/>
</resultMap>
<select id="getMaxNum" parameterType="string" resultType="double">
select max(t.order_num)
from ts_tree_label t
where t.parent_id = #{parentId}
</select>
</mapper>