/** * 这是新的获取TOP PRODUCTS的列表 2008-09-28 MODIFY BY CANNYMO * @param countForm * @param properties -属性项的KEY ,属性分类排行,价格、品牌地区也看作是一个属性 * @param values -属性项的值 * @return * @throws AppException */ public List searchTopProducts(VisitCountForm countForm,List properties,Map values) throws AppException { if (countForm == null) { throw new AppException("Null parameter is found in searchProductVisitCount function !"); } List list = null; int brandId = countForm.getBrandList(); int smalltypeId = countForm.getSmallList(); String smallTypes = countForm.getSmallTypes(); int recPerPage = countForm.getPageSize(); if (recPerPage <= 0) { recPerPage = PageUtil.getPageLines(); } initCountData(null); int ipicType = countForm.getPicType(); int iartpicCount = countForm.getArtpicCount();//图片数; boolean isAreaprice = false; //是否按地区报价 boolean isProperty = false; //是否按属性项 boolean hasProperty = false; StringBuffer propertyFilter = new StringBuffer(); for(int i=0;properties!=null && values!=null && i0 && hasProperty) { propertyFilter.append(" INTERSECT "); propertyFilter.append(tmp); } else if (tmp.length()>0) { propertyFilter.append(tmp); hasProperty = true; } } isProperty=propertyFilter.length()>0; boolean isRise=countForm.isRise(); //true:上升最快的 //added by huoqing begin boolean isQg = false; List priceValues = values!=null?(List)values.get("价格"):null; if(priceValues!=null){ String areaId = (String)priceValues.get(0); if(areaId.equals( "100" )){ isQg=true; } } //added by huoqing end String[] skipBrandIdArr = countForm.getSkipBrandIdArr(); String noBrandSql = null; Map skipBrandMap = null; if(skipBrandIdArr != null) { noBrandSql = " and a.type_id not in("; skipBrandMap = new HashMap(); for(int i = 0, l = skipBrandIdArr.length; i < l; i++) { if(i != 0) { noBrandSql += ","; } noBrandSql += ":brandid"+i; skipBrandMap.put("brandid"+i, skipBrandIdArr[i]); } noBrandSql += ") "; } try { String stmt = "select * from ( " + "select f.name as variance_name, a.*,(a.last_count_order-a.count_order) as rise_diff " + ",b.name as t_name,b.parent_id as t_parent_id,b.forum_dir,b.forum_id as t_forum_id,b.pub_url as t_pub_url,b.pub_dir " + (ipicType >= 0 ? " ,c.pic_path " : " ") + (isAreaprice&&!isQg ? " ,d.price as area_price " : " ") + (isAreaprice&&isQg ? " ,a.price as area_price " : " ") + (", nvl(e.min_price,0) as min_price, nvl(e.max_price,0) as max_price") + " from PDL_PRODUCT a, PDL_PRODUCT_TYPE b " + (ipicType >= 0 ? " ,(select * from PDL_PRODUCT_PIC where type= :ipicType) c " : " ") + (isProperty&&!isQg?",("+propertyFilter+") d":" ") + (",eml_price e ") + (",pdl_product_variance f") //添加条件 and a.concept is null 非概念产品 + " where a.status!=0 and a.review_status<>4 and a.order_type<2 and a.concept is null and a.type_id=b.id and b.status=1 and b.type=3 " + (isAreaprice&&isQg ? " and a.price BETWEEN :beginPrice AND :endPrice and a.price<>0 " : " ") + (isAreaprice&&!isQg ? " and d.price<>0 " : " ") + (isAreaprice ? " and a.hot_new not in(3,4) " : "") + " and b.parent_id" + (smallTypes!=null && smallTypes.trim().length()>0 ? " in ("+smallTypes+") " :"=:smalltypeId") + (brandId>0?" and a.type_id= :brandId":" ") + (iartpicCount>0 ? (" and a.artpic_count>= :iartpicCount") : " ") + (ipicType >= 0 ? " and c.product_id(+)=a.id " : " ") + (isProperty&&!isQg ? " and a.id=d.product_id " : " ") + (skipBrandIdArr != null ? noBrandSql : "") + (" and e.product_id(+)= a.id") + (" and a.variance_id=f.id(+) ") + " order by a.last_count_order asc" + ") where rownum <= :rownum" + (isRise ? " order by rise_diff asc " : " ") ; if (isRise){ stmt="select * from ("+stmt+") where rownum<= :recPerPage"; } //System.out.println("stmt ===== " + stmt); Map params = new HashMap(); params.put("ipicType", new Integer(ipicType)); params.put("smalltypeId", new Long(smalltypeId)); params.put("brandId", new Long(brandId)); params.put("iartpicCount", new Long(iartpicCount)); params.put("rownum", new Integer((isRise ? 100 : recPerPage))); params.put("recPerPage", new Integer(recPerPage)); if(isAreaprice&&!isQg){ params.put("areaId", (String)priceValues.get( 0 )); params.put("beginPrice", (String)priceValues.get( 1 )); params.put("endPrice", (String)priceValues.get( 2 )); } if(isAreaprice&&isQg){ params.put("beginPrice", (String)priceValues.get( 1 )); params.put("endPrice", (String)priceValues.get( 2 )); } if(skipBrandMap != null) { params.putAll(skipBrandMap); } //System.out.println("stmt================"+stmt); list = DBQueryUtils.psQuery(stmt, params); //System.out.println("list=====111==========="+list.size()); //list = DBQueryUtils.psQuery(stmt, params);// //System.out.println("list======2222=========="+list.size()); //list = BasePeer.executeQuery(stmt); //固定产品id by wind.ldr //固定形式 1_21345,3_232 指定位置固定 //固定形式 123,234 顺序固定 if(countForm.getFixedIds() != null && countForm.getFixedIds().length > 0){ int oldListSize = list.size(); boolean fixOrder = false; for(int i=0;i maxOrder){ maxOrder = forder; } orderMap.put(items[0], String.valueOf(items[1])); } } int order = 1; maxOrder = maxOrder < countForm.getFixedIds().length ? countForm.getFixedIds().length : maxOrder; maxOrder = maxOrder < list.size() ? order : list.size(); int notFixedOrderCnt = 0; for(int i=1;i<=maxOrder;i++){ if(orderMap.get(String.valueOf(i)) == null){ //找出一个非固定位置的 填补进去 while(notFixedOrderCnt < countForm.getFixedIds().length){ if(countForm.getFixedIds()[notFixedOrderCnt].indexOf("_") == -1){ orderMap.put(String.valueOf(i), countForm.getFixedIds()[notFixedOrderCnt]); break; } notFixedOrderCnt ++; } } } //去掉list中 的元素orderMap Collection orderIds = orderMap.values(); Map orderRecord = new HashMap();//pId -> Record for(Iterator iter = list.iterator();iter.hasNext();){ Record record = (Record)iter.next(); if(orderIds.contains(record.getValue("ID").asString())){ orderRecord.put(record.getValue("ID").asString(), record); iter.remove(); } } //补充orderRecord数据 StringBuffer needQueryIds = new StringBuffer(); for(Iterator iter = orderIds.iterator();iter.hasNext();){ String oId = (String)iter.next(); if(!orderRecord.keySet().contains(oId)){ if(needQueryIds.length() > 0){ needQueryIds.append(","); } needQueryIds.append(oId); } } if(needQueryIds.length() > 0){ //有id条件 没必要做优化了 stmt = "select * from ( " + "select f.name as variance_name, a.*,(a.last_count_order-a.count_order) as rise_diff " + ",b.name as t_name,b.parent_id as t_parent_id,b.forum_dir,b.forum_id as t_forum_id,b.pub_url as t_pub_url,b.pub_dir " + (ipicType >= 0 ? " ,c.pic_path " : " ") //+ (isAreaprice ? " ,d.price as area_price " : " ") + (", nvl(e.min_price,0) as min_price, nvl(e.max_price,0) as max_price") + " from PDL_PRODUCT a, PDL_PRODUCT_TYPE b " + (ipicType >= 0 ? " ,(select * from PDL_PRODUCT_PIC where type= " + ipicType + ") c " : " ") //+ (isProperty?",("+propertyFilter+") d":" ") + (",eml_price e ") + (",pdl_product_variance f") + " where a.id in("+needQueryIds.toString()+")"//加入读取id条件 + " and a.status!=0 and a.review_status<>4 and a.order_type<2 and a.concept is null and a.type_id=b.id and b.status=1 and b.type=3 " + " and b.parent_id" + (smallTypes!=null && smallTypes.trim().length()>0?" in ("+smallTypes+") " :"="+smalltypeId) + (brandId>0?" and a.type_id="+brandId:" ") + (iartpicCount>0 ? (" and a.artpic_count>="+iartpicCount) : " ") + (ipicType >= 0 ? " and c.product_id(+)=a.id " : " ") // + (isProperty ? " and a.id=d.product_id " : " ") + (" and e.product_id(+)= a.id") + (" and a.variance_id=f.id(+) ") + ")"; List needQueryList = BasePeer.executeQuery(stmt); for(int i=0;i