用友nc65 uap开发参照节点数据拉单之二----直接通过调用查询模版查询上游单据

用友nc65 uap开发参照节点数据拉单之二----直接通过调用查询模版查询上游单据
前面一篇博客讲了利用查询模版并显示在弹窗面板上的拉单方法。此次是直接通过调用查询模版查询上游所有单据。如图所示:
按钮调用查询面板

将符合条件的所有数据直接显示在编辑状态的面板上:



代码如下:
xml代码:
<bean id="refAction" class="nc.ui.fdc_pr.h303201570.ace.action.ReferAction">
		<property name="model">
			<ref bean="bmModel" />
		</property>
		<property name="editor" ref="billForm" />
		<!--当前单据类型编码 -->
		<property name="currBilltype" value="H338" />
		<!-- 来源单据类型编码 -->
		<property name="sourceBillType" value="H345" />
		<!-- 来源单据类型名称 -->
		<property name="sourceBillName" value="参照收费清单" />

		<property name="exceptionHandler">
			<ref bean="exceptionHandler" />
		</property>
		<property name="defaultUIF2RefEditor">
			<ref bean="defaultUIF2RefEditor" />
		</property>
	</bean>

	<!-- 导入编辑器 -->
	<bean id="defaultUIF2RefEditor" class="nc.itf.fdc.pub.DefaultUIF2RefEditor">
		<property name="addAction" ref="addAction" />
		<property name="billcardPanelEditor" ref="billForm" />
		<property name="appModel" ref="bmModel" />
	</bean>
按钮代码类:
package nc.ui.fdc_pr.h303201570.ace.action;

import java.awt.Container;
import java.awt.event.ActionEvent;

import nc.bs.framework.common.NCLocator;
import nc.bs.pf.pub.BillTypeCacheKey;
import nc.itf.fdc.pub.DefaultUIF2RefEditor;
import nc.itf.fdc_pr.IH303201525Maintain;
import nc.md.data.access.NCObject;
import nc.ui.ml.NCLangRes;
import nc.ui.pf.pub.PfUIDataCache;
import nc.ui.pr.H30301.LogonBO_Client;
import nc.ui.pub.beans.UIDialog;
import nc.ui.pub.bill.BillStatus;
import nc.ui.pubapp.uif2app.actions.AbstractReferenceAction;
import nc.ui.pubapp.uif2app.model.BillManageModel;
import nc.ui.querytemplate.IBillReferQuery;
import nc.ui.querytemplate.QueryConditionDLG;
import nc.ui.uif2.UIState;
import nc.ui.uif2.editor.IBillCardPanelEditor;
import nc.vo.fdc_pr.h303201525.Bill;
import nc.vo.fdc_pr.h303201570.AggDjzb;
import nc.vo.fdc_pr.h303201570.Djfb;
import nc.vo.fdc_pr.h303201570.Djzb;
import nc.vo.pub.BusinessException;
import nc.vo.pub.VOStatus;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pub.pf.BillStatusEnum;
import nc.vo.pubapp.AppContext;
import nc.vo.querytemplate.TemplateInfo;
import nc.vo.uap.pf.PFBusinessException;
import nc.vo.uif2.LoginContext;

import org.apache.commons.lang.StringUtils;

public class ReferAction extends AbstractReferenceAction {

	private static final long serialVersionUID = -7167526730230052116L;

	// 卡片面板
	private IBillCardPanelEditor editor;

	// model
	private BillManageModel model;

	private String currBilltype;

	private IBillReferQuery dlg;
	
	private DefaultUIF2RefEditor defaultUIF2RefEditor = null;


	public ReferAction() {
		super();
	}

