/**
* 根据搜索条件查询商品(带缓存)
*/
public List<ResultInfo> getSearchGoodsList(GoodsTypeCondtionBizBean condition, QueryPage queryPage){
StringBuffer sb = new StringBuffer();
List<Object> paramList = new ArrayList<Object>();
sb.append(" from ResultInfo rt where rt.markDelete='N' and nvl(rt.isClose,'N') <>'Y' and rt.goodsHeadState= 'PUBLISHED' ");
if(condition != null){
if(condition.getGoodsTypeIds() != null && condition.getGoodsTypeIds().size()>0){
String pas = "";
for(int i=0;i<condition.getGoodsTypeIds().size();i++){
if(i == 0){
pas = pas + "?";
}else{
pas = pas + "," + "?";
}
paramList.add(condition.getGoodsTypeIds().get(i));
}
sb.append(" and rt.goodsTypeId in("+pas+") ");
}
if(condition.getBrandId()!=null){
sb.append(" and rt.goodsBrandId="+condition.getBrandId() );
}

if(!StringUtils.isEmpty(condition.getOrderby())){
//按价格排序
if(condition.getOrderby().equals("goodsHeadMalltPriceUp")){
sb.append(" order by goodsHeadMalltPrice desc ");
}
if(condition.getOrderby().equals("goodsHeadMalltPriceDown")){
sb.append(" order by goodsHeadMalltPrice asc ");
}
//新品(上线时间排序)
if(condition.getOrderby().equals("goodsCreateDate")){
sb.append(" order by goodsHeadOnLineDate desc ");
}
//按收藏量排序
if(condition.getOrderby().equals("collectNum")){
sb.append(" order by goodsHeadOnLineDate desc ");
}
//按销量排序
if(condition.getOrderby().equals("goodsHeadSellSum")){
sb.append(" order by goodsHeadSellSum desc ");
}
//按人气排序
if(condition.getOrderby().equals("popularity")){
sb.append(" order by goodsHeadOnLineDate desc ");
}
}
}
getHibernateTemplate().setCacheQueries(true);
if (queryPage != null) {
return super.findByHQL(queryPage, sb.toString(), paramList.toArray());
} else {
return super.findByHQL(sb.toString(), paramList.toArray());
}
}

/**
* 查询当前搜索的商品有哪些品牌
*/
public List<GoodsBrandBizBean> findGoodsBrands(GoodsTypeCondtionBizBean condition){

StringBuffer sb = new StringBuffer();
List<Object> paramList = new ArrayList<Object>();
if(condition.getParam()==null){
throw new ApplicationException("请传入参数");
}
sb.append("select brand.* from t_goods_brand brand join (select resultinfo0_.goods_brand_id ");
sb.append(" from T_GOODS_HEAD resultinfo0_ where resultinfo0_.MARK_DELETE = 'N' and nvl(resultinfo0_.IS_CLOSE, 'N') <> 'Y' ");
sb.append(" and resultinfo0_.GOODS_HEAD_STATE ='PUBLISHED' ");
if(condition.getGoodsTypeIds() != null && condition.getGoodsTypeIds().size()>0){
String pas = "";
for(int i=0;i<condition.getGoodsTypeIds().size();i++){
if(i == 0){
pas = pas + "?";
}else{
pas = pas + "," + "?";
}
paramList.add(condition.getGoodsTypeIds().get(i));
}
sb.append(" and resultinfo0_.GOODS_TYPE_ID in("+pas+") ");
}

sb.append(" group by resultinfo0_.goods_brand_id) goods on brand.goods_brand_id=goods.goods_brand_id ");
List<Object[]> list = new ArrayList<Object[]>();
list = super.findBySQL(sb.toString(), paramList.toArray());
List<GoodsBrandBizBean> rs=new ArrayList();
GoodsBrandBizBean resultBean = null;
for(Object[] object:list){
resultBean = new GoodsBrandBizBean();
if(object[0]!=null)
resultBean.setGoodsBrandId(Long.parseLong(object[0].toString()));
if(object[1]!=null)
resultBean.setGoodsBrandName(object[1].toString());

rs.add(resultBean);
}
return rs;
}
/**
* 查询当前搜索的商品有哪些 类别
*/
public List<GoodsTypeInfo> findGoodsSort(GoodsTypeCondtionBizBean condition){

StringBuffer sb = new StringBuffer();
List<Object> paramList = new ArrayList<Object>();
if(condition.getParam()==null){
throw new ApplicationException("请传入参数");
}
sb.append("from "+condition.getParam());

sb.append(" t where t.goodsTypeId ");
sb.append(" in (select rt.goodsTypeId");

sb.append(" from GoodsHeadInfo rt where rt.markDelete='N' and nvl(rt.isClose,'N') <>'Y' ");
sb.append(" and rt.goodsHeadState = 'PUBLISHED' ");
if(condition.getGoodsTypeIds() != null && condition.getGoodsTypeIds().size()>0){
String pas = "";
for(int i=0;i<condition.getGoodsTypeIds().size();i++){
if(i == 0){
pas = pas + "?";
}else{
pas = pas + "," + "?";
}
paramList.add(condition.getGoodsTypeIds().get(i));
}
sb.append(" and rt.goodsTypeId in("+pas+") ");
}

sb.append(" group by rt.goodsTypeId )");

getHibernateTemplate().setCacheQueries(true);
return super.findByHQL(sb.toString(), paramList.toArray());

}

