From 0890860fd43b5e81d0616d4d1cec71c42eea5720 Mon Sep 17 00:00:00 2001 From: "zhangxinah@yonyou.com" Date: Sat, 12 Apr 2025 12:26:39 +0800 Subject: [PATCH] =?UTF-8?q?2312=E6=B5=81=E7=A8=8B=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=90=8C=E6=AD=A5=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E9=A1=B9-=E5=BC=A0=E9=91=AB0412?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bs/mmpac/pickm/bp/PickmInsertForMoBP.java | 114 ++ .../pac0002/bp/rule/putBeforeCheckRule.java | 147 +- .../pac0002/bp/rule/saveBeforeCheckRule.java | 170 +- .../private/nc/bs/mmpac/wr/bp/WrInsertBP.java | 237 +-- .../rule/WrSetDefaultValueWhenInsertRule.java | 70 + .../wr/rule/serialno/PickMFinishRule.java | 145 +- .../private/nc/bs/pub/action/N_55A2_SAVE.java | 32 + .../nc/rule/mmpps/plo/PloProdDeptRule.java | 30 +- .../maintain/rule/save/FillOrderVosRule.java | 1775 +++++++++++++++++ 9 files changed, 2348 insertions(+), 372 deletions(-) create mode 100644 mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmInsertForMoBP.java create mode 100644 mmpac/src/private/nc/bs/mmpac/wr/rule/WrSetDefaultValueWhenInsertRule.java create mode 100644 mmpac/src/private/nc/bs/pub/action/N_55A2_SAVE.java create mode 100644 pu/src/private/nc/bs/pu/m21/maintain/rule/save/FillOrderVosRule.java diff --git a/mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmInsertForMoBP.java b/mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmInsertForMoBP.java new file mode 100644 index 0000000..2fe6239 --- /dev/null +++ b/mmpac/src/private/nc/bs/mmpac/pickm/bp/PickmInsertForMoBP.java @@ -0,0 +1,114 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package nc.bs.mmpac.pickm.bp; + +import nc.bs.mmpac.pickm.bp.rule.PickmFillInfoFormMORule; +import nc.bs.mmpac.pickm.plugin.PickmPluginPoint; +import nc.bs.mmpac.pickm.rule.PickmCheckItemMaterialPermissionRule; +import nc.bs.mmpac.pickm.rule.PickmCheckMaterialPermissionRule; +import nc.bs.mmpac.pickm.rule.PickmCheckSameStockRule; +import nc.bs.mmpac.pickm.rule.PickmCreateSubItemRule; +import nc.bs.mmpac.pickm.rule.PickmCreateSubMoForInsertRule; +import nc.bs.mmpac.pickm.rule.PickmItemSortByRtForInsertRule; +import nc.bs.mmpac.pickm.rule.PickmMakeDateRule; +import nc.bs.mmpac.pickm.rule.PickmSaveRule; +import nc.bs.mmpac.pickm.rule.SNMaterialNotBackFlushRule; +import nc.bs.mmpac.pickm.rule.ic.PickmATPCheckRule; +import nc.bs.mmpac.pickm.rule.ic.PickmAutoReserveRule; +import nc.bs.mmpac.pickm.rule.ic.PickmSetReplaceSrcAndRowNoAfterInsertRule; +import nc.bs.mmpac.pickm.rule.realsub.PickmRewritePLOWhenInsertRule; +import nc.bs.pubapp.pub.rule.FieldLengthCheckRule; +import nc.bs.pubapp.pub.rule.FillInsertDataRule; +import nc.bs.pubapp.pub.rule.OrgDisabledCheckRule; +import nc.impl.pubapp.bd.userdef.UserDefSaveRule; +import nc.impl.pubapp.pattern.data.bill.template.InsertBPTemplate; +import nc.impl.pubapp.pattern.data.bill.tool.BillTransferTool; +import nc.impl.pubapp.pattern.rule.IRule; +import nc.impl.pubapp.pattern.rule.processer.AroundProcesser; +import nc.util.mmf.busi.rule.MMBillCodeCheckAndTrantypeRule; +import nc.util.mmf.busi.rule.MMCreateBillcodeAndTrantypecodeRule; +import nc.util.mmf.framework.base.MMValueCheck; +import nc.vo.mmpac.pickm.entity.AggPickmVO; +import nc.vo.mmpac.pickm.entity.PickmHeadVO; +import nc.vo.mmpac.pickm.entity.PickmItemVO; + +public class PickmInsertForMoBP { + + public PickmInsertForMoBP() { + } + + public AggPickmVO[] insertForMo(AggPickmVO[] vos) { + if (MMValueCheck.isEmpty(vos)) { + return null; + } else { + BillTransferTool transferTool = new BillTransferTool(vos); + AggPickmVO[] mergedVOs = (AggPickmVO[]) transferTool.getClientFullInfoBill(); + InsertBPTemplate bp = new InsertBPTemplate(PickmPluginPoint.SAVE); + this.addBeforeRule(bp.getAroundProcesser()); + this.addAfterRule(bp.getAroundProcesser()); + AggPickmVO[] retvos = (AggPickmVO[]) bp.insert(mergedVOs); + return retvos; + } + } + + /** + * @deprecated + */ + @Deprecated + protected PickmCreateSubItemRule getPickmCreateSubItemRule(boolean isBg) { + return null; + } + + private void addAfterRule(AroundProcesser processor) { + IRule setReplaceSrcRule = new PickmSetReplaceSrcAndRowNoAfterInsertRule(true); + processor.addAfterRule(setReplaceSrcRule); + IRule billCodeRule = new MMBillCodeCheckAndTrantypeRule("55A3", "vbillcode", "pk_group", "pk_org", + "vbusitype"); + processor.addAfterRule(billCodeRule); + IRule atpCheckRule = new PickmATPCheckRule(false, (AggPickmVO[]) null); + processor.addAfterRule(atpCheckRule); + IRule pickmAutoReserveRule = new PickmAutoReserveRule(); + processor.addAfterRule(pickmAutoReserveRule); + IRule pickmRewritePLOWhenInsertRule = new PickmRewritePLOWhenInsertRule(); + processor.addAfterRule(pickmRewritePLOWhenInsertRule); + IRule pickmCreateSubMoRule = new PickmCreateSubMoForInsertRule(); + processor.addAfterRule(pickmCreateSubMoRule); + } + + private void addBeforeRule(AroundProcesser processor) { + IRule orgRule = new OrgDisabledCheckRule("pk_org", "FACTORYTYPE000000000"); + processor.addBeforeRule(orgRule); + IRule fillDataRule = new FillInsertDataRule(); + processor.addBeforeRule(fillDataRule); + IRule getMakeDateRule = new PickmMakeDateRule(); + processor.addBeforeRule(getMakeDateRule); + IRule billcodeRule = new MMCreateBillcodeAndTrantypecodeRule("55A3", "vbillcode", "pk_group", + "pk_org", "vbusitype"); + processor.addBeforeRule(billcodeRule); + IRule createSubItemRule = new PickmCreateSubItemRule(true); + processor.addBeforeRule(createSubItemRule); + IRule sortItemRule = new PickmItemSortByRtForInsertRule(); + processor.addBeforeRule(sortItemRule); + IRule lengthCheckRule = new FieldLengthCheckRule(); + processor.addBeforeRule(lengthCheckRule); + IRule sameRule = new PickmCheckSameStockRule(); + processor.addBeforeRule(sameRule); + IRule marperRule = new PickmCheckMaterialPermissionRule(); + processor.addBeforeRule(marperRule); + IRule bmarperRule = new PickmCheckItemMaterialPermissionRule(); + processor.addBeforeRule(bmarperRule); + IRule pickmSaveRule = new PickmSaveRule(); + processor.addBeforeRule(pickmSaveRule); + IRule snMaterialCheckRule = new SNMaterialNotBackFlushRule(); + processor.addBeforeRule(snMaterialCheckRule); + IRule atpCheckRule = new PickmATPCheckRule(true, (AggPickmVO[]) null); + processor.addBeforeRule(atpCheckRule); + IRule userDefSaveRule = new UserDefSaveRule(new String[]{"vdef", "vbdef"}, + new Class[]{PickmHeadVO.class, PickmItemVO.class}); + processor.addBeforeRule(userDefSaveRule); + processor.addBeforeRule(new PickmFillInfoFormMORule()); + } +} diff --git a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/putBeforeCheckRule.java b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/putBeforeCheckRule.java index b24b5da..f027fd0 100644 --- a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/putBeforeCheckRule.java +++ b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/putBeforeCheckRule.java @@ -26,86 +26,83 @@ import nc.vo.so.m30.entity.SaleOrderBVO; import nc.bs.mmpac.pmo.pac0002.bp.PMORowPutBP; import nccloud.web.mmpac.pmo.action.PmoCardPutAction; - public class putBeforeCheckRule implements IRule { - private static IUifService service = (IUifService) NCLocator.getInstance() - .lookup(IUifService.class.getName()); + private static IUifService service = (IUifService) NCLocator.getInstance().lookup(IUifService.class.getName()); - @Override - public void process(PMOAggVO[] vos) { - try { - // TODO Auto-generated method stub - List list = new ArrayList(); - for (PMOAggVO vo : vos) { - //判断是否是需要控制的业务单元 - PMOHeadVO pmoHeadVO = vo.getParentVO(); - String pkstockorgStr = getPk_stockorg(pmoHeadVO.getPk_org()); - if (pkstockorgStr == null || pkstockorgStr.equals("")) { - return; - } - PMOItemVO[] iSuperVOs = vo.getChildrenVO(); - for (int i = 0; i < iSuperVOs.length; i++) { - PMOItemVO itemvo = iSuperVOs[i]; - //判断是否类型是否为30 - if (itemvo.getVsrctype() == null || !itemvo.getVsrctype().equals("30")) { - return; - } - Map valMap = getVbdef6(itemvo.getVsrcbid()); - //销售发票表头pk_billtypecode=30-Cxx-12 - if (valMap.get("pk_billtypecode").equals("30-Cxx-12")||valMap.get("pk_billtypecode").equals("30-Cxx-02")||valMap.get("pk_billtypecode").equals("30-Cxx-08")||valMap.get("pk_billtypecode").equals("30-Cxx-13")) { - return; - } - //历史数据不考虑 - String storedDateStr = (String) valMap.get("creationtime"); - String targetDateStr = "2024-12-31 00:00:00"; - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime storedDate = LocalDateTime.parse(storedDateStr, formatter); - LocalDateTime targetDate = LocalDateTime.parse(targetDateStr, formatter); - if (storedDate.isBefore(targetDate)) { - return; - } - String vdef4Str = itemvo.getVdef4();//齐套率 - String vdef4 = (vdef4Str != null) ? vdef4Str.toString() : ""; - double vdef4qty = (vdef4.isEmpty()) ? 0 : Double.parseDouble(vdef4);//齐套率 - String vdef10Str = itemvo.getVdef10();//齐套率标准 - String vdef10 = (vdef10Str != null) ? vdef10Str.toString() : ""; - double vdef10qty = (vdef10.isEmpty()) ? 0 : Double.parseDouble(vdef10);//齐套率标准 - if (vdef4qty < vdef10qty) { - throw new BusinessException( - "齐套率" + vdef4qty + "小于齐套率标准'" + vdef10qty + "',无法保存!"); - } + @Override + public void process(PMOAggVO[] vos) { + try { + // TODO Auto-generated method stub + List list = new ArrayList(); + for (PMOAggVO vo : vos) { + // 判断是否是需要控制的业务单元 + PMOHeadVO pmoHeadVO = vo.getParentVO(); + String pkstockorgStr = getPk_stockorg(pmoHeadVO.getPk_org()); + if (pkstockorgStr == null || pkstockorgStr.equals("")) { + return; + } + PMOItemVO[] iSuperVOs = vo.getChildrenVO(); + for (int i = 0; i < iSuperVOs.length; i++) { + PMOItemVO itemvo = iSuperVOs[i]; + // 判断是否类型是否为30 + if (itemvo.getVsrctype() == null || !itemvo.getVsrctype().equals("30")) { + return; + } + Map valMap = getVbdef6(itemvo.getVsrcbid()); + // 销售发票表头pk_billtypecode=30-Cxx-12 + if (valMap.get("pk_billtypecode").equals("30-Cxx-12") + || valMap.get("pk_billtypecode").equals("30-Cxx-02") + || valMap.get("pk_billtypecode").equals("30-Cxx-08") + || valMap.get("pk_billtypecode").equals("30-Cxx-13")) { + return; + } + // 历史数据不考虑 + String storedDateStr = (String) valMap.get("creationtime"); + String targetDateStr = "2024-12-31 00:00:00"; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime storedDate = LocalDateTime.parse(storedDateStr, formatter); + LocalDateTime targetDate = LocalDateTime.parse(targetDateStr, formatter); + if (storedDate.isBefore(targetDate)) { + return; + } + String vdef4Str = itemvo.getVdef4();// 齐套率 + String vdef4 = (vdef4Str != null) ? vdef4Str.toString() : ""; + double vdef4qty = (vdef4.isEmpty()) ? 0 : Double.parseDouble(vdef4);// 齐套率 + String vdef10Str = itemvo.getVdef10();// 齐套率标准 + String vdef10 = (vdef10Str != null) ? vdef10Str.toString() : ""; + double vdef10qty = (vdef10.isEmpty()) ? 0 : Double.parseDouble(vdef10);// 齐套率标准 + if (vdef4qty < vdef10qty) { + throw new BusinessException("齐套率" + vdef4qty + "小于齐套率标准'" + vdef10qty + "',无法保存!"); + } - } - } - } catch (BusinessException e) { - throw new RuntimeException(e); - } - } + } + } + } catch (BusinessException e) { + throw new RuntimeException(e); + } + } - private Map getVbdef6(String vsrcbidStr) throws BusinessException { - IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); - String sql = " SELECT bt.pk_billtypecode,s.creationtime,b.vbdef12,d.nastnum FROM so_saleorder_b b\n" - + "INNER JOIN so_saleorder s ON s.csaleorderid = b.csaleorderid\n" - + "left join (select mm_mo.Vsrcbid,sum(nastnum) as nastnum \n" - + "from mm_mo\n" - + "where mm_mo.dr=0\n" - + "group by mm_mo.Vsrcbid) d on b.csaleorderbid=d.Vsrcbid\n" - + "INNER JOIN bd_billtype bt on bt.pk_billtypeid=s.ctrantypeid\n" - + "where b.csaleorderbid='" + vsrcbidStr + "' "; - Map valList = (Map) queryBS.executeQuery(sql, new MapProcessor()); - return valList; - } + private Map getVbdef6(String vsrcbidStr) throws BusinessException { + IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); + String sql = " SELECT bt.pk_billtypecode,s.creationtime,b.vbdef12,d.nastnum FROM so_saleorder_b b\n" + + "INNER JOIN so_saleorder s ON s.csaleorderid = b.csaleorderid\n" + + "left join (select mm_mo.Vsrcbid,sum(nastnum) as nastnum \n" + "from mm_mo\n" + "where mm_mo.dr=0\n" + + "group by mm_mo.Vsrcbid) d on b.csaleorderbid=d.Vsrcbid\n" + + "INNER JOIN bd_billtype bt on bt.pk_billtypeid=s.ctrantypeid\n" + "where b.csaleorderbid='" + + vsrcbidStr + "' "; + Map valList = (Map) queryBS.executeQuery(sql, new MapProcessor()); + return valList; + } - private String getPk_stockorg(String pk_stockorg) throws BusinessException { - String sql = - " select pk_stockorg from org_stockorg where code in ('C018','C029','C033','C039','C020','C019') and pk_stockorg='" - + pk_stockorg + "' "; - String saleorderPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); - return saleorderPK; - } + private String getPk_stockorg(String pk_stockorg) throws BusinessException { + String sql = " select pk_stockorg from org_stockorg where code in ('C018','C029','C033','C039','C020','C019') and pk_stockorg='" + + pk_stockorg + "' "; + String saleorderPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); + return saleorderPK; + } - public IUAPQueryBS getQueryService() { - return NCLocator.getInstance().lookup(IUAPQueryBS.class); - } + public IUAPQueryBS getQueryService() { + return NCLocator.getInstance().lookup(IUAPQueryBS.class); + } } diff --git a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/saveBeforeCheckRule.java b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/saveBeforeCheckRule.java index dad157c..adfcfcb 100644 --- a/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/saveBeforeCheckRule.java +++ b/mmpac/src/private/nc/bs/mmpac/pmo/pac0002/bp/rule/saveBeforeCheckRule.java @@ -17,99 +17,95 @@ import nc.vo.pub.BusinessException; import nc.vo.so.m30.entity.SaleOrderBVO; /** - * 流程生成订单保存时验证销售订单累计排产状态,并验收首付款比例 - * zhangxinah 适配2312 + * 流程生成订单保存时验证销售订单累计排产状态,并验收首付款比例 zhangxinah 适配2312 */ public class saveBeforeCheckRule implements IRule { - @Override - public void process(PMOAggVO[] vos) { - // TODO Auto-generated method stub - try { - List list = new ArrayList(); - for (PMOAggVO vo : vos) { - //判断是否是需要控制的业务单元 - PMOHeadVO pmoHeadVO = vo.getParentVO(); - String pkstockorgStr = getPk_stockorg(pmoHeadVO.getPk_org()); - if (pkstockorgStr == null || pkstockorgStr.equals("")) { - return; - } - PMOItemVO[] iSuperVOs = vo.getChildrenVO(); - for (int i = 0; i < iSuperVOs.length; i++) { - PMOItemVO itemvo = iSuperVOs[i]; - //判断是否类型是否为30 - if (itemvo.getVsrctype() == null || !itemvo.getVsrctype().equals("30")) { - return; - } + @Override + public void process(PMOAggVO[] vos) { + // TODO Auto-generated method stub + try { + List list = new ArrayList(); + for (PMOAggVO vo : vos) { + // 判断是否是需要控制的业务单元 + PMOHeadVO pmoHeadVO = vo.getParentVO(); + String pkstockorgStr = getPk_stockorg(pmoHeadVO.getPk_org()); + if (pkstockorgStr == null || pkstockorgStr.equals("")) { + return; + } + PMOItemVO[] iSuperVOs = vo.getChildrenVO(); + for (int i = 0; i < iSuperVOs.length; i++) { + PMOItemVO itemvo = iSuperVOs[i]; + // 判断是否类型是否为30 + if (itemvo.getVsrctype() == null || !itemvo.getVsrctype().equals("30")) { + return; + } - Map valMap = getVbdef6(itemvo.getVsrcbid()); - if (valMap == null || valMap.isEmpty()) { - throw new BusinessException("无法关联到销售订单,无法保存!"); - } - //销售发票表头pk_billtypecode=30-Cxx-12 - if (valMap.get("pk_billtypecode").equals("30-Cxx-12")||valMap.get("pk_billtypecode").equals("30-Cxx-02")||valMap.get("pk_billtypecode").equals("30-Cxx-08")||valMap.get("pk_billtypecode").equals("30-Cxx-13")) { - return; - } - //历史数据不考虑 - String storedDateStr = (String) valMap.get("creationtime"); - String targetDateStr = "2024-12-27 00:00:00"; - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime storedDate = LocalDateTime.parse(storedDateStr, formatter); - LocalDateTime targetDate = LocalDateTime.parse(targetDateStr, formatter); - if (storedDate.isBefore(targetDate)) { - return; - } - if (valMap.get("vbdef12") == null) { - throw new BusinessException( - "生产订单明细" + (i + 1) + ",累计排产申请数量为0,无法保存!"); - } else { - try { - double sQty = Double.parseDouble((String) valMap.get("vbdef12"));//累计排产申请数量 - Object ntotaloutnumsObj = valMap.get("nastnum"); - String ntotaloutnums = (ntotaloutnumsObj != null) ? ntotaloutnumsObj.toString() : ""; - double ntotaloutnum = - (ntotaloutnums.isEmpty()) ? 0 : Double.parseDouble(ntotaloutnums);//累计生产数量 - double bdnum = itemvo.getNastnum().getDouble(); - if (sQty < (ntotaloutnum + bdnum)) { - throw new BusinessException( - "生产订单明细" + (i + 1) + ",累计生产数量'" + (ntotaloutnum + bdnum) - + "'大于销售订单累计排产申请数量'" + sQty + "',无法保存!"); - } - } catch (NumberFormatException e) { - throw new BusinessException("累计排产申请数量转化数值失败" + e); - } - } - } - } - } catch (BusinessException e) { - throw new RuntimeException(e); - } - } + Map valMap = getVbdef6(itemvo.getVsrcbid()); + if (valMap == null || valMap.isEmpty()) { + throw new BusinessException("无法关联到销售订单,无法保存!"); + } + // 销售发票表头pk_billtypecode=30-Cxx-12 + if (valMap.get("pk_billtypecode").equals("30-Cxx-12") + || valMap.get("pk_billtypecode").equals("30-Cxx-02") + || valMap.get("pk_billtypecode").equals("30-Cxx-08") + || valMap.get("pk_billtypecode").equals("30-Cxx-13")) { + return; + } + // 历史数据不考虑 + String storedDateStr = (String) valMap.get("creationtime"); + String targetDateStr = "2024-12-27 00:00:00"; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime storedDate = LocalDateTime.parse(storedDateStr, formatter); + LocalDateTime targetDate = LocalDateTime.parse(targetDateStr, formatter); + if (storedDate.isBefore(targetDate)) { + return; + } + if (valMap.get("vbdef12") == null) { + throw new BusinessException("生产订单明细" + (i + 1) + ",累计排产申请数量为0,无法保存!"); + } else { + try { + double sQty = Double.parseDouble((String) valMap.get("vbdef12"));// 累计排产申请数量 + Object ntotaloutnumsObj = valMap.get("nastnum"); + String ntotaloutnums = (ntotaloutnumsObj != null) ? ntotaloutnumsObj.toString() : ""; + double ntotaloutnum = (ntotaloutnums.isEmpty()) ? 0 : Double.parseDouble(ntotaloutnums);// 累计生产数量 + double bdnum = itemvo.getNastnum().getDouble(); + if (sQty < (ntotaloutnum + bdnum)) { + throw new BusinessException("生产订单明细" + (i + 1) + ",累计生产数量'" + (ntotaloutnum + bdnum) + + "'大于销售订单累计排产申请数量'" + sQty + "',无法保存!"); + } + } catch (NumberFormatException e) { + throw new BusinessException("累计排产申请数量转化数值失败" + e); + } + } + } + } + } catch (BusinessException e) { + throw new RuntimeException(e); + } + } - private Map getVbdef6(String vsrcbidStr) throws BusinessException { - IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); - String sql = " SELECT bt.pk_billtypecode,s.creationtime,b.vbdef12,d.nastnum FROM so_saleorder_b b\n" - + "INNER JOIN so_saleorder s ON s.csaleorderid = b.csaleorderid\n" - + "left join (select mm_mo.Vsrcbid,sum(nastnum) as nastnum \n" - + "from mm_mo\n" - + "where mm_mo.dr=0\n" - + "group by mm_mo.Vsrcbid) d on b.csaleorderbid=d.Vsrcbid\n" - + "INNER JOIN bd_billtype bt on bt.pk_billtypeid=s.ctrantypeid\n" - + "where b.csaleorderbid='" + vsrcbidStr + "' "; - Map valList = (Map) queryBS.executeQuery(sql, new MapProcessor()); - return valList; - } + private Map getVbdef6(String vsrcbidStr) throws BusinessException { + IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); + String sql = " SELECT bt.pk_billtypecode,s.creationtime,b.vbdef12,d.nastnum FROM so_saleorder_b b\n" + + "INNER JOIN so_saleorder s ON s.csaleorderid = b.csaleorderid\n" + + "left join (select mm_mo.Vsrcbid,sum(nastnum) as nastnum \n" + "from mm_mo\n" + "where mm_mo.dr=0\n" + + "group by mm_mo.Vsrcbid) d on b.csaleorderbid=d.Vsrcbid\n" + + "INNER JOIN bd_billtype bt on bt.pk_billtypeid=s.ctrantypeid\n" + "where b.csaleorderbid='" + + vsrcbidStr + "' "; + Map valList = (Map) queryBS.executeQuery(sql, new MapProcessor()); + return valList; + } - private String getPk_stockorg(String pk_stockorg) throws BusinessException { - String sql = - " select pk_stockorg from org_stockorg where code in ('C018','C029','C033','C039','C020','C019') and pk_stockorg='" - + pk_stockorg + "' "; - String saleorderPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); - return saleorderPK; - } + private String getPk_stockorg(String pk_stockorg) throws BusinessException { + String sql = " select pk_stockorg from org_stockorg where code in ('C018','C029','C033','C039','C020','C019') and pk_stockorg='" + + pk_stockorg + "' "; + String saleorderPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); + return saleorderPK; + } - public IUAPQueryBS getQueryService() { - return NCLocator.getInstance().lookup(IUAPQueryBS.class); - } + public IUAPQueryBS getQueryService() { + return NCLocator.getInstance().lookup(IUAPQueryBS.class); + } } diff --git a/mmpac/src/private/nc/bs/mmpac/wr/bp/WrInsertBP.java b/mmpac/src/private/nc/bs/mmpac/wr/bp/WrInsertBP.java index 7d9f219..75ca188 100644 --- a/mmpac/src/private/nc/bs/mmpac/wr/bp/WrInsertBP.java +++ b/mmpac/src/private/nc/bs/mmpac/wr/bp/WrInsertBP.java @@ -36,131 +36,136 @@ import java.util.HashMap; import java.util.Map; public class WrInsertBP { - private boolean isOnlyInsert = false; + private boolean isOnlyInsert = false; - public WrInsertBP() { - } + public WrInsertBP() { + } - public AggWrVO[] insert(AggWrVO[] vos) { - GCInsertBPTemplate bp = new GCInsertBPTemplate(WrPluginPoint.INSERT); - AroundProcesser processor = bp.getAroundProcesser(); - Map vbatchsMap = new HashMap(); - this.addBeforeRule(processor, vos, vbatchsMap); - this.addAfterRule(processor, vbatchsMap); - return (AggWrVO[])bp.insert(vos); - } + public AggWrVO[] insert(AggWrVO[] vos) { + GCInsertBPTemplate bp = new GCInsertBPTemplate(WrPluginPoint.INSERT); + AroundProcesser processor = bp.getAroundProcesser(); + Map vbatchsMap = new HashMap(); + this.addBeforeRule(processor, vos, vbatchsMap); + this.addAfterRule(processor, vbatchsMap); + return (AggWrVO[]) bp.insert(vos); + } - private void addBeforeRule(AroundProcesser processer, AggWrVO[] vos, Map vbatchsMap) { - IRule wrNullRule = new WrNullRule(); - processer.addBeforeRule(wrNullRule); - IRule mmatoMaterialCheckRule = new MMATOMaterialCheckRule((String)null, "cbmaterialvid", "cbffileid"); - processer.addBeforeRule(mmatoMaterialCheckRule); - IRule orgRule = new OrgDisabledCheckRule("pk_org", "FACTORYTYPE000000000"); - processer.addBeforeRule(orgRule); - IRule checkDefRule = new UserDefSaveRule(new String[]{"vdef", "vbdef", "vgdef", "vpdef"}, new Class[]{WrVO.class, WrItemVO.class, WrQualityVO.class, WrPickVO.class}); - processer.addBeforeRule(checkDefRule); - MarAssistantSaveRule marRule = new MarAssistantSaveRule(); - processer.addBeforeRule(marRule); - IRule fillInsertDataRule = new WrFillInsertDataRule(); - processer.addBeforeRule(fillInsertDataRule); - IRule autoMaterialAssignRule = new MMAutoMaterialAssignRule((String)null, "cbmaterialvid", new String[]{"pk_org"}, (String[])null); - processer.addBeforeFinalRule(autoMaterialAssignRule); - IRule orgPermissionRule = new WrCheckMaterialPermissionRule(); - processer.addBeforeRule(orgPermissionRule); - IRule moCloseRule = new WrCheckMoIsCloseRule(); - processer.addBeforeRule(moCloseRule); - processer.addBeforeRule(new MMCheckMaterialVirtualRule(WrItemVO.class)); - IRule wrSetDefaultValueWhenInsertRule = new WrSetDefaultValueWhenInsertRule(); - processer.addBeforeRule(wrSetDefaultValueWhenInsertRule); - IRule wrSetItemDefaultValueRule = new WrSetItemDefaultValueRule(); - processer.addBeforeRule(wrSetItemDefaultValueRule); - IRule billcodeRule = new MMCreateBillcodeAndTrantypecodeRule("55A4", "vbillcode", "pk_group", "pk_org", "vtrantypecode"); - processer.addBeforeRule(billcodeRule); - IRule wrHeadNotNullRule = new WrHeadNotNullRule(); - processer.addBeforeRule(wrHeadNotNullRule); - IRule wrBatchCodeRule = new WrCreateBatchCodeRule(); - processer.addBeforeRule(wrBatchCodeRule); - IRule wrClearNullProductBodyRule = new WrClearNullBodyRule(); - processer.addBeforeRule(wrClearNullProductBodyRule); - processer.addBeforeRule(new WrRowNoRule()); - IRule wrQualityFilterRule = new WrQualityFilterRule(); - processer.addBeforeRule(wrQualityFilterRule); - IRule wrPickFilterRule = new WrPickFilterRule(); - processer.addBeforeRule(wrPickFilterRule); - IRule wrOutputNotNullRule = new WrOutputNotNullRule(); - processer.addBeforeRule(wrOutputNotNullRule); - IRule wrNoneMainProductBomCheckRule = new WrNoneMainProductBomCheckRule(); - processer.addBeforeRule(wrNoneMainProductBomCheckRule); - IRule wrConsumeNotNullRule = new WrPickNotNullRule(); - processer.addBeforeRule(wrConsumeNotNullRule); - IRule lengthCheckRule = new FieldLengthCheckRule(); - processer.addBeforeRule(lengthCheckRule); - IRule wrInsertAndDelInStockBatchCodeBeforeRule = new WrInsertAndDelInStockBatchCodeBeforeRule(vbatchsMap); - processer.addBeforeRule(wrInsertAndDelInStockBatchCodeBeforeRule); - WrSetQualityVODefaultValueRule wrSetQualityVODefaultValueRule = new WrSetQualityVODefaultValueRule(); - processer.addBeforeRule(wrSetQualityVODefaultValueRule); - processer.addBeforeRule(new WrSerialNoCheckCodeRepeat()); - WrSerialNoAutoCreateBeforeRule wrAutoCreateSnBeforeRule = new WrSerialNoAutoCreateBeforeRule(); - processer.addBeforeRule(wrAutoCreateSnBeforeRule); - WrSerialNoCheckRule wrSnCheckRule = new WrSerialNoCheckRule(); - processer.addBeforeRule(wrSnCheckRule); - WrSnSynToQualtiyRule synToQRule = new WrSnSynToQualtiyRule(); - processer.addBeforeRule(synToQRule); - WrMoSerialNoMarkIRule mosnMarkRule = new WrMoSerialNoMarkIRule(); - processer.addBeforeRule(mosnMarkRule); - IRule wrCreateBatProdRule = new WrCreateBatProdRule(); - processer.addBeforeRule(wrCreateBatProdRule); - processer.addBeforeRule(new WrCheckTranstypeCodeRule()); - } + private void addBeforeRule(AroundProcesser processer, AggWrVO[] vos, Map vbatchsMap) { + IRule wrNullRule = new WrNullRule(); + processer.addBeforeRule(wrNullRule); + IRule mmatoMaterialCheckRule = new MMATOMaterialCheckRule((String) null, "cbmaterialvid", "cbffileid"); + processer.addBeforeRule(mmatoMaterialCheckRule); + IRule orgRule = new OrgDisabledCheckRule("pk_org", "FACTORYTYPE000000000"); + processer.addBeforeRule(orgRule); + IRule checkDefRule = new UserDefSaveRule(new String[] { "vdef", "vbdef", "vgdef", "vpdef" }, + new Class[] { WrVO.class, WrItemVO.class, WrQualityVO.class, WrPickVO.class }); + processer.addBeforeRule(checkDefRule); + MarAssistantSaveRule marRule = new MarAssistantSaveRule(); + processer.addBeforeRule(marRule); + IRule fillInsertDataRule = new WrFillInsertDataRule(); + processer.addBeforeRule(fillInsertDataRule); + IRule autoMaterialAssignRule = new MMAutoMaterialAssignRule((String) null, "cbmaterialvid", + new String[] { "pk_org" }, (String[]) null); + processer.addBeforeFinalRule(autoMaterialAssignRule); + IRule orgPermissionRule = new WrCheckMaterialPermissionRule(); + processer.addBeforeRule(orgPermissionRule); + IRule moCloseRule = new WrCheckMoIsCloseRule(); + processer.addBeforeRule(moCloseRule); + processer.addBeforeRule(new MMCheckMaterialVirtualRule(WrItemVO.class)); + IRule wrSetDefaultValueWhenInsertRule = new WrSetDefaultValueWhenInsertRule(); + processer.addBeforeRule(wrSetDefaultValueWhenInsertRule); + IRule wrSetItemDefaultValueRule = new WrSetItemDefaultValueRule(); + processer.addBeforeRule(wrSetItemDefaultValueRule); + IRule billcodeRule = new MMCreateBillcodeAndTrantypecodeRule("55A4", "vbillcode", "pk_group", "pk_org", + "vtrantypecode"); + processer.addBeforeRule(billcodeRule); + IRule wrHeadNotNullRule = new WrHeadNotNullRule(); + processer.addBeforeRule(wrHeadNotNullRule); + IRule wrBatchCodeRule = new WrCreateBatchCodeRule(); + processer.addBeforeRule(wrBatchCodeRule); + IRule wrClearNullProductBodyRule = new WrClearNullBodyRule(); + processer.addBeforeRule(wrClearNullProductBodyRule); + processer.addBeforeRule(new WrRowNoRule()); + IRule wrQualityFilterRule = new WrQualityFilterRule(); + processer.addBeforeRule(wrQualityFilterRule); + IRule wrPickFilterRule = new WrPickFilterRule(); + processer.addBeforeRule(wrPickFilterRule); + IRule wrOutputNotNullRule = new WrOutputNotNullRule(); + processer.addBeforeRule(wrOutputNotNullRule); + IRule wrNoneMainProductBomCheckRule = new WrNoneMainProductBomCheckRule(); + processer.addBeforeRule(wrNoneMainProductBomCheckRule); + IRule wrConsumeNotNullRule = new WrPickNotNullRule(); + processer.addBeforeRule(wrConsumeNotNullRule); + IRule lengthCheckRule = new FieldLengthCheckRule(); + processer.addBeforeRule(lengthCheckRule); + IRule wrInsertAndDelInStockBatchCodeBeforeRule = new WrInsertAndDelInStockBatchCodeBeforeRule( + vbatchsMap); + processer.addBeforeRule(wrInsertAndDelInStockBatchCodeBeforeRule); + WrSetQualityVODefaultValueRule wrSetQualityVODefaultValueRule = new WrSetQualityVODefaultValueRule(); + processer.addBeforeRule(wrSetQualityVODefaultValueRule); + processer.addBeforeRule(new WrSerialNoCheckCodeRepeat()); + WrSerialNoAutoCreateBeforeRule wrAutoCreateSnBeforeRule = new WrSerialNoAutoCreateBeforeRule(); + processer.addBeforeRule(wrAutoCreateSnBeforeRule); + WrSerialNoCheckRule wrSnCheckRule = new WrSerialNoCheckRule(); + processer.addBeforeRule(wrSnCheckRule); + WrSnSynToQualtiyRule synToQRule = new WrSnSynToQualtiyRule(); + processer.addBeforeRule(synToQRule); + WrMoSerialNoMarkIRule mosnMarkRule = new WrMoSerialNoMarkIRule(); + processer.addBeforeRule(mosnMarkRule); + IRule wrCreateBatProdRule = new WrCreateBatProdRule(); + processer.addBeforeRule(wrCreateBatProdRule); + processer.addBeforeRule(new WrCheckTranstypeCodeRule()); + } - private void addAfterRule(AroundProcesser processor, Map vbatchsMap) { - IRule rule = new MMBillCodeCheckAndTrantypeRule("55A4", "vbillcode", "pk_group", "pk_org", "vtrantypecode"); - processor.addAfterRule(rule); - IRule wrCreateInStockBatchCodeAfterRule = new WrInsertInStockBatchCodeAfterRule(vbatchsMap); - processor.addAfterRule(wrCreateInStockBatchCodeAfterRule); - processor.addAfterRule(new WrInsertRewriteWrNumForPutPlanRule()); - IRule wrMORewriteRule = new WrMORewriteRule(2); - processor.addAfterRule(wrMORewriteRule); - IRule moDiscadNumRewriteRule = new MoDiscadNumRewriteRule(2); - processor.addAfterRule(moDiscadNumRewriteRule); - IRule snSaveRule = new WrSerialNoSaveRule(); - processor.addAfterRule(snSaveRule); - /** 同步修改备料计划完成 */ - IRule pickMFinishRule = new PickMFinishRule(); - processor.addAfterRule(pickMFinishRule); - /** ******************** */ + private void addAfterRule(AroundProcesser processor, Map vbatchsMap) { + IRule rule = new MMBillCodeCheckAndTrantypeRule("55A4", "vbillcode", "pk_group", "pk_org", + "vtrantypecode"); + processor.addAfterRule(rule); + IRule wrCreateInStockBatchCodeAfterRule = new WrInsertInStockBatchCodeAfterRule(vbatchsMap); + processor.addAfterRule(wrCreateInStockBatchCodeAfterRule); + processor.addAfterRule(new WrInsertRewriteWrNumForPutPlanRule()); + IRule wrMORewriteRule = new WrMORewriteRule(2); + processor.addAfterRule(wrMORewriteRule); + IRule moDiscadNumRewriteRule = new MoDiscadNumRewriteRule(2); + processor.addAfterRule(moDiscadNumRewriteRule); + IRule snSaveRule = new WrSerialNoSaveRule(); + processor.addAfterRule(snSaveRule); + /** 同步修改备料计划完成 */ + IRule pickMFinishRule = new PickMFinishRule(); + processor.addAfterRule(pickMFinishRule); + /** ******************** */ - if (!this.isOnlyInsert) { - processor.addAfterRule(new WrIsSaveAndApproveRule()); - } + if (!this.isOnlyInsert) { + processor.addAfterRule(new WrIsSaveAndApproveRule()); + } - processor.addAfterRule(new WrAuditAndApplyCheckRule()); - processor.addAfterRule(new WrAuditAndProdInRule()); - } + processor.addAfterRule(new WrAuditAndApplyCheckRule()); + processor.addAfterRule(new WrAuditAndProdInRule()); + } - /** @deprecated */ - @Deprecated - protected IRule getMoRewriteRule() { - return null; - } + /** @deprecated */ + @Deprecated + protected IRule getMoRewriteRule() { + return null; + } - /** @deprecated */ - @Deprecated - protected IRule getMoDiscadNumRewriteRule() { - return null; - } + /** @deprecated */ + @Deprecated + protected IRule getMoDiscadNumRewriteRule() { + return null; + } - /** @deprecated */ - @Deprecated - protected IRule getAuditRule() { - return null; - } + /** @deprecated */ + @Deprecated + protected IRule getAuditRule() { + return null; + } - public boolean isOnlyInsert() { - return this.isOnlyInsert; - } + public boolean isOnlyInsert() { + return this.isOnlyInsert; + } - public void setOnlyInsert(boolean isOnlyInsert) { - this.isOnlyInsert = isOnlyInsert; - } + public void setOnlyInsert(boolean isOnlyInsert) { + this.isOnlyInsert = isOnlyInsert; + } } diff --git a/mmpac/src/private/nc/bs/mmpac/wr/rule/WrSetDefaultValueWhenInsertRule.java b/mmpac/src/private/nc/bs/mmpac/wr/rule/WrSetDefaultValueWhenInsertRule.java new file mode 100644 index 0000000..26398ed --- /dev/null +++ b/mmpac/src/private/nc/bs/mmpac/wr/rule/WrSetDefaultValueWhenInsertRule.java @@ -0,0 +1,70 @@ +package nc.bs.mmpac.wr.rule; + +import nc.impl.pubapp.pattern.rule.IRule; +import nc.util.mmf.framework.base.MMArrayUtil; +import nc.util.mmf.framework.base.MMValueCheck; +import nc.util.mmpac.wr.WrCheckRuleUtil; +import nc.vo.mmpac.wr.entity.AggWrVO; +import nc.vo.mmpac.wr.entity.WrItemVO; +import nc.vo.mmpac.wr.entity.WrVO; +import nc.vo.mmpac.wr.enumeration.WrProdModeEnum; +import nc.vo.pub.VOStatus; +import nc.vo.pubapp.AppContext; + +/** + * 生产报告新增时,设置默认值规则 + * + * @since 6.1 + * @author zhoudi + */ +public class WrSetDefaultValueWhenInsertRule implements IRule { + + @Override + public void process(AggWrVO[] vos) { + + if (MMValueCheck.isEmpty(vos)) { + return; + } + + WrVO headVO; + + for (AggWrVO aggVO : vos) { + + headVO = (WrVO) aggVO.getParent(); + + if (MMValueCheck.isEmpty(headVO)) { + continue; + } + + // 新增状态 + headVO.setStatus(VOStatus.NEW); + + // 制单人、制单时间 + headVO.setBillmaker(AppContext.getInstance().getPkUser()); + if (headVO.getDmakedate() == null) { + headVO.setDmakedate(AppContext.getInstance().getBusiDate()); + } + + if (!WrProdModeEnum.FLOW.equalsValue(vos[0].getParentVO().getFprodmode())) { + continue; + } + WrItemVO[] wrItemVOs = (WrItemVO[]) aggVO.getChildren(WrItemVO.class); + if (MMArrayUtil.isEmpty(wrItemVOs)) { + continue; + } + // 生产部门等,表体字段均相等,则同步表体字段到表头 + for (String[] headitemKey : this.headKeyToitemKey) { + if (WrCheckRuleUtil.isItemKeyValueAllSame(wrItemVOs, headitemKey[1])) { + headVO.setAttributeValue(headitemKey[0], wrItemVOs[0].getAttributeValue(headitemKey[1])); + } + } + if (MMValueCheck.isEmpty(headVO.getCdeptvid()) && MMValueCheck.isNotEmpty(headVO.getCdeptid())) { + headVO.setCdeptid(null); + } + } + } + + private String[][] headKeyToitemKey = { { WrVO.CDEPTID, WrItemVO.CBDEPTID }, { WrVO.CDEPTVID, WrItemVO.CBDEPTVID }, + { WrVO.CWKID, WrItemVO.CBWKID }, { WrVO.CTEAMID, WrItemVO.CBTEAMID }, { WrVO.CSHIFTID, WrItemVO.CBSHIFTID }, + { WrVO.CWORKMANID, WrItemVO.CBWORKMANID } }; +} diff --git a/mmpac/src/private/nc/bs/mmpac/wr/rule/serialno/PickMFinishRule.java b/mmpac/src/private/nc/bs/mmpac/wr/rule/serialno/PickMFinishRule.java index ef2ac92..7a295c8 100644 --- a/mmpac/src/private/nc/bs/mmpac/wr/rule/serialno/PickMFinishRule.java +++ b/mmpac/src/private/nc/bs/mmpac/wr/rule/serialno/PickMFinishRule.java @@ -18,89 +18,78 @@ import nc.vo.pub.BusinessException; import java.util.ArrayList; - - - - - - -public class PickMFinishRule - extends Object - implements IRule -{ - public void process(AggWrVO[] vos) { - if (MMValueCheck.isEmpty(vos)) { - return; - } - /** - * 业务逻辑: - * 1.根据生产报告子表中生产订单行查看生产订单明细表 - * 2.查看生产订单明细行的状态是否为完工(2) - * 3.若为完工状态,则根据生成报告子表中生产订单行查询备料计划 - * 4.修改备料计划为完成状态(3) - */ - for(int i = 0; i < vos.length; i++) { - AggWrVO vo = vos[i]; - WrItemVO[] items = vo.getChildrenVO(); - //循环生产报告子表 - for(int j = 0; j < items.length; j++) { - WrItemVO item = items[j]; - String cbmobid = item.getCbmobid(); - String[] keys = {cbmobid}; - //生产订单行查询 - PMOItemVO[] pmoItemvos = (new PMOItemVOQueryBP()).getPMOItemVOsByids(keys); - //查看生产订单行状态是否为完工(2) - if(pmoItemvos.length > 0) { - PMOItemVO pmoItem = pmoItemvos[0]; - int fitemStatus = pmoItem.getFitemstatus(); - if(fitemStatus != 2) { - continue; - } - //根据生产订单行查询备料计划 +public class PickMFinishRule extends Object implements IRule { + public void process(AggWrVO[] vos) { + if (MMValueCheck.isEmpty(vos)) { + return; + } + /** + * 业务逻辑: 1.根据生产报告子表中生产订单行查看生产订单明细表 2.查看生产订单明细行的状态是否为完工(2) + * 3.若为完工状态,则根据生成报告子表中生产订单行查询备料计划 4.修改备料计划为完成状态(3) + */ + for (int i = 0; i < vos.length; i++) { + AggWrVO vo = vos[i]; + WrItemVO[] items = vo.getChildrenVO(); + // 循环生产报告子表 + for (int j = 0; j < items.length; j++) { + WrItemVO item = items[j]; + String cbmobid = item.getCbmobid(); + String[] keys = { cbmobid }; + // 生产订单行查询 + PMOItemVO[] pmoItemvos = (new PMOItemVOQueryBP()).getPMOItemVOsByids(keys); + // 查看生产订单行状态是否为完工(2) + if (pmoItemvos.length > 0) { + PMOItemVO pmoItem = pmoItemvos[0]; + int fitemStatus = pmoItem.getFitemstatus(); + if (fitemStatus != 2) { + continue; + } + // 根据生产订单行查询备料计划 // BillQuery query = new BillQuery(AggPickmVO.class); // AggPickmVO[] aggVOs = (AggPickmVO[])query.query(keys); - String whereSql = "nvl(mm_pickm.dr,0) = 0 and mm_pickm.vsourcemorowid = '" + cbmobid + "'"; - IMDPersistenceQueryService aggvoQueryService = NCLocator.getInstance().lookup(IMDPersistenceQueryService.class); - // 根据主键查询得到aggvo - try { - @SuppressWarnings("unchecked") - ArrayList aggVOs = (ArrayList)aggvoQueryService.queryBillOfVOByCond(AggPickmVO.class, whereSql, true, false); - if(aggVOs.size() <= 0) { - continue; - } - //数组转换 - AggPickmVO[] aggVOsArr = new AggPickmVO[aggVOs.size()]; - boolean flag = false; - for(int z=0; z aggVOs = (ArrayList) aggvoQueryService + .queryBillOfVOByCond(AggPickmVO.class, whereSql, true, false); + if (aggVOs.size() <= 0) { + continue; + } + // 数组转换 + AggPickmVO[] aggVOsArr = new AggPickmVO[aggVOs.size()]; + boolean flag = false; + for (int z = 0; z < aggVOs.size(); z++) { + AggPickmVO aggPickmVO = aggVOs.get(z); + PickmHeadVO pickmHeadVO = aggPickmVO.getParentVO(); + Integer fbillstatus = pickmHeadVO.getFbillstatus(); + if (fbillstatus != 2) { + aggVOsArr[z] = aggVOs.get(z); + flag = true; + } - } - if(flag){ - //备料计划完工 - IPickmMaintainService ipickmMaintainService = NCLocator.getInstance().lookup(IPickmMaintainService.class); - ipickmMaintainService.finishPickm(aggVOsArr); - } - }catch(BusinessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + } + if (flag) { + // 备料计划完工 + IPickmMaintainService ipickmMaintainService = NCLocator.getInstance() + .lookup(IPickmMaintainService.class); + ipickmMaintainService.finishPickm(aggVOsArr); + } + } catch (BusinessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - } + } - } - } - AggWrChangeVO[] aggChangeVOs = WrBusiVOToChangeVO.changeOnlySerialNoVO(vos); + } + } + AggWrChangeVO[] aggChangeVOs = WrBusiVOToChangeVO.changeOnlySerialNoVO(vos); - WrSerialNoDocInsertControl inSertControl = new WrSerialNoDocInsertControl(); - inSertControl.process(aggChangeVOs); - } + WrSerialNoDocInsertControl inSertControl = new WrSerialNoDocInsertControl(); + inSertControl.process(aggChangeVOs); + } } - - diff --git a/mmpac/src/private/nc/bs/pub/action/N_55A2_SAVE.java b/mmpac/src/private/nc/bs/pub/action/N_55A2_SAVE.java new file mode 100644 index 0000000..861081a --- /dev/null +++ b/mmpac/src/private/nc/bs/pub/action/N_55A2_SAVE.java @@ -0,0 +1,32 @@ +package nc.bs.pub.action; + +import nc.bs.mmpac.pmo.pac0002.bp.PMOCommitBP; +import nc.bs.mmpac.pmo.pac0002.flowbiz.PMOCommitFlowCheckRule; +import nc.bs.mmpac.pmo.pac0002.pluginpoint.PMOPluginPoint; +import nc.bs.pubapp.pf.action.AbstractPfAction; +import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser; +import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO; +import nc.bs.mmpac.pmo.pac0002.bp.rule.saveBeforeCheckRule; + +public class N_55A2_SAVE extends AbstractPfAction { + protected CompareAroundProcesser getCompareAroundProcesserWithRules(Object userObj) { + CompareAroundProcesser processer = new CompareAroundProcesser(PMOPluginPoint.COMMIT); + + addBeforeRule(processer); + + addAfterRule(processer); + return processer; + } + + private void addBeforeRule(CompareAroundProcesser processer) { + processer.addBeforeFinalRule(new PMOCommitFlowCheckRule()); + processer.addBeforeRule(new saveBeforeCheckRule()); + } + + private void addAfterRule(CompareAroundProcesser processer) { + } + + protected PMOAggVO[] processBP(Object userObj, PMOAggVO[] clientFullVOs, PMOAggVO[] originBills) { + return (new PMOCommitBP()).commit(clientFullVOs, originBills); + } +} diff --git a/mmpps/src/public/nc/rule/mmpps/plo/PloProdDeptRule.java b/mmpps/src/public/nc/rule/mmpps/plo/PloProdDeptRule.java index a41460f..8ecefab 100644 --- a/mmpps/src/public/nc/rule/mmpps/plo/PloProdDeptRule.java +++ b/mmpps/src/public/nc/rule/mmpps/plo/PloProdDeptRule.java @@ -21,10 +21,8 @@ import nc.vo.pub.BusinessException; import nc.vo.pubapp.pattern.exception.ExceptionUtils; import nc.pubitf.mmpac.pickm.pub.IPickmPubQueryService; - /** - * 閫傞厤2312MPR杩愮畻鏃舵妸鍚堝悓缂栧彿鍚堝悓閿鍞鍗曞彿鏍囧墠椤圭洰鍙峰甫鍒拌鍒掕鍗 - * zhangxinah + * 适配2312MPR运算时把合同编号合同销售订单号标前项目号带到计划订单 zhangxinah */ public class PloProdDeptRule extends Object implements IRule { @@ -32,7 +30,7 @@ public class PloProdDeptRule extends Object implements IRule { if (null == vos) { return; } - + ArrayList vsrcbidList = new ArrayList<>(); Map> map = new HashMap>(); for (AggregatedPoVO agg : vos) { @@ -55,8 +53,8 @@ public class PloProdDeptRule extends Object implements IRule { vids.add(vid); } } - String vsrcbid = plo.getVsrcbid();// 鏉ユ簮鍗曟嵁琛ㄤ綋涓婚敭 - int fdemandbill = plo.getFdemandbill();// 闇姹傛潵婧 + String vsrcbid = plo.getVsrcbid();// 来源单据表体主键 + int fdemandbill = plo.getFdemandbill();// 需求来源 if (PoSourceEnum.COMPUT == posource && fdemandbill == 1) { vsrcbidList.add(vsrcbid); } @@ -72,23 +70,23 @@ public class PloProdDeptRule extends Object implements IRule { pickmVOMap.getClass(); for (AggregatedPoVO agg : vos) { PoVO plo = agg.getParentVO(); - String vsrcbid = plo.getVsrcbid();// 鏉ユ簮鍗曟嵁琛ㄤ綋涓婚敭 + String vsrcbid = plo.getVsrcbid();// 来源单据表体主键 AggPickmVO aggPickmVOData = pickmVOMap.get(vsrcbid); if (aggPickmVOData != null) { PickmItemVO[] children = (PickmItemVO[]) aggPickmVOData.getChildren(PickmItemVO.class); - String vbdef5 = "";// 鍚堝悓缂栧彿 - String vbdef6 = "";// 鍚堝悓閿鍞鍗曞彿 - String vbdef7 = "";// 鏍囧墠椤圭洰鍙 + String vbdef5 = "";// 合同编号 + String vbdef6 = "";// 合同销售订单号 + String vbdef7 = "";// 标前项目号 for (PickmItemVO pickmItemVO : children) { if (pickmItemVO.getCpickm_bid().equals(vsrcbid)) { - vbdef5 = pickmItemVO.getVbdef5();// 鍚堝悓缂栧彿 - vbdef6 = pickmItemVO.getVbdef6();// 鍚堝悓閿鍞鍗曞彿 - vbdef7 = pickmItemVO.getVbdef7();// 鏍囧墠椤圭洰鍙 + vbdef5 = pickmItemVO.getVbdef5();// 合同编号 + vbdef6 = pickmItemVO.getVbdef6();// 合同销售订单号 + vbdef7 = pickmItemVO.getVbdef7();// 标前项目号 } } - plo.setVdef2(vbdef5);// 鍚堝悓缂栧彿 - plo.setVdef3(vbdef6);// 鍚堝悓閿鍞鍗曞彿 - plo.setVdef4(vbdef7);// 鏍囧墠椤圭洰鍙 + plo.setVdef2(vbdef5);// 合同编号 + plo.setVdef3(vbdef6);// 合同销售订单号 + plo.setVdef4(vbdef7);// 标前项目号 } } } diff --git a/pu/src/private/nc/bs/pu/m21/maintain/rule/save/FillOrderVosRule.java b/pu/src/private/nc/bs/pu/m21/maintain/rule/save/FillOrderVosRule.java new file mode 100644 index 0000000..84175d8 --- /dev/null +++ b/pu/src/private/nc/bs/pu/m21/maintain/rule/save/FillOrderVosRule.java @@ -0,0 +1,1775 @@ +package nc.bs.pu.m21.maintain.rule.save; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import nc.bs.framework.common.NCLocator; +import nc.impl.pubapp.pattern.database.DataAccessUtils; +import nc.impl.pubapp.pattern.database.IDExQueryBuilder; +import nc.impl.pubapp.pattern.rule.IRule; +import nc.itf.pu.m21.IOrderSupplierQuery; +import nc.itf.pu.pub.IPURemoteCallCombinator; +import nc.itf.pubbd.profitcenter.IProfitCenterPubService; +import nc.itf.scmpub.reference.uap.bd.addrdoc.AddrdocPubService; +import nc.itf.scmpub.reference.uap.bd.currency.CurrencyRatePubService; +import nc.itf.scmpub.reference.uap.bd.customer.CustomerPubService; +import nc.itf.scmpub.reference.uap.bd.material.MaterialPubService; +import nc.itf.scmpub.reference.uap.bd.payment.PaymentService; +import nc.itf.scmpub.reference.uap.bd.psn.PsndocPubService; +import nc.itf.scmpub.reference.uap.bd.supplier.SupplierPubService; +import nc.itf.scmpub.reference.uap.bd.vat.BuySellFlagEnum; +import nc.itf.scmpub.reference.uap.org.OrgUnitPubService; +import nc.itf.scmpub.reference.uap.org.ProfitCenterPubService; +import nc.itf.scmpub.reference.uap.pf.PfServiceScmUtil; +import nc.itf.uap.pf.IPFConfig; +import nc.pubitf.org.IDeptPubService; +import nc.pubitf.uapbd.IMaterialPubService; +import nc.vo.bd.material.MaterialConvertVO; +import nc.vo.bd.material.MaterialVO; +import nc.vo.bd.payment.PaymentChVO; +import nc.vo.bd.payment.PaymentVO; +import nc.vo.bd.rate.util.RateReturnObject; +import nc.vo.profitcenter.ProfitCenterVO; +import nc.vo.pu.m21.entity.OrderHeaderVO; +import nc.vo.pu.m21.entity.OrderItemVO; +import nc.vo.pu.m21.entity.OrderPaymentVO; +import nc.vo.pu.m21.entity.OrderVO; +import nc.vo.pu.m21.enumeration.EnumBillStatus; +import nc.vo.pu.m21.pub.TrantypeUtil; +import nc.vo.pu.m21.query.supplier.SupplierInfo; +import nc.vo.pu.m21.rule.CurrencyAndExchangerate; +import nc.vo.pu.m21.rule.FlowStockOrgValue; +import nc.vo.pu.m21.rule.OrderScaleRule; +import nc.vo.pu.m21.rule.OrganizationDefaultValue; +import nc.vo.pu.m21.rule.PlanArriveDate; +import nc.vo.pu.m21.rule.ReqCorpDefaultValue; +import nc.vo.pu.m21.rule.vat.OrderVatValueFillRule; +import nc.vo.pu.m21.rule.vat.OrderVatValueFillRule.ICountrySetter; +import nc.vo.pu.m21.rule.vat.setter.country.OrderReceiveCountrySetter; +import nc.vo.pu.m21.rule.vat.setter.country.OrderSendCountrySetter; +import nc.vo.pu.m21.rule.vat.setter.country.OrderTaxCountrySetter; +import nc.vo.pu.pub.constant.PUParaValue; +import nc.vo.pu.pub.constant.PUTempTable; +import nc.vo.pu.pub.enumeration.EnumDiscounttaxtype; +import nc.vo.pu.pub.enumeration.PricePriority; +import nc.vo.pu.pub.rule.WeightVolumePieceCalc; +import nc.vo.pu.pub.util.BillHelper; +import nc.vo.pu.pub.util.IKeyValue; +import nc.vo.pu.pub.util.PUSysParamUtil; +import nc.vo.pu.pub.util.PubSysParamUtil; +import nc.vo.pub.BusinessException; +import nc.vo.pub.CircularlyAccessibleValueObject; +import nc.vo.pub.SuperVO; +import nc.vo.pub.VOStatus; +import nc.vo.pub.lang.UFBoolean; +import nc.vo.pub.lang.UFDate; +import nc.vo.pub.lang.UFDouble; +import nc.vo.pub.lang.UFLiteralDate; +import nc.vo.pubapp.AppContext; +import nc.vo.pubapp.calculator.Calculator; +import nc.vo.pubapp.calculator.CalculatorUtil; +import nc.vo.pubapp.calculator.Condition; +import nc.vo.pubapp.calculator.HslParseUtil; +import nc.vo.pubapp.calculator.data.IDataSetForCal; +import nc.vo.pubapp.calculator.data.IRelationForItems; +import nc.vo.pubapp.calculator.data.RelationItemForCal; +import nc.vo.pubapp.calculator.data.VODataSetForCal; +import nc.vo.pubapp.pattern.data.IRowSet; +import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.pubapp.pattern.pub.PubAppTool; +import nc.vo.pubapp.pattern.pub.SqlBuilder; +import nc.vo.pubapp.scale.BillVOScaleProcessor; +import nc.vo.pubapp.scale.ScaleUtils; +import nc.vo.pubapp.scale.TotalValueVOScaleProcessor; +import nc.vo.ratetype.RateTypeConstant; +import nc.vo.scmpub.res.billtype.POBillType; +import nc.vo.scmpub.res.para.NCPara; +import nc.vo.scmpub.util.StringUtil; +import nccloud.commons.collections.CollectionUtils; +import nccloud.commons.lang.ArrayUtils; +import nccloud.pubimpl.pu.m21.afterevent.service.body.TaxCode; + +/** + * @description 补全导入的数据 + * @author zhangmimi + * @date 2021年12月9日 上午10:28:53 + * @version ncc1.0 + */ +public class FillOrderVosRule implements IRule { + + private ScaleUtils scaleUtils = null; + private Map remoteCaller = new HashMap(); + private static final String VCHANGERATE = "1/1"; + + @Override + public void process(OrderVO[] vos) { + String pk_group = vos[0].getHVO().getPk_group(); + this.scaleUtils = new ScaleUtils(pk_group); + try { + this.fillHeadVo(vos); + this.fillBodyVo(vos); + + // 补充完数据信息之后做精度处理 + BillVOScaleProcessor scale = new BillVOScaleProcessor(pk_group, vos); + TotalValueVOScaleProcessor totalScale = new TotalValueVOScaleProcessor(vos); + new OrderScaleRule().setScale(scale, totalScale); + } catch (BusinessException e) { + ExceptionUtils.wrappException(e); + } + } + + /** + * + * 补充表体VO 1、表头退货标志为Y,导入时则校验表体数量金额是否为负,若不是,则提示“退货订单,数量不允许为正” 2.表头付款协议字段有值,导入时 + * 创建表体付款协议数据 3.表头整单税率若有值,表体未设置税率字段,则表体获取标题得税率值 4.表头整单扣税类别有值,标题未设置,获取表头得值 + * 5.表头币种与表体币种一致时,折本汇率字段为1,组织汇率类型、组织汇率来源日期为空 + * 6.折扣为空时(折扣规则编码未导入),默认100%;折扣规则编码导入,根据编码反算折扣 + * 7.需求部门pk_reqdept_v不为空,pk_reqdept为空,需要根据pk_reqdept_v填充pk_reqdept + * + * 物料materials 物料(VID) -》单位、主单位 客户 casscustvids (VID) -> 客户Oid + * 收货库存组织\物流组织\需求公司\收货利润中心\需求库存组织、结算采购组织、 arrvstoorgs(VID) ->收货库存组织OID 应付组织 + * VID-》应付组织OID、结算利润中心 结算利润中心为空,则取应付组织对应的利润中心 应付中心 apfinanceorgs VID-》结算利润中心 + * vbatchcode 批次号 需求部门pk_reqdept_v -》 pk_reqdept + * + * @param vos + * @throws BusinessException + * + */ + private void fillBodyVo(OrderVO[] vos) throws BusinessException { + Set materials = new HashSet(); + Set casscustvids = new HashSet(); + Set arrvstoorgs = new HashSet(); + Set apfinanceorgs = new HashSet(); + Set orgs = new HashSet(); + Set arrliabcenterVids = new HashSet(); + Set vbatchcode = new HashSet(); + Set depts = new HashSet();// NCC-309814 需求部门vid带oid + // 表头收货客户Oid有值带出表体收货地区地址、地点 + Map recvcustomerOids = new HashMap(); + for (OrderVO orderVO : vos) { + arrvstoorgs.add(orderVO.getHVO().getPk_org_v()); + orgs.add(orderVO.getHVO().getPk_org()); + if (orderVO.getHVO().getPk_recvcustomer() != null) { + recvcustomerOids.put(orderVO.getHVO().getPk_recvcustomer(), orderVO.getHVO().getPk_org()); + } + for (OrderItemVO orderItemVO : orderVO.getBVO()) { + materials.add(orderItemVO.getPk_material()); + casscustvids.add(orderItemVO.getCasscustvid()); + arrvstoorgs.add(orderItemVO.getPk_arrvstoorg_v()); + arrvstoorgs.add(orderItemVO.getPk_flowstockorg_v()); + arrvstoorgs.add(orderItemVO.getPk_arrliabcenter_v()); + arrliabcenterVids.add(orderItemVO.getPk_arrliabcenter_v()); + arrvstoorgs.add(orderItemVO.getPk_reqstoorg_v()); + arrvstoorgs.add(orderItemVO.getPk_psfinanceorg_v()); + arrvstoorgs.add(orderItemVO.getPk_apfinanceorg_v()); + if (orderItemVO.getPk_apfinanceorg_v() != null) { + apfinanceorgs.add(orderItemVO.getPk_apfinanceorg_v()); + } + if (orderItemVO.getPk_apliabcenter_v() != null) { + apfinanceorgs.add(orderItemVO.getPk_apliabcenter_v()); + } + vbatchcode.add(orderItemVO.getVbatchcode()); + depts.add(orderItemVO.getPk_reqdept_v());// NCC-309814 需求部门vid带oid + } + } + // NCC-309814 采购部门Vid查Oid的值 + HashMap oidsByDeptVIDS = NCLocator.getInstance().lookup(IDeptPubService.class) + .getOIDSByDeptVIDS(depts.toArray(new String[depts.size()])); + // 根据批次号查询主键 + Map vbatchIds = this.getVBatchIdByCode(vbatchcode); +// Map mapvid = new HashMap(); +// // 收货利润中心根据vid查询oid +// ProfitCenterVO[] profits = +// NCLocator.getInstance().lookup(IProfitCenterPubService.class) +// .queryProfitCenterVOByIDS(arrliabcenterVids.toArray(new String[0])); +// Stream.of(profits).forEach(profit -> {mapvid.put(profit.getPk_profitcenter(), profit.getPk_vid());}); + + // 查询利润中心oid + Map profitmap = ProfitCenterPubService + .queryProfitCenterVidByOid(apfinanceorgs.toArray(new String[0])); + + // 根据组织Vid查询Oid的值 + Map orgOidsByVrgIDS = OrgUnitPubService + .getOrgIDSByVIDS(arrvstoorgs.toArray(new String[arrvstoorgs.size()])); + // 根据物料,查找物料的基本信息 + MaterialVO[] materialsByMec = MaterialPubService.queryMaterialBaseInfoByPks( + materials.toArray(new String[materials.size()]), new String[] { MaterialVO.PK_MATERIAL, + MaterialVO.PK_ORG, MaterialVO.PK_GROUP, MaterialVO.PK_MEASDOC, MaterialVO.PK_SOURCE }); + // 物料信息集合 + Map invBasVOs = getMapMaterialToVo(materialsByMec); + // 查询物料对应的所有辅单位 + Map> measdocByVIDMap = this.getCastunitidMapByTempTable(materials); + // 获取物料下单位得所有换算率 + Map convertByMaterialAndMeasdocMap = NCLocator.getInstance() + .lookup(IMaterialPubService.class) + .queryMaterialConvertByMaterialAndMeasdoc(materials.toArray(new String[materials.size()]), + this.getpkDepts(measdocByVIDMap), new String[] { MaterialConvertVO.PK_MATERIAL, + MaterialConvertVO.MEASRATE, MaterialConvertVO.PK_MEASDOC }); + + // 根据物料VID数组查询默认采购计量单位 + Map measdocIDByPks = MaterialPubService + .queryPuMeasdocIDByPks(materials.toArray(new String[materials.size()])); + // 获得物料的基本信息 +// InvInfoQuery invInfoQuery = new InvInfoQuery(); + // InvBasVO 中 pk_measdoc为主单位值,pk_source为版本信息值 +// Map invBasVOs = invInfoQuery.getInvBasVOs(materials.toArray(new String[materials.size()])); + // 若输入客户Vid,查找客户的Oid字段 + Map customerOidsByVids = CustomerPubService + .queryCustomerOidsByVids(casscustvids.toArray(new String[casscustvids.size()])); + // 根据组织获取组织对应的利润中心 + Collection orgOids = orgOidsByVrgIDS.values(); + ProfitCenterVO[] profitCenterVOSByRelateOrgs = NCLocator.getInstance().lookup(IProfitCenterPubService.class) + .queryProfitCenterVOSByRelateOrgs(orgOids.toArray(new String[orgOids.size()])); + Map apliabcentersMapByApfinanceorg = this.getMapBySet(profitCenterVOSByRelateOrgs); + + // 获取结算组织对应的本位币,给表体币种赋值 + Map ccurrencyids = OrgUnitPubService + .queryOrgCurrByPk(orgOids.toArray(new String[orgOids.size()])); + + // 获取组织对应的仓库 +// Map directStoreByOrg = StordocPubService.getDirectstore(orgOids.toArray(new String[orgOids.size()])); + + // 存储物料库存组织信息-》仓库 +// Map materialStockInfoByArrOrg = new HashMap(); + // 存储组织所属于组织类型 + Map typeByOrg = new HashMap(); + // 存储收货利润中心的值 + Map storedocsByOrg = new HashMap(); + + // 汇率类型编辑的询汇率接口不支持批量查询,在这里定义一个map做缓存数据使用 + Map rateCacheMap = new HashMap(); + // 根据表头收货客户Oid,查找收货客户得收货地址地区、地点 + Map cdevAreaIdByReceOIds = this.getCdevareaId(recvcustomerOids); + for (OrderVO orderVO : vos) { + BillHelper voHelper = new BillHelper(orderVO); + int[] rows = new int[voHelper.getItemCount()]; + OrderHeaderVO headerVO = orderVO.getHVO(); + UFBoolean breturn = headerVO.getBreturn(); + // 收货客户 + String pk_recvcustomer = headerVO.getPk_recvcustomer(); + String pk_org = headerVO.getPk_org(); + for (int i = 0; i < orderVO.getBVO().length; i++) { + rows[i] = i; + OrderItemVO orderItemVO = orderVO.getBVO()[i]; + if (orderItemVO.getStatus() == 0 || orderItemVO.getStatus() == 2) { + orderItemVO.setStatus(VOStatus.NEW); + } + orderItemVO.setPk_group(headerVO.getPk_group()); + orderItemVO.setPk_org(headerVO.getPk_org()); + orderItemVO.setPk_org_v(headerVO.getPk_org_v()); + // 校验若退货,若数量、价税合计大于0报错 + if (breturn != null && breturn.booleanValue()) { + // 退货 + UFDouble nastnum = orderItemVO.getNastnum(); + UFDouble norigtaxmny = orderItemVO.getNorigtaxmny(); + if (nastnum.compareTo(UFDouble.ZERO_DBL) > 0 + || (norigtaxmny != null && norigtaxmny.compareTo(UFDouble.ZERO_DBL) > 0)) { + ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes() + .getStrByID("4004030_0", "04004030-0428")/* + * @res "订单退货时,表体的数量或价税合计不能为正数,请检查!" + */); + } + } + // 操作员 + orderItemVO.setChandler(AppContext.getInstance().getPkUser()); + // 主单位,不导入,获取默认值 + orderItemVO.setCunitid(invBasVOs.get(orderItemVO.getPk_material()).getPk_measdoc()); + // 扣税类别 + if (orderItemVO.getFtaxtypeflag() == null) { + orderItemVO.setFtaxtypeflag(headerVO.getFhtaxtypeflag()); + } + // 税率 + if (orderItemVO.getNtaxrate() == null) { + orderItemVO.setNtaxrate(headerVO.getNhtaxrate()); + } + // 折扣 + if (orderItemVO.getNitemdiscountrate() == null) { + orderItemVO.setNitemdiscountrate(new UFDouble(100)); + } + // 物料版本 + if (orderItemVO.getPk_srcmaterial() == null) { + orderItemVO.setPk_srcmaterial(invBasVOs.get(orderItemVO.getPk_material()).getPk_source()); + } + // 客户 + if (orderItemVO.getCasscustid() == null && orderItemVO.getCasscustvid() != null) { + orderItemVO.setCasscustid(customerOidsByVids.get(orderItemVO.getCasscustvid())); + } + // 增加校验,若收货库存组织与需求库存组织为空,清空表体收货仓库与需求仓库得值 + if (orderItemVO.getPk_arrvstoorg_v() == null) { + orderItemVO.setPk_recvstordoc(null); + } + if (orderItemVO.getPk_reqstoorg_v() == null) { + orderItemVO.setPk_reqstordoc(null); + } + + // 收货库存组织 版本 + if (orderItemVO.getPk_arrvstoorg() == null && orderItemVO.getPk_arrvstoorg_v() != null) { + orderItemVO.setPk_arrvstoorg(orgOidsByVrgIDS.get(orderItemVO.getPk_arrvstoorg_v())); + if (!this.getOrgType(orderItemVO.getPk_arrvstoorg(), nc.itf.org.IOrgConst.STOCKORGTYPE, + typeByOrg)) { + // 若无库存职能直接报错 + ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes() + .getStrByID("4004030_0", "04004030-0417")/* + * @res "该库存组织无库存职能,不能导入,请检查!" + */); + } + } + // 物流组织版本 + if (orderItemVO.getPk_flowstockorg() == null && orderItemVO.getPk_flowstockorg_v() != null) { + orderItemVO.setPk_flowstockorg(orgOidsByVrgIDS.get(orderItemVO.getPk_flowstockorg_v())); + } else { + orderItemVO.setPk_flowstockorg(orderItemVO.getPk_org()); + } + // 物流组织 未导入时默认取采购组织;导入时取导入值 + if (orderItemVO.getPk_flowstockorg_v() == null) { + orderItemVO.setPk_flowstockorg_v(orderItemVO.getPk_org_v()); + } + // 需求库存组织版本 + if (orderItemVO.getPk_reqstoorg() == null && orderItemVO.getPk_reqstoorg_v() != null) { + orderItemVO.setPk_reqstoorg(orgOidsByVrgIDS.get(orderItemVO.getPk_reqstoorg_v())); + if (!this.getOrgType(orderItemVO.getPk_reqstoorg(), nc.itf.org.IOrgConst.STOCKORGTYPE, typeByOrg)) { + // 若无库存职能直接报错 + ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes() + .getStrByID("4004030_0", "04004030-0417")/* + * @res "该库存组织无库存职能,不能导入,请检查!" + */); + } + } + // 结算财务组织版本 + if (orderItemVO.getPk_psfinanceorg() == null && orderItemVO.getPk_psfinanceorg_v() != null) { + orderItemVO.setPk_psfinanceorg(orgOidsByVrgIDS.get(orderItemVO.getPk_psfinanceorg_v())); + } else { + // 判断组织是否属于财务组织 + if (this.getOrgType(orderItemVO.getPk_org(), nc.itf.org.IOrgConst.FINANCEORGTYPE, typeByOrg)) { + orderItemVO.setPk_psfinanceorg(orderItemVO.getPk_org()); + } + } + // 结算财务组织 未导入时默认取采购组织;导入时取导入值 + if (orderItemVO.getPk_psfinanceorg_v() == null) { + // 判断组织是否属于财务组织 + if (this.getOrgType(orderItemVO.getPk_org(), nc.itf.org.IOrgConst.FINANCEORGTYPE, typeByOrg)) { + orderItemVO.setPk_psfinanceorg_v(orderItemVO.getPk_org_v()); + } + } + // 币种 根据结算财务组织获值 + if (orderItemVO.getCcurrencyid() == null) { + orderItemVO.setCcurrencyid(ccurrencyids.get(orderItemVO.getPk_psfinanceorg())); + } + // 应付组织 版本 + if (orderItemVO.getPk_apfinanceorg() == null && orderItemVO.getPk_apfinanceorg_v() != null) { + orderItemVO.setPk_apfinanceorg(orgOidsByVrgIDS.get(orderItemVO.getPk_apfinanceorg_v())); + } else { + orderItemVO.setPk_apfinanceorg(orderItemVO.getPk_psfinanceorg()); + } + // 应付组织 未导入时取结算采购组织,导入取导入值 + if (orderItemVO.getPk_apfinanceorg_v() == null) { + orderItemVO.setPk_apfinanceorg_v(orderItemVO.getPk_psfinanceorg_v()); + } + // 结算利润中心 版本 + if (orderItemVO.getPk_apliabcenter() == null && orderItemVO.getPk_apliabcenter_v() != null) { + orderItemVO.setPk_apliabcenter(profitmap.get(orderItemVO.getPk_apliabcenter_v())); + } + // 结算利润中心 未导入时取应付组织对应的利润中心,导入取导入值 + if (orderItemVO.getPk_apliabcenter_v() == null && !apliabcentersMapByApfinanceorg.isEmpty() + && apliabcentersMapByApfinanceorg.get(orderItemVO.getPk_apfinanceorg()) != null) { + orderItemVO.setPk_apliabcenter_v( + apliabcentersMapByApfinanceorg.get(orderItemVO.getPk_apfinanceorg()).getPk_vid()); + orderItemVO.setPk_apliabcenter( + apliabcentersMapByApfinanceorg.get(orderItemVO.getPk_apfinanceorg()).getPk_profitcenter()); + } + // 收货仓库\需求仓库 导入取导入值;未导入取默认值 +// if (!headerVO.getBdirect().booleanValue()) { +// // 若直运时走另外逻辑 +// String pk_reqstordoc = null; +// if (orderItemVO.getPk_recvstordoc() == null || orderItemVO.getPk_reqstordoc() == null) { +// // 接口中获取仓库地址 +// if (materialStockInfoByArrOrg == null || materialStockInfoByArrOrg.get(orderItemVO.getPk_material()) == null) { +// materialStockInfoByArrOrg = MaterialPubService.queryMaterialStockInfo(new String [] {orderItemVO.getPk_material()}, orderItemVO.getPk_arrvstoorg(), new String[] {MaterialStockVO.PK_STORDOC}); +// } +// if (!materialStockInfoByArrOrg.isEmpty() && materialStockInfoByArrOrg.get(orderItemVO.getPk_material()) != null) { +// pk_reqstordoc = materialStockInfoByArrOrg.get(orderItemVO.getPk_material()).getPk_stordoc(); +// } +// } +// if (orderItemVO.getPk_recvstordoc() == null && pk_reqstordoc != null) { +// orderItemVO.setPk_recvstordoc(pk_reqstordoc); +// } +// if (orderItemVO.getPk_reqstordoc() == null && pk_reqstordoc != null) { +// orderItemVO.setPk_reqstordoc(pk_reqstordoc); +// } +// } else { +// // 若订单类型为直运设置直运仓 +// if (orderItemVO.getPk_recvstordoc() == null) { +// orderItemVO.setPk_recvstordoc(directStoreByOrg.get(orderItemVO.getPk_arrvstoorg())); +// } +// if (orderItemVO.getPk_reqstordoc() == null) { +// orderItemVO.setPk_reqstordoc(directStoreByOrg.get(orderItemVO.getPk_arrvstoorg())); +// } +// } + // 收货利润中心版本 + if (orderItemVO.getPk_arrliabcenter() == null && orderItemVO.getPk_arrliabcenter_v() != null) { + // 根据vid查找oid + String oid = ""; + if (storedocsByOrg.isEmpty() || storedocsByOrg.get(orderItemVO.getPk_arrliabcenter_v()) == null) { + ProfitCenterVO profits = NCLocator.getInstance().lookup(IProfitCenterPubService.class) + .queryProfitCenterByVID(orderItemVO.getPk_arrliabcenter_v()); + storedocsByOrg.put(orderItemVO.getPk_arrliabcenter_v(), profits.getPk_profitcenter()); + oid = profits.getPk_profitcenter(); + } else { + oid = storedocsByOrg.get(orderItemVO.getPk_arrliabcenter_v()); + } + orderItemVO.setPk_arrliabcenter(oid); + } + // 批次号,若导入之后未查出批次号,则清空表体批次号 + if (orderItemVO.getVbatchcode() != null && vbatchIds.isEmpty() + && vbatchIds.get(orderItemVO.getVbatchcode()) == null) { + orderItemVO.setVbatchcode(null); + } + // 批次号主键 + if (orderItemVO.getVbatchcode() != null && !vbatchIds.isEmpty() + && vbatchIds.get(orderItemVO.getVbatchcode()) != null) { + orderItemVO.setPk_batchcode(vbatchIds.get(orderItemVO.getVbatchcode())); + } + // NCC-309814 补充需求部门Pk_reqdept + if (orderItemVO.getPk_reqdept() == null && orderItemVO.getPk_reqdept_v() != null) { + orderItemVO.setPk_reqdept(oidsByDeptVIDS.get(orderItemVO.getPk_reqdept_v())); + } + + // 设置表体组织汇率类型等的值 + this.setBodyRateVal(headerVO, orderItemVO, rateCacheMap); + // 校验单位与报价单位的值 + this.checkoutCasuitAndCquit(orderItemVO, measdocIDByPks, measdocByVIDMap, invBasVOs); + // 更新表体收货地区收货地点收货地址得值 + if (orderItemVO.getPk_receiveaddress() == null) { + String pk_receiveaddress = cdevAreaIdByReceOIds + .get(pk_recvcustomer + pk_org + OrderItemVO.PK_RECEIVEADDRESS); + orderItemVO.setPk_receiveaddress(pk_receiveaddress); + } + if (orderItemVO.getCdevareaid() == null) { + String cdevareaid = cdevAreaIdByReceOIds.get(pk_recvcustomer + pk_org + OrderItemVO.CDEVAREAID); + orderItemVO.setCdevareaid(cdevareaid); + } + if (orderItemVO.getCdevaddrid() == null) { + String cdevaddrid = cdevAreaIdByReceOIds.get(pk_recvcustomer + pk_org + OrderItemVO.CDEVADDRID); + orderItemVO.setCdevaddrid(cdevaddrid); + } + // 若只导入税码 + this.calNRate(orderVO, rows, orderItemVO); + } + // 设置本位币、汇率相关信息 + this.setCurrencyAndRate(voHelper, rows); + // 设置需求库存组织与收货库存组织未导入时默认值 + this.defaultOrganization(voHelper, rows); + // 设置需求公司 + new ReqCorpDefaultValue(voHelper).setDefaultValue(rows); + // 设置表体利润中心字段 +// this.setArrLiabVals(orderVO,storedocsByOrg,apliabcentersMapByApfinanceorg); + // 设置发货国,收获国,报税国 + this.registerCountryRemoteCall(voHelper, rows); + // 计算数量 + this.calculate(orderVO, rows, OrderItemVO.NQTORIGTAXPRICE, convertByMaterialAndMeasdocMap, invBasVOs); + // 设置计划到货日期 + this.setPlanArriDate(voHelper, rows); + + } + } + + private void calNRate(OrderVO vo, int[] rows, OrderItemVO orderVO) { + // 税码 + String ctaxcodeid = orderVO.getCtaxcodeid(); + // 税率 + UFDouble ntaxrate = orderVO.getNtaxrate(); + if (ctaxcodeid != null && ntaxrate == null) { + // 若导入税码,根据税码询税率 + TaxCode taxCode = new TaxCode(); + taxCode.setImport(UFBoolean.TRUE);// 导入标识,不进行计算逻辑 + taxCode.afterEdit(vo, rows); + } + } + + /** + * + * 根据表头收货客户与组织查询表体地区地址地点 + * + * @param recvcustomerOids + * @return + * + */ + private Map getCdevareaId(Map recvcustomerOids) { + HashMap hashMap = new HashMap(); + Set defaultReceiveAddress = new HashSet(); + for (Entry recvcustomerOid : recvcustomerOids.entrySet()) { + // 收货客户Oid + String receiveCustomerid = recvcustomerOid.getKey(); + // 采购组织 + String pk_org = recvcustomerOid.getValue(); + String receiveaddresskey = receiveCustomerid + pk_org + OrderItemVO.PK_RECEIVEADDRESS; + String defaultReceiveAddres = null; + if (!hashMap.containsKey(receiveaddresskey)) { + // 取默认收货地址 + defaultReceiveAddres = CustomerPubService.getDefaultAddress(receiveCustomerid, pk_org); + hashMap.put(receiveCustomerid + pk_org + OrderItemVO.PK_RECEIVEADDRESS, defaultReceiveAddres); + defaultReceiveAddress.add(defaultReceiveAddres); + + if (!PubAppTool.isNull(defaultReceiveAddres)) { + // 取默认收货地区 + String[] defaultReceiveAreas = CustomerPubService + .getAreaPksByConsignAddress(new String[] { defaultReceiveAddres }); + if (!ArrayUtils.isEmpty(defaultReceiveAreas)) { + String defaultReceiveArea = defaultReceiveAreas[0]; + hashMap.put(receiveCustomerid + pk_org + OrderItemVO.CDEVAREAID, defaultReceiveArea); + } + // 取默认收货地点 + Map defaultAddressDoc = AddrdocPubService + .getAddressDocPksByConsignAddress(new String[] { defaultReceiveAddres }); + String defaultCdevaddrid = defaultAddressDoc.get(defaultReceiveAddres); + hashMap.put(receiveCustomerid + pk_org + OrderItemVO.CDEVADDRID, defaultCdevaddrid); + } + } + } + return hashMap; + } + + /** + * + * 根据业务委托关系寻值 + * + * @param card + * @param row + * + */ + private void defaultOrganization(IKeyValue card, int[] rows) { + // 组织业务委托关系找组织 + OrganizationDefaultValue util = new OrganizationDefaultValue(card, UFBoolean.TRUE); + util.setClear(false); + util.setDefaultOrganizationValue(rows);// 需求库存组织修改时根据业务委托关系询收货库存组织 + util.setDefaultStordoc(rows);// 需求库存组织和收货库存组织询值后,询对应的需求仓库收货仓库 +// util.setDefaultOrganizationValueByArrOrg(rows); + new FlowStockOrgValue(card).setFlowStockOrg(rows); + } + + /** + * + * 根据批次号查询主键 + * + * @param vbatchcode + * @return + * + */ + private Map getVBatchIdByCode(Set vbatchcode) { + Map btachIds = new HashMap(); + String[] vbatchcodes = vbatchcode.toArray(new String[0]); + if (nc.vo.scmpub.util.CollectionUtils.isNullForAllTElements(vbatchcodes)) { + return null; + } + SqlBuilder sql = new SqlBuilder(); + sql.append("SELECT DISTINCT PK_BATCHCODE,VBATCHCODE from scm_batchcode where "); + sql.append(OrderItemVO.VBATCHCODE, vbatchcodes); + DataAccessUtils util = new DataAccessUtils(); + IRowSet rowset = util.query(sql.toString()); + while (rowset.next()) { + String vcodeId = rowset.getString(0);// 批次号主键 + String vcode = rowset.getString(1);// 批次号 + btachIds.put(vcode, vcodeId); + } + return btachIds; + } + + /** + * 数组转为map,key为pk_material,value为MaterialVO类 + * + * @param materials 物料的详细信息集合 + * @return + * + */ + private Map getMapMaterialToVo(MaterialVO[] materials) { + Map materialVOMap = new HashMap<>(); + for (MaterialVO materialVO : materials) { + materialVOMap.put(materialVO.getPk_material(), materialVO); + } + return materialVOMap; + } + + /** + * + * 计算数量与价格 + * + * @param orderVO + * @param rows + * @param itemKey 根据itemKey计算金额与单价 + * @param invBasVOs 物料本身的单位 + * @param rates 换算率集合 + */ + private void calculate(OrderVO orderVO, int[] rows, String itemKey, Map changerates, + Map invBasVOs) { + IRelationForItems item = new RelationItemForCal(); + BillHelper billHelper = new BillHelper(orderVO); + WeightVolumePieceCalc volumePieceCalc = new WeightVolumePieceCalc(billHelper, UFBoolean.TRUE); + + String pkOrg = orderVO.getHVO().getPk_org(); + boolean isChangePrice = this.isChangePrice(pkOrg); + boolean isTaxPricePriorToPrice = this.isTaxPricePriorToPrice(pkOrg); + String pk_group = orderVO.getHVO().getPk_group(); + boolean groupLobalMnyCal = this.groupLobalMnyCal(pk_group); + boolean publicLocalMnyCal = this.publicLocalMnyCal(); + + boolean isOrigCurToGroupMoney = this.isOrigCurToGroupMoney(pk_group); + boolean isOrigCurToGlobalMoney = this.isOrigCurToGlobalMoney(); + + Map fixUnitRateAst = this.isFixUnitRate(orderVO, rows, true); + Map fixUnitRateQt = this.isFixUnitRate(orderVO, rows, false); + OrderItemVO[] itemVOs = orderVO.getBVO(); + List orderItemList = Arrays.asList(itemVOs); + // 是否计算报价换算率 + UFBoolean flagnnum = UFBoolean.FALSE; + for (OrderItemVO itemVO : orderItemList) { + String material = itemVO.getPk_material(); + String cunitid = itemVO.getCunitid(); + String castunitid = itemVO.getCastunitid(); + String cqtunitid = itemVO.getCqtunitid(); + String keyAst = material + cunitid + castunitid; + String keyQt = material + cunitid + cqtunitid; + String vchangeRate = null; + if (itemVO.getNnum() != null) { + // 主数量不为空时才计算报价换算率 + flagnnum = UFBoolean.TRUE; + } + if (changerates == null || changerates.get(material + "-" + castunitid) == null) { + // 物料主单位,若主辅一致,换算率为1 + String pk_measdoc = invBasVOs.get(material).getPk_measdoc(); + if (castunitid.equals(pk_measdoc)) { + vchangeRate = VCHANGERATE; + } + } else { + vchangeRate = changerates.get(material + "-" + castunitid).getMeasrate(); + } + + // 固定换算率:不取导入值,直接询物料档案默认换算率 + // 浮动换算率:导入时,取导入值;不导入时,询物料档案相应换算率 + if (!fixUnitRateAst.get(keyAst).booleanValue()) { + // 浮动,换算率值为空且主数量或数量为空,根据物料档案取换算率值,重新寻值 + if (itemVO.getVchangerate() == null && (itemVO.getNnum() == null || itemVO.getNastnum() == null)) { + if (cunitid.equals(castunitid)) { + vchangeRate = VCHANGERATE; + } + itemVO.setVchangerate(this.scaleUtils.adjustHslScale(vchangeRate)); + } + // 浮动 为空 计算主数量值 + if (itemVO.getNnum() == null) { + UFDouble nnum = HslParseUtil.hslMultiplyUFDouble(itemVO.getVchangerate(), itemVO.getNastnum()); + itemVO.setNnum(this.scaleUtils.adjustNumScale(nnum, itemVO.getCunitid())); + } else { + // 浮动 不为空 计算换算率 + String vhangerate = HslParseUtil.buildHslString(itemVO.getNnum(), itemVO.getNastnum()); + itemVO.setVchangerate(this.scaleUtils.adjustHslScale(vhangerate));// 处理换算率精度 + } + } else { + // 固定 浮动值空 + if (cunitid.equals(castunitid)) { + vchangeRate = VCHANGERATE; + } + itemVO.setVchangerate(this.scaleUtils.adjustHslScale(vchangeRate)); + // 主数量为空 计算值 +// if (itemVO.getNnum() == null) { + UFDouble nnum = HslParseUtil.hslMultiplyUFDouble(itemVO.getVchangerate(), itemVO.getNastnum()); + itemVO.setNnum(this.scaleUtils.adjustNumScale(nnum, itemVO.getCunitid())); +// } + } + + // 报价换算率 固定 为空 ,寻值 计算报价数量得值 + // 报价换算率不导,若报价数量为空,则根据换算率与主数量计算报价数量得值,若报价数量导入则根据主数量与报价数量计算报价换算率得值 + String vchangerate = ""; + if (itemVO.getNqtunitnum() == null || fixUnitRateQt.get(keyQt).booleanValue()) { + if (cunitid.equals(cqtunitid)) { + vchangerate = VCHANGERATE; + itemVO.setNqtunitnum(itemVO.getNnum()); + } else if (castunitid.equals(cqtunitid)) { + vchangerate = changerates.get(material + "-" + castunitid).getMeasrate(); + itemVO.setNqtunitnum(itemVO.getNastnum()); + } else { + vchangerate = changerates.get(material + "-" + cqtunitid).getMeasrate(); + UFDouble nastnum = CalculatorUtil.div(itemVO.getNnum(), HslParseUtil.getUFDoubleHsl(vchangerate)); + itemVO.setNqtunitnum(this.scaleUtils.adjustNumScale(nastnum, itemVO.getCqtunitid())); + } + if (fixUnitRateQt.get(keyQt).booleanValue()) { + // 固定 + itemVO.setVqtunitrate(this.scaleUtils.adjustHslScale(vchangerate)); + } else { + if (flagnnum.booleanValue()) { + // 浮动,根据报价数量与主数量计算 + String vhangerate = HslParseUtil.buildHslString(itemVO.getNnum(), itemVO.getNqtunitnum()); + // 若为浮动换算率,且报价数量不为空,则根据报价数量与主数量计算报价换算率得值 + itemVO.setVqtunitrate(this.scaleUtils.adjustHslScale(vhangerate)); + } else { + if (cunitid.equals(cqtunitid)) { + vchangerate = VCHANGERATE; + } else if (castunitid.equals(cqtunitid)) { + vchangerate = changerates.get(material + "-" + castunitid).getMeasrate(); + } else { + vchangerate = changerates.get(material + "-" + cqtunitid).getMeasrate(); + } + itemVO.setVqtunitrate(this.scaleUtils.adjustHslScale(vchangerate)); + } + } + } else { + // 浮动 不为空 计算换算率 + if (flagnnum.booleanValue()) { + // 浮动,根据报价数量与主数量计算 + String vhangerate = HslParseUtil.buildHslString(itemVO.getNnum(), itemVO.getNqtunitnum()); + // 若为浮动换算率,且报价数量不为空,则根据报价数量与主数量计算报价换算率得值 + itemVO.setVqtunitrate(this.scaleUtils.adjustHslScale(vhangerate)); + } else { + // 固定 + itemVO.setVqtunitrate(this.scaleUtils.adjustHslScale(vchangerate)); + } +// else { +// ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl +// .getNCLangRes().getStrByID("4004030_2", +// "2400403002-0259")/* +// * @res "该报价单位换算率为浮动换算率,报价数量必输,请重新导入" +// */); +// } + } + + // 创建数据集实例 初始化数据关系计算用的数据集 + IDataSetForCal data = new OrderDataSetForCal(itemVO, item, orderVO); + Calculator tool = new Calculator(data, this.scaleUtils); + // 创建参数实例,在计算的时候用来获得参数条件:是否含税优先等 + Condition cond = new Condition();// 创建参数实例 + // 设置是否进行本币换算 + cond.setIsCalLocalCurr(true); + // 设置调单价方式调折扣 + cond.setIsChgPriceOrDiscount(isChangePrice); + // 全局本位币计算方式 + cond.setGlobalLocalCurrencyEnable(publicLocalMnyCal); + // 集团本位币计算方式 + cond.setGroupLocalCurrencyEnable(groupLobalMnyCal); + cond.setOrigCurToGlobalMoney(isOrigCurToGlobalMoney); + cond.setOrigCurToGroupMoney(isOrigCurToGroupMoney); + // 设置是否固定单位换算率 + cond.setIsFixNchangerate( + null == fixUnitRateAst.get(keyAst) ? false : fixUnitRateAst.get(keyAst).booleanValue()); + // 是否固定报价单位换算率 + cond.setIsFixNqtunitrate( + null == fixUnitRateQt.get(keyQt) ? false : fixUnitRateQt.get(keyQt).booleanValue()); + + // 设置含税优先还是无税优先 + cond.setIsTaxOrNet(isTaxPricePriorToPrice); + Integer fbuysellflag = itemVO.getFbuysellflag(); + // 是否跨国业务(购销类型为出口销售、进口采购时,为跨国业务) + cond.setInternational(BuySellFlagEnum.IMPORT.value().equals(fbuysellflag) + || BuySellFlagEnum.OUTPUT.value().equals(fbuysellflag)); + // 两个参数 cond 为计算时的参数条件 +// if (!isTaxPricePriorToPrice) { +// // 若参数po28为无税单价优先,按照无税单价计算 +// itemKey = OrderItemVO.NQTORIGPRICE; +// } + itemKey = this.chekoutPriceCal(itemVO, isTaxPricePriorToPrice); + tool.calculate(cond, itemKey); + } + + // 计算总体积、数量、重量 + if (null != volumePieceCalc) { + volumePieceCalc.calc(rows);// 总体积、数量、重量计算 + } + } + + private UFDouble setDefultByNull(UFDouble pricaVal) { + return pricaVal == null ? UFDouble.ZERO_DBL : pricaVal; + } + + /** + * + * 判断根据什么值计算, po28含税优先还是无税优先: 触发单价金额算法的优先顺序是:含税金额、无税金额、含税净价、无税净价、含税单价、无税单价 + * 若导入值唯一,则按照导入值计算;如导入无税单价,但po28未含税优先,按照无税单价计算 + * + * @param itemVO + * @param isTaxPricePriorToPrice 含税优先 + * @return + * + */ + private String chekoutPriceCal(OrderItemVO itemVO, boolean isTaxPricePriorToPrice) { + // 无税金额 + UFDouble norigmny = this.setDefultByNull(itemVO.getNorigmny()); + // 无税净价 + UFDouble nqtorignetprice = this.setDefultByNull(itemVO.getNqtorignetprice()); + // 无税单价 + UFDouble nqtorigprice = this.setDefultByNull(itemVO.getNqtorigprice()); + + // 价税合计 + UFDouble norigtaxmny = this.setDefultByNull(itemVO.getNorigtaxmny()); + // 含税净价 + UFDouble nqtorigtaxnetprc = this.setDefultByNull(itemVO.getNqtorigtaxnetprc()); + // 含税单价 + UFDouble nqtorigtaxprice = this.setDefultByNull(itemVO.getNqtorigtaxprice()); + + // 是否赠品 + UFBoolean blargess = itemVO.getBlargess() == null ? UFBoolean.FALSE : itemVO.getBlargess(); + + // 金额判断,若只有一个有值,按照有值得计算,若两者都有值,按照无税优先还是含税优先 + if (norigmny.compareTo(UFDouble.ZERO_DBL) != 0 && norigtaxmny.compareTo(UFDouble.ZERO_DBL) != 0) { + // 无税有值,含税有值 + if (isTaxPricePriorToPrice) { + // 含税优先 + return OrderItemVO.NORIGTAXMNY; + } else { + return OrderItemVO.NORIGMNY; + } + } else if (norigmny.compareTo(UFDouble.ZERO_DBL) != 0) { + // 无税有值,含税无值,按照无税计算 + return OrderItemVO.NORIGMNY; + } else if (norigtaxmny.compareTo(UFDouble.ZERO_DBL) != 0) { + // 含税有值,无税无值,按照含税计算 + return OrderItemVO.NORIGTAXMNY; + } + + // 净价判断,若只有一个有值,按照有值得计算,若两者都有值,按照无税优先还是含税优先 + if (nqtorignetprice.compareTo(UFDouble.ZERO_DBL) != 0 && nqtorigtaxnetprc.compareTo(UFDouble.ZERO_DBL) != 0) { + // 无税有值,含税有值 + if (isTaxPricePriorToPrice) { + return OrderItemVO.NQTORIGTAXNETPRC; + } else { + return OrderItemVO.NQTORIGNETPRICE; + } + } else if (nqtorignetprice.compareTo(UFDouble.ZERO_DBL) != 0) { + // 无税有值,含税无值,按照无税计算 + return OrderItemVO.NQTORIGNETPRICE; + } else if (nqtorigtaxnetprc.compareTo(UFDouble.ZERO_DBL) != 0) { + // 含税有值,无税无值,按照含税计算 + return OrderItemVO.NQTORIGTAXNETPRC; + } + + // 单价判断,若只有一个有值,按照有值得计算,若两者都有值,按照无税优先还是含税优先 + if (nqtorigprice.compareTo(UFDouble.ZERO_DBL) != 0 && nqtorigtaxprice.compareTo(UFDouble.ZERO_DBL) != 0) { + // 无税有值,含税有值 + if (isTaxPricePriorToPrice) { + return OrderItemVO.NQTORIGTAXPRICE; + } else { + return OrderItemVO.NQTORIGPRICE; + } + } else if (nqtorigprice.compareTo(UFDouble.ZERO_DBL) != 0) { + // 无税有值,含税无值,按照无税计算 + return OrderItemVO.NQTORIGPRICE; + } else if (nqtorigtaxprice.compareTo(UFDouble.ZERO_DBL) != 0) { + // 含税有值,无税无值,按照含税计算 + return OrderItemVO.NQTORIGTAXPRICE; + } else if (UFBoolean.TRUE.equals(blargess) && nqtorigprice.compareTo(UFDouble.ZERO_DBL) == 0 + && nqtorigtaxprice.compareTo(UFDouble.ZERO_DBL) == 0) { + // NCC-306842 如果是赠品,并且含税单价、无税单价都是0,则随便返回一个值即可 + return OrderItemVO.NQTORIGTAXPRICE; + } + return null; + } + + /** + * + * @param panel + * @param rows + * @param isAst 是辅单位还是报价单位,是否是固定、浮动换算率 + * @return + */ + private Map isFixUnitRate(OrderVO vo, int[] rows, boolean isAst) { + Map map = new HashMap(); + List pk_materials = new ArrayList(); + List mainunits = new ArrayList(); + List otherunits = new ArrayList(); + for (int row = 0; row < rows.length; row++) { + String material = vo.getBVO()[rows[row]].getPk_material(); + String cunitid = vo.getBVO()[rows[row]].getCunitid(); + String castunitid = vo.getBVO()[rows[row]].getCastunitid(); + String cqtunitid = vo.getBVO()[rows[row]].getCqtunitid(); + pk_materials.add(material); + mainunits.add(cunitid); + if (isAst) { + otherunits.add(castunitid); + } else { + otherunits.add(cqtunitid); + } + } + if (CollectionUtils.isEmpty(pk_materials) || CollectionUtils.isEmpty(otherunits)) { + return map; + } + String[] materialsstr = pk_materials.toArray(new String[0]); + String[] mainunitsstr = mainunits.toArray(new String[0]); + String[] otherunitsstr = otherunits.toArray(new String[0]); + + map = MaterialPubService.queryIsFixedRateByMaterialAndMeasdocs(materialsstr, otherunitsstr); + Map mapRes = new HashMap(); + int count = pk_materials.size(); + for (int i = 0; i < count; i++) { + String keyRes = materialsstr[i] + mainunitsstr[i] + otherunitsstr[i]; + String keyTemp = materialsstr[i] + otherunitsstr[i]; + // 主单位或者要转换的单位为空 + if (StringUtil.isSEmptyOrNull(mainunitsstr[i]) || StringUtil.isSEmptyOrNull(otherunitsstr[i])) { + mapRes.put(keyRes, UFBoolean.FALSE); + } + // 主单位和要转换单位相同 + else if (otherunitsstr[i].equals(mainunitsstr[i])) { + mapRes.put(keyRes, UFBoolean.TRUE); + } + // 主单位和要转换单位不同,查询 + else { + mapRes.put(keyRes, map.get(keyTemp)); + } + } + return mapRes; + + } + + private boolean groupLobalMnyCal(String pk_group) { + String nc001 = PubSysParamUtil.getNC001(pk_group); + if (NCPara.NC001_NOUSEGROUPCURRTYPE.getName().equals(nc001)) { + return false; + } + return true; + } + + private boolean isChangePrice(String pk_org) { + return PUParaValue.po84.adjust_price == PUSysParamUtil.getPO84(pk_org); + } + + private boolean isOrigCurToGlobalMoney() { + String nc002 = PubSysParamUtil.getNC002(); + if (NCPara.NC001_CALCULATEBYORIGCURRTYPE.getName().equals(nc002)) { + return true; + } + return false; + } + + private boolean isOrigCurToGroupMoney(String pk_group) { + String nc001 = PubSysParamUtil.getNC001(pk_group); + if (NCPara.NC001_CALCULATEBYORIGCURRTYPE.getName().equals(nc001)) { + return true; + } + return false; + } + + private boolean isTaxPricePriorToPrice(String pk_org) { + boolean flag = true; + PricePriority pricePriority = PUSysParamUtil.getPO28(pk_org); + if (!PricePriority.TAXPRICE_PRIOR_TO_PRICE.equals(pricePriority)) { + flag = false; + } + return flag; + } + + private boolean publicLocalMnyCal() { + String nc002 = PubSysParamUtil.getNC002(); + if (NCPara.NC002_NOUSEGLOBALCURRTYPE.getName().equals(nc002)) { + return false; + } + return true; + } + + /** + * 报价单位 如果导入,校验报价单位是否属于物料档案中定义的主单位和辅单位,不属于时报错; + * 如果未导入,根据业务参数“采购订单默认报价单位”判断取主单位还是辅单位,如果参数为主单位则取主单位,如果参数为辅单位则取采购默认单位。 + * 校验单位与报价单位的值 + * + * @param orderItemVO + * @param measdocIDByPks + * @param measdocByVIDMap + * @param invBasVOs + * + */ + private void checkoutCasuitAndCquit(OrderItemVO orderItemVO, Map measdocIDByPks, + Map> measdocByVIDMap, Map invBasVOs) { + // 单位 若导入 校验单位是否属于物料档案中定义的主单位和辅单位;若未导入,首先取采购默认单位,然后再取主单位。 + if (orderItemVO.getCastunitid() == null) { + // 若未导入,首先取采购默认单位,然后再取主单位。 + if (measdocIDByPks == null || measdocIDByPks.get(orderItemVO.getPk_material()) == null) { + orderItemVO.setCastunitid(orderItemVO.getCunitid()); + } else { + orderItemVO.setCastunitid(measdocIDByPks.get(orderItemVO.getPk_material())); + } + } else { + // 导入 校验单位是否属于物料档案中定义的主单位和辅单位 + if (!invBasVOs.get(orderItemVO.getPk_material()).getPk_measdoc().equals(orderItemVO.getCastunitid()) + && ((measdocByVIDMap.isEmpty() || measdocByVIDMap.get(orderItemVO.getPk_material()).isEmpty()) + || !measdocByVIDMap.get(orderItemVO.getPk_material()) + .contains(orderItemVO.getCastunitid()))) { + ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4004020_0", + "04004020-0126")/* + * @res "该单位不属于物料档案中定义的主单位和辅单位,重新导入" + */); + } + } + + // 报价单位 + // 如果未导入,根据业务参数“采购订单默认报价单位”判断取主单位还是辅单位,如果参数为主单位则取主单位,如果参数为辅单位则取采购默认单位。 + if (orderItemVO.getCqtunitid() == null) { + // 获得组织级参数po94(报价单位取主单位还是辅单位) + PUParaValue.po94 po94 = PUSysParamUtil.getPO94(orderItemVO.getPk_org()); + if (po94.equals(PUParaValue.po94.CUNITID)) { // 主单位 + orderItemVO.setCqtunitid(orderItemVO.getCunitid()); + } else { + orderItemVO.setCqtunitid(orderItemVO.getCastunitid()); + } + } else { + // 导入 校验报价单位是否属于物料档案中定义的主单位和辅单位 + if (!invBasVOs.get(orderItemVO.getPk_material()).getPk_measdoc().equals(orderItemVO.getCqtunitid()) + && ((measdocByVIDMap.isEmpty() || measdocByVIDMap.get(orderItemVO.getPk_material()).isEmpty()) + || !measdocByVIDMap.get(orderItemVO.getPk_material()) + .contains(orderItemVO.getCqtunitid()))) { + ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4004020_0", + "04004020-0126")/* + * @res "该单位不属于物料档案中定义的主单位和辅单位,重新导入" + */); + } + } + } + + /** + * + * 设置表体组织汇率类型、汇率、日期的值 1.原币币种和本币币种一致时,折本汇率默认1,不取导入值;组织汇率类型、组织汇率来源日期为空。 + * + * @param headerVO + * @param orderItemVO + * @param bodyRateVals 存储汇率的集合 + * + */ + private void setBodyRateVal(OrderHeaderVO headerVO, OrderItemVO orderItemVO, + Map rateCacheMap) { + // 组织汇率类型 + String cratetype = orderItemVO.getCratetype(); + // 组织汇率来源日期 + UFLiteralDate dratedate = orderItemVO.getDratedate(); + // 折本汇率 + UFDouble nexchangerate = orderItemVO.getNexchangerate(); + + // 币种 + String corigcurrencyid = headerVO.getCorigcurrencyid(); + // 本币 + String ccurrencyid = orderItemVO.getCcurrencyid(); + // 订单日期 + UFDate date = headerVO.getDbilldate(); + + if (corigcurrencyid.equals(ccurrencyid)) { + orderItemVO.setNexchangerate(UFDouble.ONE_DBL); + orderItemVO.setCratetype(null); + orderItemVO.setDratedate(null); + orderItemVO.setFratecategory(null); + } else { + if (cratetype != null) { + UFBoolean flag = UFBoolean.FALSE; + if (RateTypeConstant.RATE_TYPE_MIDDLE.equals(cratetype) + || RateTypeConstant.RATE_TYPE_SELLING.equals(cratetype) + || RateTypeConstant.RATE_TYPE_FIX.equals(cratetype) + || RateTypeConstant.RATE_TYPE_CUSTOM.equals(cratetype)) { + flag = UFBoolean.TRUE; + } + if (!flag.booleanValue()) { + ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes() + .getStrByID("4004030_2", "2400403002-0356")/* + * @res + * "只支持组织汇率类型为:基准汇率方案-中间汇率,基准汇率方案-卖出汇率,自定义汇率,固定汇率,当前存在不支持的组织汇率类型,不能导入,请检查" + */); + } + // 用汇率类型+原币+本币拼接作为rateCacheMap的key + String key = orderItemVO.getCratetype() + corigcurrencyid + ccurrencyid; + if (!rateCacheMap.containsKey(key)) { + // 录入汇率类型,判断是否是自定义汇率或是固定汇率。 + RateReturnObject ratereturn = CurrencyRatePubService + .getCurrencyRateByRateType(orderItemVO.getCratetype(), corigcurrencyid, ccurrencyid, date); + // 折本汇率询不到提示“组织汇率来源类型询不到折本汇率,不能导入,请检查”。 + if (ratereturn == null || (ratereturn != null + && (ratereturn.getRate_category() != 7 && ratereturn.getRate_category() != 5) + && ratereturn.getRate().compareTo(UFDouble.ZERO_DBL) == 0)) { + ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes() + .getStrByID("4004030_2", "2400403002-0257")/* + * @res "组织汇率来源类型询不到折本汇率,不能导入,请检查" + */); + } + // 增加校验,若为自定义或固定,判断是否导入折本汇率,若未导入则报错 + if ((ratereturn.getRate_category() == 7 || ratereturn.getRate_category() == 5) + && nexchangerate == null) { + ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID( + "4004030_2", "2400403002-0308")/* + * @res "当组织汇率类型为自定义汇率或固定汇率时,折本汇率为空不能导入,请检查!" + */); + } + + rateCacheMap.put(key, ratereturn); + } + RateReturnObject ratereturnobject = rateCacheMap.get(key); + // 若导入三者,不进行后续逻辑,非自定义与固定 + if (ratereturnobject != null + && (ratereturnobject.getRate_category() != 5 && ratereturnobject.getRate_category() != 7)) { + if (cratetype != null && dratedate != null && nexchangerate != null) { + orderItemVO.setFratecategory(ratereturnobject.getRate_category()); + return; + } + } + + if (ratereturnobject != null && (ratereturnobject.getRate_category() == 5 + || ratereturnobject.getRate_category() == 7 || ratereturnobject.getRate_category() == 0 + || ratereturnobject.getRate_category() == 2)) { + // 固定,自定义,取录入的汇率 +// if(ratereturnobject.getRate_category()==5 || ratereturnobject.getRate_category() ==7) { +// orderItemVO.setCratetype(ratereturnobject.getPk_ratetype()); +// orderItemVO.setFratecategory(ratereturnobject.getRate_category()); +// }else { +// //重新询汇率 +// orderItemVO.setCratetype(ratereturnobject.getPk_ratetype()); +// orderItemVO.setDratedate(ratereturnobject.getDate()); +// orderItemVO.setFratecategory(ratereturnobject.getRate_category()); +// orderItemVO.setNexchangerate(ratereturnobject.getRate()); +// } + // 若录入取录入值 + // 若导入汇率类型与折本汇率,日期清空 + if (cratetype != null && nexchangerate != null) { + orderItemVO.setDratedate(null); + } else { + orderItemVO.setDratedate( + ratereturnobject.getDate() == null ? dratedate : ratereturnobject.getDate()); + } + orderItemVO.setCratetype(cratetype); + orderItemVO.setFratecategory(ratereturnobject.getRate_category()); + orderItemVO.setNexchangerate(nexchangerate == null ? ratereturnobject.getRate() : nexchangerate); + } else { + orderItemVO.setCratetype(null); + orderItemVO.setDratedate(null); + orderItemVO.setFratecategory(null); + } + } else { + // 组织汇率类型为空 + // 2) 只导入折本汇率:折本汇率取导入值,组织汇率类型、组织汇率来源日期为空。 + // 3) 只导入组织汇率来源日期:提示“不允许仅导入组织汇率来源日期,请导入组织汇率来源类型或折本汇率”。 + if (orderItemVO.getNexchangerate() == null && orderItemVO.getDratedate() != null) { + ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes() + .getStrByID("4004030_2", "2400403002-0258")/* + * @res "不允许仅导入组织汇率来源日期,请导入组织汇率来源类型或折本汇率" + */); + } + } + } + } + + /** + * + * 设置发货国、报货国 + * + * @param rows + * @param voHelper2 + * + */ + private void registerCountryRemoteCall(BillHelper voHelper, int[] rows) { + List countryList = new ArrayList(); + OrderSendCountrySetter setter = new OrderSendCountrySetter(voHelper, rows); + setter.setReset(true); + countryList.add(setter);// 发货国 + countryList.add(new OrderReceiveCountrySetter(voHelper, rows));// 收货国 + countryList.add(new OrderTaxCountrySetter(voHelper, rows));// 报税国 + setter.setCountry(); + OrderVatValueFillRule vatrule = new OrderVatValueFillRule(voHelper, rows, countryList); + vatrule.prepare(); + vatrule.setExcelImport(true); + vatrule.process(); + this.remoteCaller.put(OrderVatValueFillRule.class.getName(), vatrule); + } + + /** + * + * 计算计划到期日期 + * + * @param orderVO + * + */ + private void setPlanArriDate(BillHelper voHelper, int[] rows) { + new PlanArriveDate(voHelper).setPlanArriveDate(rows); + } + + /** + * + * 设置表体本位币与汇率信息 + * + * @param orderVO + * + */ + private void setCurrencyAndRate(BillHelper voHelper, int[] rows) { + CurrencyAndExchangerate currency = new CurrencyAndExchangerate(voHelper); +// currency.setCurrencyAndExchangeRate(rows); + currency.setCurrencyAndGroupRate(rows); + } + + /** + * + * 设置收货利润中心的值: 1.导入取导入值。 2.未导入 ①从收货仓库对应的利润中心带。 ② 仓库未带出,则从收货库存组织带, ③没有则从财务组织带。 + * ④若没有则从结算利润中心带出 pk_apliabcenter 结算利润中心最新版本 收货仓库 recvstordocs-》 + * + * @param orderItemVO + * @param storedocsByOrg 缓存集合 key(仓库)value利润中心 + * @param apliabcentersMapByApfinanceorg 收货库存组织获取的利润中心 + * @throws BusinessException + * + */ +// private void setArrLiabVals(OrderVO orderItemVO, Map storedocsByOrg, Map apliabcentersMapByApfinanceorg) throws BusinessException { +// Set recvstordocs = new HashSet(); +// Map vidByOids = new HashMap(); +// for (OrderItemVO itemVO : orderItemVO.getBVO()) { +// if (!StringUtil.isSEmptyOrNull(itemVO.getPk_recvstordoc())) { +// recvstordocs.add(itemVO.getPk_recvstordoc()); +// } +// } +// if (recvstordocs.isEmpty()) { +// return; +// } +// // 仓库获取利润中心 +// StordocVO[] stordocByPks = StordocPubService.queryStordocByPks(recvstordocs.toArray(new String[recvstordocs.size()]), new String[] { StordocVO.PROFITCENTRE }); +// for (StordocVO stordocVO : stordocByPks) { +// storedocsByOrg.put(stordocVO.getPk_stordoc(), stordocVO.getProfitcentre()); +// } +// Collection storedocs = storedocsByOrg.values(); +// ProfitCenterVO[] profits = NCLocator.getInstance().lookup(IProfitCenterPubService.class).queryProfitCenterVOByIDS(storedocs.toArray(new String[storedocs.size()])); +// for (ProfitCenterVO profit : profits) { +// vidByOids.put(profit.getPk_profitcenter(), profit.getPk_vid()); +// } +// // 设置表体的利润中心值 +// for (OrderItemVO itemVO : orderItemVO.getBVO()) { +// if (itemVO.getPk_arrliabcenter_v() == null) { +// if (storedocsByOrg.containsKey(itemVO.getPk_recvstordoc()) && storedocsByOrg.get(itemVO.getPk_recvstordoc()) != null) { +// itemVO.setPk_arrliabcenter(storedocsByOrg.get(itemVO.getPk_recvstordoc())); +// itemVO.setPk_arrliabcenter_v(vidByOids.get(itemVO.getPk_arrliabcenter_v())); +// } else if(itemVO.getPk_apliabcenter_v() != null) { +// itemVO.setPk_arrliabcenter(itemVO.getPk_apliabcenter()); +// itemVO.setPk_arrliabcenter_v(itemVO.getPk_apliabcenter_v()); +// } +// } +// } +// +// } + + /** + * + * 判断组织是否属于什么类型 + * + * @param pk_org 组织 + * @param type 类型 + * @param typeByOrg 类型分类 + * @return + * + */ + private boolean getOrgType(String pk_org, String type, Map typeByOrg) { + if (pk_org == null) { + return false; + } + // 将组织和类型联合作为key,组织是否属于类型作为value + String key = pk_org + type; + if (typeByOrg.containsKey(key)) { + return typeByOrg.get(key).booleanValue(); + } + + boolean istype = OrgUnitPubService.isTypeOf(pk_org, type); + typeByOrg.put(key, UFBoolean.valueOf(istype)); + return istype; + } + + /** + * + * 传入的值转Map + * + * @param profitCenterVOSByRelateOrgs + * @return + * + */ + private Map getMapBySet(ProfitCenterVO[] profitCenterVOSByRelateOrgs) { + Map pmap = new HashMap<>(); + for (ProfitCenterVO pvo : profitCenterVOSByRelateOrgs) { + if (pvo.getPforgvos() != null && pvo.getPforgvos().length > 0) { + pmap.put(pvo.getPforgvos()[0].getPk_businessunit(), pvo); + } + } + return pmap; + } + + /** + * + * 根据传入的map获取value值,返回类型为set + * + * @param planPandocIDs + * @return + * + */ + public String[] getpkDepts(Map> planPandocIDs) { + Set pk_deptIds = new HashSet(); + for (List plans : planPandocIDs.values()) { + for (String deptIds : plans) { + pk_deptIds.add(deptIds); + } + } + return pk_deptIds.toArray(new String[pk_deptIds.size()]); + } + + /** + * + * 查找物料所有得辅单位 + * + * @param material 物料集合 + * @param castunitids 单位集合 + * @return + * + */ + private Map> getCastunitidMapByTempTable(Set materials) { + Map> map = new HashMap>(); + SqlBuilder sql = new SqlBuilder(); + sql.append("SELECT DISTINCT pk_material, pk_measdoc, pk_materialconvert , ispumeasdoc "); + sql.append(" FROM bd_materialconvert WHERE dr=0 and "); + IDExQueryBuilder builder = new IDExQueryBuilder(PUTempTable.TMP_PO_21_67.name()); + sql.append(builder.buildSQL("pk_material", materials.toArray(new String[materials.size()]))); + IRowSet rowset = new DataAccessUtils().query(sql.toString()); + while (rowset.next()) { + String pk_material = rowset.getString(0);// 物料 + String pk_measdoc = rowset.getString(1);// 辅单位 + if (map.get(pk_material) == null) { + List list = new ArrayList(); + list.add(pk_measdoc); + map.put(pk_material, list); + } else { + map.get(pk_material).add(pk_measdoc); + } + } + return map; + } + + /** + * 补充表头VO 对应得集合 需带出得值 采购员 -》 cemployeeids-》采购部门 (Vid、Oid) 收货客户 -》 + * recvcustomers-》收货地址(收货地点、收货地区) 采购组织 -》 orgs (oid)-》采购组织Vid 供应商 -》 suppliers + * (vid)-》供应商Oid 开票供应商 -》 invcsuplliers (vid)-》开票供应商Oid 订单类型 -》 billtypes -》业务流程 + * 采购部门 -》 depts (vid)-》采购部门Oid 付款协议 payterms -》表体付款协议信息 + * + * @param vos + * @throws BusinessException + * + */ + private void fillHeadVo(OrderVO[] vos) throws BusinessException { + Set orgs = new HashSet(); + Set depts = new HashSet(); + List billtypes = new ArrayList(); + Set suppliers = new HashSet(); + Set cemployeeids = new HashSet(); + Set recvcustomers = new HashSet(); + Set invcsuplliers = new HashSet(); + Set payterms = new HashSet(); + for (OrderVO orderVO : vos) { + orgs.add(orderVO.getHVO().getPk_org()); + depts.add(orderVO.getHVO().getPk_dept_v()); + billtypes.add(orderVO.getHVO().getCtrantypeid()); + suppliers.add(orderVO.getHVO().getPk_supplier_v()); + cemployeeids.add(orderVO.getHVO().getCemployeeid()); + recvcustomers.add(orderVO.getHVO().getPk_recvcustomer_v()); + invcsuplliers.add(orderVO.getHVO().getPk_invcsupllier_v()); + if (orderVO.getHVO().getPk_payterm() != null) { + payterms.add(orderVO.getHVO().getPk_payterm()); + } + } + + // 采购组织Oid查询Vid的值 + Map vidsByOrgIDS = OrgUnitPubService.getNewVIDSByOrgIDS(orgs.toArray(new String[orgs.size()])); + // 订单类型查询订单类型编码 + Map trantypecodeByids = PfServiceScmUtil + .getTrantypecodeByids(billtypes.toArray(new String[billtypes.size()])); + // 采购部门Vid查Oid的值 + HashMap oidsByDeptVIDS = NCLocator.getInstance().lookup(IDeptPubService.class) + .getOIDSByDeptVIDS(depts.toArray(new String[depts.size()])); + // 根据采购组织获得组织本位币 + Map currByOrgs = OrgUnitPubService.queryOrgCurrByPk(orgs.toArray(new String[orgs.size()])); + // 供应商Vid查询供应商Oid的值 + Map supplierOidsByVid = SupplierPubService + .querySupplierOidsByVids(suppliers.toArray(new String[suppliers.size()])); + // 开票供应商Vid查询供应商Oid的值 + Map incvSupplierOidsByVid = SupplierPubService + .querySupplierOidsByVids(invcsuplliers.toArray(new String[invcsuplliers.size()])); + // 收货客户Vid查询收货客户Oid得值 + Map customerOidsByVid = CustomerPubService + .queryCustomerOidsByVids(recvcustomers.toArray(new String[recvcustomers.size()])); + + // 存储供应商档案的数据 + Map supplierInfosBySuplierAndOrg = new HashMap(); + // 存储查询到得采购部门Oid的数据 + Map cemployeeidsBycemIdAndOrg = new HashMap(); + // 存储查询到得业务流程的数据 + Map busiTypesByTypeAndOrg = new HashMap(); + // 获取供应商Oid的集合 +// Set supplierSet = new HashSet(supplierOidsByVid.values()); + Collection OidsValues = supplierOidsByVid.values(); + // 获取供应商默认的开户银行 + Map defaultBankAccbasVOBySupplier = SupplierPubService + .getDefaultBankAccbasVOBySupplier(OidsValues.toArray(new String[OidsValues.size()])); + + // 获取是否直运 + Collection typeCodevalues = trantypecodeByids.values(); + Map directPursByTypeCode = TrantypeUtil.getInstance() + .getDirectPurchaseAttr(typeCodevalues.toArray(new String[typeCodevalues.size()])); + // 存储查询到得采购部门Vid的数据 + Map cemployVidByOid = new HashMap(); + // 存储开票供应商Oid查询供应商Vid的值 + Map incvSupplierVidsByOid = new HashMap(); + // 设置表头的值 + for (OrderVO orderVO : vos) { + OrderHeaderVO headerVO = orderVO.getHVO(); + SupplierInfo supplierInfo = null; + if (headerVO.getStatus() == 0 || headerVO.getStatus() == 2) { + headerVO.setStatus(VOStatus.NEW); + } + headerVO.setNversion(UFDouble.ROUND_DOWN);// 版本 + // 单据状态为自由 + headerVO.setForderstatus(EnumBillStatus.FREE.toIntValue()); + // 制单人 + headerVO.setAttributeValue(OrderHeaderVO.BILLMAKER, AppContext.getInstance().getPkUser()); + // 制单日期 + headerVO.setDmakedate(AppContext.getInstance().getBusiDate()); + // 补货 + headerVO.setBisreplenish(UFBoolean.FALSE); + // 单据日期 + if (headerVO.getDbilldate() == null) { + headerVO.setDbilldate(AppContext.getInstance().getBusiDate()); + } + + if (headerVO.getPk_supplier() == null) { + headerVO.setPk_supplier(supplierOidsByVid.get(headerVO.getPk_supplier_v())); + } + if (headerVO.getPk_org_v() == null) { + headerVO.setPk_org_v(vidsByOrgIDS.get(headerVO.getPk_org())); + } + // 订单类型编码 + if (headerVO.getVtrantypecode() == null) { + headerVO.setVtrantypecode(trantypecodeByids.get(headerVO.getCtrantypeid())); + headerVO.setBdirect(directPursByTypeCode.get(headerVO.getVtrantypecode()));// 设置是否直运 + } + // 业务流程 + if (headerVO.getPk_busitype() == null) { + String busitype = null; + if (busiTypesByTypeAndOrg == null + || busiTypesByTypeAndOrg.get(headerVO.getVtrantypecode() + headerVO.getPk_org()) == null) { + busitype = NCLocator.getInstance().lookup(IPFConfig.class).retBusitypeCanStart( + POBillType.Order.getCode(), headerVO.getVtrantypecode(), headerVO.getPk_org(), + headerVO.getBillmaker()); + busiTypesByTypeAndOrg.put(headerVO.getVtrantypecode() + headerVO.getPk_org(), busitype); + } else { + busitype = busiTypesByTypeAndOrg.get(headerVO.getVtrantypecode() + headerVO.getPk_org()); + } + headerVO.setPk_busitype(busitype); + } + + // 若供应商档案中设置采购的信息且有值,则获取供应商档案的值 + if (supplierInfosBySuplierAndOrg.get(headerVO.getPk_supplier() + headerVO.getPk_org()) == null) { + supplierInfo = NCLocator.getInstance().lookup(IOrderSupplierQuery.class) + .querySupplier(headerVO.getPk_supplier(), headerVO.getPk_org()); + supplierInfosBySuplierAndOrg.put(headerVO.getPk_supplier() + headerVO.getPk_org(), supplierInfo); + } else { + supplierInfo = supplierInfosBySuplierAndOrg.get(headerVO.getPk_supplier() + headerVO.getPk_org()); + } + + // 订单日期 + if (headerVO.getDbilldate() == null) { + headerVO.setDbilldate(AppContext.getInstance().getBusiDate()); + } + // 整单扣税类别 + if (headerVO.getFhtaxtypeflag() == null) { + headerVO.setFhtaxtypeflag(EnumDiscounttaxtype.TAXOUT.toIntValue()); + } + + // 采购员 若导入则以导入为主;若未导入且物料档案有值,则取物料档案的值; + if (headerVO.getCemployeeid() != null) { + // 若导入,需带出采购部门得值 + String psndocID = null; + if (cemployeeidsBycemIdAndOrg == null + || cemployeeidsBycemIdAndOrg.get(headerVO.getPk_org() + headerVO.getCemployeeid()) == null) { + psndocID = PsndocPubService.queryDeptIDByPsndocID(headerVO.getPk_org(), headerVO.getCemployeeid()); + cemployeeidsBycemIdAndOrg.put(headerVO.getPk_org() + headerVO.getCemployeeid(), psndocID); + } else { + psndocID = cemployeeidsBycemIdAndOrg.get(headerVO.getPk_org() + headerVO.getCemployeeid()); + } + headerVO.setPk_dept(psndocID); + String cemployVid = ""; + if (!cemployVidByOid.isEmpty() && cemployVidByOid.get(psndocID) != null) { + // map中有,从map中获取 + cemployVid = cemployVidByOid.get(psndocID); + } else { + IDeptPubService serviceD = NCLocator.getInstance().lookup(IDeptPubService.class); + Map vids = serviceD.getLastVIDSByDeptIDS(new String[] { psndocID }); + cemployVidByOid.putAll(vids); + cemployVid = cemployVidByOid.get(psndocID); + } + // 根据部门Oid获得Vid + headerVO.setPk_dept_v(cemployVid); + } else if (headerVO.getCemployeeid() == null && supplierInfo.getRespPerson() != null) { + headerVO.setCemployeeid(supplierInfo.getRespPerson()); + } + // 采购部门 + if (headerVO.getPk_dept() == null && headerVO.getPk_dept_v() != null) { + headerVO.setPk_dept(oidsByDeptVIDS.get(headerVO.getPk_dept_v())); + } + // 开票供应商 + if (headerVO.getPk_invcsupllier() == null && headerVO.getPk_invcsupllier_v() != null) { + // 若导入则以导入为主 + headerVO.setPk_invcsupllier(incvSupplierOidsByVid.get(headerVO.getPk_supplier())); + } else if (supplierInfo.getBillingSupplier() != null && headerVO.getPk_invcsupllier() == null) { + // 开票供应商 若未导入且物料档案有值,则取物料档案的值(开票供应商Vid字段未设置); + headerVO.setPk_invcsupllier(supplierInfo.getBillingSupplier()); + String[] pks = { supplierInfo.getBillingSupplier() }; + if (incvSupplierVidsByOid.isEmpty() + || incvSupplierVidsByOid.get(supplierInfo.getBillingSupplier()) == null) { + // 调用scmpub封装的方法根据供应商oid查询vid + incvSupplierVidsByOid.putAll(SupplierPubService.querySupplierVidsByOids(pks)); + } + headerVO.setPk_invcsupllier_v(incvSupplierVidsByOid.get(supplierInfo.getBillingSupplier())); + } else if (supplierInfo.getBillingSupplier() == null && headerVO.getPk_invcsupllier() == null + && headerVO.getPk_invcsupllier_v() == null) { + // 若供应商档案无值且未导入 取供应商的值 + headerVO.setPk_invcsupllier(headerVO.getPk_supplier()); + headerVO.setPk_invcsupllier_v(headerVO.getPk_supplier_v()); + } + // 运输方式 若导入以导入为主;若未导入且物料档案有值,获取物料档案值 + if (headerVO.getPk_transporttype() == null && supplierInfo.getTransportType() != null) { + headerVO.setPk_transporttype(supplierInfo.getTransportType()); + } + // 付款协议 若导入以导入为主;若未导入且物料档案有值,获取物料档案值 + if (headerVO.getPk_payterm() == null && supplierInfo.getDefaultPaymentTerm() != null) { + headerVO.setPk_payterm(supplierInfo.getDefaultPaymentTerm()); + payterms.add(headerVO.getPk_payterm()); + } + // 币种 若导入以导入为主;若未导入且物料档案有值,获取物料档案值;若未导入且供应商档案无值 获取组织本位币 + if (supplierInfo.getDefaultCurrency() != null && headerVO.getCorigcurrencyid() == null) { + headerVO.setCorigcurrencyid(supplierInfo.getDefaultCurrency()); + } else if (headerVO.getCorigcurrencyid() == null) { + headerVO.setCorigcurrencyid(currByOrgs.get(headerVO.getPk_org())); + } + // 开户银行 若导入以导入为主;若未导入且物料档案有值,获取物料档案值 + if (headerVO.getPk_bankdoc() == null && supplierInfo.getBankAccount() != null) { + headerVO.setPk_bankdoc(supplierInfo.getBankAccount()); + } + // 供应商发货地址 若导入以导入为主;若未导入且物料档案有值,获取物料档案值;表体得供应商发货地址获取表头得供应商发货地址得值 + if (headerVO.getPk_deliveradd() == null && supplierInfo.getAddress() != null) { + headerVO.setPk_deliveradd(supplierInfo.getAddress()); + } + // 付款协议:若导入以导入为主; 未导入 取供应商档案默认的付款协议 + if (headerVO.getPk_payterm() == null && supplierInfo.getDefaultPaymentTerm() != null) { + headerVO.setPk_payterm(supplierInfo.getDefaultPaymentTerm()); + } + + // 收货客户 + if (headerVO.getPk_recvcustomer() == null && headerVO.getPk_recvcustomer_v() != null) { + headerVO.setPk_recvcustomer(customerOidsByVid.get(headerVO.getPk_recvcustomer_v())); + } + + // 开户银行 + if (headerVO.getPk_bankdoc() == null + && defaultBankAccbasVOBySupplier.get(headerVO.getPk_supplier()) != null) { + String defaultBankAcc = SupplierPubService.getDefaultBankAcc(headerVO.getPk_supplier()); + headerVO.setPk_bankdoc(defaultBankAcc); + headerVO.setAttributeValue(OrderHeaderVO.VBANKACCOUNT, + defaultBankAccbasVOBySupplier.get(headerVO.getPk_supplier())[1]); + } + + // 退货/库基于原订单补货 + if (headerVO.getBrefwhenreturn() == null) { + headerVO.setBrefwhenreturn(UFBoolean.FALSE); + } + // 退货 + if (headerVO.getBreturn() == null) { + headerVO.setBreturn(UFBoolean.FALSE); + } + // 是否直运 + if (headerVO.getBdirect() == null) { + headerVO.setBdirect(UFBoolean.FALSE); + } + } + // 根据付款协议主键查询付款协议数据,设置表体协议数据 + this.setPayMents(vos, payterms); + } + + /** + * + * 设置表体付款协议数据 + * + * @param vos + * @param payterms + * + */ + private void setPayMents(OrderVO[] vos, Set payterms) { + // 设置表体获取付款协议的值 + // Map paymentVOs = this.getOrderPaymentVOs(payterms); + // YBP-SCM-BUG-213 NCC-368292 导入多单且付款协议相同时,只导入成功了第一单,后面几单都没导入成功 + Map paymentVOs = this.queryPaymentVOs(payterms); + for (OrderVO orderVO : vos) { + BillHelper helper = new BillHelper(orderVO); + OrderHeaderVO headerVO = orderVO.getHVO(); + // 设置付款协议 + if (!paymentVOs.isEmpty() && paymentVOs.get(headerVO.getPk_payterm()) != null) { + // OrderPaymentVO[] orderPaymentVOs = paymentVOs.get(headerVO.getPk_payterm()); + PaymentVO paymentvo = paymentVOs.get(headerVO.getPk_payterm()); + OrderPaymentVO[] newOrderPaymentVOs = this.getOrderPaymentVOs(paymentvo); + // 如果付款计划相同,这里是一个对象,第一条保存完成之后,会有主键冲突的问题 + // OrderPaymentVO[] newOrderPaymentVOs = (OrderPaymentVO[])new + // DeepCloneTool().deepClone(orderPaymentVOs); + helper.setBodyVOs(newOrderPaymentVOs, OrderPaymentVO.class); + } + } + } + + /** + * YBP-SCM-BUG-213 NCC-368292 导入多单且付款协议相同时,只导入成功了第一单,后面几单都没导入成功 获取付款协议档案 + * + * @param pk_payterm + * @return + */ + private Map queryPaymentVOs(Set pk_payterm) { + Map paymentVOMaps = new HashMap(); + if (pk_payterm.size() == 0) { + return paymentVOMaps; + } + SuperVO[] vos = PaymentService.queryPaymentByIds(pk_payterm.toArray(new String[pk_payterm.size()]), + PaymentVO.class); + if (vos != null && vos.length > 0) { + for (SuperVO vo : vos) { + if (vo instanceof PaymentVO) { + PaymentVO paymentVo = (PaymentVO) vo; + String hid = paymentVo.getPk_payment(); + paymentVOMaps.put(hid, paymentVo); + } + } + } + return paymentVOMaps; + } + + /** + * YBP-SCM-BUG-213 NCC-368292 导入多单且付款协议相同时,只导入成功了第一单,后面几单都没导入成功 + * 根据付款协议档案生成采购订单的付款计划子表数据 + * + * @param payVO + * @return + */ + private OrderPaymentVO[] getOrderPaymentVOs(PaymentVO payVO) { + OrderPaymentVO[] orderPayments = null; + if (payVO == null) { + return orderPayments; + } + PaymentChVO[] paybodys = payVO.getPaymentch(); + if (paybodys != null && paybodys.length > 0) { + orderPayments = new OrderPaymentVO[paybodys.length]; + for (int i = 0; i < paybodys.length; i++) { + PaymentChVO vo = paybodys[i]; + orderPayments[i] = new OrderPaymentVO(); + orderPayments[i].setAttributeValue(OrderPaymentVO.SHOWORDER, + vo.getAttributeValue(OrderPaymentVO.SHOWORDER)); + orderPayments[i].setAttributeValue(OrderPaymentVO.ACCRATE, + vo.getAttributeValue(OrderPaymentVO.ACCRATE)); + orderPayments[i].setAttributeValue(OrderPaymentVO.PREPAYMENT, + vo.getAttributeValue(OrderPaymentVO.PREPAYMENT)); + orderPayments[i].setAttributeValue(OrderPaymentVO.EFFECTADDMONTH, + vo.getAttributeValue(OrderPaymentVO.EFFECTADDMONTH)); + orderPayments[i].setAttributeValue(OrderPaymentVO.EFFECTMONTH, + vo.getAttributeValue(OrderPaymentVO.EFFECTMONTH)); + orderPayments[i].setAttributeValue(OrderPaymentVO.EFFECTDATEADDDATE, + vo.getAttributeValue(OrderPaymentVO.EFFECTDATEADDDATE)); + orderPayments[i].setAttributeValue(OrderPaymentVO.PK_PAYPERIOD, + vo.getAttributeValue(OrderPaymentVO.PK_PAYPERIOD)); + orderPayments[i].setAttributeValue(OrderPaymentVO.PK_BALATYPE, + vo.getAttributeValue(OrderPaymentVO.PK_BALATYPE)); + orderPayments[i].setAttributeValue(OrderPaymentVO.PK_RATE, + vo.getAttributeValue(OrderPaymentVO.PK_RATE)); + orderPayments[i].setAttributeValue(OrderPaymentVO.PAYMENTDAY, + vo.getAttributeValue(OrderPaymentVO.PAYMENTDAY)); + orderPayments[i].setAttributeValue(OrderPaymentVO.CHECKDATA, + vo.getAttributeValue(OrderPaymentVO.CHECKDATA)); + orderPayments[i].setAttributeValue(OrderPaymentVO.ISDEPOSIT, + vo.getAttributeValue(OrderPaymentVO.ISDEPOSIT)); + orderPayments[i].setAttributeValue(OrderPaymentVO.ACCOUNTDAY, + vo.getAttributeValue(OrderPaymentVO.ACCOUNTDAY)); + } + } + return orderPayments; + } + + /** + * 获取付款协议页签VO + * + * @param pk_payterm 付款协议档案主键 + * @return + */ +// private Map getOrderPaymentVOs(Set pk_payterm) { +// Map paymentVOMaps = new HashMap(); +// if (pk_payterm.size() == 0 ) { +// return paymentVOMaps; +// } +// SuperVO[] vos = PaymentService.queryPaymentByIds(pk_payterm.toArray(new String[pk_payterm.size()]), PaymentVO.class); +// +// for (SuperVO supvo : vos) { +// if (paymentVOMaps.get(supvo.getAttributeValue("pk_payment").toString()) != null) { +// continue; +// } +// PaymentChVO[] chvos = ((PaymentVO) supvo).getPaymentch(); +// OrderPaymentVO[] paymentVOs = new OrderPaymentVO[chvos.length]; +// for (int i = 0; i < chvos.length; i++) { +// PaymentChVO vo = chvos[i]; +// paymentVOs[i] = new OrderPaymentVO(); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.SHOWORDER, +// vo.getAttributeValue(OrderPaymentVO.SHOWORDER)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.ACCRATE, +// vo.getAttributeValue(OrderPaymentVO.ACCRATE)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.PREPAYMENT, +// vo.getAttributeValue(OrderPaymentVO.PREPAYMENT)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.EFFECTADDMONTH, +// vo.getAttributeValue(OrderPaymentVO.EFFECTADDMONTH)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.EFFECTMONTH, +// vo.getAttributeValue(OrderPaymentVO.EFFECTMONTH)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.EFFECTDATEADDDATE, +// vo.getAttributeValue(OrderPaymentVO.EFFECTDATEADDDATE)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.PK_PAYPERIOD, +// vo.getAttributeValue(OrderPaymentVO.PK_PAYPERIOD)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.PK_BALATYPE, +// vo.getAttributeValue(OrderPaymentVO.PK_BALATYPE)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.PK_RATE, +// vo.getAttributeValue(OrderPaymentVO.PK_RATE)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.PAYMENTDAY, +// vo.getAttributeValue(OrderPaymentVO.PAYMENTDAY)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.CHECKDATA, +// vo.getAttributeValue(OrderPaymentVO.CHECKDATA)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.ISDEPOSIT, +// vo.getAttributeValue(OrderPaymentVO.ISDEPOSIT)); +// paymentVOs[i].setAttributeValue(OrderPaymentVO.ACCOUNTDAY, +// vo.getAttributeValue(OrderPaymentVO.ACCOUNTDAY)); +// } +// paymentVOMaps.put(supvo.getAttributeValue("pk_payment").toString(), paymentVOs); +// } +// +// return paymentVOMaps; +// } + + private static class OrderDataSetForCal extends VODataSetForCal { + private OrderVO orderVO; + + public OrderDataSetForCal(CircularlyAccessibleValueObject currVO, IRelationForItems item, OrderVO orderVO) { + super(currVO, item); + this.orderVO = orderVO; + } + + @Override + public UFDate getBillDate() { + return this.orderVO.getHVO().getDbilldate(); + } + + /** 获得原币币种 */ + @Override + public String getCorigcurrencyid() { + return this.orderVO.getHVO().getCorigcurrencyid(); + } + + @Override + public boolean hasItemKey(String key) { + if (OrderHeaderVO.CORIGCURRENCYID.equals(key)) { + return true; + } else if (OrderHeaderVO.DBILLDATE.equals(key)) { + return true; + } else { + return super.hasItemKey(key); + } + } + } +}