원자재, 가공업체 수정

This commit is contained in:
2025-12-19 18:31:26 +09:00
parent 1aa7cb5544
commit e1db86179d
6 changed files with 702 additions and 5 deletions

View File

@@ -1934,4 +1934,147 @@ public class ProductionPlanningService {
return resultList;
}
/**
* M-BOM 기준 원자재(구매품 + 원소재) 소요량 조회
* - 여러 M-BOM을 입력받아 PART_TYPE이 '0000063'(구매품)인 항목 조회
* - RAW_MATERIAL_PART_NO가 있는 항목은 "원소재"로 별도 조회
* - 동일 품번은 합산하여 반환
* @param paramMap - mbomItems: [{mbomObjid, qty}, ...]
* @return 품번별 합산된 소요량 목록
*/
public List getRawMaterialRequirementList(Map paramMap) {
SqlSession sqlSession = null;
List resultList = new ArrayList();
try {
sqlSession = SqlMapConfig.getInstance().getSqlSession();
// 입력받은 M-BOM 목록
List<Map<String, Object>> mbomItems = (List<Map<String, Object>>) paramMap.get("mbomItems");
if(mbomItems == null || mbomItems.isEmpty()) {
return resultList;
}
// 구매품 품번별 소요량 Map
Map<String, Map<String, Object>> purchasePartNoMap = new LinkedHashMap<>();
// 원소재 품번별 소요량 Map
Map<String, Map<String, Object>> rawSourcePartNoMap = new LinkedHashMap<>();
// 각 M-BOM별로 조회하여 합산
for(Map<String, Object> mbomItem : mbomItems) {
String mbomObjid = CommonUtils.nullToEmpty((String)mbomItem.get("mbomObjid"));
int inputQty = 0;
Object qtyObj = mbomItem.get("qty");
if(qtyObj != null) {
if(qtyObj instanceof Number) {
inputQty = ((Number)qtyObj).intValue();
} else {
try {
inputQty = Integer.parseInt(qtyObj.toString());
} catch(NumberFormatException e) {
inputQty = 0;
}
}
}
if("".equals(mbomObjid) || inputQty <= 0) {
continue;
}
Map<String, Object> queryParam = new HashMap<>();
queryParam.put("mbomHeaderObjid", mbomObjid);
// 1. 구매품 조회
List<Map<String, Object>> purchaseItems = sqlSession.selectList("productionplanning.getMbomRawMaterialItems", queryParam);
for(Map<String, Object> bomItem : purchaseItems) {
String partNo = CommonUtils.nullToEmpty((String)bomItem.get("part_no"));
if("".equals(partNo)) continue;
int itemQty = getIntValue(bomItem.get("item_qty"));
int requiredQty = inputQty * itemQty;
if(purchasePartNoMap.containsKey(partNo)) {
Map<String, Object> existingItem = purchasePartNoMap.get(partNo);
int existingQty = (Integer)existingItem.get("REQUIRED_QTY");
existingItem.put("REQUIRED_QTY", existingQty + requiredQty);
} else {
Map<String, Object> newItem = new LinkedHashMap<>();
newItem.put("PART_NO", partNo);
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("REQUIRED_QTY", requiredQty);
// 구매품은 소재 관련 컬럼 빈값
newItem.put("RAW_MATERIAL", "");
newItem.put("RAW_MATERIAL_SIZE", "");
newItem.put("MATERIAL_PART_NO", "");
newItem.put("MATERIAL_REQUIRED_QTY", "");
purchasePartNoMap.put(partNo, newItem);
}
}
// 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;
int itemQty = getIntValue(bomItem.get("item_qty"));
int 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);
} else {
Map<String, Object> newItem = new LinkedHashMap<>();
newItem.put("PART_NO", partNo);
newItem.put("PART_NAME", bomItem.get("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("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);
}
}
}
// 구매품 먼저, 원소재 나중에 합침
resultList.addAll(purchasePartNoMap.values());
resultList.addAll(rawSourcePartNoMap.values());
} catch(Exception e) {
e.printStackTrace();
} finally {
if(sqlSession != null) {
sqlSession.close();
}
}
return resultList;
}
/**
* Object를 int로 변환하는 유틸 메서드
*/
private int getIntValue(Object obj) {
if(obj == null) return 0;
if(obj instanceof Number) {
return ((Number)obj).intValue();
}
try {
return Integer.parseInt(obj.toString());
} catch(NumberFormatException e) {
return 0;
}
}
}