提交 b39e03f6 authored 作者: inroi's avatar inroi

微调

上级 6896c1d7
......@@ -114,10 +114,14 @@ public class BillOfMaterialKingDeeApi {
}
}
//使用比例
List<Map<String, Object>> tempList = this.tree(list, String.valueOf(map.get("mtrl_code")));
String code = this.getTopLevel(list, String.valueOf(map.get("main_code")));
List<Map<String, Object>> tempList = this.tree(list, code);
if (!CollectionUtils.isEmpty(tempList)) {
int dosage = tempList.stream().mapToInt(m -> Integer.parseInt(String.valueOf(m.get("dosage")))).sum();
double value = new BigDecimal(Integer.parseInt(String.valueOf(map.get("dosage"))) / dosage).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
tempList.add(list.stream().filter(m -> code.equals(String.valueOf(m.get("mtrl_code")))).findFirst().orElse(new HashMap<>()));
int dosage = Integer.parseInt(String.valueOf(map.get("dosage")));
int dosageTotal = tempList.stream().mapToInt(m -> Integer.parseInt(String.valueOf(m.get("dosage")))).sum();
String ratio = Double.toString(((double) dosage / dosageTotal));
BigDecimal value = new BigDecimal(ratio).setScale(6, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
fEntityMap.put("FUseRate", value);
} else {
fEntityMap.put("FUseRate", 100);
......@@ -130,14 +134,30 @@ public class BillOfMaterialKingDeeApi {
return modelMap;
}
public String getTopLevel(List<Map<String, Object>> dataList, String code) {
List<Map<String, Object>> tempList = dataList.stream()
.filter(m -> code.equals(String.valueOf(m.get("mtrl_code"))))
.collect(Collectors.toList());
for (Map<String, Object> temp : tempList) {
if ("true".equals(String.valueOf(temp.get("is_main")))) {
return String.valueOf(temp.get("mtrl_code"));
}
return this.getTopLevel(dataList, String.valueOf(temp.get("main_code")));
}
return "";
}
public List<Map<String, Object>> tree(List<Map<String, Object>> dataList, String code) {
List<Map<String, Object>> response = new ArrayList<>();
List<Map<String, Object>> tempList = dataList.stream()
.filter(m -> code.equals(String.valueOf(m.get("main_code"))) && !code.equals(String.valueOf(m.get("mtrl_code"))))
.collect(Collectors.toList());
for (Map<String, Object> temp : tempList) {
tempList.addAll(this.tree(dataList, String.valueOf(temp.get("mtrl_code"))));
response.add(temp);
response.addAll(this.tree(dataList, String.valueOf(temp.get("mtrl_code"))));
}
return tempList;
return response;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论