Procházet zdrojové kódy

供应商发货时增加对采购需求数量以发货数量对比判断

hejq před 7 roky
rodič
revize
530694c457

+ 9 - 1
src/main/java/com/uas/platform/b2b/dao/PurchaseNoticeDao.java

@@ -162,8 +162,16 @@ public interface PurchaseNoticeDao extends JpaSpecificationExecutor<PurchaseNoti
 	 * @param noticeId 发货提醒id
 	 * @param status 状态
 	 */
-	@Transactional
+	@Transactional(rollbackFor = Exception.class)
     @Modifying(clearAutomatically = true)
 	@Query("update PurchaseNotice set status = :status where id = :noticeId")
 	void updateStatus(@Param("noticeId") Long noticeId, @Param("status") short status);
+
+	/**
+	 * 通过采购单明细id查询对应的所有的发货提醒
+	 *
+	 * @param orderItemId 采购单明细id
+	 * @return
+	 */
+    List<PurchaseNotice> findByOrderItemId(Long orderItemId);
 }

+ 30 - 0
src/main/java/com/uas/platform/b2b/service/impl/PurchaseNoticeServiceImpl.java

@@ -106,6 +106,9 @@ public class PurchaseNoticeServiceImpl implements PurchaseNoticeService {
 	@Autowired
     private PersonalProductService personalProductService;
 
+	@Autowired
+	private PurchaseOrderItemDao orderItemDao;
+
     /**
      * 最多数量
      */
@@ -372,6 +375,8 @@ public class PurchaseNoticeServiceImpl implements PurchaseNoticeService {
 			if (endQty > notice.getQty()) {
 				throw new IllegalOperatorException("累计发货数量将超出本次送货提醒的需求数!");
 			}
+			// 检验采购单需求数量
+			checkOrderQty(notice, thisQty);
 			PurchaseOrder order = notice.getOrderItem().getOrder();
 			send.setCurrency(order.getCurrency());
 			send.setBackStatus((short) Status.NOT_UPLOAD.value());
@@ -411,6 +416,31 @@ public class PurchaseNoticeServiceImpl implements PurchaseNoticeService {
 		}
 	}
 
+	/**
+	 * 校验发货提醒与采购单需求数量对比
+     *
+	 * @param notice 发货提醒
+	 * @param thisQty 本次发货数量
+	 */
+	private void checkOrderQty(PurchaseNotice notice, double thisQty) {
+		List<PurchaseNotice> notices = purchaseNoticeDao.findByOrderItemId(notice.getOrderItemId());
+		PurchaseOrderItem item = orderItemDao.findOne(notice.getOrderItemId());
+		// 查询所有已发货数量
+		Double sendQty = 0.0;
+		for (PurchaseNotice purchaseNotice : notices) {
+			if (purchaseNotice.getEnd() != null) {
+				if (purchaseNotice.getEnd() != 1) {
+					sendQty += purchaseNotice.getEndQty();
+				}
+			} else {
+				sendQty += purchaseNotice.getEndQty();
+			}
+		}
+		if (sendQty + thisQty > item.getQty()) {
+			throw new IllegalOperatorException("该采购单已发货数量[" + sendQty + "]本次发货数量["
+					+ thisQty + "]总数超过订单需求数量[" + item.getQty() + "],请核对数量后重新发货");
+		}
+	}
     @Override
 	public int getOnhandCount() {
 		return purchaseNoticeDao.getCountByVendUUAndStatus(SystemSession.getUser().getEnterprise().getUu(),