273 lines
12 KiB
Java
273 lines
12 KiB
Java
package com.engine.salary.service.impl;
|
||
|
||
import com.api.formmode.mybatis.util.SqlProxyHandle;
|
||
import com.engine.common.util.ServiceUtil;
|
||
import com.engine.core.impl.Service;
|
||
import com.engine.salary.biz.EmployBiz;
|
||
import com.engine.salary.entity.SalarySobExtRangePO;
|
||
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
||
import com.engine.salary.entity.hrm.DeptInfo;
|
||
import com.engine.salary.entity.hrm.PositionInfo;
|
||
import com.engine.salary.entity.hrm.SubCompanyInfo;
|
||
import com.engine.salary.entity.salarysob.bo.SalarySobRangeBO;
|
||
import com.engine.salary.entity.salarysob.param.SalarySobRangeEmpQueryParam;
|
||
import com.engine.salary.entity.salarysob.po.SalarySobRangePO;
|
||
import com.engine.salary.enums.UserStatusEnum;
|
||
import com.engine.salary.enums.datacollection.UseEmployeeTypeEnum;
|
||
import com.engine.salary.mapper.datacollection.EmployMapper;
|
||
import com.engine.salary.mapper.sys.SalarySysConfMapper;
|
||
import com.engine.salary.service.ExtEmpService;
|
||
import com.engine.salary.service.SalaryEmployeeService;
|
||
import com.engine.salary.service.SalarySobExtRangeService;
|
||
import com.engine.salary.service.SalarySobRangeService;
|
||
import com.engine.salary.sys.entity.po.SalarySysConfPO;
|
||
import com.engine.salary.util.SalaryEntityUtil;
|
||
import com.engine.salary.util.db.MapperProxyFactory;
|
||
import com.google.common.collect.Lists;
|
||
import org.apache.commons.collections4.CollectionUtils;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.apache.commons.lang3.math.NumberUtils;
|
||
import weaver.hrm.User;
|
||
|
||
import java.util.*;
|
||
import java.util.stream.Collectors;
|
||
|
||
/**
|
||
* 人员信息
|
||
* <p>Copyright: Copyright (c) 2022</p>
|
||
* <p>Company: 泛微软件</p>
|
||
*
|
||
* @author qiantao
|
||
* @version 1.0
|
||
**/
|
||
public class SalaryEmployeeServiceImpl extends Service implements SalaryEmployeeService {
|
||
|
||
private EmployBiz employBiz = new EmployBiz();
|
||
|
||
private SalarySobRangeService getSalarySobRangeService(User user) {
|
||
return ServiceUtil.getService(SalarySobRangeServiceImpl.class, user);
|
||
}
|
||
|
||
private EmployMapper getEmployMapper() {
|
||
return MapperProxyFactory.getProxy(EmployMapper.class);
|
||
}
|
||
|
||
private SalarySysConfMapper getSalarySysConfMapper() {
|
||
return SqlProxyHandle.getProxy(SalarySysConfMapper.class);
|
||
}
|
||
|
||
|
||
private ExtEmpService getExtEmpService(User user) {
|
||
return ServiceUtil.getService(ExtEmpServiceImpl.class, user);
|
||
}
|
||
|
||
|
||
private SalarySobExtRangeService getSalarySobExtRangeService(User user) {
|
||
return ServiceUtil.getService(SalarySobExtRangeServiceImpl.class, user);
|
||
}
|
||
|
||
boolean openExtEmp = true;
|
||
|
||
@Override
|
||
public List<DataCollectionEmployee> listAll(UseEmployeeTypeEnum empType) {
|
||
List<DataCollectionEmployee> result = new ArrayList<>();
|
||
if (empType == UseEmployeeTypeEnum.ORG) {
|
||
result = employBiz.listAll();
|
||
}
|
||
if (empType == UseEmployeeTypeEnum.EXT) {
|
||
result = getExtEmpService(user).listEmployee();
|
||
}
|
||
if (empType == UseEmployeeTypeEnum.ALL) {
|
||
result.addAll(employBiz.listAll());
|
||
result.addAll(getExtEmpService(user).listEmployee());
|
||
}
|
||
return result;
|
||
}
|
||
|
||
@Override
|
||
public List<DataCollectionEmployee> listAllForReport() {
|
||
List<DataCollectionEmployee> result = employBiz.listAllForReport();
|
||
if (openExtEmp) {
|
||
result.addAll(getExtEmpService(user).listAllForReport());
|
||
}
|
||
return result;
|
||
}
|
||
|
||
@Override
|
||
public List<DataCollectionEmployee> listBySalarySobId(Long salarySobId) {
|
||
|
||
List<DataCollectionEmployee> includeSalaryEmployees = new ArrayList<>();
|
||
|
||
// 查询薪资账套的人员范围
|
||
List<SalarySobRangePO> includeSalarySobRangePOS = getSalarySobRangeService(user).listBySalarySobIdAndIncludeType(salarySobId, NumberUtils.INTEGER_ONE);
|
||
if (CollectionUtils.isNotEmpty(includeSalarySobRangePOS)) {
|
||
// 将薪资账套的人员范围转换成人员查询参数
|
||
List<SalarySobRangeEmpQueryParam> includeQueryParams = SalarySobRangeBO.convert2EmployeeQueryParam(includeSalarySobRangePOS);
|
||
// 根据上一步的查询参数查询人员
|
||
includeSalaryEmployees = listByParams(includeQueryParams);
|
||
if (CollectionUtils.isEmpty(includeSalaryEmployees)) {
|
||
return Collections.emptyList();
|
||
}
|
||
//去重
|
||
includeSalaryEmployees = includeSalaryEmployees.stream().distinct().collect(Collectors.toList());
|
||
// 查询薪资账套的人员范围(从范围中排除)
|
||
List<SalarySobRangePO> excludeSalarySobRangePOS = getSalarySobRangeService(user).listBySalarySobIdAndIncludeType(salarySobId, NumberUtils.INTEGER_ZERO);
|
||
if (CollectionUtils.isNotEmpty(excludeSalarySobRangePOS)) {
|
||
// 将薪资账套的人员范围转换成人员查询参数
|
||
List<SalarySobRangeEmpQueryParam> excludeQueryParams = SalarySobRangeBO.convert2EmployeeQueryParam(excludeSalarySobRangePOS);
|
||
// 根据上一步的查询参数查询人员
|
||
List<DataCollectionEmployee> excludeSalaryEmployees = listByParams(excludeQueryParams);
|
||
// 需要排除的人员范围
|
||
Set<Long> excludeEmployeeIds = SalaryEntityUtil.properties(excludeSalaryEmployees, DataCollectionEmployee::getEmployeeId);
|
||
// 过滤人员
|
||
includeSalaryEmployees = includeSalaryEmployees.stream()
|
||
.filter(salaryEmployee -> !excludeEmployeeIds.contains(salaryEmployee.getEmployeeId()))
|
||
.collect(Collectors.toList());
|
||
}
|
||
}
|
||
|
||
//外部人员
|
||
List<SalarySobExtRangePO> salarySobExtRangePOS = getSalarySobExtRangeService(user).listBySalarySobId(salarySobId);
|
||
if (CollectionUtils.isNotEmpty(salarySobExtRangePOS)) {
|
||
List<Long> ids = SalaryEntityUtil.properties(salarySobExtRangePOS, SalarySobExtRangePO::getTargetId, Collectors.toList());
|
||
List<DataCollectionEmployee> extEmps = getExtEmpService(user).getEmployeeByIds(ids);
|
||
extEmps = extEmps.stream().distinct().collect(Collectors.toList());
|
||
|
||
includeSalaryEmployees.addAll(extEmps);
|
||
}
|
||
|
||
return includeSalaryEmployees;
|
||
}
|
||
|
||
@Override
|
||
public List<DataCollectionEmployee> getEmployeeByIdsAll(List<Long> ids) {
|
||
if (CollectionUtils.isEmpty(ids)) {
|
||
return new ArrayList<>();
|
||
}
|
||
List<DataCollectionEmployee> employeeList = employBiz.getEmployeeByIdsAll(ids);
|
||
if (openExtEmp) {
|
||
employeeList.addAll(getExtEmpService(user).getEmployeeByIds(ids));
|
||
}
|
||
return employeeList;
|
||
}
|
||
|
||
@Override
|
||
public List<DataCollectionEmployee> listByIds(List<Long> ids) {
|
||
return employBiz.getEmployeeByIdsAll(ids);
|
||
}
|
||
|
||
@Override
|
||
public DataCollectionEmployee getEmployeeById(Long employeeId) {
|
||
if (openExtEmp) {
|
||
DataCollectionEmployee employeeById = getExtEmpService(user).getEmployeeById(employeeId);
|
||
if (Objects.nonNull(employeeById)) {
|
||
return employeeById;
|
||
}
|
||
}
|
||
return employBiz.getEmployeeById(employeeId);
|
||
}
|
||
|
||
@Override
|
||
public List<DataCollectionEmployee> getEmployeeByIds(List<Long> simpleEmployeeIds) {
|
||
if (CollectionUtils.isEmpty(simpleEmployeeIds)) {
|
||
return new ArrayList<>();
|
||
}
|
||
List<DataCollectionEmployee> employeeList = new ArrayList<>();
|
||
List<List<Long>> partition = Lists.partition(simpleEmployeeIds, 1000);
|
||
for (List<Long> longs : partition) {
|
||
employeeList.addAll(employBiz.getEmployeeByIds(longs));
|
||
if (openExtEmp) {
|
||
employeeList.addAll(getExtEmpService(user).getEmployeeByIds(longs));
|
||
}
|
||
}
|
||
|
||
return employeeList;
|
||
|
||
}
|
||
|
||
|
||
public List<DataCollectionEmployee> filterEmployees(List<DataCollectionEmployee> employees, String userName, String deparmentName, String mobile) {
|
||
List<DataCollectionEmployee> employeeSameIds = employees.stream().filter(e -> (StringUtils.isBlank(userName) || Objects.equals(e.getUsername(), userName))
|
||
&& (StringUtils.isBlank(deparmentName) || Objects.equals(e.getDepartmentName(), deparmentName))
|
||
&& (StringUtils.isBlank(mobile) || Objects.equals(e.getMobile(), mobile)))
|
||
.collect(Collectors.toList());
|
||
//存在离职和在职状态取在职状态
|
||
employeeSameIds = employeeSameIds.stream()
|
||
.filter(e -> UserStatusEnum.getNormalStatus().contains(e.getStatus()))
|
||
.collect(Collectors.toList());
|
||
|
||
return employeeSameIds;
|
||
}
|
||
|
||
@Override
|
||
public List<DataCollectionEmployee> matchImportEmployee(List<DataCollectionEmployee> employeeList, String userName, String deparmentName, String mobile, String workcode, Long uid) {
|
||
if (uid != null) {
|
||
return employeeList.stream()
|
||
.filter(e -> Objects.equals(e.getEmployeeId(), uid))
|
||
.collect(Collectors.toList());
|
||
}
|
||
|
||
//查询对于人员信息导入筛选的全局配置
|
||
String confValue = empValidType();
|
||
List<DataCollectionEmployee> employees = new ArrayList<>();
|
||
//“0”代表姓名+部门+手机号的匹配原则,“1”代表工号为唯一匹配原则
|
||
if ("0".equals(confValue)) {
|
||
employees = employeeList.stream().filter(e -> (StringUtils.isBlank(userName) || Objects.equals(e.getUsername(), userName))
|
||
&& (StringUtils.isBlank(deparmentName) || Objects.equals(e.getDepartmentName(), deparmentName))
|
||
&& (StringUtils.isBlank(mobile) || Objects.equals(e.getMobile(), mobile)))
|
||
.collect(Collectors.toList());
|
||
} else if ("1".equals(confValue)) {
|
||
employees = employeeList.stream().filter(e -> (StringUtils.isBlank(workcode) || Objects.equals(e.getWorkcode(), workcode)))
|
||
.collect(Collectors.toList());
|
||
}
|
||
|
||
return employees;
|
||
|
||
}
|
||
|
||
/**
|
||
* 人员定位方式
|
||
* “0”代表姓名+部门+手机号的匹配原则,“1”代表工号为唯一匹配原则
|
||
*
|
||
* @return
|
||
*/
|
||
@Override
|
||
public String empValidType() {
|
||
SalarySysConfPO salarySysConfPO = getSalarySysConfMapper().getOneByCode("matchEmployeeMode");
|
||
return (salarySysConfPO != null && salarySysConfPO.getConfValue() != null && !"".equals(salarySysConfPO.getConfValue())) ? salarySysConfPO.getConfValue() : "0";
|
||
}
|
||
|
||
@Override
|
||
public List<DeptInfo> getDeptInfoList(List<Long> departmentIds) {
|
||
return employBiz.getDeptInfoList(departmentIds);
|
||
}
|
||
|
||
@Override
|
||
public List<SubCompanyInfo> getSubCompanyInfoList(List<Long> subDepartmentIds) {
|
||
return employBiz.getSubCompanyInfoList(subDepartmentIds);
|
||
}
|
||
|
||
@Override
|
||
public List<PositionInfo> listPositionInfo(List<Long> positionIds) {
|
||
return employBiz.listPositionInfo(positionIds);
|
||
}
|
||
|
||
@Override
|
||
public List<DataCollectionEmployee> listEmployee() {
|
||
List<DataCollectionEmployee> result = employBiz.listEmployee();
|
||
if (openExtEmp) {
|
||
result.addAll(getExtEmpService(user).listEmployee());
|
||
}
|
||
return result;
|
||
}
|
||
|
||
@Override
|
||
public List<DataCollectionEmployee> listByParams(List<SalarySobRangeEmpQueryParam> includeQueryParams) {
|
||
List<DataCollectionEmployee> result = employBiz.listByParams(includeQueryParams);
|
||
if (openExtEmp) {
|
||
result.addAll(getExtEmpService(user).listByParams(includeQueryParams));
|
||
}
|
||
return result;
|
||
}
|
||
}
|