nc查询模板参照过滤联动

注意不要放错包了
import nc.ui.querytemplate.value.IFieldValueElement;
import nc.ui.querytemplate.value.RefValueObject;
这两个包很重要,
修改代码后需要重启客户端

package nc.ui.af.tableware.query;

import nc.ui.pubapp.uif2app.query2.IQueryConditionDLGInitializer;
import nc.ui.pubapp.uif2app.query2.QueryConditionDLGDelegator;
import nc.ui.pubapp.uif2app.query2.refregion.QueryDefaultOrgFilter;
import nc.ui.queryarea.quick.QuickQueryArea;
import nc.ui.querytemplate.CriteriaChangedEvent;
import nc.ui.querytemplate.ICriteriaChangedListener;
import nc.ui.querytemplate.ICriteriaEditor;
import nc.ui.querytemplate.filtereditor.FilterEditorWrapper;
import nc.ui.querytemplate.filtereditor.IFilterEditor;
import nc.ui.querytemplate.simpleeditor.SimpleEditor;
import nc.ui.querytemplate.value.IFieldValueElement;
import nc.ui.querytemplate.value.RefValueObject;

import java.util.ArrayList;
import java.util.List;

public class TablewareQueryConditionInitializer implements
    IQueryConditionDLGInitializer {

  @Override
  public void initQueryConditionDLG(QueryConditionDLGDelegator condDLGDelegator) {
      // TODO 初始化查询模板逻辑
      //这个数组目前是空的,请业务组把需要按组织过滤的参照字段加入到这个数组中
      List targetFields = new ArrayList();
      // TODO 加入需要按组织过滤的参照字段
    //根据当前用户所分配职责过滤组织参照	likq2	2019-2-25
      String[] permissionPkorgs = condDLGDelegator.getLogincontext().getPkorgs();
//      condDLGDelegator.setDefaultValue("pk_org", permissionPkorgs[0]);//添加默认的组织
      condDLGDelegator.registerNeedPermissionOrgFieldCode("pk_org", permissionPkorgs);
      QueryDefaultOrgFilter orgFilter=new QueryDefaultOrgFilter(condDLGDelegator,"pk_org",targetFields);
      orgFilter.addEditorListener();
      //从下面开始就是联动,代码修改后一定要重启客户端
      condDLGDelegator.registerCriteriaEditorListener(new ICriteriaChangedListener() {
			@Override
			public void criteriaChanged(CriteriaChangedEvent e) {
				if (e.getEventtype()==CriteriaChangedEvent.FILTER_CHANGED) {
					if ("pk_org".equals(e.getFieldCode())) {
						String[] refKeys = {"pk_fltconn","pk_assembly_details_f.pk_fltno"};//要过滤的字段,第一个字段是主表字段,第二个字段是子表字段
						List editorList = null;
						ICriteriaEditor ice = e.getCriteriaEditor();
						for(String refKey : refKeys){
						if (ice instanceof SimpleEditor) {//查询模板的获取
							editorList = ((SimpleEditor)e.getCriteriaEditor()).getFilterEditorsByCode(refKey);
						}else if(ice instanceof QuickQueryArea){//快速查询的获取
							editorList = ((QuickQueryArea)e.getCriteriaEditor()).getFilterEditorsByCode(refKey);
						}
						if (null != editorList && editorList.size() > 0) {
							IFilterEditor editor = editorList.get(0);
							FilterEditorWrapper few = new FilterEditorWrapper(editor);
							List list = e.getFilter().getFieldValue().getFieldValues();
							if (null != list && list.size()>0) {
								StringBuilder sb = new StringBuilder();
								String comma = "";
								for (IFieldValueElement element : list) {
									RefValueObject refValue = (RefValueObject) element.getValueObject();
									String pk_org = refValue.getPk();
									sb.append(comma);
									sb.append("'"+pk_org+"'");
									comma = ",";
								}
								few.setRefWherePart(" pk_org in ("+sb.toString()+") ");
							}else {
								few.setRefWherePart("");
							}
						}
					}
					}
				}
				
			}
			  
		  });
  }

}

你可能感兴趣的:(nc)