|
@@ -1100,7 +1100,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
this.save(oldStock);
|
|
|
}
|
|
|
|
|
|
- if(ObjectUtil.isEmpty(oldStock.getVictoriatouristJson())){
|
|
|
+ if (ObjectUtil.isEmpty(oldStock.getVictoriatouristJson())) {
|
|
|
oldStock.setVictoriatouristJson("{}");
|
|
|
this.updateById(oldStock);
|
|
|
}
|
|
@@ -1123,10 +1123,11 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
|
|
|
//操作普通库存
|
|
|
if (stockType.equals(StockType.QUANTITY)) {
|
|
|
+ String setSql = inOutType != InOutType.SET ? "quantity = quantity %s %s" : "quantity %s %s";
|
|
|
boolean update = update(q -> q
|
|
|
.eq(Stock::getProductId, inOutBo.getProductId())
|
|
|
.eq(Stock::getWarehouseId, warehouseId)
|
|
|
- .setSql(String.format("quantity = quantity %s %s", opStr, inOutBo.getQuantity()))
|
|
|
+ .setSql(String.format(setSql, opStr, inOutBo.getQuantity()))
|
|
|
.apply(inOutType.equals(InOutType.OUT), "quantity - {0} >= 0", inOutBo.getQuantity())
|
|
|
);
|
|
|
if (!update) {
|
|
@@ -1140,10 +1141,14 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
}
|
|
|
//操作冻结库存
|
|
|
if (stockType.equals(StockType.FROZEN_QUANTITY)) {
|
|
|
+ BigDecimal quantity = inOutBo.getQuantity();
|
|
|
+ String set1 = "victoriatourist_json = JSON_SET(victoriatourist_json,'$.frozenQuantity',IFNULL(json_unquote(victoriatourist_json -> '$.frozenQuantity'), 0) %s %s)";
|
|
|
+ String set2 = "victoriatourist_json = JSON_SET(victoriatourist_json,'$.frozenQuantity',%s)";
|
|
|
+ String setSql = inOutType != InOutType.SET ? String.format(set1, opStr, quantity) : String.format(set2, quantity);
|
|
|
boolean update = update(q -> q
|
|
|
.eq(Stock::getProductId, inOutBo.getProductId())
|
|
|
.eq(Stock::getWarehouseId, warehouseId)
|
|
|
- .setSql(String.format("victoriatourist_json = JSON_SET(victoriatourist_json,'$.frozenQuantity',IFNULL(json_unquote(victoriatourist_json -> '$.frozenQuantity'), 0) %s %s)", opStr, inOutBo.getQuantity()))
|
|
|
+ .setSql(setSql)
|
|
|
.apply(inOutType.equals(InOutType.OUT), "IFNULL(json_unquote(victoriatourist_json -> '$.frozenQuantity'), 0) - {0} >= 0", inOutBo.getQuantity())
|
|
|
);
|
|
|
if (!update) {
|
|
@@ -1160,18 +1165,22 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
}
|
|
|
//操作次品库存
|
|
|
if (stockType.equals(StockType.DEFECTIVE_QUANTITY)) {
|
|
|
+ BigDecimal quantity = inOutBo.getQuantity();
|
|
|
+ String set1 = "victoriatourist_json = JSON_SET(victoriatourist_json,'$.defectiveQuantity',IFNULL(json_unquote(victoriatourist_json -> '$.defectiveQuantity'), 0) %s %s)";
|
|
|
+ String set2 = "victoriatourist_json = JSON_SET(victoriatourist_json,'$.defectiveQuantity',%s)";
|
|
|
+ String setSql = inOutType != InOutType.SET ? String.format(set1, opStr, quantity) : String.format(set2, quantity);
|
|
|
boolean update = update(q -> q
|
|
|
.eq(Stock::getProductId, inOutBo.getProductId())
|
|
|
.eq(Stock::getWarehouseId, warehouseId)
|
|
|
- .setSql(String.format("victoriatourist_json = JSON_SET(victoriatourist_json,'$.defectiveQuantity',IFNULL(json_unquote(victoriatourist_json -> '$.defectiveQuantity'), 0) %s %s)", opStr, inOutBo.getQuantity()))
|
|
|
- .apply(inOutType.equals(InOutType.OUT), "IFNULL(json_unquote(victoriatourist_json -> '$.defectiveQuantity'), 0) - {0} >= 0", inOutBo.getQuantity())
|
|
|
+ .setSql(setSql)
|
|
|
+ .apply(inOutType.equals(InOutType.OUT), "IFNULL(json_unquote(victoriatourist_json -> '$.defectiveQuantity'), 0) - {0} >= 0", quantity)
|
|
|
);
|
|
|
if (!update) {
|
|
|
if (inOutType.equals(InOutType.OUT)) {
|
|
|
String jsonStr = oldStock.getVictoriatouristJson();
|
|
|
JSONObject json = ObjectUtil.isEmpty(jsonStr) ? new JSONObject() : JSONObject.parseObject(jsonStr);
|
|
|
|
|
|
- if (json.getBigDecimal("defectiveQuantity").subtract(inOutBo.getQuantity()).compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ if (json.getBigDecimal("defectiveQuantity").subtract(quantity).compareTo(BigDecimal.ZERO) < 0) {
|
|
|
throw new ServiceException("产品次品库存不足无法出库:", productInfo.getName());
|
|
|
}
|
|
|
}
|