下单时 检验库存数
This commit is contained in:
@@ -12,5 +12,9 @@ import java.math.BigDecimal;
|
||||
public class ConsStockRecord {
|
||||
@Column("id")
|
||||
private Long consId;
|
||||
//消耗值
|
||||
private BigDecimal stockNumber;
|
||||
private String conName;
|
||||
//库存数
|
||||
private BigDecimal currentStockNumber;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.Map;
|
||||
* @author ww
|
||||
* @since 2025-02-13
|
||||
*/
|
||||
public interface OrderInfoCustomMapper{
|
||||
public interface OrderInfoCustomMapper {
|
||||
|
||||
/**
|
||||
* 交班售出商品明细
|
||||
@@ -42,6 +42,7 @@ public interface OrderInfoCustomMapper{
|
||||
int updatePayOrderId(@Param("orderId") Long orderId, @Param("paymentId") Long paymentId, @Param("payType") String payType, @Param("remark") String remark);
|
||||
|
||||
List<ConsStockRecord> getConsByProductAndNum(
|
||||
@Param("shopId") Long shopId,
|
||||
@Param("productUsageMap") Map<Long, BigDecimal> productUsageMap
|
||||
);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ import com.czg.order.enums.PayEnums;
|
||||
import com.czg.order.service.*;
|
||||
import com.czg.order.vo.*;
|
||||
import com.czg.pay.PayNotifyRespDTO;
|
||||
import com.czg.product.entity.ConsInfo;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.entity.ShopProdCategory;
|
||||
import com.czg.product.service.ConsInfoService;
|
||||
@@ -81,7 +80,6 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -115,8 +113,6 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
@DubboReference
|
||||
private ProductService productService;
|
||||
@DubboReference
|
||||
private ConsInfoService consInfoService;
|
||||
@DubboReference
|
||||
private ShopProdCategoryService shopProdCategoryService;
|
||||
@DubboReference
|
||||
private ProductRpcService productRpcService;
|
||||
@@ -1090,23 +1086,20 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
if (CollUtil.isEmpty(productNumMap)) {
|
||||
return;
|
||||
}
|
||||
List<ConsInfo> consStockList = consInfoService.list(new QueryWrapper().select(ConsInfo::getId, ConsInfo::getConName, ConsInfo::getConUnit, ConsInfo::getStockNumber)
|
||||
.eq(ConsInfo::getShopId, shopId).eq(ConsInfo::getIsStock, 1));
|
||||
if (CollUtil.isEmpty(consStockList)) {
|
||||
return;
|
||||
}
|
||||
Map<Long, ConsInfo> map = consStockList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
ConsInfo::getId,
|
||||
Function.identity()
|
||||
));
|
||||
List<ConsStockRecord> consNumList = orderInfoCustomMapper.getConsByProductAndNum(productNumMap);
|
||||
// List<ConsInfo> consStockList = consInfoService.list(new QueryWrapper().select(ConsInfo::getId, ConsInfo::getConName, ConsInfo::getConUnit, ConsInfo::getStockNumber)
|
||||
// .eq(ConsInfo::getShopId, shopId).eq(ConsInfo::getIsStock, 1));
|
||||
// if (CollUtil.isEmpty(consStockList)) {
|
||||
// return;
|
||||
// }
|
||||
// Map<Long, ConsInfo> map = consStockList.stream()
|
||||
// .collect(Collectors.toMap(
|
||||
// ConsInfo::getId,
|
||||
// Function.identity()
|
||||
// ));
|
||||
List<ConsStockRecord> consNumList = orderInfoCustomMapper.getConsByProductAndNum(shopId, productNumMap);
|
||||
for (ConsStockRecord consStockRecord : consNumList) {
|
||||
if (map.containsKey(consStockRecord.getConsId())) {
|
||||
ConsInfo consInfo = map.get(consStockRecord.getConsId());
|
||||
if (consStockRecord.getStockNumber().compareTo(consInfo.getStockNumber()) > 0) {
|
||||
throw new CzgException("耗材:" + consInfo.getConName() + "库存不足,当前库存:" + consInfo.getStockNumber() + consInfo.getConUnit());
|
||||
}
|
||||
if (consStockRecord.getStockNumber().compareTo(consStockRecord.getCurrentStockNumber()) > 0) {
|
||||
throw new CzgException("耗材:" + consStockRecord.getConName() + "库存不足,当前库存:" + consStockRecord.getCurrentStockNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,19 +84,21 @@
|
||||
<select id="getConsByProductAndNum" resultType="com.czg.product.vo.ConsStockRecord">
|
||||
SELECT
|
||||
r.cons_info_id AS consId,
|
||||
SUM(
|
||||
CASE r.product_id
|
||||
SUM(r.surplus_stock *
|
||||
CASE
|
||||
<foreach collection="productUsageMap.entrySet()" item="qty" index="pid">
|
||||
WHEN #{pid} THEN #{qty}
|
||||
WHEN r.product_id = #{pid} THEN #{qty}
|
||||
</foreach>
|
||||
ELSE 0
|
||||
END
|
||||
) AS stockNumber
|
||||
FROM tb_prod_cons_relation r
|
||||
WHERE r.product_id IN
|
||||
) AS stockNumber,
|
||||
cons.con_name as conName,
|
||||
cons.stock_number as currentStockNumber
|
||||
FROM tb_prod_cons_relation r INNER JOIN tb_cons_info cons on r.cons_info_id = cons.id and cons.is_stock = 1
|
||||
WHERE r.shop_id = #{shopId} AND r.product_id IN
|
||||
<foreach collection="productUsageMap.keySet()" item="pid" open="(" separator="," close=")">
|
||||
#{pid}
|
||||
</foreach>
|
||||
GROUP BY r.cons_info_id
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user