weaver-hrm-salary/src/com/engine/salary/report/wrapper/SalaryStatisticsEmployeeWra...

374 lines
19 KiB
Java
Raw Normal View History

2023-05-09 10:43:51 +08:00
package com.engine.salary.report.wrapper;
import com.cloudstore.eccom.constant.WeaBoolAttr;
2024-03-25 16:08:34 +08:00
import com.cloudstore.eccom.pc.table.WeaTable;
2023-05-09 10:43:51 +08:00
import com.cloudstore.eccom.pc.table.WeaTableColumn;
import com.cloudstore.eccom.result.WeaResultMsg;
2023-05-09 10:43:51 +08:00
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
2023-05-26 16:45:05 +08:00
import com.engine.salary.component.SalaryWeaTable;
2024-08-16 11:08:57 +08:00
import com.engine.salary.component.WeaTableColumnGroup;
2024-03-25 16:08:34 +08:00
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
2023-05-26 16:45:05 +08:00
import com.engine.salary.entity.salaryarchive.dto.SalaryArchiveListDTO;
2023-05-09 10:43:51 +08:00
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
2024-11-25 16:04:19 +08:00
import com.engine.salary.entity.setting.dto.PageListTemplateDTO;
import com.engine.salary.entity.setting.param.PageListSettingQueryParam;
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
2023-05-09 10:43:51 +08:00
import com.engine.salary.report.common.constant.SalaryConstant;
import com.engine.salary.report.entity.bo.SalaryStatisticsReportBO;
import com.engine.salary.report.entity.dto.SalaryStatisticsEmployeeDetailResultDTO;
import com.engine.salary.report.entity.dto.SalaryStatisticsEmployeeListDTO;
import com.engine.salary.report.entity.param.SalaryStatisticsEmployeeDetailQueryParam;
import com.engine.salary.report.entity.param.SalaryStatisticsEmployeeQueryParam;
2024-03-25 16:08:34 +08:00
import com.engine.salary.report.entity.param.SalaryStatisticsEmployeeSalaryQueryParam;
2023-05-09 10:43:51 +08:00
import com.engine.salary.report.service.SalaryStatisticsEmployeeService;
import com.engine.salary.report.service.impl.SalaryStatisticsEmployeeServiceImpl;
import com.engine.salary.report.util.ReportDataUtil;
2024-08-16 11:08:57 +08:00
import com.engine.salary.service.SalaryItemService;
2024-11-07 17:45:17 +08:00
import com.engine.salary.service.SettingService;
2024-08-16 11:08:57 +08:00
import com.engine.salary.service.impl.SalaryItemServiceImpl;
2024-11-07 17:45:17 +08:00
import com.engine.salary.service.impl.SettingServiceImpl;
import com.engine.salary.sys.service.SalarySysConfService;
import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl;
import com.engine.salary.util.SalaryEntityUtil;
2023-05-09 10:43:51 +08:00
import com.engine.salary.util.SalaryI18nUtil;
2024-03-25 16:08:34 +08:00
import com.engine.salary.util.excel.ExcelUtilPlus;
2023-05-09 10:43:51 +08:00
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
2024-06-13 13:39:24 +08:00
import com.google.common.collect.Lists;
2023-05-09 10:43:51 +08:00
import com.google.common.collect.Maps;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
2023-05-25 13:51:27 +08:00
import org.apache.commons.lang3.math.NumberUtils;
2024-03-25 16:08:34 +08:00
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import weaver.general.PageIdConst;
import weaver.general.Util;
2023-05-09 10:43:51 +08:00
import weaver.hrm.User;
import java.math.BigDecimal;
2023-05-26 16:45:05 +08:00
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
2024-03-25 16:08:34 +08:00
import java.util.stream.Collectors;
2023-05-09 10:43:51 +08:00
2024-11-07 17:45:17 +08:00
import static com.engine.salary.enums.setting.PageListSettingPageEnum.SALARY_DETAILS_REPORT;
import static com.engine.salary.sys.constant.SalarySysConstant.SALARY_DETAILS_REPORT_SHOW_TYPE;
2023-05-09 10:43:51 +08:00
/**
* 薪酬统计员工明细
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
public class SalaryStatisticsEmployeeWrapper extends Service {
private SalaryStatisticsEmployeeService getSalaryStatisticsEmployeeService(User user) {
return ServiceUtil.getService(SalaryStatisticsEmployeeServiceImpl.class, user);
}
2024-08-16 11:08:57 +08:00
private SalaryItemService getSalaryItemService(User user) {
return ServiceUtil.getService(SalaryItemServiceImpl.class, user);
}
2024-11-07 17:45:17 +08:00
private SettingService getSettingService(User user) {
return ServiceUtil.getService(SettingServiceImpl.class, user);
}
private SalarySysConfService getSalarySysConfService(User user) {
return ServiceUtil.getService(SalarySysConfServiceImpl.class, user);
}
//是否模板显示
private final boolean templateShow = "1".equals(getSalarySysConfService(user).getValueByCode(SALARY_DETAILS_REPORT_SHOW_TYPE));
2023-05-09 10:43:51 +08:00
/**
* 员工列表
*
* @param queryParam
* @return
*/
public PageInfo<SalaryStatisticsEmployeeListDTO> list(SalaryStatisticsEmployeeQueryParam queryParam) {
return getSalaryStatisticsEmployeeService(user).listPage(queryParam);
2023-05-09 10:43:51 +08:00
}
/**
* 员工详情列表
*
* @param queryParam
* @return
*/
public Map<String, Object> detailList(SalaryStatisticsEmployeeDetailQueryParam queryParam) {
// 获取核算数据
SalaryStatisticsEmployeeDetailResultDTO salaryStatisticsEmployeeDetailResult = getSalaryStatisticsEmployeeService(user).getDetailSalaryAcctResult(queryParam);
List<Map<String, Object>> records = getSalaryStatisticsEmployeeService(user).listDetailPage(salaryStatisticsEmployeeDetailResult, queryParam);
Map<String, Object> countResultMap = Maps.newHashMap();
if (CollectionUtils.isNotEmpty(records)) {
List<SalaryItemPO> salaryItems = salaryStatisticsEmployeeDetailResult.getSalaryItemList();
for (SalaryItemPO item : salaryItems) {
BigDecimal sumBigDecimal = new BigDecimal(SalaryStatisticsReportBO.ZERO);
String itemKey = item.getId() + SalaryConstant.DYNAMIC_SUFFIX;
for (Map<String, Object> record : records) {
if (record.containsKey(itemKey)) {
if (Objects.nonNull(record.get(itemKey)) && StringUtils.isNotEmpty(record.get(itemKey).toString()) && NumberUtils.isCreatable(record.get(itemKey).toString())) {
2023-05-09 10:43:51 +08:00
sumBigDecimal = sumBigDecimal.add(new BigDecimal(record.get(itemKey).toString()));
record.put(itemKey, ReportDataUtil.thousandthConvert(record.get(itemKey).toString()));
}
}
}
countResultMap.put(itemKey, ReportDataUtil.thousandthConvert(sumBigDecimal.toString()));
}
}
PageInfo<Map<String, Object>> pageInfo = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), records);
// 列表columns
2024-03-25 16:08:34 +08:00
List<WeaTableColumn> weaTableColumns = buildDetailTableColumns(salaryStatisticsEmployeeDetailResult, false);
2023-05-09 10:43:51 +08:00
2023-05-26 16:45:05 +08:00
SalaryWeaTable<SalaryArchiveListDTO> table = new SalaryWeaTable<SalaryArchiveListDTO>(user, SalaryStatisticsEmployeeDetailResultDTO.class);
table.setColumns(weaTableColumns);
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
result.success();
2023-05-09 10:43:51 +08:00
// 结果
Map<String, Object> resultMap = Maps.newHashMap();
// resultMap.put("columns", weaTableColumns);
resultMap.put("dataKey", result.getResultMap());
2023-05-09 10:43:51 +08:00
resultMap.put("pageInfo", pageInfo);
resultMap.put("countResult", countResultMap);
2023-05-09 10:43:51 +08:00
return resultMap;
}
2024-03-25 16:08:34 +08:00
private List<WeaTableColumn> buildDetailTableColumns(SalaryStatisticsEmployeeDetailResultDTO salaryStatisticsEmployeeDetailResult, boolean isSalaryList) {
2023-05-09 10:43:51 +08:00
// 表格表头
List<WeaTableColumn> columns = new ArrayList<>();
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(87614, "薪资所属月"), "salaryMonth"));
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"), "taxAgent"));
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(86184, "账套"), "salarySob"));
2024-03-25 16:08:34 +08:00
if (isSalaryList) {
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(0, "姓名"), "userName"));
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(0, "分部"), "subCompany"));
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(0, "部门"), "department"));
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(0, "岗位"), "jobTitle"));
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(0, "员工状态"), "status"));
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(0, "工号"), "workCode"));
2024-10-09 18:10:38 +08:00
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(0, "入职日期"), "companystartdate"));
2024-03-25 16:08:34 +08:00
}
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(86184, "次数"), "acctTimes").setDisplay(WeaBoolAttr.FALSE));
// columns.add(new WeaTableColumn("100px",SalaryI18nUtil.getI18nLabel( 121908, "收入所得项目"), "incomeCategory"));
2023-05-09 10:43:51 +08:00
salaryStatisticsEmployeeDetailResult.getSalaryItemList().forEach(item -> {
columns.add(new WeaTableColumn("100px", item.getName(), item.getId() + SalaryConstant.DYNAMIC_SUFFIX));
2023-05-09 10:43:51 +08:00
});
return columns;
}
2024-03-25 16:08:34 +08:00
/**
* 获取员工发薪明细列表
2024-06-13 13:39:24 +08:00
*
2024-03-25 16:08:34 +08:00
* @param queryParam
*/
public Map<String, Object> salaryList(SalaryStatisticsEmployeeSalaryQueryParam queryParam) {
Map<String, Object> resultMap = Maps.newHashMap();
if (StringUtils.isBlank(queryParam.getStartDateStr()) || StringUtils.isBlank(queryParam.getEndDateStr())) {
return resultMap;
}
// 获取发薪人员
PageInfo<SalaryAcctEmployeePO> salaryAcctEmployeePageInfo = getSalaryStatisticsEmployeeService(user).listSalaryAcctEmp(queryParam);
2024-03-26 09:12:59 +08:00
// 获取薪资核算结果
2024-06-13 13:39:24 +08:00
SalaryStatisticsEmployeeDetailResultDTO salaryStatisticsEmployeeDetailResult = getSalaryStatisticsEmployeeService(user).getDetailSalaryAcctResultByAcctEmp(salaryAcctEmployeePageInfo.getList());
2024-03-25 16:08:34 +08:00
List<Map<String, Object>> records = getSalaryStatisticsEmployeeService(user).listDetailPage(salaryStatisticsEmployeeDetailResult, null);
2024-03-27 09:35:47 +08:00
PageInfo<Map<String, Object>> pageInfo = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize());
pageInfo.setList(records);
2024-03-25 16:08:34 +08:00
pageInfo.setTotal(salaryAcctEmployeePageInfo.getTotal());
2024-11-07 17:45:17 +08:00
List<WeaTableColumn> weaTableColumns;
//显示方案1显示模板
if (templateShow) {
weaTableColumns = getSettingService(user).getPageListColumns(SALARY_DETAILS_REPORT.getValue());
} else {
2024-11-25 16:04:19 +08:00
PageListSettingQueryParam param = PageListSettingQueryParam.builder().page(SALARY_DETAILS_REPORT.getValue()).build();
PageListTemplateDTO pageListSetting = getSettingService(user).getPageListSetting(param);
weaTableColumns = pageListSetting.getChecked();
2024-11-07 17:45:17 +08:00
}
2024-03-25 16:08:34 +08:00
// 结果
2024-11-07 17:45:17 +08:00
resultMap.put("columns", weaTableColumns);
2024-03-25 16:08:34 +08:00
if (queryParam.isExport()) {
2024-11-11 09:59:27 +08:00
Map<String, Object> countResultMap = Maps.newHashMap();
List<SalaryItemPO> salaryItems = salaryStatisticsEmployeeDetailResult.getSalaryItemList();
if (CollectionUtils.isNotEmpty(records)) {
for (SalaryItemPO item : salaryItems) {
BigDecimal sumBigDecimal = new BigDecimal(SalaryStatisticsReportBO.ZERO);
String itemKey = item.getId() + SalaryConstant.DYNAMIC_SUFFIX;
for (Map<String, Object> record : records) {
if (Objects.nonNull(record.get(itemKey)) && NumberUtils.isCreatable(record.get(itemKey).toString())) {
sumBigDecimal = sumBigDecimal.add(new BigDecimal(record.get(itemKey).toString()));
}
}
countResultMap.put(itemKey, sumBigDecimal.toString());
}
}
2024-06-13 13:39:24 +08:00
resultMap.put("salaryItems", salaryStatisticsEmployeeDetailResult.getSalaryItemList());
2024-03-26 13:49:37 +08:00
resultMap.put("countResult", countResultMap);
2024-03-25 16:08:34 +08:00
} else {
WeaTable table = new WeaTable();
String pageId = "b72ed4bb-725e-45de-aea1-4eb4c9184af7";
table.setPageID(pageId);
table.setPageUID(pageId + user.getUID());
table.setPagesize(PageIdConst.getPageSize(pageId, user.getUID()));
table.setBackfields("");
table.setColumns(weaTableColumns);
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
result.success();
resultMap.put("dataKey", result.getResultMap());
}
resultMap.put("pageInfo", pageInfo);
2024-03-26 13:49:37 +08:00
return resultMap;
}
/**
* 获取员工发薪明细列表
2024-06-13 13:39:24 +08:00
*
2024-03-26 13:49:37 +08:00
* @param queryParam
*/
public Map<String, Object> salaryListSum(SalaryStatisticsEmployeeSalaryQueryParam queryParam) {
Map<String, Object> resultMap = Maps.newHashMap();
2024-11-12 15:34:51 +08:00
Map<String, Object> sumResultMap = Maps.newHashMap();
resultMap.put("sumRow", sumResultMap);
2024-03-26 13:49:37 +08:00
if (StringUtils.isBlank(queryParam.getStartDateStr()) || StringUtils.isBlank(queryParam.getEndDateStr())) {
return resultMap;
}
queryParam.setExport(true);
// 获取发薪人员
PageInfo<SalaryAcctEmployeePO> salaryAcctEmployeePageInfo = getSalaryStatisticsEmployeeService(user).listSalaryAcctEmp(queryParam);
2024-06-13 13:39:24 +08:00
List<SalaryAcctEmployeePO> employeePOS = salaryAcctEmployeePageInfo.getList();
2024-11-07 17:45:17 +08:00
if (CollectionUtils.isEmpty(employeePOS)) {
2024-10-11 15:34:17 +08:00
return resultMap;
}
2024-03-26 13:49:37 +08:00
2024-06-13 13:39:24 +08:00
List<List<SalaryAcctEmployeePO>> empParts = Lists.partition(employeePOS, 500);
for (int i = 0; i < empParts.size(); i++) {
// 获取薪资核算结果
SalaryStatisticsEmployeeDetailResultDTO salaryStatisticsEmployeeDetailResult = getSalaryStatisticsEmployeeService(user).getDetailSalaryAcctResultByAcctEmp(empParts.get(i));
List<Map<String, Object>> records = getSalaryStatisticsEmployeeService(user).listDetailPage(salaryStatisticsEmployeeDetailResult, null);
if (CollectionUtils.isNotEmpty(records)) {
List<SalaryItemPO> salaryItems = salaryStatisticsEmployeeDetailResult.getSalaryItemList();
// 过滤只统计数值型薪资项目
salaryItems = salaryItems.stream().filter(salaryItemPO -> salaryItemPO.getDataType().equals(SalaryDataTypeEnum.NUMBER.getValue())).collect(Collectors.toList());
2024-06-13 13:39:24 +08:00
for (SalaryItemPO item : salaryItems) {
BigDecimal sumBigDecimal = new BigDecimal(SalaryStatisticsReportBO.ZERO);
String itemKey = item.getId() + SalaryConstant.DYNAMIC_SUFFIX;
for (Map<String, Object> record : records) {
if (record.containsKey(itemKey)) {
2024-11-11 09:59:27 +08:00
if (Objects.nonNull(record.get(itemKey)) && NumberUtils.isCreatable(record.get(itemKey).toString())) {
2024-06-13 13:39:24 +08:00
sumBigDecimal = sumBigDecimal.add(new BigDecimal(record.get(itemKey).toString()));
}
2024-03-26 13:49:37 +08:00
}
}
2024-06-13 13:39:24 +08:00
Object o = sumResultMap.get(itemKey + "_n");
if (o != null) {
sumBigDecimal = sumBigDecimal.add((BigDecimal) o);
}
sumResultMap.put(itemKey + "_n", sumBigDecimal);
// 薪资项目合计
sumResultMap.put(itemKey, ReportDataUtil.thousandthConvert(sumBigDecimal.toString()));
2024-03-26 13:49:37 +08:00
}
}
}
resultMap.put("sumRow", sumResultMap);
2024-03-25 16:08:34 +08:00
return resultMap;
}
public XSSFWorkbook exportSalaryList(SalaryStatisticsEmployeeSalaryQueryParam queryParam) {
queryParam.setCurrent(1);
queryParam.setExport(true);
Map<String, Object> resultMap = salaryList(queryParam);
2024-11-07 17:45:17 +08:00
List<WeaTableColumn> columns = (List<WeaTableColumn>) resultMap.get("columns");
2024-03-25 16:08:34 +08:00
List<Map<String, Object>> resultList = ((PageInfo<Map<String, Object>>) resultMap.get("pageInfo")).getList();
2024-11-07 17:45:17 +08:00
Map<String, Object> countResult = (Map<String, Object>) resultMap.get("countResult");
2024-03-25 16:08:34 +08:00
Map<String, WeaTableColumn> columnMap = SalaryEntityUtil.convert2Map(columns, WeaTableColumn::getColumn);
2024-08-16 11:08:57 +08:00
// 获取薪资项目保留小数位数
List<SalaryItemPO> salaryItemPOList = getSalaryItemService(user).listAll();
Map<String, SalaryItemPO> salaryItemMap = SalaryEntityUtil.convert2Map(salaryItemPOList, item -> item.getId() + "_salaryItem");
List<Object> finalColumns = new ArrayList<>();
queryParam.getColumns().forEach(col -> {
WeaTableColumn column = columnMap.get(col);
if (column != null) {
2024-08-16 11:08:57 +08:00
SalaryItemPO salaryItemPO = salaryItemMap.get(column.getColumn());
Integer pattern = salaryItemPO == null ? 0 : salaryItemPO.getPattern();
String dataType = salaryItemPO == null ? SalaryDataTypeEnum.STRING.getValue() : salaryItemPO.getDataType();
2024-11-11 09:59:27 +08:00
finalColumns.add(new WeaTableColumnGroup("100px", Util.formatMultiLang(column.getText()), column.getColumn(), "false", pattern, dataType));
}
});
2024-03-25 16:08:34 +08:00
List<List<Object>> rowList = new ArrayList<>();
// 表头
2024-08-16 11:08:57 +08:00
rowList.add(finalColumns);
2024-03-25 16:08:34 +08:00
// 数据
for (Map<String, Object> valueMap : resultList) {
List<Object> list = new ArrayList<>();
2024-08-16 11:08:57 +08:00
for (Object column : finalColumns) {
2024-11-07 17:45:17 +08:00
WeaTableColumnGroup col = (WeaTableColumnGroup) column;
2024-08-16 11:08:57 +08:00
if (col.getDataType().equals(SalaryDataTypeEnum.NUMBER.getValue())) {
try {
list.add(new BigDecimal(Util.null2String(valueMap.get(col.getColumn()))));
} catch (Exception e) {
list.add(Util.null2String(valueMap.get(col.getColumn())));
}
} else {
list.add(Util.null2String(valueMap.get(col.getColumn())));
}
2024-03-25 16:08:34 +08:00
}
rowList.add(list);
}
// 合计
List<Object> sumRow = new ArrayList<>();
sumRow.add("总计");
2024-08-16 11:08:57 +08:00
for (int i = 1; i < finalColumns.size(); i++) {
2024-11-07 17:45:17 +08:00
WeaTableColumnGroup weaTableColumnGroup = (WeaTableColumnGroup) finalColumns.get(i);
2024-08-16 11:08:57 +08:00
if (weaTableColumnGroup.getDataType().equals(SalaryDataTypeEnum.NUMBER.getValue())) {
try {
sumRow.add(new BigDecimal(Util.null2String(countResult.get(weaTableColumnGroup.getColumn()))));
} catch (Exception e) {
sumRow.add(Util.null2String(countResult.get(weaTableColumnGroup.getColumn())));
}
} else {
sumRow.add(Util.null2String(countResult.get(weaTableColumnGroup.getColumn())));
}
2024-03-25 16:08:34 +08:00
}
rowList.add(sumRow);
2024-08-16 11:08:57 +08:00
return ExcelUtilPlus.genWorkbookV2WithPattern(rowList, "薪资明细", true);
2024-03-25 16:08:34 +08:00
}
2023-05-09 10:43:51 +08:00
// public Map<String, Object> exportDetailList(SalaryStatisticsEmployeeDetailQueryParam queryParam) {
// SalaryAssert.notNull(queryParam.getEmployeeId(), SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 163974, "人员id不能为空"));
// // 构建异步导出参数
// Map<String, Object> map = salaryBatchService.buildeExportParam("exportSalaryStatisticsEmployeeDetailList");
// LocalRunnable localRunnable = new LocalRunnable() {
// @Override
// public void execute() {
// try {
// DSTenantKeyThreadVar.tenantKey.set(currentTenantKey);
// getSalaryStatisticsEmployeeService(user).exportDetailList(map, queryParam);
// } finally {
// DSTenantKeyThreadVar.tenantKey.remove();
// }
// }
// };
// ThreadPoolUtil.execute(localRunnable);
//
// return map;
// }
}