From 5c25a7df9d4735fe81cd88fb3572eeab4f34cf56 Mon Sep 17 00:00:00 2001 From: lihao Date: Tue, 3 Feb 2026 16:38:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E5=8A=9B=E7=94=B5=E5=AD=90=E8=B4=9F?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pwr/action/PwrCheckRewriteAction.java | 731 ++++++++++++------ 1 file changed, 506 insertions(+), 225 deletions(-) diff --git a/mmpac/src/client/nccloud/web/mmpac/pwr/action/PwrCheckRewriteAction.java b/mmpac/src/client/nccloud/web/mmpac/pwr/action/PwrCheckRewriteAction.java index eb90102e..cf1f4463 100644 --- a/mmpac/src/client/nccloud/web/mmpac/pwr/action/PwrCheckRewriteAction.java +++ b/mmpac/src/client/nccloud/web/mmpac/pwr/action/PwrCheckRewriteAction.java @@ -94,24 +94,25 @@ public class PwrCheckRewriteAction implements ICommonAction { if (MMValueCheck.isEmpty(aggvos)) { ExceptionUtils.wrappBusinessException(PMOConstLang.getMSG_REWRITE_WRNUM_AUTOERROR()); } - for (PMOAggVO aggvo : aggvos) { - String pkOrg = aggvo.getParentVO().getPk_org(); - String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); - if (checkIfOrg(orgCode, configParams)) { - - } - } + // for (PMOAggVO aggvo : aggvos) { + // String pkOrg = aggvo.getParentVO().getPk_org(); + // String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); + // if (checkIfOrg(orgCode, configParams)) { + // + // } + // } Set originbidSet = new HashSet(); Set bidSet = paraMapList.keySet(); Map headMap = new HashMap(); Map itemMap = new HashMap(); + Map itemMap2 = new HashMap(); for(PMOAggVO aggvo : aggvos) { PMOHeadVO headvo = aggvo.getParentVO(); String pkOrg = aggvo.getParentVO().getPk_org(); String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg); - if (checkIfOrg(orgCode, configParams)) { + if (!checkIfOrg(orgCode, configParams,"planOrg")) { continue; } if (hidList.contains(headvo.getCpmohid())) { @@ -123,276 +124,556 @@ public class PwrCheckRewriteAction implements ICommonAction { for(PMOItemVO item : items) { originbidSet.add(item.getCmoid()); if (bidSet.contains(item.getCmoid())) { - itemMap.put(item.getCmoid(), item); + if (checkIfOrg(orgCode, configParams,"xbOrg")){ + itemMap.put(item.getCmoid(), item); + } else if (checkIfOrg(orgCode, configParams,"dldzOrg")) { + itemMap2.put(item.getCmoid(), item); + } } } } } - if (MMMapUtil.isEmpty(itemMap)) { + if (MMMapUtil.isEmpty(itemMap) && MMMapUtil.isEmpty(itemMap2)) { return 0; } + if (!MMMapUtil.isEmpty(itemMap)) { + PMOItemVO[] items = (PMOItemVO[])itemMap.values().toArray(new PMOItemVO[0]); - PMOItemVO[] items = (PMOItemVO[])itemMap.values().toArray(new PMOItemVO[0]); - - for(PMORewriteParaVO para : paras) { - if (!originbidSet.contains(para.getCpmobid())) { - ExceptionUtils.wrappBusinessException(PMOConstLang.getMSG_PMO_DeleteLine()); - } - } - - BDPKLockUtil.lockSuperVO(items); - this.checkMOstatus(items, headMap); - Set cmaterials = new HashSet(); - Set ctrantypes = new HashSet(); - Set pk_orgs = new HashSet(); - MapList sortOrgMarMap = new MapList(); - - for(PMOItemVO item : items) { - if (!cmaterials.contains(item.getCmaterialvid())) { - cmaterials.add(item.getCmaterialvid()); + for(PMORewriteParaVO para : paras) { + if (!originbidSet.contains(para.getCpmobid())) { + ExceptionUtils.wrappBusinessException(PMOConstLang.getMSG_PMO_DeleteLine()); + } } - PMOHeadVO head = (PMOHeadVO)headMap.get(item.getCpmohid()); - if (!MMValueCheck.isEmpty(head) && !ctrantypes.contains(head.getCtrantypeid())) { - ctrantypes.add(head.getCtrantypeid()); + BDPKLockUtil.lockSuperVO(items); + this.checkMOstatus(items, headMap); + Set cmaterials = new HashSet(); + Set ctrantypes = new HashSet(); + Set pk_orgs = new HashSet(); + MapList sortOrgMarMap = new MapList(); + + for(PMOItemVO item : items) { + if (!cmaterials.contains(item.getCmaterialvid())) { + cmaterials.add(item.getCmaterialvid()); + } + + PMOHeadVO head = (PMOHeadVO)headMap.get(item.getCpmohid()); + if (!MMValueCheck.isEmpty(head) && !ctrantypes.contains(head.getCtrantypeid())) { + ctrantypes.add(head.getCtrantypeid()); + } + + if (!pk_orgs.contains(item.getPk_org())) { + pk_orgs.add(item.getPk_org()); + } + + sortOrgMarMap.put(item.getPk_org(), item.getCmaterialvid()); } - if (!pk_orgs.contains(item.getPk_org())) { - pk_orgs.add(item.getPk_org()); + Map prodtolerance = new HashMap(); + + for(Map.Entry> entry : sortOrgMarMap.entrySet()) { + Map tempdowntolerance = PMOBPCalUtil.getProdtolerance((String)entry.getKey(), (String[])((List)entry.getValue()).toArray(new String[0])); + if (MMMapUtil.isNotEmpty(tempdowntolerance)) { + prodtolerance.putAll(tempdowntolerance); + } } - sortOrgMarMap.put(item.getPk_org(), item.getCmaterialvid()); - } + Map intolerance = PMOBPCalUtil.getInStockControlScope((String[])cmaterials.toArray(new String[0])); + Map autodonepara = PMOBPService.getIPMOTransTypeQueryService().getBAutoFinishByTranTypeIDs((String[])ctrantypes.toArray(new String[0])); + Map bpara = MMBDFactoryParameter.getPAC012BatchParaBoolean((String[])pk_orgs.toArray(new String[0])); + this.checkWrts(paraMapList, items); + List planoutputList = new ArrayList(); - Map prodtolerance = new HashMap(); + for(int i = 0; i < items.length; ++i) { + List paraList = paraMapList.get(items[i].getCmoid()); + PMOPlanOutputVO[] moPlanOutVOS = items[i].getPlanoutputs(); + if (!MMArrayUtil.isEmpty(moPlanOutVOS)) { + for(PMOPlanOutputVO planOutVO : moPlanOutVOS) { + boolean isupd = false; - for(Map.Entry> entry : sortOrgMarMap.entrySet()) { - Map tempdowntolerance = PMOBPCalUtil.getProdtolerance((String)entry.getKey(), (String[])((List)entry.getValue()).toArray(new String[0])); - if (MMMapUtil.isNotEmpty(tempdowntolerance)) { - prodtolerance.putAll(tempdowntolerance); - } - } + for(PMORewriteParaVO paravo : paraList) { + if (!MMMapUtil.isEmpty(paravo.getPoutMap())) { + UFDouble delNum = MMNumberUtil.toNotNullValue((UFDouble)paravo.getPoutMap().get(planOutVO.getCplanoutputid())); + if (MMNumberUtil.isNotNullAndNotZero(delNum)) { + (new NumScaleUtil()).checkNumberScale(new UFDouble[]{delNum}, planOutVO.getCunitid()); + } - Map intolerance = PMOBPCalUtil.getInStockControlScope((String[])cmaterials.toArray(new String[0])); - Map autodonepara = PMOBPService.getIPMOTransTypeQueryService().getBAutoFinishByTranTypeIDs((String[])ctrantypes.toArray(new String[0])); - Map bpara = MMBDFactoryParameter.getPAC012BatchParaBoolean((String[])pk_orgs.toArray(new String[0])); - this.checkWrts(paraMapList, items); - List planoutputList = new ArrayList(); - - for(int i = 0; i < items.length; ++i) { - List paraList = paraMapList.get(items[i].getCmoid()); - PMOPlanOutputVO[] moPlanOutVOS = items[i].getPlanoutputs(); - if (!MMArrayUtil.isEmpty(moPlanOutVOS)) { - for(PMOPlanOutputVO planOutVO : moPlanOutVOS) { - boolean isupd = false; - - for(PMORewriteParaVO paravo : paraList) { - if (!MMMapUtil.isEmpty(paravo.getPoutMap())) { - UFDouble delNum = MMNumberUtil.toNotNullValue((UFDouble)paravo.getPoutMap().get(planOutVO.getCplanoutputid())); - if (MMNumberUtil.isNotNullAndNotZero(delNum)) { - (new NumScaleUtil()).checkNumberScale(new UFDouble[]{delNum}, planOutVO.getCunitid()); + if (MMNumberUtil.isNotNullAndNotZero(delNum)) { + UFDouble wrNum = MMNumberUtil.add(new UFDouble[]{delNum, MMNumberUtil.toNotNullValue(planOutVO.getNwrnum())}); + planOutVO.setNwrnum(wrNum); + planOutVO.setStatus(1); + PMOBPCalUtil.fillReAssNumber("nplanoutputnum", "nastplanoutputnum", planOutVO, "vchangerate", "nwrnum", "nwrastnum"); + isupd = true; + } } + } - if (MMNumberUtil.isNotNullAndNotZero(delNum)) { - UFDouble wrNum = MMNumberUtil.add(new UFDouble[]{delNum, MMNumberUtil.toNotNullValue(planOutVO.getNwrnum())}); - planOutVO.setNwrnum(wrNum); - planOutVO.setStatus(1); - PMOBPCalUtil.fillReAssNumber("nplanoutputnum", "nastplanoutputnum", planOutVO, "vchangerate", "nwrnum", "nwrastnum"); - isupd = true; + if (isupd) { + planoutputList.add(planOutVO); + } + } + } + + for(PMORewriteParaVO paravo : paraList) { + UFDouble delNum = MMNumberUtil.toNotNullValue(paravo.getDelNum()); + if (MMNumberUtil.isNotNullAndNotZero(delNum)) { + (new NumScaleUtil()).checkNumberScale(new UFDouble[]{delNum}, items[i].getCunitid()); + } + + UFDouble wrNum = MMNumberUtil.add(new UFDouble[]{delNum, MMNumberUtil.toNotNullValue(items[i].getNwrnum())}); + items[i].setNwrnum(wrNum); + PMOBPCalUtil.fillReAssNumber("nplanputnum", "nplanputastnum", items[i], "vchangerate", "nwrnum", "nwrastnum"); + items[i].setStatus(1); + } + } + + List filterList = new ArrayList(); + List putplanfinishList = new ArrayList(); + + + + + + for(PMOItemVO item : items) { + String var10001 = item.getPk_org(); + UFDouble downPara = (UFDouble)prodtolerance.get(var10001 + "#" + item.getCmaterialvid()); + UFDouble compareplanputnum = item.getNplanputnum(); + if (MMNumberUtil.isGtZero(downPara)) { + compareplanputnum = MMNumberUtil.multiply(new UFDouble[]{item.getNplanputnum(), MMNumberUtil.sub(UFDouble.ONE_DBL, new UFDouble[]{downPara.div((double)100.0F)})}); + } + + UFBoolean flag = UFBoolean.FALSE; + if (!MMMapUtil.isEmpty(bpara)) { + flag = (UFBoolean)bpara.get(item.getPk_org()); + if (null == flag) { + flag = UFBoolean.FALSE; + } + } + + if (flag.booleanValue()) { + UFDouble dpara = (UFDouble)intolerance.get(item.getCmaterialvid()); + UFDouble dparabl = UFDouble.ONE_DBL; + if (!MMValueCheck.isEmpty(bpara)) { + dparabl = MMNumberUtil.add(new UFDouble[]{UFDouble.ONE_DBL, dpara.div((double)100.0F)}); + } + + UFDouble totalputnum = MMNumberUtil.add(new UFDouble[]{item.getNplanputnum(), item.getNrejectnum()}); + if (MMNumberUtil.isLsEqual(item.getNwrnum(), MMNumberUtil.multiply(new UFDouble[]{totalputnum, dparabl}))) { + filterList.add(item); + } + + if (MMNumberUtil.isGtEqual(item.getNwrnum(), compareplanputnum) && !MMMapUtil.isEmpty(autodonepara)) { + PMOHeadVO head = (PMOHeadVO)headMap.get(item.getCpmohid()); + UFBoolean autoFlag = (UFBoolean)autodonepara.get(head.getCtrantypeid()); + if (autoFlag.booleanValue()) { + BaseDAO dao = new BaseDAO(); + // 查询备料计划 如果下游备料计划未出库数量(计划出库-累计出库)小于0,生产订单自动完工取消 naccoutnum 累计出库数量 nplanoutnum计划出库 + String pickmsql = "select cbmaterialvid,vrowno,nplanoutnum,naccoutnum from mm_pickm_b where cpickmid in ( select cpickmid from mm_pickm where csourcebillrowid='" + item.getCmoid() + "' and dr=0) and dr = 0"; + List> hmateral = (List>) dao.executeQuery(pickmsql, new MapListProcessor()); + List vrownos = new ArrayList(); + List> maps = new ArrayList(); + + Boolean l=false; + for (Map map : hmateral) { + String material =MaterialVO.CODE+","+MaterialVO.NAME+","+MaterialVO.OUTTOLERANCE; + if(map.get("naccoutnum") == null){ + map.put("naccoutnum", 0); + } + // 物料出库容差 % 0.0000 + Map goodsMap = MyHelper.transferFields(MaterialVO.getDefaultTableName(), material, MaterialVO.PK_MATERIAL, item.getCmaterialvid()); + String Outtolerance= null !=goodsMap.get("outtolerance") ? goodsMap.get("outtolerance").toString() : "0"; + if(null != map.get("nplanoutnum") && null != map.get("naccoutnum") && (new UFDouble(String.valueOf(map.get("nplanoutnum").toString())).sub(new UFDouble(String.valueOf(map.get("naccoutnum").toString()))).abs()).compareTo(new UFDouble(String.valueOf(map.get("nplanoutnum").toString())).multiply(new UFDouble(String.valueOf(Outtolerance.toString())))) > 0) { + l=true; + Map map1 =new HashMap<>(); + map1.put("vrowno",map.get("vrowno").toString()); + map1.put("mrlname",goodsMap.get("name").toString()); + map1.put("mrlcode",goodsMap.get("code").toString()); + maps.add(map1); + } } + if(l){ + // String pickm = " select vbillcode,cpickmid from mm_pickm where csourcebillrowid='" + item.getCmoid() + "' and dr=0"; + // List> pickms = (List>) dao.executeQuery(pickm, new MapListProcessor()); + String err=""; + for (Map vrowno : maps) { + String pmobillcode= head.getVbillcode(); + String pmovrowno= item.getVrowno(); + // String pickmbillcode= pickms.get(0).get("vbillcode").toString(); + String pickmvrowno= vrowno.get("vrowno").toString(); + String mrlname= vrowno.get("mrlname").toString(); + String mrlcode= vrowno.get("mrlcode").toString(); + err=err+"生产订单"+pmobillcode+"行"+pmovrowno+"的备料计划行"+pickmvrowno+"物料【"+mrlcode+","+mrlname+"】检查不通过\n"; + } + return err; + } + item.setFitemstatus(Integer.valueOf(PMOFItemStatusEnum.FINISH.getEnumValue().getValue())); + item.setTactendtime(new UFDateTime(AppBsContext.getInstance().getBusiDate().toPersisted())); + item.setStatus(1); + putplanfinishList.add(item.getCmoid()); } } - if (isupd) { - planoutputList.add(planOutVO); - } - } - } - - for(PMORewriteParaVO paravo : paraList) { - UFDouble delNum = MMNumberUtil.toNotNullValue(paravo.getDelNum()); - if (MMNumberUtil.isNotNullAndNotZero(delNum)) { - (new NumScaleUtil()).checkNumberScale(new UFDouble[]{delNum}, items[i].getCunitid()); - } - - UFDouble wrNum = MMNumberUtil.add(new UFDouble[]{delNum, MMNumberUtil.toNotNullValue(items[i].getNwrnum())}); - items[i].setNwrnum(wrNum); - PMOBPCalUtil.fillReAssNumber("nplanputnum", "nplanputastnum", items[i], "vchangerate", "nwrnum", "nwrastnum"); - items[i].setStatus(1); - } - } - - List filterList = new ArrayList(); - List putplanfinishList = new ArrayList(); - - for(PMOItemVO item : items) { - String var10001 = item.getPk_org(); - UFDouble downPara = (UFDouble)prodtolerance.get(var10001 + "#" + item.getCmaterialvid()); - UFDouble compareplanputnum = item.getNplanputnum(); - if (MMNumberUtil.isGtZero(downPara)) { - compareplanputnum = MMNumberUtil.multiply(new UFDouble[]{item.getNplanputnum(), MMNumberUtil.sub(UFDouble.ONE_DBL, new UFDouble[]{downPara.div((double)100.0F)})}); - } - - UFBoolean flag = UFBoolean.FALSE; - if (!MMMapUtil.isEmpty(bpara)) { - flag = (UFBoolean)bpara.get(item.getPk_org()); - if (null == flag) { - flag = UFBoolean.FALSE; - } - } - - if (flag.booleanValue()) { - UFDouble dpara = (UFDouble)intolerance.get(item.getCmaterialvid()); - UFDouble dparabl = UFDouble.ONE_DBL; - if (!MMValueCheck.isEmpty(bpara)) { - dparabl = MMNumberUtil.add(new UFDouble[]{UFDouble.ONE_DBL, dpara.div((double)100.0F)}); - } - - UFDouble totalputnum = MMNumberUtil.add(new UFDouble[]{item.getNplanputnum(), item.getNrejectnum()}); - if (MMNumberUtil.isLsEqual(item.getNwrnum(), MMNumberUtil.multiply(new UFDouble[]{totalputnum, dparabl}))) { - filterList.add(item); - } - - if (MMNumberUtil.isGtEqual(item.getNwrnum(), compareplanputnum) && !MMMapUtil.isEmpty(autodonepara)) { - PMOHeadVO head = (PMOHeadVO)headMap.get(item.getCpmohid()); - UFBoolean autoFlag = (UFBoolean)autodonepara.get(head.getCtrantypeid()); - if (autoFlag.booleanValue()) { - BaseDAO dao = new BaseDAO(); - // 查询备料计划 如果下游备料计划未出库数量(计划出库-累计出库)小于0,生产订单自动完工取消 naccoutnum 累计出库数量 nplanoutnum计划出库 - String pickmsql = "select cbmaterialvid,vrowno,nplanoutnum,naccoutnum from mm_pickm_b where cpickmid in ( select cpickmid from mm_pickm where csourcebillrowid='" + item.getCmoid() + "' and dr=0) and dr = 0"; - List> hmateral = (List>) dao.executeQuery(pickmsql, new MapListProcessor()); - List vrownos = new ArrayList(); - List> maps = new ArrayList(); - - Boolean l=false; - for (Map map : hmateral) { - String material =MaterialVO.CODE+","+MaterialVO.NAME+","+MaterialVO.OUTTOLERANCE; - if(map.get("naccoutnum") == null){ - map.put("naccoutnum", 0); - } - // 物料出库容差 % 0.0000 - Map goodsMap = MyHelper.transferFields(MaterialVO.getDefaultTableName(), material, MaterialVO.PK_MATERIAL, item.getCmaterialvid()); - String Outtolerance= null !=goodsMap.get("outtolerance") ? goodsMap.get("outtolerance").toString() : "0"; - if(null != map.get("nplanoutnum") && null != map.get("naccoutnum") && (new UFDouble(String.valueOf(map.get("nplanoutnum").toString())).sub(new UFDouble(String.valueOf(map.get("naccoutnum").toString()))).abs()).compareTo(new UFDouble(String.valueOf(map.get("nplanoutnum").toString())).multiply(new UFDouble(String.valueOf(Outtolerance.toString())))) > 0) { - l=true; - Map map1 =new HashMap<>(); - map1.put("vrowno",map.get("vrowno").toString()); - map1.put("mrlname",goodsMap.get("name").toString()); - map1.put("mrlcode",goodsMap.get("code").toString()); - maps.add(map1); - } - } - if(l){ - // String pickm = " select vbillcode,cpickmid from mm_pickm where csourcebillrowid='" + item.getCmoid() + "' and dr=0"; - // List> pickms = (List>) dao.executeQuery(pickm, new MapListProcessor()); - String err=""; - for (Map vrowno : maps) { - String pmobillcode= head.getVbillcode(); - String pmovrowno= item.getVrowno(); - // String pickmbillcode= pickms.get(0).get("vbillcode").toString(); - String pickmvrowno= vrowno.get("vrowno").toString(); - String mrlname= vrowno.get("mrlname").toString(); - String mrlcode= vrowno.get("mrlcode").toString(); - err=err+"生产订单"+pmobillcode+"行"+pmovrowno+"的备料计划行"+pickmvrowno+"物料【"+mrlcode+","+mrlname+"】检查不通过\n"; - } - return err; - } - item.setFitemstatus(Integer.valueOf(PMOFItemStatusEnum.FINISH.getEnumValue().getValue())); - item.setTactendtime(new UFDateTime(AppBsContext.getInstance().getBusiDate().toPersisted())); + if (MMNumberUtil.isLs(item.getNwrnum(), compareplanputnum) && item.getFitemstatus().equals(Integer.valueOf(PMOFItemStatusEnum.FINISH.getEnumValue().getValue()))) { + item.setFitemstatus(Integer.valueOf(PMOFItemStatusEnum.PUT.getEnumValue().getValue())); + item.setTactendtime((UFDateTime)null); item.setStatus(1); - putplanfinishList.add(item.getCmoid()); } - } + } else { + UFDouble divNum = MMNumberUtil.add(new UFDouble[]{item.getNzcgnum(), item.getNzwwnum()}); + divNum = MMNumberUtil.add(new UFDouble[]{divNum, item.getNzdbnum()}); + UFDouble totalWRnum = MMNumberUtil.add(new UFDouble[]{divNum, item.getNwrnum()}); + if (!MMNumberUtil.isLsZero(item.getNwrnum())) { + filterList.add(item); + } - if (MMNumberUtil.isLs(item.getNwrnum(), compareplanputnum) && item.getFitemstatus().equals(Integer.valueOf(PMOFItemStatusEnum.FINISH.getEnumValue().getValue()))) { - item.setFitemstatus(Integer.valueOf(PMOFItemStatusEnum.PUT.getEnumValue().getValue())); - item.setTactendtime((UFDateTime)null); - item.setStatus(1); - } - } else { - UFDouble divNum = MMNumberUtil.add(new UFDouble[]{item.getNzcgnum(), item.getNzwwnum()}); - divNum = MMNumberUtil.add(new UFDouble[]{divNum, item.getNzdbnum()}); - UFDouble totalWRnum = MMNumberUtil.add(new UFDouble[]{divNum, item.getNwrnum()}); - if (!MMNumberUtil.isLsZero(item.getNwrnum())) { - filterList.add(item); - } - - if (totalWRnum.doubleValue() >= compareplanputnum.doubleValue() && !MMMapUtil.isEmpty(autodonepara)) { + if (totalWRnum.doubleValue() >= compareplanputnum.doubleValue() && !MMMapUtil.isEmpty(autodonepara)) { - PMOHeadVO head = (PMOHeadVO)headMap.get(item.getCpmohid()); - UFBoolean autoFlag = (UFBoolean)autodonepara.get(head.getCtrantypeid()); - if (autoFlag.booleanValue()) { - BaseDAO dao = new BaseDAO(); - // 查询备料计划 如果下游备料计划未出库数量(计划出库-累计出库)小于0,生产订单自动完工取消 naccoutnum 累计出库数量 nplanoutnum计划出库 - String pickmsql = "select cbmaterialvid,vrowno,nplanoutnum,naccoutnum from mm_pickm_b where cpickmid in ( select cpickmid from mm_pickm where csourcebillrowid='" + item.getCmoid() + "' and dr=0) and dr = 0"; - List> hmateral = (List>) dao.executeQuery(pickmsql, new MapListProcessor()); - List vrownos = new ArrayList(); - List> maps = new ArrayList(); + PMOHeadVO head = (PMOHeadVO)headMap.get(item.getCpmohid()); + UFBoolean autoFlag = (UFBoolean)autodonepara.get(head.getCtrantypeid()); + if (autoFlag.booleanValue()) { + BaseDAO dao = new BaseDAO(); + // 查询备料计划 如果下游备料计划未出库数量(计划出库-累计出库)小于0,生产订单自动完工取消 naccoutnum 累计出库数量 nplanoutnum计划出库 + String pickmsql = "select cbmaterialvid,vrowno,nplanoutnum,naccoutnum from mm_pickm_b where cpickmid in ( select cpickmid from mm_pickm where csourcebillrowid='" + item.getCmoid() + "' and dr=0) and dr = 0"; + List> hmateral = (List>) dao.executeQuery(pickmsql, new MapListProcessor()); + List vrownos = new ArrayList(); + List> maps = new ArrayList(); - Boolean l=false; - for (Map map : hmateral) { - String material =MaterialVO.CODE+","+MaterialVO.NAME+","+MaterialVO.OUTTOLERANCE; - // 物料出库容差 % 0.0000 - if(map.get("naccoutnum") == null){ - map.put("naccoutnum", 0); + Boolean l=false; + for (Map map : hmateral) { + String material =MaterialVO.CODE+","+MaterialVO.NAME+","+MaterialVO.OUTTOLERANCE; + // 物料出库容差 % 0.0000 + if(map.get("naccoutnum") == null){ + map.put("naccoutnum", 0); + } + Map goodsMap = MyHelper.transferFields(MaterialVO.getDefaultTableName(), material, MaterialVO.PK_MATERIAL, item.getCmaterialvid()); + String Outtolerance= null !=goodsMap.get("outtolerance") ? goodsMap.get("outtolerance").toString() : "0"; + if(null != map.get("nplanoutnum") && null != map.get("naccoutnum") && (new UFDouble(map.get("nplanoutnum").toString()).sub(new UFDouble(String.valueOf(map.get("naccoutnum").toString()))).abs()).compareTo(new UFDouble(String.valueOf(map.get("nplanoutnum").toString())).multiply(new UFDouble(String.valueOf(Outtolerance.toString())))) > 0) { + UFDouble num1 = new UFDouble(map.get("nplanoutnum").toString()).sub(new UFDouble(String.valueOf(map.get("naccoutnum").toString()))).abs(); + + l=true; + Map map1 =new HashMap<>(); + map1.put("vrowno",map.get("vrowno").toString()); + map1.put("mrlname",goodsMap.get("name").toString()); + map1.put("mrlcode",goodsMap.get("code").toString()); + maps.add(map1); + } } - Map goodsMap = MyHelper.transferFields(MaterialVO.getDefaultTableName(), material, MaterialVO.PK_MATERIAL, item.getCmaterialvid()); - String Outtolerance= null !=goodsMap.get("outtolerance") ? goodsMap.get("outtolerance").toString() : "0"; - if(null != map.get("nplanoutnum") && null != map.get("naccoutnum") && (new UFDouble(map.get("nplanoutnum").toString()).sub(new UFDouble(String.valueOf(map.get("naccoutnum").toString()))).abs()).compareTo(new UFDouble(String.valueOf(map.get("nplanoutnum").toString())).multiply(new UFDouble(String.valueOf(Outtolerance.toString())))) > 0) { - UFDouble num1 = new UFDouble(map.get("nplanoutnum").toString()).sub(new UFDouble(String.valueOf(map.get("naccoutnum").toString()))).abs(); - - l=true; - Map map1 =new HashMap<>(); - map1.put("vrowno",map.get("vrowno").toString()); - map1.put("mrlname",goodsMap.get("name").toString()); - map1.put("mrlcode",goodsMap.get("code").toString()); - maps.add(map1); + if(l){ + // String pickm = " select vbillcode,cpickmid from mm_pickm where csourcebillrowid='" + item.getCmoid() + "' and dr=0"; + // List> pickms = (List>) dao.executeQuery(pickm, new MapListProcessor()); + String err=""; + for (Map vrowno : maps) { + String pmobillcode= head.getVbillcode(); + String pmovrowno= item.getVrowno(); + // String pickmbillcode= pickms.get(0).get("vbillcode").toString(); + String pickmvrowno= vrowno.get("vrowno").toString(); + String mrlname= vrowno.get("mrlname").toString(); + String mrlcode= vrowno.get("mrlcode").toString(); + err=err+"生产订单"+pmobillcode+"行"+pmovrowno+"的备料计划行"+pickmvrowno+"物料【"+mrlcode+","+mrlname+"】检查不通过\n"; + } + return err; } } - if(l){ - // String pickm = " select vbillcode,cpickmid from mm_pickm where csourcebillrowid='" + item.getCmoid() + "' and dr=0"; - // List> pickms = (List>) dao.executeQuery(pickm, new MapListProcessor()); - String err=""; - for (Map vrowno : maps) { - String pmobillcode= head.getVbillcode(); - String pmovrowno= item.getVrowno(); - // String pickmbillcode= pickms.get(0).get("vbillcode").toString(); - String pickmvrowno= vrowno.get("vrowno").toString(); - String mrlname= vrowno.get("mrlname").toString(); - String mrlcode= vrowno.get("mrlcode").toString(); - err=err+"生产订单"+pmobillcode+"行"+pmovrowno+"的备料计划行"+pickmvrowno+"物料【"+mrlcode+","+mrlname+"】检查不通过\n"; + } + + if (totalWRnum.doubleValue() < compareplanputnum.doubleValue() && item.getFitemstatus().equals(Integer.valueOf(PMOFItemStatusEnum.FINISH.getEnumValue().getValue()))) { + item.setFitemstatus(Integer.valueOf(PMOFItemStatusEnum.PUT.getEnumValue().getValue())); + item.setTactendtime((UFDateTime)null); + item.setStatus(1); + } + } + } + + + + } + + + if( !MMMapUtil.isEmpty(itemMap2)){ + PMOItemVO[] items2 = (PMOItemVO[])itemMap2.values().toArray(new PMOItemVO[0]); + for(PMORewriteParaVO para : paras) { + if (!originbidSet.contains(para.getCpmobid())) { + ExceptionUtils.wrappBusinessException(PMOConstLang.getMSG_PMO_DeleteLine()); + } + } + + BDPKLockUtil.lockSuperVO(items2); + this.checkMOstatus(items2, headMap); + Set cmaterials = new HashSet(); + Set ctrantypes = new HashSet(); + Set pk_orgs = new HashSet(); + MapList sortOrgMarMap = new MapList(); + + for(PMOItemVO item : items2) { + if (!cmaterials.contains(item.getCmaterialvid())) { + cmaterials.add(item.getCmaterialvid()); + } + + PMOHeadVO head = (PMOHeadVO)headMap.get(item.getCpmohid()); + if (!MMValueCheck.isEmpty(head) && !ctrantypes.contains(head.getCtrantypeid())) { + ctrantypes.add(head.getCtrantypeid()); + } + + if (!pk_orgs.contains(item.getPk_org())) { + pk_orgs.add(item.getPk_org()); + } + + sortOrgMarMap.put(item.getPk_org(), item.getCmaterialvid()); + } + + Map prodtolerance = new HashMap(); + + for(Map.Entry> entry : sortOrgMarMap.entrySet()) { + Map tempdowntolerance = PMOBPCalUtil.getProdtolerance((String)entry.getKey(), (String[])((List)entry.getValue()).toArray(new String[0])); + if (MMMapUtil.isNotEmpty(tempdowntolerance)) { + prodtolerance.putAll(tempdowntolerance); + } + } + + Map intolerance = PMOBPCalUtil.getInStockControlScope((String[])cmaterials.toArray(new String[0])); + Map autodonepara = PMOBPService.getIPMOTransTypeQueryService().getBAutoFinishByTranTypeIDs((String[])ctrantypes.toArray(new String[0])); + Map bpara = MMBDFactoryParameter.getPAC012BatchParaBoolean((String[])pk_orgs.toArray(new String[0])); + this.checkWrts(paraMapList, items2); + List planoutputList = new ArrayList(); + + for(int i = 0; i < items2.length; ++i) { + List paraList = paraMapList.get(items2[i].getCmoid()); + PMOPlanOutputVO[] moPlanOutVOS = items2[i].getPlanoutputs(); + if (!MMArrayUtil.isEmpty(moPlanOutVOS)) { + for(PMOPlanOutputVO planOutVO : moPlanOutVOS) { + boolean isupd = false; + + for(PMORewriteParaVO paravo : paraList) { + if (!MMMapUtil.isEmpty(paravo.getPoutMap())) { + UFDouble delNum = MMNumberUtil.toNotNullValue((UFDouble)paravo.getPoutMap().get(planOutVO.getCplanoutputid())); + if (MMNumberUtil.isNotNullAndNotZero(delNum)) { + (new NumScaleUtil()).checkNumberScale(new UFDouble[]{delNum}, planOutVO.getCunitid()); + } + + if (MMNumberUtil.isNotNullAndNotZero(delNum)) { + UFDouble wrNum = MMNumberUtil.add(new UFDouble[]{delNum, MMNumberUtil.toNotNullValue(planOutVO.getNwrnum())}); + planOutVO.setNwrnum(wrNum); + planOutVO.setStatus(1); + PMOBPCalUtil.fillReAssNumber("nplanoutputnum", "nastplanoutputnum", planOutVO, "vchangerate", "nwrnum", "nwrastnum"); + isupd = true; + } } - return err; + } + + if (isupd) { + planoutputList.add(planOutVO); } } } - if (totalWRnum.doubleValue() < compareplanputnum.doubleValue() && item.getFitemstatus().equals(Integer.valueOf(PMOFItemStatusEnum.FINISH.getEnumValue().getValue()))) { - item.setFitemstatus(Integer.valueOf(PMOFItemStatusEnum.PUT.getEnumValue().getValue())); - item.setTactendtime((UFDateTime)null); - item.setStatus(1); + for(PMORewriteParaVO paravo : paraList) { + UFDouble delNum = MMNumberUtil.toNotNullValue(paravo.getDelNum()); + if (MMNumberUtil.isNotNullAndNotZero(delNum)) { + (new NumScaleUtil()).checkNumberScale(new UFDouble[]{delNum}, items2[i].getCunitid()); + } + + UFDouble wrNum = MMNumberUtil.add(new UFDouble[]{delNum, MMNumberUtil.toNotNullValue(items2[i].getNwrnum())}); + items2[i].setNwrnum(wrNum); + PMOBPCalUtil.fillReAssNumber("nplanputnum", "nplanputastnum", items2[i], "vchangerate", "nwrnum", "nwrastnum"); + items2[i].setStatus(1); + } + } + List filterList = new ArrayList(); + List putplanfinishList = new ArrayList(); + for(PMOItemVO item : items2) { + String var10001 = item.getPk_org(); + UFDouble downPara = (UFDouble)prodtolerance.get(var10001 + "#" + item.getCmaterialvid()); + UFDouble compareplanputnum = item.getNplanputnum(); + if (MMNumberUtil.isGtZero(downPara)) { + compareplanputnum = MMNumberUtil.multiply(new UFDouble[]{item.getNplanputnum(), MMNumberUtil.sub(UFDouble.ONE_DBL, new UFDouble[]{downPara.div((double)100.0F)})}); + } + + UFBoolean flag = UFBoolean.FALSE; + if (!MMMapUtil.isEmpty(bpara)) { + flag = (UFBoolean)bpara.get(item.getPk_org()); + if (null == flag) { + flag = UFBoolean.FALSE; + } + } + + if (flag.booleanValue()) { + UFDouble dpara = (UFDouble)intolerance.get(item.getCmaterialvid()); + UFDouble dparabl = UFDouble.ONE_DBL; + if (!MMValueCheck.isEmpty(bpara)) { + dparabl = MMNumberUtil.add(new UFDouble[]{UFDouble.ONE_DBL, dpara.div((double)100.0F)}); + } + + UFDouble totalputnum = MMNumberUtil.add(new UFDouble[]{item.getNplanputnum(), item.getNrejectnum()}); + if (MMNumberUtil.isLsEqual(item.getNwrnum(), MMNumberUtil.multiply(new UFDouble[]{totalputnum, dparabl}))) { + filterList.add(item); + } + + if (MMNumberUtil.isGtEqual(item.getNwrnum(), compareplanputnum) && !MMMapUtil.isEmpty(autodonepara)) { + PMOHeadVO head = (PMOHeadVO)headMap.get(item.getCpmohid()); + UFBoolean autoFlag = (UFBoolean)autodonepara.get(head.getCtrantypeid()); + if (autoFlag.booleanValue()) { + BaseDAO dao = new BaseDAO(); + // 查询备料计划 如果下游备料计划未出库数量(计划出库-累计出库)小于0,生产订单自动完工取消 naccoutnum 累计出库数量 nplanoutnum计划出库 + // String pickmsql = "select cbmaterialvid,vrowno,nplanoutnum,naccoutnum from mm_pickm_b where cpickmid in ( select cpickmid from mm_pickm where csourcebillrowid='" + item.getCmoid() + "' and dr=0) and dr = 0"; + + String pickmsql = "select mm_pickm_b.cbmaterialvid,mm_pickm_b.naccoutnum,mm_pickm_b.nplanoutnum,mm_pickm.vbillcode from mm_pickm_b left join mm_pickm on mm_pickm.cpickmid=mm_pickm_b.cpickmid and mm_pickm.csourcebillrowid='" + item.getCmoid() + "' where mm_pickm_b.dr = 0 AND mm_pickm.dr=0"; + + List> hmateral = (List>) dao.executeQuery(pickmsql, new MapListProcessor()); + List> maps = new ArrayList(); + String orgName = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.NAME, OrgVO.PK_ORG, head.getPk_org()); + + Boolean l=false; + for (Map map : hmateral) { + String material =MaterialVO.CODE+","+MaterialVO.NAME+","+MaterialVO.OUTTOLERANCE; + // 物料出库容差 % 0.0000 + if(map.get("naccoutnum") == null){ + map.put("naccoutnum", 0); + } + Map goodsMap = MyHelper.transferFields(MaterialVO.getDefaultTableName(), material, MaterialVO.PK_MATERIAL, item.getCmaterialvid()); + String Outtolerance= null !=goodsMap.get("outtolerance") ? goodsMap.get("outtolerance").toString() : "0"; + if(null != map.get("nplanoutnum") && null != map.get("naccoutnum") && (new UFDouble(map.get("nplanoutnum").toString()).sub(new UFDouble(String.valueOf(map.get("naccoutnum").toString()))).abs()).compareTo(new UFDouble(String.valueOf(map.get("nplanoutnum").toString())).multiply(new UFDouble(String.valueOf(Outtolerance.toString())))) > 0) { + l=true; + Map map1 =new HashMap<>(); + map1.put("vbillcode",map.get("vbillcode").toString()); + maps.add(map1); + maps.add(map1); + } + } + if(l){ + // 1. 初始化空字符串接收最终错误信息 + String err = ""; +// 2. 定义Set集合存储唯一的vbillcode,天然过滤重复值 + Set uniqueVbillCodes = new HashSet<>(); + +// 3. 第一次遍历:收集所有不重复的vbillcode(增加非空判断,避免空指针异常) + for (Map vrowno : maps) { + Object vbillcodeObj = vrowno.get("vbillcode"); + if (vbillcodeObj != null) { // 判空:防止vbillcode为null时调用toString()报空指针 + String vbillcode = vbillcodeObj.toString(); + uniqueVbillCodes.add(vbillcode); // Set自动忽略重复值 + } + } + +// 4. 第二次遍历:用StringBuilder拼接不重复的错误信息(高效,避免频繁创建String对象) + if (!uniqueVbillCodes.isEmpty()) { // 无数据时不拼接,保持err为空 + StringBuilder errSb = new StringBuilder(); + for (String uniqueCode : uniqueVbillCodes) { + errSb.append(orgName).append("备料计划").append(uniqueCode).append("存在需退料物资,请处理。"); + } + err = errSb.toString(); // 转换为最终字符串 + } + return err; + } + item.setFitemstatus(Integer.valueOf(PMOFItemStatusEnum.FINISH.getEnumValue().getValue())); + item.setTactendtime(new UFDateTime(AppBsContext.getInstance().getBusiDate().toPersisted())); + item.setStatus(1); + putplanfinishList.add(item.getCmoid()); + } + } + + if (MMNumberUtil.isLs(item.getNwrnum(), compareplanputnum) && item.getFitemstatus().equals(Integer.valueOf(PMOFItemStatusEnum.FINISH.getEnumValue().getValue()))) { + item.setFitemstatus(Integer.valueOf(PMOFItemStatusEnum.PUT.getEnumValue().getValue())); + item.setTactendtime((UFDateTime)null); + item.setStatus(1); + } + } else { + UFDouble divNum = MMNumberUtil.add(new UFDouble[]{item.getNzcgnum(), item.getNzwwnum()}); + divNum = MMNumberUtil.add(new UFDouble[]{divNum, item.getNzdbnum()}); + UFDouble totalWRnum = MMNumberUtil.add(new UFDouble[]{divNum, item.getNwrnum()}); + if (!MMNumberUtil.isLsZero(item.getNwrnum())) { + filterList.add(item); + } + + if (totalWRnum.doubleValue() >= compareplanputnum.doubleValue() && !MMMapUtil.isEmpty(autodonepara)) { + + + PMOHeadVO head = (PMOHeadVO)headMap.get(item.getCpmohid()); + UFBoolean autoFlag = (UFBoolean)autodonepara.get(head.getCtrantypeid()); + if (autoFlag.booleanValue()) { + BaseDAO dao = new BaseDAO(); + // 查询备料计划 如果下游备料计划未出库数量(计划出库-累计出库)小于0,生产订单自动完工取消 naccoutnum 累计出库数量 nplanoutnum计划出库 + // String pickmsql = "select cbmaterialvid,vrowno,nplanoutnum,naccoutnum from mm_pickm_b where cpickmid in ( select cpickmid from mm_pickm where csourcebillrowid='" + item.getCmoid() + "' and dr=0) and dr = 0"; + String pickmsql = "select mm_pickm_b.cbmaterialvid,mm_pickm_b.nplanoutnum,mm_pickm_b.naccoutnum,mm_pickm.vbillcode from mm_pickm_b left join mm_pickm on mm_pickm.cpickmid=mm_pickm_b.cpickmid and mm_pickm.csourcebillrowid='" + item.getCmoid() + "' where mm_pickm_b.dr = 0 AND mm_pickm.dr=0"; + + List> hmateral = (List>) dao.executeQuery(pickmsql, new MapListProcessor()); + List vrownos = new ArrayList(); + List> maps = new ArrayList(); + String pkOrg = head.getPk_org(); + String orgName = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.NAME, OrgVO.PK_ORG, pkOrg); + Boolean l=false; + for (Map map : hmateral) { + String material =MaterialVO.CODE+","+MaterialVO.NAME+","+MaterialVO.OUTTOLERANCE; + // 物料出库容差 % 0.0000 + if(map.get("naccoutnum") == null){ + map.put("naccoutnum", 0); + } + Map goodsMap = MyHelper.transferFields(MaterialVO.getDefaultTableName(), material, MaterialVO.PK_MATERIAL, item.getCmaterialvid()); + String Outtolerance= null !=goodsMap.get("outtolerance") ? goodsMap.get("outtolerance").toString() : "0"; + if(null != map.get("nplanoutnum") && null != map.get("naccoutnum") && (new UFDouble(map.get("nplanoutnum").toString()).sub(new UFDouble(String.valueOf(map.get("naccoutnum").toString()))).abs()).compareTo(new UFDouble(String.valueOf(map.get("nplanoutnum").toString())).multiply(new UFDouble(String.valueOf(Outtolerance.toString())))) > 0) { + l=true; + Map map1 =new HashMap<>(); + map1.put("vbillcode",map.get("vbillcode").toString()); + maps.add(map1); + } + } + if(l){ + // String pickm = " select vbillcode,cpickmid from mm_pickm where csourcebillrowid='" + item.getCmoid() + "' and dr=0"; + // List> pickms = (List>) dao.executeQuery(pickm, new MapListProcessor()); + // 1. 初始化空字符串接收最终错误信息 + String err = ""; +// 2. 定义Set集合存储唯一的vbillcode,天然过滤重复值 + Set uniqueVbillCodes = new HashSet<>(); + +// 3. 第一次遍历:收集所有不重复的vbillcode(增加非空判断,避免空指针异常) + for (Map vrowno : maps) { + Object vbillcodeObj = vrowno.get("vbillcode"); + if (vbillcodeObj != null) { // 判空:防止vbillcode为null时调用toString()报空指针 + String vbillcode = vbillcodeObj.toString(); + uniqueVbillCodes.add(vbillcode); // Set自动忽略重复值 + } + } + +// 4. 第二次遍历:用StringBuilder拼接不重复的错误信息(高效,避免频繁创建String对象) + if (!uniqueVbillCodes.isEmpty()) { // 无数据时不拼接,保持err为空 + StringBuilder errSb = new StringBuilder(); + for (String uniqueCode : uniqueVbillCodes) { + errSb.append(orgName).append("备料计划").append(uniqueCode).append("存在需退料物资,请处理。"); + } + err = errSb.toString(); // 转换为最终字符串 + } + return err; + } + } + } + + if (totalWRnum.doubleValue() < compareplanputnum.doubleValue() && item.getFitemstatus().equals(Integer.valueOf(PMOFItemStatusEnum.FINISH.getEnumValue().getValue()))) { + item.setFitemstatus(Integer.valueOf(PMOFItemStatusEnum.PUT.getEnumValue().getValue())); + item.setTactendtime((UFDateTime)null); + item.setStatus(1); + } } } } + return 0; } catch (BusinessException e) { throw new RuntimeException(e); } } - private boolean checkIfOrg(String code, Map configParams) throws BusinessException { - String targetCode = configParams.get("xbOrg"); + private boolean checkIfOrg(String code, Map configParams, String planOrg) throws BusinessException { + String targetCode = configParams.get(planOrg); if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) { throw new BusinessException("未配置组织参数"); } String[] orgItem = targetCode.split(","); for (String orgCode : orgItem) { if (!orgCode.isEmpty() && orgCode.equals(code)) { - return false; + return true; } } - return true; + return false; } private void checkMOstatus(PMOItemVO[] items, Map headMap) { if (!MMArrayUtil.isEmpty(items)) {