/**
* 根据搜索条件查询商品(不带缓存)(类型ID)
*/
public List<ResultBean> getSearchTypeGoodsList(GoodsTypeCondtionBizBean condition, QueryPage queryPage){
StringBuffer sb = new StringBuffer();
List<Object> paramList = new ArrayList<Object>();
sb.append(" select * from ( ");
sb.append(" select distinct t1.GOODS_HEAD_ID, t1.GOODS_HEAD_MALLPRICE, ");
sb.append(" t1.GOODS_HEAD_TITLE,t1.GOODS_HEAD_LABEL ,t1.GOODS_HEAD_PRICETYPE,t1.GOODS_HEAD_MARKETPRICE,t1.GOODS_HEAD_SHORTNAME,t1.GOODS_HEAD_POINT,t1.GOODS_HEAD_POINTMALL ");
sb.append(" ,t1.GOODS_BRAND_NAME,t1.GOODS_CATEGORY_NAME,t1.GOODS_TYPE_NAME,t1.GOODS_TYPE_ID,t1.GOODS_HEAD_TYPE_DISPLAY,t1.GODDS_HEAD_KEYS2 ");
sb.append(" ,t1.GOODS_HEAD_NAME,t1.GOODS_HEAD_SELLSUM,t1.GOODS_COLLECT_NUM,t1.GOODS_POPULARITY,t1.GOODS_HEAD_ONLINEDATE,t1.supplier_head_id ");
sb.append(" from T_GOODS_HEAD t1 ");
// sb.append(" inner join T_GOODS_PICTURE t2 on t1.GOODS_HEAD_ID = t2.GOODS_HEAD_ID and t2.goods_picture_type = 'MAIN' ");
// sb.append(" inner join T_GOODS_PICRELATED t3 on t2.goods_picrelated_id = t3.goods_picrelated_id ");
if(condition != null){
//根据属性查找
if(condition.getMap() != null && condition.getMap().size()>0){
int i = 2;
for(Map.Entry<String, Object> entry : condition.getMap().entrySet()){
sb.append(" inner join t_goods_expandvalue t"+i+" on t"+i+".goods_head_id = t1.goods_head_id ");
sb.append(" and t"+i+".goods_expand_name = ? ");
paramList.add(entry.getKey());
sb.append(" and t"+i+".goods_expandvalue_value = ? ");
paramList.add(entry.getValue());
i++;
}
}
if(!StringUtils.isEmpty(condition.getShopSpecialType())){
//是否有满送优惠
if(condition.getShopSpecialType().equals("SHOP_FULL_SEND")){
sb.append(" join t_red_envelope_head reh on t1.supplier_head_id = reh.supplier_head_id ");
sb.append(" and reh.mark_delete = 'N' and reh.grant_type = 'RED_ENVELOPE_MERCHANT' and reh.state = 'RED_ENVELOPE_USING' and reh.start_use_date <= sysdate and reh.end_use_date >= sysdate ");
}
//是否优惠券优惠
else if(condition.getShopSpecialType().equals("SHOP_SEND_COUPON")){
sb.append(" join t_coupon_head tch on t1.supplier_head_id = tch.supplier_head_id ");
sb.append(" and tch.mark_delete = 'N' and tch.grant_type = 'COUPON_MERCHANT' and tch.state = 'COUPON_NOT_USING' and tch.start_use_date <= sysdate and tch.end_use_date >= sysdate ");
}
//是否红包优惠
else if(condition.getShopSpecialType().equals("SHOP_SEND_RED_ENVELOPE")){
sb.append(" join t_full_send_head fsh on t1.supplier_head_id = fsh.supplier_head_id ");
sb.append(" and fsh.mark_delete = 'N' and fsh.state = 'FULL_SEND_STATE_USING' and fsh.start_use_date <= sysdate and fsh.end_use_date >= sysdate ");
}
//是否限时特价优惠
else if(condition.getShopSpecialType().equals("SHOP_LIMIT_PRICE")){
sb.append(" join t_special_limited_head slh on t1.supplier_head_id = slh.supplier_head_id ");
sb.append(" and slh.mark_delete = 'N' ");
}
}
sb.append(" where 1=1 ");
if(condition.getGoodsTypeIds() != null && condition.getGoodsTypeIds().size()>0){
String pas = "";
for(int i=0;i<condition.getGoodsTypeIds().size();i++){
if(i == 0){
pas = pas + "?";
}else{
pas = pas + "," + "?";
}
paramList.add(condition.getGoodsTypeIds().get(i));
}
sb.append(" and t1.GOODS_TYPE_ID in("+pas+") ");
}
}
sb.append(" and t1.mark_delete = 'N' and t1.GOODS_HEAD_STATE ='PUBLISHED' and t1.GOODS_HEAD_FLAG ='Y' ");
if(condition != null){
if(!StringUtils.isEmpty(condition.getOrderby())){
//按价格排序
if(condition.getOrderby().equals("goodsHeadMalltPrice")){
sb.append(" order by t1.GOODS_HEAD_MALLPRICE desc ");
}
//新品(上线时间排序)
else if(condition.getOrderby().equals("goodsCreateDate")){
sb.append(" order by t1.GOODS_HEAD_ONLINEDATE desc ");
}
//按收藏量排序
else if(condition.getOrderby().equals("collectNum")){
sb.append(" order by t1.GOODS_COLLECT_NUM desc ");
}
//按销量排序
else if(condition.getOrderby().equals("goodsHeadSellSum")){
sb.append(" order by t1.GOODS_HEAD_SELLSUM desc ");
}
//按人气排序
else if(condition.getOrderby().equals("popularity")){
sb.append(" order by t1.GOODS_POPULARITY desc ");
}
else{
sb.append(" order by t1.goods_head_id desc ");
}
}
}
sb.append(" ) ");
List<Object[]> list = new ArrayList<Object[]>();
if (queryPage != null) {
list = super.findBySQLNotRemoveOrderBy(queryPage, sb.toString(), paramList.toArray());
} else {
list = super.findBySQL(sb.toString(), paramList.toArray());
}
List<ResultBean> goodsList = new ArrayList<ResultBean>();
ResultBean resultBean = null;
for(Object[] object:list){
resultBean = new ResultBean();
if(object[0]!=null)
resultBean.setGoodsHeadID(Long.parseLong(object[0].toString()));
if(object[1]!=null)
resultBean.setGoodsHeadMalltPrice(object[1].toString());
if(object[2]!=null)
resultBean.setGoodsHeadTitle(object[2].toString());
if(object[3]!=null)
resultBean.setGoodsHeadLabel(object[3].toString());
if(object[4]!=null)
resultBean.setGoodsHeadPriceType(object[4].toString());
if(object[5]!=null)
resultBean.setGoodsHeadMarketPrice(object[5].toString());
if(object[6]!=null)
resultBean.setGoodsHeadShortName(object[6].toString());
if(object[7]!=null)
resultBean.setGoodsHeadPoint(object[7].toString());
if(object[8]!=null)
resultBean.setGoodsHeadPointMall(object[8].toString());
if(object[9]!=null)
resultBean.setBrandName(object[9].toString());
if(object[10]!=null)
resultBean.setGoodsCategoryName(object[10].toString());
if(object[11]!=null)
resultBean.setGoodsTypeName(object[11].toString());
if(object[12]!=null)
resultBean.setGoodsTypeId(Long.parseLong(object[12].toString()));
if(object[13]!=null)
resultBean.setGoodsHeadTypeDisplay(object[13].toString());
if(object[14]!=null)
resultBean.setGoodsHeadKeys(object[14].toString());
if(object[15]!=null)
resultBean.setGoodsHeadName(object[15].toString());
if(object[16]!=null)
resultBean.setGoodsHeadSellSum(Long.valueOf(object[16].toString()));
if(object[17]!=null)
resultBean.setCollectNum(Long.valueOf(object[17].toString()));
if(object[18]!=null)
resultBean.setPopularity(Long.valueOf(object[18].toString()));
if(object[19]!=null)
resultBean.setGoodsCreateDate(object[19].toString());
if(object[20]!=null)
resultBean.setSupplierId(Long.valueOf(object[20].toString()));
goodsList.add(resultBean);
}
return goodsList;
}