	@Override
	public void doAction(ActionEvent e) throws Exception {

		LoginContext context = this.getModel().getContext();
		String funNode = PfUIDataCache.getBillType(
				new BillTypeCacheKey().buildBilltype(getSourceBillType())
						.buildPkGroup(context.getPk_group())).getNodecode();
		if (funNode == null || funNode.equals(""))
			throw new PFBusinessException(NCLangRes.getInstance().getStrByID(
					"pfworkflow1", "PfUtilClient-000001", null,
					new String[] { getSourceBillType() })/* 请注册单据{0}的功能节点号 */);

		// 1.构造查询对话框

		if (dlg == null) {
			dlg = setConditionClient(null, context.getEntranceUI(),
					context.getPk_loginUser(), funNode, context.getPk_group());
		}

		if (dlg.showModal() != UIDialog.ID_OK) {
			return;
		}

		//not exists ( select 1 from fdc_pr_FareType ft where nvl(ft.dr,0)=0 and nvl(ft.reserve1,'N')='Y' and ft.pk_head = fdc_pr_Bill.pk_faretypeid )
		StringBuffer strWhere = new StringBuffer();
		if(dlg.getWhereSQL()==null||dlg.getWhereSQL().trim().length()==0){
			strWhere.append(" 1=1 ");
		}else{
			strWhere.append(dlg.getWhereSQL());
		}
		
		strWhere.append( " and isnull(fdc_pr_Bill.dr,0)=0 and isnull(fdc_pr_Bill.bisarap,'N')='N' ");
		strWhere.append( " and not exists ( select 1 from fdc_pr_FareType ft where isnull(ft.dr,0)=0 and isnull(ft.reserve1,'N')='Y' and ft.pk_head = fdc_pr_Bill.pk_faretypeid )  ");
		strWhere.append( " and isnull(fdc_pr_Bill.bclose,'N')='N'" );//关闭的数据不参照过来
		// 2.根据查询条件得到收费清单:

		// 2. 1 根据单据类型,利用元数据查询 :前提要求上游元数据,实现了IHeadBodyQueryItf接口
		// IPFConfig pfConfig = (IPFConfig)
		// NCLocator.getInstance().lookup(IPFConfig.class.getName());
		// CircularlyAccessibleValueObject[] tmpHeadVo =
		// pfConfig.queryHeadAllData(getSourceBillType(), tmpWhere);

		// 2. 2 调用上游查询接口

		IH303201525Maintain maint = NCLocator.getInstance().lookup(
				IH303201525Maintain.class);
		//查询模板查询条件查询收费清单*(已经收完款的不用查出来)
		NCObject[] bills = maint.querybillbywhere(strWhere.toString());
//		Bill[] bills = maint.query(strWhere);

		if (bills == null || bills.length == 0) {
			 throw new BusinessException("未查询到收费清单数据.");
		}
		// 3. 转换数据:可以代码 硬编码转换,也可以调用单据转换规则。

		AggDjzb bill = chg(bills);//生成单据
		
		
		// 4. 设置编辑状态数据
		getDefaultUIF2RefEditor().addNew();
		getDefaultUIF2RefEditor().setValue(bill);
	}
	
	
	/**
	 * 生成“财务应收单”
	 * */
	private AggDjzb chg(NCObject[] bills) {
		
		AggDjzb bill = new AggDjzb();

		Djzb zb = chgHead(bills);

		bill.setParentVO(zb);

		bill.setChildrenVO(chgBodys(bills));

		return bill;
	}
	
	/**
	 * 设置表头数据
	 * */
	public Djzb chgHead(NCObject[] bills) {
		Djzb head = new Djzb();
		head.setPk_group(AppContext.getInstance().getPkGroup());//集团
		head.setDbilldate(AppContext.getInstance().getBusiDate());//单据日期
		head.setAttributeValue("approvestatus", BillStatusEnum.FREE.value());//单据状态
		String pk_org = getModel().getContext().getPk_org();
		if (StringUtils.isBlank(pk_org)) {
			if (bills != null && bills.length > 0) {
				pk_org = (String) bills[0].getAttributeValue("pk_org");
			}
	    		getModel().getContext().setPk_org(pk_org);
		}
		head.setPk_org(pk_org);//组织
		//是否传会计平台
		head.setFisvoucher(UFBoolean.TRUE);
		//计财务应收日期
		head.setDrecordapdate(AppContext.getInstance().getBusiDate());
		//制单人
		head.setCreator(AppContext.getInstance().getPkUser());
		//制单日期
		head.setMaketime(AppContext.getInstance().getServerTime());
		//单据状态
		head.setVbillstatus(BillStatus.FREE);
		//服务中心
//		head.setPk_managementsecid();
		//经办人
		head.setPk_psndoc(AppContext.getInstance().getPkUser());
		//单据类型
		head.setBilltype("H338");
		//创建人
		head.setBillmaker(AppContext.getInstance().getPkUser());
		//币种
		head.setVdef1("");
		//
		head.setStatus(VOStatus.NEW);
		
		head.setPk_managementsecid(LogonBO_Client.getManageUnit());//服务中心
		head.setPk_psndoc(AppContext.getInstance().getPkUser());//经办人	
		
		return head;
	}

