diff --git a/sscivm/src/private/nccloud/itf/sscivm/ivsale/impl/IVApplicationServiceImpl.java b/sscivm/src/private/nccloud/itf/sscivm/ivsale/impl/IVApplicationServiceImpl.java new file mode 100644 index 0000000..637886b --- /dev/null +++ b/sscivm/src/private/nccloud/itf/sscivm/ivsale/impl/IVApplicationServiceImpl.java @@ -0,0 +1,796 @@ +package nccloud.itf.sscivm.ivsale.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +import nc.bs.dao.BaseDAO; +import nc.bs.framework.common.InvocationInfoProxy; +import nc.bs.framework.common.NCLocator; +import nc.bs.framework.common.RuntimeEnv; +import nc.bs.framework.core.service.TimeService; +import nc.bs.logging.Logger; +import nc.bs.sscivm.ivsale.bp.IVApplicationDeleteBP; +import nc.bs.sscivm.ivsale.bp.IVApplicationInsertBP; +import nc.bs.sscivm.ivsale.bp.IVApplicationQueryBP; +import nc.bs.sscivm.ivsale.bp.IVApplicationUpdateBP; +import nc.bs.sscivm.ivsale.ivaconst.IVAWebConst; +import nc.bs.sscivm.ivsale.util.ActionUtils; +import nc.bs.sscivm.ivsale.util.IVApplicationBillDefValue; +import nc.bs.sscivm.ivsale.util.IVApplicationEventType; +import nc.bs.sscivm.ivsale.util.IVApplicationSlsmUtil; +import nc.bs.sscivm.ivsale.util.IVSaleUtil; +import nc.bs.sscivm.util.IVMSagaValidationUtils; +import nc.impl.pubapp.pattern.data.bill.tool.BillTransferTool; +import nc.itf.uap.pf.IWorkflowDefine; +import nc.itf.uap.pf.IWorkflowMachine; +import nc.itf.uap.pf.metadata.IFlowBizItf; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.jdbc.framework.processor.MapListProcessor; +import nc.pubitf.bbd.CurrtypeQuery; +import nc.pubitf.para.SysInitQuery; +import nc.pubitf.uapbd.CurrencyRateUtilHelper; +import nc.uap.pf.metadata.PfMetadataTools; +import nc.vo.bd.currtype.CurrtypeVO; +import nc.vo.ic.pub.util.StringUtil; +import nc.vo.ml.NCLangRes4VoTransl; +import nc.vo.pf.change.PfUtilBaseTools; +import nc.vo.pf.pub.util.SQLUtil; +import nc.vo.pub.AggregatedValueObject; +import nc.vo.pub.BusinessException; +import nc.vo.pub.CircularlyAccessibleValueObject; +import nc.vo.pub.VOStatus; +import nc.vo.pub.lang.UFBoolean; +import nc.vo.pub.lang.UFDate; +import nc.vo.pub.lang.UFDateTime; +import nc.vo.pub.lang.UFDouble; +import nc.vo.pub.pf.workflow.IPFActionName; +import nc.vo.pub.workflownote.WorkflownoteVO; +import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.sscivm.ivmpub.IVAplocationFPXZ; +import nc.vo.sscivm.ivmpub.IVAplocationKPFS; +import nc.vo.sscivm.ivsale.IVApplicationAggVO; +import nc.vo.sscivm.ivsale.IVApplicationBodyVO; +import nc.vo.sscivm.ivsale.IVApplicationHeadVO; +import nc.vo.sscivm.ivsale.IVApplogVO; +import nc.vo.sscivm.ivsale.IVBilltypeVO; +import nc.vo.sscivm.ivsale.IVTspzsBodyVO; +import nc.vo.sscivm.ivsale.MessageVO; +import nc.vo.trade.pub.IBillStatus; +import nc.vo.uap.pf.PFBusinessException; +import nc.vo.uap.pf.PfProcessBatchRetObject; +import nc.vo.wfengine.definition.WorkflowTypeEnum; +import nccloud.commons.lang.StringUtils; +import nccloud.itf.sscivm.ivsale.service.ApplicationLogService; +import nccloud.itf.sscivm.ivsale.service.IVABilltypeExtService; +import nccloud.itf.sscivm.ivsale.service.IVApplicationInvoiceService; +import nccloud.itf.sscivm.ivsale.service.IVApplicationQueryService; +import nccloud.itf.sscivm.ivsale.service.IVApplicationService; +import nccloud.pubitf.riart.pflow.CloudPFlowContext; +import nccloud.pubitf.riart.pflow.ICloudScriptPFlowService; +import nccloud.putitf.riart.billtype.IBilltypeService; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; +import com.google.gson.internal.LinkedTreeMap; + +public class IVApplicationServiceImpl implements IVApplicationService { + + @Override + public IVApplicationAggVO save(IVApplicationAggVO ivApplicationVO) throws BusinessException { + IVApplicationAggVO[] ivApplicationVOs = null; + try { + ivApplicationVOs = saveBatch(new IVApplicationAggVO[] { ivApplicationVO }); + } catch (Exception e) { + ExceptionUtils.marsh(e); + } + return ivApplicationVOs == null || ivApplicationVOs.length == 0 ? null : ivApplicationVOs[0]; + + } + + @Override + public IVApplicationAggVO[] saveBatch(IVApplicationAggVO[] clientFullVOs) throws BusinessException { + IVApplicationAggVO[] retvos = null; + HashSet retVOLits = new HashSet(); + try { + //BillTransferTool transferTool = new BillTransferTool(clientFullVOs); + IVApplicationInsertBP action = new IVApplicationInsertBP(); + retvos = action.insert(clientFullVOs); + //retvos = (IVApplicationAggVO[]) transferTool.getBillForToClient(retvos); + //处理自动提交 + HashSet tradetypeids = new HashSet(); + for (IVApplicationAggVO applicationAggVO : retvos) { + tradetypeids.add(applicationAggVO.getParentVO().getTranstypecode()); + } + IVBilltypeVO[] billtypeVOS = + NCLocator + .getInstance() + .lookup(IVABilltypeExtService.class) + .getBilltypeVOsByWhere( + " " + + IVBilltypeVO.PK_GROUP + + " ='" + + InvocationInfoProxy.getInstance().getGroupId() + + "' and " + + SQLUtil.buildSqlForIn(IVBilltypeVO.BILLTYPECODE, + tradetypeids.toArray(new String[tradetypeids.size()]))); + //提交时处理自动审批功能 + if (billtypeVOS != null && billtypeVOS.length > 0) { + // 3、自动提交勾选时 + HashSet atuoVOs = new HashSet(); + HashSet noatuoVOs = new HashSet(); + for (IVApplicationAggVO retvo : retvos) { + boolean Isatuo_submit = UFBoolean.FALSE.booleanValue(); + for (IVBilltypeVO billtypeVO : billtypeVOS) { + if (retvo.getParentVO().getTranstypecode() != null + && retvo.getParentVO().getTranstypecode() + .equals(billtypeVO.getBilltypecode())) { + if (billtypeVO.getIsatuo_submit() == UFBoolean.TRUE) { + Isatuo_submit = UFBoolean.TRUE.booleanValue(); + } + } + } + if (Isatuo_submit) { + atuoVOs.add(retvo); + } else { + noatuoVOs.add(retvo); + } + } + if (atuoVOs != null && atuoVOs.size() > 0) { + Object submitObj = this.submit(atuoVOs.toArray(new IVApplicationAggVO[atuoVOs.size()]), null, null); + if (submitObj instanceof Map) { + throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0053")/*@res "开票申请单保存提交失败,下游环节含有指派信息"*/); + } + retvos = (IVApplicationAggVO[])submitObj; + if (retvos != null && retvos.length > 0) { + for (IVApplicationAggVO retvo : retvos) { + retVOLits.add(retvo); + } + if (noatuoVOs != null && noatuoVOs.size() > 0) { + retVOLits.addAll(noatuoVOs); + } + } + retvos = retVOLits.toArray(new IVApplicationAggVO[retVOLits + .size()]); + } else { + if (noatuoVOs != null && noatuoVOs.size() > 0) { + retVOLits.addAll(noatuoVOs); + retvos = retVOLits + .toArray(new IVApplicationAggVO[retVOLits + .size()]); + } + } + } + + } catch (Exception e) { + ExceptionUtils.marsh(e); + } + return retvos; + } + + @Override + public void deleteById(String pk) throws BusinessException { + deleteByIds(new String[] { pk }); + } + + @Override + public void deleteByIds(String[] pks) throws BusinessException { + IVApplicationAggVO[] retvos = new IVApplicationQueryBP().queryAggIVApplicationVOByCondition(SQLUtil.buildSqlForIn( + IVApplicationHeadVO.PK_IVAPPLICATION, pks)); + new IVApplicationDeleteBP().delete(retvos); + } + + @Override + public void delete(IVApplicationAggVO vo) throws BusinessException { + try { + new IVApplicationDeleteBP().delete(new IVApplicationAggVO[] { vo }); + } catch (Exception e) { + ExceptionUtils.marsh(e); + } + } + + @Override + public void deleteBatch(IVApplicationAggVO[] vos) throws BusinessException { + try { + new IVApplicationDeleteBP().delete(vos); + } catch (Exception e) { + ExceptionUtils.marsh(e); + } + } + + @Override + public IVApplicationAggVO update(IVApplicationAggVO ivApplicationVO) throws BusinessException { + IVApplicationAggVO[] retvos = null; + try { + if (ivApplicationVO == null + || ivApplicationVO.getParentVO() == null) { + return null; + } + + Integer approveStatus = ivApplicationVO.getParentVO() + .getBillstatus(); + // 审批通过的单据不允许修改 + if (approveStatus.intValue() == IBillStatus.CHECKPASS) { + throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl + .getNCLangRes() + .getStrByID("1058sal_0", "01058sal-0024")/* + * @res + * "审批通过的单据不允许修改" + */); + } + // 审批进行中的单据只允许当前审批人修改 + if (approveStatus.intValue() == IBillStatus.COMMIT + || approveStatus.intValue() == IBillStatus.CHECKGOING) { + String billId = ivApplicationVO.getParentVO() + .getPk_ivapplication(); + String billType = ivApplicationVO.getParentVO() + .getTranstypecode(); + String userId = InvocationInfoProxy.getInstance().getUserId(); + if (!isFlowCheckman(billId, billType, userId)) { + throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl + .getNCLangRes().getStrByID("1058sal_0", + "01058sal-0050")/* + * @res + * "审批流程中的单据,只有当前审批人可以修改!" + */); + } + } + + //如果来源单据为销售发票,根据来源单据编号src_billno和来源单据类型(billtype = 32)查询销售发票价税合计(ntotalorigmny)与开票申请中价税合计(jshj)比较,须满足 jshj 0){ + throw new BusinessException("价税合计不能超过销售发票中价税合计"); + } + } +// + + retvos = updateBatch(new IVApplicationAggVO[] { ivApplicationVO }, null); + if(retvos!=null && retvos.length>0){ + CircularlyAccessibleValueObject[] bodys = retvos[0].getChildrenVO(); + if(bodys!=null && bodys.length>0){ + for(int m=0;m transferTool = new BillTransferTool(clientFullVOs); + IVApplicationUpdateBP action = new IVApplicationUpdateBP(); + originBills = transferTool.getOriginBills(); + retvos = action.update(clientFullVOs, originBills); + //retvos = (IVApplicationAggVO[]) transferTool.getBillForToClient(retvos); + } catch (Exception e) { + ExceptionUtils.marsh(e); + } + return retvos; + } + + @Override + public Object submit(IVApplicationAggVO[] clientBills, IVApplicationAggVO[] originBills, Object assingUsers) throws BusinessException { + //判断saga状态 + if(clientBills != null && clientBills.length > 0) { + String[] pks = new String[clientBills.length]; + for (int i = 0; i < clientBills.length; i++) { + pks[i] = clientBills[i].getParentVO().getPk_ivapplication(); + } + + IVMSagaValidationUtils.checkSagaStatus(pks, IVApplicationHeadVO.getDefaultTableName(), IVApplicationHeadVO.PK_IVAPPLICATION); + } + List retvos = new ArrayList(); + try { + + for (int i = 0; i < clientBills.length; i++) { + AggregatedValueObject billVO = clientBills[i]; + if (clientBills[i].getParentVO().getBillstatus() != IBillStatus.FREE) { + // 存在非自由态的单据 + throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0025")/*@res "第:"*/ + (i + 1) + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0026")/*@res "行,非自由态的单据不允许提交!"*/); + } + Object retObj = doNccCommit(billVO, assingUsers); + if(retObj instanceof Map){ + return retObj; + } + if (retObj != null) { + retvos.add((IVApplicationAggVO)((MessageVO)retObj).getSuccessVO()); + } + } + } catch (Exception e) { + ExceptionUtils.marsh(e); + } + return retvos.toArray(new IVApplicationAggVO[retvos.size()]); + } + + private Object doNccCommit(AggregatedValueObject aggVos, Object assingUsers) throws Exception { + MessageVO result = null; + + IVApplicationQueryService ivApplicationQueryService = + NCLocator.getInstance().lookup(IVApplicationQueryService.class); + + AggregatedValueObject billVO = aggVos; + String djlxbm = null; + try { + if (billVO.getParentVO() instanceof IVApplicationHeadVO) { + IVApplicationAggVO[] submitVos = + ivApplicationQueryService + .queryAggVOsByPks(new String[] {((IVApplicationHeadVO)billVO.getParentVO()).getPrimaryKey()}); + if (submitVos != null && submitVos.length > 0) { + if (null == ((IVApplicationHeadVO)billVO.getParentVO()).getTs() + || ((IVApplicationHeadVO)billVO.getParentVO()).getTs().compareTo( + submitVos[0].getParentVO().getTs()) != 0) { + throw new Exception(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0057")/*@res "单据已经被他人修改,请刷新页面!"*/); + } + } + + String tradetypePk = ((IVApplicationHeadVO)billVO.getParentVO()).getPk_tradetype(); + djlxbm = NCLocator.getInstance().lookup(IBilltypeService.class).getBilltypeCode(tradetypePk); + } + Object retObj = null; + HashMap paramMap = new HashMap(); + paramMap.put(PfUtilBaseTools.PARAM_SILENTLY, PfUtilBaseTools.PARAM_SILENTLY); + // String actionCode = IVSaleUtil.getActionCode((String) + // billVO.getParentVO().getAttributeValue(IVApplicationHeadVO.PK_ORG)); + String cuserid = InvocationInfoProxy.getInstance().getUserId(); + UFDateTime currTime = TimeService.getInstance().getUFDateTime(); + WorkflownoteVO noteVO = null; + try { + noteVO = + ((IWorkflowMachine)NCLocator.getInstance().lookup(IWorkflowMachine.class)).checkWorkFlow( + IPFActionName.SAVE, djlxbm, billVO, null); + } catch (BusinessException e) { + } + boolean hasWorkfFlow = false; + if (noteVO == null) { + try{ + IFlowBizItf fbi = PfMetadataTools.getBizItfImpl(billVO, IFlowBizItf.class); + + IWorkflowDefine wfDefine = NCLocator.getInstance().lookup(IWorkflowDefine.class); + hasWorkfFlow = wfDefine.hasValidProcessDef(((IVApplicationHeadVO)billVO.getParentVO()).getPk_org(), + ((IVApplicationHeadVO)billVO.getParentVO()).getTranstypecode(), fbi.getPkorg(), fbi.getBillMaker(), fbi.getEmendEnum(),WorkflowTypeEnum.Workflow.getIntValue()); + if(!hasWorkfFlow){ + hasWorkfFlow = wfDefine.hasValidProcessDef(InvocationInfoProxy.getInstance().getGroupId(), + ((IVApplicationHeadVO)billVO.getParentVO()).getTranstypecode(), fbi.getPkorg(), fbi.getBillMaker(), fbi.getEmendEnum(),WorkflowTypeEnum.Workflow.getIntValue()); + } + }catch (PFBusinessException e){ + String err = NCLangRes4VoTransl.getNCLangRes().getStrByID("pfworkflow", "UPPpfworkflow-000058");/** 找不到工作流定义 无法启动工作流*/ + if (e.getMessage()!=null && e.getMessage().contains(err)) { + //throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0027")/*@res "找不到流程定义,无法启动流程!"*/); + }else{ + throw new PFBusinessException(e); + } + } + if (!hasWorkfFlow) { + ((IVApplicationHeadVO)billVO.getParentVO()).setApprover(cuserid); + ((IVApplicationHeadVO)billVO.getParentVO()).setApprovedate(currTime); + ((IVApplicationHeadVO)billVO.getParentVO()).setBillstatus(IBillStatus.CHECKPASS); +// ((IVApplicationHeadVO)billVO.getParentVO()).setStatus(VOStatus.UPDATED); +// retObj = this.updateBatch(new IVApplicationAggVO[] { (IVApplicationAggVO) billVO }, null)[0]; + retObj = approveVOs(new IVApplicationAggVO[] { (IVApplicationAggVO) billVO }); + + } else { + retObj = commitScriptPFlow(IPFActionName.START, djlxbm, billVO, assingUsers); + } + } else { + // 有审批流走审批流 + retObj = commitScriptPFlow(IPFActionName.SAVE, djlxbm, billVO, assingUsers); + } + + if (retObj == null) { + result = new MessageVO(billVO, ActionUtils.COMMIT); + result.setSuccess(false); + result + .setErrorMessage(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("2011", "UPP2011-000339")/* + * @ + * res + * "用户取消操作"*/); + } else { + if(retObj instanceof Map){ + return retObj; + } + if (retObj instanceof AggregatedValueObject) {// 仅提交 + result = new MessageVO((AggregatedValueObject)retObj, ActionUtils.COMMIT); + } else if (retObj instanceof MessageVO[]) {// 提交并审批的情况会出现 + MessageVO[] messages = (MessageVO[])retObj; + result = messages[0]; + } else if (retObj instanceof MessageVO) { + result = (MessageVO)retObj; + }else if (retObj instanceof PfProcessBatchRetObject) { + if ((PfProcessBatchRetObject) retObj != null && ((PfProcessBatchRetObject) retObj).getRetObj() != null) { + result = (MessageVO) ((PfProcessBatchRetObject) retObj).getRetObj()[0]; + } else { + result = new MessageVO(null, ActionUtils.COMMIT); + } + } + } + + } catch (Exception e) { + ExceptionUtils.marsh(e); + } + + return result; + } + + private Object commitScriptPFlow(String actionName, String djlxbm, AggregatedValueObject aggVo, Object assingUsers) throws BusinessException { + JSONObject assignContent = new JSONObject(); + HashMap eParam = new HashMap(); + if ((assingUsers instanceof LinkedTreeMap)) { + assignContent = JSON.parseObject(new Gson().toJson(assingUsers)); + eParam.put("content", assignContent); + } + // 调用平台接口 + eParam.put(PfUtilBaseTools.PARAM_SILENTLY, PfUtilBaseTools.PARAM_SILENTLY); +// eParam.put("isSkipAssign", true); + CloudPFlowContext context = new CloudPFlowContext(); + context.setActionName(actionName); + context.setBillType(djlxbm); + context.setBillVos(new AggregatedValueObject[] { aggVo }); + context.seteParam(eParam); + + Object[] ss = null; + if(IPFActionName.START.equals(actionName)){ + WorkflowTypeEnum flowtype = nc.bs.pub.pf.PfUtilTools.runningFlowStatus(nccloud.commons.lang.StringUtils.isNotEmpty(context.getTrantype()) ? context.getTrantype() : context.getBillType(), aggVo.getParentVO().getPrimaryKey()); + if(flowtype==null){ + ss =NCLocator.getInstance().lookup(ICloudScriptPFlowService.class).exeScriptPFlow_CommitNoFlowBatch(context); + } + } + if(ss==null){ + ss =NCLocator.getInstance().lookup(ICloudScriptPFlowService.class).exeScriptPFlow(context); + } + + Object obj = ss[0]; + if (((obj instanceof Map)) + && (((Map)obj).get("workflow") != null) + && (("approveflow".equals(String.valueOf(((Map)obj).get("workflow")))) || ("workflow".equals(String + .valueOf(((Map)obj).get("workflow")))))) { + @SuppressWarnings("unchecked") + Map map = (Map)obj; + if (map.get("workflow") != null) { + return map; + } + } + return obj; + } + + @Override + public IVApplicationAggVO[] recall(IVApplicationAggVO[] clientBills, IVApplicationAggVO[] originBills) throws BusinessException { + //判断saga状态 + if(clientBills != null && clientBills.length > 0) { + String[] pks = new String[clientBills.length]; + for (int i = 0; i < clientBills.length; i++) { + pks[i] = clientBills[i].getParentVO().getPk_ivapplication(); + } + + IVMSagaValidationUtils.checkSagaStatus(pks, IVApplicationHeadVO.getDefaultTableName(), IVApplicationHeadVO.PK_IVAPPLICATION); + } + List retvos = new ArrayList(); + try { + for (int i = 0; i < clientBills.length; i++) { + AggregatedValueObject billVO = clientBills[i]; + if(clientBills[i].getParentVO().getBillstatus()!=IBillStatus.COMMIT && clientBills[i].getParentVO().getBillstatus()!=IBillStatus.CHECKPASS){ + //存在非自由态的单据 + throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0025")/*@res "第:"*/+(i+1)+nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0028")/*@res "行,非提交态的单据不允许收回!"*/); + } + List applogVOList = + NCLocator.getInstance().lookup(ApplicationLogService.class) + .queryApplicationLogByLyid(new String[] {clientBills[i].getParentVO().getPk_ivapplication()}); + + if(applogVOList != null && applogVOList.size() > 0){ + throw new nc.vo.pub.BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0029")/*@res "单据"*/ + clientBills[i].getParentVO().getBillno() + + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0030")/*@res "已经开票,不允许取消审批!"*/); + } + Object retObj = doNccRecall(billVO); + + retvos.add( (IVApplicationAggVO) ((MessageVO) retObj).getSuccessVO()); + } + } catch (Exception e) { + ExceptionUtils.marsh(e); + } + return retvos.toArray(new IVApplicationAggVO[retvos.size()]); + } + + private Object doNccRecall(AggregatedValueObject billVO) throws Exception { + MessageVO result = null; + + IVApplicationQueryService ivApplicationQueryService = NCLocator.getInstance().lookup(IVApplicationQueryService.class); + + String djlxbm = null; + try { + if (billVO.getParentVO() instanceof IVApplicationHeadVO) { + IVApplicationAggVO[] submitVos = ivApplicationQueryService.queryAggVOsByPks(new String[] { ((IVApplicationHeadVO) billVO + .getParentVO()).getPrimaryKey() }); + if (submitVos != null && submitVos.length > 0) { + if (null == ((IVApplicationHeadVO) billVO.getParentVO()).getTs() + || ((IVApplicationHeadVO) billVO.getParentVO()).getTs().compareTo(submitVos[0].getParentVO().getTs()) != 0) { + throw new Exception(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0057")/*@res "单据已经被他人修改,请刷新页面!"*/); + } + } + + String tradetypePk = ((IVApplicationHeadVO) billVO.getParentVO()).getPk_tradetype(); + djlxbm = NCLocator.getInstance().lookup(IBilltypeService.class).getBilltypeCode(tradetypePk); + } + + String actionName = IPFActionName.RECALL; + + boolean isApproveflowFlag = IVSaleUtil.isApproveFlowStartup(billVO.getParentVO().getPrimaryKey(), djlxbm); + if (isApproveflowFlag) { + actionName = IPFActionName.UNSAVE; + } + + // 收回流程信息 + Object[] exeScriptPFlow = null; + CloudPFlowContext context = new CloudPFlowContext(); + context.setActionName(actionName); + context.setBillType(djlxbm);// 开票申请单 + context.setBillVos(new AggregatedValueObject[] { billVO }); + context.seteParam(new HashMap()); + + WorkflowTypeEnum flowtype = nc.bs.pub.pf.PfUtilTools.runningFlowStatus(nccloud.commons.lang.StringUtils.isNotEmpty(context.getTrantype()) ? context.getTrantype() : context.getBillType(), billVO.getParentVO().getPrimaryKey()); + + ICloudScriptPFlowService service = NCLocator.getInstance().lookup(ICloudScriptPFlowService.class); + + if (flowtype == null) { + // 一个制单环节 + exeScriptPFlow = service.exeScriptPFlow_UnSaveNoFlowBatch(context); + + } else { + // 多个制单环节 + exeScriptPFlow = service.exeScriptPFlow(context); + } + + if (exeScriptPFlow[0] instanceof PfProcessBatchRetObject) { + if ((PfProcessBatchRetObject) exeScriptPFlow[0] != null && ((PfProcessBatchRetObject) exeScriptPFlow[0]).getRetObj() != null) { + result = new MessageVO((AggregatedValueObject) ((PfProcessBatchRetObject) exeScriptPFlow[0]).getRetObj()[0], ActionUtils.RECALL); + } else { + result = new MessageVO(null, ActionUtils.RECALL); + } + } else if (exeScriptPFlow[0] instanceof AggregatedValueObject) { + result = new MessageVO((AggregatedValueObject) (exeScriptPFlow[0]), ActionUtils.RECALL); + } + + } catch (Exception e) { + Logger.error(e.getMessage(), e); + throw e; + } + + return result; + } + + + + + /** + * 开票申请-初始化默认数据 + * @param ivapplicationaggvo + * @return + * @throws BusinessException + */ + public IVApplicationAggVO dealDefValue(String uistate, String pk_group, String pk_user, String pk_tradetype) throws Exception { + IVApplicationAggVO retvos = new IVApplicationAggVO(); + IVApplicationBillDefValue billDefValue = new IVApplicationBillDefValue(); + // 自定义默认值 + if (IVAWebConst.INIT_LOADDEF.equals(uistate) || IVAWebConst.UISTATUS_ADD.equals(uistate)) { + retvos = billDefValue.getNewVO(pk_group, pk_user, pk_tradetype); + } else if (IVAWebConst.CHANGE_LOADDEF.equals(uistate) || IVAWebConst.UISTATUS_EDIT.equals(uistate)) { + //retvos = billDefValue.getDefaultVO(pk_org); + } + return retvos; + } + + /** + * 开票申请-查询组织本币对应币种 + * @param String + * @return + * @throws BusinessException + */ + public String getOrgLocalCurrPK(String pk_org) throws BusinessException { + String orgLocalCurrPK = CurrencyRateUtilHelper.getInstance().getLocalCurrtypeByOrgID(pk_org); + return orgLocalCurrPK; + } + + /** + * 开票申请-币种对应精度 + * @param String + * @return + * @throws BusinessException + */ + public Integer getCurrDigit(String pk_currtype) throws BusinessException { + if (StringUtils.isEmpty(pk_currtype)) { + return 0; + } + + CurrtypeVO currtypeVO = null; + if (RuntimeEnv.getInstance().isRunningInServer()) { + currtypeVO = CurrtypeQuery.getInstance().getCurrtypeVO(pk_currtype); + } + return currtypeVO == null ? 0 : currtypeVO.getCurrdigit(); + } + + /** + * 开票申请-获取组织对应版本 + * @param String + * @return + * @throws BusinessException + */ + public String getOrgVersion(String voclassname, String name, String pk_org) throws Exception { + String className = new IVApplicationBillDefValue().getClassname(voclassname); + String pk_org_v = (String) new IVApplicationBillDefValue().getRelationItemValue(className, name, "pk_org", pk_org); + return pk_org_v; + } + + @Override + public MessageVO[] approveVOs(IVApplicationAggVO[] applicationAggVOs) throws Exception { + if (applicationAggVOs == null || applicationAggVOs.length == 0) { + return null; + } + + // 1、更新单据 + for (int i = 0; i < applicationAggVOs.length; i++) { + applicationAggVOs[i].getParentVO().setStatus(VOStatus.UPDATED); + } + IVApplicationAggVO[] aggVOs = updateBatch(applicationAggVOs, null); + + MessageVO[] msgs = new MessageVO[aggVOs.length]; + for (int i = 0; i < aggVOs.length; i++) { + msgs[i] = new MessageVO(aggVOs[i], ActionUtils.AUDIT); + } + + // 2、审批通过时自动开票 + IVApplicationInvoiceService applicationInvoiceService = NCLocator.getInstance().lookup(IVApplicationInvoiceService.class); + for (int i = 0; i < aggVOs.length; i++) { + String billTypePk = aggVOs[i].getParentVO().getPk_tradetype(); + String billtypeCode = NCLocator.getInstance().lookup(IBilltypeService.class).getBilltypeCode(billTypePk); + IVBilltypeVO billtypeVO = NCLocator.getInstance().lookup(IVABilltypeExtService.class).getBilltypeVOByCode(billtypeCode, + InvocationInfoProxy.getInstance().getGroupId()); + if(null != billtypeVO){ + if(billtypeVO.getIsatuo_invoice() == UFBoolean.TRUE && IVApplicationSlsmUtil.slsmCheck(aggVOs[i])){//@全电发票@@特殊票种电子凭证@ + JSONObject jsonObj = new JSONObject(); + IVApplicationAggVO[] voAfterMakeInvoice = applicationInvoiceService.makeInvoice(new IVApplicationAggVO[] {aggVOs[i]}, jsonObj, null, false); + msgs[i] = new MessageVO(voAfterMakeInvoice[0], ActionUtils.AUDIT); + } + } + } + + return msgs; + } + + @Override + public Object unApproveVOs(IVApplicationAggVO[] applicationAggVOs) throws BusinessException { + if (applicationAggVOs == null || applicationAggVOs.length == 0) { + return null; + } + + // 1、判断开票申请单是否已经开票,如果已经开票,则不允许取消审批 + for (int i = 0; i < applicationAggVOs.length; i++) { + List applogVOList = + NCLocator.getInstance().lookup(ApplicationLogService.class) + .queryApplicationLogByLyid(new String[] {applicationAggVOs[i].getParentVO().getPk_ivapplication()}); + + if(applogVOList != null && applogVOList.size() > 0){ + throw new nc.vo.pub.BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0029")/*@res "单据"*/ + applicationAggVOs[i].getParentVO().getBillno() + + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0030")/*@res "已经开票,不允许取消审批!"*/); + } + applicationAggVOs[i].getParentVO().setStatus(VOStatus.UPDATED); + } + + // 2、更新单据状态 + IVApplicationAggVO[] aggVOs = updateBatch(applicationAggVOs, null); + + MessageVO[] msgs = new MessageVO[aggVOs.length]; + for (int i = 0; i < aggVOs.length; i++) { + msgs[i] = new MessageVO(aggVOs[i], ActionUtils.UNAUDIT); + } + + return msgs; + } + + @Override + public IVApplicationAggVO copyApplication(String pk) throws Exception { + // 1、校验单据是否存在 + IVApplicationAggVO aggVO = NCLocator.getInstance().lookup(IVApplicationQueryService.class).queryByPK(pk); + if (aggVO == null) { + throw new nc.vo.pub.BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0057")/*@res "单据已经被他人修改,请刷新页面!"*/); + } + if(aggVO.getParentVO().getHzfp() == UFBoolean.TRUE || aggVO.getParentVO().getZffp() == UFBoolean.TRUE){ + throw new nc.vo.pub.BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0031")/*@res "单据关联的发票是红字发票或作废发票,不允许复制单据!"*/); + } + if(aggVO.getParentVO().getSrc_pkbusibill() != null){ + throw new nc.vo.pub.BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0","01058sal-0032")/*@res "单据已关联上游单据,不允许复制单据!"*/); + } + + // 2、复制单据 + IVApplicationAggVO copyVo = aggVO.clone(); + IVApplicationHeadVO headvo = copyVo.getParentVO(); + + // 3、清除表头不该复制的字段 + //清除saga相关的三个字段,否则复制时出现主键被加锁的情况 + String[] headFieldNotCopy = + {IVApplicationHeadVO.PK_IVAPPLICATION, IVApplicationHeadVO.APPROVEDATE, IVApplicationHeadVO.APPROVER, + IVApplicationHeadVO.BILLNO, IVApplicationHeadVO.BILLSTATUS, IVApplicationHeadVO.CREATIONTIME, + IVApplicationHeadVO.CREATOR, IVApplicationHeadVO.KPR, IVApplicationHeadVO.KPZT, + IVApplicationHeadVO.LYID, IVApplicationHeadVO.MODIFIEDTIME, IVApplicationHeadVO.MODIFIER, + IVApplicationHeadVO.PREPAREDATE, IVApplicationHeadVO.SRC_BILLNO, IVApplicationHeadVO.SRC_BILLTYPE, + IVApplicationHeadVO.SRC_PKBUSIBILL, IVApplicationHeadVO.SRC_TRADETYPE,IVApplicationHeadVO.SAGA_FROZEN, + IVApplicationHeadVO.SAGA_GTXID,IVApplicationHeadVO.SAGA_BTXID,IVApplicationHeadVO.SAGA_STATUS}; + + for (int i = 0; i < headFieldNotCopy.length; i++) { + headvo.setAttributeValue(headFieldNotCopy[i], null); + } + + // 4、清除表体字段 + for (int i = 0; i < copyVo.getChildrenVO().length; i++) { + IVApplicationBodyVO bodyVO = (IVApplicationBodyVO) copyVo.getChildrenVO()[i]; + bodyVO.setPk_ivappdetail(null); + bodyVO.setPk_ivapplication(null); + } + + //@特殊票种电子凭证@begin + // 5、清除特殊票种相关字段 + if (copyVo.getIvTspzsBodyVO() != null) { + for (int i = 0; i < copyVo.getIvTspzsBodyVO().length; i++) { + IVTspzsBodyVO ivTspzsBodyVO = copyVo.getIvTspzsBodyVO()[i]; + ivTspzsBodyVO.setPk_ivtspzsdetail(null); + ivTspzsBodyVO.setPk_ivapplication(null); + ivTspzsBodyVO.setPk_ivappdetail(null); + } + } + //@特殊票种电子凭证@end + + // 5、重新制单人、修改人、时间等信息 + String cuserid = InvocationInfoProxy.getInstance().getUserId(); + UFDateTime currTime = TimeService.getInstance().getUFDateTime(); + UFDate currDate = currTime.getDate(); + + headvo.setBillstatus(IBillStatus.FREE); + headvo.setPreparedate(currDate); + headvo.setCreator(cuserid); + headvo.setCreationtime(currTime); + headvo.setModifier(cuserid); + headvo.setModifiedtime(currTime); + headvo.setHzfp(UFBoolean.FALSE); + headvo.setCkfp(UFBoolean.FALSE); + headvo.setZffp(UFBoolean.FALSE); + headvo.setFpdm(""); + headvo.setFphm(""); + //表头设置开票方式默认值,默认为1 直联开票 + Integer paramValue = SysInitQuery.getParaInt(headvo.getPk_org(), IVAWebConst.IVA_KP_SSCIVA01); + headvo.setKpfs(paramValue == null ? IVAplocationKPFS.ZLKP.toIntValue() : paramValue); + + for (int i = 0; i < copyVo.getChildrenVO().length; i++) { + IVApplicationBodyVO bodyvo = (IVApplicationBodyVO) copyVo.getChildrenVO()[i]; + bodyvo.setStatus(VOStatus.NEW); + } + + return copyVo; + } + + @Override + public boolean isFlowCheckman(String billId, String billType, String userId) + throws BusinessException { + return IVSaleUtil.isCheckman(billId, billType, userId); + } + +} \ No newline at end of file diff --git a/uapbd/src/private/nc/bs/uapbd/task/InvoiceTaskPlugin.java b/uapbd/src/private/nc/bs/uapbd/task/InvoiceTaskPlugin.java index c5a3099..3570365 100644 --- a/uapbd/src/private/nc/bs/uapbd/task/InvoiceTaskPlugin.java +++ b/uapbd/src/private/nc/bs/uapbd/task/InvoiceTaskPlugin.java @@ -44,6 +44,8 @@ import nc.jdbc.framework.processor.MapListProcessor; import nc.vo.pub.BusinessException; import nc.vo.sscivm.ivsale.IVApplicationHeadVO; import nc.vo.sscivm.ivsale.IVApplogVO; +import uap.iweb.log.Logger; +import uap.mw.trans.TransactionFactory; import javax.net.ssl.HttpsURLConnection; @@ -52,6 +54,7 @@ public class InvoiceTaskPlugin implements IBackgroundWorkPlugin{ @Override public PreAlertObject executeTask(BgWorkingContext arg0) throws BusinessException { // TODO Auto-generated method stub + Logger.error("---start----任务开始运行--"); try { BaseDAO dao = new BaseDAO(); String sql = " SELECT sscivm_invoice.pk_invoice,so_saleinvoice.csaleinvoiceid,so_saleinvoice.vbillcode billcode, sscivm_invoice.fphm, " + @@ -67,6 +70,7 @@ public class InvoiceTaskPlugin implements IBackgroundWorkPlugin{ " and sscivm_ivapplog.kpzt = 2 "; // + " so_saleinvoice.vbillcode = 'SI2024070400000738' "; ArrayList> al = (ArrayList>)dao.executeQuery(sql, new MapListProcessor()); + Logger.error("---alData------"+al); if(al.size() > 0) { for(HashMap sscivm_invoice : al) { Object pk_invoice = sscivm_invoice.get("pk_invoice"); //bip发票主键 @@ -80,6 +84,7 @@ public class InvoiceTaskPlugin implements IBackgroundWorkPlugin{ String ctcode=""; HYSuperDMO dmo = new HYSuperDMO(); IVApplogVO[] ivApplogVO=(IVApplogVO[]) dmo.queryByWhereClause(IVApplogVO.class, "fphm='"+fphm+"' and dr=0 "); + Logger.error("---ivApplogVO------"+ivApplogVO); if(ivApplogVO!=null&&ivApplogVO.length>0) { ivApplogVO[0].getLyid();//开票申请单主键 IVApplicationHeadVO ivApplicationHeadVO =(IVApplicationHeadVO) dmo.queryByPrimaryKey(IVApplicationHeadVO.class, ivApplogVO[0].getLyid()); @@ -93,36 +98,74 @@ public class InvoiceTaskPlugin implements IBackgroundWorkPlugin{ * 3.根据销售发票id 回写下游应收单表头表体发票号 * 4.查询销售发票下游单据,如果有将下游单据表体字段【来源单据号】更新成新的发票号 */ - String updateRecbillAndItemSql = "BEGIN\n" + - "UPDATE sscivm_invoice_relation set billno = '" + billno +"' where pk_invoice = '"+ pk_invoice +"' and billid = '"+ csaleinvoiceid +"';\n" + - "UPDATE so_saleinvoice set vdef20 = 'Y' , vdef13 = '" + fphm + "', vbillcode = '" + billno +" where csaleinvoiceid = '" + csaleinvoiceid + "';\n" + - "MERGE INTO ar_recbill a USING ar_recitem b ON ( a.pk_recbill = b.pk_recbill AND b.top_billid = '" + csaleinvoiceid + "' AND b.top_billtype = '32' ) \n" + + //手动开启事务 + TransactionFactory.getTMProxy().begin(3,0); + //修改发票关联关系单据编码 + String sirSql = "UPDATE sscivm_invoice_relation set billno = '" + billno +"' where pk_invoice = '"+ pk_invoice +"' and billid = '"+ csaleinvoiceid +"'"; + dao.executeUpdate(sirSql); + Logger.error("---sirSqlExecute------"+sirSql); + //ERP销售发票回传,根据销售发票id,回写发票号和单据编号 + String sSaleSql = "UPDATE so_saleinvoice set vdef20 = 'Y' , vdef13 = '" + fphm + "', vbillcode = '" + billno +"' where csaleinvoiceid = '" + csaleinvoiceid + "'"; + dao.executeUpdate(sSaleSql); + Logger.error("---sSaleSqlExecute------"+sSaleSql); + //根据销售发票id 回写下游应收单表头发票号 + String recBillSql = "MERGE INTO ar_recbill a USING (select DISTINCT pk_recbill,top_billid,top_billtype from ar_recitem) b ON ( a.pk_recbill = b.pk_recbill AND b.top_billid = '" + csaleinvoiceid + "' AND b.top_billtype = '32' ) \n" + "WHEN MATCHED THEN\n" + "UPDATE \n" + - "SET a.invoiceno = '" + fphm + "';\n" + - "UPDATE ar_recitem \n" + + "SET a.invoiceno = '" + fphm + "'"; + dao.executeUpdate(recBillSql); + Logger.error("---recBillSqlExecute------"+recBillSql); + //根据销售发票id 回写下游应收单表体发票号 + String recItemSql = "UPDATE ar_recitem \n" + "SET invoiceno = '" + fphm + "' \n" + "WHERE\n" + "top_billid = '" + csaleinvoiceid + "' \n" + - "AND top_billtype = '32';\n" + - "UPDATE ic_saleout_b \n" + + "AND top_billtype = '32'"; + dao.executeUpdate(recItemSql); + Logger.error("---recItemSqlExecute------"+recItemSql); + //查询销售发票下游单据,如果有将下游单据表体字段【来源单据号】更新成新的发票号 + String saleOutSql = "UPDATE ic_saleout_b \n" + "SET vsourcebillcode = '"+ billno +"' \n" + "WHERE\n" + "csourcetype = '32' \n" + - "AND csourcebillhid = '" + csaleinvoiceid +"';\n" + - "COMMIT;\n" + - "EXCEPTION \n" + - "WHEN OTHERS THEN\n" + - "ROLLBACK;\n" + - "RAISE;\n" + - "END;"; - dao.executeUpdate(updateRecbillAndItemSql); + "AND csourcebillhid = '" + csaleinvoiceid +"'"; + dao.executeUpdate(saleOutSql); + Logger.error("---saleOutSqlExecute------"+saleOutSql); + //正常结束 + TransactionFactory.getTMProxy().end(null); +// String updateRecbillAndItemSql = "BEGIN\n" + +// "UPDATE sscivm_invoice_relation set billno = '" + billno +"' where pk_invoice = '"+ pk_invoice +"' and billid = '"+ csaleinvoiceid +"';\n" + +// "UPDATE so_saleinvoice set vdef20 = 'Y' , vdef13 = '" + fphm + "', vbillcode = '" + billno +"' where csaleinvoiceid = '" + csaleinvoiceid + "';\n" + +// "MERGE INTO ar_recbill a USING ar_recitem b ON ( a.pk_recbill = b.pk_recbill AND b.top_billid = '" + csaleinvoiceid + "' AND b.top_billtype = '32' ) \n" + +// "WHEN MATCHED THEN\n" + +// "UPDATE \n" + +// "SET a.invoiceno = '" + fphm + "';\n" + +// "UPDATE ar_recitem \n" + +// "SET invoiceno = '" + fphm + "' \n" + +// "WHERE\n" + +// "top_billid = '" + csaleinvoiceid + "' \n" + +// "AND top_billtype = '32';\n" + +// "UPDATE ic_saleout_b \n" + +// "SET vsourcebillcode = '"+ billno +"' \n" + +// "WHERE\n" + +// "csourcetype = '32' \n" + +// "AND csourcebillhid = '" + csaleinvoiceid +"';\n" + +// "COMMIT;\n" + +// "EXCEPTION \n" + +// "WHEN OTHERS THEN\n" + +// "ROLLBACK;\n" + +// "RAISE;\n" + +// "END;"; +// dao.executeUpdate(updateRecbillAndItemSql); } } } catch(Exception e) { e.printStackTrace(); + //异常回滚 + TransactionFactory.getTMProxy().end(e); + Logger.error("writeBack Error: ",e); } return null; }