From 4b935f21063589f293c35450ffc50a8db7c35f87 Mon Sep 17 00:00:00 2001 From: grimm <1769111741@qq.com> Date: Thu, 29 Aug 2024 11:31:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=9C=A8=E4=BF=AE=E4=BB=990.1,?= =?UTF-8?q?=E8=BF=94=E5=88=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jmfy/controller/ItemSendController.java | 11 +++--- src/main/java/com/jmfy/util/RedisUtil.java | 34 ++++++++++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/jmfy/controller/ItemSendController.java b/src/main/java/com/jmfy/controller/ItemSendController.java index fc6bfe0..d2970a9 100644 --- a/src/main/java/com/jmfy/controller/ItemSendController.java +++ b/src/main/java/com/jmfy/controller/ItemSendController.java @@ -102,16 +102,17 @@ public class ItemSendController { LOGGER.info("免费返利,直接返回"); return true; } + + String roleid = params.get("roleid"); + String nonce = params.get("nonce"); String orderId = params.get("sendid"); - CPayOrder cPayOrder = cuserDao.getCpayOrderByOrderId(orderId); + + CPayOrder cPayOrder = RedisUtil.getInstence().getMapValue(RedisUserKey.REBATES_ORDER, roleid, orderId, CPayOrder.class); if (cPayOrder != null) { LOGGER.error("订单已存在,订单ID:{}", orderId); return false; } - String roleid = params.get("roleid"); - String nonce = params.get("nonce"); - CPayOrder payOrder = new CPayOrder(); payOrder.setOrderId(orderId); payOrder.setUserId(roleid); @@ -123,7 +124,7 @@ public class ItemSendController { payOrder.setCc_id("0"); payOrder.setPlatform("0"); - RedisUtil.getInstence().putMapEntry(RedisUserKey.REBATES_ORDER, roleid, orderId, payOrder, 0); + RedisUtil.getInstence().putMapValue(RedisUserKey.REBATES_ORDER, roleid, orderId, payOrder); // cuserDao.addCpayOrder(payOrder); return true; } diff --git a/src/main/java/com/jmfy/util/RedisUtil.java b/src/main/java/com/jmfy/util/RedisUtil.java index add118f..9cd808f 100644 --- a/src/main/java/com/jmfy/util/RedisUtil.java +++ b/src/main/java/com/jmfy/util/RedisUtil.java @@ -3,7 +3,6 @@ package com.jmfy.util; import com.google.gson.Gson; import com.jmfy.redisProperties.RedisProperties; import com.jmfy.redisProperties.RedisUserKey; -import com.jmfy.server.ServerProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.redis.RedisConnectionFailureException; @@ -290,6 +289,8 @@ public class RedisUtil { delObject(type, key); } } + + /** * 删除Map中某hashKey值 * @@ -325,16 +326,13 @@ public class RedisUtil { * @param key * @return */ - public Map getMap(String key, Class clazz,int expireTime) { + public Map getMap(String type, String key, Class clazz) { try { Map reslut = new HashMap<>(); - Map map = redisObjectTemplate.opsForHash().entries(key); + Map map = redisObjectTemplate.opsForHash().entries(type+ ":" +key); for (Map.Entry entry : map.entrySet()) { reslut.put((String) entry.getKey(), gson.fromJson((String) entry.getValue(), clazz)); } - if(expireTime > 0){ - redisObjectTemplate.expire(key, expireTime, TimeUnit.SECONDS); - } return reslut; } catch (RedisConnectionFailureException e) { LOGGER.error("------------------Redis 连接失败------------------"); @@ -349,15 +347,12 @@ public class RedisUtil { * @param mapKey * @return */ - public T getMapValue(String type, String key, String mapKey, Class clazz, int expireTime) { + public T getMapValue(String type, String key, String mapKey, Class clazz) { try { - String valueStr = (String) redisObjectTemplate.opsForHash().get(type+key, mapKey); + String valueStr = (String) redisObjectTemplate.opsForHash().get(type+ ":" +key, mapKey); if (valueStr == null) { return null; } -// if(expireTime > 0){ -// redisObjectTemplate.expire(getKey(type, key), expireTime, TimeUnit.SECONDS); -// } return gson.fromJson(valueStr, clazz); } catch (RedisConnectionFailureException e) { e.printStackTrace(); @@ -372,21 +367,28 @@ public class RedisUtil { * @param key * @param value */ - public void putMap(String type, String key, Map value, int expireTime) { + public void putMap(String type, String key, Map value) { try { Map map = new HashMap<>(); for (Map.Entry entry : value.entrySet()) { String valueStr = gson.toJson(entry.getValue()); map.put(entry.getKey(), valueStr); } - redisObjectTemplate.opsForHash().putAll(type+key, map); -// if (expireTime > 0) { -// redisObjectTemplate.expire(getKey(type, key), expireTime, TimeUnit.SECONDS); -// } + redisObjectTemplate.opsForHash().putAll(type+ ":" +key, map); } catch (RedisConnectionFailureException e) { e.printStackTrace(); LOGGER.error("------------------Redis 连接失败------------------"); delObject(type, key); } } + + public void putMapValue(String type, String key, String mapKey, T value) { + try { + String valueStr = gson.toJson(value); + redisObjectTemplate.opsForHash().put(type + ":" + key, mapKey, valueStr); + } catch (RedisConnectionFailureException e) { + LOGGER.error("------------------Redis 连接失败------------------"); + delObject(type, key); + } + } }