diff --git a/pu/src/private/nccloud/api/impl/pu/m23/APIPuArriveMaitainImpl.java b/pu/src/private/nccloud/api/impl/pu/m23/APIPuArriveMaitainImpl.java new file mode 100644 index 0000000..8487cbe --- /dev/null +++ b/pu/src/private/nccloud/api/impl/pu/m23/APIPuArriveMaitainImpl.java @@ -0,0 +1,158 @@ +package nccloud.api.impl.pu.m23; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import nc.bs.framework.common.NCLocator; +import nc.bs.pf.pub.PfDataCache; +import nc.itf.scmpub.reference.uap.pf.PfServiceScmUtil; +import nc.itf.uap.pf.IPfExchangeService; +import nc.pubimpl.pu.m23.api.ProduceDateSetForArrival; +import nc.ui.pub.print.version55.util.DeepClone; +import nc.vo.pu.m21.entity.OrderItemVO; +import nc.vo.pu.m21.entity.OrderVO; +import nc.vo.pu.m23.entity.ArriveHeaderVO; +import nc.vo.pu.m23.entity.ArriveItemVO; +import nc.vo.pu.m23.entity.ArriveVO; +import nc.vo.pu.m23.rule.api.check.PUArriveVONullValidate; +import nc.vo.pub.BusinessException; +import nc.vo.pub.billtype.BilltypeVO; +import nc.vo.pubapp.AppContext; +import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.pubapp.pattern.pub.MathTool; +import nc.vo.scmpub.check.billvalidate.BillVOsCheckRule; +import nccloud.api.impl.pu.m23.fill.ArriveSaveFromOrder; +import nccloud.api.impl.pu.m23.util.queryFromOrder; +import nccloud.api.pu.m23.IAPIPuArriveMaitain; +import nccloud.openapi.scmpub.pub.TransferCodeToPKTool; +import nccloud.openapi.scmpub.pub.TransferMapToVOTool; + +/** + * zhangxinah 解决参照采购订单生成到货单校验过早的问题 + * 2312 + */ +public class APIPuArriveMaitainImpl implements IAPIPuArriveMaitain { + public ArriveVO[] saveFromOrder(List> paramList) throws BusinessException { + ArriveVO[] arriveVOs = null; + ArriveVO[] saveVOs = null; + + try { + List aggVOList = TransferMapToVOTool.transferMapToAggVO(paramList, ArriveVO.class); + + ArriveVO[] vos = (ArriveVO[]) aggVOList.toArray(new ArriveVO[aggVOList.size()]); + + aggVOList = TransferCodeToPKTool.transferAggVO(aggVOList); + + HashSet pk_order = new HashSet(); + for (ArriveVO vo : vos) { + for (ArriveItemVO itemVO : vo.getBVO()) { + pk_order.add(itemVO.getCsourceid()); + } + } + + OrderVO[] orderVOs = (new queryFromOrder()).query((String[]) pk_order.toArray(new String[0])); + calNumAndMny(orderVOs); + + IPfExchangeService service = (IPfExchangeService) NCLocator.getInstance().lookup(IPfExchangeService.class); + arriveVOs = (ArriveVO[]) service.runChangeDataAry("21", "23", orderVOs, null); + + BillVOsCheckRule checker = new BillVOsCheckRule(new PUArriveVONullValidate()); + checker.check(arriveVOs); + + Map destiHMap = new HashMap(); + for (ArriveVO arriveVO : arriveVOs) { + destiHMap.put(arriveVO.getBVO()[0].getCsourceid(), arriveVO.getHVO()); + } + + Map destiItemMap = new HashMap(); + for (ArriveVO arriveVO : arriveVOs) { + for (ArriveItemVO arriveItemVO : arriveVO.getBVO()) { + destiItemMap.put(arriveItemVO.getCsourcebid(), arriveItemVO); + } + } + + saveVOs = new ArriveVO[vos.length]; + for (int i = 0; i < saveVOs.length; i++) { + saveVOs[i] = new ArriveVO(); + + saveVOs[i].setHVO((ArriveHeaderVO) destiHMap.get(vos[i].getBVO()[0].getCsourceid())); + ArriveItemVO[] itemvos = new ArriveItemVO[vos[i].getBVO().length]; + for (int j = 0; j < itemvos.length; j++) { + + itemvos[j] = (ArriveItemVO) DeepClone.clone(destiItemMap.get(vos[i].getBVO()[j].getCsourcebid())); + } + saveVOs[i].setBVO(itemvos); + } + + for (int i = 0; i < vos.length; i++) { + + ArriveHeaderVO HVO = vos[i].getHVO(); + + ArriveItemVO[] BVO = vos[i].getBVO(); + + for (String key : HVO.getAttributeNames()) { + + if (null != HVO.getAttributeValue(key)) { + saveVOs[i].getHVO().setAttributeValue(key, HVO.getAttributeValue(key)); + } + } + + for (int j = 0; j < BVO.length; j++) { + for (String key : BVO[j].getAttributeNames()) { + + if (null != BVO[j].getAttributeValue(key)) { + saveVOs[i].getBVO()[j].setAttributeValue(key, BVO[j].getAttributeValue(key)); + } + } + } + } + + for (ArriveVO saveVO : saveVOs) { + + int rowNum = 0; + ArriveItemVO[] bvos = saveVO.getBVO(); + for (int i = 0; i < bvos.length; i++) { + rowNum++; + bvos[i].setCrowno("" + rowNum * 10); + } + + BilltypeVO trantypeVO = PfDataCache.getBillTypeInfo(AppContext.getInstance().getPkGroup(), + saveVO.getHVO().getVtrantypecode()); + saveVO.getHVO().setCtrantypeid(trantypeVO.getPk_billtypeid()); + } + + (new ArriveSaveFromOrder()).setDefaultValue(saveVOs); + + (new ProduceDateSetForArrival()).setProduceDate(saveVOs); + + saveVOs = (ArriveVO[]) PfServiceScmUtil.processBatch("SAVEBASE", "23", saveVOs, null, null); + } catch (Exception e) { + ExceptionUtils.wrappException(e); + } + return saveVOs; + } + + private void calNumAndMny(OrderVO[] vos) { + for (OrderVO vo : vos) { + OrderItemVO[] bvos = vo.getBVO(); + for (OrderItemVO bvo : bvos) { + + if (bvo.getNnopayorgmny() == null) { + bvo.setNnopayorgmny(MathTool.sub(bvo.getNtaxmny(), bvo.getNacccancelinvmny())); + } + + if (bvo.getNcanarrivenum() == null) { + bvo.setNcanarrivenum(MathTool.sub(bvo.getNnum(), bvo.getNaccumarrvnum())); + } + + if (bvo.getNcaninnum() == null) { + bvo.setNcaninnum(MathTool.sub(bvo.getNnum(), bvo.getNaccumstorenum())); + } + + if (bvo.getNcaninvoicenum() == null) + bvo.setNcaninvoicenum(MathTool.sub(bvo.getNnum(), bvo.getNaccuminvoicenum())); + } + } + } +} diff --git a/uapbd/src/private/nccloud/api/impl/mmbd/bom/APIBomBusinessServiceImpl.java b/uapbd/src/private/nccloud/api/impl/mmbd/bom/APIBomBusinessServiceImpl.java new file mode 100644 index 0000000..cd405bf --- /dev/null +++ b/uapbd/src/private/nccloud/api/impl/mmbd/bom/APIBomBusinessServiceImpl.java @@ -0,0 +1,1387 @@ +package nccloud.api.impl.mmbd.bom; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import nc.bs.framework.common.NCLocator; +import nc.itf.bd.bom.bom0202.IBomBillMaintainService; +import nc.itf.bd.bom.bom0202.IBomBillQueryService; +import nc.itf.mmf.busi.measure.IMeasesureService; +import nc.mmbd.utils.factoryparam.MMBDFactoryParameter; +import nc.pubitf.uapbd.IMaterialPubService; +import nc.pubitf.uapbd.IMaterialPubService_C; +import nc.ui.querytemplate.querytree.IQueryScheme; +import nc.util.bd.bom.openapi.BillFieldsCodeToPkUtil; +import nc.util.mmf.busi.measure.MeasureHelper; +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.MMValueCheck; +import nc.vo.bd.bom.bom0202.entity.AggBomVO; +import nc.vo.bd.bom.bom0202.entity.BomActivityVO; +import nc.vo.bd.bom.bom0202.entity.BomItemSourceVO; +import nc.vo.bd.bom.bom0202.entity.BomItemVO; +import nc.vo.bd.bom.bom0202.entity.BomLossVO; +import nc.vo.bd.bom.bom0202.entity.BomOutputsVO; +import nc.vo.bd.bom.bom0202.entity.BomPosVO; +import nc.vo.bd.bom.bom0202.entity.BomReplVO; +import nc.vo.bd.bom.bom0202.entity.BomSelectVO; +import nc.vo.bd.bom.bom0202.entity.BomUseOrgVO; +import nc.vo.bd.bom.bom0202.entity.BomVO; +import nc.vo.bd.bom.bom0202.entity.BomWipVO; +import nc.vo.bd.bom.bom0202.enumeration.BackflushTimeEnum; +import nc.vo.bd.bom.bom0202.enumeration.BackflushTypeEnum; +import nc.vo.bd.bom.bom0202.enumeration.BomCategoryEnum; +import nc.vo.bd.bom.bom0202.enumeration.BomTypeEnum; +import nc.vo.bd.bom.bom0202.enumeration.VersionTypeEnum; +import nc.vo.bd.bom.bom0202.paramvo.BomHeadMtrlParam; +import nc.vo.bd.bom.bom0202.paramvo.BomHeadMtrlResult; +import nc.vo.bd.bom.bom0202.paramvo.BomMaterialParam; +import nc.vo.bd.material.MaterialVO; +import nc.vo.bd.material.MaterialVersionVO; +import nc.vo.bd.material.plan.MaterialPlanVO; +import nc.vo.pub.BusinessException; +import nc.vo.pub.CircularlyAccessibleValueObject; +import nc.vo.pub.ISuperVO; +import nc.vo.pub.SuperVO; +import nc.vo.pub.lang.UFBoolean; +import nc.vo.pub.lang.UFDate; +import nc.vo.pub.lang.UFDateTime; +import nc.vo.pub.lang.UFDouble; +import nc.vo.pubapp.AppContext; +import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill; +import nccloud.api.mmbd.bom.IAPIBomBusinessService; +import nccloud.api.mmbd.utils.QuerySchemeUtils; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.vo.bd.bom.bom0202.validate.BomSavingValidation; +import org.json.JSONString; + +public class APIBomBusinessServiceImpl implements IAPIBomBusinessService { + 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 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()]); + + BillFieldsCodeToPkUtil.doTranslateVOFields(aggVOs); + + for (AggBomVO agg : aggVOs) { + // zhangxinah 对物料主键进行翻译 + dealWithMaterial(agg); + dataSupplement(agg); + + UFBoolean flag = (UFBoolean) agg.getParent().getAttributeValue("hbdefault"); + if (UFBoolean.TRUE.equals(flag)) { + UFBoolean bHasOtherDefaultVersion = getIsExistDefaultVersion(agg); + if (bHasOtherDefaultVersion.equals(UFBoolean.TRUE)) { + ExceptionUtils.wrappBusinessException("hasOtherDefaultVersion"); + } + } + + (new BomSavingValidation()).validate(agg); + } + + mapClear(); + + AggBomVO[] result = service.insertBom((AggBomVO[]) list.toArray(new AggBomVO[0])); + return ResultMessageUtil.toJSON(result, "BOM保存成功"); + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + + private void dealWithMaterial(AggBomVO agg) { + String hcmaterialvid = (String) agg.getParentVO().getAttributeValue("hcmaterialvid"); + //物料没启用版本,直接赋值 + if(hcmaterialvid.length()==20) { + agg.getParentVO().setAttributeValue("hcmaterialid", hcmaterialvid); + } + } + + 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); + + JSONString checkInfo = requiredCheck(agg); + if (checkInfo != null) { + return checkInfo; + } + list.add(agg); + } + + AggBomVO[] aggVOs = (AggBomVO[]) list.toArray(new AggBomVO[list.size()]); + + BillFieldsCodeToPkUtil.doTranslateVOFields(aggVOs); + + for (AggBomVO agg : aggVOs) { + + dataSupplement(agg); + + UFBoolean flag = (UFBoolean) agg.getParent().getAttributeValue("hbdefault"); + if (UFBoolean.TRUE.equals(flag)) { + UFBoolean bHasOtherDefaultVersion = getIsExistDefaultVersion(agg); + if (bHasOtherDefaultVersion.equals(UFBoolean.TRUE)) { + ExceptionUtils.wrappBusinessException("hasOtherDefaultVersion"); + } + } + + (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) { + if (aggvo != null) { + BomVO headvo = (BomVO) aggvo.getParentVO(); + String pk_org = headvo.getPk_org().toString(); + String materialOid = headvo.getHcmaterialid().toString(); + 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()); + } + if (MMValueCheck.isNotEmpty(defaultBOM)) { + for (AggBomVO aggBomVO : defaultBOM) { + BomVO head = (BomVO) aggBomVO.getParent(); + if (VersionTypeEnum.AVAILABLE.equalsValue(head.getHfversiontype()) + && !head.getCbomid().equals(headvo.getCbomid())) { + return UFBoolean.TRUE; + } + } + + } + } catch (BusinessException e) { + ExceptionUtils.wrappException(e); + } + } + + return UFBoolean.FALSE; + } + + private IBomBillQueryService getBomBillQueryService() { + return (IBomBillQueryService) NCLocator.getInstance().lookup(IBomBillQueryService.class); + } + + private void dataSupplement(AggBomVO agg) { + orgSupplement(agg); + + versionTypeSupplement(agg); + + materialidSupplement(agg); + + itemSupplement(agg); + + outputSupplement(agg); + + useOrgSupplement(agg); + } + + private void outputSupplement(AggBomVO agg) { + BomOutputsVO[] outputVOs = (BomOutputsVO[]) agg.getChildren(BomOutputsVO.class); + handleEvent(outputVOs); + } + + private void orgSupplement(AggBomVO agg) { + 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); + } + + 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)); + } + } + + 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(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()); + } + + 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()); + + if (MMValueCheck.isEmpty(agg.getParent().getAttributeValue("hbdefault"))) { + if ("1.0".equals(result.getVersion())) { + + agg.getParent().setAttributeValue("hbdefault", "true"); + } else { + + agg.getParent().setAttributeValue("hbdefault", "false"); + } + } + + 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()); + + bom.setHnassparentnum(assNum); + bom.setHnparentnum(num); + + 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) { + + 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()); + } + + private BomHeadMtrlParam getQueryParam(AggBomVO agg) { + String pk_org = agg.getParentVO().getAttributeValue("pk_org").toString(); + String hcmaterialid = agg.getParentVO().getAttributeValue("hcmaterialid").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(); + } + + BomHeadMtrlParam param = new BomHeadMtrlParam(); + param.setPk_org(pk_org); + param.setMaterialid(hcmaterialid); + 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 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; + } + + private void itemSupplement(AggBomVO agg) { + 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")); + + fitemtypeEvent(item); + + bprojectmaterialEvent(item); + + bcustommaterial(item); + + fbackflushtypeEvent(item); + + ndisspationumEvent(item, pk_org); + + 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); + } + } + + 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); + } + } + } + + handleEvent(items); + } + + 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) { + 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; + } + + 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 + "行存在未填的必输项", "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 + "行存在未填的必输项", "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")); + } + } +}