public abstract class BaseController {
    public BaseController() {
        
    }
     /**
     * 编辑查询条件
     * @param  search             HttpServletRequest
     * @return Map<String, Object> 检索条件Map
     */
    public QueryWrapper getSearchMap(String search, String sortPlus, String sortOrder, String[] conditionArray,Schema.SObjectType type) {
        return getSearchMap(search, sortPlus, sortOrder, conditionArray,type, null);
    }
     /**
     * 编辑查询条件
     * @param  search             HttpServletRequest
     * @return Map<String, Object> 检索条件Map
     */
    public QueryWrapper getSearchMap(String search, String sortPlus, String sortOrder, String[] conditionArray,Schema.SObjectType type, List<SObjectField> sObjectFieldList) {
      
        // 对搜索条件进行过滤
        Map<String, Object> conditionMap = new Map<String, Object>();
        if(search != null && !search.equals('')){
            String param = EncodingUtil.urlDecode(search, 'utf-8');
            // 前一次检索条件
            Map<String, Object> pageCond = (Map<String, Object>)JSON.deserializeUntyped(param);
            if (pageCond != null && !pageCond.equals('')) {
                for(String key : pageCond.keySet()) {
                    if(conditionArray.contains(key)) {
                        Integer i = 1;
                        conditionMap.put(key.trim(), pageCond == null || pageCond.equals('') 
                                || pageCond.get(key) == null || (pageCond.get(key) instanceof String && ((String)pageCond.get(key)).equals(''))
                                ? null : pageCond.get(key));
                    }
                }
            }
            
        }

        QueryWrapper queryWrapper = new QueryWrapper(type, sObjectFieldList);
        if (sortPlus != null && !sortPlus.equals('') && sortOrder != null && !sortOrder.equals('')) {
            if ( sortOrder.equals('asc')) {
                // 判断列名称的合法性，防止SQL注入。只能是【字母，数字，下划线】
                // if (!sortPlus.matches('[A-Za-z0-9_]+')) {
                    // throw new IllegalArgumentException("非法的排序字段名称：" + sort);
                // }
                queryWrapper.orderByAsc(sortPlus);
            } else if ( sortOrder.equals('desc')) {
                // 判断列名称的合法性，防止SQL注入。只能是【字母，数字，下划线】
                // if (!sortPlus.matches('[A-Za-z0-9_]+')) {
                    // throw new IllegalArgumentException("非法的排序字段名称：" + sort);
                // }
                queryWrapper.orderByDesc(sortPlus);
            } else {
                // throw new IllegalArgumentException("非法的排序策略：" + sortOrder);
            }
        }

        for(String mEntry : conditionMap.keySet()) {
            if(conditionMap.get(mEntry) != null && !conditionMap.get(mEntry).equals('')) {
                if (mEntry.endsWith('Equal')) {
                    if (mEntry.endsWith('NotEqual')) {
                        queryWrapper.ne(mEntry.substring(0, mEntry.length() - 8), conditionMap.get(mEntry));
                    } else {
                        queryWrapper.eq(mEntry.substring(0, mEntry.length() - 5), conditionMap.get(mEntry));
                    }
                } else if (mEntry.endsWith('Begin')) {
                    queryWrapper.gt(mEntry.substring(0,mEntry.length() - 5),conditionMap.get(mEntry));
                } else if (mEntry.endsWith('BeginEqual')) {
                    queryWrapper.ge(mEntry.substring(0,mEntry.length() - 10),conditionMap.get(mEntry));
                } else if (mEntry.endsWith('End')) {
                    queryWrapper.lt(mEntry.substring(0,mEntry.length() - 3),conditionMap.get(mEntry));
                } else if (mEntry.endsWith('EndEqual')) {
                    queryWrapper.le(mEntry.substring(0,mEntry.length() - 8),conditionMap.get(mEntry));
                } else if (mEntry.endsWith('Like')) {
                    queryWrapper.likePlus(mEntry.substring(0,mEntry.length() - 4),conditionMap.get(mEntry));
                } else if (mEntry.endsWith('LikeLeft')) {
                    queryWrapper.likeLeft(mEntry.substring(0,mEntry.length() - 8),conditionMap.get(mEntry));
                } else if (mEntry.endsWith('LikeRight')) {
                    queryWrapper.likeRight(mEntry.substring(0,mEntry.length() - 9),conditionMap.get(mEntry));
                } else if (mEntry.endsWith('IsNull')) {
                    queryWrapper.isNull(mEntry.substring(0,mEntry.length() - 6));
                } else if (mEntry.endsWith('IsNotNull')) {
                    queryWrapper.isNotNull(mEntry.substring(0,mEntry.length() - 9));
                } else if (mEntry.endsWith('In')) {
                    if (mEntry.endsWith('NotIn')) {
                        queryWrapper.notIn(mEntry.substring(0,mEntry.length() - 5), ((String)conditionMap.get(mEntry)).split(','));
                    } else {
                        queryWrapper.inPlus(mEntry.substring(0,mEntry.length() - 2), ((String)conditionMap.get(mEntry)).split(','));
                    }
                } else if (mEntry.endsWith('EqualDate')) {
                    if (mEntry.endsWith('NotEqualDate')) {
                        queryWrapper.ne(mEntry.substring(0, mEntry.length() - 12), DateTime.newInstance(Long.valueOf(String.valueOf(conditionMap.get(mEntry)))));
                    } else {
                        queryWrapper.eq(mEntry.substring(0, mEntry.length() - 9), DateTime.newInstance(Long.valueOf(String.valueOf(conditionMap.get(mEntry)))));
                    }
                } else if (mEntry.endsWith('BeginDate')) {
                    queryWrapper.gt(mEntry.substring(0,mEntry.length() - 9),DateTime.newInstance(Long.valueOf(String.valueOf(conditionMap.get(mEntry)))));
                } else if (mEntry.endsWith('BeginEqualDate')) {
                    queryWrapper.ge(mEntry.substring(0,mEntry.length() - 14),DateTime.newInstance(Long.valueOf(String.valueOf(conditionMap.get(mEntry)))));
                } else if (mEntry.endsWith('EndDate')) {
                    queryWrapper.lt(mEntry.substring(0,mEntry.length() - 7),DateTime.newInstance(Long.valueOf(String.valueOf(conditionMap.get(mEntry)))));
                } else if (mEntry.endsWith('EndEqualDate')) {
                    queryWrapper.le(mEntry.substring(0,mEntry.length() - 12),DateTime.newInstance(Long.valueOf(String.valueOf(conditionMap.get(mEntry)))));
                } else if (mEntry.endsWith('InDate')) {
                    String s = (String)conditionMap.get(mEntry);
                    List<String> sas = s.split(',');
                    for(String sa : sas) {
                        if (mEntry.endsWith('NotInDate')) {
                           // queryWrapper.notIn(mEntry.substring(0,mEntry.length() - 9), DateTime.newInstance(Long.valueOf(String.valueOf(sa))));
                        } else {
                           // queryWrapper.inPlus(mEntry.substring(0,mEntry.length() - 6), DateTime.newInstance(Long.valueOf(String.valueOf(sa))));
                        }
                    }
                }
            }

        }
        return queryWrapper;
    }

        /**
     * 编辑查询条件
     * @param  page             HttpServletRequest
     * @return Map<String, Object> 检索条件Map
     */
    public PagePlus getPage(Integer page, Integer limits) {
        return page != null && limits != null ? new PagePlus(page, limits) : null;
    }
}