Merge branch 'feature-商品起售数量' into dev

This commit is contained in:
2024-07-11 15:41:49 +08:00
7 changed files with 53 additions and 86 deletions

View File

@@ -50,10 +50,7 @@ public class OrderController {
@RequestParam Integer size, @RequestParam String status){
return orderService.orderList(userId,page,size,status);
}
@GetMapping("/testMessage")
private void testMessage(@RequestParam("tableId") String tableId, @RequestParam("message") String message) throws IOException {
orderService.testMessage(tableId,message);
}
@GetMapping("/tradeIntegral")
private Result tradeIntegral(@RequestParam("userId") String userId, @RequestParam("id") String id) throws IOException, ParseException {
return orderService.tradeIntegral(userId,id);

View File

@@ -15,19 +15,11 @@ import java.util.List;
public interface TbProductSkuMapper {
int deleteByPrimaryKey(Integer id);
int insert(TbProductSkuWithBLOBs record);
int insertSelective(TbProductSkuWithBLOBs record);
TbProductSkuWithBLOBs selectByPrimaryKey(Integer id);
Integer selectBySpecSnap(@Param("shopId")String shopId,@Param("tableId") Integer tableId,@Param("specSnap") String specSnap);
int updateByPrimaryKeySelective(TbProductSkuWithBLOBs record);
List<HomeVO> selectSale();
List<HomeVO> selectDay();
int updateByPrimaryKeyWithBLOBs(TbProductSkuWithBLOBs record);
int updateByPrimaryKey(TbProductSku record);
TbProductSkuWithBLOBs selectByShopIdAndProductIdAndSpec(@Param("shopId") String shopId, @Param("productId") String productId, @Param("spec") String spec);

View File

@@ -24,6 +24,8 @@ public class TbProductSku implements Serializable {
private BigDecimal guidePrice;
private Integer suit;
private BigDecimal strategyPrice;
private Double stockNumber;
@@ -47,6 +49,7 @@ public class TbProductSku implements Serializable {
private Long updatedAt;
private Integer isPauseSale = 0;
private Integer isDel;
private static final long serialVersionUID = 1L;
@@ -186,6 +189,14 @@ public class TbProductSku implements Serializable {
this.realSalesNumber = realSalesNumber;
}
public Integer getSuit() {
return suit;
}
public void setSuit(Integer suit) {
this.suit = suit;
}
public BigDecimal getFirstShared() {
return firstShared;
}
@@ -225,4 +236,12 @@ public class TbProductSku implements Serializable {
public void setIsPauseSale(Integer isPauseSale) {
this.isPauseSale = isPauseSale;
}
public Integer getIsDel() {
return isDel;
}
public void setIsDel(Integer isDel) {
this.isDel = isDel;
}
}

View File

@@ -160,54 +160,6 @@ public class PushToClientChannelHandlerAdapter extends NettyChannelHandlerAdapte
});
}
/**
* @param message 发送的消息内容
* @param shopId 店铺Id
// * @param clientId 客户端Id
// * @param userFlag 为true 单发给clientId
* 为false 群发 shopId为空 发给所有人
*/
// @Async
// public void AppSendInfo(String message, String shopId,String clientId, boolean userFlag) {
// log.info("netty连接client 发送消息 shopId:{} clientId:{} userFlag:{} message:{}",shopId,clientId,userFlag, JSONUtil.toJSONString(message));
// if (userFlag) {
// if (webSocketMap.containsKey(shopId)) {
// ConcurrentHashMap<String, ChannelHandlerContext> webSockets = webSocketMap.get(shopId);
// if(!webSockets.isEmpty()){
// if (StringUtils.isNotBlank(clientId)) {
// ChannelHandlerContext ctx = webSockets.get(clientId);
// if (ctx != null) {
// sendMesToApp(message,ctx);
// }
// }
// }
// }
// } else {
// if (StringUtils.isEmpty(shopId)) {
// // 向所有用户发送信息
// for (ConcurrentHashMap<String, ChannelHandlerContext> value : webSocketMap.values()) {
// for (ChannelHandlerContext ctx : value.values()) {
// sendMesToApp(message,ctx);
// }
// }
// } else if (webSocketMap.containsKey(shopId)) {
// ConcurrentHashMap<String, ChannelHandlerContext> webSockets = webSocketMap.get(shopId);
// if((!webSockets.isEmpty() && !webSockets.keySet().isEmpty())) {
// for (String user : webSockets.keySet()) {
// ChannelHandlerContext ctx = webSockets.get(user);
// if (ctx != null) {
// log.info("netty连接client 发送消息 桌码群发 clientId:{}",user);
// sendMesToApp(message,ctx);
// }else {
// log.info("netty连接client 发送消息 桌码群发 clientId:{} 失败",user);
// }
// }
// }else {
// log.info("netty连接client 发送消息 桌码群发 clientId:{} 失败",clientId);
// }
// }
// }
// }
public void AppSendInfoV1(String shopId, String orderNo, JSONObject message) {
log.info("netty连接client 发送消息 shopId:{} clientId:{} userFlag:{} message:{}", shopId, message.get("orderInfo"));
retryQueue.computeIfAbsent(shopId, k -> new ConcurrentLinkedQueue<>()).offer(message);

View File

@@ -288,7 +288,6 @@ public class CartService {
// log.error("长链接错误 createCart{}", e.getMessage());
// }
// }
public void createCart(JSONObject jsonObject) {
try {
String tableId = jsonObject.getString("tableId");
@@ -311,10 +310,11 @@ public class CartService {
Integer buyNum = jsonObject.getInteger("num");
String skuId = jsonObject.getString("skuId");
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
if (tbProduct.getIsStock() == 1) {
// 1:共享库存 0:独立库存
if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) {
if (tbProduct.getIsPauseSale() == 1 || tbProduct.getStockNumber() - buyNum < 0) {//是否售罄
if (tbProduct.getIsPauseSale() == 1 || tbProduct.getStockNumber() < buyNum ) {//是否售罄
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品已售罄");
@@ -326,8 +326,7 @@ public class CartService {
throw new MsgException("该商品已售罄");
}
} else {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
if(tbProductSkuWithBLOBs.getIsPauseSale() == 1 || tbProductSkuWithBLOBs.getStockNumber() - buyNum < 0){//是否售罄
if (tbProductSkuWithBLOBs.getIsPauseSale() == 1 || tbProductSkuWithBLOBs.getStockNumber() < buyNum ) {//是否售罄
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品已售罄");
@@ -360,6 +359,10 @@ public class CartService {
if (cashierCart.getSkuId().equals(skuId)) {
cashierCart.setTotalNumber(cashierCart.getTotalNumber() + buyNum);
cashierCart.setNumber(cashierCart.getNumber() + buyNum);
if (buyNum < 0 && tbProductSkuWithBLOBs.getSuit() != null && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() <= tbProductSkuWithBLOBs.getSuit()) {
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
continue;
}
if (cashierCart.getNumber() > 0) {
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
@@ -498,9 +501,24 @@ public class CartService {
throw new MsgException("该商品规格不存在");
}
TbCashierCart cashierCart = new TbCashierCart();
if (productSku.getSuit() != null && productSku.getSuit() > 1) {
if (productSku.getSuit() > productSku.getStockNumber()) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品" + productSku.getSuit() + "起售,现库存不足");
jsonObject1.put("data", new ArrayList<>());
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true);
log.error("购物车添加商品异常,该商品起售库存不足:{}", productId);
throw new MsgException("该商品起售库存不足");
}
cashierCart.setNumber(productSku.getSuit());
cashierCart.setTotalNumber(productSku.getSuit());
}else {
cashierCart.setNumber(num);
cashierCart.setTotalNumber(num);
}
cashierCart.setProductId(productId);
cashierCart.setSkuId(skuId);
cashierCart.setNumber(num);
cashierCart.setCoverImg(product.getCoverImg());
cashierCart.setName(product.getName());
cashierCart.setCategoryId(product.getCategoryId());
@@ -515,7 +533,6 @@ public class CartService {
cashierCart.setSalePrice(productSku.getSalePrice());
cashierCart.setCreatedAt(Instant.now().toEpochMilli());
cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
cashierCart.setTotalNumber(num);
cashierCart.setPackFee(BigDecimal.ZERO);
cashierCart.setRefundNumber(0);
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(productSku.getSalePrice().add(cashierCart.getPackFee())));
@@ -577,10 +594,10 @@ public class CartService {
try {
if (tbProduct1.getIsStock() == 1) {
productService.updateStock(tbProduct.getProductId(), tbProduct.getId(), cashierCart.getNumber(), tbProduct1.getIsDistribute() == 1);
}else {
} else {
productService.updateStockAndNoCheck(tbProduct.getProductId(), tbProduct.getId(), cashierCart.getNumber(), tbProduct1.getIsDistribute() == 1);
}
}catch (Exception e) {
} catch (Exception e) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "商品库存不足" + tbProduct1.getName());
@@ -590,9 +607,9 @@ public class CartService {
}
// 发送判断耗材是否耗尽消息
JSONObject objectMsg=new JSONObject();
objectMsg.put("skuId",Integer.valueOf(cashierCart.getSkuId()));
objectMsg.put("shopId",Integer.valueOf(cashierCart.getShopId()));
JSONObject objectMsg = new JSONObject();
objectMsg.put("skuId", Integer.valueOf(cashierCart.getSkuId()));
objectMsg.put("shopId", Integer.valueOf(cashierCart.getShopId()));
producer.con_msg(objectMsg.toString());
totalAmount = totalAmount.add(cashierCart.getTotalAmount());

View File

@@ -248,18 +248,6 @@ public class OrderService {
}
public void testMessage(String tableId, String message) throws IOException {
// AppWebSocketServer.AppSendInfo(message,tableId);
// redisUtil.seckill(tableId,message);
// AppWebSocketServer.onClosed(tableId);
List<TbProductSku> list = productSkuMapper.selectAll();
for (TbProductSku productSku : list) {
// productSku.setStockNumber(200.00);
redisUtil.saveMessage("PRODUCT:" + productSku.getShopId() + ":" + productSku.getId(), "10000");
}
}
@Transactional(rollbackFor = Exception.class)
public Result tradeIntegral(String userId, String id) throws ParseException {
updateIntegral(userId, id);

View File

@@ -12,6 +12,7 @@
<result column="meal_price" jdbcType="DECIMAL" property="mealPrice" />
<result column="sale_price" jdbcType="DECIMAL" property="salePrice" />
<result column="guide_price" jdbcType="DECIMAL" property="guidePrice" />
<result column="suit" jdbcType="INTEGER" property="suit" />
<result column="strategy_price" jdbcType="DECIMAL" property="strategyPrice" />
<result column="stock_number" jdbcType="DOUBLE" property="stockNumber" />
<result column="cover_img" jdbcType="VARCHAR" property="coverImg" />
@@ -24,6 +25,7 @@
<result column="created_at" jdbcType="BIGINT" property="createdAt" />
<result column="updated_at" jdbcType="BIGINT" property="updatedAt" />
<result column="is_pause_sale" jdbcType="INTEGER" property="isPauseSale" />
<result column="is_del" jdbcType="INTEGER" property="isDel" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.chaozhanggui.system.cashierservice.entity.TbProductSkuWithBLOBs">
<result column="spec_info" jdbcType="LONGVARCHAR" property="specInfo" />
@@ -31,8 +33,8 @@
</resultMap>
<sql id="Base_Column_List">
id, shop_id, bar_code, product_id, origin_price, cost_price, member_price, meal_price,
sale_price, guide_price, strategy_price, stock_number, cover_img, warn_line, weight,
volume, real_sales_number, first_shared, second_shared, created_at, updated_at, is_pause_sale
sale_price, guide_price,suit, strategy_price, stock_number, cover_img, warn_line, weight,
volume, real_sales_number, first_shared, second_shared, created_at, updated_at, is_pause_sale ,is_del
</sql>
<sql id="Blob_Column_List">
spec_info, spec_snap
@@ -359,7 +361,7 @@
</update>
<select id="selectByShopIdAndProductIdAndSpec" resultMap="ResultMapWithBLOBs">
select * from tb_product_sku where shop_id=#{shopId} and product_id=#{productId}
select * from tb_product_sku where shop_id=#{shopId} and product_id=#{productId} and is_del = 0
<if test="spec != null and spec !=''">
and spec_snap = #{spec}