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

267 lines
12 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-04-11 09:22:09 +08:00
import com.cloudstore.eccom.pc.table.WeaTableColumn;
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-04-18 18:55:38 +08:00
import com.engine.salary.component.WeaFormOption;
2023-04-11 09:22:09 +08:00
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.report.entity.bo.SalaryStatisticsReportBO;
import com.engine.salary.report.entity.param.SalaryStatisticsReportDataQueryParam;
import com.engine.salary.report.entity.param.SalaryStatisticsReportQueryParam;
import com.engine.salary.report.entity.param.SalaryStatisticsReportSaveParam;
import com.engine.salary.report.entity.param.SalaryStatisticsSearchConditionSaveParam;
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-04-23 10:14:32 +08:00
import com.engine.salary.util.*;
2023-04-11 09:22:09 +08:00
import com.engine.salary.util.page.PageInfo;
2023-04-10 09:47:33 +08:00
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
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;
/**
* @Description: 薪酬统计维度
* @Author: wangxiangzhong
* @Date: 2022/12/15 13:46
*/
@Component
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
/**
* 报表列表
*
* @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<>();
data.put("salaryStartMonth", SalaryDateUtil.localDate2YearMonth(po.getSalaryStartMonth()));
data.put("salaryEndMonth", SalaryDateUtil.localDate2YearMonth(po.getSalaryEndMonth()));
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-11 09:22:09 +08:00
List<WeaTableColumn> 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
* @param employeeId
* @param tenantKey
* @return
*/
public Map<String, String> exportData(SalaryStatisticsReportDataQueryParam param, Long employeeId, String tenantKey) {
2023-04-11 09:22:09 +08:00
// if (param.getId() == null || param.getDimensionId() == null) {
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误"));
// }
//
2023-04-14 15:18:18 +08:00
// SalaryStatisticsReportPO po = this.getSalaryStatisticsReportService(user).getById(param.getId());
2023-04-11 09:22:09 +08:00
// if (po == null) {
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(161845, "薪酬统计报表不存在"));
// }
2023-04-14 15:18:18 +08:00
// SalaryStatisticsDimensionPO dimension = getSalaryStatisticsDimensionService(user).getById(param.getDimensionId());
2023-04-11 09:22:09 +08:00
// if (dimension == null) {
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(161300, "统计维度不存在"));
// }
// // 查询自定义统计项目
2023-04-14 15:18:18 +08:00
// List<SalaryStatisticsItemPO> salaryStatisticsItemList = this.getSalaryStatisticsItemService(user).listByStatisticsReportId(po.getId());
2023-04-11 09:22:09 +08:00
// // 列表data
2023-04-14 15:18:18 +08:00
// Page<Map<String, Object>> page = this.getSalaryStatisticsReportService(user).buildReportRecords(dimension, param, po, salaryStatisticsItemList);
2023-04-11 09:22:09 +08:00
// // 组装合计
// Map<String, Object> countResultMap = SalaryStatisticsReportBO.buildTotal(page, salaryStatisticsItemList);
// if (CollectionUtils.isNotEmpty(page.getRecords()) && MapUtils.isNotEmpty(countResultMap)) {
// page.getRecords().add(countResultMap);
// }
// // 获取数据
// List<Map<String, String>> records = CollectionUtils.emptyIfNull(page.getRecords()).stream().map(m -> m.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue() + StringUtils.EMPTY))).collect(Collectors.toList());
//
// // 获取列头
// List<WeaTableColumn> weaTableColumns = SalaryStatisticsReportBO.buildReportColumns(dimension.getDimName(), salaryStatisticsItemList);
//
// // 组装导出参数
// ExportCommonParam exportParam = SalaryStatisticsReportBO.buildExportParam(dimension.getDimName(), weaTableColumns, records);
// exportParam.setSheetName(SalaryI18nUtil.getI18nLabel(179263, "薪酬统计报表") + "-" + exportParam.getDimensionName());
2023-04-14 15:18:18 +08:00
// return getSubTableExportService(user).exportCommon(exportParam, UserContext.getCurrentUser(), TenantContext.get());
2023-04-11 09:22:09 +08:00
return null;
2023-04-10 09:47:33 +08:00
}
}