购物网站11:产品Service---品牌---产品信息---产品样式---产品类型---产品搜索---查询结果回调
2009-08-31 22:46
731 查看
@Service
@Transactional
public class BrandServiceBean extends DaoSupport<Brand> implements BrandService {
@Override
public void save(Object entity) {
((Brand)entity).setCode(UUID.randomUUID().toString());
super.save(entity);
}
}
----------------------------------------------------------------
@Service
@Transactional
public class ProductInfoServiceBean extends DaoSupport<ProductInfo> implements ProductInfoService {
@Resource(name="productTypeServiceBean") private ProductTypeService productTypeService;
@SuppressWarnings("unchecked")
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public List<ProductInfo> getViewHistory(Integer[] productids, int maxResult){
StringBuffer jpql = new StringBuffer();
for(int i=0 ;i<productids.length; i++){
jpql.append('?').append(i).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("select o from ProductInfo o where o.id in("+ jpql.toString()+")");
for(int i=0 ;i<productids.length; i++){
query.setParameter(i, productids[i]);
}
query.setFirstResult(0).setMaxResults(maxResult);
return query.getResultList();
}
@SuppressWarnings("unchecked")
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public List<ProductInfo> getTopSell(Integer typeid, int maxResult){
List<Integer> typeids = new ArrayList<Integer>();
typeids.add(typeid);
getTypeids(typeids, new Integer[]{typeid});
StringBuffer n = new StringBuffer();
for(int i=0; i<typeids.size();i++){
n.append('?').append((i+2)).append(',');
}
n.deleteCharAt(n.length()-1);
Query query = em.createQuery("select o from ProductInfo o where o.commend=?1 and o.type.typeid in("+ n.toString()+") order by o.sellcount desc");
query.setParameter(1, true);
for(int i=0; i<typeids.size();i++){
query.setParameter(i+2, typeids.get(i));
}
query.setFirstResult(0).setMaxResults(maxResult);
return query.getResultList();
}
private void getTypeids(List<Integer> outtypeids, Integer[] typeids){
List<Integer> subtypeids = productTypeService.getSubTypeid(typeids);
if(subtypeids!=null && subtypeids.size()>0){
outtypeids.addAll(subtypeids);
Integer[] ids = new Integer[subtypeids.size()];
for(int i=0;i<subtypeids.size();i++){
ids[i]=subtypeids.get(i);
}
getTypeids(outtypeids, ids);
}
}
@SuppressWarnings("unchecked")
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public List<Brand> getBrandsByProductTypeid(Integer[] typeids){
if(typeids!=null && typeids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0;i<typeids.length;i++){
jpql.append('?').append((i+1)).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("select o from Brand o where o.code in(select p.brand.code from ProductInfo p where p.type.typeid in("+ jpql.toString()+") group by p.brand.code)");
for(int i=0;i<typeids.length;i++){
query.setParameter(i+1, typeids[i]);
}
return query.getResultList();
}
return null;
}
public void setCommendStatu(Integer[] productids, boolean statu) {
if(productids!=null && productids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0;i<productids.length;i++){
jpql.append('?').append((i+2)).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("update ProductInfo o set o.commend=?1 where o.id in("+ jpql.toString()+ ")");
query.setParameter(1, statu);
for(int i=0;i<productids.length;i++){
query.setParameter(i+2, productids[i]);
}
query.executeUpdate();
}
}
public void setVisibleStatu(Integer[] productids, boolean statu) {
if(productids!=null && productids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0;i<productids.length;i++){
jpql.append('?').append((i+2)).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("update ProductInfo o set o.visible=?1 where o.id in("+ jpql.toString()+ ")");
query.setParameter(1, statu);
for(int i=0;i<productids.length;i++){
query.setParameter(i+2, productids[i]);
}
query.executeUpdate();
}
}
}
-------------------------------------------------------------------
@Service
public class ProductSearchBean implements ProductSearch {
private CompassTemplate compassTemplate;
@Resource
public void setCompass(Compass compass){
compassTemplate = new CompassTemplate(compass);
}
public QueryResult<ProductInfo> query(String key, int firstResult, int maxResult) {
return compassTemplate.execute(new QueryCallback(key, firstResult, maxResult));
}
}
-------------------------------------------------------------------
@Service
@Transactional
public class ProductStyleServiceBean extends DaoSupport<ProductStyle> implements ProductStyleService {
public void setVisibleStatu(Integer[] productstyleids, boolean statu) {
if(productstyleids!=null && productstyleids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0;i<productstyleids.length;i++){
jpql.append('?').append((i+2)).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("update ProductStyle o set o.visible=?1 where o.id in("+ jpql.toString()+ ")");
query.setParameter(1, statu);
for(int i=0;i<productstyleids.length;i++){
query.setParameter(i+2, productstyleids[i]);
}
query.executeUpdate();
}
}
}
----------------------------------------------------------------------------
@Service
@Transactional
public class ProductTypeServiceBean extends DaoSupport<ProductType> implements ProductTypeService {
@Override
public void delete(Serializable ... entityids) {
if(entityids!=null && entityids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0 ;i<entityids.length;i++){
jpql.append("?").append(i+2).append(",");
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("update ProductType o set o.visible=?1 where o.typeid in("+ jpql.toString()+")")
.setParameter(1, false);
for(int i=0 ;i<entityids.length;i++){
query.setParameter(i+2, entityids[i]);
}
query.executeUpdate();
}
}
@SuppressWarnings("unchecked")
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public List<Integer> getSubTypeid(Integer[] parentids){
if(parentids!=null && parentids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0; i<parentids.length; i++){
jpql.append('?').append((i+1)).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("select o.typeid from ProductType o where o.parent.typeid in("+ jpql.toString()+ ")");
for(int i=0; i<parentids.length; i++){
query.setParameter(i+1, parentids[i]);
}
return query.getResultList();
}
return null;
}
}
-----------------------------------------------------------------------------
public class QueryCallback implements CompassCallback<QueryResult<ProductInfo>> {
private String key;
private int firstResult;
private int maxResult;
public QueryCallback(String key, int firstResult, int maxResult) {
this.key = key;
this.firstResult = firstResult;
this.maxResult = maxResult;
}
public QueryResult<ProductInfo> doInCompass(CompassSession session) throws CompassException {
CompassHits hits = session.find(key);
CompassQueryBuilder queryBuilder = session.queryBuilder();
/*
* 查询产品类别等于12,并且任意索引属性匹配查询关键词的记录,记录按销售价降序排列
CompassHits queryhits = queryBuilder.bool().addMust(queryBuilder.spanEq("typeid", 12))
.addMust(queryBuilder.queryString(key).toQuery())
.toQuery().addSort("sellprice", SortPropertyType.FLOAT, SortDirection.REVERSE)
.hits();
*/
QueryResult<ProductInfo> qr = new QueryResult<ProductInfo>();
qr.setTotalrecord(hits.length());//得到匹配记录的总数 1
int length = firstResult+ maxResult;
if(length>hits.length()) length = hits.length();
List<ProductInfo> products = new ArrayList<ProductInfo>();
for(int i=firstResult; i<length; i++){
ProductInfo product = (ProductInfo)hits.data(i);
if(hits.highlighter(i).fragment("productName")!=null){//处理高亮显示
product.setName(hits.highlighter(i).fragment("productName"));
}
if(hits.highlighter(i).fragment("description")!=null){//处理高亮显示
product.setDescription(hits.highlighter(i).fragment("description"));
}
products.add(product);
}
qr.setResultlist(products);
return qr;
}
}
@Transactional
public class BrandServiceBean extends DaoSupport<Brand> implements BrandService {
@Override
public void save(Object entity) {
((Brand)entity).setCode(UUID.randomUUID().toString());
super.save(entity);
}
}
----------------------------------------------------------------
@Service
@Transactional
public class ProductInfoServiceBean extends DaoSupport<ProductInfo> implements ProductInfoService {
@Resource(name="productTypeServiceBean") private ProductTypeService productTypeService;
@SuppressWarnings("unchecked")
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public List<ProductInfo> getViewHistory(Integer[] productids, int maxResult){
StringBuffer jpql = new StringBuffer();
for(int i=0 ;i<productids.length; i++){
jpql.append('?').append(i).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("select o from ProductInfo o where o.id in("+ jpql.toString()+")");
for(int i=0 ;i<productids.length; i++){
query.setParameter(i, productids[i]);
}
query.setFirstResult(0).setMaxResults(maxResult);
return query.getResultList();
}
@SuppressWarnings("unchecked")
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public List<ProductInfo> getTopSell(Integer typeid, int maxResult){
List<Integer> typeids = new ArrayList<Integer>();
typeids.add(typeid);
getTypeids(typeids, new Integer[]{typeid});
StringBuffer n = new StringBuffer();
for(int i=0; i<typeids.size();i++){
n.append('?').append((i+2)).append(',');
}
n.deleteCharAt(n.length()-1);
Query query = em.createQuery("select o from ProductInfo o where o.commend=?1 and o.type.typeid in("+ n.toString()+") order by o.sellcount desc");
query.setParameter(1, true);
for(int i=0; i<typeids.size();i++){
query.setParameter(i+2, typeids.get(i));
}
query.setFirstResult(0).setMaxResults(maxResult);
return query.getResultList();
}
private void getTypeids(List<Integer> outtypeids, Integer[] typeids){
List<Integer> subtypeids = productTypeService.getSubTypeid(typeids);
if(subtypeids!=null && subtypeids.size()>0){
outtypeids.addAll(subtypeids);
Integer[] ids = new Integer[subtypeids.size()];
for(int i=0;i<subtypeids.size();i++){
ids[i]=subtypeids.get(i);
}
getTypeids(outtypeids, ids);
}
}
@SuppressWarnings("unchecked")
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public List<Brand> getBrandsByProductTypeid(Integer[] typeids){
if(typeids!=null && typeids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0;i<typeids.length;i++){
jpql.append('?').append((i+1)).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("select o from Brand o where o.code in(select p.brand.code from ProductInfo p where p.type.typeid in("+ jpql.toString()+") group by p.brand.code)");
for(int i=0;i<typeids.length;i++){
query.setParameter(i+1, typeids[i]);
}
return query.getResultList();
}
return null;
}
public void setCommendStatu(Integer[] productids, boolean statu) {
if(productids!=null && productids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0;i<productids.length;i++){
jpql.append('?').append((i+2)).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("update ProductInfo o set o.commend=?1 where o.id in("+ jpql.toString()+ ")");
query.setParameter(1, statu);
for(int i=0;i<productids.length;i++){
query.setParameter(i+2, productids[i]);
}
query.executeUpdate();
}
}
public void setVisibleStatu(Integer[] productids, boolean statu) {
if(productids!=null && productids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0;i<productids.length;i++){
jpql.append('?').append((i+2)).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("update ProductInfo o set o.visible=?1 where o.id in("+ jpql.toString()+ ")");
query.setParameter(1, statu);
for(int i=0;i<productids.length;i++){
query.setParameter(i+2, productids[i]);
}
query.executeUpdate();
}
}
}
-------------------------------------------------------------------
@Service
public class ProductSearchBean implements ProductSearch {
private CompassTemplate compassTemplate;
@Resource
public void setCompass(Compass compass){
compassTemplate = new CompassTemplate(compass);
}
public QueryResult<ProductInfo> query(String key, int firstResult, int maxResult) {
return compassTemplate.execute(new QueryCallback(key, firstResult, maxResult));
}
}
-------------------------------------------------------------------
@Service
@Transactional
public class ProductStyleServiceBean extends DaoSupport<ProductStyle> implements ProductStyleService {
public void setVisibleStatu(Integer[] productstyleids, boolean statu) {
if(productstyleids!=null && productstyleids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0;i<productstyleids.length;i++){
jpql.append('?').append((i+2)).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("update ProductStyle o set o.visible=?1 where o.id in("+ jpql.toString()+ ")");
query.setParameter(1, statu);
for(int i=0;i<productstyleids.length;i++){
query.setParameter(i+2, productstyleids[i]);
}
query.executeUpdate();
}
}
}
----------------------------------------------------------------------------
@Service
@Transactional
public class ProductTypeServiceBean extends DaoSupport<ProductType> implements ProductTypeService {
@Override
public void delete(Serializable ... entityids) {
if(entityids!=null && entityids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0 ;i<entityids.length;i++){
jpql.append("?").append(i+2).append(",");
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("update ProductType o set o.visible=?1 where o.typeid in("+ jpql.toString()+")")
.setParameter(1, false);
for(int i=0 ;i<entityids.length;i++){
query.setParameter(i+2, entityids[i]);
}
query.executeUpdate();
}
}
@SuppressWarnings("unchecked")
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public List<Integer> getSubTypeid(Integer[] parentids){
if(parentids!=null && parentids.length>0){
StringBuffer jpql = new StringBuffer();
for(int i=0; i<parentids.length; i++){
jpql.append('?').append((i+1)).append(',');
}
jpql.deleteCharAt(jpql.length()-1);
Query query = em.createQuery("select o.typeid from ProductType o where o.parent.typeid in("+ jpql.toString()+ ")");
for(int i=0; i<parentids.length; i++){
query.setParameter(i+1, parentids[i]);
}
return query.getResultList();
}
return null;
}
}
-----------------------------------------------------------------------------
public class QueryCallback implements CompassCallback<QueryResult<ProductInfo>> {
private String key;
private int firstResult;
private int maxResult;
public QueryCallback(String key, int firstResult, int maxResult) {
this.key = key;
this.firstResult = firstResult;
this.maxResult = maxResult;
}
public QueryResult<ProductInfo> doInCompass(CompassSession session) throws CompassException {
CompassHits hits = session.find(key);
CompassQueryBuilder queryBuilder = session.queryBuilder();
/*
* 查询产品类别等于12,并且任意索引属性匹配查询关键词的记录,记录按销售价降序排列
CompassHits queryhits = queryBuilder.bool().addMust(queryBuilder.spanEq("typeid", 12))
.addMust(queryBuilder.queryString(key).toQuery())
.toQuery().addSort("sellprice", SortPropertyType.FLOAT, SortDirection.REVERSE)
.hits();
*/
QueryResult<ProductInfo> qr = new QueryResult<ProductInfo>();
qr.setTotalrecord(hits.length());//得到匹配记录的总数 1
int length = firstResult+ maxResult;
if(length>hits.length()) length = hits.length();
List<ProductInfo> products = new ArrayList<ProductInfo>();
for(int i=firstResult; i<length; i++){
ProductInfo product = (ProductInfo)hits.data(i);
if(hits.highlighter(i).fragment("productName")!=null){//处理高亮显示
product.setName(hits.highlighter(i).fragment("productName"));
}
if(hits.highlighter(i).fragment("description")!=null){//处理高亮显示
product.setDescription(hits.highlighter(i).fragment("description"));
}
products.add(product);
}
qr.setResultlist(products);
return qr;
}
}
相关文章推荐
- 购物网站5:产品设计--品牌----产品信息---产品样式---产品类型----性别
- 购物网站17-2:产品action---产品查询----产品样式列表----产品样式管理-----产品控制---产品类型列表----产品类型管理----浏览商品
- 购物网站25:FORM----产品----品牌----前台产品----后台产品----产品查询----产品类型
- 谷歌在搜索结果中加入品牌 改变产品搜索策略
- 分页查询产品信息,第六步;封装结果
- Python实现抓取百度搜索结果页的网站标题信息
- Python实现抓取百度搜索结果页的网站标题信息
- 2012CSDN网站六大类职位火热招聘:社区编辑、产品交互设计、信息安全主管、前端工程师、Ruby工程师、搜索工程师
- 如何从谷歌搜索结果中删除含有用户个人隐私信息的其他网站网页
- 根据查询的关键字,实现获取百度指定页数的搜索结果的信息(网页地址,标题,摘要,并有排序的说明)
- 百度搜索结果显示网站图标,凸显网站品牌和商标效应?
- 2012CSDN网站六大类职位火热招聘:社区编辑、产品交互设计、信息安全主管、前端工程师、Ruby工程师、搜索工程师 (已结束)
- 购物网站17-1:产品action---品牌列表---品牌管理---生成产品静态页面---前台产品管理----产品列表----产品管理
- 项目调试之供求网站信息开发----实现网页中搜索匹配查询功能
- 牛腩购物32:完成整个网站的功能制作(后台产品列表,多表查询+分页),产品修改保存,图片的上传保存
- 搜霸天下首推查询国外网站信息搜索导航
- 如何在Google搜索结果中显示网站的作者信息
- 阿里物联网套件-服务端SDK学习实践(基础篇-4查询产品类型信息)
- 各大招聘网站信息实时查询浏览
- oracle中查询表的信息,包括表名,字段名,字段类型,主键,外键唯一性约束信息