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);
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM