购物网站11:产品Service---品牌---产品信息---产品样式---产品类型---产品搜索---查询结果回调
来源:互联网 发布:淘宝q币自动充值软件 编辑:程序博客网 时间:2024/05/03 22:08
@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;
}
}
- 购物网站11:产品Service---品牌---产品信息---产品样式---产品类型---产品搜索---查询结果回调
- 购物网站5:产品设计--品牌----产品信息---产品样式---产品类型----性别
- 购物网站25:FORM----产品----品牌----前台产品----后台产品----产品查询----产品类型
- 购物网站17-2:产品action---产品查询----产品样式列表----产品样式管理-----产品控制---产品类型列表----产品类型管理----浏览商品
- 购物网站17-1:产品action---品牌列表---品牌管理---生成产品静态页面---前台产品管理----产品列表----产品管理
- 产品
- 产品
- 产品
- 产品
- 产品
- 产品
- 产品
- 产品
- 分页查询产品信息,第五步:完成产品的分页显示
- 忘掉品牌回归产品
- 谷歌在搜索结果中加入品牌 改变产品搜索策略
- 仿购物网站产品放大镜效果
- 分页查询产品信息案例;第一步:创建产品页面,向服务器发送请求(获取所有产品信息)
- 普适计算技术的特点与发展趋势
- About Words and Deeds
- Displaying Interval of Time in JavaScript
- 购物网站10:权限Service---部门--员工--权限组---权限
- JFreeChart api file
- 购物网站11:产品Service---品牌---产品信息---产品样式---产品类型---产品搜索---查询结果回调
- asp.net页面间变量值传递的方法
- C#控件命名规范
- 购物网站12:文件上传Service---根据ID获取文件的真实路径
- 数据表中查询日期字段为空的记录并进行赋值的方法
- spring 对hessian支持
- 购物网站13:顾客/用户管理Service
- August,31 (R)
- 购物网站14:WEB action:系统初始化action