Compare commits
3 Commits
f51f76fa6d
...
f05803432f
| Author | SHA1 | Date |
|---|---|---|
|
|
f05803432f | |
|
|
8e3f27eeaf | |
|
|
2924849d2f |
|
|
@ -41,15 +41,15 @@ public class EdTagLibraryController {
|
||||||
// 拖拽修改排序/分组
|
// 拖拽修改排序/分组
|
||||||
@GetMapping("/updateOrder")
|
@GetMapping("/updateOrder")
|
||||||
@UserOperation(value="修改了标签顺序", modelName = UserOperationModuleEnum.TAG)
|
@UserOperation(value="修改了标签顺序", modelName = UserOperationModuleEnum.TAG)
|
||||||
public ElectromagneticResult<?> updateTagOrder(@RequestParam String tagId, @RequestParam String newParentId, @RequestParam Integer newOrderBy) {
|
public ElectromagneticResult<?> updateTagOrder(@RequestParam String tagId, @RequestParam String newTagId, @RequestParam String newParentId, @RequestParam Integer newOrderBy) {
|
||||||
String updatedBy = UserThreadLocal.getUserId();
|
String updatedBy = UserThreadLocal.getUserId();
|
||||||
return ElectromagneticResultUtil.success(edTagLibraryService.updateTagOrder(tagId, newParentId, newOrderBy,updatedBy));
|
return ElectromagneticResultUtil.success(edTagLibraryService.updateTagOrder(tagId, newTagId, newParentId, newOrderBy,updatedBy));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发布标签
|
// 发布标签
|
||||||
@GetMapping("/batchPublish")
|
@PostMapping("/batchPublish")
|
||||||
@UserOperation(value="发布了标签组", modelName = UserOperationModuleEnum.TAG)
|
@UserOperation(value="发布了标签组", modelName = UserOperationModuleEnum.TAG)
|
||||||
public ElectromagneticResult<?> publishTag(@RequestParam List<String> tagIds) {
|
public ElectromagneticResult<?> publishTag(@RequestBody List<String> tagIds) {
|
||||||
return ElectromagneticResultUtil.success(edTagLibraryService.batchPublishTagGroups(tagIds));
|
return ElectromagneticResultUtil.success(edTagLibraryService.batchPublishTagGroups(tagIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public interface EdTagLibraryService extends IService<EdTagLibrary> {
|
||||||
* @param tagId
|
* @param tagId
|
||||||
* @param newOrderBy
|
* @param newOrderBy
|
||||||
*/
|
*/
|
||||||
Boolean updateTagOrder(String tagId, String newParentId, Integer newOrderBy, String updatedBy);
|
Boolean updateTagOrder(String tagId, String newTagId, String newParentId, Integer newOrderBy, String updatedBy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发布标签
|
* 发布标签
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,9 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
@Override
|
@Override
|
||||||
public Boolean createTagGroup(String tagName, String createdBy) {
|
public Boolean createTagGroup(String tagName, String createdBy) {
|
||||||
|
|
||||||
|
Assert.isTrue(!checkNameExist(tagName),StrFormatter.format("该标签组 {} 已存在",tagName));
|
||||||
// 查询当前最大排序值
|
// 查询当前最大排序值
|
||||||
Integer maxOrder = this.getBaseMapper()
|
Integer maxOrder = selectMaxOrder(TagTypeEnum.GROUP.getCode(), "0");
|
||||||
.selectMaxOrder(TagTypeEnum.GROUP.getCode(), "0");
|
|
||||||
if (maxOrder == null) {
|
|
||||||
maxOrder = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
EdTagLibrary tagGroup = new EdTagLibrary();
|
EdTagLibrary tagGroup = new EdTagLibrary();
|
||||||
tagGroup.setTagId(IdWorker.getSnowFlakeIdString());
|
tagGroup.setTagId(IdWorker.getSnowFlakeIdString());
|
||||||
tagGroup.setParentId("0"); // 标签组父节点为"0"
|
tagGroup.setParentId("0"); // 标签组父节点为"0"
|
||||||
|
|
@ -66,14 +62,9 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean createTag(String parentId, String tagName, String createdBy) {
|
public Boolean createTag(String parentId, String tagName, String createdBy) {
|
||||||
|
Assert.isTrue(!checkNameExist(tagName),StrFormatter.format("该标签名 {} 已存在",tagName));
|
||||||
// 查询当前组内最大排序值
|
// 查询当前组内最大排序值
|
||||||
Integer maxOrder = this.getBaseMapper()
|
Integer maxOrder = selectMaxOrder(TagTypeEnum.TAG.getCode(), parentId);
|
||||||
.selectMaxOrder(TagTypeEnum.TAG.getCode(), parentId);
|
|
||||||
if (maxOrder == null) {
|
|
||||||
maxOrder = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
EdTagLibrary tag = new EdTagLibrary();
|
EdTagLibrary tag = new EdTagLibrary();
|
||||||
tag.setTagId(IdWorker.getSnowFlakeIdString());
|
tag.setTagId(IdWorker.getSnowFlakeIdString());
|
||||||
tag.setParentId(parentId);
|
tag.setParentId(parentId);
|
||||||
|
|
@ -96,18 +87,30 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Boolean updateTagOrder(String tagId, String newParentId, Integer newOrderBy, String updatedBy) {
|
public Boolean updateTagOrder(String tagId, String newTagId, String newParentId, Integer newOrderBy, String updatedBy) {
|
||||||
|
|
||||||
|
|
||||||
if (StringUtils.isEmpty(newParentId) || newOrderBy == null) {
|
if (StringUtils.isEmpty(newParentId) || newOrderBy == null) {
|
||||||
throw new IllegalArgumentException("缺少参数");
|
throw new IllegalArgumentException("缺少参数");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询该标签
|
// 查询该标签
|
||||||
EdTagLibrary tag = this.getOne(new LambdaQueryWrapper<EdTagLibrary>()
|
EdTagLibrary tag = this.getOne(new LambdaQueryWrapper<EdTagLibrary>()
|
||||||
.eq(EdTagLibrary::getTagId, tagId));
|
.eq(EdTagLibrary::getTagId, tagId));
|
||||||
|
// 查询交换顺序的标签/组
|
||||||
|
EdTagLibrary newTag = this.getOne(new LambdaQueryWrapper<EdTagLibrary>()
|
||||||
|
.eq(EdTagLibrary::getTagId, newTagId));
|
||||||
|
|
||||||
Assert.notNull(tag,"标签不存在");
|
Assert.notNull(tag,"此标签/标签组不存在");
|
||||||
|
Assert.notNull(newTag, "无法将标签/标签组移动到此位置");
|
||||||
|
|
||||||
|
// 若标签挪到空标签组下,newTagId为新标签组Id
|
||||||
|
if (!tag.getType().equals(newTag.getType())) {
|
||||||
|
if (tag.getType().equals(TagTypeEnum.TAG.getCode())) {
|
||||||
|
newParentId = newTagId;
|
||||||
|
newOrderBy = 1;
|
||||||
|
} else {
|
||||||
|
throw new BizException("标签组无法移动到标签下");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String oldParentId = tag.getParentId();
|
String oldParentId = tag.getParentId();
|
||||||
Integer oldOrderBy = tag.getOrderBy();
|
Integer oldOrderBy = tag.getOrderBy();
|
||||||
|
|
@ -116,11 +119,11 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
|
|
||||||
if (isMoveToNewGroup) {
|
if (isMoveToNewGroup) {
|
||||||
// 旧组重新排序
|
// 旧组重新排序
|
||||||
int max = this.baseMapper.selectMaxOrder(tag.getType(),oldParentId)+1;
|
int max = selectMaxOrder(tag.getType(),oldParentId)+1;
|
||||||
reorderTagGroup(oldParentId, oldOrderBy, max);
|
reorderTagGroup(oldParentId, oldOrderBy, max);
|
||||||
|
|
||||||
// 新组重新排序
|
// 新组重新排序
|
||||||
max = this.baseMapper.selectMaxOrder(tag.getType(), newParentId)+1;
|
max = selectMaxOrder(tag.getType(), newParentId)+1;
|
||||||
reorderTagGroup(newParentId, max, newOrderBy);
|
reorderTagGroup(newParentId, max, newOrderBy);
|
||||||
} else {
|
} else {
|
||||||
// 仅更新同组内的排序
|
// 仅更新同组内的排序
|
||||||
|
|
@ -224,6 +227,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean updateTagInfo(String tagId, String tagName, String updatedBy) {
|
public Boolean updateTagInfo(String tagId, String tagName, String updatedBy) {
|
||||||
|
Assert.isTrue(!checkNameExist(tagName), StrFormatter.format("该标签/标签组名 {} 已存在" , tagName));
|
||||||
LambdaUpdateWrapper<EdTagLibrary> updateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<EdTagLibrary> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
updateWrapper.eq(EdTagLibrary::getTagId, tagId)
|
updateWrapper.eq(EdTagLibrary::getTagId, tagId)
|
||||||
.set(EdTagLibrary::getTagName, tagName)
|
.set(EdTagLibrary::getTagName, tagName)
|
||||||
|
|
@ -318,5 +322,26 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
return info;
|
return info;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验名字是否重复
|
||||||
|
* @param tagName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean checkNameExist(String tagName) {
|
||||||
|
LambdaQueryWrapper<EdTagLibrary> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(EdTagLibrary::getTagName, tagName);
|
||||||
|
return this.count(queryWrapper) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算顺序
|
||||||
|
* @return maxOrder
|
||||||
|
*/
|
||||||
|
private int selectMaxOrder(int typeCode, String parentId) {
|
||||||
|
// 查询当前最大排序值
|
||||||
|
int maxOrder = Optional.ofNullable(this.getBaseMapper().selectMaxOrder(typeCode, parentId)).orElse(0);
|
||||||
|
return maxOrder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue