开票申请保存校验-2005适配2312-liujie

This commit is contained in:
mzr 2025-03-26 18:55:34 +08:00
parent a6b89d1caa
commit 376a4571e6
1 changed files with 938 additions and 0 deletions

View File

@ -0,0 +1,938 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package nccloud.itf.sscivm.ivsale.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.internal.LinkedTreeMap;
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.businessevent.EventDispatcher;
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.pub.pf.PfUtilTools;
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.splitmerge.util.TransSpiltMergePksUtil;
import nc.bs.sscivm.ivsale.util.ApplicationBusinessEvent;
import nc.bs.sscivm.ivsale.util.IVApplicationBillDefValue;
import nc.bs.sscivm.ivsale.util.IVApplicationSlsmUtil;
import nc.bs.sscivm.ivsale.util.IVSaleUtil;
import nc.bs.sscivm.logger.SSCIVMLogger;
import nc.bs.sscivm.util.IVMSagaValidationUtils;
import nc.impl.pubapp.pattern.data.bill.tool.BillTransferTool;
import nc.itf.bd.material.baseinfo.IMaterialBaseInfoQueryService;
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.pubitf.bbd.CurrtypeQuery;
import nc.pubitf.para.SysInitQuery;
import nc.pubitf.uapbd.CurrencyRateUtilHelper;
import nc.pubitf.uapbd.ICustomerPubService;
import nc.pubitf.uapbd.IMaterialPubService;
import nc.uap.pf.metadata.PfMetadataTools;
import nc.vo.bd.currtype.CurrtypeVO;
import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.material.MaterialVersionVO;
import nc.vo.ic.pub.util.StringUtil;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.org.OrgQueryUtil;
import nc.vo.org.OrgVO;
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.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFDouble;
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.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;
public class IVApplicationServiceImpl implements IVApplicationService {
public IVApplicationServiceImpl() {
}
public IVApplicationAggVO save(IVApplicationAggVO ivApplicationVO) throws BusinessException {
IVApplicationAggVO[] ivApplicationVOs = null;
try {
ivApplicationVOs = this.saveBatch(new IVApplicationAggVO[]{ivApplicationVO});
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
ExceptionUtils.marsh(e);
}
return ivApplicationVOs != null && ivApplicationVOs.length != 0 ? ivApplicationVOs[0] : null;
}
public IVApplicationAggVO[] saveBatch(IVApplicationAggVO[] clientFullVOs) throws BusinessException {
IVApplicationAggVO[] retvos = null;
HashSet<IVApplicationAggVO> retVOLits = new HashSet();
try {
IVApplicationInsertBP action = new IVApplicationInsertBP();
retvos = action.insert(clientFullVOs);
HashSet<String> tradetypeids = new HashSet();
for(IVApplicationAggVO applicationAggVO : retvos) {
tradetypeids.add(applicationAggVO.getParentVO().getTranstypecode());
}
IVABilltypeExtService var10000 = (IVABilltypeExtService)NCLocator.getInstance().lookup(IVABilltypeExtService.class);
String var10001 = InvocationInfoProxy.getInstance().getGroupId();
IVBilltypeVO[] billtypeVOS = var10000.getBilltypeVOsByWhere(" pk_group ='" + var10001 + "' and " + SQLUtil.buildSqlForIn("billtypecode", (String[])tradetypeids.toArray(new String[tradetypeids.size()])));
if (billtypeVOS != null && billtypeVOS.length > 0) {
HashSet<IVApplicationAggVO> atuoVOs = new HashSet();
HashSet<IVApplicationAggVO> 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()) && 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((IVApplicationAggVO[])atuoVOs.toArray(new IVApplicationAggVO[atuoVOs.size()]), (IVApplicationAggVO[])null, (Object)null);
if (submitObj instanceof Map) {
throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0053"));
}
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 = (IVApplicationAggVO[])retVOLits.toArray(new IVApplicationAggVO[retVOLits.size()]);
} else if (noatuoVOs != null && noatuoVOs.size() > 0) {
retVOLits.addAll(noatuoVOs);
retvos = (IVApplicationAggVO[])retVOLits.toArray(new IVApplicationAggVO[retVOLits.size()]);
}
}
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
ExceptionUtils.marsh(e);
}
return retvos;
}
public void deleteById(String pk) throws BusinessException {
this.deleteByIds(new String[]{pk});
}
public void deleteByIds(String[] pks) throws BusinessException {
IVApplicationAggVO[] retvos = (new IVApplicationQueryBP()).queryAggIVApplicationVOByCondition(SQLUtil.buildSqlForIn("pk_ivapplication", pks));
(new IVApplicationDeleteBP()).delete(retvos);
}
public void delete(IVApplicationAggVO vo) throws BusinessException {
try {
(new IVApplicationDeleteBP()).delete(new IVApplicationAggVO[]{vo});
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
ExceptionUtils.marsh(e);
}
}
public void deleteBatch(IVApplicationAggVO[] vos) throws BusinessException {
try {
(new IVApplicationDeleteBP()).delete(vos);
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
ExceptionUtils.marsh(e);
}
}
public void deleteBatchdUnCheckApproveStaus(IVApplicationAggVO[] vos) throws BusinessException {
try {
(new IVApplicationDeleteBP()).deleteUnCheckApproveStaus(vos);
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
ExceptionUtils.marsh(e);
}
}
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 == 1) {
throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0024"));
}
if (approveStatus == 3 || approveStatus == 2) {
String billId = ivApplicationVO.getParentVO().getPk_ivapplication();
String billType = ivApplicationVO.getParentVO().getTranstypecode();
String userId = InvocationInfoProxy.getInstance().getUserId();
if (!this.isFlowCheckman(billId, billType, userId)) {
throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0050"));
}
}
retvos = this.updateBatch(new IVApplicationAggVO[]{ivApplicationVO}, (IVApplicationAggVO[])null);
if (retvos != null && retvos.length > 0) {
CircularlyAccessibleValueObject[] bodys = retvos[0].getChildrenVO();
if (bodys != null && bodys.length > 0) {
for(int m = 0; m < bodys.length; ++m) {
CircularlyAccessibleValueObject body = bodys[m];
body.setAttributeValue("rowid", ivApplicationVO.getChildrenVO()[m].getAttributeValue("rowid"));
}
}
}
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
ExceptionUtils.marsh(e);
}
return retvos != null && retvos.length != 0 ? retvos[0] : null;
}
public IVApplicationAggVO[] updateBatch(IVApplicationAggVO[] clientFullVOs, IVApplicationAggVO[] originBills) throws BusinessException {
IVApplicationAggVO[] retvos = null;
try {
BillTransferTool<IVApplicationAggVO> transferTool = new BillTransferTool(clientFullVOs);
IVApplicationUpdateBP action = new IVApplicationUpdateBP();
originBills = (IVApplicationAggVO[])transferTool.getOriginBills();
retvos = action.update(clientFullVOs, originBills);
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
ExceptionUtils.marsh(e);
}
return retvos;
}
public IVApplicationAggVO updateForUI(IVApplicationAggVO ivApplicationVO) throws BusinessException {
IVApplicationAggVO[] retvos = null;
try {
if (ivApplicationVO == null || ivApplicationVO.getParentVO() == null) {
return null;
}
Integer approveStatus = ivApplicationVO.getParentVO().getBillstatus();
if (approveStatus == 1) {
throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0024"));
}
if (approveStatus == 3 || approveStatus == 2) {
String billId = ivApplicationVO.getParentVO().getPk_ivapplication();
String billType = ivApplicationVO.getParentVO().getTranstypecode();
String userId = InvocationInfoProxy.getInstance().getUserId();
if (!this.isFlowCheckman(billId, billType, userId)) {
throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0050"));
}
}
//如果来源单据为销售发票,根据来源单据编号src_billno和来源单据类型billtype = 32查询销售发票价税合计ntotalorigmny与开票申请中价税合计jshj比较须满足 jshj<ntotalorigmny
String src_billtype = ivApplicationVO.getParentVO().getSrc_billtype(); //来源单据类型
String src_billno = ivApplicationVO.getParentVO().getSrc_billno(); //来源单据号
String def23 = ivApplicationVO.getParentVO().getDef23(); //bip开票类型 3出口发票
//根据开票申请自定义项23查询自定义档案编码
BaseDAO dao = new BaseDAO();
String sqlDefdoc = "select code from bd_defdoc where dr = 0 and pk_defdoc = '" +def23+"'";
Object objDefdoc = dao.executeQuery(sqlDefdoc, new ColumnProcessor());
String def23Code = "";
if(objDefdoc != null) {
def23Code = objDefdoc.toString();
}
/**
* 2025-03-12新增
* 开票申请自定义项 23bip开票类型 不等于 3def23Code = 3
* 再做金额校验
*/
if("32".equals(src_billtype) && !StringUtil.isNullStringOrNull(src_billno) && !"3".equals(def23Code)){
String sql = "select ntotalorigmny from so_saleinvoice where dr = 0 and vbillcode = '" +src_billno+"'";
Object obj = dao.executeQuery(sql, new ColumnProcessor());
//销售发票价税合计
UFDouble ntotalorigmny = UFDouble.ZERO_DBL;
if(obj != null) {
ntotalorigmny = new UFDouble(obj.toString());
}
//开票申请价税合计
UFDouble jshj = ivApplicationVO.getParentVO().getJshj();
//如果开票申请价税合计 大于 销售发票价税合计则返回报错
if(jshj != null && ntotalorigmny != null && jshj.compareTo(ntotalorigmny) > 0){
throw new BusinessException("价税合计不能超过销售发票中价税合计");
}
}
retvos = this.updateBatchForUI(new IVApplicationAggVO[]{ivApplicationVO}, (IVApplicationAggVO[])null);
if (retvos != null && retvos.length > 0) {
CircularlyAccessibleValueObject[] bodys = retvos[0].getChildrenVO();
if (bodys != null && bodys.length > 0) {
for(int m = 0; m < bodys.length; ++m) {
CircularlyAccessibleValueObject body = bodys[m];
body.setAttributeValue("rowid", ivApplicationVO.getChildrenVO()[m].getAttributeValue("rowid"));
}
}
}
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
ExceptionUtils.marsh(e);
}
return retvos != null && retvos.length != 0 ? retvos[0] : null;
}
private IVApplicationAggVO[] updateBatchForUI(IVApplicationAggVO[] clientFullVOs, IVApplicationAggVO[] originBills) throws BusinessException {
IVApplicationAggVO[] retvos = null;
try {
BillTransferTool<IVApplicationAggVO> transferTool = new BillTransferTool(clientFullVOs);
IVApplicationUpdateBP action = new IVApplicationUpdateBP();
originBills = (IVApplicationAggVO[])transferTool.getOriginBills();
retvos = action.update(clientFullVOs, originBills);
Map<String, IVApplicationAggVO> pkAndOldVOMap = new HashMap();
for(IVApplicationAggVO aggVO : originBills) {
pkAndOldVOMap.put(aggVO.getPrimaryKey(), aggVO);
}
HashSet<String> tradetypeids = new HashSet();
for(IVApplicationAggVO applicationAggVO : retvos) {
IVApplicationAggVO oldApplicationAggVO = (IVApplicationAggVO)pkAndOldVOMap.get(applicationAggVO.getPrimaryKey());
if (applicationAggVO.getParentVO().getBillstatus() == -1 && oldApplicationAggVO.getParentVO().getBillstatus() == -1) {
tradetypeids.add(applicationAggVO.getParentVO().getTranstypecode());
}
}
if (tradetypeids.size() == 0) {
return retvos;
}
IVABilltypeExtService var10000 = (IVABilltypeExtService)NCLocator.getInstance().lookup(IVABilltypeExtService.class);
String var10001 = InvocationInfoProxy.getInstance().getGroupId();
IVBilltypeVO[] billtypeVOS = var10000.getBilltypeVOsByWhere(" pk_group ='" + var10001 + "' and " + SQLUtil.buildSqlForIn("billtypecode", (String[])tradetypeids.toArray(new String[tradetypeids.size()])));
if (billtypeVOS != null && billtypeVOS.length > 0) {
HashSet<IVApplicationAggVO> atuoVOs = new HashSet();
HashSet<IVApplicationAggVO> 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()) && billtypeVO.getIsatuo_submit() == UFBoolean.TRUE) {
Isatuo_submit = UFBoolean.TRUE.booleanValue();
}
}
if (Isatuo_submit) {
atuoVOs.add(retvo);
} else {
noatuoVOs.add(retvo);
}
}
List<IVApplicationAggVO> retVOLits = new ArrayList();
if (atuoVOs != null && atuoVOs.size() > 0) {
Object submitObj = this.submit((IVApplicationAggVO[])atuoVOs.toArray(new IVApplicationAggVO[atuoVOs.size()]), (IVApplicationAggVO[])null, (Object)null);
if (submitObj instanceof Map) {
throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0053"));
}
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 = (IVApplicationAggVO[])retVOLits.toArray(new IVApplicationAggVO[retVOLits.size()]);
} else if (noatuoVOs != null && noatuoVOs.size() > 0) {
retVOLits.addAll(noatuoVOs);
retvos = (IVApplicationAggVO[])retVOLits.toArray(new IVApplicationAggVO[retVOLits.size()]);
}
}
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
ExceptionUtils.marsh(e);
}
return retvos;
}
public Object submit(IVApplicationAggVO[] clientBills, IVApplicationAggVO[] originBills, Object assingUsers) throws BusinessException {
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(), "pk_ivapplication");
}
List<IVApplicationAggVO> retvos = new ArrayList();
try {
for(int i = 0; i < clientBills.length; ++i) {
AggregatedValueObject billVO = clientBills[i];
if (clientBills[i].getParentVO().getBillstatus() != -1) {
String var10002 = NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0025");
throw new BusinessException(var10002 + (i + 1) + NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0026"));
}
Object retObj = this.doNccCommit(billVO, assingUsers);
if (retObj instanceof Map) {
return retObj;
}
if (retObj != null) {
retvos.add((IVApplicationAggVO)((MessageVO)retObj).getSuccessVO());
}
}
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), 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 = (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 && (null == ((IVApplicationHeadVO)billVO.getParentVO()).getTs() || ((IVApplicationHeadVO)billVO.getParentVO()).getTs().compareTo(submitVos[0].getParentVO().getTs()) != 0)) {
throw new Exception(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0057"));
}
String tradetypePk = ((IVApplicationHeadVO)billVO.getParentVO()).getPk_tradetype();
djlxbm = ((IBilltypeService)NCLocator.getInstance().lookup(IBilltypeService.class)).getBilltypeCode(tradetypePk);
}
Object retObj = null;
HashMap<String, String> paramMap = new HashMap();
paramMap.put("silently", "silently");
String cuserid = InvocationInfoProxy.getInstance().getUserId();
UFDateTime currTime = new UFDateTime(InvocationInfoProxy.getInstance().getBizDateTime());
WorkflownoteVO noteVO = null;
try {
noteVO = ((IWorkflowMachine)NCLocator.getInstance().lookup(IWorkflowMachine.class)).checkWorkFlow("SAVE", djlxbm, billVO, (HashMap)null);
} catch (BusinessException e) {
SSCIVMLogger.error(e.getMessage(), e);
}
boolean hasWorkfFlow = false;
if (noteVO == null) {
try {
IFlowBizItf fbi = (IFlowBizItf)PfMetadataTools.getBizItfImpl(billVO, IFlowBizItf.class);
IWorkflowDefine wfDefine = (IWorkflowDefine)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 var16) {
String err = NCLangRes4VoTransl.getNCLangRes().getStrByID("pfworkflow", "UPPpfworkflow-000058");
if (var16.getMessage() == null || !var16.getMessage().contains(err)) {
throw new PFBusinessException(var16);
}
}
if (!hasWorkfFlow) {
((IVApplicationHeadVO)billVO.getParentVO()).setApprover(cuserid);
((IVApplicationHeadVO)billVO.getParentVO()).setApprovedate(currTime);
((IVApplicationHeadVO)billVO.getParentVO()).setBillstatus(1);
UFDate preDate = ((IVApplicationHeadVO)billVO.getParentVO()).getPreparedate();
if (preDate.toStdString().substring(0, 10).compareTo(currTime.toStdString().substring(0, 10)) > 0) {
throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0150"));
}
retObj = this.approveVOs(new IVApplicationAggVO[]{(IVApplicationAggVO)billVO});
} else {
retObj = this.commitScriptPFlow("START", djlxbm, billVO, assingUsers);
}
} else {
retObj = this.commitScriptPFlow("SAVE", djlxbm, billVO, assingUsers);
}
if (retObj == null) {
result = new MessageVO(billVO, 8);
result.setSuccess(false);
result.setErrorMessage(NCLangRes4VoTransl.getNCLangRes().getStrByID("2011", "UPP2011-000339"));
} else {
if (retObj instanceof Map) {
return retObj;
}
if (retObj instanceof AggregatedValueObject) {
result = new MessageVO((AggregatedValueObject)retObj, 8);
} 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((AggregatedValueObject)null, 8);
}
}
}
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
ExceptionUtils.marsh(e);
}
return result;
}
private Object commitScriptPFlow(String actionName, String djlxbm, AggregatedValueObject aggVo, Object assingUsers) throws BusinessException {
new JSONObject();
HashMap<Object, Object> eParam = new HashMap();
if (assingUsers instanceof LinkedTreeMap) {
JSONObject assignContent = JSON.parseObject((new Gson()).toJson(assingUsers));
eParam.put("content", assignContent);
}
eParam.put("silently", "silently");
if ("START".equals(actionName)) {
String checkman = "";
BaseDAO dao = new BaseDAO();
String sql = " SELECT a.checkman FROM PUB_WORKFLOWNOTE a INNER JOIN PUB_WF_TASK b ON a.PK_WF_TASK = b.PK_WF_TASK WHERE a.billid ='" + aggVo.getParentVO().getPrimaryKey() + "' and a.actiontype='MAKEBILL' and b.REJECTTACHEACTIVITYID is not null and a.ischeck='N' ";
Object obj = dao.executeQuery(sql, new ColumnProcessor());
if (obj != null) {
checkman = (String)obj;
actionName = "SIGNAL" + checkman;
}
}
CloudPFlowContext context = new CloudPFlowContext();
context.setActionName(actionName);
context.setBillType(djlxbm);
context.setBillVos(new AggregatedValueObject[]{aggVo});
context.seteParam(eParam);
Object[] ss = null;
if ("START".equals(actionName)) {
WorkflownoteVO noteVO = null;
try {
noteVO = ((IWorkflowMachine)NCLocator.getInstance().lookup(IWorkflowMachine.class)).checkWorkFlow("START", djlxbm, aggVo, (HashMap)null);
} catch (BusinessException e) {
SSCIVMLogger.error(e.getMessage(), e);
}
WorkflowTypeEnum flowtype = PfUtilTools.runningFlowStatus(StringUtils.isNotEmpty(context.getTrantype()) ? context.getTrantype() : context.getBillType(), aggVo.getParentVO().getPrimaryKey());
if (flowtype == null && (noteVO == null || noteVO.getTaskInfo().getAssignableInfos().size() == 0)) {
ss = ((ICloudScriptPFlowService)NCLocator.getInstance().lookup(ICloudScriptPFlowService.class)).exeScriptPFlow_CommitNoFlowBatch(context);
}
}
if (ss == null) {
ss = ((ICloudScriptPFlowService)NCLocator.getInstance().lookup(ICloudScriptPFlowService.class)).exeScriptPFlow(context);
}
Object obj = ss[0];
if (obj instanceof Map map && ((Map)obj).get("workflow") != null && ("approveflow".equals(String.valueOf(((Map)obj).get("workflow"))) || "workflow".equals(String.valueOf(((Map)obj).get("workflow"))))) {
if (map.get("workflow") != null) {
return map;
}
}
return obj;
}
public IVApplicationAggVO[] recall(IVApplicationAggVO[] clientBills, IVApplicationAggVO[] originBills) throws BusinessException {
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(), "pk_ivapplication");
}
List<IVApplicationAggVO> retvos = new ArrayList();
try {
for(int i = 0; i < clientBills.length; ++i) {
AggregatedValueObject billVO = clientBills[i];
if (clientBills[i].getParentVO().getBillstatus() != 3 && clientBills[i].getParentVO().getBillstatus() != 1) {
String var11 = NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0025");
throw new BusinessException(var11 + (i + 1) + NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0028"));
}
List<IVApplogVO> applogVOList = ((ApplicationLogService)NCLocator.getInstance().lookup(ApplicationLogService.class)).queryApplicationLogByLyid(TransSpiltMergePksUtil.transIvapplicationToLyid(new String[]{clientBills[i].getParentVO().getPk_ivapplication()}));
if (applogVOList != null && applogVOList.size() > 0) {
String var10002 = NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0029");
throw new BusinessException(var10002 + clientBills[i].getParentVO().getBillno() + NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0030"));
}
Object retObj = this.doNccRecall(billVO);
retvos.add((IVApplicationAggVO)((MessageVO)retObj).getSuccessVO());
}
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
ExceptionUtils.marsh(e);
}
return (IVApplicationAggVO[])retvos.toArray(new IVApplicationAggVO[retvos.size()]);
}
private Object doNccRecall(AggregatedValueObject billVO) throws Exception {
MessageVO result = null;
IVApplicationQueryService 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 && (null == ((IVApplicationHeadVO)billVO.getParentVO()).getTs() || ((IVApplicationHeadVO)billVO.getParentVO()).getTs().compareTo(submitVos[0].getParentVO().getTs()) != 0)) {
throw new Exception(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0057"));
}
String tradetypePk = ((IVApplicationHeadVO)billVO.getParentVO()).getPk_tradetype();
djlxbm = ((IBilltypeService)NCLocator.getInstance().lookup(IBilltypeService.class)).getBilltypeCode(tradetypePk);
}
String actionName = "RECALL";
boolean isApproveflowFlag = IVSaleUtil.isApproveFlowStartup(billVO.getParentVO().getPrimaryKey(), djlxbm);
if (isApproveflowFlag) {
actionName = "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 = PfUtilTools.runningFlowStatus(StringUtils.isNotEmpty(context.getTrantype()) ? context.getTrantype() : context.getBillType(), billVO.getParentVO().getPrimaryKey());
ICloudScriptPFlowService service = (ICloudScriptPFlowService)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], 9);
} else {
result = new MessageVO((AggregatedValueObject)null, 9);
}
} else if (exeScriptPFlow[0] instanceof AggregatedValueObject) {
result = new MessageVO((AggregatedValueObject)exeScriptPFlow[0], 9);
}
return result;
} catch (Exception e) {
SSCIVMLogger.error(e.getMessage(), e);
throw e;
}
}
public IVApplicationAggVO dealDefValue(String uistate, String pk_group, String pk_user, String pk_tradetype, String appcode) throws Exception {
IVApplicationAggVO retvos = new IVApplicationAggVO();
IVApplicationBillDefValue billDefValue = new IVApplicationBillDefValue();
if (!"onInit".equals(uistate) && !"add".equals(uistate)) {
if (!"onChange".equals(uistate) && "edit".equals(uistate)) {
}
} else {
retvos = billDefValue.getNewVO(pk_group, pk_user, pk_tradetype, appcode);
}
return retvos;
}
public String getOrgLocalCurrPK(String pk_org) throws BusinessException {
String orgLocalCurrPK = CurrencyRateUtilHelper.getInstance().getLocalCurrtypeByOrgID(pk_org);
return orgLocalCurrPK;
}
public Integer getCurrDigit(String pk_currtype) throws BusinessException {
if (StringUtils.isEmpty(pk_currtype)) {
return 0;
} else {
CurrtypeVO currtypeVO = null;
if (RuntimeEnv.getInstance().isRunningInServer()) {
currtypeVO = CurrtypeQuery.getInstance().getCurrtypeVO(pk_currtype);
}
return currtypeVO == null ? 0 : currtypeVO.getCurrdigit();
}
}
public String getOrgVersion(String voclassname, String name, String pk_org) throws Exception {
OrgVO[] vos = OrgQueryUtil.queryOrgVOByPks(new String[]{pk_org});
return vos[0].getPk_vid();
}
public MessageVO[] approveVOs(IVApplicationAggVO[] applicationAggVOs) throws Exception {
if (applicationAggVOs != null && applicationAggVOs.length != 0) {
for(int i = 0; i < applicationAggVOs.length; ++i) {
applicationAggVOs[i].getParentVO().setStatus(1);
}
IVApplicationAggVO[] aggVOs = this.updateBatch(applicationAggVOs, (IVApplicationAggVO[])null);
MessageVO[] msgs = new MessageVO[aggVOs.length];
for(int i = 0; i < aggVOs.length; ++i) {
msgs[i] = new MessageVO(aggVOs[i], 1);
}
EventDispatcher.fireEvent(new ApplicationBusinessEvent("f4555e3d-c6a1-42bf-8354-57be38eb5dd6", "1020", aggVOs));
IVApplicationInvoiceService applicationInvoiceService = (IVApplicationInvoiceService)NCLocator.getInstance().lookup(IVApplicationInvoiceService.class);
for(int i = 0; i < aggVOs.length; ++i) {
String billTypePk = aggVOs[i].getParentVO().getPk_tradetype();
String billtypeCode = ((IBilltypeService)NCLocator.getInstance().lookup(IBilltypeService.class)).getBilltypeCode(billTypePk);
IVBilltypeVO billtypeVO = ((IVABilltypeExtService)NCLocator.getInstance().lookup(IVABilltypeExtService.class)).getBilltypeVOByCode(billtypeCode, InvocationInfoProxy.getInstance().getGroupId());
if (null != billtypeVO && IVApplicationSlsmUtil.slsmCheck(aggVOs[i]) && billtypeVO.getIsatuo_invoice() == UFBoolean.TRUE) {
JSONObject jsonObj = new JSONObject();
IVApplicationAggVO[] voAfterMakeInvoice = applicationInvoiceService.makeInvoice(new IVApplicationAggVO[]{aggVOs[i]}, jsonObj, (Map)null, false);
msgs[i] = new MessageVO(voAfterMakeInvoice[0], 1);
}
}
return msgs;
} else {
return null;
}
}
public Object unApproveVOs(IVApplicationAggVO[] applicationAggVOs) throws BusinessException {
if (applicationAggVOs != null && applicationAggVOs.length != 0) {
for(int i = 0; i < applicationAggVOs.length; ++i) {
List<IVApplogVO> applogVOList = ((ApplicationLogService)NCLocator.getInstance().lookup(ApplicationLogService.class)).queryApplicationLogByLyid(TransSpiltMergePksUtil.transIvapplicationToLyid(new String[]{applicationAggVOs[i].getParentVO().getPk_ivapplication()}));
if (applogVOList != null && applogVOList.size() > 0) {
String var10002 = NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0029");
throw new BusinessException(var10002 + applicationAggVOs[i].getParentVO().getBillno() + NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0030"));
}
applicationAggVOs[i].getParentVO().setStatus(1);
}
IVApplicationAggVO[] aggVOs = this.updateBatch(applicationAggVOs, (IVApplicationAggVO[])null);
MessageVO[] msgs = new MessageVO[aggVOs.length];
for(int i = 0; i < aggVOs.length; ++i) {
msgs[i] = new MessageVO(aggVOs[i], 2);
}
EventDispatcher.fireEvent(new ApplicationBusinessEvent("f4555e3d-c6a1-42bf-8354-57be38eb5dd6", "1022", aggVOs));
return msgs;
} else {
return null;
}
}
public IVApplicationAggVO copyApplication(String pk) throws Exception {
IVApplicationAggVO aggVO = ((IVApplicationQueryService)NCLocator.getInstance().lookup(IVApplicationQueryService.class)).queryByPK(pk);
if (aggVO == null) {
throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0057"));
} else if (aggVO.getParentVO().getHzfp() != UFBoolean.TRUE && aggVO.getParentVO().getZffp() != UFBoolean.TRUE) {
if (aggVO.getParentVO().getSrc_pkbusibill() != null) {
throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0032"));
} else {
IVApplicationAggVO copyVo = aggVO.clone();
IVApplicationHeadVO headvo = copyVo.getParentVO();
String[] headFieldNotCopy = new String[]{"pk_ivapplication", "approvedate", "approver", "billno", "billstatus", "creationtime", "creator", "kpr", "kpzt", "lyid", "modifiedtime", "modifier", "preparedate", "src_billno", "src_pkbusibill", "src_tradetype", "saga_frozen", "saga_gtxid", "saga_btxid", "saga_status", "invoiced_hjje", "invoiced_hjse", "invoiced_jshj", "invoiceing_hjje", "invoiceing_hjse", "invoiceing_jshj", "caninvoice_hjje", "caninvoice_hjse", "caninvoice_jshj", "hzxxsqb", "email", "slsm"};
for(int i = 0; i < headFieldNotCopy.length; ++i) {
headvo.setAttributeValue(headFieldNotCopy[i], (Object)null);
}
Set<String> meterialPKs = new HashSet();
for(int i = 0; i < copyVo.getChildrenVO().length; ++i) {
IVApplicationBodyVO bodyVO = (IVApplicationBodyVO)copyVo.getChildrenVO()[i];
bodyVO.setPk_ivappdetail((String)null);
bodyVO.setPk_ivapplication((String)null);
bodyVO.setCaninvoice_se(UFDouble.ZERO_DBL);
bodyVO.setCaninvoice_xmje(UFDouble.ZERO_DBL);
bodyVO.setCaninvoice_xmjshj(UFDouble.ZERO_DBL);
bodyVO.setCaninvoice_xmsl(UFDouble.ZERO_DBL);
bodyVO.setInvoiced_se(UFDouble.ZERO_DBL);
bodyVO.setInvoiced_xmje(UFDouble.ZERO_DBL);
bodyVO.setInvoiced_xmjshj(UFDouble.ZERO_DBL);
bodyVO.setInvoiced_xmsl(UFDouble.ZERO_DBL);
bodyVO.setInvoiceing_se(UFDouble.ZERO_DBL);
bodyVO.setInvoiceing_xmje(UFDouble.ZERO_DBL);
bodyVO.setInvoiceing_xmjshj(UFDouble.ZERO_DBL);
bodyVO.setInvoiceing_xmsl(UFDouble.ZERO_DBL);
if (bodyVO.getPk_materiel() != null) {
meterialPKs.add(bodyVO.getPk_materiel());
}
if (IVAplocationFPXZ.FPXZ_ZCH.toIntValue() == bodyVO.getFphxz()) {
bodyVO.setHh((String)null);
bodyVO.setZkhhh((String)null);
}
}
if (copyVo.getIvTspzsBodyVO() != null) {
for(int i = 0; i < copyVo.getIvTspzsBodyVO().length; ++i) {
IVTspzsBodyVO ivTspzsBodyVO = copyVo.getIvTspzsBodyVO()[i];
ivTspzsBodyVO.setPk_ivtspzsdetail((String)null);
ivTspzsBodyVO.setPk_ivapplication((String)null);
ivTspzsBodyVO.setPk_ivappdetail((String)null);
}
}
if (meterialPKs.size() > 0) {
Map<String, String> meterialMap = new HashMap();
MaterialVO[] materialVOS = ((IMaterialBaseInfoQueryService)NCLocator.getInstance().lookup(IMaterialBaseInfoQueryService.class)).queryDataByPks((String[])meterialPKs.toArray(new String[0]));
meterialPKs.clear();
for(MaterialVO materialVO : materialVOS) {
meterialPKs.add(materialVO.getPk_source());
meterialMap.put(materialVO.getPk_material(), materialVO.getPk_source());
}
Map<String, MaterialVersionVO> map = ((IMaterialPubService)NCLocator.getInstance().lookup(IMaterialPubService.class)).queryMaterialBaseInfoByOidPks((String[])meterialPKs.toArray(new String[0]), new String[]{"pk_material"});
for(int i = 0; i < copyVo.getChildrenVO().length; ++i) {
IVApplicationBodyVO bodyVO = (IVApplicationBodyVO)copyVo.getChildrenVO()[i];
if (bodyVO.getPk_materiel() != null) {
bodyVO.setPk_materiel(((MaterialVersionVO)map.get(meterialMap.get(bodyVO.getPk_materiel()))).getPk_material());
}
}
}
String cuserid = InvocationInfoProxy.getInstance().getUserId();
UFDateTime currTime = new UFDateTime(InvocationInfoProxy.getInstance().getBizDateTime());
UFDate currDate = currTime.getDate();
headvo.setBillstatus(-1);
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("");
Integer paramValue = SysInitQuery.getParaInt(headvo.getPk_org(), "SSCIVA01");
headvo.setKpfs(paramValue == null ? IVAplocationKPFS.ZLKP.toIntValue() : paramValue);
Map<String, UFDate> map = new HashMap();
map.put(headvo.getPk_customer(), headvo.getPreparedate());
Map<String, String> idMap = ((ICustomerPubService)NCLocator.getInstance().lookup(ICustomerPubService.class)).getCustomerLastVIDByOidAndDate(map);
headvo.setPk_customer_v((String)idMap.get(headvo.getPk_customer()));
for(int i = 0; i < copyVo.getChildrenVO().length; ++i) {
IVApplicationBodyVO bodyvo = (IVApplicationBodyVO)copyVo.getChildrenVO()[i];
bodyvo.setStatus(2);
}
return copyVo;
}
} else {
throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1058sal_0", "01058sal-0031"));
}
}
public boolean isFlowCheckman(String billId, String billType, String userId) throws BusinessException {
return IVSaleUtil.isCheckman(billId, billType, userId);
}
public IVApplicationAggVO calHeadJe(IVApplicationAggVO vo) throws BusinessException {
UFDouble hjje = UFDouble.ZERO_DBL;
UFDouble hjse = UFDouble.ZERO_DBL;
UFDouble jshj = UFDouble.ZERO_DBL;
UFDouble can_hjje = UFDouble.ZERO_DBL;
UFDouble can_hjse = UFDouble.ZERO_DBL;
UFDouble can_jshj = UFDouble.ZERO_DBL;
for(IVApplicationBodyVO bvo : vo.getBodyVOs()) {
if (bvo.getStatus() != 3) {
UFDouble xmje = bvo.getXmje() == null ? UFDouble.ZERO_DBL : bvo.getXmje();
UFDouble se = bvo.getSe() == null ? UFDouble.ZERO_DBL : bvo.getSe();
UFDouble xmjshj = bvo.getXmjshj() == null ? UFDouble.ZERO_DBL : bvo.getXmjshj();
UFDouble can_xmje = bvo.getCaninvoice_xmje() == null ? UFDouble.ZERO_DBL : bvo.getCaninvoice_xmje();
UFDouble can_se = bvo.getCaninvoice_se() == null ? UFDouble.ZERO_DBL : bvo.getCaninvoice_se();
UFDouble can_xmjshj = bvo.getCaninvoice_xmjshj() == null ? UFDouble.ZERO_DBL : bvo.getCaninvoice_xmjshj();
hjje = hjje.add(xmje);
hjse = hjse.add(se);
jshj = jshj.add(xmjshj);
can_hjje = can_hjje.add(can_xmje);
can_hjse = can_hjse.add(can_se);
can_jshj = can_jshj.add(can_xmjshj);
}
}
IVApplicationHeadVO headvo = vo.getHeadVO();
headvo.setHjje(hjje);
headvo.setHjse(hjse);
headvo.setJshj(jshj);
headvo.setCaninvoice_hjje(can_hjje);
headvo.setCaninvoice_hjse(can_hjse);
headvo.setCaninvoice_jshj(can_jshj);
return vo;
}
}