|  | @@ -1,250 +0,0 @@
 | 
	
		
			
				|  |  | -package nc.bs.ic.special.plugins;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -import java.util.HashMap;
 | 
	
		
			
				|  |  | -import java.util.Map;
 | 
	
		
			
				|  |  | -import nc.bs.framework.common.NCLocator;
 | 
	
		
			
				|  |  | -import nc.bs.ic.general.plugins.CheckMnyUtil;
 | 
	
		
			
				|  |  | -import nc.bs.ic.general.plugins.CheckScaleUtil;
 | 
	
		
			
				|  |  | -import nc.bs.ic.pub.env.ICBSContext;
 | 
	
		
			
				|  |  | -import nc.bs.logging.Logger;
 | 
	
		
			
				|  |  | -import nc.bs.pfxx.ISwapContext;
 | 
	
		
			
				|  |  | -import nc.bs.pfxx.plugin.AbstractPfxxPlugin;
 | 
	
		
			
				|  |  | -import nc.impl.pubapp.pattern.data.vo.VOQuery;
 | 
	
		
			
				|  |  | -import nc.itf.scmpub.reference.uap.pf.PfServiceScmUtil;
 | 
	
		
			
				|  |  | -import nc.itf.uap.pf.IPFBusiAction;
 | 
	
		
			
				|  |  | -import nc.vo.ic.general.util.InOutHelp;
 | 
	
		
			
				|  |  | -import nc.vo.ic.pub.define.ICSpecialTableInfo;
 | 
	
		
			
				|  |  | -import nc.vo.ic.pub.util.StringUtil;
 | 
	
		
			
				|  |  | -import nc.vo.ic.pub.util.ValueCheckUtil;
 | 
	
		
			
				|  |  | -import nc.vo.ic.special.define.ICSpecialBillFlag;
 | 
	
		
			
				|  |  | -import nc.vo.ic.special.define.ICSpecialBodyVO;
 | 
	
		
			
				|  |  | -import nc.vo.ic.special.define.ICSpecialHeadVO;
 | 
	
		
			
				|  |  | -import nc.vo.ic.special.define.ICSpecialVO;
 | 
	
		
			
				|  |  | -import nc.vo.ml.NCLangRes4VoTransl;
 | 
	
		
			
				|  |  | -import nc.vo.pfxx.auxiliary.AggxsysregisterVO;
 | 
	
		
			
				|  |  | -import nc.vo.pfxx.util.PfxxPluginUtils;
 | 
	
		
			
				|  |  | -import nc.vo.pub.AggregatedValueObject;
 | 
	
		
			
				|  |  | -import nc.vo.pub.BusinessException;
 | 
	
		
			
				|  |  | -import nc.vo.pub.workflownote.WorkflownoteVO;
 | 
	
		
			
				|  |  | -import nc.vo.pubapp.pattern.data.ValueUtils;
 | 
	
		
			
				|  |  | -import nc.vo.pubapp.pattern.exception.ExceptionUtils;
 | 
	
		
			
				|  |  | -import nc.vo.pubapp.pattern.pub.SqlBuilder;
 | 
	
		
			
				|  |  | -import nc.vo.pubapp.util.VORowNoUtils;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -public class SpecialDefdocPlugin extends AbstractPfxxPlugin {
 | 
	
		
			
				|  |  | -	protected Object processBill(Object vo, ISwapContext swapContext, AggxsysregisterVO aggxsysvo)
 | 
	
		
			
				|  |  | -			throws BusinessException {
 | 
	
		
			
				|  |  | -		if (vo == null) {
 | 
	
		
			
				|  |  | -			throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4008001_0", "04008001-0137"));
 | 
	
		
			
				|  |  | -		} else {
 | 
	
		
			
				|  |  | -			String vopk = PfxxPluginUtils.queryBillPKBeforeSaveOrUpdate(swapContext.getBilltype(),
 | 
	
		
			
				|  |  | -					swapContext.getDocID(), swapContext.getOrgPk());
 | 
	
		
			
				|  |  | -			if (!StringUtil.isSEmptyOrNull(vopk) && !this.canUpdate()) {
 | 
	
		
			
				|  |  | -				throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4008001_0", "04008001-0138"));
 | 
	
		
			
				|  |  | -			} else {
 | 
	
		
			
				|  |  | -				ICSpecialVO icbill = (ICSpecialVO) vo;
 | 
	
		
			
				|  |  | -				icbill.getHead().setCspecialhid(vopk);
 | 
	
		
			
				|  |  | -				ICSpecialVO[] icbills = null;
 | 
	
		
			
				|  |  | -				if (ValueUtils.getBoolean(swapContext.getReplace())) {
 | 
	
		
			
				|  |  | -					icbills = this.doUpdate(swapContext, icbill);
 | 
	
		
			
				|  |  | -				} else {
 | 
	
		
			
				|  |  | -					icbills = this.doSave(swapContext, icbill);
 | 
	
		
			
				|  |  | -				}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -				return icbills[0].getHead().getCspecialhid();
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	private ICSpecialVO[] doSave(ISwapContext swapContext, ICSpecialVO icbill) throws BusinessException {
 | 
	
		
			
				|  |  | -		this.checkCanInster(icbill);
 | 
	
		
			
				|  |  | -		Logger.info("保存新单据前处理...");
 | 
	
		
			
				|  |  | -		this.processBeforeSave(icbill);
 | 
	
		
			
				|  |  | -		Logger.info("保存新单据...");
 | 
	
		
			
				|  |  | -		IPFBusiAction service = (IPFBusiAction) NCLocator.getInstance().lookup(IPFBusiAction.class);
 | 
	
		
			
				|  |  | -		ICSpecialVO[] icbills = (ICSpecialVO[]) ((ICSpecialVO[]) service.processAction("WRITE",
 | 
	
		
			
				|  |  | -				swapContext.getBilltype(), (WorkflownoteVO) null, icbill, (Object) null, (HashMap) null));
 | 
	
		
			
				|  |  | -		
 | 
	
		
			
				|  |  | -		if(swapContext.getBilltype().equals("4K")){
 | 
	
		
			
				|  |  | -	    	  service.processAction("APPROVE",
 | 
	
		
			
				|  |  | -	    	                 "4K", null, icbill, null, null);
 | 
	
		
			
				|  |  | -	    	 }
 | 
	
		
			
				|  |  | -		Logger.info("保存新单据完成...");
 | 
	
		
			
				|  |  | -		Logger.info("保存新单据后处理...");
 | 
	
		
			
				|  |  | -		this.processAfterSave(icbill);
 | 
	
		
			
				|  |  | -		if (ValueCheckUtil.isNullORZeroLength(icbills)) {
 | 
	
		
			
				|  |  | -			return null;
 | 
	
		
			
				|  |  | -		} else {
 | 
	
		
			
				|  |  | -			if (this.canUpdate()) {
 | 
	
		
			
				|  |  | -				PfxxPluginUtils.addDocIDVsPKContrast(swapContext.getBilltype(), swapContext.getDocID(),
 | 
	
		
			
				|  |  | -						swapContext.getOrgPk(), icbills[0].getHead().getCspecialhid());
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -			return icbills;
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	private ICSpecialVO[] doUpdate(ISwapContext swapContext, ICSpecialVO icbill) throws BusinessException {
 | 
	
		
			
				|  |  | -		ICSpecialVO bill = this.getOriBillVO(icbill, swapContext.getBilltype());
 | 
	
		
			
				|  |  | -		if (bill != null) {
 | 
	
		
			
				|  |  | -			IPFBusiAction service = (IPFBusiAction) NCLocator.getInstance().lookup(IPFBusiAction.class);
 | 
	
		
			
				|  |  | -			service.processAction("DELETE", swapContext.getBilltype(), (WorkflownoteVO) null, bill, (Object) null,
 | 
	
		
			
				|  |  | -					(HashMap) null);
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		return this.doSave(swapContext, icbill);
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	private ICSpecialVO getOriBillVO(ICSpecialVO icbill, String billtype) {
 | 
	
		
			
				|  |  | -		if (StringUtil.isSEmptyOrNull(icbill.getHead().getVbillcode())) {
 | 
	
		
			
				|  |  | -			return null;
 | 
	
		
			
				|  |  | -		} else {
 | 
	
		
			
				|  |  | -			SqlBuilder where = new SqlBuilder();
 | 
	
		
			
				|  |  | -			where.append(" and ");
 | 
	
		
			
				|  |  | -			where.append("vbillcode", icbill.getHead().getVbillcode());
 | 
	
		
			
				|  |  | -			where.append(" and ");
 | 
	
		
			
				|  |  | -			where.append("pk_group", icbill.getHead().getPk_group());
 | 
	
		
			
				|  |  | -			ICSpecialTableInfo billinfo = ICSpecialTableInfo.getICBillTableInfo(InOutHelp.getICBillType(billtype));
 | 
	
		
			
				|  |  | -			VOQuery<ICSpecialHeadVO> query = new VOQuery(billinfo.getHeadClass(), new String[]{"cspecialhid", "ts"});
 | 
	
		
			
				|  |  | -			ICSpecialHeadVO[] heads = (ICSpecialHeadVO[]) query.query(where.toString(), (String) null);
 | 
	
		
			
				|  |  | -			if (ValueCheckUtil.isNullORZeroLength(heads)) {
 | 
	
		
			
				|  |  | -				return null;
 | 
	
		
			
				|  |  | -			} else {
 | 
	
		
			
				|  |  | -				where = new SqlBuilder();
 | 
	
		
			
				|  |  | -				where.append(" and ");
 | 
	
		
			
				|  |  | -				where.append("cspecialhid", heads[0].getCspecialhid());
 | 
	
		
			
				|  |  | -				VOQuery<ICSpecialBodyVO> bodyquery = new VOQuery(billinfo.getBodyClass(),
 | 
	
		
			
				|  |  | -						new String[]{"cspecialhid", "cspecialbid", "ts"});
 | 
	
		
			
				|  |  | -				ICSpecialBodyVO[] bodys = (ICSpecialBodyVO[]) bodyquery.query(where.toString(), (String) null);
 | 
	
		
			
				|  |  | -				if (ValueCheckUtil.isNullORZeroLength(bodys)) {
 | 
	
		
			
				|  |  | -					return null;
 | 
	
		
			
				|  |  | -				} else {
 | 
	
		
			
				|  |  | -					ICSpecialVO bill = (ICSpecialVO) billinfo.createBillVO();
 | 
	
		
			
				|  |  | -					bill.setParent(heads[0]);
 | 
	
		
			
				|  |  | -					bill.setChildrenVO(bodys);
 | 
	
		
			
				|  |  | -					return bill;
 | 
	
		
			
				|  |  | -				}
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	protected void processBeforeSave(ICSpecialVO vo) throws BusinessException {
 | 
	
		
			
				|  |  | -		if (null == vo) {
 | 
	
		
			
				|  |  | -			throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4008001_0", "04008001-0139"));
 | 
	
		
			
				|  |  | -		} else {
 | 
	
		
			
				|  |  | -			ICBSContext context = new ICBSContext();
 | 
	
		
			
				|  |  | -			if (StringUtil.isSEmptyOrNull(vo.getParentVO().getPk_org())) {
 | 
	
		
			
				|  |  | -				vo.getParentVO().setPk_org(vo.getBodys()[0].getPk_org());
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -			if (StringUtil.isSEmptyOrNull(vo.getParentVO().getPk_org_v())) {
 | 
	
		
			
				|  |  | -				vo.getParentVO().setPk_org_v(vo.getBodys()[0].getPk_org_v());
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -			if (StringUtil.isSEmptyOrNull(vo.getParentVO().getCwarehouseid())) {
 | 
	
		
			
				|  |  | -				vo.getParentVO().setCwarehouseid(vo.getBodys()[0].getCbodywarehouseid());
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -			this.headVOProcess(vo.getParentVO(), context);
 | 
	
		
			
				|  |  | -			this.bodyVOProcess(vo, context);
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	protected void processAfterSave(ICSpecialVO vo) throws BusinessException {
 | 
	
		
			
				|  |  | -		if (null == vo) {
 | 
	
		
			
				|  |  | -			throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4008001_0", "04008001-0140"));
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	private void headVOProcess(ICSpecialHeadVO vo, ICBSContext context) {
 | 
	
		
			
				|  |  | -		vo.setStatus(2);
 | 
	
		
			
				|  |  | -		if (StringUtil.isSEmptyOrNull(vo.getPk_group())) {
 | 
	
		
			
				|  |  | -			vo.setPk_group(context.getPk_group());
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		if (vo.getIprintcount() == null) {
 | 
	
		
			
				|  |  | -			vo.setIprintcount(0);
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		if (vo.getFbillflag() == null) {
 | 
	
		
			
				|  |  | -			vo.setFbillflag((Integer) ICSpecialBillFlag.FREE.value());
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		if (vo.getDbilldate() == null) {
 | 
	
		
			
				|  |  | -			vo.setDbilldate(context.getBizDate());
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		if (StringUtil.isSEmptyOrNull(vo.getCorpoid()) || StringUtil.isSEmptyOrNull(vo.getCorpvid())) {
 | 
	
		
			
				|  |  | -			vo.setCorpoid(context.getOrgInfo().getCorpIDByCalBodyID(vo.getPk_org()));
 | 
	
		
			
				|  |  | -			vo.setCorpvid(context.getOrgInfo().getCorpVIDByCalBodyID(vo.getPk_org()));
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		if (StringUtil.isSEmptyOrNull(vo.getCtrantypeid())) {
 | 
	
		
			
				|  |  | -			String vtrantypecode = vo.getVtrantypecode();
 | 
	
		
			
				|  |  | -			Map<String, String> map = PfServiceScmUtil.getTrantypeidByCode(new String[]{vtrantypecode});
 | 
	
		
			
				|  |  | -			vo.setCtrantypeid(map == null ? null : (String) map.get(vtrantypecode));
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	private void bodyVOProcess(ICSpecialVO vo, ICBSContext context) throws BusinessException {
 | 
	
		
			
				|  |  | -		ICSpecialBodyVO[] vos = vo.getChildrenVO();
 | 
	
		
			
				|  |  | -		if (ValueCheckUtil.isNullORZeroLength(vos)) {
 | 
	
		
			
				|  |  | -			throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4008001_0", "04008001-0141"));
 | 
	
		
			
				|  |  | -		} else {
 | 
	
		
			
				|  |  | -			VORowNoUtils.setVOsRowNoByRule(vos, "crowno");
 | 
	
		
			
				|  |  | -			ICSpecialHeadVO head = vo.getParentVO();
 | 
	
		
			
				|  |  | -			ICSpecialBodyVO[] arr$ = vos;
 | 
	
		
			
				|  |  | -			int len$ = vos.length;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -			for (int i$ = 0; i$ < len$; ++i$) {
 | 
	
		
			
				|  |  | -				ICSpecialBodyVO body = arr$[i$];
 | 
	
		
			
				|  |  | -				body.setStatus(2);
 | 
	
		
			
				|  |  | -				if (StringUtil.isSEmptyOrNull(body.getCmaterialoid())
 | 
	
		
			
				|  |  | -						|| StringUtil.isSEmptyOrNull(body.getCmaterialvid())) {
 | 
	
		
			
				|  |  | -					throw new BusinessException(
 | 
	
		
			
				|  |  | -							NCLangRes4VoTransl.getNCLangRes().getStrByID("4008001_0", "04008001-0142"));
 | 
	
		
			
				|  |  | -				}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -				if (StringUtil.isSEmptyOrNull(body.getCastunitid())) {
 | 
	
		
			
				|  |  | -					body.setCastunitid(context.getInvInfo().getInvBasVO(body.getCmaterialvid()).getPk_stockmeas());
 | 
	
		
			
				|  |  | -				}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -				this.bodyVOCopyFromHeadVO(body, head);
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	private void bodyVOCopyFromHeadVO(ICSpecialBodyVO body, ICSpecialHeadVO head) {
 | 
	
		
			
				|  |  | -		body.setPk_group(head.getPk_group());
 | 
	
		
			
				|  |  | -		body.setPk_org(head.getPk_org());
 | 
	
		
			
				|  |  | -		body.setPk_org_v(head.getPk_org_v());
 | 
	
		
			
				|  |  | -		body.setCorpoid(head.getCorpoid());
 | 
	
		
			
				|  |  | -		body.setCorpvid(head.getCorpvid());
 | 
	
		
			
				|  |  | -		body.setCbodywarehouseid(head.getCwarehouseid());
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	protected boolean canUpdate() {
 | 
	
		
			
				|  |  | -		return false;
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	protected void checkCanInster(AggregatedValueObject vo) {
 | 
	
		
			
				|  |  | -		this.checkBillFlag(vo);
 | 
	
		
			
				|  |  | -		(new CheckMnyUtil()).checkMny(vo);
 | 
	
		
			
				|  |  | -		(new CheckScaleUtil()).checkScale(vo);
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	private void checkBillFlag(AggregatedValueObject vo) {
 | 
	
		
			
				|  |  | -		if (!Integer.valueOf(ICSpecialBillFlag.getFreeFlag())
 | 
	
		
			
				|  |  | -				.equals(vo.getParentVO().getAttributeValue(this.getBillStatusKey()))) {
 | 
	
		
			
				|  |  | -			ExceptionUtils
 | 
	
		
			
				|  |  | -					.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4008001_0", "04008001-0816"));
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	protected String getBillStatusKey() {
 | 
	
		
			
				|  |  | -		return "fbillflag";
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -}
 |