材料出库接口重排行号
This commit is contained in:
		
							parent
							
								
									a59b2f60c8
								
							
						
					
					
						commit
						a3447b46b6
					
				|  | @ -0,0 +1,272 @@ | |||
| package nccloud.api.impl.ic.m4d; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.HashSet; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.Set; | ||||
| 
 | ||||
| import org.apache.commons.lang3.ArrayUtils; | ||||
| import org.apache.commons.lang3.StringUtils; | ||||
| 
 | ||||
| import nc.bs.framework.common.NCLocator; | ||||
| import nc.bs.scmpub.query.SCMBillQuery; | ||||
| import nc.itf.scmpub.reference.uap.pf.PfServiceScmUtil; | ||||
| import nc.pubimpl.ic.api.maintain.BillMaintainTool; | ||||
| import nc.pubitf.ic.m4d.api.IMaterialOutMaintainAPI; | ||||
| import nc.vo.ic.general.define.ICBillFlag; | ||||
| import nc.vo.ic.general.define.ICBillHeadVO; | ||||
| import nc.vo.ic.general.util.ICLocationUtil; | ||||
| import nc.vo.ic.location.ICLocationVO; | ||||
| import nc.vo.ic.m4d.entity.MaterialOutBodyVO; | ||||
| import nc.vo.ic.m4d.entity.MaterialOutHeadVO; | ||||
| import nc.vo.ic.m4d.entity.MaterialOutVO; | ||||
| import nc.vo.ic.pub.define.ICPubMetaNameConst; | ||||
| import nc.vo.pub.BusinessException; | ||||
| import nc.vo.pub.VOStatus; | ||||
| import nc.vo.scmpub.check.billvalidate.BillVOsCheckRule; | ||||
| import nc.vo.scmpub.res.billtype.ICBillType; | ||||
| import nccloud.api.ic.m4d.IAPIMaterialOutMaintain; | ||||
| import nccloud.api.impl.ic.m4d.check.CheckMaterialOutSaveValidator; | ||||
| import nccloud.api.impl.ic.m4d.fill.MaterialOutSaveFillValue; | ||||
| import nccloud.api.impl.ic.m4d.fill.MaterialOutUpdateFillValue; | ||||
| import nccloud.api.impl.ic.pub.check.CheckProhibitUpdateFields; | ||||
| import nccloud.openapi.ic.util.ICAPILocationVOUtils; | ||||
| import nccloud.openapi.scmpub.pub.TransferCodeToPKTool; | ||||
| import nccloud.openapi.scmpub.pub.TransferMapToVOTool; | ||||
| 
 | ||||
| /** | ||||
|  * | ||||
|  * @Description: 库存材料出库单维护实现类 | ||||
|  * | ||||
|  * @author: 曹军 | ||||
|  * @date:   2019-5-17 上午10:49:30 | ||||
|  * @version NCC1909 | ||||
|  */ | ||||
| 
 | ||||
