2022-05-18 09:19:50 +08:00
|
|
|
package com.engine.salary.service.impl;
|
|
|
|
|
|
2022-11-22 15:37:07 +08:00
|
|
|
import com.cloudstore.dev.api.util.Util_DataCache;
|
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.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;
|
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.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-11-22 15:37:07 +08:00
|
|
|
import com.engine.salary.service.TaxAgentEmpService;
|
|
|
|
|
import com.engine.salary.service.TaxAgentManageRangeService;
|
|
|
|
|
import com.engine.salary.service.TaxAgentService;
|
2022-05-18 09:19:50 +08:00
|
|
|
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;
|
2022-11-22 15:37:07 +08:00
|
|
|
import com.weaver.util.threadPool.ThreadPoolUtil;
|
|
|
|
|
import com.weaver.util.threadPool.entity.LocalRunnable;
|
2022-05-18 09:19:50 +08:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
2022-05-24 09:14:26 +08:00
|
|
|
import weaver.hrm.User;
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
import java.util.*;
|
2022-06-09 17:45:28 +08:00
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
import java.util.concurrent.Executors;
|
2022-05-18 09:19:50 +08:00
|
|
|
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-06-09 17:45:28 +08:00
|
|
|
private static final ExecutorService taskExecutor = Executors.newFixedThreadPool(5);
|
|
|
|
|
|
|
|
|
|
|
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-07-11 09:39:57 +08:00
|
|
|
private TaxAgentService getTaxAgentService(User user) {
|
2022-05-31 21:05:59 +08:00
|
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
2022-05-24 09:14:26 +08:00
|
|
|
}
|
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
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
private EmployMapper getEmployMapper() {
|
|
|
|
|
return MapperProxyFactory.getProxy(EmployMapper.class);
|
|
|
|
|
}
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
|
2022-05-24 09:14:26 +08:00
|
|
|
private EmployBiz employBiz = new EmployBiz();
|
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
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取范围下的人员
|
|
|
|
|
*
|
|
|
|
|
* @param taxAgentId
|
|
|
|
|
* @param allTaxAgentManageRanges
|
2022-11-22 15:37:07 +08:00
|
|
|
* @param salaryEmployees
|
2022-05-18 09:19:50 +08:00
|
|
|
* @return
|
|
|
|
|
*/
|
2022-11-22 15:37:07 +08:00
|
|
|
private List<DataCollectionEmployee> getManageRangeSalaryEmployees(Long taxAgentId, List<TaxAgentManageRangePO> allTaxAgentManageRanges, List<DataCollectionEmployee> salaryEmployees) {
|
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;
|
|
|
|
|
}
|
|
|
|
|
// 根据上一步的查询参数查询人员
|
2022-11-22 15:37:07 +08:00
|
|
|
includeSalaryEmployees = listSalaryEmployeeByManageRange(includeTaxAgentManageRanges, salaryEmployees);
|
2022-05-18 09:19:50 +08:00
|
|
|
if (CollectionUtils.isEmpty(includeSalaryEmployees)) {
|
|
|
|
|
return includeSalaryEmployees;
|
|
|
|
|
}
|
|
|
|
|
// 查询管理范围(从范围中排除)
|
|
|
|
|
List<TaxAgentManageRangePO> excludeTaxAgentManageRanges = excludeAllTaxAgentManageRanges.stream().filter(f -> f.getTaxAgentId().equals(taxAgentId)).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(excludeTaxAgentManageRanges)) {
|
|
|
|
|
// 根据上一步的查询参数查询人员
|
2022-11-22 15:37:07 +08:00
|
|
|
List<DataCollectionEmployee> excludeSalaryEmployees = listSalaryEmployeeByManageRange(excludeTaxAgentManageRanges, salaryEmployees);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 需要排除的人员范围
|
|
|
|
|
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
|
|
|
|
|
*/
|
2022-11-22 15:37:07 +08:00
|
|
|
private List<DataCollectionEmployee> listSalaryEmployeeByManageRange(List<TaxAgentManageRangePO> taxAgentManageRanges, List<DataCollectionEmployee> salaryEmployees) {
|
|
|
|
|
if (CollectionUtils.isEmpty(taxAgentManageRanges) || CollectionUtils.isEmpty(salaryEmployees)) {
|
2022-05-18 09:19:50 +08:00
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
List<DataCollectionEmployee> salaryEmployeeList = Lists.newArrayList();
|
|
|
|
|
for (TaxAgentManageRangePO manageRange : taxAgentManageRanges) {
|
|
|
|
|
salaryEmployeeList.addAll(salaryEmployees.stream()
|
|
|
|
|
.filter(salaryEmployee -> {
|
2022-11-22 15:37:07 +08:00
|
|
|
if (StringUtils.isEmpty(manageRange.getEmployeeStatus()) || !manageRange.getEmployeeStatus().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())
|
2022-06-01 17:45:49 +08:00
|
|
|
&& Objects.equals(manageRange.getTargetId(), salaryEmployee.getSubcompanyid())) {
|
2022-05-18 09:19:50 +08:00
|
|
|
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());
|
|
|
|
|
}
|
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-06-01 15:18:10 +08:00
|
|
|
dtoPage.setList(SalaryPageUtil.subList(dtoPage.getPageNum(), dtoPage.getPageSize(), 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-06-10 14:21:21 +08:00
|
|
|
|
|
|
|
|
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("对象不能为空");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-07-11 09:39:57 +08:00
|
|
|
// 查询个税扣缴义务人
|
|
|
|
|
TaxAgentPO taxAgent = getTaxAgentService(user).getById(saveParam.getTaxAgentId());
|
2022-05-18 09:19:50 +08:00
|
|
|
if (Objects.isNull(taxAgent)) {
|
2022-06-21 22:37:22 +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
|
|
|
|
2022-07-11 09:39:57 +08:00
|
|
|
/* 检查当前个税扣缴义务人的所有人员范围与所有分管理员的管理范围===========================start */
|
2022-05-18 09:19:50 +08:00
|
|
|
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-11-22 15:37:07 +08:00
|
|
|
|
|
|
|
|
List<DataCollectionEmployee> salaryEmployees = getEmployMapper().listAll();
|
|
|
|
|
List<DataCollectionEmployee> allSalaryEmployees = this.getManageRangeSalaryEmployees(saveParam.getTaxAgentId(), allRanges, salaryEmployees);
|
2022-07-11 09:39:57 +08:00
|
|
|
|
|
|
|
|
/* 检查当前个税扣缴义务人的所有人员范围与所有分管理员的管理范围===========================end */
|
2022-05-18 09:19:50 +08:00
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedInsertTaxAgentManageRanges())) {
|
2022-05-24 09:14:26 +08:00
|
|
|
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));
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
2022-07-11 09:39:57 +08:00
|
|
|
/* 同步本地人员范围的关联人员=========================== */
|
2022-06-01 15:18:10 +08:00
|
|
|
syncLocalEmp(saveParam.getTaxAgentId(), allSalaryEmployees, null);
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 16:41:11 +08:00
|
|
|
private void syncLocalEmp(Long taxAgentId, List<DataCollectionEmployee> allSalaryEmployees, List<TaxAgentManageRangePO> allSubAdminRanges) {
|
2022-07-11 09:39:57 +08:00
|
|
|
log.info("开始同步人员step");
|
2022-06-09 17:45:28 +08:00
|
|
|
taskExecutor.execute(() -> {
|
|
|
|
|
syncLocalEmp(taxAgentId, allSalaryEmployees, allSubAdminRanges, (long) user.getUID());
|
|
|
|
|
});
|
2022-06-10 14:21:21 +08:00
|
|
|
|
2022-05-31 16:41:11 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-18 09:19:50 +08:00
|
|
|
/**
|
|
|
|
|
* 获取个税口角义务人的管理范围
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
}
|
|
|
|
|
|
2022-05-31 16:41:11 +08:00
|
|
|
|
2022-05-18 09:19:50 +08:00
|
|
|
/**
|
|
|
|
|
* 根据分管理员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-11-22 15:37:07 +08:00
|
|
|
List<DataCollectionEmployee> salaryEmployees = getEmployMapper().listAll();
|
2022-11-22 15:53:05 +08:00
|
|
|
List<DataCollectionEmployee> allSalaryEmployees = this.getManageRangeSalaryEmployees(taxAgentId, allRanges, salaryEmployees);
|
2022-11-22 15:37:07 +08:00
|
|
|
|
2022-11-22 15:53:05 +08:00
|
|
|
List<DataCollectionEmployee> allSubAdminSalaryEmployees = this.getManageRangeSalaryEmployees(taxAgentId, allSubAdminRanges, salaryEmployees);
|
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
|
|
|
/** 同步本地人员范围的关联人员=========================== */
|
2022-05-31 16:41:11 +08:00
|
|
|
|
|
|
|
|
syncLocalEmp(taxAgentId, allSalaryEmployees, allSubAdminRanges);
|
2022-05-18 09:19:50 +08:00
|
|
|
// 记录日志 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-05-24 09:14:26 +08:00
|
|
|
* 同步处理所有人员范围
|
2022-05-18 09:19:50 +08:00
|
|
|
*
|
2022-11-22 15:37:07 +08:00
|
|
|
* @param taxAgentIds 为空代表所有个税扣缴义务人
|
2022-05-18 09:19:50 +08:00
|
|
|
*/
|
2022-11-22 15:37:07 +08:00
|
|
|
private void handleSyncTaxAgentEmpData(List<Long> taxAgentIds) {
|
|
|
|
|
|
|
|
|
|
List<TaxAgentManageRangePO> allManageRanges = getTaxAgentManageRangeMapper().listSome(TaxAgentManageRangePO.builder().taxAgentIds(taxAgentIds).build());
|
|
|
|
|
|
2022-05-18 09:19:50 +08:00
|
|
|
if (CollectionUtils.isEmpty(allManageRanges)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-22 15:37:07 +08:00
|
|
|
taxAgentIds = allManageRanges.stream().map(TaxAgentManageRangePO::getTaxAgentId).distinct().collect(Collectors.toList());
|
|
|
|
|
// 获取所有人员
|
|
|
|
|
List<DataCollectionEmployee> salaryEmployees = getEmployMapper().listAll();
|
2022-05-18 09:19:50 +08:00
|
|
|
|
|
|
|
|
List<TaxAgentEmpSaveParam> taxAgentEmpSaveParamList = Lists.newArrayList();
|
|
|
|
|
List<TaxAgentSubAdminEmpSaveParam> subAdminEmpSaveParamList = Lists.newArrayList();
|
2022-11-22 15:37:07 +08:00
|
|
|
|
|
|
|
|
Map<String, List<TaxAgentManageRangePO>> allRangeMap = SalaryEntityUtil.group2Map(allManageRanges, k -> k.getTaxAgentId() + "-" + k.getRangeType());
|
2022-05-18 09:19:50 +08:00
|
|
|
taxAgentIds.forEach(taxAgentId -> {
|
|
|
|
|
// 当前个税扣缴义务人的所有范围
|
2022-11-22 15:37:07 +08:00
|
|
|
List<TaxAgentManageRangePO> allRanges = Optional.ofNullable(allRangeMap.get(taxAgentId + "-" + TaxAgentRangeTypeEnum.TAXAGENT.getValue())).orElse(Collections.emptyList());
|
|
|
|
|
List<DataCollectionEmployee> allSalaryEmployees = this.getManageRangeSalaryEmployees(taxAgentId, allRanges, salaryEmployees);
|
2022-05-18 09:19:50 +08:00
|
|
|
taxAgentEmpSaveParamList.add(getTaxAgentEmpSyncParam(taxAgentId, allSalaryEmployees));
|
|
|
|
|
|
2022-11-22 15:37:07 +08:00
|
|
|
List<TaxAgentManageRangePO> allSubAdminRanges = Optional.ofNullable(allRangeMap.get(taxAgentId + "-" + TaxAgentRangeTypeEnum.SUBADMIN.getValue())).orElse(Collections.emptyList());
|
|
|
|
|
subAdminEmpSaveParamList.addAll(getTaxAgentSubAdminEmpSyncParam(taxAgentId, allSubAdminRanges, salaryEmployees));
|
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-11-22 15:37:07 +08:00
|
|
|
// taxAgentSubAdminEmployeeService.syncTaxAgentSubAdminEmployee(subAdminEmpSaveParamList, employeeId, tenantKey);
|
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
|
2022-11-22 15:37:07 +08:00
|
|
|
* @param salaryEmployees
|
2022-05-18 09:19:50 +08:00
|
|
|
* @return
|
|
|
|
|
*/
|
2022-11-22 15:37:07 +08:00
|
|
|
private List<TaxAgentSubAdminEmpSaveParam> getTaxAgentSubAdminEmpSyncParam(Long taxAgentId, List<TaxAgentManageRangePO> allSubAdminRanges, List<DataCollectionEmployee> salaryEmployees) {
|
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-11-22 15:37:07 +08:00
|
|
|
List<DataCollectionEmployee> subAdminSalaryEmployees = this.getManageRangeSalaryEmployees(taxAgentId, singSubAdminRanges, salaryEmployees);
|
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-06-09 17:45:28 +08:00
|
|
|
log.info("同步个税扣缴人员范围");
|
|
|
|
|
try {
|
|
|
|
|
List<TaxAgentEmpSaveParam> taxAgentEmpSaveParamList = Collections.singletonList(getTaxAgentEmpSyncParam(taxAgentId, allSalaryEmployees));
|
|
|
|
|
// 同步个税扣缴义务人的人员
|
|
|
|
|
getTaxAgentEmpService(user).syncTaxAgentEmployee(taxAgentEmpSaveParamList, employeeId);
|
2022-05-18 09:19:50 +08:00
|
|
|
|
2022-05-31 16:41:11 +08:00
|
|
|
// List<TaxAgentSubAdminEmpSaveParam> subAdminEmpSaveParamList = getTaxAgentSubAdminEmpSyncParam(taxAgentId, allSubAdminRanges);
|
2022-06-09 17:45:28 +08:00
|
|
|
// 同步分管理员的人员
|
2022-05-31 16:41:11 +08:00
|
|
|
// taxAgentSubAdminEmployeeService.syncTaxAgentSubAdminEmployee(subAdminEmpSaveParamList, employeeId);
|
2022-06-09 17:45:28 +08:00
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("同步个税扣缴人员范围异常", e);
|
|
|
|
|
}
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|
2022-11-22 15:37:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 同步人员范围
|
|
|
|
|
*
|
|
|
|
|
* @param taxAgentIds
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2022-11-22 15:53:05 +08:00
|
|
|
public void syncManageRange(List<Long> taxAgentIds,String index) {
|
2022-11-22 15:37:07 +08:00
|
|
|
// 开始同步
|
|
|
|
|
LocalRunnable localRunnable = new LocalRunnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void execute() {
|
|
|
|
|
try {
|
|
|
|
|
Util_DataCache.setObjVal(index, "1");
|
|
|
|
|
handleSyncTaxAgentEmpData(taxAgentIds);
|
|
|
|
|
} finally {
|
|
|
|
|
Util_DataCache.clearVal(index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
ThreadPoolUtil.execute(localRunnable);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 09:19:50 +08:00
|
|
|
}
|