package com.sckj.iron.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.eventbus.AsyncEventBus; import com.sckj.iron.entity.TIronStep; import com.sckj.iron.mapper.TIronStepMapper; import com.sckj.iron.vo.IronStepVO; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * 出铁步骤配置实现类 * * @author LikeAdmin */ @Service public class TIronStepServiceImpl extends ServiceImpl { @Resource TIronStepMapper tIronStepMapper; @Resource private AsyncEventBus asyncEventBus; /*** * 获取步骤及其子步骤 * @return */ public List getTreeSteps() { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(TIronStep::getStatus, "1").orderByAsc(TIronStep::getSort); List stepList = list(queryWrapper); List stepDTOList = new ArrayList<>(); IronStepVO stepDTO = null; for (TIronStep step : stepList) { if (step.getStepId().length() == 3) { stepDTO = new IronStepVO(); stepDTO.setChilds(new ArrayList<>()); BeanUtils.copyProperties(step, stepDTO); stepDTOList.add(stepDTO); } else { if (ObjectUtils.isNotEmpty(stepDTO) && StringUtils.startsWith(step.getStepId(), stepDTO.getStepId())) { IronStepVO stepChildDTO = new IronStepVO(); BeanUtils.copyProperties(step, stepChildDTO); stepDTO.getChilds().add(stepChildDTO); } } } return stepDTOList; } // public Map getLinkedMapSteps(){ // QueryWrapper queryWrapper = new QueryWrapper<>(); // queryWrapper.lambda().eq(TIronStep::getStatus, "1").orderByAsc(TIronStep::getSort); // List stepList = list(queryWrapper); // // //将 stepList 转换为 LinkedHashMap // Map stepMap = stepList.stream() // .map(step->{ // IronStepVO vo = new IronStepVO(); // BeanUtils.copyProperties(step, vo); // return vo; // }) // .collect(Collectors.toMap( // IronStepVO::getStepId, // step -> step, // (existing, replacement) -> existing, // LinkedHashMap::new // )); // // Map treeMap = new LinkedHashMap<>(); // // String key = ""; // for(Map.Entry entry: stepMap.entrySet()){ // IronStepVO step = entry.getValue(); // if (step.getStepId().length() == 3) { // key = entry.getKey(); // step.setChilds(new LinkedHashMap<>()); // treeMap.put(key,step); //// stepDTO = new IronStepVO(); //// stepDTO.setChilds(new ArrayList<>()); //// BeanUtils.copyProperties(step, stepDTO); //// stepDTOList.add(stepDTO); // } else { // treeMap.get(key).getChilds().put(entry.getKey(),entry.getValue()); //// if (ObjectUtils.isNotEmpty(stepDTO) && StringUtils.startsWith(step.getStepId(), stepDTO.getStepId())) { //// IronStepVO stepChildDTO = new IronStepVO(); //// BeanUtils.copyProperties(step, stepChildDTO); //// stepDTO.getChilds().add(stepChildDTO); //// } // } // } // // // return stepMap; // // } public void refreshTreeSteps() { asyncEventBus.post(Boolean.TRUE); } }