From 1e53e5f28c55ece70b28c752fa318e2fd951e643 Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期三, 20 三月 2019 16:33:51 +0800
Subject: [PATCH] taobao 下dao改造以及删除dao

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/TaoBaoCouponServiceImpl.java |  154 ++++++++++-----------------------------------------
 1 files changed, 30 insertions(+), 124 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/TaoBaoCouponServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/TaoBaoCouponServiceImpl.java
index f27cd7a..99273e1 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/TaoBaoCouponServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/TaoBaoCouponServiceImpl.java
@@ -1,6 +1,5 @@
 package com.yeshi.fanli.service.impl.goods;
 
-import java.io.Serializable;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -9,17 +8,13 @@
 
 import javax.annotation.Resource;
 
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
 import org.springframework.cache.annotation.Cacheable;
-import org.springframework.orm.hibernate4.HibernateCallback;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
-import com.yeshi.fanli.dao.taobao.TaoBaoCouponDao;
+import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoCouponMapper;
 import com.yeshi.fanli.entity.taobao.PidUser;
 import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
 import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
@@ -37,7 +32,7 @@
 public class TaoBaoCouponServiceImpl implements TaoBaoCouponService {
 
 	@Resource
-	private TaoBaoCouponDao taoBaoCouponDao;
+	private TaoBaoCouponMapper taoBaoCouponMapper;
 
 	@Resource
 	private TaoBaoUnionConfigService taoBaoUnionConfigService;
@@ -46,6 +41,7 @@
 	private RedisManager redisManager;
 
 	@Transactional
+	@Override
 	public void updateTaoBaoCoupon() {
 		List<TaoBaoUnionConfig> config = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
 
@@ -66,144 +62,54 @@
 		int ii = 0;
 		for (TaoBaoCoupon taoBaoCoupon : list) {
 			if (ii == 0) {
-				minId = (Long) taoBaoCouponDao.save(taoBaoCoupon);
+				taoBaoCouponMapper.insert(taoBaoCoupon);
+				minId = taoBaoCoupon.getId();
 			} else {
-				taoBaoCouponDao.save(taoBaoCoupon);
+				taoBaoCouponMapper.insert(taoBaoCoupon);
 			}
 			ii++;
 		}
-
-		final long endId = minId;
-		taoBaoCouponDao.excute(new HibernateCallback() {
-
-			public Object doInHibernate(Session session) throws HibernateException {
-				Query query = session.createSQLQuery("delete from yeshi_ec_taobao_coupon where id < ? ");
-				query.setParameter(0, endId);
-				return query.executeUpdate();
-			}
-		});
+		
+		taoBaoCouponMapper.deleteBeforeCouponInfo(minId);
 	}
 
+	@Override
 	public List<TaoBaoCoupon> getTaoBaoCouponList(String key, int page) {
-		int start = (page - 1) * Constant.PAGE_SIZE;
-		List<TaoBaoCoupon> list = taoBaoCouponDao.list(
-				"from TaoBaoCoupon tbc where tbc.title like ? order by tbc.orderby,tbc.id ", start, Constant.PAGE_SIZE,
-				new Serializable[] { "%" + key + "%" });
-		return list;
+		return taoBaoCouponMapper.getTaoBaoCouponList((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, key);
 	}
 
+	@Override
 	public int getCount(String key) {
-		Long count = taoBaoCouponDao.getCount("select count(*) from TaoBaoCoupon tbc where tbc.title like ? ",
-				new Serializable[] { "%" + key + "%" });
-		return count.intValue();
+		return taoBaoCouponMapper.getCount(key);
 	}
 
-	public void deleteTaoBaoCoupons(long[] ids) {
-		for (long id : ids) {
-			taoBaoCouponDao.delete(new TaoBaoCoupon(id));
-		}
-	}
-
-	public TaoBaoCoupon getaoBaoCoupon(long id) {
-		TaoBaoCoupon find = taoBaoCouponDao.find(TaoBaoCoupon.class, id);
-		return find;
-	}
-
-	@Transactional
-	public void updatetaoBaoCoupon(TaoBaoCoupon find) {
-		taoBaoCouponDao.update(find);
-	}
-
-	public List<TaoBaoCoupon> getTaoBaoCouponListByClassKeys(String[] keys, int page) {
-		int start = (page - 1) * Constant.PAGE_SIZE;
-		StringBuffer sb = new StringBuffer("from TaoBaoCoupon tbc where tbc.classNames like ? ");
-		int keyCount = keys.length;
-		for (int i = 0; i < keyCount; i++) {
-			if (i != 0) {
-				sb.append(" or tbc.classNames like ? ");
-			}
-			keys[i] = "%" + keys[i] + "%";
-		}
-		sb.append(" order by tbc.biz30day desc ");
-		List<TaoBaoCoupon> list = taoBaoCouponDao.list(sb.toString(), start, Constant.PAGE_SIZE, keys);
-		// if(list.size() > 0){
-		// String proportion =
-		// hongBaoManageService.get(Constant.HONGBAO_GOODS_PROPORTION);
-		// double pd=Double.parseDouble(proportion)/100;
-		// for (TaoBaoCoupon taoBaoCoupon : list) {
-		// double tk = (taoBaoCoupon.getTkRate()/100) * pd;
-		// BigDecimal zkPrice = taoBaoCoupon.getZkPrice();
-		// BigDecimal hb = BigDecimalUtil.mul2(zkPrice, new BigDecimal(tk));
-		// taoBaoCoupon.setHongbao(hb);
-		// }
-		// }
-		return list;
-
-	}
-
+	@Override
 	public List<TaoBaoCoupon> getTaoBaoCouponListBykeys(List<String> searchKeys, int page) {
 
 		if (searchKeys == null || searchKeys.size() == 0) {
 			searchKeys = new ArrayList<String>();
 			searchKeys.add("");
 		}
-
-		StringBuffer sb = new StringBuffer("from TaoBaoCoupon tbc where ");
-		int ii = 0;
-		for (String key : searchKeys) {
-			key = key.replaceAll(" ", "%");
-			if (ii == 0) {
-				sb.append("( tbc.title like '%" + key + "%' ");
-			} else {
-				sb.append(" or tbc.title like '%" + key + "%' ");
-			}
-			ii++;
-		}
-		sb.append(") and tbc.showType = 3 ");
-		// sb.append(" order by tbc.biz30day desc ");
-		int start = (page - 1) * Constant.PAGE_SIZE;
-		return taoBaoCouponDao.list(sb.toString(), start, Constant.PAGE_SIZE, new Serializable[] {});
+		
+		return taoBaoCouponMapper.getTaoBaoCouponListBykeys((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE,searchKeys);
 	}
-
-	public TaoBaoCoupon getTaoBaoCouponByActionId(String id) {
-		List<TaoBaoCoupon> list = taoBaoCouponDao.list("from TaoBaoCoupon tbc where tbc.auctionId = ? ",
-				new Serializable[] { id });
-		if (list.size() > 0) {
-			return list.get(0);
-		}
-		return null;
-	}
-
-	public int getCount(List<String> searchKeys) {
-
-		if (searchKeys == null || searchKeys.size() == 0) {
-			return 0;
-		}
-
-		StringBuffer sb = new StringBuffer();
-		sb.append("select count(tbc.id) from TaoBaoCoupon tbc where ");
-		int ii = 0;
-		for (String key : searchKeys) {
-			key = key.replaceAll(" ", "%");
-			if (ii == 0) {
-				sb.append("( tbc.title like '%" + key + "%' ");
-			} else {
-				sb.append(" or tbc.title like '%" + key + "%' ");
-			}
-			ii++;
-		}
-		sb.append(") and tbc.showType = 3 ");
-		Long count = taoBaoCouponDao.getCount(sb.toString());
-		return count.intValue();
-	}
-
+	
 	@Override
-	public TaoBaoCoupon getTaoBaoCouponByAuctionId(long id) {
-		List<TaoBaoCoupon> findList = taoBaoCouponDao.list("from TaoBaoCoupon coupon where coupon.auctionId=" + id);
-		if (findList != null && findList.size() > 0)
-			return findList.get(0);
-		return null;
+	public int getCount(List<String> searchKeys) {
+		if (searchKeys == null || searchKeys.size() == 0) {
+			searchKeys = new ArrayList<String>();
+			searchKeys.add("");
+		}
+		
+		return taoBaoCouponMapper.countTaoBaoCouponListBykeys(searchKeys);
 	}
+	
+	
+	@Override
+	public TaoBaoCoupon getTaoBaoCouponByActionId(String auctionId) {
+		return taoBaoCouponMapper.getTaoBaoCouponByActionId(auctionId);
+	}
+
 
 	/**
 	 * 閲囩敤redis鍋氱紦瀛�

--
Gitblit v1.8.0