package com.engine.salary.service.impl;

import com.engine.core.impl.Service;
import com.engine.salary.entity.taxagent.po.TaxAgentEmpChangePO;
import com.engine.salary.enums.taxagent.TaxAgentEmpChangeModuleEnum;
import com.engine.salary.mapper.taxagent.TaxAgentEmpChangeMapper;
import com.engine.salary.service.TaxAgentEmpChangeService;
import com.engine.salary.util.db.MapperProxyFactory;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;

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

/**
 * 个税扣缴义务人管理范围的增量人员
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public class TaxAgentEmpChangeServiceImpl extends Service implements TaxAgentEmpChangeService {

    private TaxAgentEmpChangeMapper getTaxAgentEmpChangeMapper() {
        return MapperProxyFactory.getProxy(TaxAgentEmpChangeMapper.class);
    }


    @Override
    public List<TaxAgentEmpChangePO> listAll() {
        return getTaxAgentEmpChangeMapper().listAll();
    }

    @Override
    public List<TaxAgentEmpChangePO> listAllByModule(TaxAgentEmpChangeModuleEnum moduleTypeEnum) {
        return getTaxAgentEmpChangeMapper().listSome(TaxAgentEmpChangePO.builder().moduleType(moduleTypeEnum.getValue()).build());
    }

    @Override
    public boolean deleleByIds(Collection<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return Boolean.FALSE;
        }
        List<List<Long>> partition = Lists.partition((List<Long>) ids, 1000);
        partition.forEach(getTaxAgentEmpChangeMapper()::deleteByIds);
        return Boolean.TRUE;
    }

    @Override
    public void batchInsert(List<TaxAgentEmpChangePO> taxAgentEmpChangeList) {
        List<List<TaxAgentEmpChangePO>> partition = Lists.partition(taxAgentEmpChangeList, 100);
        partition.forEach(getTaxAgentEmpChangeMapper()::batchInsert);
    }
}
