Revert "完成标签维护功能"

This reverts commit 0eece5f7ec.
This commit is contained in:
2023-04-19 15:29:48 +08:00
parent 0eece5f7ec
commit 580a2f6d4e
6 changed files with 56 additions and 30 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);
}
@@ -31,13 +31,18 @@ public class TreeLabelEntity implements Serializable {
/**
*
*/
private String name;
private String label;
/**
*
*/
private String parentId;
/**
* 备注
*/
private String remark;
/**
*
*/
@@ -46,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;
@@ -17,8 +17,6 @@ public interface ITreeLabelService extends IService<TreeLabelEntity> {
* 获取标签树形结构
*
* @param like 模糊查询字段
* 返回树形结构
*
* @return
*/
List<TreeLabelVo> getTreeLabellist(String like);
@@ -35,7 +33,6 @@ public interface ITreeLabelService extends IService<TreeLabelEntity> {
*
* @param id 标签id
* @return
* 自动维护顺序的删除标签方法
*/
boolean deleteByIdAutoOrder(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));
//如果删除的不是最后一个标签,需要移动前面的标签
@@ -133,7 +140,7 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
List<TreeLabelVo> tree = new ArrayList<>();
for (TreeLabelVo label : treeLabelVos) {
if (label.getParentId().equals(rootParentId)) {
label.setChildLabel(createTree(label.getId(), treeLabelVos));
label.setChildren(createTree(label.getId(), treeLabelVos));
tree.add(label);
}
}
@@ -143,20 +150,20 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
public static TreeLabelVo filterByName(TreeLabelVo root, String name) {
TreeLabelVo newRoot = new TreeLabelVo();
newRoot.setId(root.getId());
newRoot.setName(root.getName());
newRoot.setLabel(root.getLabel());
newRoot.setParentId(root.getParentId());
newRoot.setOrderNum(root.getOrderNum());
List<TreeLabelVo> childLabel = new ArrayList<>();
if (root.getChildLabel() != null) {
for (TreeLabelVo child : root.getChildLabel()) {
if (root.getChildren() != null) {
for (TreeLabelVo child : root.getChildren()) {
TreeLabelVo newChild = filterByName(child, name);
if (newChild != null) {
childLabel.add(newChild);
}
}
}
newRoot.setChildLabel(childLabel.isEmpty() ? null : childLabel);
return root.getName().contains(name) || !childLabel.isEmpty() ? newRoot : null;
newRoot.setChildren(childLabel.isEmpty() ? null : childLabel);
return root.getLabel().contains(name) || !childLabel.isEmpty() ? newRoot : null;
}
}
@@ -27,25 +27,31 @@ public class TreeLabelVo {
* 标签名称
*/
@NotBlank(message = "名称不能为空")
private String name;
private String label;
/**
* 备注
*/
private String remark;
/**
* 父id
*/
@NotBlank(message = "上级标签不能为空")
private String parentId;
/**
*
*/
private Integer orderNum;
private Double orderNum;
/**
* 子标签
*/
private List<TreeLabelVo> childLabel;
private List<TreeLabelVo> children;
public TreeLabelVo(String parentId) {
this.parentId = parentId;
this.childLabel = new ArrayList<>();
this.children = new ArrayList<>();
}
}