From 84ad04810bce1cf070162c257bd03d87a82e3751 Mon Sep 17 00:00:00 2001 From: mzr Date: Mon, 15 Sep 2025 21:44:33 +0800 Subject: [PATCH] =?UTF-8?q?bom=E6=9B=BF=E4=BB=A3=E6=96=99=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mmbd/bom/APIBomBusinessServiceImpl.java | 3408 +++++++++-------- .../api/mmbd/bom/IAPIBomBusinessService.java | 24 + .../nccloud/openapi/mmbd/bom/BomResource.java | 233 +- 3 files changed, 1847 insertions(+), 1818 deletions(-) create mode 100644 uapbd/src/public/nccloud/api/mmbd/bom/IAPIBomBusinessService.java diff --git a/uapbd/src/private/nccloud/api/impl/mmbd/bom/APIBomBusinessServiceImpl.java b/uapbd/src/private/nccloud/api/impl/mmbd/bom/APIBomBusinessServiceImpl.java index 9ac9a0a..22909fc 100644 --- a/uapbd/src/private/nccloud/api/impl/mmbd/bom/APIBomBusinessServiceImpl.java +++ b/uapbd/src/private/nccloud/api/impl/mmbd/bom/APIBomBusinessServiceImpl.java @@ -1,5 +1,7 @@ package nccloud.api.impl.mmbd.bom; +import nc.bs.bd.bom.bom0202.bp.BomPubBP; +import nc.bs.bd.bom.bom0202.bp.BomUpdateBP; import nc.bs.dao.BaseDAO; import nc.bs.framework.common.InvocationInfoProxy; import nc.bs.framework.common.NCLocator; @@ -24,9 +26,12 @@ import nc.util.mmf.busi.measure.MeasureParam; import nc.util.mmf.busi.measure.MeasureVO; import nc.util.mmf.busi.measure.NumScaleUtil; import nc.util.mmf.busi.service.OrgUnitPubService; +import nc.util.mmf.framework.base.MMArrayUtil; import nc.util.mmf.framework.base.MMValueCheck; +import nc.util.mmf.framework.gc.GCBillTransferTool; import nc.vo.bd.bom.bom0202.entity.*; import nc.vo.bd.bom.bom0202.enumeration.*; +import nc.vo.bd.bom.bom0202.message.MMBDLangConstBom0202; import nc.vo.bd.bom.bom0202.paramvo.BomHeadMtrlParam; import nc.vo.bd.bom.bom0202.paramvo.BomHeadMtrlResult; import nc.vo.bd.bom.bom0202.paramvo.BomMaterialParam; @@ -61,1022 +66,1051 @@ import java.util.stream.Stream; public class APIBomBusinessServiceImpl implements IAPIBomBusinessService { - // 2025年5月28日 电缆组织金思维BOM版本号自动计算处理 - private static final BaseDAO DAO = new BaseDAO(); - - private static final IHttpPostOtherSys HTTP_POST_OTHER_SYS = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); - - // 2025年7月4日 添加日志支持 - private static final String LOG_INFO_NAME = "OALOG"; - private static final Log obmlog = Log.getInstance(LOG_INFO_NAME); - - public static final String MESUSERCODE = "MES"; - - private static String HEADTABLE = "bd_bom"; - - private static String BODYTABLE = "bd_bom_b"; - - private static String ORGTABLE = "bd_bom_useorg"; - - private static String ACTIVITYTABLE = "bd_bom_activity"; - - private static String OUTPUTSTABLE = "bd_bom_outputs"; - - private static String POSITIONTABLE = "bd_bom_position"; - - private static String REPLTABLE = "bd_bom_repl"; - - private static String LOSSTABLE = "bd_bom_loss"; - - private static String WIPTABLE = "bd_bom_wip"; - - private static Map tsMap = new HashMap(); - - private String orgCodeFlag = null; - - private static Map voMap = new HashMap(); - - private static Map> idsMap = new HashMap(); - - public JSONString insert(List> paramList) { - try { - IBomBillMaintainService service = (IBomBillMaintainService) NCLocator.getInstance() - .lookup(IBomBillMaintainService.class); - List list = new ArrayList(); - for (Map paramMap : paramList) { - if (!paramMap.containsKey(HEADTABLE) || !paramMap.containsKey(BODYTABLE)) { - return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); - } - - AggBomVO agg = aggInit(paramMap); - - JSONString checkInfo = requiredCheck(agg); - if (checkInfo != null) { - return checkInfo; - } - - list.add(agg); - } - AggBomVO[] aggVOs = (AggBomVO[]) list.toArray(new AggBomVO[list.size()]); - if (aggVOs[0].getParentVO().getAttributeValue("pk_org") == null || aggVOs[0].getParentVO().getAttributeValue("pk_org") == "") { - ExceptionUtils.wrappBusinessException("请求参数pk_org为空,请检查!!!!"); - } else { - this.orgCodeFlag = aggVOs[0].getParentVO().getAttributeValue("pk_org").toString(); - } - BillFieldsCodeToPkUtil.doTranslateVOFields(aggVOs); - IUifService iUifService = NCLocator.getInstance().lookup(IUifService.class); - for (AggBomVO aggtwo : aggVOs) { - BomItemVO[] items = aggtwo.getChildrenVO(); - //2025年5月9日08点56分--添加表头物料翻译校验 start - if (aggtwo.getParent().getAttributeValue("hcmaterialid") != null) { - MaterialVO headMaterialVO = (MaterialVO) iUifService.queryByPrimaryKey(MaterialVO.class, - aggtwo.getParent().getAttributeValue("hcmaterialid").toString()); - if (headMaterialVO == null) { - ExceptionUtils.wrappBusinessException("根据物料【" + aggtwo.getParent().getAttributeValue("hcmaterialid").toString() + "】查询物料失败,请在BIP里确认是否物料已存在!!!"); - } - } - //2025年5月9日08点56分--添加表头物料翻译校验 end - for (int i = 0; i < items.length; i++) { - MaterialVO bankAccSub = (MaterialVO) iUifService.queryByPrimaryKey(MaterialVO.class, - items[i].getAttributeValue("cmaterialid").toString()); - //2025年5月7日08点41分 添加为空校验 sdlizheng --start - if (bankAccSub == null) { - ExceptionUtils.wrappBusinessException("根据物料【" + items[i].getAttributeValue("cmaterialid").toString() + "】查询物料失败,请在BIP里确认是否物料已存在!!!"); - } - //2025年5月7日08点41分 添加为空校验 sdlizheng --end - items[i].setAttributeValue("cmaterialvid", bankAccSub.getAttributeValue("pk_source")); - } - } - List commitAggvoList = new ArrayList<>(); - List addAggvoList = new ArrayList<>(); - String userCode = InvocationInfoProxy.getInstance().getUserCode(); - for (AggBomVO agg : aggVOs) { - Object fBillStatusFlag = agg.getParent().getAttributeValue("fbillstatus"); - if (fBillStatusFlag == null || "-1".equals(fBillStatusFlag.toString())) { - addAggvoList.add(agg); - } else if ("1".equals(fBillStatusFlag.toString())) { - commitAggvoList.add(agg); - } - // zhangxinah 对物料主键进行翻译 - dealWithMaterial(agg); - - // 2025年5月28日 电缆组织金思维BOM版本号自动计算处理 By maolei - handleCableOrgJinSiWeiBomVersion(agg); - - dataSupplement(agg, userCode); - - UFBoolean flag = (UFBoolean) agg.getParent().getAttributeValue("hbdefault"); - if (UFBoolean.TRUE.equals(flag)) { - UFBoolean bHasOtherDefaultVersion = getIsExistDefaultVersion(agg, userCode); - if (bHasOtherDefaultVersion.equals(UFBoolean.TRUE)) { - ExceptionUtils.wrappBusinessException("有其它默认版本,请检查!!!"); - } - } - (new BomSavingValidation()).validate(agg); - } - - mapClear(); - // 请求参数状态为审批通过时,自动提交--不设审批流 start - AggBomVO[] result = null; - if (commitAggvoList.isEmpty() && addAggvoList.isEmpty()) { - return ResultMessageUtil.exceptionToJSON("BOM保存失败,不存在单据状态不为【空/自由/审批通过】的数据", "999"); - } else if (commitAggvoList.isEmpty() && !addAggvoList.isEmpty()) { - result = service.insertBom((AggBomVO[]) addAggvoList.toArray(new AggBomVO[0])); - } else if (!commitAggvoList.isEmpty() && addAggvoList.isEmpty()) { - List newAggVOList = new ArrayList<>(); - if ("gaoning".equals(userCode) || "C029".equals(orgCodeFlag)) { - for (AggBomVO aggvo : commitAggvoList) { - result = service.insertCommitBomWithParam(new AggBomVO[]{aggvo}, true, true); - insertBomMatchRt(result); - newAggVOList.add(result[0]); - } - return ResultMessageUtil.toJSON(newAggVOList.toArray(new AggBomVO[0]), "BOM保存成功"); - } else if ("dlkgsrm".equals(userCode) || "hgqwms".equals(userCode)) { - for (AggBomVO aggvo : commitAggvoList) { - try { - result = service.insertCommitBomWithParam_RequiresNew(new AggBomVO[]{aggvo}, true, true); - newAggVOList.add(result[0]); - } catch (Exception e) { - if (e.getMessage() != null) { - if (e.getMessage().length() > 100) { - aggvo.getParent().setAttributeValue("hvdef2", e.getMessage().substring(0, 100)); - } else { - aggvo.getParent().setAttributeValue("hvdef2", - e.getMessage().substring(0, e.getMessage().length() - 1)); - } - } else { - Throwable unmarsh = ExceptionUtils.unmarsh(e); - aggvo.getParent().setAttributeValue("hvdef2", "异常" + unmarsh.getMessage()); - } - - newAggVOList.add(aggvo); - } - } - return ResultMessageUtil.toJSON(newAggVOList.toArray(new AggBomVO[0]), "100999", - "BOM保存提交成功部分成功部分失败", true); - } else { - try { - IHttpPostOtherSys httpPostOtherSys = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); - - // 检查当前用户是否为排除用户 - if (httpPostOtherSys.checkIfExcludeUser()) { - // 排除用户直接跳过同步处理,执行普通保存逻辑 - for (AggBomVO aggvo : commitAggvoList) { - result = service.insertBom(new AggBomVO[]{aggvo}); - newAggVOList.add(result[0]); - } - return ResultMessageUtil.toJSON(newAggVOList.toArray(new AggBomVO[0]), "BOM保存成功(排除用户)"); - } - - // 检查当前组织是否属于金思维MES同步组织(电缆组织) - String currentOrgCode = this.orgCodeFlag; - boolean isIncludeOrg = httpPostOtherSys.checkIfIncludeOrg(currentOrgCode); - - if (isIncludeOrg) { - // 属于金思维MES同步组织,执行特殊处理逻辑 - for (AggBomVO aggvo : commitAggvoList) { - result = service.insertCommitBomWithParam(new AggBomVO[]{aggvo}, true, true); - newAggVOList.add(result[0]); - } - return ResultMessageUtil.toJSON(newAggVOList.toArray(new AggBomVO[0]), "BOM保存成功(金思维MES同步组织)"); - } else { - // 不属于金思维MES同步组织,执行默认处理逻辑 - for (AggBomVO aggvo : commitAggvoList) { - try { - result = service.insertCommitBomWithParam_RequiresNew(new AggBomVO[]{aggvo}, true, true); - newAggVOList.add(result[0]); - } catch (Exception e) { - if (e.getMessage() != null) { - if (e.getMessage().length() > 100) { - aggvo.getParent().setAttributeValue("hvdef2", e.getMessage().substring(0, 100)); - } else { - aggvo.getParent().setAttributeValue("hvdef2", - e.getMessage().substring(0, e.getMessage().length() - 1)); - } - } else { - Throwable unmarsh = ExceptionUtils.unmarsh(e); - aggvo.getParent().setAttributeValue("hvdef2", "异常" + unmarsh.getMessage()); - } - newAggVOList.add(aggvo); - } - } - return ResultMessageUtil.toJSON(newAggVOList.toArray(new AggBomVO[0]), "100999", - "BOM保存提交成功部分成功部分失败", true); - } - } catch (BusinessException e) { - // HTTP工具类调用失败时,回退到原有的异常处理 - ExceptionUtils.wrappBusinessException("HTTP工具类判断失败:" + e.getMessage() + ",未匹配到符合条件的三方注册用户账号【" + userCode + "】,请检查!!!"); - } - } - - } else { - return ResultMessageUtil.exceptionToJSON("BOM保存失败,新增不允许单据状态自由或者空和审批通过同时存在", "999"); - } - // 请求参数状态为审批通过时,自动提交--不设审批流 end - return ResultMessageUtil.toJSON(result, "BOM保存成功"); - } catch (Exception e) { - return ResultMessageUtil.exceptionToJSON(e); - } - } - - - private void insertBomMatchRt(AggBomVO[] result) throws BusinessException { - AggBomVO aggBomVO = result[0]; - BomVO bomVO = (BomVO) aggBomVO.getParentVO(); - BomItemVO[] bomItemVOs = aggBomVO.getChildrenVO(); - SuperVOUtil.sortByAttributeName(bomItemVOs,"cbeginperiod",false); - - BomMatchRtVO bomMatchRtVO = new BomMatchRtVO(); - bomMatchRtVO.setStatus(VOStatus.NEW); - bomMatchRtVO.setDr(0); - bomMatchRtVO.setPk_group(PubEnv.getPk_group()); - bomMatchRtVO.setPk_org(bomVO.getPk_org()); - bomMatchRtVO.setPk_org_v(bomVO.getPk_org_v()); - bomMatchRtVO.setCmaterialid(bomVO.getHcmaterialid()); - bomMatchRtVO.setCmaterialvid(bomVO.getHcmaterialvid()); - - String hversion = bomVO.getHversion(); - String whereSql = " project_code ='" + hversion + "' and pk_org='" + bomVO.getPk_org() + "' and nvl(dr,0)=0 "; - // IBean bean = MDManageUtil.getBeanByContainedObject(new AggBomVO()); - // String hcprojectid = TranslateUtils.trancelateCodeToID(bean, "hcprojectid", hversion, PubEnv.getPk_group()); - List projectList = (List) new BaseDAO().retrieveByClause(ProjectHeadVO.class, - whereSql); - if (projectList != null && projectList.size() > 0) { - bomMatchRtVO.setCprojectid(projectList.get(0).getPk_project()); - } - - bomMatchRtVO.setDeffectdate(bomItemVOs[0].getCbeginperiod()); - bomMatchRtVO.setDloseeffectdate(bomItemVOs[0].getCendperiod()); - bomMatchRtVO.setProduction(UFBoolean.TRUE); - bomMatchRtVO.setEntrust(UFBoolean.FALSE); - bomMatchRtVO.setCbomid(bomVO.getPrimaryKey()); - IBmrtMaintain iBmrtMaintain = NCLocator.getInstance().lookup(IBmrtMaintain.class); - BomMatchRtVO[] insert = iBmrtMaintain.insert(new BomMatchRtVO[]{bomMatchRtVO}); - System.out.println(insert); - } - - - private void dealWithMaterial(AggBomVO agg) { - String hcmaterialvid = (String) agg.getParentVO().getAttributeValue("hcmaterialvid"); - String hcmaterialid = (String) agg.getParentVO().getAttributeValue("hcmaterialid"); - // 物料没启用版本,直接赋值 - if (hcmaterialvid.length() == 20) { - agg.getParentVO().setAttributeValue("hcmaterialid", hcmaterialvid); - } - // 物料没启用版本,直接赋值 - if (hcmaterialid.length() == 20) { - agg.getParentVO().setAttributeValue("hcmaterialvid", hcmaterialid); - } - } - - public JSONString update(List> paramList) { - try { - IBomBillMaintainService service = (IBomBillMaintainService) NCLocator.getInstance() - .lookup(IBomBillMaintainService.class); - - IBomBillQueryService queryService = (IBomBillQueryService) NCLocator.getInstance() - .lookup(IBomBillQueryService.class); - List list = new ArrayList(); - List idList = new ArrayList(); - Map map = new HashMap(); - for (Map paramMap : paramList) { - - Map bom = (Map) paramMap.get(HEADTABLE); - idList.add((String) bom.get("cbomid")); - } - AggBomVO[] originalvos = queryService.queryAggBomByBomID((String[]) idList.toArray(new String[0])); - for (AggBomVO originalvo : originalvos) { - map.put(originalvo.getParent().getPrimaryKey(), originalvo); - } - - for (Map paramMap : paramList) { - if (!paramMap.containsKey(HEADTABLE) || !paramMap.containsKey(BODYTABLE)) { - return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); - } - - Map bom = (Map) paramMap.get(HEADTABLE); - AggBomVO original = (AggBomVO) map.get((String) bom.get("cbomid")); - - mapInit(original); - - AggBomVO agg = aggInit(paramMap); - // 2025年4月11日14点35分 --重新赋值上制单人创建人+默认 --start - agg.getParentVO().setAttributeValue("billmaker", original.getParent().getAttributeValue("billmaker")); - agg.getParentVO().setAttributeValue("creator", original.getParent().getAttributeValue("creator")); - if (bom.get("hbdefault") == null) { - agg.getParentVO().setAttributeValue("hbdefault", - original.getParent().getAttributeValue("hbdefault")); - } - // 2025年4月11日14点35分 --重新赋值上制单人创建人+默认 --end - JSONString checkInfo = requiredCheck(agg); - if (checkInfo != null) { - return checkInfo; - } - list.add(agg); - } - - AggBomVO[] aggVOs = (AggBomVO[]) list.toArray(new AggBomVO[list.size()]); - - BillFieldsCodeToPkUtil.doTranslateVOFields(aggVOs); - IUifService iUifService = NCLocator.getInstance().lookup(IUifService.class); - for (AggBomVO aggtwo : aggVOs) { - //2025年5月9日08点56分--添加表头物料翻译校验 start - if (aggtwo.getParent().getAttributeValue("hcmaterialid") != null) { - MaterialVO headMaterialVO = (MaterialVO) iUifService.queryByPrimaryKey(MaterialVO.class, - aggtwo.getParent().getAttributeValue("hcmaterialid").toString()); - if (headMaterialVO == null) { - ExceptionUtils.wrappBusinessException("根据物料【" + aggtwo.getParent().getAttributeValue("hcmaterialid").toString() + "】查询物料失败,请在BIP里确认是否物料已存在!!!"); - } - } - //2025年5月9日08点56分--添加表头物料翻译校验 end - BomItemVO[] items = aggtwo.getChildrenVO(); - for (int i = 0; i < items.length; i++) { - MaterialVO bankAccSub = (MaterialVO) iUifService.queryByPrimaryKey(MaterialVO.class, - items[i].getAttributeValue("cmaterialid").toString()); - //2025年5月7日08点41分 添加为空校验 sdlizheng --start - if (bankAccSub == null) { - ExceptionUtils.wrappBusinessException("根据物料【" + items[i].getAttributeValue("cmaterialid").toString() + "】查询物料失败,请在BIP里确认是否物料已存在!!!"); - } - //2025年5月7日08点41分 添加为空校验 sdlizheng --end - items[i].setAttributeValue("cmaterialvid", bankAccSub.getAttributeValue("pk_source")); - } - } - String userCode = InvocationInfoProxy.getInstance().getUserCode(); - for (AggBomVO agg : aggVOs) { - // zhangxinah 对物料主键进行翻译 - dealWithMaterial(agg); - dataSupplement(agg, userCode); - - UFBoolean flag = (UFBoolean) agg.getParent().getAttributeValue("hbdefault"); - if (UFBoolean.TRUE.equals(flag)) { - UFBoolean bHasOtherDefaultVersion = getIsExistDefaultVersion(agg, userCode); - if (bHasOtherDefaultVersion.equals(UFBoolean.TRUE)) { - ExceptionUtils.wrappBusinessException("有其它默认版本,请检查!!!"); - } - } - - (new BomSavingValidation()).validate(agg); - } - - mapClear(); - - AggBomVO[] result = service.updateBom((AggBomVO[]) list.toArray(new AggBomVO[0])); - return ResultMessageUtil.toJSON(result, "BOM保存成功"); - } catch (Exception e) { - return ResultMessageUtil.exceptionToJSON(e); - } - } - - public JSONString query(Map paramMap) { - try { - Map map = mapDataTranslator(paramMap); - - QuerySchemeUtils schemeUtil = new QuerySchemeUtils(AggBomVO.class, map); - IQueryScheme queryscheme = schemeUtil.creatQueryScheme(); - IBomBillQueryService query = (IBomBillQueryService) NCLocator.getInstance() - .lookup(IBomBillQueryService.class); - - AggBomVO[] aggvos = query.queryBySchemeAndPwdkeyForBomWithParam(queryscheme, null, getRelation(), false, - false); - - if (MMValueCheck.isEmpty(aggvos)) { - return ResultMessageUtil.toJSON(new AggBomVO[0], "无相应数据"); - } - - Set pkSet = (Set) Stream.of(aggvos).map(AbstractBill::getPrimaryKey).collect(Collectors.toSet()); - AggBomVO[] results = query.queryAggBomByBomID((String[]) pkSet.toArray(new String[0])); - - List list = new ArrayList(); - if (MMValueCheck.isNotEmpty(aggvos)) { - for (AggBomVO agg : aggvos) { - list.add((BomVO) agg.getParentVO()); - } - } - return ResultMessageUtil.toJSON(results, "查询成功"); - } catch (Exception e) { - return ResultMessageUtil.exceptionToJSON(e); - } - } - - private void mapInit(AggBomVO aggs) { - tsMap.put(aggs.getParent().getPrimaryKey(), aggs.getParent().getAttributeValue("ts")); - - BomItemVO[] items = aggs.getChildrenVO(); - - if (MMValueCheck.isEmpty(items)) { - return; - } - - Set itemSet = new HashSet(); - for (BomItemVO item : items) { - tsMap.put(item.getPrimaryKey(), item.getTs()); - voMap.put(item.getPrimaryKey(), item); - itemSet.add(item.getPrimaryKey()); - - BomWipVO[] wips = item.getWips(); - Set wipSet = new HashSet(); - if (MMValueCheck.isNotEmpty(wips)) { - for (BomWipVO vo : wips) { - tsMap.put(vo.getCbom_wipid(), vo.getTs()); - voMap.put(vo.getCbom_wipid(), vo); - wipSet.add(vo.getCbom_wipid()); - } - idsMap.put(WIPTABLE, wipSet); - } - - BomPosVO[] pos = item.getPos(); - Set posSet = new HashSet(); - if (MMValueCheck.isNotEmpty(pos)) { - for (BomPosVO vo : pos) { - tsMap.put(vo.getCbom_positionid(), vo.getTs()); - voMap.put(vo.getCbom_positionid(), vo); - posSet.add(vo.getCbom_positionid()); - } - idsMap.put(POSITIONTABLE, posSet); - } - - BomLossVO[] loss = item.getLoss(); - Set lossSet = new HashSet(); - if (MMValueCheck.isNotEmpty(loss)) { - for (BomLossVO vo : loss) { - tsMap.put(vo.getCbom_lossid(), vo.getTs()); - voMap.put(vo.getCbom_lossid(), vo); - lossSet.add(vo.getCbom_lossid()); - } - idsMap.put(LOSSTABLE, lossSet); - } - - BomReplVO[] repl = item.getRepl(); - Set replSet = new HashSet(); - if (MMValueCheck.isNotEmpty(repl)) { - for (BomReplVO vo : repl) { - tsMap.put(vo.getCbom_replaceid(), vo.getTs()); - voMap.put(vo.getCbom_replaceid(), vo); - replSet.add(vo.getCbom_replaceid()); - } - idsMap.put(REPLTABLE, replSet); - } - } - - idsMap.put(BODYTABLE, itemSet); - - BomActivityVO[] activityVOs = (BomActivityVO[]) aggs.getChildren(BomActivityVO.class); - Set activitySet = new HashSet(); - if (MMValueCheck.isNotEmpty(activityVOs)) { - for (BomActivityVO vo : activityVOs) { - tsMap.put(vo.getCbom_activityid(), vo.getTs()); - voMap.put(vo.getCbom_activityid(), vo); - activitySet.add(vo.getCbom_activityid()); - } - idsMap.put(ACTIVITYTABLE, activitySet); - } - - BomUseOrgVO[] useOrgVOs = (BomUseOrgVO[]) aggs.getChildren(BomUseOrgVO.class); - Set orgSet = new HashSet(); - if (MMValueCheck.isNotEmpty(useOrgVOs)) { - for (BomUseOrgVO vo : useOrgVOs) { - tsMap.put(vo.getPk_bom_useorg(), vo.getTs()); - voMap.put(vo.getPk_bom_useorg(), vo); - orgSet.add(vo.getPk_bom_useorg()); - } - idsMap.put(ORGTABLE, orgSet); - } - - BomOutputsVO[] outputVOs = (BomOutputsVO[]) aggs.getChildren(BomOutputsVO.class); - Set outputSet = new HashSet(); - if (MMValueCheck.isNotEmpty(outputVOs)) { - for (BomOutputsVO vo : outputVOs) { - tsMap.put(vo.getCbom_outputsid(), vo.getTs()); - voMap.put(vo.getCbom_outputsid(), vo); - outputSet.add(vo.getCbom_outputsid()); - } - idsMap.put(OUTPUTSTABLE, outputSet); - } - } - - private void mapClear() { - tsMap.clear(); - voMap.clear(); - idsMap.clear(); - } - - public Map mapDataTranslator(Map paramMap) { - AggBomVO[] aggs = new AggBomVO[1]; - AggBomVO vo = new AggBomVO(); - - BomVO head = new BomVO(); - for (String key : paramMap.keySet()) { - head.setAttributeValue(key, paramMap.get(key)); - } - vo.setParent(head); - aggs[0] = vo; - - BillFieldsCodeToPkUtil.doTranslateVOFields(aggs); - BomVO parent = (BomVO) aggs[0].getParent(); - Map map = new HashMap(); - for (String key : paramMap.keySet()) { - map.put(key, parent.getAttributeValue(key)); - } - return map; - } - - private AggBomVO aggInit(Map paramMap) { - AggBomVO vo = new AggBomVO(); - - headInit(vo, paramMap); - - bodyInit(vo, paramMap); - - return vo; - } - - private void headInit(AggBomVO vo, Map paramMap) { - Map headInfo = (Map) paramMap.get(HEADTABLE); - BomVO head = new BomVO(); - head.setPk_group(AppContext.getInstance().getPkGroup()); - for (String key : headInfo.keySet()) { - head.setAttributeValue(key, headInfo.get(key)); - } - - head.setAttributeValue("vbilltype", "19B1"); - head.setAttributeValue("hfbomcategory", Integer.valueOf(BomCategoryEnum.NORMAL_BOM.toIntValue())); - head.setAttributeValue("hbcustomized", UFBoolean.FALSE); - head.setTs((UFDateTime) tsMap.get(head.getPrimaryKey())); - vo.setParent(head); - } - - private void bodyInit(AggBomVO vo, Map paramMap) { - itemInit(vo, paramMap); - - useOrgInit(vo, paramMap); - - activityInit(vo, paramMap); - - outputsInit(vo, paramMap); - } - - private void itemInit(AggBomVO agg, Map paramMap) { - List list = new ArrayList(); - Set set = (Set) idsMap.get(BODYTABLE); - - if (set == null) { - set = new HashSet(); - } - - List> itemInfos = new ArrayList>(); - - if (paramMap.get(BODYTABLE) instanceof List) { - itemInfos = (List) paramMap.get(BODYTABLE); - } else { - Map bodyInfo = (Map) paramMap.get(BODYTABLE); - if (MMValueCheck.isNotEmpty(bodyInfo)) { - itemInfos.add(bodyInfo); - } - } - - for (Map itemMap : itemInfos) { - BomItemVO item = new BomItemVO(); - for (String key : itemMap.keySet()) { - if (WIPTABLE.equals(key)) { - List> wipInfos = (List) itemMap.get(WIPTABLE); - item.setWips(getWipVos(wipInfos)); - } else if (POSITIONTABLE.equals(key)) { - List> positionInfos = (List) itemMap.get(POSITIONTABLE); - item.setPos(getPosVos(positionInfos)); - } else if (REPLTABLE.equals(key)) { - List> replInfos = (List) itemMap.get(REPLTABLE); - item.setRepl(getReplVos(replInfos)); - } else if (LOSSTABLE.equals(key)) { - List> lossInfos = (List) itemMap.get(LOSSTABLE); - item.setLoss(getLossVos(lossInfos, item)); - - } else { - - item.setAttributeValue(key, itemMap.get(key)); - } - if (MMValueCheck.isEmpty(item.getAttributeValue("cmaterialid"))) - ; - } - - set.remove(item.getPrimaryKey()); - item.setTs((UFDateTime) tsMap.get(item.getPrimaryKey())); - if (MMValueCheck.isNotEmpty(item.getPrimaryKey())) { - item.setStatus(1); - } else { - item.setStatus(2); - } - list.add(item); - } - - for (String key : set) { - BomItemVO vo = (BomItemVO) voMap.get(key); - vo.setStatus(3); - list.add(vo); - } - - agg.setChildren(BomItemVO.class, (ISuperVO[]) list.toArray(new BomItemVO[0])); - } - - private void useOrgInit(AggBomVO agg, Map paramMap) { - List list = new ArrayList(); - Set set = (Set) idsMap.get(ORGTABLE); - - if (set == null) { - set = new HashSet(); - } - - List> orgInfos = new ArrayList>(); - if (paramMap.get(ORGTABLE) instanceof List) { - orgInfos = (List) paramMap.get(ORGTABLE); - } else { - Map orgInfo = (Map) paramMap.get(ORGTABLE); - if (MMValueCheck.isNotEmpty(orgInfo)) { - orgInfos.add(orgInfo); - } - } - - for (Map itemMap : orgInfos) { - BomUseOrgVO item = new BomUseOrgVO(); - for (String key : itemMap.keySet()) { - item.setAttributeValue(key, itemMap.get(key)); - } - - set.remove(item.getPrimaryKey()); - if (MMValueCheck.isNotEmpty(item.getPrimaryKey())) { - item.setStatus(1); - } else { - item.setStatus(2); - } - item.setTs((UFDateTime) tsMap.get(item.getPrimaryKey())); - list.add(item); - } - - for (String key : set) { - BomUseOrgVO vo = (BomUseOrgVO) voMap.get(key); - vo.setStatus(3); - list.add(vo); - } - - agg.setChildren(BomUseOrgVO.class, (ISuperVO[]) list.toArray(new BomUseOrgVO[0])); - } - - private void activityInit(AggBomVO agg, Map paramMap) { - List list = new ArrayList(); - Set set = (Set) idsMap.get(ACTIVITYTABLE); - - if (set == null) { - set = new HashSet(); - } - - List> activityInfos = new ArrayList>(); - if (paramMap.get(ACTIVITYTABLE) instanceof List) { - activityInfos = (List) paramMap.get(ACTIVITYTABLE); - } else { - Map activyInfo = (Map) paramMap.get(ACTIVITYTABLE); - if (MMValueCheck.isNotEmpty(activyInfo)) { - activityInfos.add(activyInfo); - } - } - - for (Map itemMap : activityInfos) { - BomActivityVO item = new BomActivityVO(); - for (String key : itemMap.keySet()) { - item.setAttributeValue(key, itemMap.get(key)); - } - set.remove(item.getPrimaryKey()); - if (MMValueCheck.isNotEmpty(item.getPrimaryKey())) { - item.setStatus(1); - } else { - item.setStatus(2); - } - item.setTs((UFDateTime) tsMap.get(item.getPrimaryKey())); - list.add(item); - } - - for (String key : set) { - BomActivityVO vo = (BomActivityVO) voMap.get(key); - vo.setStatus(3); - list.add(vo); - } - - agg.setChildren(BomActivityVO.class, (ISuperVO[]) list.toArray(new BomActivityVO[0])); - } - - private void outputsInit(AggBomVO agg, Map paramMap) { - List list = new ArrayList(); - Set set = (Set) idsMap.get(OUTPUTSTABLE); - - if (set == null) { - set = new HashSet(); - } - - List> outputInfos = new ArrayList>(); - - if (paramMap.get(OUTPUTSTABLE) instanceof List) { - outputInfos = (List) paramMap.get(OUTPUTSTABLE); - } else { - Map outputInfo = (Map) paramMap.get(OUTPUTSTABLE); - if (MMValueCheck.isNotEmpty(outputInfo)) { - outputInfos.add(outputInfo); - } - } - - for (Map itemMap : outputInfos) { - BomOutputsVO item = new BomOutputsVO(); - for (String key : itemMap.keySet()) { - item.setAttributeValue(key, itemMap.get(key)); - } - if (MMValueCheck.isNotEmpty(item.getPrimaryKey())) { - item.setStatus(1); - } else { - item.setStatus(2); - } - set.remove(item.getPrimaryKey()); - item.setTs((UFDateTime) tsMap.get(item.getPrimaryKey())); - list.add(item); - } - - for (String key : set) { - BomOutputsVO vo = (BomOutputsVO) voMap.get(key); - vo.setStatus(3); - list.add(vo); - } - - agg.setChildren(BomOutputsVO.class, (ISuperVO[]) list.toArray(new BomOutputsVO[0])); - } - - private UFBoolean getIsExistDefaultVersion(AggBomVO aggvo, String userCode) { - if (aggvo != null) { - BomVO headvo = (BomVO) aggvo.getParentVO(); - String pk_org = headvo.getPk_org().toString(); - String materialOid = headvo.getHcmaterialid().toString(); - String hversion = headvo.getHversion(); - String materialVid = null; - if (MMValueCheck.isNotEmpty(headvo.getHcmaterialvid())) { - materialVid = headvo.getHcmaterialvid().toString(); - } - Integer bomtype = headvo.getFbomtype(); - Integer hfbomcategory = headvo.getHfbomcategory(); - if (MMValueCheck.isEmpty(hfbomcategory)) { - hfbomcategory = Integer.valueOf(1); - } - String vsobillcode = headvo.getVsobillcode(); - String vsobillno = headvo.getVsobillno(); - try { - AggBomVO[] defaultBOM = null; - if (hfbomcategory.intValue() == 1) { - defaultBOM = getBomBillQueryService().queryBomByMaterialCond(pk_org, materialOid, materialVid, - bomtype.intValue()); - } else { - defaultBOM = getBomBillQueryService().queryOrderBomByMaterialCond(pk_org, vsobillcode, vsobillno, - bomtype.intValue()); - } + // 2025年5月28日 电缆组织金思维BOM版本号自动计算处理 + private static final BaseDAO DAO = new BaseDAO(); + + private static final IHttpPostOtherSys HTTP_POST_OTHER_SYS = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); + + // 2025年7月4日 添加日志支持 + private static final String LOG_INFO_NAME = "OALOG"; + private static final Log obmlog = Log.getInstance(LOG_INFO_NAME); + + public static final String MESUSERCODE = "MES"; + + private static String HEADTABLE = "bd_bom"; + + private static String BODYTABLE = "bd_bom_b"; + + private static String ORGTABLE = "bd_bom_useorg"; + + private static String ACTIVITYTABLE = "bd_bom_activity"; + + private static String OUTPUTSTABLE = "bd_bom_outputs"; + + private static String POSITIONTABLE = "bd_bom_position"; + + private static String REPLTABLE = "bd_bom_repl"; + + private static String LOSSTABLE = "bd_bom_loss"; + + private static String WIPTABLE = "bd_bom_wip"; + + private static Map tsMap = new HashMap(); + + private String orgCodeFlag = null; + + private static Map voMap = new HashMap(); + + private static Map> idsMap = new HashMap(); + + public JSONString insert(List> paramList) { + try { + IBomBillMaintainService service = (IBomBillMaintainService) NCLocator.getInstance() + .lookup(IBomBillMaintainService.class); + List list = new ArrayList(); + for (Map paramMap : paramList) { + if (!paramMap.containsKey(HEADTABLE) || !paramMap.containsKey(BODYTABLE)) { + return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); + } + + AggBomVO agg = aggInit(paramMap); + + JSONString checkInfo = requiredCheck(agg); + if (checkInfo != null) { + return checkInfo; + } + + list.add(agg); + } + AggBomVO[] aggVOs = (AggBomVO[]) list.toArray(new AggBomVO[list.size()]); + if (aggVOs[0].getParentVO().getAttributeValue("pk_org") == null || aggVOs[0].getParentVO().getAttributeValue("pk_org") == "") { + ExceptionUtils.wrappBusinessException("请求参数pk_org为空,请检查!!!!"); + } else { + this.orgCodeFlag = aggVOs[0].getParentVO().getAttributeValue("pk_org").toString(); + } + BillFieldsCodeToPkUtil.doTranslateVOFields(aggVOs); + IUifService iUifService = NCLocator.getInstance().lookup(IUifService.class); + for (AggBomVO aggtwo : aggVOs) { + BomItemVO[] items = aggtwo.getChildrenVO(); + // 2025年5月9日08点56分--添加表头物料翻译校验 start + if (aggtwo.getParent().getAttributeValue("hcmaterialid") != null) { + MaterialVO headMaterialVO = (MaterialVO) iUifService.queryByPrimaryKey(MaterialVO.class, + aggtwo.getParent().getAttributeValue("hcmaterialid").toString()); + if (headMaterialVO == null) { + ExceptionUtils.wrappBusinessException("根据物料【" + aggtwo.getParent().getAttributeValue("hcmaterialid").toString() + "】查询物料失败,请在BIP里确认是否物料已存在!!!"); + } + } + // 2025年5月9日08点56分--添加表头物料翻译校验 end + for (int i = 0; i < items.length; i++) { + MaterialVO bankAccSub = (MaterialVO) iUifService.queryByPrimaryKey(MaterialVO.class, + items[i].getAttributeValue("cmaterialid").toString()); + // 2025年5月7日08点41分 添加为空校验 sdlizheng --start + if (bankAccSub == null) { + ExceptionUtils.wrappBusinessException("根据物料【" + items[i].getAttributeValue("cmaterialid").toString() + "】查询物料失败,请在BIP里确认是否物料已存在!!!"); + } + // 2025年5月7日08点41分 添加为空校验 sdlizheng --end + items[i].setAttributeValue("cmaterialvid", bankAccSub.getAttributeValue("pk_source")); + } + } + List commitAggvoList = new ArrayList<>(); + List addAggvoList = new ArrayList<>(); + String userCode = InvocationInfoProxy.getInstance().getUserCode(); + for (AggBomVO agg : aggVOs) { + Object fBillStatusFlag = agg.getParent().getAttributeValue("fbillstatus"); + if (fBillStatusFlag == null || "-1".equals(fBillStatusFlag.toString())) { + addAggvoList.add(agg); + } else if ("1".equals(fBillStatusFlag.toString())) { + commitAggvoList.add(agg); + } + // zhangxinah 对物料主键进行翻译 + dealWithMaterial(agg); + + // 2025年5月28日 电缆组织金思维BOM版本号自动计算处理 By maolei + handleCableOrgJinSiWeiBomVersion(agg); + + dataSupplement(agg, userCode); + + UFBoolean flag = (UFBoolean) agg.getParent().getAttributeValue("hbdefault"); + if (UFBoolean.TRUE.equals(flag)) { + UFBoolean bHasOtherDefaultVersion = getIsExistDefaultVersion(agg, userCode); + if (bHasOtherDefaultVersion.equals(UFBoolean.TRUE)) { + ExceptionUtils.wrappBusinessException("有其它默认版本,请检查!!!"); + } + } + (new BomSavingValidation()).validate(agg); + } + + mapClear(); + // 请求参数状态为审批通过时,自动提交--不设审批流 start + AggBomVO[] result = null; + if (commitAggvoList.isEmpty() && addAggvoList.isEmpty()) { + return ResultMessageUtil.exceptionToJSON("BOM保存失败,不存在单据状态不为【空/自由/审批通过】的数据", "999"); + } else if (commitAggvoList.isEmpty() && !addAggvoList.isEmpty()) { + result = service.insertBom((AggBomVO[]) addAggvoList.toArray(new AggBomVO[0])); + } else if (!commitAggvoList.isEmpty() && addAggvoList.isEmpty()) { + List newAggVOList = new ArrayList<>(); + if ("gaoning".equals(userCode) || "C029".equals(orgCodeFlag) || "dldzspplm".equals(userCode)) { + for (AggBomVO aggvo : commitAggvoList) { + result = service.insertCommitBomWithParam(new AggBomVO[]{aggvo}, true, true); + insertBomMatchRt(result); + newAggVOList.add(result[0]); + } + return ResultMessageUtil.toJSON(newAggVOList.toArray(new AggBomVO[0]), "BOM保存成功"); + } else if ("dlkgsrm".equals(userCode) || "hgqwms".equals(userCode)) { + for (AggBomVO aggvo : commitAggvoList) { + try { + result = service.insertCommitBomWithParam_RequiresNew(new AggBomVO[]{aggvo}, true, true); + newAggVOList.add(result[0]); + } catch (Exception e) { + if (e.getMessage() != null) { + if (e.getMessage().length() > 100) { + aggvo.getParent().setAttributeValue("hvdef2", e.getMessage().substring(0, 100)); + } else { + aggvo.getParent().setAttributeValue("hvdef2", + e.getMessage().substring(0, e.getMessage().length() - 1)); + } + } else { + Throwable unmarsh = ExceptionUtils.unmarsh(e); + aggvo.getParent().setAttributeValue("hvdef2", "异常" + unmarsh.getMessage()); + } + + newAggVOList.add(aggvo); + } + } + return ResultMessageUtil.toJSON(newAggVOList.toArray(new AggBomVO[0]), "100999", + "BOM保存提交成功部分成功部分失败", true); + } else { + try { + IHttpPostOtherSys httpPostOtherSys = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); + + // 检查当前用户是否为排除用户 + if (httpPostOtherSys.checkIfExcludeUser()) { + // 排除用户直接跳过同步处理,执行普通保存逻辑 + for (AggBomVO aggvo : commitAggvoList) { + result = service.insertBom(new AggBomVO[]{aggvo}); + newAggVOList.add(result[0]); + } + return ResultMessageUtil.toJSON(newAggVOList.toArray(new AggBomVO[0]), "BOM保存成功(排除用户)"); + } + + // 检查当前组织是否属于金思维MES同步组织(电缆组织) + String currentOrgCode = this.orgCodeFlag; + boolean isIncludeOrg = httpPostOtherSys.checkIfIncludeOrg(currentOrgCode); + + if (isIncludeOrg) { + // 属于金思维MES同步组织,执行特殊处理逻辑 + for (AggBomVO aggvo : commitAggvoList) { + result = service.insertCommitBomWithParam(new AggBomVO[]{aggvo}, true, true); + newAggVOList.add(result[0]); + } + return ResultMessageUtil.toJSON(newAggVOList.toArray(new AggBomVO[0]), "BOM保存成功(金思维MES同步组织)"); + } else { + // 不属于金思维MES同步组织,执行默认处理逻辑 + for (AggBomVO aggvo : commitAggvoList) { + try { + result = service.insertCommitBomWithParam_RequiresNew(new AggBomVO[]{aggvo}, true, true); + newAggVOList.add(result[0]); + } catch (Exception e) { + if (e.getMessage() != null) { + if (e.getMessage().length() > 100) { + aggvo.getParent().setAttributeValue("hvdef2", e.getMessage().substring(0, 100)); + } else { + aggvo.getParent().setAttributeValue("hvdef2", + e.getMessage().substring(0, e.getMessage().length() - 1)); + } + } else { + Throwable unmarsh = ExceptionUtils.unmarsh(e); + aggvo.getParent().setAttributeValue("hvdef2", "异常" + unmarsh.getMessage()); + } + newAggVOList.add(aggvo); + } + } + return ResultMessageUtil.toJSON(newAggVOList.toArray(new AggBomVO[0]), "100999", + "BOM保存提交成功部分成功部分失败", true); + } + } catch (BusinessException e) { + // HTTP工具类调用失败时,回退到原有的异常处理 + ExceptionUtils.wrappBusinessException("HTTP工具类判断失败:" + e.getMessage() + ",未匹配到符合条件的三方注册用户账号【" + userCode + "】,请检查!!!"); + } + } + + } else { + return ResultMessageUtil.exceptionToJSON("BOM保存失败,新增不允许单据状态自由或者空和审批通过同时存在", "999"); + } + // 请求参数状态为审批通过时,自动提交--不设审批流 end + return ResultMessageUtil.toJSON(result, "BOM保存成功"); + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + + + private void insertBomMatchRt(AggBomVO[] result) throws BusinessException { + AggBomVO aggBomVO = result[0]; + BomVO bomVO = (BomVO) aggBomVO.getParentVO(); + BomItemVO[] bomItemVOs = aggBomVO.getChildrenVO(); + SuperVOUtil.sortByAttributeName(bomItemVOs, "cbeginperiod", false); + + BomMatchRtVO bomMatchRtVO = new BomMatchRtVO(); + bomMatchRtVO.setStatus(VOStatus.NEW); + bomMatchRtVO.setDr(0); + bomMatchRtVO.setPk_group(PubEnv.getPk_group()); + bomMatchRtVO.setPk_org(bomVO.getPk_org()); + bomMatchRtVO.setPk_org_v(bomVO.getPk_org_v()); + bomMatchRtVO.setCmaterialid(bomVO.getHcmaterialid()); + bomMatchRtVO.setCmaterialvid(bomVO.getHcmaterialvid()); + + String hversion = bomVO.getHversion(); + String whereSql = " project_code ='" + hversion + "' and pk_org='" + bomVO.getPk_org() + "' and nvl(dr,0)=0 "; + // IBean bean = MDManageUtil.getBeanByContainedObject(new AggBomVO()); + // String hcprojectid = TranslateUtils.trancelateCodeToID(bean, "hcprojectid", hversion, PubEnv.getPk_group()); + List projectList = (List) new BaseDAO().retrieveByClause(ProjectHeadVO.class, + whereSql); + if (projectList != null && projectList.size() > 0) { + bomMatchRtVO.setCprojectid(projectList.get(0).getPk_project()); + } + + bomMatchRtVO.setDeffectdate(bomItemVOs[0].getCbeginperiod()); + bomMatchRtVO.setDloseeffectdate(bomItemVOs[0].getCendperiod()); + bomMatchRtVO.setProduction(UFBoolean.TRUE); + bomMatchRtVO.setEntrust(UFBoolean.FALSE); + bomMatchRtVO.setCbomid(bomVO.getPrimaryKey()); + IBmrtMaintain iBmrtMaintain = NCLocator.getInstance().lookup(IBmrtMaintain.class); + BomMatchRtVO[] insert = iBmrtMaintain.insert(new BomMatchRtVO[]{bomMatchRtVO}); + System.out.println(insert); + } + + + private void dealWithMaterial(AggBomVO agg) { + String hcmaterialvid = (String) agg.getParentVO().getAttributeValue("hcmaterialvid"); + String hcmaterialid = (String) agg.getParentVO().getAttributeValue("hcmaterialid"); + // 物料没启用版本,直接赋值 + if (hcmaterialvid.length() == 20) { + agg.getParentVO().setAttributeValue("hcmaterialid", hcmaterialvid); + } + // 物料没启用版本,直接赋值 + if (hcmaterialid.length() == 20) { + agg.getParentVO().setAttributeValue("hcmaterialvid", hcmaterialid); + } + } + + public JSONString update(List> paramList) { + try { + IBomBillMaintainService service = (IBomBillMaintainService) NCLocator.getInstance() + .lookup(IBomBillMaintainService.class); + + IBomBillQueryService queryService = (IBomBillQueryService) NCLocator.getInstance() + .lookup(IBomBillQueryService.class); + List list = new ArrayList(); + List idList = new ArrayList(); + Map map = new HashMap(); + for (Map paramMap : paramList) { + + Map bom = (Map) paramMap.get(HEADTABLE); + idList.add((String) bom.get("cbomid")); + } + AggBomVO[] originalvos = queryService.queryAggBomByBomID((String[]) idList.toArray(new String[0])); + for (AggBomVO originalvo : originalvos) { + map.put(originalvo.getParent().getPrimaryKey(), originalvo); + } + + for (Map paramMap : paramList) { + if (!paramMap.containsKey(HEADTABLE) || !paramMap.containsKey(BODYTABLE)) { + return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); + } + + Map bom = (Map) paramMap.get(HEADTABLE); + AggBomVO original = (AggBomVO) map.get((String) bom.get("cbomid")); + + mapInit(original); + + AggBomVO agg = aggInit(paramMap); + // 2025年4月11日14点35分 --重新赋值上制单人创建人+默认 --start + agg.getParentVO().setAttributeValue("billmaker", original.getParent().getAttributeValue("billmaker")); + agg.getParentVO().setAttributeValue("creator", original.getParent().getAttributeValue("creator")); + if (bom.get("hbdefault") == null) { + agg.getParentVO().setAttributeValue("hbdefault", + original.getParent().getAttributeValue("hbdefault")); + } + // 2025年4月11日14点35分 --重新赋值上制单人创建人+默认 --end + JSONString checkInfo = requiredCheck(agg); + if (checkInfo != null) { + return checkInfo; + } + list.add(agg); + } + + AggBomVO[] aggVOs = (AggBomVO[]) list.toArray(new AggBomVO[list.size()]); + + BillFieldsCodeToPkUtil.doTranslateVOFields(aggVOs); + IUifService iUifService = NCLocator.getInstance().lookup(IUifService.class); + for (AggBomVO aggtwo : aggVOs) { + // 2025年5月9日08点56分--添加表头物料翻译校验 start + if (aggtwo.getParent().getAttributeValue("hcmaterialid") != null) { + MaterialVO headMaterialVO = (MaterialVO) iUifService.queryByPrimaryKey(MaterialVO.class, + aggtwo.getParent().getAttributeValue("hcmaterialid").toString()); + if (headMaterialVO == null) { + ExceptionUtils.wrappBusinessException("根据物料【" + aggtwo.getParent().getAttributeValue("hcmaterialid").toString() + "】查询物料失败,请在BIP里确认是否物料已存在!!!"); + } + } + // 2025年5月9日08点56分--添加表头物料翻译校验 end + BomItemVO[] items = aggtwo.getChildrenVO(); + for (int i = 0; i < items.length; i++) { + MaterialVO bankAccSub = (MaterialVO) iUifService.queryByPrimaryKey(MaterialVO.class, + items[i].getAttributeValue("cmaterialid").toString()); + // 2025年5月7日08点41分 添加为空校验 sdlizheng --start + if (bankAccSub == null) { + ExceptionUtils.wrappBusinessException("根据物料【" + items[i].getAttributeValue("cmaterialid").toString() + "】查询物料失败,请在BIP里确认是否物料已存在!!!"); + } + // 2025年5月7日08点41分 添加为空校验 sdlizheng --end + items[i].setAttributeValue("cmaterialvid", bankAccSub.getAttributeValue("pk_source")); + } + } + String userCode = InvocationInfoProxy.getInstance().getUserCode(); + for (AggBomVO agg : aggVOs) { + // zhangxinah 对物料主键进行翻译 + dealWithMaterial(agg); + dataSupplement(agg, userCode); + + UFBoolean flag = (UFBoolean) agg.getParent().getAttributeValue("hbdefault"); + if (UFBoolean.TRUE.equals(flag)) { + UFBoolean bHasOtherDefaultVersion = getIsExistDefaultVersion(agg, userCode); + if (bHasOtherDefaultVersion.equals(UFBoolean.TRUE)) { + ExceptionUtils.wrappBusinessException("有其它默认版本,请检查!!!"); + } + } + + (new BomSavingValidation()).validate(agg); + } + + mapClear(); + + AggBomVO[] result = service.updateBom((AggBomVO[]) list.toArray(new AggBomVO[0])); + return ResultMessageUtil.toJSON(result, "BOM保存成功"); + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + + public JSONString query(Map paramMap) { + try { + Map map = mapDataTranslator(paramMap); + + QuerySchemeUtils schemeUtil = new QuerySchemeUtils(AggBomVO.class, map); + IQueryScheme queryscheme = schemeUtil.creatQueryScheme(); + IBomBillQueryService query = (IBomBillQueryService) NCLocator.getInstance() + .lookup(IBomBillQueryService.class); + + AggBomVO[] aggvos = query.queryBySchemeAndPwdkeyForBomWithParam(queryscheme, null, getRelation(), false, + false); + + if (MMValueCheck.isEmpty(aggvos)) { + return ResultMessageUtil.toJSON(new AggBomVO[0], "无相应数据"); + } + + Set pkSet = (Set) Stream.of(aggvos).map(AbstractBill::getPrimaryKey).collect(Collectors.toSet()); + AggBomVO[] results = query.queryAggBomByBomID((String[]) pkSet.toArray(new String[0])); + + List list = new ArrayList(); + if (MMValueCheck.isNotEmpty(aggvos)) { + for (AggBomVO agg : aggvos) { + list.add((BomVO) agg.getParentVO()); + } + } + return ResultMessageUtil.toJSON(results, "查询成功"); + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + + public AggBomVO[] updateBomWithParam(AggBomVO[] aggvos, boolean isFromBom, boolean isecn, boolean isCheckEcn, + boolean isOnApprove) throws BusinessException { + if (MMArrayUtil.isEmpty(aggvos)) { + return null; + } + try { + // 检查该BOM是否被删除,因为如果BOM树状维护将BOM删除了,不允许修改该条记录 + Set bomids = new HashSet(); + for (AggBomVO vo : aggvos) { + bomids.add(vo.getPrimaryKey()); + } + Set checkResult = BomPubBP.getBomID(bomids.toArray(new String[]{})); + if (checkResult != null && checkResult.size() < bomids.size()) { + nc.vo.pubapp.pattern.exception.ExceptionUtils.wrappBusinessException(MMBDLangConstBom0202.getBOM_DELETED()); + } + // 加锁 + 检查ts + GCBillTransferTool transTool = new GCBillTransferTool(aggvos); + // 补全前台VO + AggBomVO[] fullBills = transTool.getClientFullInfoBill(); + // 获得修改前vo + AggBomVO[] originBills = transTool.getOriginBills(); + BomUpdateBP bp = new BomUpdateBP(); + return bp.update(fullBills, originBills, isCheckEcn, isOnApprove, isFromBom, isecn); + } catch (Exception e) { + nc.vo.pubapp.pattern.exception.ExceptionUtils.marsh(e); + } + return null; + } + + private void mapInit(AggBomVO aggs) { + tsMap.put(aggs.getParent().getPrimaryKey(), aggs.getParent().getAttributeValue("ts")); + + BomItemVO[] items = aggs.getChildrenVO(); + + if (MMValueCheck.isEmpty(items)) { + return; + } + + Set itemSet = new HashSet(); + for (BomItemVO item : items) { + tsMap.put(item.getPrimaryKey(), item.getTs()); + voMap.put(item.getPrimaryKey(), item); + itemSet.add(item.getPrimaryKey()); + + BomWipVO[] wips = item.getWips(); + Set wipSet = new HashSet(); + if (MMValueCheck.isNotEmpty(wips)) { + for (BomWipVO vo : wips) { + tsMap.put(vo.getCbom_wipid(), vo.getTs()); + voMap.put(vo.getCbom_wipid(), vo); + wipSet.add(vo.getCbom_wipid()); + } + idsMap.put(WIPTABLE, wipSet); + } + + BomPosVO[] pos = item.getPos(); + Set posSet = new HashSet(); + if (MMValueCheck.isNotEmpty(pos)) { + for (BomPosVO vo : pos) { + tsMap.put(vo.getCbom_positionid(), vo.getTs()); + voMap.put(vo.getCbom_positionid(), vo); + posSet.add(vo.getCbom_positionid()); + } + idsMap.put(POSITIONTABLE, posSet); + } + + BomLossVO[] loss = item.getLoss(); + Set lossSet = new HashSet(); + if (MMValueCheck.isNotEmpty(loss)) { + for (BomLossVO vo : loss) { + tsMap.put(vo.getCbom_lossid(), vo.getTs()); + voMap.put(vo.getCbom_lossid(), vo); + lossSet.add(vo.getCbom_lossid()); + } + idsMap.put(LOSSTABLE, lossSet); + } + + BomReplVO[] repl = item.getRepl(); + Set replSet = new HashSet(); + if (MMValueCheck.isNotEmpty(repl)) { + for (BomReplVO vo : repl) { + tsMap.put(vo.getCbom_replaceid(), vo.getTs()); + voMap.put(vo.getCbom_replaceid(), vo); + replSet.add(vo.getCbom_replaceid()); + } + idsMap.put(REPLTABLE, replSet); + } + } + + idsMap.put(BODYTABLE, itemSet); + + BomActivityVO[] activityVOs = (BomActivityVO[]) aggs.getChildren(BomActivityVO.class); + Set activitySet = new HashSet(); + if (MMValueCheck.isNotEmpty(activityVOs)) { + for (BomActivityVO vo : activityVOs) { + tsMap.put(vo.getCbom_activityid(), vo.getTs()); + voMap.put(vo.getCbom_activityid(), vo); + activitySet.add(vo.getCbom_activityid()); + } + idsMap.put(ACTIVITYTABLE, activitySet); + } + + BomUseOrgVO[] useOrgVOs = (BomUseOrgVO[]) aggs.getChildren(BomUseOrgVO.class); + Set orgSet = new HashSet(); + if (MMValueCheck.isNotEmpty(useOrgVOs)) { + for (BomUseOrgVO vo : useOrgVOs) { + tsMap.put(vo.getPk_bom_useorg(), vo.getTs()); + voMap.put(vo.getPk_bom_useorg(), vo); + orgSet.add(vo.getPk_bom_useorg()); + } + idsMap.put(ORGTABLE, orgSet); + } + + BomOutputsVO[] outputVOs = (BomOutputsVO[]) aggs.getChildren(BomOutputsVO.class); + Set outputSet = new HashSet(); + if (MMValueCheck.isNotEmpty(outputVOs)) { + for (BomOutputsVO vo : outputVOs) { + tsMap.put(vo.getCbom_outputsid(), vo.getTs()); + voMap.put(vo.getCbom_outputsid(), vo); + outputSet.add(vo.getCbom_outputsid()); + } + idsMap.put(OUTPUTSTABLE, outputSet); + } + } + + private void mapClear() { + tsMap.clear(); + voMap.clear(); + idsMap.clear(); + } + + public Map mapDataTranslator(Map paramMap) { + AggBomVO[] aggs = new AggBomVO[1]; + AggBomVO vo = new AggBomVO(); + + BomVO head = new BomVO(); + for (String key : paramMap.keySet()) { + head.setAttributeValue(key, paramMap.get(key)); + } + vo.setParent(head); + aggs[0] = vo; + + BillFieldsCodeToPkUtil.doTranslateVOFields(aggs); + BomVO parent = (BomVO) aggs[0].getParent(); + Map map = new HashMap(); + for (String key : paramMap.keySet()) { + map.put(key, parent.getAttributeValue(key)); + } + return map; + } + + private AggBomVO aggInit(Map paramMap) { + AggBomVO vo = new AggBomVO(); + + headInit(vo, paramMap); + + bodyInit(vo, paramMap); + + return vo; + } + + private void headInit(AggBomVO vo, Map paramMap) { + Map headInfo = (Map) paramMap.get(HEADTABLE); + BomVO head = new BomVO(); + head.setPk_group(AppContext.getInstance().getPkGroup()); + for (String key : headInfo.keySet()) { + head.setAttributeValue(key, headInfo.get(key)); + } + + head.setAttributeValue("vbilltype", "19B1"); + head.setAttributeValue("hfbomcategory", Integer.valueOf(BomCategoryEnum.NORMAL_BOM.toIntValue())); + head.setAttributeValue("hbcustomized", UFBoolean.FALSE); + head.setTs((UFDateTime) tsMap.get(head.getPrimaryKey())); + vo.setParent(head); + } + + private void bodyInit(AggBomVO vo, Map paramMap) { + itemInit(vo, paramMap); + + useOrgInit(vo, paramMap); + + activityInit(vo, paramMap); + + outputsInit(vo, paramMap); + } + + private void itemInit(AggBomVO agg, Map paramMap) { + List list = new ArrayList(); + Set set = (Set) idsMap.get(BODYTABLE); + + if (set == null) { + set = new HashSet(); + } + + List> itemInfos = new ArrayList>(); + + if (paramMap.get(BODYTABLE) instanceof List) { + itemInfos = (List) paramMap.get(BODYTABLE); + } else { + Map bodyInfo = (Map) paramMap.get(BODYTABLE); + if (MMValueCheck.isNotEmpty(bodyInfo)) { + itemInfos.add(bodyInfo); + } + } + + for (Map itemMap : itemInfos) { + BomItemVO item = new BomItemVO(); + for (String key : itemMap.keySet()) { + if (WIPTABLE.equals(key)) { + List> wipInfos = (List) itemMap.get(WIPTABLE); + item.setWips(getWipVos(wipInfos)); + } else if (POSITIONTABLE.equals(key)) { + List> positionInfos = (List) itemMap.get(POSITIONTABLE); + item.setPos(getPosVos(positionInfos)); + } else if (REPLTABLE.equals(key)) { + List> replInfos = (List) itemMap.get(REPLTABLE); + item.setRepl(getReplVos(replInfos)); + } else if (LOSSTABLE.equals(key)) { + List> lossInfos = (List) itemMap.get(LOSSTABLE); + item.setLoss(getLossVos(lossInfos, item)); + + } else { + + item.setAttributeValue(key, itemMap.get(key)); + } + if (MMValueCheck.isEmpty(item.getAttributeValue("cmaterialid"))) + ; + } + + set.remove(item.getPrimaryKey()); + item.setTs((UFDateTime) tsMap.get(item.getPrimaryKey())); + if (MMValueCheck.isNotEmpty(item.getPrimaryKey())) { + item.setStatus(1); + } else { + item.setStatus(2); + } + list.add(item); + } + + for (String key : set) { + BomItemVO vo = (BomItemVO) voMap.get(key); + vo.setStatus(3); + list.add(vo); + } + + agg.setChildren(BomItemVO.class, (ISuperVO[]) list.toArray(new BomItemVO[0])); + } + + private void useOrgInit(AggBomVO agg, Map paramMap) { + List list = new ArrayList(); + Set set = (Set) idsMap.get(ORGTABLE); + + if (set == null) { + set = new HashSet(); + } + + List> orgInfos = new ArrayList>(); + if (paramMap.get(ORGTABLE) instanceof List) { + orgInfos = (List) paramMap.get(ORGTABLE); + } else { + Map orgInfo = (Map) paramMap.get(ORGTABLE); + if (MMValueCheck.isNotEmpty(orgInfo)) { + orgInfos.add(orgInfo); + } + } + + for (Map itemMap : orgInfos) { + BomUseOrgVO item = new BomUseOrgVO(); + for (String key : itemMap.keySet()) { + item.setAttributeValue(key, itemMap.get(key)); + } + + set.remove(item.getPrimaryKey()); + if (MMValueCheck.isNotEmpty(item.getPrimaryKey())) { + item.setStatus(1); + } else { + item.setStatus(2); + } + item.setTs((UFDateTime) tsMap.get(item.getPrimaryKey())); + list.add(item); + } + + for (String key : set) { + BomUseOrgVO vo = (BomUseOrgVO) voMap.get(key); + vo.setStatus(3); + list.add(vo); + } + + agg.setChildren(BomUseOrgVO.class, (ISuperVO[]) list.toArray(new BomUseOrgVO[0])); + } + + private void activityInit(AggBomVO agg, Map paramMap) { + List list = new ArrayList(); + Set set = (Set) idsMap.get(ACTIVITYTABLE); + + if (set == null) { + set = new HashSet(); + } + + List> activityInfos = new ArrayList>(); + if (paramMap.get(ACTIVITYTABLE) instanceof List) { + activityInfos = (List) paramMap.get(ACTIVITYTABLE); + } else { + Map activyInfo = (Map) paramMap.get(ACTIVITYTABLE); + if (MMValueCheck.isNotEmpty(activyInfo)) { + activityInfos.add(activyInfo); + } + } + + for (Map itemMap : activityInfos) { + BomActivityVO item = new BomActivityVO(); + for (String key : itemMap.keySet()) { + item.setAttributeValue(key, itemMap.get(key)); + } + set.remove(item.getPrimaryKey()); + if (MMValueCheck.isNotEmpty(item.getPrimaryKey())) { + item.setStatus(1); + } else { + item.setStatus(2); + } + item.setTs((UFDateTime) tsMap.get(item.getPrimaryKey())); + list.add(item); + } + + for (String key : set) { + BomActivityVO vo = (BomActivityVO) voMap.get(key); + vo.setStatus(3); + list.add(vo); + } + + agg.setChildren(BomActivityVO.class, (ISuperVO[]) list.toArray(new BomActivityVO[0])); + } + + private void outputsInit(AggBomVO agg, Map paramMap) { + List list = new ArrayList(); + Set set = (Set) idsMap.get(OUTPUTSTABLE); + + if (set == null) { + set = new HashSet(); + } + + List> outputInfos = new ArrayList>(); + + if (paramMap.get(OUTPUTSTABLE) instanceof List) { + outputInfos = (List) paramMap.get(OUTPUTSTABLE); + } else { + Map outputInfo = (Map) paramMap.get(OUTPUTSTABLE); + if (MMValueCheck.isNotEmpty(outputInfo)) { + outputInfos.add(outputInfo); + } + } + + for (Map itemMap : outputInfos) { + BomOutputsVO item = new BomOutputsVO(); + for (String key : itemMap.keySet()) { + item.setAttributeValue(key, itemMap.get(key)); + } + if (MMValueCheck.isNotEmpty(item.getPrimaryKey())) { + item.setStatus(1); + } else { + item.setStatus(2); + } + set.remove(item.getPrimaryKey()); + item.setTs((UFDateTime) tsMap.get(item.getPrimaryKey())); + list.add(item); + } + + for (String key : set) { + BomOutputsVO vo = (BomOutputsVO) voMap.get(key); + vo.setStatus(3); + list.add(vo); + } + + agg.setChildren(BomOutputsVO.class, (ISuperVO[]) list.toArray(new BomOutputsVO[0])); + } + + private UFBoolean getIsExistDefaultVersion(AggBomVO aggvo, String userCode) { + if (aggvo != null) { + BomVO headvo = (BomVO) aggvo.getParentVO(); + String pk_org = headvo.getPk_org().toString(); + String materialOid = headvo.getHcmaterialid().toString(); + String hversion = headvo.getHversion(); + String materialVid = null; + if (MMValueCheck.isNotEmpty(headvo.getHcmaterialvid())) { + materialVid = headvo.getHcmaterialvid().toString(); + } + Integer bomtype = headvo.getFbomtype(); + Integer hfbomcategory = headvo.getHfbomcategory(); + if (MMValueCheck.isEmpty(hfbomcategory)) { + hfbomcategory = Integer.valueOf(1); + } + String vsobillcode = headvo.getVsobillcode(); + String vsobillno = headvo.getVsobillno(); + try { + AggBomVO[] defaultBOM = null; + if (hfbomcategory.intValue() == 1) { + defaultBOM = getBomBillQueryService().queryBomByMaterialCond(pk_org, materialOid, materialVid, + bomtype.intValue()); + } else { + defaultBOM = getBomBillQueryService().queryOrderBomByMaterialCond(pk_org, vsobillcode, vsobillno, + bomtype.intValue()); + } // IBomBusinessService service = (IBomBusinessService)NCLocator.getInstance().lookup(IBomBusinessService.class); - if (MMValueCheck.isNotEmpty(defaultBOM)) { - for (AggBomVO aggBomVO : defaultBOM) { - BomVO head = (BomVO) aggBomVO.getParent(); - if (VersionTypeEnum.AVAILABLE.equalsValue(head.getHfversiontype()) - && !head.getCbomid().equals(headvo.getCbomid())) { - // sdlizheng --添加独立判断--plm三方越过此校验 - if ("gaoning".equals(userCode) || "dlkgsrm".equals(userCode) || "C029".equals(this.orgCodeFlag) || "hgqwms".equals(userCode)) { + if (MMValueCheck.isNotEmpty(defaultBOM)) { + for (AggBomVO aggBomVO : defaultBOM) { + BomVO head = (BomVO) aggBomVO.getParent(); + if (VersionTypeEnum.AVAILABLE.equalsValue(head.getHfversiontype()) + && !head.getCbomid().equals(headvo.getCbomid())) { + // sdlizheng --添加独立判断--plm三方越过此校验 + if ("gaoning".equals(userCode) || "dlkgsrm".equals(userCode) || "C029".equals(this.orgCodeFlag) || "hgqwms".equals(userCode)) { // AggBomVO afterVO = service.canceldefault(aggBomVO); - } else if (MESUSERCODE.equals(userCode)) { - //2025-6-20 添加MES用户判断 - } else { - return UFBoolean.TRUE; - } - // sdlizheng --添加独立判断--plm三方越过此校验 - } - } + } else if (MESUSERCODE.equals(userCode)) { + // 2025-6-20 添加MES用户判断 + } else { + return UFBoolean.TRUE; + } + // sdlizheng --添加独立判断--plm三方越过此校验 + } + } - } - } catch (BusinessException e) { - ExceptionUtils.wrappException(e); - } - } + } + } catch (BusinessException e) { + ExceptionUtils.wrappException(e); + } + } - return UFBoolean.FALSE; - } + return UFBoolean.FALSE; + } - private IBomBillQueryService getBomBillQueryService() { - return (IBomBillQueryService) NCLocator.getInstance().lookup(IBomBillQueryService.class); - } + private IBomBillQueryService getBomBillQueryService() { + return (IBomBillQueryService) NCLocator.getInstance().lookup(IBomBillQueryService.class); + } - private void dataSupplement(AggBomVO agg, String userCode) throws BusinessException { - orgSupplement(agg, userCode); + private void dataSupplement(AggBomVO agg, String userCode) throws BusinessException { + orgSupplement(agg, userCode); - // 2025年6月20日 - 处理MES用户的hbdefault(默认)字段设置 - handleMesUserDefaultSetting(agg, userCode); + // 2025年6月20日 - 处理MES用户的hbdefault(默认)字段设置 + handleMesUserDefaultSetting(agg, userCode); - versionTypeSupplement(agg); + versionTypeSupplement(agg); - materialidSupplement(agg); + materialidSupplement(agg); - itemSupplement(agg); + itemSupplement(agg); - outputSupplement(agg); + outputSupplement(agg); - useOrgSupplement(agg); - } + useOrgSupplement(agg); + } - private void outputSupplement(AggBomVO agg) { - BomOutputsVO[] outputVOs = (BomOutputsVO[]) agg.getChildren(BomOutputsVO.class); - handleEvent(outputVOs); - } + private void outputSupplement(AggBomVO agg) { + BomOutputsVO[] outputVOs = (BomOutputsVO[]) agg.getChildren(BomOutputsVO.class); + handleEvent(outputVOs); + } - private void orgSupplement(AggBomVO agg, String userCode) { - if (MMValueCheck.isEmpty(agg.getParent().getAttributeValue("pk_org_v"))) { - String pk_org_v = OrgUnitPubService - .getNewVIDByOrgID(agg.getParent().getAttributeValue("pk_org").toString()); - agg.getParent().setAttributeValue("pk_org_v", pk_org_v); - } - Object fbillstatus = agg.getParent().getAttributeValue("fbillstatus"); - if (MMValueCheck.isEmpty(agg.getParent().getAttributeValue("cbomid"))) { - agg.getParent().setAttributeValue("fbomtype", Integer.valueOf(1)); - agg.getParent().setAttributeValue("hfversiontype", Integer.valueOf(2)); - agg.getParent().setAttributeValue("fbillstatus", Integer.valueOf(-1)); - agg.getParent().setAttributeValue("hfbomsource", Integer.valueOf(1)); - agg.getParent().setAttributeValue("hfbomcategory", Integer.valueOf(1)); - if ("gaoning".equals(userCode) || "dlkgsrm".equals(userCode) || "C029".equals(this.orgCodeFlag) || "hgqwms".equals(userCode)) { - // sdlizheng - // 1、对于之前不存在的BOM,新增时:如果是传自由态,不默认且无效,走标准逻辑,如果传的是审批态默认且有效。2025年4月11日16点28分 start - if (fbillstatus != null && "1".equals(fbillstatus.toString())) { - agg.getParent().setAttributeValue("hfversiontype", Integer.valueOf(1)); - agg.getParent().setAttributeValue("hbdefault", UFBoolean.TRUE); - } else if (fbillstatus != null && "-1".equals(fbillstatus.toString())) { - if ("gaoning".equals(userCode) || "C029".equals(this.orgCodeFlag)) { - agg.getParent().setAttributeValue("hfversiontype", Integer.valueOf(1)); - agg.getParent().setAttributeValue("hbdefault", UFBoolean.TRUE); - } - } - // sdlizheng 1、对于之前不存在的BOM,新增时:如果是传自由态,不默认且无效,如果传的是审批态默认且有效。2025年4月11日16点28分 end - } - } + private void orgSupplement(AggBomVO agg, String userCode) { + if (MMValueCheck.isEmpty(agg.getParent().getAttributeValue("pk_org_v"))) { + String pk_org_v = OrgUnitPubService + .getNewVIDByOrgID(agg.getParent().getAttributeValue("pk_org").toString()); + agg.getParent().setAttributeValue("pk_org_v", pk_org_v); + } + Object fbillstatus = agg.getParent().getAttributeValue("fbillstatus"); + if (MMValueCheck.isEmpty(agg.getParent().getAttributeValue("cbomid"))) { + agg.getParent().setAttributeValue("fbomtype", Integer.valueOf(1)); + agg.getParent().setAttributeValue("hfversiontype", Integer.valueOf(2)); + agg.getParent().setAttributeValue("fbillstatus", Integer.valueOf(-1)); + agg.getParent().setAttributeValue("hfbomsource", Integer.valueOf(1)); + agg.getParent().setAttributeValue("hfbomcategory", Integer.valueOf(1)); + if ("gaoning".equals(userCode) || "dlkgsrm".equals(userCode) || "C029".equals(this.orgCodeFlag) || "hgqwms".equals(userCode)) { + // sdlizheng + // 1、对于之前不存在的BOM,新增时:如果是传自由态,不默认且无效,走标准逻辑,如果传的是审批态默认且有效。2025年4月11日16点28分 start + if (fbillstatus != null && "1".equals(fbillstatus.toString())) { + agg.getParent().setAttributeValue("hfversiontype", Integer.valueOf(1)); + agg.getParent().setAttributeValue("hbdefault", UFBoolean.TRUE); + } else if (fbillstatus != null && "-1".equals(fbillstatus.toString())) { + if ("gaoning".equals(userCode) || "C029".equals(this.orgCodeFlag)) { + agg.getParent().setAttributeValue("hfversiontype", Integer.valueOf(1)); + agg.getParent().setAttributeValue("hbdefault", UFBoolean.TRUE); + } + } + // sdlizheng 1、对于之前不存在的BOM,新增时:如果是传自由态,不默认且无效,如果传的是审批态默认且有效。2025年4月11日16点28分 end + } + } - } + } - private void materialidSupplement(AggBomVO agg) { - BomHeadMtrlParam param = getQueryParam(agg); - Object assnumObject = agg.getParent().getAttributeValue("hnassparentnum"); - Object numObject = agg.getParent().getAttributeValue("hnparentnum"); - UFDouble assNum = UFDouble.ZERO_DBL; - UFDouble num = UFDouble.ZERO_DBL; + private void materialidSupplement(AggBomVO agg) { + BomHeadMtrlParam param = getQueryParam(agg); + Object assnumObject = agg.getParent().getAttributeValue("hnassparentnum"); + Object numObject = agg.getParent().getAttributeValue("hnparentnum"); + UFDouble assNum = UFDouble.ZERO_DBL; + UFDouble num = UFDouble.ZERO_DBL; - if (MMValueCheck.isNotEmpty(assnumObject)) { - assNum = (UFDouble) agg.getParent().getAttributeValue("hnassparentnum"); - } + if (MMValueCheck.isNotEmpty(assnumObject)) { + assNum = (UFDouble) agg.getParent().getAttributeValue("hnassparentnum"); + } - if (MMValueCheck.isNotEmpty(numObject)) { - num = (UFDouble) agg.getParent().getAttributeValue("hnparentnum"); - } + if (MMValueCheck.isNotEmpty(numObject)) { + num = (UFDouble) agg.getParent().getAttributeValue("hnparentnum"); + } - IBomBillQueryService service = (IBomBillQueryService) NCLocator.getInstance() - .lookup(IBomBillQueryService.class); - BomHeadMtrlResult result = service.queryMtrlInfo(param); - if (MMValueCheck.isNotEmpty(agg.getParentVO().getAttributeValue("hcmaterialvid"))) { - agg.getParent().setAttributeValue("hcmaterialvid", result.getMaterialvid()); - } + IBomBillQueryService service = (IBomBillQueryService) NCLocator.getInstance() + .lookup(IBomBillQueryService.class); + BomHeadMtrlResult result = service.queryMtrlInfo(param); + if (MMValueCheck.isNotEmpty(agg.getParentVO().getAttributeValue("hcmaterialvid"))) { + agg.getParent().setAttributeValue("hcmaterialvid", result.getMaterialvid()); + } - agg.getParent().setAttributeValue("hcmaterialname", result.getMtrlname()); - agg.getParent().setAttributeValue("hvplaintext", result.getMtrltruename()); - if (MMValueCheck.isEmpty(agg.getParent().getAttributeValue("hversion"))) { - agg.getParent().setAttributeValue("hversion", result.getVersion()); - } + agg.getParent().setAttributeValue("hcmaterialname", result.getMtrlname()); + agg.getParent().setAttributeValue("hvplaintext", result.getMtrltruename()); + if (MMValueCheck.isEmpty(agg.getParent().getAttributeValue("hversion"))) { + agg.getParent().setAttributeValue("hversion", result.getVersion()); + } - agg.getParent().setAttributeValue("hiswholesetsend", "" + result.getIswhole().booleanValue()); - agg.getParent().setAttributeValue("hisvirtual", "" + result.getIsvertual().booleanValue()); + agg.getParent().setAttributeValue("hiswholesetsend", "" + result.getIswhole().booleanValue()); + agg.getParent().setAttributeValue("hisvirtual", "" + result.getIsvertual().booleanValue()); - if (MMValueCheck.isEmpty(agg.getParent().getAttributeValue("hbdefault"))) { - if ("1.0".equals(result.getVersion())) { + if (MMValueCheck.isEmpty(agg.getParent().getAttributeValue("hbdefault"))) { + if ("1.0".equals(result.getVersion())) { - agg.getParent().setAttributeValue("hbdefault", "true"); - } else { + agg.getParent().setAttributeValue("hbdefault", "true"); + } else { - agg.getParent().setAttributeValue("hbdefault", "false"); - } - } + agg.getParent().setAttributeValue("hbdefault", "false"); + } + } - agg.getParent().setAttributeValue("hvchangerate", result.getMeasureVO().getVchangeRate()); + agg.getParent().setAttributeValue("hvchangerate", result.getMeasureVO().getVchangeRate()); - BomVO bom = new BomVO(); - bom.setHcmeasureid(result.getMeasureVO().getCmeasureid()); - bom.setHcassmeasureid(result.getMeasureVO().getCassMeasures()); - bom.setHvchangerate(result.getMeasureVO().getVchangeRate()); + BomVO bom = new BomVO(); + bom.setHcmeasureid(result.getMeasureVO().getCmeasureid()); + bom.setHcassmeasureid(result.getMeasureVO().getCassMeasures()); + bom.setHvchangerate(result.getMeasureVO().getVchangeRate()); - bom.setHnassparentnum(assNum); - bom.setHnparentnum(num); + bom.setHnassparentnum(assNum); + bom.setHnparentnum(num); - MeasureParam headParam = new MeasureParam(); - headParam.setCmeasureid("hcmeasureid"); - headParam.setCassMeasures("hcassmeasureid"); - headParam.setVchangeRate("hvchangerate"); + MeasureParam headParam = new MeasureParam(); + headParam.setCmeasureid("hcmeasureid"); + headParam.setCassMeasures("hcassmeasureid"); + headParam.setVchangeRate("hvchangerate"); - if ((assNum.equals(UFDouble.ZERO_DBL) && num.compareTo(UFDouble.ZERO_DBL) > 0) - || (assNum.compareTo(UFDouble.ZERO_DBL) > 0 && num.compareTo(UFDouble.ZERO_DBL) > 0)) { - MeasureHelper.fillAssNumber(bom, headParam, "hnparentnum", "hnassparentnum"); - } else if (num.equals(UFDouble.ZERO_DBL) && assNum.compareTo(UFDouble.ZERO_DBL) > 0) { + if ((assNum.equals(UFDouble.ZERO_DBL) && num.compareTo(UFDouble.ZERO_DBL) > 0) + || (assNum.compareTo(UFDouble.ZERO_DBL) > 0 && num.compareTo(UFDouble.ZERO_DBL) > 0)) { + MeasureHelper.fillAssNumber(bom, headParam, "hnparentnum", "hnassparentnum"); + } else if (num.equals(UFDouble.ZERO_DBL) && assNum.compareTo(UFDouble.ZERO_DBL) > 0) { - MeasureHelper.fillAccNumber(bom, headParam, "hnparentnum", "hnassparentnum"); - } + MeasureHelper.fillAccNumber(bom, headParam, "hnparentnum", "hnassparentnum"); + } - agg.getParent().setAttributeValue("hcassmeasureid", bom.getHcassmeasureid()); - agg.getParent().setAttributeValue("hcmeasureid", bom.getHcmeasureid()); - agg.getParent().setAttributeValue("hnassparentnum", bom.getHnassparentnum()); - agg.getParent().setAttributeValue("hnparentnum", bom.getHnparentnum()); - } + agg.getParent().setAttributeValue("hcassmeasureid", bom.getHcassmeasureid()); + agg.getParent().setAttributeValue("hcmeasureid", bom.getHcmeasureid()); + agg.getParent().setAttributeValue("hnassparentnum", bom.getHnassparentnum()); + agg.getParent().setAttributeValue("hnparentnum", bom.getHnparentnum()); + } - private BomHeadMtrlParam getQueryParam(AggBomVO agg) { - String pk_org = agg.getParentVO().getAttributeValue("pk_org").toString(); - String hcmaterialid = agg.getParentVO().getAttributeValue("hcmaterialid").toString(); - String hcmateriavid = agg.getParentVO().getAttributeValue("hcmaterialvid").toString(); - String pwdkey = null; - boolean iscust = false; + private BomHeadMtrlParam getQueryParam(AggBomVO agg) { + String pk_org = agg.getParentVO().getAttributeValue("pk_org").toString(); + String hcmaterialid = agg.getParentVO().getAttributeValue("hcmaterialid").toString(); + String hcmateriavid = agg.getParentVO().getAttributeValue("hcmaterialvid").toString(); + String pwdkey = null; + boolean iscust = false; - int bomtype = BomTypeEnum.PRODUCTFINISH.toIntValue(); - if (MMValueCheck.isNotEmpty(agg.getParentVO().getAttributeValue("fbomtype"))) { - bomtype = Integer.valueOf(agg.getParentVO().getAttributeValue("fbomtype").toString()).intValue(); - } + int bomtype = BomTypeEnum.PRODUCTFINISH.toIntValue(); + if (MMValueCheck.isNotEmpty(agg.getParentVO().getAttributeValue("fbomtype"))) { + bomtype = Integer.valueOf(agg.getParentVO().getAttributeValue("fbomtype").toString()).intValue(); + } - BomHeadMtrlParam param = new BomHeadMtrlParam(); - param.setPk_org(pk_org); - param.setMaterialid(hcmaterialid); - param.setMateriavid(hcmateriavid); - param.setPwdkey(pwdkey); - param.setBomtype(bomtype); - param.setIscust(iscust); - return param; - } + BomHeadMtrlParam param = new BomHeadMtrlParam(); + param.setPk_org(pk_org); + param.setMaterialid(hcmaterialid); + param.setMateriavid(hcmateriavid); + param.setPwdkey(pwdkey); + param.setBomtype(bomtype); + param.setIscust(iscust); + return param; + } - private void versionTypeSupplement(AggBomVO agg) { - if (MMValueCheck.isNotEmpty(agg.getParent().getAttributeValue("hfversiontype"))) { - if ("2".equals(agg.getParent().getAttributeValue("hfversiontype").toString())) { - agg.getParent().setAttributeValue("hbdefault", UFBoolean.FALSE); - } - } else { - agg.getParent().setAttributeValue("hbdefault", UFBoolean.TRUE); - } - } + private void versionTypeSupplement(AggBomVO agg) { + if (MMValueCheck.isNotEmpty(agg.getParent().getAttributeValue("hfversiontype"))) { + if ("2".equals(agg.getParent().getAttributeValue("hfversiontype").toString())) { + agg.getParent().setAttributeValue("hbdefault", UFBoolean.FALSE); + } + } else { + agg.getParent().setAttributeValue("hbdefault", UFBoolean.TRUE); + } + } - private Map getRelation() { - Map relation = new HashMap(); - relation.put("wips", new BomWipVO()); - relation.put("loss", new BomLossVO()); - relation.put("repl", new BomReplVO()); - relation.put("select", new BomSelectVO()); - relation.put("resource", new BomItemSourceVO()); - relation.put("pos", new BomPosVO()); + private Map getRelation() { + Map relation = new HashMap(); + relation.put("wips", new BomWipVO()); + relation.put("loss", new BomLossVO()); + relation.put("repl", new BomReplVO()); + relation.put("select", new BomSelectVO()); + relation.put("resource", new BomItemSourceVO()); + relation.put("pos", new BomPosVO()); - return relation; - } + return relation; + } - private void itemSupplement(AggBomVO agg) throws BusinessException { - String pk_org = (String) agg.getParent().getAttributeValue("pk_org"); - BomItemVO[] items = agg.getChildrenVO(); - for (BomItemVO item : items) { + private void itemSupplement(AggBomVO agg) throws BusinessException { + String pk_org = (String) agg.getParent().getAttributeValue("pk_org"); + BomItemVO[] items = agg.getChildrenVO(); + for (BomItemVO item : items) { - ileadtimenumEvent(item, pk_org, (String) item.getAttributeValue("cmaterialid"), - (String) item.getAttributeValue("cmaterialvid")); + ileadtimenumEvent(item, pk_org, (String) item.getAttributeValue("cmaterialid"), + (String) item.getAttributeValue("cmaterialvid")); - fitemtypeEvent(item); + fitemtypeEvent(item); - bprojectmaterialEvent(item); + bprojectmaterialEvent(item); - bcustommaterial(item); + bcustommaterial(item); - fbackflushtypeEvent(item); + fbackflushtypeEvent(item); - ndisspationumEvent(item, pk_org); + ndisspationumEvent(item, pk_org); - BomWipVO[] wips = item.getWips(); - if (MMValueCheck.isNotEmpty(wips)) { - for (BomWipVO vo : wips) { - wipNumsEvent(vo); - } - } + BomWipVO[] wips = item.getWips(); + if (MMValueCheck.isNotEmpty(wips)) { + for (BomWipVO vo : wips) { + wipNumsEvent(vo); + } + } - BomPosVO[] positions = item.getPos(); - if (MMValueCheck.isNotEmpty(positions)) { - for (BomPosVO vo : positions) { - posNumsEvent(vo); - } - } + BomPosVO[] positions = item.getPos(); + if (MMValueCheck.isNotEmpty(positions)) { + for (BomPosVO vo : positions) { + posNumsEvent(vo); + } + } - BomLossVO[] lossVOs = item.getLoss(); - if (MMValueCheck.isNotEmpty(lossVOs)) { - for (BomLossVO vo : lossVOs) { - lossNumEvent(vo); - } - } + BomLossVO[] lossVOs = item.getLoss(); + if (MMValueCheck.isNotEmpty(lossVOs)) { + for (BomLossVO vo : lossVOs) { + lossNumEvent(vo); + } + } - BomReplVO[] replVOs = item.getRepl(); - if (MMValueCheck.isNotEmpty(replVOs)) { - for (BomReplVO vo : replVOs) { - replMaterialOidFill(vo); - } - } - } + BomReplVO[] replVOs = item.getRepl(); + if (MMValueCheck.isNotEmpty(replVOs)) { + for (BomReplVO vo : replVOs) { + replMaterialOidFill(vo); + } + } + } - handleEvent(items); + handleEvent(items); // // IHttpPostOtherSys mesUtils = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); // @@ -1084,723 +1118,725 @@ public class APIBomBusinessServiceImpl implements IAPIBomBusinessService { // if(mesUtils.checkIfIncludeOrg(code)) { // this.handleEventTwo(agg); // } - } - - private void replMaterialOidFill(BomReplVO replVO) { - if (MMValueCheck.isNotEmpty(replVO.getCreplmaterialoid())) { - return; - } - Map map = getMateriaInfoByVid(replVO.getCreplmaterialvid()); - String pkSource = ((MaterialVO) map.get(replVO.getCreplmaterialvid())).getPk_source(); - replVO.setCreplmaterialoid(pkSource); - } - - public void ileadtimenumEvent(BomItemVO item, String pk_org, String hcmaterialoid, String hcmaterialvid) { - try { - Integer ileadtimenum = item.getIleadtimenum(); - if (ileadtimenum == null) { - return; - } - String pkorg = item.getPk_org(); - if (MMValueCheck.isEmpty(hcmaterialvid) && MMValueCheck.isEmpty(hcmaterialoid)) { - item.setIleadtimenum(null); - } - - if (MMValueCheck.isEmpty(hcmaterialvid)) { - - hcmaterialvid = ((MaterialVersionVO) ((IMaterialPubService_C) NCLocator.getInstance() - .lookup(IMaterialPubService_C.class)) - .queryMaterialBaseInfoByOidPks(new String[]{hcmaterialoid}, new String[]{"pk_material"}) - .get(hcmaterialoid)).toString(); - } - Map map = queryMaterialPlanInfoByPks(new String[]{hcmaterialvid}, pkorg, - new String[]{"fixedahead"}); - - UFDouble fixedahead = UFDouble.ZERO_DBL; - if (MMValueCheck.isNotEmpty(map) && MMValueCheck.isNotEmpty((SuperVO) map.get(hcmaterialvid)) - && MMValueCheck.isNotEmpty(((MaterialPlanVO) map.get(hcmaterialvid)).getFixedahead())) { - fixedahead = ((MaterialPlanVO) map.get(hcmaterialvid)).getFixedahead(); - } - if ((new UFDouble(ileadtimenum.intValue())).compareTo(fixedahead) > 0) { - item.setIleadtimenum(null); - - } - - } catch (BusinessException e) { - ExceptionUtils.wrappBusinessException(e.toString()); - } - } - - public static Map queryMaterialPlanInfoByPks(String[] pks, String pk_stockorg, - String[] fields) throws BusinessException { - Map map = null; - - List vids = (List) Stream.of(pks).filter(e -> (e != null)).distinct().collect(Collectors.toList()); - if (vids.size() == 0) { - map = new HashMap(); - } else { - - map = ((IMaterialPubService) NCLocator.getInstance().lookup(IMaterialPubService.class)) - .queryMaterialPlanInfoByPks((String[]) vids.toArray(new String[0]), pk_stockorg, fields); - } - - return map; - } - - private void fitemtypeEvent(BomItemVO item) { - String fitem = item.getAttributeValue("fitemtype").toString(); - if ("1".equals(fitem)) { - if (MMValueCheck.isEmpty(item.getFitemsource())) { - item.setAttributeValue("fitemsource", Integer.valueOf(1)); - } - } else { - item.setAttributeValue("fitemsource", null); - } - } - - private void bprojectmaterialEvent(BomItemVO item) { - Object bprojectMaterial = item.getAttributeValue("bprojectmaterial"); - if (MMValueCheck.isEmpty(bprojectMaterial)) { - item.setAttributeValue("cprojectid", null); - } - } - - private void bcustommaterial(BomItemVO item) { - Object bcustommaterial = item.getAttributeValue("bcustommaterial"); - if (MMValueCheck.isEmpty(bcustommaterial)) { - item.setAttributeValue("ccustomerid", null); - item.setAttributeValue("ccustomerid_v", null); - } - } - - private void fbackflushtypeEvent(BomItemVO item) { - Object bcustommaterial = item.getAttributeValue("fbackflushtype"); - if (MMValueCheck.isNotEmpty(bcustommaterial) && "1".equals(bcustommaterial.toString())) { - item.setAttributeValue("fbackflushtime", null); - } - } - - private void ndisspationumEvent(BomItemVO item, String pkorg) { - int scale = MMBDFactoryParameter.findMMBDDigitNumber(pkorg).intValue(); - UFDouble ndisspationum = (UFDouble) item.getAttributeValue("ndissipationum"); - if (MMValueCheck.isNotEmpty(ndisspationum)) { - ndisspationum.setScale(scale, 1); - item.setAttributeValue("ndissipationum", ndisspationum); - } - } - - private int getNumberDecimalDigits(String balanceStr) { - int dcimalDigits = 0; - int indexOf = balanceStr.indexOf("."); - if (indexOf > 0) { - dcimalDigits = balanceStr.length() - 1 - indexOf; - } - return dcimalDigits; - } - - private void wipNumsEvent(BomWipVO vo) { - UFDouble num = (UFDouble) vo.getAttributeValue("nnum"); - String unitid = (String) vo.getAttributeValue("cassmeasureid"); - UFDouble nnum = (new NumScaleUtil()).calNumScale(num, unitid); - int scale = getNumberDecimalDigits(nnum.toString()); - vo.setAttributeValue("nnum", nnum.setScale(scale, 1)); - } - - private void posNumsEvent(BomPosVO vo) { - UFDouble num = (UFDouble) vo.getAttributeValue("nnum"); - String unitid = (String) vo.getAttributeValue("cassmeasureid"); - UFDouble nnum = (new NumScaleUtil()).calNumScale(new UFDouble(num), unitid); - int scale = getNumberDecimalDigits(nnum.toString()); - vo.setAttributeValue("nnum", nnum.setScale(scale, 1)); - } - - private void lossNumEvent(BomLossVO vo) { - BomLossVO loss = new BomLossVO(); - loss.setAttributeValue("clunitid", vo.getAttributeValue("clunitid")); - loss.setAttributeValue("clunitastid", vo.getAttributeValue("clunitastid")); - loss.setAttributeValue("vlchangerate", vo.getAttributeValue("vlchangerate")); - loss.setAttributeValue("nlfromastnum", vo.getAttributeValue("nlfromastnum")); - loss.setAttributeValue("nltoastnum", vo.getAttributeValue("nltoastnum")); - MeasureParam headParam = new MeasureParam(); - headParam.setCmeasureid("clunitid"); - headParam.setCassMeasures("clunitastid"); - headParam.setVchangeRate("vlchangerate"); - MeasureHelper.fillAccNumber(loss, headParam, "nlfromnum", "nlfromastnum"); - double fromNum = loss.getNlfromnum().doubleValue(); - - vo.setAttributeValue("nlfromnum", Double.valueOf(fromNum)); - - MeasureHelper.fillAccNumber(loss, headParam, "nltonum", "nltoastnum"); - double ltonum = loss.getNltonum().doubleValue(); - - vo.setAttributeValue("nltonum", Double.valueOf(ltonum)); - } - - private BomWipVO[] getWipVos(List> infos) { - List list = new ArrayList(); - Set set = (Set) idsMap.get(WIPTABLE); - if (set == null) { - set = new HashSet(); - } - - for (Map info : infos) { - BomWipVO vo = new BomWipVO(); - for (String key : info.keySet()) { - vo.setAttributeValue(key, info.get(key)); - } - set.remove(vo.getPrimaryKey()); - if (MMValueCheck.isNotEmpty(vo.getPrimaryKey())) { - vo.setStatus(1); - } else { - vo.setStatus(2); - } - vo.setTs((UFDateTime) tsMap.get(vo.getPrimaryKey())); - list.add(vo); - } - - for (String key : set) { - BomWipVO vo = (BomWipVO) voMap.get(key); - vo.setStatus(3); - list.add(vo); - } - - return (BomWipVO[]) list.toArray(new BomWipVO[0]); - } - - private BomPosVO[] getPosVos(List> infos) { - List list = new ArrayList(); - Set set = (Set) idsMap.get(POSITIONTABLE); - - if (set == null) { - set = new HashSet(); - } - - for (Map info : infos) { - BomPosVO vo = new BomPosVO(); - for (String key : info.keySet()) { - vo.setAttributeValue(key, info.get(key)); - } - set.remove(vo.getPrimaryKey()); - if (MMValueCheck.isNotEmpty(vo.getPrimaryKey())) { - vo.setStatus(1); - } else { - vo.setStatus(2); - } - vo.setTs((UFDateTime) tsMap.get(vo.getPrimaryKey())); - list.add(vo); - } - - for (String key : set) { - BomPosVO vo = (BomPosVO) voMap.get(key); - vo.setStatus(3); - list.add(vo); - } - return (BomPosVO[]) list.toArray(new BomPosVO[0]); - } - - private BomReplVO[] getReplVos(List> infos) { - List list = new ArrayList(); - Set set = (Set) idsMap.get(REPLTABLE); - - if (set == null) { - set = new HashSet(); - } - - for (Map info : infos) { - BomReplVO vo = new BomReplVO(); - for (String key : info.keySet()) { - vo.setAttributeValue(key, info.get(key)); - } - set.remove(vo.getPrimaryKey()); - if (MMValueCheck.isNotEmpty(vo.getPrimaryKey())) { - vo.setStatus(1); - } else { - vo.setStatus(2); - } - vo.setTs((UFDateTime) tsMap.get(vo.getPrimaryKey())); - list.add(vo); - } - - for (String key : set) { - BomReplVO vo = (BomReplVO) voMap.get(key); - vo.setStatus(3); - list.add(vo); - } - return (BomReplVO[]) list.toArray(new BomReplVO[0]); - } - - private BomLossVO[] getLossVos(List> infos, BomItemVO item) { - List list = new ArrayList(); - Set set = (Set) idsMap.get(LOSSTABLE); - - if (set == null) { - set = new HashSet(); - } - - for (Map info : infos) { - BomLossVO vo = new BomLossVO(); - for (String key : info.keySet()) { - vo.setAttributeValue(key, info.get(key)); - } - set.remove(vo.getPrimaryKey()); - if (MMValueCheck.isNotEmpty(vo.getPrimaryKey())) { - vo.setStatus(1); - } else { - vo.setStatus(2); - } - vo.setTs((UFDateTime) tsMap.get(vo.getPrimaryKey())); - vo.setAttributeValue("clunitastid", item.getAttributeValue("cassmeasureid")); - vo.setAttributeValue("clunitid", item.getAttributeValue("cmeasureid")); - list.add(vo); - } - - for (String key : set) { - BomLossVO vo = (BomLossVO) voMap.get(key); - vo.setStatus(3); - list.add(vo); - } - return (BomLossVO[]) list.toArray(new BomLossVO[0]); - } - - public BomItemVO[] handleEvent(BomItemVO[] items) throws BusinessException { - List itemCmaterialvids = new ArrayList(); - for (BomItemVO item : items) { - if (MMValueCheck.isNotEmpty(item.getCmaterialvid())) { - itemCmaterialvids.add(item.getCmaterialvid()); - } - } - Map materialMap = new HashMap(); - Map measurevoMap = new HashMap(); - - String pkorg = items[0].getPk_org(); - if (itemCmaterialvids.size() > 0) { - try { - materialMap = ((IBomBillQueryService) NCLocator.getInstance().lookup(IBomBillQueryService.class)) - .queryMaterialInfo(pkorg, (String[]) itemCmaterialvids.toArray(new String[0])); - IMeasesureService service = (IMeasesureService) NCLocator.getInstance().lookup(IMeasesureService.class); - measurevoMap.putAll(service.getMeasureInfoMap((String[]) itemCmaterialvids.toArray(new String[0]))); - } catch (BusinessException e1) { - ExceptionUtils.wrappBusinessException(e1.toString()); - } - } - - for (BomItemVO item : items) { - if (MMValueCheck.isNotEmpty(item.getCmaterialvid())) { - item.setVitemversion(null); - item.setVpackversion(null); - item.setVfree1(null); - item.setVfree2(null); - item.setVfree3(null); - item.setVfree4(null); - item.setVfree5(null); - item.setVfree6(null); - item.setVfree7(null); - item.setVfree8(null); - item.setVfree9(null); - item.setVfree10(null); - - if (measurevoMap.containsKey(item.getCmaterialvid())) { - if (MMValueCheck.isEmpty(item.getVchangerate())) { - item.setVchangerate(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getVchangeRate()); - } - - item.setCmeasureid(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getCmeasureid()); - - item.setCassmeasureid(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getCassMeasures()); - } - - setMaterialInfo(materialMap, item); - MeasureParam headParam = new MeasureParam(); - headParam.setCmaterialvid("cmaterialvid"); - headParam.setCmeasureid("cmeasureid"); - headParam.setCassMeasures("cassmeasureid"); - headParam.setVchangeRate("vchangerate"); - MeasureHelper.fillAccNumber(item, headParam, "nitemnum", "nassitemnum"); - } else { - - item.setBdeliver(UFBoolean.FALSE); - item.setAttributeValue("iscreatesonprodorder", UFBoolean.FALSE); - item.setAttributeValue("nbfixshrinkastnum", null); - item.setAttributeValue("nbfixshrinknum", null); - item.setAttributeValue("ndissipationum", null); - item.setAttributeValue("fbackflushtime", null); - item.setAttributeValue("fbackflushtype", null); - item.setAttributeValue("bbunibatch", UFBoolean.FALSE); - item.setVfree1(null); - item.setVfree2(null); - item.setVfree3(null); - item.setVfree4(null); - item.setVfree5(null); - item.setVfree6(null); - item.setVfree7(null); - item.setVfree8(null); - item.setVfree9(null); - item.setVfree10(null); - } - } - - return items; - } - - public BomItemVO[] handleEventTwo( AggBomVO agg) throws MetaDataException { - IUifService iUifService = NCLocator.getInstance().lookup(IUifService.class); - BomItemVO[] items = agg.getChildrenVO(); - for(BomItemVO item : items) { - StringBuffer whereSqlitem = new StringBuffer(); - whereSqlitem.append(" hcmaterialid = '"+item.getCmaterialid()+"'").append(" and dr ='0'"); - Collection aggBomVOitem; - try { - aggBomVOitem = MDPersistenceService.lookupPersistenceQueryService().queryBillOfVOByCond(AggBomVO.class, whereSqlitem.toString(), false); - if(Objects.nonNull(aggBomVOitem)&&!aggBomVOitem.isEmpty() ) { - StringBuffer whereSql = new StringBuffer(); - whereSql.append(" hcmaterialid = '"+item.getCmaterialid()+"'").append(" and hvdef3 ='"+agg.getParent().getAttributeValue("hvdef3")+"'").append(" and hvdef2 ='"+agg.getParent().getAttributeValue("hvdef2")+"'").append(" and dr ='0'"); - Collection aggBomVO; - aggBomVO = MDPersistenceService.lookupPersistenceQueryService().queryBillOfVOByCond(AggBomVO.class, whereSql.toString(), false); - if(Objects.nonNull(aggBomVO) && aggBomVO.size()==1) { - for (AggBomVO aggBom : aggBomVO) { - item.setVitemversion(aggBom.getPrimaryKey()); - } - }else { - nccloud.base.exception.ExceptionUtils.wrapBusinessException("根据条件未查出bom或者查出多条bom不唯一"+whereSql); - } - } - } catch (MetaDataException e1) { - e1.printStackTrace(); - ExceptionUtils.wrappBusinessException(e1.toString()); - } - } - - return items; - } - void setMaterialInfo(Map materialMap, BomItemVO item) { - String materialvid = item.getCmaterialvid(); - if (!materialMap.containsKey(materialvid)) { - return; - } - - BomMaterialParam materialParam = (BomMaterialParam) materialMap.get(materialvid); - if (materialParam == null) { - return; - } - if (UFBoolean.TRUE == materialParam.getIsvirtual()) { - - item.setBbsteploss(UFBoolean.FALSE); - item.setNbfixshrinknum(null); - item.setNbfixshrinkastnum(null); - item.setNdissipationum(null); - item.setIleadtimenum(null); - item.setBupint(UFBoolean.FALSE); - - item.setBisvirtual(UFBoolean.TRUE); - } else { - item.setAttributeValue("nbfixshrinknum", materialParam.getNfixshrinknum()); - - MeasureParam headParam = new MeasureParam(); - headParam.setCmaterialvid("cmaterialvid"); - headParam.setCmeasureid("cmeasureid"); - headParam.setCassMeasures("cassmeasureid"); - headParam.setVchangeRate("vchangerate"); - MeasureHelper.fillOnlyNumAssNumQtNum(item, headParam, "nbfixshrinknum", "nbfixshrinkastnum", null); - - item.setAttributeValue("ndissipationum", materialParam.getNdissipationnum()); - } - - if (MMValueCheck.isEmpty(item.getBdeliver())) { - item.setAttributeValue("bdeliver", materialParam.getBdeliver()); - } - - if (MMValueCheck.isEmpty(item.getFbackflushtype())) { - item.setAttributeValue("fbackflushtype", materialParam.getFbackflushtype()); - } - - if (MMValueCheck.isEmpty(item.getFbackflushtime())) { - item.setAttributeValue("fbackflushtime", materialParam.getFbackflushtime()); - } - - if (MMValueCheck.isEmpty(item.getBbunibatch())) { - item.setAttributeValue("bbunibatch", materialParam.getBunibatch()); - } - - if (BackflushTypeEnum.NOBACKFLUSH.equalsValue(materialParam.getFbackflushtype())) { - item.setAttributeValue("fbackflushtime", null); - - } else if (BackflushTypeEnum.AUTOBACKFLUSH.equalsValue(materialParam.getFbackflushtype()) - || BackflushTypeEnum.EXCHANGEBACKFLUSH.equalsValue(materialParam.getFbackflushtype())) { - if (MMValueCheck.isEmpty(materialParam.getFbackflushtime())) { - item.setAttributeValue("fbackflushtime", Integer.valueOf(BackflushTimeEnum.MMBOM.toIntValue())); - } - } else if (MMValueCheck.isEmpty(materialParam.getFbackflushtype())) { - - item.setAttributeValue("fbackflushtype", Integer.valueOf(BackflushTypeEnum.EXCHANGEBACKFLUSH.toIntValue())); - item.setAttributeValue("fbackflushtime", Integer.valueOf(BackflushTimeEnum.MMBOM.toIntValue())); - } - - item.setAttributeValue("iscreatesonprodorder", materialParam.getIscreatesonprodorder()); - } - - public BomOutputsVO[] handleEvent(BomOutputsVO[] items) { - Map materialMap = new HashMap(); - for (BomOutputsVO item : items) { - try { - materialMap = ((IBomBillQueryService) NCLocator.getInstance().lookup(IBomBillQueryService.class)) - .queryMaterialInfo(item.getPk_org(), new String[]{item.getCmaterialvid()}); - - Map measurevoMap = new HashMap(); - IMeasesureService service = (IMeasesureService) NCLocator.getInstance().lookup(IMeasesureService.class); - measurevoMap.putAll(service.getMeasureInfoMap(new String[]{item.getCmaterialvid()})); - if (measurevoMap.containsKey(item.getCmaterialvid())) { - item.setVchangerate(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getVchangeRate()); - item.setCastunitid(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getCassMeasures()); - item.setCunitid(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getCmeasureid()); - } - - Map cmaterialMap = getMateriaInfoByVid(item.getCmaterialvid()); - MaterialVO materialVO = (MaterialVO) cmaterialMap.get(item.getCmaterialvid()); - item.setCmaterialid(materialVO.getPk_source()); - } catch (BusinessException e1) { - ExceptionUtils.wrappBusinessException(e1.toString()); - } - MeasureParam headParam = new MeasureParam(); - headParam.setCmaterialvid("cmaterialvid"); - headParam.setCmeasureid("cunitid"); - headParam.setCassMeasures("castunitid"); - headParam.setVchangeRate("vchangerate"); - MeasureHelper.fillAccNumber(item, headParam, "noutputnum", "nastoutputnum"); - - item.setVfree1(null); - item.setVfree2(null); - item.setVfree3(null); - item.setVfree4(null); - item.setVfree5(null); - item.setVfree6(null); - item.setVfree7(null); - item.setVfree8(null); - item.setVfree9(null); - item.setVfree10(null); - } - - return items; - } - - private JSONString requiredCheck(AggBomVO agg) { - Object hcmaterialid = agg.getParent().getAttributeValue("hcmaterialid"); - - Object fbomtype = agg.getParent().getAttributeValue("fbomtype"); - - Object hversion = agg.getParent().getAttributeValue("hversion"); - - if (MMValueCheck.isEmpty(hcmaterialid) || MMValueCheck.isEmpty(fbomtype) || MMValueCheck.isEmpty(hversion)) { - return ResultMessageUtil.exceptionToJSON("传入数据异常,表头信息存在未填的必输项", "1"); - } - - BomItemVO[] items = agg.getChildrenVO(); - for (int i = 0; i < items.length; i++) { - BomItemVO item = items[i]; - - String cmaterialvid = item.getCmaterialvid(); - - UFDouble nassitemnum = item.getNassitemnum(); - - Integer ibasenum = item.getIbasenum(); - - Integer fitemtype = item.getFitemtype(); - - Integer fsupplymode = item.getFsupplymode(); - - Integer fbackflushtype = item.getFbackflushtype(); - - Integer fcontrol = item.getFcontrol(); - - UFDate cbeginperiod = item.getCbeginperiod(); - - UFDate cendperiod = item.getCendperiod(); - - if (MMValueCheck.isEmpty(cmaterialvid) || MMValueCheck.isEmpty(nassitemnum) - || MMValueCheck.isEmpty(ibasenum) || MMValueCheck.isEmpty(fitemtype) - || MMValueCheck.isEmpty(fsupplymode) || MMValueCheck.isEmpty(fcontrol) - || MMValueCheck.isEmpty(cbeginperiod) || MMValueCheck.isEmpty(cendperiod) - || MMValueCheck.isEmpty(fbackflushtype)) { - return ResultMessageUtil.exceptionToJSON("传入数据异常,子表材料第" + i + 1 + "行"+ cmaterialvid +"存在未填的必输项", "1"); - } - } - - BomOutputsVO[] bomOutputsVO = (BomOutputsVO[]) agg.getChildren(BomOutputsVO.class); - - for (int j = 0; j < bomOutputsVO.length; j++) { - BomOutputsVO outputsVO = bomOutputsVO[j]; - - Integer foutputtype = outputsVO.getFoutputtype(); - - String cmaterialvid = outputsVO.getCmaterialvid(); - - if (MMValueCheck.isEmpty(foutputtype) || MMValueCheck.isEmpty(cmaterialvid)) { - return ResultMessageUtil.exceptionToJSON("传入数据异常,联副产品第" + j + 1 + "行"+cmaterialvid+"存在未填的必输项", "1"); - } - } - - return null; - } - - private Map getMateriaInfoByVid(String materialVid) { - Map materialSourceMap = new HashMap(); - try { - materialSourceMap = ((IMaterialPubService_C) NCLocator.getInstance().lookup(IMaterialPubService_C.class)) - .queryMaterialBaseInfoByPks(new String[]{materialVid}, - new String[]{"pk_source", "graphid", "materialspec", "materialtype"}); - - } catch (BusinessException e1) { - ResultMessageUtil.exceptionToJSON(e1); - } - return materialSourceMap; - } - - private void useOrgSupplement(AggBomVO agg) { - BomUseOrgVO[] useOrgVOs = (BomUseOrgVO[]) agg.getChildren(BomUseOrgVO.class); - if (MMValueCheck.isNotEmpty(useOrgVOs)) - for (BomUseOrgVO item : useOrgVOs) { - - item.setCbomid((String) agg.getParentVO().getAttributeValue("cbomid")); - item.setPk_org((String) agg.getParentVO().getAttributeValue("pk_org")); - item.setPk_org_v((String) agg.getParentVO().getAttributeValue("pk_org_v")); - item.setPk_useorg((String) agg.getParentVO().getAttributeValue("pk_org")); - item.setPk_useorg_v((String) agg.getParentVO().getAttributeValue("pk_org_v")); - } - } - - - private void handleCableOrgJinSiWeiBomVersion(AggBomVO agg) { - try { - String pk_org = (String) agg.getParent().getAttributeValue("pk_org"); - String hcmaterialid = (String) agg.getParent().getAttributeValue("hcmaterialid"); - String hversion = agg.getParent().getAttributeValue("hversion").toString(); - String cbomid = (String) agg.getParent().getAttributeValue("cbomid"); - String hvnote = (String) agg.getParent().getAttributeValue("hvnote"); - - // 检查必要字段 - if (MMValueCheck.isEmpty(hcmaterialid) || MMValueCheck.isEmpty(hversion)) { - return; - } - - // 判断是否为电缆组织(组织编码C034)且备注包含"金思维" - boolean isCableOrgJinSiWei = isCableOrganizationWithJinSiWei(pk_org, hvnote); - - if (isCableOrgJinSiWei) { - // 计算版本号 - String calculatedVersion = calculateBomVersion(pk_org, hcmaterialid); - agg.getParent().setAttributeValue("hversion", calculatedVersion); - } - } catch (Exception e) { - ExceptionUtils.wrappBusinessException("同步电缆组织金思维BOM版本号处理异常:" + e.getMessage()); - } - } - - /** - * 判断是否为电缆组织且备注包含金思维 - * - * @param pk_org 组织主键 - * @param hvnote 备注信息 - * @return 是否符合条件 - */ - private boolean isCableOrganizationWithJinSiWei(String pk_org, String hvnote) { - if (MMValueCheck.isEmpty(pk_org)) { - return false; - } - - try { - // 查询组织编码 - String sql = "SELECT code FROM org_orgs WHERE dr = 0 and pk_org = ?"; - SQLParameter param = new SQLParameter(); - param.addParam(pk_org); - String orgCode = (String) DAO.executeQuery(sql, param, new ColumnProcessor()); - - // 使用统一的组织判断方法 - boolean isCableOrg = HTTP_POST_OTHER_SYS.checkIfIncludeOrg(orgCode); - - // 判断备注是否包含"金思维" - boolean containsJinSiWei = MMValueCheck.isNotEmpty(hvnote) && hvnote.contains("金思维"); - - return isCableOrg && containsJinSiWei; - } catch (Exception e) { - // 查询异常时返回false - return false; - } - } - - /** - * 计算BOM版本号 - * - * @param pk_org 组织主键 - * @param hcmaterialid 物料编码 - * @return 计算出的版本号 - */ - private String calculateBomVersion(String pk_org, String hcmaterialid) throws BusinessException { - try { - // 构建查询条件 - StringBuilder sql = new StringBuilder(); - sql.append("SELECT MAX(TO_NUMBER(hversion)) as max_version "); - sql.append("FROM bd_bom "); - sql.append("WHERE dr = 0 and pk_org = ? "); - - SQLParameter param = new SQLParameter(); - param.addParam(pk_org); - - // 根据物料情况添加查询条件 - sql.append("AND hcmaterialid = ? "); - param.addParam(hcmaterialid); - - // 只查询数字版本号,排除非数字版本 - sql.append("AND REGEXP_LIKE(hversion, '^[0-9]+$') "); - // 如果查询不到数据,默认版本号为1;否则最大版本号加1 - Object mayBeNullVersion = DAO.executeQuery(sql.toString(), param, new ColumnProcessor()); - String number = Objects.isNull(mayBeNullVersion) ? "1" : DAO.executeQuery(sql.toString(), param, new ColumnProcessor()).toString(); - return String.valueOf(Long.parseLong(number) + 1); - - } catch (Exception e) { - throw new BusinessException("计算BOM版本号异常:" + e.getMessage()); - } - } - - /** - * 处理MES用户的hbdefault字段设置逻辑 - * 2025年6月20日新增 - 专门用于MES用户的处理 - * 2025年7月10日修改 - 改为根据自定义项hvdef4判断是否为定制BOM - * 同步MES时:只有标准版本的bom "默认"(hbdefault) 生效(hfversiontype的等于1) - * 定制bom(hvdef4值为Y)取消 "默认"(hbdefault,值为N) 但生效(hfversiontype的等于1) - * @auther 毛磊 - * @param agg AggBomVO对象 - * @param userCode 用户代码 - */ - private void handleMesUserDefaultSetting(AggBomVO agg, String userCode) { - obmlog.debug("handleMesUserDefaultSetting - 开始处理MES用户的默认设置逻辑,用户代码:" + userCode); - - // 仅针对MES用户进行处理 - if (!MESUSERCODE.equals(userCode)) { - obmlog.debug("handleMesUserDefaultSetting - 非MES用户,跳过处理"); - return; - } - - // 获取自定义项hvdef4的值 - String hvdef4 = (String) agg.getParent().getAttributeValue("hvdef4"); - obmlog.debug("handleMesUserDefaultSetting - 获取到自定义项hvdef4的值:" + hvdef4); - - // 判断是否为定制BOM(hvdef4值为Y时为定制BOM,其余情况为标准版本) - boolean isCustomBom = "Y".equals(hvdef4); - obmlog.debug("handleMesUserDefaultSetting - 是否为定制BOM:" + isCustomBom); - - // 所有MES用户的BOM都设置为生效状态 - agg.getParent().setAttributeValue("hfversiontype", 1); - obmlog.debug("handleMesUserDefaultSetting - 设置版本类型为生效状态(hfversiontype=1)"); - - if (isCustomBom) { - // 定制BOM:取消默认但仍然生效 - agg.getParent().setAttributeValue("hbdefault","N"); - obmlog.debug("handleMesUserDefaultSetting - 定制BOM,取消默认(hbdefault=false)"); - } else { - // 标准版本:设置为默认且生效 - agg.getParent().setAttributeValue("hbdefault", "Y"); - obmlog.debug("handleMesUserDefaultSetting - 标准版本,设置为默认(hbdefault=true)"); - } - - obmlog.debug("handleMesUserDefaultSetting - MES用户默认设置处理完成"); - } + } + + private void replMaterialOidFill(BomReplVO replVO) { + if (MMValueCheck.isNotEmpty(replVO.getCreplmaterialoid())) { + return; + } + Map map = getMateriaInfoByVid(replVO.getCreplmaterialvid()); + String pkSource = ((MaterialVO) map.get(replVO.getCreplmaterialvid())).getPk_source(); + replVO.setCreplmaterialoid(pkSource); + } + + public void ileadtimenumEvent(BomItemVO item, String pk_org, String hcmaterialoid, String hcmaterialvid) { + try { + Integer ileadtimenum = item.getIleadtimenum(); + if (ileadtimenum == null) { + return; + } + String pkorg = item.getPk_org(); + if (MMValueCheck.isEmpty(hcmaterialvid) && MMValueCheck.isEmpty(hcmaterialoid)) { + item.setIleadtimenum(null); + } + + if (MMValueCheck.isEmpty(hcmaterialvid)) { + + hcmaterialvid = ((MaterialVersionVO) ((IMaterialPubService_C) NCLocator.getInstance() + .lookup(IMaterialPubService_C.class)) + .queryMaterialBaseInfoByOidPks(new String[]{hcmaterialoid}, new String[]{"pk_material"}) + .get(hcmaterialoid)).toString(); + } + Map map = queryMaterialPlanInfoByPks(new String[]{hcmaterialvid}, pkorg, + new String[]{"fixedahead"}); + + UFDouble fixedahead = UFDouble.ZERO_DBL; + if (MMValueCheck.isNotEmpty(map) && MMValueCheck.isNotEmpty((SuperVO) map.get(hcmaterialvid)) + && MMValueCheck.isNotEmpty(((MaterialPlanVO) map.get(hcmaterialvid)).getFixedahead())) { + fixedahead = ((MaterialPlanVO) map.get(hcmaterialvid)).getFixedahead(); + } + if ((new UFDouble(ileadtimenum.intValue())).compareTo(fixedahead) > 0) { + item.setIleadtimenum(null); + + } + + } catch (BusinessException e) { + ExceptionUtils.wrappBusinessException(e.toString()); + } + } + + public static Map queryMaterialPlanInfoByPks(String[] pks, String pk_stockorg, + String[] fields) throws BusinessException { + Map map = null; + + List vids = (List) Stream.of(pks).filter(e -> (e != null)).distinct().collect(Collectors.toList()); + if (vids.size() == 0) { + map = new HashMap(); + } else { + + map = ((IMaterialPubService) NCLocator.getInstance().lookup(IMaterialPubService.class)) + .queryMaterialPlanInfoByPks((String[]) vids.toArray(new String[0]), pk_stockorg, fields); + } + + return map; + } + + private void fitemtypeEvent(BomItemVO item) { + String fitem = item.getAttributeValue("fitemtype").toString(); + if ("1".equals(fitem)) { + if (MMValueCheck.isEmpty(item.getFitemsource())) { + item.setAttributeValue("fitemsource", Integer.valueOf(1)); + } + } else { + item.setAttributeValue("fitemsource", null); + } + } + + private void bprojectmaterialEvent(BomItemVO item) { + Object bprojectMaterial = item.getAttributeValue("bprojectmaterial"); + if (MMValueCheck.isEmpty(bprojectMaterial)) { + item.setAttributeValue("cprojectid", null); + } + } + + private void bcustommaterial(BomItemVO item) { + Object bcustommaterial = item.getAttributeValue("bcustommaterial"); + if (MMValueCheck.isEmpty(bcustommaterial)) { + item.setAttributeValue("ccustomerid", null); + item.setAttributeValue("ccustomerid_v", null); + } + } + + private void fbackflushtypeEvent(BomItemVO item) { + Object bcustommaterial = item.getAttributeValue("fbackflushtype"); + if (MMValueCheck.isNotEmpty(bcustommaterial) && "1".equals(bcustommaterial.toString())) { + item.setAttributeValue("fbackflushtime", null); + } + } + + private void ndisspationumEvent(BomItemVO item, String pkorg) { + int scale = MMBDFactoryParameter.findMMBDDigitNumber(pkorg).intValue(); + UFDouble ndisspationum = (UFDouble) item.getAttributeValue("ndissipationum"); + if (MMValueCheck.isNotEmpty(ndisspationum)) { + ndisspationum.setScale(scale, 1); + item.setAttributeValue("ndissipationum", ndisspationum); + } + } + + private int getNumberDecimalDigits(String balanceStr) { + int dcimalDigits = 0; + int indexOf = balanceStr.indexOf("."); + if (indexOf > 0) { + dcimalDigits = balanceStr.length() - 1 - indexOf; + } + return dcimalDigits; + } + + private void wipNumsEvent(BomWipVO vo) { + UFDouble num = (UFDouble) vo.getAttributeValue("nnum"); + String unitid = (String) vo.getAttributeValue("cassmeasureid"); + UFDouble nnum = (new NumScaleUtil()).calNumScale(num, unitid); + int scale = getNumberDecimalDigits(nnum.toString()); + vo.setAttributeValue("nnum", nnum.setScale(scale, 1)); + } + + private void posNumsEvent(BomPosVO vo) { + UFDouble num = (UFDouble) vo.getAttributeValue("nnum"); + String unitid = (String) vo.getAttributeValue("cassmeasureid"); + UFDouble nnum = (new NumScaleUtil()).calNumScale(new UFDouble(num), unitid); + int scale = getNumberDecimalDigits(nnum.toString()); + vo.setAttributeValue("nnum", nnum.setScale(scale, 1)); + } + + private void lossNumEvent(BomLossVO vo) { + BomLossVO loss = new BomLossVO(); + loss.setAttributeValue("clunitid", vo.getAttributeValue("clunitid")); + loss.setAttributeValue("clunitastid", vo.getAttributeValue("clunitastid")); + loss.setAttributeValue("vlchangerate", vo.getAttributeValue("vlchangerate")); + loss.setAttributeValue("nlfromastnum", vo.getAttributeValue("nlfromastnum")); + loss.setAttributeValue("nltoastnum", vo.getAttributeValue("nltoastnum")); + MeasureParam headParam = new MeasureParam(); + headParam.setCmeasureid("clunitid"); + headParam.setCassMeasures("clunitastid"); + headParam.setVchangeRate("vlchangerate"); + MeasureHelper.fillAccNumber(loss, headParam, "nlfromnum", "nlfromastnum"); + double fromNum = loss.getNlfromnum().doubleValue(); + + vo.setAttributeValue("nlfromnum", Double.valueOf(fromNum)); + + MeasureHelper.fillAccNumber(loss, headParam, "nltonum", "nltoastnum"); + double ltonum = loss.getNltonum().doubleValue(); + + vo.setAttributeValue("nltonum", Double.valueOf(ltonum)); + } + + private BomWipVO[] getWipVos(List> infos) { + List list = new ArrayList(); + Set set = (Set) idsMap.get(WIPTABLE); + if (set == null) { + set = new HashSet(); + } + + for (Map info : infos) { + BomWipVO vo = new BomWipVO(); + for (String key : info.keySet()) { + vo.setAttributeValue(key, info.get(key)); + } + set.remove(vo.getPrimaryKey()); + if (MMValueCheck.isNotEmpty(vo.getPrimaryKey())) { + vo.setStatus(1); + } else { + vo.setStatus(2); + } + vo.setTs((UFDateTime) tsMap.get(vo.getPrimaryKey())); + list.add(vo); + } + + for (String key : set) { + BomWipVO vo = (BomWipVO) voMap.get(key); + vo.setStatus(3); + list.add(vo); + } + + return (BomWipVO[]) list.toArray(new BomWipVO[0]); + } + + private BomPosVO[] getPosVos(List> infos) { + List list = new ArrayList(); + Set set = (Set) idsMap.get(POSITIONTABLE); + + if (set == null) { + set = new HashSet(); + } + + for (Map info : infos) { + BomPosVO vo = new BomPosVO(); + for (String key : info.keySet()) { + vo.setAttributeValue(key, info.get(key)); + } + set.remove(vo.getPrimaryKey()); + if (MMValueCheck.isNotEmpty(vo.getPrimaryKey())) { + vo.setStatus(1); + } else { + vo.setStatus(2); + } + vo.setTs((UFDateTime) tsMap.get(vo.getPrimaryKey())); + list.add(vo); + } + + for (String key : set) { + BomPosVO vo = (BomPosVO) voMap.get(key); + vo.setStatus(3); + list.add(vo); + } + return (BomPosVO[]) list.toArray(new BomPosVO[0]); + } + + private BomReplVO[] getReplVos(List> infos) { + List list = new ArrayList(); + Set set = (Set) idsMap.get(REPLTABLE); + + if (set == null) { + set = new HashSet(); + } + + for (Map info : infos) { + BomReplVO vo = new BomReplVO(); + for (String key : info.keySet()) { + vo.setAttributeValue(key, info.get(key)); + } + set.remove(vo.getPrimaryKey()); + if (MMValueCheck.isNotEmpty(vo.getPrimaryKey())) { + vo.setStatus(1); + } else { + vo.setStatus(2); + } + vo.setTs((UFDateTime) tsMap.get(vo.getPrimaryKey())); + list.add(vo); + } + + for (String key : set) { + BomReplVO vo = (BomReplVO) voMap.get(key); + vo.setStatus(3); + list.add(vo); + } + return (BomReplVO[]) list.toArray(new BomReplVO[0]); + } + + private BomLossVO[] getLossVos(List> infos, BomItemVO item) { + List list = new ArrayList(); + Set set = (Set) idsMap.get(LOSSTABLE); + + if (set == null) { + set = new HashSet(); + } + + for (Map info : infos) { + BomLossVO vo = new BomLossVO(); + for (String key : info.keySet()) { + vo.setAttributeValue(key, info.get(key)); + } + set.remove(vo.getPrimaryKey()); + if (MMValueCheck.isNotEmpty(vo.getPrimaryKey())) { + vo.setStatus(1); + } else { + vo.setStatus(2); + } + vo.setTs((UFDateTime) tsMap.get(vo.getPrimaryKey())); + vo.setAttributeValue("clunitastid", item.getAttributeValue("cassmeasureid")); + vo.setAttributeValue("clunitid", item.getAttributeValue("cmeasureid")); + list.add(vo); + } + + for (String key : set) { + BomLossVO vo = (BomLossVO) voMap.get(key); + vo.setStatus(3); + list.add(vo); + } + return (BomLossVO[]) list.toArray(new BomLossVO[0]); + } + + public BomItemVO[] handleEvent(BomItemVO[] items) throws BusinessException { + List itemCmaterialvids = new ArrayList(); + for (BomItemVO item : items) { + if (MMValueCheck.isNotEmpty(item.getCmaterialvid())) { + itemCmaterialvids.add(item.getCmaterialvid()); + } + } + Map materialMap = new HashMap(); + Map measurevoMap = new HashMap(); + + String pkorg = items[0].getPk_org(); + if (itemCmaterialvids.size() > 0) { + try { + materialMap = ((IBomBillQueryService) NCLocator.getInstance().lookup(IBomBillQueryService.class)) + .queryMaterialInfo(pkorg, (String[]) itemCmaterialvids.toArray(new String[0])); + IMeasesureService service = (IMeasesureService) NCLocator.getInstance().lookup(IMeasesureService.class); + measurevoMap.putAll(service.getMeasureInfoMap((String[]) itemCmaterialvids.toArray(new String[0]))); + } catch (BusinessException e1) { + ExceptionUtils.wrappBusinessException(e1.toString()); + } + } + + for (BomItemVO item : items) { + if (MMValueCheck.isNotEmpty(item.getCmaterialvid())) { + item.setVitemversion(null); + item.setVpackversion(null); + item.setVfree1(null); + item.setVfree2(null); + item.setVfree3(null); + item.setVfree4(null); + item.setVfree5(null); + item.setVfree6(null); + item.setVfree7(null); + item.setVfree8(null); + item.setVfree9(null); + item.setVfree10(null); + + if (measurevoMap.containsKey(item.getCmaterialvid())) { + if (MMValueCheck.isEmpty(item.getVchangerate())) { + item.setVchangerate(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getVchangeRate()); + } + + item.setCmeasureid(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getCmeasureid()); + + item.setCassmeasureid(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getCassMeasures()); + } + + setMaterialInfo(materialMap, item); + MeasureParam headParam = new MeasureParam(); + headParam.setCmaterialvid("cmaterialvid"); + headParam.setCmeasureid("cmeasureid"); + headParam.setCassMeasures("cassmeasureid"); + headParam.setVchangeRate("vchangerate"); + MeasureHelper.fillAccNumber(item, headParam, "nitemnum", "nassitemnum"); + } else { + + item.setBdeliver(UFBoolean.FALSE); + item.setAttributeValue("iscreatesonprodorder", UFBoolean.FALSE); + item.setAttributeValue("nbfixshrinkastnum", null); + item.setAttributeValue("nbfixshrinknum", null); + item.setAttributeValue("ndissipationum", null); + item.setAttributeValue("fbackflushtime", null); + item.setAttributeValue("fbackflushtype", null); + item.setAttributeValue("bbunibatch", UFBoolean.FALSE); + item.setVfree1(null); + item.setVfree2(null); + item.setVfree3(null); + item.setVfree4(null); + item.setVfree5(null); + item.setVfree6(null); + item.setVfree7(null); + item.setVfree8(null); + item.setVfree9(null); + item.setVfree10(null); + } + } + + return items; + } + + public BomItemVO[] handleEventTwo(AggBomVO agg) throws MetaDataException { + IUifService iUifService = NCLocator.getInstance().lookup(IUifService.class); + BomItemVO[] items = agg.getChildrenVO(); + for (BomItemVO item : items) { + StringBuffer whereSqlitem = new StringBuffer(); + whereSqlitem.append(" hcmaterialid = '" + item.getCmaterialid() + "'").append(" and dr ='0'"); + Collection aggBomVOitem; + try { + aggBomVOitem = MDPersistenceService.lookupPersistenceQueryService().queryBillOfVOByCond(AggBomVO.class, whereSqlitem.toString(), false); + if (Objects.nonNull(aggBomVOitem) && !aggBomVOitem.isEmpty()) { + StringBuffer whereSql = new StringBuffer(); + whereSql.append(" hcmaterialid = '" + item.getCmaterialid() + "'").append(" and hvdef3 ='" + agg.getParent().getAttributeValue("hvdef3") + "'").append(" and hvdef2 ='" + agg.getParent().getAttributeValue("hvdef2") + "'").append(" and dr ='0'"); + Collection aggBomVO; + aggBomVO = MDPersistenceService.lookupPersistenceQueryService().queryBillOfVOByCond(AggBomVO.class, whereSql.toString(), false); + if (Objects.nonNull(aggBomVO) && aggBomVO.size() == 1) { + for (AggBomVO aggBom : aggBomVO) { + item.setVitemversion(aggBom.getPrimaryKey()); + } + } else { + nccloud.base.exception.ExceptionUtils.wrapBusinessException("根据条件未查出bom或者查出多条bom不唯一" + whereSql); + } + } + } catch (MetaDataException e1) { + e1.printStackTrace(); + ExceptionUtils.wrappBusinessException(e1.toString()); + } + } + + return items; + } + + void setMaterialInfo(Map materialMap, BomItemVO item) { + String materialvid = item.getCmaterialvid(); + if (!materialMap.containsKey(materialvid)) { + return; + } + + BomMaterialParam materialParam = (BomMaterialParam) materialMap.get(materialvid); + if (materialParam == null) { + return; + } + if (UFBoolean.TRUE == materialParam.getIsvirtual()) { + + item.setBbsteploss(UFBoolean.FALSE); + item.setNbfixshrinknum(null); + item.setNbfixshrinkastnum(null); + item.setNdissipationum(null); + item.setIleadtimenum(null); + item.setBupint(UFBoolean.FALSE); + + item.setBisvirtual(UFBoolean.TRUE); + } else { + item.setAttributeValue("nbfixshrinknum", materialParam.getNfixshrinknum()); + + MeasureParam headParam = new MeasureParam(); + headParam.setCmaterialvid("cmaterialvid"); + headParam.setCmeasureid("cmeasureid"); + headParam.setCassMeasures("cassmeasureid"); + headParam.setVchangeRate("vchangerate"); + MeasureHelper.fillOnlyNumAssNumQtNum(item, headParam, "nbfixshrinknum", "nbfixshrinkastnum", null); + + item.setAttributeValue("ndissipationum", materialParam.getNdissipationnum()); + } + + if (MMValueCheck.isEmpty(item.getBdeliver())) { + item.setAttributeValue("bdeliver", materialParam.getBdeliver()); + } + + if (MMValueCheck.isEmpty(item.getFbackflushtype())) { + item.setAttributeValue("fbackflushtype", materialParam.getFbackflushtype()); + } + + if (MMValueCheck.isEmpty(item.getFbackflushtime())) { + item.setAttributeValue("fbackflushtime", materialParam.getFbackflushtime()); + } + + if (MMValueCheck.isEmpty(item.getBbunibatch())) { + item.setAttributeValue("bbunibatch", materialParam.getBunibatch()); + } + + if (BackflushTypeEnum.NOBACKFLUSH.equalsValue(materialParam.getFbackflushtype())) { + item.setAttributeValue("fbackflushtime", null); + + } else if (BackflushTypeEnum.AUTOBACKFLUSH.equalsValue(materialParam.getFbackflushtype()) + || BackflushTypeEnum.EXCHANGEBACKFLUSH.equalsValue(materialParam.getFbackflushtype())) { + if (MMValueCheck.isEmpty(materialParam.getFbackflushtime())) { + item.setAttributeValue("fbackflushtime", Integer.valueOf(BackflushTimeEnum.MMBOM.toIntValue())); + } + } else if (MMValueCheck.isEmpty(materialParam.getFbackflushtype())) { + + item.setAttributeValue("fbackflushtype", Integer.valueOf(BackflushTypeEnum.EXCHANGEBACKFLUSH.toIntValue())); + item.setAttributeValue("fbackflushtime", Integer.valueOf(BackflushTimeEnum.MMBOM.toIntValue())); + } + + item.setAttributeValue("iscreatesonprodorder", materialParam.getIscreatesonprodorder()); + } + + public BomOutputsVO[] handleEvent(BomOutputsVO[] items) { + Map materialMap = new HashMap(); + for (BomOutputsVO item : items) { + try { + materialMap = ((IBomBillQueryService) NCLocator.getInstance().lookup(IBomBillQueryService.class)) + .queryMaterialInfo(item.getPk_org(), new String[]{item.getCmaterialvid()}); + + Map measurevoMap = new HashMap(); + IMeasesureService service = (IMeasesureService) NCLocator.getInstance().lookup(IMeasesureService.class); + measurevoMap.putAll(service.getMeasureInfoMap(new String[]{item.getCmaterialvid()})); + if (measurevoMap.containsKey(item.getCmaterialvid())) { + item.setVchangerate(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getVchangeRate()); + item.setCastunitid(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getCassMeasures()); + item.setCunitid(((MeasureVO) measurevoMap.get(item.getCmaterialvid())).getCmeasureid()); + } + + Map cmaterialMap = getMateriaInfoByVid(item.getCmaterialvid()); + MaterialVO materialVO = (MaterialVO) cmaterialMap.get(item.getCmaterialvid()); + item.setCmaterialid(materialVO.getPk_source()); + } catch (BusinessException e1) { + ExceptionUtils.wrappBusinessException(e1.toString()); + } + MeasureParam headParam = new MeasureParam(); + headParam.setCmaterialvid("cmaterialvid"); + headParam.setCmeasureid("cunitid"); + headParam.setCassMeasures("castunitid"); + headParam.setVchangeRate("vchangerate"); + MeasureHelper.fillAccNumber(item, headParam, "noutputnum", "nastoutputnum"); + + item.setVfree1(null); + item.setVfree2(null); + item.setVfree3(null); + item.setVfree4(null); + item.setVfree5(null); + item.setVfree6(null); + item.setVfree7(null); + item.setVfree8(null); + item.setVfree9(null); + item.setVfree10(null); + } + + return items; + } + + private JSONString requiredCheck(AggBomVO agg) { + Object hcmaterialid = agg.getParent().getAttributeValue("hcmaterialid"); + + Object fbomtype = agg.getParent().getAttributeValue("fbomtype"); + + Object hversion = agg.getParent().getAttributeValue("hversion"); + + if (MMValueCheck.isEmpty(hcmaterialid) || MMValueCheck.isEmpty(fbomtype) || MMValueCheck.isEmpty(hversion)) { + return ResultMessageUtil.exceptionToJSON("传入数据异常,表头信息存在未填的必输项", "1"); + } + + BomItemVO[] items = agg.getChildrenVO(); + for (int i = 0; i < items.length; i++) { + BomItemVO item = items[i]; + + String cmaterialvid = item.getCmaterialvid(); + + UFDouble nassitemnum = item.getNassitemnum(); + + Integer ibasenum = item.getIbasenum(); + + Integer fitemtype = item.getFitemtype(); + + Integer fsupplymode = item.getFsupplymode(); + + Integer fbackflushtype = item.getFbackflushtype(); + + Integer fcontrol = item.getFcontrol(); + + UFDate cbeginperiod = item.getCbeginperiod(); + + UFDate cendperiod = item.getCendperiod(); + + if (MMValueCheck.isEmpty(cmaterialvid) || MMValueCheck.isEmpty(nassitemnum) + || MMValueCheck.isEmpty(ibasenum) || MMValueCheck.isEmpty(fitemtype) + || MMValueCheck.isEmpty(fsupplymode) || MMValueCheck.isEmpty(fcontrol) + || MMValueCheck.isEmpty(cbeginperiod) || MMValueCheck.isEmpty(cendperiod) + || MMValueCheck.isEmpty(fbackflushtype)) { + return ResultMessageUtil.exceptionToJSON("传入数据异常,子表材料第" + i + 1 + "行" + cmaterialvid + "存在未填的必输项", "1"); + } + } + + BomOutputsVO[] bomOutputsVO = (BomOutputsVO[]) agg.getChildren(BomOutputsVO.class); + + for (int j = 0; j < bomOutputsVO.length; j++) { + BomOutputsVO outputsVO = bomOutputsVO[j]; + + Integer foutputtype = outputsVO.getFoutputtype(); + + String cmaterialvid = outputsVO.getCmaterialvid(); + + if (MMValueCheck.isEmpty(foutputtype) || MMValueCheck.isEmpty(cmaterialvid)) { + return ResultMessageUtil.exceptionToJSON("传入数据异常,联副产品第" + j + 1 + "行" + cmaterialvid + "存在未填的必输项", "1"); + } + } + + return null; + } + + private Map getMateriaInfoByVid(String materialVid) { + Map materialSourceMap = new HashMap(); + try { + materialSourceMap = ((IMaterialPubService_C) NCLocator.getInstance().lookup(IMaterialPubService_C.class)) + .queryMaterialBaseInfoByPks(new String[]{materialVid}, + new String[]{"pk_source", "graphid", "materialspec", "materialtype"}); + + } catch (BusinessException e1) { + ResultMessageUtil.exceptionToJSON(e1); + } + return materialSourceMap; + } + + private void useOrgSupplement(AggBomVO agg) { + BomUseOrgVO[] useOrgVOs = (BomUseOrgVO[]) agg.getChildren(BomUseOrgVO.class); + if (MMValueCheck.isNotEmpty(useOrgVOs)) + for (BomUseOrgVO item : useOrgVOs) { + + item.setCbomid((String) agg.getParentVO().getAttributeValue("cbomid")); + item.setPk_org((String) agg.getParentVO().getAttributeValue("pk_org")); + item.setPk_org_v((String) agg.getParentVO().getAttributeValue("pk_org_v")); + item.setPk_useorg((String) agg.getParentVO().getAttributeValue("pk_org")); + item.setPk_useorg_v((String) agg.getParentVO().getAttributeValue("pk_org_v")); + } + } + + + private void handleCableOrgJinSiWeiBomVersion(AggBomVO agg) { + try { + String pk_org = (String) agg.getParent().getAttributeValue("pk_org"); + String hcmaterialid = (String) agg.getParent().getAttributeValue("hcmaterialid"); + String hversion = agg.getParent().getAttributeValue("hversion").toString(); + String cbomid = (String) agg.getParent().getAttributeValue("cbomid"); + String hvnote = (String) agg.getParent().getAttributeValue("hvnote"); + + // 检查必要字段 + if (MMValueCheck.isEmpty(hcmaterialid) || MMValueCheck.isEmpty(hversion)) { + return; + } + + // 判断是否为电缆组织(组织编码C034)且备注包含"金思维" + boolean isCableOrgJinSiWei = isCableOrganizationWithJinSiWei(pk_org, hvnote); + + if (isCableOrgJinSiWei) { + // 计算版本号 + String calculatedVersion = calculateBomVersion(pk_org, hcmaterialid); + agg.getParent().setAttributeValue("hversion", calculatedVersion); + } + } catch (Exception e) { + ExceptionUtils.wrappBusinessException("同步电缆组织金思维BOM版本号处理异常:" + e.getMessage()); + } + } + + /** + * 判断是否为电缆组织且备注包含金思维 + * + * @param pk_org 组织主键 + * @param hvnote 备注信息 + * @return 是否符合条件 + */ + private boolean isCableOrganizationWithJinSiWei(String pk_org, String hvnote) { + if (MMValueCheck.isEmpty(pk_org)) { + return false; + } + + try { + // 查询组织编码 + String sql = "SELECT code FROM org_orgs WHERE dr = 0 and pk_org = ?"; + SQLParameter param = new SQLParameter(); + param.addParam(pk_org); + String orgCode = (String) DAO.executeQuery(sql, param, new ColumnProcessor()); + + // 使用统一的组织判断方法 + boolean isCableOrg = HTTP_POST_OTHER_SYS.checkIfIncludeOrg(orgCode); + + // 判断备注是否包含"金思维" + boolean containsJinSiWei = MMValueCheck.isNotEmpty(hvnote) && hvnote.contains("金思维"); + + return isCableOrg && containsJinSiWei; + } catch (Exception e) { + // 查询异常时返回false + return false; + } + } + + /** + * 计算BOM版本号 + * + * @param pk_org 组织主键 + * @param hcmaterialid 物料编码 + * @return 计算出的版本号 + */ + private String calculateBomVersion(String pk_org, String hcmaterialid) throws BusinessException { + try { + // 构建查询条件 + StringBuilder sql = new StringBuilder(); + sql.append("SELECT MAX(TO_NUMBER(hversion)) as max_version "); + sql.append("FROM bd_bom "); + sql.append("WHERE dr = 0 and pk_org = ? "); + + SQLParameter param = new SQLParameter(); + param.addParam(pk_org); + + // 根据物料情况添加查询条件 + sql.append("AND hcmaterialid = ? "); + param.addParam(hcmaterialid); + + // 只查询数字版本号,排除非数字版本 + sql.append("AND REGEXP_LIKE(hversion, '^[0-9]+$') "); + // 如果查询不到数据,默认版本号为1;否则最大版本号加1 + Object mayBeNullVersion = DAO.executeQuery(sql.toString(), param, new ColumnProcessor()); + String number = Objects.isNull(mayBeNullVersion) ? "1" : DAO.executeQuery(sql.toString(), param, new ColumnProcessor()).toString(); + return String.valueOf(Long.parseLong(number) + 1); + + } catch (Exception e) { + throw new BusinessException("计算BOM版本号异常:" + e.getMessage()); + } + } + + /** + * 处理MES用户的hbdefault字段设置逻辑 + * 2025年6月20日新增 - 专门用于MES用户的处理 + * 2025年7月10日修改 - 改为根据自定义项hvdef4判断是否为定制BOM + * 同步MES时:只有标准版本的bom "默认"(hbdefault) 生效(hfversiontype的等于1) + * 定制bom(hvdef4值为Y)取消 "默认"(hbdefault,值为N) 但生效(hfversiontype的等于1) + * + * @param agg AggBomVO对象 + * @param userCode 用户代码 + * @auther 毛磊 + */ + private void handleMesUserDefaultSetting(AggBomVO agg, String userCode) { + obmlog.debug("handleMesUserDefaultSetting - 开始处理MES用户的默认设置逻辑,用户代码:" + userCode); + + // 仅针对MES用户进行处理 + if (!MESUSERCODE.equals(userCode)) { + obmlog.debug("handleMesUserDefaultSetting - 非MES用户,跳过处理"); + return; + } + + // 获取自定义项hvdef4的值 + String hvdef4 = (String) agg.getParent().getAttributeValue("hvdef4"); + obmlog.debug("handleMesUserDefaultSetting - 获取到自定义项hvdef4的值:" + hvdef4); + + // 判断是否为定制BOM(hvdef4值为Y时为定制BOM,其余情况为标准版本) + boolean isCustomBom = "Y".equals(hvdef4); + obmlog.debug("handleMesUserDefaultSetting - 是否为定制BOM:" + isCustomBom); + + // 所有MES用户的BOM都设置为生效状态 + agg.getParent().setAttributeValue("hfversiontype", 1); + obmlog.debug("handleMesUserDefaultSetting - 设置版本类型为生效状态(hfversiontype=1)"); + + if (isCustomBom) { + // 定制BOM:取消默认但仍然生效 + agg.getParent().setAttributeValue("hbdefault", "N"); + obmlog.debug("handleMesUserDefaultSetting - 定制BOM,取消默认(hbdefault=false)"); + } else { + // 标准版本:设置为默认且生效 + agg.getParent().setAttributeValue("hbdefault", "Y"); + obmlog.debug("handleMesUserDefaultSetting - 标准版本,设置为默认(hbdefault=true)"); + } + + obmlog.debug("handleMesUserDefaultSetting - MES用户默认设置处理完成"); + } } diff --git a/uapbd/src/public/nccloud/api/mmbd/bom/IAPIBomBusinessService.java b/uapbd/src/public/nccloud/api/mmbd/bom/IAPIBomBusinessService.java new file mode 100644 index 0000000..fe06317 --- /dev/null +++ b/uapbd/src/public/nccloud/api/mmbd/bom/IAPIBomBusinessService.java @@ -0,0 +1,24 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package nccloud.api.mmbd.bom; + +import java.util.List; +import java.util.Map; + +import nc.vo.bd.bom.bom0202.entity.AggBomVO; +import nc.vo.pub.BusinessException; +import org.json.JSONString; + +public interface IAPIBomBusinessService { + JSONString insert(List> var1); + + JSONString update(List> var1); + + JSONString query(Map var1); + + AggBomVO[] updateBomWithParam(AggBomVO[] aggvos, boolean isFromBom, boolean isecn, boolean isCheckEcn, + boolean isOnApprove) throws BusinessException; +} diff --git a/uapbd/src/public/nccloud/openapi/mmbd/bom/BomResource.java b/uapbd/src/public/nccloud/openapi/mmbd/bom/BomResource.java index 06a9f81..c17808c 100644 --- a/uapbd/src/public/nccloud/openapi/mmbd/bom/BomResource.java +++ b/uapbd/src/public/nccloud/openapi/mmbd/bom/BomResource.java @@ -6,15 +6,6 @@ package nccloud.openapi.mmbd.bom; import com.alibaba.fastjson.JSONObject; - -import java.util.*; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import nc.bs.bd.bom.bom0202.bp.BomPubBP; -import nc.bs.bd.bom.bom0202.bp.BomUpdateBP; import nc.bs.framework.common.NCLocator; import nc.bs.trade.business.HYPubBO; import nc.itf.bd.bom.bom0202.IBomBillMaintainService; @@ -22,13 +13,10 @@ import nc.itf.bd.bom.bom0202.IBomBillQueryService; import nc.jdbc.framework.generator.IdGenerator; import nc.mmbd.utils.factoryparam.MMBDFactoryParameter; import nc.uif.pub.exception.UifException; -import nc.util.mmf.framework.base.MMArrayUtil; import nc.util.mmf.framework.base.MMValueCheck; -import nc.util.mmf.framework.gc.GCBillTransferTool; import nc.vo.bd.bom.bom0202.entity.AggBomVO; import nc.vo.bd.bom.bom0202.entity.BomItemVO; import nc.vo.bd.bom.bom0202.entity.BomReplVO; -import nc.vo.bd.bom.bom0202.message.MMBDLangConstBom0202; import nc.vo.ml.NCLangRes4VoTransl; import nc.vo.pub.BusinessException; import nc.vo.pub.VOStatus; @@ -37,9 +25,18 @@ import nc.vo.pub.lang.UFDouble; import nccloud.api.mmbd.bom.IAPIBomBusinessService; import nccloud.api.rest.utils.ResultMessageUtil; import nccloud.framework.core.exception.ExceptionUtils; -//import nccloud.framework.service.ServiceLocator; import nccloud.ws.rest.resource.AbstractNCCRestResource; import org.json.JSONString; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + @Path("mmbd/bom") public class BomResource extends AbstractNCCRestResource { public BomResource() { @@ -50,11 +47,11 @@ public class BomResource extends AbstractNCCRestResource { @Consumes({"application/json"}) @Produces({"application/json"}) public JSONString insert(JSONObject para) { - List> paramList = (List)para.get("data"); + List> paramList = (List) para.get("data"); if (MMValueCheck.isEmpty(paramList)) { return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); } else { - IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); + IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class); JSONString result = service.insert(paramList); return result; } @@ -68,7 +65,7 @@ public class BomResource extends AbstractNCCRestResource { if (MMValueCheck.isEmpty(paramList)) { return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); } else { - IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); + IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class); JSONString result = service.insert(paramList); return result; } @@ -79,11 +76,11 @@ public class BomResource extends AbstractNCCRestResource { @Consumes({"application/json"}) @Produces({"application/json"}) public JSONString update(JSONObject para) { - List> paramList = (List)para.get("data"); + List> paramList = (List) para.get("data"); if (MMValueCheck.isEmpty(paramList)) { return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); } else { - IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); + IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class); JSONString result = service.update(paramList); return result; } @@ -97,7 +94,7 @@ public class BomResource extends AbstractNCCRestResource { if (MMValueCheck.isEmpty(paramList)) { return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1"); } else { - IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); + IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class); JSONString result = service.update(paramList); return result; } @@ -111,7 +108,7 @@ public class BomResource extends AbstractNCCRestResource { if (MMValueCheck.isEmpty(paramMap)) { return ResultMessageUtil.exceptionToJSON("传入数据异常,未传入查询条件", "1"); } else { - IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); + IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class); JSONString result = service.query(paramMap); return result; } @@ -125,108 +122,108 @@ public class BomResource extends AbstractNCCRestResource { if (MMValueCheck.isEmpty(paramMap)) { return ResultMessageUtil.exceptionToJSON("传入数据异常,未传入更新数据", "1"); } else { - try{ + try { - IAPIBomBusinessService service = (IAPIBomBusinessService)NCLocator.getInstance().lookup(IAPIBomBusinessService.class); -// List<> - IBomBillQueryService qry = (IBomBillQueryService)NCLocator.getInstance().lookup(IBomBillQueryService.class); - IBomBillMaintainService bomBillMaintainService = (IBomBillMaintainService)NCLocator.getInstance().lookup(IBomBillMaintainService.class); + IAPIBomBusinessService service = (IAPIBomBusinessService) NCLocator.getInstance().lookup(IAPIBomBusinessService.class); + IBomBillQueryService qry = (IBomBillQueryService) NCLocator.getInstance().lookup(IBomBillQueryService.class); + IBomBillMaintainService bomBillMaintainService = (IBomBillMaintainService) NCLocator.getInstance().lookup(IBomBillMaintainService.class); - List bomReplVOS = new ArrayList<>(); - for (Map param : paramMap) { - String cbomid = (String) param.get("cbomid"); - String targetCbomReplaceId = (String) param.get("cbom_replaceid"); // 目标替代ID - String targetCbomBid = (String) param.get("cbombid"); // 目标物料项ID + List bomReplVOS = new ArrayList<>(); + for (Map param : paramMap) { + String cbomid = (String) param.get("cbomid"); + String targetCbomReplaceId = (String) param.get("cbom_replaceid"); // 目标替代ID + String targetCbomBid = (String) param.get("cbombid"); // 目标物料项ID - // 校验必要参数 - if (MMValueCheck.isEmpty(cbomid) || MMValueCheck.isEmpty(targetCbomBid)) { - ExceptionUtils.wrapBusinessException("cbomid和cbombid为必传参数"); - } - - // 查询BOM数据 - AggBomVO[] aggbomvos = qry.queryAggBomByBomID(new String[]{cbomid}); - if (MMValueCheck.isEmpty(aggbomvos)) { - ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("bdpub", "0bdpub0057")); - } - - for (AggBomVO aggBomVO : aggbomvos) { - BomItemVO[] bomItemVOS = aggBomVO.getChildrenVO(); - if (MMValueCheck.isEmpty(bomItemVOS)) { - continue; // 无物料项则跳过 + // 校验必要参数 + if (MMValueCheck.isEmpty(cbomid) || MMValueCheck.isEmpty(targetCbomBid)) { + ExceptionUtils.wrapBusinessException("cbomid和cbombid为必传参数"); } - for (BomItemVO bomItemVO : bomItemVOS) { - // 匹配目标物料项 - if (targetCbomBid.equals(bomItemVO.getCbom_bid())) { - BomReplVO[] replVOS = bomItemVO.getRepl(); - List replList = MMValueCheck.isEmpty(replVOS) - ? new ArrayList<>() - : new ArrayList<>(Arrays.asList(replVOS)); + // 查询BOM数据 + AggBomVO[] aggbomvos = qry.queryAggBomByBomID(new String[]{cbomid}); + if (MMValueCheck.isEmpty(aggbomvos)) { + ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("bdpub", "0bdpub0057")); + } - boolean isUpdated = false; + for (AggBomVO aggBomVO : aggbomvos) { + BomItemVO[] bomItemVOS = aggBomVO.getChildrenVO(); + if (MMValueCheck.isEmpty(bomItemVOS)) { + continue; // 无物料项则跳过 + } - // 存在cbom_replaceid则更新 - if (!MMValueCheck.isEmpty(targetCbomReplaceId)) { - for (BomReplVO replVO : replList) { - if (targetCbomReplaceId.equals(replVO.getCbom_replaceid())) { - // 设置属性(复用工具方法) - setReplVOProperties(replVO, param); - replVO.setStatus(VOStatus.UPDATED); - isUpdated = true; - break; + for (BomItemVO bomItemVO : bomItemVOS) { + // 匹配目标物料项 + if (targetCbomBid.equals(bomItemVO.getCbom_bid())) { + BomReplVO[] replVOS = bomItemVO.getRepl(); + List replList = MMValueCheck.isEmpty(replVOS) + ? new ArrayList<>() + : new ArrayList<>(Arrays.asList(replVOS)); + + boolean isUpdated = false; + + // 存在cbom_replaceid则更新 + if (!MMValueCheck.isEmpty(targetCbomReplaceId)) { + for (BomReplVO replVO : replList) { + if (targetCbomReplaceId.equals(replVO.getCbom_replaceid())) { + // 设置属性(复用工具方法) + setReplVOProperties(replVO, param); + replVO.setStatus(VOStatus.UPDATED); + isUpdated = true; + break; + } } } + + // 不存在cbom_replaceid则新增 + if (!isUpdated && MMValueCheck.isEmpty(targetCbomReplaceId)) { + BomReplVO newReplVO = new BomReplVO(); + IdGenerator idGenerator = NCLocator.getInstance().lookup(IdGenerator.class); + + newReplVO.setCbom_replaceid(idGenerator.generate()); // 生成新ID + newReplVO.setCbom_bid(targetCbomBid); // 关联当前物料项 + + // 计算新行号:(原有替代项数量 + 1) * 10 + int existingCount = replList.size(); + int newRowNumber = (existingCount + 1) * 10; + newReplVO.setVrowno(String.valueOf(newRowNumber)); // 设置新行号 + + // 设置其他属性(会覆盖param中的vrowno,确保按规则生成) + setReplVOProperties(newReplVO, param); + + newReplVO.setStatus(VOStatus.NEW); + replList.add(newReplVO); + } + + // 更新物料项的替代项数组 + bomItemVO.setRepl(replList.toArray(new BomReplVO[0])); } - - // 不存在cbom_replaceid则新增 - if (!isUpdated && MMValueCheck.isEmpty(targetCbomReplaceId)) { - BomReplVO newReplVO = new BomReplVO(); - IdGenerator idGenerator = NCLocator.getInstance().lookup(IdGenerator.class); - - newReplVO.setCbom_replaceid(idGenerator.generate()); // 生成新ID - newReplVO.setCbom_bid(targetCbomBid); // 关联当前物料项 - - // 计算新行号:(原有替代项数量 + 1) * 10 - int existingCount = replList.size(); - int newRowNumber = (existingCount + 1) * 10; - newReplVO.setVrowno(String.valueOf(newRowNumber)); // 设置新行号 - - // 设置其他属性(会覆盖param中的vrowno,确保按规则生成) - setReplVOProperties(newReplVO, param); - - newReplVO.setStatus(VOStatus.NEW); - replList.add(newReplVO); - } - - // 更新物料项的替代项数组 - bomItemVO.setRepl(replList.toArray(new BomReplVO[0])); } + + // 更新BOM + aggBomVO.setChildrenVO(bomItemVOS); + AggBomVO[] result = service.updateBomWithParam( + new AggBomVO[]{aggBomVO}, + false, + false, + MMBDFactoryParameter.getMMECN001Value( + aggBomVO.getParentVO().getAttributeValue("pk_org").toString() + ).booleanValue(), + true + ); + bomReplVOS.addAll(Arrays.asList(result)); } - - // 更新BOM - aggBomVO.setChildrenVO(bomItemVOS); - AggBomVO[] result = this.updateBomWithParam( - new AggBomVO[]{aggBomVO}, - false, - false, - MMBDFactoryParameter.getMMECN001Value( - aggBomVO.getParentVO().getAttributeValue("pk_org").toString() - ).booleanValue(), - true - ); - bomReplVOS.addAll(Arrays.asList(result)); } - } - return ResultMessageUtil.toJSON(bomReplVOS, "BOM更新成功"); - }catch (BusinessException e) { - throw new RuntimeException(e); + return ResultMessageUtil.toJSON(bomReplVOS, "BOM更新成功"); + } catch (BusinessException e) { + return ResultMessageUtil.exceptionToJSON(e); } } } + // 提取属性设置为工具方法,减少冗余 private void setReplVOProperties(BomReplVO replVO, Map param) throws UifException { HYPubBO hybo = new HYPubBO(); @@ -238,8 +235,8 @@ public class BomResource extends AbstractNCCRestResource { // } if (param.containsKey("creplmaterialvid")) { - String mrlCode= (String) param.get("creplmaterialvid"); - String mrlid=(String) hybo.findColValue("bd_material","pk_material"," code = '" + mrlCode + "' "); + String mrlCode = (String) param.get("creplmaterialvid"); + String mrlid = (String) hybo.findColValue("bd_material", "pk_material", " code = '" + mrlCode + "' "); replVO.setCreplmaterialvid(mrlid); } @@ -273,34 +270,6 @@ public class BomResource extends AbstractNCCRestResource { } } } - public AggBomVO[] updateBomWithParam(AggBomVO[] aggvos, boolean isFromBom, boolean isecn, boolean isCheckEcn, - boolean isOnApprove) throws BusinessException { - if (MMArrayUtil.isEmpty(aggvos)) { - return null; - } - try { - // 检查该BOM是否被删除,因为如果BOM树状维护将BOM删除了,不允许修改该条记录 - Set bomids = new HashSet(); - for (AggBomVO vo : aggvos) { - bomids.add(vo.getPrimaryKey()); - } - Set checkResult = BomPubBP.getBomID(bomids.toArray(new String[] {})); - if (checkResult != null && checkResult.size() < bomids.size()) { - nc.vo.pubapp.pattern.exception.ExceptionUtils.wrappBusinessException(MMBDLangConstBom0202.getBOM_DELETED()); - } - // 加锁 + 检查ts - GCBillTransferTool transTool = new GCBillTransferTool(aggvos); - // 补全前台VO - AggBomVO[] fullBills = transTool.getClientFullInfoBill(); - // 获得修改前vo - AggBomVO[] originBills = transTool.getOriginBills(); - BomUpdateBP bp = new BomUpdateBP(); - return bp.update(fullBills, originBills, isCheckEcn, isOnApprove, isFromBom, isecn); - } catch (Exception e) { - nc.vo.pubapp.pattern.exception.ExceptionUtils.marsh(e); - } - return null; - } public String getModule() { return "mmbd";