jeecg自定义CriteriaQuery查询组装

@RequestMapping(params = "datagrid")
    public void datagrid(TbTendUserEntity tbTendUser, HttpServletRequest request, HttpServletResponse response,
            DataGrid dataGrid) {
        
        CriteriaQuery cq = new CriteriaQuery(TbTendUserEntity.class, dataGrid);
        // 查询条件组装器
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tbTendUser, request.getParameterMap());
        try {
            String sql1=" SELECT t.id,t.create_name createName,t.create_by createBy,t.create_date createDate, " + 
                    "t.update_name updateName,t.update_by updateBy,t.update_date updateDate,t.sys_org_code sysOrgCode, " + 
                    "t.sys_company_code sysCompanyCode,t.bpm_status bpmStatus,t.tend_user_id tendUserId,t.user_name userName, " + 
                    "t.pass_word passWord,t.begin_date beginDate,t.end_date endDate,t.id_card_num idCardNum,t.fingerprint_data fingerprintData, " + 
                    "t.photograph_data photographData,t.sex,t.age,t.duty,t.`status`,t.will1,t.will2,t.will3,t.user_real userReal, " + 
                    "t.schedule_status scheduleStatus,t.group_status groupStatus,t.domicile_location domicileLocation,t.work_location workLocation " + 
                    "FROM tb_tend_user t where 1=1 ";
            String sql2=" SELECT COUNT(1) FROM tb_tend_user t where 1=1 ";
            if(StringUtil.isNotEmpty(tbTendUser.getDomicileLocation())) {//户籍所在地过滤
                sql1+="and (domicile_location <> '"+tbTendUser.getDomicileLocation()+"' or domicile_location is null) ";
                sql2+="and (domicile_location <> '"+tbTendUser.getDomicileLocation()+"' or domicile_location is null) ";
            }
            if(StringUtil.isNotEmpty(tbTendUser.getWorkLocation())) {//工作地过滤
                sql1+="and (work_location <> '"+tbTendUser.getWorkLocation()+"' or work_location is null) ";
                sql2+="and (work_location <> '"+tbTendUser.getWorkLocation()+"' or work_location is null) ";
            }
            if(StringUtil.isNotEmpty(tbTendUser.getGroupStatus())) {//分组状态
                sql1+="and (group_status = '"+tbTendUser.getGroupStatus()+"' or group_status is null) ";
                sql2+="and (group_status = '"+tbTendUser.getGroupStatus()+"' or group_status is null) ";
            }
            if(StringUtil.isNotEmpty(tbTendUser.getUserReal())) {//姓名
                sql1+="and (user_real = '"+tbTendUser.getUserReal()+"') ";
                sql2+="and (user_real = '"+tbTendUser.getUserReal()+"') ";
            }
            /*获取总数,用于分页使用*/
            long countMwo = systemService.getCountForJdbc(sql2);
            /*转换为 int 整形*/
            int allCounts = (int)countMwo;
            
            int pageSize = cq.getPageSize();/*每页显示数*/
            int curPageNO = PagerUtil.getcurPageNo(allCounts, cq.getCurPage(),pageSize);/*当前页*/
            
            /*获取数据列表,参数一:查询的sql、参数二三:当前页码、数据总数*/
            List<Map<String, Object>> listMwo=systemService.findForJdbc(sql1, curPageNO, pageSize);
            
            cq.getDataGrid().setResults(listMwo);
            cq.getDataGrid().setTotal(allCounts);
            
        } catch (Exception e) {
            throw new BusinessException(e.getMessage());
        }
        TagUtil.datagrid(response, dataGrid);
    }
上一篇:数据结构导论之第三章(栈、队列、数组)


下一篇:jeecg随笔