package org.jeecg.modules.tms.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.jeecg.common.api.vo.CommonGenericTree; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.util.StrUtils; import org.jeecg.modules.tms.entity.ToolsClassify; import org.jeecg.modules.tms.mapper.ToolsClassifyMapper; import org.jeecg.modules.tms.service.IToolsClassifyService; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import javax.tools.Tool; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Description: tms_tools_classify * @Author: jeecg-boot * @Date: 2025-05-06 * @Version: V1.0 */ @Service public class ToolsClassifyServiceImpl extends ServiceImpl implements IToolsClassifyService { @Override public IPage queryPageList(Page page, Map parameterMap) { QueryWrapper queryWrapper = Wrappers.query(); String[] classifyIds = parameterMap.get("classifyId"); if (classifyIds != null && classifyIds.length > 0) { queryWrapper.like("t.classify_id", classifyIds[0]); } String[] typeNames = parameterMap.get("typeName"); if (typeNames != null && typeNames.length > 0) { queryWrapper.like("t.type_name", typeNames[0]); } String[] parentIds = parameterMap.get("parentId"); if (parentIds != null && parentIds.length > 0) { queryWrapper.eq("t.parent_id", parentIds[0]); } queryWrapper.orderByAsc("t.seq"); return this.baseMapper.queryPageList(page, queryWrapper); } public List loadTree() { List toolsClassifyList = this.list(); List commonGenericTreeList = loadTree(toolsClassifyList); return commonGenericTreeList; } public List loadTree(List toolsClassifyList) { @SuppressWarnings("unused") ToolsClassify toolsClassify = new ToolsClassify(); List list = new ArrayList<>(); Map map = new HashMap<>(); CommonGenericTree node = new CommonGenericTree<>(); node.setKey("-1"); node.setTitle("工具分类"); node.setRField1(""); node.setRField2(""); node.setEntity(new ToolsClassify().setId("-1").setClassifyId("0").setTypeName("工具分类").setLeafFlag("2")); list.add(node); if (CollectionUtils.isNotEmpty(toolsClassifyList)) { CommonGenericTree tcNode; for (ToolsClassify tc : toolsClassifyList) { if (StrUtils.isBlankOrNull(tc.getParentId()) || tc.getParentId().equals("-1")) { tcNode = new CommonGenericTree<>(); tcNode.setKey(tc.getId()); tcNode.setTitle(tc.getClassifyId() + "/" + tc.getTypeName()); tcNode.setParentId(node.getKey()); tcNode.setIcon(""); tcNode.setType(1); tcNode.setValue(tc.getId()); tcNode.setDisabled(CommonConstant.STATUS_0.equals(tc.getStatus()) ? true : false); tcNode.setRField1(tc.getClassifyId()); tcNode.setRField2(getBaseParent(tc.getId(), 0).getClassifyId()); tcNode.setEntity(tc); node.addChildren(tcNode); map.put(tc.getId(), tcNode); } } CommonGenericTree childNode; for (ToolsClassify tc : toolsClassifyList) { ToolsClassify child = tc; if (map.containsKey(child.getParentId())) { if (StrUtils.isBlankOrNull(tc.getParentId()) || tc.getParentId().equals("-1")) { toolsClassify = tc; } else { tcNode = map.get(child.getParentId()); childNode = new CommonGenericTree<>(); childNode.setKey(tc.getId()); childNode.setTitle(tc.getClassifyId() + "/" + tc.getTypeName()); childNode.setParentId(tc.getParentId()); childNode.setIcon(""); childNode.setType(0); childNode.setValue(tc.getId()); childNode.setDisabled(CommonConstant.STATUS_0.equals(tc.getStatus()) ? true : false); childNode.setRField1(tc.getClassifyId()); childNode.setRField2(getBaseParent(tc.getId(), 0).getClassifyId()); childNode.setEntity(tc); tcNode.addChildren(childNode); map.put(child.getId(), childNode); } } } } return list; } public ToolsClassify getBaseParent(String id, int index) { ToolsClassify toolsClassify = null; if (index < 99) { toolsClassify = getById(id); if (StrUtils.isNotBlankOrNull(toolsClassify.getParentId())) { if (!toolsClassify.getParentId().equals("-1")) { toolsClassify = getBaseParent(toolsClassify.getParentId(), index++); } } } return toolsClassify; } }