Merge branch 'feature/250301_社保福利台账增减人员' into release/3.0.1.2503.01

This commit is contained in:
Harryxzy 2025-03-13 16:59:11 +08:00
commit d0ec44c7b1
7 changed files with 290 additions and 14 deletions

View File

@ -192,4 +192,12 @@ public interface InsuranceAccountDetailMapper {
* 获取补差数据(账单月份+人员id+个税扣缴义务人)
*/
List<InsuranceAccountDetailPO> queryBalanceList(InsuranceAccountDetailPO po);
/**
* 根据id删除
* @param ids
*/
void deleteByIds(@Param("ids")List<Long> ids);
void deleteByEmpIds(@Param("employeeIds")List<Long> deleteEmployeeIds, @Param("billMonth") String billMonth, @Param("paymentOrganization") Long paymentOrganization);
}

View File

@ -553,6 +553,7 @@
<select id="selectList" resultMap="BaseResultMap">
SELECT
t.id,
t.employee_id,t.social_sum,t.fund_sum,t.other_sum,t.fund_pay_org,t.social_pay_org,
t.other_pay_org, t.payment_status
FROM
@ -1563,6 +1564,29 @@
AND employee_id = #{employeeId}
</delete>
<delete id="deleteByIds">
UPDATE hrsa_bill_detail
SET delete_type = 1
WHERE delete_type = 0
<if test="ids != null and ids.size()>0">
AND id IN
<foreach collection="ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
</delete>
<delete id="deleteByEmpIds">
UPDATE hrsa_bill_detail
SET delete_type = 1
WHERE delete_type = 0
AND bill_month = #{billMonth}
AND payment_organization = #{paymentOrganization}
AND employee_id in
<foreach collection="employeeIds" open="(" item="employeeId" separator="," close=")">
#{employeeId}
</foreach>
</delete>
<select id="getOneByBpep" resultMap="BaseResultMap">
SELECT
t.id,t.employee_id,t.social_per_json,t.social_com_json,

View File

@ -20,6 +20,8 @@ public interface InsuranceBaseInfoMapper {
*/
List<InsuranceArchivesBaseInfoPO> listAll();
List<InsuranceArchivesBaseInfoPO> listByEmployeeIds(@Param("employeeIds")Collection<Long> employeeIds);
/**
* 查询对应id集合的记录
*

View File

@ -43,6 +43,18 @@
WHERE delete_type = 0
</select>
<select id="listByEmployeeIds"
resultType="com.engine.salary.entity.siarchives.po.InsuranceArchivesBaseInfoPO">
SELECT
<include refid="baseColumns"/>
FROM hrsa_insurance_base_info t
WHERE delete_type = 0
AND employee_id IN
<foreach collection="employeeIds" open="(" item="employeeId" separator="," close=")">
#{employeeId}
</foreach>
</select>
<!-- 查询对应id的数据 -->
<select id="listByIds" resultMap="BaseResultMap">
SELECT

View File

@ -320,5 +320,9 @@ public interface SIAccountService {
void cacheWelfareField(List<String> welfareNames);
void cacheBalanceWelfareField(List<String> welfareNames);
void deleteSocialAcctEmp(SaveCommonAccountParam param);
String addSocialAcctEmp(SaveCommonAccountParam param);
}

View File

@ -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()));
});
}
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());
}
}
}

View File

@ -243,6 +243,38 @@ public class SIAccountController {
}
}
/**
* 正常缴纳页 删除社保核算人员
* @param request
* @param response
* @param param
* @return
*/
@POST
@Path("/deleteSocialAcctEmp")
@Produces(MediaType.APPLICATION_JSON)
public String deleteSocialAcctEmp(@Context HttpServletRequest request, @Context HttpServletResponse response,
@RequestBody SaveCommonAccountParam param) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<SaveCommonAccountParam, String>(user).run(getService(user)::deleteSocialAcctEmp, param);
}
/**
* 正常缴纳页 添加社保核算人员
* @param request
* @param response
* @param param
* @return
*/
@POST
@Path("/addSocialAcctEmp")
@Produces(MediaType.APPLICATION_JSON)
public String addSocialAcctEmp(@Context HttpServletRequest request, @Context HttpServletResponse response,
@RequestBody SaveCommonAccountParam param) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<SaveCommonAccountParam, String>(user).run(getService(user)::addSocialAcctEmp, param);
}
/**
* 删除月份表单