feat:添加标签树结构的展示功能
This commit is contained in:
parent
2bd7795002
commit
9c6ababd34
|
|
@ -69,5 +69,12 @@ public class EdTagLibraryController {
|
||||||
String updatedBy = UserThreadLocal.getUserId();
|
String updatedBy = UserThreadLocal.getUserId();
|
||||||
return ElectromagneticResultUtil.success(edTagLibraryService.updateTagInfo(tagId, tagName, updatedBy));
|
return ElectromagneticResultUtil.success(edTagLibraryService.updateTagInfo(tagId, tagName, updatedBy));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查看标签树
|
||||||
|
@GetMapping ("/tree")
|
||||||
|
@UserOperation(value="查看了标签树", modelName = UserOperationModuleEnum.TAG)
|
||||||
|
public ElectromagneticResult<?> listTagTree() {
|
||||||
|
return ElectromagneticResultUtil.success(edTagLibraryService.listTagTree());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.electromagnetic.industry.software.manage.service;
|
package com.electromagnetic.industry.software.manage.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.electromagnetic.industry.software.common.pojo.TreeNode;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.EdTagLibrary;
|
import com.electromagnetic.industry.software.manage.pojo.models.EdTagLibrary;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.resp.TagListVO;
|
import com.electromagnetic.industry.software.manage.pojo.resp.TagListVO;
|
||||||
|
|
||||||
|
|
@ -56,4 +57,10 @@ public interface EdTagLibraryService extends IService<EdTagLibrary> {
|
||||||
* @return 更新结果
|
* @return 更新结果
|
||||||
*/
|
*/
|
||||||
Boolean updateTagInfo(String tagId, String tagName, String updatedBy);
|
Boolean updateTagInfo(String tagId, String tagName, String updatedBy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建标签树
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<TreeNode> listTagTree();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.electromagnetic.industry.software.common.enums.PublishEnum;
|
import com.electromagnetic.industry.software.common.enums.PublishEnum;
|
||||||
import com.electromagnetic.industry.software.common.enums.TagTypeEnum;
|
import com.electromagnetic.industry.software.common.enums.TagTypeEnum;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
|
import com.electromagnetic.industry.software.common.pojo.TreeNode;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.IdWorker;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.EdTagLibraryMapper;
|
import com.electromagnetic.industry.software.manage.mapper.EdTagLibraryMapper;
|
||||||
|
|
@ -146,24 +147,15 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
public Boolean batchPublishTagGroups(List<String> tagGroupIds) {
|
public Boolean batchPublishTagGroups(List<String> tagGroupIds) {
|
||||||
|
|
||||||
Assert.notEmpty(tagGroupIds, "参数 tagGroupIds 不能为空");
|
Assert.notEmpty(tagGroupIds, "参数 tagGroupIds 不能为空");
|
||||||
boolean groupUpdated = this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
||||||
.in(EdTagLibrary::getTagId, tagGroupIds)
|
.in(EdTagLibrary::getTagId, tagGroupIds)
|
||||||
.eq(EdTagLibrary::getType, TagTypeEnum.GROUP.getCode()) // 只更新标签组
|
.eq(EdTagLibrary::getType, TagTypeEnum.GROUP.getCode()) // 只更新标签组
|
||||||
.set(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode()));
|
.set(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode()));
|
||||||
|
|
||||||
if (!groupUpdated) {
|
this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
||||||
throw new BizException("发布标签组失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean tagUpdated = this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
|
||||||
.in(EdTagLibrary::getParentId, tagGroupIds) // 父 ID 是传入的标签组
|
.in(EdTagLibrary::getParentId, tagGroupIds) // 父 ID 是传入的标签组
|
||||||
.eq(EdTagLibrary::getType, TagTypeEnum.TAG.getCode()) // 只更新标签
|
.eq(EdTagLibrary::getType, TagTypeEnum.TAG.getCode()) // 只更新标签
|
||||||
.set(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode()));
|
.set(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode()));
|
||||||
|
|
||||||
if (!tagUpdated) {
|
|
||||||
throw new RuntimeException("发布标签失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
UserThreadLocal.setSuccessInfo("", "", "发布了标签");
|
UserThreadLocal.setSuccessInfo("", "", "发布了标签");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -264,5 +256,49 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
this.update(updateWrapper);
|
this.update(updateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建标签树
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<TreeNode> listTagTree() {
|
||||||
|
|
||||||
|
LambdaQueryWrapper<EdTagLibrary> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode());
|
||||||
|
List<EdTagLibrary> tags = this.list(queryWrapper);
|
||||||
|
Map<String, TreeNode> map = new HashMap<>();
|
||||||
|
List<TreeNode> list = new ArrayList<>();
|
||||||
|
|
||||||
|
for (EdTagLibrary tag : tags) {
|
||||||
|
TreeNode node = null;
|
||||||
|
if (tag.getType().equals(TagTypeEnum.GROUP.getCode())) {
|
||||||
|
node = TreeNode.builder()
|
||||||
|
.title(tag.getTagName())
|
||||||
|
.key(tag.getTagId())
|
||||||
|
.children(new ArrayList<>())
|
||||||
|
.build();
|
||||||
|
} else if(tag.getType().equals(TagTypeEnum.TAG.getCode())) {
|
||||||
|
node = TreeNode.builder()
|
||||||
|
.title(tag.getTagName())
|
||||||
|
.key(tag.getTagId())
|
||||||
|
.children(null)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
map.put(tag.getTagId(), node);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (EdTagLibrary tag : tags) {
|
||||||
|
if (tag.getType().equals(TagTypeEnum.GROUP.getCode())) {
|
||||||
|
list.add(map.get(tag.getTagId()));
|
||||||
|
} else if (tag.getType().equals(TagTypeEnum.TAG.getCode())) {
|
||||||
|
TreeNode parentNode = map.get(tag.getParentId());
|
||||||
|
if (parentNode != null) {
|
||||||
|
parentNode.getChildren().add(map.get(tag.getTagId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -361,16 +361,9 @@ public class UserServiceImpl implements UserService {
|
||||||
@Override
|
@Override
|
||||||
public ElectromagneticResult<?> validateOldPassword(String userId, String oldInputPassword) {
|
public ElectromagneticResult<?> validateOldPassword(String userId, String oldInputPassword) {
|
||||||
|
|
||||||
// To lzh: UserId可以从UserThreadLocal中获取
|
|
||||||
// To lzh:代码可以尽量简洁,避免过多的嵌套和逻辑判断,注释也不用写太多,简单的逻辑简单处理
|
|
||||||
|
|
||||||
User user = userMapper.getSingleUser(userId);
|
User user = userMapper.getSingleUser(userId);
|
||||||
Assert.notNull(user, StrFormatter.format("用户不存在,ID为 {}", userId));
|
Assert.notNull(user, StrFormatter.format("用户不存在,ID为 {}", userId));
|
||||||
String decodeOldPwd = AESUtils.decrypt(oldInputPassword, UserConstants.SECRET_KEY);
|
String decodeOldPwd = AESUtils.decrypt(oldInputPassword, UserConstants.SECRET_KEY);
|
||||||
|
|
||||||
// if (!user.getUserPwd().equals(SignUtils.MD5(decodeOldPwd + user.getSalt()))) {
|
|
||||||
// return ElectromagneticResultUtil.fail("53107", "OLD_PASSWORD_INCORRECT");
|
|
||||||
// }
|
|
||||||
Assert.isTrue(matchPassword(user,decodeOldPwd), StrFormatter.format("旧密码错误,ID为 {}", userId));
|
Assert.isTrue(matchPassword(user,decodeOldPwd), StrFormatter.format("旧密码错误,ID为 {}", userId));
|
||||||
return ElectromagneticResultUtil.success(true);
|
return ElectromagneticResultUtil.success(true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.electromagnetic.industry.software.common.pojo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class TreeNode {
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
private List<TreeNode> children;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue