Browse Source

修改交换机网络状态定时任务

develop
Mr.Wang 7 months ago
parent
commit
fbb5a1b76d
  1. 4
      zc-business/src/main/java/com/zc/business/controller/DcSwitchController.java
  2. 20
      zc-business/src/main/resources/mapper/business/DcSwitchMapper.xml

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

@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -71,7 +72,7 @@ public class DcSwitchController extends BaseController {
ExecutorService executor = Executors.newFixedThreadPool(100); ExecutorService executor = Executors.newFixedThreadPool(100);
List<DcSwitch> collect = switchList.stream() List<DcSwitch> collect = switchList.stream()
.filter(dcSwitch -> { .filter(dcSwitch -> {
return dcSwitch.getAncestors().split(",").length > 1; return dcSwitch.getParentId() != null;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
CountDownLatch latch = new CountDownLatch(collect.size()); CountDownLatch latch = new CountDownLatch(collect.size());
collect.forEach(dcSwitch -> { collect.forEach(dcSwitch -> {
@ -85,6 +86,7 @@ public class DcSwitchController extends BaseController {
// 失败 // 失败
dcSwitch.setNetWorkStatus(0); dcSwitch.setNetWorkStatus(0);
} }
dcSwitch.setUpdateTime(new Date());
} catch (IOException e) { } catch (IOException e) {
e.getMessage(); e.getMessage();
} finally { } finally {

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

@ -45,11 +45,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<update id="updateBatchByNetWorkStatus" parameterType="List"> <update id="updateBatchByNetWorkStatus" parameterType="List">
update dc_switch set netWork_status = update dc_switch
<foreach collection="list" item="item" index="index" <trim prefix="set" suffixOverrides=",">
separator=" " open="case switch_id" close="end"> <trim prefix="netWork_status =case" suffix="end,">
when #{item.switchId} then #{item.netWorkStatus} <foreach collection="list" item="item" index="index">
</foreach> when switch_id=#{item.switchId}
then #{item.netWorkStatus}
</foreach>
</trim>
<trim prefix="update_time =case" suffix="end,">
<foreach collection="list" item="item" index="index">
when switch_id=#{item.switchId}
then #{item.updateTime}
</foreach>
</trim>
</trim>
where switch_id in where switch_id in
<foreach collection="list" item="item" index="index" <foreach collection="list" item="item" index="index"
separator="," open="(" close=")"> separator="," open="(" close=")">

Loading…
Cancel
Save