package com.engine.salary.biz;

import com.engine.salary.entity.salarysob.po.SalarySobDefaultEmpFieldPO;
import com.engine.salary.entity.salarysob.po.SalarySobEmpFieldPO;
import com.engine.salary.mapper.salarysob.SalarySobDefaultEmpFieldMapper;
import com.engine.salary.mapper.salarysob.SalarySobEmpFieldMapper;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.ibatis.session.SqlSession;
import weaver.conn.mybatis.MyBatisFactory;

import java.util.Collection;
import java.util.List;

public class SalarySobEmpFieldBiz {


    public List<SalarySobEmpFieldPO> listSome(SalarySobEmpFieldPO build) {

        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobEmpFieldMapper mapper = sqlSession.getMapper(SalarySobEmpFieldMapper.class);
            return mapper.listSome(build);

        } finally {
            sqlSession.close();
        }
    }

    public void batchInsert(Collection<SalarySobEmpFieldPO> salarySobEmpFieldPOS) {
        if (CollectionUtils.isEmpty(salarySobEmpFieldPOS)) {
            return;
        }
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobEmpFieldMapper mapper = sqlSession.getMapper(SalarySobEmpFieldMapper.class);
            List<List<SalarySobEmpFieldPO>> partition = Lists.partition((List) salarySobEmpFieldPOS, 100);
            partition.forEach(mapper::batchInsert);
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }

    public void deleteBySalarySobIds(Collection<Long> salarySobIds) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobEmpFieldMapper mapper = sqlSession.getMapper(SalarySobEmpFieldMapper.class);
            mapper.deleteBySalarySobIds(salarySobIds);
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }


    public void deleteByIds(Collection<Long> ids) {

        if (CollectionUtils.isEmpty(ids)) {
            return;
        }

        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobEmpFieldMapper mapper = sqlSession.getMapper(SalarySobEmpFieldMapper.class);
            mapper.deleteByIds(ids);
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }


    //---------------------------系统默认员工信息字段-----------------------------------

    public List<SalarySobDefaultEmpFieldPO> listDefaultEmpField() {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySobDefaultEmpFieldMapper mapper = sqlSession.getMapper(SalarySobDefaultEmpFieldMapper.class);
            return mapper.listAll();
        } finally {
            sqlSession.close();
        }
    }



}
