weaver-hrm-salary/src/com/engine/salary/entity/salaryacct/bo/SalaryAcctEmployeeBO.java

172 lines
9.1 KiB
Java
Raw Normal View History

2022-04-07 16:54:10 +08:00
package com.engine.salary.entity.salaryacct.bo;
import com.engine.salary.constant.SalaryDefaultTenantConstant;
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import com.engine.salary.entity.salaryacct.dto.SalaryAccEmployeeListDTO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
import com.engine.salary.entity.salaryarchive.dto.SalaryArchiveDataDTO;
import com.engine.salary.entity.salaryarchive.dto.SalaryArchiveTaxAgentDataDTO;
2022-05-31 16:41:11 +08:00
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
2024-10-16 15:25:48 +08:00
import com.engine.salary.enums.AccountTypeEnum;
2022-04-28 17:44:26 +08:00
import com.engine.salary.enums.UserStatusEnum;
2022-04-07 16:54:10 +08:00
import com.engine.salary.util.SalaryEntityUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
2022-04-28 17:44:26 +08:00
import org.apache.commons.lang3.math.NumberUtils;
2024-06-18 15:28:31 +08:00
import weaver.general.Util;
2022-04-07 16:54:10 +08:00
import java.util.*;
import java.util.stream.Collectors;
/**
* 薪资核算人员
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
public class SalaryAcctEmployeeBO {
/**
* 将薪资核算人员po转换成薪资核算人员列表dto
*
* @param salaryAccountingEmployees
* @param taxAgents
* @param simpleEmployees
* @return
*/
public static List<SalaryAccEmployeeListDTO> convert2EmployeeListDTO(List<SalaryAcctEmployeePO> salaryAccountingEmployees,
2022-05-31 16:41:11 +08:00
List<TaxAgentPO> taxAgents,
2022-04-07 16:54:10 +08:00
List<DataCollectionEmployee> simpleEmployees) {
if (CollectionUtils.isEmpty(salaryAccountingEmployees)) {
return Collections.emptyList();
}
2022-05-31 16:41:11 +08:00
Map<Long, String> taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgents, TaxAgentPO::getId, TaxAgentPO::getName);
2022-04-07 16:54:10 +08:00
Map<Long, DataCollectionEmployee> simpleEmployeeMap = SalaryEntityUtil.convert2Map(simpleEmployees, DataCollectionEmployee::getEmployeeId);
return salaryAccountingEmployees.stream()
.map(e -> {
DataCollectionEmployee simpleEmployee = simpleEmployeeMap.get(e.getEmployeeId());
if (simpleEmployee == null) {
return SalaryAccEmployeeListDTO.builder()
.id(e.getId())
.employeeId(e.getId())
.taxAgentId(e.getTaxAgentId())
.taxAgentName(taxAgentNameMap.getOrDefault(e.getTaxAgentId(), StringUtils.EMPTY))
.build();
}
return SalaryAccEmployeeListDTO.builder()
.id(e.getId())
.employeeId(simpleEmployee.getEmployeeId())
.employeeName(simpleEmployee.getUsername())
.taxAgentId(e.getTaxAgentId())
.taxAgentName(taxAgentNameMap.getOrDefault(e.getTaxAgentId(), StringUtils.EMPTY))
2024-09-25 11:45:36 +08:00
.departmentId(e.getDepartmentId())
.departmentName(e.getDepartmentName())
.status(UserStatusEnum.getDefaultLabelByValue(NumberUtils.toInt(e.getStatus())))
2024-10-16 15:25:48 +08:00
.accountType(AccountTypeEnum.getDefaultLabelByValue(e.getAccountType()))
2022-04-07 16:54:10 +08:00
.mobile(simpleEmployee.getMobile())
.jobNum(simpleEmployee.getWorkcode())
2022-04-28 10:05:27 +08:00
.hireDate(simpleEmployee.getCompanystartdate())
2022-05-05 10:35:58 +08:00
.dismissDate(simpleEmployee.getDismissdate())
2022-04-07 16:54:10 +08:00
.build();
}).collect(Collectors.toList());
}
2023-03-15 18:03:46 +08:00
public static List<SalaryAcctEmployeePO> convert2Employee(Collection<DataCollectionEmployee> employee,
2024-06-18 15:28:31 +08:00
SalaryAcctRecordPO salaryAcctRecord,
List<SalaryArchiveDataDTO> salaryArchiveTaxAgentData,
Long employeeId) {
2023-03-15 18:03:46 +08:00
if (CollectionUtils.isEmpty(employee)) {
return Collections.emptyList();
}
List<SalaryAcctEmployeePO> resultList = Lists.newArrayList();
Map<Long, Set<List<SalaryArchiveTaxAgentDataDTO>>> empIdKeyTaxAgentMap = SalaryEntityUtil.group2Map(salaryArchiveTaxAgentData, SalaryArchiveDataDTO::getEmployeeId, SalaryArchiveDataDTO::getTaxAgents);
Date now = new Date();
for (DataCollectionEmployee emp : employee) {
Set<Long> taxAgentIds = Sets.newHashSet();
Set<List<SalaryArchiveTaxAgentDataDTO>> taxAgentSet = empIdKeyTaxAgentMap.getOrDefault(emp.getEmployeeId(), Collections.emptySet());
for (List<SalaryArchiveTaxAgentDataDTO> taxAgents : taxAgentSet) {
taxAgentIds.addAll(SalaryEntityUtil.properties(taxAgents, SalaryArchiveTaxAgentDataDTO::getTaxAgentId));
}
if (CollectionUtils.isEmpty(taxAgentIds)) {
taxAgentIds.add(0L);
}
for (Long taxAgentId : taxAgentIds) {
SalaryAcctEmployeePO salaryAcctEmployee = SalaryAcctEmployeePO.builder()
.salaryAcctRecordId(salaryAcctRecord.getId())
.salarySobId(salaryAcctRecord.getSalarySobId())
.salaryMonth(salaryAcctRecord.getSalaryMonth())
.employeeId(emp.getEmployeeId())
.employeeType(emp.isExtEmp() ? 1 : 0)
.taxAgentId(taxAgentId)
2024-12-06 16:00:05 +08:00
// .departmentId(emp.getDepartmentId())
// .departmentName(emp.getDepartmentName())
// .jobcall(emp.getJobcall())
// .jobcallId(emp.getJobcallId())
// .jobtitleId(emp.getJobtitleId())
// .jobtitleName(emp.getJobtitleName())
// .subcompanyId(emp.getSubcompanyid())
// .subcompanyName(emp.getSubcompanyName())
// .status(emp.getStatus())
// .accountType(emp.getAccountType())
2023-03-15 18:03:46 +08:00
.creator(employeeId)
.createTime(now)
.updateTime(now)
.deleteType(0)
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.build();
resultList.add(salaryAcctEmployee);
}
}
return resultList;
}
2024-06-18 15:28:31 +08:00
/**
* 核算人员信息替换实时信息
* @param simpleEmployee
* @param acctEmployeePO
*/
public static void copyAcctEmp(DataCollectionEmployee simpleEmployee, SalaryAcctEmployeePO acctEmployeePO) {
simpleEmployee.setDepartmentId(acctEmployeePO.getDepartmentId());
simpleEmployee.setDepartmentName(acctEmployeePO.getDepartmentName());
simpleEmployee.setSubcompanyid(acctEmployeePO.getSubcompanyId());
simpleEmployee.setSubcompanyName(acctEmployeePO.getSubcompanyName());
simpleEmployee.setJobcallId(acctEmployeePO.getJobcallId());
simpleEmployee.setJobcall(acctEmployeePO.getJobcall());
simpleEmployee.setJobtitleId(acctEmployeePO.getJobtitleId());
simpleEmployee.setJobtitleName(acctEmployeePO.getJobtitleName());
simpleEmployee.setStatusName(UserStatusEnum.getDefaultLabelByValue(new Integer(Util.null2s(acctEmployeePO.getStatus(), "1"))));
simpleEmployee.setStatus(acctEmployeePO.getStatus());
2024-10-16 15:25:48 +08:00
simpleEmployee.setAccountType(acctEmployeePO.getAccountType());
simpleEmployee.setAccountTypeName(AccountTypeEnum.getDefaultLabelByValue(acctEmployeePO.getAccountType()));
2024-06-18 15:28:31 +08:00
}
2022-11-23 18:30:53 +08:00
public static List<List<SalaryAcctEmployeePO>> partitionByEmployeeId(List<SalaryAcctEmployeePO> salaryAcctEmployees) {
if (CollectionUtils.isEmpty(salaryAcctEmployees)) {
return Collections.emptyList();
}
List<Long> employeeIdList = salaryAcctEmployees.stream()
.map(SalaryAcctEmployeePO::getEmployeeId)
.distinct()
.collect(Collectors.toList());
// 每个线程处理多少个人员一个线程最多处理10个人员
int size = 100;
List<List<Long>> partition = Lists.partition(employeeIdList, size);
List<List<SalaryAcctEmployeePO>> resultList = new ArrayList<>();
Map<Long, List<SalaryAcctEmployeePO>> salaryAcctEmployeeMap = SalaryEntityUtil.group2Map(salaryAcctEmployees, SalaryAcctEmployeePO::getEmployeeId);
for (List<Long> employeeIds : partition) {
List<SalaryAcctEmployeePO> temp = new ArrayList<>();
for (Long employeeId : employeeIds) {
temp.addAll(salaryAcctEmployeeMap.getOrDefault(employeeId, Collections.emptyList()));
}
resultList.add(temp);
}
return resultList;
}
2022-04-07 16:54:10 +08:00
}