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

1073 lines
62 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 cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import com.api.formmode.mybatis.util.SqlProxyHandle;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.hrmelog.entity.dto.LoggerContext;
import com.engine.salary.common.LocalDateRange;
import com.engine.salary.config.SalaryElogConfig;
import com.engine.salary.constant.SalaryDefaultTenantConstant;
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.salaryacct.po.SalaryAcctResultPO;
import com.engine.salary.entity.salaryarchive.dto.SalaryArchiveDataDTO;
import com.engine.salary.entity.salaryarchive.po.SalaryArchivePO;
import com.engine.salary.entity.salarysob.bo.SalarySobCycleBO;
import com.engine.salary.entity.salarysob.dto.SalarySobCycleDTO;
import com.engine.salary.entity.salarysob.po.SalarySobPO;
import com.engine.salary.enums.OperateTypeEnum;
import com.engine.salary.enums.salaryaccounting.LockStatusEnum;
import com.engine.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.salaryacct.SalaryAcctEmployeeMapper;
import com.engine.salary.mapper.sys.SalarySysConfMapper;
import com.engine.salary.report.entity.param.SalaryStatisticsReportDataQueryParam;
import com.engine.salary.service.*;
import com.engine.salary.sys.entity.vo.OrderRuleVO;
import com.engine.salary.sys.service.SalarySysConfService;
import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl;
import com.engine.salary.util.SalaryDateUtil;
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.ValidUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.BeanUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
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
**/
@Slf4j
public class SalaryAcctEmployeeServiceImpl extends Service implements SalaryAcctEmployeeService {
private SalaryAcctEmployeeMapper getSalaryAcctEmployeeMapper() {
return MapperProxyFactory.getProxy(SalaryAcctEmployeeMapper.class);
}
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
}
private SalaryAcctResultService getSalaryAcctResultService(User user) {
return ServiceUtil.getService(SalaryAcctResultServiceImpl.class, user);
}
private SalaryAcctReportServiceImpl getSalaryAcctReportService(User user) {
return ServiceUtil.getService(SalaryAcctReportServiceImpl.class, user);
}
// private SalaryCheckResultDetailService salaryCheckResultDetailService;
// private SalaryComparisonResultService salaryComparisonResultService;
private SalarySobService getSalarySobService(User user) {
return ServiceUtil.getService(SalarySobServiceImpl.class, user);
}
private SalaryEmployeeService getSalaryEmployeeService(User user) {
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
}
private SalaryArchiveService getSalaryArchiveService(User user) {
return ServiceUtil.getService(SalaryArchiveServiceImpl.class, user);
}
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
private SalarySysConfMapper getSalarySysConfMapper() {
return SqlProxyHandle.getProxy(SalarySysConfMapper.class);
}
private SalarySysConfService getSalarySysConfService(User user) {
return ServiceUtil.getService(SalarySysConfServiceImpl.class, user);
}
@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) {
SalaryAcctEmployeePO po = getSalaryAcctEmployeeMapper().getById(id);
SalaryI18nUtil.i18n(po);
return po;
}
@Override
public List<SalaryAcctEmployeePO> listByIds(Collection<Long> ids) {
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().ids(ids).build());
}
@Override
public List<SalaryAcctEmployeePO> listBySalaryAcctRecordId(Long salaryAcctRecordId) {
if (salaryAcctRecordId == null) {
return null;
}
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordId(salaryAcctRecordId).build());
}
@Override
public List<SalaryAcctEmployeePO> listBySalaryAcctRecordIds(Collection<Long> salaryAcctRecordIds) {
if (CollectionUtils.isEmpty(salaryAcctRecordIds)) {
return Collections.emptyList();
}
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();
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());
if (CollectionUtils.isNotEmpty(newSalaryAcctEmployeePOS)) {
batchSave(newSalaryAcctEmployeePOS);
}
}
@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();
}
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;
}
@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);
//排序配置
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
queryParam.setOrderRule(orderRule);
// 分页参数
// 查询薪资核算人员
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = getSalaryAcctEmployeeMapper().listPage(queryParam);
return SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(),
salaryAcctEmployeePOS, SalaryAcctEmployeePO.class);
}
@Override
public List<SalaryAcctEmployeePO> listByParam(SalaryAcctEmployeeQueryParam queryParam) {
// ValidUtil.doValidator(queryParam);
//排序配置
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
queryParam.setOrderRule(orderRule);
return getSalaryAcctEmployeeMapper().list(queryParam);
}
@Override
public PageInfo<SalaryAcctEmployeePO> listPageByResultQueryParam(SalaryAcctResultQueryParam queryParam) {
ValidUtil.doValidator(queryParam);
// 薪资核算人员的查询参数
SalaryAcctEmployeeQueryParam salaryAcctEmployeeQueryParam = new SalaryAcctEmployeeQueryParam();
BeanUtils.copyProperties(queryParam, salaryAcctEmployeeQueryParam);
// 查询薪资核算人员(分页)
// 如果需要筛选是否合并计税
if (StringUtils.isNotEmpty(queryParam.getConsolidatedTaxation()) && queryParam.getConsolidatedTaxation().equals("1")) {
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;
}
@Override
public PageInfo<SalaryAcctEmployeePO> listPageByParam4Reduce(SalaryAcctEmployeeQueryParam queryParam) {
// 查询薪资核算人员
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = listByParam4Reduce(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;
}
@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;
}
@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);
// 上个月的核算人员
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();
if (CollectionUtils.isNotEmpty(keySet)) {
lastMonthSalaryAcctEmployeePOMap.forEach((k, v) -> {
if (!keySet.contains(k)) {
resultList.add(v);
}
});
}
return resultList;
}
@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();
thisMonthSalaryAcctEmployeePOMap.forEach((k, v) -> {
if (!lastMonthSalaryAcctEmployeePOMap.containsKey(k)) {
resultList.add(v);
}
});
return resultList;
}
@Override
public PageInfo<SalaryAcctEmployeePO> listPageByParam4ConsolidatedTax(SalaryAcctEmployeeQueryParam queryParam) {
//排序配置
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
queryParam.setOrderRule(orderRule);
// 查询合并计税的其他薪资核算记录
List<SalaryAcctRecordPO> otherSalaryAcctRecordPOS = getSalaryAcctRecordService(user).listById4OtherConsolidatedTax(queryParam.getSalaryAcctRecordId());
if (CollectionUtils.isEmpty(otherSalaryAcctRecordPOS)) {
return new PageInfo<>();
}
// 查询合并计税的薪资核算人员
Set<Long> otherSalaryAcctRecordIds = SalaryEntityUtil.properties(otherSalaryAcctRecordPOS, SalaryAcctRecordPO::getId);
// 分页参数
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);
}
return SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(),
salaryAcctEmployeePOS, SalaryAcctEmployeePO.class);
}
@Override
public List<SalaryAcctEmployeePO> listByParam4ConsolidatedTax(SalaryAcctEmployeeQueryParam queryParam) {
//排序配置
OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
queryParam.setOrderRule(orderRule);
// 查询合并计税的其他薪资核算记录
List<SalaryAcctRecordPO> otherSalaryAcctRecordPOS = getSalaryAcctRecordService(user).listById4OtherConsolidatedTax(queryParam.getSalaryAcctRecordId());
if (CollectionUtils.isEmpty(otherSalaryAcctRecordPOS)) {
return Collections.emptyList();
}
// 查询合并计税的薪资核算人员
Set<Long> otherSalaryAcctRecordIds = SalaryEntityUtil.properties(otherSalaryAcctRecordPOS, SalaryAcctRecordPO::getId);
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;
}
return getSalaryAcctEmployeeMapper().list4ConsolidatedTax(otherSalaryAcctRecordIds, queryParam);
}
@Override
public void save(SalaryAcctEmployeeSaveParam saveParam) {
ValidUtil.doValidator(saveParam);
// 查询薪资核算记录
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, "人员已存在,请勿重复添加"));
}
// 根据薪资账套查询薪资周期
SalarySobCycleDTO salarySobCycleDTO = getSalarySobService(user).getSalarySobCycle(salaryAcctRecordPO.getSalarySobId(), SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth()));
//获取核算的扣缴义务人
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
if (Objects.isNull(salarySobPO)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98769, "薪资账套不存在或已被删除"));
}
Long taxAgentId = salarySobPO.getTaxAgentId();
// 查询薪资档案
List<SalaryArchiveDataDTO> salaryArchiveDataDTOS = getSalaryArchiveService(user).getSalaryArchiveTaxAgentData(salarySobCycleDTO.getSalaryCycle(), saveParam.getEmployeeIds(), taxAgentId);
// 转换成薪资核算人员po
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = SalaryAcctEmployeeBO.convert2EmployeePO(saveParam.getEmployeeIds(), salaryAcctRecordPO, salaryArchiveDataDTOS, (long) user.getUID());
//过滤不是扣缴义务人下的人员
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);
// 记录日志
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());
loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(0, "添加薪资核算人员"));
loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(0, "添加薪资核算人员") + ":" + targetName);
loggerContext.setNewValueList(salaryAcctEmployeePOS);
SalaryElogConfig.salaryAcctRecordLoggerTemplate.write(loggerContext);
}
@Override
public void batchSave(Collection<SalaryAcctEmployeePO> salaryAcctEmployeePOS) {
if (CollectionUtils.isEmpty(salaryAcctEmployeePOS)) {
return;
}
List<List<SalaryAcctEmployeePO>> partition = Lists.partition((List) salaryAcctEmployeePOS, 50);
partition.forEach(getSalaryAcctEmployeeMapper()::batchInsert);
}
@Override
public void deleteByIds(Collection<Long> ids) {
// 删除薪资核算人员
getSalaryAcctEmployeeMapper().deleteByIds(ids);
// 删除薪资核算人员对应的薪资核算结果
getSalaryAcctResultService(user).deleteBySalaryAcctEmployeeIds(ids);
// 删除报表
getSalaryAcctReportService(user).deleteBySalaryAcctEmpIds(ids);
// 删除薪资核算人员对应的校验异常明细
// salaryCheckResultDetailService.deleteBySalaryAcctEmployeeIds(ids);
// 删除薪资核算人员对应的线下对比结果
// salaryComparisonResultService.deleteBySalaryAcctRecordIds(ids);
}
@Override
public void deleteByParam(SalaryAcctEmployeeDeleteParam deleteParam) {
ValidUtil.doValidator(deleteParam);
// 查询薪资核算记录
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(deleteParam.getSalaryAcctRecordId());
if (Objects.isNull(salaryAcctRecordPO)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
}
// 回算不允许删除薪资核算人员
if (Objects.equals(salaryAcctRecordPO.getBackCalcStatus(), 1)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0, "正常薪资已经发放,薪资回算时,不允许再删除薪资核算人员"));
}
// 只有未归档时才能删除薪资核算人员
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);
// 查询薪资账套(记录日志用)
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
if (Objects.isNull(salarySobPO)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98769, "薪资账套不存在或已被删除"));
}
// 记录日志
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());
loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(0, "删除薪资核算人员"));
loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(0, "删除薪资核算人员") + ":" + targetName);
loggerContext.setOldValueList(salaryAcctEmployeePOS);
SalaryElogConfig.salaryAcctRecordLoggerTemplate.write(loggerContext);
}
@Override
public void deleteBySalaryAcctRecordIds(Collection<Long> salaryAcctRecordIds) {
getSalaryAcctEmployeeMapper().deleteBySalaryAcctRecordIds(salaryAcctRecordIds);
}
@Override
public void initBySalaryAcctRecord(SalaryAcctRecordPO salaryAcctRecordPO) {
// 根据薪资账套查询人员
List<DataCollectionEmployee> salaryEmployees = getSalaryEmployeeService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
if (CollectionUtils.isEmpty(salaryEmployees)) {
return;
}
// 根据薪资账套查询薪资周期
SalarySobCycleDTO salarySobCycleDTO = getSalarySobService(user).getSalarySobCycle(salaryAcctRecordPO.getSalarySobId(), SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth()));
// // 根据薪资账套的"核算人员范围"过滤入职日期大于薪资周期止的人员
// 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());
//查询账套对应的扣缴义务人
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
Long taxAgentId = salarySobPO.getTaxAgentId();
// //过滤扣税扣缴义务人不包含的人员
// Collection<Long> employeeIdsInTaxAgent = getTaxAgentService(user).listEmployeeIdsInTaxAgent(taxAgentId);
// salaryEmployees = salaryEmployees.stream().filter(salaryEmployee -> employeeIdsInTaxAgent.contains(salaryEmployee.getEmployeeId())).collect(Collectors.toList());
// 查询薪资档案,获取人员的个税扣缴义务人
List<Long> employeeIds = SalaryEntityUtil.properties(salaryEmployees, DataCollectionEmployee::getEmployeeId, Collectors.toList());
List<SalaryArchiveDataDTO> salaryArchiveDataDTOS = getSalaryArchiveService(user).getSalaryArchiveTaxAgentData(salarySobCycleDTO.getSalaryCycle(), employeeIds, taxAgentId);
// 转换成薪资核算人员po
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = SalaryAcctEmployeeBO.convert2Employee(salaryEmployees, salaryAcctRecordPO, salaryArchiveDataDTOS, (long) user.getUID());
//过滤掉不属于当前账套扣缴义务人的人员
salaryAcctEmployeePOS = salaryAcctEmployeePOS.stream().filter(po -> Objects.equals(taxAgentId, po.getTaxAgentId())).collect(Collectors.toList());
// 保存薪资核算人员
if (CollectionUtils.isNotEmpty(salaryAcctEmployeePOS)) {
batchSave(salaryAcctEmployeePOS);
}
}
@Override
public void refresh(Long salaryAcctRecordId) {
// 查询薪资核算人员
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = listBySalaryAcctRecordId(salaryAcctRecordId);
if (CollectionUtils.isEmpty(salaryAcctEmployeePOS)) {
return;
}
List<Long> employeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getEmployeeId, Collectors.toList());
// 查询薪资核算记录
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
if (Objects.isNull(salaryAcctRecordPO)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
}
//查询账套对应的扣缴义务人
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
//过滤掉不属于当前账套扣缴义务人的人员
Long taxAgentId = salarySobPO.getTaxAgentId();
// 查询薪资核算记录所用的帐套的薪资周期
SalarySobCycleDTO salarySobCycleDTO = getSalarySobService(user).getSalarySobCycle(salaryAcctRecordPO.getSalarySobId(), SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth()));
// 查询薪资档案,获取人员的个税扣缴义务人
List<SalaryArchiveDataDTO> salaryArchiveDataDTOS = getSalaryArchiveService(user).getSalaryArchiveTaxAgentData(salarySobCycleDTO.getSalaryCycle(), employeeIds, taxAgentId);
// 转换成薪资核算人员po
List<SalaryAcctEmployeePO> newSalaryAcctEmployeePOS = SalaryAcctEmployeeBO.convert2EmployeePO(employeeIds, salaryAcctRecordPO, salaryArchiveDataDTOS, (long) user.getUID());
newSalaryAcctEmployeePOS = newSalaryAcctEmployeePOS.stream().filter(po -> Objects.equals(taxAgentId, po.getTaxAgentId())).collect(Collectors.toList());
// 删除以前的薪资核算人员
getSalaryAcctEmployeeMapper().deleteBySalaryAcctRecordIds(Collections.singleton(salaryAcctRecordId));
// 插入新的薪资核算人员
if (CollectionUtils.isNotEmpty(newSalaryAcctEmployeePOS)) {
batchSave(newSalaryAcctEmployeePOS);
}
}
@Override
public List<SalaryAcctEmployeePO> listBySalaryStatisticsReportParam(SalaryStatisticsReportDataQueryParam param) {
SalaryAcctEmployeePO lambdaQueryChainWrapper = SalaryAcctEmployeePO.builder().build();
// 个税扣缴义务人
// 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());
}
if (CollectionUtils.isNotEmpty(param.getSalarySob())) {
lambdaQueryChainWrapper.setSalarySobIds(param.getSalarySob());
}
// 薪资所属月
Date startYearMonth = SalaryDateUtil.dateStrToLocalYearMonth(param.getSalaryStartMonth());
Date endYearMonth = SalaryDateUtil.dateStrToLocalYearMonth(param.getSalaryEndMonth());
if (Objects.nonNull(startYearMonth) && Objects.nonNull(endYearMonth)) {
Set<Date> yearMonths = Sets.newHashSet();
while (!startYearMonth.after(endYearMonth)) {
yearMonths.add(startYearMonth);
startYearMonth = DateUtil.offsetMonth(startYearMonth, 1);
}
lambdaQueryChainWrapper.setSalaryMonths(yearMonths);
}
// 收入所得项目
// if (CollectionUtils.isNotEmpty(param.getIncomeCategory())) {
// lambdaQueryChainWrapper.in(SalaryAcctEmployeePO::getIncomeCategory, param.getIncomeCategory().stream().map(Object::toString).collect(Collectors.toList()));
// }
//排除未归档数据
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;
}
if (CollectionUtils.isEmpty(list)) {
return Lists.newArrayList();
}
List<Long> employeeIds = list.stream().map(SalaryAcctEmployeePO::getEmployeeId).collect(Collectors.toList());
List<DataCollectionEmployee> employeeList = getSalaryEmployeeService(user).listByIds(employeeIds);
// 获取分部信息
List<Long> subCompanyIds = param.getSubCompany();
if (CollectionUtils.isNotEmpty(subCompanyIds)) {
// 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());
}
// 部门过滤
List<Long> depart = param.getDepart();
if (CollectionUtils.isNotEmpty(depart)) {
// 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());
}
// 职级过滤
// 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());
// }
// 人事状态过滤
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());
}
// 入职日期
if (CollectionUtils.isNotEmpty(param.getHiredate())) {
Set<Long> employeeIdsByHiredate = new HashSet<>();
employeeList.forEach(simpleEmployee -> {
Date hiredate = SalaryDateUtil.stringToDate(simpleEmployee.getCompanystartdate());
if (hiredate != null && !hiredate.before(param.getHiredate().get(0)) && !hiredate.after(param.getHiredate().get(1))) {
employeeIdsByHiredate.add(simpleEmployee.getEmployeeId());
}
});
if (CollectionUtils.isEmpty(employeeIdsByHiredate)) {
return Lists.newArrayList();
}
list = list.stream().filter(po -> employeeIdsByHiredate.contains(po.getEmployeeId())).collect(Collectors.toList());
}
// // 离职日期 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());
}
Set<Long> empIds = SalaryEntityUtil.properties(employeeList, DataCollectionEmployee::getEmployeeId);
list = list.stream().filter(po -> empIds.contains(po.getEmployeeId())).collect(Collectors.toList());
return list;
}
@Override
public List<SalaryAcctEmployeePO> listByTaxAgentAndSalaryMonth(List<Long> taxAgentIds, Set<Date> salaryMonths) {
return getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().taxAgentIds(taxAgentIds).salaryMonths(salaryMonths).build());
}
@Override
public void lockEmp(SalaryAcctResultUpdateLockStatusParam updateParam) {
// 查询薪资核算记录
SalaryAcctRecordPO salaryAcctRecord = getSalaryAcctRecordService(user).getById(updateParam.getSalaryAcctRecordId());
if (CollectionUtils.isEmpty(salaryAcctRecord.getLockSalaryItemIds())) {
salaryAcctRecord.setLockSalaryItemIds(new ArrayList<>());
}
List<SalaryAcctEmployeePO> salaryAcctEmployees = listBySalaryAcctRecordId(updateParam.getSalaryAcctRecordId());
if (CollectionUtils.isEmpty(salaryAcctEmployees)) {
return;
}
LockStatusEnum lockStatus = updateParam.getLockStatus();
if (lockStatus == null) {
throw new SalaryRunTimeException("锁定状态异常!");
}
Set<Long> acctEmpIds = updateParam.getAcctEmpIds();
Date now = new Date();
if (CollUtil.isNotEmpty(acctEmpIds)) {
//锁定指定人员
getSalaryAcctEmployeeMapper().lockByAcctEmpIds(lockStatus.getValue(), acctEmpIds, now);
// 宁波精华,需要更新支付方式的值
List<SalaryAcctEmployeePO> salaryAcctEmployeePOList = listByIds(acctEmpIds);
nbjhUpdateZffs(salaryAcctRecord, salaryAcctEmployeePOList, now, lockStatus.getValue());
} else {
//锁定全部
getSalaryAcctEmployeeMapper().lockByRecordId(lockStatus.getValue(), updateParam.getSalaryAcctRecordId(), now);
// 宁波精华,需要更新支付方式的值
nbjhUpdateZffs(salaryAcctRecord, salaryAcctEmployees, now, lockStatus.getValue());
}
}
private void nbjhUpdateZffs(SalaryAcctRecordPO salaryAcctRecord, List<SalaryAcctEmployeePO> salaryAcctEmployees, Date date, Integer lockStatus) {
BaseBean baseBean = new BaseBean();
// 获取是否是离职账套
List<Long> resignationSobIds = Arrays.asList(baseBean.getPropValue("nbjhSalary", "dimissionSobIds").split(","))
.stream()
.filter(NumberUtil::isNumber)
.map(Long::valueOf).collect(Collectors.toList());
if (resignationSobIds.contains(salaryAcctRecord.getSalarySobId())) {
// 获取支付方式id
Long zffs1ItemId = NumberUtils.isCreatable(baseBean.getPropValue("nbjhSalary", "sjjt_zffs1_item_id")) ? Long.valueOf(baseBean.getPropValue("nbjhSalary", "sjjt_zffs1_item_id")) : 0L;
String nowMonth = SalaryDateUtil.getFormatYearMonth(date);
String salaryMonth = SalaryDateUtil.getFormatYearMonth(salaryAcctRecord.getSalaryMonth());
String resultValue;
if (nowMonth.equals(salaryMonth)) {
resultValue = "上月已发";
} else {
resultValue = "本月已发";
}
// 先删除对应的结果
List<Long> salaryAcctEmpIds = salaryAcctEmployees.stream().map(SalaryAcctEmployeePO::getId).collect(Collectors.toList());
List<Long> salaryItemIds = new ArrayList<>();
salaryItemIds.add(zffs1ItemId);
getSalaryAcctResultService(user).deleteByAcctEmployeeIdsAndSalaryItemIds(salaryAcctEmpIds, salaryItemIds);
// 插入对应的支付方式结果
if (lockStatus.equals(LockStatusEnum.LOCK.getValue())) {
List<SalaryAcctResultPO> batchSaveList = salaryAcctEmployees.stream().map(acctEmp ->
SalaryAcctResultPO.builder()
.salaryAcctRecordId(salaryAcctRecord.getId())
.salarySobId(salaryAcctRecord.getSalarySobId())
.salaryAcctEmpId(acctEmp.getId())
.employeeId(acctEmp.getEmployeeId())
.taxAgentId(acctEmp.getTaxAgentId())
.salaryItemId(zffs1ItemId)
.resultValue(resultValue)
.creator((long) user.getUID())
.createTime(date)
.updateTime(date)
.deleteType(0)
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.build()
).collect(Collectors.toList());
getSalaryAcctResultService(user).batchSave(batchSaveList);
}
}
}
@Override
public void handleNbjhSalaryAcctEmp(Long salaryAcctRecordId) {
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
if (salaryAcctRecordPO == null) {
throw new SalaryRunTimeException("薪资核算记录不存在或已被删除!");
}
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
// 宁波精华二开 - 240814获取不需要发薪的人员
RecordSet rs = new RecordSet();
rs.execute("select xm from uf_lztz where sfsx = 1");
List<Long> notAcctEmpIds = new ArrayList<>();
while (rs.next()) {
int xm = rs.getInt("xm");
notAcctEmpIds.add(Long.valueOf(xm));
}
BaseBean baseBean = new BaseBean();
List<Long> resignationSobIds = Arrays.asList(baseBean.getPropValue("nbjhSalary", "dimissionSobIds").split(","))
.stream()
.filter(NumberUtil::isNumber)
.map(Long::valueOf).collect(Collectors.toList());
if (resignationSobIds.contains(salaryAcctRecordPO.getSalarySobId())) {
// 是离职账套
// 逻辑1进入离职账套的人员确认页面自动获取薪资档案中最后发薪日期为本月的人员若不在本月离职的人员确认中则自动加入。
// 获取最后发薪日期为本月的人员
LocalDateRange salaryCycle = SalarySobCycleBO.buildSalarySobCycle(salarySobPO, SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth())).getSalaryCycle();
List<SalaryArchivePO> salaryArchivePOList = getSalaryArchiveService(user).listByPayEndDate(salaryCycle.getFromDate(), salaryCycle.getEndDate());
// 过滤义务人
List<Long> thisMonthResigEmpIds = salaryArchivePOList.stream().filter(po -> po.getTaxAgentId().equals(salarySobPO.getTaxAgentId())).collect(Collectors.toList()).stream().map(SalaryArchivePO::getEmployeeId).collect(Collectors.toList());
// 获取本次核算中有哪些人
List<Long> salaryAcctEmployeeIds = getSalaryAcctEmployeeMapper()
.listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordId(salaryAcctRecordId).build())
.stream()
.map(SalaryAcctEmployeePO::getEmployeeId)
.collect(Collectors.toList());
// 过滤人员范围
List<Long> salaryEmployees = getSalaryEmployeeService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId()).stream().map(DataCollectionEmployee::getEmployeeId).collect(Collectors.toList());
List<Long> needAddEmpIds = thisMonthResigEmpIds.stream().filter(empId -> !salaryAcctEmployeeIds.contains(empId) && salaryEmployees.contains(empId)).collect(Collectors.toList());
// 过滤不需要算薪的人
needAddEmpIds = needAddEmpIds.stream().filter(empId -> !notAcctEmpIds.contains(empId)).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(needAddEmpIds)) {
List<DataCollectionEmployee> employeeList = getSalaryEmployeeService(user).listByIds(needAddEmpIds);
Map<Long, DataCollectionEmployee> empMap = SalaryEntityUtil.convert2Map(employeeList, DataCollectionEmployee::getEmployeeId);
Date now = new Date();
List<SalaryAcctEmployeePO> needInsertList = needAddEmpIds.stream().map(empId -> {
DataCollectionEmployee emp = empMap.getOrDefault(empId, DataCollectionEmployee.builder().build());
return SalaryAcctEmployeePO.builder()
.salaryAcctRecordId(salaryAcctRecordId)
.salarySobId(salarySobPO.getId())
.employeeId(empId)
.taxAgentId(salarySobPO.getTaxAgentId())
.salaryMonth(salaryAcctRecordPO.getSalaryMonth())
.creator(Long.valueOf(user.getUID()))
.createTime(now)
.updateTime(now)
.deleteType(0)
.employeeType(0)
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.subcompanyId(emp.getSubcompanyid())
.subcompanyName(emp.getSubcompanyName())
.departmentId(emp.getDepartmentId())
.departmentName(emp.getDepartmentName())
.jobtitleId(emp.getJobtitleId())
.jobtitleName(emp.getJobtitleName())
.jobcall(emp.getJobcall())
.jobcallId(emp.getJobcallId())
.status(emp.getStatus())
.build();
}).collect(Collectors.toList());
getSalaryAcctEmployeeMapper().batchInsert(needInsertList);
}
// 逻辑2、进离职账套的人员确认页面判断上月是否有已经归档的正常工资核算记录若存在已归档记录不做任何处理若不存在判断发薪起始日期是否在上月则将人员确认页面中的人员再全部加到上月的离职账套中去。
// 查询本次离职账套人员
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordId(salaryAcctRecordId).build());
// 获取正常账套上月是否已有归档的记录
List<Long> sobIds = Arrays.asList(baseBean.getPropValue("nbjhSalary", "needDeleteSobIds").split(","))
.stream()
.filter(NumberUtil::isNumber)
.map(Long::valueOf).collect(Collectors.toList());
sobIds = getSalarySobService(user).listByIds(sobIds).stream().filter(sob -> sob.getTaxAgentId().equals(salarySobPO.getTaxAgentId())).map(SalarySobPO::getId).collect(Collectors.toList());
salaryCycle = SalarySobCycleBO.buildSalarySobCycle(salarySobPO, SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth()).minusMonths(1)).getSalaryCycle();
List<SalaryAcctRecordPO> salaryAcctRecordPOS = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(sobIds, salaryCycle);
List<Long> archivedRecordIdList = salaryAcctRecordPOS.stream()
.filter(record -> record.getStatus() > 1)
.map(SalaryAcctRecordPO::getId)
.collect(Collectors.toList());
List<Long> archivedEmpIds = new ArrayList<>();
if (CollectionUtils.isNotEmpty(archivedRecordIdList)) {
archivedEmpIds.addAll( getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordIds(archivedRecordIdList).build())
.stream()
.map(SalaryAcctEmployeePO::getEmployeeId)
.collect(Collectors.toList()));
}
// 过滤出上月没有归档记录的人员,加到上个月的离职账套中去。
List<Long> needHandleEmpIds = salaryAcctEmployeePOS.stream().filter(acctEmp -> !archivedEmpIds.contains(acctEmp.getEmployeeId()))
.map(SalaryAcctEmployeePO::getEmployeeId)
.collect(Collectors.toList());
// 过滤不需要算薪的人
needHandleEmpIds = needHandleEmpIds.stream().filter(empId -> !notAcctEmpIds.contains(empId)).collect(Collectors.toList());
// 获取这些人的薪资档案,判断起始发薪日期是否早于或等于上月
if (CollectionUtils.isNotEmpty(needHandleEmpIds)) {
List<SalaryArchivePO> needHandleArchiveIds = getSalaryArchiveService(user).listSome(SalaryArchivePO.builder().employeeIds(needHandleEmpIds).taxAgentId(salarySobPO.getTaxAgentId()).build());
LocalDateRange finalSalaryCycle = salaryCycle;
needHandleArchiveIds = needHandleArchiveIds.stream().filter(archive -> !archive.getPayStartDate().after(finalSalaryCycle.getEndDate())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(needHandleArchiveIds)) {
// 获取上个月的离职记录
List<SalaryAcctRecordPO> lastMonthResigRecords = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(Collections.singletonList(salaryAcctRecordPO.getSalarySobId()), salaryCycle);
if (CollectionUtils.isNotEmpty(lastMonthResigRecords)) {
Long lastMonthRecordId = lastMonthResigRecords.get(0).getId();
Long lastMonthSalarySobId = lastMonthResigRecords.get(0).getSalarySobId();
// 获取上月离职中已有数据
List<Long> lastMonthExistsEmp = getSalaryAcctEmployeeMapper().listSome(SalaryAcctEmployeePO.builder().salaryAcctRecordId(lastMonthRecordId).build())
.stream()
.map(SalaryAcctEmployeePO::getEmployeeId)
.collect(Collectors.toList());
needHandleArchiveIds = needHandleArchiveIds.stream().filter(archive -> !lastMonthExistsEmp.contains(archive.getEmployeeId())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(needHandleArchiveIds)) {
Date now = new Date();
List<Long> empIds = needHandleArchiveIds.stream().map(SalaryArchivePO::getEmployeeId).collect(Collectors.toList());
List<DataCollectionEmployee> employeeList = getSalaryEmployeeService(user).listByIds(empIds);
Map<Long, DataCollectionEmployee> empMap = SalaryEntityUtil.convert2Map(employeeList, DataCollectionEmployee::getEmployeeId);
List<SalaryAcctEmployeePO> needInsertList = needHandleArchiveIds.stream().map(archiveId -> {
DataCollectionEmployee emp = empMap.getOrDefault(archiveId.getEmployeeId(), DataCollectionEmployee.builder().build());
return SalaryAcctEmployeePO.builder()
.salaryAcctRecordId(lastMonthRecordId)
.salarySobId(lastMonthSalarySobId)
.employeeId(archiveId.getEmployeeId())
.taxAgentId(salarySobPO.getTaxAgentId())
.salaryMonth(finalSalaryCycle.getFromDate())
.creator(Long.valueOf(user.getUID()))
.createTime(now)
.updateTime(now)
.deleteType(0)
.employeeType(0)
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.subcompanyId(emp.getSubcompanyid())
.subcompanyName(emp.getSubcompanyName())
.departmentId(emp.getDepartmentId())
.departmentName(emp.getDepartmentName())
.jobtitleId(emp.getJobtitleId())
.jobtitleName(emp.getJobtitleName())
.jobcall(emp.getJobcall())
.jobcallId(emp.getJobcallId())
.status(emp.getStatus())
.build();
}).collect(Collectors.toList());
getSalaryAcctEmployeeMapper().batchInsert(needInsertList);
}
}
}
}
}
// 删除本次核算记录中不需要算薪的人
if (salaryAcctRecordPO.getStatus().equals(SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue())) {
List<SalaryAcctEmployeePO> salaryAcctEmployeePOList = listBySalaryAcctRecordId(salaryAcctRecordId);
List<Long> needDeleteAcctEmpIds = salaryAcctEmployeePOList.stream()
.filter(acctEmp -> notAcctEmpIds.contains(acctEmp.getEmployeeId()))
.map(SalaryAcctEmployeePO::getId)
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(needDeleteAcctEmpIds)) {
deleteByIds(needDeleteAcctEmpIds);
}
}
}
@Override
public void deleteResignationEmp(Long salaryAcctRecordId) {
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
if (salaryAcctRecordPO == null) {
throw new SalaryRunTimeException("薪资核算记录不存在或已被删除!");
}
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
BaseBean baseBean = new BaseBean();
List<Long> needDeleteSobIds = Arrays.asList(baseBean.getPropValue("nbjhSalary", "needDeleteSobIds").split(","))
.stream()
.filter(NumberUtil::isNumber)
.map(Long::valueOf).collect(Collectors.toList());
if (needDeleteSobIds.contains(salaryAcctRecordPO.getSalarySobId())) {
List<Long> resignationSobIds = Arrays.asList(baseBean.getPropValue("nbjhSalary", "dimissionSobIds").split(","))
.stream()
.filter(NumberUtil::isNumber)
.map(Long::valueOf).collect(Collectors.toList());
// TODO 是否需要限制与当前账套在同一个个税扣缴义务人下
resignationSobIds = getSalarySobService(user).listByIds(resignationSobIds).stream()
.filter(sob -> sob.getTaxAgentId().equals(salarySobPO.getTaxAgentId()))
.map(SalarySobPO::getId)
.collect(Collectors.toList());
// 获取本月离职账套中的薪资核算记录
LocalDateRange dateRange = new LocalDateRange(salaryAcctRecordPO.getSalaryMonth(), salaryAcctRecordPO.getSalaryMonth());
List<SalaryAcctRecordPO> salaryAcctRecordPOS = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(resignationSobIds, dateRange);
List<Long> resignationAcctRecordIds = SalaryEntityUtil.properties(salaryAcctRecordPOS, SalaryAcctRecordPO::getId, Collectors.toList());
// 获取离职账套中本月所包含的人员
List<SalaryAcctEmployeePO> resignationAcctEmployeeList = listBySalaryAcctRecordIds(resignationAcctRecordIds);
List<Long> empIdList = resignationAcctEmployeeList.stream().map(SalaryAcctEmployeePO::getEmployeeId).collect(Collectors.toList());
// 从本次核算中删除离职人员
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = listBySalaryAcctRecordIdAndEmployeeIds(salaryAcctRecordId, empIdList);
List<Long> salaryAcctEmpIds = salaryAcctEmployeePOS.stream().map(SalaryAcctEmployeePO::getId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(salaryAcctEmpIds)) {
deleteByIds(salaryAcctEmpIds);
// 从薪资核算结果中删除
getSalaryAcctResultService(user).deleteBySalaryAcctEmployeeIds(salaryAcctEmpIds);
}
}
}
}