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

692 lines
32 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.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.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.taxagent.TaxAgentMapper;
import com.engine.salary.service.*;
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 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 weaver.hrm.User;
import java.util.*;
import java.util.stream.Collectors;
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 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<TaxAgentAdminPO> taxAgentAdmins = getTaxAgentAdminService(user).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) {
String allAdminRoleId = salaryRoleBiz.getAllAdminRoleId();
List<Object> roleInfo = getHrmCommonService(user).getRoleInfo(user.getUID());
Map map = roleInfo.stream().map(m -> (Map) m).filter(m -> m.get("roleid") != null && m.get("roleid").toString().equals(allAdminRoleId)).findFirst().orElse(null);
return map != null;
//return authorityService.checkPermissionSet(TaxAgentPermissionConstant.MENU_CODE, TaxAgentPermissionConstant.ITEM_CODE_DEVOLUTION, currentEmployeeId);
}
@Override
public Boolean isDefaultOpen(Long currentEmployeeId) {
return true;
// 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 = getTaxAgentAdminService(user).listByEmployeeId(currentEmployeeId);
return CollectionUtils.isNotEmpty(taxAgentAdminList);
}
}
return Boolean.TRUE;
}
@Override
public PageInfo<TaxAgentPO> listPage(TaxAgentQueryParam queryParam) {
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<TaxAgentPO> taxAgentPOS = getTaxAgentMapper().listBySome(queryParam);
return new PageInfo<>(taxAgentPOS);
}
@Override
public List<TaxAgentPO> list(TaxAgentQueryParam queryParam) {
return getTaxAgentMapper().listBySome(queryParam);
}
@Override
public List<TaxAgentPO> listByIds(Collection<Long> ids) {
return getTaxAgentMapper().listBySome(TaxAgentQueryParam.builder().ids(ids).build());
}
@Override
public List<TaxAgentPO> listAll() {
return getTaxAgentMapper().listAll();
}
@Override
public TaxAgentPO getById(Long id) {
return getTaxAgentMapper().getById(id);
}
@Override
public Collection<TaxAgentListDTO> findAll() {
List<TaxAgentPO> taxAgents = getTaxAgentMapper().listAll();
return TaxAgentBO.convertToListDTO(taxAgents);
}
@Override
public Collection<TaxAgentPO> listAllTaxAgents(Long employeeId) {
List<TaxAgentPO> taxAgents = getTaxAgentMapper().listAll();
return handleForDevolution(taxAgents, employeeId);
}
@Override
public Collection<TaxAgentPO> listAllTaxAgentsAsAdmin(Long employeeId) {
List<TaxAgentPO> taxAgents = getTaxAgentMapper().listAll();
// 是否开启分权
boolean isOpenDevolution = getTaxAgentBaseService(user).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 = getTaxAgentAdminService(user).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 = getTaxAgentMapper().listAll();
List<Long> taxAgentIds = taxAgents.stream().map(TaxAgentPO::getId).collect(Collectors.toList());
List<TaxAgentEmpPO> taxAgentEmployees = getTaxAgentEmpService(user).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) {
ValidUtil.doValidator(saveParam);
// 是否开启分权
boolean isOpenDevolution = getTaxAgentBaseService(user).isOpenDevolution();
if (isOpenDevolution && CollectionUtils.isEmpty(saveParam.getAdminUserIds())) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(106271, "请选择管理员"));
}
List<TaxAgentPO> 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().insert(taxAgent);
if (isOpenDevolution) {
getTaxAgentAdminService(user).batchInsert(saveParam.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<TaxAgentPO> 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<TaxAgentAdminPO> 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<SalaryAcctRecordPO> 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<Long> ids) {
if (org.springframework.util.CollectionUtils.isEmpty(ids)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误"));
}
List<TaxAgentPO> 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<Long> ids) {
//fixme 被薪资档案引用
// List<SalaryArchivePO> 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<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 = getAddUpDeductionMapper().listSome(AddUpDeduction.builder().taxAgentIds(ids).build());
if (CollectionUtils.isNotEmpty(addUpDeductionList)) {
return Boolean.TRUE;
}
// 被其他免税扣除引用
List<OtherDeductionPO> otherDeductionList = getOtherDeductionMapper().listSome(OtherDeductionPO.builder().taxAgentIds(ids).build());
if (CollectionUtils.isNotEmpty(otherDeductionList)) {
return Boolean.TRUE;
}
// 被往期累计情况引用
List<AddUpSituation> addUpSituationList = getAddUpSituationMapper().listSome(AddUpSituation.builder().taxAgentIds(ids).build());
if (CollectionUtils.isNotEmpty(addUpSituationList)) {
return Boolean.TRUE;
}
return Boolean.FALSE;
}
@Override
public List<Map<String, Object>> selectList() {
List<TaxAgentPO> taxAgents = getTaxAgentMapper().listAll();
taxAgents = handleForDevolution(taxAgents, (long) user.getUID());
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 = getTaxAgentBaseService(user).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 = getTaxAgentAdminService(user).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 getTaxAgentBaseService(user).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 = getTaxAgentMapper().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 = getTaxAgentAdminService(user).listByTaxAgentIdsAndEmployeeId(taxAgentIds, (long) user.getUID());
// 是管理员的列表
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 = getTaxAgentEmpService(user).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;
}
}