Compare commits
3 Commits
f51f76fa6d
...
f05803432f
| Author | SHA1 | Date |
|---|---|---|
|
|
f05803432f | |
|
|
8e3f27eeaf | |
|
|
2924849d2f |
|
|
@ -41,15 +41,15 @@ public class EdTagLibraryController {
|
|||
// 拖拽修改排序/分组
|
||||
@GetMapping("/updateOrder")
|
||||
@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();
|
||||
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)
|
||||
public ElectromagneticResult<?> publishTag(@RequestParam List<String> tagIds) {
|
||||
public ElectromagneticResult<?> publishTag(@RequestBody List<String> tagIds) {
|
||||
return ElectromagneticResultUtil.success(edTagLibraryService.batchPublishTagGroups(tagIds));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public interface EdTagLibraryService extends IService<EdTagLibrary> {
|
|||
* @param tagId
|
||||
* @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
|
||||
public Boolean createTagGroup(String tagName, String createdBy) {
|
||||
|
||||
Assert.isTrue(!checkNameExist(tagName),StrFormatter.format("该标签组 {} 已存在",tagName));
|
||||
// 查询当前最大排序值
|
||||
Integer maxOrder = this.getBaseMapper()
|
||||
.selectMaxOrder(TagTypeEnum.GROUP.getCode(), "0");
|
||||
if (maxOrder == null) {
|
||||
maxOrder = 0;
|
||||
}
|
||||
|
||||
Integer maxOrder = selectMaxOrder(TagTypeEnum.GROUP.getCode(), "0");
|
||||
EdTagLibrary tagGroup = new EdTagLibrary();
|
||||
tagGroup.setTagId(IdWorker.getSnowFlakeIdString());
|
||||
tagGroup.setParentId("0"); // 标签组父节点为"0"
|
||||
|
|
@ -66,14 +62,9 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
*/
|
||||
@Override
|
||||
public Boolean createTag(String parentId, String tagName, String createdBy) {
|
||||
|
||||
Assert.isTrue(!checkNameExist(tagName),StrFormatter.format("该标签名 {} 已存在",tagName));
|
||||
// 查询当前组内最大排序值
|
||||
Integer maxOrder = this.getBaseMapper()
|
||||
.selectMaxOrder(TagTypeEnum.TAG.getCode(), parentId);
|
||||
if (maxOrder == null) {
|
||||
maxOrder = 0;
|
||||
}
|
||||
|
||||
Integer maxOrder = selectMaxOrder(TagTypeEnum.TAG.getCode(), parentId);
|
||||
EdTagLibrary tag = new EdTagLibrary();
|
||||
tag.setTagId(IdWorker.getSnowFlakeIdString());
|
||||
tag.setParentId(parentId);
|
||||
|
|
@ -96,18 +87,30 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
*/
|
||||
@Override
|
||||
@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) {
|
||||
throw new IllegalArgumentException("缺少参数");
|
||||
}
|
||||
|
||||
// 查询该标签
|
||||
EdTagLibrary tag = this.getOne(new LambdaQueryWrapper<EdTagLibrary>()
|
||||
.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();
|
||||
Integer oldOrderBy = tag.getOrderBy();
|
||||
|
|
@ -116,11 +119,11 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
|
||||
if (isMoveToNewGroup) {
|
||||
// 旧组重新排序
|
||||
int max = this.baseMapper.selectMaxOrder(tag.getType(),oldParentId)+1;
|
||||
int max = selectMaxOrder(tag.getType(),oldParentId)+1;
|
||||
reorderTagGroup(oldParentId, oldOrderBy, max);
|
||||
|
||||
// 新组重新排序
|
||||
max = this.baseMapper.selectMaxOrder(tag.getType(), newParentId)+1;
|
||||
max = selectMaxOrder(tag.getType(), newParentId)+1;
|
||||
reorderTagGroup(newParentId, max, newOrderBy);
|
||||
} else {
|
||||
// 仅更新同组内的排序
|
||||
|
|
@ -134,7 +137,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
.set(EdTagLibrary::getOrderBy, newOrderBy)
|
||||
.set(EdTagLibrary::getUpdatedBy, updatedBy));
|
||||
if (isUpdated) {
|
||||
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("更新了标签{}的排序", tag.getTagName()));
|
||||
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("更新了标签 {} 的排序", tag.getTagName()));
|
||||
}
|
||||
return isUpdated;
|
||||
}
|
||||
|
|
@ -178,7 +181,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
// 删除本身
|
||||
boolean isDeleted = this.removeById(tagId);
|
||||
if (isDeleted) {
|
||||
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("删除了标签{}", tag.getTagName()));
|
||||
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("删除了标签 {} ", tag.getTagName()));
|
||||
}
|
||||
return isDeleted;
|
||||
}
|
||||
|
|
@ -224,13 +227,14 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
*/
|
||||
@Override
|
||||
public Boolean updateTagInfo(String tagId, String tagName, String updatedBy) {
|
||||
Assert.isTrue(!checkNameExist(tagName), StrFormatter.format("该标签/标签组名 {} 已存在" , tagName));
|
||||
LambdaUpdateWrapper<EdTagLibrary> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(EdTagLibrary::getTagId, tagId)
|
||||
.set(EdTagLibrary::getTagName, tagName)
|
||||
.set(EdTagLibrary::getUpdatedBy, updatedBy);
|
||||
boolean isUpdated = this.update(updateWrapper);
|
||||
if (isUpdated) {
|
||||
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("更新了标签{}信息", tagName));
|
||||
UserThreadLocal.setSuccessInfo("", tagId, StrFormatter.format("更新了标签 {} 信息", tagName));
|
||||
}
|
||||
return isUpdated;
|
||||
}
|
||||
|
|
@ -318,5 +322,26 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
|||
return info;
|
||||
}).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