funUtil修改
This commit is contained in:
@@ -49,6 +49,8 @@ public class CallTableServiceImpl extends ServiceImpl<CallTableMapper, CallTable
|
|||||||
@Resource
|
@Resource
|
||||||
private ShopUserService shopUserService;
|
private ShopUserService shopUserService;
|
||||||
@Resource
|
@Resource
|
||||||
|
private FunUtil funUtil;
|
||||||
|
@Resource
|
||||||
private StringRedisTemplate stringRedisTemplate;
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
@Resource
|
@Resource
|
||||||
private ShopInfoService shopInfoService;
|
private ShopInfoService shopInfoService;
|
||||||
@@ -220,7 +222,7 @@ public class CallTableServiceImpl extends ServiceImpl<CallTableMapper, CallTable
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getCallNumber(Long shopId, CallTable callTable) {
|
private String getCallNumber(Long shopId, CallTable callTable) {
|
||||||
return FunUtil.runFunAndCheckKey(() -> {
|
return funUtil.runFunAndCheckKey(() -> {
|
||||||
String callNumKey = RedisCst.getTableCallNumKey(shopId, callTable.getId());
|
String callNumKey = RedisCst.getTableCallNumKey(shopId, callTable.getId());
|
||||||
String value = stringRedisTemplate.opsForValue().get(callNumKey);
|
String value = stringRedisTemplate.opsForValue().get(callNumKey);
|
||||||
AtomicReference<String> newVal = new AtomicReference<>("");
|
AtomicReference<String> newVal = new AtomicReference<>("");
|
||||||
@@ -244,7 +246,7 @@ public class CallTableServiceImpl extends ServiceImpl<CallTableMapper, CallTable
|
|||||||
stringRedisTemplate.opsForValue().set(callNumKey, value);
|
stringRedisTemplate.opsForValue().set(callNumKey, value);
|
||||||
return callTable.getPrefix() + value;
|
return callTable.getPrefix() + value;
|
||||||
}
|
}
|
||||||
}, stringRedisTemplate, RedisCst.getLockKey("UPDATE_TABLE", shopId, callTable.getId()));
|
}, RedisCst.getLockKey("UPDATE_TABLE", shopId, callTable.getId()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import java.util.Calendar;
|
|||||||
@Service
|
@Service
|
||||||
public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrderStatisticMapper, ShopTableOrderStatistic> implements ShopTableOrderStatisticService{
|
public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrderStatisticMapper, ShopTableOrderStatistic> implements ShopTableOrderStatisticService{
|
||||||
@Resource
|
@Resource
|
||||||
private StringRedisTemplate redisTemplate;
|
private FunUtil funUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<ShopTableOrderStatistic> summary(Long shopId, String startTime, String endTime) {
|
public Page<ShopTableOrderStatistic> summary(Long shopId, String startTime, String endTime) {
|
||||||
@@ -39,7 +39,7 @@ public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrd
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addInfo(long shopId, long tableId, long count, BigDecimal amount) {
|
public boolean addInfo(long shopId, long tableId, long count, BigDecimal amount) {
|
||||||
return FunUtil.runFunAndCheckKey(() -> {
|
return funUtil.runFunAndCheckKey(() -> {
|
||||||
ShopTableOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getTableId, tableId)
|
ShopTableOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getTableId, tableId)
|
||||||
.eq(ShopTableOrderStatistic::getCreateDay, DateUtil.date().toDateStr()));
|
.eq(ShopTableOrderStatistic::getCreateDay, DateUtil.date().toDateStr()));
|
||||||
if (statistic == null) {
|
if (statistic == null) {
|
||||||
@@ -52,6 +52,6 @@ public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrd
|
|||||||
save(statistic);
|
save(statistic);
|
||||||
}
|
}
|
||||||
return mapper.incrInfo(shopId, tableId, count, amount, DateUtil.date().toDateStr());
|
return mapper.incrInfo(shopId, tableId, count, amount, DateUtil.date().toDateStr());
|
||||||
}, redisTemplate, RedisCst.getLockKey("add_table_order_statistic", shopId, tableId));
|
}, RedisCst.getLockKey("add_table_order_statistic", shopId, tableId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package com.czg.service.account.util;
|
package com.czg.service.account.util;
|
||||||
|
|
||||||
import com.czg.exception.ApiNotPrintException;
|
import com.czg.exception.ApiNotPrintException;
|
||||||
|
import com.czg.service.RedisService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -14,10 +18,13 @@ import java.util.function.Supplier;
|
|||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Component
|
||||||
public class FunUtil {
|
public class FunUtil {
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
public static int retryCount = 5;
|
public static int retryCount = 5;
|
||||||
|
|
||||||
public static<T> T runFunAndCheckKey(Supplier<T> supplier, StringRedisTemplate redisTemplate, String lockKey) {
|
public <T> T runFunAndCheckKey(Supplier<T> supplier, String lockKey) {
|
||||||
try{
|
try{
|
||||||
// 设置分布式锁
|
// 设置分布式锁
|
||||||
boolean lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, "1", 30, TimeUnit.MILLISECONDS));
|
boolean lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, "1", 30, TimeUnit.MILLISECONDS));
|
||||||
|
|||||||
Reference in New Issue
Block a user