2022-04-07 16:54:10 +08:00
|
|
|
package com.engine.salary.service.impl;
|
|
|
|
|
|
2024-01-30 10:26:44 +08:00
|
|
|
import cn.hutool.core.collection.CollUtil;
|
2023-04-10 12:43:48 +08:00
|
|
|
import cn.hutool.core.date.DateUtil;
|
2022-09-15 15:31:34 +08:00
|
|
|
import com.api.formmode.mybatis.util.SqlProxyHandle;
|
2022-04-07 16:54:10 +08:00
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
import com.engine.core.impl.Service;
|
2024-01-24 09:50:58 +08:00
|
|
|
import com.engine.salary.config.SalaryElogConfig;
|
2022-04-07 16:54:10 +08:00
|
|
|
import com.engine.salary.constant.SalaryDefaultTenantConstant;
|
2024-03-12 14:34:44 +08:00
|
|
|
import com.engine.hrmelog.entity.dto.LoggerContext;
|
2022-04-07 16:54:10 +08:00
|
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
|
|
|
|
import com.engine.salary.entity.salaryacct.bo.SalaryAcctEmployeeBO;
|
|
|
|
|
import com.engine.salary.entity.salaryacct.dto.SalaryAcctEmployeeCountDTO;
|
|
|
|
|
import com.engine.salary.entity.salaryacct.param.*;
|
|
|
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
|
|
|
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
|
|
|
|
|
import com.engine.salary.entity.salaryarchive.dto.SalaryArchiveDataDTO;
|
|
|
|
|
import com.engine.salary.entity.salarysob.dto.SalarySobCycleDTO;
|
|
|
|
|
import com.engine.salary.entity.salarysob.po.SalarySobPO;
|
2024-01-24 09:50:58 +08:00
|
|
|
import com.engine.salary.enums.OperateTypeEnum;
|
2022-04-07 16:54:10 +08:00
|
|
|
import com.engine.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum;
|
|
|
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
|
|
|
|
import com.engine.salary.mapper.salaryacct.SalaryAcctEmployeeMapper;
|
2022-09-15 15:31:34 +08:00
|
|
|
import com.engine.salary.mapper.sys.SalarySysConfMapper;
|
2023-04-10 09:47:33 +08:00
|
|
|
import com.engine.salary.report.entity.param.SalaryStatisticsReportDataQueryParam;
|
2022-04-07 16:54:10 +08:00
|
|
|
import com.engine.salary.service.*;
|
2022-09-26 18:51:17 +08:00
|
|
|
import com.engine.salary.sys.entity.vo.OrderRuleVO;
|
|
|
|
|
import com.engine.salary.sys.service.SalarySysConfService;
|
|
|
|
|
import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl;
|
2022-04-07 16:54:10 +08:00
|
|
|
import com.engine.salary.util.SalaryDateUtil;
|
|
|
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
|
|
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
2022-04-11 20:46:25 +08:00
|
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
2022-04-07 16:54:10 +08:00
|
|
|
import com.engine.salary.util.page.PageInfo;
|
2022-05-25 13:10:03 +08:00
|
|
|
import com.engine.salary.util.page.SalaryPageUtil;
|
2022-04-07 16:54:10 +08:00
|
|
|
import com.engine.salary.util.valid.ValidUtil;
|
2022-05-26 13:41:58 +08:00
|
|
|
import com.google.common.collect.Lists;
|
2023-04-10 12:43:48 +08:00
|
|
|
import com.google.common.collect.Sets;
|
2023-04-26 15:17:08 +08:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2022-04-07 16:54:10 +08:00
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import weaver.hrm.User;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 薪资核算人员
|
|
|
|
|
* <p>Copyright: Copyright (c) 2022</p>
|
|
|
|
|
* <p>Company: 泛微软件</p>
|
|
|
|
|
*
|
|
|
|
|
* @author qiantao
|
|
|
|
|
* @version 1.0
|
|
|
|
|
**/
|
2023-04-26 15:17:08 +08:00
|
|
|
@Slf4j
|
2022-04-07 16:54:10 +08:00
|
|
|
public class SalaryAcctEmployeeServiceImpl extends Service implements SalaryAcctEmployeeService {
|
|
|
|
|
|
|
|
|
|
private SalaryAcctEmployeeMapper getSalaryAcctEmployeeMapper() {
|
2022-04-11 20:46:25 +08:00
|
|
|
return MapperProxyFactory.getProxy(SalaryAcctEmployeeMapper.class);
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
|
2022-06-29 17:38:00 +08:00
|
|
|
return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
2022-04-12 19:25:19 +08:00
|
|
|
private SalaryAcctResultService getSalaryAcctResultService(User user) {
|
2022-06-29 17:38:00 +08:00
|
|
|
return ServiceUtil.getService(SalaryAcctResultServiceImpl.class, user);
|
2022-04-12 19:25:19 +08:00
|
|
|
}
|
2022-04-07 16:54:10 +08:00
|
|
|
|
2022-07-11 17:31:33 +08:00
|
|
|
private SalaryAcctReportServiceImpl getSalaryAcctReportService(User user) {
|
|
|
|
|
return ServiceUtil.getService(SalaryAcctReportServiceImpl.class, user);
|
|
|
|
|
}
|
2022-04-07 16:54:10 +08:00
|
|
|
|
|
|
|
|
// private SalaryCheckResultDetailService salaryCheckResultDetailService;
|
|
|
|
|
|
|
|
|
|
// private SalaryComparisonResultService salaryComparisonResultService;
|
|
|
|
|
|
2022-04-08 16:30:10 +08:00
|
|
|
private SalarySobService getSalarySobService(User user) {
|
2022-07-28 15:42:25 +08:00
|
|
|
return ServiceUtil.getService(SalarySobServiceImpl.class, user);
|
2022-04-08 16:30:10 +08:00
|
|
|
}
|
2022-04-07 16:54:10 +08:00
|
|
|
|
2022-04-08 16:30:10 +08:00
|
|
|
private SalaryEmployeeService getSalaryEmployeeService(User user) {
|
2022-06-29 17:38:00 +08:00
|
|
|
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
|
2022-04-08 16:30:10 +08:00
|
|
|
}
|
2022-04-07 16:54:10 +08:00
|
|
|
|
2022-04-08 16:30:10 +08:00
|
|
|
private SalaryArchiveService getSalaryArchiveService(User user) {
|
2022-07-11 17:31:33 +08:00
|
|
|
return ServiceUtil.getService(SalaryArchiveServiceImpl.class, user);
|
2022-06-29 17:38:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TaxAgentService getTaxAgentService(User user) {
|
|
|
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
2022-04-08 16:30:10 +08:00
|
|
|
}
|
2022-04-07 16:54:10 +08:00
|
|
|
|
2022-09-15 15:31:34 +08:00
|
|
|
private SalarySysConfMapper getSalarySysConfMapper() {
|
|
|
|
|
return SqlProxyHandle.getProxy(SalarySysConfMapper.class);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 18:51:17 +08:00
|
|
|
private SalarySysConfService getSalarySysConfService(User user) {
|
|
|
|
|
return ServiceUtil.getService(SalarySysConfServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeeCountDTO> countBySalaryAcctRecordId(Collection<Long> salaryAcctRecordIds) {
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryAcctRecordIds)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
return getSalaryAcctEmployeeMapper().countGroupBySalaryAcctRecordId(salaryAcctRecordIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SalaryAcctEmployeePO getById(Long id) {
|
|
|
|
|
return getSalaryAcctEmployeeMapper().getById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listByIds(Collection<Long> ids) {
|
|
|
|
|
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().ids(ids).build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listBySalaryAcctRecordId(Long salaryAcctRecordId) {
|
|
|
|
|
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordId(salaryAcctRecordId).build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listBySalaryAcctRecordIds(Collection<Long> salaryAcctRecordIds) {
|
|
|
|
|
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordIds(salaryAcctRecordIds).build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listBySalaryAcctRecordIdAndTaxAgentId(Long salaryAcctRecordId, Long taxAgentId) {
|
|
|
|
|
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordId(salaryAcctRecordId).taxAgentId(taxAgentId).build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addFromReduce(SalaryAcctEmployeeAddParam addParam) {
|
|
|
|
|
ValidUtil.doValidator(addParam);
|
|
|
|
|
// 查询薪资核算记录
|
|
|
|
|
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(addParam.getSalaryAcctRecordId());
|
|
|
|
|
if (Objects.isNull(salaryAcctRecordPO)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
|
|
|
|
|
}
|
|
|
|
|
// 查询环比减少的薪资核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = listByIds(addParam.getIds());
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryAcctEmployeePOS)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98830, "薪资核算人员不存在或已被删除"));
|
|
|
|
|
}
|
|
|
|
|
// 添加薪资核算人员
|
|
|
|
|
Date now = new Date();
|
2022-07-11 17:31:33 +08:00
|
|
|
List<SalaryAcctEmployeePO> newSalaryAcctEmployeePOS = salaryAcctEmployeePOS.stream().map(salaryAcctEmployeePO -> new SalaryAcctEmployeePO()
|
|
|
|
|
.setSalaryAcctRecordId(salaryAcctRecordPO.getId()).setSalarySobId(salaryAcctRecordPO.getSalarySobId()).setSalaryMonth(salaryAcctRecordPO.getSalaryMonth()).setEmployeeId(salaryAcctEmployeePO.getEmployeeId()).setTaxAgentId(salaryAcctEmployeePO.getTaxAgentId()).setTenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY).setCreateTime(now).setUpdateTime(now).setCreator((long) user.getUID()).setDeleteType(0)).collect(Collectors.toList());
|
2022-04-07 16:54:10 +08:00
|
|
|
if (CollectionUtils.isNotEmpty(newSalaryAcctEmployeePOS)) {
|
2022-05-26 13:41:58 +08:00
|
|
|
batchSave(newSalaryAcctEmployeePOS);
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listBySalaryAcctRecordIdAndIds(Long salaryAcctRecordId, Collection<Long> ids) {
|
|
|
|
|
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordId(salaryAcctRecordId).ids(ids).build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listBySalaryAcctRecordIdAndEmployeeIds(Long salaryAcctRecordId, Collection<Long> employeeIds) {
|
|
|
|
|
if (CollectionUtils.isEmpty(employeeIds)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordId(salaryAcctRecordId).employeeIds(employeeIds).build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listBySalaryAcctRecordIdsAndEmployeeIds(Collection<Long> salaryAcctRecordIds, Collection<Long> employeeIds) {
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryAcctRecordIds) || CollectionUtils.isEmpty(employeeIds)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
2023-10-20 10:29:46 +08:00
|
|
|
List<List<Long>> partition = Lists.partition((List<Long>) employeeIds, 500);
|
|
|
|
|
List<SalaryAcctEmployeePO> list = new ArrayList<>();
|
|
|
|
|
partition.forEach(l -> {
|
|
|
|
|
list.addAll(getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordIds(salaryAcctRecordIds).employeeIds(l).build()));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return list;
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listByRecordIdsAndEmpIdAndTaxAgentId(Collection<Long> salaryAcctRecordIds, Long employeeId, Long taxAgentId) {
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryAcctRecordIds)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordIds(salaryAcctRecordIds).employeeId(employeeId).taxAgentId(taxAgentId).build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageInfo<SalaryAcctEmployeePO> listPageByParam(SalaryAcctEmployeeQueryParam queryParam) {
|
|
|
|
|
ValidUtil.doValidator(queryParam);
|
2022-09-26 18:51:17 +08:00
|
|
|
|
|
|
|
|
//排序配置
|
|
|
|
|
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
|
|
|
|
|
queryParam.setOrderRule(orderRule);
|
|
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
// 分页参数
|
|
|
|
|
// 查询薪资核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = getSalaryAcctEmployeeMapper().listPage(queryParam);
|
2022-12-12 10:25:55 +08:00
|
|
|
return SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(),
|
|
|
|
|
salaryAcctEmployeePOS, SalaryAcctEmployeePO.class);
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listByParam(SalaryAcctEmployeeQueryParam queryParam) {
|
2023-08-21 19:35:14 +08:00
|
|
|
// ValidUtil.doValidator(queryParam);
|
2022-09-26 18:51:17 +08:00
|
|
|
//排序配置
|
|
|
|
|
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
|
|
|
|
|
queryParam.setOrderRule(orderRule);
|
2022-04-07 16:54:10 +08:00
|
|
|
return getSalaryAcctEmployeeMapper().list(queryParam);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 19:35:14 +08:00
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listByTaxCycleAndTaxAgentId(SalaryAcctEmployeeQueryParam queryParam) {
|
|
|
|
|
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().taxAgentIds(queryParam.getTaxAgentIds()).taxCycle(queryParam.getTaxCycle()).build());
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
@Override
|
|
|
|
|
public PageInfo<SalaryAcctEmployeePO> listPageByResultQueryParam(SalaryAcctResultQueryParam queryParam) {
|
|
|
|
|
ValidUtil.doValidator(queryParam);
|
|
|
|
|
// 薪资核算人员的查询参数
|
|
|
|
|
SalaryAcctEmployeeQueryParam salaryAcctEmployeeQueryParam = new SalaryAcctEmployeeQueryParam();
|
|
|
|
|
BeanUtils.copyProperties(queryParam, salaryAcctEmployeeQueryParam);
|
|
|
|
|
// 查询薪资核算人员(分页)
|
|
|
|
|
// 如果需要筛选是否合并计税
|
|
|
|
|
if (StringUtils.isNotEmpty(queryParam.getConsolidatedTaxation())) {
|
|
|
|
|
return listPageByParam4ConsolidatedTax(salaryAcctEmployeeQueryParam);
|
|
|
|
|
} else {
|
|
|
|
|
return listPageByParam(salaryAcctEmployeeQueryParam);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listByResultQueryParam(SalaryAcctResultQueryParam queryParam) {
|
|
|
|
|
// 薪资核算人员的查询参数
|
|
|
|
|
SalaryAcctEmployeeQueryParam salaryAcctEmployeeQueryParam = new SalaryAcctEmployeeQueryParam();
|
|
|
|
|
BeanUtils.copyProperties(queryParam, salaryAcctEmployeeQueryParam);
|
|
|
|
|
// 查询薪资核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS;
|
|
|
|
|
// 如果需要筛选是否合并计税
|
|
|
|
|
if (StringUtils.isNotEmpty(queryParam.getConsolidatedTaxation())) {
|
|
|
|
|
salaryAcctEmployeePOS = listByParam4ConsolidatedTax(salaryAcctEmployeeQueryParam);
|
|
|
|
|
} else {
|
|
|
|
|
salaryAcctEmployeePOS = listByParam(salaryAcctEmployeeQueryParam);
|
|
|
|
|
}
|
|
|
|
|
return salaryAcctEmployeePOS;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 16:05:59 +08:00
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
@Override
|
|
|
|
|
public PageInfo<SalaryAcctEmployeePO> listPageByParam4Reduce(SalaryAcctEmployeeQueryParam queryParam) {
|
2022-08-11 16:57:12 +08:00
|
|
|
|
|
|
|
|
// 查询薪资核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = listByParam4Reduce(queryParam);
|
|
|
|
|
PageInfo<SalaryAcctEmployeePO> salaryAcctEmployeePOPageInfo = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), SalaryAcctEmployeePO.class);
|
2022-04-07 16:54:10 +08:00
|
|
|
// 分页参数
|
2022-08-11 16:57:12 +08:00
|
|
|
salaryAcctEmployeePOPageInfo.setTotal(salaryAcctEmployeePOS.size());
|
|
|
|
|
salaryAcctEmployeePOPageInfo.setList(SalaryPageUtil.subList(queryParam.getCurrent(), queryParam.getPageSize(), salaryAcctEmployeePOS));
|
2022-04-07 16:54:10 +08:00
|
|
|
return salaryAcctEmployeePOPageInfo;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 16:05:59 +08:00
|
|
|
@Override
|
|
|
|
|
public PageInfo<SalaryAcctEmployeePO> listPageByParam4Add(SalaryAcctEmployeeQueryParam queryParam) {
|
|
|
|
|
// 查询薪资核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = listByParam4Add(queryParam);
|
|
|
|
|
PageInfo<SalaryAcctEmployeePO> salaryAcctEmployeePOPageInfo = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), SalaryAcctEmployeePO.class);
|
|
|
|
|
// 分页参数
|
|
|
|
|
salaryAcctEmployeePOPageInfo.setTotal(salaryAcctEmployeePOS.size());
|
|
|
|
|
salaryAcctEmployeePOPageInfo.setList(SalaryPageUtil.subList(queryParam.getCurrent(), queryParam.getPageSize(), salaryAcctEmployeePOS));
|
|
|
|
|
return salaryAcctEmployeePOPageInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listByParam4Reduce(SalaryAcctEmployeeQueryParam queryParam) {
|
|
|
|
|
// 查询上个月的薪资核算记录(同一个薪资账套)
|
|
|
|
|
List<SalaryAcctRecordPO> salaryAcctRecordPOS = getSalaryAcctRecordService(user).listById4LastSalaryMonth(queryParam.getSalaryAcctRecordId());
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryAcctRecordPOS)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
Set<Long> lastMonthSalaryAcctRecordIds = SalaryEntityUtil.properties(salaryAcctRecordPOS, SalaryAcctRecordPO::getId);
|
2022-08-11 16:57:12 +08:00
|
|
|
// 上个月的核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> lastMonthSalaryAcctEmployeePOS = listBySalaryAcctRecordIds(lastMonthSalaryAcctRecordIds);
|
|
|
|
|
Map<String, SalaryAcctEmployeePO> lastMonthSalaryAcctEmployeePOMap = SalaryEntityUtil.convert2Map(lastMonthSalaryAcctEmployeePOS, salaryAcctEmployeePO -> salaryAcctEmployeePO.getEmployeeId() + "-" + salaryAcctEmployeePO.getTaxAgentId());
|
|
|
|
|
// 本月的核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = listByParam(queryParam);
|
|
|
|
|
Set<String> keySet = SalaryEntityUtil.properties(salaryAcctEmployeePOS, salaryAcctEmployeePO -> salaryAcctEmployeePO.getEmployeeId() + "-" + salaryAcctEmployeePO.getTaxAgentId());
|
|
|
|
|
List<SalaryAcctEmployeePO> resultList = Lists.newArrayList();
|
2024-01-30 10:26:44 +08:00
|
|
|
if (CollectionUtils.isNotEmpty(keySet)) {
|
2023-11-13 17:12:25 +08:00
|
|
|
lastMonthSalaryAcctEmployeePOMap.forEach((k, v) -> {
|
|
|
|
|
if (!keySet.contains(k)) {
|
|
|
|
|
resultList.add(v);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-08-11 16:57:12 +08:00
|
|
|
return resultList;
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-19 16:05:59 +08:00
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listByParam4Add(SalaryAcctEmployeeQueryParam queryParam) {
|
|
|
|
|
// 查询上个月的薪资核算记录(同一个薪资账套)
|
|
|
|
|
List<SalaryAcctRecordPO> salaryAcctRecordPOS = getSalaryAcctRecordService(user).listById4LastSalaryMonth(queryParam.getSalaryAcctRecordId());
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryAcctRecordPOS)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
Set<Long> lastMonthSalaryAcctRecordIds = SalaryEntityUtil.properties(salaryAcctRecordPOS, SalaryAcctRecordPO::getId);
|
|
|
|
|
// 上个月的核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> lastMonthSalaryAcctEmployeePOS = listBySalaryAcctRecordIds(lastMonthSalaryAcctRecordIds);
|
|
|
|
|
Map<String, SalaryAcctEmployeePO> lastMonthSalaryAcctEmployeePOMap = SalaryEntityUtil.convert2Map(lastMonthSalaryAcctEmployeePOS, salaryAcctEmployeePO -> salaryAcctEmployeePO.getEmployeeId() + "-" + salaryAcctEmployeePO.getTaxAgentId());
|
|
|
|
|
// 本月的核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = listByParam(queryParam);
|
|
|
|
|
// Set<String> keySet = SalaryEntityUtil.properties(salaryAcctEmployeePOS, salaryAcctEmployeePO -> salaryAcctEmployeePO.getEmployeeId() + "-" + salaryAcctEmployeePO.getTaxAgentId());
|
|
|
|
|
Map<String, SalaryAcctEmployeePO> thisMonthSalaryAcctEmployeePOMap = SalaryEntityUtil.convert2Map(salaryAcctEmployeePOS, salaryAcctEmployeePO -> salaryAcctEmployeePO.getEmployeeId() + "-" + salaryAcctEmployeePO.getTaxAgentId());
|
|
|
|
|
List<SalaryAcctEmployeePO> resultList = Lists.newArrayList();
|
2022-09-27 17:43:43 +08:00
|
|
|
thisMonthSalaryAcctEmployeePOMap.forEach((k, v) -> {
|
|
|
|
|
if (!lastMonthSalaryAcctEmployeePOMap.containsKey(k)) {
|
2022-09-19 16:05:59 +08:00
|
|
|
resultList.add(v);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return resultList;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-11 16:57:12 +08:00
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
@Override
|
|
|
|
|
public PageInfo<SalaryAcctEmployeePO> listPageByParam4ConsolidatedTax(SalaryAcctEmployeeQueryParam queryParam) {
|
2022-09-26 18:51:17 +08:00
|
|
|
//排序配置
|
|
|
|
|
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
|
|
|
|
|
queryParam.setOrderRule(orderRule);
|
2022-04-07 16:54:10 +08:00
|
|
|
// 查询合并计税的其他薪资核算记录
|
|
|
|
|
List<SalaryAcctRecordPO> otherSalaryAcctRecordPOS = getSalaryAcctRecordService(user).listById4OtherConsolidatedTax(queryParam.getSalaryAcctRecordId());
|
|
|
|
|
if (CollectionUtils.isEmpty(otherSalaryAcctRecordPOS)) {
|
|
|
|
|
return new PageInfo<>();
|
|
|
|
|
}
|
|
|
|
|
// 查询合并计税的薪资核算人员
|
|
|
|
|
Set<Long> otherSalaryAcctRecordIds = SalaryEntityUtil.properties(otherSalaryAcctRecordPOS, SalaryAcctRecordPO::getId);
|
|
|
|
|
// 分页参数
|
2024-01-30 10:26:44 +08:00
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = new ArrayList<>();
|
|
|
|
|
if (CollUtil.isNotEmpty(queryParam.getIds())) {
|
|
|
|
|
List<SalaryAcctEmployeePO> list = new ArrayList<>();
|
|
|
|
|
List<List<Long>> partition = Lists.partition(queryParam.getIds(), 500);
|
|
|
|
|
partition.forEach(ids -> {
|
|
|
|
|
queryParam.setIds(ids);
|
|
|
|
|
list.addAll(getSalaryAcctEmployeeMapper().list4ConsolidatedTax(otherSalaryAcctRecordIds, queryParam));
|
|
|
|
|
});
|
|
|
|
|
salaryAcctEmployeePOS = list;
|
|
|
|
|
} else {
|
|
|
|
|
salaryAcctEmployeePOS = getSalaryAcctEmployeeMapper().listPage4ConsolidatedTax(otherSalaryAcctRecordIds, queryParam);
|
|
|
|
|
}
|
2023-04-10 12:43:48 +08:00
|
|
|
return SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(),
|
2022-12-12 10:25:55 +08:00
|
|
|
salaryAcctEmployeePOS, SalaryAcctEmployeePO.class);
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listByParam4ConsolidatedTax(SalaryAcctEmployeeQueryParam queryParam) {
|
2022-09-26 18:51:17 +08:00
|
|
|
//排序配置
|
|
|
|
|
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
|
|
|
|
|
queryParam.setOrderRule(orderRule);
|
2022-04-07 16:54:10 +08:00
|
|
|
// 查询合并计税的其他薪资核算记录
|
|
|
|
|
List<SalaryAcctRecordPO> otherSalaryAcctRecordPOS = getSalaryAcctRecordService(user).listById4OtherConsolidatedTax(queryParam.getSalaryAcctRecordId());
|
|
|
|
|
if (CollectionUtils.isEmpty(otherSalaryAcctRecordPOS)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
// 查询合并计税的薪资核算人员
|
|
|
|
|
Set<Long> otherSalaryAcctRecordIds = SalaryEntityUtil.properties(otherSalaryAcctRecordPOS, SalaryAcctRecordPO::getId);
|
2024-01-30 10:26:44 +08:00
|
|
|
|
|
|
|
|
List<SalaryAcctEmployeePO> list = new ArrayList<>();
|
|
|
|
|
if (CollUtil.isNotEmpty(queryParam.getIds())) {
|
|
|
|
|
List<List<Long>> partition = Lists.partition(queryParam.getIds(), 500);
|
|
|
|
|
partition.forEach(ids -> {
|
|
|
|
|
queryParam.setIds(ids);
|
|
|
|
|
list.addAll(getSalaryAcctEmployeeMapper().list4ConsolidatedTax(otherSalaryAcctRecordIds, queryParam));
|
|
|
|
|
});
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
return getSalaryAcctEmployeeMapper().list4ConsolidatedTax(otherSalaryAcctRecordIds, queryParam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void save(SalaryAcctEmployeeSaveParam saveParam) {
|
2022-04-08 16:30:10 +08:00
|
|
|
ValidUtil.doValidator(saveParam);
|
|
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
// 查询薪资核算记录
|
|
|
|
|
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(saveParam.getSalaryAcctRecordId());
|
|
|
|
|
if (Objects.isNull(salaryAcctRecordPO)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
|
|
|
|
|
}
|
|
|
|
|
// 查询薪资核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> existSalaryAcctEmployeePOS = listBySalaryAcctRecordIdAndEmployeeIds(saveParam.getSalaryAcctRecordId(), saveParam.getEmployeeIds());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(existSalaryAcctEmployeePOS)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(101581, "人员已存在,请勿重复添加"));
|
|
|
|
|
}
|
|
|
|
|
// 根据薪资账套查询薪资周期
|
2022-04-08 16:30:10 +08:00
|
|
|
SalarySobCycleDTO salarySobCycleDTO = getSalarySobService(user).getSalarySobCycle(salaryAcctRecordPO.getSalarySobId(), SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth()));
|
2022-08-09 16:45:22 +08:00
|
|
|
//获取核算的扣缴义务人
|
2022-04-08 16:30:10 +08:00
|
|
|
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
|
2022-04-07 16:54:10 +08:00
|
|
|
if (Objects.isNull(salarySobPO)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98769, "薪资账套不存在或已被删除"));
|
|
|
|
|
}
|
2022-07-28 16:23:39 +08:00
|
|
|
Long taxAgentId = salarySobPO.getTaxAgentId();
|
2022-08-09 16:45:22 +08:00
|
|
|
|
|
|
|
|
// 查询薪资档案
|
|
|
|
|
List<SalaryArchiveDataDTO> salaryArchiveDataDTOS = getSalaryArchiveService(user).getSalaryArchiveTaxAgentData(salarySobCycleDTO.getSalaryCycle(), saveParam.getEmployeeIds(), taxAgentId);
|
|
|
|
|
// 转换成薪资核算人员po
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = SalaryAcctEmployeeBO.convert2EmployeePO(saveParam.getEmployeeIds(), salaryAcctRecordPO, salaryArchiveDataDTOS, (long) user.getUID());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//过滤不是扣缴义务人下的人员
|
2022-07-28 16:23:39 +08:00
|
|
|
salaryAcctEmployeePOS = salaryAcctEmployeePOS.stream().filter(ps -> Objects.equals(taxAgentId, ps.getTaxAgentId())).collect(Collectors.toList());
|
|
|
|
|
// 保存薪资核算人员
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryAcctEmployeePOS)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98769, "个税扣缴义务人下无该人员档案信息或薪资缴纳日期不在薪资周期内"));
|
|
|
|
|
}
|
|
|
|
|
batchSave(salaryAcctEmployeePOS);
|
|
|
|
|
|
|
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
// 记录日志
|
2024-01-24 09:50:58 +08:00
|
|
|
String targetName = salarySobPO.getName() + ":" + SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth());
|
|
|
|
|
LoggerContext loggerContext = new LoggerContext<>();
|
|
|
|
|
loggerContext.setUser(user);
|
|
|
|
|
loggerContext.setTargetId("" + salaryAcctRecordPO.getId());
|
|
|
|
|
loggerContext.setTargetName(targetName);
|
|
|
|
|
loggerContext.setOperateType(OperateTypeEnum.ADD.getValue());
|
2024-02-04 15:10:35 +08:00
|
|
|
loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(0, "添加薪资核算人员"));
|
|
|
|
|
loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(0, "添加薪资核算人员") + ":" + targetName);
|
2024-01-24 09:50:58 +08:00
|
|
|
loggerContext.setNewValueList(salaryAcctEmployeePOS);
|
2024-01-30 09:58:13 +08:00
|
|
|
SalaryElogConfig.salaryAcctRecordLoggerTemplate.write(loggerContext);
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void batchSave(Collection<SalaryAcctEmployeePO> salaryAcctEmployeePOS) {
|
2022-05-31 11:03:56 +08:00
|
|
|
if (CollectionUtils.isEmpty(salaryAcctEmployeePOS)) {
|
2022-05-26 13:41:58 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<List<SalaryAcctEmployeePO>> partition = Lists.partition((List) salaryAcctEmployeePOS, 100);
|
|
|
|
|
partition.forEach(getSalaryAcctEmployeeMapper()::batchInsert);
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteByIds(Collection<Long> ids) {
|
|
|
|
|
// 删除薪资核算人员
|
|
|
|
|
getSalaryAcctEmployeeMapper().deleteByIds(ids);
|
2022-04-12 19:25:19 +08:00
|
|
|
// 删除薪资核算人员对应的薪资核算结果
|
|
|
|
|
getSalaryAcctResultService(user).deleteBySalaryAcctEmployeeIds(ids);
|
2022-07-11 17:31:33 +08:00
|
|
|
// 删除报表
|
|
|
|
|
getSalaryAcctReportService(user).deleteBySalaryAcctEmpIds(ids);
|
|
|
|
|
|
2022-04-12 19:25:19 +08:00
|
|
|
// 删除薪资核算人员对应的校验异常明细
|
2022-04-07 16:54:10 +08:00
|
|
|
// salaryCheckResultDetailService.deleteBySalaryAcctEmployeeIds(ids);
|
2022-04-12 19:25:19 +08:00
|
|
|
// 删除薪资核算人员对应的线下对比结果
|
2022-04-07 16:54:10 +08:00
|
|
|
// salaryComparisonResultService.deleteBySalaryAcctRecordIds(ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteByParam(SalaryAcctEmployeeDeleteParam deleteParam) {
|
2022-04-08 16:30:10 +08:00
|
|
|
ValidUtil.doValidator(deleteParam);
|
2022-04-07 16:54:10 +08:00
|
|
|
// 查询薪资核算记录
|
|
|
|
|
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(deleteParam.getSalaryAcctRecordId());
|
|
|
|
|
if (Objects.isNull(salaryAcctRecordPO)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
|
|
|
|
|
}
|
2022-12-02 17:35:14 +08:00
|
|
|
// 回算不允许删除薪资核算人员
|
2023-04-10 12:43:48 +08:00
|
|
|
if (Objects.equals(salaryAcctRecordPO.getBackCalcStatus(), 1)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0, "正常薪资已经发放,薪资回算时,不允许再删除薪资核算人员"));
|
2022-12-02 17:35:14 +08:00
|
|
|
}
|
2022-04-07 16:54:10 +08:00
|
|
|
// 只有未归档时才能删除薪资核算人员
|
|
|
|
|
if (!Objects.equals(salaryAcctRecordPO.getStatus(), SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue())) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98830, "薪资核算已归档或已申报,不允许再删除薪资核算人员"));
|
|
|
|
|
}
|
|
|
|
|
// 查询薪资核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = listBySalaryAcctRecordIdAndIds(deleteParam.getSalaryAcctRecordId(), deleteParam.getIds());
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryAcctEmployeePOS)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98830, "薪资核算人员不存在或已被删除"));
|
|
|
|
|
}
|
|
|
|
|
// 删除薪资核算人员
|
|
|
|
|
Set<Long> ids = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId);
|
|
|
|
|
deleteByIds(ids);
|
|
|
|
|
|
|
|
|
|
// 查询薪资账套(记录日志用)
|
2022-04-08 16:30:10 +08:00
|
|
|
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
|
2022-04-07 16:54:10 +08:00
|
|
|
if (Objects.isNull(salarySobPO)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98769, "薪资账套不存在或已被删除"));
|
|
|
|
|
}
|
|
|
|
|
// 记录日志
|
2024-01-24 09:50:58 +08:00
|
|
|
String targetName = salarySobPO.getName() + ":" + SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth());
|
|
|
|
|
LoggerContext loggerContext = new LoggerContext<>();
|
|
|
|
|
loggerContext.setUser(user);
|
|
|
|
|
loggerContext.setTargetId("" + salaryAcctRecordPO.getId());
|
|
|
|
|
loggerContext.setTargetName(targetName);
|
|
|
|
|
loggerContext.setOperateType(OperateTypeEnum.DELETE.getValue());
|
2024-02-04 15:10:35 +08:00
|
|
|
loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(0, "删除薪资核算人员"));
|
|
|
|
|
loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(0, "删除薪资核算人员") + ":" + targetName);
|
2024-01-24 09:50:58 +08:00
|
|
|
loggerContext.setOldValueList(salaryAcctEmployeePOS);
|
2024-01-30 09:58:13 +08:00
|
|
|
SalaryElogConfig.salaryAcctRecordLoggerTemplate.write(loggerContext);
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteBySalaryAcctRecordIds(Collection<Long> salaryAcctRecordIds) {
|
|
|
|
|
getSalaryAcctEmployeeMapper().deleteBySalaryAcctRecordIds(salaryAcctRecordIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initBySalaryAcctRecord(SalaryAcctRecordPO salaryAcctRecordPO) {
|
|
|
|
|
// 根据薪资账套查询人员
|
2022-04-08 16:30:10 +08:00
|
|
|
List<DataCollectionEmployee> salaryEmployees = getSalaryEmployeeService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
|
2022-04-07 16:54:10 +08:00
|
|
|
if (CollectionUtils.isEmpty(salaryEmployees)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 根据薪资账套查询薪资周期
|
2022-04-08 16:30:10 +08:00
|
|
|
SalarySobCycleDTO salarySobCycleDTO = getSalarySobService(user).getSalarySobCycle(salaryAcctRecordPO.getSalarySobId(), SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth()));
|
2022-06-08 16:36:50 +08:00
|
|
|
|
2022-07-28 15:42:25 +08:00
|
|
|
// // 根据薪资账套的"核算人员范围"过滤入职日期大于薪资周期止的人员
|
|
|
|
|
// salaryEmployees = salaryEmployees.stream().filter(salaryEmployee -> StringUtils.isBlank(salaryEmployee.getCompanystartdate()) || (SalaryDateUtil.stringToDate(salaryEmployee.getCompanystartdate()) != null && SalaryDateUtil.stringToDate(salaryEmployee.getCompanystartdate()).compareTo(salarySobCycleDTO.getSalaryCycle().getEndDate()) <= 0)).collect(Collectors.toList());
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// // 根据薪资账套的"核算人员范围"过滤离职日期小于薪资周期起的人员
|
|
|
|
|
// salaryEmployees = salaryEmployees.stream().filter(salaryEmployee -> StringUtils.isBlank(salaryEmployee.getDismissdate()) || (SalaryDateUtil.stringToDate(salaryEmployee.getCompanystartdate()) != null && SalaryDateUtil.stringToDate(salaryEmployee.getDismissdate()).compareTo(salarySobCycleDTO.getSalaryCycle().getEndDate()) > 0)).collect(Collectors.toList());
|
2022-05-12 14:36:16 +08:00
|
|
|
|
2022-06-29 17:38:00 +08:00
|
|
|
|
|
|
|
|
//查询账套对应的扣缴义务人
|
|
|
|
|
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
|
|
|
|
|
Long taxAgentId = salarySobPO.getTaxAgentId();
|
2022-08-03 17:02:03 +08:00
|
|
|
// //过滤扣税扣缴义务人不包含的人员
|
|
|
|
|
// Collection<Long> employeeIdsInTaxAgent = getTaxAgentService(user).listEmployeeIdsInTaxAgent(taxAgentId);
|
|
|
|
|
// salaryEmployees = salaryEmployees.stream().filter(salaryEmployee -> employeeIdsInTaxAgent.contains(salaryEmployee.getEmployeeId())).collect(Collectors.toList());
|
2022-06-29 17:38:00 +08:00
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
// 查询薪资档案,获取人员的个税扣缴义务人
|
2023-04-10 12:43:48 +08:00
|
|
|
List<Long> employeeIds = SalaryEntityUtil.properties(salaryEmployees, DataCollectionEmployee::getEmployeeId, Collectors.toList());
|
2022-08-09 16:45:22 +08:00
|
|
|
List<SalaryArchiveDataDTO> salaryArchiveDataDTOS = getSalaryArchiveService(user).getSalaryArchiveTaxAgentData(salarySobCycleDTO.getSalaryCycle(), employeeIds, taxAgentId);
|
2022-04-07 16:54:10 +08:00
|
|
|
// 转换成薪资核算人员po
|
2023-03-15 18:03:46 +08:00
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = SalaryAcctEmployeeBO.convert2Employee(salaryEmployees, salaryAcctRecordPO, salaryArchiveDataDTOS, (long) user.getUID());
|
2022-06-29 17:38:00 +08:00
|
|
|
|
|
|
|
|
//过滤掉不属于当前账套扣缴义务人的人员
|
2022-07-11 17:31:33 +08:00
|
|
|
salaryAcctEmployeePOS = salaryAcctEmployeePOS.stream().filter(po -> Objects.equals(taxAgentId, po.getTaxAgentId())).collect(Collectors.toList());
|
2022-06-29 17:38:00 +08:00
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
// 保存薪资核算人员
|
|
|
|
|
if (CollectionUtils.isNotEmpty(salaryAcctEmployeePOS)) {
|
2022-05-26 13:41:58 +08:00
|
|
|
batchSave(salaryAcctEmployeePOS);
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void refresh(Long salaryAcctRecordId) {
|
|
|
|
|
// 查询薪资核算人员
|
|
|
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = listBySalaryAcctRecordId(salaryAcctRecordId);
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryAcctEmployeePOS)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-10 12:43:48 +08:00
|
|
|
List<Long> employeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getEmployeeId, Collectors.toList());
|
2022-04-07 16:54:10 +08:00
|
|
|
// 查询薪资核算记录
|
|
|
|
|
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
|
|
|
|
|
if (Objects.isNull(salaryAcctRecordPO)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
|
|
|
|
|
}
|
2022-08-09 16:45:22 +08:00
|
|
|
//查询账套对应的扣缴义务人
|
|
|
|
|
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
|
|
|
|
|
//过滤掉不属于当前账套扣缴义务人的人员
|
|
|
|
|
Long taxAgentId = salarySobPO.getTaxAgentId();
|
|
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
// 查询薪资核算记录所用的帐套的薪资周期
|
2022-07-11 17:31:33 +08:00
|
|
|
SalarySobCycleDTO salarySobCycleDTO = getSalarySobService(user).getSalarySobCycle(salaryAcctRecordPO.getSalarySobId(), SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth()));
|
2022-04-07 16:54:10 +08:00
|
|
|
// 查询薪资档案,获取人员的个税扣缴义务人
|
2022-08-09 16:45:22 +08:00
|
|
|
List<SalaryArchiveDataDTO> salaryArchiveDataDTOS = getSalaryArchiveService(user).getSalaryArchiveTaxAgentData(salarySobCycleDTO.getSalaryCycle(), employeeIds, taxAgentId);
|
2022-04-07 16:54:10 +08:00
|
|
|
// 转换成薪资核算人员po
|
|
|
|
|
List<SalaryAcctEmployeePO> newSalaryAcctEmployeePOS = SalaryAcctEmployeeBO.convert2EmployeePO(employeeIds, salaryAcctRecordPO, salaryArchiveDataDTOS, (long) user.getUID());
|
2022-07-11 17:31:33 +08:00
|
|
|
newSalaryAcctEmployeePOS = newSalaryAcctEmployeePOS.stream().filter(po -> Objects.equals(taxAgentId, po.getTaxAgentId())).collect(Collectors.toList());
|
2022-04-07 16:54:10 +08:00
|
|
|
// 删除以前的薪资核算人员
|
|
|
|
|
getSalaryAcctEmployeeMapper().deleteBySalaryAcctRecordIds(Collections.singleton(salaryAcctRecordId));
|
|
|
|
|
// 插入新的薪资核算人员
|
|
|
|
|
if (CollectionUtils.isNotEmpty(newSalaryAcctEmployeePOS)) {
|
2022-05-26 13:41:58 +08:00
|
|
|
batchSave(newSalaryAcctEmployeePOS);
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
}
|
2022-09-15 15:31:34 +08:00
|
|
|
|
2023-04-10 09:47:33 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SalaryAcctEmployeePO> listBySalaryStatisticsReportParam(SalaryStatisticsReportDataQueryParam param) {
|
|
|
|
|
SalaryAcctEmployeePO lambdaQueryChainWrapper = SalaryAcctEmployeePO.builder().build();
|
|
|
|
|
|
|
|
|
|
// 个税扣缴义务人
|
2023-12-26 16:12:44 +08:00
|
|
|
// Collection<TaxAgentPO> taxAgentList = getTaxAgentService(user).listAllTaxAgents((long) user.getUID());
|
|
|
|
|
// if (CollectionUtils.isNotEmpty(taxAgentList)) {
|
|
|
|
|
// List<Long> taxAgentIds = taxAgentList.stream().map(TaxAgentPO::getId).collect(Collectors.toList());
|
|
|
|
|
// // 有查询参数就取交集
|
|
|
|
|
// if (CollectionUtils.isNotEmpty(param.getTaxAgent())) {
|
|
|
|
|
// List<Long> finalTaxAgentIds = taxAgentIds;
|
|
|
|
|
// taxAgentIds = param.getTaxAgent().stream().filter(finalTaxAgentIds::contains).collect(Collectors.toList());
|
|
|
|
|
// lambdaQueryChainWrapper.setTaxAgentIds(CollectionUtils.isEmpty(taxAgentIds) ? Collections.singletonList(0L) : taxAgentIds);
|
|
|
|
|
// } else {
|
|
|
|
|
// lambdaQueryChainWrapper.setTaxAgentIds(taxAgentIds);
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// lambdaQueryChainWrapper.setTaxAgentIds(Collections.singletonList(0L));
|
|
|
|
|
// }
|
|
|
|
|
if (CollectionUtils.isNotEmpty(param.getTaxAgent())) {
|
|
|
|
|
lambdaQueryChainWrapper.setTaxAgentIds(param.getTaxAgent());
|
2023-04-10 09:47:33 +08:00
|
|
|
}
|
|
|
|
|
|
2024-02-28 14:43:27 +08:00
|
|
|
if (CollectionUtils.isNotEmpty(param.getSalarySob())) {
|
|
|
|
|
lambdaQueryChainWrapper.setSalarySobIds(param.getSalarySob());
|
2023-04-10 09:47:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 薪资所属月
|
2023-04-26 15:17:08 +08:00
|
|
|
Date startYearMonth = SalaryDateUtil.dateStrToLocalYearMonth(param.getSalaryStartMonth());
|
|
|
|
|
Date endYearMonth = SalaryDateUtil.dateStrToLocalYearMonth(param.getSalaryEndMonth());
|
2023-04-10 09:47:33 +08:00
|
|
|
if (Objects.nonNull(startYearMonth) && Objects.nonNull(endYearMonth)) {
|
2023-04-10 12:43:48 +08:00
|
|
|
Set<Date> yearMonths = Sets.newHashSet();
|
|
|
|
|
while (!startYearMonth.after(endYearMonth)) {
|
|
|
|
|
yearMonths.add(startYearMonth);
|
|
|
|
|
startYearMonth = DateUtil.offsetMonth(startYearMonth, 1);
|
2023-04-10 09:47:33 +08:00
|
|
|
}
|
2023-04-10 12:43:48 +08:00
|
|
|
lambdaQueryChainWrapper.setSalaryMonths(yearMonths);
|
2023-04-10 09:47:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 收入所得项目
|
2023-04-10 12:43:48 +08:00
|
|
|
// if (CollectionUtils.isNotEmpty(param.getIncomeCategory())) {
|
|
|
|
|
// lambdaQueryChainWrapper.in(SalaryAcctEmployeePO::getIncomeCategory, param.getIncomeCategory().stream().map(Object::toString).collect(Collectors.toList()));
|
|
|
|
|
// }
|
2023-04-10 09:47:33 +08:00
|
|
|
|
2023-06-16 13:49:40 +08:00
|
|
|
//排除未归档数据
|
|
|
|
|
List<SalaryAcctRecordPO> salaryAcctRecordPOS = getSalaryAcctRecordService(user).listAll();
|
|
|
|
|
List<Long> salaryAcctRecordIds = salaryAcctRecordPOS.stream()
|
|
|
|
|
.filter(po -> !Objects.equals(po.getStatus(), SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue()))
|
|
|
|
|
.map(SalaryAcctRecordPO::getId)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
List<SalaryAcctEmployeePO> list = new ArrayList<>();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(salaryAcctRecordIds)) {
|
|
|
|
|
//分片查询
|
|
|
|
|
List<List<Long>> partition = Lists.partition(salaryAcctRecordIds, 500);
|
|
|
|
|
List<SalaryAcctEmployeePO> empList = new ArrayList<>();
|
|
|
|
|
partition.forEach(part -> {
|
|
|
|
|
lambdaQueryChainWrapper.setSalaryAcctRecordIds(salaryAcctRecordIds);
|
|
|
|
|
empList.addAll(getSalaryAcctEmployeeMapper().listSome(lambdaQueryChainWrapper));
|
|
|
|
|
});
|
|
|
|
|
list = empList;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 09:47:33 +08:00
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
return Lists.newArrayList();
|
|
|
|
|
}
|
|
|
|
|
List<Long> employeeIds = list.stream().map(SalaryAcctEmployeePO::getEmployeeId).collect(Collectors.toList());
|
|
|
|
|
|
2023-04-10 12:43:48 +08:00
|
|
|
|
|
|
|
|
List<DataCollectionEmployee> employeeList = getSalaryEmployeeService(user).listByIds(employeeIds);
|
2023-04-10 09:47:33 +08:00
|
|
|
// 获取分部信息
|
2023-04-10 12:43:48 +08:00
|
|
|
List<Long> subCompanyIds = param.getSubCompany();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(subCompanyIds)) {
|
2023-11-24 16:49:54 +08:00
|
|
|
// SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo();
|
|
|
|
|
// List<String> allSubcompanyIds = new ArrayList<>();
|
|
|
|
|
// for (Long subCompanyId : subCompanyIds) {
|
|
|
|
|
// String organizationIds = Util.null2String(subCompanyId);
|
|
|
|
|
// String allChildSubcompanyId = subCompanyComInfo.getAllChildSubcompanyId(subCompanyId.toString(), organizationIds);
|
|
|
|
|
// allSubcompanyIds.addAll(Arrays.asList(allChildSubcompanyId.split(",")));
|
|
|
|
|
// }
|
|
|
|
|
employeeList = employeeList.stream().filter(emp -> subCompanyIds.contains(emp.getSubcompanyid())).collect(Collectors.toList());
|
2023-04-10 09:47:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 部门过滤
|
2023-04-10 12:43:48 +08:00
|
|
|
List<Long> depart = param.getDepart();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(depart)) {
|
2023-11-24 16:49:54 +08:00
|
|
|
// List<String> allDepartIds = new ArrayList<>();
|
|
|
|
|
// for (Long subDepartId : depart) {
|
|
|
|
|
// String ids = Util.null2String(subDepartId);
|
|
|
|
|
// try {
|
|
|
|
|
// String allDepartId = DepartmentComInfo.getAllChildDepartId(subDepartId.toString(), ids);
|
|
|
|
|
// allDepartIds.addAll(Arrays.asList(allDepartId.toString().split(",")));
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// log.error("获取子部门失败", e);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
employeeList = employeeList.stream().filter(emp -> depart.contains(emp.getDepartmentId())).collect(Collectors.toList());
|
2023-04-10 09:47:33 +08:00
|
|
|
}
|
|
|
|
|
// 职级过滤
|
2023-04-10 12:43:48 +08:00
|
|
|
// if (CollectionUtils.isNotEmpty(param.getGrade())) {
|
|
|
|
|
// Set<Long> employeeIdsByGradeFilter = new HashSet<>();
|
|
|
|
|
// simpleEmployeeList.forEach(simpleEmployee -> {
|
|
|
|
|
// if (simpleEmployee.getGrade() != null && param.getGrade().contains(simpleEmployee.getGrade().getId())) {
|
|
|
|
|
// employeeIdsByGradeFilter.add(simpleEmployee.getEmployeeId());
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// if (CollectionUtils.isEmpty(employeeIdsByGradeFilter)) {
|
|
|
|
|
// return Lists.newArrayList();
|
|
|
|
|
// }
|
|
|
|
|
// list = list.stream().filter(po -> employeeIdsByGradeFilter.contains(po.getEmployeeId())).collect(Collectors.toList());
|
|
|
|
|
// }
|
|
|
|
|
// // 岗位过滤
|
|
|
|
|
// if (CollectionUtils.isNotEmpty(param.getPosition())) {
|
|
|
|
|
// Set<Long> employeeIdsByPostionFilter = new HashSet<>();
|
|
|
|
|
// simpleEmployeeList.forEach(simpleEmployee -> {
|
|
|
|
|
// if (simpleEmployee.getPosition() != null && param.getPosition().contains(simpleEmployee.getPosition().getId())) {
|
|
|
|
|
// employeeIdsByPostionFilter.add(simpleEmployee.getEmployeeId());
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// if (CollectionUtils.isEmpty(employeeIdsByPostionFilter)) {
|
|
|
|
|
// return Lists.newArrayList();
|
|
|
|
|
// }
|
|
|
|
|
// list = list.stream().filter(po -> employeeIdsByPostionFilter.contains(po.getEmployeeId())).collect(Collectors.toList());
|
|
|
|
|
// }
|
2024-03-25 17:29:40 +08:00
|
|
|
// 人事状态过滤
|
|
|
|
|
if (CollectionUtils.isNotEmpty(param.getStatus())) {
|
|
|
|
|
Set<Long> employeeIdsByStatus = new HashSet<>();
|
|
|
|
|
employeeList.forEach(simpleEmployee -> {
|
|
|
|
|
if (simpleEmployee.getStatus() != null && param.getStatus().contains(simpleEmployee.getStatus())) {
|
|
|
|
|
employeeIdsByStatus.add(simpleEmployee.getEmployeeId());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (CollectionUtils.isEmpty(employeeIdsByStatus)) {
|
|
|
|
|
return Lists.newArrayList();
|
|
|
|
|
}
|
|
|
|
|
list = list.stream().filter(po -> employeeIdsByStatus.contains(po.getEmployeeId())).collect(Collectors.toList());
|
|
|
|
|
}
|
2023-04-26 15:17:08 +08:00
|
|
|
// 入职日期
|
|
|
|
|
if (CollectionUtils.isNotEmpty(param.getHiredate())) {
|
|
|
|
|
Set<Long> employeeIdsByHiredate = new HashSet<>();
|
2023-04-26 16:04:33 +08:00
|
|
|
employeeList.forEach(simpleEmployee -> {
|
|
|
|
|
Date hiredate = SalaryDateUtil.stringToDate(simpleEmployee.getCompanystartdate());
|
|
|
|
|
if (hiredate != null && !hiredate.before(param.getHiredate().get(0)) && !hiredate.after(param.getHiredate().get(1))) {
|
2023-04-26 15:17:08 +08:00
|
|
|
employeeIdsByHiredate.add(simpleEmployee.getEmployeeId());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (CollectionUtils.isEmpty(employeeIdsByHiredate)) {
|
|
|
|
|
return Lists.newArrayList();
|
|
|
|
|
}
|
|
|
|
|
list = list.stream().filter(po -> employeeIdsByHiredate.contains(po.getEmployeeId())).collect(Collectors.toList());
|
|
|
|
|
}
|
2023-04-10 09:47:33 +08:00
|
|
|
// // 离职日期 todo
|
|
|
|
|
// if (CollectionUtils.isNotEmpty(param.getLeavedate())) {
|
|
|
|
|
// Set<Long> employeeIdsByLeavedate = new HashSet<>();
|
|
|
|
|
// simpleEmployeeList.forEach(simpleEmployee -> {
|
|
|
|
|
//
|
|
|
|
|
// if (simpleEmployee.get() != null && ) {
|
|
|
|
|
// employeeIdsByLeavedate.add(simpleEmployee.getEmployeeId());
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// if (CollectionUtils.isEmpty(employeeIdsByLeavedate)) {
|
|
|
|
|
// return Lists.newArrayList();
|
|
|
|
|
// }
|
|
|
|
|
// list = list.stream().filter(po -> employeeIdsByLeavedate.contains(po.getEmployeeId())).collect(Collectors.toList());
|
|
|
|
|
// }
|
|
|
|
|
// 人员
|
|
|
|
|
if (CollectionUtils.isNotEmpty(param.getEmployee())) {
|
|
|
|
|
list = list.stream().filter(po -> param.getEmployee().contains(po.getEmployeeId())).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 12:43:48 +08:00
|
|
|
Set<Long> empIds = SalaryEntityUtil.properties(employeeList, DataCollectionEmployee::getEmployeeId);
|
|
|
|
|
list = list.stream().filter(po -> empIds.contains(po.getEmployeeId())).collect(Collectors.toList());
|
|
|
|
|
|
2023-04-10 09:47:33 +08:00
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2023-04-10 12:43:48 +08:00
|
|
|
public List<SalaryAcctEmployeePO> listByTaxAgentAndSalaryMonth(List<Long> taxAgentIds, Set<Date> salaryMonths) {
|
|
|
|
|
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().taxAgentIds(taxAgentIds).salaryMonths(salaryMonths).build());
|
2023-04-10 09:47:33 +08:00
|
|
|
}
|
|
|
|
|
|
2022-04-07 16:54:10 +08:00
|
|
|
}
|