|
@@ -1,412 +1,429 @@
|
|
|
-package nc.bs.ic.general.plugins;
|
|
|
-
|
|
|
-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 nc.bs.framework.common.NCLocator;
|
|
|
-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.pubitf.scmf.ic.mbatchcode.IBatchcodePubService;
|
|
|
-import nc.vo.ic.general.define.ICBillBodyVO;
|
|
|
-import nc.vo.ic.general.define.ICBillFlag;
|
|
|
-import nc.vo.ic.general.define.ICBillHeadVO;
|
|
|
-import nc.vo.ic.general.define.ICBillVO;
|
|
|
-import nc.vo.ic.general.define.MetaNameConst;
|
|
|
-import nc.vo.ic.general.util.InOutHelp;
|
|
|
-import nc.vo.ic.pub.define.ICBillTableInfo;
|
|
|
-import nc.vo.ic.pub.define.ICPubMetaNameConst;
|
|
|
-import nc.vo.ic.pub.util.StringUtil;
|
|
|
-import nc.vo.ic.pub.util.ValueCheckUtil;
|
|
|
-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.VOStatus;
|
|
|
-import nc.vo.pub.lang.UFBoolean;
|
|
|
-import nc.vo.pub.pf.workflow.IPFActionName;
|
|
|
-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;
|
|
|
-import nc.vo.scmf.ic.mbatchcode.BatchcodeVO;
|
|
|
-
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
-
|
|
|
-/**
|
|
|
- * 外部交换平台,导入外部普通单数据处理类
|
|
|
- *
|
|
|
- * @since 6.0
|
|
|
- * @version 2011-4-25 下午04:07:36
|
|
|
- * @author wanghna
|
|
|
- */
|
|
|
-public class GeneralDefdocPlugin extends AbstractPfxxPlugin {
|
|
|
- @Override
|
|
|
- protected Object processBill(Object vo, ISwapContext swapContext,
|
|
|
- AggxsysregisterVO aggxsysvo) throws BusinessException {
|
|
|
-
|
|
|
- if (vo == null)
|
|
|
- throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
- .getStrByID("4008001_0", "04008001-0137")/*@res "转换后的vo数据为空"*/);
|
|
|
-
|
|
|
- String vopk =
|
|
|
- PfxxPluginUtils.queryBillPKBeforeSaveOrUpdate(
|
|
|
- swapContext.getBilltype(), swapContext.getDocID(),
|
|
|
- swapContext.getOrgPk());
|
|
|
-
|
|
|
- if (!StringUtil.isSEmptyOrNull(vopk) && !this.canUpdate())
|
|
|
- throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
- .getStrByID("4008001_0", "04008001-0138")/*@res "当前单据以前被导入过"*/);
|
|
|
- // TODO 如果存在是否允许更新
|
|
|
- // PfxxPluginUtils.checkBillCanBeUpdate(UfinterfaceVO swapContext);
|
|
|
-
|
|
|
- ICBillVO icbill = (ICBillVO) vo;
|
|
|
- icbill.getHead().setCgeneralhid(vopk);
|
|
|
-
|
|
|
- ICBillVO[] icbills = null;
|
|
|
- if (ValueUtils.getBoolean(swapContext.getReplace()))
|
|
|
- icbills = this.doUpdate(swapContext, icbill);
|
|
|
- else
|
|
|
- icbills = this.doSave(swapContext, icbill);
|
|
|
-
|
|
|
- return icbills[0].getHead().getCgeneralhid();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 新增
|
|
|
- *
|
|
|
- * @param swapContext
|
|
|
- * @param icbill
|
|
|
- * @return
|
|
|
- * @throws BusinessException
|
|
|
- */
|
|
|
- private ICBillVO[] doSave(ISwapContext swapContext, ICBillVO icbill)
|
|
|
- throws BusinessException {
|
|
|
- //检查是否允许保存
|
|
|
- this.checkCanInster(icbill);
|
|
|
- Logger.info("保存新单据前处理...");
|
|
|
- this.processBeforeSave(icbill);
|
|
|
-
|
|
|
- // TODO 单据设置有辅助信息,aggxsysvo为用户配置的具体辅助信息
|
|
|
-
|
|
|
- Logger.info("保存新单据...");
|
|
|
- IPFBusiAction service = NCLocator.getInstance().lookup(IPFBusiAction.class);
|
|
|
- ICBillVO[] icbills =
|
|
|
- (ICBillVO[]) service.processAction(IPFActionName.WRITE,
|
|
|
- swapContext.getBilltype(), null, icbill, null, null);
|
|
|
- //zth
|
|
|
- icbills =
|
|
|
- (ICBillVO[]) service.processAction(IPFActionName.APPROVE,
|
|
|
- swapContext.getBilltype(), null, icbill, null, null);
|
|
|
-
|
|
|
- Logger.info("保存新单据完成...");
|
|
|
-
|
|
|
- Logger.info("保存新单据后处理...");
|
|
|
- this.processAfterSave(icbill);
|
|
|
-
|
|
|
- if (ValueCheckUtil.isNullORZeroLength(icbills))
|
|
|
- return null;
|
|
|
-
|
|
|
- if (this.canUpdate())
|
|
|
- PfxxPluginUtils.addDocIDVsPKContrast(swapContext.getBilltype(),
|
|
|
- swapContext.getDocID(), swapContext.getOrgPk(), icbills[0].getHead()
|
|
|
- .getCgeneralhid());
|
|
|
- return icbills;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改:先删除,后新增
|
|
|
- *
|
|
|
- * @param swapContext
|
|
|
- * @param icbill
|
|
|
- * @return
|
|
|
- * @throws BusinessException
|
|
|
- */
|
|
|
- private ICBillVO[] doUpdate(ISwapContext swapContext, ICBillVO icbill)
|
|
|
- throws BusinessException {
|
|
|
- ICBillVO bill = getOriBillVO(icbill, swapContext.getBilltype());
|
|
|
- if (bill != null) {
|
|
|
- IPFBusiAction service =
|
|
|
- NCLocator.getInstance().lookup(IPFBusiAction.class);
|
|
|
- service.processAction(IPFActionName.DEL_DELETE,
|
|
|
- swapContext.getBilltype(), null, bill, null, null);
|
|
|
- }
|
|
|
- return this.doSave(swapContext, icbill);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据单据号获得已存在的vo
|
|
|
- *
|
|
|
- * @param icbill
|
|
|
- * @param billtype
|
|
|
- * @return
|
|
|
- */
|
|
|
- private ICBillVO getOriBillVO(ICBillVO icbill, String billtype) {
|
|
|
- if (StringUtil.isSEmptyOrNull(icbill.getHead().getVbillcode()))
|
|
|
- return null;
|
|
|
- SqlBuilder where = new SqlBuilder();
|
|
|
- where.append(" and ");
|
|
|
- where.append(ICPubMetaNameConst.VBILLCODE, icbill.getHead().getVbillcode());
|
|
|
- where.append(" and ");
|
|
|
- where.append(ICPubMetaNameConst.PK_GROUP, icbill.getHead().getPk_group());
|
|
|
- // where.append(" and ");
|
|
|
- // where.append(ICPubMetaNameConst.PK_ORG,icbill.getHead().getPk_org());
|
|
|
-
|
|
|
- ICBillTableInfo billinfo =
|
|
|
- ICBillTableInfo.getICBillTableInfo(InOutHelp.getICBillType(billtype));
|
|
|
- VOQuery<ICBillHeadVO> query =
|
|
|
- new VOQuery<ICBillHeadVO>(billinfo.getHeadClass());
|
|
|
- ICBillHeadVO[] heads = query.query(where.toString(), null);
|
|
|
- if (ValueCheckUtil.isNullORZeroLength(heads))
|
|
|
- return null;
|
|
|
- where = new SqlBuilder();
|
|
|
- where.append(" and ");
|
|
|
- where.append(MetaNameConst.CGENERALHID, heads[0].getCgeneralhid());
|
|
|
- VOQuery<ICBillBodyVO> bodyquery =
|
|
|
- new VOQuery<ICBillBodyVO>(billinfo.getBodyClass());
|
|
|
- ICBillBodyVO[] bodys = bodyquery.query(where.toString(), null);
|
|
|
- if (ValueCheckUtil.isNullORZeroLength(bodys))
|
|
|
- return null;
|
|
|
-
|
|
|
- ICBillVO bill = billinfo.createBillVO();
|
|
|
- bill.setParent(heads[0]);
|
|
|
- bill.setChildrenVO(bodys);
|
|
|
- return bill;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 单据保存前处理
|
|
|
- *
|
|
|
- * @param vo
|
|
|
- */
|
|
|
- protected void processBeforeSave(ICBillVO vo) throws BusinessException {
|
|
|
-
|
|
|
- if (null == vo)
|
|
|
- throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
- .getStrByID("4008001_0", "04008001-0139")/*@res "单据不能为空"*/);
|
|
|
-
|
|
|
- // this.checkNullValue(vo);
|
|
|
- // 表头组织翻译后没有赋值,需要重表体字段重新取一边
|
|
|
- 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());
|
|
|
-
|
|
|
- ICBSContext context = new ICBSContext();
|
|
|
- this.headVOProcess(vo.getHead(), context);
|
|
|
- this.bodyVOProcess(vo, context);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 单据保存后处理
|
|
|
- *
|
|
|
- * @param vo
|
|
|
- */
|
|
|
- protected void processAfterSave(ICBillVO vo) throws BusinessException {
|
|
|
- if (null == vo)
|
|
|
- throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
- .getStrByID("4008001_0", "04008001-0140")/*@res "单据保存失败"*/);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 表头处理,处理默认值,公司,单据日期,单据状态,打印次数,集团
|
|
|
- *
|
|
|
- * @param vo
|
|
|
- */
|
|
|
- private void headVOProcess(ICBillHeadVO vo, ICBSContext context) {
|
|
|
- vo.setStatus(VOStatus.NEW);
|
|
|
- // 集团
|
|
|
- if (StringUtil.isSEmptyOrNull(vo.getPk_group()))
|
|
|
- vo.setPk_group(context.getPk_group());
|
|
|
- // 打印次数
|
|
|
- if (vo.getIprintcount() == null)
|
|
|
- vo.setIprintcount(Integer.valueOf(0));
|
|
|
- // 单据状态
|
|
|
- if (vo.getFbillflag() == null)
|
|
|
- vo.setFbillflag((Integer) ICBillFlag.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())) {
|
|
|
- // uap不支持单据类型的翻译,暂时以交易类型code查询id的方式补交易类型
|
|
|
- String vtrantypecode = vo.getVtrantypecode();
|
|
|
- Map<String, String> map =
|
|
|
- PfServiceScmUtil.getTrantypeidByCode(new String[] {
|
|
|
- vtrantypecode
|
|
|
- });
|
|
|
- vo.setCtrantypeid(map == null ? null : map.get(vtrantypecode));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 单据表体处理
|
|
|
- *
|
|
|
- * @param vo
|
|
|
- * @param context
|
|
|
- * @throws BusinessException
|
|
|
- */
|
|
|
- private void bodyVOProcess(ICBillVO vo, ICBSContext context)
|
|
|
- throws BusinessException {
|
|
|
- ICBillBodyVO[] vos = vo.getBodys();
|
|
|
- if (ValueCheckUtil.isNullORZeroLength(vos))
|
|
|
- throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
- .getStrByID("4008001_0", "04008001-0141")/*@res "单据表体不能为空"*/);
|
|
|
-
|
|
|
- VORowNoUtils.setVOsRowNoByRule(vos, ICPubMetaNameConst.CROWNO);// 行号处理
|
|
|
-
|
|
|
- ICBillHeadVO head = vo.getHead();
|
|
|
- Map<String, BatchcodeVO> batchmap = this.getBatchcodeVO(vos);
|
|
|
- for (ICBillBodyVO body : vos) {
|
|
|
- body.setStatus(VOStatus.NEW);
|
|
|
- if (StringUtil.isSEmptyOrNull(body.getCmaterialoid())
|
|
|
- || StringUtil.isSEmptyOrNull(body.getCmaterialvid()))
|
|
|
- throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
- .getStrByID("4008001_0", "04008001-0142")/*@res "单据表体物料不能为空"*/);
|
|
|
-
|
|
|
- body.setBbarcodeclose(UFBoolean.FALSE);// 单据行是否条码关闭
|
|
|
- body.setBonroadflag(UFBoolean.FALSE);// 是否在途
|
|
|
- if (body.getNnum()!=null &&body.getNassistnum()!=null&&body.getDbizdate() == null)
|
|
|
- body.setDbizdate(context.getBizDate());// 业务日期
|
|
|
- // 辅单位
|
|
|
- if (StringUtil.isSEmptyOrNull(body.getCastunitid()))
|
|
|
- body.setCastunitid(context.getInvInfo()
|
|
|
- .getInvBasVO(body.getCmaterialvid()).getPk_stockmeas());
|
|
|
-
|
|
|
- // 有批次号但无批次主键时, 需要补全批次主键,有必要时(保质期管理)补全生产日期和失效日期
|
|
|
- if (!StringUtils.isEmpty(body.getVbatchcode())
|
|
|
- && StringUtils.isEmpty(body.getPk_batchcode())) {
|
|
|
- BatchcodeVO batchvo =
|
|
|
- batchmap.get(body.getCmaterialvid() + body.getVbatchcode());
|
|
|
- if (batchvo != null) {
|
|
|
- body.setPk_batchcode(batchvo.getPk_batchcode());
|
|
|
- body.setDproducedate(batchvo.getDproducedate());
|
|
|
- body.setDvalidate(batchvo.getDvalidate());
|
|
|
- }
|
|
|
- }
|
|
|
- bodyVOCopyFromHeadVO(body, head);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取批次号档案
|
|
|
- *
|
|
|
- * @param vos
|
|
|
- * @return Map<String(cmaterialvid+vbatchcode), BatchcodeVO批次档案>
|
|
|
- */
|
|
|
- private Map<String, BatchcodeVO> getBatchcodeVO(ICBillBodyVO[] vos) {
|
|
|
- List<String> cmaterialvidList = new ArrayList<String>();
|
|
|
- List<String> vbatchcodeList = new ArrayList<String>();
|
|
|
- Set<String> materialbatch = new HashSet<String>();
|
|
|
- for (ICBillBodyVO body : vos) {
|
|
|
- if (body.getCmaterialvid() != null && body.getVbatchcode() != null) {
|
|
|
- if (materialbatch.contains(body.getCmaterialvid()
|
|
|
- + body.getVbatchcode())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- cmaterialvidList.add(body.getCmaterialvid());
|
|
|
- vbatchcodeList.add(body.getVbatchcode());
|
|
|
- materialbatch.add(body.getCmaterialvid() + body.getVbatchcode());
|
|
|
- }
|
|
|
- }
|
|
|
- if (materialbatch.size() == 0) {
|
|
|
- return new HashMap<String, BatchcodeVO>();
|
|
|
- }
|
|
|
- IBatchcodePubService batchservice =
|
|
|
- NCLocator.getInstance().lookup(IBatchcodePubService.class);
|
|
|
- BatchcodeVO[] batchvos = null;
|
|
|
- try {
|
|
|
- batchvos =
|
|
|
- batchservice.queryBatchVOs(cmaterialvidList.toArray(new String[0]),
|
|
|
- vbatchcodeList.toArray(new String[0]));
|
|
|
- }
|
|
|
- catch (BusinessException e) {
|
|
|
- ExceptionUtils.wrappException(e);
|
|
|
- }
|
|
|
-
|
|
|
- if (batchvos == null || batchvos.length == 0) {
|
|
|
- return new HashMap<String, BatchcodeVO>();
|
|
|
- }
|
|
|
- Map<String, BatchcodeVO> batchmap = new HashMap<String, BatchcodeVO>();
|
|
|
- for (BatchcodeVO batchvo : batchvos) {
|
|
|
- batchmap
|
|
|
- .put(batchvo.getCmaterialvid() + batchvo.getVbatchcode(), batchvo);
|
|
|
- }
|
|
|
- return batchmap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据表头设置表体默认值,表体集团,库存组织,公司,仓库,交易类型
|
|
|
- *
|
|
|
- * @param body
|
|
|
- * @param head
|
|
|
- */
|
|
|
- private void bodyVOCopyFromHeadVO(ICBillBodyVO body, ICBillHeadVO 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());
|
|
|
- body.setCbodytranstypecode(head.getVtrantypecode());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 是否允许更新
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- protected boolean canUpdate() {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 检验vo是否可更新
|
|
|
- *
|
|
|
- * @param vo
|
|
|
- */
|
|
|
- protected void checkCanInster(AggregatedValueObject vo) {
|
|
|
- this.checkBillFlag(vo);
|
|
|
- new CheckMnyUtil().checkMny(vo);
|
|
|
- new CheckScaleUtil().checkScale(vo);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 检验vo状态
|
|
|
- *
|
|
|
- * @param vo
|
|
|
- */
|
|
|
- private void checkBillFlag(AggregatedValueObject vo) {
|
|
|
- if (!Integer.valueOf(ICBillFlag.getFreeFlag()).equals(
|
|
|
- vo.getParentVO().getAttributeValue(this.getBillStatusKey()))) {
|
|
|
- ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl
|
|
|
- .getNCLangRes().getStrByID("4008001_0", "04008001-0816")/*
|
|
|
- * @res
|
|
|
- * "非自由态的单据不允许导入!"
|
|
|
- */);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected String getBillStatusKey() {
|
|
|
- return ICPubMetaNameConst.FBILLFLAG;
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+package nc.bs.ic.general.plugins;
|
|
|
+
|
|
|
+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 nc.bs.framework.common.NCLocator;
|
|
|
+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.pubitf.scmf.ic.mbatchcode.IBatchcodePubService;
|
|
|
+import nc.vo.ic.general.define.ICBillBodyVO;
|
|
|
+import nc.vo.ic.general.define.ICBillFlag;
|
|
|
+import nc.vo.ic.general.define.ICBillHeadVO;
|
|
|
+import nc.vo.ic.general.define.ICBillVO;
|
|
|
+import nc.vo.ic.general.define.MetaNameConst;
|
|
|
+import nc.vo.ic.general.util.InOutHelp;
|
|
|
+import nc.vo.ic.pub.define.ICBillTableInfo;
|
|
|
+import nc.vo.ic.pub.define.ICPubMetaNameConst;
|
|
|
+import nc.vo.ic.pub.util.StringUtil;
|
|
|
+import nc.vo.ic.pub.util.ValueCheckUtil;
|
|
|
+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.VOStatus;
|
|
|
+import nc.vo.pub.lang.UFBoolean;
|
|
|
+import nc.vo.pub.pf.workflow.IPFActionName;
|
|
|
+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;
|
|
|
+import nc.vo.scmf.ic.mbatchcode.BatchcodeVO;
|
|
|
+
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 外部交换平台,导入外部普通单数据处理类
|
|
|
+ *
|
|
|
+ * @since 6.0
|
|
|
+ * @version 2011-4-25 下午04:07:36
|
|
|
+ * @author wanghna
|
|
|
+ */
|
|
|
+public class GeneralDefdocPlugin extends AbstractPfxxPlugin {
|
|
|
+ @Override
|
|
|
+ protected Object processBill(Object vo, ISwapContext swapContext,
|
|
|
+ AggxsysregisterVO aggxsysvo) throws BusinessException {
|
|
|
+
|
|
|
+ if (vo == null)
|
|
|
+ throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
+ .getStrByID("4008001_0", "04008001-0137")/*@res "转换后的vo数据为空"*/);
|
|
|
+
|
|
|
+ String vopk =
|
|
|
+ PfxxPluginUtils.queryBillPKBeforeSaveOrUpdate(
|
|
|
+ swapContext.getBilltype(), swapContext.getDocID(),
|
|
|
+ swapContext.getOrgPk());
|
|
|
+
|
|
|
+ if (!StringUtil.isSEmptyOrNull(vopk) && !this.canUpdate())
|
|
|
+ throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
+ .getStrByID("4008001_0", "04008001-0138")/*@res "当前单据以前被导入过"*/);
|
|
|
+ // TODO 如果存在是否允许更新
|
|
|
+ // PfxxPluginUtils.checkBillCanBeUpdate(UfinterfaceVO swapContext);
|
|
|
+
|
|
|
+ ICBillVO icbill = (ICBillVO) vo;
|
|
|
+ icbill.getHead().setCgeneralhid(vopk);
|
|
|
+
|
|
|
+ ICBillVO[] icbills = null;
|
|
|
+ if (ValueUtils.getBoolean(swapContext.getReplace()))
|
|
|
+ icbills = this.doUpdate(swapContext, icbill);
|
|
|
+ else
|
|
|
+ icbills = this.doSave(swapContext, icbill);
|
|
|
+
|
|
|
+ return icbills[0].getHead().getCgeneralhid();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ *
|
|
|
+ * @param swapContext
|
|
|
+ * @param icbill
|
|
|
+ * @return
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ private ICBillVO[] doSave(ISwapContext swapContext, ICBillVO icbill)
|
|
|
+ throws BusinessException {
|
|
|
+ //检查是否允许保存
|
|
|
+ this.checkCanInster(icbill);
|
|
|
+ Logger.info("保存新单据前处理...");
|
|
|
+ this.processBeforeSave(icbill);
|
|
|
+
|
|
|
+ // TODO 单据设置有辅助信息,aggxsysvo为用户配置的具体辅助信息
|
|
|
+
|
|
|
+ Logger.info("保存新单据...");
|
|
|
+ IPFBusiAction service = NCLocator.getInstance().lookup(IPFBusiAction.class);
|
|
|
+ ICBillVO[] icbills =
|
|
|
+ (ICBillVO[]) service.processAction(IPFActionName.WRITE,swapContext.getBilltype(), null, icbill, null, null);
|
|
|
+ //其它领料
|
|
|
+ if(swapContext.getBilltype().equals("4C")){
|
|
|
+ service.processAction("SIGN","4C", null, icbill, null, null);
|
|
|
+ }
|
|
|
+ //其他入库
|
|
|
+ if(swapContext.getBilltype().equals("4A")){
|
|
|
+ service.processAction("SIGN","4A", null, icbill, null, null);
|
|
|
+ }
|
|
|
+ //其他出库
|
|
|
+ if(swapContext.getBilltype().equals("4I")){
|
|
|
+ service.processAction("SIGN","4I", null, icbill, null, null);
|
|
|
+ }
|
|
|
+ //委外领料——材料出库
|
|
|
+ if(swapContext.getBilltype().equals("4D")){
|
|
|
+ service.processAction("SIGN","4D", null, icbill, null, null);
|
|
|
+ }
|
|
|
+ //委托加工入库
|
|
|
+ if(swapContext.getBilltype().equals("47")){
|
|
|
+ service.processAction("SIGN","47", null, icbill, null, null);
|
|
|
+ }
|
|
|
+ if(swapContext.getBilltype().equals("45")){
|
|
|
+ service.processAction("SIGN","45", null, icbill, null, null);
|
|
|
+ }
|
|
|
+ Logger.info("保存新单据完成...");
|
|
|
+
|
|
|
+ Logger.info("保存新单据后处理...");
|
|
|
+ this.processAfterSave(icbill);
|
|
|
+
|
|
|
+ if (ValueCheckUtil.isNullORZeroLength(icbills))
|
|
|
+ return null;
|
|
|
+
|
|
|
+ if (this.canUpdate())
|
|
|
+ PfxxPluginUtils.addDocIDVsPKContrast(swapContext.getBilltype(),
|
|
|
+ swapContext.getDocID(), swapContext.getOrgPk(), icbills[0].getHead()
|
|
|
+ .getCgeneralhid());
|
|
|
+ return icbills;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改:先删除,后新增
|
|
|
+ *
|
|
|
+ * @param swapContext
|
|
|
+ * @param icbill
|
|
|
+ * @return
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ private ICBillVO[] doUpdate(ISwapContext swapContext, ICBillVO icbill)
|
|
|
+ throws BusinessException {
|
|
|
+ ICBillVO bill = getOriBillVO(icbill, swapContext.getBilltype());
|
|
|
+ if (bill != null) {
|
|
|
+ IPFBusiAction service =
|
|
|
+ NCLocator.getInstance().lookup(IPFBusiAction.class);
|
|
|
+ service.processAction(IPFActionName.DEL_DELETE,
|
|
|
+ swapContext.getBilltype(), null, bill, null, null);
|
|
|
+ }
|
|
|
+ return this.doSave(swapContext, icbill);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据单据号获得已存在的vo
|
|
|
+ *
|
|
|
+ * @param icbill
|
|
|
+ * @param billtype
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ICBillVO getOriBillVO(ICBillVO icbill, String billtype) {
|
|
|
+ if (StringUtil.isSEmptyOrNull(icbill.getHead().getVbillcode()))
|
|
|
+ return null;
|
|
|
+ SqlBuilder where = new SqlBuilder();
|
|
|
+ where.append(" and ");
|
|
|
+ where.append(ICPubMetaNameConst.VBILLCODE, icbill.getHead().getVbillcode());
|
|
|
+ where.append(" and ");
|
|
|
+ where.append(ICPubMetaNameConst.PK_GROUP, icbill.getHead().getPk_group());
|
|
|
+ // where.append(" and ");
|
|
|
+ // where.append(ICPubMetaNameConst.PK_ORG,icbill.getHead().getPk_org());
|
|
|
+
|
|
|
+ ICBillTableInfo billinfo =
|
|
|
+ ICBillTableInfo.getICBillTableInfo(InOutHelp.getICBillType(billtype));
|
|
|
+ VOQuery<ICBillHeadVO> query =
|
|
|
+ new VOQuery<ICBillHeadVO>(billinfo.getHeadClass());
|
|
|
+ ICBillHeadVO[] heads = query.query(where.toString(), null);
|
|
|
+ if (ValueCheckUtil.isNullORZeroLength(heads))
|
|
|
+ return null;
|
|
|
+ where = new SqlBuilder();
|
|
|
+ where.append(" and ");
|
|
|
+ where.append(MetaNameConst.CGENERALHID, heads[0].getCgeneralhid());
|
|
|
+ VOQuery<ICBillBodyVO> bodyquery =
|
|
|
+ new VOQuery<ICBillBodyVO>(billinfo.getBodyClass());
|
|
|
+ ICBillBodyVO[] bodys = bodyquery.query(where.toString(), null);
|
|
|
+ if (ValueCheckUtil.isNullORZeroLength(bodys))
|
|
|
+ return null;
|
|
|
+
|
|
|
+ ICBillVO bill = billinfo.createBillVO();
|
|
|
+ bill.setParent(heads[0]);
|
|
|
+ bill.setChildrenVO(bodys);
|
|
|
+ return bill;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单据保存前处理
|
|
|
+ *
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ protected void processBeforeSave(ICBillVO vo) throws BusinessException {
|
|
|
+
|
|
|
+ if (null == vo)
|
|
|
+ throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
+ .getStrByID("4008001_0", "04008001-0139")/*@res "单据不能为空"*/);
|
|
|
+
|
|
|
+ // this.checkNullValue(vo);
|
|
|
+ // 表头组织翻译后没有赋值,需要重表体字段重新取一边
|
|
|
+ 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());
|
|
|
+
|
|
|
+ ICBSContext context = new ICBSContext();
|
|
|
+ this.headVOProcess(vo.getHead(), context);
|
|
|
+ this.bodyVOProcess(vo, context);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单据保存后处理
|
|
|
+ *
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ protected void processAfterSave(ICBillVO vo) throws BusinessException {
|
|
|
+ if (null == vo)
|
|
|
+ throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
+ .getStrByID("4008001_0", "04008001-0140")/*@res "单据保存失败"*/);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 表头处理,处理默认值,公司,单据日期,单据状态,打印次数,集团
|
|
|
+ *
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ private void headVOProcess(ICBillHeadVO vo, ICBSContext context) {
|
|
|
+ vo.setStatus(VOStatus.NEW);
|
|
|
+ // 集团
|
|
|
+ if (StringUtil.isSEmptyOrNull(vo.getPk_group()))
|
|
|
+ vo.setPk_group(context.getPk_group());
|
|
|
+ // 打印次数
|
|
|
+ if (vo.getIprintcount() == null)
|
|
|
+ vo.setIprintcount(Integer.valueOf(0));
|
|
|
+ // 单据状态
|
|
|
+ if (vo.getFbillflag() == null)
|
|
|
+ vo.setFbillflag((Integer) ICBillFlag.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())) {
|
|
|
+ // uap不支持单据类型的翻译,暂时以交易类型code查询id的方式补交易类型
|
|
|
+ String vtrantypecode = vo.getVtrantypecode();
|
|
|
+ Map<String, String> map =
|
|
|
+ PfServiceScmUtil.getTrantypeidByCode(new String[] {
|
|
|
+ vtrantypecode
|
|
|
+ });
|
|
|
+ vo.setCtrantypeid(map == null ? null : map.get(vtrantypecode));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单据表体处理
|
|
|
+ *
|
|
|
+ * @param vo
|
|
|
+ * @param context
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ private void bodyVOProcess(ICBillVO vo, ICBSContext context)
|
|
|
+ throws BusinessException {
|
|
|
+ ICBillBodyVO[] vos = vo.getBodys();
|
|
|
+ if (ValueCheckUtil.isNullORZeroLength(vos))
|
|
|
+ throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
+ .getStrByID("4008001_0", "04008001-0141")/*@res "单据表体不能为空"*/);
|
|
|
+
|
|
|
+ VORowNoUtils.setVOsRowNoByRule(vos, ICPubMetaNameConst.CROWNO);// 行号处理
|
|
|
+
|
|
|
+ ICBillHeadVO head = vo.getHead();
|
|
|
+ Map<String, BatchcodeVO> batchmap = this.getBatchcodeVO(vos);
|
|
|
+ for (ICBillBodyVO body : vos) {
|
|
|
+ body.setStatus(VOStatus.NEW);
|
|
|
+ if (StringUtil.isSEmptyOrNull(body.getCmaterialoid())
|
|
|
+ || StringUtil.isSEmptyOrNull(body.getCmaterialvid()))
|
|
|
+ throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
|
|
|
+ .getStrByID("4008001_0", "04008001-0142")/*@res "单据表体物料不能为空"*/);
|
|
|
+
|
|
|
+ body.setBbarcodeclose(UFBoolean.FALSE);// 单据行是否条码关闭
|
|
|
+ body.setBonroadflag(UFBoolean.FALSE);// 是否在途
|
|
|
+ if (body.getNnum()!=null &&body.getNassistnum()!=null&&body.getDbizdate() == null)
|
|
|
+ body.setDbizdate(context.getBizDate());// 业务日期
|
|
|
+ // 辅单位
|
|
|
+ if (StringUtil.isSEmptyOrNull(body.getCastunitid()))
|
|
|
+ body.setCastunitid(context.getInvInfo()
|
|
|
+ .getInvBasVO(body.getCmaterialvid()).getPk_stockmeas());
|
|
|
+
|
|
|
+ // 有批次号但无批次主键时, 需要补全批次主键,有必要时(保质期管理)补全生产日期和失效日期
|
|
|
+ if (!StringUtils.isEmpty(body.getVbatchcode())
|
|
|
+ && StringUtils.isEmpty(body.getPk_batchcode())) {
|
|
|
+ BatchcodeVO batchvo =
|
|
|
+ batchmap.get(body.getCmaterialvid() + body.getVbatchcode());
|
|
|
+ if (batchvo != null) {
|
|
|
+ body.setPk_batchcode(batchvo.getPk_batchcode());
|
|
|
+ body.setDproducedate(batchvo.getDproducedate());
|
|
|
+ body.setDvalidate(batchvo.getDvalidate());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bodyVOCopyFromHeadVO(body, head);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取批次号档案
|
|
|
+ *
|
|
|
+ * @param vos
|
|
|
+ * @return Map<String(cmaterialvid+vbatchcode), BatchcodeVO批次档案>
|
|
|
+ */
|
|
|
+ private Map<String, BatchcodeVO> getBatchcodeVO(ICBillBodyVO[] vos) {
|
|
|
+ List<String> cmaterialvidList = new ArrayList<String>();
|
|
|
+ List<String> vbatchcodeList = new ArrayList<String>();
|
|
|
+ Set<String> materialbatch = new HashSet<String>();
|
|
|
+ for (ICBillBodyVO body : vos) {
|
|
|
+ if (body.getCmaterialvid() != null && body.getVbatchcode() != null) {
|
|
|
+ if (materialbatch.contains(body.getCmaterialvid()
|
|
|
+ + body.getVbatchcode())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ cmaterialvidList.add(body.getCmaterialvid());
|
|
|
+ vbatchcodeList.add(body.getVbatchcode());
|
|
|
+ materialbatch.add(body.getCmaterialvid() + body.getVbatchcode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (materialbatch.size() == 0) {
|
|
|
+ return new HashMap<String, BatchcodeVO>();
|
|
|
+ }
|
|
|
+ IBatchcodePubService batchservice =
|
|
|
+ NCLocator.getInstance().lookup(IBatchcodePubService.class);
|
|
|
+ BatchcodeVO[] batchvos = null;
|
|
|
+ try {
|
|
|
+ batchvos =
|
|
|
+ batchservice.queryBatchVOs(cmaterialvidList.toArray(new String[0]),
|
|
|
+ vbatchcodeList.toArray(new String[0]));
|
|
|
+ }
|
|
|
+ catch (BusinessException e) {
|
|
|
+ ExceptionUtils.wrappException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (batchvos == null || batchvos.length == 0) {
|
|
|
+ return new HashMap<String, BatchcodeVO>();
|
|
|
+ }
|
|
|
+ Map<String, BatchcodeVO> batchmap = new HashMap<String, BatchcodeVO>();
|
|
|
+ for (BatchcodeVO batchvo : batchvos) {
|
|
|
+ batchmap
|
|
|
+ .put(batchvo.getCmaterialvid() + batchvo.getVbatchcode(), batchvo);
|
|
|
+ }
|
|
|
+ return batchmap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据表头设置表体默认值,表体集团,库存组织,公司,仓库,交易类型
|
|
|
+ *
|
|
|
+ * @param body
|
|
|
+ * @param head
|
|
|
+ */
|
|
|
+ private void bodyVOCopyFromHeadVO(ICBillBodyVO body, ICBillHeadVO 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());
|
|
|
+ body.setCbodytranstypecode(head.getVtrantypecode());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否允许更新
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ protected boolean canUpdate() {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检验vo是否可更新
|
|
|
+ *
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ protected void checkCanInster(AggregatedValueObject vo) {
|
|
|
+ this.checkBillFlag(vo);
|
|
|
+ new CheckMnyUtil().checkMny(vo);
|
|
|
+ new CheckScaleUtil().checkScale(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检验vo状态
|
|
|
+ *
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ private void checkBillFlag(AggregatedValueObject vo) {
|
|
|
+ if (!Integer.valueOf(ICBillFlag.getFreeFlag()).equals(
|
|
|
+ vo.getParentVO().getAttributeValue(this.getBillStatusKey()))) {
|
|
|
+ ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl
|
|
|
+ .getNCLangRes().getStrByID("4008001_0", "04008001-0816")/*
|
|
|
+ * @res
|
|
|
+ * "非自由态的单据不允许导入!"
|
|
|
+ */);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String getBillStatusKey() {
|
|
|
+ return ICPubMetaNameConst.FBILLFLAG;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|