|
@@ -26,8 +26,6 @@ import com.dk.mdm.model.query.ivt.OutboundItemQuery;
|
|
|
import com.dk.mdm.model.query.ivt.OutboundQuery;
|
|
import com.dk.mdm.model.query.ivt.OutboundQuery;
|
|
|
import com.dk.mdm.model.response.ivt.OutboundItemResponse;
|
|
import com.dk.mdm.model.response.ivt.OutboundItemResponse;
|
|
|
import com.dk.mdm.model.response.ivt.OutboundResponse;
|
|
import com.dk.mdm.model.response.ivt.OutboundResponse;
|
|
|
-import com.dk.mdm.model.response.pur.PurchaseItemResponse;
|
|
|
|
|
-import com.dk.mdm.model.response.sale.OrderResponse;
|
|
|
|
|
import com.dk.mdm.model.vo.ivt.OutboundItemVO;
|
|
import com.dk.mdm.model.vo.ivt.OutboundItemVO;
|
|
|
import com.dk.mdm.model.vo.ivt.OutboundVO;
|
|
import com.dk.mdm.model.vo.ivt.OutboundVO;
|
|
|
import com.dk.mdm.service.common.CommonService;
|
|
import com.dk.mdm.service.common.CommonService;
|
|
@@ -187,21 +185,49 @@ public class OutboundService extends BaseService<Outbound> {
|
|
|
rollbackFor = {Exception.class}
|
|
rollbackFor = {Exception.class}
|
|
|
)
|
|
)
|
|
|
public ResponseResultVO<Boolean> update(OutboundVO outboundVO) {
|
|
public ResponseResultVO<Boolean> update(OutboundVO outboundVO) {
|
|
|
|
|
+ // 订单明细实体
|
|
|
|
|
+ OrderItem orderItemForUpdate;
|
|
|
|
|
+ // 订单明细实体
|
|
|
|
|
+ OutboundItem outboundItemForUpdate;
|
|
|
// 转化实体
|
|
// 转化实体
|
|
|
Outbound outbound = outboundConvert.convertToPo(outboundVO);
|
|
Outbound outbound = outboundConvert.convertToPo(outboundVO);
|
|
|
|
|
|
|
|
- // 编辑的
|
|
|
|
|
|
|
+ // 编辑出库明细
|
|
|
List<OutboundItemVO> editOutboundItemVOList = outboundVO.getItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
|
|
List<OutboundItemVO> editOutboundItemVOList = outboundVO.getItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
|
|
|
for (OutboundItemVO outboundItemVO : editOutboundItemVOList) {
|
|
for (OutboundItemVO outboundItemVO : editOutboundItemVOList) {
|
|
|
// 出库中数量不能小于出库数量
|
|
// 出库中数量不能小于出库数量
|
|
|
if (outboundItemVO.getOutingQty().compareTo(outboundItemVO.getOutQty()) == -1) {
|
|
if (outboundItemVO.getOutingQty().compareTo(outboundItemVO.getOutQty()) == -1) {
|
|
|
throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.OUTINGQTY_NO_LESS_OUTQTY.getMessage());
|
|
throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.OUTINGQTY_NO_LESS_OUTQTY.getMessage());
|
|
|
- } else {
|
|
|
|
|
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
|
|
- outboundItemService.updateByUuid(outboundItem);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ outboundItemForUpdate = outboundItemMapper.selectByIdForUpdate(outboundItemVO.getItemId());
|
|
|
|
|
+ orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItemVO.getFromItemId());
|
|
|
|
|
+
|
|
|
|
|
+ // 订单的商品数量不能小于(订单之前的出库中数量 - 出库明细之前的出库中数量 + 出库明细现在的出库中数量)
|
|
|
|
|
+ if (orderItemForUpdate.getItemQty().compareTo(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()).add(outboundItemVO.getOutingQty())) == -1) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_OUTQTY.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ // 更新订单明细出库中数量
|
|
|
|
|
+ OrderItem orderItemUpdate = new OrderItem();
|
|
|
|
|
+ orderItemUpdate.setOutingQty(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()).add(outboundItemVO.getOutingQty()))
|
|
|
|
|
+ .setOutingAmt(orderItemForUpdate.getOutingAmt().subtract(outboundItemForUpdate.getOutingAmt()).add(outboundItemVO.getOutingAmt()))
|
|
|
|
|
+ .setItemId(orderItemForUpdate.getItemId());
|
|
|
|
|
+ orderItemService.updateByUuid(orderItemUpdate);
|
|
|
|
|
+ // 更新出库明细
|
|
|
|
|
+ OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
|
|
+ outboundItemService.updateByUuid(outboundItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ Outbound outboundForUpdate = outboundMapper.selectByIdForUpdate(outboundVO.getOutId());
|
|
|
|
|
+
|
|
|
|
|
+ // 更新订单上的退货数量,金额
|
|
|
|
|
+ Order orderForUpdate = orderMapper.selectByIdForUpdate(outboundVO.getFromId());
|
|
|
|
|
+ Order orderUpdate = new Order();
|
|
|
|
|
+ orderUpdate.setOutingQty(orderForUpdate.getOutingQty().subtract(outboundForUpdate.getOutingQty()).add(outboundForUpdate.getOutingQty()))
|
|
|
|
|
+ .setOutingAmt(orderForUpdate.getOutingAmt().subtract(outboundForUpdate.getOutingAmt()).add(outboundForUpdate.getOutingAmt()))
|
|
|
|
|
+ .setOrderId(outboundVO.getFromId());
|
|
|
|
|
+ orderService.updateByUuid(orderUpdate);
|
|
|
|
|
+
|
|
|
return ResponseResultUtil.success(super.update(outbound, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
|
|
return ResponseResultUtil.success(super.update(outbound, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
|
|
|
UUID.fromString(outbound.getOutId()))));
|
|
UUID.fromString(outbound.getOutId()))));
|
|
|
}
|
|
}
|
|
@@ -212,6 +238,47 @@ public class OutboundService extends BaseService<Outbound> {
|
|
|
* @date : 2024-03-08 16:38
|
|
* @date : 2024-03-08 16:38
|
|
|
*/
|
|
*/
|
|
|
public ResponseResultVO<?> invalid(String id) {
|
|
public ResponseResultVO<?> invalid(String id) {
|
|
|
|
|
+ Outbound outbound = outboundMapper.selectByIdForUpdate(id);
|
|
|
|
|
+ // 如果退货数量不是0,不能作废
|
|
|
|
|
+ if (!outbound.getReturnQty().equals(new BigDecimal(0))) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISEXISTS_AFTER_OPERATE.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ double sumOutingQty = 0; // 合计出库中数量
|
|
|
|
|
+ double sumOutingAmt = 0; // 合计出库中金额
|
|
|
|
|
+ List<OutboundItem> outboundItemList = outboundItemMapper.selectByZIdForUpdate(id);
|
|
|
|
|
+ OrderItem orderItemForUpdate;
|
|
|
|
|
+ for (OutboundItem outboundItemForUpdate : outboundItemList) {
|
|
|
|
|
+ orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItemForUpdate.getFromItemId());
|
|
|
|
|
+ // 更新订单明细出库中数量
|
|
|
|
|
+ OrderItem orderItemUpdate = new OrderItem();
|
|
|
|
|
+ orderItemUpdate.setOutingQty(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()))
|
|
|
|
|
+ .setOutingAmt(orderItemForUpdate.getOutingAmt().subtract(outboundItemForUpdate.getOutingAmt()))
|
|
|
|
|
+ .setItemId(orderItemForUpdate.getItemId());
|
|
|
|
|
+ orderItemService.updateByUuid(orderItemUpdate);
|
|
|
|
|
+
|
|
|
|
|
+ // 累加出库中数量,金额
|
|
|
|
|
+ sumOutingQty += outboundItemForUpdate.getOutingQty().doubleValue();
|
|
|
|
|
+ sumOutingAmt += outboundItemForUpdate.getOutingAmt().doubleValue();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 更新订单上的出库中数量,金额,状态
|
|
|
|
|
+ Order orderForUpdate = orderMapper.selectByIdForUpdate(outbound.getFromId());
|
|
|
|
|
+ Order orderUpdate = new Order();
|
|
|
|
|
+ orderUpdate.setOutingQty(orderForUpdate.getOutingQty().subtract(new BigDecimal(sumOutingQty)))
|
|
|
|
|
+ .setOutingAmt(orderForUpdate.getOutingAmt().subtract(new BigDecimal(sumOutingAmt)))
|
|
|
|
|
+ .setOrderId(outbound.getFromId());
|
|
|
|
|
+ // 如果出库中数量为0了,更新状态为待出库
|
|
|
|
|
+ if(orderUpdate.getOutingQty().equals(new BigDecimal(0))){
|
|
|
|
|
+ orderUpdate.setOutStatus(Constant.OutStatus.DAICHUKU.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ orderService.updateByUuid(orderUpdate);
|
|
|
|
|
+
|
|
|
|
|
+ // 作废
|
|
|
|
|
+ Outbound outboundUpdate = new Outbound();
|
|
|
|
|
+ outboundUpdate.setFlgValid(false).setOutId(id);
|
|
|
|
|
+ super.update(outboundUpdate, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
|
|
|
|
|
+ UUID.fromString(outboundUpdate.getOutId())));
|
|
|
return ResponseResultUtil.success();
|
|
return ResponseResultUtil.success();
|
|
|
}
|
|
}
|
|
|
|
|
|