Browse Source

交换机增加查询所有数据

develop
Mr.Wang 7 months ago
parent
commit
315cc01f40
  1. 9
      zc-business/src/main/java/com/zc/business/controller/DcSwitchController.java
  2. 3
      zc-business/src/main/java/com/zc/business/domain/DcSwitch.java
  3. 6
      zc-business/src/main/java/com/zc/business/service/DcSwitchService.java
  4. 66
      zc-business/src/main/java/com/zc/business/service/impl/DcSwitchServiceImpl.java
  5. 2
      zc-business/src/main/resources/mapper/business/DcSwitchMapper.xml

9
zc-business/src/main/java/com/zc/business/controller/DcSwitchController.java

@ -43,4 +43,13 @@ public class DcSwitchController extends BaseController {
public AjaxResult getDeviceList(@PathVariable String deviceList) {
return AjaxResult.success(dcSwitchService.getDeviceList(deviceList));
}
/**
* 查询所有数据
* @return
*/
@GetMapping("/list")
public AjaxResult getSwitchListAll() {
return AjaxResult.success(dcSwitchService.getSwitchListAll());
}
}

3
zc-business/src/main/java/com/zc/business/domain/DcSwitch.java

@ -9,6 +9,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
/**
* 交换机对象 dc_switch
@ -94,5 +95,7 @@ public class DcSwitch {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date updateTime;
private List<DcSwitch> children;
}

6
zc-business/src/main/java/com/zc/business/service/DcSwitchService.java

@ -22,4 +22,10 @@ public interface DcSwitchService {
* 根据设备列表查询设备
*/
List<DcDevice> getDeviceList(String deviceList);
/**
* 查询所有数据
* @return
*/
List<DcSwitch> getSwitchListAll();
}

66
zc-business/src/main/java/com/zc/business/service/impl/DcSwitchServiceImpl.java

@ -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;
}
}

2
zc-business/src/main/resources/mapper/business/DcSwitchMapper.xml

@ -35,9 +35,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getSwitchList" parameterType="DcSwitch" resultType="DcSwitch">
<include refid="selectDcSwitchVo"/>
<where>
user_state = 1
<if test="parentId != null ">and parent_id = #{parentId}</if>
</where>
and user_state = 1
</select>
</mapper>

Loading…
Cancel
Save