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