2022-03-22 21:01:38 +08:00
|
|
|
|
package com.engine.salary.service.impl;
|
|
|
|
|
|
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import com.api.formmode.mybatis.util.SqlProxyHandle;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
|
import com.engine.core.impl.Service;
|
2022-03-23 13:52:43 +08:00
|
|
|
|
import com.engine.hrm.biz.OrganizationShowSetBiz;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.biz.SalarySobRangeBiz;
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import com.engine.salary.biz.SpecialAddDeductionBiz;
|
2024-01-30 09:58:13 +08:00
|
|
|
|
import com.engine.salary.config.SalaryElogConfig;
|
|
|
|
|
|
import com.engine.salary.elog.entity.dto.LoggerContext;
|
2022-03-23 18:41:38 +08:00
|
|
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
|
|
|
|
|
import com.engine.salary.entity.hrm.DeptInfo;
|
|
|
|
|
|
import com.engine.salary.entity.hrm.PositionInfo;
|
2022-06-09 17:45:28 +08:00
|
|
|
|
import com.engine.salary.entity.hrm.SubCompanyInfo;
|
2022-03-23 18:41:38 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.bo.SalarySobRangeBO;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.bo.SalarySobRangeSaveBO;
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.dto.SalarySobRangeImportListDTO;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.dto.SalarySobRangeListDTO;
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.param.SalarySobRangeImportParam;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.entity.salarysob.param.SalarySobRangeQueryParam;
|
|
|
|
|
|
import com.engine.salary.entity.salarysob.param.SalarySobRangeSaveParam;
|
|
|
|
|
|
import com.engine.salary.entity.salarysob.po.SalarySobPO;
|
|
|
|
|
|
import com.engine.salary.entity.salarysob.po.SalarySobRangePO;
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeEmployeeDTO;
|
2024-01-30 09:58:13 +08:00
|
|
|
|
import com.engine.salary.enums.OperateTypeEnum;
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import com.engine.salary.enums.UserStatusEnum;
|
|
|
|
|
|
import com.engine.salary.enums.salarysob.SalaryEmployeeStatusEnum;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.enums.salarysob.TargetTypeEnum;
|
|
|
|
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
2023-03-14 10:52:48 +08:00
|
|
|
|
import com.engine.salary.mapper.salarysob.SalarySobExtRangeMapper;
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import com.engine.salary.mapper.sys.SalarySysConfMapper;
|
|
|
|
|
|
import com.engine.salary.service.SalaryEmployeeService;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.service.SalarySobRangeService;
|
|
|
|
|
|
import com.engine.salary.service.SalarySobService;
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import com.engine.salary.service.TaxAgentService;
|
|
|
|
|
|
import com.engine.salary.sys.entity.po.SalarySysConfPO;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
|
|
|
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import com.engine.salary.util.excel.ExcelComment;
|
|
|
|
|
|
import com.engine.salary.util.excel.ExcelParseHelper;
|
|
|
|
|
|
import com.engine.salary.util.excel.ExcelUtil;
|
2022-03-23 18:41:38 +08:00
|
|
|
|
import com.engine.salary.util.page.PageInfo;
|
2022-05-25 13:10:03 +08:00
|
|
|
|
import com.engine.salary.util.page.SalaryPageUtil;
|
2022-03-23 18:41:38 +08:00
|
|
|
|
import com.engine.salary.util.valid.ValidUtil;
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import com.google.common.collect.Maps;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2022-03-23 18:41:38 +08:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import org.apache.commons.lang3.Validate;
|
|
|
|
|
|
import org.apache.poi.util.IOUtils;
|
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
|
import weaver.file.ImageFileManager;
|
|
|
|
|
|
import weaver.general.Util;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
import weaver.hrm.User;
|
|
|
|
|
|
|
2023-01-09 15:12:44 +08:00
|
|
|
|
import java.io.InputStream;
|
2022-03-22 21:01:38 +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 SalarySobRangeServiceImpl extends Service implements SalarySobRangeService {
|
|
|
|
|
|
|
2022-03-23 20:54:08 +08:00
|
|
|
|
private SalarySobRangeBiz salarySobRangeBiz = new SalarySobRangeBiz();
|
2022-03-25 18:05:07 +08:00
|
|
|
|
private OrganizationShowSetBiz orgBiz = new OrganizationShowSetBiz();
|
2022-03-23 13:52:43 +08:00
|
|
|
|
|
2022-03-22 21:01:38 +08:00
|
|
|
|
|
|
|
|
|
|
private SalarySobService getSalarySobService(User user) {
|
|
|
|
|
|
return (SalarySobService) ServiceUtil.getService(SalarySobServiceImpl.class, user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-09 15:12:44 +08:00
|
|
|
|
private TaxAgentService getTaxAgentService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SalaryEmployeeService getSalaryEmployeeService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SalarySysConfMapper getSalarySysConfMapper() {
|
|
|
|
|
|
return SqlProxyHandle.getProxy(SalarySysConfMapper.class);
|
|
|
|
|
|
}
|
2022-03-22 21:01:38 +08:00
|
|
|
|
|
2023-03-14 10:52:48 +08:00
|
|
|
|
private SalarySobExtRangeMapper getSalarySobExtRangeMapper() {
|
|
|
|
|
|
return SqlProxyHandle.getProxy(SalarySobExtRangeMapper.class);
|
|
|
|
|
|
}
|
2022-03-22 21:01:38 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public List<SalarySobRangePO> listByIds(Collection<Long> ids) {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(ids)) {
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
}
|
2022-03-23 20:54:08 +08:00
|
|
|
|
return salarySobRangeBiz.listSome(SalarySobRangePO.builder().ids(ids).build());
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public List<SalarySobRangePO> listBySalarySobIdAndIncludeType(Long salarySobId, Integer includeType) {
|
2022-03-23 20:54:08 +08:00
|
|
|
|
return salarySobRangeBiz.listSome(SalarySobRangePO.builder().salarySobId(salarySobId).includeType(includeType).build());
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-08 17:21:38 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public List<SalarySobRangePO> listAllSalarySobRange() {
|
|
|
|
|
|
return salarySobRangeBiz.listSome(SalarySobRangePO.builder().build());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-22 21:01:38 +08:00
|
|
|
|
@Override
|
2022-03-23 18:41:38 +08:00
|
|
|
|
public PageInfo<SalarySobRangeListDTO> listPageByParamAndIncludeType(SalarySobRangeQueryParam queryParam, Integer includeType) {
|
2022-03-22 21:01:38 +08:00
|
|
|
|
// 查询人员范围
|
|
|
|
|
|
List<SalarySobRangePO> salarySobRangePOS = listBySalarySobIdAndIncludeType(queryParam.getSalarySobId(), includeType);
|
|
|
|
|
|
// 查询人员信息
|
2022-03-23 18:41:38 +08:00
|
|
|
|
List<Long> employeeIds = salarySobRangePOS.stream()
|
2022-03-22 21:01:38 +08:00
|
|
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.EMPLOYEE.getValue()))
|
|
|
|
|
|
.map(SalarySobRangePO::getTargetId)
|
|
|
|
|
|
.collect(Collectors.toList());
|
2023-03-07 17:14:25 +08:00
|
|
|
|
List<DataCollectionEmployee> empInfos = getSalaryEmployeeService(user).getEmployeeByIds(employeeIds);
|
2022-03-23 13:52:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询部门信息
|
2022-03-23 18:41:38 +08:00
|
|
|
|
List<DeptInfo> deptInfos = salarySobRangePOS.stream()
|
2022-03-22 21:01:38 +08:00
|
|
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.DEPT.getValue()))
|
|
|
|
|
|
.map(SalarySobRangePO::getTargetId)
|
2022-03-23 18:41:38 +08:00
|
|
|
|
.map(id -> {
|
|
|
|
|
|
return DeptInfo.builder().id(id).name(orgBiz.getDepartmentShow(String.valueOf(id), "0", "-")).build();
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
2022-06-09 17:45:28 +08:00
|
|
|
|
// 查询分部信息
|
|
|
|
|
|
List<SubCompanyInfo> subCompanyInfos = salarySobRangePOS.stream()
|
|
|
|
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.SUBCOMPANY.getValue()))
|
|
|
|
|
|
.map(SalarySobRangePO::getTargetId)
|
|
|
|
|
|
.map(id -> {
|
|
|
|
|
|
return SubCompanyInfo.builder().id(id).name(orgBiz.getSubcompanyShow(String.valueOf(id), "0", "-")).build();
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
2022-03-23 18:41:38 +08:00
|
|
|
|
|
|
|
|
|
|
// 查询岗位信息
|
|
|
|
|
|
List<Long> positionIds = salarySobRangePOS.stream()
|
|
|
|
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.POSITION.getValue()))
|
|
|
|
|
|
.map(SalarySobRangePO::getTargetId)
|
|
|
|
|
|
.collect(Collectors.toList());
|
2023-03-07 17:14:25 +08:00
|
|
|
|
List<PositionInfo> positionInfos = getSalaryEmployeeService(user).listPositionInfo(positionIds);
|
2022-03-23 18:41:38 +08:00
|
|
|
|
|
|
|
|
|
|
// 薪资账套的人员范围po转换成列表dto
|
2023-03-14 10:52:48 +08:00
|
|
|
|
List<SalarySobRangeListDTO> salarySobRangeListDTOS = SalarySobRangeBO.convert2ListDTO(salarySobRangePOS, empInfos, deptInfos, subCompanyInfos, positionInfos);
|
2022-03-23 18:41:38 +08:00
|
|
|
|
// 根据对象名称过滤
|
|
|
|
|
|
if (StringUtils.isNotEmpty(queryParam.getTargetName())) {
|
|
|
|
|
|
salarySobRangeListDTOS = salarySobRangeListDTOS.stream()
|
|
|
|
|
|
.filter(salarySobRangeListDTO -> salarySobRangeListDTO.getTargetName().contains(queryParam.getTargetName()))
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
}
|
|
|
|
|
|
// 填充总数和当页数据
|
2023-03-14 10:52:48 +08:00
|
|
|
|
PageInfo<SalarySobRangeListDTO> pageInfo = new PageInfo<SalarySobRangeListDTO>(salarySobRangeListDTOS, SalarySobRangeListDTO.class);
|
2022-03-23 18:41:38 +08:00
|
|
|
|
pageInfo.setTotal(salarySobRangeListDTOS.size());
|
2022-05-25 13:10:03 +08:00
|
|
|
|
pageInfo.setList(SalaryPageUtil.subList(queryParam.getCurrent(), queryParam.getPageSize(), salarySobRangeListDTOS));
|
2022-08-16 17:26:16 +08:00
|
|
|
|
pageInfo.setPageNum(queryParam.getCurrent());
|
|
|
|
|
|
pageInfo.setPageSize(queryParam.getPageSize());
|
2022-03-23 18:41:38 +08:00
|
|
|
|
return pageInfo;
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void save(SalarySobRangeSaveParam saveParam) {
|
2022-03-23 18:41:38 +08:00
|
|
|
|
|
|
|
|
|
|
ValidUtil.doValidator(saveParam);
|
|
|
|
|
|
|
2022-03-22 21:01:38 +08:00
|
|
|
|
// 查询薪资账套
|
|
|
|
|
|
SalarySobPO salarySobPO = getSalarySobService(user).getById(saveParam.getSalarySobId());
|
|
|
|
|
|
if (Objects.isNull(salarySobPO)) {
|
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98379, "参数错误,薪资账套不存在或者已被删除"));
|
|
|
|
|
|
}
|
|
|
|
|
|
// 查询已有的人员范围
|
|
|
|
|
|
List<SalarySobRangePO> salarySobRangePOS = listBySalarySobIdAndIncludeType(saveParam.getSalarySobId(), saveParam.getIncludeType());
|
|
|
|
|
|
// 处理一下本次的保存参数(如果原来添加过对应的人员(/部门/岗位),那么本次不需要新增,只需要更新)
|
2023-02-08 17:48:14 +08:00
|
|
|
|
SalarySobRangeSaveBO.Result result = SalarySobRangeSaveBO.handle(salarySobRangePOS, saveParam, (long) user.getUID(), false);
|
2022-03-22 21:01:38 +08:00
|
|
|
|
// 保存
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedInsertSalarySobRanges())) {
|
2022-03-23 20:54:08 +08:00
|
|
|
|
salarySobRangeBiz.batchInsert(result.getNeedInsertSalarySobRanges());
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedUpdateSalarySobRanges())) {
|
2022-03-23 20:54:08 +08:00
|
|
|
|
result.getNeedUpdateSalarySobRanges().forEach(e -> salarySobRangeBiz.updateById(e));
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|
2024-01-30 09:58:13 +08:00
|
|
|
|
//记录日志
|
|
|
|
|
|
String operateTypeName = Objects.equals(saveParam.getIncludeType(), 1) ?
|
|
|
|
|
|
SalaryI18nUtil.getI18nLabel(98601, "关联人员范围新增对象") : SalaryI18nUtil.getI18nLabel(98602, "从范围中排除新增对象");
|
|
|
|
|
|
LoggerContext<SalarySobRangeSaveParam> loggerContext = new LoggerContext<>();
|
|
|
|
|
|
loggerContext.setUser(user);
|
|
|
|
|
|
loggerContext.setTargetId("" + salarySobPO.getId());
|
|
|
|
|
|
loggerContext.setTargetName(salarySobPO.getName());
|
|
|
|
|
|
loggerContext.setOperateType(OperateTypeEnum.UPDATE.getValue());
|
|
|
|
|
|
loggerContext.setOperateTypeName(operateTypeName);
|
|
|
|
|
|
loggerContext.setOperatedesc(operateTypeName);
|
|
|
|
|
|
loggerContext.setNewValues(saveParam);
|
|
|
|
|
|
SalaryElogConfig.salarySobLoggerTemplate.write(loggerContext);
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void deleteByIds(Collection<Long> ids) {
|
|
|
|
|
|
// 查询薪资账套的人员范围
|
|
|
|
|
|
List<SalarySobRangePO> salarySobRangePOS = listByIds(ids);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(salarySobRangePOS)) {
|
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98604, "数据不存在或已被删除"));
|
|
|
|
|
|
}
|
|
|
|
|
|
ids = SalaryEntityUtil.properties(salarySobRangePOS, SalarySobRangePO::getId);
|
|
|
|
|
|
// 删除薪资账套的人员范围
|
2022-03-23 20:54:08 +08:00
|
|
|
|
salarySobRangeBiz.deleteByIds(ids);
|
2022-03-22 21:01:38 +08:00
|
|
|
|
// 查询薪资账套
|
2023-03-14 10:52:48 +08:00
|
|
|
|
// Set<Long> salarySobIds = SalaryEntityUtil.properties(salarySobRangePOS, SalarySobRangePO::getSalarySobId);
|
|
|
|
|
|
// List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByIds(salarySobIds);
|
|
|
|
|
|
// // 是"关联人员范围"还是"从范围中排除"
|
|
|
|
|
|
// Integer includeType = salarySobRangePOS.get(0).getIncludeType();
|
|
|
|
|
|
// // todo 记录日志
|
|
|
|
|
|
// String operateTypeName = Objects.equals(includeType, NumberUtils.INTEGER_ONE) ?
|
|
|
|
|
|
// SalaryI18nUtil.getI18nLabel(98605, "关联人员范围删除对象") : SalaryI18nUtil.getI18nLabel(98606, "从范围中排除删除对象");
|
2022-03-22 21:01:38 +08:00
|
|
|
|
// salarySobPOS.forEach(salarySobPO -> {
|
|
|
|
|
|
// LoggerContext<SalarySobPO> loggerContext = new LoggerContext<>();
|
|
|
|
|
|
// loggerContext.setTargetId("" + salarySobPO.getId());
|
|
|
|
|
|
// loggerContext.setTargetName(salarySobPO.getName());
|
|
|
|
|
|
// loggerContext.setOperateType(OperateTypeEnum.DELETE.getValue());
|
|
|
|
|
|
// loggerContext.setOperateTypeName(operateTypeName);
|
|
|
|
|
|
// loggerContext.setOperatedesc(operateTypeName);
|
|
|
|
|
|
// });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void deleteBySalarySobIds(Collection<Long> salarySobIds) {
|
2022-03-23 20:54:08 +08:00
|
|
|
|
salarySobRangeBiz.deleteBySalarySobIds(salarySobIds);
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|
2022-10-08 17:21:38 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void updateEmployeeStatuses(SalarySobRangePO item) {
|
|
|
|
|
|
salarySobRangeBiz.updateEmployeeStatuses(item);
|
|
|
|
|
|
}
|
2023-01-09 15:12:44 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public XSSFWorkbook downloadTemplateRange() {
|
|
|
|
|
|
//获取操作按钮资源
|
|
|
|
|
|
List<List<Object>> rowList = getExcelRowList();
|
|
|
|
|
|
//查询对于人员信息导入筛选的全局配置
|
|
|
|
|
|
SalarySysConfPO salarySysConfPO = getSalarySysConfMapper().getOneByCode("matchEmployeeMode");
|
|
|
|
|
|
String confValue = (salarySysConfPO != null && salarySysConfPO.getConfValue() != null && !"".equals(salarySysConfPO.getConfValue())) ? salarySysConfPO.getConfValue() : "0";
|
|
|
|
|
|
// 注释
|
|
|
|
|
|
List<ExcelComment> excelComments = Lists.newArrayList();
|
2023-03-14 10:52:48 +08:00
|
|
|
|
if (confValue.equals("1")) {
|
2023-01-09 15:12:44 +08:00
|
|
|
|
// 人员校验规则为工号
|
|
|
|
|
|
excelComments.add(new ExcelComment(3, 0, 4, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
|
2023-03-14 10:52:48 +08:00
|
|
|
|
} else {
|
2023-01-09 15:12:44 +08:00
|
|
|
|
excelComments.add(new ExcelComment(0, 0, 1, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
|
|
|
|
|
|
}
|
2023-02-08 17:48:14 +08:00
|
|
|
|
excelComments.add(new ExcelComment(4, 0, 6, 3, SalaryI18nUtil.getI18nLabel(100344, "若不填,默认全部员工状态。指定员工状态格式:试用、正式、临时、试用延期")));
|
|
|
|
|
|
|
2023-01-09 15:12:44 +08:00
|
|
|
|
|
|
|
|
|
|
//获取excel
|
|
|
|
|
|
return ExcelUtil.genWorkbookV2(rowList, "薪资账套人员范围", excelComments);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Map<String, Object> importData(SalarySobRangeImportParam importParam) {
|
|
|
|
|
|
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
|
|
|
|
|
|
|
|
|
|
|
|
long currentEmployeeId = user.getUID();
|
|
|
|
|
|
Map<String, Object> apidatas = new HashMap<String, Object>();
|
|
|
|
|
|
SpecialAddDeductionBiz SpecialAddDeductionBiz = new SpecialAddDeductionBiz();
|
|
|
|
|
|
|
|
|
|
|
|
//查询对于人员信息导入筛选的全局配置
|
|
|
|
|
|
SalarySysConfPO salarySysConfPO = getSalarySysConfMapper().getOneByCode("matchEmployeeMode");
|
|
|
|
|
|
String confValue = (salarySysConfPO != null && salarySysConfPO.getConfValue() != null && !"".equals(salarySysConfPO.getConfValue())) ? salarySysConfPO.getConfValue() : "0";
|
|
|
|
|
|
|
|
|
|
|
|
//检验参数
|
|
|
|
|
|
checkImportParam(importParam);
|
|
|
|
|
|
|
|
|
|
|
|
//excel文件id
|
|
|
|
|
|
String imageId = Util.null2String(importParam.getImageId());
|
|
|
|
|
|
//薪资账套ID
|
|
|
|
|
|
String salarySobIdStr = Util.null2String(importParam.getSalarySobId());
|
|
|
|
|
|
Long salarySobId = SalaryEntityUtil.string2Long(salarySobIdStr);
|
|
|
|
|
|
|
|
|
|
|
|
// 查询薪资账套
|
|
|
|
|
|
SalarySobPO salarySobPO = getSalarySobService(user).getById(salarySobId);
|
|
|
|
|
|
if (Objects.isNull(salarySobPO)) {
|
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98379, "参数错误,薪资账套不存在或者已被删除"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InputStream fileInputStream = null;
|
|
|
|
|
|
try {
|
|
|
|
|
|
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(imageId));
|
2023-02-08 17:48:14 +08:00
|
|
|
|
List<SalarySobRangeImportListDTO> salarySobRangeImportLists = ExcelParseHelper.parse2Map(fileInputStream, SalarySobRangeImportListDTO.class, 0, 1, 5, "SpecialAddDeductionTemplate.xlsx");
|
2023-01-09 15:12:44 +08:00
|
|
|
|
|
|
|
|
|
|
int total = salarySobRangeImportLists.size();
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
int successCount = 0;
|
|
|
|
|
|
int errorCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
//人员信息
|
2023-03-07 17:14:25 +08:00
|
|
|
|
List<DataCollectionEmployee> employees = getSalaryEmployeeService(user).listEmployee();
|
2023-01-09 15:12:44 +08:00
|
|
|
|
// 获取所有个税扣缴义务人
|
|
|
|
|
|
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
|
|
|
|
|
|
// 错误excel内容
|
|
|
|
|
|
List<Map> errorData = new ArrayList<>();
|
|
|
|
|
|
//合规数据
|
|
|
|
|
|
List<SalarySobRangeSaveParam.SalarySobRangeTargetParam> eligibleData = new ArrayList<>();
|
|
|
|
|
|
for (int i = 0; i < salarySobRangeImportLists.size(); i++) {
|
|
|
|
|
|
SalarySobRangeImportListDTO dto = salarySobRangeImportLists.get(i);
|
|
|
|
|
|
|
|
|
|
|
|
//待插入数据库对象
|
|
|
|
|
|
SalarySobRangeSaveParam.SalarySobRangeTargetParam po = new SalarySobRangeSaveParam.SalarySobRangeTargetParam();
|
|
|
|
|
|
po.setTargetType(TargetTypeEnum.EMPLOYEE);
|
|
|
|
|
|
|
|
|
|
|
|
//异常点数量
|
|
|
|
|
|
int errorSum = 0;
|
|
|
|
|
|
|
|
|
|
|
|
//行号
|
|
|
|
|
|
String rowIndex = String.format("第%s行", i + 2);
|
|
|
|
|
|
|
|
|
|
|
|
//相同的姓名
|
|
|
|
|
|
String userName = dto.getUsername();
|
|
|
|
|
|
String deparmentName = dto.getDepartmentName();
|
|
|
|
|
|
String mobile = dto.getMobile();
|
|
|
|
|
|
String workcode = dto.getJobNum();
|
2023-02-08 17:48:14 +08:00
|
|
|
|
String employeeStatusStr = dto.getEmployeeStatus();
|
2023-01-09 15:12:44 +08:00
|
|
|
|
List<Long> employeeSameIds = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
//筛选导入人员信息可以在人力资源池中匹配到的人员信息
|
|
|
|
|
|
List<DataCollectionEmployee> emps = getSalaryEmployeeService(user)
|
|
|
|
|
|
.matchImportEmployee(employees, userName, deparmentName, mobile, workcode, null);
|
|
|
|
|
|
//含在职和离职,选在职数据
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(emps) && emps.size() > 1) {
|
|
|
|
|
|
employeeSameIds = emps.stream()
|
|
|
|
|
|
.filter(e -> UserStatusEnum.getNormalStatus().contains(e.getStatus()))
|
|
|
|
|
|
.map(DataCollectionEmployee::getEmployeeId)
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(emps) && emps.size() == 1) {
|
|
|
|
|
|
employeeSameIds = emps.stream()
|
|
|
|
|
|
.map(DataCollectionEmployee::getEmployeeId)
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//当人员信息导入筛选的全局配置为"0"时,姓名才是必填项
|
|
|
|
|
|
if (StringUtils.isBlank(userName) && "0".equals(confValue)) {
|
|
|
|
|
|
//姓名 不能为空
|
|
|
|
|
|
//错误消息对象
|
|
|
|
|
|
Map<String, String> errorMessageMap = Maps.newHashMap();
|
|
|
|
|
|
errorMessageMap.put("message", rowIndex + "姓名不能为空");
|
|
|
|
|
|
errorData.add(errorMessageMap);
|
|
|
|
|
|
errorSum += 1;
|
|
|
|
|
|
} else if (CollectionUtils.isEmpty(employeeSameIds) || employeeSameIds.size() > 1) {
|
|
|
|
|
|
Map<String, String> errorMessageMap = Maps.newHashMap();
|
|
|
|
|
|
errorMessageMap.put("message", rowIndex + "员工信息不存在或者存在多个员工");
|
|
|
|
|
|
errorData.add(errorMessageMap);
|
|
|
|
|
|
errorSum += 1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Long employeeId = CollectionUtils.isNotEmpty(employeeSameIds) && employeeSameIds.size() == 1 ? employeeSameIds.get(0) : null;
|
|
|
|
|
|
if (employeeId != null && employeeId > 0) {
|
|
|
|
|
|
po.setTargetId(employeeId);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
//姓名错误,系统内不存在该姓名
|
|
|
|
|
|
Map<String, String> errorMessageMap = new HashMap<>();
|
|
|
|
|
|
errorMessageMap.put("message", rowIndex + "姓名错误,系统内不存在该姓名");
|
|
|
|
|
|
errorData.add(errorMessageMap);
|
|
|
|
|
|
errorSum += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-02-08 17:48:14 +08:00
|
|
|
|
|
|
|
|
|
|
// 设置员工状态
|
2023-03-14 10:52:48 +08:00
|
|
|
|
if (StringUtils.isEmpty(employeeStatusStr)) {
|
2023-02-08 17:48:14 +08:00
|
|
|
|
SalaryEmployeeStatusEnum[] values = SalaryEmployeeStatusEnum.values();
|
|
|
|
|
|
po.setEmployeeStatus(SalaryEmployeeStatusEnum.values());
|
2023-03-14 10:52:48 +08:00
|
|
|
|
} else {
|
2023-02-08 17:48:14 +08:00
|
|
|
|
Boolean[] haveError = {false};
|
|
|
|
|
|
// 人员状态字符串转换为对应的value
|
|
|
|
|
|
SalaryEmployeeStatusEnum[] status = SalaryEmployeeStatusEnum.getEnumsParseByFormatStr(employeeStatusStr, haveError);
|
2023-03-14 10:52:48 +08:00
|
|
|
|
if (haveError[0]) {
|
2023-02-08 17:48:14 +08:00
|
|
|
|
Map<String, String> errorMessageMap = new HashMap<>();
|
|
|
|
|
|
errorMessageMap.put("message", rowIndex + "员工状态不存在,或格式有误。格式为:试用、正式、临时、试用延期");
|
|
|
|
|
|
errorData.add(errorMessageMap);
|
|
|
|
|
|
errorSum += 1;
|
2023-03-14 10:52:48 +08:00
|
|
|
|
} else {
|
2023-02-08 17:48:14 +08:00
|
|
|
|
po.setEmployeeStatus(status);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-09 15:12:44 +08:00
|
|
|
|
//fixme 分权判断
|
|
|
|
|
|
if (errorSum == 0) {
|
|
|
|
|
|
successCount += 1;
|
|
|
|
|
|
// 合格数据
|
|
|
|
|
|
eligibleData.add(po);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
errorCount += 1;
|
|
|
|
|
|
// 添加错误数据
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 入库
|
2023-01-11 09:47:57 +08:00
|
|
|
|
eligibleData = handleImportData(eligibleData);
|
2023-01-09 15:12:44 +08:00
|
|
|
|
// 查询已有的人员范围
|
|
|
|
|
|
List<SalarySobRangePO> salarySobRangePOS = listBySalarySobIdAndIncludeType(salarySobId, 1);
|
|
|
|
|
|
SalarySobRangeSaveParam saveParam = new SalarySobRangeSaveParam();
|
|
|
|
|
|
saveParam.setTargetParams(eligibleData);
|
2023-02-08 17:48:14 +08:00
|
|
|
|
// saveParam.setEmployeeStatus( SalaryEmployeeStatusEnum.values());
|
2023-01-09 15:12:44 +08:00
|
|
|
|
saveParam.setIncludeType(1);
|
|
|
|
|
|
saveParam.setSalarySobId(salarySobId);
|
|
|
|
|
|
// 处理一下本次的保存参数(如果原来添加过对应的人员(/部门/岗位),那么本次不需要新增,只需要更新)
|
2023-02-08 17:48:14 +08:00
|
|
|
|
SalarySobRangeSaveBO.Result result = SalarySobRangeSaveBO.handle(salarySobRangePOS, saveParam, (long) user.getUID(), true);
|
2023-01-09 15:12:44 +08:00
|
|
|
|
// 保存
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedInsertSalarySobRanges())) {
|
|
|
|
|
|
salarySobRangeBiz.batchInsert(result.getNeedInsertSalarySobRanges());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedUpdateSalarySobRanges())) {
|
|
|
|
|
|
result.getNeedUpdateSalarySobRanges().forEach(e -> salarySobRangeBiz.updateById(e));
|
|
|
|
|
|
}
|
|
|
|
|
|
apidatas.put("successCount", successCount);
|
|
|
|
|
|
apidatas.put("errorCount", errorCount);
|
|
|
|
|
|
apidatas.put("errorData", errorData);
|
|
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
IOUtils.closeQuietly(fileInputStream);
|
|
|
|
|
|
}
|
|
|
|
|
|
return apidatas;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-11 09:47:57 +08:00
|
|
|
|
// 处理导入数据
|
|
|
|
|
|
private List<SalarySobRangeSaveParam.SalarySobRangeTargetParam> handleImportData(List<SalarySobRangeSaveParam.SalarySobRangeTargetParam> pos) {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(pos)) {
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
}
|
|
|
|
|
|
// 多条相同人的则以第一条为准,如果逆序排列(用于重复的则以最后一条为准)Collections.reverse(pos);
|
|
|
|
|
|
// 去重(通过记录的唯一条件(人员id)
|
2023-03-14 10:52:48 +08:00
|
|
|
|
List<SalarySobRangeSaveParam.SalarySobRangeTargetParam> finalPos = pos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(f -> f.getTargetId()))), ArrayList::new));
|
2023-01-11 09:47:57 +08:00
|
|
|
|
return finalPos;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-09 15:12:44 +08:00
|
|
|
|
private void checkImportParam(SalarySobRangeImportParam importParam) {
|
|
|
|
|
|
//excel文件id
|
|
|
|
|
|
String imageId = Util.null2String(importParam.getImageId());
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(imageId)) {
|
|
|
|
|
|
throw new SalaryRunTimeException("文件不存在");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isBlank(importParam.getSalarySobId())) {
|
|
|
|
|
|
throw new SalaryRunTimeException("薪资账套ID为空");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Map<String, Object> preview(SalarySobRangeImportParam importParam) {
|
|
|
|
|
|
Map<String, Object> apidatas = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
|
|
|
|
//excel文件id
|
|
|
|
|
|
String imageId = Util.null2String(importParam.getImageId());
|
|
|
|
|
|
Validate.notBlank(imageId, "imageId为空");
|
|
|
|
|
|
|
|
|
|
|
|
InputStream fileInputStream = null;
|
|
|
|
|
|
try {
|
|
|
|
|
|
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(imageId));
|
2023-03-14 10:52:48 +08:00
|
|
|
|
List<SalarySobRangeImportListDTO> salarySobRangeImportList = ExcelParseHelper.parse2Map(fileInputStream, SalarySobRangeImportListDTO.class, 0, 1, 5, "TaxAgentEmployee.xlsx");
|
2023-01-09 15:12:44 +08:00
|
|
|
|
apidatas.put("preview", salarySobRangeImportList);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
IOUtils.closeQuietly(fileInputStream);
|
|
|
|
|
|
}
|
|
|
|
|
|
return apidatas;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-03-14 10:52:48 +08:00
|
|
|
|
* @return List<List < String>>
|
2023-01-09 15:12:44 +08:00
|
|
|
|
* @description 获取excel数据行
|
|
|
|
|
|
* @author Harryxzy
|
|
|
|
|
|
* @date 2023/1/9 11:37
|
|
|
|
|
|
*/
|
|
|
|
|
|
private List<List<Object>> getExcelRowList() {
|
|
|
|
|
|
// 表头
|
|
|
|
|
|
List<Object> headers = Lists.newArrayList();
|
2023-03-14 10:52:48 +08:00
|
|
|
|
headers.add(SalaryI18nUtil.getI18nLabel(85429, "姓名"));
|
|
|
|
|
|
headers.add(SalaryI18nUtil.getI18nLabel(86185, "部门"));
|
2023-01-09 15:12:44 +08:00
|
|
|
|
headers.add(SalaryI18nUtil.getI18nLabel(86186, "手机号"));
|
|
|
|
|
|
headers.add(SalaryI18nUtil.getI18nLabel(86317, "工号"));
|
2023-02-08 17:48:14 +08:00
|
|
|
|
headers.add(SalaryI18nUtil.getI18nLabel(86318, "员工状态"));
|
2023-01-09 15:12:44 +08:00
|
|
|
|
List<List<Object>> rowList = new ArrayList<>();
|
|
|
|
|
|
rowList.add(headers);
|
|
|
|
|
|
return rowList;
|
|
|
|
|
|
}
|
2022-03-22 21:01:38 +08:00
|
|
|
|
}
|