595 lines
31 KiB
Java
595 lines
31 KiB
Java
package com.engine.salary.service.impl;
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
import com.engine.core.impl.Service;
|
|
import com.engine.salary.biz.EmployBiz;
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
|
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;
|
|
import com.engine.salary.entity.taxagent.bo.TaxAgentBO;
|
|
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeEmployeeDTO;
|
|
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeListDTO;
|
|
import com.engine.salary.entity.taxagent.param.*;
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentManageRangePO;
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
|
|
import com.engine.salary.enums.UserStatusEnum;
|
|
import com.engine.salary.enums.salarysob.SalaryEmployeeStatusEnum;
|
|
import com.engine.salary.enums.salarysob.TargetTypeEnum;
|
|
import com.engine.salary.enums.taxagent.TaxAgentRangeTypeEnum;
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
|
import com.engine.salary.mapper.datacollection.EmployMapper;
|
|
import com.engine.salary.mapper.taxagent.TaxAgentManageRangeMapper;
|
|
import com.engine.salary.service.*;
|
|
import com.engine.salary.util.JsonUtil;
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
|
import com.engine.salary.util.page.PageInfo;
|
|
import com.engine.salary.util.page.SalaryPageUtil;
|
|
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 weaver.hrm.User;
|
|
|
|
import java.util.*;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
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 {
|
|
|
|
private static final ExecutorService taskExecutor = Executors.newFixedThreadPool(5);
|
|
|
|
|
|
private TaxAgentManageRangeMapper getTaxAgentManageRangeMapper() {
|
|
return MapperProxyFactory.getProxy(TaxAgentManageRangeMapper.class);
|
|
}
|
|
|
|
private TaxAgentService getTaxAgentService(User user) {
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
|
}
|
|
|
|
private TaxAgentEmpService getTaxAgentEmpService(User user) {
|
|
return ServiceUtil.getService(TaxAgentEmpServiceImpl.class, user);
|
|
}
|
|
|
|
private EmployMapper getEmployMapper() {
|
|
return MapperProxyFactory.getProxy(EmployMapper.class);
|
|
}
|
|
|
|
|
|
private EmployBiz employBiz = new EmployBiz();
|
|
|
|
private List<TaxAgentManageRangePO> listByTaxAgentIds(List<Long> taxAgentIds) {
|
|
if (CollectionUtils.isEmpty(taxAgentIds)) {
|
|
return Lists.newArrayList();
|
|
}
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().rangeType(TaxAgentRangeTypeEnum.TAXAGENT.getValue()).taxAgentIds(taxAgentIds).build());
|
|
}
|
|
|
|
@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);
|
|
}
|
|
|
|
@Override
|
|
public List<TaxAgentManageRangePO> listBySubAdminIds(Collection<Long> taxAgentSubAdminIds) {
|
|
if (CollectionUtils.isEmpty(taxAgentSubAdminIds)) {
|
|
return Lists.newArrayList();
|
|
}
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().rangeType(TaxAgentRangeTypeEnum.SUBADMIN.getValue()).taxAgentSubAdminIds(taxAgentSubAdminIds).build());
|
|
}
|
|
|
|
@Override
|
|
public List<TaxAgentManageRangeEmployeeDTO> listSalaryEmployeeBySubAdminIds(List<Long> taxAgentIds) {
|
|
return listSalaryEmployeeBySubAdminIds(null, taxAgentIds);
|
|
}
|
|
|
|
@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);
|
|
}
|
|
|
|
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,
|
|
List<TaxAgentManageRangePO> allTaxAgentManageRanges) {
|
|
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)) {
|
|
// personnelStatuss = UserStatusEnum.getNormalStatus();
|
|
// } else if (employeeStatus.equals(SalaryEmployeeStatusEnum.UNAVAILABLE)) {
|
|
// personnelStatuss = UserStatusEnum.getUnavailableStatus();
|
|
// }
|
|
personnelStatuss.add(employeeStatus.getValue().toString());
|
|
}
|
|
// 根据上一步的查询参数查询人员
|
|
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();
|
|
}
|
|
List<DataCollectionEmployee> salaryEmployees = getEmployMapper().listAllFields();
|
|
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());
|
|
}
|
|
if (CollectionUtils.isNotEmpty(hrmStatusList) && !hrmStatusList.contains(salaryEmployee.getStatus())) {
|
|
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.getSubcompanyid())) {
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* 根据分管理员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());
|
|
}
|
|
|
|
/**
|
|
* 获取个税口角义务人的管理范围
|
|
*
|
|
* @param taxAgentId
|
|
* @param includeType
|
|
* @return
|
|
*/
|
|
private List<TaxAgentManageRangePO> listByTaxAgentIdAndIncludeType(Long taxAgentId, Integer includeType) {
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().taxAgentId(taxAgentId).rangeType(TaxAgentRangeTypeEnum.TAXAGENT.getValue()).includeType(includeType).build());
|
|
}
|
|
|
|
@Override
|
|
public PageInfo<TaxAgentManageRangeListDTO> listPageByParamAndIncludeType(TaxAgentSubAdminRangeQueryParam queryParam, Integer includeType) {
|
|
// 查询已有的管理范围
|
|
List<TaxAgentManageRangePO> taxAgentManageRanges = listBySubAdminIdAndIncludeType(queryParam.getSubAdminId(), includeType);
|
|
return listPageByParamAndIncludeType(taxAgentManageRanges, queryParam, includeType);
|
|
}
|
|
|
|
@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) {
|
|
|
|
// 查询人员信息
|
|
List<Long> employeeIds = taxAgentManageRanges.stream()
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.EMPLOYEE.getValue()))
|
|
.map(TaxAgentManageRangePO::getTargetId)
|
|
.collect(Collectors.toList());
|
|
// List<DataCollectionEmployee> employeeComInfos = comInfoCache.getCacheList(HrmEmployeeComInfo.class, employeeIds);
|
|
List<DataCollectionEmployee> employeeComInfos = employBiz.getEmployeeByIdsAll(employeeIds);
|
|
// 查询部门信息
|
|
List<Long> departmentIds = taxAgentManageRanges.stream()
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.DEPT.getValue()))
|
|
.map(TaxAgentManageRangePO::getTargetId)
|
|
.collect(Collectors.toList());
|
|
List<DeptInfo> departmentComInfos = employBiz.getDeptInfoList(departmentIds);
|
|
// 查询分部信息
|
|
List<Long> subDepartmentIds = taxAgentManageRanges.stream()
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.SUBCOMPANY.getValue()))
|
|
.map(TaxAgentManageRangePO::getTargetId)
|
|
.collect(Collectors.toList());
|
|
|
|
List<SubCompanyInfo> subDepartmentComInfos = employBiz.getSubCompanyInfoList(subDepartmentIds);
|
|
// 查询岗位信息
|
|
List<Long> positionIds = taxAgentManageRanges.stream()
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.POSITION.getValue()))
|
|
.map(TaxAgentManageRangePO::getTargetId)
|
|
.collect(Collectors.toList());
|
|
List<PositionInfo> positionComInfos = employBiz.listPositionInfo(positionIds);
|
|
// 分页参数
|
|
PageInfo<TaxAgentManageRangeListDTO> dtoPage = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), TaxAgentManageRangeListDTO.class);
|
|
// 查询人员状态
|
|
// List<HrmStatus> hrmStatusList = hrmCommonHrmStatusService.list();
|
|
List<HrmStatus> hrmStatusList = UserStatusEnum.getHrmStatusList();
|
|
// 薪资账套的人员范围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());
|
|
dtoPage.setList(SalaryPageUtil.subList(dtoPage.getPageNum(), dtoPage.getPageSize(), taxAgentManageRangeList));
|
|
return dtoPage;
|
|
}
|
|
|
|
/**
|
|
* 根据个税口角义务人id保存管理范围
|
|
*
|
|
* @param saveParam 保存参数
|
|
*/
|
|
@Override
|
|
public void save(TaxAgentRangeSaveParam saveParam) {
|
|
|
|
if (saveParam == null) {
|
|
throw new SalaryRunTimeException("参数错误");
|
|
}
|
|
|
|
if (Objects.isNull(saveParam.getTaxAgentId())) {
|
|
throw new SalaryRunTimeException("个税扣缴义务人的id不允许为空");
|
|
}
|
|
|
|
if (saveParam.getIncludeType() != 0 && saveParam.getIncludeType() != 1) {
|
|
throw new SalaryRunTimeException("只能选择 关联人员范围/从范围中排除");
|
|
}
|
|
|
|
if (CollectionUtils.isEmpty(saveParam.getEmployeeStatus())) {
|
|
throw new SalaryRunTimeException("员工状态不允许为空");
|
|
}
|
|
|
|
if (CollectionUtils.isNotEmpty(saveParam.getTargetParams())) {
|
|
saveParam.getTargetParams().forEach(target -> {
|
|
if (target.getTargetType() == null) {
|
|
throw new SalaryRunTimeException("对象类型不能为空");
|
|
}
|
|
if (target.getTargetId() == null) {
|
|
throw new SalaryRunTimeException("对象不能为空");
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
// 查询个税扣缴义务人
|
|
TaxAgentPO taxAgent = getTaxAgentService(user).getById(saveParam.getTaxAgentId());
|
|
if (Objects.isNull(taxAgent)) {
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(108605, "参数错误,个税扣缴义务人不存在或不在权限范围内"));
|
|
}
|
|
// 查询已有的管理范围
|
|
List<TaxAgentManageRangePO> taxAgentManageAllRanges = listByTaxAgentId(saveParam.getTaxAgentId());
|
|
|
|
List<TaxAgentManageRangePO> taxAgentManageRanges = taxAgentManageAllRanges.stream().filter(f -> f.getIncludeType().equals(saveParam.getIncludeType())).collect(Collectors.toList());
|
|
// 处理一下本次的保存参数(如果原来添加过对应的人员(/部门/岗位),那么本次不需要新增,只需要更新)
|
|
TaxAgentBO.Result result = TaxAgentBO.handleTaxAgentRange(taxAgentManageRanges, saveParam, taxAgent.getId(), (long) user.getUID());
|
|
|
|
/* 检查当前个税扣缴义务人的所有人员范围与所有分管理员的管理范围===========================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));
|
|
List<DataCollectionEmployee> allSalaryEmployees = this.getManageRangeSalaryEmployees(null, saveParam.getTaxAgentId(), allRanges);
|
|
|
|
/* 检查当前个税扣缴义务人的所有人员范围与所有分管理员的管理范围===========================end */
|
|
if (CollectionUtils.isNotEmpty(result.getNeedInsertTaxAgentManageRanges())) {
|
|
result.getNeedInsertTaxAgentManageRanges().forEach(range -> getTaxAgentManageRangeMapper().insertIgnoreNull(range));
|
|
}
|
|
if (CollectionUtils.isNotEmpty(result.getNeedUpdateTaxAgentManageRanges())) {
|
|
result.getNeedInsertTaxAgentManageRanges().forEach(range -> getTaxAgentManageRangeMapper().updateIgnoreNull(range));
|
|
}
|
|
|
|
/* 同步本地人员范围的关联人员=========================== */
|
|
syncLocalEmp(saveParam.getTaxAgentId(), allSalaryEmployees, null);
|
|
|
|
}
|
|
|
|
private void syncLocalEmp(Long taxAgentId, List<DataCollectionEmployee> allSalaryEmployees, List<TaxAgentManageRangePO> allSubAdminRanges) {
|
|
log.info("开始同步人员step");
|
|
taskExecutor.execute(() -> {
|
|
syncLocalEmp(taxAgentId, allSalaryEmployees, allSubAdminRanges, (long) user.getUID());
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
* 获取个税口角义务人的管理范围
|
|
*
|
|
* @param taxAgentId
|
|
* @return
|
|
*/
|
|
private List<TaxAgentManageRangePO> listByTaxAgentId(Long taxAgentId) {
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().taxAgentId(taxAgentId).rangeType(TaxAgentRangeTypeEnum.TAXAGENT.getValue()).build());
|
|
}
|
|
|
|
private List<TaxAgentManageRangePO> listSunAdminRangeByTaxAgentId(Long taxAgentId) {
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().taxAgentId(taxAgentId).rangeType(TaxAgentRangeTypeEnum.SUBADMIN.getValue()).build());
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 根据分管理员id获取管理范围列表
|
|
*
|
|
* @param subAdminId
|
|
* @return
|
|
*/
|
|
private List<TaxAgentManageRangePO> listBySubAdminId(Long subAdminId) {
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().taxAgentSubAdminId(subAdminId).rangeType(TaxAgentRangeTypeEnum.SUBADMIN.getValue()).build());
|
|
}
|
|
|
|
private List<TaxAgentManageRangePO> listByIds(Collection<Long> ids) {
|
|
if (CollectionUtils.isEmpty(ids)) {
|
|
return Collections.emptyList();
|
|
}
|
|
return getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().ids(ids).build());
|
|
}
|
|
|
|
@Override
|
|
public void deleteByIds(Collection<Long> ids) {
|
|
// 查询管理范围
|
|
List<TaxAgentManageRangePO> taxAgentManageRanges = listByIds(ids);
|
|
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;
|
|
taxAgentManageRanges = this.listByTaxAgentIds(taxAgentIds);
|
|
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);
|
|
List<DataCollectionEmployee> allSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentId, allRanges);
|
|
|
|
List<DataCollectionEmployee> allSubAdminSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentId, allSubAdminRanges);
|
|
allSalaryEmployees.forEach(f -> {
|
|
allSubAdminSalaryEmployees.removeIf(a -> a.getEmployeeId().equals(f.getEmployeeId()));
|
|
});
|
|
if (CollectionUtils.isNotEmpty(allSubAdminSalaryEmployees)) {
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(110160, "分管理员存在超出整体人员范围以外的人员,不可删除"));
|
|
}
|
|
// 删除管理范围
|
|
getTaxAgentManageRangeMapper().deleteByIds(ids);
|
|
|
|
/** 同步本地人员范围的关联人员=========================== */
|
|
|
|
syncLocalEmp(taxAgentId, allSalaryEmployees, allSubAdminRanges);
|
|
// 记录日志 todo
|
|
}
|
|
|
|
@Override
|
|
public void deleteByTaxAgentIds(Collection<Long> taxAgentIds) {
|
|
getTaxAgentManageRangeMapper().deleteByTaxAgentIds(taxAgentIds);
|
|
// 删除管理范围下的所有人员
|
|
getTaxAgentEmpService(user).deleteByTaxAgentIds(taxAgentIds);
|
|
}
|
|
|
|
@Override
|
|
public void deleteBySubAdmins(Collection<Long> subAdminIds) {
|
|
if (CollectionUtils.isEmpty(subAdminIds)) {
|
|
return;
|
|
}
|
|
getTaxAgentManageRangeMapper().deleteBySubAdminIds(subAdminIds);
|
|
// 删除管理范围下的所有人员
|
|
// taxAgentSubAdminEmployeeService.deleteBySubAdminIds(subAdminIds);
|
|
}
|
|
|
|
//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 {
|
|
// }
|
|
// });
|
|
// }
|
|
|
|
/**
|
|
* 同步处理所有人员范围
|
|
*
|
|
* @param
|
|
*/
|
|
private void handleSyncTaxAgentEmpData() {
|
|
List<TaxAgentManageRangePO> allManageRanges = getTaxAgentManageRangeMapper().listAll();
|
|
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());
|
|
List<DataCollectionEmployee> allSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentId, allRanges);
|
|
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());
|
|
|
|
subAdminEmpSaveParamList.addAll(getTaxAgentSubAdminEmpSyncParam(taxAgentId, allSubAdminRanges));
|
|
});
|
|
Long employeeId = 0L;
|
|
// 同步管理员的人员
|
|
getTaxAgentEmpService(user).syncTaxAgentEmployee(taxAgentEmpSaveParamList, employeeId);
|
|
// 同步分管理员的人员
|
|
// taxAgentSubAdminEmployeeService.syncTaxAgentSubAdminEmployee(subAdminEmpSaveParamList, employeeId);
|
|
}
|
|
|
|
/**
|
|
* 获取个税扣缴义务人的同步参数
|
|
*
|
|
* @param taxAgentId
|
|
* @param allSalaryEmployees
|
|
* @return
|
|
*/
|
|
private TaxAgentEmpSaveParam getTaxAgentEmpSyncParam(Long taxAgentId, List<DataCollectionEmployee> allSalaryEmployees) {
|
|
return TaxAgentEmpSaveParam.builder()
|
|
.taxAgentId(taxAgentId)
|
|
.salaryEmployeeList(allSalaryEmployees)
|
|
.build();
|
|
}
|
|
|
|
/**
|
|
* 获取分管理员的同步参数
|
|
*
|
|
* @param taxAgentId
|
|
* @param allSubAdminRanges
|
|
* @return
|
|
*/
|
|
private List<TaxAgentSubAdminEmpSaveParam> getTaxAgentSubAdminEmpSyncParam(Long taxAgentId, List<TaxAgentManageRangePO> allSubAdminRanges) {
|
|
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());
|
|
List<DataCollectionEmployee> subAdminSalaryEmployees = this.getManageRangeSalaryEmployees(null, taxAgentId, singSubAdminRanges);
|
|
|
|
subAdminEmpSaveParamList.add(TaxAgentSubAdminEmpSaveParam.builder()
|
|
.taxAgentId(taxAgentId)
|
|
.subAdminId(e)
|
|
.salaryEmployeeList(subAdminSalaryEmployees)
|
|
.build());
|
|
});
|
|
return subAdminEmpSaveParamList;
|
|
}
|
|
|
|
/**
|
|
* 同步本地范围关联人员
|
|
*
|
|
* @param taxAgentId
|
|
* @param allSalaryEmployees 个税扣缴义务人下的所有人员
|
|
* @param allSubAdminRanges
|
|
* @param employeeId
|
|
*/
|
|
private void syncLocalEmp(Long taxAgentId, List<DataCollectionEmployee> allSalaryEmployees, List<TaxAgentManageRangePO> allSubAdminRanges, Long employeeId) {
|
|
log.info("同步个税扣缴人员范围");
|
|
try {
|
|
List<TaxAgentEmpSaveParam> taxAgentEmpSaveParamList = Collections.singletonList(getTaxAgentEmpSyncParam(taxAgentId, allSalaryEmployees));
|
|
// 同步个税扣缴义务人的人员
|
|
getTaxAgentEmpService(user).syncTaxAgentEmployee(taxAgentEmpSaveParamList, employeeId);
|
|
|
|
// List<TaxAgentSubAdminEmpSaveParam> subAdminEmpSaveParamList = getTaxAgentSubAdminEmpSyncParam(taxAgentId, allSubAdminRanges);
|
|
// 同步分管理员的人员
|
|
// taxAgentSubAdminEmployeeService.syncTaxAgentSubAdminEmployee(subAdminEmpSaveParamList, employeeId);
|
|
} catch (Exception e) {
|
|
log.error("同步个税扣缴人员范围异常", e);
|
|
}
|
|
}
|
|
}
|