|
|
@ -1,16 +1,18 @@ |
|
|
|
package com.zc.business.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.ruoyi.common.utils.StringUtils; |
|
|
|
import com.zc.business.domain.DcDevice; |
|
|
|
import com.zc.business.domain.DcSwitch; |
|
|
|
import com.zc.business.mapper.DcDeviceMapper; |
|
|
|
import com.zc.business.mapper.DcSwitchMapper; |
|
|
|
import com.zc.business.service.DcSwitchService; |
|
|
|
import com.zc.business.service.IDcDeviceService; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
@ -42,7 +44,69 @@ public class DcSwitchServiceImpl extends ServiceImpl<DcSwitchMapper, DcSwitch> i |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<DcDevice> getDeviceList(String deviceList) { |
|
|
|
if (StringUtils.isEmpty(deviceList)) { |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
List<String> devices = Arrays.stream(deviceList.split(",")).collect(Collectors.toList()); |
|
|
|
return dcDeviceMapper.selectBatchIds(devices); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询所有数据 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<DcSwitch> getSwitchListAll() { |
|
|
|
List<DcSwitch> dcSwitches = dcSwitchMapper.getSwitchList(new DcSwitch()); |
|
|
|
List<DcSwitch> returnList = new ArrayList<>(); |
|
|
|
List<Integer> tempList = new ArrayList<>(); |
|
|
|
for (DcSwitch switche : dcSwitches) { |
|
|
|
tempList.add(switche.getSwitchId()); |
|
|
|
} |
|
|
|
for (DcSwitch switches : dcSwitches) { |
|
|
|
// 如果是顶级节点, 遍历该父节点的所有子节点
|
|
|
|
if (!tempList.contains(switches.getParentId())) { |
|
|
|
recursionFn(dcSwitches, switches); |
|
|
|
returnList.add(switches); |
|
|
|
} |
|
|
|
} |
|
|
|
if (returnList.isEmpty()) { |
|
|
|
returnList = dcSwitches; |
|
|
|
} |
|
|
|
return returnList; |
|
|
|
} |
|
|
|
|
|
|
|
private void recursionFn(List<DcSwitch> list, DcSwitch t) { |
|
|
|
// 得到子节点列表
|
|
|
|
List<DcSwitch> childList = getChildList(list, t); |
|
|
|
t.setChildren(childList); |
|
|
|
for (DcSwitch tChild : childList) { |
|
|
|
if (hasChild(list, tChild)) { |
|
|
|
recursionFn(list, tChild); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 得到子节点列表 |
|
|
|
*/ |
|
|
|
private List<DcSwitch> getChildList(List<DcSwitch> list, DcSwitch t) { |
|
|
|
List<DcSwitch> tlist = new ArrayList<>(); |
|
|
|
Iterator<DcSwitch> it = list.iterator(); |
|
|
|
while (it.hasNext()) { |
|
|
|
DcSwitch n = (DcSwitch) it.next(); |
|
|
|
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getSwitchId().longValue()) { |
|
|
|
tlist.add(n); |
|
|
|
} |
|
|
|
} |
|
|
|
return tlist; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 判断是否有子节点 |
|
|
|
*/ |
|
|
|
private boolean hasChild(List<DcSwitch> list, DcSwitch t) { |
|
|
|
return getChildList(list, t).size() > 0; |
|
|
|
} |
|
|
|
} |
|
|
|