	/**
	 * 生成表体数据 
	 * 
	 * */
	public Djfb[] chgBodys(NCObject[] bills) {

		if (bills == null) {
			return null;
		}
		Djfb[] bodys = new Djfb[bills.length];

		for (int i = 0; i < bodys.length; i++) {
			Bill head = (Bill) bills[i].getModelConsistObject();
			if(head.getSrnmny()==null||head.getSrnmny().doubleValue()<=0){
				continue;
			}
			/*if(head.getSrnrevmny()!=null
					&&head.getSrnrevmny().doubleValue()>0
					&&head.getSrnmny().sub(head.getSrnrevmny()).doubleValue()==0D){
				continue;
			}*/
				
			Djfb body = new Djfb();
			body.setVsourcebillid(head.getPk_head());//来源单据ID == 收费清单主键
			body.setReserve5(head.getReserve1());//合同编号
			body.setPk_pact(head.getPk_pact());
			if(head.getPk_currency()!=null){
				body.setPk_currency(head.getPk_currency());//币种
			}else{
				body.setPk_currency("1002Z0100000000001K1");//币种,人民币
			}
			body.setPk_faretypeid(head.getPk_faretypeid());//收费项目
			body.setReserve1(head.getPk_allhouses());//单元
			body.setReserve2(head.getPk_customer());//租户
			body.setDbegin(head.getDbegin());//收费开始日期
			body.setCostbelongmonth(head.getCostbelongmonth());//费用所属月
			body.setDend(head.getDend());//费用截至日期
			body.setDshpay(head.getDshpay());//应收款日期
			body.setBusreceivemonth(head.getBusreceivemonth());//业务应收月
			body.setReserve3(head.getPk_faretypeid());//收费项目
			
			//应收金额信息(原币/本币)
			UFDouble srnmny = new UFDouble(0);
			if(null != head.getSrnmny())srnmny =head.getSrnmny();
			UFDouble srnrevmny = new UFDouble(0);
			if(null != head.getSrnrevmny())srnrevmny =head.getSrnrevmny();
			
//			body.setSrnmny(srnmny.sub(srnrevmny));//应收金额 == 总应收 - 已收金额
			body.setSrnmny(srnmny);//应收金额 
			body.setNmny(srnmny.sub(srnrevmny));
//			body.setNyarapverifmny(nyarapverifmny);//核销金额
			
			//收费清单的来源源单据类型
			body.setSrc_bill_type(head.getVsourcebilltype());
			// 来源单据信息
			body.setVsourcebillid(head.getPrimaryKey());
			//来源单据号
			body.setSrc_bill_code(head.getVbillcode());
			//租约类型
			body.setPk_pacttype(head.getPk_pacttype());
			body.setStatus(VOStatus.NEW);
			//上游单据主键
			body.setVlastbillrowid(head.getPk_head());
			
			bodys[i] = body;
		}

		return bodys;

	}

	/**
	 * 构造一个查询对话框,并为其设置查询模板
	 * 
	 * @param templateId
	 * @param parent
	 * @param isRelationCorp
	 * @param pkOperator
	 * @param funNode
	 */
	private IBillReferQuery setConditionClient(String templateId,
			Container parent, final String pkOperator, final String funNode,
			String pkCorp) {
		TemplateInfo ti = new TemplateInfo();
		ti.setTemplateId(templateId);
		ti.setPk_Org(pkCorp);
		ti.setUserid(pkOperator);
		ti.setCurrentCorpPk(pkCorp);
		ti.setFunNode(funNode);
		ti.setNodekey("qt");

		QueryConditionDLG qcDlg = new QueryConditionDLG(parent, ti);

		qcDlg.setVisibleNormalPanel(true);
		return qcDlg;
	}

	public IBillCardPanelEditor getEditor() {
		return this.editor;
	}

