원자재, 구매리스트 가공업체 수정~~

This commit is contained in:
2025-12-22 11:26:55 +09:00
parent e1db86179d
commit 57b14daf19
6 changed files with 90 additions and 49 deletions

View File

@@ -2004,10 +2004,10 @@ public class ProductionPlanningService {
newItem.put("PART_NAME", bomItem.get("part_name"));
newItem.put("CATEGORY_NAME", bomItem.get("category_name"));
newItem.put("UNIT", bomItem.get("unit"));
newItem.put("MATERIAL", bomItem.get("material"));
newItem.put("SPEC", bomItem.get("spec"));
// 구매품은 소재 관련 컬럼 전부 빈값
newItem.put("MATERIAL", "");
newItem.put("SPEC", "");
newItem.put("REQUIRED_QTY", requiredQty);
// 구매품은 소재 관련 컬럼 빈값
newItem.put("RAW_MATERIAL", "");
newItem.put("RAW_MATERIAL_SIZE", "");
newItem.put("MATERIAL_PART_NO", "");
@@ -2017,40 +2017,50 @@ public class ProductionPlanningService {
}
// 2. 원소재 조회 (RAW_MATERIAL_PART_NO가 있는 항목)
// 원소재는 소재품번 기준으로 합산 (소수점 합산 후 올림)
List<Map<String, Object>> rawSourceItems = sqlSession.selectList("productionplanning.getMbomRawSourceItems", queryParam);
for(Map<String, Object> bomItem : rawSourceItems) {
String partNo = CommonUtils.nullToEmpty((String)bomItem.get("part_no"));
if("".equals(partNo)) continue;
String materialPartNo = CommonUtils.nullToEmpty((String)bomItem.get("raw_material_part_no"));
if("".equals(materialPartNo)) continue;
int itemQty = getIntValue(bomItem.get("item_qty"));
int requiredQty = inputQty * itemQty;
double itemQty = getDoubleValue(bomItem.get("item_qty"));
double requiredQty = inputQty * itemQty;
if(rawSourcePartNoMap.containsKey(partNo)) {
Map<String, Object> existingItem = rawSourcePartNoMap.get(partNo);
int existingQty = (Integer)existingItem.get("REQUIRED_QTY");
existingItem.put("REQUIRED_QTY", existingQty + requiredQty);
if(rawSourcePartNoMap.containsKey(materialPartNo)) {
Map<String, Object> existingItem = rawSourcePartNoMap.get(materialPartNo);
double existingQty = (Double)existingItem.get("MATERIAL_REQUIRED_QTY_RAW");
existingItem.put("MATERIAL_REQUIRED_QTY_RAW", existingQty + requiredQty);
} else {
Map<String, Object> newItem = new LinkedHashMap<>();
newItem.put("PART_NO", partNo);
newItem.put("PART_NAME", bomItem.get("part_name"));
// 원소재는 품번, 품명, 소요량 빈값
newItem.put("PART_NO", "");
newItem.put("PART_NAME", "");
newItem.put("CATEGORY_NAME", "원소재");
newItem.put("UNIT", "");
newItem.put("MATERIAL", bomItem.get("raw_material"));
newItem.put("SPEC", bomItem.get("raw_material_size"));
newItem.put("REQUIRED_QTY", requiredQty);
// 원소재 관련 컬럼
newItem.put("REQUIRED_QTY", "");
// 원소재 관련 컬럼만 표시
newItem.put("RAW_MATERIAL", bomItem.get("raw_material"));
newItem.put("RAW_MATERIAL_SIZE", bomItem.get("raw_material_size"));
newItem.put("MATERIAL_PART_NO", bomItem.get("raw_material_part_no"));
newItem.put("MATERIAL_REQUIRED_QTY", requiredQty);
rawSourcePartNoMap.put(partNo, newItem);
newItem.put("MATERIAL_PART_NO", materialPartNo);
newItem.put("MATERIAL_REQUIRED_QTY_RAW", requiredQty); // 합산용 (소수점)
rawSourcePartNoMap.put(materialPartNo, newItem);
}
}
}
// 구매품 먼저, 원소재 나중에 합침
// 구매품 먼저 추가
resultList.addAll(purchasePartNoMap.values());
resultList.addAll(rawSourcePartNoMap.values());
// 원소재는 소수점 합산 후 올림 처리하여 추가
for(Map<String, Object> item : rawSourcePartNoMap.values()) {
double rawQty = (Double)item.get("MATERIAL_REQUIRED_QTY_RAW");
int ceilQty = (int)Math.ceil(rawQty); // 올림 처리
item.put("MATERIAL_REQUIRED_QTY", ceilQty);
item.remove("MATERIAL_REQUIRED_QTY_RAW"); // 임시 필드 제거
resultList.add(item);
}
} catch(Exception e) {
e.printStackTrace();
@@ -2077,4 +2087,19 @@ public class ProductionPlanningService {
return 0;
}
}
/**
* Object를 double로 변환하는 유틸 메서드
*/
private double getDoubleValue(Object obj) {
if(obj == null) return 0.0;
if(obj instanceof Number) {
return ((Number)obj).doubleValue();
}
try {
return Double.parseDouble(obj.toString());
} catch(NumberFormatException e) {
return 0.0;
}
}
}