1. 程式人生 > >hql 查詢 合並查詢根據不同條件的結果 並排序

hql 查詢 合並查詢根據不同條件的結果 並排序

ets nts actor transform spa onf out ren 紅色

 1 public List<?> getUntakedOrderList(Long userId, List statusList) {
 2         Session currentSession = this.getSessionFactory().getCurrentSession();
 3         String hql = "select orderInfo.orderStatus as orderStatus, orderInfo.orderTime as orderTime, areaRelationStart.areaCityName as startCityName, areaRelationStart.areaName as startAreaName, areaRelationEnd.areaCityName as endCityName, " +
 4
"areaRelationEnd.areaName as endAreaName,userAddressStart.addressLocation as startAddress,userAddressEnd.addressLocation as endAddress,orderInfo.orderId as orderId," + 5 "userAddressEnd.addressName as addressName,orderInfo.orderCommonNo as orderCommonNo " + 6 "from OrderInfo as orderInfo left outer join OrderInfoAppend as orderInfoAppend on orderInfo.orderId=orderInfoAppend.appendOrderId " + 7
"left join UserAddress as userAddressStart on orderInfo.orderSendAddId=userAddressStart.addressId " + 8 "left join UserAddress as userAddressEnd on orderInfo.orderReceiveAddId=userAddressEnd.addressId " + 9 "left join AreaRelation as areaRelationStart on areaRelationStart.areaCode=userAddressStart.addressCity " + 10
"left join AreaRelation as areaRelationEnd on areaRelationEnd.areaCode=userAddressEnd.addressCity" + 11 " where (orderInfoAppend.appendOrderId = null and orderInfo.orderUserId=(:userId) and orderInfo.orderStatus in (:statusList) " + 12 "and orderInfo.orderDeleted=false) or (orderInfo.orderUserId=(:userId) and orderInfo.orderStatus=(:orderStatus) and orderInfo.orderDeleted=false) order by orderInfo.orderTime desc "; 13 Query query = currentSession.createQuery(hql) 14 .setParameter("userId", userId) 15 .setParameterList("statusList", statusList) 16 .setParameter("orderStatus", 290) 17 .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); 18 return query.list(); 19 }

1.紅色部分為第一部分的條件,藍色部分為第二部分的條件

hql 查詢 合並查詢根據不同條件的結果 並排序