From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 二月 2025 16:41:22 +0800
Subject: [PATCH] 淘宝转链接口更新

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/TaoBaoCouponServiceImpl.java |  412 ++++++++++++++++++++++------------------------------------
 1 files changed, 158 insertions(+), 254 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..4393ba2 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,254 +1,158 @@
-package com.yeshi.fanli.service.impl.goods;
-
-import java.io.Serializable;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
-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.entity.taobao.PidUser;
-import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
-import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
-import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
-import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
-import com.yeshi.fanli.service.inter.goods.TaoBaoCouponService;
-import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.RedisManager;
-import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.taobao.TaoBaoCouponUtil;
-import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
-
-@Service
-public class TaoBaoCouponServiceImpl implements TaoBaoCouponService {
-
-	@Resource
-	private TaoBaoCouponDao taoBaoCouponDao;
-
-	@Resource
-	private TaoBaoUnionConfigService taoBaoUnionConfigService;
-
-	@Resource
-	private RedisManager redisManager;
-
-	@Transactional
-	public void updateTaoBaoCoupon() {
-		List<TaoBaoUnionConfig> config = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
-
-		Set<TaoBaoCoupon> taoBaoCouponList = TaoBaoCouponUtil.getTaoBaoCouponList(config.get(0));
-		if (taoBaoCouponList == null) {
-			return;
-		}
-
-		List<TaoBaoCoupon> list = new ArrayList<>();
-		for (TaoBaoCoupon taoBaoCoupon : taoBaoCouponList) {
-			list.add(taoBaoCoupon);
-		}
-
-		// 闅忔満鎺掑簭
-		if (list != null)
-			Collections.shuffle(list);
-		long minId = 1;
-		int ii = 0;
-		for (TaoBaoCoupon taoBaoCoupon : list) {
-			if (ii == 0) {
-				minId = (Long) taoBaoCouponDao.save(taoBaoCoupon);
-			} else {
-				taoBaoCouponDao.save(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();
-			}
-		});
-	}
-
-	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;
-	}
-
-	public int getCount(String key) {
-		Long count = taoBaoCouponDao.getCount("select count(*) from TaoBaoCoupon tbc where tbc.title like ? ",
-				new Serializable[] { "%" + key + "%" });
-		return count.intValue();
-	}
-
-	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;
-
-	}
-
-	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[] {});
-	}
-
-	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;
-	}
-
-	/**
-	 * 閲囩敤redis鍋氱紦瀛�
-	 */
-	@Override
-	public List<TaoBaoGoodsBrief> getTaoBaoCouponList(int page) {
-		System.out.println("杩涘叆浜嗘柟娉�");
-		String key = "cachecoupon-" + page;
-		String resultStr = "";
-		try {
-			resultStr = redisManager.getCommonString(key);
-		} catch (Exception e) {
-		}
-
-		if (!StringUtil.isNullOrEmpty(resultStr)) {
-			Type type = new TypeToken<List<TaoBaoGoodsBrief>>() {
-			}.getType();
-			List<TaoBaoGoodsBrief> list = new Gson().fromJson(resultStr, type);
-			return list;
-		}
-
-		TaoBaoSearchResult result = TaoKeApiUtil.getMaterialByMaterialId(3756, page, 20);// searchCouple(null,
-																							// null,
-																							// page,
-																							// 20);
-		if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) {
-			// 20鍒嗛挓缂撳瓨
-			try {
-				redisManager.cacheCommonString(key, new Gson().toJson(result.getTaoBaoGoodsBriefs()), 60 * 20);
-			} catch (Exception e) {
-			}
-
-			return result.getTaoBaoGoodsBriefs();
-		}
-
-		return null;
-	}
-
-	@Cacheable(value = "taoBaoCouponCache", key = "'getTaoBaoCouponListByMeterialId'+#materialId+'-'+#page")
-	@Override
-	public List<TaoBaoGoodsBrief> getTaoBaoCouponListByMeterialId(int materialId, int page) {
-		TaoBaoSearchResult result = TaoKeApiUtil.getMaterialByMaterialId(materialId, page, 20);
-		if (result != null)
-			return result.getTaoBaoGoodsBriefs();
-		return null;
-	}
-
-}
+package com.yeshi.fanli.service.impl.goods;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import javax.annotation.Resource;
+
+import org.springframework.cache.annotation.Cacheable;
+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.mybatis.taobao.TaoBaoCouponMapper;
+import com.yeshi.fanli.entity.taobao.PidUser;
+import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
+import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
+import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
+import com.yeshi.fanli.service.inter.goods.TaoBaoCouponService;
+import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
+import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.RedisKeyEnum;
+import com.yeshi.fanli.util.RedisManager;
+import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.taobao.TaoBaoCouponUtil;
+import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
+
+@Service
+public class TaoBaoCouponServiceImpl implements TaoBaoCouponService {
+
+	@Resource
+	private TaoBaoCouponMapper taoBaoCouponMapper;
+
+	@Resource
+	private TaoBaoUnionConfigService taoBaoUnionConfigService;
+
+	@Resource
+	private RedisManager redisManager;
+
+	@Transactional
+	@Override
+	public void updateTaoBaoCoupon() {
+		List<TaoBaoUnionConfig> config = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
+
+		Set<TaoBaoCoupon> taoBaoCouponList = TaoBaoCouponUtil.getTaoBaoCouponList(config.get(0));
+		if (taoBaoCouponList == null) {
+			return;
+		}
+
+		List<TaoBaoCoupon> list = new ArrayList<>();
+		for (TaoBaoCoupon taoBaoCoupon : taoBaoCouponList) {
+			list.add(taoBaoCoupon);
+		}
+
+		// 闅忔満鎺掑簭
+		if (list != null)
+			Collections.shuffle(list);
+		long minId = 1;
+		int ii = 0;
+		for (TaoBaoCoupon taoBaoCoupon : list) {
+			if (ii == 0) {
+				taoBaoCouponMapper.insert(taoBaoCoupon);
+				minId = taoBaoCoupon.getId();
+			} else {
+				taoBaoCouponMapper.insert(taoBaoCoupon);
+			}
+			ii++;
+		}
+		
+		taoBaoCouponMapper.deleteBeforeCouponInfo(minId);
+	}
+
+	@Override
+	public List<TaoBaoCoupon> getTaoBaoCouponList(String key, int page) {
+		return taoBaoCouponMapper.getTaoBaoCouponList((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, key);
+	}
+
+	@Override
+	public int getCount(String key) {
+		return taoBaoCouponMapper.getCount(key);
+	}
+
+	@Override
+	public List<TaoBaoCoupon> getTaoBaoCouponListBykeys(List<String> searchKeys, int page) {
+
+		if (searchKeys != null && searchKeys.size() == 0) {
+			searchKeys = null;
+		}
+		
+		return taoBaoCouponMapper.getTaoBaoCouponListBykeys((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE,searchKeys);
+	}
+	
+	@Override
+	public int getCount(List<String> searchKeys) {
+		if (searchKeys != null && searchKeys.size() == 0) {
+			searchKeys = null;
+		}
+		return taoBaoCouponMapper.countTaoBaoCouponListBykeys(searchKeys);
+	}
+	
+	
+	@Override
+	public TaoBaoCoupon getTaoBaoCouponByActionId(String auctionId) {
+		return taoBaoCouponMapper.getTaoBaoCouponByActionId(auctionId);
+	}
+
+
+	/**
+	 * 閲囩敤redis鍋氱紦瀛�
+	 */
+	@Override
+	public List<TaoBaoGoodsBrief> getTaoBaoCouponList(int page) {
+		System.out.println("杩涘叆浜嗘柟娉�");
+		String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoCachecoupon, page +"");
+		String resultStr = "";
+		try {
+			resultStr = redisManager.getCommonString(key);
+		} catch (Exception e) {
+		}
+
+		if (!StringUtil.isNullOrEmpty(resultStr)) {
+			Type type = new TypeToken<List<TaoBaoGoodsBrief>>() {
+			}.getType();
+			List<TaoBaoGoodsBrief> list = new Gson().fromJson(resultStr, type);
+			return list;
+		}
+
+		TaoBaoSearchResult result = TaoKeApiUtil.getMaterialByMaterialId(3756, page, 20);// searchCouple(null,
+																							// null,
+																							// page,
+																							// 20);
+		if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) {
+			// 20鍒嗛挓缂撳瓨
+			try {
+				redisManager.cacheCommonString(key, new Gson().toJson(result.getTaoBaoGoodsBriefs()), 60 * 20);
+			} catch (Exception e) {
+			}
+
+			return result.getTaoBaoGoodsBriefs();
+		}
+
+		return null;
+	}
+
+	@Cacheable(value = "taoBaoCouponCache", key = "'getTaoBaoCouponListByMeterialId'+#materialId+'-'+#page")
+	@Override
+	public List<TaoBaoGoodsBrief> getTaoBaoCouponListByMeterialId(int materialId, int page) {
+		TaoBaoSearchResult result = TaoKeApiUtil.getMaterialByMaterialId(materialId, page, 20);
+		if (result != null)
+			return result.getTaoBaoGoodsBriefs();
+		return null;
+	}
+
+}

--
Gitblit v1.8.0