1、在列表界面查询控件新建beforeSearch 方法,在查询前干预查询参数,具体代码和脚本如下
前端代码:
beforequery:function(filter){
waf.doPost({
action:'getPersonByUserId',
data:{//向后台传递的参数
},
async:false,
success:function(data){//成功后返回的数据
if(data){
var ctx = waf.getContext();
if(!data.isLeader){
var cgpersonFilter=waf.parseSql.getFilter("cgperson.id","=",data["personId"]);
var applierFilter=waf.parseSql.getFilter("applier.id","=",data["personId"]);
var creatorFilter=waf.parseSql.getFilter("creator.id","=",ctx.currentUser.id);
var filter2=waf.parseSql.mergeFilter([applierFilter, cgpersonFilter,creatorFilter],'or');
filter = waf.parseSql.mergeFilter([filter, filter2],'and');
}
}
}
});
return filter;
}
后端脚本:
var imp=JavaImporter();
imp.importPackage(Packages.com.kingdee.eas.custom);
imp.importPackage(Packages.java.lang);
imp.importPackage(Packages.com.kingdee.bos);
imp.importPackage(Packages.com.kingdee.bos.webframework.context);
imp.importPackage(Packages.com.kingdee.eas.base.permission);
imp.importPackage(Packages.com.kingdee.eas.common);
imp.importPackage(Packages.com.kingdee.eas.basedata.org);
imp.importPackage(Packages.javax.servlet.http);
imp.importPackage(Packages.com.kingdee.eas.util.app);
imp.importPackage(Packages.com.kingdee.eas.basedata.assistant);
imp.importPackage(Packages.com.kingdee.bos.dao.ormapping);
imp.importPackage(Packages.com.kingdee.bos);
imp.importPackage(Packages.com.kingdee.eas.ep);
imp.importPackage(Packages.com.kingdee.bos.metadata);
imp.importPackage(Packages.com.kingdee.bos.util);
imp.importPackage(Packages.com.kingdee.eas.basedata.person);
imp.importPackage(Packages.com.kingdee.bos.webframework.exception);
imp.importPackage(Packages.com.kingdee.bos.webframework.util);
imp.importPackage(Packages.com.kingdee.bos.webframework.dynamic.application);
imp.importPackage(Packages.com.kingdee.bos.webframework.dynamic.event.view);
imp.importPackage(Packages.com.kingdee.bos.webframework.json);
imp.importPackage(Packages.com.kingdee.eas.hr.emp);
imp.importPackage(Packages.com.kingdee.bos.metadata.entity);
imp.importPackage(Packages.java.util);
with(imp){
var ctx=WafContext.getInstance().getContext();
//当前用户
var user =ctx.get(com.kingdee.eas.common.SysContextConstant.USERINFO);
var cu=ctx.get(OrgType.ControlUnit);
var entityViewInfo=new EntityViewInfo();
var filterInfo=new FilterInfo();
filterInfo.getFilterItems().add(new FilterItemInfo("person.id",user.getPerson().getId().toString()));
filterInfo.getFilterItems().add(new FilterItemInfo("CU.id",cu.getId().toString()));
filterInfo.setMaskString("(#0 and #1)");
entityViewInfo.setFilter(filterInfo);
//var personPositionCollection=PersonPositionFactory.getLocalInstance(ctx).getPersonPositionCollection(entityViewInfo);
var resultMap=new HashMap();
resultMap.put("personId", user.getPerson().getId());
//查询
var sql="select b.fid from T_ORG_PositionMember a "
+"join T_ORG_Position b on a.FPOSITIONID =b.fid "
+"JOIN T_ORG_BASEUNIT C ON B.FADMINORGUNITID =C.FID "
+"where a.FPERSONID ='"+user.getPerson().getId().toString()+"' and ((c.FCONTROLUNITID ='"+cu.getId().toString()+"' and b.FNAME_L2 in('部门经理') AND C.FNAME_L2='XXX') "
var rowset = DbUtil.executeQuery(ctx, sql);
if (rowset.next()){
resultMap.put("isLeader", true);
}
else{
resultMap.put("isLeader", false);
}
resultMap.put("sql", sql);
JSONUtils.SUCCESS(resultMap);
}