2022-05-18 09:19:50 +08:00
|
|
|
package com.engine.salary.service.impl;
|
|
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
import com.engine.common.util.ServiceUtil;
|
2022-05-18 09:19:50 +08:00
|
|
|
import com.engine.core.impl.Service;
|
2022-05-24 09:14:26 +08:00
|
|
|
import com.engine.salary.biz.EmployBiz;
|
2022-05-18 09:19:50 +08:00
|
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
2022-05-24 09:14:26 +08:00
|
|
|
import com.engine.salary.entity.hrm.DeptInfo;
|
|
|
|
|
import com.engine.salary.entity.hrm.HrmStatus;
|
|
|
|
|
import com.engine.salary.entity.hrm.PositionInfo;
|
|
|
|
|
import com.engine.salary.entity.hrm.SubCompanyInfo;
|
2022-05-19 16:36:18 +08:00
|
|
|
import com.engine.salary.entity.taxagent.bo.TaxAgentBO;
|
2022-05-18 09:19:50 +08:00
|
|
|
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeEmployeeDTO;
|
|
|
|
|
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeListDTO;
|
2022-05-19 16:36:18 +08:00
|
|
|
import com.engine.salary.entity.taxagent.param.*;
|
2022-05-18 09:19:50 +08:00
|
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentManageRangePO;
|
2022-05-19 16:36:18 +08:00
|
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
|
|
|
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentSubAdminPO;
|
2022-05-24 09:14:26 +08:00
|
|
|
import com.engine.salary.enums.UserStatusEnum;
|
2022-05-18 09:19:50 +08:00
|
|
|
import com.engine.salary.enums.salarysob.SalaryEmployeeStatusEnum;
|
|
|
|
|
import com.engine.salary.enums.salarysob.TargetTypeEnum;
|
|
|
|
|
import com.engine.salary.enums.taxagent.TaxAgentRangeTypeEnum;
|
2022-05-19 16:36:18 +08:00
|
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
2022-05-18 09:19:50 +08:00
|
|
|
import com.engine.salary.mapper.datacollection.EmployMapper;
|
|
|
|
|
import com.engine.salary.mapper.taxagent.TaxAgentManageRangeMapper;
|
2022-05-19 16:36:18 +08:00
|
|
|
import com.engine.salary.service.*;
|
2022-05-18 09:19:50 +08:00
|
|
|
import com.engine.salary.util.JsonUtil;
|
|
|
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
2022-05-19 16:36:18 +08:00
|
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
2022-05-24 09:14:26 +08:00
|
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
2022-05-18 09:19:50 +08:00
|
|
|
import com.engine.salary.util.page.PageInfo;
|
2022-05-25 13:10:03 +08:00
|
|
|
import com.engine.salary.util.page.SalaryPageUtil;
|
2022-05-18 09:19:50 +08:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2022-05-24 09:14:26 +08:00
|
|
|
import weaver.hrm.User;
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 个税扣缴义务人的管理范围
|
|
|
|
|
* <p>Copyright: Copyright (c) 2022</p>
|
|
|
|
|
* <p>Company: 泛微软件</p>
|
|
|
|
|
*
|
|
|
|
|
* @author qiantao
|
|
|
|
|
* @version 1.0
|
|
|
|
|
**/
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class TaxAgentManageRangeServiceImpl extends Service implements TaxAgentManageRangeService {
|
|
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
private TaxAgentManageRangeMapper getTaxAgentManageRangeMapper() {
|
|
|
|
|
return MapperProxyFactory.getProxy(TaxAgentManageRangeMapper.class);
|
|
|
|
|
}
|
2022-05-18 09:19:50 +08:00
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
private TaxAgentV2Service getTaxAgentV2Service(User user) {
|
|
|
|
|
return ServiceUtil.getService(TaxAgentV2ServiceImpl.class, user);
|
|
|
|
|
}
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
private TaxAgentSubAdminService taxAgentSubAdminService;
|
2022-05-24 09:14:26 +08:00
|
|
|
// private TaxAgentSubAdminService getTaxAgentSubAdminService(User user) {
|
|
|
|
|
// return ServiceUtil.getService(TaxAgentSubAdminServiceImpl.class, user);
|
|
|
|
|
// }
|
2022-05-18 09:19:50 +08:00
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
private TaxAgentEmpService getTaxAgentEmpService(User user) {
|
|
|
|
|
return ServiceUtil.getService(TaxAgentEmpServiceImpl.class, user);
|
|
|
|
|
}
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
private TaxAgentSubAdminEmpService taxAgentSubAdminEmployeeService;
|
2022-05-24 09:14:26 +08:00
|
|
|
// private TaxAgentSubAdminEmpService getTaxAgentSubAdminEmpService(User user) {
|
|
|
|
|
// return ServiceUtil.getService(TaxAgentSubAdminEmpServiceImpl.class, user);
|
|
|
|
|
// }
|
2022-05-18 09:19:50 +08:00
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
// private ComInfoCache comInfoCache;
|
2022-05-18 09:19:50 +08:00
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
private EmployMapper getEmployMapper() {
|
|
|
|
|
return MapperProxyFactory.getProxy(EmployMapper.class);
|
|
|
|
|
}
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
private ExecutorService taskExecutor;
|
|
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
private EmployBiz employBiz = new EmployBiz();
|
|
|
|
|
// private HrmCommonHrmStatusService hrmCommonHrmStatusService;
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
private List<TaxAgentManageRangePO> listByTaxAgentIds(List<Long> taxAgentIds) {
|
|
|
|
|
if (CollectionUtils.isEmpty(taxAgentIds)) {
|
|
|
|
|
return Lists.newArrayList();
|
|
|
|
|
}
|
2022-05-24 09:14:26 +08:00
|
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().rangeType(TaxAgentRangeTypeEnum.TAXAGENT.getValue()).taxAgentIds(taxAgentIds).build());
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TaxAgentManageRangeEmployeeDTO> listSalaryEmployeeByTaxAgentIds(List<Long> taxAgentIds) {
|
|
|
|
|
return listSalaryEmployeeByTaxAgentIds(null, taxAgentIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TaxAgentManageRangeEmployeeDTO> listSalaryEmployeeByTaxAgentIds(SalaryEmployeeStatusEnum employeeStatus, List<Long> taxAgentIds) {
|
|
|
|
|
List<TaxAgentManageRangePO> allTaxAgentManageRanges = this.listByTaxAgentIds(taxAgentIds);
|
|
|
|
|
return convertTaxAgentEmployee(employeeStatus, taxAgentIds, allTaxAgentManageRanges);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-19 16:36:18 +08:00
|
|
|
@Override
|
|
|
|
|
public List<TaxAgentManageRangePO> listBySubAdminIds(Collection<Long> taxAgentSubAdminIds) {
|
|
|
|
|
if (CollectionUtils.isEmpty(taxAgentSubAdminIds)) {
|
|
|
|
|
return Lists.newArrayList();
|
|
|
|
|
}
|
2022-05-24 09:14:26 +08:00
|
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().rangeType(TaxAgentRangeTypeEnum.SUBADMIN.getValue()).taxAgentSubAdminIds(taxAgentSubAdminIds).build());
|
2022-05-19 16:36:18 +08:00
|
|
|
}
|
2022-05-18 09:19:50 +08:00
|
|
|
|
2022-05-19 16:36:18 +08:00
|
|
|
@Override
|
|
|
|
|
public List<TaxAgentManageRangeEmployeeDTO> listSalaryEmployeeBySubAdminIds(List<Long> taxAgentIds) {
|
|
|
|
|
return listSalaryEmployeeBySubAdminIds(null, taxAgentIds);
|
|
|
|
|
}
|
2022-05-18 09:19:50 +08:00
|
|
|
|
2022-05-19 16:36:18 +08:00
|
|
|
@Override
|
|
|
|
|
public List<TaxAgentManageRangeEmployeeDTO> listSalaryEmployeeBySubAdminIds(SalaryEmployeeStatusEnum employeeStatus, List<Long> taxAgentSubAdminIds) {
|
|
|
|
|
List<TaxAgentManageRangePO> allTaxAgentManageRanges = this.listBySubAdminIds(taxAgentSubAdminIds);
|
|
|
|
|
List<Long> taxAgentIds = allTaxAgentManageRanges.stream().map(TaxAgentManageRangePO::getTaxAgentId).distinct().collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
return convertTaxAgentEmployee(employeeStatus, taxAgentIds, allTaxAgentManageRanges);
|
|
|
|
|
}
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
private List<TaxAgentManageRangeEmployeeDTO> convertTaxAgentEmployee(SalaryEmployeeStatusEnum employeeStatus, List<Long> taxAgentIds, List<TaxAgentManageRangePO> allTaxAgentManageRanges) {
|
|
|
|
|
return taxAgentIds.stream().distinct().map(e -> {
|
|
|
|
|
// 获取范围下的人员
|
|
|
|
|
List<DataCollectionEmployee> salaryEmployees = getManageRangeSalaryEmployees(employeeStatus, e, allTaxAgentManageRanges);
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryEmployees)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
List<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> taxAgentEmployees = salaryEmployees.stream().map(m -> {
|
|
|
|
|
TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee taxAgentEmployee = new TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee();
|
|
|
|
|
taxAgentEmployee.setEmployeeId(m.getEmployeeId());
|
|
|
|
|
taxAgentEmployee.setUsername(m.getUsername());
|
|
|
|
|
return taxAgentEmployee;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
return TaxAgentManageRangeEmployeeDTO.builder()
|
|
|
|
|
.taxAgentId(e)
|
|
|
|
|
.taxAgentName("")
|
|
|
|
|
.employeeList(taxAgentEmployees)
|
|
|
|
|
.build();
|
|
|
|
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取范围下的人员
|
|
|
|
|
*
|
|
|
|
|
* @param employeeStatus
|
|
|
|
|
* @param taxAgentId
|
|
|
|
|
* @param allTaxAgentManageRanges
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<DataCollectionEmployee> getManageRangeSalaryEmployees(SalaryEmployeeStatusEnum employeeStatus, Long taxAgentId,
|
2022-05-19 16:36:18 +08:00
|
|
|
List<TaxAgentManageRangePO> allTaxAgentManageRanges) {
|
2022-05-18 09:19:50 +08:00
|
|
|
List<TaxAgentManageRangePO> includeAllTaxAgentManageRanges = allTaxAgentManageRanges.stream().filter(f -> f.getIncludeType().equals(NumberUtils.INTEGER_ONE)).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isEmpty(includeAllTaxAgentManageRanges)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
List<TaxAgentManageRangePO> excludeAllTaxAgentManageRanges = allTaxAgentManageRanges.stream().filter(f -> f.getIncludeType().equals(NumberUtils.INTEGER_ZERO)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
List<DataCollectionEmployee> includeSalaryEmployees = Lists.newArrayList();
|
|
|
|
|
List<TaxAgentManageRangePO> includeTaxAgentManageRanges = includeAllTaxAgentManageRanges.stream().filter(f -> f.getTaxAgentId().equals(taxAgentId)).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isEmpty(includeTaxAgentManageRanges)) {
|
|
|
|
|
return includeSalaryEmployees;
|
|
|
|
|
}
|
|
|
|
|
// 如果需要状态过滤
|
|
|
|
|
List<String> personnelStatuss = Lists.newArrayList();
|
|
|
|
|
if (employeeStatus != null) {
|
|
|
|
|
// 查询人员状态
|
|
|
|
|
if (employeeStatus.equals(SalaryEmployeeStatusEnum.NORMAL)) {
|
2022-05-24 09:14:26 +08:00
|
|
|
personnelStatuss = UserStatusEnum.getNormalStatus();
|
2022-05-18 09:19:50 +08:00
|
|
|
} else if (employeeStatus.equals(SalaryEmployeeStatusEnum.UNAVAILABLE)) {
|
2022-05-24 09:14:26 +08:00
|
|
|
personnelStatuss = UserStatusEnum.getUnavailableStatus();
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 根据上一步的查询参数查询人员
|
|
|
|
|
includeSalaryEmployees = listSalaryEmployeeByManageRange(includeTaxAgentManageRanges, personnelStatuss);
|
|
|
|
|
if (CollectionUtils.isEmpty(includeSalaryEmployees)) {
|
|
|
|
|
return includeSalaryEmployees;
|
|
|
|
|
}
|
|
|
|
|
// 查询管理范围(从范围中排除)
|
|
|
|
|
List<TaxAgentManageRangePO> excludeTaxAgentManageRanges = excludeAllTaxAgentManageRanges.stream().filter(f -> f.getTaxAgentId().equals(taxAgentId)).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(excludeTaxAgentManageRanges)) {
|
|
|
|
|
// 根据上一步的查询参数查询人员
|
|
|
|
|
List<DataCollectionEmployee> excludeSalaryEmployees = listSalaryEmployeeByManageRange(excludeTaxAgentManageRanges, personnelStatuss);
|
|
|
|
|
// 需要排除的人员范围
|
|
|
|
|
Set<Long> excludeEmployeeIds = SalaryEntityUtil.properties(excludeSalaryEmployees, DataCollectionEmployee::getEmployeeId);
|
|
|
|
|
// 过滤人员
|
|
|
|
|
includeSalaryEmployees = includeSalaryEmployees.stream()
|
|
|
|
|
.filter(salaryEmployee -> !excludeEmployeeIds.contains(salaryEmployee.getEmployeeId()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
return includeSalaryEmployees;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据范围加载人员
|
|
|
|
|
*
|
|
|
|
|
* @param taxAgentManageRanges
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<DataCollectionEmployee> listSalaryEmployeeByManageRange(List<TaxAgentManageRangePO> taxAgentManageRanges, List<String> personnelStatuss) {
|
|
|
|
|
if (CollectionUtils.isEmpty(taxAgentManageRanges)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
2022-05-24 09:14:26 +08:00
|
|
|
List<DataCollectionEmployee> salaryEmployees = getEmployMapper().listAll();
|
2022-05-18 09:19:50 +08:00
|
|
|
List<DataCollectionEmployee> salaryEmployeeList = Lists.newArrayList();
|
|
|
|
|
for (TaxAgentManageRangePO manageRange : taxAgentManageRanges) {
|
|
|
|
|
salaryEmployeeList.addAll(salaryEmployees.stream()
|
|
|
|
|
.filter(salaryEmployee -> {
|
|
|
|
|
// 判断人员状态
|
|
|
|
|
List<String> hrmStatusList = JsonUtil.parseList(manageRange.getEmployeeStatus(), String.class);
|
|
|
|
|
// 有状态过滤则取交集
|
|
|
|
|
if (CollectionUtils.isNotEmpty(personnelStatuss)) {
|
|
|
|
|
hrmStatusList = hrmStatusList.stream().filter(personnelStatuss::contains).collect(Collectors.toList());
|
|
|
|
|
}
|
2022-05-24 09:14:26 +08:00
|
|
|
if (CollectionUtils.isNotEmpty(hrmStatusList) && !hrmStatusList.contains(salaryEmployee.getStatus())) {
|
2022-05-18 09:19:50 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (Objects.equals(manageRange.getTargetType(), TargetTypeEnum.ALL.getValue())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (Objects.equals(manageRange.getTargetType(), TargetTypeEnum.EMPLOYEE.getValue())
|
|
|
|
|
&& Objects.equals(manageRange.getTargetId(), salaryEmployee.getEmployeeId())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (Objects.equals(manageRange.getTargetType(), TargetTypeEnum.DEPT.getValue())
|
|
|
|
|
&& Objects.equals(manageRange.getTargetId(), salaryEmployee.getDepartmentId())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (Objects.equals(manageRange.getTargetType(), TargetTypeEnum.SUBCOMPANY.getValue())
|
|
|
|
|
&& Objects.equals(manageRange.getTargetId(), salaryEmployee.getDepartmentId())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (Objects.equals(manageRange.getTargetType(), TargetTypeEnum.POSITION.getValue())
|
|
|
|
|
&& Objects.equals(manageRange.getTargetId(), salaryEmployee.getJobtitleId())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}).collect(Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
// 去重
|
|
|
|
|
salaryEmployeeList = salaryEmployeeList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(DataCollectionEmployee::getEmployeeId))), ArrayList::new));
|
|
|
|
|
return salaryEmployeeList;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
/**
|
|
|
|
|
* 根据分管理员id获取管理范围列表
|
|
|
|
|
*
|
|
|
|
|
* @param subAdminId
|
|
|
|
|
* @param includeType
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<TaxAgentManageRangePO> listBySubAdminIdAndIncludeType(Long subAdminId, Integer includeType) {
|
|
|
|
|
|
|
|
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().taxAgentSubAdminId(subAdminId).rangeType(TaxAgentRangeTypeEnum.SUBADMIN.getValue()).includeType(includeType).build());
|
|
|
|
|
// return new LambdaQueryChainWrapper<>(getTaxAgentManageRangeMapper())
|
2022-05-19 16:36:18 +08:00
|
|
|
// .eq(TaxAgentManageRangePO::getTenantKey)
|
2022-05-18 09:19:50 +08:00
|
|
|
// .eq(TaxAgentManageRangePO::getDeleteType, 0)
|
|
|
|
|
// .eq(TaxAgentManageRangePO::getTaxAgentSubAdminId, subAdminId)
|
|
|
|
|
// .eq(TaxAgentManageRangePO::getRangeType, TaxAgentRangeTypeEnum.SUBADMIN.getValue())
|
|
|
|
|
// .eq(TaxAgentManageRangePO::getIncludeType, includeType)
|
|
|
|
|
// .orderByDesc(TaxAgentManageRangePO::getId)
|
|
|
|
|
// .list();
|
2022-05-24 09:14:26 +08:00
|
|
|
}
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取个税口角义务人的管理范围
|
|
|
|
|
*
|
|
|
|
|
* @param taxAgentId
|
|
|
|
|
* @param includeType
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<TaxAgentManageRangePO> listByTaxAgentIdAndIncludeType(Long taxAgentId, Integer includeType) {
|
2022-05-24 09:14:26 +08:00
|
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().taxAgentId(taxAgentId).rangeType(TaxAgentRangeTypeEnum.TAXAGENT.getValue()).includeType(includeType).build());
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
@Override
|
|
|
|
|
public PageInfo<TaxAgentManageRangeListDTO> listPageByParamAndIncludeType(TaxAgentSubAdminRangeQueryParam queryParam, Integer includeType) {
|
|
|
|
|
// 查询已有的管理范围
|
|
|
|
|
List<TaxAgentManageRangePO> taxAgentManageRanges = listBySubAdminIdAndIncludeType(queryParam.getSubAdminId(), includeType);
|
|
|
|
|
return listPageByParamAndIncludeType(taxAgentManageRanges, queryParam, includeType);
|
|
|
|
|
}
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageInfo<TaxAgentManageRangeListDTO> listPageByParamAndIncludeType(TaxAgentRangeQueryParam queryParam, Integer includeType) {
|
|
|
|
|
// 查询已有的管理范围
|
|
|
|
|
List<TaxAgentManageRangePO> taxAgentManageRanges = listByTaxAgentIdAndIncludeType(queryParam.getTaxAgentId(), includeType);
|
|
|
|
|
return listPageByParamAndIncludeType(taxAgentManageRanges, queryParam, includeType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PageInfo<TaxAgentManageRangeListDTO> listPageByParamAndIncludeType(List<TaxAgentManageRangePO> taxAgentManageRanges, TaxAgentManageRangeQueryParam queryParam, Integer includeType) {
|
|
|
|
|
|
|
|
|
|
// 查询人员信息
|
2022-05-24 09:14:26 +08:00
|
|
|
List<Long> employeeIds = taxAgentManageRanges.stream()
|
2022-05-18 09:19:50 +08:00
|
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.EMPLOYEE.getValue()))
|
|
|
|
|
.map(TaxAgentManageRangePO::getTargetId)
|
|
|
|
|
.collect(Collectors.toList());
|
2022-05-24 09:14:26 +08:00
|
|
|
// List<DataCollectionEmployee> employeeComInfos = comInfoCache.getCacheList(HrmEmployeeComInfo.class, employeeIds);
|
|
|
|
|
List<DataCollectionEmployee> employeeComInfos = employBiz.getEmployeeByIdsAll(employeeIds);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 查询部门信息
|
2022-05-24 09:14:26 +08:00
|
|
|
List<Long> departmentIds = taxAgentManageRanges.stream()
|
2022-05-18 09:19:50 +08:00
|
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.DEPT.getValue()))
|
|
|
|
|
.map(TaxAgentManageRangePO::getTargetId)
|
|
|
|
|
.collect(Collectors.toList());
|
2022-05-24 09:14:26 +08:00
|
|
|
List<DeptInfo> departmentComInfos = employBiz.getDeptInfoList(departmentIds);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 查询分部信息
|
2022-05-24 09:14:26 +08:00
|
|
|
List<Long> subDepartmentIds = taxAgentManageRanges.stream()
|
2022-05-18 09:19:50 +08:00
|
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.SUBCOMPANY.getValue()))
|
|
|
|
|
.map(TaxAgentManageRangePO::getTargetId)
|
|
|
|
|
.collect(Collectors.toList());
|
2022-05-24 09:14:26 +08:00
|
|
|
|
|
|
|
|
List<SubCompanyInfo> subDepartmentComInfos = employBiz.getSubCompanyInfoList(subDepartmentIds);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 查询岗位信息
|
2022-05-24 09:14:26 +08:00
|
|
|
List<Long> positionIds = taxAgentManageRanges.stream()
|
2022-05-18 09:19:50 +08:00
|
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.POSITION.getValue()))
|
|
|
|
|
.map(TaxAgentManageRangePO::getTargetId)
|
|
|
|
|
.collect(Collectors.toList());
|
2022-05-24 09:14:26 +08:00
|
|
|
List<PositionInfo> positionComInfos = employBiz.listPositionInfo(positionIds);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 分页参数
|
2022-05-25 13:10:03 +08:00
|
|
|
PageInfo<TaxAgentManageRangeListDTO> dtoPage = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), TaxAgentManageRangeListDTO.class);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 查询人员状态
|
2022-05-24 09:14:26 +08:00
|
|
|
// List<HrmStatus> hrmStatusList = hrmCommonHrmStatusService.list();
|
|
|
|
|
List<HrmStatus> hrmStatusList = UserStatusEnum.getHrmStatusList();
|
2022-05-18 09:19:50 +08:00
|
|
|
// 薪资账套的人员范围po转换成列表dto
|
|
|
|
|
List<TaxAgentManageRangeListDTO> taxAgentManageRangeList = TaxAgentBO.convert2ListDTO(taxAgentManageRanges, employeeComInfos, departmentComInfos, subDepartmentComInfos, positionComInfos, hrmStatusList);
|
|
|
|
|
// 根据对象名称过滤
|
|
|
|
|
if (StringUtils.isNotEmpty(queryParam.getTargetName())) {
|
|
|
|
|
taxAgentManageRangeList = taxAgentManageRangeList.stream()
|
|
|
|
|
.filter(f -> f.getTargetName().contains(queryParam.getTargetName()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
// 填充总数和当页数据
|
|
|
|
|
dtoPage.setTotal(taxAgentManageRangeList.size());
|
2022-05-25 13:10:03 +08:00
|
|
|
dtoPage.setList(SalaryPageUtil.subList(dtoPage.getPageNum(), dtoPage.getSize(), taxAgentManageRangeList));
|
2022-05-18 09:19:50 +08:00
|
|
|
return dtoPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据个税口角义务人id保存管理范围
|
|
|
|
|
*
|
2022-05-24 09:14:26 +08:00
|
|
|
* @param saveParam 保存参数
|
2022-05-18 09:19:50 +08:00
|
|
|
*/
|
|
|
|
|
@Override
|
2022-05-24 09:14:26 +08:00
|
|
|
public void save(TaxAgentRangeSaveParam saveParam) {
|
2022-05-18 09:19:50 +08:00
|
|
|
// 查询薪资账套
|
2022-05-24 09:14:26 +08:00
|
|
|
TaxAgentPO taxAgent = getTaxAgentV2Service(user).getById(saveParam.getTaxAgentId());
|
2022-05-18 09:19:50 +08:00
|
|
|
if (Objects.isNull(taxAgent)) {
|
2022-05-19 16:36:18 +08:00
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(108605, "参数错误,个税扣缴义务人不存在或者已被删除"));
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
// 查询已有的管理范围
|
2022-05-19 16:36:18 +08:00
|
|
|
List<TaxAgentManageRangePO> taxAgentManageAllRanges = listByTaxAgentId(saveParam.getTaxAgentId());
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
List<TaxAgentManageRangePO> taxAgentManageRanges = taxAgentManageAllRanges.stream().filter(f -> f.getIncludeType().equals(saveParam.getIncludeType())).collect(Collectors.toList());
|
|
|
|
|
// 处理一下本次的保存参数(如果原来添加过对应的人员(/部门/岗位),那么本次不需要新增,只需要更新)
|
2022-05-24 09:14:26 +08:00
|
|
|
TaxAgentBO.Result result = TaxAgentBO.handleTaxAgentRange(taxAgentManageRanges, saveParam, taxAgent.getId(), (long) user.getUID());
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
/** 检查当前个税扣缴义务人的所有人员范围与所有分管理员的管理范围===========================start */
|
|
|
|
|
List<TaxAgentManageRangePO> allRanges = Lists.newArrayList(taxAgentManageAllRanges);
|
|
|
|
|
allRanges.addAll(result.getNeedInsertTaxAgentManageRanges());
|
|
|
|
|
allRanges.addAll(result.getNeedUpdateTaxAgentManageRanges());
|
|
|
|
|
// 去重
|
|
|
|
|
allRanges = allRanges.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
|
|
|
|
|
Comparator.comparing(f -> f.getTaxAgentId() + "." + f.getRangeType() + "." + f.getTargetType() + "." + f.getTargetId() + "." + f.getEmployeeStatus() + "." + f.getIncludeType()))
|
|
|
|
|
), ArrayList::new));
|
2022-05-19 16:36:18 +08:00
|
|
|
List<DataCollectionEmployee> allSalaryEmployees = this.getManageRangeSalaryEmployees(null, saveParam.getTaxAgentId(), allRanges);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 如果是排除是否会对分管理范围产生影响
|
2022-05-19 16:36:18 +08:00
|
|
|
List<TaxAgentManageRangePO> allSubAdminRanges = listSunAdminRangeByTaxAgentId(saveParam.getTaxAgentId());
|
2022-05-18 09:19:50 +08:00
|
|
|
if (saveParam.getIncludeType().equals(NumberUtils.INTEGER_ZERO)) {
|
2022-05-19 16:36:18 +08:00
|
|
|
List<DataCollectionEmployee> allSubAdminSalaryEmployees = this.getManageRangeSalaryEmployees(null, saveParam.getTaxAgentId(), allSubAdminRanges);
|
2022-05-18 09:19:50 +08:00
|
|
|
|
2022-05-19 16:36:18 +08:00
|
|
|
List<Long> allSalaryEmployeeIds = allSalaryEmployees.stream().map(DataCollectionEmployee::getEmployeeId).collect(Collectors.toList());
|
2022-05-18 09:19:50 +08:00
|
|
|
allSubAdminSalaryEmployees.removeIf(a -> allSalaryEmployeeIds.contains(a.getEmployeeId()));
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(allSubAdminSalaryEmployees)) {
|
2022-05-19 16:36:18 +08:00
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(110122, "分管理员包含该范围,不能删除"));
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/** 检查当前个税扣缴义务人的所有人员范围与所有分管理员的管理范围===========================end */
|
2022-05-24 09:14:26 +08:00
|
|
|
// todo 保存
|
2022-05-18 09:19:50 +08:00
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedInsertTaxAgentManageRanges())) {
|
2022-05-24 09:14:26 +08:00
|
|
|
// this.saveBatch(result.getNeedInsertTaxAgentManageRanges());
|
|
|
|
|
result.getNeedInsertTaxAgentManageRanges().forEach(range -> getTaxAgentManageRangeMapper().insertIgnoreNull(range));
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedUpdateTaxAgentManageRanges())) {
|
2022-05-24 09:14:26 +08:00
|
|
|
result.getNeedInsertTaxAgentManageRanges().forEach(range -> getTaxAgentManageRangeMapper().updateIgnoreNull(range));
|
|
|
|
|
// this.updateBatchById(result.getNeedUpdateTaxAgentManageRanges());
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 同步本地人员范围的关联人员=========================== */
|
|
|
|
|
taskExecutor.execute(() -> {
|
|
|
|
|
try {
|
2022-05-24 09:14:26 +08:00
|
|
|
syncLocalEmp(saveParam.getTaxAgentId(), allSalaryEmployees, allSubAdminRanges, (long) user.getUID());
|
2022-05-18 09:19:50 +08:00
|
|
|
} finally {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 记录日志 todo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取个税口角义务人的管理范围
|
|
|
|
|
*
|
|
|
|
|
* @param taxAgentId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-05-19 16:36:18 +08:00
|
|
|
private List<TaxAgentManageRangePO> listByTaxAgentId(Long taxAgentId) {
|
2022-05-24 09:14:26 +08:00
|
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().taxAgentId(taxAgentId).rangeType(TaxAgentRangeTypeEnum.TAXAGENT.getValue()).build());
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-19 16:36:18 +08:00
|
|
|
private List<TaxAgentManageRangePO> listSunAdminRangeByTaxAgentId(Long taxAgentId) {
|
2022-05-24 09:14:26 +08:00
|
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().taxAgentId(taxAgentId).rangeType(TaxAgentRangeTypeEnum.SUBADMIN.getValue()).build());
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
2022-05-24 09:14:26 +08:00
|
|
|
public void save4SubAdmin(TaxAgentSubAdminRangeSaveParam saveParam) {
|
2022-05-18 09:19:50 +08:00
|
|
|
// 查询薪资账套
|
2022-05-19 16:36:18 +08:00
|
|
|
TaxAgentSubAdminPO taxAgentSubAdmin = taxAgentSubAdminService.getById(saveParam.getSubAdminId());
|
2022-05-18 09:19:50 +08:00
|
|
|
if (Objects.isNull(taxAgentSubAdmin)) {
|
2022-05-19 16:36:18 +08:00
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(106687, "参数错误,分管理员不存在或者已被删除"));
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
// 查询已有的管理范围
|
2022-05-19 16:36:18 +08:00
|
|
|
List<TaxAgentManageRangePO> taxAgentManageAllRanges = listBySubAdminId(saveParam.getSubAdminId());
|
2022-05-18 09:19:50 +08:00
|
|
|
List<TaxAgentManageRangePO> taxAgentManageRanges = taxAgentManageAllRanges.stream().filter(f -> f.getIncludeType().equals(saveParam.getIncludeType())).collect(Collectors.toList());
|
|
|
|
|
// 处理一下本次的保存参数(如果原来添加过对应的人员(/部门/岗位),那么本次不需要新增,只需要更新)
|
2022-05-24 09:14:26 +08:00
|
|
|
TaxAgentBO.Result result = TaxAgentBO.handleSubAdminRange(taxAgentManageRanges, saveParam, taxAgentSubAdmin.getTaxAgentId(), taxAgentSubAdmin.getId(), (long) user.getUID());
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
// 当前库中所有分管理员的管理范围
|
2022-05-19 16:36:18 +08:00
|
|
|
List<TaxAgentManageRangePO> allSubAdminRangesExist = listSunAdminRangeByTaxAgentId(taxAgentSubAdmin.getTaxAgentId());
|
2022-05-18 09:19:50 +08:00
|
|
|
/** 检查当前分管理员的范围与其他分管理员人员范围===========================start */
|
|
|
|
|
// 当前分管理员的范围
|
|
|
|
|
List<TaxAgentManageRangePO> allSubAdminRangesCuttent = Lists.newArrayList(taxAgentManageAllRanges);
|
|
|
|
|
// 其他分管理员的范围
|
|
|
|
|
List<TaxAgentManageRangePO> otherSubAdminRangesExist = allSubAdminRangesExist.stream().filter(f -> !f.getTaxAgentSubAdminId().equals(saveParam.getSubAdminId())).collect(Collectors.toList());
|
|
|
|
|
allSubAdminRangesCuttent.addAll(result.getNeedInsertTaxAgentManageRanges());
|
|
|
|
|
allSubAdminRangesCuttent.addAll(result.getNeedUpdateTaxAgentManageRanges());
|
|
|
|
|
|
|
|
|
|
// 当前分管理员的所有人员
|
2022-05-24 09:14:26 +08:00
|
|
|
List<DataCollectionEmployee> currentSubAdminSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentSubAdmin.getTaxAgentId(), allSubAdminRangesCuttent);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 其他分管理员的所有人员
|
2022-05-24 09:14:26 +08:00
|
|
|
List<DataCollectionEmployee> otherSubAdminSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentSubAdmin.getTaxAgentId(), otherSubAdminRangesExist);
|
|
|
|
|
for (DataCollectionEmployee se : currentSubAdminSalaryEmployees) {
|
|
|
|
|
Optional<DataCollectionEmployee> optionalSe = otherSubAdminSalaryEmployees.stream().filter(f -> f.getEmployeeId().equals(se.getEmployeeId())).findFirst();
|
2022-05-18 09:19:50 +08:00
|
|
|
if (optionalSe.isPresent()) {
|
2022-05-19 16:36:18 +08:00
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(110149, "不可包含其他分管理员的人员"));
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/** 检查当前分管理员的范围与其他分管理员人员范围===========================end */
|
|
|
|
|
|
|
|
|
|
/** 检查当前分管理员的范围与所属个税扣缴义务人的人员范围===========================start */
|
|
|
|
|
// 所属个税扣缴义务人的所有分管理员的管理范围
|
|
|
|
|
List<TaxAgentManageRangePO> allSubAdminRanges = Lists.newArrayList(allSubAdminRangesExist);
|
|
|
|
|
allSubAdminRanges.addAll(result.getNeedInsertTaxAgentManageRanges());
|
|
|
|
|
allSubAdminRanges.addAll(result.getNeedUpdateTaxAgentManageRanges());
|
|
|
|
|
// 去重
|
|
|
|
|
allSubAdminRanges = allSubAdminRanges.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
|
|
|
|
|
Comparator.comparing(f -> f.getTaxAgentSubAdminId() + "." + f.getRangeType() + "." + f.getTargetType() + "." + f.getTargetId() + "." + f.getEmployeeStatus() + "." + f.getIncludeType()))
|
|
|
|
|
), ArrayList::new));
|
|
|
|
|
// 所属个税扣缴义务人的所有人员
|
2022-05-19 16:36:18 +08:00
|
|
|
List<TaxAgentManageRangePO> allRanges = listByTaxAgentId(taxAgentSubAdmin.getTaxAgentId());
|
2022-05-24 09:14:26 +08:00
|
|
|
List<DataCollectionEmployee> allSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentSubAdmin.getTaxAgentId(), allRanges);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 所有分管理员的所有人员
|
2022-05-24 09:14:26 +08:00
|
|
|
List<DataCollectionEmployee> allSubAdminSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentSubAdmin.getTaxAgentId(), allSubAdminRanges);
|
|
|
|
|
List<Long> allSalaryEmployeeIds = allSalaryEmployees.stream().map(DataCollectionEmployee::getEmployeeId).collect(Collectors.toList());
|
2022-05-18 09:19:50 +08:00
|
|
|
allSubAdminSalaryEmployees.removeIf(a -> allSalaryEmployeeIds.contains(a.getEmployeeId()));
|
|
|
|
|
if (CollectionUtils.isNotEmpty(allSubAdminSalaryEmployees)) {
|
2022-05-19 16:36:18 +08:00
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(110125, "超出了整体人员范围"));
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
/** 检查当前分管理员的范围与所属个税扣缴义务人的人员范围===========================end */
|
|
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedInsertTaxAgentManageRanges())) {
|
2022-05-24 09:14:26 +08:00
|
|
|
result.getNeedInsertTaxAgentManageRanges().forEach(range -> getTaxAgentManageRangeMapper().insertIgnoreNull(range));
|
|
|
|
|
// todo this.saveBatch(result.getNeedInsertTaxAgentManageRanges());
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedUpdateTaxAgentManageRanges())) {
|
2022-05-24 09:14:26 +08:00
|
|
|
result.getNeedUpdateTaxAgentManageRanges().forEach(range -> getTaxAgentManageRangeMapper().updateIgnoreNull(range));
|
|
|
|
|
// todo this.updateBatchById(result.getNeedUpdateTaxAgentManageRanges());
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
/** 同步本地人员范围的关联人员=========================== */
|
|
|
|
|
List<TaxAgentManageRangePO> finalAllSubAdminRanges = allSubAdminRanges;
|
|
|
|
|
taskExecutor.execute(() -> {
|
|
|
|
|
try {
|
2022-05-24 09:14:26 +08:00
|
|
|
syncLocalEmp(taxAgentSubAdmin.getTaxAgentId(), allSalaryEmployees, finalAllSubAdminRanges, (long) user.getUID());
|
2022-05-18 09:19:50 +08:00
|
|
|
} finally {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 记录日志 todo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据分管理员id获取管理范围列表
|
|
|
|
|
*
|
|
|
|
|
* @param subAdminId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-05-19 16:36:18 +08:00
|
|
|
private List<TaxAgentManageRangePO> listBySubAdminId(Long subAdminId) {
|
2022-05-24 09:14:26 +08:00
|
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().taxAgentSubAdminId(subAdminId).rangeType(TaxAgentRangeTypeEnum.SUBADMIN.getValue()).build());
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-19 16:36:18 +08:00
|
|
|
private List<TaxAgentManageRangePO> listByIds(Collection<Long> ids) {
|
2022-05-18 09:19:50 +08:00
|
|
|
if (CollectionUtils.isEmpty(ids)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
2022-05-24 09:14:26 +08:00
|
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().ids(ids).build());
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-05-24 09:14:26 +08:00
|
|
|
public void deleteByIds(Collection<Long> ids) {
|
2022-05-18 09:19:50 +08:00
|
|
|
// 查询管理范围
|
2022-05-19 16:36:18 +08:00
|
|
|
List<TaxAgentManageRangePO> taxAgentManageRanges = listByIds(ids);
|
2022-05-18 09:19:50 +08:00
|
|
|
if (CollectionUtils.isEmpty(taxAgentManageRanges)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98604, "数据不存在或已被删除"));
|
|
|
|
|
}
|
|
|
|
|
List<Long> taxAgentIds = taxAgentManageRanges.stream().map(TaxAgentManageRangePO::getTaxAgentId).distinct().collect(Collectors.toList());
|
|
|
|
|
if (taxAgentIds.size() > 1) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(110159, "一次只能删一个个税个税扣缴义务人的范围"));
|
|
|
|
|
}
|
|
|
|
|
Collection<Long> finalIds = ids;
|
2022-05-19 16:36:18 +08:00
|
|
|
taxAgentManageRanges = this.listByTaxAgentIds(taxAgentIds);
|
2022-05-18 09:19:50 +08:00
|
|
|
List<TaxAgentManageRangePO> allManageRanges = taxAgentManageRanges.stream().filter(f -> !finalIds.contains(f.getId())).collect(Collectors.toList());
|
|
|
|
|
List<TaxAgentManageRangePO> allRanges = allManageRanges.stream().filter(f -> f.getRangeType().equals(TaxAgentRangeTypeEnum.TAXAGENT.getValue())).collect(Collectors.toList());
|
|
|
|
|
List<TaxAgentManageRangePO> allSubAdminRanges = allManageRanges.stream().filter(f -> f.getRangeType().equals(TaxAgentRangeTypeEnum.SUBADMIN.getValue())).collect(Collectors.toList());
|
|
|
|
|
Long taxAgentId = taxAgentIds.get(0);
|
2022-05-19 16:36:18 +08:00
|
|
|
List<DataCollectionEmployee> allSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentId, allRanges);
|
2022-05-18 09:19:50 +08:00
|
|
|
|
2022-05-19 16:36:18 +08:00
|
|
|
List<DataCollectionEmployee> allSubAdminSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentId, allSubAdminRanges);
|
2022-05-18 09:19:50 +08:00
|
|
|
allSalaryEmployees.forEach(f -> {
|
|
|
|
|
allSubAdminSalaryEmployees.removeIf(a -> a.getEmployeeId().equals(f.getEmployeeId()));
|
|
|
|
|
});
|
|
|
|
|
if (CollectionUtils.isNotEmpty(allSubAdminSalaryEmployees)) {
|
2022-05-19 16:36:18 +08:00
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(110160, "分管理员存在超出整体人员范围以外的人员,不可删除"));
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
// 删除管理范围
|
2022-05-24 09:14:26 +08:00
|
|
|
getTaxAgentManageRangeMapper().deleteByIds(ids);
|
2022-05-19 16:36:18 +08:00
|
|
|
|
2022-05-18 09:19:50 +08:00
|
|
|
/** 同步本地人员范围的关联人员=========================== */
|
|
|
|
|
taskExecutor.execute(() -> {
|
|
|
|
|
try {
|
2022-05-24 09:14:26 +08:00
|
|
|
syncLocalEmp(taxAgentId, allSalaryEmployees, allSubAdminRanges, (long) user.getUID());
|
2022-05-18 09:19:50 +08:00
|
|
|
} finally {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 记录日志 todo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-05-24 09:14:26 +08:00
|
|
|
public void deleteByTaxAgentIds(Collection<Long> taxAgentIds) {
|
|
|
|
|
getTaxAgentManageRangeMapper().deleteByTaxAgentIds(taxAgentIds);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 删除管理范围下的所有人员
|
2022-05-24 09:14:26 +08:00
|
|
|
getTaxAgentEmpService(user).deleteByTaxAgentIds(taxAgentIds);
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-05-24 09:14:26 +08:00
|
|
|
public void deleteBySubAdmins(Collection<Long> subAdminIds) {
|
2022-05-18 09:19:50 +08:00
|
|
|
if (CollectionUtils.isEmpty(subAdminIds)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-24 09:14:26 +08:00
|
|
|
getTaxAgentManageRangeMapper().deleteBySubAdminIds(subAdminIds);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 删除管理范围下的所有人员
|
2022-05-19 16:36:18 +08:00
|
|
|
taxAgentSubAdminEmployeeService.deleteBySubAdminIds(subAdminIds);
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
//fixme
|
|
|
|
|
// @AsyncListener(topic = "hrm_resource_queue")
|
|
|
|
|
// public void receiveHrmResourceQueue(AsyncBean<HrmCommonQueue> asyncBean) {
|
|
|
|
|
// log.info("接受到人员变动的结果:{}", JSONObject.toJSONString(asyncBean));
|
|
|
|
|
// // todo 过滤必要性事件类型进行处理,后续加上时间间隔,避免人事批量操作时,监听事件过多
|
|
|
|
|
// if (asyncBean == null || asyncBean.getMessage() == null) {
|
|
|
|
|
// log.error("接受到人员变动的结果失败");
|
|
|
|
|
// }
|
|
|
|
|
// String tenantKey = asyncBean.getMessage().getTenantKey();
|
|
|
|
|
// // 开始同步
|
|
|
|
|
// taskExecutor.execute(() -> {
|
|
|
|
|
// try {
|
|
|
|
|
// handleSyncTaxAgentEmpData();
|
|
|
|
|
// } finally {
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
/**
|
2022-05-24 09:14:26 +08:00
|
|
|
* 同步处理所有人员范围
|
2022-05-18 09:19:50 +08:00
|
|
|
*
|
2022-05-19 16:36:18 +08:00
|
|
|
* @param
|
2022-05-18 09:19:50 +08:00
|
|
|
*/
|
2022-05-19 16:36:18 +08:00
|
|
|
private void handleSyncTaxAgentEmpData() {
|
2022-05-24 09:14:26 +08:00
|
|
|
List<TaxAgentManageRangePO> allManageRanges = getTaxAgentManageRangeMapper().listAll();
|
2022-05-18 09:19:50 +08:00
|
|
|
if (CollectionUtils.isEmpty(allManageRanges)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<Long> taxAgentIds = allManageRanges.stream().map(m -> m.getTaxAgentId()).distinct().collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
List<TaxAgentEmpSaveParam> taxAgentEmpSaveParamList = Lists.newArrayList();
|
|
|
|
|
List<TaxAgentSubAdminEmpSaveParam> subAdminEmpSaveParamList = Lists.newArrayList();
|
|
|
|
|
taxAgentIds.forEach(taxAgentId -> {
|
|
|
|
|
// 当前个税扣缴义务人的所有范围
|
|
|
|
|
List<TaxAgentManageRangePO> allRanges = allManageRanges.stream().filter(f -> f.getTaxAgentId().equals(taxAgentId) && f.getRangeType().equals(TaxAgentRangeTypeEnum.TAXAGENT.getValue())).collect(Collectors.toList());
|
2022-05-19 16:36:18 +08:00
|
|
|
List<DataCollectionEmployee> allSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentId, allRanges);
|
2022-05-18 09:19:50 +08:00
|
|
|
taxAgentEmpSaveParamList.add(getTaxAgentEmpSyncParam(taxAgentId, allSalaryEmployees));
|
|
|
|
|
List<TaxAgentManageRangePO> allSubAdminRanges = allManageRanges.stream().filter(f -> f.getTaxAgentId().equals(taxAgentId) && f.getRangeType().equals(TaxAgentRangeTypeEnum.SUBADMIN.getValue())).collect(Collectors.toList());
|
|
|
|
|
|
2022-05-19 16:36:18 +08:00
|
|
|
subAdminEmpSaveParamList.addAll(getTaxAgentSubAdminEmpSyncParam(taxAgentId, allSubAdminRanges));
|
2022-05-18 09:19:50 +08:00
|
|
|
});
|
|
|
|
|
Long employeeId = 0L;
|
|
|
|
|
// 同步管理员的人员
|
2022-05-24 09:14:26 +08:00
|
|
|
getTaxAgentEmpService(user).syncTaxAgentEmployee(taxAgentEmpSaveParamList, employeeId);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 同步分管理员的人员
|
2022-05-19 16:36:18 +08:00
|
|
|
taxAgentSubAdminEmployeeService.syncTaxAgentSubAdminEmployee(subAdminEmpSaveParamList, employeeId);
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取个税扣缴义务人的同步参数
|
|
|
|
|
*
|
|
|
|
|
* @param taxAgentId
|
|
|
|
|
* @param allSalaryEmployees
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-05-19 16:36:18 +08:00
|
|
|
private TaxAgentEmpSaveParam getTaxAgentEmpSyncParam(Long taxAgentId, List<DataCollectionEmployee> allSalaryEmployees) {
|
2022-05-18 09:19:50 +08:00
|
|
|
return TaxAgentEmpSaveParam.builder()
|
|
|
|
|
.taxAgentId(taxAgentId)
|
|
|
|
|
.salaryEmployeeList(allSalaryEmployees)
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取分管理员的同步参数
|
|
|
|
|
*
|
|
|
|
|
* @param taxAgentId
|
|
|
|
|
* @param allSubAdminRanges
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-05-19 16:36:18 +08:00
|
|
|
private List<TaxAgentSubAdminEmpSaveParam> getTaxAgentSubAdminEmpSyncParam(Long taxAgentId, List<TaxAgentManageRangePO> allSubAdminRanges) {
|
2022-05-18 09:19:50 +08:00
|
|
|
List<Long> allSubAdminIds = allSubAdminRanges.stream().map(TaxAgentManageRangePO::getTaxAgentSubAdminId).distinct().collect(Collectors.toList());
|
|
|
|
|
List<TaxAgentSubAdminEmpSaveParam> subAdminEmpSaveParamList = Lists.newArrayList();
|
|
|
|
|
allSubAdminIds.forEach(e -> {
|
|
|
|
|
List<TaxAgentManageRangePO> singSubAdminRanges = allSubAdminRanges.stream().filter(r -> e.equals(r.getTaxAgentSubAdminId())).collect(Collectors.toList());
|
2022-05-19 16:36:18 +08:00
|
|
|
List<DataCollectionEmployee> subAdminSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentId, singSubAdminRanges);
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
subAdminEmpSaveParamList.add(TaxAgentSubAdminEmpSaveParam.builder()
|
|
|
|
|
.taxAgentId(taxAgentId)
|
|
|
|
|
.subAdminId(e)
|
|
|
|
|
.salaryEmployeeList(subAdminSalaryEmployees)
|
|
|
|
|
.build());
|
|
|
|
|
});
|
|
|
|
|
return subAdminEmpSaveParamList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 同步本地范围关联人员
|
|
|
|
|
*
|
|
|
|
|
* @param taxAgentId
|
|
|
|
|
* @param allSalaryEmployees 个税扣缴义务人下的所有人员
|
|
|
|
|
* @param allSubAdminRanges
|
|
|
|
|
* @param employeeId
|
|
|
|
|
*/
|
2022-05-19 16:36:18 +08:00
|
|
|
private void syncLocalEmp(Long taxAgentId, List<DataCollectionEmployee> allSalaryEmployees, List<TaxAgentManageRangePO> allSubAdminRanges, Long employeeId) {
|
2022-05-18 09:19:50 +08:00
|
|
|
List<TaxAgentEmpSaveParam> taxAgentEmpSaveParamList = Collections.singletonList(getTaxAgentEmpSyncParam(taxAgentId, allSalaryEmployees));
|
|
|
|
|
// 同步个税扣缴义务人的人员
|
2022-05-24 09:14:26 +08:00
|
|
|
getTaxAgentEmpService(user).syncTaxAgentEmployee(taxAgentEmpSaveParamList, employeeId);
|
2022-05-18 09:19:50 +08:00
|
|
|
|
2022-05-19 16:36:18 +08:00
|
|
|
List<TaxAgentSubAdminEmpSaveParam> subAdminEmpSaveParamList = getTaxAgentSubAdminEmpSyncParam(taxAgentId, allSubAdminRanges);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 同步分管理员的人员
|
2022-05-19 16:36:18 +08:00
|
|
|
taxAgentSubAdminEmployeeService.syncTaxAgentSubAdminEmployee(subAdminEmpSaveParamList, employeeId);
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
}
|