|
|
|
|
@ -4923,6 +4923,15 @@ public class SIAccountServiceImpl extends Service implements SIAccountService {
|
|
|
|
|
validIds.addAll(emp2);
|
|
|
|
|
validIds.addAll(emp3);
|
|
|
|
|
|
|
|
|
|
if (!param.isFlag()) {
|
|
|
|
|
// 不是首次创建核算 还需要添加历史核算人员
|
|
|
|
|
List<InsuranceAccountDetailPO> insuranceAccountDetailPOS = getInsuranceAccountDetailMapper().selectList(param.getBillMonth(), param.getPaymentOrganization());
|
|
|
|
|
List<Long> historyEmpIds = insuranceAccountDetailPOS.stream().filter(po -> po.getPaymentStatus().equals(PaymentStatusEnum.COMMON.getValue())).map(InsuranceAccountDetailPO::getEmployeeId).collect(Collectors.toList());
|
|
|
|
|
validIds.addAll(historyEmpIds);
|
|
|
|
|
List<Long> finalEmpIds = empIds;
|
|
|
|
|
empIds.addAll(historyEmpIds.stream().filter(empId -> !finalEmpIds.contains(empId)).collect(Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Long> finalValidIds = validIds.stream().distinct().collect(Collectors.toList());
|
|
|
|
|
ids = empIds.stream().filter(finalValidIds::contains).collect(Collectors.toList());
|
|
|
|
|
} else {
|
|
|
|
|
@ -4980,14 +4989,11 @@ public class SIAccountServiceImpl extends Service implements SIAccountService {
|
|
|
|
|
Map<Long, InsuranceArchivesAccountPO> insuranceArchivesAccountPOS = getSIArchivesService(user).buildBatchAccount(ids, paymentOrganization);
|
|
|
|
|
List<InsuranceAccountDetailPO> historyDetailData = new ArrayList<>();
|
|
|
|
|
List<DataCollectionEmployee> employeeList = getSalaryEmployeeService(user).listByIds(ids);
|
|
|
|
|
if (!isFirstFlag) {
|
|
|
|
|
// 不是首次核算,需要把社保历史数据取出
|
|
|
|
|
List<List<Long>> partition = Lists.partition(ids, 100);
|
|
|
|
|
partition.forEach(part -> {
|
|
|
|
|
historyDetailData.addAll(getInsuranceAccountDetailMapper().list(InsuranceAccountDetailParam.builder().billMonth(billMonth).paymentOrganization(paymentOrganization.toString()).employeeIds(part).build()));
|
|
|
|
|
historyDetailData.addAll(getInsuranceAccountDetailMapper().extList(InsuranceAccountDetailParam.builder().billMonth(billMonth).paymentOrganization(paymentOrganization.toString()).employeeIds(part).build()));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
List<List<Long>> partition = Lists.partition(ids, 100);
|
|
|
|
|
partition.forEach(part -> {
|
|
|
|
|
historyDetailData.addAll(getInsuranceAccountDetailMapper().list(InsuranceAccountDetailParam.builder().billMonth(billMonth).paymentOrganization(paymentOrganization.toString()).employeeIds(part).build()));
|
|
|
|
|
historyDetailData.addAll(getInsuranceAccountDetailMapper().extList(InsuranceAccountDetailParam.builder().billMonth(billMonth).paymentOrganization(paymentOrganization.toString()).employeeIds(part).build()));
|
|
|
|
|
});
|
|
|
|
|
Map<Long, InsuranceAccountDetailPO> historyDetailDataMap = SalaryEntityUtil.convert2Map(historyDetailData, InsuranceAccountDetailPO::getEmployeeId);
|
|
|
|
|
Map<Long, DataCollectionEmployee> employeeMap = SalaryEntityUtil.convert2Map(employeeList, DataCollectionEmployee::getEmployeeId);
|
|
|
|
|
|
|
|
|
|
@ -5063,14 +5069,18 @@ public class SIAccountServiceImpl extends Service implements SIAccountService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//临时表入库前先对(可能存在的)历史数据进行删除
|
|
|
|
|
// List<List<Long>> partition = Lists.partition((List<Long>) ids, 100);
|
|
|
|
|
// partition.forEach(part -> {
|
|
|
|
|
// getSIAccountDetailTempMapper().batchDelByEmpIdsAndMonthAndPayOrg(part, billMonth, paymentOrganization);
|
|
|
|
|
// });
|
|
|
|
|
// 根据人员id删,会少删不再参与社保核算的人。
|
|
|
|
|
getSIAccountDetailTempMapper().batchDelByMonthAndPayOrg(billMonth, paymentOrganization);
|
|
|
|
|
partition.forEach(part -> {
|
|
|
|
|
getSIAccountDetailTempMapper().batchDelByEmpIdsAndMonthAndPayOrg(part, billMonth, paymentOrganization);
|
|
|
|
|
});
|
|
|
|
|
// // 根据人员id删,会少删不再参与社保核算的人。
|
|
|
|
|
// getSIAccountDetailTempMapper().batchDelByMonthAndPayOrg(billMonth, paymentOrganization);
|
|
|
|
|
//临时表数据入库
|
|
|
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
|
|
|
if (!isFirstFlag) {
|
|
|
|
|
// 点击台账内的核算按钮,核算人员不变(不增加人)
|
|
|
|
|
List<String> existDataKey = historyDetailData.stream().map(po -> po.getPaymentOrganization() + "_" + po.getEmployeeId()).collect(Collectors.toList());
|
|
|
|
|
list = list.stream().filter(po -> existDataKey.contains(po.getPaymentOrganization() + "_" + po.getEmployeeId())).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
encryptUtil.encryptList(list, InsuranceAccountDetailTempPO.class);
|
|
|
|
|
List<List<InsuranceAccountDetailTempPO>> lists = splitList(list, 20);
|
|
|
|
|
lists.forEach(subList -> {
|
|
|
|
|
@ -6795,4 +6805,188 @@ public class SIAccountServiceImpl extends Service implements SIAccountService {
|
|
|
|
|
|
|
|
|
|
/*****以上代码为SIAccountBiz中方法逻辑迁移,旨在减少Biz类的使用*****/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 正常缴纳页 删除社保核算人员
|
|
|
|
|
* @param param
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteSocialAcctEmp(SaveCommonAccountParam param) {
|
|
|
|
|
if (StringUtils.isBlank(param.getBillMonth()) || param.getPaymentOrganization() == null) {
|
|
|
|
|
throw new SalaryRunTimeException("参数错误");
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isEmpty(param.getIds())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<InsuranceAccountDetailPO> insuranceAccountDetailPOS = getInsuranceAccountDetailMapper().selectList(param.getBillMonth(), param.getPaymentOrganization());
|
|
|
|
|
insuranceAccountDetailPOS = insuranceAccountDetailPOS.stream().filter(detailPO -> param.getIds().contains(detailPO.getId())).collect(Collectors.toList());
|
|
|
|
|
List<Long> deleteEmployeeIds = insuranceAccountDetailPOS.stream().map(InsuranceAccountDetailPO::getEmployeeId).collect(Collectors.toList());
|
|
|
|
|
deleteAccountDetailsByEmpIds(deleteEmployeeIds, param.getBillMonth(), param.getPaymentOrganization());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(deleteEmployeeIds)) {
|
|
|
|
|
// 重新计算合计值
|
|
|
|
|
updateBatchAccount((AccountParam.builder().billMonth(param.getBillMonth()).paymentOrganization(param.getPaymentOrganization())).build());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void deleteAccountDetailsByEmpIds(List<Long> deleteEmployeeIds, String billMonth, Long paymentOrganization) {
|
|
|
|
|
if (CollectionUtils.isNotEmpty(deleteEmployeeIds)) {
|
|
|
|
|
List<List<Long>> partition = Lists.partition(deleteEmployeeIds, 100);
|
|
|
|
|
partition.forEach(part -> {
|
|
|
|
|
// 删除该台账下,员工的所有数据
|
|
|
|
|
getInsuranceAccountDetailMapper().deleteByEmpIds(part, billMonth, paymentOrganization);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 正常缴纳页 添加社保核算人员
|
|
|
|
|
* @param param
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String addSocialAcctEmp(SaveCommonAccountParam param) {
|
|
|
|
|
if (StringUtils.isBlank(param.getBillMonth()) || param.getPaymentOrganization() == null) {
|
|
|
|
|
throw new SalaryRunTimeException("参数错误");
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isEmpty(param.getIncludes())) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
InsuranceAccountBatchPO insuranceAccountBatchPO = getInsuranceAccountBatchMapper().getByBillMonth(param.getBillMonth(), param.getPaymentOrganization());
|
|
|
|
|
if (insuranceAccountBatchPO == null) {
|
|
|
|
|
throw new SalaryRunTimeException("台账不存在或已被删除");
|
|
|
|
|
}
|
|
|
|
|
// 校验是否可以添加这些员工
|
|
|
|
|
List<Long> empIds = param.getIncludes();
|
|
|
|
|
List<Long> validIds = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 获取当前台账已经存在的人员
|
|
|
|
|
List<InsuranceAccountDetailPO> insuranceAccountDetailPOS = getInsuranceAccountDetailMapper().queryNormalListByBillMonth(param.getBillMonth(), param.getPaymentOrganization());
|
|
|
|
|
List<Long> existEmpIds = insuranceAccountDetailPOS.stream().map(InsuranceAccountDetailPO::getEmployeeId).collect(Collectors.toList());
|
|
|
|
|
Optional<Long> existOptional = empIds.stream().filter(existEmpIds::contains).findFirst();
|
|
|
|
|
if (existOptional.isPresent()) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(101581, "人员已存在,请勿重复添加"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//过滤出需要核算的人员,即福利档案基础信息表中runStatus为正在缴纳和待减员的人员
|
|
|
|
|
List<InsuranceArchivesBaseInfoPO> baseInfoPOList = getInsuranceBaseInfoMapper().listByEmployeeIds(empIds);
|
|
|
|
|
List<Long> canAccountIds = baseInfoPOList.stream()
|
|
|
|
|
.filter(f->f.getPaymentOrganization().equals(param.getPaymentOrganization()))
|
|
|
|
|
.map(InsuranceArchivesBaseInfoPO::getEmployeeId)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
//20231122逻辑优化,过滤出不在起始缴纳月和最后缴纳月区间的人员
|
|
|
|
|
List<Long> empIdsInPayMonthRange = listCanPayEmpIds(param.getPaymentOrganization(), param.getBillMonth());
|
|
|
|
|
empIds = empIds.stream().filter(f->canAccountIds.contains(f) && empIdsInPayMonthRange.contains(f)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
List<InsuranceArchivesSocialSchemePO> socials = getSIArchivesService(user).getSocialByEmployeeIds(empIds);
|
|
|
|
|
//过滤出目标个税扣缴义务人相关信息
|
|
|
|
|
socials = socials.stream().filter(f -> f.getPaymentOrganization().equals(param.getPaymentOrganization())).collect(Collectors.toList());
|
|
|
|
|
List<Long> emp1 = socials.stream()
|
|
|
|
|
.filter(s -> !(StringUtils.isBlank(s.getSocialEndTime()) && StringUtils.isBlank(s.getSocialStartTime())) &&
|
|
|
|
|
(StringUtils.isBlank(s.getSocialEndTime()) || (SalaryDateUtil.stringToDate(s.getSocialEndTime() + "-01") != null && !SalaryDateUtil.stringToDate(param.getBillMonth() + "-01").after(SalaryDateUtil.stringToDate(s.getSocialEndTime() + "-01")))) )
|
|
|
|
|
.map(InsuranceArchivesSocialSchemePO::getEmployeeId)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
List<InsuranceArchivesFundSchemePO> funds = getSIArchivesService(user).getFundByEmployeeIds(empIds);
|
|
|
|
|
//过滤出目标个税扣缴义务人相关信息
|
|
|
|
|
funds = funds.stream().filter(f -> f.getPaymentOrganization().equals(param.getPaymentOrganization())).collect(Collectors.toList());
|
|
|
|
|
List<Long> emp2 = funds.stream()
|
|
|
|
|
.filter(s -> !(StringUtils.isBlank(s.getFundStartTime()) && StringUtils.isBlank(s.getFundEndTime())) &&
|
|
|
|
|
(StringUtils.isBlank(s.getFundEndTime()) || (SalaryDateUtil.stringToDate(s.getFundEndTime() + "-01") != null && !SalaryDateUtil.stringToDate(param.getBillMonth() + "-01").after(SalaryDateUtil.stringToDate(s.getFundEndTime() + "-01")))))
|
|
|
|
|
.map(InsuranceArchivesFundSchemePO::getEmployeeId)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
List<InsuranceArchivesOtherSchemePO> others = getSIArchivesService(user).getOtherByEmployeeIds(empIds);
|
|
|
|
|
//过滤出目标个税扣缴义务人相关信息
|
|
|
|
|
others = others.stream().filter(f -> f.getPaymentOrganization().equals(param.getPaymentOrganization())).collect(Collectors.toList());
|
|
|
|
|
List<Long> emp3 = others.stream()
|
|
|
|
|
.filter(s -> !(StringUtils.isBlank(s.getOtherStartTime()) && StringUtils.isBlank(s.getOtherEndTime())) &&
|
|
|
|
|
(StringUtils.isBlank(s.getOtherEndTime()) || (SalaryDateUtil.stringToDate(s.getOtherEndTime() + "-01") != null && !SalaryDateUtil.stringToDate(param.getBillMonth() + "-01").after(SalaryDateUtil.stringToDate(s.getOtherEndTime() + "-01")))))
|
|
|
|
|
.map(InsuranceArchivesOtherSchemePO::getEmployeeId)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
validIds.addAll(emp1);
|
|
|
|
|
validIds.addAll(emp2);
|
|
|
|
|
validIds.addAll(emp3);
|
|
|
|
|
List<Long> finalValidIds = validIds.stream().distinct().collect(Collectors.toList());
|
|
|
|
|
List<Long> conNotAddEmpIds = param.getIncludes().stream().filter(empId -> !finalValidIds.contains(empId)).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(conNotAddEmpIds)) {
|
|
|
|
|
String canNotAddName = getSalaryEmployeeService(user).listByIds(conNotAddEmpIds).stream().map(DataCollectionEmployee::getUsername).collect(Collectors.joining(","));
|
|
|
|
|
throw new SalaryRunTimeException("添加失败,员工:" +canNotAddName + ",社保、公积金、其他福利需至少有一种在当前账单月需缴纳,并且社保档案需为在缴员工");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addCommonEmpAndAccount(param.getBillMonth(), empIds, param.getPaymentOrganization());
|
|
|
|
|
return "success";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加正常缴纳人员,并核算
|
|
|
|
|
* @param billMonth
|
|
|
|
|
* @param ids
|
|
|
|
|
* @param paymentOrganization
|
|
|
|
|
*/
|
|
|
|
|
public void addCommonEmpAndAccount(String billMonth, List<Long> ids, Long paymentOrganization) {
|
|
|
|
|
Map<Long, InsuranceArchivesAccountPO> insuranceArchivesAccountPOS = getSIArchivesService(user).buildBatchAccount(ids, paymentOrganization);
|
|
|
|
|
List<DataCollectionEmployee> employeeList = getSalaryEmployeeService(user).listByIds(ids);
|
|
|
|
|
Map<Long, DataCollectionEmployee> employeeMap = SalaryEntityUtil.convert2Map(employeeList, DataCollectionEmployee::getEmployeeId);
|
|
|
|
|
|
|
|
|
|
List<InsuranceAccountDetailTempPO> list = new ArrayList<>();
|
|
|
|
|
for (Map.Entry<Long, InsuranceArchivesAccountPO> entry : insuranceArchivesAccountPOS.entrySet()) {
|
|
|
|
|
Long k = entry.getKey();
|
|
|
|
|
InsuranceArchivesAccountPO v = entry.getValue();
|
|
|
|
|
InsuranceAccountDetailPO insuranceAccountDetailPO = new InsuranceAccountDetailPO();
|
|
|
|
|
insuranceAccountDetailPO.setBillMonth(billMonth);
|
|
|
|
|
insuranceAccountDetailPO.setBillStatus(BillStatusEnum.NOT_ARCHIVED.getValue());
|
|
|
|
|
insuranceAccountDetailPO.setCreator((long) user.getUID());
|
|
|
|
|
insuranceAccountDetailPO.setCreateTime(new Date());
|
|
|
|
|
insuranceAccountDetailPO.setDeleteType(DeleteTypeEnum.NOT_DELETED.getValue());
|
|
|
|
|
insuranceAccountDetailPO.setEmployeeId(k);
|
|
|
|
|
insuranceAccountDetailPO.setUpdateTime(new Date());
|
|
|
|
|
insuranceAccountDetailPO.setPaymentStatus(PaymentStatusEnum.COMMON.getValue());
|
|
|
|
|
insuranceAccountDetailPO.setResourceFrom(ResourceFromEnum.SYSTEM.getValue());
|
|
|
|
|
insuranceAccountDetailPO.setTenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY);
|
|
|
|
|
insuranceAccountDetailPO.setPaymentOrganization(paymentOrganization);
|
|
|
|
|
|
|
|
|
|
DataCollectionEmployee employee = employeeMap.get(k);
|
|
|
|
|
if (employee != null) {
|
|
|
|
|
insuranceAccountDetailPO.setSubcompanyName(employee.getSubcompanyName());
|
|
|
|
|
insuranceAccountDetailPO.setSubcompanyId(employee.getSubcompanyid());
|
|
|
|
|
insuranceAccountDetailPO.setDepartmentName(employee.getDepartmentName());
|
|
|
|
|
insuranceAccountDetailPO.setDepartmentId(employee.getDepartmentId());
|
|
|
|
|
insuranceAccountDetailPO.setJobtitleName(employee.getJobtitleName());
|
|
|
|
|
insuranceAccountDetailPO.setJobtitleId(employee.getJobtitleId());
|
|
|
|
|
insuranceAccountDetailPO.setJobcall(employee.getJobcall());
|
|
|
|
|
insuranceAccountDetailPO.setJobcallId(employee.getJobcallId());
|
|
|
|
|
insuranceAccountDetailPO.setStatus(employee.getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//核算社保
|
|
|
|
|
accountSocial(insuranceAccountDetailPO, v, billMonth);
|
|
|
|
|
//核算公积金
|
|
|
|
|
accountFund(insuranceAccountDetailPO, v, billMonth);
|
|
|
|
|
//核算其他福利
|
|
|
|
|
accountOther(insuranceAccountDetailPO, v, billMonth);
|
|
|
|
|
//计算合计
|
|
|
|
|
account(insuranceAccountDetailPO);
|
|
|
|
|
//临时表PO
|
|
|
|
|
InsuranceAccountDetailTempPO insuranceAccountDetailTempPO = new InsuranceAccountDetailTempPO();
|
|
|
|
|
BeanUtils.copyProperties(insuranceAccountDetailPO, insuranceAccountDetailTempPO);
|
|
|
|
|
list.add(insuranceAccountDetailTempPO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 入库
|
|
|
|
|
//生成bill_detail入库数据
|
|
|
|
|
List<InsuranceAccountDetailPO> collect = list.stream().map(item -> {
|
|
|
|
|
InsuranceAccountDetailPO insuranceAccountDetailPO = new InsuranceAccountDetailPO();
|
|
|
|
|
BeanUtils.copyProperties(item, insuranceAccountDetailPO);
|
|
|
|
|
return insuranceAccountDetailPO;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
|
|
encryptUtil.encryptList(collect, InsuranceAccountDetailPO.class);
|
|
|
|
|
List<List<InsuranceAccountDetailPO>> lists = splitDetailList(collect, 20);
|
|
|
|
|
lists.forEach(subList -> {
|
|
|
|
|
getInsuranceAccountDetailMapper().batchSaveAccountDetails(subList);
|
|
|
|
|
});
|
|
|
|
|
updateBatchAccount((AccountParam.builder().billMonth(billMonth).paymentOrganization(paymentOrganization)).build());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|