package com.css.simulation.resource.monitor.domain;

import api.common.pojo.po.home.SystemServerPO;
import com.css.simulation.resource.monitor.infra.mysql.mapper.SystemServerMapper;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SystemServerDomainService {


    @Resource
    private SqlSessionFactory sqlSessionFactory;

    public void deleteAndInsert(List<SystemServerPO> systemServerPOList) {

        try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
            SystemServerMapper systemServerMapper = sqlSession.getMapper(SystemServerMapper.class);
            systemServerMapper.delete();
            for (SystemServerPO systemServerPO : systemServerPOList) {
                systemServerMapper.insert(systemServerPO);
            }
            sqlSession.commit();
        }
    }
}
