|
|
@@ -27,6 +27,8 @@ import com.sckw.product.enums.GoodsStatusEnum;
|
|
|
import com.sckw.product.model.*;
|
|
|
import com.sckw.product.model.vo.req.*;
|
|
|
import com.sckw.product.model.vo.res.*;
|
|
|
+import com.sckw.redis.constant.RedisConstant;
|
|
|
+import com.sckw.redis.utils.RedissonUtils;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
import com.sckw.system.api.model.dto.res.SysDictResDto;
|
|
|
@@ -229,6 +231,10 @@ public class KwpGoodsService {
|
|
|
if (Objects.equals(goods.getStatus(), GoodsStatusEnum.PUT_ON_SHELVES.getCode())
|
|
|
|| Objects.equals(goods.getStatus(), GoodsStatusEnum.TAKE_OFF_SHELVES.getCode())) {
|
|
|
judgeParameters(param);
|
|
|
+ if (Objects.equals(goods.getStatus(), GoodsStatusEnum.PUT_ON_SHELVES.getCode()) &&
|
|
|
+ goods.getAmount().compareTo(param.getAmount()) != 0) {
|
|
|
+ throw new BusinessException("上架商品不可修改库存数量!");
|
|
|
+ }
|
|
|
}
|
|
|
BeanUtils.copyProperties(param, goods);
|
|
|
if (Objects.nonNull(param.getAddressInfo())) {
|
|
|
@@ -564,7 +570,8 @@ public class KwpGoodsService {
|
|
|
export.setHighestPrice(Objects.isNull(e.getHighestPrice()) ? null : String.valueOf(e.getHighestPrice()))
|
|
|
.setLowestPrice(Objects.isNull(e.getLowestPrice()) ? null : String.valueOf(e.getLowestPrice()))
|
|
|
.setAddedTime(Objects.isNull(e.getAddedTime()) ? null : DateUtil.getDateTime(e.getAddedTime()))
|
|
|
- .setShelfTime(Objects.isNull(e.getShelfTime()) ? null : DateUtil.getDateTime(e.getShelfTime()));
|
|
|
+ .setShelfTime(Objects.isNull(e.getShelfTime()) ? null : DateUtil.getDateTime(e.getShelfTime()))
|
|
|
+ .setCreateTime(Objects.isNull(e.getCreateTime()) ? null : DateUtil.getDateTime(e.getCreateTime()));
|
|
|
list.add(export);
|
|
|
});
|
|
|
return list;
|
|
|
@@ -871,4 +878,38 @@ public class KwpGoodsService {
|
|
|
BigDecimal divide = new BigDecimal(money).divide(param.getUtilPrice().multiply(new BigDecimal("100")), 2, RoundingMode.HALF_UP);
|
|
|
return amount.compareTo(divide) < 0 ? amount : divide;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc: 更新商品库存
|
|
|
+ * @author: yzc
|
|
|
+ * @date: 2023-08-03 17:06
|
|
|
+ * @Param param:
|
|
|
+ * @return: void
|
|
|
+ */
|
|
|
+ public void updateAmount(UpdateAmountParam param) {
|
|
|
+ Long id = param.getId();
|
|
|
+ BigDecimal updateAmount = param.getUpdateAmount();
|
|
|
+ LambdaQueryWrapper<KwpGoods> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(KwpGoods::getId, id).eq(KwpGoods::getStatus, GoodsStatusEnum.PUT_ON_SHELVES.getCode())
|
|
|
+ .eq(KwpGoods::getDelFlag, Global.NO).last("LIMIT 1");
|
|
|
+ KwpGoods goods = kwpGoodsMapper.selectOne(wrapper);
|
|
|
+ if (Objects.isNull(goods)) {
|
|
|
+ throw new BusinessException("商品不存在或已下架!");
|
|
|
+ }
|
|
|
+ BigDecimal amount = goods.getAmount();
|
|
|
+ BigDecimal finalAmount = Objects.equals(param.getUpdateType(), 0) ? amount.add(updateAmount) : amount.subtract(updateAmount);
|
|
|
+ if (finalAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ throw new BusinessException("库存数量更新后不能小于等于零!");
|
|
|
+ }
|
|
|
+ String lockKey = String.format(RedisConstant.GOODS_UPDATE_AMOUNT_KEY, id);
|
|
|
+ try {
|
|
|
+ if (Boolean.FALSE.equals(RedissonUtils.tryLock(lockKey, 10L, 30L))) {
|
|
|
+ throw new BusinessException("业务繁忙,请稍后再试!");
|
|
|
+ }
|
|
|
+ goods.setAmount(finalAmount);
|
|
|
+ kwpGoodsMapper.updateById(goods);
|
|
|
+ } finally {
|
|
|
+ RedissonUtils.unlock(lockKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|