|
|
@ -9,6 +9,10 @@ import com.xujie.sys.modules.deliverySchedule.service.DeliveryScheduleService; |
|
|
import com.xujie.sys.modules.deliverySchedule.mapper.DeliveryScheduleMapper; |
|
|
import com.xujie.sys.modules.deliverySchedule.mapper.DeliveryScheduleMapper; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @author Jia |
|
|
* @author Jia |
|
|
@ -34,13 +38,29 @@ public class DeliveryScheduleServiceImpl extends ServiceImpl<DeliveryScheduleMap |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public void autoReservationInitiateHandler(DeliveryScheduleData data) { |
|
|
public void autoReservationInitiateHandler(DeliveryScheduleData data) { |
|
|
Double allotmentQty = data.getAllotmentQty(); |
|
|
Double allotmentQty = data.getAllotmentQty(); |
|
|
|
|
|
List<Double> pendingQtyList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
for (DeliveryScheduleData deliveryScheduleData : data.getAutoReservationDataList()) { |
|
|
for (DeliveryScheduleData deliveryScheduleData : data.getAutoReservationDataList()) { |
|
|
double pendingQty = deliveryScheduleData.getQty() - deliveryScheduleData.getDelNotifyQty(); |
|
|
|
|
|
if (allotmentQty <= 0){ |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
double pendingQty = 0.0; |
|
|
|
|
|
if (deliveryScheduleData.getDelNotifyQty() == null){ |
|
|
|
|
|
pendingQty = deliveryScheduleData.getQty(); |
|
|
|
|
|
}else { |
|
|
|
|
|
pendingQty = deliveryScheduleData.getQty() - deliveryScheduleData.getDelNotifyQty(); |
|
|
} |
|
|
} |
|
|
|
|
|
pendingQtyList.add(pendingQty); |
|
|
|
|
|
// 如果是最后一个循环 |
|
|
|
|
|
if (data.getAutoReservationDataList().indexOf(deliveryScheduleData) == data.getAutoReservationDataList().size() - 1){ |
|
|
|
|
|
double sum = pendingQtyList.stream().mapToDouble(Double::doubleValue).sum(); |
|
|
|
|
|
if (sum <= 0){ |
|
|
|
|
|
throw new RuntimeException("请检查订单是否已经发货!"); |
|
|
|
|
|
} |
|
|
|
|
|
if (pendingQty < allotmentQty) { |
|
|
|
|
|
throw new RuntimeException("总待发货数量超过总订单数量,无法自动预留!"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
if (pendingQty <= allotmentQty){ |
|
|
if (pendingQty <= allotmentQty){ |
|
|
deliveryScheduleData.setDeliveryQty(pendingQty); |
|
|
deliveryScheduleData.setDeliveryQty(pendingQty); |
|
|
baseMapper.updateSupplierDeliveryScheduleDeliveryQty(deliveryScheduleData); |
|
|
baseMapper.updateSupplierDeliveryScheduleDeliveryQty(deliveryScheduleData); |
|
|
|