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; import com.engine.salary.entity.taxagent.po.TaxAgentPO; import com.engine.salary.enums.AccountTypeEnum; import com.engine.salary.enums.UserStatusEnum; 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; import org.apache.commons.lang3.math.NumberUtils; import weaver.general.Util; import java.util.*; import java.util.stream.Collectors; /** * 薪资核算人员 *

Copyright: Copyright (c) 2022

*

Company: 泛微软件

* * @author qiantao * @version 1.0 **/ public class SalaryAcctEmployeeBO { /** * 将薪资核算人员po转换成薪资核算人员列表dto * * @param salaryAccountingEmployees * @param taxAgents * @param simpleEmployees * @return */ public static List convert2EmployeeListDTO(List salaryAccountingEmployees, List taxAgents, List simpleEmployees) { if (CollectionUtils.isEmpty(salaryAccountingEmployees)) { return Collections.emptyList(); } Map taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgents, TaxAgentPO::getId, TaxAgentPO::getName); Map 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)) .departmentId(e.getDepartmentId()) .departmentName(e.getDepartmentName()) .status(UserStatusEnum.getDefaultLabelByValue(NumberUtils.toInt(e.getStatus()))) .accountType(AccountTypeEnum.getDefaultLabelByValue(e.getAccountType())) .mobile(simpleEmployee.getMobile()) .jobNum(simpleEmployee.getWorkcode()) .hireDate(simpleEmployee.getCompanystartdate()) .dismissDate(simpleEmployee.getDismissdate()) .build(); }).collect(Collectors.toList()); } public static List convert2Employee(Collection employee, SalaryAcctRecordPO salaryAcctRecord, List salaryArchiveTaxAgentData, Long employeeId) { if (CollectionUtils.isEmpty(employee)) { return Collections.emptyList(); } List resultList = Lists.newArrayList(); Map>> empIdKeyTaxAgentMap = SalaryEntityUtil.group2Map(salaryArchiveTaxAgentData, SalaryArchiveDataDTO::getEmployeeId, SalaryArchiveDataDTO::getTaxAgents); Date now = new Date(); for (DataCollectionEmployee emp : employee) { Set taxAgentIds = Sets.newHashSet(); Set> taxAgentSet = empIdKeyTaxAgentMap.getOrDefault(emp.getEmployeeId(), Collections.emptySet()); for (List 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) // .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()) .creator(employeeId) .createTime(now) .updateTime(now) .deleteType(0) .tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY) .build(); resultList.add(salaryAcctEmployee); } } return resultList; } /** * 核算人员信息替换实时信息 * @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()); simpleEmployee.setAccountType(acctEmployeePO.getAccountType()); simpleEmployee.setAccountTypeName(AccountTypeEnum.getDefaultLabelByValue(acctEmployeePO.getAccountType())); } public static List> partitionByEmployeeId(List salaryAcctEmployees) { if (CollectionUtils.isEmpty(salaryAcctEmployees)) { return Collections.emptyList(); } List employeeIdList = salaryAcctEmployees.stream() .map(SalaryAcctEmployeePO::getEmployeeId) .distinct() .collect(Collectors.toList()); // 每个线程处理多少个人员(一个线程最多处理10个人员) int size = 100; List> partition = Lists.partition(employeeIdList, size); List> resultList = new ArrayList<>(); Map> salaryAcctEmployeeMap = SalaryEntityUtil.group2Map(salaryAcctEmployees, SalaryAcctEmployeePO::getEmployeeId); for (List employeeIds : partition) { List temp = new ArrayList<>(); for (Long employeeId : employeeIds) { temp.addAll(salaryAcctEmployeeMap.getOrDefault(employeeId, Collections.emptyList())); } resultList.add(temp); } return resultList; } }