hql例子的更多相关文章

  1. HQL查询

    HQL ,Hibernate Query Language ,是Hibernate查询语言,不直接操作数据表,而是操作实体类,根据实体类和对应数据表中的映射关系,查找数据. 下面是hql的基本步骤: ...

  2. com.apache.dc.query.Query所属包名apache-common-sid.jar

    com.apache.dc.query.Query所属包名apache-common-sid.jar 首先这个类是基于HQL的,好多方法里面要传String clzz, 刚开始我真不知道这个参数传什么 ...

  3. Hive优化策略

    hive优化目标 在有限的资源下,运行效率高. 常见问题 数据倾斜.Map数设置.Reduce数设置等 hive运行 查看运行计划 explain [extended] hql 例子 explain ...

  4. Hibernate中的HQL的基本常用小例子,单表查询与多表查询

    <span style="font-size:24px;color:#3366ff;">本文章实现HQL的以下功能:</span> /** * hql语法: ...

  5. Hibernate之HQL查询的一些例子

    Hibernate配备了一种非常强大的查询语言,就是HQL(hibernate query language),HQL看上去很像sql,但只是语法结构上相似,HQL是一种面向对象的查询,他可以理解继承 ...

  6. Hibernate之HQL添加过滤器查询的用法

    HQL查询过程中支持添加过滤器.使用步骤是这样的: 首先在要查询的实体对象的映射中使用<filter-def>标签配置过滤器,并在相对应的<class>标签中添加对应的< ...

  7. [NHibernate]HQL查询

    目录 写在前面 文档与系列文章 查询的几种方式 HQL查询 一个例子 总结 写在前面 上篇文章介绍了nhibernate在项目中的基本配置,包括数据库连接字符串的设置,映射文件的配置及需注意的地方,这 ...

  8. [转]hql 语法与详细解释

    HQL查询:Criteria查询对查询条件进行了面向对象封装,符合编程人员的思维方式,不过HQL(Hibernate Query Lanaguage)查询提供了更加丰富的和灵活的查询特性,因此 Hib ...

  9. 【Java EE 学习 48】【Hibernate学习第五天】【抓取策略】【二级缓存】【HQL】

    一.抓取策略. 1.hibernate中提供了三种抓取策略. (1)连接抓取(Join Fetch):这种抓取方式是默认的抓取方式.使用这种抓取方式hibernate会在select中内连接的方式获取 ...

随机推荐

  1. 【刷题笔记】LeetCode 48. Rotate Image

    题意 原地顺时针翻转一个 n*n 的矩阵 图解 下面例子中用 5*5 矩阵做示例,如下图,我们要把该矩阵顺时针翻转90度,并且不能使用另外的矩阵空间来暂存数据,而是原地改变矩阵中数值. 我的想法是这样 ...

  2. md5加密 和拉钩网的登录

    #使用requests模块 #1.登录lagou #2.登录人人,保存个人首页 import requests from urllib import parse #hashlib是MD5加密的一个py ...

  3. Python字符串前缀

    1,r/R表示raw string(原始字符串) #!/usr/bin/python str1 = 'hello \n world' str2 = r'hello \n world' print(st ...

  4. 63.Perfect Squares(完美平方数)

    Level:   Medium 题目描述: Given a positive integer n, find the least number of perfect square numbers (f ...

  5. LeetCode Linked List Medium 2. Add Two Numbers

    Description You are given two non-empty linked lists representing two non-negative integers. The dig ...

  6. Linux操作练习

    打印显示当前时间,格式是:20181209211008 [root@Centos7 ~]#date "+%Y%m%d%H%M%S" 实现晚上20:30自动关机 [root@Cent ...

  7. 【转】Git的安装与使用

    Git作为分布式的版本控制器有其独特的优势,可以不依赖与网络而进行版本控制,而SVN则必须有网才可以.今天咱们不讨论Git与SVN的具体区别.咱们先看看Git这个分布式版本控制器是怎么玩的.下面的内容 ...

  8. 写一个自定义类加载器demo

    public class MyTest16 extends ClassLoader { private String classLoaderName; private String fileExten ...

  9. 重磅 | 阿里云与MongoDB达成战略合作,成为全球唯一提供最新版MongoDB的云厂商

    MongoDB是业界最受欢迎的开源数据库之一,2019年一份面向开发者的数据库调查报告中,MongoDB以 24.6%的使用率占据次席. 阿里云是国内最早提供MongoDB服务的云厂商,提供完全兼容M ...

  10. css float 浮动

    CSS Float(浮动) 什么是 CSS Float(浮动)?大理石平台价格 CSS 的 Float(浮动),会使元素向左或向右移动,其周围的元素也会重新排列. Float(浮动),往往是用于图像, ...