763 lines
41 KiB
Java
763 lines
41 KiB
Java
package com.engine.salary.service.impl;
|
||
|
||
import com.cloudstore.eccom.pc.table.WeaTableColumn;
|
||
import com.engine.common.util.ServiceUtil;
|
||
import com.engine.core.impl.Service;
|
||
import com.engine.salary.biz.TaxAgentBiz;
|
||
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
||
import com.engine.salary.entity.salaryacct.bo.SalaryAcctEmployeeBO;
|
||
import com.engine.salary.entity.salaryacct.bo.SalaryAcctResultBO;
|
||
import com.engine.salary.entity.salaryacct.dto.SalaryAccEmployeeListDTO;
|
||
import com.engine.salary.entity.salaryacct.dto.SalaryAcctImportFieldDTO;
|
||
import com.engine.salary.entity.salaryacct.dto.SalaryComparisonResultListDTO;
|
||
import com.engine.salary.entity.salaryacct.param.SalaryAcctEmployeeQueryParam;
|
||
import com.engine.salary.entity.salaryacct.param.SalaryAcctImportTemplateParam;
|
||
import com.engine.salary.entity.salaryacct.param.SalaryAcctResultQueryParam;
|
||
import com.engine.salary.entity.salaryacct.param.SalaryComparisonResultQueryParam;
|
||
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
|
||
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
|
||
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
|
||
import com.engine.salary.entity.salarysob.dto.SalarySobItemAggregateDTO;
|
||
import com.engine.salary.entity.salarysob.po.SalarySobEmpFieldPO;
|
||
import com.engine.salary.entity.salarysob.po.SalarySobItemPO;
|
||
import com.engine.salary.entity.taxrate.TaxAgent;
|
||
import com.engine.salary.enums.SalaryValueTypeEnum;
|
||
import com.engine.salary.exception.SalaryRunTimeException;
|
||
import com.engine.salary.service.*;
|
||
import com.engine.salary.util.SalaryEntityUtil;
|
||
import com.engine.salary.util.SalaryI18nUtil;
|
||
import com.engine.salary.util.excel.ExcelUtil;
|
||
import com.google.common.collect.Lists;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.collections4.CollectionUtils;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||
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
|
||
**/
|
||
@Slf4j
|
||
public class SalaryAcctExcelServiceImpl extends Service implements SalaryAcctExcelService {
|
||
|
||
|
||
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
|
||
return (SalaryAcctRecordService) ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
|
||
}
|
||
|
||
private SalaryAcctEmployeeService getSalaryAcctEmployeeService(User user) {
|
||
return (SalaryAcctEmployeeService) ServiceUtil.getService(SalaryAcctEmployeeServiceImpl.class, user);
|
||
}
|
||
|
||
private SalaryAcctResultService getSalaryAcctResultService(User user) {
|
||
return (SalaryAcctResultService) ServiceUtil.getService(SalaryAcctResultServiceImpl.class, user);
|
||
}
|
||
|
||
private SalarySobEmpFieldService getSalarySobEmpFieldService(User user) {
|
||
return (SalarySobEmpFieldService) ServiceUtil.getService(SalarySobEmpFieldServiceImpl.class, user);
|
||
}
|
||
|
||
private SalarySobItemService getSalarySobItemService(User user) {
|
||
return (SalarySobItemService) ServiceUtil.getService(SalarySobItemServiceImpl.class, user);
|
||
}
|
||
|
||
private SalaryItemService getSalaryItemService(User user) {
|
||
return (SalaryItemService) ServiceUtil.getService(SalaryItemServiceImpl.class, user);
|
||
}
|
||
|
||
// private SalaryFormulaService getSalaryFormulaService(User user) {
|
||
// return (SalaryFormulaService) ServiceUtil.getService(SalaryFormulaServiceImpl.class, user);
|
||
// }
|
||
|
||
private SalaryComparisonResultService getSalaryComparisonResultService(User user) {
|
||
return (SalaryComparisonResultService) ServiceUtil.getService(SalaryComparisonResultServiceImpl.class, user);
|
||
}
|
||
|
||
private TaxAgentBiz taxAgentService = new TaxAgentBiz();
|
||
|
||
|
||
private SalaryEmployeeService getSalaryEmployeeService(User user) {
|
||
return (SalaryEmployeeService) ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
|
||
}
|
||
|
||
private SalaryCheckResultService salaryCheckResultService;
|
||
|
||
private SalaryCheckResultDetailService salaryCheckResultDetailService;
|
||
|
||
private SalarySobCheckRuleService salarySobCheckRuleService;
|
||
|
||
|
||
@Override
|
||
public XSSFWorkbook exportSalaryAcctEmployee(SalaryAcctEmployeeQueryParam queryParam) {
|
||
|
||
// 1.工作簿名称
|
||
String sheetName = SalaryI18nUtil.getI18nLabel(85368, "核算人员范围");
|
||
// 2.表头
|
||
String[] header = {
|
||
SalaryI18nUtil.getI18nLabel(85429, "姓名"),
|
||
SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"),
|
||
SalaryI18nUtil.getI18nLabel(86185, "部门"),
|
||
SalaryI18nUtil.getI18nLabel(86186, "手机号"),
|
||
SalaryI18nUtil.getI18nLabel(86186, "工号"),
|
||
SalaryI18nUtil.getI18nLabel(91075, "员工状态"),
|
||
SalaryI18nUtil.getI18nLabel(91075, "入职日期"),
|
||
SalaryI18nUtil.getI18nLabel(91075, "离职日期")
|
||
};
|
||
List<Object> headerList = new ArrayList<>(Arrays.asList(header));
|
||
// 查询薪资核算人员
|
||
List<SalaryAcctEmployeePO> salaryAcctEmployees = getSalaryAcctEmployeeService(user).listByParam(queryParam);
|
||
|
||
// 组装数据
|
||
List<List<Object>> rows = new ArrayList<>();
|
||
rows.add(headerList);
|
||
|
||
// 3.表数据
|
||
List<List<Object>> lists = convert2ExcelRow(salaryAcctEmployees);
|
||
rows.addAll(lists);
|
||
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||
|
||
}
|
||
|
||
|
||
@Override
|
||
public XSSFWorkbook exportReducedEmployee(SalaryAcctEmployeeQueryParam queryParam) {
|
||
// 1.工作簿名称
|
||
String sheetName = SalaryI18nUtil.getI18nLabel(85368, "环比上月减少人员");
|
||
// 2.表头
|
||
String[] header = {
|
||
SalaryI18nUtil.getI18nLabel(85429, "姓名"),
|
||
SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"),
|
||
SalaryI18nUtil.getI18nLabel(86185, "部门"),
|
||
SalaryI18nUtil.getI18nLabel(86186, "手机号"),
|
||
SalaryI18nUtil.getI18nLabel(86186, "工号"),
|
||
SalaryI18nUtil.getI18nLabel(91075, "员工状态"),
|
||
SalaryI18nUtil.getI18nLabel(91075, "入职日期"),
|
||
SalaryI18nUtil.getI18nLabel(91075, "离职日期")
|
||
};
|
||
List<Object> headerList = new ArrayList<>(Arrays.asList(header));
|
||
// 查询薪资核算人员(环比上月减少)
|
||
List<SalaryAcctEmployeePO> salaryAcctEmployees = getSalaryAcctEmployeeService(user).listByParam4Reduce(queryParam);
|
||
|
||
// 组装数据
|
||
List<List<Object>> rows = new ArrayList<>();
|
||
rows.add(headerList);
|
||
|
||
// 3.表数据
|
||
List<List<Object>> lists = convert2ExcelRow(salaryAcctEmployees);
|
||
rows.addAll(lists);
|
||
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||
|
||
}
|
||
|
||
|
||
private List<List<Object>> convert2ExcelRow(List<SalaryAcctEmployeePO> salaryAcctEmployees) {
|
||
if (CollectionUtils.isEmpty(salaryAcctEmployees)) {
|
||
return Collections.emptyList();
|
||
}
|
||
List<SalaryAccEmployeeListDTO> salaryAccEmployeeListDTOS = new ArrayList<>();
|
||
List<List<SalaryAcctEmployeePO>> partition = Lists.partition(salaryAcctEmployees, 1000);
|
||
for (List<SalaryAcctEmployeePO> tempList : partition) {
|
||
// 人员
|
||
List<Long> employeeIds = tempList.stream().map(SalaryAcctEmployeePO::getEmployeeId).collect(Collectors.toList());
|
||
List<DataCollectionEmployee> simpleEmployees = getSalaryEmployeeService(user).listByIds(employeeIds);
|
||
// 个税扣缴义务人
|
||
List<Long> taxAgentIds = tempList.stream().map(SalaryAcctEmployeePO::getTaxAgentId).distinct().collect(Collectors.toList());
|
||
List<TaxAgent> taxAgents = taxAgentService.listByIds(taxAgentIds);
|
||
// 转换成列表数据
|
||
salaryAccEmployeeListDTOS.addAll(SalaryAcctEmployeeBO.convert2EmployeeListDTO(tempList, taxAgents, simpleEmployees));
|
||
}
|
||
List<List<Object>> rows = Lists.newArrayListWithExpectedSize(salaryAccEmployeeListDTOS.size());
|
||
for (SalaryAccEmployeeListDTO dto : salaryAccEmployeeListDTOS) {
|
||
List<Object> row = Lists.newArrayListWithExpectedSize(8);
|
||
row.add(dto.getEmployeeName());
|
||
row.add(dto.getTaxAgentName());
|
||
row.add(dto.getDepartmentName());
|
||
row.add(dto.getMobile());
|
||
row.add(dto.getJobNum());
|
||
row.add(dto.getStatus());
|
||
row.add(dto.getHireDate());
|
||
row.add(dto.getDismissDate());
|
||
rows.add(row);
|
||
}
|
||
return rows;
|
||
}
|
||
|
||
@Override
|
||
public XSSFWorkbook exportSalaryAcctResult(SalaryAcctResultQueryParam queryParam) {
|
||
// 查询薪资核算记录
|
||
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(queryParam.getSalaryAcctRecordId());
|
||
if (Objects.isNull(salaryAcctRecordPO)) {
|
||
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
|
||
}
|
||
// 查询列表的表头
|
||
List<WeaTableColumn> weaTableColumns = listWeaTableColumn(salaryAcctRecordPO);
|
||
// excel导出的表头
|
||
String[] headers = weaTableColumns.stream()
|
||
.map(WeaTableColumn::getText)
|
||
.toArray(String[]::new);
|
||
List<Object> headerList = new ArrayList<>(Arrays.asList(headers));
|
||
// 查询薪资核算结果
|
||
List<Map<String, Object>> resultMapList = getSalaryAcctResultService(user).listByParam(queryParam);
|
||
// excel导出的数据
|
||
List<List<Object>> rows = new ArrayList<>();
|
||
rows.add(headerList);
|
||
for (Map<String, Object> map : resultMapList) {
|
||
List<Object> row = Lists.newArrayListWithExpectedSize(weaTableColumns.size());
|
||
for (WeaTableColumn weaTableColumn : weaTableColumns) {
|
||
row.add(map.getOrDefault(weaTableColumn.getColumn(), StringUtils.EMPTY));
|
||
}
|
||
rows.add(row);
|
||
}
|
||
|
||
String sheetName = "薪资核算结果";
|
||
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||
}
|
||
|
||
/**
|
||
* 构建薪资核算结果列表的表头
|
||
*
|
||
* @param salaryAcctRecordPO 薪资核算记录
|
||
* @return
|
||
*/
|
||
public List<WeaTableColumn> listWeaTableColumn(SalaryAcctRecordPO salaryAcctRecordPO) {
|
||
// 查询薪资账套下的薪资项目+员工信息字段
|
||
SalarySobItemAggregateDTO salarySobItemAggregateDTO = getSalarySobItemService(user).getAggregateBySalarySobId(salaryAcctRecordPO.getSalarySobId());
|
||
// 构建薪资核算结果列表表头
|
||
return SalaryAcctResultBO.buildTableColumns(salarySobItemAggregateDTO);
|
||
}
|
||
|
||
// /**
|
||
// * 解析表头
|
||
// *
|
||
// * @param headerList
|
||
// * @param weaTableColumns
|
||
// */
|
||
// private void parseHeader(List<WeaTableColumnWapper> headerList, List<WeaTableColumnWapper> weaTableColumns) {
|
||
// for (WeaTableColumnWapper weaTableColumnWapper : weaTableColumns) {
|
||
// if (CollectionUtils.isEmpty(weaTableColumnWapper.getChildren())) {
|
||
// headerList.add(weaTableColumnWapper);
|
||
// continue;
|
||
// }
|
||
// parseHeader(headerList, weaTableColumnWapper.getChildren());
|
||
// }
|
||
// }
|
||
@Override
|
||
public SalaryAcctImportFieldDTO getImportField(Long salaryAcctRecordId) {
|
||
// 查询薪资核算记录
|
||
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
|
||
if (Objects.isNull(salaryAcctRecordPO)) {
|
||
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
|
||
}
|
||
// 查询薪资核算记录所用的薪资账套的薪资项目副本
|
||
List<SalarySobItemPO> salarySobItems = getSalarySobItemService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
|
||
Set<Long> salaryItemIds = SalaryEntityUtil.properties(salarySobItems, SalarySobItemPO::getSalaryItemId);
|
||
// 查询薪资项目
|
||
List<SalaryItemPO> salaryItems = getSalaryItemService(user).listByIds(salaryItemIds);
|
||
// 薪资项目中的公式项
|
||
List<SalaryAcctImportFieldDTO.ImportFieldDTO> formulaItems = salaryItems.stream()
|
||
.filter(salaryItemPO -> Objects.equals(salaryItemPO.getValueType(), SalaryValueTypeEnum.FORMULA.getValue()))
|
||
.map(salaryItemPO -> SalaryAcctImportFieldDTO.ImportFieldDTO.builder()
|
||
.salaryItemId(salaryItemPO.getId())
|
||
.salaryItemName(salaryItemPO.getName())
|
||
.build())
|
||
.collect(Collectors.toList());
|
||
// 薪资项目中的输入项
|
||
List<SalaryAcctImportFieldDTO.ImportFieldDTO> inputItems = salaryItems.stream()
|
||
.filter(salaryItemPO -> Objects.equals(salaryItemPO.getValueType(), SalaryValueTypeEnum.INPUT.getValue()))
|
||
.map(salaryItemPO -> SalaryAcctImportFieldDTO.ImportFieldDTO.builder()
|
||
.salaryItemId(salaryItemPO.getId())
|
||
.salaryItemName(salaryItemPO.getName())
|
||
.build())
|
||
.collect(Collectors.toList());
|
||
// 转换成dto
|
||
return SalaryAcctImportFieldDTO.builder().formulaItems(formulaItems).inputItems(inputItems).build();
|
||
}
|
||
|
||
@Override
|
||
public XSSFWorkbook exportImportTemplate(SalaryAcctImportTemplateParam param) {
|
||
// 必须选择导入模板所需的薪资项目
|
||
if (CollectionUtils.isEmpty(param.getSalaryItemIds())) {
|
||
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(99019, "参数错误,请选择导入模板所需的薪资项目"));
|
||
}
|
||
// 查询薪资核算记录
|
||
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(param.getSalaryAcctRecordId());
|
||
if (Objects.isNull(salaryAcctRecordPO)) {
|
||
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
|
||
}
|
||
// 模板表头(默认必带"个税扣缴义务人"、"姓名")
|
||
List<Object> headerList = Lists.newArrayList(SalaryI18nUtil.getI18nLabel(85429, "姓名"), SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"));
|
||
List<String> dataIndexList = Lists.newArrayList("username", "taxAgentName");
|
||
// 查询薪资项目
|
||
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listByIds(param.getSalaryItemIds());
|
||
for (SalaryItemPO salaryItemPO : salaryItemPOS) {
|
||
headerList.add(salaryItemPO.getName());
|
||
dataIndexList.add("" + salaryItemPO.getId());
|
||
}
|
||
String[] headers = headerList.toArray(new String[0]);
|
||
|
||
// 查询薪资核算结果
|
||
List<Map<String, Object>> resultMapList = getSalaryAcctResultService(user).listByParam(param);
|
||
// excel导出的数据
|
||
List<List<Object>> rows = Lists.newArrayListWithExpectedSize(resultMapList.size());
|
||
rows.add(headerList);
|
||
for (Map<String, Object> map : resultMapList) {
|
||
List<Object> row = Lists.newArrayListWithExpectedSize(headerList.size());
|
||
for (String dataIndex : dataIndexList) {
|
||
row.add(map.getOrDefault(dataIndex, StringUtils.EMPTY));
|
||
}
|
||
rows.add(row);
|
||
}
|
||
|
||
String sheetName = "薪资核算导入模板";
|
||
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||
}
|
||
|
||
|
||
@Override
|
||
public XSSFWorkbook exportComparisonResult(SalaryComparisonResultQueryParam queryParam) {
|
||
// 查询薪资核算记录
|
||
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(queryParam.getSalaryAcctRecordId());
|
||
if (Objects.isNull(salaryAcctRecordPO)) {
|
||
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
|
||
}
|
||
// 查询线下对比结果
|
||
SalaryComparisonResultListDTO salaryComparisonResultListDTO = getSalaryComparisonResultService(user).listByParam(queryParam);
|
||
// 薪资核算线下对比结果列表表头
|
||
List<Object> headerList = Lists.newArrayList();
|
||
// 查询薪资核算所用的薪资账套的员工信息字段
|
||
List<SalarySobEmpFieldPO> salarySobEmpFieldPOS = getSalarySobEmpFieldService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
|
||
Set<String> employeeFieldCodeSet = SalaryEntityUtil.properties(salarySobEmpFieldPOS, SalarySobEmpFieldPO::getFieldCode);
|
||
// 查询薪资项目
|
||
List<SalaryItemPO> salaryItemPOS = getSalarySobItemService(user).listBySalarySobId4SalaryItem(salaryAcctRecordPO.getSalarySobId());
|
||
Set<String> salaryItemIds = SalaryEntityUtil.properties(salaryItemPOS, salaryItemPO -> "" + salaryItemPO.getId());
|
||
for (WeaTableColumn weaTableColumn : salaryComparisonResultListDTO.getWeaTableColumns()) {
|
||
// 员工信息字段
|
||
if (employeeFieldCodeSet.contains(weaTableColumn.getColumn())) {
|
||
headerList.add(weaTableColumn.getText());
|
||
}
|
||
// 薪资项目的表头
|
||
if (salaryItemIds.contains(weaTableColumn.getColumn())) {
|
||
headerList.add(weaTableColumn.getText() + " (线上值)");
|
||
headerList.add(weaTableColumn.getText() + " (线下值)");
|
||
}
|
||
}
|
||
|
||
List<Map<String, Object>> resultMapList = salaryComparisonResultListDTO.getData().getList();
|
||
// excel导出的数据
|
||
List<List<Object>> rows = new ArrayList<>();
|
||
rows.add(headerList);
|
||
for (Map<String, Object> map : resultMapList) {
|
||
List<Object> row = Lists.newArrayList();
|
||
for (WeaTableColumn weaTableColumn : salaryComparisonResultListDTO.getWeaTableColumns()) {
|
||
// 员工信息字段的值
|
||
if (employeeFieldCodeSet.contains(weaTableColumn.getColumn())) {
|
||
row.add(map.get(weaTableColumn.getColumn()));
|
||
}
|
||
// 薪资项目的值
|
||
if (salaryItemIds.contains(weaTableColumn.getColumn())) {
|
||
Map tempMap = (Map) map.getOrDefault(weaTableColumn.getColumn(), Collections.emptyMap());
|
||
row.add(tempMap.get("acctResultValue"));
|
||
row.add(tempMap.get("excelResultValue"));
|
||
}
|
||
}
|
||
rows.add(row);
|
||
}
|
||
|
||
String sheetName = "线下对比结果";
|
||
|
||
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||
}
|
||
//
|
||
//
|
||
// @Override
|
||
// public XSSFWorkbook exportComparisonResultTemplate(SalaryComparisonResultExportParam exportParam) {
|
||
// // 查询薪资核算记录
|
||
// SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(exportParam.getSalaryAcctRecordId());
|
||
// if (Objects.isNull(salaryAcctRecordPO)) {
|
||
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
|
||
// }
|
||
// // 模板表头(默认必带"个税扣缴义务人"、"姓名")
|
||
// List<Object> headerList = Lists.newArrayList(SalaryI18nUtil.getI18nLabel(85429, "姓名"), SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"));
|
||
// // 查询薪资账套下的薪资项目
|
||
// SalarySobItemAggregateDTO salarySobItemAggregateDTO = getSalarySobItemService(user).getAggregateBySalarySobId(salaryAcctRecordPO.getSalarySobId());
|
||
// // 薪资项目分类下的新资项目
|
||
// for (SalarySobItemGroupDTO itemGroup : salarySobItemAggregateDTO.getItemGroups()) {
|
||
// for (SalarySobItemDTO item : itemGroup.getItems()) {
|
||
// headerList.add(item.getName());
|
||
// }
|
||
// }
|
||
// // 没有分类的薪资项目
|
||
// for (SalarySobItemDTO item : salarySobItemAggregateDTO.getItems()) {
|
||
// headerList.add(item.getName());
|
||
// }
|
||
// List<List<Object>> rows = new ArrayList<>();
|
||
// rows.add(headerList);
|
||
// String sheetName = "线下对比结果导入模板";
|
||
//
|
||
// return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||
// }
|
||
//
|
||
//
|
||
//
|
||
// @BatchImportHandler("importSalaryAcctResult")
|
||
// @Transactional(rollbackFor = Exception.class)
|
||
// public void importSalaryAcctResult() {
|
||
// BatchDocumentMessage message = BatchImportContext.getBatchDocumentMessage();
|
||
// String tenantKey = message.getTenantKey();
|
||
// try {
|
||
// // 加密用
|
||
// DSTenantKeyThreadVar.tenantKey.set(tenantKey);
|
||
// // 接收到解析的数据
|
||
// batchImport(message, "importSalaryAcctResult");
|
||
// } catch (Exception e) {
|
||
// log.error("薪资核算结果导入失败:{}", e.getMessage(), e);
|
||
// } finally {
|
||
// DSTenantKeyThreadVar.tenantKey.remove();
|
||
// }
|
||
// }
|
||
//
|
||
// @BatchImportHandler("importExcelAcctResult")
|
||
// @Transactional(rollbackFor = Exception.class)
|
||
// public void importExcelAcctResult() {
|
||
// BatchDocumentMessage message = BatchImportContext.getBatchDocumentMessage();
|
||
// String tenantKey = message.getTenantKey();
|
||
// try {
|
||
// // 加密用
|
||
// DSTenantKeyThreadVar.tenantKey.set(tenantKey);
|
||
// // 接收到解析的数据
|
||
// batchImport(message, "importExcelAcctResult");
|
||
// } catch (Exception e) {
|
||
// log.error("线下核算结果导入失败:{}", e.getMessage(), e);
|
||
// } finally {
|
||
// // 加密用
|
||
// DSTenantKeyThreadVar.tenantKey.remove();
|
||
// }
|
||
// }
|
||
//
|
||
// private void batchImport(BatchDocumentMessage message, String importType) {
|
||
// String tenantKey = message.getTenantKey();
|
||
// Long currentEmployeeId = message.getUserId();
|
||
// LocalDateTime now = LocalDateTime.now();
|
||
// // 前端传入的参数(薪资核算记录的id)
|
||
// Map<String, Object> paramMap = JsonUtil.parseMap(message.getUploadSet().getCustomData(), Object.class);
|
||
// // 薪资核算记录的id
|
||
// Long salaryAcctRecordId = Long.valueOf(String.valueOf(paramMap.get("salaryAcctRecordId")));
|
||
// // 薪资核算记录
|
||
// SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
|
||
// if (salaryAcctRecordPO == null) {
|
||
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
|
||
// }
|
||
// // 薪资账套下的薪资项目副本
|
||
// List<SalarySobItemPO> salarySobItemPOS = getSalarySobItemService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
|
||
// // 薪资项目
|
||
// Set<Long> salaryItemIds = SalaryEntityUtil.properties(salarySobItemPOS, SalarySobItemPO::getSalaryItemId);
|
||
// List<SalaryItemPO> salaryItems = getSalaryItemService(user).listByIds(salaryItemIds);
|
||
// Map<String, Long> salaryItemMap = SalaryEntityUtil.convert2Map(salaryItems, SalaryItemPO::getName, SalaryItemPO::getId);
|
||
// // 薪资核算确认的人员
|
||
// List<SalaryAcctEmployeePO> salaryAcctEmployees = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordId(salaryAcctRecordId);
|
||
// Map<String, SalaryAcctEmployeePO> salaryAcctEmployeeMap = SalaryEntityUtil.convert2Map(salaryAcctEmployees, e -> e.getEmployeeId() + "-" + e.getTaxAgentId());
|
||
// // 租户下所有的人员
|
||
// List<SalaryEmployee> salaryEmployees = getSalaryEmployeeService(user).listAll(tenantKey);
|
||
// Map<String, Long> salaryEmployeeMap = SalaryEntityUtil.convert2Map(salaryEmployees, SalaryEmployee::getUsername, SalaryEmployee::getId);
|
||
// // 租户下所有的个税扣缴义务人
|
||
// List<TaxAgentPO> taxAgents = taxAgentService.listAll(tenantKey);
|
||
// Map<String, Long> taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgents, TaxAgentPO::getName, TaxAgentPO::getId);
|
||
//
|
||
// // 索引(用于计算进度)
|
||
// int index = 0;
|
||
// // 失败的数量
|
||
// int failCount = 0;
|
||
// // 成功的数量
|
||
// int successCount = 0;
|
||
// // 总数
|
||
// int total = message.getBatchFile().getExcelSheets().stream()
|
||
// .filter(e -> CollectionUtils.isNotEmpty(e.getHeader()) && CollectionUtils.isNotEmpty(e.getData()))
|
||
// .map(e -> BigDecimal.valueOf(e.getData().size()))
|
||
// .reduce(BigDecimal.ZERO, BigDecimal::add)
|
||
// .intValue();
|
||
// // 包含错误提示信息的sheet页
|
||
// List<ExcelSheet> errorExcelSheets = Lists.newArrayList();
|
||
// // 解析excel
|
||
// Set<Long> salaryAcctEmpIds = Sets.newHashSet();
|
||
// // excel导入了哪些薪资项目
|
||
// Set<Long> excelSalaryItemIds = Sets.newHashSet();
|
||
// List<SalaryAcctResultPO> salaryAcctResults = Lists.newArrayList();
|
||
// List<SalaryAcctEmployeePO> newSalaryAcctEmployees = Lists.newArrayList();
|
||
//
|
||
// List<ExcelAcctResultPO> excelAcctResults = Lists.newArrayList();
|
||
// for (ExcelSheet excelSheet : message.getBatchFile().getExcelSheets()) {
|
||
// if (CollectionUtils.isEmpty(excelSheet.getHeader())) {
|
||
// continue;
|
||
// }
|
||
// // 错误提示信息
|
||
// List<ExcelComment> excelComments = Lists.newArrayList();
|
||
// // 存在错误的那行数据
|
||
// List<Map<String, Object>> errorDatas = Lists.newArrayList();
|
||
// // 表头
|
||
// List<Map> headers = excelSheet.getHeader();
|
||
// // 处理数值
|
||
// List<Map<String, Object>> data = excelSheet.getData();
|
||
// if (CollectionUtils.isEmpty(data)) {
|
||
// continue;
|
||
// }
|
||
// for (int i = 0; i < data.size(); i++) {
|
||
// int usernameIndex = 0;
|
||
// boolean isError = false;
|
||
// Map<String, Object> map = data.get(i);
|
||
// Long employeeId = 0L;
|
||
// Long taxAgentId = 0L;
|
||
// List<SalaryAcctResultPO> salaryAcctResultsOfOneEmp = Lists.newArrayListWithExpectedSize(headers.size() - 1);
|
||
// List<ExcelAcctResultPO> excelAcctResultsOfOneEmp = Lists.newArrayListWithExpectedSize(headers.size() - 1);
|
||
// for (int j = 0; j < headers.size(); j++) {
|
||
// Map header = headers.get(j);
|
||
// Object dataKey = header.get("key");
|
||
// if (dataKey == null) {
|
||
// continue;
|
||
// }
|
||
// String dataValue = (String) map.getOrDefault(dataKey.toString(), "");
|
||
// if (StringUtils.equals(SalaryI18nUtil.getI18nLabel(85429, "姓名"), dataKey.toString())) {
|
||
// usernameIndex = j;
|
||
// if (StringUtils.isEmpty(dataValue)) {
|
||
// isError = true;
|
||
// salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(102838, "姓名不能为空"), i, i, j, j);
|
||
// } else {
|
||
// employeeId = salaryEmployeeMap.getOrDefault(dataValue, 0L);
|
||
// if (employeeId == null || employeeId <= 0) {
|
||
// isError = true;
|
||
// salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(100579, "姓名错误,系统内不存在该姓名"), i, i, j, j);
|
||
// }
|
||
// }
|
||
// } else if (StringUtils.equals(SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"), dataKey.toString())) {
|
||
// if (StringUtils.isEmpty(dataValue)) {
|
||
// isError = true;
|
||
// salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(102839, "个税扣缴义务人不能为空"), i, i, j, j);
|
||
// } else {
|
||
// taxAgentId = taxAgentNameMap.getOrDefault(dataValue, 0L);
|
||
// if (taxAgentId == null || taxAgentId <= 0) {
|
||
// isError = true;
|
||
// salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(102840, "个税扣缴义务人错误,系统内不存在该个税扣缴义务人"), i, i, j, j);
|
||
// }
|
||
// }
|
||
// } else {
|
||
// Long salaryItemId = salaryItemMap.get(dataKey.toString());
|
||
// if (salaryItemId == null || salaryItemId <= 0) {
|
||
// isError = true;
|
||
// salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(102841, "表头错误,本次核算所用账套不包含该薪资项目"), i, i, j, j);
|
||
// } else {
|
||
// excelSalaryItemIds.add(salaryItemId);
|
||
// if (StringUtils.equals("importExcelAcctResult", importType)) {
|
||
// ExcelAcctResultPO excelAcctResult = ExcelAcctResultPO.builder()
|
||
// .id(IdGenerator.generate())
|
||
// .salaryAcctRecordId(salaryAcctRecordPO.getId())
|
||
// .salarySobId(salaryAcctRecordPO.getSalarySobId())
|
||
// .salaryItemId(salaryItemId)
|
||
// .resultValue(dataValue)
|
||
// .creator(currentEmployeeId)
|
||
// .createTime(now)
|
||
// .updateTime(now)
|
||
// .deleteType(0)
|
||
// .tenantKey(tenantKey)
|
||
// .build();
|
||
// excelAcctResultsOfOneEmp.add(excelAcctResult);
|
||
// }
|
||
// if (StringUtils.equals("importSalaryAcctResult", importType)) {
|
||
// SalaryAcctResultPO salaryAcctResult = SalaryAcctResultPO.builder()
|
||
// .id(IdGenerator.generate())
|
||
// .salaryAcctRecordId(salaryAcctRecordPO.getId())
|
||
// .salarySobId(salaryAcctRecordPO.getSalarySobId())
|
||
// .salaryItemId(salaryItemId)
|
||
// .resultValue(dataValue)
|
||
// .creator(currentEmployeeId)
|
||
// .createTime(now)
|
||
// .updateTime(now)
|
||
// .deleteType(0)
|
||
// .tenantKey(tenantKey)
|
||
// .build();
|
||
// salaryAcctResultsOfOneEmp.add(salaryAcctResult);
|
||
// }
|
||
// }
|
||
// }
|
||
// // (如果是线下对比)如果个税扣缴义务人+人员目前不在核算人员里面,不支持导入
|
||
// if (StringUtils.equals("importExcelAcctResult", importType)
|
||
// && (employeeId != null && employeeId > 0)
|
||
// && (taxAgentId != null && taxAgentId > 0)
|
||
// && i == data.size() - 1
|
||
// && !salaryAcctEmployeeMap.containsKey(employeeId + "-" + taxAgentId)) {
|
||
// isError = true;
|
||
// salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(102842, "本次薪资核算不包含该人员"), i, i, usernameIndex, usernameIndex);
|
||
// }
|
||
// }
|
||
// // 每处理50个数据更新一次进度
|
||
// index++;
|
||
// if (index % 50 == 0 || index >= total) {
|
||
// salaryBatchService.sendImportRate(message.getBizId(), total, index);
|
||
// }
|
||
// if (isError) {
|
||
// failCount++;
|
||
// errorDatas.add(map);
|
||
// continue;
|
||
// }
|
||
// SalaryAcctEmployeePO salaryAcctEmployee = salaryAcctEmployeeMap.get(employeeId + "-" + taxAgentId);
|
||
// Long salaryAcctEmpId = Optional.ofNullable(salaryAcctEmployee).map(SalaryAcctEmployeePO::getId).orElse(0L);
|
||
// if (StringUtils.equals("importExcelAcctResult", importType)) {
|
||
// for (ExcelAcctResultPO excelAcctResultPO : excelAcctResultsOfOneEmp) {
|
||
// excelAcctResultPO.setEmployeeId(employeeId);
|
||
// excelAcctResultPO.setTaxAgentId(taxAgentId);
|
||
// excelAcctResultPO.setSalaryAcctEmpId(salaryAcctEmpId);
|
||
// }
|
||
// excelAcctResults.addAll(excelAcctResultsOfOneEmp);
|
||
// }
|
||
// if (StringUtils.equals("importSalaryAcctResult", importType)) {
|
||
// if (salaryAcctEmpId <= 0) {
|
||
// SalaryAcctEmployeePO acctEmployee = SalaryAcctEmployeePO.builder()
|
||
// .id(IdGenerator.generate())
|
||
// .employeeId(employeeId)
|
||
// .salaryAcctRecordId(salaryAcctRecordId)
|
||
// .salarySobId(salaryAcctRecordPO.getSalarySobId())
|
||
// .salaryMonth(salaryAcctRecordPO.getSalaryMonth())
|
||
// .taxAgentId(taxAgentId)
|
||
// .creator(currentEmployeeId)
|
||
// .createTime(now)
|
||
// .updateTime(now)
|
||
// .deleteType(0)
|
||
// .tenantKey(tenantKey)
|
||
// .build();
|
||
// newSalaryAcctEmployees.add(acctEmployee);
|
||
// salaryAcctEmpId = acctEmployee.getId();
|
||
// }
|
||
// for (SalaryAcctResultPO salaryAcctResultPO : salaryAcctResultsOfOneEmp) {
|
||
// salaryAcctResultPO.setEmployeeId(employeeId);
|
||
// salaryAcctResultPO.setTaxAgentId(taxAgentId);
|
||
// salaryAcctResultPO.setSalaryAcctEmpId(salaryAcctEmpId);
|
||
// }
|
||
// salaryAcctEmpIds.add(salaryAcctEmpId);
|
||
// salaryAcctResults.addAll(salaryAcctResultsOfOneEmp);
|
||
// }
|
||
// successCount++;
|
||
// }
|
||
// // 如果sheet包含错误数据
|
||
// if (CollectionUtils.isNotEmpty(errorDatas)) {
|
||
// salaryBatchService.createErrorExcelSheet(headers, errorDatas, excelSheet.getName(), excelComments, errorExcelSheets);
|
||
// }
|
||
// }
|
||
// if (StringUtils.equals("importExcelAcctResult", importType)) {
|
||
// getSalaryComparisonResultService(user).deleteBySalaryAcctRecordIds(Collections.singleton(salaryAcctRecordId));
|
||
// if (CollectionUtils.isNotEmpty(excelAcctResults)) {
|
||
// getSalaryComparisonResultService(user).batchSave(excelAcctResults);
|
||
// }
|
||
// }
|
||
// if (StringUtils.equals("importSalaryAcctResult", importType)) {
|
||
// if (CollectionUtils.isNotEmpty(salaryAcctEmpIds)) {
|
||
// getSalaryAcctResultService(user).deleteByAcctEmployeeIdsAndSalaryItemIds(salaryAcctEmpIds, excelSalaryItemIds);
|
||
// }
|
||
// if (CollectionUtils.isNotEmpty(salaryAcctResults)) {
|
||
// getSalaryAcctResultService(user).batchSave(salaryAcctResults);
|
||
// }
|
||
// if (CollectionUtils.isNotEmpty(newSalaryAcctEmployees)) {
|
||
// getSalaryAcctEmployeeService(user).batchSave(newSalaryAcctEmployees);
|
||
// }
|
||
// }
|
||
// // 发送导入回调信息
|
||
// salaryBatchService.sendImportCallBackInfo(message, successCount, failCount, errorExcelSheets);
|
||
// }
|
||
//
|
||
// @Override
|
||
// public Map<String, Object> exportCheckResult(
|
||
// SalaryCheckResultExportParam exportParam,
|
||
// ) {
|
||
// // 查询薪资核算结果校验异常
|
||
// List<SalaryCheckResultPO> salaryCheckResults = salaryCheckResultService.listBySalaryAcctRecordId(exportParam.getSalaryAcctRecordId());
|
||
// List<ExcelSheetData> excelSheetData = Lists.newArrayListWithExpectedSize(salaryCheckResults.size());
|
||
// for (SalaryCheckResultPO salaryCheckResult : salaryCheckResults) {
|
||
// excelSheetData.add(buildDetailExcelSheetData(salaryCheckResult, simpleEmployee.getEmployeeId()));
|
||
// }
|
||
// ExportExcelInfo exportExcelInfo = ExportExcelInfo.builder()
|
||
// .fileName("校验异常")
|
||
// .dataType("校验异常")
|
||
// .function(excelExportParam.getFunction())
|
||
// .handlerName("salaryCheckResultHandler")
|
||
// .flag(true)
|
||
// .bizId(String.valueOf(excelExportParam.getBiz()))
|
||
// .module(excelExportParam.getModule())
|
||
// .userId(simpleEmployee.getEmployeeId())
|
||
// .tenantKey(tenantKey)
|
||
// .operator(simpleEmployee.getUsername())
|
||
// .eteamsId(eteamsId)
|
||
// .build();
|
||
// return salaryBatchService.simpleExportExcel(exportExcelInfo, excelSheetData);
|
||
// }
|
||
//
|
||
// @BatchExportHandler("salaryCheckResultHandler")
|
||
// private void salaryCheckResultHandler() {
|
||
// BatchCallbackMessage message = BatchExportContext.getBatchCallbackMessage();
|
||
// log.info("导出结束:{}", JsonUtil.toJsonString(message));
|
||
// }
|
||
//
|
||
// @Override
|
||
// public Map<String, Object> exportCheckResultDetail(
|
||
// Long checkResultId,
|
||
// ) {
|
||
// // 查询校验异常
|
||
// SalaryCheckResultPO checkResult = salaryCheckResultService.getById(checkResultId);
|
||
// // 查询校验异常明细
|
||
// ExcelSheetData excelSheetData = buildDetailExcelSheetData(checkResult, simpleEmployee.getEmployeeId());
|
||
// ExportExcelInfo exportExcelInfo = ExportExcelInfo.builder()
|
||
// .fileName("校验异常明细")
|
||
// .dataType("校验异常明细")
|
||
// .function(excelExportParam.getFunction())
|
||
// .handlerName("salaryCheckResultDetailHandler")
|
||
// .flag(true)
|
||
// .bizId(String.valueOf(excelExportParam.getBiz()))
|
||
// .module(excelExportParam.getModule())
|
||
// .userId(simpleEmployee.getEmployeeId())
|
||
// .tenantKey(tenantKey)
|
||
// .operator(simpleEmployee.getUsername())
|
||
// .eteamsId(eteamsId)
|
||
// .build();
|
||
// return salaryBatchService.simpleExportExcel(exportExcelInfo, Collections.singletonList(excelSheetData));
|
||
// }
|
||
//
|
||
// @BatchExportHandler("salaryCheckResultDetailHandler")
|
||
// private void salaryCheckResultDetailHandler() {
|
||
// BatchCallbackMessage message = BatchExportContext.getBatchCallbackMessage();
|
||
// log.info("导出结束:{}", JsonUtil.toJsonString(message));
|
||
// }
|
||
//
|
||
// private ExcelSheetData buildDetailExcelSheetData(SalaryCheckResultPO checkResult, Long employeeId) {
|
||
// // 查询校验异常中的校验规则
|
||
// SalarySobCheckRulePO checkRule = salarySobCheckRuleService.getById(checkResult.getSalaryCheckRuleId());
|
||
// // 查询校验异常明细
|
||
// List<SalaryCheckResultRecordPO> salaryCheckResultRecords = salaryCheckResultDetailService.listByCheckResultId(checkResult.getId());
|
||
// String[] headers = new String[]{"规则名称", "规则内容", "姓名"};
|
||
// List<List<Object>> rows = Lists.newArrayList();
|
||
// ExcelSheetData excelSheetData = new ExcelSheetData();
|
||
// excelSheetData.setSheetName("校验异常");
|
||
// excelSheetData.setHeaders(Collections.singletonList(headers));
|
||
// excelSheetData.setRows(rows);
|
||
// if (CollectionUtils.isEmpty(salaryCheckResultRecords)) {
|
||
// return excelSheetData;
|
||
// }
|
||
// List<Long> employeeIds = SalaryEntityUtil.properties(salaryCheckResultRecords, SalaryCheckResultRecordPO::getEmployeeId, Collectors.toList());
|
||
// List<SimpleEmployee> simpleEmployees = hrmCommonEmployeeService.getEmployeeByIds(employeeIds);
|
||
// Map<Long, String> simpleEmployeeMap = SalaryEntityUtil.convert2Map(simpleEmployees, SimpleEmployee::getEmployeeId, SimpleEmployee::getUsername);
|
||
// List<ExpressFormula> expressFormulas = getSalaryFormulaService(user).listExpressFormula(Collections.singleton(checkResult.getFormulaId()));
|
||
// Map<Long, String> formulaMap = SalaryEntityUtil.convert2Map(expressFormulas, ExpressFormula::getId, ExpressFormula::getFormula);
|
||
// for (SalaryCheckResultRecordPO salaryCheckResultRecord : salaryCheckResultRecords) {
|
||
// List<Object> row = Lists.newArrayListWithExpectedSize(3);
|
||
// row.add(checkRule.getName());
|
||
// row.add(formulaMap.getOrDefault(salaryCheckResultRecord.getFormulaId(), ""));
|
||
// row.add(simpleEmployeeMap.getOrDefault(salaryCheckResultRecord.getEmployeeId(), ""));
|
||
// rows.add(row);
|
||
// }
|
||
// return excelSheetData;
|
||
// }
|
||
}
|