	/**
	 * @return model
	 */
	public BillManageModel getModel() {
		return this.model;
	}

	public void setEditor(IBillCardPanelEditor editor) {
		this.editor = editor;
	}

	/**
	 * @param model
	 *            要设置的 model
	 */
	public void setModel(BillManageModel model) {
		this.model = model;
		model.addAppEventListener(this);
	}

	public String getCurrBilltype() {
		return currBilltype;
	}

	public void setCurrBilltype(String currBilltype) {
		this.currBilltype = currBilltype;
	}

	/**
	 * 父类方法重写
	 * 
	 * @see nc.ui.uif2.NCAction#isActionEnable()
	 */
	@Override
	protected boolean isActionEnable() {
		return UIState.NOT_EDIT == this.getModel().getUiState();
	}

	/**
	 * 转单是否根据流程过滤
	 * 
	 * @return
	 */
	protected boolean isBusiness() {
		return true;
	}

	public DefaultUIF2RefEditor getDefaultUIF2RefEditor() {
		return defaultUIF2RefEditor;
	}

	public void setDefaultUIF2RefEditor(DefaultUIF2RefEditor defaultUIF2RefEditor) {
		this.defaultUIF2RefEditor = defaultUIF2RefEditor;
	}

}
导入编辑器类
package nc.itf.fdc.pub;

import nc.ui.pub.bill.BillData;
import nc.ui.uif2.NCAction;
import nc.ui.uif2.editor.IBillCardPanelEditor;
import nc.ui.uif2.model.AbstractUIAppModel;
import nc.vo.pub.AggregatedValueObject;


public  class DefaultUIF2RefEditor  {
 
	
	
	private NCAction addAction = null;
									
	private Exception ex;    //保存过程中通过拦截器将异常抛出 

	
	private IBillCardPanelEditor billcardPanelEditor = null;
	
	private AbstractUIAppModel appModel = null;
	

	protected NCAction createAddAction()
	{
		return null;
	}
	
	protected NCAction createSaveAction()
	{
		return null;
	} 
	
	protected NCAction createCancelAction()
	{
		return null;
	}
	
	protected IBillCardPanelEditor createBillCardPanelEditor()
	{
		return null;
	}
	
	protected AbstractUIAppModel createAppModel()
	{
		return null;
	}
	
	
	 
	
	/**
	 * 新增操作
	 * 
	 * @see nc.itf.trade.excelimport.IImportableEditor#addNew()
	 */
	public void addNew() {
		try {
			getAddAction().actionPerformed(null);
		} catch (Exception e) {
			nc.bs.logging.Logger.error(e.getMessage());
		}
	} 
	
	/**
	 * 设值操作
	 * 
	 * 标准的操作步骤如下:
	 * 1,转型VO为ExtendedAggregatedValueObject
	 * 2,根据转换规则处理VO的相关属性值
	 * 3,将处理后的VO值设置到界面上
	 */
	public void setValue(Object obj) {
		if(getBillcardPanelEditor() != null)
		{
			BillData bd = getBillcardPanelEditor().getBillCardPanel().getBillData();
			bd.setBillValueVO((AggregatedValueObject)obj);
		}
	}



	
	/**
	 * 返回AddAction对象
	 */
	public NCAction getAddAction() {
		
		if(addAction == null)
			addAction = createAddAction();
		return this.addAction;
	}

	

	public void setAddAction(NCAction addAction) {
		this.addAction = addAction;
	}

	public IBillCardPanelEditor getBillcardPanelEditor() {
		
		if(billcardPanelEditor == null)
			billcardPanelEditor = createBillCardPanelEditor();
		return billcardPanelEditor;
	}

	public void setBillcardPanelEditor(IBillCardPanelEditor billcardPanelEditor) {
		this.billcardPanelEditor = billcardPanelEditor;
	}



	
	public AbstractUIAppModel getAppModel() {
		
		if(this.appModel == null)
			appModel = createAppModel();
		return appModel;
	}

	public void setAppModel(AbstractUIAppModel model) {
		this.appModel = model;
	}
	
	public int getExportCount() {
		return 1;
	}

	public Exception getEx() {
		return ex;
	}

	public void setEx(Exception ex) {
		this.ex = ex;
	}
}




  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值