其他分享
首页 > 其他分享> > EAS列表过滤

EAS列表过滤

作者:互联网

@Override
protected IQueryExecutor getQueryExecutor(IMetaDataPK pk,
EntityViewInfo viewInfo) {
EntityViewInfo botpFilter = getBOTPFilter();

       SorterItemCollection sorterItems = viewInfo.getSorter();// 获取排序条件
       EntityViewInfo evi = viewInfo;
       FilterInfo filter2 = new FilterInfo();
  if(botpFilter != null){
        // 针对botp使用原始条件
        filter2 = viewInfo.getFilter();
  }else{
        // 当前登录人
        Object number = SysContext.getSysContext().getCurrentUserInfo().get("number");
        if(number == null) number = "";
        Object personID = SysContext.getSysContext().getCurrentUserInfo().getId();
        // 当前登录组织
        Object orgID = SysContext.getSysContext().getCurrentOrgUnit().getId();
        FilterItemCollection collection = viewInfo.getFilter().getFilterItems();
        // 1.针对user
        if("user".equalsIgnoreCase(number.toString())){
             // 剔除组织过滤条件
             if(collection != null){
                  int size = collection.size();
                   // 将组织过滤条件剔除
                   for(int i = 0;i < size; i++){
                         String val = collection.get(i).toString();
                         if(collection.get(i).toString().indexOf("FICompany.id") < 0 & collection.get(i).toString().indexOf("CU.id") < 0){
                              filter2.getFilterItems().add(collection.get(i));
                         }
                   }
             }
        }else{
             FilterInfo filter3 = new FilterInfo();
             String val = "";
             int j = 0;//次标记用来记录条件的 or and
             int k = 0;//假如在前台加上过滤条件,那么cu.id将不是第一个条件,应该用and连接,用k记录他是不是第一个条件
             StringBuffer buffer = new StringBuffer();
             // 2.针对普通用户
             if(collection != null){
                  int size = collection.size();
                   // 将组织过滤条件剔除
                   for(int i = 0;i < size; i++){
                         val = collection.get(i).toString();
                         if(val.indexOf("id in") < 0){
                              filter3.getFilterItems().add(collection.get(i));
                              if(val.indexOf("CU.id") >= 0){
                                   if(j == 0)
                                        buffer.append("#"+j);
                                   else if(j > 0){
                                        if(k == 0 && j > 0){
                                              // 有通用过滤
                                              buffer.append(" and #"+j);
                                        }else{
                                              // 无通用过滤
                                              buffer.append(" or #"+j);
                                        }
                                   }
                                   k++;
                              }else{
                                   if(j == 0)
                                        buffer.append("#"+j);
                                   else if(j > 0){
                                        buffer.append(" and #"+j);
                                   }
                              }
                              j++;
                         }
                   }
                   String mask = buffer.toString();
                   System.out.println(mask);
                   filter3.setMaskString(mask);
             }
             
                 Set params = new HashSet();
                 String sql = "Select FID from CT_Ass_AssetStoreIn where CFFICompanyID in (";
                 sql += "Select t1.FID deptID from ";
                 sql += " T_ORG_BaseUnit t1 ";
                 sql += " inner join CT_Ass_CusPermissionEntry t2 on t1.FID = t2.CFDeptId ";
                 sql += " inner join CT_Ass_CusPermission t3 on t2.FParentID = t3.FID ";
                 sql += " where (t1.fid ='"+orgID+"' or  t1.FPARENTID = '"+orgID+"') and t3.CFPersonID = ";
                 sql += "(select FPersonId from T_PM_User where FID = '"+personID+"')";
                 sql += ")";
                 //sql = "{Call proc_wmq_CtlDB('"+orgID+"','"+personID+"',14)}";
                 ISQLExecutor se=SQLExecutorFactory.getRemoteInstance(sql);
                 IRowSet rowSet = null;
                 try {
                       rowSet =se.executeSQL();
                       while(rowSet.next()){
                            params.add(rowSet.getString("FID")); // 需要动态获取的ID
                       }
                       // 过滤 ,多个filter默认是and 当需条件为or时,如下
                       if(params.size() < 1){
                            params.add("");
                       }
                 }catch(Exception sqlEE){
                       sqlEE.printStackTrace();
                 }          
                 filter2.getFilterItems().add(
                            new FilterItemInfo("id", params, CompareType.INCLUDE));
                 try {
                       filter2.mergeFilter(filter3, "and");
                 } catch (BOSException e) {
                       e.printStackTrace();
                 }
        }
  }
  evi.setSorter(sorterItems);
       evi.setFilter(filter2);
  IQueryExecutor queryExecutor = super.getQueryExecutor(pk, evi);
       return queryExecutor;
}

标签:get,buffer,collection,列表,过滤,FID,sql,EAS,size
来源: https://www.cnblogs.com/wmq1310/p/filterList.html