显示字符统计规则

This commit is contained in:
钱涛 2023-11-02 14:43:15 +08:00
parent 22a946d9ad
commit 83f38d1d74
6 changed files with 276 additions and 125 deletions

View File

@ -16,8 +16,8 @@ public class SalaryStatisticsItemStringRuleDTO {
/**
* 是否显示
* 是否启用
*/
private Integer display;
private Integer ableValue;
}

View File

@ -0,0 +1,26 @@
package com.engine.salary.report.entity.param;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 薪酬统计报表自定义统计项目保存参数
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SalaryStatisticsItemGetFormParam {
//统计项目id
private Long id;
//统计项目
private Long itemId;
}

View File

@ -129,21 +129,35 @@ public class SalaryStatisticsItemPO implements Serializable {
/**
* 最近值
* <p>
* "able":"1", 是否使用
*/
private String lastRule;
/**
* 最早值
* <p>
* {
* "able":"1", 是否使用
* }
*/
private String oldRule;
/**
* 出现最多
* <p>
* {
* "able":"1", 是否使用
* }
*/
private String frequentRule;
/**
* 按时间平铺
* 平铺
* <p>
* {
* "able":"1", 是否使用
* }
*/
private String tileRule;
@ -152,6 +166,7 @@ public class SalaryStatisticsItemPO implements Serializable {
/**
* 统计单位
*
* @see UnitTypeEnum
*/
//统计单位")

View File

@ -0,0 +1,52 @@
package com.engine.salary.report.enums;
import com.engine.salary.enums.BaseEnum;
import java.util.Objects;
public enum SalaryStatisticsItemStringRuleEnum implements BaseEnum<String> {
LAST("last", "最近值", 83993),
OLD("old", "最早值", 83994),
FREQUENT("frequent", "出现最多", 83994),
TILE("tile", "平铺", 83994),
;
private String value;
private String defaultLabel;
private int labelId;
SalaryStatisticsItemStringRuleEnum(String value, String defaultLabel, int labelId) {
this.value = value;
this.defaultLabel = defaultLabel;
this.labelId = labelId;
}
@Override
public String getValue() {
return value;
}
@Override
public String getDefaultLabel() {
return defaultLabel;
}
@Override
public Integer getLabelId() {
return labelId;
}
public static SalaryStatisticsItemStringRuleEnum parseByValue(String value) {
for (SalaryStatisticsItemStringRuleEnum typeEnum : SalaryStatisticsItemStringRuleEnum.values()) {
if (Objects.equals(typeEnum.getValue(), value)) {
return typeEnum;
}
}
return null;
}
}

View File

@ -31,6 +31,7 @@ public class SalaryStatisticsItemController {
private SalaryStatisticsItemWrapper getSalaryStatisticsItemWrapper(User user) {
return ServiceUtil.getService(SalaryStatisticsItemWrapper.class, user);
}
/**
* 获取自定义统计项目表单
*
@ -40,11 +41,26 @@ public class SalaryStatisticsItemController {
@GET
@Path("/getForm")
@Produces(MediaType.APPLICATION_JSON)
public String getForm(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "id")Long id) {
public String getForm(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "id") Long id) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<Long, SalaryStatisticsItemFormDTO>(user).run(getSalaryStatisticsItemWrapper(user)::getForm, id);
}
/**
* 切换薪资项目
* @param request
* @param response
* @param itemId
* @return
*/
@GET
@Path("/changeTab")
@Produces(MediaType.APPLICATION_JSON)
public String changeTab(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "itemId") Long itemId) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<Long, SalaryStatisticsItemFormDTO>(user).run(getSalaryStatisticsItemWrapper(user)::changeTab, itemId);
}
/**
* 自定义统计项目列表
@ -55,7 +71,7 @@ public class SalaryStatisticsItemController {
@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public String list(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "statisticsReportId")Long statisticsReportId) {
public String list(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "statisticsReportId") Long statisticsReportId) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<Long, List<Map<String, Object>>>(user).run(getSalaryStatisticsItemWrapper(user)::list, statisticsReportId);
}

View File

@ -9,6 +9,7 @@ import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
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.SalaryStatisticsItemStringRuleEnum;
import com.engine.salary.report.enums.UnitTypeEnum;
import com.engine.salary.report.service.SalaryStatisticsItemService;
import com.engine.salary.report.service.impl.SalaryStatisticsItemServiceImpl;
@ -48,7 +49,7 @@ public class SalaryStatisticsItemWrapper extends Service {
* @return
*/
public SalaryStatisticsItemFormDTO getForm(Long id) {
Map weaForm = new HashMap();
Map<String, Object> weaForm = new HashMap<>();
Map<String, Object> ruleData = new HashMap<>();
if (Objects.nonNull(id)) {
SalaryStatisticsItemPO salaryStatisticsItem = getSalaryStatisticsItemService(user).getById(id);
@ -65,7 +66,7 @@ public class SalaryStatisticsItemWrapper extends Service {
welfareItem.put("dataType", itemsMap.get(value).getDataType());
welfareItems.add(welfareItem);
});
Map map = new HashMap();
Map<String, Object> map = new HashMap<>();
//版本变更由多选变成单选
map.put("itemValue", welfareItems.get(0));
map.put("itemName", salaryStatisticsItem.getItemName());
@ -83,128 +84,168 @@ public class SalaryStatisticsItemWrapper extends Service {
.build();
}
public Map buildRule(SalaryDataTypeEnum dataType, SalaryStatisticsItemPO salaryStatisticsItem) {
Map<String, Object> weaTable = new HashMap<>();
public SalaryStatisticsItemFormDTO changeTab(Long itemId) {
SalaryItemPO po = getSalaryItemService(user).getById(itemId);
Map<String, Object> ruleData = buildRule(SalaryDataTypeEnum.parseByValue(po.getDataType()), null);
return SalaryStatisticsItemFormDTO.builder().ruleData(ruleData).build();
}
public Map<String, Object> buildRule(SalaryDataTypeEnum dataType, SalaryStatisticsItemPO salaryStatisticsItem) {
Map<String, Object> weaTable;
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);
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);
}
}
weaTable.put("data", result);
weaTable = buildNumberRule(salaryStatisticsItem);
} else {
List<WeaTableColumn> list = new ArrayList<>();
WeaTableColumn ruleName = new WeaTableColumn("20%", SalaryI18nUtil.getI18nLabel(157532, "字符取值规则"), "ruleName");
list.add(ruleName);
weaTable.put("columns", list);
List<Map<String, Object>> result = new ArrayList<>();
List<String> ruleList = Arrays.asList("count", "last");
List<String> ruleNameList = Arrays.asList(
SalaryI18nUtil.getI18nLabel(157266, "最近值"));
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);
}
} else {
for (int i = 0; i < ruleList.size(); i++) {
Map<String, Object> rule = new HashMap<>();
switch (ruleList.get(i)) {
case "last":
rule = JSON.parseObject(salaryStatisticsItem.getLatestRule(), 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));
result.add(rule);
}
}
weaTable.put("data", result);
weaTable = buildStringRule(salaryStatisticsItem);
}
return weaTable;
}
/**
* 字符取值规则
*
* @param salaryStatisticsItem 统计项
* @return
*/
private Map<String, Object> buildStringRule(SalaryStatisticsItemPO salaryStatisticsItem) {
Map<String, Object> weaTable = new HashMap<>();
List<WeaTableColumn> list = new ArrayList<>();
WeaTableColumn ruleName = new WeaTableColumn("20%", SalaryI18nUtil.getI18nLabel(157532, "字符取值规则"), "ruleName");
list.add(ruleName);
weaTable.put("columns", list);
List<Map<String, Object>> result = new ArrayList<>();
if (salaryStatisticsItem == null) {
for (SalaryStatisticsItemStringRuleEnum ruleEnum : SalaryStatisticsItemStringRuleEnum.values()) {
Map<String, Object> rule = new HashMap<>();
rule.put("id", ruleEnum.getValue());
rule.put("ruleName", ruleEnum.getDefaultLabel());
rule.put("totalValue", 0);
result.add(rule);
}
} else {
for (SalaryStatisticsItemStringRuleEnum ruleEnum : SalaryStatisticsItemStringRuleEnum.values()) {
Map<String, Object> rule = new HashMap<>();
switch (ruleEnum) {
case LAST:
rule = JSON.parseObject(salaryStatisticsItem.getLastRule(), HashMap.class);
break;
case OLD:
rule = JSON.parseObject(salaryStatisticsItem.getOldRule(), HashMap.class);
break;
case FREQUENT:
rule = JSON.parseObject(salaryStatisticsItem.getFrequentRule(), HashMap.class);
break;
case TILE:
rule = JSON.parseObject(salaryStatisticsItem.getTileRule(), HashMap.class);
break;
default:
break;
}
if (rule == null) {
rule = new HashMap<>();
}
rule.put("id", ruleEnum.getValue());
rule.put("ruleName", ruleEnum.getDefaultLabel());
rule.put("totalValue", Optional.ofNullable(rule.get("totalValue")).orElse(0));
result.add(rule);
}
}
weaTable.put("data", result);
return weaTable;
}
/**
* 数值取值规则
*
* @param salaryStatisticsItem 统计项
* @return
*/
private Map<String, Object> buildNumberRule(SalaryStatisticsItemPO salaryStatisticsItem) {
Map<String, Object> weaTable = new HashMap<>();
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);
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(), HashMap.class);
break;
case "sum":
rule = JSON.parseObject(salaryStatisticsItem.getSumRule(), HashMap.class);
break;
case "avg":
rule = JSON.parseObject(salaryStatisticsItem.getAvgRule(), HashMap.class);
break;
case "max":
rule = JSON.parseObject(salaryStatisticsItem.getMaxRule(), HashMap.class);
break;
case "min":
rule = JSON.parseObject(salaryStatisticsItem.getMinRule(), HashMap.class);
break;
case "median":
rule = JSON.parseObject(salaryStatisticsItem.getMedianRule(), HashMap.class);
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);
}
}
weaTable.put("data", result);
return weaTable;
}
@ -255,4 +296,5 @@ public class SalaryStatisticsItemWrapper extends Service {
public String save(SalaryStatisticsItemSaveParam saveParam) {
return getSalaryStatisticsItemService(user).save(saveParam);
}
}