package org.framework.lazy.cloud.network.heartbeat.server.init;


import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.entity.*;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;

import java.util.List;

/**
 * 数据修改
 */
@Component
public class ChangeDataInit implements CommandLineRunner {

    private final LazyLambdaStream lazyLambdaStream;

    public ChangeDataInit(LazyLambdaStream lazyLambdaStream) {
        this.lazyLambdaStream = lazyLambdaStream;
    }

    @Override
    public void run(String... args) throws Exception {
        // 服务端渗透客户端 统计数
        Long serverPermeateClientCount = lazyLambdaStream.count(LazyWrappers.<LazyInternalNetworkServerPermeateClientMappingDO>lambdaWrapper().notNull(LazyInternalNetworkServerPermeateClientMappingDO::getId));
        if (serverPermeateClientCount == 0) {
            // 同步数据
            List<LazyInternalNetworkServerPermeateClientMappingDO> list = lazyLambdaStream.selectList(LazyWrappers.<LazyInternalNetworkPenetrationMappingDO>lambdaWrapper().notNull(LazyInternalNetworkPenetrationMappingDO::getId), LazyInternalNetworkServerPermeateClientMappingDO.class);
            lazyLambdaStream.insert(list);
        }

        // 服务端渗透服务端 统计数
        Long serverPermeateServerCount = lazyLambdaStream.count(LazyWrappers.<LazyInternalNetworkServerPermeateServerMappingDO>lambdaWrapper().notNull(LazyInternalNetworkServerPermeateServerMappingDO::getId));
        if (serverPermeateServerCount == 0) {
            // 同步数据
            List<LazyInternalNetworkServerPermeateServerMappingDO> list = lazyLambdaStream.selectList(LazyWrappers.<LazyInternalNetworkServerPermeateMappingDO>lambdaWrapper().notNull(LazyInternalNetworkServerPermeateMappingDO::getId), LazyInternalNetworkServerPermeateServerMappingDO.class);
            lazyLambdaStream.insert(list);
        }

        // 服务端渗透服务端 统计数
        Long lazyNettyServerPermeatePortPoolCount = lazyLambdaStream.count(LazyWrappers.<LazyNettyServerPermeatePortPoolDO>lambdaWrapper().notNull(LazyNettyServerPermeatePortPoolDO::getId));
        if (lazyNettyServerPermeatePortPoolCount == 0) {
            // 同步数据
            List<LazyNettyServerPermeatePortPoolDO> list = lazyLambdaStream.selectList(LazyWrappers.<LazyNettyServerVisitorDO>lambdaWrapper().notNull(LazyNettyServerVisitorDO::getId), LazyNettyServerPermeatePortPoolDO.class);
            lazyLambdaStream.insert(list);
        }

    }
}
