package com.engine.salary.service.impl;

import com.engine.core.impl.Service;
import com.engine.salary.entity.salaryacct.po.SalaryAcctResultTempPO;
import com.engine.salary.mapper.salaryacct.SalaryAcctResultTempMapper;
import com.engine.salary.service.SalaryAcctResultTempService;
import com.engine.salary.util.db.MapperProxyFactory;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

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

/**
 * 薪资核算结果临时存储
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public class SalaryAcctResultTempServiceImpl extends Service implements SalaryAcctResultTempService {
    private SalaryAcctResultTempMapper getSalaryAcctResultTempMapper() {
        return MapperProxyFactory.getProxy(SalaryAcctResultTempMapper.class);
    }


    @Override
    public List<SalaryAcctResultTempPO> listByCalculateKey(String calculateKey) {

        if (StringUtils.isBlank(calculateKey)) {
            return Lists.newArrayList();
        }
        return getSalaryAcctResultTempMapper().listSome(SalaryAcctResultTempPO.builder().calculateKey(calculateKey).build());


    }

    @Override
    public void batchSave(Collection<SalaryAcctResultTempPO> salaryAcctResultTempPOS) {
        if (CollectionUtils.isNotEmpty(salaryAcctResultTempPOS)) {
            List<List<SalaryAcctResultTempPO>> partition = Lists.partition((List<SalaryAcctResultTempPO>) salaryAcctResultTempPOS, 100);
            partition.forEach(p -> getSalaryAcctResultTempMapper().batchInsert(p));
        }
    }

    @Override
    public void deleteByCalculateKey(String calculateKey) {
        getSalaryAcctResultTempMapper().deleteByCalculateKey(calculateKey);
    }
}
