weaver-hrm-salary/src/com/engine/salary/service/impl/TaxDeclarationDetailService...

263 lines
15 KiB
Java
Raw Normal View History

2022-04-16 15:33:51 +08:00
package com.engine.salary.service.impl;
2022-04-18 18:56:17 +08:00
import com.engine.common.util.ServiceUtil;
2022-04-16 15:33:51 +08:00
import com.engine.core.impl.Service;
2022-05-24 09:23:17 +08:00
import com.engine.salary.encrypt.taxdeclaration.TaxDeclarationDetailPOEncrypt;
2022-04-18 18:56:17 +08:00
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
2022-06-10 13:33:48 +08:00
import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeDTO;
2022-04-18 18:56:17 +08:00
import com.engine.salary.entity.taxdeclaration.bo.TaxDeclarationBO;
2022-06-10 13:33:48 +08:00
import com.engine.salary.entity.taxdeclaration.bo.TaxDeclarationDetailBO;
2022-04-18 18:56:17 +08:00
import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationDetailListDTO;
2022-06-10 13:33:48 +08:00
import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationEmployeeDTO;
2022-04-16 15:33:51 +08:00
import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationLaborListDTO;
import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationWageListDTO;
import com.engine.salary.entity.taxdeclaration.param.TaxDeclarationDetailListQueryParam;
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationDetailPO;
2022-06-10 13:33:48 +08:00
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationPO;
import com.engine.salary.enums.salaryaccounting.EmployeeTypeEnum;
2022-08-02 10:59:12 +08:00
import com.engine.salary.exception.SalaryRunTimeException;
2022-04-16 15:33:51 +08:00
import com.engine.salary.mapper.taxdeclaration.TaxDeclarationDetailMapper;
2022-04-18 18:56:17 +08:00
import com.engine.salary.service.SalaryEmployeeService;
2022-06-10 13:33:48 +08:00
import com.engine.salary.service.TaxAgentService;
2022-04-16 15:33:51 +08:00
import com.engine.salary.service.TaxDeclarationDetailService;
2022-06-10 13:33:48 +08:00
import com.engine.salary.service.TaxDeclarationService;
import com.engine.salary.util.SalaryEntityUtil;
2022-04-18 18:56:17 +08:00
import com.engine.salary.util.db.MapperProxyFactory;
2022-04-16 15:33:51 +08:00
import com.engine.salary.util.page.PageInfo;
2022-06-10 13:33:48 +08:00
import com.engine.salary.util.page.SalaryPageUtil;
2022-05-26 13:41:58 +08:00
import com.google.common.collect.Lists;
2022-06-10 13:33:48 +08:00
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import weaver.hrm.User;
2022-04-16 15:33:51 +08:00
2022-06-10 13:33:48 +08:00
import java.util.*;
import java.util.stream.Collectors;
2022-04-16 15:33:51 +08:00
/**
2022-06-15 16:31:40 +08:00
* 个税申报表明细
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
2022-04-16 15:33:51 +08:00
public class TaxDeclarationDetailServiceImpl extends Service implements TaxDeclarationDetailService {
2022-05-09 11:46:49 +08:00
private TaxDeclarationDetailMapper getTaxDeclarationDetailMapper() {
2022-04-18 18:56:17 +08:00
return MapperProxyFactory.getProxy(TaxDeclarationDetailMapper.class);
}
2022-05-26 13:41:58 +08:00
2022-04-18 18:56:17 +08:00
private SalaryEmployeeService getSalaryEmployeeService() {
2022-06-10 13:33:48 +08:00
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
}
private TaxDeclarationService getTaxDeclarationService(User user) {
return ServiceUtil.getService(TaxDeclarationServiceImpl.class, user);
}
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
private SalaryEmployeeService getSalaryEmployeeService(User user) {
2022-04-18 18:56:17 +08:00
return (SalaryEmployeeService) ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
}
2022-04-16 15:33:51 +08:00
2022-06-10 13:33:48 +08:00
@Override
public List<TaxDeclarationDetailPO> listByTaxDeclarationIdAndEmployeeIds(Long taxDeclarationId, Collection<Long> employeeIds) {
2022-04-16 15:33:51 +08:00
if (CollectionUtils.isEmpty(employeeIds)) {
return Collections.emptyList();
}
2022-06-10 13:33:48 +08:00
return getTaxDeclarationDetailMapper().listByTaxDeclarationIdAndEmployeeIds(taxDeclarationId, employeeIds);
2022-04-16 15:33:51 +08:00
}
@Override
2022-06-10 13:33:48 +08:00
public PageInfo<TaxDeclarationEmployeeDTO> listPage4EmployeeIdByParam(TaxDeclarationDetailListQueryParam queryParam) {
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<TaxDeclarationEmployeeDTO> taxDeclarationEmployeeDTOS = getTaxDeclarationDetailMapper().listPage4EmployeeId(queryParam.getTaxDeclarationId());
return new PageInfo<>(taxDeclarationEmployeeDTOS, TaxDeclarationEmployeeDTO.class);
2022-04-16 15:33:51 +08:00
}
2022-06-10 13:33:48 +08:00
2022-04-16 15:33:51 +08:00
@Override
2022-04-18 18:56:17 +08:00
public PageInfo<TaxDeclarationDetailListDTO> listDtoPageByParam(TaxDeclarationDetailListQueryParam queryParam) {
2022-04-16 15:33:51 +08:00
// 查询个税申报表明细的人员
2022-05-09 11:46:49 +08:00
List<Long> employeeIdPage = getTaxDeclarationDetailMapper().listEmployeeId(queryParam.getTaxDeclarationId());
2022-04-18 18:56:17 +08:00
PageInfo<TaxDeclarationDetailListDTO> dtoPage = new PageInfo<TaxDeclarationDetailListDTO>(TaxDeclarationDetailListDTO.class);
dtoPage.setPageNum(queryParam.getCurrent());
dtoPage.setPageSize(queryParam.getPageSize());
2022-05-26 13:41:58 +08:00
if (null == employeeIdPage) {
2022-04-19 20:58:30 +08:00
return dtoPage;
}
if (CollectionUtils.isNotEmpty(employeeIdPage)) {
2022-04-16 15:33:51 +08:00
// 查询个税申报表明细
2022-04-19 20:58:30 +08:00
List<TaxDeclarationDetailPO> taxDeclarationDetailPOS = listByTaxDeclarationIdAndEmployeeIds(queryParam.getTaxDeclarationId(), employeeIdPage);
2022-04-18 18:56:17 +08:00
// 查询人员
2022-04-19 20:58:30 +08:00
List<DataCollectionEmployee> simpleEmployees = getSalaryEmployeeService().listByIds(employeeIdPage);
2022-05-26 13:41:58 +08:00
// List<SimpleEmployee> simpleEmployees = hrmCommonEmployeeService.getEmployeeByIds(employeeIdPage.getRecords(), tenantKey);
2022-04-16 15:33:51 +08:00
// 转换成列表dto
TaxDeclarationBO.buildDetailListDTO(queryParam.getTaxDeclarationId(), dtoPage, taxDeclarationDetailPOS, simpleEmployees);
}
return dtoPage;
2022-04-18 18:56:17 +08:00
}
2022-04-16 15:33:51 +08:00
@Override
public PageInfo<TaxDeclarationLaborListDTO> listDtoPageByParam4Labor(TaxDeclarationDetailListQueryParam queryParam) {
2022-06-10 13:33:48 +08:00
2022-08-02 10:59:12 +08:00
// 查询个税申报主表
TaxDeclarationPO taxDeclarationPO = getTaxDeclarationService(user).getById(queryParam.getTaxDeclarationId());
// 判断是否有权限查看
boolean canSee = getTaxDeclarationService(user).checkByAuthority(taxDeclarationPO, (long) user.getUID());
if (!canSee) {
throw new SalaryRunTimeException("对不起,您暂时没有权限查看");
}
// 查询个税申报表明细的人员
PageInfo<TaxDeclarationEmployeeDTO> employeeIdPage = listPage4EmployeeIdByParam(queryParam);
PageInfo<TaxDeclarationLaborListDTO> dtoPage = new PageInfo<>(TaxDeclarationLaborListDTO.class);
dtoPage.setPageSize(employeeIdPage.getPageSize());
dtoPage.setPageNum(employeeIdPage.getPageNum());
dtoPage.setTotal(employeeIdPage.getTotal());
List list = employeeIdPage.getList();
if (CollectionUtils.isNotEmpty(list)) {
// 转换成列表dto
List<TaxDeclarationLaborListDTO> taxDeclarationLaborListDTOS = listDto4Labor(queryParam.getTaxDeclarationId(), list);
dtoPage.setList(taxDeclarationLaborListDTOS);
}
return dtoPage;
}
@Override
public List<TaxDeclarationLaborListDTO> listDto4Labor(Long taxDeclarationId, List<TaxDeclarationEmployeeDTO> taxDeclarationEmployees) {
long employeeId = (long) user.getUID();
// 查询个税申报主表
TaxDeclarationPO taxDeclarationPO = getTaxDeclarationService(user).getById(taxDeclarationId);
// 判断是否有权限查看
boolean canSee = getTaxDeclarationService(user).checkByAuthority(taxDeclarationPO, employeeId);
if (!canSee) {
throw new SalaryRunTimeException("对不起,您暂时没有权限查看");
}
// 查询个税申报表明细
List<Long> employeeIds = taxDeclarationEmployees.stream().map(TaxDeclarationEmployeeDTO::getEmployeeId).collect(Collectors.toList());
List<TaxDeclarationDetailPO> taxDeclarationDetailPOS = listByTaxDeclarationIdAndEmployeeIds(taxDeclarationId, employeeIds);
// 查询人员信息
List<DataCollectionEmployee> simpleEmployees = getSalaryEmployeeService().listByIds(employeeIds);
// 转换成列表dto
return TaxDeclarationDetailBO.convert2ListDTO4Labor(taxDeclarationDetailPOS, taxDeclarationEmployees, simpleEmployees);
2022-04-16 15:33:51 +08:00
}
2022-06-10 13:33:48 +08:00
/**
* 根据权限范围过滤
*
* @param taxDeclarationPO
* @param taxDeclarationEmployeeDTOS
* @return
*/
private List<TaxDeclarationEmployeeDTO> filterByAuthority(TaxDeclarationPO taxDeclarationPO, List<TaxDeclarationEmployeeDTO> taxDeclarationEmployeeDTOS) {
long employeeId = user.getUID();
if (CollectionUtils.isEmpty(taxDeclarationEmployeeDTOS)) {
return Collections.emptyList();
}
// 判断是否开启了分权
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
// 是否是总管理员
Boolean isChief = getTaxAgentService(user).isChief(employeeId);
if (BooleanUtils.isFalse(openDevolution) || isChief) {
return taxDeclarationEmployeeDTOS;
}
// 查询权限范围内的人员
List<TaxAgentEmployeeDTO> taxAgentEmployeeDTOS = getTaxAgentService(user).listTaxAgentAndEmployee(employeeId);
Set<String> simpleEmployeeKeySet = SalaryEntityUtil.properties(taxAgentEmployeeDTOS, taxAgentEmployeeDTO -> taxAgentEmployeeDTO.getEmployeeId() + "-" + taxAgentEmployeeDTO.getTaxAgentId());
// 查询权限范围内的外部人员
// List<ExtEmployeePO> extEmployeePOS = extEmployeeService.listCanUseByEmployeeId(employeeId, tenantKey);
// Set<String> extEmployeeKeySet = SalaryEntityUtil.properties(extEmployeePOS, extEmployeePO -> extEmployeePO.getId() + "-" + extEmployeePO.getTaxAgentId());
// 根据权限范围过滤
return taxDeclarationEmployeeDTOS.stream().filter(taxDeclarationEmployeeDTO -> {
if (taxDeclarationEmployeeDTO.getEmployeeType() == null || Objects.equals(taxDeclarationEmployeeDTO.getEmployeeType(), EmployeeTypeEnum.ORGANIZATION.getValue())
&& simpleEmployeeKeySet.contains(taxDeclarationEmployeeDTO.getEmployeeId() + "-" + taxDeclarationPO.getTaxAgentId())) {
return true;
}
// if (Objects.equals(taxDeclarationEmployeeDTO.getEmployeeType(), EmployeeTypeEnum.EXT_EMPLOYEE.getValue())
// && extEmployeeKeySet.contains(taxDeclarationEmployeeDTO.getEmployeeId() + "-" + taxDeclarationPO.getTaxAgentId())) {
// return true;
// }
return false;
}).collect(Collectors.toList());
}
2022-04-16 15:33:51 +08:00
@Override
public PageInfo<TaxDeclarationWageListDTO> listDtoPageByParam4Wage(TaxDeclarationDetailListQueryParam queryParam) {
2022-06-10 13:33:48 +08:00
// 查询个税申报主表
TaxDeclarationPO taxDeclarationPO = getTaxDeclarationService(user).getById(queryParam.getTaxDeclarationId());
// 查询个税申报表明细的人员
PageInfo<TaxDeclarationEmployeeDTO> employeeIdPage = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize());
// 判断是否开启了分权
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
// 是否是总管理员
Boolean isChief = getTaxAgentService(user).isChief((long) user.getUID());
// if (BooleanUtils.isTrue(openDevolution) && !isChief) {
// List<TaxDeclarationEmployeeDTO> taxDeclarationEmployeeDTOS = getTaxDeclarationDetailMapper().list4EmployeeId(queryParam.getTaxDeclarationId());
// // 根据权限过滤
// taxDeclarationEmployeeDTOS = filterByAuthority(taxDeclarationPO, taxDeclarationEmployeeDTOS);
// employeeIdPage.setTotal(taxDeclarationEmployeeDTOS.size());
// employeeIdPage.setList(SalaryPageUtil.subList((int) employeeIdPage.getPageNum(), (int) employeeIdPage.getPageSize(), taxDeclarationEmployeeDTOS));
// } else {
employeeIdPage = listPage4EmployeeIdByParam(queryParam);
// }
2022-08-02 10:59:12 +08:00
PageInfo<TaxDeclarationWageListDTO> dtoPage = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), TaxDeclarationWageListDTO.class);
2022-06-10 13:33:48 +08:00
dtoPage.setTotal(employeeIdPage.getTotal());
if (CollectionUtils.isNotEmpty(employeeIdPage.getList())) {
List<TaxDeclarationEmployeeDTO> list = employeeIdPage.getList();
// 查询个税申报表明细
Set<Long> employeeIds = SalaryEntityUtil.properties(list, TaxDeclarationEmployeeDTO::getEmployeeId);
List<TaxDeclarationDetailPO> taxDeclarationDetailPOS = listByTaxDeclarationIdAndEmployeeIds(queryParam.getTaxDeclarationId(),
employeeIds);
2022-06-10 18:07:25 +08:00
TaxDeclarationDetailPOEncrypt.decryptTaxDeclarationDetailPOList(taxDeclarationDetailPOS);
2022-06-10 13:33:48 +08:00
// 查询人员信息
List<Long> simpleEmployeeIds = list.stream()
.filter(taxDeclarationEmployeeDTO -> Objects.equals(taxDeclarationEmployeeDTO.getEmployeeType(), EmployeeTypeEnum.ORGANIZATION.getValue()))
.map(TaxDeclarationEmployeeDTO::getEmployeeId)
.collect(Collectors.toList());
List<DataCollectionEmployee> simpleEmployees = getSalaryEmployeeService(user).getEmployeeByIds(simpleEmployeeIds);
// 查询人员薪资(身份证号码等)
// List<SimpleUserInfo> simpleUserInfos = salaryEmployeeService.listByEmployeeIds(simpleEmployeeIds, tenantKey);
// 查询外部人员
// Set<Long> extEmployeeIds = employeeIdPage.getRecords().stream()
// .filter(taxDeclarationEmployeeDTO -> Objects.equals(taxDeclarationEmployeeDTO.getEmployeeType(), EmployeeTypeEnum.EXT_EMPLOYEE.getValue()))
// .map(TaxDeclarationEmployeeDTO::getEmployeeId)
// .collect(Collectors.toSet());
// List<ExtEmployeePO> extEmployees = extEmployeeService.listByIds(extEmployeeIds, tenantKey);
// 转换成列表dto
List<TaxDeclarationWageListDTO> taxDeclarationWageListDTOS = TaxDeclarationDetailBO.convert2ListDTO4Wage(taxDeclarationDetailPOS,
employeeIdPage.getList(), simpleEmployees);
dtoPage.setList(taxDeclarationWageListDTOS);
}
return dtoPage;
2022-04-16 15:33:51 +08:00
}
@Override
public void batchSave(Collection<TaxDeclarationDetailPO> taxDeclarationDetailPOS) {
2022-05-26 13:41:58 +08:00
if (CollectionUtils.isNotEmpty(taxDeclarationDetailPOS)) {
2022-06-06 21:21:10 +08:00
TaxDeclarationDetailPOEncrypt.encryptTaxDeclarationDetailPOList(taxDeclarationDetailPOS);
2022-05-26 13:41:58 +08:00
List<List<TaxDeclarationDetailPO>> partition = Lists.partition((List) taxDeclarationDetailPOS, 100);
partition.forEach(getTaxDeclarationDetailMapper()::batchInsert);
}
2022-04-18 18:56:17 +08:00
}
2022-05-26 13:41:58 +08:00
2022-04-19 20:58:30 +08:00
public List<TaxDeclarationDetailPO> listByTaxDeclarationIdAndEmployeeIds(Long taxDeclarationId, List<Long> employeeIds) {
2022-04-18 18:56:17 +08:00
if (CollectionUtils.isEmpty(employeeIds)) {
return Collections.emptyList();
}
2022-05-24 09:23:17 +08:00
List<TaxDeclarationDetailPO> taxDeclarationDetailPOS = getTaxDeclarationDetailMapper().listByTaxDeclarationIdAndEmployeeIds(taxDeclarationId, employeeIds);
return TaxDeclarationDetailPOEncrypt.decryptTaxDeclarationDetailPOList(taxDeclarationDetailPOS);
2022-05-09 11:46:49 +08:00
}
@Override
public void deleteByTaxDeclarationIds(Collection<Long> taxDeclarationIds) {
getTaxDeclarationDetailMapper().deleteByTaxDeclarationIds(taxDeclarationIds);
2022-04-16 15:33:51 +08:00
}
}