2023-04-17 09:46:01 +08:00
|
|
|
package com.engine.salary.report.wrapper;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.cloudstore.eccom.pc.table.WeaTableColumn;
|
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
import com.engine.core.impl.Service;
|
|
|
|
|
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
|
2023-11-01 09:54:09 +08:00
|
|
|
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
|
2023-04-17 09:46:01 +08:00
|
|
|
import com.engine.salary.report.entity.dto.SalaryStatisticsItemFormDTO;
|
|
|
|
|
import com.engine.salary.report.entity.param.SalaryStatisticsItemSaveParam;
|
|
|
|
|
import com.engine.salary.report.entity.po.SalaryStatisticsItemPO;
|
|
|
|
|
import com.engine.salary.report.enums.UnitTypeEnum;
|
|
|
|
|
import com.engine.salary.report.service.SalaryStatisticsItemService;
|
|
|
|
|
import com.engine.salary.report.service.impl.SalaryStatisticsItemServiceImpl;
|
|
|
|
|
import com.engine.salary.service.SalaryItemService;
|
|
|
|
|
import com.engine.salary.service.impl.SalaryItemServiceImpl;
|
|
|
|
|
import com.engine.salary.util.SalaryAssert;
|
|
|
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
|
|
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import weaver.hrm.User;
|
|
|
|
|
|
|
|
|
|
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-17 09:46:01 +08:00
|
|
|
public class SalaryStatisticsItemWrapper extends Service {
|
|
|
|
|
|
|
|
|
|
private SalaryStatisticsItemService getSalaryStatisticsItemService(User user) {
|
2023-04-23 10:14:32 +08:00
|
|
|
return ServiceUtil.getService(SalaryStatisticsItemServiceImpl.class, user);
|
2023-04-17 09:46:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SalaryItemService getSalaryItemService(User user) {
|
2023-04-23 10:14:32 +08:00
|
|
|
return ServiceUtil.getService(SalaryItemServiceImpl.class, user);
|
2023-04-17 09:46:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取自定义统计项目表单
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public SalaryStatisticsItemFormDTO getForm(Long id) {
|
|
|
|
|
Map weaForm = new HashMap();
|
|
|
|
|
Map<String, Object> ruleData = new HashMap<>();
|
|
|
|
|
if (Objects.nonNull(id)) {
|
|
|
|
|
SalaryStatisticsItemPO salaryStatisticsItem = getSalaryStatisticsItemService(user).getById(id);
|
|
|
|
|
SalaryAssert.notNull(salaryStatisticsItem, SalaryI18nUtil.getI18nLabel(152591, "统计项目不存在"));
|
|
|
|
|
String itemValue = salaryStatisticsItem.getItemValue();
|
|
|
|
|
if (StringUtils.isNotBlank(itemValue)) {
|
|
|
|
|
List<SalaryItemPO> salaryItems = getSalaryItemService(user).listAll();
|
2023-11-01 09:54:09 +08:00
|
|
|
Map<String, SalaryItemPO> itemsMap = SalaryEntityUtil.convert2Map(salaryItems, k -> k.getId().toString());
|
2023-04-17 09:46:01 +08:00
|
|
|
List<Map<String, String>> welfareItems = new ArrayList<>();
|
|
|
|
|
Arrays.stream(itemValue.split(",")).forEach(value -> {
|
|
|
|
|
Map<String, String> welfareItem = new HashMap<>();
|
|
|
|
|
welfareItem.put("id", value);
|
2023-11-01 09:54:09 +08:00
|
|
|
welfareItem.put("name", itemsMap.get(value).getName());
|
|
|
|
|
welfareItem.put("dataType", itemsMap.get(value).getDataType());
|
2023-04-17 09:46:01 +08:00
|
|
|
welfareItems.add(welfareItem);
|
|
|
|
|
});
|
|
|
|
|
Map map = new HashMap();
|
2023-11-01 09:54:09 +08:00
|
|
|
//版本变更,由多选变成单选
|
|
|
|
|
map.put("itemValue", welfareItems.get(0));
|
2023-04-17 09:46:01 +08:00
|
|
|
map.put("itemName", salaryStatisticsItem.getItemName());
|
|
|
|
|
weaForm.put("data", map);
|
2023-11-01 09:54:09 +08:00
|
|
|
ruleData = buildRule(SalaryDataTypeEnum.parseByValue(welfareItems.get(0).get("dataType")), salaryStatisticsItem);
|
2023-04-17 09:46:01 +08:00
|
|
|
}
|
|
|
|
|
} else {
|
2023-11-01 09:54:09 +08:00
|
|
|
ruleData = buildRule(null, null);
|
2023-04-17 09:46:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SalaryStatisticsItemFormDTO.builder()
|
|
|
|
|
.id(id)
|
|
|
|
|
.baseForm(weaForm)
|
|
|
|
|
.ruleData(ruleData)
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-01 09:54:09 +08:00
|
|
|
public Map buildRule(SalaryDataTypeEnum dataType, SalaryStatisticsItemPO salaryStatisticsItem) {
|
2023-04-17 09:46:01 +08:00
|
|
|
Map<String, Object> weaTable = new HashMap<>();
|
2023-11-01 09:54:09 +08:00
|
|
|
if (dataType == null || dataType == SalaryDataTypeEnum.NUMBER) {
|
|
|
|
|
List<WeaTableColumn> list = new ArrayList<>();
|
|
|
|
|
WeaTableColumn ruleName = new WeaTableColumn("20%", SalaryI18nUtil.getI18nLabel(157532, "统计规则"), "ruleName");
|
|
|
|
|
WeaTableColumn ratio = new WeaTableColumn("10%", SalaryI18nUtil.getI18nLabel(162990, "占比"), "ratio");
|
|
|
|
|
WeaTableColumn m2m = new WeaTableColumn("10%", SalaryI18nUtil.getI18nLabel(157533, "环比"), "m2m");
|
|
|
|
|
WeaTableColumn m2mLimit = new WeaTableColumn("25%", SalaryI18nUtil.getI18nLabel(157536, "环比增幅正常区间设置"), "m2mLimit");
|
|
|
|
|
WeaTableColumn y2y = new WeaTableColumn("10%", SalaryI18nUtil.getI18nLabel(162991, "同比"), "y2y");
|
|
|
|
|
WeaTableColumn y2yLimit = new WeaTableColumn("25%", SalaryI18nUtil.getI18nLabel(162992, "同比增幅正常区间设置"), "y2yLimit");
|
|
|
|
|
list.add(ruleName);
|
|
|
|
|
list.add(ratio);
|
|
|
|
|
list.add(m2m);
|
|
|
|
|
list.add(m2mLimit);
|
|
|
|
|
list.add(y2y);
|
|
|
|
|
list.add(y2yLimit);
|
|
|
|
|
weaTable.put("columns", list);
|
2023-04-17 09:46:01 +08:00
|
|
|
|
2023-11-01 09:54:09 +08:00
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
|
|
List<String> ruleList = Arrays.asList("count", "sum", "avg", "max", "min", "median");
|
|
|
|
|
List<String> ruleNameList = Arrays.asList(
|
|
|
|
|
SalaryI18nUtil.getI18nLabel(157268, "计数"),
|
|
|
|
|
SalaryI18nUtil.getI18nLabel(157266, "求和"),
|
|
|
|
|
SalaryI18nUtil.getI18nLabel(100132, "平均值"),
|
|
|
|
|
SalaryI18nUtil.getI18nLabel(163001, "最大值"),
|
|
|
|
|
SalaryI18nUtil.getI18nLabel(163002, "最小值"),
|
|
|
|
|
SalaryI18nUtil.getI18nLabel(163003, "中位数"));
|
|
|
|
|
if (salaryStatisticsItem == null) {
|
|
|
|
|
for (int i = 0; i < ruleList.size(); i++) {
|
|
|
|
|
Map<String, Object> rule = new HashMap<>();
|
|
|
|
|
rule.put("id", ruleList.get(i));
|
|
|
|
|
rule.put("ruleName", ruleNameList.get(i));
|
|
|
|
|
rule.put("totalValue", 0);
|
|
|
|
|
rule.put("ratioValue", 0);
|
|
|
|
|
rule.put("m2mValue", 0);
|
|
|
|
|
rule.put("m2mUpperLimit", "");
|
|
|
|
|
rule.put("m2mLowerLimit", "");
|
|
|
|
|
rule.put("y2yValue", 0);
|
|
|
|
|
rule.put("y2yUpperLimit", "");
|
|
|
|
|
rule.put("y2yLowerLimit", "");
|
|
|
|
|
result.add(rule);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < ruleList.size(); i++) {
|
|
|
|
|
Map<String, Object> rule = new HashMap<>();
|
|
|
|
|
switch (ruleList.get(i)) {
|
|
|
|
|
case "count":
|
|
|
|
|
rule = JSON.parseObject(salaryStatisticsItem.getCountRule(), new HashMap<String, String>().getClass());
|
|
|
|
|
break;
|
|
|
|
|
case "sum":
|
|
|
|
|
rule = JSON.parseObject(salaryStatisticsItem.getSumRule(), new HashMap<String, String>().getClass());
|
|
|
|
|
break;
|
|
|
|
|
case "avg":
|
|
|
|
|
rule = JSON.parseObject(salaryStatisticsItem.getAvgRule(), new HashMap<String, String>().getClass());
|
|
|
|
|
break;
|
|
|
|
|
case "max":
|
|
|
|
|
rule = JSON.parseObject(salaryStatisticsItem.getMaxRule(), new HashMap<String, String>().getClass());
|
|
|
|
|
break;
|
|
|
|
|
case "min":
|
|
|
|
|
rule = JSON.parseObject(salaryStatisticsItem.getMinRule(), new HashMap<String, String>().getClass());
|
|
|
|
|
break;
|
|
|
|
|
case "median":
|
|
|
|
|
rule = JSON.parseObject(salaryStatisticsItem.getMedianRule(), new HashMap<String, String>().getClass());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (rule == null) {
|
|
|
|
|
rule = new HashMap<>();
|
|
|
|
|
}
|
|
|
|
|
rule.put("id", ruleList.get(i));
|
|
|
|
|
rule.put("ruleName", ruleNameList.get(i));
|
|
|
|
|
rule.put("totalValue", Optional.ofNullable(rule.get("totalValue")).orElse(0));
|
|
|
|
|
rule.put("ratioValue", Optional.ofNullable(rule.get("ratioValue")).orElse(0));
|
|
|
|
|
rule.put("m2mValue", Optional.ofNullable(rule.get("m2mValue")).orElse(0));
|
|
|
|
|
rule.put("m2mUpperLimit", Optional.ofNullable(rule.get("m2mUpperLimit")).orElse(""));
|
|
|
|
|
rule.put("m2mLowerLimit", Optional.ofNullable(rule.get("m2mLowerLimit")).orElse(""));
|
|
|
|
|
rule.put("y2yValue", Optional.ofNullable(rule.get("y2yValue")).orElse(0));
|
|
|
|
|
rule.put("y2yUpperLimit", Optional.ofNullable(rule.get("y2yUpperLimit")).orElse(""));
|
|
|
|
|
rule.put("y2yLowerLimit", Optional.ofNullable(rule.get("y2yLowerLimit")).orElse(""));
|
|
|
|
|
result.add(rule);
|
|
|
|
|
}
|
2023-04-17 09:46:01 +08:00
|
|
|
}
|
2023-11-01 09:54:09 +08:00
|
|
|
weaTable.put("data", result);
|
2023-11-01 16:09:19 +08:00
|
|
|
} else {
|
2023-11-01 09:54:09 +08:00
|
|
|
List<WeaTableColumn> list = new ArrayList<>();
|
2023-11-01 16:09:19 +08:00
|
|
|
WeaTableColumn ruleName = new WeaTableColumn("20%", SalaryI18nUtil.getI18nLabel(157532, "字符取值规则"), "ruleName");
|
2023-11-01 09:54:09 +08:00
|
|
|
list.add(ruleName);
|
|
|
|
|
weaTable.put("columns", list);
|
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
2023-11-01 16:09:19 +08:00
|
|
|
List<String> ruleList = Arrays.asList("count", "last");
|
2023-11-01 09:54:09 +08:00
|
|
|
List<String> ruleNameList = Arrays.asList(
|
2023-11-01 16:09:19 +08:00
|
|
|
SalaryI18nUtil.getI18nLabel(157266, "最近值"));
|
2023-11-01 09:54:09 +08:00
|
|
|
if (salaryStatisticsItem == null) {
|
|
|
|
|
for (int i = 0; i < ruleList.size(); i++) {
|
|
|
|
|
Map<String, Object> rule = new HashMap<>();
|
|
|
|
|
rule.put("id", ruleList.get(i));
|
|
|
|
|
rule.put("ruleName", ruleNameList.get(i));
|
|
|
|
|
result.add(rule);
|
2023-04-17 09:46:01 +08:00
|
|
|
}
|
2023-11-01 09:54:09 +08:00
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < ruleList.size(); i++) {
|
|
|
|
|
Map<String, Object> rule = new HashMap<>();
|
|
|
|
|
switch (ruleList.get(i)) {
|
2023-11-01 16:09:19 +08:00
|
|
|
case "last":
|
|
|
|
|
rule = JSON.parseObject(salaryStatisticsItem.getLatestRule(), new HashMap<String, String>().getClass());
|
2023-11-01 09:54:09 +08:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (rule == null) {
|
|
|
|
|
rule = new HashMap<>();
|
|
|
|
|
}
|
|
|
|
|
rule.put("id", ruleList.get(i));
|
|
|
|
|
rule.put("ruleName", ruleNameList.get(i));
|
|
|
|
|
result.add(rule);
|
2023-04-17 09:46:01 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-11-01 09:54:09 +08:00
|
|
|
weaTable.put("data", result);
|
2023-04-17 09:46:01 +08:00
|
|
|
}
|
2023-11-01 09:54:09 +08:00
|
|
|
|
2023-04-17 09:46:01 +08:00
|
|
|
return weaTable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取自定义统计项目列表
|
|
|
|
|
*
|
|
|
|
|
* @param statisticsReportId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<Map<String, Object>> list(Long statisticsReportId) {
|
|
|
|
|
List<SalaryStatisticsItemPO> salaryStatisticsItemList = getSalaryStatisticsItemService(user).listByStatisticsReportId(statisticsReportId);
|
|
|
|
|
salaryStatisticsItemList = salaryStatisticsItemList.stream().sorted(Comparator.comparing(SalaryStatisticsItemPO::getIndexValue)).collect(Collectors.toList());
|
|
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
|
|
salaryStatisticsItemList.forEach(po -> {
|
|
|
|
|
Map<String, Object> rule = new HashMap<>();
|
|
|
|
|
rule.put("id", po.getId().toString());
|
|
|
|
|
rule.put("itemName", po.getItemName());
|
2023-04-23 10:14:32 +08:00
|
|
|
rule.put("unitType", po.getUnitType() == null ? UnitTypeEnum.YUAN.getValue() : po.getUnitType());
|
2023-04-17 09:46:01 +08:00
|
|
|
rule.put("itemValue", po.getItemValue());
|
|
|
|
|
rule.put("countRule", po.getCountRule());
|
|
|
|
|
rule.put("sumRule", po.getSumRule());
|
|
|
|
|
rule.put("avgRule", po.getAvgRule());
|
|
|
|
|
rule.put("maxRule", po.getMaxRule());
|
|
|
|
|
rule.put("minRule", po.getMinRule());
|
|
|
|
|
rule.put("medianRule", po.getMedianRule());
|
|
|
|
|
rule.put("indexValue", po.getIndexValue());
|
|
|
|
|
result.add(rule);
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除自定义统计项目
|
|
|
|
|
*
|
|
|
|
|
* @param ids
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public String delete(Collection<Long> ids) {
|
|
|
|
|
return getSalaryStatisticsItemService(user).delete(ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存自定义统计项目
|
|
|
|
|
*
|
|
|
|
|
* @param saveParam
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public String save(SalaryStatisticsItemSaveParam saveParam) {
|
|
|
|
|
return getSalaryStatisticsItemService(user).save(saveParam);
|
|
|
|
|
}
|
|
|
|
|
}
|