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

613 lines
28 KiB
Java
Raw Normal View History

2023-04-10 09:47:33 +08:00
package com.engine.salary.report.wrapper;
2023-06-15 17:34:52 +08:00
import cn.hutool.crypto.SecureUtil;
2023-04-23 10:14:32 +08:00
import com.alibaba.fastjson.JSONArray;
2023-06-08 18:04:25 +08:00
import com.cloudstore.eccom.pc.table.WeaTable;
2023-06-07 15:43:23 +08:00
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;
2024-03-19 13:35:37 +08:00
import com.engine.hrmelog.entity.dto.LoggerContext;
2023-06-15 17:34:52 +08:00
import com.engine.salary.cache.SalaryCacheKey;
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;
2024-02-23 15:11:56 +08:00
import com.engine.salary.config.SalaryElogConfig;
2023-06-07 15:43:23 +08:00
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
2024-02-23 15:11:56 +08:00
import com.engine.salary.enums.OperateTypeEnum;
2024-03-19 13:35:37 +08:00
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
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.param.*;
2023-09-20 09:10:47 +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.SalaryStatisticsPushPO;
import com.engine.salary.report.entity.po.SalaryStatisticsReportPO;
2023-09-18 18:20:53 +08:00
import com.engine.salary.report.service.*;
import com.engine.salary.report.service.impl.*;
2023-09-20 15:02:44 +08:00
import com.engine.salary.service.*;
import com.engine.salary.service.impl.*;
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-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-09-19 13:11:24 +08:00
import org.apache.commons.lang3.math.NumberUtils;
2023-04-24 16:34:23 +08:00
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
2023-06-08 18:04:25 +08:00
import weaver.general.PageIdConst;
2023-04-14 15:18:18 +08:00
import weaver.hrm.User;
2023-06-15 17:34:52 +08:00
import weaver.wechat.util.Utils;
2023-04-10 09:47:33 +08:00
2024-03-19 13:35:37 +08:00
import java.math.BigDecimal;
2023-04-10 09:47:33 +08:00
import java.util.*;
import java.util.stream.Collectors;
2023-06-15 17:34:52 +08:00
2023-04-10 09:47:33 +08:00
/**
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) {
2023-06-15 17:34:52 +08:00
return ServiceUtil.getService(SalaryAcctResultServiceImpl.class, user);
2023-06-07 15:43:23 +08:00
}
private SalaryItemService getSalaryItemService(User user) {
2023-06-15 17:34:52 +08:00
return ServiceUtil.getService(SalaryItemServiceImpl.class, user);
}
private SalaryCacheService getSalaryCacheService(User user) {
return ServiceUtil.getService(SalaryCacheServiceImpl.class, user);
2023-06-07 15:43:23 +08:00
}
2023-09-18 18:20:53 +08:00
private SalaryStatisticsPushService getSalaryStatisticsPushService(User user) {
return ServiceUtil.getService(SalaryStatisticsPushServiceImpl.class, user);
}
private SalaryStatisticsPushDetailService getSalaryStatisticsPushDetailService(User user) {
return ServiceUtil.getService(SalaryStatisticsPushDetailServiceImpl.class, user);
}
2023-09-20 15:02:44 +08:00
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
2023-09-18 18:20:53 +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-09-18 18:20:53 +08:00
Long uid = Long.valueOf(user.getUID());
2023-04-10 09:47:33 +08:00
// 初始化
2023-09-18 18:20:53 +08:00
getSalaryStatisticsDimensionService(user).init(uid);
2023-09-20 15:02:44 +08:00
// 所有人能够看到自己创建的报表,薪酬总管理员能够查看所有报表
2023-09-18 18:20:53 +08:00
List<SalaryStatisticsReportPO> reportList = getSalaryStatisticsReportService(user).listByCreator(uid);
2023-09-20 15:02:44 +08:00
List<Long> reportIds = reportList.stream().map(SalaryStatisticsReportPO::getId).collect(Collectors.toList());
2023-09-18 18:20:53 +08:00
// 获取所有没有撤回没有过期的报表ID不包含过期失效的
List<SalaryStatisticsPushPO> pushList = getSalaryStatisticsPushService(user).getSuccessPushListByReceiver(uid);
List<Long> sharedReportIds = pushList.stream().map(po -> Arrays.asList(StringUtils.split(po.getReportIds(), ",")))
.flatMap(Collection::stream).distinct().map(Long::valueOf).collect(Collectors.toList());
2023-09-20 15:02:44 +08:00
sharedReportIds = sharedReportIds.stream().filter(id -> !reportIds.contains(id)).collect(Collectors.toList());
2023-09-18 18:20:53 +08:00
reportList.addAll(getSalaryStatisticsReportService(user).getByIds(sharedReportIds));
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<>();
2023-09-20 15:02:44 +08:00
List<Long> finalSharedReportIds = sharedReportIds;
2023-04-10 09:47:33 +08:00
reportList.forEach(po -> {
Map<String, Object> temp = new HashMap<>();
temp.put("id", po.getId().toString());
temp.put("reportName", po.getReportName());
2023-11-09 16:14:35 +08:00
temp.put("timeType", po.getTimeType() == null ? 10 : po.getTimeType());
temp.put("salaryStartMonth", SalaryDateUtil.getFormatYearMonth(po.getSalaryStartMonth()));
temp.put("salaryEndMonth", SalaryDateUtil.getFormatYearMonth(po.getSalaryEndMonth()));
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());
2023-09-20 15:02:44 +08:00
temp.put("isShare", finalSharedReportIds.contains(po.getId()));
2023-04-10 09:47:33 +08:00
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());
// 获取默认维度统计
List<SalaryStatisticsDimensionPO> defaultSalaryStatisticsDimensions = getSalaryStatisticsDimensionService(user).listAllDefaultDimension();
List<Long> defaultDimensionIds = defaultSalaryStatisticsDimensions.stream().map(SalaryStatisticsDimensionPO::getId).collect(Collectors.toList());
// 获取有薪资统计报表引用的统计维度
Set<String> haveUsedDimIds = new HashSet<>();
List<SalaryStatisticsReportPO> salaryStatisticsReports = getSalaryStatisticsReportService(user).listAll();
salaryStatisticsReports.stream().forEach(report -> Collections.addAll(haveUsedDimIds, report.getDimension().split(",")));
statsDimOptions.stream().forEach(option -> {
2023-06-15 17:34:52 +08:00
if (defaultDimensionIds.contains(Long.valueOf(option.getId()))) {
// 默认维度不允许修改、删除
option.setCanDelete(false);
option.setCanEdit(false);
2023-06-15 17:34:52 +08:00
} else if (haveUsedDimIds.contains(option.getId())) {
// 被薪资统计报表引用的不能删除
option.setCanEdit(true);
option.setCanDelete(false);
}
});
2023-04-18 18:55:38 +08:00
// 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
2023-11-07 15:55:03 +08:00
/**
* 复制薪资账套
2023-12-16 12:35:24 +08:00
*
2023-11-07 15:55:03 +08:00
* @param id
*/
public void duplicate(Long id) {
if (id == null) {
throw new SalaryRunTimeException("id为空");
}
getSalaryStatisticsReportService(user).duplicate(id);
}
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-11-09 16:14:35 +08:00
data.put("timeType", po.getTimeType() == null ? 10 : po.getTimeType());
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()));
2024-03-05 13:44:34 +08:00
data.put("salarySob", JSONArray.parseArray(po.getSalarySobSetting()));
2023-04-23 10:14:32 +08:00
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-06-15 17:34:52 +08:00
Long id = param.getId();
if (id == null || param.getDimensionId() == null) {
2023-04-10 09:47:33 +08:00
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
}
// 查询报表配置
2023-06-15 17:34:52 +08:00
SalaryStatisticsReportPO po = this.getSalaryStatisticsReportService(user).getById(id);
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-09-20 09:10:47 +08:00
if (param.isShare()) {
2023-09-19 13:11:24 +08:00
// 是被分享的报表
Long uid = Long.valueOf(user.getUID());
// 校验查看权限,获取有效的分享记录
List<SalaryStatisticsPushPO> pushList = getSalaryStatisticsPushService(user).shareReportValid(param.getId(), uid);
List<Long> batchIds = pushList.stream().map(SalaryStatisticsPushPO::getId).collect(Collectors.toList());
getSalaryStatisticsPushService(user).updateReportViewStatus(batchIds, uid);
// salaryStatisticsPushService.sendViewedMsg(param.getBatchId(), param.getId(), employeeId, tenantKey);
// 如果是被分享的报表校验分享权限通过后将user赋值为报表创建人
User creator = new User();
creator.setUid(po.getCreator().intValue());
user = creator;
} else {
2023-09-20 15:02:44 +08:00
// 判断报表是否是登陆人创建的,或薪酬总管理员
Boolean needAuth = getTaxAgentService(user).isNeedAuth((long) user.getUID());
if (needAuth && NumberUtils.compare(po.getCreator().intValue(), user.getUID()) != 0) {
2023-09-19 13:11:24 +08:00
throw new SalaryRunTimeException("无权限查看该报表!");
}
}
// weaTable对象
Map<String, Object> weaTable = new HashMap<>();
2023-06-15 17:34:52 +08:00
2023-06-27 16:18:42 +08:00
// 查询自定义统计项目
List<SalaryStatisticsItemPO> salaryStatisticsItemList = this.getSalaryStatisticsItemService(user).listByStatisticsReportId(po.getId());
2023-06-15 18:48:31 +08:00
// 参数转换
SalaryStatisticsReportBO.poToQueryParam(param, po);
2023-06-27 16:18:42 +08:00
String paramMd5 = SecureUtil.md5(param + salaryStatisticsItemList.toString());
2023-06-15 17:34:52 +08:00
//已缓存的报表id
String salaryReportIds = Utils.null2String(getSalaryCacheService(user).get(SalaryCacheKey.SALARY_REPORT_IDS));
String salaryReportConditions = "";
2023-11-07 19:11:16 +08:00
if (StringUtils.isNotBlank(salaryReportIds) && salaryReportIds.contains(id + "")) {
//报表中缓存的条件
salaryReportConditions = Utils.null2String(getSalaryCacheService(user).get(SalaryCacheKey.SALARY_REPORT_CONDITIONS + id));
if (StringUtils.isNotBlank(salaryReportConditions) && salaryReportConditions.contains(paramMd5)) {
2023-12-16 12:35:24 +08:00
return getSalaryCacheService(user).get(SalaryCacheKey.SALARY_REPORT_DATA + id + "_" + paramMd5);
2023-11-07 19:11:16 +08:00
}
}
2023-06-15 17:34:52 +08:00
2023-04-10 09:47:33 +08:00
// 列表data
2023-06-15 18:48:31 +08:00
PageInfo<Map<String, Object>> page = this.getSalaryStatisticsReportService(user).buildReportRecords(dimension, param, 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
List<WeaTableColumnGroup> weaTableColumns = SalaryStatisticsReportBO.buildReportColumns(dimension, 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);
2023-06-15 17:34:52 +08:00
resultMap.put("reportId", id);
2023-12-16 12:40:33 +08:00
//设置报表缓存
2023-06-15 17:34:52 +08:00
getSalaryCacheService(user).set(SalaryCacheKey.SALARY_REPORT_IDS, salaryReportIds + "," + id);
getSalaryCacheService(user).set(SalaryCacheKey.SALARY_REPORT_CONDITIONS + id, salaryReportConditions + "," + paramMd5);
2023-12-16 12:35:24 +08:00
getSalaryCacheService(user).set(SalaryCacheKey.SALARY_REPORT_DATA + id + "_" + paramMd5, resultMap);
2023-06-15 17:34:52 +08:00
2023-04-10 09:47:33 +08:00
return resultMap;
}
2023-06-15 17:34:52 +08:00
2023-04-10 09:47:33 +08:00
/**
* 导出报表数据
*
* @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, "统计维度不存在"));
}
2023-09-20 09:10:47 +08:00
sharedReportCheck(param.isShare(), po);
2023-06-15 18:48:31 +08:00
// 参数转换
SalaryStatisticsReportBO.poToQueryParam(param, po);
2023-04-24 16:34:23 +08:00
// 查询自定义统计项目
List<SalaryStatisticsItemPO> salaryStatisticsItemList = this.getSalaryStatisticsItemService(user).listByStatisticsReportId(po.getId());
// 列表data
2023-06-15 18:48:31 +08:00
PageInfo<Map<String, Object>> page = this.getSalaryStatisticsReportService(user).buildReportRecords(dimension, param, salaryStatisticsItemList);
2023-04-24 16:34:23 +08:00
// 组装合计
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());
// 获取列头
List<WeaTableColumnGroup> weaTableColumns = SalaryStatisticsReportBO.buildReportColumns(dimension, 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
2024-02-23 15:11:56 +08:00
// 记录操作日志
String name = SalaryI18nUtil.getI18nLabel(0, "导出");
LoggerContext loggerContext = new LoggerContext<>();
loggerContext.setTargetId(po.getId().toString());
loggerContext.setTargetName(po.getReportName());
loggerContext.setOperateType(OperateTypeEnum.EXCEL_EXPORT.getValue());
loggerContext.setOperateTypeName(name);
loggerContext.setOperatedesc(name + SalaryI18nUtil.getI18nLabel(0, "薪酬统计报表") + "-" + po.getReportName());
loggerContext.setUser(user);
SalaryElogConfig.salaryStatReportLoggerTemplate.write(loggerContext);
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
/**
* 获取报表透视数据
2023-06-15 17:34:52 +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, "统计维度不存在"));
}
2023-09-19 13:11:24 +08:00
// 校验报表权限如果是被分享报表修改User
2023-09-20 09:10:47 +08:00
sharedReportCheck(param.isShare(), po);
2023-06-07 15:43:23 +08:00
// 查询自定义统计项目中所有薪资项目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());
2023-06-07 16:50:09 +08:00
PageInfo<Map<String, Object>> pageInfo = getSalaryStatisticsReportService(user).buildDataPerspectiveRecords(param, po, dimension, salaryStatisticsItemPOS);
2023-06-07 15:43:23 +08:00
List<SalaryItemPO> itemList = getSalaryItemService(user).listByIds(salaryItemIds);
// 列表columns
List<WeaTableColumn> weaTableColumns = buildDataPerspectiveTableColumns(itemList);
2023-06-08 18:04:25 +08:00
WeaTable table = new WeaTable();
2023-06-15 17:34:52 +08:00
String pageId = "a4f85an7-9576-4125-adn9-7d06e7sy69f2";
2023-06-08 18:04:25 +08:00
table.setPageID(pageId);
2023-06-15 17:34:52 +08:00
table.setPageUID(pageId + user.getUID());
2023-06-08 18:04:25 +08:00
table.setPagesize(PageIdConst.getPageSize(pageId, user.getUID()));
table.setBackfields("");
2023-06-07 15:43:23 +08:00
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;
}
2024-03-19 13:35:37 +08:00
/**
* 获取报表透视数据
*
* @param param
* @return
*/
public Map<String, Object> exportDataPerspective(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, "统计维度不存在"));
}
// 校验报表权限如果是被分享报表修改User
sharedReportCheck(param.isShare(), po);
// 查询自定义统计项目中所有薪资项目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());
param.setCurrent(1);
param.setPageSize(1000000000);
PageInfo<Map<String, Object>> pageInfo = getSalaryStatisticsReportService(user).buildDataPerspectiveRecords(param, po, dimension, salaryStatisticsItemPOS);
List<List<Object>> resultList = new ArrayList<>();
List<SalaryItemPO> itemList = getSalaryItemService(user).listByIds(salaryItemIds);
// 表格表头
List<WeaTableColumn> weaTableColumns = buildDataPerspectiveTableColumns(itemList);
List<Object> columns = new ArrayList<>();
for (WeaTableColumn column : weaTableColumns) {
columns.add(column.getText());
}
resultList.add(columns);
List<Map<String, Object>> list = pageInfo.getList();
for (Map<String, Object> resultMap : list) {
List<Object> row = new ArrayList<>();
for (WeaTableColumn column : weaTableColumns) {
try {
if (StringUtils.isNotBlank(column.getOtherpara()) && column.getOtherpara().equals(SalaryDataTypeEnum.NUMBER.getValue())) {
// 数值
row.add(new BigDecimal(resultMap.get(column.getColumn()).toString()));
} else {
row.add(Utils.null2String(resultMap.get(column.getColumn())));
}
} catch (Exception e) {
row.add(Utils.null2String(resultMap.get(column.getColumn())));
}
}
resultList.add(row);
}
String sheetName = SalaryI18nUtil.getI18nLabel(179263, "薪酬统计报表明细") + "-" + dimension.getDimName();
XSSFWorkbook book = ExcelUtilPlus.genWorkbookV2(resultList, sheetName);
Map<String, Object> map = new HashMap<>();
map.put("workbook", book);
map.put("fileName", sheetName);
return map;
}
2023-09-19 13:11:24 +08:00
/**
* 权限校验
2023-11-07 15:55:03 +08:00
*
2023-09-19 13:11:24 +08:00
* @param isShared 是否是被分享的报表
2023-11-07 15:55:03 +08:00
* @param po 报表po
2023-09-19 13:11:24 +08:00
*/
private void sharedReportCheck(boolean isShared, SalaryStatisticsReportPO po) {
if (isShared) {
// 是被分享的报表
Long uid = Long.valueOf(user.getUID());
// 校验分享查看权限
getSalaryStatisticsPushService(user).shareReportValid(po.getId(), uid);
// 如果是被分享的报表校验分享权限通过后将user赋值为报表创建人
User creator = new User();
creator.setUid(po.getCreator().intValue());
user = creator;
} else {
2023-09-20 15:02:44 +08:00
// 判断报表是否是登陆人创建的,或薪酬总管理员
Boolean needAuth = getTaxAgentService(user).isNeedAuth((long) user.getUID());
if (needAuth && NumberUtils.compare(po.getCreator().intValue(), user.getUID()) != 0) {
2023-09-19 13:11:24 +08:00
throw new SalaryRunTimeException("无权限查看该报表!");
}
}
}
2023-06-07 15:43:23 +08:00
private List<WeaTableColumn> buildDataPerspectiveTableColumns(List<SalaryItemPO> salaryItems) {
// 表格表头
List<WeaTableColumn> columns = new ArrayList<>();
2023-06-07 16:50:09 +08:00
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(87614, "姓名"), "userName"));
columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(87614, "部门"), "departmentName"));
2023-06-07 15:43:23 +08:00
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"));
2023-06-08 12:25:11 +08:00
// columns.add(new WeaTableColumn("100px", SalaryI18nUtil.getI18nLabel(86184, "次数"), "acctTimes").setDisplay(WeaBoolAttr.FALSE));
2023-06-07 15:43:23 +08:00
salaryItems.forEach(item -> {
2024-03-19 13:35:37 +08:00
WeaTableColumn weaTableColumn = new WeaTableColumn("100px", item.getName(), item.getId() + SalaryConstant.DYNAMIC_SUFFIX);
weaTableColumn.setOtherpara(item.getDataType());
columns.add(weaTableColumn);
2023-06-07 15:43:23 +08:00
});
return columns;
}
2023-04-10 09:47:33 +08:00
}