| public class APIMaterialOutMaintainImpl implements IAPIMaterialOutMaintain{ | ||||
| 
 | ||||
|     @Override | ||||
|     public MaterialOutVO[] save(List<Map<String, Object>> paramList) throws BusinessException { | ||||
|         // MapList转聚合VOList | ||||
|         List<MaterialOutVO> aggVOList = | ||||
|                 TransferMapToVOTool.transferMapToAggVO(paramList, MaterialOutVO.class); | ||||
|         MaterialOutVO[] vos = | ||||
|                 aggVOList.toArray(new MaterialOutVO[aggVOList.size()]); | ||||
|         // 设置货位序列号VO | ||||
|         ICAPILocationVOUtils.setLocationVO(ICBillType.MaterialOut.getCode(),vos); | ||||
|         // 1、传入数据基本非空校验 | ||||
|         BillVOsCheckRule checker = | ||||
|                 new BillVOsCheckRule(new CheckMaterialOutSaveValidator()); | ||||
|         checker.check(vos); | ||||
|         // 2、编码翻译成pk | ||||
|         aggVOList = TransferCodeToPKTool.transferAggVO(aggVOList); | ||||
|         // 翻译货位 | ||||
|         ICAPILocationVOUtils.translate(vos); | ||||
|         //其他数据填充 | ||||
|         new MaterialOutSaveFillValue().setDefaultValue(vos); | ||||
| 
 | ||||
|         IMaterialOutMaintainAPI materialOut = NCLocator.getInstance().lookup(IMaterialOutMaintainAPI.class); | ||||
|         //设置每行行号 | ||||
|         setMaterialOutRowNum(vos); | ||||
|         return materialOut.insertBills(vos); | ||||
|     } | ||||
| 
 | ||||
|     private void setMaterialOutRowNum(MaterialOutVO[] vos) { | ||||
|         for (int i = 0; i < vos.length; i++) { | ||||
|             MaterialOutVO vo = vos[i]; | ||||
|             MaterialOutBodyVO[] bodys = vo.getBodys(); | ||||
|             if (bodys != null && bodys.length > 0) { | ||||
|                 for (int j = 0; j < bodys.length; j++) { | ||||
|                     MaterialOutBodyVO body = bodys[j]; | ||||
|                     body.setCrowno(String.valueOf((j +1)*10)); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public MaterialOutVO[] update(List<Map<String, Object>> paramList) throws BusinessException { | ||||
|         // MapList转聚合VOList | ||||
|         List<MaterialOutVO> aggVOList = | ||||
|                 TransferMapToVOTool.transferMapToAggVO(paramList, MaterialOutVO.class); | ||||
|         // 2、编码翻译成pk | ||||
|         aggVOList = TransferCodeToPKTool.transferAggVO(aggVOList); | ||||
|         MaterialOutVO[] vos = | ||||
|                 aggVOList.toArray(new MaterialOutVO[aggVOList.size()]); | ||||
|         // 设置货位序列号VO | ||||
|         ICAPILocationVOUtils.setLocationVO(ICBillType.MaterialOut.getCode(),vos); | ||||
|         MaterialOutHeadVO newVO = vos[0].getHead(); | ||||
|         String cgeneralhid = newVO.getCgeneralhid(); | ||||
|         if(StringUtils.isEmpty(cgeneralhid)){ | ||||
|             throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0391")/*@res "修改材料出库单请指定表头主键cgeneralhid值。"*/); | ||||
|         } | ||||
|         SCMBillQuery<MaterialOutVO> queryTool = | ||||
|                 new SCMBillQuery<MaterialOutVO>(MaterialOutVO.class); | ||||
|         MaterialOutVO[] materialOutVOs = queryTool.queryVOByIDs(new String[]{cgeneralhid}); | ||||
|         Map<String, ICLocationVO[]> deleteLoc = | ||||
|                 new HashMap<String, ICLocationVO[]>(); | ||||
|         // 加载原始单据和货位信息 | ||||
|         MaterialOutVO[] originBills = queryTool.queryVOByIDs(new String[] { | ||||
|                 cgeneralhid | ||||
|         }); | ||||
|         ICLocationUtil.loadLocationVOs(originBills); | ||||
|         if(ArrayUtils.isEmpty(materialOutVOs)){ | ||||
|             throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0360")/*@res "没找到要修改的出库单信息,请检查数据的表头主键cgeneralhid。"*/); | ||||
|         }else{ | ||||
|             List<String> headProFields = CheckProhibitUpdateFields.getHeadProhibitFields("4D"); | ||||
|             List<String> bodyProFields = CheckProhibitUpdateFields.getBodyProhibitFields("4D"); | ||||
|             MaterialOutHeadVO origVO = materialOutVOs[0].getHead(); | ||||
|             if(origVO.getFbillflag() == null || | ||||
|                     0 != ((Integer) ICBillFlag.FREE.value()) | ||||
|                             .compareTo((Integer) origVO.getFbillflag())){ | ||||
|                 throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0361")/*@res "当前出库单编号:"*/ + origVO.getVbillcode() + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0362")/*@res "不是自由状态,不能修改"*/); | ||||
|             } | ||||
|             origVO.setStatus(VOStatus.UPDATED); | ||||
|             for(String attr : newVO.getAttributeNames()){ | ||||
|                 if(newVO.getAttributeValue(attr) == null) { | ||||
|                     continue; | ||||
|                 } | ||||
|                 if(headProFields.contains(attr) | ||||
|                         && !newVO.getAttributeValue(attr).equals(origVO.getAttributeValue(attr))){ | ||||
|                     throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0363")/*@res "表头字段:"*/ + attr + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0364")/*@res "不允许修改。"*/ ); | ||||
|                 } | ||||
|                 origVO.setAttributeValue(attr, newVO.getAttributeValue(attr)); | ||||
|             } | ||||
|             for (MaterialOutVO orivo : originBills) { | ||||
|                 MaterialOutBodyVO[] oribodys = orivo.getBodys(); | ||||
|                 for (MaterialOutBodyVO oribody : oribodys) { | ||||
|                     ICLocationVO[] locationVOs = oribody.getLocationVOs(); | ||||
|                     if (null != locationVOs) { | ||||
|                         deleteLoc.put(oribody.getCgeneralbid(), locationVOs); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             if(vos[0].getBodys() != null){ | ||||
|                 Map<String, MaterialOutBodyVO> pkbs = new HashMap<String, MaterialOutBodyVO>(); | ||||
|                 for(MaterialOutBodyVO origBvo : materialOutVOs[0].getBodys()){ | ||||
|                     origBvo.setStatus(VOStatus.UPDATED); | ||||
|                     pkbs.put(origBvo.getCgeneralbid(), origBvo); | ||||
|                 } | ||||
|                 for(MaterialOutBodyVO newBvo : vos[0].getBodys()){ | ||||
|                     MaterialOutBodyVO roigBvo = pkbs.get(newBvo.getCgeneralbid()); | ||||
|                     if(newBvo.getCgeneralbid() == null || roigBvo == null){ | ||||
|                         throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0365")/*@res "没有匹配到原始出库单表体信息,请检查数据的表体主键cgeneralbid。"*/); | ||||
|                     } | ||||
|                     Set<String> bfields = new HashSet<String>(); | ||||
|                     for(String battr : newBvo.getAttributeNames()){ | ||||
|                         if(newBvo.getAttributeValue(battr) == null) { | ||||
|                             continue; | ||||
|                         } | ||||
|                         if(bodyProFields.contains(battr) | ||||
|                                 && !newBvo.getAttributeValue(battr).equals(roigBvo.getAttributeValue(battr))){ | ||||
|                             throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0366")/*@res "表体字段:"*/ + battr + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0364")/*@res "不允许修改。"*/ ); | ||||
|                         } | ||||
|                         roigBvo.setAttributeValue(battr, newBvo.getAttributeValue(battr)); | ||||
|                         bfields.add(battr); | ||||
|                     } | ||||
|                     //设置货位序列号孙表,把原来的孙表删除,修改的货位置为新增 | ||||
|                     if(null != newBvo.getLocationVOs()) { | ||||
|                         List<ICLocationVO> allloc = new ArrayList<ICLocationVO>(); | ||||
|                         if(null != deleteLoc && null != deleteLoc.get(roigBvo.getCgeneralbid())) { | ||||
|                             for(ICLocationVO delloc : deleteLoc.get(roigBvo.getCgeneralbid())) { | ||||
|                                 delloc.setStatus(VOStatus.DELETED); | ||||
|                                 allloc.add(delloc); | ||||
|                             } | ||||
|                         } | ||||
|                         for(ICLocationVO loc : newBvo.getLocationVOs()) { | ||||
|                             loc.setStatus(VOStatus.NEW); | ||||
|                             allloc.add(loc); | ||||
|                         } | ||||
|                         roigBvo.setLocationVOs(allloc.toArray(new ICLocationVO[allloc.size()])); | ||||
|                     } | ||||
|                     // 翻译货位 | ||||
|                     ICAPILocationVOUtils.translate(materialOutVOs); | ||||
|                     //其他数据填充 | ||||
|                     new MaterialOutUpdateFillValue().setDefaultValue(materialOutVOs,bfields); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         BillMaintainTool<MaterialOutVO> tool = | ||||
|                 new BillMaintainTool<MaterialOutVO>(MaterialOutVO.class, | ||||
|                         ICBillType.MaterialOut.getCode()); | ||||
|         tool.doBeforeInsert(materialOutVOs); | ||||
|         return NCLocator.getInstance() | ||||
|                 .lookup(nc.itf.ic.m4d.IMaterialOutMaintain.class).update(materialOutVOs,originBills); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public MaterialOutVO[] delete(MaterialOutVO[] vos) throws BusinessException { | ||||
|         if(ArrayUtils.isEmpty(vos)){ | ||||
|             return null; | ||||
|         } | ||||
|         for(MaterialOutVO aggvo : vos){ | ||||
|             ICBillHeadVO parentVO = aggvo.getParentVO(); | ||||
|             if(parentVO.getFbillflag() == null || | ||||
|                     0 != ((Integer) ICBillFlag.FREE.value()) | ||||
|                             .compareTo((Integer) parentVO.getFbillflag())){ | ||||
|                 throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0361")/*@res "当前出库单编号:"*/ + parentVO.getVbillcode() + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0367")/*@res "不是自由状态,不能删除"*/); | ||||
|             } | ||||
|         } | ||||
|         return (MaterialOutVO[]) PfServiceScmUtil.processBatch("DELETE", "4D", vos, null, null); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public MaterialOutVO[] sign(MaterialOutVO[] vos) throws BusinessException { | ||||
|         if(ArrayUtils.isEmpty(vos)){ | ||||
|             return null; | ||||
|         } | ||||
|         for(MaterialOutVO aggvo : vos){ | ||||
|             ICBillHeadVO parentVO = aggvo.getParentVO(); | ||||
|             if(parentVO.getFbillflag() == null || | ||||
|                     0 != ((Integer) ICBillFlag.FREE.value()) | ||||
|                             .compareTo((Integer) parentVO.getFbillflag())){ | ||||
|                 throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0361")/*@res "当前出库单编号:"*/ + parentVO.getVbillcode() + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0330")/*@res "不是自由状态,不能签字"*/); | ||||
|             } | ||||
|             if(aggvo.getChildrenVO() != null && aggvo.getChildrenVO().length > 0){ | ||||
|                 if(aggvo.getChildrenVO()[0].getAttributeValue(ICPubMetaNameConst.NNUM) == null){ | ||||
|                     throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0361")/*@res "当前出库单编号:"*/ + parentVO.getVbillcode() + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0392")/*@res "总数量为空,不能签字"*/); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|         } | ||||
|         ICLocationUtil.loadLocationVOs(vos); | ||||
|         return (MaterialOutVO[]) PfServiceScmUtil.processBatch("SIGN", "4D", vos, null, null); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public MaterialOutVO[] unSign(MaterialOutVO[] vos) throws BusinessException { | ||||
|         if(ArrayUtils.isEmpty(vos)){ | ||||
|             return null; | ||||
|         } | ||||
|         for(MaterialOutVO aggvo : vos){ | ||||
|             ICBillHeadVO parentVO = aggvo.getParentVO(); | ||||
|             if(parentVO.getFbillflag() == null || | ||||
|                     0 != ((Integer) ICBillFlag.SIGN.value()) | ||||
|                             .compareTo((Integer) parentVO.getFbillflag())){ | ||||
|                 throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0361")/*@res "当前出库单编号:"*/ + parentVO.getVbillcode() + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008027_0","04008027-0332")/*@res "不是签字状态,不能取消签字"*/); | ||||
|             } | ||||
|         } | ||||
|         return (MaterialOutVO[]) PfServiceScmUtil.processBatch("CANCELSIGN", "4D", vos, null, null); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public MaterialOutVO[] saveByRef(List<Map<String, Object>> paramList) throws BusinessException{ | ||||
| 
 | ||||
|         // MapList转聚合VOList | ||||
|         List<MaterialOutVO> aggVOList = | ||||
|                 TransferMapToVOTool.transferMapToAggVO(paramList, MaterialOutVO.class); | ||||
|         MaterialOutVO[] vos = | ||||
|                 aggVOList.toArray(new MaterialOutVO[aggVOList.size()]); | ||||
|         // 1、传入数据基本非空校验 | ||||
|         BillVOsCheckRule checker = | ||||
|                 new BillVOsCheckRule(new CheckMaterialOutSaveValidator()); | ||||
|         checker.check(vos); | ||||
|         // 2、编码翻译成pk | ||||
|         aggVOList = TransferCodeToPKTool.transferAggVO(aggVOList); | ||||
|         IMaterialOutMaintainAPI materialOut = NCLocator.getInstance().lookup(IMaterialOutMaintainAPI.class); | ||||
|         return materialOut.insertBills(vos); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
		Reference in New Issue