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 閱讀(517) 評論(0)  編輯  收藏 所屬分類: 示例代碼
          主站蜘蛛池模板: 宣城市| 黎城县| 漠河县| 吐鲁番市| 洛南县| 九寨沟县| 大埔县| 琼中| 德安县| 邯郸县| 丹东市| 浦城县| 石门县| 巴林左旗| 烟台市| 大英县| 普定县| 遂溪县| 延津县| 樟树市| 奉化市| 肃北| 商南县| 封开县| 介休市| 屯门区| 乌拉特前旗| 诸城市| 滁州市| 桦甸市| 华亭县| 巴楚县| 五河县| 南皮县| 湾仔区| 白城市| 资溪县| 大邑县| 盐源县| 前郭尔| 阳原县|