diff --git a/src/com/engine/salary/mapper/archive/SalaryArchiveMapper.java b/src/com/engine/salary/mapper/archive/SalaryArchiveMapper.java index c25f47e55..79f7dcf30 100644 --- a/src/com/engine/salary/mapper/archive/SalaryArchiveMapper.java +++ b/src/com/engine/salary/mapper/archive/SalaryArchiveMapper.java @@ -133,4 +133,6 @@ public interface SalaryArchiveMapper { void deleteByIds(@Param("ids")Collection deleteIds); List listPayEndDateIsNull(@Param("ids")List employeeIds); + + List listPayStartDateIsNull(@Param("runStatus")String runStatus); } \ No newline at end of file diff --git a/src/com/engine/salary/mapper/archive/SalaryArchiveMapper.xml b/src/com/engine/salary/mapper/archive/SalaryArchiveMapper.xml index c08dd87e2..0ad41c310 100644 --- a/src/com/engine/salary/mapper/archive/SalaryArchiveMapper.xml +++ b/src/com/engine/salary/mapper/archive/SalaryArchiveMapper.xml @@ -722,6 +722,15 @@ + + UPDATE hrsa_salary_archive diff --git a/src/com/engine/salary/mapper/siarchives/InsuranceBaseInfoMapper.java b/src/com/engine/salary/mapper/siarchives/InsuranceBaseInfoMapper.java index 80e9c5e2e..898d55471 100644 --- a/src/com/engine/salary/mapper/siarchives/InsuranceBaseInfoMapper.java +++ b/src/com/engine/salary/mapper/siarchives/InsuranceBaseInfoMapper.java @@ -127,4 +127,11 @@ public interface InsuranceBaseInfoMapper { * @return */ List listEndDateIsNull(@Param("employeeIds") List employeeIds); + + /** + * 获取没有设置社保、公积金最后缴纳月的档案 + * @param employeeIds + * @return + */ + List listStartDateIsNull(@Param("employeeIds") List employeeIds); } diff --git a/src/com/engine/salary/mapper/siarchives/InsuranceBaseInfoMapper.xml b/src/com/engine/salary/mapper/siarchives/InsuranceBaseInfoMapper.xml index 467dbf9f2..33ceb8af1 100644 --- a/src/com/engine/salary/mapper/siarchives/InsuranceBaseInfoMapper.xml +++ b/src/com/engine/salary/mapper/siarchives/InsuranceBaseInfoMapper.xml @@ -301,6 +301,38 @@ + + + UPDATE hrsa_insurance_base_info diff --git a/src/com/engine/salary/service/SIArchivesService.java b/src/com/engine/salary/service/SIArchivesService.java index 4f98cc742..877355676 100644 --- a/src/com/engine/salary/service/SIArchivesService.java +++ b/src/com/engine/salary/service/SIArchivesService.java @@ -7,11 +7,11 @@ import com.engine.salary.entity.siarchives.param.InsuranceArchivesSaveParam; import com.engine.salary.entity.siarchives.param.SIArchiveBaseHistoryListParam; import com.engine.salary.entity.siarchives.po.*; import com.engine.salary.util.page.PageInfo; +import com.google.common.collect.Lists; +import org.apache.commons.collections4.CollectionUtils; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @Author weaver_cl @@ -152,4 +152,12 @@ public interface SIArchivesService { void batchInsertAdjustHistory(List adjustHistoryList); List listEndDateIsNull(List employeeIds); + + List listStartDateIsNull(List employeeIds); + + List listInsuranceArchivesSocialSchemeByIds(List ids); + + List listInsuranceArchivesFundSchemeByIds(List ids); + + List listInsuranceArchivesOtherSchemeByIds(List ids); } diff --git a/src/com/engine/salary/service/SalaryArchiveService.java b/src/com/engine/salary/service/SalaryArchiveService.java index 60a059bae..5ab2dac29 100644 --- a/src/com/engine/salary/service/SalaryArchiveService.java +++ b/src/com/engine/salary/service/SalaryArchiveService.java @@ -250,4 +250,10 @@ public interface SalaryArchiveService { */ String syncPayStartDate(); + /** + * 根据列表状态获取起始发薪日期为空的薪资档案 + * @param runStatus + * @return + */ + List listPayStartDateIsNull(String runStatus); } diff --git a/src/com/engine/salary/service/impl/SIArchivesServiceImpl.java b/src/com/engine/salary/service/impl/SIArchivesServiceImpl.java index 9dd1e070f..811127514 100644 --- a/src/com/engine/salary/service/impl/SIArchivesServiceImpl.java +++ b/src/com/engine/salary/service/impl/SIArchivesServiceImpl.java @@ -3954,5 +3954,48 @@ public class SIArchivesServiceImpl extends Service implements SIArchivesService } return getInsuranceBaseInfoMapper().listEndDateIsNull(employeeIds); } + + /** + * 获取没有设置社保、公积金最后缴纳月的档案 + * @param employeeIds + * @return + */ + @Override + public List listStartDateIsNull(List employeeIds) { + return getInsuranceBaseInfoMapper().listStartDateIsNull(employeeIds); + } /*****以上代码为SIArchivesBiz中方法逻辑迁移,旨在减少Biz类的使用*****/ + + @Override + public List listInsuranceArchivesSocialSchemeByIds(List ids) { + if (CollectionUtils.isEmpty(ids)) { + return Collections.emptyList(); + } + List> partition = Lists.partition(ids, 1000); + ArrayList resultList = new ArrayList<>(); + partition.forEach(list -> resultList.addAll(getSocialSchemeMapper().getSocialById(list))); + return resultList; + } + + @Override + public List listInsuranceArchivesFundSchemeByIds(List ids) { + if (CollectionUtils.isEmpty(ids)) { + return Collections.emptyList(); + } + List> partition = Lists.partition(ids, 1000); + ArrayList resultList = new ArrayList<>(); + partition.forEach(list -> resultList.addAll(getFundSchemeMapper().getFundById(list))); + return resultList; + } + + @Override + public List listInsuranceArchivesOtherSchemeByIds(List ids) { + if (CollectionUtils.isEmpty(ids)) { + return Collections.emptyList(); + } + List> partition = Lists.partition(ids, 1000); + ArrayList resultList = new ArrayList<>(); + partition.forEach(list -> resultList.addAll(getOtherSchemeMapper().getOtherById(list))); + return resultList; + } } diff --git a/src/com/engine/salary/service/impl/SalaryArchiveServiceImpl.java b/src/com/engine/salary/service/impl/SalaryArchiveServiceImpl.java index b5958e8bf..e492cbd16 100644 --- a/src/com/engine/salary/service/impl/SalaryArchiveServiceImpl.java +++ b/src/com/engine/salary/service/impl/SalaryArchiveServiceImpl.java @@ -1419,4 +1419,12 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe salaryArchiveMapper.batchUpdate(archives); return "执行完毕"; } + + @Override + public List listPayStartDateIsNull(String runStatus) { + if (StringUtils.isBlank(runStatus)) { + return Collections.emptyList(); + } + return getSalaryArchiveMapper().listPayStartDateIsNull(runStatus); + } } diff --git a/src/com/engine/salary/timer/AutoSyncEmpArchiveStartDateJob.java b/src/com/engine/salary/timer/AutoSyncEmpArchiveStartDateJob.java new file mode 100644 index 000000000..1b4c32c84 --- /dev/null +++ b/src/com/engine/salary/timer/AutoSyncEmpArchiveStartDateJob.java @@ -0,0 +1,159 @@ +package com.engine.salary.timer; + +import com.engine.common.util.ServiceUtil; +import com.engine.salary.biz.SalaryArchiveBiz; +import com.engine.salary.entity.datacollection.DataCollectionEmployee; +import com.engine.salary.entity.salaryarchive.po.SalaryArchivePO; +import com.engine.salary.entity.siarchives.po.InsuranceArchivesBaseInfoPO; +import com.engine.salary.entity.siarchives.po.InsuranceArchivesFundSchemePO; +import com.engine.salary.entity.siarchives.po.InsuranceArchivesOtherSchemePO; +import com.engine.salary.entity.siarchives.po.InsuranceArchivesSocialSchemePO; +import com.engine.salary.enums.salaryarchive.SalaryArchiveListTypeEnum; +import com.engine.salary.enums.siaccount.EmployeeStatusEnum; +import com.engine.salary.mapper.siarchives.FundSchemeMapper; +import com.engine.salary.mapper.siarchives.OtherSchemeMapper; +import com.engine.salary.mapper.siarchives.SocialSchemeMapper; +import com.engine.salary.service.SIArchivesService; +import com.engine.salary.service.SalaryArchiveService; +import com.engine.salary.service.SalaryEmployeeService; +import com.engine.salary.service.impl.SIArchivesServiceImpl; +import com.engine.salary.service.impl.SalaryArchiveServiceImpl; +import com.engine.salary.service.impl.SalaryEmployeeServiceImpl; +import com.engine.salary.util.SalaryDateUtil; +import com.engine.salary.util.SalaryEntityUtil; +import com.engine.salary.util.db.MapperProxyFactory; +import org.apache.commons.lang3.StringUtils; +import weaver.hrm.User; +import weaver.interfaces.schedule.BaseCronJob; + +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author Harryxzy + * @ClassName AutoSyncInsuranceArchiveJob + * @date 2023/08/14 9:30 + * @description 自动同步人员社保福利档案、薪资档案为公司开始日期字段(companystartdate) + */ +public class AutoSyncEmpArchiveStartDateJob extends BaseCronJob { + + private SalaryArchiveService getSalaryArchiveService(User user) { + return ServiceUtil.getService(SalaryArchiveServiceImpl.class,user); + } + + private SalaryEmployeeService getSalaryEmployeeService(User user) { + return ServiceUtil.getService(SalaryEmployeeServiceImpl.class,user); + } + + + private SIArchivesService getSIArchivesService(User user) { + return ServiceUtil.getService(SIArchivesServiceImpl.class,user); + } + + private String syncInsuranceArchive; + + private String syncSalaryArchive; + + private SalaryArchiveBiz getSalaryArchiveMapper = new SalaryArchiveBiz(); + + private SocialSchemeMapper getSocialSchemeMapper() { + return MapperProxyFactory.getProxy(SocialSchemeMapper.class); + } + + private FundSchemeMapper getFundSchemeMapper() { + return MapperProxyFactory.getProxy(FundSchemeMapper.class); + } + + private OtherSchemeMapper getOtherSchemeMapper() { + return MapperProxyFactory.getProxy(OtherSchemeMapper.class); + } + + + + @Override + public void execute() { + User user = new User(); + user.setUid(1); + user.setLoginid("sysadmin"); + + if (StringUtils.isBlank(syncInsuranceArchive) || !StringUtils.equals(syncInsuranceArchive,"false")) { + // 同步社保福利档案 + // 获取社保、公积金、其他福利中起始缴纳月任意一个为空的社保档案主表po + List needSyncInsuranceBaseInfoList = getSIArchivesService(user).listStartDateIsNull(Collections.emptyList()); + // 过滤出档案状态为待增员的 + needSyncInsuranceBaseInfoList = needSyncInsuranceBaseInfoList.stream().filter(po -> po.getRunStatus().equals(EmployeeStatusEnum.STAY_ADD.getValue())).collect(Collectors.toList()); + // 获取同步人员的公司开始日期 + List employeeList = getSalaryEmployeeService(user).listByIds(SalaryEntityUtil.properties(needSyncInsuranceBaseInfoList, InsuranceArchivesBaseInfoPO::getEmployeeId, Collectors.toList())); + Map empInfoMap = SalaryEntityUtil.convert2Map(employeeList, DataCollectionEmployee::getEmployeeId, emp -> { + if (StringUtils.isBlank(emp.getCompanystartdate()) || !SalaryDateUtil.checkDay(emp.getCompanystartdate())) { + return ""; + } else { + return StringUtils.substring(emp.getCompanystartdate(), 0, 7); + } + }); + // 设置社保起始缴纳月信息 + List needSyncSocialArchiveIds = SalaryEntityUtil.properties(needSyncInsuranceBaseInfoList, InsuranceArchivesBaseInfoPO::getSocialArchivesId, Collectors.toList()); + List insuranceArchivesSocialSchemePOS = getSIArchivesService(user).listInsuranceArchivesSocialSchemeByIds(needSyncSocialArchiveIds); + insuranceArchivesSocialSchemePOS.stream().forEach(po -> { + if (StringUtils.isBlank(po.getSocialStartTime()) && StringUtils.isNotBlank(empInfoMap.get(po.getEmployeeId()))) { + po.setSocialStartTime(empInfoMap.get(po.getEmployeeId())); + getSocialSchemeMapper().updateById(po); + } + }); + + // 设置公积金起始缴纳月信息 + List needSyncFundArchiveIds = SalaryEntityUtil.properties(needSyncInsuranceBaseInfoList, InsuranceArchivesBaseInfoPO::getFundArchivesId, Collectors.toList()); + List insuranceArchivesFundSchemePOS = getSIArchivesService(user).listInsuranceArchivesFundSchemeByIds(needSyncFundArchiveIds); + insuranceArchivesFundSchemePOS.stream().forEach(po -> { + if (StringUtils.isBlank(po.getFundStartTime()) && StringUtils.isNotBlank(empInfoMap.get(po.getEmployeeId()))) { + po.setFundStartTime(empInfoMap.get(po.getEmployeeId())); + getFundSchemeMapper().updateById(po); + } + }); + + // 设置其他福利起始缴纳月信息 + List needSyncOtherArchiveIds = SalaryEntityUtil.properties(needSyncInsuranceBaseInfoList, InsuranceArchivesBaseInfoPO::getOtherArchivesId, Collectors.toList()); + List insuranceArchivesOtherSchemePOS = getSIArchivesService(user).listInsuranceArchivesOtherSchemeByIds(needSyncOtherArchiveIds); + insuranceArchivesOtherSchemePOS.stream().forEach(po -> { + if (StringUtils.isBlank(po.getOtherStartTime()) && StringUtils.isNotBlank(empInfoMap.get(po.getEmployeeId()))) { + po.setOtherStartTime(empInfoMap.get(po.getEmployeeId())); + getOtherSchemeMapper().updateById(po); + } + }); + } + + if (StringUtils.isBlank(syncSalaryArchive) || !StringUtils.equals(syncSalaryArchive,"false")) { + // 同步薪资档案 + // 获取薪资档案起始发薪日为空且是待定薪资的档案 + List salaryArchiveList = getSalaryArchiveService(user).listPayStartDateIsNull(SalaryArchiveListTypeEnum.PENDING.getValue()); + List empIds = SalaryEntityUtil.properties(salaryArchiveList, SalaryArchivePO::getEmployeeId, Collectors.toList()); + List employeeList = getSalaryEmployeeService(user).listByIds(empIds); + Map empMap = SalaryEntityUtil.convert2Map(employeeList, DataCollectionEmployee::getEmployeeId, emp -> { + if (StringUtils.isBlank(emp.getCompanystartdate()) || !SalaryDateUtil.checkDay(emp.getCompanystartdate())) { + return null; + } else { + return SalaryDateUtil.stringToDate(StringUtils.substring(emp.getCompanystartdate(), 0, 10)); + } + }); + List needUpdateArchiveList = salaryArchiveList.stream().filter(archive -> { + if (archive.getPayStartDate() == null) { + Date startDate = empMap.get(archive.getEmployeeId()); + if (startDate != null) { + archive.setPayStartDate(startDate); + return true; + } else { + return false; + } + } else { + return false; + } + }).collect(Collectors.toList()); + getSalaryArchiveMapper.batchUpdate(needUpdateArchiveList); + } + + } + +}