|
|
@@ -28,6 +28,8 @@ import com.sckw.payment.api.model.dto.WalletDto;
|
|
|
import com.sckw.payment.api.model.dto.common.R;
|
|
|
import com.sckw.product.api.dubbo.GoodsInfoService;
|
|
|
import com.sckw.product.api.model.KwpGoods;
|
|
|
+import com.sckw.redis.constant.RedisConstant;
|
|
|
+import com.sckw.redis.utils.RedissonUtils;
|
|
|
import com.sckw.stream.model.SckwBusSum;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.system.api.model.dto.res.AreaTreeFrontResDto;
|
|
|
@@ -776,29 +778,37 @@ public class KwoTradeOrderService {
|
|
|
if (kwoTradeOrderUnitService.entMatch(param.getId(), LoginUserHolder.getEntId(), DictEnum.TORDER_UNIT_TYPE_2.getValue())) {
|
|
|
throw new BusinessException("无订单操作权限!");
|
|
|
}
|
|
|
- order.setActualAmount(param.getActualAmount()).setStatus(Integer.valueOf(DictEnum.TORDER_STATUS_5.getValue()));
|
|
|
- kwoTradeOrderMapper.updateById(order);
|
|
|
- //订单状态记录
|
|
|
- KwoTradeOrderTrack track = new KwoTradeOrderTrack();
|
|
|
- track.setTOrderId(order.getId()).setTOrderNo(order.getTOrderNo()).setRemark(param.getRemark()).setStatus(order.getStatus());
|
|
|
- kwoTradeOrderTrackService.insert(track);
|
|
|
- if (param.getActualAmount().compareTo(order.getAmount()) != 0) {
|
|
|
- KwoTradeOrderGoods goods = kwoTradeOrderGoodsService.getByOrderId(param.getId());
|
|
|
- if (Objects.isNull(goods)) {
|
|
|
- throw new BusinessException("商品信息异常!");
|
|
|
- }
|
|
|
- //更新库存
|
|
|
- BigDecimal amount = param.getActualAmount().subtract(order.getAmount());
|
|
|
- HttpResult updateResult = goodsInfoService.updateGoodsAmount(goods.getGoodsId(), amount);
|
|
|
- if (!Objects.equals(HttpStatus.SUCCESS_CODE, updateResult.getCode())) {
|
|
|
- throw new BusinessException(updateResult.getMsg());
|
|
|
+ String lockKey = String.format(RedisConstant.TORDER_UPDATE_AMOUNT_KEY, param.getId());
|
|
|
+ if (Boolean.FALSE.equals(RedissonUtils.tryLock(lockKey, 10L, 30L))) {
|
|
|
+ throw new BusinessException("业务繁忙,请稍后再试!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ order.setActualAmount(param.getActualAmount()).setStatus(Integer.valueOf(DictEnum.TORDER_STATUS_5.getValue()));
|
|
|
+ kwoTradeOrderMapper.updateById(order);
|
|
|
+ //订单状态记录
|
|
|
+ KwoTradeOrderTrack track = new KwoTradeOrderTrack();
|
|
|
+ track.setTOrderId(order.getId()).setTOrderNo(order.getTOrderNo()).setRemark(param.getRemark()).setStatus(order.getStatus());
|
|
|
+ kwoTradeOrderTrackService.insert(track);
|
|
|
+ if (param.getActualAmount().compareTo(order.getAmount()) != 0) {
|
|
|
+ KwoTradeOrderGoods goods = kwoTradeOrderGoodsService.getByOrderId(param.getId());
|
|
|
+ if (Objects.isNull(goods)) {
|
|
|
+ throw new BusinessException("商品信息异常!");
|
|
|
+ }
|
|
|
+ //更新库存
|
|
|
+ BigDecimal amount = param.getActualAmount().subtract(order.getAmount());
|
|
|
+ HttpResult updateResult = goodsInfoService.updateGoodsAmount(goods.getGoodsId(), amount);
|
|
|
+ if (!Objects.equals(HttpStatus.SUCCESS_CODE, updateResult.getCode())) {
|
|
|
+ throw new BusinessException(updateResult.getMsg());
|
|
|
+ }
|
|
|
}
|
|
|
+ //mongodb更新订单状态
|
|
|
+ SckwTradeOrder updateParam = new SckwTradeOrder();
|
|
|
+ updateParam.setTOrderId(order.getId()).setActualAmount(order.getActualAmount()).setStatus(order.getStatus())
|
|
|
+ .setUpdateBy(LoginUserHolder.getUserId()).setUpdateByName(LoginUserHolder.getUserName()).setUpdateTime(new Date());
|
|
|
+ saveMongoDb(3, updateParam);
|
|
|
+ } finally {
|
|
|
+ RedissonUtils.unlock(lockKey);
|
|
|
}
|
|
|
- //mongodb更新订单状态
|
|
|
- SckwTradeOrder updateParam = new SckwTradeOrder();
|
|
|
- updateParam.setTOrderId(order.getId()).setActualAmount(order.getActualAmount()).setStatus(order.getStatus())
|
|
|
- .setUpdateBy(LoginUserHolder.getUserId()).setUpdateByName(LoginUserHolder.getUserName()).setUpdateTime(new Date());
|
|
|
- saveMongoDb(3, updateParam);
|
|
|
|
|
|
}
|
|
|
|