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.constant.SalaryDefaultTenantConstant; 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.*; import com.engine.salary.entity.salaryacct.po.ExcelAcctResultPO; import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO; import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO; import com.engine.salary.entity.salaryacct.po.SalaryAcctResultPO; import com.engine.salary.entity.salaryitem.po.SalaryItemPO; import com.engine.salary.entity.salarysob.dto.SalarySobItemAggregateDTO; import com.engine.salary.entity.salarysob.dto.SalarySobItemDTO; import com.engine.salary.entity.salarysob.dto.SalarySobItemGroupDTO; 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.ExcelParseHelper; import com.engine.salary.util.excel.ExcelSupport; import com.engine.salary.util.excel.ExcelUtil; import com.engine.salary.util.valid.ValidUtil; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.file.ImageFileManager; import weaver.hrm.User; import java.io.InputStream; import java.util.*; import java.util.stream.Collectors; import static com.engine.salary.util.excel.ExcelSupport.EXCEL_TYPE_XLSX; /** * 薪资核算导入导出 *

Copyright: Copyright (c) 2022

*

Company: 泛微软件

* * @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 headerList = new ArrayList<>(Arrays.asList(header)); // 查询薪资核算人员 List salaryAcctEmployees = getSalaryAcctEmployeeService(user).listByParam(queryParam); // 组装数据 List> rows = new ArrayList<>(); rows.add(headerList); // 3.表数据 List> 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 headerList = new ArrayList<>(Arrays.asList(header)); // 查询薪资核算人员(环比上月减少) List salaryAcctEmployees = getSalaryAcctEmployeeService(user).listByParam4Reduce(queryParam); // 组装数据 List> rows = new ArrayList<>(); rows.add(headerList); // 3.表数据 List> lists = convert2ExcelRow(salaryAcctEmployees); rows.addAll(lists); return ExcelUtil.genWorkbookV2(rows, sheetName); } private List> convert2ExcelRow(List salaryAcctEmployees) { if (CollectionUtils.isEmpty(salaryAcctEmployees)) { return Collections.emptyList(); } List salaryAccEmployeeListDTOS = new ArrayList<>(); List> partition = Lists.partition(salaryAcctEmployees, 1000); for (List tempList : partition) { // 人员 List employeeIds = tempList.stream().map(SalaryAcctEmployeePO::getEmployeeId).collect(Collectors.toList()); List simpleEmployees = getSalaryEmployeeService(user).listByIds(employeeIds); // 个税扣缴义务人 List taxAgentIds = tempList.stream().map(SalaryAcctEmployeePO::getTaxAgentId).distinct().collect(Collectors.toList()); List taxAgents = taxAgentService.listByIds(taxAgentIds); // 转换成列表数据 salaryAccEmployeeListDTOS.addAll(SalaryAcctEmployeeBO.convert2EmployeeListDTO(tempList, taxAgents, simpleEmployees)); } List> rows = Lists.newArrayListWithExpectedSize(salaryAccEmployeeListDTOS.size()); for (SalaryAccEmployeeListDTO dto : salaryAccEmployeeListDTOS) { List 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 weaTableColumns = listWeaTableColumn(salaryAcctRecordPO); // excel导出的表头 String[] headers = weaTableColumns.stream() .map(WeaTableColumn::getText) .toArray(String[]::new); List headerList = new ArrayList<>(Arrays.asList(headers)); // 查询薪资核算结果 List> resultMapList = getSalaryAcctResultService(user).listByParam(queryParam); // excel导出的数据 List> rows = new ArrayList<>(); rows.add(headerList); for (Map map : resultMapList) { List 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 listWeaTableColumn(SalaryAcctRecordPO salaryAcctRecordPO) { // 查询薪资账套下的薪资项目+员工信息字段 SalarySobItemAggregateDTO salarySobItemAggregateDTO = getSalarySobItemService(user).getAggregateBySalarySobId(salaryAcctRecordPO.getSalarySobId()); // 构建薪资核算结果列表表头 return SalaryAcctResultBO.buildTableColumns(salarySobItemAggregateDTO); } // /** // * 解析表头 // * // * @param headerList // * @param weaTableColumns // */ // private void parseHeader(List headerList, List 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 salarySobItems = getSalarySobItemService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId()); Set salaryItemIds = SalaryEntityUtil.properties(salarySobItems, SalarySobItemPO::getSalaryItemId); // 查询薪资项目 List salaryItems = getSalaryItemService(user).listByIds(salaryItemIds); // 薪资项目中的公式项 List 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 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 headerList = Lists.newArrayList(SalaryI18nUtil.getI18nLabel(85429, "姓名"), SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人")); List dataIndexList = Lists.newArrayList("username", "taxAgentName"); // 查询薪资项目 List salaryItemPOS = getSalaryItemService(user).listByIds(param.getSalaryItemIds()); for (SalaryItemPO salaryItemPO : salaryItemPOS) { headerList.add(salaryItemPO.getName()); dataIndexList.add("" + salaryItemPO.getId()); } // 查询薪资核算结果 List> resultMapList = getSalaryAcctResultService(user).listByParam(param); // excel导出的数据 List> rows = Lists.newArrayListWithExpectedSize(resultMapList.size()); rows.add(headerList); for (Map map : resultMapList) { List 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 headerList = Lists.newArrayList(); // 查询薪资核算所用的薪资账套的员工信息字段 List salarySobEmpFieldPOS = getSalarySobEmpFieldService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId()); Set employeeFieldCodeSet = SalaryEntityUtil.properties(salarySobEmpFieldPOS, SalarySobEmpFieldPO::getFieldCode); // 查询薪资项目 List salaryItemPOS = getSalarySobItemService(user).listBySalarySobId4SalaryItem(salaryAcctRecordPO.getSalarySobId()); Set 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> resultMapList = salaryComparisonResultListDTO.getData().getList(); // excel导出的数据 List> rows = new ArrayList<>(); rows.add(headerList); for (Map map : resultMapList) { List 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) { ValidUtil.doValidator(exportParam); // 查询薪资核算记录 SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(exportParam.getSalaryAcctRecordId()); if (Objects.isNull(salaryAcctRecordPO)) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除")); } // 模板表头(默认必带"个税扣缴义务人"、"姓名") List 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> rows = new ArrayList<>(); rows.add(headerList); String sheetName = "线下对比结果导入模板"; return ExcelUtil.genWorkbookV2(rows, sheetName); } public Map importSalaryAcctResult(SalaryAcctImportParam param) { return batchImport(param, "importSalaryAcctResult"); } public Map importExcelAcctResult(SalaryAcctImportParam param) { return batchImport(param, "importExcelAcctResult"); } private Map batchImport(SalaryAcctImportParam param, String importType) { Map apidatas = new HashMap(); ValidUtil.doValidator(param); Date now = new Date(); Long currentEmployeeId = (long) user.getUID(); // 薪资核算记录的id Long salaryAcctRecordId = param.getSalaryAcctRecordId(); // 薪资核算记录 SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId); if (salaryAcctRecordPO == null) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除")); } // 薪资账套下的薪资项目副本 List salarySobItemPOS = getSalarySobItemService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId()); // 薪资项目 Set salaryItemIds = SalaryEntityUtil.properties(salarySobItemPOS, SalarySobItemPO::getSalaryItemId); List salaryItems = getSalaryItemService(user).listByIds(salaryItemIds); Map salaryItemMap = SalaryEntityUtil.convert2Map(salaryItems, SalaryItemPO::getName, SalaryItemPO::getId); // 薪资核算确认的人员 List salaryAcctEmployees = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordId(salaryAcctRecordId); Map salaryAcctEmployeeMap = SalaryEntityUtil.convert2Map(salaryAcctEmployees, e -> e.getEmployeeId() + "-" + e.getTaxAgentId()); // 租户下所有的人员 List salaryEmployees = getSalaryEmployeeService(user).listAll(); Map salaryEmployeeMap = SalaryEntityUtil.convert2Map(salaryEmployees, DataCollectionEmployee::getUsername, DataCollectionEmployee::getEmployeeId); // 租户下所有的个税扣缴义务人 List taxAgents = taxAgentService.listAll(); Map taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgents, TaxAgent::getName, TaxAgent::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> errorExcelSheets = Lists.newArrayList(); // 解析excel Set salaryAcctEmpIds = Sets.newHashSet(); // excel导入了哪些薪资项目 Set excelSalaryItemIds = Sets.newHashSet(); List salaryAcctResults = Lists.newArrayList(); List newSalaryAcctEmployees = Lists.newArrayList(); List excelAcctResults = Lists.newArrayList(); InputStream fileInputStream = null; try { fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(param.getImageId())); Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLSX); // 错误提示信息 List excelComments = Lists.newArrayList(); // 存在错误的那行数据 List> errorDatas = Lists.newArrayList(); // 表头 List headers = ExcelSupport.getSheetHeader(sheet, 0); // 处理数值 List> data = ExcelParseHelper.parse2Map(sheet, 1); if (CollectionUtils.isEmpty(headers)) { throw new RuntimeException("表头为空"); } if (CollectionUtils.isEmpty(data)) { throw new RuntimeException("无数据"); } for (int i = 0; i < data.size(); i++) { int usernameIndex = 0; boolean isError = false; Map map = data.get(i); Long employeeId = 0L; Long taxAgentId = 0L; List salaryAcctResultsOfOneEmp = Lists.newArrayListWithExpectedSize(headers.size() - 1); List excelAcctResultsOfOneEmp = Lists.newArrayListWithExpectedSize(headers.size() - 1); for (int j = 0; j < headers.size(); j++) { String header = headers.get(j); String dataKey = header; 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; Map errorMessageMap = Maps.newHashMap(); errorMessageMap.put("message", SalaryI18nUtil.getI18nLabel(102838, "姓名不能为空")); excelComments.add(errorMessageMap); //salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(102838, "姓名不能为空"), i, i, j, j); } else { employeeId = salaryEmployeeMap.getOrDefault(dataValue, 0L); if (employeeId == null || employeeId <= 0) { isError = true; Map errorMessageMap = Maps.newHashMap(); errorMessageMap.put("message", SalaryI18nUtil.getI18nLabel(100579, "姓名错误,系统内不存在该姓名")); excelComments.add(errorMessageMap); // 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; Map errorMessageMap = Maps.newHashMap(); errorMessageMap.put("message", SalaryI18nUtil.getI18nLabel(100579, SalaryI18nUtil.getI18nLabel(102839, "个税扣缴义务人不能为空"))); excelComments.add(errorMessageMap); // salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(102839, "个税扣缴义务人不能为空"), i, i, j, j); } else { taxAgentId = taxAgentNameMap.getOrDefault(dataValue, 0L); if (taxAgentId == null || taxAgentId <= 0) { isError = true; Map errorMessageMap = Maps.newHashMap(); errorMessageMap.put("message", SalaryI18nUtil.getI18nLabel(100579, SalaryI18nUtil.getI18nLabel(102840, "个税扣缴义务人错误,系统内不存在该个税扣缴义务人"))); excelComments.add(errorMessageMap); // salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(102840, "个税扣缴义务人错误,系统内不存在该个税扣缴义务人"), i, i, j, j); } } } else { Long salaryItemId = salaryItemMap.get(dataKey.toString()); if (salaryItemId == null || salaryItemId <= 0) { isError = true; Map errorMessageMap = Maps.newHashMap(); errorMessageMap.put("message", SalaryI18nUtil.getI18nLabel(100579, SalaryI18nUtil.getI18nLabel(102840, "本次核算所用账套不包含该薪资项目"))); excelComments.add(errorMessageMap); // 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(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY) .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(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY) .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; Map errorMessageMap = Maps.newHashMap(); errorMessageMap.put("message", SalaryI18nUtil.getI18nLabel(100579, SalaryI18nUtil.getI18nLabel(102840, "本次薪资核算不包含该人员"))); excelComments.add(errorMessageMap); // 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(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY) .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); } } apidatas.put("successCount", successCount); apidatas.put("errorCount", failCount); apidatas.put("errorData", excelComments); } finally { IOUtils.closeQuietly(fileInputStream); } // 发送导入回调信息 // salaryBatchService.sendImportCallBackInfo(message, successCount, failCount, errorExcelSheets); return apidatas; } // @Override // public Map exportCheckResult( // SalaryCheckResultExportParam exportParam, // ) { // // 查询薪资核算结果校验异常 // List salaryCheckResults = salaryCheckResultService.listBySalaryAcctRecordId(exportParam.getSalaryAcctRecordId()); // List 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 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 salaryCheckResultRecords = salaryCheckResultDetailService.listByCheckResultId(checkResult.getId()); // String[] headers = new String[]{"规则名称", "规则内容", "姓名"}; // List> rows = Lists.newArrayList(); // ExcelSheetData excelSheetData = new ExcelSheetData(); // excelSheetData.setSheetName("校验异常"); // excelSheetData.setHeaders(Collections.singletonList(headers)); // excelSheetData.setRows(rows); // if (CollectionUtils.isEmpty(salaryCheckResultRecords)) { // return excelSheetData; // } // List employeeIds = SalaryEntityUtil.properties(salaryCheckResultRecords, SalaryCheckResultRecordPO::getEmployeeId, Collectors.toList()); // List simpleEmployees = hrmCommonEmployeeService.getEmployeeByIds(employeeIds); // Map simpleEmployeeMap = SalaryEntityUtil.convert2Map(simpleEmployees, SimpleEmployee::getEmployeeId, SimpleEmployee::getUsername); // List expressFormulas = getSalaryFormulaService(user).listExpressFormula(Collections.singleton(checkResult.getFormulaId())); // Map formulaMap = SalaryEntityUtil.convert2Map(expressFormulas, ExpressFormula::getId, ExpressFormula::getFormula); // for (SalaryCheckResultRecordPO salaryCheckResultRecord : salaryCheckResultRecords) { // List 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; // } }