package com.engine.salary.service.impl; import com.engine.common.service.HrmCommonService; import com.engine.common.service.impl.HrmCommonServiceImpl; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; import com.engine.salary.biz.SalaryRoleBiz; import com.engine.salary.constant.SalaryAuthConstant; import com.engine.salary.encrypt.datacollection.AddUpDeductionEncrypt; import com.engine.salary.encrypt.datacollection.AddUpSituationEncrypt; import com.engine.salary.encrypt.datacollection.OtherDeductionPOEncrypt; 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.salarysob.po.SalarySobPO; 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.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.salarysob.SalarySobMapper; import com.engine.salary.mapper.taxagent.TaxAgentMapper; import com.engine.salary.service.*; 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.engine.salary.util.valid.RuntimeTypeEnum; import com.engine.salary.util.valid.ValidUtil; 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.springframework.beans.BeanUtils; import org.springframework.transaction.annotation.Transactional; import weaver.hrm.User; import weaver.systeminfo.setting.HrmUserSettingComInfo; import weaver.systeminfo.systemright.CheckUserRight; import java.util.*; import java.util.stream.Collectors; @Slf4j public class TaxAgentServiceImpl extends Service implements TaxAgentService { // private ExtEmployeeService extEmployeeService; SalaryRoleBiz salaryRoleBiz = new SalaryRoleBiz(); private TaxAgentBaseService getTaxAgentBaseService(User user) { return ServiceUtil.getService(TaxAgentBaseServiceImpl.class, user); } private TaxAgentAdminService getTaxAgentAdminService(User user) { return ServiceUtil.getService(TaxAgentAdminServiceImpl.class, user); } private TaxAgentSubAdminService taxAgentSubAdminService; // private TaxAgentSubAdminService getTaxAgentSubAdminService(User user) { // return ServiceUtil.getService(TaxAgentSubAdminServiceImpl.class, user); // } private TaxAgentManageRangeService getTaxAgentManageRangeService(User user) { return ServiceUtil.getService(TaxAgentManageRangeServiceImpl.class, user); } private TaxAgentEmpService getTaxAgentEmpService(User user) { return ServiceUtil.getService(TaxAgentEmpServiceImpl.class, user); } private TaxAgentSubAdminEmpService taxAgentSubAdminEmpService; // private TaxAgentSubAdminEmpService getTaxAgentSubAdminEmpService(User user) { // return ServiceUtil.getService(TaxAgentSubAdminEmpServiceImpl.class, user); // } private HrmCommonService getHrmCommonService(User user) { return ServiceUtil.getService(HrmCommonServiceImpl.class, user); } private SalaryAcctRecordService getSalaryAcctRecordService(User user) { return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user); } private SIAccountService getSIAccountService(User user) { return ServiceUtil.getService(SIAccountServiceImpl.class, user); } private SalaryArchiveMapper getSalaryArchiveMapper() { return MapperProxyFactory.getProxy(SalaryArchiveMapper.class); } private AddUpDeductionMapper getAddUpDeductionMapper() { return MapperProxyFactory.getProxy(AddUpDeductionMapper.class); } private OtherDeductionMapper getOtherDeductionMapper() { return MapperProxyFactory.getProxy(OtherDeductionMapper.class); } private AddUpSituationMapper getAddUpSituationMapper() { return MapperProxyFactory.getProxy(AddUpSituationMapper.class); } private SalarySobMapper getSalarySobMapper() { return MapperProxyFactory.getProxy(SalarySobMapper.class); } private TaxAgentMapper getTaxAgentMapper() { return MapperProxyFactory.getProxy(TaxAgentMapper.class); } private EmployMapper getEmployMapper() { return MapperProxyFactory.getProxy(EmployMapper.class); } // private PaymentAgencyMapper paymentAgencyMapper; // private SIArchivesSocialMapper siArchivesSocialMapper; // private SIArchivesFundMapper siArchivesFundMapper; // private SIArchivesOtherMapper siArchivesOtherMapper; // private AuthorityService authorityService; // private HrmCommonHrmStatusService hrmCommonHrmStatusService; @Override public TaxAgentRoleTypeEnum getRoleType(Long currentEmployeeId) { TaxAgentRoleTypeEnum roleType = TaxAgentRoleTypeEnum.NONE; if (isChief(currentEmployeeId)) { return TaxAgentRoleTypeEnum.CHIEF; } // 是否开启分权 boolean isOpenDevolution = getTaxAgentBaseService(user).isOpenDevolution(); if (!isOpenDevolution) { List taxAgentAdmins = getTaxAgentAdminService(user).listByEmployeeId(currentEmployeeId); if (CollectionUtils.isNotEmpty(taxAgentAdmins)) { return TaxAgentRoleTypeEnum.ADMIN; } List taxAgentSubAdmins = taxAgentSubAdminService.listByAndEmployeeId(currentEmployeeId); if (CollectionUtils.isNotEmpty(taxAgentSubAdmins)) { return TaxAgentRoleTypeEnum.SUBADMIN; } } return roleType; } @Override public Boolean isNeedAuth(Long currentEmployeeId) { return isOpenDevolution() && !isChief(currentEmployeeId); } @Override public Boolean isChief(Long currentEmployeeId) { if (user == null) { return false; } CheckUserRight ck = new CheckUserRight(); boolean hasRight = ck.checkUserRight(SalaryAuthConstant.SALARY_CHIEF, user); if (!hasRight) { String belongtoshow = "";// 是否启用多账号数据显示 try { HrmUserSettingComInfo HrmUserSettingComInfo = new HrmUserSettingComInfo(); belongtoshow = HrmUserSettingComInfo.getBelongtoshowByUserId("" + user.getUID()); } catch (Exception e) { log.error("获取权限异常", e); } if (belongtoshow.equals("1")) { List lsUser = User.getBelongtoUsersByUserId(user.getUID());// 所有此账号 if (lsUser != null) { for (Object tmpUser : lsUser) { hasRight = ck.checkUserRight(SalaryAuthConstant.SALARY_CHIEF, (User) tmpUser); if (hasRight) { break; } } } } } return hasRight; } @Override public Boolean isDefaultOpen(Long currentEmployeeId) { return getTaxAgentBaseService(user).isOpenDevolution(); } @Override public Boolean isAdminEnable(Long currentEmployeeId) { //是管理员 List taxAgentAdminList = getTaxAgentAdminService(user).listByEmployeeId(currentEmployeeId); return CollectionUtils.isNotEmpty(taxAgentAdminList); } @Override public PageInfo listPage(TaxAgentQueryParam queryParam) { SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize()); List taxAgentPOS = getTaxAgentMapper().listBySome(queryParam); return new PageInfo<>(taxAgentPOS); } @Override public List list(TaxAgentQueryParam queryParam) { return getTaxAgentMapper().listBySome(queryParam); } @Override public List listByIds(Collection ids) { return getTaxAgentMapper().listBySome(TaxAgentQueryParam.builder().ids(ids).build()); } @Override public List listAll() { return getTaxAgentMapper().listAll(); } @Override public TaxAgentPO getById(Long id) { return getTaxAgentMapper().getById(id); } @Override public Collection findAll() { List taxAgents = getTaxAgentMapper().listAll(); return TaxAgentBO.convertToListDTO(taxAgents); } @Override public Collection listAllTaxAgents(Long employeeId) { List taxAgents = getTaxAgentMapper().listAll(); return handleForDevolution(taxAgents, employeeId); } @Override public Collection listAllTaxAgentsAsAdmin(Long employeeId) { List taxAgents = getTaxAgentMapper().listAll(); // 是否开启分权 boolean isOpenDevolution = getTaxAgentBaseService(user).isOpenDevolution(); if (!isOpenDevolution) { return taxAgents; } List taxAgentIds = taxAgents.stream().map(TaxAgentPO::getId).collect(Collectors.toList()); List enableTaxAgentIds = Lists.newArrayList(); // 1.判断自己是否是管理员, 如果是管理员,就是能够查看所属个税扣缴义务人 List taxAgentAdminList = getTaxAgentAdminService(user).listByTaxAgentIds(taxAgentIds); // 是管理员的列表 List 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 listAllTaxAgentsAsRange(List employeeIds) { List taxAgents = getTaxAgentMapper().listAll(); List taxAgentIds = taxAgents.stream().map(TaxAgentPO::getId).collect(Collectors.toList()); List taxAgentEmployees = getTaxAgentEmpService(user).listByTaxAgentIds(taxAgentIds); if (CollectionUtils.isEmpty(taxAgentEmployees)) { return Lists.newArrayList(); } // 转换数据结构 List allemployeeIds = taxAgentEmployees.stream().map(TaxAgentEmpPO::getEmployeeId).distinct().collect(Collectors.toList()); return allemployeeIds.stream().map(m -> { List 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) { ValidUtil.doValidator(saveParam); // 是否开启分权 boolean isOpenDevolution = getTaxAgentBaseService(user).isOpenDevolution(); if (isOpenDevolution && CollectionUtils.isEmpty(saveParam.getAdminUserIds())) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(106271, "请选择管理员")); } List taxAgents = getTaxAgentMapper().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, (long) user.getUID()); getTaxAgentMapper().insertIgnoreNull(taxAgent); if (isOpenDevolution) { getTaxAgentAdminService(user).batchInsert(taxAgent.getId(), saveParam.getAdminUserIds()); } // 记录日志 // 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) { getTaxAgentMapper().update(taxAgentPO); return ""; } @Override public String update(TaxAgentSaveParam saveParam) { ValidUtil.doValidator(saveParam, RuntimeTypeEnum.UPDATE); TaxAgentPO taxAgent = getById(saveParam.getId()); if (taxAgent == null) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100545, "个税扣缴义务人不存在或不在权限范围内")); } // 是否开启分权 boolean isOpenDevolution = getTaxAgentBaseService(user).isOpenDevolution(); if (isOpenDevolution && CollectionUtils.isEmpty(saveParam.getAdminUserIds())) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(106271, "请选择管理员")); } List individualTaxWithholdingAgents = getTaxAgentMapper().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()); getTaxAgentMapper().update(taxAgentNew); if (isOpenDevolution) { // Boolean isUnEnableChange = adminChangeCheck(TaxAgentAdminChangeCheckParam.builder() // .taxAgentId(saveParam.getId()) // .adminUserId(saveParam.getAdminUserIds()) // .build()); // if (isUnEnableChange) { // throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(115937, "该管理员有未归档核算数据,不可更换管理员")); // } // 删除管理员 getTaxAgentAdminService(user).deleteByTaxAgentIds(Collections.singletonList(taxAgent.getId())); // 新增管理员 getTaxAgentAdminService(user).batchInsert(saveParam.getId(), saveParam.getAdminUserIds()); } // 记录日志 // SalaryLoggerUtil.recordUpdateSingleLog(taxAgentLoggerTemplate, // taxAgent.getId(), // taxAgentNew.getName(), // SalaryI18nUtil.getI18nLabel(93767, "编辑个税扣缴义务人"), // SalaryI18nUtil.getI18nLabel(93767, "编辑个税扣缴义务人"), // taxAgent, // taxAgentNew); return StringUtils.EMPTY; } @Override public Boolean adminChangeCheck(TaxAgentAdminChangeCheckParam checkParam) { ValidUtil.doValidator(checkParam); List taxAgentAdminList = getTaxAgentAdminService(user).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;// getSIAccountService(user).changeAdminUnfiledCheck(adminUserId); // 2.薪资核算是否有核算未归档 List salaryAcctRecords = getSalaryAcctRecordService(user).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 ids) { if (org.springframework.util.CollectionUtils.isEmpty(ids)) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误")); } List taxAgents = getTaxAgentMapper().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, "正在使用的记录不允许删除")); } // 删除管理员 getTaxAgentAdminService(user).deleteByTaxAgentIds(ids); // 删除分管理员和对应管理范围 // todo taxAgentSubAdminService.deleteByTaxAgentIds(ids); // 删除人员范围 getTaxAgentManageRangeService(user).deleteByTaxAgentIds(ids); getTaxAgentMapper().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 ids) { //fixme 被薪资档案引用 // List salaryArchiveList = new LambdaQueryChainWrapper<>(getSalaryArchiveMapper()) // .eq(SalaryArchivePO::getDeleteType, 0) // .eq(SalaryArchivePO::getTenantKey) // .in(SalaryArchivePO::getTaxAgentId, ids) // .list(); // getSalaryArchiveMapper().listSome(SalaryArchivePO.builder().t); // if (CollectionUtils.isNotEmpty(salaryArchiveList)) { // return Boolean.TRUE; // } // todo 被社保福利档案引用 // List 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 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 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 extEmployeeList = extEmployeeService.listAll(tenantKey); // List 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 addUpDeductionList = getAddUpDeductionMapper().listSome(AddUpDeduction.builder().taxAgentIds(ids).build()); AddUpDeductionEncrypt.decryptAddUpDeductionList(addUpDeductionList); if (CollectionUtils.isNotEmpty(addUpDeductionList)) { return Boolean.TRUE; } // 被其他免税扣除引用 List otherDeductionList = getOtherDeductionMapper().listSome(OtherDeductionPO.builder().taxAgentIds(ids).build()); OtherDeductionPOEncrypt.decryptOtherDeductionPOList(otherDeductionList); if (CollectionUtils.isNotEmpty(otherDeductionList)) { return Boolean.TRUE; } // 被往期累计情况引用 List addUpSituationList = getAddUpSituationMapper().listSome(AddUpSituation.builder().taxAgentIds(ids).build()); AddUpSituationEncrypt.decryptAddUpSituationList(addUpSituationList); if (CollectionUtils.isNotEmpty(addUpSituationList)) { return Boolean.TRUE; } //账套 List salarySobPOS = getSalarySobMapper().listSome(SalarySobPO.builder().taxAgentIds(ids).build()); if (CollectionUtils.isNotEmpty(salarySobPOS)) { return Boolean.TRUE; } return Boolean.FALSE; } @Override public List> selectList() { List taxAgents = getTaxAgentMapper().listAll(); taxAgents = handleForDevolution(taxAgents, (long) user.getUID()); return taxAgents.stream().map(m -> { Map 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 handleForDevolution(List taxAgents, Long currentEmployeeId) { // 是否开启分权 boolean isOpenDevolution = getTaxAgentBaseService(user).isOpenDevolution(); if (!isOpenDevolution || isChief(currentEmployeeId)) { return taxAgents; } List taxAgentIds = taxAgents.stream().map(TaxAgentPO::getId).collect(Collectors.toList()); List enableTaxAgentIds = Lists.newArrayList(); // 1.判断自己是否是管理员, 如果是管理员,就是能够查看所属个税扣缴义务人 List taxAgentAdminList = getTaxAgentAdminService(user).listByTaxAgentIdsAndEmployeeId(taxAgentIds, currentEmployeeId); // 是管理员的列表 List adminTaxAgentIds = taxAgentAdminList.stream().map(TaxAgentAdminPO::getTaxAgentId).collect(Collectors.toList()); enableTaxAgentIds.addAll(adminTaxAgentIds); // 2.根据作为非管理员查找自己作为分管理员的个税扣缴义务人id // List noAdminTaxAgentIds = taxAgents.stream() // .map(TaxAgentPO::getId) // .filter(id -> !adminTaxAgentIds.contains(id)).collect(Collectors.toList()); // if (CollectionUtils.isNotEmpty(noAdminTaxAgentIds)) { // List taxAgentSubAdmins = taxAgentSubAdminService.listByTaxAgentIdsAndEmployeeId(noAdminTaxAgentIds, currentEmployeeId); // List 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 getTaxAgentBaseService(user).isOpenDevolution(); } @Override public List listTaxAgentAndEmployeeTree(Long employeeId) { return listTaxAgentAndEmployeeTree(null, employeeId); } @Override public List listTaxAgentAndEmployee(Long employeeId) { return listTaxAgentAndEmployee(null, employeeId); } @Override public List listTaxAgentAndEmployeeTree(SalaryEmployeeStatusEnum employeeStatus, Long employeeId) { List taxAgentManageRangeEmployeeList = Lists.newArrayList(); // 所有个税扣缴义务人 List allTaxAgents = listAll(); if (CollectionUtils.isEmpty(allTaxAgents)) { return taxAgentManageRangeEmployeeList; } List taxAgentIds = allTaxAgents.stream().map(TaxAgentPO::getId).collect(Collectors.toList()); List allEmployees = getTaxAgentMapper().listEmployee(); if (employeeStatus != null) { List 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 taxAgentAdminList = getTaxAgentAdminService(user).listByTaxAgentIdsAndEmployeeId(taxAgentIds, (long) user.getUID()); // 是管理员的列表 List adminTaxAgentIds = taxAgentAdminList.stream().map(TaxAgentAdminPO::getTaxAgentId).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(adminTaxAgentIds)) { taxAgentManageRangeEmployeeList.addAll(getTaxAgentEmp(allTaxAgents, adminTaxAgentIds, allEmployees)); } // 2.根据作为非管理员查找自己作为分管理员, 对应的管理范围人员 List 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 getTaxAgentSubAdminEmp(List allTaxAgents, List noAdminTaxAgentIds, List allEmployees) { List taxAgentManageRangeEmployeeList = Lists.newArrayList(); List taxAgentEmps = taxAgentSubAdminEmpService.listByTaxAgentIds(noAdminTaxAgentIds); taxAgentEmps = taxAgentEmps.stream().filter(f -> allEmployees.stream().anyMatch(e -> e.getEmployeeId().equals(f.getEmployeeId()))).collect(Collectors.toList()); List finalTaxAgentEmps = taxAgentEmps; noAdminTaxAgentIds.forEach(e -> { Optional optionalTaxAgent = allTaxAgents.stream().filter(t -> t.getId().equals(e)).findFirst(); String taxAgentName = (optionalTaxAgent.isPresent() ? optionalTaxAgent.get().getName() : ""); List 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 getTaxAgentEmp(List allTaxAgents, List taxAgentIds, List allEmployees) { List taxAgentManageRangeEmployeeList = Lists.newArrayList(); List taxAgentEmps = getTaxAgentEmpService(user).listByTaxAgentIds(taxAgentIds); taxAgentEmps = taxAgentEmps.stream().filter(f -> allEmployees.stream().anyMatch(e -> e.getEmployeeId().equals(f.getEmployeeId()))).collect(Collectors.toList()); List finalTaxAgentEmps = taxAgentEmps; taxAgentIds.forEach(e -> { Optional optionalTaxAgent = allTaxAgents.stream().filter(t -> t.getId().equals(e)).findFirst(); String taxAgentName = (optionalTaxAgent.isPresent() ? optionalTaxAgent.get().getName() : ""); List 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 listTaxAgentAndEmployee(SalaryEmployeeStatusEnum employeeStatus, Long employeeId) { List taxAgentEmployeeList = Lists.newArrayList(); List taxAgentManageRangeEmployeeList = listTaxAgentAndEmployeeTree(employeeStatus, employeeId); taxAgentManageRangeEmployeeList.forEach(m -> { List 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; } @Override public Collection listEmployeeIdsInTaxAgent(Long taxAgentId) { List taxAgentEmpPOS = getTaxAgentEmpService(user).listByTaxAgentIds(Collections.singletonList(taxAgentId)); return SalaryEntityUtil.properties(taxAgentEmpPOS,TaxAgentEmpPO::getEmployeeId); } }