TIronStepServiceImpl.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.sckj.iron.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.google.common.eventbus.AsyncEventBus;
  5. import com.sckj.iron.entity.TIronStep;
  6. import com.sckj.iron.mapper.TIronStepMapper;
  7. import com.sckj.iron.vo.IronStepVO;
  8. import org.apache.commons.lang3.ObjectUtils;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.springframework.beans.BeanUtils;
  11. import org.springframework.stereotype.Service;
  12. import javax.annotation.Resource;
  13. import java.util.ArrayList;
  14. import java.util.LinkedHashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.stream.Collectors;
  18. /**
  19. * 出铁步骤配置实现类
  20. *
  21. * @author LikeAdmin
  22. */
  23. @Service
  24. public class TIronStepServiceImpl extends ServiceImpl<TIronStepMapper, TIronStep> {
  25. @Resource
  26. TIronStepMapper tIronStepMapper;
  27. @Resource
  28. private AsyncEventBus asyncEventBus;
  29. /***
  30. * 获取步骤及其子步骤
  31. * @return
  32. */
  33. public List<IronStepVO> getTreeSteps() {
  34. QueryWrapper<TIronStep> queryWrapper = new QueryWrapper<>();
  35. queryWrapper.lambda().eq(TIronStep::getStatus, "1").orderByAsc(TIronStep::getSort);
  36. List<TIronStep> stepList = list(queryWrapper);
  37. List<IronStepVO> stepDTOList = new ArrayList<>();
  38. IronStepVO stepDTO = null;
  39. for (TIronStep step : stepList) {
  40. if (step.getStepId().length() == 3) {
  41. stepDTO = new IronStepVO();
  42. stepDTO.setChilds(new ArrayList<>());
  43. BeanUtils.copyProperties(step, stepDTO);
  44. stepDTOList.add(stepDTO);
  45. } else {
  46. if (ObjectUtils.isNotEmpty(stepDTO) && StringUtils.startsWith(step.getStepId(), stepDTO.getStepId())) {
  47. IronStepVO stepChildDTO = new IronStepVO();
  48. BeanUtils.copyProperties(step, stepChildDTO);
  49. stepDTO.getChilds().add(stepChildDTO);
  50. }
  51. }
  52. }
  53. return stepDTOList;
  54. }
  55. // public Map<String,IronStepVO> getLinkedMapSteps(){
  56. // QueryWrapper<TIronStep> queryWrapper = new QueryWrapper<>();
  57. // queryWrapper.lambda().eq(TIronStep::getStatus, "1").orderByAsc(TIronStep::getSort);
  58. // List<TIronStep> stepList = list(queryWrapper);
  59. //
  60. // //将 stepList 转换为 LinkedHashMap
  61. // Map<String, IronStepVO> stepMap = stepList.stream()
  62. // .map(step->{
  63. // IronStepVO vo = new IronStepVO();
  64. // BeanUtils.copyProperties(step, vo);
  65. // return vo;
  66. // })
  67. // .collect(Collectors.toMap(
  68. // IronStepVO::getStepId,
  69. // step -> step,
  70. // (existing, replacement) -> existing,
  71. // LinkedHashMap::new
  72. // ));
  73. //
  74. // Map<String,IronStepVO> treeMap = new LinkedHashMap<>();
  75. //
  76. // String key = "";
  77. // for(Map.Entry<String,IronStepVO> entry: stepMap.entrySet()){
  78. // IronStepVO step = entry.getValue();
  79. // if (step.getStepId().length() == 3) {
  80. // key = entry.getKey();
  81. // step.setChilds(new LinkedHashMap<>());
  82. // treeMap.put(key,step);
  83. //// stepDTO = new IronStepVO();
  84. //// stepDTO.setChilds(new ArrayList<>());
  85. //// BeanUtils.copyProperties(step, stepDTO);
  86. //// stepDTOList.add(stepDTO);
  87. // } else {
  88. // treeMap.get(key).getChilds().put(entry.getKey(),entry.getValue());
  89. //// if (ObjectUtils.isNotEmpty(stepDTO) && StringUtils.startsWith(step.getStepId(), stepDTO.getStepId())) {
  90. //// IronStepVO stepChildDTO = new IronStepVO();
  91. //// BeanUtils.copyProperties(step, stepChildDTO);
  92. //// stepDTO.getChilds().add(stepChildDTO);
  93. //// }
  94. // }
  95. // }
  96. //
  97. //
  98. // return stepMap;
  99. //
  100. // }
  101. public void refreshTreeSteps() {
  102. asyncEventBus.post(Boolean.TRUE);
  103. }
  104. }