gpt4 book ai didi

java - hibernate 标准限制 :- how to fetch current and last month data

转载 作者:行者123 更新时间:2023-11-29 11:37:39 26 4
gpt4 key购买 nike

这是我从创建日期获取特定月份和年份数据的方法。

    @Override
public List getMonthlyOrdersSummary(LabOrderConditions labOrderConditions) {
Criteria criteria = getCurrentSession().createCriteria(LabOrder.class);

criteria.add(Restrictions.gt("orderNo", 0));
if (StringUtils.isNotBlank(labOrderConditions.getClientCode()))
criteria.add(Restrictions.eq("clientCode", labOrderConditions.getClientCode()));

if (labOrderConditions.getAccountCodesList() != null) {
criteria.add(Restrictions.in("practice.code", labOrderConditions.getAccountCodesList()));
}


if (StringUtils.isNotBlank(labOrderConditions.getClientsCodes())) {
if (labOrderConditions.getCallingPlace().equalsIgnoreCase("allClients")) {
List<String> items = Arrays.asList(labOrderConditions.getClientsCodes().split("\\s*,\\s*"));
criteria.add(Restrictions.in("clientCode", items));
}
}

criteria.add(Restrictions.sqlRestriction("YEAR(createdDate)=" + labOrderConditions.getYear()));
ProjectionList projectionList = Projections.projectionList();

if (labOrderConditions.getCallingPlace().equalsIgnoreCase("allClients")) {
projectionList.add(Projections.groupProperty("clientCode"), "clientCode");
}

projectionList.add(Projections.sqlGroupProjection("MONTHNAME(createdDate) as orderMonthName", "MONTHNAME(createdDate)",
new String[] { "orderMonthName" }, new Type[] { StandardBasicTypes.STRING }));
projectionList.add(Projections.sqlGroupProjection("Month(createdDate) as orderMonthNo", "Month(createdDate)", new String[] { "orderMonthNo" },
new Type[] { StandardBasicTypes.INTEGER }));

projectionList.add(Projections.rowCount());
criteria.setProjection(projectionList);
criteria.addOrder(org.hibernate.criterion.Order.asc("createdDate"));
return criteria.list();
}

那么如何编写当前和上个月的限制。

我只想要类似的东西 criteria.add(Restrictions.in("MONTHNAME(createdDate)", labOrderConditions.getCompareMonthList()));

如果有人有任何建议,请与我分享。

谢谢西坦苏

最佳答案

从 labOrderConditions.getCompareMonthList() 中,用 Java 创建相应的开始日期和结束日期对象,然后:

criteria.add(Restrictions.between("createdDate", startDate, endDate));

如果您有多个间隔,您还可以添加“或”限制。

这会解决您的问题吗?还是您期待其他结果?

关于java - hibernate 标准限制 :- how to fetch current and last month data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36327236/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com