+18
-2
@@ -37,12 +37,28 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,7 +71,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
|
||||||
*/
|
*/
|
||||||
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 parentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -46,12 +51,7 @@ public class TreeLabelEntity implements Serializable {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private Integer orderNum;
|
private Double 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,8 +17,6 @@ public interface ITreeLabelService extends IService<TreeLabelEntity> {
|
|||||||
* 获取标签树形结构
|
* 获取标签树形结构
|
||||||
*
|
*
|
||||||
* @param like 模糊查询字段
|
* @param like 模糊查询字段
|
||||||
* 返回树形结构
|
|
||||||
*
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<TreeLabelVo> getTreeLabellist(String like);
|
List<TreeLabelVo> getTreeLabellist(String like);
|
||||||
@@ -35,7 +33,6 @@ public interface ITreeLabelService extends IService<TreeLabelEntity> {
|
|||||||
*
|
*
|
||||||
* @param id 标签id
|
* @param id 标签id
|
||||||
* @return
|
* @return
|
||||||
* 自动维护顺序的删除标签方法
|
|
||||||
*/
|
*/
|
||||||
boolean deleteByIdAutoOrder(String id);
|
boolean deleteByIdAutoOrder(String id);
|
||||||
|
|
||||||
|
|||||||
+20
-13
@@ -36,10 +36,8 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TreeLabelVo> getTreeLabellist(String like) {
|
public List<TreeLabelVo> getTreeLabellist(String like) {
|
||||||
//查询所有未删除的标签
|
//查询所有标签
|
||||||
LambdaQueryWrapper<TreeLabelEntity> treeLabelEntityWrapper = new LambdaQueryWrapper<>();
|
List<TreeLabelEntity> treeLabelEntities = list();
|
||||||
treeLabelEntityWrapper.eq(TreeLabelEntity::getDelFlag, TreeLabelConstants.UNDELETE);
|
|
||||||
List<TreeLabelEntity> treeLabelEntities = treeLabelDao.selectList(treeLabelEntityWrapper);
|
|
||||||
//找出根节点
|
//找出根节点
|
||||||
TreeLabelEntity rootTag = treeLabelEntities.stream().
|
TreeLabelEntity rootTag = treeLabelEntities.stream().
|
||||||
filter(treeLabelEntity ->
|
filter(treeLabelEntity ->
|
||||||
@@ -93,10 +91,19 @@ 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 {
|
||||||
//编辑标签
|
//编辑标签
|
||||||
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) {
|
public boolean deleteByIdAutoOrder(String id) {
|
||||||
TreeLabelEntity labelEntity = treeLabelDao.selectById(id);
|
TreeLabelEntity labelEntity = treeLabelDao.selectById(id);
|
||||||
String parentId = labelEntity.getParentId();
|
String parentId = labelEntity.getParentId();
|
||||||
int currentNum = labelEntity.getOrderNum();
|
double currentNum = labelEntity.getOrderNum();
|
||||||
int maxNum = treeLabelDao.getMaxNum(parentId);
|
double maxNum = treeLabelDao.getMaxNum(parentId);
|
||||||
//删除标签
|
//删除标签
|
||||||
treeLabelDao.delete(new QueryWrapper<TreeLabelEntity>().eq("id", id));
|
treeLabelDao.delete(new QueryWrapper<TreeLabelEntity>().eq("id", id));
|
||||||
//如果删除的不是最后一个标签,需要移动前面的标签
|
//如果删除的不是最后一个标签,需要移动前面的标签
|
||||||
@@ -133,7 +140,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.setChildLabel(createTree(label.getId(), treeLabelVos));
|
label.setChildren(createTree(label.getId(), treeLabelVos));
|
||||||
tree.add(label);
|
tree.add(label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,20 +150,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.setName(root.getName());
|
newRoot.setLabel(root.getLabel());
|
||||||
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.getChildLabel() != null) {
|
if (root.getChildren() != null) {
|
||||||
for (TreeLabelVo child : root.getChildLabel()) {
|
for (TreeLabelVo child : root.getChildren()) {
|
||||||
TreeLabelVo newChild = filterByName(child, name);
|
TreeLabelVo newChild = filterByName(child, name);
|
||||||
if (newChild != null) {
|
if (newChild != null) {
|
||||||
childLabel.add(newChild);
|
childLabel.add(newChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newRoot.setChildLabel(childLabel.isEmpty() ? null : childLabel);
|
newRoot.setChildren(childLabel.isEmpty() ? null : childLabel);
|
||||||
return root.getName().contains(name) || !childLabel.isEmpty() ? newRoot : null;
|
return root.getLabel().contains(name) || !childLabel.isEmpty() ? newRoot : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,25 +27,31 @@ public class TreeLabelVo {
|
|||||||
* 标签名称
|
* 标签名称
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "名称不能为空")
|
@NotBlank(message = "名称不能为空")
|
||||||
private String name;
|
private String label;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 父id
|
* 父id
|
||||||
*/
|
*/
|
||||||
|
@NotBlank(message = "上级标签不能为空")
|
||||||
private String parentId;
|
private String parentId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private Integer orderNum;
|
private Double orderNum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 子标签
|
* 子标签
|
||||||
*/
|
*/
|
||||||
private List<TreeLabelVo> childLabel;
|
private List<TreeLabelVo> children;
|
||||||
|
|
||||||
public TreeLabelVo(String parentId) {
|
public TreeLabelVo(String parentId) {
|
||||||
this.parentId = parentId;
|
this.parentId = parentId;
|
||||||
this.childLabel = new ArrayList<>();
|
this.children = new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user