选择人数添加锁
This commit is contained in:
@@ -28,9 +28,7 @@ public class OrderController {
|
||||
private OrderService orderService;
|
||||
|
||||
@PutMapping("/updateVip")
|
||||
public ResponseEntity<Object> updateVip(
|
||||
@Validated @RequestBody UpdateVipDTO updateVipDTO
|
||||
) {
|
||||
public ResponseEntity<Object> updateVip(@Validated @RequestBody UpdateVipDTO updateVipDTO) {
|
||||
return ResponseEntity.ok(orderService.updateVip(updateVipDTO));
|
||||
}
|
||||
|
||||
@@ -38,12 +36,11 @@ public class OrderController {
|
||||
public Result createCart(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@Validated @RequestBody CartVo cartVo
|
||||
) {
|
||||
@Validated @RequestBody CartVo cartVo) {
|
||||
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
|
||||
String userId = jsonObject.getString("accountId");
|
||||
return orderService.createCart(cartVo.getMasterId(), cartVo.getProductId(), cartVo.getShopId(),
|
||||
cartVo.getSkuId(), cartVo.getNumber(), userId, clientType, cartVo.getCartId(), cartVo.getIsGift(),
|
||||
return orderService.createCart(cartVo.getMasterId(), cartVo.getProductId(), cartVo.getShopId(), cartVo.getSkuId(),
|
||||
cartVo.getNumber(), userId, clientType, cartVo.getCartId(), cartVo.getIsGift(),
|
||||
cartVo.getIsPack(), cartVo.getUuid(), cartVo.getType(), cartVo.getTableId());
|
||||
}
|
||||
|
||||
@@ -53,8 +50,7 @@ public class OrderController {
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam(value = "masterId", required = false) String masterId,
|
||||
@RequestParam(required = false) String tableId,
|
||||
@RequestParam("shopId") String shopId
|
||||
) {
|
||||
@RequestParam("shopId") String shopId) {
|
||||
if (tableId == null && StrUtil.isBlank(masterId)) {
|
||||
return Result.fail("masterId和tableId不能同时为空");
|
||||
}
|
||||
@@ -68,8 +64,7 @@ public class OrderController {
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam(required = false) String tableId,
|
||||
@RequestParam(value = "masterId", required = false) String masterId,
|
||||
@RequestParam("cartId") Integer cartId
|
||||
) {
|
||||
@RequestParam("cartId") Integer cartId) {
|
||||
return orderService.delCart(masterId, cartId);
|
||||
}
|
||||
|
||||
@@ -78,38 +73,43 @@ public class OrderController {
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("shopId") String shopId,
|
||||
@RequestParam(required = false) String tableId,
|
||||
String type
|
||||
) {
|
||||
@RequestParam(required = false) String tableId, String type) {
|
||||
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
|
||||
String userId = jsonObject.getString("accountId");
|
||||
return orderService.createCode(shopId, clientType, userId, type, tableId);
|
||||
}
|
||||
|
||||
@GetMapping("/getCartList")
|
||||
public Result getCart(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestParam("shopId") Integer shopId) {
|
||||
public Result getCart(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("shopId") Integer shopId) {
|
||||
return orderService.getCartList(shopId);
|
||||
}
|
||||
|
||||
@GetMapping("/getCartPrductSpec")
|
||||
public Result getCartPrductSpec(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestParam("cartId") Integer cartId) {
|
||||
public Result getCartPrductSpec(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("cartId") Integer cartId) {
|
||||
return orderService.getCartPrductSpec(cartId);
|
||||
}
|
||||
|
||||
@PostMapping("/cartStatus")
|
||||
public Result cartStatus(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestBody CartVo cartVo) {
|
||||
public Result cartStatus(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody CartVo cartVo) {
|
||||
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
|
||||
String userId = jsonObject.getString("accountId");
|
||||
return orderService.cartStatus(cartVo.getShopId(), cartVo.getMasterId(),
|
||||
cartVo.getStatus(), userId, cartVo.getUuid(), clientType, cartVo.getTableId(), token, cartVo.getOrderId());
|
||||
return orderService.cartStatus(cartVo.getShopId(), cartVo.getMasterId(), cartVo.getStatus(), userId, cartVo.getUuid(), clientType, cartVo.getTableId(), token, cartVo.getOrderId());
|
||||
}
|
||||
|
||||
@PostMapping("/createOrder")
|
||||
public Result createOrder(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestBody OrderVo orderVo) {
|
||||
public Result createOrder(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody OrderVo orderVo) {
|
||||
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
|
||||
String userId = jsonObject.getString("accountId");
|
||||
orderVo.setMerchantId(Integer.valueOf(userId));
|
||||
@@ -118,8 +118,10 @@ public class OrderController {
|
||||
}
|
||||
|
||||
@PostMapping("/createBackOrder")
|
||||
public Result createBackOrder(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestBody OrderVo orderVo) {
|
||||
public Result createBackOrder(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody OrderVo orderVo) {
|
||||
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
|
||||
String userId = jsonObject.getString("accountId");
|
||||
orderVo.setMerchantId(Integer.valueOf(userId));
|
||||
@@ -128,22 +130,28 @@ public class OrderController {
|
||||
}
|
||||
|
||||
@PostMapping("/packall")
|
||||
public Result packall(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestBody CartVo cartVo) {
|
||||
public Result packall(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody CartVo cartVo) {
|
||||
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
|
||||
String userId = jsonObject.getString("accountId");
|
||||
return orderService.packall(cartVo);
|
||||
}
|
||||
|
||||
@PostMapping("/clearCart")
|
||||
public Result clearCart(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestBody CartVo cartVo) {
|
||||
public Result clearCart(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody CartVo cartVo) {
|
||||
return orderService.clearCart(cartVo);
|
||||
}
|
||||
|
||||
@GetMapping("/findOrder")
|
||||
public Result findOrder(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestParam("shopId") Integer shopId,
|
||||
public Result findOrder(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("shopId") Integer shopId,
|
||||
@RequestParam("status") String status,
|
||||
@RequestParam(value = "orderNo", required = false) String orderNo,
|
||||
@RequestParam(value = "startTime", required = false) String startTime,
|
||||
@@ -154,8 +162,10 @@ public class OrderController {
|
||||
}
|
||||
|
||||
@GetMapping("/orderDetail")
|
||||
public Result orderDetail(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestParam("shopId") Integer shopId,
|
||||
public Result orderDetail(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("shopId") Integer shopId,
|
||||
@RequestParam("id") Integer id) {
|
||||
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
|
||||
String userId = jsonObject.getString("accountId");
|
||||
@@ -164,22 +174,30 @@ public class OrderController {
|
||||
|
||||
|
||||
@RequestMapping(value = "sendMessage")
|
||||
public Result sendMessage(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestParam("orderId") String orderId) {
|
||||
public Result sendMessage(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("orderId") String orderId) {
|
||||
return orderService.sendMassage(orderId);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "scanSendMessage")
|
||||
public Result scanSendMessage(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestParam("outNumber") String outNumber, @RequestParam("shopId") String shopId) {
|
||||
public Result scanSendMessage(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("outNumber") String outNumber,
|
||||
@RequestParam("shopId") String shopId) {
|
||||
return orderService.scanSendMessage(outNumber, shopId);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "getsendMessage")
|
||||
public Result getsendMessage(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType, @RequestParam("shopId") String shopId, @RequestParam("page") int page,
|
||||
public Result getsendMessage(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("shopId") String shopId,
|
||||
@RequestParam("page") int page,
|
||||
@RequestParam("pageSize") int pageSize) {
|
||||
return orderService.getOutNumber(shopId, page, pageSize);
|
||||
}
|
||||
@@ -191,9 +209,7 @@ public class OrderController {
|
||||
}
|
||||
|
||||
@PutMapping("/choseCount")
|
||||
public Result choseCount(
|
||||
@Validated @RequestBody ChoseCountDTO choseCountDTO
|
||||
) {
|
||||
public Result choseCount(@Validated @RequestBody ChoseCountDTO choseCountDTO) {
|
||||
return Result.success(CodeEnum.SUCCESS, orderService.choseCount(choseCountDTO));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -123,6 +124,9 @@ public class OrderService {
|
||||
private MpProductMapper mpProductMapper;
|
||||
|
||||
private final MpCashierCartService mpCashierCartService;
|
||||
@Qualifier("stringRedisTemplate")
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
|
||||
public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper, WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper, TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper, TbCashierCartMapper tbCashierCartMapper, MpCashierCartService mpCashierCartService) {
|
||||
@@ -1705,61 +1709,64 @@ public class OrderService {
|
||||
}
|
||||
|
||||
public Object choseCount(ChoseCountDTO choseCountDTO) {
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(choseCountDTO.getShopId(), ShopInfoEatModelEnum.DINE_IN.getValue());
|
||||
return Utils.runFunAndCheckKey(() -> {
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(choseCountDTO.getShopId(), ShopInfoEatModelEnum.DINE_IN.getValue());
|
||||
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(choseCountDTO.getShopId());
|
||||
if (shopInfo == null) throw new NotPrintException("店铺信息不存在");
|
||||
|
||||
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(choseCountDTO.getShopId());
|
||||
if (shopInfo == null) throw new NotPrintException("店铺信息不存在");
|
||||
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 1) {
|
||||
throw new NotPrintException("当前店铺无需选择餐位费");
|
||||
}
|
||||
|
||||
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 1) {
|
||||
throw new NotPrintException("当前店铺无需选择餐位费");
|
||||
}
|
||||
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, choseCountDTO.getTableId()));
|
||||
if (shopTable == null) {
|
||||
throw new NotPrintException("台桌不存在");
|
||||
}
|
||||
|
||||
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, choseCountDTO.getTableId()));
|
||||
if (shopTable == null) {
|
||||
throw new NotPrintException("台桌不存在");
|
||||
}
|
||||
if (shopTable.getMaxCapacity() < choseCountDTO.getNum()) {
|
||||
throw new NotPrintException("当前台桌最大人数为: " + shopTable.getMaxCapacity());
|
||||
}
|
||||
|
||||
if (shopTable.getMaxCapacity() < choseCountDTO.getNum()) {
|
||||
throw new NotPrintException("当前台桌最大人数为: " + shopTable.getMaxCapacity());
|
||||
}
|
||||
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, choseCountDTO.getShopId())
|
||||
.and(q -> q.eq(TbCashierCart::getMasterId, choseCountDTO.getMasterId()).or().isNull(TbCashierCart::getMasterId).or().eq(TbCashierCart::getMasterId, ""))
|
||||
.eq(TbCashierCart::getProductId, "-999")
|
||||
.eq(TbCashierCart::getSkuId, "-999")
|
||||
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
.eq(TbCashierCart::getStatus, "create")
|
||||
.eq(TbCashierCart::getTableId, choseCountDTO.getTableId());
|
||||
TbCashierCart tbCashierCart = mpCashierCartMapper.selectOne(query);
|
||||
|
||||
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, choseCountDTO.getShopId())
|
||||
.eq(TbCashierCart::getMasterId, choseCountDTO.getMasterId())
|
||||
.eq(TbCashierCart::getProductId, "-999")
|
||||
.eq(TbCashierCart::getSkuId, "-999")
|
||||
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
|
||||
.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
||||
.eq(TbCashierCart::getTableId, choseCountDTO.getTableId());
|
||||
TbCashierCart tbCashierCart = mpCashierCartMapper.selectOne(query);
|
||||
if (tbCashierCart == null) {
|
||||
tbCashierCart = new TbCashierCart();
|
||||
tbCashierCart.setStatus("create");
|
||||
tbCashierCart.setCreatedAt(System.currentTimeMillis());
|
||||
tbCashierCart.setTableId(choseCountDTO.getTableId());
|
||||
tbCashierCart.setName("客座费");
|
||||
tbCashierCart.setSalePrice(shopInfo.getTableFee());
|
||||
tbCashierCart.setMasterId(choseCountDTO.getMasterId());
|
||||
tbCashierCart.setShopId(String.valueOf(choseCountDTO.getShopId()));
|
||||
tbCashierCart.setTradeDay(DateUtils.getDay());
|
||||
tbCashierCart.setStatus("create");
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
|
||||
tbCashierCart.setPlaceNum(1);
|
||||
tbCashierCart.setProductId("-999");
|
||||
tbCashierCart.setSkuId("-999");
|
||||
tbCashierCart.setPackFee(BigDecimal.ZERO);
|
||||
tbCashierCart.setNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
tbCashierCartMapper.insert(tbCashierCart);
|
||||
} else {
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
|
||||
tbCashierCart.setNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
mpCashierCartMapper.updateById(tbCashierCart);
|
||||
}
|
||||
|
||||
if (tbCashierCart == null) {
|
||||
tbCashierCart = new TbCashierCart();
|
||||
tbCashierCart.setStatus("create");
|
||||
tbCashierCart.setCreatedAt(System.currentTimeMillis());
|
||||
tbCashierCart.setTableId(choseCountDTO.getTableId());
|
||||
tbCashierCart.setName("客座费");
|
||||
tbCashierCart.setSalePrice(shopInfo.getTableFee());
|
||||
tbCashierCart.setMasterId(choseCountDTO.getMasterId());
|
||||
tbCashierCart.setShopId(String.valueOf(choseCountDTO.getShopId()));
|
||||
tbCashierCart.setTradeDay(DateUtils.getDay());
|
||||
tbCashierCart.setStatus("create");
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
|
||||
tbCashierCart.setPlaceNum(1);
|
||||
tbCashierCart.setProductId("-999");
|
||||
tbCashierCart.setSkuId("-999");
|
||||
tbCashierCart.setPackFee(BigDecimal.ZERO);
|
||||
tbCashierCart.setNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
tbCashierCartMapper.insert(tbCashierCart);
|
||||
} else {
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
|
||||
tbCashierCart.setNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
mpCashierCartMapper.updateById(tbCashierCart);
|
||||
}
|
||||
return tbCashierCart;
|
||||
}, stringRedisTemplate, RedisCst.getLockKey(RedisCst.CHOSE_TABLE_COUNT, choseCountDTO.getShopId(), choseCountDTO.getTableId()));
|
||||
|
||||
return tbCashierCart;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@ public class RedisCst {
|
||||
static String CURRENT_TABLE_ORDER = "CURRENT_TABLE_ORDER:";
|
||||
public static String TABLE_CART = "TABLE:CART:";
|
||||
|
||||
public static final String LOCK_KEY = "LOCK:";
|
||||
// 选择人数锁
|
||||
public static final String CHOSE_TABLE_COUNT = "CHOSE_TABLE_COUNT";
|
||||
|
||||
|
||||
|
||||
|
||||
public static String getCurrentOrderKey(String tableId, String shopId) {
|
||||
@@ -35,4 +40,14 @@ public class RedisCst {
|
||||
public static String getTableCartKey(String tableId, String shopId) {
|
||||
return TABLE_CART + tableId + "-" + shopId;
|
||||
}
|
||||
|
||||
public static String getLockKey(String sign, Object... args) {
|
||||
StringBuilder key = new StringBuilder(LOCK_KEY + ":" + sign + ":");
|
||||
for (Object arg : args) {
|
||||
if (arg != null) {
|
||||
key.append(":").append(arg);
|
||||
}
|
||||
}
|
||||
return key.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user