自在修仙0.1,返利

master
grimm 2024-08-29 11:31:08 +08:00
parent 66e48a1f92
commit 4b935f2106
2 changed files with 24 additions and 21 deletions

View File

@ -102,16 +102,17 @@ public class ItemSendController {
LOGGER.info("免费返利,直接返回"); LOGGER.info("免费返利,直接返回");
return true; return true;
} }
String roleid = params.get("roleid");
String nonce = params.get("nonce");
String orderId = params.get("sendid"); 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) { if (cPayOrder != null) {
LOGGER.error("订单已存在订单ID{}", orderId); LOGGER.error("订单已存在订单ID{}", orderId);
return false; return false;
} }
String roleid = params.get("roleid");
String nonce = params.get("nonce");
CPayOrder payOrder = new CPayOrder(); CPayOrder payOrder = new CPayOrder();
payOrder.setOrderId(orderId); payOrder.setOrderId(orderId);
payOrder.setUserId(roleid); payOrder.setUserId(roleid);
@ -123,7 +124,7 @@ public class ItemSendController {
payOrder.setCc_id("0"); payOrder.setCc_id("0");
payOrder.setPlatform("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); // cuserDao.addCpayOrder(payOrder);
return true; return true;
} }

View File

@ -3,7 +3,6 @@ package com.jmfy.util;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.jmfy.redisProperties.RedisProperties; import com.jmfy.redisProperties.RedisProperties;
import com.jmfy.redisProperties.RedisUserKey; import com.jmfy.redisProperties.RedisUserKey;
import com.jmfy.server.ServerProperties;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.RedisConnectionFailureException;
@ -290,6 +289,8 @@ public class RedisUtil {
delObject(type, key); delObject(type, key);
} }
} }
/** /**
* MaphashKey * MaphashKey
* *
@ -325,16 +326,13 @@ public class RedisUtil {
* @param key * @param key
* @return * @return
*/ */
public <T> Map<String, T> getMap(String key, Class<T> clazz,int expireTime) { public <T> Map<String, T> getMap(String type, String key, Class<T> clazz) {
try { try {
Map<String, T> reslut = new HashMap<>(); Map<String, T> reslut = new HashMap<>();
Map<Object, Object> map = redisObjectTemplate.opsForHash().entries(key); Map<Object, Object> map = redisObjectTemplate.opsForHash().entries(type+ ":" +key);
for (Map.Entry<Object, Object> entry : map.entrySet()) { for (Map.Entry<Object, Object> entry : map.entrySet()) {
reslut.put((String) entry.getKey(), gson.fromJson((String) entry.getValue(), clazz)); reslut.put((String) entry.getKey(), gson.fromJson((String) entry.getValue(), clazz));
} }
if(expireTime > 0){
redisObjectTemplate.expire(key, expireTime, TimeUnit.SECONDS);
}
return reslut; return reslut;
} catch (RedisConnectionFailureException e) { } catch (RedisConnectionFailureException e) {
LOGGER.error("------------------Redis 连接失败------------------"); LOGGER.error("------------------Redis 连接失败------------------");
@ -349,15 +347,12 @@ public class RedisUtil {
* @param mapKey * @param mapKey
* @return * @return
*/ */
public <T> T getMapValue(String type, String key, String mapKey, Class<T> clazz, int expireTime) { public <T> T getMapValue(String type, String key, String mapKey, Class<T> clazz) {
try { try {
String valueStr = (String) redisObjectTemplate.opsForHash().get(type+key, mapKey); String valueStr = (String) redisObjectTemplate.opsForHash().get(type+ ":" +key, mapKey);
if (valueStr == null) { if (valueStr == null) {
return null; return null;
} }
// if(expireTime > 0){
// redisObjectTemplate.expire(getKey(type, key), expireTime, TimeUnit.SECONDS);
// }
return gson.fromJson(valueStr, clazz); return gson.fromJson(valueStr, clazz);
} catch (RedisConnectionFailureException e) { } catch (RedisConnectionFailureException e) {
e.printStackTrace(); e.printStackTrace();
@ -372,21 +367,28 @@ public class RedisUtil {
* @param key * @param key
* @param value * @param value
*/ */
public <T> void putMap(String type, String key, Map<String, T> value, int expireTime) { public <T> void putMap(String type, String key, Map<String, T> value) {
try { try {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
for (Map.Entry<String, T> entry : value.entrySet()) { for (Map.Entry<String, T> entry : value.entrySet()) {
String valueStr = gson.toJson(entry.getValue()); String valueStr = gson.toJson(entry.getValue());
map.put(entry.getKey(), valueStr); map.put(entry.getKey(), valueStr);
} }
redisObjectTemplate.opsForHash().putAll(type+key, map); redisObjectTemplate.opsForHash().putAll(type+ ":" +key, map);
// if (expireTime > 0) {
// redisObjectTemplate.expire(getKey(type, key), expireTime, TimeUnit.SECONDS);
// }
} catch (RedisConnectionFailureException e) { } catch (RedisConnectionFailureException e) {
e.printStackTrace(); e.printStackTrace();
LOGGER.error("------------------Redis 连接失败------------------"); LOGGER.error("------------------Redis 连接失败------------------");
delObject(type, key); delObject(type, key);
} }
} }
public <T> 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);
}
}
} }