mashiguang

小马快跑

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  20 随笔 :: 0 文章 :: 60 评论 :: 0 Trackbacks
package com.jl.dao.bookplatform.impl;

import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import org.springframework.dao.DataAccessException;

import com.jl.dao.baseDao.GenericDao;
import com.jl.dao.bookplatform.ProductItemDao;
import com.jl.entity.bookplatform.CrmProduct;
import com.jl.entity.bookplatform.CrmProductItem;
import com.jl.entity.bookplatform.ProductItemConfig;

public class ProductItemDaoImpl extends GenericDao<CrmProductItem, Long> implements ProductItemDao {

    
    
public List<ProductItemConfig> getProductItemConfigs(Long productId, Long planetypeId) throws DataAccessException{
        String sql 
= "select chi.charge_item_id \"chargeItemId\"," +
                
" chi.charge_item \"chargeItem\"," +
                
" chi.charge_unit \"chargeUnit\"," +
                
" cpi.product_id \"productId\"," +
                
" cpi.product_item_id \"productItemId\"," +
                
" cpi.sale_planetype_id \"salePlanetypeId\"," +
                
" cpi.inland_price \"inlandPrice\"," +
                
" cpi.outland_price \"outlandPrice\"" +
                
" from (select * from crm_charge_item chi2 where chi2.if_regular = 1) chi left join crm_product_item cpi" +
                
" on cpi.charge_item_id = chi.charge_item_id " +
                
" and cpi.product_id = ?" +
                
" and cpi.sale_planetype_id = ?" +
                
" order by chi.charge_item_id";
        
        Session session 
= getSession();
        Query query 
= session.createSQLQuery(sql)
            .addScalar(
"chargeItemId", Hibernate.LONG)
            .addScalar(
"chargeItem",Hibernate.STRING)
            .addScalar(
"chargeUnit",Hibernate.STRING)
            .addScalar(
"productId",Hibernate.LONG)
            .addScalar(
"productItemId",Hibernate.LONG)
            .addScalar(
"salePlanetypeId",Hibernate.LONG)
            .addScalar(
"inlandPrice",Hibernate.DOUBLE)
            .addScalar(
"outlandPrice",Hibernate.DOUBLE)
            .setResultTransformer(Transformers.aliasToBean(ProductItemConfig.
class))
            .setParameter(
0, productId)
            .setParameter(
1, planetypeId);
        
        List
<ProductItemConfig> configs = query.list();
        
        
return configs;
    }

    
public List<CrmProductItem> getProductItem(CrmProduct product) throws DataAccessException {
        
        String hql 
= "from CrmProductItem cpi where cpi.crmProduct = ?";
        Session session 
= getSession();
        Query query 
= session.createSQLQuery(hql).setParameter(0, product);
        
        List
<CrmProductItem> items = query.list();
        
return items;
    }
    
    
public void copy(Long productId_dest,Long productId_orig,String createMan) throws DataAccessException {
        String sql 
= "insert into crm_product_item " +
                
" select hibernate_sequence.nextval," +
                
" ?," +
                
" cpi.charge_item_id," +
                
" cpi.sale_planetype_id," +
                
" cpi.inland_price," +
                
" cpi.outland_price," +
                
" ?," +
                
" sysdate" +
                
" from crm_product_item cpi" +
                
" where cpi.product_id = ?";
        
        Session session 
= getSession();
        Query sqlQuery 
= session.createSQLQuery(sql)
                        .setParameter(
0, productId_dest)
                        .setParameter(
1, createMan)
                        .setParameter(
2, productId_orig);
        sqlQuery.executeUpdate();
    }
    
    
}
posted on 2011-08-11 22:25 mashiguang 阅读(500) 评论(0)  编辑  收藏 所属分类: 示例代码