weaver-hrm-salary/src/com/engine/salary/service/impl/TaxAgentV2ServiceImpl.java

642 lines
30 KiB
Java
Raw Normal View History

2022-05-19 14:50:01 +08:00
package com.engine.salary.service.impl;
import com.engine.core.impl.Service;
import com.engine.salary.constant.TaxAgentPermissionConstant;
import com.engine.salary.entity.datacollection.AddUpDeduction;
import com.engine.salary.entity.datacollection.AddUpSituation;
import com.engine.salary.entity.datacollection.po.OtherDeductionPO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
import com.engine.salary.entity.salaryarchive.po.SalaryArchivePO;
import com.engine.salary.entity.taxagent.bo.TaxAgentBO;
import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeDTO;
import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeTaxAgentDTO;
import com.engine.salary.entity.taxagent.dto.TaxAgentListDTO;
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeEmployeeDTO;
import com.engine.salary.entity.taxagent.param.TaxAgentAdminChangeCheckParam;
import com.engine.salary.entity.taxagent.param.TaxAgentQueryParam;
import com.engine.salary.entity.taxagent.param.TaxAgentSaveParam;
import com.engine.salary.entity.taxagent.po.*;
import com.engine.salary.enums.SalaryJobFlagEnum;
import com.engine.salary.enums.UserStatusEnum;
import com.engine.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum;
import com.engine.salary.enums.salarysob.SalaryEmployeeStatusEnum;
import com.engine.salary.enums.taxagent.TaxAgentRoleTypeEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.archive.SalaryArchiveMapper;
import com.engine.salary.mapper.datacollection.AddUpDeductionMapper;
import com.engine.salary.mapper.datacollection.AddUpSituationMapper;
import com.engine.salary.mapper.datacollection.EmployMapper;
import com.engine.salary.mapper.datacollection.OtherDeductionMapper;
import com.engine.salary.mapper.taxagent.TaxAgentMapper;
import com.engine.salary.service.*;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.PageUtil;
import com.google.common.collect.Lists;
import dm.jdbc.util.IdGenerator;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
public class TaxAgentV2ServiceImpl extends Service implements TaxAgentV2Service {
private TaxAgentMapper taxAgentMapper;
private EmployMapper employMapper;
//
// private ExtEmployeeService extEmployeeService;
private TaxAgentBaseService taxAgentBaseService;
private TaxAgentAdminService taxAgentAdminService;
private TaxAgentSubAdminService taxAgentSubAdminService;
private TaxAgentManageRangeService taxAgentManageRangeService;
private TaxAgentEmpService taxAgentEmpService;
private TaxAgentSubAdminEmpService taxAgentSubAdminEmpService;
private SalaryArchiveMapper salaryArchiveMapper;
private AddUpDeductionMapper addUpDeductionMapper;
private OtherDeductionMapper otherDeductionMapper;
private AddUpSituationMapper addUpSituationMapper;
// private PaymentAgencyMapper paymentAgencyMapper;
// private SIArchivesSocialMapper siArchivesSocialMapper;
// private SIArchivesFundMapper siArchivesFundMapper;
// private SIArchivesOtherMapper siArchivesOtherMapper;
// private AuthorityService authorityService;
private SalaryAcctRecordService salaryAcctRecordService;
private SIAccountService siAccountService;
private HrmCommonHrmStatusService hrmCommonHrmStatusService;
@Override
public TaxAgentRoleTypeEnum getRoleType(Long currentEmployeeId) {
TaxAgentRoleTypeEnum roleType = TaxAgentRoleTypeEnum.NONE;
if (isChief(currentEmployeeId)) {
return TaxAgentRoleTypeEnum.CHIEF;
}
// 是否开启分权
boolean isOpenDevolution = taxAgentBaseService.isOpenDevolution();
if (!isOpenDevolution) {
List<TaxAgentAdminPO> taxAgentAdmins = taxAgentAdminService.listByEmployeeId(currentEmployeeId);
if (CollectionUtils.isNotEmpty(taxAgentAdmins)) {
return TaxAgentRoleTypeEnum.ADMIN;
}
List<TaxAgentSubAdminPO> taxAgentSubAdmins = taxAgentSubAdminService.listByAndEmployeeId(currentEmployeeId);
if (CollectionUtils.isNotEmpty(taxAgentSubAdmins)) {
return TaxAgentRoleTypeEnum.SUBADMIN;
}
}
return roleType;
}
@Override
public Boolean isChief(Long currentEmployeeId) {
return currentEmployeeId == 1;
//return authorityService.checkPermissionSet(TaxAgentPermissionConstant.MENU_CODE, TaxAgentPermissionConstant.ITEM_CODE_DEVOLUTION, currentEmployeeId);
}
@Override
public Boolean isDefaultOpen(Long currentEmployeeId) {
return authorityService.checkPermissionSet(TaxAgentPermissionConstant.MENU_CODE, TaxAgentPermissionConstant.ITEM_CODE_DEFAULT, currentEmployeeId);
}
@Override
public Boolean isAdminEnable(Long currentEmployeeId) {
// 如果不是超管,是管理员
if (!isChief(currentEmployeeId)) {
// 没有开启分权
if (!isOpenDevolution()) {
return Boolean.FALSE;
} else {
// 自己有没有被分配为管理员
List<TaxAgentAdminPO> taxAgentAdminList = taxAgentAdminService.listByEmployeeId(currentEmployeeId);
return CollectionUtils.isNotEmpty(taxAgentAdminList);
}
}
return Boolean.TRUE;
}
@Override
public PageInfo<TaxAgentPO> listPage(TaxAgentQueryParam queryParam) {
PageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<TaxAgentPO> taxAgentPOS = taxAgentMapper.listBySome(queryParam);
return new PageInfo<>(taxAgentPOS);
}
@Override
public List<TaxAgentPO> list(TaxAgentQueryParam queryParam) {
return taxAgentMapper.listBySome(queryParam);
}
@Override
public List<TaxAgentPO> listByIds(Collection<Long> ids) {
return taxAgentMapper.listBySome(TaxAgentQueryParam.builder().ids(ids).build());
}
@Override
public List<TaxAgentPO> listAll() {
return taxAgentMapper.listAll();
}
@Override
public TaxAgentPO getById(Long id) {
return taxAgentMapper.getById(id);
}
@Override
public Collection<TaxAgentListDTO> findAll() {
List<TaxAgentPO> taxAgents = taxAgentMapper.listAll();
return TaxAgentBO.convertToListDTO(taxAgents);
}
@Override
public Collection<TaxAgentPO> listAllTaxAgents(Long employeeId) {
List<TaxAgentPO> taxAgents = taxAgentMapper.listAll();
return handleForDevolution(taxAgents, employeeId);
}
@Override
public Collection<TaxAgentPO> listAllTaxAgentsAsAdmin(Long employeeId) {
List<TaxAgentPO> taxAgents = taxAgentMapper.listAll();
// 是否开启分权
boolean isOpenDevolution = taxAgentBaseService.isOpenDevolution();
if (!isOpenDevolution) {
return taxAgents;
}
List<Long> taxAgentIds = taxAgents.stream().map(TaxAgentPO::getId).collect(Collectors.toList());
List<Long> enableTaxAgentIds = Lists.newArrayList();
// 1.判断自己是否是管理员, 如果是管理员,就是能够查看所属个税扣缴义务人
List<TaxAgentAdminPO> taxAgentAdminList = taxAgentAdminService.listByTaxAgentIds(taxAgentIds);
// 是管理员的列表
List<Long> adminTaxAgentIds = taxAgentAdminList.stream().filter(f -> f.getEmployeeId().equals(employeeId)).map(TaxAgentAdminPO::getTaxAgentId).collect(Collectors.toList());
enableTaxAgentIds.addAll(adminTaxAgentIds);
return taxAgents.stream().filter(f -> enableTaxAgentIds.contains(f.getId())).collect(Collectors.toList());
}
@Override
public Collection<TaxAgentEmployeeTaxAgentDTO> listAllTaxAgentsAsRange(List<Long> employeeIds) {
List<TaxAgentPO> taxAgents = taxAgentMapper.listAll();
List<Long> taxAgentIds = taxAgents.stream().map(TaxAgentPO::getId).collect(Collectors.toList());
List<TaxAgentEmpPO> taxAgentEmployees = taxAgentEmpService.listByTaxAgentIds(taxAgentIds);
if (CollectionUtils.isEmpty(taxAgentEmployees)) {
return Lists.newArrayList();
}
// 转换数据结构
List<Long> allemployeeIds = taxAgentEmployees.stream().map(TaxAgentEmpPO::getEmployeeId).distinct().collect(Collectors.toList());
return allemployeeIds.stream().map(m -> {
List<Long> enableTaxAgentIds = taxAgentEmployees.stream().filter(f -> f.getEmployeeId().equals(m)).map(TaxAgentEmpPO::getTaxAgentId).distinct()
.collect(Collectors.toList());
return TaxAgentEmployeeTaxAgentDTO.builder()
.employeeId(m)
.taxAgentIds(enableTaxAgentIds)
.build();
}).collect(Collectors.toList());
}
@Override
public String save(TaxAgentSaveParam saveParam, Long employeeId) {
// 是否开启分权
boolean isOpenDevolution = taxAgentBaseService.isOpenDevolution();
if (isOpenDevolution && saveParam.getAdminUserId() == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(106271, "请选择管理员"));
}
List<TaxAgentPO> taxAgents = taxAgentMapper.listByName(saveParam.getName());
if (CollectionUtils.isNotEmpty(taxAgents)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98080, "名称不允许重复"));
}
// PaymentAgencyPO paymentAgencyPO = new LambdaQueryChainWrapper<>(paymentAgencyMapper)
// .eq(PaymentAgencyPO::getTenantKey)
// .eq(PaymentAgencyPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue())
// .eq(PaymentAgencyPO::getAgencyName, saveParam.getName())
// .one();
// if (paymentAgencyPO != null) {
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(115130, "名称不允许与社保福利代缴机构名称重复"));
// }
// 保存
saveParam.setId(IdGenerator.generate());
TaxAgentPO taxAgent = TaxAgentBO.convertToPO(saveParam, employeeId);
taxAgentMapper.insert(taxAgent);
if (isOpenDevolution) {
taxAgentAdminService.batchInsert(saveParam.getId(), Collections.singletonList(saveParam.getAdminUserId()));
}
// 记录日志
// SalaryLoggerUtil.recordAddSingleLog(taxAgentLoggerTemplate,
// taxAgent.getId(),
// taxAgent.getName(),
// SalaryI18nUtil.getI18nLabel( 93766, "新增个税扣缴义务人"),
// SalaryI18nUtil.getI18nLabel( 93766, "新增个税扣缴义务人"),
// taxAgent);
return StringUtils.EMPTY + taxAgent.getId();
}
// @Override
// public String paymentAgencyUpdate(TaxAgentPO taxAgentPO, Long employeeId) {
// taxAgentMapper.updateById(taxAgentPO);
// return "";
// }
@Override
@Transactional(rollbackFor = Exception.class)
public String update(TaxAgentSaveParam saveParam, Long employeeId) {
TaxAgentPO taxAgent = getById(saveParam.getId());
if (taxAgent == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100545, "个税扣缴义务人不存在"));
}
// 是否开启分权
boolean isOpenDevolution = taxAgentBaseService.isOpenDevolution();
if (isOpenDevolution && saveParam.getAdminUserId() == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(106271, "请选择管理员"));
}
List<TaxAgentPO> individualTaxWithholdingAgents = taxAgentMapper.listByName(saveParam.getName());
boolean nameExist = individualTaxWithholdingAgents.stream().anyMatch(e -> !Objects.equals(e.getId(), saveParam.getId()));
if (nameExist) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98080, "名称不允许重复"));
}
TaxAgentPO taxAgentNew = new TaxAgentPO();
BeanUtils.copyProperties(taxAgent, taxAgentNew);
BeanUtils.copyProperties(saveParam, taxAgentNew);
taxAgentNew.setUpdateTime(new Date());
taxAgentMapper.update(taxAgentNew);
if (isOpenDevolution) {
Boolean isUnEnableChange = adminChangeCheck(TaxAgentAdminChangeCheckParam.builder()
.taxAgentId(saveParam.getId())
.adminUserId(saveParam.getAdminUserId())
.build(), employeeId);
if (isUnEnableChange) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(115937, "该管理员有未归档核算数据,不可更换管理员"));
}
// 删除管理员
taxAgentAdminService.deleteByTaxAgentIds(Collections.singletonList(taxAgent.getId()));
// 新增管理员
taxAgentAdminService.batchInsert(saveParam.getId(), Collections.singletonList(saveParam.getAdminUserId()));
}
// 记录日志
// SalaryLoggerUtil.recordUpdateSingleLog(taxAgentLoggerTemplate,
// taxAgent.getId(),
// taxAgentNew.getName(),
// SalaryI18nUtil.getI18nLabel(93767, "编辑个税扣缴义务人"),
// SalaryI18nUtil.getI18nLabel(93767, "编辑个税扣缴义务人"),
// taxAgent,
// taxAgentNew);
return StringUtils.EMPTY;
}
@Override
public Boolean adminChangeCheck(TaxAgentAdminChangeCheckParam checkParam, Long currentEmployeeId) {
List<TaxAgentAdminPO> taxAgentAdminList = taxAgentAdminService.listByTaxAgentIds(Collections.singletonList(checkParam.getTaxAgentId()));
Long adminUserId = CollectionUtils.isNotEmpty(taxAgentAdminList) ? taxAgentAdminList.get(0).getEmployeeId() : 0L;
boolean isChanged = checkParam.getAdminUserId() != null && !adminUserId.equals(checkParam.getAdminUserId());
// 更换了管理员
if (isChanged) {
// 检查是否核算
//todo 1.社保福利档案是否有核算未归档
Boolean checkedValue = false;// siAccountService.changeAdminUnfiledCheck(adminUserId);
// 2.薪资核算是否有核算未归档
List<SalaryAcctRecordPO> salaryAcctRecords = salaryAcctRecordService.listByStatusAndEmployeeId(SalaryAcctRecordStatusEnum.NOT_ARCHIVED, adminUserId);
if (CollectionUtils.isNotEmpty(salaryAcctRecords) || checkedValue) {
return Boolean.TRUE;
}
}
return Boolean.FALSE;
}
@Override
@Transactional(rollbackFor = Exception.class)
public String delete(Collection<Long> ids, Long employeeId) {
List<TaxAgentPO> taxAgents = taxAgentMapper.listBySome(TaxAgentQueryParam.builder().ids(ids).build());
if (CollectionUtils.isEmpty(taxAgents)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(85382, "要删除的个税扣缴义务人在不存在或已删除"));
}
// 正在使用的记录不允许删除
boolean checkUsed = checkUsed(ids);
if (checkUsed) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100570, "正在使用的记录不允许删除"));
}
// 删除管理员
taxAgentAdminService.deleteByTaxAgentIds(ids);
// 删除分管理员和对应管理范围
taxAgentSubAdminService.deleteByTaxAgentIds(ids);
// 删除人员范围
taxAgentManageRangeService.deleteByTaxAgentIds(ids);
taxAgentMapper.deleteByIds(ids);
// 记录日志
// taxAgents.forEach(e -> SalaryLoggerUtil.recordDeleteSingleLog(taxAgentLoggerTemplate,
// e.getId(),
// e.getName(),
// SalaryI18nUtil.getI18nLabel(100546, "删除个税扣缴义务人"),
// SalaryI18nUtil.getI18nLabel(100546, "删除个税扣缴义务人") + "" + e.getName(),
// e));
return StringUtils.EMPTY;
}
/**
* 检查正在被使用的记录
*
* @param ids
* @return
*/
private boolean checkUsed(Collection<Long> ids) {
// 被薪资档案引用
List<SalaryArchivePO> salaryArchiveList = new LambdaQueryChainWrapper<>(salaryArchiveMapper)
.eq(SalaryArchivePO::getDeleteType, 0)
.eq(SalaryArchivePO::getTenantKey)
.in(SalaryArchivePO::getTaxAgentId, ids)
.list();
salaryArchiveMapper.listSome(SalaryArchivePO.builder().t)
if (CollectionUtils.isNotEmpty(salaryArchiveList)) {
return Boolean.TRUE;
}
// todo 被社保福利档案引用
// List<InsuranceArchivesSocialSchemePO> socialSchemePOList = new LambdaQueryChainWrapper<>(siArchivesSocialMapper)
// .eq(InsuranceArchivesSocialSchemePO::getTenantKey)
// .eq(InsuranceArchivesSocialSchemePO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue())
// .in(InsuranceArchivesSocialSchemePO::getPaymentOrganization, ids)
// .list();
// if (CollectionUtils.isNotEmpty(socialSchemePOList)) {
// return Boolean.TRUE;
// }
// List<InsuranceArchivesFundSchemePO> fundSchemePOList = new LambdaQueryChainWrapper<>(siArchivesFundMapper)
// .eq(InsuranceArchivesFundSchemePO::getTenantKey)
// .eq(InsuranceArchivesFundSchemePO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue())
// .in(InsuranceArchivesFundSchemePO::getPaymentOrganization, ids)
// .list();
// if (CollectionUtils.isNotEmpty(fundSchemePOList)) {
// return Boolean.TRUE;
// }
// List<InsuranceArchivesOtherSchemePO> otherSchemePOList = new LambdaQueryChainWrapper<>(siArchivesOtherMapper)
// .eq(InsuranceArchivesOtherSchemePO::getTenantKey)
// .eq(InsuranceArchivesOtherSchemePO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue())
// .in(InsuranceArchivesOtherSchemePO::getPaymentOrganization, ids)
// .list();
// if (CollectionUtils.isNotEmpty(otherSchemePOList)) {
// return Boolean.TRUE;
// }
// 被外部人员引用
// List<ExtEmployeePO> extEmployeeList = extEmployeeService.listAll(tenantKey);
// List<Long> extTaxAgentIds = extEmployeeList.stream().map(ExtEmployeePO::getTaxAgentId).distinct().collect(Collectors.toList());
// if (CollectionUtils.isNotEmpty(extTaxAgentIds)) {
// return ids.stream().anyMatch(e -> extTaxAgentIds.stream().anyMatch(f -> f.equals(e)));
// }
// 被累计专项附加扣除引用
List<AddUpDeduction> addUpDeductionList = addUpDeductionMapper.listSome(AddUpDeduction.builder().taxAgentIds(ids).build());
if (CollectionUtils.isNotEmpty(addUpDeductionList)) {
return Boolean.TRUE;
}
// 被其他免税扣除引用
List<OtherDeductionPO> otherDeductionList = otherDeductionMapper.listSome(OtherDeductionPO.builder().taxAgentIds(ids).build());
if (CollectionUtils.isNotEmpty(otherDeductionList)) {
return Boolean.TRUE;
}
// 被往期累计情况引用
List<AddUpSituation> addUpSituationList = addUpSituationMapper.listSome(AddUpSituation.builder().taxAgentIds(ids).build());
if (CollectionUtils.isNotEmpty(addUpSituationList)) {
return Boolean.TRUE;
}
return Boolean.FALSE;
}
@Override
public List<Map<String, Object>> selectList(Long currentEmployeeId) {
List<TaxAgentPO> taxAgents = taxAgentMapper.listAll();
taxAgents = handleForDevolution(taxAgents, currentEmployeeId);
return taxAgents.stream().map(m -> {
Map<String, Object> map = new HashMap<>(2);
map.put("id", String.valueOf(m.getId()));
map.put("content", m.getName());
return map;
}).collect(Collectors.toList());
}
/**
* 分权处理
*
* @param taxAgents
* @param currentEmployeeId
* @return
*/
private List<TaxAgentPO> handleForDevolution(List<TaxAgentPO> taxAgents, Long currentEmployeeId) {
// 是否开启分权
boolean isOpenDevolution = taxAgentBaseService.isOpenDevolution();
if (!isOpenDevolution || isChief(currentEmployeeId)) {
return taxAgents;
}
List<Long> taxAgentIds = taxAgents.stream().map(TaxAgentPO::getId).collect(Collectors.toList());
List<Long> enableTaxAgentIds = Lists.newArrayList();
// 1.判断自己是否是管理员, 如果是管理员,就是能够查看所属个税扣缴义务人
List<TaxAgentAdminPO> taxAgentAdminList = taxAgentAdminService.listByTaxAgentIdsAndEmployeeId(taxAgentIds, currentEmployeeId);
// 是管理员的列表
List<Long> adminTaxAgentIds = taxAgentAdminList.stream().map(TaxAgentAdminPO::getTaxAgentId).collect(Collectors.toList());
enableTaxAgentIds.addAll(adminTaxAgentIds);
// 2.根据作为非管理员查找自己作为分管理员的个税扣缴义务人id
List<Long> noAdminTaxAgentIds = taxAgents.stream()
.map(TaxAgentPO::getId)
.filter(id -> !adminTaxAgentIds.contains(id)).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(noAdminTaxAgentIds)) {
List<TaxAgentSubAdminPO> taxAgentSubAdmins = taxAgentSubAdminService.listByTaxAgentIdsAndEmployeeId(noAdminTaxAgentIds, currentEmployeeId);
List<Long> sunAdminTaxAgentIds = taxAgentSubAdmins.stream().map(TaxAgentSubAdminPO::getTaxAgentId).collect(Collectors.toList());
enableTaxAgentIds.addAll(sunAdminTaxAgentIds);
}
return taxAgents.stream().filter(f -> enableTaxAgentIds.contains(f.getId())).collect(Collectors.toList());
}
@Override
public Boolean isOpenDevolution() {
return taxAgentBaseService.isOpenDevolution();
}
@Override
public List<TaxAgentManageRangeEmployeeDTO> listTaxAgentAndEmployeeTree(Long employeeId) {
return listTaxAgentAndEmployeeTree(null, employeeId);
}
@Override
public List<TaxAgentEmployeeDTO> listTaxAgentAndEmployee(Long employeeId) {
return listTaxAgentAndEmployee(null, employeeId);
}
@Override
public List<TaxAgentManageRangeEmployeeDTO> listTaxAgentAndEmployeeTree(SalaryEmployeeStatusEnum employeeStatus, Long employeeId) {
List<TaxAgentManageRangeEmployeeDTO> taxAgentManageRangeEmployeeList = Lists.newArrayList();
// 所有个税扣缴义务人
List<TaxAgentPO> allTaxAgents = listAll();
if (CollectionUtils.isEmpty(allTaxAgents)) {
return taxAgentManageRangeEmployeeList;
}
List<Long> taxAgentIds = allTaxAgents.stream().map(TaxAgentPO::getId).collect(Collectors.toList());
List<TaxAgentEmployeePO> allEmployees = taxAgentMapper.listEmployee();
if (employeeStatus != null) {
List<String> personnelStatusList;
// 查询人员状态
if (employeeStatus.equals(SalaryEmployeeStatusEnum.NORMAL)) {
allEmployees = allEmployees.stream().filter(f -> UserStatusEnum.getNormalStatus().contains(f.getStatus())).collect(Collectors.toList());
} else if (employeeStatus.equals(SalaryEmployeeStatusEnum.UNAVAILABLE)) {
allEmployees = allEmployees.stream().filter(f -> UserStatusEnum.getUnavailableStatus().contains(f.getStatus())).collect(Collectors.toList());
}
}
// 是否开启分权
if (!isOpenDevolution() || isChief(employeeId)) {
return getTaxAgentEmp(allTaxAgents, taxAgentIds, allEmployees);
}
// 1.判断自己是否是管理员, 如果是管理员,就是能够操作所属个税扣缴义务人下的所有人的数据
List<TaxAgentAdminPO> taxAgentAdminList = taxAgentAdminService.listByTaxAgentIdsAndEmployeeId(taxAgentIds, employeeId);
// 是管理员的列表
List<Long> adminTaxAgentIds = taxAgentAdminList.stream().map(TaxAgentAdminPO::getTaxAgentId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(adminTaxAgentIds)) {
taxAgentManageRangeEmployeeList.addAll(getTaxAgentEmp(allTaxAgents, adminTaxAgentIds, allEmployees));
}
// 2.根据作为非管理员查找自己作为分管理员, 对应的管理范围人员
List<Long> noAdminTaxAgentIds = allTaxAgents.stream()
.map(TaxAgentPO::getId)
.filter(id -> !adminTaxAgentIds.contains(id)).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(noAdminTaxAgentIds)) {
taxAgentManageRangeEmployeeList.addAll(getTaxAgentSubAdminEmp(allTaxAgents, noAdminTaxAgentIds, allEmployees));
}
return taxAgentManageRangeEmployeeList;
}
/**
* 获取分管理员的关联人员
*
* @param allTaxAgents
* @param noAdminTaxAgentIds
* @param allEmployees
* @return
*/
private List<TaxAgentManageRangeEmployeeDTO> getTaxAgentSubAdminEmp(List<TaxAgentPO> allTaxAgents, List<Long> noAdminTaxAgentIds, List<TaxAgentEmployeePO> allEmployees) {
List<TaxAgentManageRangeEmployeeDTO> taxAgentManageRangeEmployeeList = Lists.newArrayList();
List<TaxAgentSubAdminEmpPO> taxAgentEmps = taxAgentSubAdminEmpService.listByTaxAgentIds(noAdminTaxAgentIds);
taxAgentEmps = taxAgentEmps.stream().filter(f -> allEmployees.stream().anyMatch(e -> e.getEmployeeId().equals(f.getEmployeeId()))).collect(Collectors.toList());
List<TaxAgentSubAdminEmpPO> finalTaxAgentEmps = taxAgentEmps;
noAdminTaxAgentIds.forEach(e -> {
Optional<TaxAgentPO> optionalTaxAgent = allTaxAgents.stream().filter(t -> t.getId().equals(e)).findFirst();
String taxAgentName = (optionalTaxAgent.isPresent() ? optionalTaxAgent.get().getName() : "");
List<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> taxAgentEmployees = finalTaxAgentEmps.stream().filter(f -> f.getTaxAgentId().equals(e)).map(m -> {
TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee taxAgentEmployee = new TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee();
taxAgentEmployee.setEmployeeId(m.getEmployeeId());
taxAgentEmployee.setUsername(m.getEmployeeName());
return taxAgentEmployee;
}).collect(Collectors.toList());
taxAgentManageRangeEmployeeList.add(
TaxAgentManageRangeEmployeeDTO.builder()
.taxAgentId(e)
.taxAgentName(taxAgentName)
.employeeList(taxAgentEmployees)
.build()
);
});
return taxAgentManageRangeEmployeeList;
}
/**
* 获取个税口角义务人的关联人员
*
* @param allTaxAgents
* @param taxAgentIds
* @return
*/
private List<TaxAgentManageRangeEmployeeDTO> getTaxAgentEmp(List<TaxAgentPO> allTaxAgents, List<Long> taxAgentIds, List<TaxAgentEmployeePO> allEmployees) {
List<TaxAgentManageRangeEmployeeDTO> taxAgentManageRangeEmployeeList = Lists.newArrayList();
List<TaxAgentEmpPO> taxAgentEmps = taxAgentEmpService.listByTaxAgentIds(taxAgentIds);
taxAgentEmps = taxAgentEmps.stream().filter(f -> allEmployees.stream().anyMatch(e -> e.getEmployeeId().equals(f.getEmployeeId()))).collect(Collectors.toList());
List<TaxAgentEmpPO> finalTaxAgentEmps = taxAgentEmps;
taxAgentIds.forEach(e -> {
Optional<TaxAgentPO> optionalTaxAgent = allTaxAgents.stream().filter(t -> t.getId().equals(e)).findFirst();
String taxAgentName = (optionalTaxAgent.isPresent() ? optionalTaxAgent.get().getName() : "");
List<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> taxAgentEmployees = finalTaxAgentEmps.stream().filter(f -> f.getTaxAgentId().equals(e)).map(m -> {
TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee taxAgentEmployee = new TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee();
taxAgentEmployee.setEmployeeId(m.getEmployeeId());
taxAgentEmployee.setUsername(m.getEmployeeName());
return taxAgentEmployee;
}).collect(Collectors.toList());
taxAgentManageRangeEmployeeList.add(
TaxAgentManageRangeEmployeeDTO.builder()
.taxAgentId(e)
.taxAgentName(taxAgentName)
.employeeList(taxAgentEmployees)
.build()
);
});
return taxAgentManageRangeEmployeeList;
}
@Override
public List<TaxAgentEmployeeDTO> listTaxAgentAndEmployee(SalaryEmployeeStatusEnum employeeStatus, Long employeeId) {
List<TaxAgentEmployeeDTO> taxAgentEmployeeList = Lists.newArrayList();
List<TaxAgentManageRangeEmployeeDTO> taxAgentManageRangeEmployeeList = listTaxAgentAndEmployeeTree(employeeStatus, employeeId);
taxAgentManageRangeEmployeeList.forEach(m -> {
List<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> employeeList = m.getEmployeeList();
if (CollectionUtils.isEmpty(employeeList)) {
taxAgentEmployeeList.add(TaxAgentEmployeeDTO.builder()
.taxAgentId(m.getTaxAgentId())
.taxAgentName(m.getTaxAgentName())
.employeeId(null)
.username(null)
.build());
} else {
employeeList.forEach(f -> taxAgentEmployeeList.add(TaxAgentEmployeeDTO.builder()
.taxAgentId(m.getTaxAgentId())
.taxAgentName(m.getTaxAgentName())
.employeeId(f.getEmployeeId())
.username(f.getUsername())
.build()));
}
});
return taxAgentEmployeeList;
}
}