/**
* 根据搜索条件查询商品(带缓存)
*/
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. 实验报告(五)&第七周学习总结

    实验目的 理解抽象类与接口的使用: 了解包的作用,掌握包的设计方法. 实验要求 掌握使用抽象类的方法. 掌握使用系统接口的技术和创建自定义接口的方法. 了解 Java 系统包的结构. 掌握创建自定义包 ...

  2. JS实现上传图片的三种方法并实现预览图片功能

    地址:http://www.jb51.net/article/118660.htm js HTML5拖拽图片预览 地址:http://www.jb51.net/article/88803.htm js ...

  3. 监控工具 zxbbix

    报错 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server throug ...

  4. C++中的面向对象(二)

    1,类之间的基本关系: 1,继承: 1,从已存在类细分出来的类和原类之间具有继承关系(is-a): 1,子类就是一个(is-a)父类: 2,继承是单向的: 2,继承的类(子类)拥有原类(父类)的所有属 ...

  5. python学习第三天-元组、列表及字典

    元组 # 元组() 关键字:tuple# 元组的值一旦确定,不可更改,包括增.删.改都不行# 1.元组只有一个数据时,加逗号在后面,不然就不是元组类型的数据tuple_1 = ("hello ...

  6. PTA 紧急救援 /// dijkstra 最短路数 输出路径

    题目大意: 给定 n m s t :表示n个点编号为0~n-1 m条边 起点s终点t 接下来一行给定n个数:表示第i个点的救援队数量 接下来m行给定u v w:表示点u到点v有一条长度为w的边 求从s ...

  7. NOIP后一波总结

    我的山寨较为可靠分数为305(洛谷是真的水~显然不能用啊,果断换了一组合适的数据) 据大神们估计,得奖的分数在280, 我肯定是没有啥希望了.(我旁边的lxy同学从初二开始,每次以超分数线至少60分的 ...

  8. redis与mysql一致性方案解析

    一 前言 首先,缓存由于其高并发和高性能的特性,已经在项目中被广泛使用.在读取缓存方面,大家没啥疑问,都是按照下图的流程来进行业务操作 但是在更新缓存方面,对于更新完数据库,是更新缓存呢,还是删除缓存 ...

  9. mysql数据库的水平分表与垂直分表实例讲解

    mysql语句的优化有局限性,mysql语句的优化都是围绕着索引去优化的,那么如果mysql中的索引也解决不了海量数据查询慢的状况,那么有了水平分表与垂直分表的出现(我就是记录一下自己的理解) 水平分 ...

  10. 如何通过命令行编写调试第一个C++程序(UNIX)

    1.文件保存以.cc,.cpp等结尾: 2.bash窗口调试命令:cc prog1.cc,编译器生成可执行问价,Unix系统中为a.out,windows中一般以filename.exe; 3.(1) ...