123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 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<TIronStepMapper, TIronStep> {
- @Resource
- TIronStepMapper tIronStepMapper;
- @Resource
- private AsyncEventBus asyncEventBus;
- /***
- * 获取步骤及其子步骤
- * @return
- */
- public List<IronStepVO> getTreeSteps() {
- QueryWrapper<TIronStep> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(TIronStep::getStatus, "1").orderByAsc(TIronStep::getSort);
- List<TIronStep> stepList = list(queryWrapper);
- List<IronStepVO> 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<String,IronStepVO> getLinkedMapSteps(){
- // QueryWrapper<TIronStep> queryWrapper = new QueryWrapper<>();
- // queryWrapper.lambda().eq(TIronStep::getStatus, "1").orderByAsc(TIronStep::getSort);
- // List<TIronStep> stepList = list(queryWrapper);
- //
- // //将 stepList 转换为 LinkedHashMap
- // Map<String, IronStepVO> 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<String,IronStepVO> treeMap = new LinkedHashMap<>();
- //
- // String key = "";
- // for(Map.Entry<String,IronStepVO> 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);
- }
- }
|