fix:生产工单中的物料需求功能开发

This commit is contained in:
zhangxuanming 2025-01-16 14:58:59 +08:00
parent 8cb6142d88
commit 30e5302a9b

View File

@ -25,9 +25,8 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.*;
import java.util.Iterator; import java.util.stream.Collectors;
import java.util.List;
/** /**
* 生产工单Controller * 生产工单Controller
@ -228,7 +227,25 @@ public class ProWorkorderController extends BaseController
result.addAll(getBoms(theBom,bom.getQuantity(),0)); result.addAll(getBoms(theBom,bom.getQuantity(),0));
} }
} }
return getDataTable(result); TableDataInfo dataTable = getDataTable(result);
List<MdProductBom> rows = (List<MdProductBom>) dataTable.getRows();
// 使用Map来合并对象
Map<String, MdProductBom> map = new HashMap<>();
for (MdProductBom bom : rows) {
String bomItemCode = bom.getBomItemCode();
if (map.containsKey(bomItemCode)) {
MdProductBom existingObj = map.get(bomItemCode);
existingObj.setQuantity(existingObj.getQuantity().add(bom.getQuantity()) );
} else {
map.put(bomItemCode, bom);
}
}
// 从Map中获取去重且合并后的对象集合
Collection<MdProductBom> mergedCollection = map.values();
// 可选将结果转换回List
List<MdProductBom> mergedList = mergedCollection.stream().collect(Collectors.toList());
dataTable.setRows(mergedList);
return dataTable;
} }
private List<MdProductBom> getBoms(MdProductBom item,BigDecimal quantity,int count){ private List<MdProductBom> getBoms(MdProductBom item,BigDecimal quantity,int count){