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