package com.engine.salary.service.impl;

import com.engine.core.impl.Service;
import com.engine.salary.entity.salaryacct.po.SalaryAcctResultLogPO;
import com.engine.salary.mapper.salaryacct.SalaryAcctResultLogMapper;
import com.engine.salary.service.SalaryAcctResultLogService;
import com.engine.salary.util.db.MapperProxyFactory;
import com.google.common.collect.Lists;

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

/**
 * @author Harryxzy
 * @date 2023/05/12 15:29
 * @description
 */
public class SalaryAcctResultLogServiceImpl extends Service implements SalaryAcctResultLogService {

    private SalaryAcctResultLogMapper getSalaryAcctResultLogMapper() {
        return MapperProxyFactory.getProxy(SalaryAcctResultLogMapper.class);
    }

    @Override
    public List<SalaryAcctResultLogPO> listAll() {
        return getSalaryAcctResultLogMapper().listAll();
    }

    @Override
    public SalaryAcctResultLogPO getById(Long id) {
        return getSalaryAcctResultLogMapper().getById(id);
    }

    @Override
    public int insertIgnoreNull(SalaryAcctResultLogPO salaryAcctResultLog) {
        return  getSalaryAcctResultLogMapper().insertIgnoreNull(salaryAcctResultLog);
    }


    @Override
    public int update(SalaryAcctResultLogPO salaryAcctResultLog) {
        return getSalaryAcctResultLogMapper().update(salaryAcctResultLog);
    }

    @Override
    public int updateIgnoreNull(SalaryAcctResultLogPO salaryAcctResultLog) {
        return getSalaryAcctResultLogMapper().updateIgnoreNull(salaryAcctResultLog);
    }

    @Override
    public int delete(SalaryAcctResultLogPO salaryAcctResultLog) {
        return getSalaryAcctResultLogMapper().delete(salaryAcctResultLog);
    }

    @Override
    public void batchInsert(List<SalaryAcctResultLogPO> salaryAcctResultLogList) {
        List<List<SalaryAcctResultLogPO>> partition = Lists.partition(salaryAcctResultLogList, 50);
        partition.forEach(getSalaryAcctResultLogMapper()::batchInsert);
    }

    @Override
    public void deleteBySalaryAcctEmpIdExceptItemIds(List<Long> salaryAcctEmployeeIds, Collection<Long> lockSalaryItemIds) {
        // 分片
        List<List<Long>> partition = Lists.partition(salaryAcctEmployeeIds, 50);
        partition.forEach(part -> {
            getSalaryAcctResultLogMapper().deleteBySalaryAcctEmpIdExceptItemIds(part,lockSalaryItemIds, new Date());
        });
    }
}
