package com.engine.salary.biz;

import com.engine.salary.entity.salaryBill.dto.SalarySendListDTO;
import com.engine.salary.entity.salaryBill.param.SalarySendQueryParam;
import com.engine.salary.entity.salaryBill.po.SalarySendPO;
import com.engine.salary.mapper.salarybill.SalarySendMapper;
import org.apache.ibatis.session.SqlSession;
import weaver.conn.mybatis.MyBatisFactory;

import java.util.List;
import java.util.Map;

public class SalarySendBiz {
    /**
     * 根据id获取数据
     * @param id
     * @return
     */
    public SalarySendPO getById(Long id) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySendMapper mapper = sqlSession.getMapper(SalarySendMapper.class);
            return mapper.getById(id);
        } finally {
            sqlSession.close();
        }
    }


    /**
     * 更新
     * @param salarySendNew
     */
    public void updateById(SalarySendPO salarySendNew) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySendMapper mapper = sqlSession.getMapper(SalarySendMapper.class);
            mapper.updateIgnoreNull(salarySendNew);
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }

    /**
     * 根据查询条件查询
     * @param condition
     */
    public List<SalarySendPO> listSomeWithCondition(Map<String, Object> condition) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySendMapper mapper = sqlSession.getMapper(SalarySendMapper.class);
            return mapper.listSomeWithCondition(condition);
        } finally {
            sqlSession.close();
        }
    }

    /**
     * 根据现有字段查询
     * @return
     */
    public List<SalarySendPO> listSome(SalarySendPO po) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySendMapper mapper = sqlSession.getMapper(SalarySendMapper.class);
            return mapper.listSome(po);
        } finally {
            sqlSession.close();
        }
    }


    /**
     * 工资单发放列表（分页）
     * @param queryParam
     * @return
     */
    public List<SalarySendListDTO> list(SalarySendQueryParam queryParam) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySendMapper mapper = sqlSession.getMapper(SalarySendMapper.class);
            return mapper.list(queryParam);
        } finally {
            sqlSession.close();
        }
    }

    public void insert(SalarySendPO salarySend) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySendMapper mapper = sqlSession.getMapper(SalarySendMapper.class);
            mapper.insertIgnoreNull(salarySend);
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }

    public void batchHandleSendStatusHistory() {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySendMapper mapper = sqlSession.getMapper(SalarySendMapper.class);
            mapper.batchHandleSendStatusHistory();
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }

    public void batchHandleSalaryAcctTypeHistory() {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            SalarySendMapper mapper = sqlSession.getMapper(SalarySendMapper.class);
            mapper.batchHandleSalaryAcctTypeHistory();
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }
}
