实现功能
下面两个是按钮
下面红框里面的内容是上面单据带过来的
上面就是本地代码实现的功能
具体实现代码
提前约定
为了方便称呼,这里把第一张图称为上游单据,第二张图为下游单据
所有代码AggVo都要替换成你自己的
- 配置文件
上游单据拓展配置文件:
<!-- 插入整改按钮 -->
<bean class="nc.ui.pubapp.plugin.action.InsertActionInfo">
<property name="actionContainer" ref="actionsOfList" />
<property name="actionType" value="notedit" />
<!-- pFApproveStatusInfoAction是你单据里面的一个按钮 -->
<property name="target" ref="pFApproveStatusInfoAction" />
<property name="pos" value="after" />
<!-- ExecuAction对应下面的bean,这个bean就是按钮配置类 -->
<property name="action" ref="ExecuAction" />
</bean>
<bean id="ExecuAction" class="nc.ui.hd.hazardenter.action.CorrectAction">
<property name="model" ref="bmModel" />
</bean>
- ExecuAction对应的CorrectAction类
package nc.ui.hd.hazardenter.action;
import java.awt.event.ActionEvent;
import nc.desktop.ui.WorkbenchEnvironment;
import nc.funcnode.ui.FuncletInitData;
import nc.funcnode.ui.FuncletWindowLauncher;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.uif2.NCAction;
import nc.ui.uif2.model.AbstractAppModel;
import nc.vo.hd.hazardenter.AggHazardHVO;
import nc.vo.sm.funcreg.FuncRegisterVO;
/**
*
* @author: wangchao
* @ClassName: CorrectAction
* @Description: 对XX进行XX
* @date: 2022年12月29日
*/
public class CorrectAction extends NCAction {
private static final long serialVersionUID = 9169939802794646069L;
private AbstractAppModel model;
public AbstractAppModel getModel() {
return model;
}
public void setModel(AbstractAppModel model) {
this.model = model;
}
public CorrectAction(){
setBtnName("按钮名称");
setCode("writcorrect");
}
@Override
public void doAction(ActionEvent e) throws Exception {
// AggHazardHVO 是上游单据的AggVo,换成你自己的
AggHazardHVO aggRent=(AggHazardHVO) this.getModel().getSelectedData();
if (aggRent==null || aggRent.equals("")) {
MessageDialog.showErrorDlg(getModel().getContext().getEntranceUI(),"错误","请选择一项XX进行XX!");
return;
}
// 45H90405是要打开的下游单据的功能编码
FuncRegisterVO funvo = WorkbenchEnvironment.getInstance().getFuncRegisterVO("45H90405");
FuncletWindowLauncher.openFuncNodeInTabbedPane(null, funvo, getInitData(aggRent), null, true);
}
public FuncletInitData getInitData(AggHazardHVO aggRent){
FuncletInitData data = new FuncletInitData();
data.setInitData(aggRent);
data.setInitType(-1);
return data;
}
}
- 下游单据配置文件
<!-- 打开节点监听 newadd-->
<!--<bean id="InitDataListener" class="nc.ui.pubapp.uif2app.model.DefaultFuncNodeInitDataListener">
<property name="model" ref="bmModel"/>
<property name="context" ref="context"></property>
<property name="voClassName" value="nc.vo.hd.hazardcorrect.AggHazardcorrect"/>
</bean>-->
<!-- 打开节点监听 newadd-->
<bean id="InitDataListener" class="nc.ui.hd.hazardcorrect.ace.handler.MyDefaultFuncNodeInitDataListener">
<property name="model" ref="bmModel"/>
<property name="context" ref="context"></property>
<property name="billform" ref="billForm"></property>
<property name="defaultUIF2RefEditor">
<ref bean="defaultUIF2RefEditor" />
</property>
</bean>
<!-- 导入编辑器 -->
<bean id="defaultUIF2RefEditor" class="nc.itf.hd.DefaultUIF2RefEditor">
<property name="addAction" ref="addAction" />
<property name="billcardPanelEditor" ref="billForm" />
<property name="appModel" ref="bmModel" />
</bean>
说明:注释掉原来的节点监听,编写自己的MyDefaultFuncNodeInitDataListener 节点初始化监听类,再来一个DefaultUIF2RefEditor类就可以了
- MyDefaultFuncNodeInitDataListener 类
package nc.ui.hd.hazardcorrect.ace.handler;
import java.util.Collection;
import java.util.List;
import nc.bs.framework.common.NCLocator;
import nc.funcnode.ui.FuncletInitData;
import nc.itf.hd.DefaultUIF2RefEditor;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.md.persist.framework.MDPersistenceService;
import nc.ui.pubapp.uif2app.model.DefaultFuncNodeInitDataListener;
import nc.ui.pubapp.uif2app.view.ShowUpableBillForm;
import nc.vo.hd.hazardcorrect.AggHazardcorrect;
import nc.vo.hd.hazardcorrect.Hazardcorrect;
import nc.vo.hd.hazardenter.AggHazardHVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.AppContext;
/**
*
* @author: wangchao
* @ClassName: MyDefaultFuncNodeInitDataListener
* @Description: 节点打开初始化数据
* @date: 2022年12月29日
*/
public class MyDefaultFuncNodeInitDataListener extends DefaultFuncNodeInitDataListener {
ShowUpableBillForm billform;
private DefaultUIF2RefEditor defaultUIF2RefEditor = null;
public MyDefaultFuncNodeInitDataListener(){
super();
}
@Override
public void initData(FuncletInitData data) {
if (null == data) {
this.getModel().initModel(null);
return;
}
//用参数中传过来的数据初始化AppModel,可能会转换成VO或VO数组,根据业务确定
AggHazardHVO parentInitData =(AggHazardHVO) data.getInitData();
InitDataListener initData = new InitDataListener();
String sql = "select * from HD_CORRECT where PK_HIDDENDANGER = '"+ parentInitData.getParentVO().getPk_hiddendanger_h()+"'"; //数据库名 改成需要的
System.out.println("=============="+sql);
//this.getModel().setContext(context);
//我这做了一个逻辑判断,如果查询到下游单据没用数据,则新增。如果有就展示列表数据,进行提交、审核等操作
if (initData.getFuncletInitData(sql, AggHazardcorrect.class) != null) {
this.getModel().initModel(initData.getFuncletInitData(sql, AggHazardcorrect.class).getInitData()); //agg改成需要的
//super.initData(initData.getInitData(sql, AggTenderProject.class));
}else{
//这里bill是下游单据的AggVo,用chg方法封装一下
AggHazardcorrect bill = chg(parentInitData);//生成单据
// //调用添加按钮
getDefaultUIF2RefEditor().addNew();
// //初始化数据
getDefaultUIF2RefEditor().setValue(bill);
}
}
private AggHazardcorrect chg(AggHazardHVO parentInitData) {
AggHazardcorrect bill = new AggHazardcorrect();
Hazardcorrect zb = chgHead(parentInitData);
bill.setParentVO(zb);
bill.setChildrenVO(null);
return bill;
}
private Hazardcorrect chgHead(AggHazardHVO parentInitData){
Hazardcorrect zb = new Hazardcorrect();
zb.setPk_hiddendanger(parentInitData.getParentVO().getPk_hiddendanger_h());
zb.setHd_checkform(parentInitData.getParentVO().getHd_checkform());
zb.setHd_checkorg(parentInitData.getParentVO().getHd_checkorg());
zb.setHd_checkorg(parentInitData.getParentVO().getHd_checkorg());
zb.setHd_outcheckorg(parentInitData.getParentVO().getHd_outcheckorg());
zb.setHd_checkuser(parentInitData.getParentVO().getHd_checkuser());
zb.setHd_becheckorg(parentInitData.getParentVO().getHd_becheckorg());
zb.setHd_checktime(parentInitData.getParentVO().getHd_checktime());
zb.setHd_level(parentInitData.getParentVO().getHd_level());
zb.setHd_content(parentInitData.getParentVO().getHd_content());
zb.setHd_limitime(parentInitData.getParentVO().getHd_limittime());
zb.setHd_dutydept(parentInitData.getParentVO().getHd_dutydept());
zb.setHd_status(parentInitData.getParentVO().getHd_status());
zb.setHd_isextension(parentInitData.getParentVO().getHd_isextension()+"");
zb.setPk_group(parentInitData.getParentVO().getPk_group());
zb.setPk_org(parentInitData.getParentVO().getPk_org());
zb.setPk_org_v(parentInitData.getParentVO().getPk_org_v());
zb.setRec_org(parentInitData.getParentVO().getHd_becheckorg());
zb.setFstatusflag(-1);
zb.setOperator(AppContext.getInstance().getPkUser());
return zb;
}
public class InitDataListener {
private FuncletInitData data = null;
/**
* 根据查询主表sql与AggVO类型,获取需要加载到页面的初始化数据
* @param sql 需要加载的数据的查询sql,注意,这里只写查询主表的sql
* @param clazz 该单据的AggVO
* @return
*/
public FuncletInitData getFuncletInitData(String sql, Class<?> clazz){
IUAPQueryBS query = (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
Object[] objs = null;
String[] pkIds = null;
List<String> list = null;
try {
list = (List<String>) query.executeQuery(sql, new ColumnListProcessor());
if(list != null && list.size()>0){
pkIds = new String[list.size()];
for(int i=0; i<list.size(); i++){
pkIds[i] = list.get(i);
}
Collection collection = MDPersistenceService.lookupPersistenceQueryService().queryBillOfVOByPKs(clazz, pkIds, false);
objs = collection.toArray();
getData().setInitData(objs);
}
else{
return null;
}
} catch (BusinessException e) {
e.printStackTrace();
}
return data;
}
/**
* 获取FuncletInitData
* @return
*/
public FuncletInitData getData() {
if(data == null){
data = new FuncletInitData();
}
return data;
}
public void setData(FuncletInitData data) {
this.data = data;
}
}
public ShowUpableBillForm getBillform() {
return billform;
}
public void setBillform(ShowUpableBillForm billform) {
this.billform = billform;
}
public DefaultUIF2RefEditor getDefaultUIF2RefEditor() {
return defaultUIF2RefEditor;
}
public void setDefaultUIF2RefEditor(DefaultUIF2RefEditor defaultUIF2RefEditor) {
this.defaultUIF2RefEditor = defaultUIF2RefEditor;
}
}
- DefaultUIF2RefEditor类(这个类不用改动,直接粘过去就行)
package nc.itf.hd;
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;
}
}
上面就是实现开头图片功能的所有代码了,当然也能实现下游单据主子表的功能,具体给
bill.setChildrenVO(null);
找到这行代码,给child赋值查询出来的list即可