我需要将以下CRITERIA转换为HQL

时间:2019-05-23 05:20:02

标签: hibernate grails

我需要将条件更改为hql查询

def licenseSummaryList = LicenseSummary.createCriteria().list(max:params.max,offset:params.offset){
        log.info("param.max : " + params.max +"params.offset : " + params.offset)
        if (params.licenseLevel || params.classOfBusiness || params.businessUnit || params.portfolioMgrSurame || params.portfolioMgrFirstname) {
          createAlias('licenseDetails', 'ld', JoinType.LEFT_OUTER_JOIN)
          createAlias('ld.portfolioApprovalManager', 'pm', JoinType.LEFT_OUTER_JOIN)
          createAlias('ld.classOfBusiness', 'cb', JoinType.LEFT_OUTER_JOIN)
          createAlias('cb.businessUnit', 'bu', JoinType.LEFT_OUTER_JOIN)
          createAlias('cb.product', 'prod', JoinType.LEFT_OUTER_JOIN)
          createAlias('cb.classOfBusinessPortfolioApprovalManagers', 'cbpm', JoinType.LEFT_OUTER_JOIN)
          createAlias('cbpm.portfolioApprovalManager', 'cbpme', JoinType.LEFT_OUTER_JOIN)
          if (params.licenseLevel) eq('ld.licenseLevel', params.licenseLevel)
          if (params.classOfBusiness) {
            eq('cb.id', params.classOfBusiness.toLong())
          } else if (params.businessUnit) {
            eq('bu.id', params.businessUnit.toLong())
          }
          if (params.portfolioMgrSurame || params.portfolioMgrFirstname) {
            createAlias('pm.user', 'pme', JoinType.LEFT_OUTER_JOIN)
            if (params.portfolioMgrSurame) ilike('pme.lastName', '%' + params.portfolioMgrSurame + '%')
            if (params.portfolioMgrFirstname) ilike('pme.firstName', '%' + params.portfolioMgrFirstname + '%')
          }
        }
        if (params.underwriterFirstname || params.underwriterSurname || params.underwriterEmpNo || params.reportMgr) {
          createAlias('user', 'lse', JoinType.LEFT_OUTER_JOIN)
          if (params.underwriterSurname) ilike('lse.lastName', '%' + params.underwriterSurname + '%')
          if (params.underwriterFirstname) ilike('lse.firstName', '%' + params.underwriterFirstname + '%')
          if (params.underwriterEmpNo) eq('lse.id', params.underwriterEmpNo.toLong())
          if (params.reportMgr) ilike('lse.mgrName', '%' + params.reportMgr + '%')
        }
        if (params.authStartDate) le('authorityStartDate', parseDate(params.authStartDate))
        if (params.authEndDate) ge('authorityEndDate', parseDate(params.authEndDate))
        if (params.licenseStatus) eq('status', LicenseStatus.valueOf(params.licenseStatus))

        order('id', 'desc')
      }

0 个答案:

没有答案