List of usage examples for org.hibernate.criterion Restrictions eq
public static SimpleExpression eq(String propertyName, Object value)
From source file:Almacen.formatosPedido.java
void formato() { h = new Herramientas(usr, 0); h.session(sessionPrograma);/*w w w . ja va 2 s . c om*/ Session session = HibernateUtil.getSessionFactory().openSession(); try { miAlmacen = (Almacen) session.get(Almacen.class, miAlmacen.getIdAlmacen()); DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); session.beginTransaction().begin(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); PDF reporte = new PDF(); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); Movimiento[] mov = (Movimiento[]) session.createCriteria(Movimiento.class) .add(Restrictions.eq("almacen.idAlmacen", miAlmacen.getIdAlmacen())).list() .toArray(new Movimiento[0]); Orden ord = null; OrdenExterna ordEx = null; if (mov.length > 0) { if (miAlmacen.getOperacion() == 1) ord = mov[0].getPartida().getOrdenByIdOrden(); /*if(miAlmacen.getOperacion()==2) ordEx=miAlmacen.getPedido().getOrdenExterna();*/ if (miAlmacen.getOperacion() == 3) ord = miAlmacen.getPedido().getOrden(); //ord=miAlmacen.getPedido().getPartida().getOrdenByIdOrden(); } File folder = new File("reportes"); folder.mkdirs(); reporte.Abrir(PageSize.LETTER, "Almacen", "reportes/" + valor + "-" + miAlmacen.getIdAlmacen() + "-almacen.pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float tam[]; PdfPTable tabla; if (miAlmacen.getOperacion() != 6) { tam = new float[] { 20, 20, 80, 190, 20, 30, 50, 50 }; tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT); } else { tam = new float[] { 20, 20, 80, 190, 20, 30 }; tabla = reporte.crearTabla(6, tam, 100, Element.ALIGN_LEFT); } cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); int ren = 0; double total = 0d; if (mov.length > 0) { int renglon = 0; for (int i = 0; i < mov.length; i++) { if (miAlmacen.getOperacion() == 1) { int r = i + 1; renglon++; tabla.addCell(reporte.celda("" + mov[i].getPartida().getIdEvaluacion(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("" + mov[i].getPartida().getSubPartida(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (mov[i].getPartida().getEjemplar() != null) tabla.addCell(reporte.celda("" + mov[i].getPartida().getEjemplar().getIdParte(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartida().getCatalogo().getNombre(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartida().getMed(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getPartida().getPcp()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); double sum = mov[i].getCantidad() * mov[i].getPartida().getPcp(); total += sum; tabla.addCell(reporte.celda(formatoPorcentaje.format(sum), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (ren == 20)//20 { reporte.writer.newPage(); reporte.agregaObjeto(tabla); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(tabla); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT); cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); ren = -1; renglon = 0; } ren++; } if (miAlmacen.getOperacion() == 2 || miAlmacen.getOperacion() == 6) { int r = i + 1; renglon++; tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (mov[i].getPartidaExterna().getNoParte() != null) tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getNoParte(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getDescripcion(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getUnidad(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (miAlmacen.getOperacion() == 2) { tabla.addCell( reporte.celda(formatoPorcentaje.format(mov[i].getPartidaExterna().getCosto()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); double sum = mov[i].getCantidad() * mov[i].getPartidaExterna().getCosto(); total += sum; tabla.addCell(reporte.celda(formatoPorcentaje.format(sum), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } if (ren == 20)//20 { reporte.writer.newPage(); reporte.agregaObjeto(tabla); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(tabla); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT); cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); ren = -1; renglon = 0; } ren++; } if (miAlmacen.getOperacion() == 3) { int r = i + 1; renglon++; //tabla.addCell(reporte.celda(""+miAlmacen.getPedido().getPartida().getIdEvaluacion(), font, contenido, izquierda, 0,1,Rectangle.RECTANGLE)); //tabla.addCell(reporte.celda(""+miAlmacen.getPedido().getPartida().getSubPartida(), font, contenido, derecha, 0,1,Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (mov[i].getPartidaExterna().getNoParte() != null) tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getNoParte(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //tabla.addCell(reporte.celda(miAlmacen.getPedido().getPartida().getCatalogo().getNombre()+"/"+mov[i].getPartidaExterna().getDescripcion(), font, contenido, izquierda, 0,1,Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getDescripcion(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getUnidad(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getPartidaExterna().getCosto()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); double sum = mov[i].getCantidad() * mov[i].getPartidaExterna().getCosto(); total += sum; tabla.addCell(reporte.celda(formatoPorcentaje.format(sum), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (ren == 20)//20 { reporte.writer.newPage(); reporte.agregaObjeto(tabla); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(tabla); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT); cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); ren = -1; renglon = 0; } ren++; } } for (renglon = renglon; renglon < 20; renglon++) { tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } } tabla.addCell(reporte.celda("Notas: ", font, contenido, izquierda, 0, 1, Rectangle.BOTTOM)); tabla.addCell(reporte.celda(miAlmacen.getNotas(), font, contenido, izquierda, tabla.getNumberOfColumns() - 1, 1, Rectangle.BOTTOM)); if (miAlmacen.getOperacion() != 6) { tabla.addCell(reporte.celda("", font, contenido, izquierda, 3, 1, Rectangle.NO_BORDER)); tabla.addCell(reporte.celda("Sub-total:", font, contenido, derecha, 4, 1, Rectangle.NO_BORDER)); tabla.addCell(reporte.celda(formatoPorcentaje.format(total), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("IVA:", font, contenido, derecha, 7, 1, Rectangle.NO_BORDER)); Configuracion con = (Configuracion) session.get(Configuracion.class, 1); double iva = total * con.getIva() / 100; tabla.addCell(reporte.celda(formatoPorcentaje.format(iva), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("Total:", font, contenido, derecha, 7, 1, Rectangle.NO_BORDER)); total += iva; tabla.addCell(reporte.celda(formatoPorcentaje.format(total), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda("", font, contenido, izquierda, 8, 1, Rectangle.NO_BORDER)); tabla.addCell(reporte.celda("", font, contenido, derecha, 8, 1, Rectangle.NO_BORDER)); tabla.addCell(reporte.celda("", font, contenido, derecha, 8, 1, Rectangle.RECTANGLE)); } session.beginTransaction().rollback(); reporte.agregaObjeto(tabla); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar("reportes/" + valor + "-" + miAlmacen.getIdAlmacen() + "-almacen.pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(null, "No se pudo realizar el reporte si el archivo esta abierto"); } if (session != null) if (session.isOpen()) session.close(); }
From source file:alpha.portal.dao.hibernate.AlphaCardDaoHibernate.java
License:Apache License
/** * List alpha cards by criterion./*from ww w . j a va 2 s .c om*/ * * @param caseId * the case id * @param criteriaArray * the criteria array * @return the list * @see alpha.portal.dao.AlphaCardDao#listAlphaCardsByCriterion(org.hibernate.criterion.Criterion) */ public List<AlphaCard> listAlphaCardsByCriterion(final String caseId, final Criterion... criteriaArray) { Session session; boolean sessionOwn = false; try { session = this.getSessionFactory().getCurrentSession(); } catch (final Exception e) { session = this.getSessionFactory().openSession(); sessionOwn = true; } // get newest sequenceNumber for each cardId final DetachedCriteria version = DetachedCriteria.forClass(AlphaCard.class, "cardVersion") .add(Property.forName("card.alphaCardIdentifier.cardId") .eqProperty("cardVersion.alphaCardIdentifier.cardId")) .setProjection( Projections.projectionList().add(Projections.max("alphaCardIdentifier.sequenceNumber"))); final Criteria crit = session.createCriteria(AlphaCard.class, "card"); for (final Criterion c : criteriaArray) { // Create the subquery (somehow we need to use the Descriptor or // else the subquery-JOIN is not done) final DetachedCriteria subcrit = DetachedCriteria.forClass(AlphaCardDescriptor.class, "crit"); // Join the adornments subcrit.createAlias("crit.adornmentList", "ad"); // Add adornment condition subcrit.add(c); // Map the subquery back to the outer query subcrit.add(Restrictions.eqProperty("card.alphaCardIdentifier", "crit.alphaCardIdentifier")); // Narrow down subquery or else we get a NullPointer-Exception subcrit.setProjection(Projections.property("crit.alphaCardIdentifier.cardId")); // Add this subquery to the outer query. crit.add(Subqueries.exists(subcrit)); } crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY) .add(Property.forName("alphaCardIdentifier.sequenceNumber").eq(version)) .createAlias("alphaCase", "case").add(Restrictions.eq("case.caseId", caseId)); List<AlphaCard> list = crit.list(); if (list.size() > 1) { final List<AlphaCard> order = (list.get(0)).getAlphaCase().getAlphaCards(); final List<AlphaCard> orderedList = new LinkedList<AlphaCard>(); for (final AlphaCard cc : order) { for (final AlphaCard c : list) { if (c.getAlphaCardIdentifier().equals(cc.getAlphaCardIdentifier())) { orderedList.add(c); break; } } } list = orderedList; } if (sessionOwn) { session.close(); } return list; }
From source file:alpha.portal.service.impl.AlphaCardManagerImpl.java
License:Apache License
/** * Returns a {@link Criterion} to get all Adornments with the given userId * as contributor./*from w w w. j a v a2s.c o m*/ * * @param userId * the users id * @return a {@link Criterion} */ public static Criterion getContributorCriterionOwn(final String userId) { return Restrictions.and(AlphaCardManagerImpl._CONTRIBUTOR, Restrictions.eq("ad.value", userId)); }
From source file:alpha.portal.service.impl.AlphaCardManagerImplTest.java
License:Apache License
/** * Test list alpha cards by criterion./*from w w w . java 2s. c om*/ */ @Test public void testListAlphaCardsByCriterion() { final String caseId = "123"; final Criterion crit = Restrictions.eq("gibtsnicht", ""); final List<AlphaCard> list = new LinkedList<AlphaCard>(); this.context.checking(new Expectations() { { this.one(AlphaCardManagerImplTest.this.dao).listAlphaCardsByCriterion( this.with(Expectations.equal(caseId)), this.with(Expectations.equal(new Criterion[] { crit }))); this.will(Expectations.returnValue(list)); } }); this.manager.listAlphaCardsByCriterion(caseId, crit); Assert.assertNull(this.manager.listAlphaCardsByCriterion(null, crit)); Assert.assertNull(this.manager.listAlphaCardsByCriterion("", crit)); }
From source file:alpha.portal.service.impl.AlphaCardManagerImplTest.java
License:Apache License
/** * Test criterion./*from w ww . j av a 2 s . co m*/ */ @Test public void testCriterion() { Assert.assertEquals( Restrictions.and(AlphaCardManagerImpl._CONTRIBUTOR, Restrictions.ne("ad.value", "123")).toString(), AlphaCardManagerImpl.getContributorCriterionOthers("123").toString()); Assert.assertEquals( Restrictions.and(AlphaCardManagerImpl._CONTRIBUTOR, Restrictions.eq("ad.value", "123")).toString(), AlphaCardManagerImpl.getContributorCriterionOwn("123").toString()); Assert.assertEquals( Restrictions.and(AlphaCardManagerImpl._CONTRIBUTORROLE, Restrictions.not(Restrictions.in("ad.value", new String[] { "role1" }))).toString(), AlphaCardManagerImpl.getContributorRoleCriterionOthers("role1").toString()); Assert.assertEquals( Restrictions.and(AlphaCardManagerImpl._CONTRIBUTORROLE, Restrictions.in("ad.value", new String[] { "role1" })).toString(), AlphaCardManagerImpl.getContributorRoleCriterionOwn("role1").toString()); }
From source file:analysers.MarketValueAnalyser.java
License:Open Source License
/** * Gets the date before or after./* www. j a v a 2 s . c om*/ * * @param company the company * @param date the date * @param dec_inc the dec_inc * @return the date before or after */ public MarketValue getDateBeforeOrAfter(Company company, Calendar date, int dec_inc) { MarketValue value; List<Criterion> cr; Calendar cal = Calendar.getInstance(); cal.setTime(date.getTime()); for (int count = 0; count < 10; count++) { //System.out.println("I am trying to fetch a value..."); cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR) + dec_inc); cr = new ArrayList<Criterion>(); cr.add(Restrictions.eq("company", company)); cr.add(Restrictions.eq("date", cal.getTime())); value = HibernateSupport.readOneObject(MarketValue.class, cr); if (value != null) { return value; } } return null; }
From source file:API.Login.java
@Path("Auth") @GET//from ww w. j ava2 s.com public void auth(@QueryParam("uname") String uname, @QueryParam("password") String pwd) { String path = ""; try { Session se = NewHibernateUtil.getSessionFactory().openSession(); Transaction t = se.beginTransaction(); Criteria cr = se.createCriteria(LoginTable.class); cr.add(Restrictions.eq("username", uname)); cr.add(Restrictions.eq("password", pwd)); ArrayList<LoginTable> al = (ArrayList<LoginTable>) cr.list(); if (al.size() > 0) { path = "index.html"; } else { String msg = "" + "Try Again"; path = "Login.jsp"; } t.commit(); } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:apm.common.service.DataService.java
License:Open Source License
/** * ?/* w ww. ja va 2 s . c om*/ * @param dc Hibernate * @param user ?UserUtils.getUser()?? * @param officeAlias ??dc.createAlias("office", "office"); * @param userAlias ??? * @return ? */ protected static Junction dataScopeFilter(User user, String officeAlias, String userAlias) { // ???? List<String> dataScope = Lists.newArrayList(); Junction junction = Restrictions.disjunction(); // ??? if (!user.isAdmin()) { for (Role r : user.getRoleList()) { String DATA_SCOPE = r.getDataScope(); if (!dataScope.contains(DATA_SCOPE) && StringUtils.isNotBlank(officeAlias)) { boolean isDataScopeAll = false; if (Role.DATA_SCOPE_ALL.equals(DATA_SCOPE)) { isDataScopeAll = true; } else if (Role.DATA_SCOPE_COMPANY_AND_CHILD.equals(DATA_SCOPE)) { //(?)?? junction.add(Restrictions.eq(officeAlias + ".id", user.getCompany().getId())); junction.add(Restrictions.like(officeAlias + ".parentIds", user.getCompany().getParentIds() + user.getCompany().getId() + ",%")); } else if (Role.DATA_SCOPE_COMPANY.equals(DATA_SCOPE)) { junction.add(Restrictions.eq(officeAlias + ".id", user.getCompany().getId())); junction.add(Restrictions.and( Restrictions.eq(officeAlias + ".parent.id", user.getCompany().getId()), Restrictions.eq(officeAlias + ".type", "2"))); // ? } else if (Role.DATA_SCOPE_OFFICE_AND_CHILD.equals(DATA_SCOPE)) { junction.add(Restrictions.eq(officeAlias + ".id", user.getOffice().getId())); junction.add(Restrictions.like(officeAlias + ".parentIds", user.getOffice().getParentIds() + user.getOffice().getId() + ",%")); } else if (Role.DATA_SCOPE_OFFICE.equals(DATA_SCOPE)) { junction.add(Restrictions.eq(officeAlias + ".id", user.getOffice().getId())); } else if (Role.DATA_SCOPE_CUSTOM.equals(DATA_SCOPE)) { junction.add(Restrictions.in(officeAlias + ".id", r.getOfficeIdList())); } //else if (Role.DATA_SCOPE_SELF.equals(DATA_SCOPE)){ if (!isDataScopeAll) { if (StringUtils.isNotBlank(userAlias)) { junction.add(Restrictions.eq(userAlias + ".id", user.getId())); } else { junction.add(Restrictions.isNull(officeAlias + ".id")); } } else { // ????? junction = Restrictions.disjunction(); break; } dataScope.add(DATA_SCOPE); } } } return junction; }
From source file:apm.modules.sys.service.DictService.java
License:Open Source License
public Page<Dict> find(Page<Dict> page, Dict dict) { DetachedCriteria dc = dao.createDetachedCriteria(); if (StringUtils.isNotEmpty(dict.getType())) { dc.add(Restrictions.eq("type", dict.getType())); }//from w w w . ja va 2s . co m if (StringUtils.isNotEmpty(dict.getDescription())) { dc.add(Restrictions.like("description", "%" + dict.getDescription() + "%")); } dc.add(Restrictions.eq(Dict.DEL_FLAG, Dict.DEL_FLAG_NORMAL)); dc.addOrder(Order.asc("type")).addOrder(Order.asc("sort")).addOrder(Order.desc("id")); return dao.find(page, dc); }
From source file:apm.modules.sys.service.LogService.java
License:Open Source License
public Page<Log> find(Page<Log> page, Map<String, Object> paramMap) { DetachedCriteria dc = dao.createDetachedCriteria(); String createById = ObjectUtils.toString(paramMap.get("createById")); if (StringUtils.isNotEmpty(createById)) { dc.add(Restrictions.eq("createBy.id", createById)); }//w ww .j a v a 2s .co m String uri = ObjectUtils.toString(paramMap.get("uri")); if (StringUtils.isNotBlank(uri)) { dc.add(Restrictions.like("uri", "%" + uri + "%")); } String exception = ObjectUtils.toString(paramMap.get("exception")); if (StringUtils.isNotBlank(exception)) { dc.add(Restrictions.eq("type", Log.TYPE_EXCEPTION)); } Date beginDate = DateUtils.parseDate(paramMap.get("beginDate")); if (beginDate == null) { beginDate = DateUtils.setDays(new Date(), 1); paramMap.put("beginDate", DateUtils.formatDate(beginDate, "yyyy-MM-dd")); } Date endDate = DateUtils.parseDate(paramMap.get("endDate")); if (endDate == null) { endDate = DateUtils.addDays(DateUtils.addMonths(beginDate, 1), -1); paramMap.put("endDate", DateUtils.formatDate(endDate, "yyyy-MM-dd")); } dc.add(Restrictions.between("createDate", beginDate, endDate)); dc.addOrder(Order.desc("createDate")); return dao.find(page, dc); }