/**
 * Project Name : 전사 법무/계약관리시스템 개선
 * File Name    : DeptDao.java
 * Description  : Dept 관련 서비스
 * Author       : 정성호(jsh)
 * Date         : 2023.04.19 - 부서정보 Migration및 조회
 * Copyright 	: 2023 by SAMSUNG. All rights reserved.
 */
package com.samsung.embo.common.dept.dao;


import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.samsung.embo.common.dept.dto.DeptVO;



@Repository
public class DeptDao {

	/**
	 * SqlSession
	 */
	@Autowired
	private SqlSession sqlSession;

    public List<Map<String, Object>> getDeptTree(DeptVO vo){
        return sqlSession.selectList("dept.selectDeptTree", vo);
    }

    public int deleteTnInfHrDept() {
        return sqlSession.delete("dept.deleteTnInfHrDept");
    }

    public int deleteComDept() {
        return sqlSession.delete("dept.deleteComDept");
    }

   

    public int insertTnInfHrDept(List list) {
    	int skip = 0;
        int limit = 50;
        int iValue = 0;
        while (skip < list.size()) {
        	final List perRequests = (List) list
                            .stream()
                            .skip(skip)
                            .limit(limit)
                            .collect(Collectors.toList());
                            
            skip += limit;
            
            iValue += sqlSession.insert("dept.insertTnInfHrDept", perRequests);
        }
        
        return iValue;
    }

    public int insertComDept() {
        return sqlSession.insert("dept.insertComDept");
    }

    public int insertEtcDept() {
    	return sqlSession.insert("dept.insertEtcDept");
    }
}
