package com.engine.salary.service.impl;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import com.engine.salary.entity.employeedeclare.po.EmployeeDeclarePO;
import com.engine.salary.entity.extemp.po.ExtEmpPO;
import com.engine.salary.entity.taxdeclaration.bo.TaxDeclareEmployeeBO;
import com.engine.salary.entity.taxdeclaration.dto.AbnormalEmployeeListDTO;
import com.engine.salary.entity.taxdeclaration.param.AbnormalEmployeeListQueryParam;
import com.engine.salary.entity.taxdeclaration.po.TaxDeclareEmployeePO;
import com.engine.salary.entity.taxdeclaration.po.TaxDeclareRecordPO;
import com.engine.salary.enums.salaryaccounting.EmployeeTypeEnum;
import com.engine.salary.mapper.taxdeclaration.TaxDeclarationValueMapper;
import com.engine.salary.service.EmployeeDeclareService;
import com.engine.salary.service.ExtEmpService;
import com.engine.salary.service.SalaryEmployeeService;
import com.engine.salary.service.TaxDeclareEmployeeService;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.db.MapperProxyFactory;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
import org.apache.commons.collections4.CollectionUtils;
import weaver.hrm.User;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 个税申报表明细中的人员
*
Copyright: Copyright (c) 2023
* Company: 泛微软件
*
* @author qiantao
* @version 1.0
**/
public class TaxDeclareEmployeeServiceImpl extends Service implements TaxDeclareEmployeeService {
private TaxDeclarationValueMapper getTaxDeclarationValueMapper() {
return MapperProxyFactory.getProxy(TaxDeclarationValueMapper.class);
}
private SalaryEmployeeService getSalaryEmployeeService(User user) {
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
}
private ExtEmpService getExtEmpService(User user) {
return ServiceUtil.getService(ExtEmpServiceImpl.class, user);
}
private EmployeeDeclareService getEmployeeDeclareService(User user) {
return ServiceUtil.getService(EmployeeDeclareServiceImpl.class, user);
}
@Override
public PageInfo listPage4NotDeclareByParam(AbnormalEmployeeListQueryParam queryParam) {
List list = getTaxDeclarationValueMapper().listPage4NotDeclareByParam(queryParam);
return SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), list, TaxDeclareEmployeePO.class);
}
@Override
public List list4NotDeclareByParam(AbnormalEmployeeListQueryParam queryParam) {
return getTaxDeclarationValueMapper().list4NotDeclareByParam(queryParam);
}
@Override
public PageInfo listPage4NoValueByParam(AbnormalEmployeeListQueryParam queryParam) {
List list = getTaxDeclarationValueMapper().listPage4NoValueByParam(queryParam);
return SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), list, TaxDeclareEmployeePO.class);
}
@Override
public List list4NoValueByParam(AbnormalEmployeeListQueryParam queryParam) {
return getTaxDeclarationValueMapper().list4NoValueByParam(queryParam);
}
@Override
public List convert2AbnormalEmployeeList(TaxDeclareRecordPO taxDeclareRecord, List taxDeclareEmployees) {
if (CollectionUtils.isEmpty(taxDeclareEmployees)) {
return Collections.emptyList();
}
// 人员id
Set employeeIds = SalaryEntityUtil.properties(taxDeclareEmployees, TaxDeclareEmployeePO::getEmployeeId);
// 查询报送的人员
List employeeDeclares = getEmployeeDeclareService(user).listByTaxCycleAndTaxAgentIdAndEmployeeIds(
taxDeclareRecord.getTaxCycle(), taxDeclareRecord.getTaxAgentId(), employeeIds);
// 查询人员信息
List simpleEmployeeIds = taxDeclareEmployees.stream()
.filter(taxDeclarationValue -> Objects.equals(taxDeclarationValue.getEmployeeType(), EmployeeTypeEnum.ORGANIZATION.getValue()))
.map(TaxDeclareEmployeePO::getEmployeeId)
.distinct()
.collect(Collectors.toList());
List simpleEmployees = getSalaryEmployeeService(user).getEmployeeByIds(simpleEmployeeIds);
// 查询人员薪资(身份证号码等)
List simpleUserInfos = getSalaryEmployeeService(user).listByIds(simpleEmployeeIds);
// 查询外部人员
List extEmployeeIds = taxDeclareEmployees.stream()
.filter(taxDeclarationValue -> Objects.equals(taxDeclarationValue.getEmployeeType(), EmployeeTypeEnum.EXT_EMPLOYEE.getValue()))
.map(TaxDeclareEmployeePO::getEmployeeId)
.collect(Collectors.toList());
List extEmployees = getExtEmpService(user).getExtEmpByIds(extEmployeeIds);
return TaxDeclareEmployeeBO.convert2AbnormalEmployee(taxDeclareEmployees, employeeDeclares, simpleEmployees, simpleUserInfos, extEmployees);
}
}