|
|
@@ -13,10 +13,7 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -126,48 +123,33 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
|
|
|
*/
|
|
|
@Override
|
|
|
public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(List<IotSfElementfactor> factorList) {
|
|
|
- Map<String, IotSfElementfactorAlreadyListResVo> eleMap = new LinkedHashMap<>();
|
|
|
- Map<String, IotSfElementfactor> tempMap = new LinkedHashMap<>();
|
|
|
-
|
|
|
- for (IotSfElementfactor elementfactor : factorList) {
|
|
|
- String sfBid = elementfactor.getSfBid();
|
|
|
- tempMap.put(sfBid, elementfactor);
|
|
|
- }
|
|
|
|
|
|
+ Map<String, IotSfElementfactorAlreadyListResVo> resultMap = new LinkedHashMap<>();
|
|
|
for (IotSfElementfactor elementfactor : factorList) {
|
|
|
String sfBid = elementfactor.getSfBid();
|
|
|
String sfParentBid = elementfactor.getSfParentBid();
|
|
|
-
|
|
|
IotSfElementfactorAlreadyListResVo eleResVo = new IotSfElementfactorAlreadyListResVo();
|
|
|
BeanUtils.copyProperties(elementfactor, eleResVo);
|
|
|
-
|
|
|
- // 表示是一级元素,直接添加
|
|
|
- if(StringUtils.isEmpty(sfParentBid) && !eleMap.containsKey(sfBid)){
|
|
|
+ if(StringUtils.isEmpty(sfParentBid)){
|
|
|
eleResVo.setChildrenList(new ArrayList<>());
|
|
|
- eleMap.put(sfBid, eleResVo);
|
|
|
- }else{
|
|
|
- // 表示不是一级元素,需要判断父元素是否已经存在
|
|
|
- IotSfElementfactorAlreadyListResVo parentInfo = eleMap.get(sfParentBid);
|
|
|
- // 如果父类已经添加,直接添加到父类的childrenList中
|
|
|
- if(parentInfo != null){
|
|
|
- parentInfo.getChildrenList().add(eleResVo);
|
|
|
- }else{
|
|
|
- // 如果父类没有添加,需要先添加父类,再添加当前元素
|
|
|
- IotSfElementfactor parentElement = tempMap.get(sfParentBid);
|
|
|
- // 如果父类不存在,直接跳过
|
|
|
- if(parentElement == null){
|
|
|
- continue;
|
|
|
- }
|
|
|
- IotSfElementfactorAlreadyListResVo parentReq = new IotSfElementfactorAlreadyListResVo();
|
|
|
- BeanUtils.copyProperties(parentElement, parentReq);
|
|
|
- parentReq.setChildrenList(new ArrayList<>());
|
|
|
+ resultMap.put(sfBid, eleResVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- parentReq.getChildrenList().add(eleResVo);
|
|
|
- eleMap.put(sfParentBid, parentReq);
|
|
|
- }
|
|
|
+ for (IotSfElementfactor elementfactor : factorList) {
|
|
|
+ String sfParentBid = elementfactor.getSfParentBid();
|
|
|
+ if(StringUtils.isEmpty(sfParentBid)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ IotSfElementfactorAlreadyListResVo parentInfo = resultMap.get(sfParentBid);
|
|
|
+ if(parentInfo == null){
|
|
|
+ continue;
|
|
|
}
|
|
|
+ IotSfElementfactorAlreadyListResVo childResVo = new IotSfElementfactorAlreadyListResVo();
|
|
|
+ BeanUtils.copyProperties(elementfactor, childResVo);
|
|
|
+ parentInfo.getChildrenList().add(childResVo);
|
|
|
}
|
|
|
- return new ArrayList<>(eleMap.values());
|
|
|
+ return new ArrayList<>(resultMap.values());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -244,31 +226,4 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
|
|
|
List<IotSfElementfactor> elementfactorList = selectIotSfElementfactorList(reqVo);
|
|
|
return getAlreadyElementList(elementfactorList);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询电磁阀已配置要素列表
|
|
|
- *
|
|
|
- * @param reqVo
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<IotSfElementfactorAlreadyListResVo> getValveAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
|
|
|
- List<IotSfElementfactor> elementfactorList = selectIotSfElementfactorListByValve(reqVo);
|
|
|
- return getAlreadyElementList(elementfactorList);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询已配置要素列表
|
|
|
- *
|
|
|
- * @param sfBid@return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public IotSfElementfactorAlreadyListResVo getAlreadyElementByBid(String sfBid) {
|
|
|
- List<IotSfElementfactor> elementfactorList = iotSfElementfactorMapper.getAlreadyElementByBid(sfBid);
|
|
|
- List<IotSfElementfactorAlreadyListResVo> alreadyElementList = getAlreadyElementList(elementfactorList);
|
|
|
- if(alreadyElementList != null && !alreadyElementList.isEmpty()){
|
|
|
- return alreadyElementList.get(0);
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
}
|