diff --git a/WebContent/WEB-INF/view/productionplanning/semiProductRequirementList.jsp b/WebContent/WEB-INF/view/productionplanning/semiProductRequirementList.jsp new file mode 100644 index 0000000..f59eb89 --- /dev/null +++ b/WebContent/WEB-INF/view/productionplanning/semiProductRequirementList.jsp @@ -0,0 +1,344 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ page import="com.pms.common.utils.*"%> +<%@ page import="java.util.*" %> +<%@include file= "/init.jsp" %> +<% +// DB에서 메뉴명 조회 (공통 유틸 사용) +String menuObjId = request.getParameter("menuObjId"); +String menuName = CommonUtils.getMenuName(menuObjId, "반제품소요량"); +%> + + + + + <%=Constants.SYSTEM_NAME%> + + + + + + + +
+ + + +
+
+
+

+ <%=menuName%> +

+
+ + + +
+
+ + +
+
M-BOM 선택 및 수량 입력
+
+
+ + +
반제품 소요량 (부품/조립품) - 조회결과: 0
+
+
+
+
+ + diff --git a/src/com/pms/controller/ProductionPlanningController.java b/src/com/pms/controller/ProductionPlanningController.java index 41b40c5..0b62a9a 100644 --- a/src/com/pms/controller/ProductionPlanningController.java +++ b/src/com/pms/controller/ProductionPlanningController.java @@ -1844,4 +1844,43 @@ public class ProductionPlanningController extends BaseService { return resultMap; } + /** + * 반제품소요량 조회 화면 + */ + @RequestMapping("/productionplanning/semiProductRequirementList.do") + public String semiProductRequirementList(HttpServletRequest request, @RequestParam Map paramMap) { + Map code_map = new HashMap(); + try { + // M-BOM 목록 (셀렉트박스용) + code_map.put("mbom_list", commonService.bizMakeOptionList("", "", "productionplanning.getMbomListForSelect2")); + + request.setAttribute("code_map", code_map); + } catch(Exception e) { + e.printStackTrace(); + } + return "/productionplanning/semiProductRequirementList"; + } + + /** + * M-BOM 기준 반제품 소요량 조회 + * @param request + * @param paramMap - mbomItems: [{mbomObjid, qty}, ...] + * @return 품번별 합산된 소요량 목록 + */ + @ResponseBody + @RequestMapping(value="/productionplanning/getSemiProductRequirementList.do", produces="application/json;charset=UTF-8") + public Map getSemiProductRequirementList(HttpServletRequest request, @RequestBody Map paramMap) { + Map resultMap = new HashMap(); + try { + List list = productionPlanningService.getSemiProductRequirementList(paramMap); + resultMap.put("result", "success"); + resultMap.put("list", list); + } catch(Exception e) { + e.printStackTrace(); + resultMap.put("result", "fail"); + resultMap.put("msg", "조회 실패: " + e.getMessage()); + } + return resultMap; + } + } diff --git a/src/com/pms/mapper/productionplanning.xml b/src/com/pms/mapper/productionplanning.xml index 33ea7d3..0473770 100644 --- a/src/com/pms/mapper/productionplanning.xml +++ b/src/com/pms/mapper/productionplanning.xml @@ -4743,5 +4743,26 @@ MODIFIER = #{userId} WHERE OBJID = #{OBJID} + + + diff --git a/src/com/pms/service/ProductionPlanningService.java b/src/com/pms/service/ProductionPlanningService.java index fea250b..3873fd4 100644 --- a/src/com/pms/service/ProductionPlanningService.java +++ b/src/com/pms/service/ProductionPlanningService.java @@ -2,6 +2,7 @@ package com.pms.service; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -1827,4 +1828,110 @@ public class ProductionPlanningService { return result; } + + /** + * M-BOM 기준 반제품 소요량 조회 + * - 여러 M-BOM을 입력받아 범주가 '부품', '조립품'인 항목만 조회 + * - 동일 품번은 합산하여 반환 + * @param paramMap - mbomItems: [{mbomObjid, qty}, ...] + * @return 품번별 합산된 소요량 목록 + */ + public List getSemiProductRequirementList(Map paramMap) { + SqlSession sqlSession = null; + List resultList = new ArrayList(); + + try { + sqlSession = SqlMapConfig.getInstance().getSqlSession(); + + // 입력받은 M-BOM 목록 + List> mbomItems = (List>) paramMap.get("mbomItems"); + if(mbomItems == null || mbomItems.isEmpty()) { + return resultList; + } + + // 품번별 소요량을 합산하기 위한 Map (key: PART_NO, value: {품번정보, 소요량합계}) + Map> partNoMap = new LinkedHashMap<>(); + + // 각 M-BOM별로 조회하여 합산 + for(Map 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; + } + + // M-BOM 항목 조회 (범주가 '부품', '조립품'인 것만) + Map queryParam = new HashMap<>(); + queryParam.put("mbomHeaderObjid", mbomObjid); + List> bomItems = sqlSession.selectList("productionplanning.getMbomSemiProductItems", queryParam); + + // 소요량 합산 (PostgreSQL은 소문자 키로 반환) + for(Map bomItem : bomItems) { + String partNo = CommonUtils.nullToEmpty((String)bomItem.get("part_no")); + if("".equals(partNo)) continue; + + // M-BOM의 항목수량 + int itemQty = 0; + Object itemQtyObj = bomItem.get("item_qty"); + if(itemQtyObj != null) { + if(itemQtyObj instanceof Number) { + itemQty = ((Number)itemQtyObj).intValue(); + } else { + try { + itemQty = Integer.parseInt(itemQtyObj.toString()); + } catch(NumberFormatException e) { + itemQty = 0; + } + } + } + + // 소요량 = 입력수량 × 항목수량 + int requiredQty = inputQty * itemQty; + + if(partNoMap.containsKey(partNo)) { + // 기존 품번이면 소요량만 합산 + Map existingItem = partNoMap.get(partNo); + int existingQty = (Integer)existingItem.get("REQUIRED_QTY"); + existingItem.put("REQUIRED_QTY", existingQty + requiredQty); + } else { + // 새로운 품번이면 추가 + Map 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); + partNoMap.put(partNo, newItem); + } + } + } + + // Map -> List 변환 + resultList = new ArrayList(partNoMap.values()); + + } catch(Exception e) { + e.printStackTrace(); + } finally { + if(sqlSession != null) { + sqlSession.close(); + } + } + + return resultList; + } }