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

383 lines
17 KiB
Java
Raw Normal View History

2023-04-10 09:47:33 +08:00
package com.engine.salary.report.wrapper;
2023-04-23 10:14:32 +08:00
import com.alibaba.fastjson.JSONArray;
2023-06-07 15:43:23 +08:00
import com.cloudstore.eccom.constant.WeaBoolAttr;
import com.cloudstore.eccom.pc.table.WeaTableColumn;
import com.cloudstore.eccom.result.WeaResultMsg;
2023-04-14 15:18:18 +08:00
import com.engine.common.util.ServiceUtil;
2023-04-11 09:22:09 +08:00
import com.engine.core.impl.Service;
2023-06-07 15:43:23 +08:00
import com.engine.salary.component.SalaryWeaTable;
2023-04-18 18:55:38 +08:00
import com.engine.salary.component.WeaFormOption;
2023-04-27 16:05:03 +08:00
import com.engine.salary.component.WeaTableColumnGroup;
2023-06-07 15:43:23 +08:00
import com.engine.salary.entity.salaryarchive.dto.SalaryArchiveListDTO;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
2023-04-11 09:22:09 +08:00
import com.engine.salary.exception.SalaryRunTimeException;
2023-06-07 15:43:23 +08:00
import com.engine.salary.report.common.constant.SalaryConstant;
2023-04-11 09:22:09 +08:00
import com.engine.salary.report.entity.bo.SalaryStatisticsReportBO;
2023-06-07 15:43:23 +08:00
import com.engine.salary.report.entity.dto.SalaryStatisticsEmployeeDetailResultDTO;
import com.engine.salary.report.entity.param.*;
2023-04-11 09:22:09 +08:00
import com.engine.salary.report.entity.po.SalaryStatisticsDimensionPO;
import com.engine.salary.report.entity.po.SalaryStatisticsItemPO;
import com.engine.salary.report.entity.po.SalaryStatisticsReportPO;
import com.engine.salary.report.service.SalaryStatisticsDimensionService;
import com.engine.salary.report.service.SalaryStatisticsItemService;
2023-04-10 09:47:33 +08:00
import com.engine.salary.report.service.SalaryStatisticsReportService;
2023-04-11 09:22:09 +08:00
import com.engine.salary.report.service.SubTableExportService;
2023-04-14 15:18:18 +08:00
import com.engine.salary.report.service.impl.SalaryStatisticsDimensionServiceImpl;
import com.engine.salary.report.service.impl.SalaryStatisticsItemServiceImpl;
import com.engine.salary.report.service.impl.SalaryStatisticsReportServiceImpl;
import com.engine.salary.report.service.impl.SubTableExportServiceImpl;
2023-06-07 15:43:23 +08:00
import com.engine.salary.service.SalaryAcctEmployeeService;
import com.engine.salary.service.SalaryAcctResultService;
import com.engine.salary.service.SalaryItemService;
import com.engine.salary.service.impl.SalaryAcctEmployeeServiceImpl;
import com.engine.salary.service.impl.SalaryAcctResultServiceImpl;
import com.engine.salary.service.impl.SalaryItemServiceImpl;
2023-04-23 10:14:32 +08:00
import com.engine.salary.util.*;
2023-04-24 16:34:23 +08:00
import com.engine.salary.util.excel.ExcelUtilPlus;
2023-04-11 09:22:09 +08:00
import com.engine.salary.util.page.PageInfo;
2023-06-07 15:43:23 +08:00
import com.engine.salary.util.page.SalaryPageUtil;
2023-04-24 16:34:23 +08:00
import com.google.common.collect.Lists;
2023-04-10 09:47:33 +08:00
import com.google.common.collect.Maps;
2023-04-24 16:34:23 +08:00
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
2023-04-10 09:47:33 +08:00
import org.apache.commons.lang3.StringUtils;
2023-04-24 16:34:23 +08:00
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
2023-04-14 15:18:18 +08:00
import weaver.hrm.User;
2023-04-10 09:47:33 +08:00
import java.util.*;
import java.util.stream.Collectors;
/**
2023-05-05 14:08:37 +08:00
* 薪酬统计维度
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
2023-04-11 09:22:09 +08:00
public class SalaryStatisticsReportWrapper extends Service {
2023-04-10 09:47:33 +08:00
private static final String conditionId = "salaryStatisticsReportSearchCondition";
2023-04-14 15:18:18 +08:00
private SalaryStatisticsReportService getSalaryStatisticsReportService(User user) {
2023-04-24 14:09:27 +08:00
return ServiceUtil.getService(SalaryStatisticsReportServiceImpl.class, user);
2023-04-14 15:18:18 +08:00
}
2023-04-11 09:22:09 +08:00
2023-04-14 15:18:18 +08:00
private SalaryStatisticsItemService getSalaryStatisticsItemService(User user) {
2023-04-24 14:09:27 +08:00
return ServiceUtil.getService(SalaryStatisticsItemServiceImpl.class, user);
2023-04-14 15:18:18 +08:00
}
2023-04-11 09:22:09 +08:00
2023-04-14 15:18:18 +08:00
private SalaryStatisticsDimensionService getSalaryStatisticsDimensionService(User user) {
2023-04-24 14:09:27 +08:00
return ServiceUtil.getService(SalaryStatisticsDimensionServiceImpl.class, user);
2023-04-14 15:18:18 +08:00
}
2023-04-24 14:09:27 +08:00
2023-04-14 15:18:18 +08:00
private SubTableExportService getSubTableExportService(User user) {
2023-04-24 14:09:27 +08:00
return ServiceUtil.getService(SubTableExportServiceImpl.class, user);
2023-04-14 15:18:18 +08:00
}
2023-04-10 09:47:33 +08:00
2023-06-07 15:43:23 +08:00
private SalaryAcctEmployeeService getSalaryAcctEmployeeService(User user) {
return ServiceUtil.getService(SalaryAcctEmployeeServiceImpl.class, user);
}
private SalaryAcctResultService getSalaryAcctResultService(User user) {
return (SalaryAcctResultService) ServiceUtil.getService(SalaryAcctResultServiceImpl.class, user);
}
private SalaryItemService getSalaryItemService(User user) {
return (SalaryItemService) ServiceUtil.getService(SalaryItemServiceImpl.class, user);
}
2023-04-10 09:47:33 +08:00
/**
* 报表列表
*
* @param queryParam
* @return
*/
2023-04-11 09:22:09 +08:00
public List<Map<String, Object>> list(SalaryStatisticsReportQueryParam queryParam) {
2023-04-10 09:47:33 +08:00
// 初始化
2023-04-24 14:09:27 +08:00
getSalaryStatisticsDimensionService(user).init((long) user.getUID());
2023-04-10 09:47:33 +08:00
2023-04-14 15:18:18 +08:00
List<SalaryStatisticsReportPO> reportList = getSalaryStatisticsReportService(user).list();
2023-04-10 09:47:33 +08:00
if (StringUtils.isNotEmpty(queryParam.getReportName())) {
reportList = reportList.stream().filter(rp -> rp.getReportName().contains(queryParam.getReportName())).collect(Collectors.toList());
}
2023-04-14 15:18:18 +08:00
List<SalaryStatisticsDimensionPO> salaryStatisticsDimensionList = this.getSalaryStatisticsDimensionService(user).listAll();
2023-04-10 09:47:33 +08:00
Map<String, String> salaryStatisticsDimensionMap = SalaryEntityUtil.convert2Map(salaryStatisticsDimensionList, k -> k.getId().toString(), SalaryStatisticsDimensionPO::getDimName);
List<Map<String, Object>> result = new ArrayList<>();
reportList.forEach(po -> {
Map<String, Object> temp = new HashMap<>();
temp.put("id", po.getId().toString());
temp.put("reportName", po.getReportName());
2023-04-11 09:22:09 +08:00
List<String> dimNames = Arrays.stream(po.getDimension().split(",")).map(dim -> Optional.ofNullable(salaryStatisticsDimensionMap.get(dim)).orElse("")).collect(Collectors.toList());
temp.put("dimension", StringUtils.join(dimNames, ","));
2023-04-10 09:47:33 +08:00
temp.put("dimensionId", po.getDimension());
result.add(temp);
});
return result;
}
/**
* 获取薪酬统计报表表单
*
* @param id
2023-04-11 09:22:09 +08:00
* @param
2023-04-10 09:47:33 +08:00
* @return
*/
2023-04-24 14:09:27 +08:00
public Map<String, Object> getFrom(Long id) {
2023-04-10 09:47:33 +08:00
2023-04-14 15:18:18 +08:00
List<SalaryStatisticsDimensionPO> salaryStatisticsDimensions = getSalaryStatisticsDimensionService(user).listAll();
2023-04-10 09:47:33 +08:00
2023-04-18 18:55:38 +08:00
List<WeaFormOption> statsDimOptions = salaryStatisticsDimensions.stream().map(sd -> new WeaFormOption(sd.getId().toString(), sd.getDimName())).collect(Collectors.toList());
// 1.构建基础信息表单
2023-04-24 14:09:27 +08:00
Map<String, Object> weaForm = new HashMap<>();
weaForm.put("statsDimOptions", statsDimOptions);
2023-04-10 09:47:33 +08:00
2023-04-18 18:55:38 +08:00
if (id != null) {
SalaryStatisticsReportPO po = this.getSalaryStatisticsReportService(user).getById(id);
if (po == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(161845, "薪酬统计报表不存在"));
}
Map<String, Object> dataMap = JsonUtil.parseMap(po, Object.class);
dataMap.put("dimension", Arrays.asList(po.getDimension().split(",")));
2023-04-24 14:09:27 +08:00
weaForm.put("data", dataMap);
2023-04-10 09:47:33 +08:00
}
2023-04-18 18:55:38 +08:00
return weaForm;
2023-04-10 09:47:33 +08:00
}
/**
* 保存薪酬统计报表
*
* @param saveParam
2023-04-11 09:22:09 +08:00
* @param
2023-04-10 09:47:33 +08:00
* @return
*/
2023-04-11 09:22:09 +08:00
public String save(SalaryStatisticsReportSaveParam saveParam) {
2023-04-14 15:18:18 +08:00
return getSalaryStatisticsReportService(user).save(saveParam);
2023-04-10 09:47:33 +08:00
}
/**
* 删除薪酬统计报表
*
* @param ids
2023-04-11 09:22:09 +08:00
* @param
2023-04-10 09:47:33 +08:00
* @return
*/
2023-04-11 09:22:09 +08:00
public Map<String, Object> delete(Collection<Long> ids) {
2023-04-14 15:18:18 +08:00
return getSalaryStatisticsReportService(user).delete(ids);
2023-04-10 09:47:33 +08:00
}
2023-04-23 10:14:32 +08:00
/**
* 获取统计条件
*
* @param id
* @return
*/
2023-04-24 14:09:27 +08:00
public Map<String, Object> getSearchCondition(Long id) {
2023-04-23 10:14:32 +08:00
// 高级搜索实例
2023-04-24 14:09:27 +08:00
Map<String, Object> map = new HashMap<>();
2023-04-23 10:14:32 +08:00
if (id != null) {
SalaryStatisticsReportPO po = getSalaryStatisticsReportService(user).getById(id);
SalaryAssert.notNull(po, SalaryI18nUtil.getI18nLabel(152563, "报表不存在"));
Map<String, Object> data = new HashMap<>();
2023-04-24 14:57:54 +08:00
data.put("salaryStartMonth", SalaryDateUtil.getFormatYearMonth(po.getSalaryStartMonth()));
data.put("salaryEndMonth", SalaryDateUtil.getFormatYearMonth(po.getSalaryEndMonth()));
2023-04-23 10:14:32 +08:00
data.put("taxAgent", JSONArray.parseArray(po.getTaxAgentSetting()));
data.put("incomeCategory", JSONArray.parseArray(po.getIncomeCategorySetting()));
data.put("subCompany", JSONArray.parseArray(po.getSubCompanySetting()));
data.put("department", JSONArray.parseArray(po.getDepartSetting()));
data.put("grade", JSONArray.parseArray(po.getGradeSetting()));
data.put("position", JSONArray.parseArray(po.getPositionSetting()));
data.put("status", JSONArray.parseArray(po.getStatusSetting()));
data.put("employee", JSONArray.parseArray(po.getEmployeeSetting()));
data.put("hiredate", JSONArray.parseArray(po.getHiredateSetting()));
// data.put("leavedate", JSONArray.parseArray(po.getLeavedateSetting()));
2023-04-24 14:09:27 +08:00
map.put("data", data);
2023-04-23 10:14:32 +08:00
}
return map;
}
2023-04-10 09:47:33 +08:00
2023-04-11 09:22:09 +08:00
public String saveSearchCondition(SalaryStatisticsSearchConditionSaveParam param) {
2023-04-14 15:18:18 +08:00
return this.getSalaryStatisticsReportService(user).saveSearchCondition(param);
2023-04-10 09:47:33 +08:00
}
/**
* 获取报表数据
*
* @param param
* @return
*/
2023-04-11 09:22:09 +08:00
public Map<String, Object> getData(SalaryStatisticsReportDataQueryParam param) {
2023-04-10 09:47:33 +08:00
if (param.getId() == null || param.getDimensionId() == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误"));
}
2023-04-14 15:18:18 +08:00
SalaryStatisticsDimensionPO dimension = getSalaryStatisticsDimensionService(user).getById(param.getDimensionId());
2023-04-10 09:47:33 +08:00
if (dimension == null) {
2023-04-11 09:22:09 +08:00
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(161300, "统计维度不存在"));
2023-04-10 09:47:33 +08:00
}
// weaTable对象
2023-04-24 14:09:27 +08:00
Map<String, Object> weaTable = new HashMap<>();
2023-04-10 09:47:33 +08:00
// 查询报表配置
2023-04-14 15:18:18 +08:00
SalaryStatisticsReportPO po = this.getSalaryStatisticsReportService(user).getById(param.getId());
2023-04-10 09:47:33 +08:00
if (po == null) {
2023-04-11 09:22:09 +08:00
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(161845, "薪酬统计报表不存在"));
2023-04-10 09:47:33 +08:00
}
// 查询自定义统计项目
2023-04-14 15:18:18 +08:00
List<SalaryStatisticsItemPO> salaryStatisticsItemList = this.getSalaryStatisticsItemService(user).listByStatisticsReportId(po.getId());
2023-04-10 09:47:33 +08:00
// 列表data
2023-04-14 15:18:18 +08:00
PageInfo<Map<String, Object>> page = this.getSalaryStatisticsReportService(user).buildReportRecords(dimension, param, po, salaryStatisticsItemList);
2023-04-10 09:47:33 +08:00
// 组装合计
2023-04-24 14:09:27 +08:00
Map<String, Object> countResultMap = SalaryStatisticsReportBO.buildTotal(page, salaryStatisticsItemList, (long) user.getUID());
2023-04-10 09:47:33 +08:00
// 列表columns
2023-04-27 16:05:03 +08:00
List<WeaTableColumnGroup> weaTableColumns = SalaryStatisticsReportBO.buildReportColumns(dimension.getDimName(), salaryStatisticsItemList);
2023-04-10 09:47:33 +08:00
Map<String, Object> resultMap = Maps.newHashMap();
resultMap.putAll(JsonUtil.parseMap(weaTable, Object.class));
2023-04-11 09:22:09 +08:00
resultMap.put("columns", weaTableColumns);
resultMap.put("pageInfo", page);
2023-04-10 09:47:33 +08:00
resultMap.put("countResult", countResultMap);
return resultMap;
}
/**
* 导出报表数据
*
* @param param
* @return
*/
2023-04-27 16:05:03 +08:00
public Map<String, Object> exportData(SalaryStatisticsReportDataQueryParam param) {
2023-04-24 16:34:23 +08:00
if (param.getId() == null || param.getDimensionId() == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误"));
}
SalaryStatisticsReportPO po = this.getSalaryStatisticsReportService(user).getById(param.getId());
if (po == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(161845, "薪酬统计报表不存在"));
}
SalaryStatisticsDimensionPO dimension = getSalaryStatisticsDimensionService(user).getById(param.getDimensionId());
if (dimension == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(161300, "统计维度不存在"));
}
// 查询自定义统计项目
List<SalaryStatisticsItemPO> salaryStatisticsItemList = this.getSalaryStatisticsItemService(user).listByStatisticsReportId(po.getId());
// 列表data
PageInfo<Map<String, Object>> page = this.getSalaryStatisticsReportService(user).buildReportRecords(dimension, param, po, salaryStatisticsItemList);
// 组装合计
Map<String, Object> countResultMap = SalaryStatisticsReportBO.buildTotal(page, salaryStatisticsItemList, (long) user.getUID());
List<Map<String, Object>> list = page.getList();
if (CollectionUtils.isNotEmpty(list) && MapUtils.isNotEmpty(countResultMap)) {
list.add(countResultMap);
}
// 获取数据
List<Map<String, String>> records = list.stream().map(m -> m.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue() + StringUtils.EMPTY))).collect(Collectors.toList());
// 获取列头
2023-04-27 16:05:03 +08:00
List<WeaTableColumnGroup> weaTableColumns = SalaryStatisticsReportBO.buildReportColumns(dimension.getDimName(), salaryStatisticsItemList);
2023-04-24 16:34:23 +08:00
// 组装导出参数
2023-04-11 09:22:09 +08:00
// ExportCommonParam exportParam = SalaryStatisticsReportBO.buildExportParam(dimension.getDimName(), weaTableColumns, records);
// exportParam.setSheetName(SalaryI18nUtil.getI18nLabel(179263, "薪酬统计报表") + "-" + exportParam.getDimensionName());
2023-04-24 16:34:23 +08:00
//
List rows = new ArrayList<>();
rows.add(weaTableColumns);
2023-04-27 16:05:03 +08:00
List<String> head = new ArrayList<>();
weaTableColumns.forEach(weaTableColumn -> {
String column = weaTableColumn.getColumn();
if (CollectionUtils.isEmpty(weaTableColumn.getChildren())) {
head.add(column);
} else {
weaTableColumn.getChildren().forEach(children -> {
head.add(children.getColumn());
});
}
});
2023-04-24 16:34:23 +08:00
for (Map<String, String> map : records) {
List<Object> row = Lists.newArrayListWithExpectedSize(records.size());
2023-04-27 16:05:03 +08:00
head.forEach(k -> {
2023-04-24 16:34:23 +08:00
row.add(map.getOrDefault(k, StringUtils.EMPTY));
2023-04-27 16:05:03 +08:00
});
2023-04-24 16:34:23 +08:00
rows.add(row);
}
String sheetName = SalaryI18nUtil.getI18nLabel(179263, "薪酬统计报表") + "-" + dimension.getDimName();
XSSFWorkbook book = ExcelUtilPlus.genWorkbookWithChildTitleColumn(rows, sheetName, true);
2023-04-27 16:05:03 +08:00
Map<String, Object> map = new HashMap<>();
map.put("workbook", book);
map.put("fileName", sheetName);
2023-04-24 16:34:23 +08:00
return map;
2023-04-10 09:47:33 +08:00
}
2023-06-07 15:43:23 +08:00
/**
* 获取报表透视数据
* @param param
* @return
*/
public Map<String, Object> getDataPerspective(SalaryStatisticsDataPerspectiveQueryParam param) {
if (param.getId() == null || param.getDimensionId() == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误"));
}
SalaryStatisticsReportPO po = this.getSalaryStatisticsReportService(user).getById(param.getId());
if (po == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(161845, "薪酬统计报表不存在"));
}
SalaryStatisticsDimensionPO dimension = getSalaryStatisticsDimensionService(user).getById(param.getDimensionId());
if (dimension == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(161300, "统计维度不存在"));
}
// 查询自定义统计项目中所有薪资项目id
List<SalaryStatisticsItemPO> salaryStatisticsItemPOS = getSalaryStatisticsItemService(user).listByStatisticsReportId(param.getId());
List<Long> salaryItemIds = salaryStatisticsItemPOS.stream().filter(item -> StringUtils.isNotBlank(item.getItemValue())).map(p -> p.getItemValue().split(","))
.flatMap(Arrays::stream).map(Long::valueOf).collect(Collectors.toList());
List<Map<String, Object>> records = getSalaryStatisticsReportService(user).buildDataPerspectiveRecords(param, po, dimension, salaryStatisticsItemPOS);
PageInfo<Map<String, Object>> pageInfo = SalaryPageUtil.buildPage(param.getCurrent(), param.getPageSize(), records);
List<SalaryItemPO> itemList = getSalaryItemService(user).listByIds(salaryItemIds);
// 列表columns
List<WeaTableColumn> weaTableColumns = buildDataPerspectiveTableColumns(itemList);
SalaryWeaTable<SalaryArchiveListDTO> table = new SalaryWeaTable<SalaryArchiveListDTO>(user, SalaryStatisticsEmployeeDetailResultDTO.class);
table.setColumns(weaTableColumns);
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
result.success();
// 结果
Map<String, Object> resultMap = Maps.newHashMap();
resultMap.put("dataKey", result.getResultMap());
resultMap.put("pageInfo", pageInfo);
return resultMap;
}
private List<WeaTableColumn> buildDataPerspectiveTableColumns(List<SalaryItemPO> salaryItems) {
// 表格表头
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"));
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(86184, "次数"), "acctTimes").setDisplay(WeaBoolAttr.FALSE));
salaryItems.forEach(item -> {
columns.add(new WeaTableColumn("100px", item.getName(), item.getId() + SalaryConstant.DYNAMIC_SUFFIX));
});
return columns;
}
2023-04-10 09:47:33 +08:00
}