冲销接口
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.zt.plat.module.contractorder.api;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.zt.plat.framework.common.exception.ErrorCode;
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
import com.zt.plat.module.contractorder.api.dto.order.*;
|
||||
@@ -25,6 +26,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@@ -128,6 +130,47 @@ public class OrderApiImpl implements OrderApi {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> voidOrderLstQty(List<UpdateOrderLstQtyDTO> updateOrderLstQtyDTOS) {
|
||||
if (updateOrderLstQtyDTOS == null || updateOrderLstQtyDTOS.isEmpty()) {
|
||||
throw new RuntimeException("请求数据错误");
|
||||
}
|
||||
SalesOrderDetailMapper salesOrderDetailMapper = SpringUtil.getBean(SalesOrderDetailMapper.class);
|
||||
PrchOrdDtlMapper prchOrdDtlMapper = SpringUtil.getBean(PrchOrdDtlMapper.class);
|
||||
updateOrderLstQtyDTOS.forEach(f -> {
|
||||
if ("SALE".equals(f.getSplyBsnTp())) {
|
||||
SalesOrderDetailDO salesOrderDetailDO = salesOrderDetailMapper.selectById(f.getOrderDetailId());
|
||||
// 处理 trfQty 可能为 null 的情况,默认值 0
|
||||
BigDecimal lstQty = Optional.ofNullable(salesOrderDetailDO.getTrfQty())
|
||||
.orElse(BigDecimal.ZERO);
|
||||
if (lstQty.equals(BigDecimal.ZERO)) {
|
||||
throw exception(new ErrorCode(1_008_00_609,"积累量不能等于0"));
|
||||
}
|
||||
SalesOrderDetailDO updateDO = new SalesOrderDetailDO();
|
||||
updateDO.setId(f.getOrderDetailId()); // 给更新对象设 ID
|
||||
updateDO.setTrfQty(lstQty.subtract(f.getLstQty())); // 减法
|
||||
log.info("更新销售订单明细:{}", updateDO);
|
||||
salesOrderDetailMapper.updateById(updateDO);
|
||||
} else if ("PUR".equals(f.getSplyBsnTp())) {
|
||||
// 采购
|
||||
PrchOrdDtlDO prchOrdDtlDO = prchOrdDtlMapper.selectById(f.getOrderDetailId());
|
||||
BigDecimal lstQty = Optional.ofNullable(prchOrdDtlDO.getTrfQty())
|
||||
.orElse(BigDecimal.ZERO);
|
||||
if (lstQty.equals(BigDecimal.ZERO)) {
|
||||
throw exception(new ErrorCode(1_008_00_609,"积累量不能等于0"));
|
||||
}
|
||||
PrchOrdDtlDO updateDO = new PrchOrdDtlDO();
|
||||
updateDO.setId(f.getOrderDetailId());
|
||||
updateDO.setLstQty(lstQty.subtract(f.getLstQty()));
|
||||
log.info("更新销售订单明细:{}", updateDO);
|
||||
prchOrdDtlMapper.updateById(updateDO);
|
||||
} else {
|
||||
throw new RuntimeException("请求数据错误");
|
||||
}
|
||||
});
|
||||
return success(true);
|
||||
}
|
||||
|
||||
private List<SalesOrderDO> getOrderByIds(List<Long> ids) {
|
||||
return SpringUtil.getBean(SalesOrderMapper.class).selectByIds(ids); // 采购订单与销售订单的
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user