完成标签维护功能
This commit is contained in:
+2
-18
@@ -37,28 +37,12 @@ public class TreeLabelManagerController {
|
|||||||
* @param treeLabelVo
|
* @param treeLabelVo
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ApiOperation("新增标签")
|
@ApiOperation("新增或编辑标签")
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
public ResponseMessage add(@Valid @RequestBody TreeLabelVo treeLabelVo) {
|
public ResponseMessage add(@Valid @RequestBody TreeLabelVo treeLabelVo) {
|
||||||
TreeLabelEntity treeLabelEntity = Convert.convert(TreeLabelEntity.class, treeLabelVo);
|
TreeLabelEntity treeLabelEntity = Convert.convert(TreeLabelEntity.class, treeLabelVo);
|
||||||
iTreeLabelService.saveOrUpdateTag(treeLabelEntity);
|
iTreeLabelService.saveOrUpdateTag(treeLabelEntity);
|
||||||
return Result.success();
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,7 +55,7 @@ public class TreeLabelManagerController {
|
|||||||
@ApiOperation("标签列表")
|
@ApiOperation("标签列表")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public ResponseMessage list(@RequestParam(value = "like", required = false) String like
|
public ResponseMessage list(@RequestParam(value = "like", required = false) String like
|
||||||
) throws ExecutionException, InterruptedException {
|
) throws ExecutionException, InterruptedException {
|
||||||
List<TreeLabelVo> rootLabel = iTreeLabelService.getTreeLabellist(like);
|
List<TreeLabelVo> rootLabel = iTreeLabelService.getTreeLabellist(like);
|
||||||
return Result.success(rootLabel);
|
return Result.success(rootLabel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public interface TreeLabelDao extends BaseMapper<TreeLabelEntity> {
|
|||||||
* @param parentId
|
* @param parentId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
double getMaxNum(String parentId);
|
int getMaxNum(String parentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,18 +31,13 @@ public class TreeLabelEntity implements Serializable {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private String label;
|
private String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private String parentId;
|
private String parentId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 备注
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -51,7 +46,12 @@ public class TreeLabelEntity implements Serializable {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private Double orderNum;
|
private Integer orderNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0代表未删除,1代表已删除
|
||||||
|
*/
|
||||||
|
private Integer delFlag;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public interface ITreeLabelService extends IService<TreeLabelEntity> {
|
|||||||
* 获取标签树形结构
|
* 获取标签树形结构
|
||||||
*
|
*
|
||||||
* @param like 模糊查询字段
|
* @param like 模糊查询字段
|
||||||
|
* 返回树形结构
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<TreeLabelVo> getTreeLabellist(String like);
|
List<TreeLabelVo> getTreeLabellist(String like);
|
||||||
@@ -33,6 +35,7 @@ public interface ITreeLabelService extends IService<TreeLabelEntity> {
|
|||||||
*
|
*
|
||||||
* @param id 标签id
|
* @param id 标签id
|
||||||
* @return
|
* @return
|
||||||
|
* 自动维护顺序的删除标签方法
|
||||||
*/
|
*/
|
||||||
boolean deleteByIdAutoOrder(String id);
|
boolean deleteByIdAutoOrder(String id);
|
||||||
|
|
||||||
|
|||||||
+13
-20
@@ -36,8 +36,10 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TreeLabelVo> getTreeLabellist(String like) {
|
public List<TreeLabelVo> getTreeLabellist(String like) {
|
||||||
//查询所有标签
|
//查询所有未删除的标签
|
||||||
List<TreeLabelEntity> treeLabelEntities = list();
|
LambdaQueryWrapper<TreeLabelEntity> treeLabelEntityWrapper = new LambdaQueryWrapper<>();
|
||||||
|
treeLabelEntityWrapper.eq(TreeLabelEntity::getDelFlag, TreeLabelConstants.UNDELETE);
|
||||||
|
List<TreeLabelEntity> treeLabelEntities = treeLabelDao.selectList(treeLabelEntityWrapper);
|
||||||
//找出根节点
|
//找出根节点
|
||||||
TreeLabelEntity rootTag = treeLabelEntities.stream().
|
TreeLabelEntity rootTag = treeLabelEntities.stream().
|
||||||
filter(treeLabelEntity ->
|
filter(treeLabelEntity ->
|
||||||
@@ -91,19 +93,10 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
|
|||||||
if (StringUtils.isEmpty(entity.getId())) {
|
if (StringUtils.isEmpty(entity.getId())) {
|
||||||
entity.setId(UUID.randomUUID10());
|
entity.setId(UUID.randomUUID10());
|
||||||
entity.setCreateDate(format.format(new Date()));
|
entity.setCreateDate(format.format(new Date()));
|
||||||
if (Objects.isNull(entity.getOrderNum())) {
|
|
||||||
double maxNum = treeLabelDao.getMaxNum(entity.getParentId());
|
|
||||||
entity.setOrderNum(maxNum + 1);
|
|
||||||
}
|
|
||||||
treeLabelDao.insert(entity);
|
treeLabelDao.insert(entity);
|
||||||
} else {
|
} else {
|
||||||
//编辑标签
|
//编辑标签
|
||||||
TreeLabelEntity treeLabelEntity = treeLabelDao.selectById(entity.getId());
|
treeLabelDao.updateById(entity);
|
||||||
if (Objects.nonNull(treeLabelEntity)) {
|
|
||||||
treeLabelDao.updateById(entity);
|
|
||||||
} else {
|
|
||||||
throw new AdcDaBaseException("标签id无效");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,8 +104,8 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
|
|||||||
public boolean deleteByIdAutoOrder(String id) {
|
public boolean deleteByIdAutoOrder(String id) {
|
||||||
TreeLabelEntity labelEntity = treeLabelDao.selectById(id);
|
TreeLabelEntity labelEntity = treeLabelDao.selectById(id);
|
||||||
String parentId = labelEntity.getParentId();
|
String parentId = labelEntity.getParentId();
|
||||||
double currentNum = labelEntity.getOrderNum();
|
int currentNum = labelEntity.getOrderNum();
|
||||||
double maxNum = treeLabelDao.getMaxNum(parentId);
|
int maxNum = treeLabelDao.getMaxNum(parentId);
|
||||||
//删除标签
|
//删除标签
|
||||||
treeLabelDao.delete(new QueryWrapper<TreeLabelEntity>().eq("id", id));
|
treeLabelDao.delete(new QueryWrapper<TreeLabelEntity>().eq("id", id));
|
||||||
//如果删除的不是最后一个标签,需要移动前面的标签
|
//如果删除的不是最后一个标签,需要移动前面的标签
|
||||||
@@ -140,7 +133,7 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
|
|||||||
List<TreeLabelVo> tree = new ArrayList<>();
|
List<TreeLabelVo> tree = new ArrayList<>();
|
||||||
for (TreeLabelVo label : treeLabelVos) {
|
for (TreeLabelVo label : treeLabelVos) {
|
||||||
if (label.getParentId().equals(rootParentId)) {
|
if (label.getParentId().equals(rootParentId)) {
|
||||||
label.setChildren(createTree(label.getId(), treeLabelVos));
|
label.setChildLabel(createTree(label.getId(), treeLabelVos));
|
||||||
tree.add(label);
|
tree.add(label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,20 +143,20 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
|
|||||||
public static TreeLabelVo filterByName(TreeLabelVo root, String name) {
|
public static TreeLabelVo filterByName(TreeLabelVo root, String name) {
|
||||||
TreeLabelVo newRoot = new TreeLabelVo();
|
TreeLabelVo newRoot = new TreeLabelVo();
|
||||||
newRoot.setId(root.getId());
|
newRoot.setId(root.getId());
|
||||||
newRoot.setLabel(root.getLabel());
|
newRoot.setName(root.getName());
|
||||||
newRoot.setParentId(root.getParentId());
|
newRoot.setParentId(root.getParentId());
|
||||||
newRoot.setOrderNum(root.getOrderNum());
|
newRoot.setOrderNum(root.getOrderNum());
|
||||||
List<TreeLabelVo> childLabel = new ArrayList<>();
|
List<TreeLabelVo> childLabel = new ArrayList<>();
|
||||||
if (root.getChildren() != null) {
|
if (root.getChildLabel() != null) {
|
||||||
for (TreeLabelVo child : root.getChildren()) {
|
for (TreeLabelVo child : root.getChildLabel()) {
|
||||||
TreeLabelVo newChild = filterByName(child, name);
|
TreeLabelVo newChild = filterByName(child, name);
|
||||||
if (newChild != null) {
|
if (newChild != null) {
|
||||||
childLabel.add(newChild);
|
childLabel.add(newChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newRoot.setChildren(childLabel.isEmpty() ? null : childLabel);
|
newRoot.setChildLabel(childLabel.isEmpty() ? null : childLabel);
|
||||||
return root.getLabel().contains(name) || !childLabel.isEmpty() ? newRoot : null;
|
return root.getName().contains(name) || !childLabel.isEmpty() ? newRoot : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,31 +27,25 @@ public class TreeLabelVo {
|
|||||||
* 标签名称
|
* 标签名称
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "名称不能为空")
|
@NotBlank(message = "名称不能为空")
|
||||||
private String label;
|
private String name;
|
||||||
|
|
||||||
/**
|
|
||||||
* 备注
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 父id
|
* 父id
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "上级标签不能为空")
|
|
||||||
private String parentId;
|
private String parentId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private Double orderNum;
|
private Integer orderNum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 子标签
|
* 子标签
|
||||||
*/
|
*/
|
||||||
private List<TreeLabelVo> children;
|
private List<TreeLabelVo> childLabel;
|
||||||
|
|
||||||
public TreeLabelVo(String parentId) {
|
public TreeLabelVo(String parentId) {
|
||||||
this.parentId = parentId;
|
this.parentId = parentId;
|
||||||
this.children = new ArrayList<>();
|
this.childLabel = new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user