Browse Source

发货提醒数量更新记录日志

hejq 7 years ago
parent
commit
ee56011b5f

+ 7 - 6
src/main/java/com/uas/platform/b2b/dao/PurchaseNoticeDao.java

@@ -68,14 +68,15 @@ public interface PurchaseNoticeDao extends JpaSpecificationExecutor<PurchaseNoti
 	@Query("select count(n) from PurchaseNotice n where n.vendUU = :vendUU and n.status = :status and n.waiting = 0")
 	int getCountByVendUUAndStatus(@Param("vendUU") long vendUU, @Param("status") short status);
 
-	/**
-	 * 按发货单更新通知单的发货数
-	 * @param id 发货单id
-	 */
+    /**
+     * 按发货单更新通知单的发货数
+     * @param id 发货单id
+     * @param sendQty 已发货数量
+     */
 	@Modifying(clearAutomatically = true)
     @Transactional(rollbackFor = SQLException.class)
-	@Query("update PurchaseNotice n set n.endQty=(select sum(s.qty) from SaleSendItem s where s.notice=n) where n.id= :id")
-	void updateBySend(@Param("id") long id);
+	@Query("update PurchaseNotice n set n.endQty= :sendQty where n.id= :id")
+	void updateBySend(@Param("id") long id, @Param("sendQty") Double sendQty);
 	
 	/**
 	 * 根据截止日期获取(交货日期)

+ 16 - 7
src/main/java/com/uas/platform/b2b/dao/SaleSendItemDao.java

@@ -1,7 +1,6 @@
 package com.uas.platform.b2b.dao;
 
-import java.util.List;
-
+import com.uas.platform.b2b.model.SaleSendItem;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
@@ -10,10 +9,10 @@ import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 import org.springframework.transaction.annotation.Transactional;
 
-import com.uas.platform.b2b.model.SaleSendItem;
+import java.sql.SQLException;
+import java.util.List;
 
 @Repository
-@Transactional
 public interface SaleSendItemDao extends JpaSpecificationExecutor<SaleSendItem>, JpaRepository<SaleSendItem, Long> {
 
 	/**
@@ -40,6 +39,7 @@ public interface SaleSendItemDao extends JpaSpecificationExecutor<SaleSendItem>,
 	 */
 	@Modifying(clearAutomatically = true)
 	@Query("update SaleSendItem s set s.qty = :qty,s.replyRemark = :remark where s.id= :id")
+	@Transactional(rollbackFor = SQLException.class)
 	public void updateByReply(@Param("id") long id, @Param("qty") double qty, @Param("remark") String remark);
 	
 	/**
@@ -50,6 +50,7 @@ public interface SaleSendItemDao extends JpaSpecificationExecutor<SaleSendItem>,
 	@Modifying(clearAutomatically = true)
 	@Query(nativeQuery = true,
 		value = "update sale$senditem si set si_verifyqty = (select sum(siv_qty) from SALE$SENDITEMVERIFY siv where siv.SIV_SENDITEMID = si.SI_ID ), si_okqty = (select sum(siv_okqty) from SALE$SENDITEMVERIFY siv where siv.SIV_SENDITEMID = si.SI_ID ), si_notokqty = (select sum(siv_notokqty) from SALE$SENDITEMVERIFY siv where siv.SIV_SENDITEMID = si.SI_ID ) where si.si_id= :id")
+	@Transactional(rollbackFor = SQLException.class)
 	public void updateByVerify(@Param("id") long id);
 	
 	/**
@@ -76,8 +77,16 @@ public interface SaleSendItemDao extends JpaSpecificationExecutor<SaleSendItem>,
 	 */
 	@Modifying
 	@Query("update SaleSendItem s set s.packageQty = :packageQty,s.outBoxQty = :outBoxQty where s.id= :id")
-	public void updatePackageQty(@Param("id") long id, @Param("packageQty") Double packageQty, @Param("outBoxQty") Double outBoxQty);
-	
-	
+	@Transactional(rollbackFor = SQLException.class)
+	void updatePackageQty(@Param("id") long id, @Param("packageQty") Double packageQty, @Param("outBoxQty") Double outBoxQty);
+
+    /**
+     * 根据发货提醒id获取已发货数量
+     *
+     * @param noticeId 发货提醒id
+     * @return 该发货提醒已发货的数量
+     */
+	@Query("select sum(s.qty) from SaleSendItem s where s.noticeId= :noticeId")
+	Double getSendQtyByNoticeId(@Param("noticeId") Long noticeId);
 
 }

+ 16 - 21
src/main/java/com/uas/platform/b2b/erp/service/impl/PurchaseNotifyServiceImpl.java

@@ -71,28 +71,23 @@ public class PurchaseNotifyServiceImpl implements PurchaseNotifyService {
 				}
 				// 对卖家传输状态 // 待上传
 				existNotice.setSendStatus((short) Status.NOT_UPLOAD.value());
-				Double sendQty = purchaseNoticeDao.getSendQtyByItemId(notice.getOrderItemId());
 				if (existNotice.getQty() != null && !existNotice.getQty().equals(notice.getQty())) {
-				    // 先判断本次需求数量+已发货数量与订单需求数量大小
-                    Double needQty = sendQty + notice.getQty();
-                    if (needQty <= notice.getOrderItem().getQty()) {
-                        if (existNotice.getEndQty() > notice.getQty()) {
-                            // 已发货数大于新的需求数,修改平台上的需求数为已发货数,将已发货数量传回买家ERP修改发货提醒的数量
-                            existNotice.setRemark(remark + dateString + "修改需求数量," + existNotice.getQty() + " -> "
-                                    + existNotice.getEndQty());
-                            // 需求数量
-                            existNotice.setQty(existNotice.getEndQty());
-                            // 状态  已回复
-                            existNotice.setStatus((short) Status.REPLIED.value());
-                            notices.add(existNotice);
-                        } else {
-                            // 已发货数小于或等于新的需求数,修改平台上的需求数为新的需求数
-                            existNotice.setRemark(
-                                    remark + dateString + "修改需求数量," + existNotice.getQty() + " -> " + notice.getQty());
-                            existNotice.setQty(notice.getQty());
-                            existNotice.setDelivery(notice.getDelivery());
-                            notices.add(existNotice);
-                        }
+                    if (existNotice.getEndQty() > notice.getQty()) {
+                        // 已发货数大于新的需求数,修改平台上的需求数为已发货数,将已发货数量传回买家ERP修改发货提醒的数量
+                        existNotice.setRemark(remark + dateString + "修改需求数量," + existNotice.getQty() + " -> "
+                                + existNotice.getEndQty());
+                        // 需求数量
+                        existNotice.setQty(existNotice.getEndQty());
+                        // 状态  已回复
+                        existNotice.setStatus((short) Status.REPLIED.value());
+                        notices.add(existNotice);
+                    } else {
+                        // 已发货数小于或等于新的需求数,修改平台上的需求数为新的需求数
+                        existNotice.setRemark(
+                                remark + dateString + "修改需求数量," + existNotice.getQty() + " -> " + notice.getQty());
+                        existNotice.setQty(notice.getQty());
+                        existNotice.setDelivery(notice.getDelivery());
+                        notices.add(existNotice);
                     }
 				} else {
 					String existDeliveryStr = "空";

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

@@ -6,7 +6,6 @@ import com.uas.platform.b2b.core.util.ThreadTask;
 import com.uas.platform.b2b.dao.*;
 import com.uas.platform.b2b.erp.model.PurchaseNotify;
 import com.uas.platform.b2b.event.SaleSendAcceptReleaseEvent;
-import com.uas.platform.b2b.event.SaleSendRefuseReleaseEvent;
 import com.uas.platform.b2b.model.*;
 import com.uas.platform.b2b.ps.service.PersonalProductService;
 import com.uas.platform.b2b.search.SearchService;
@@ -243,7 +242,10 @@ public class PurchaseNoticeServiceImpl implements PurchaseNoticeService {
 		saleSendItemDao.save(sendItems);
 		for (SaleSendItem item : sendItems) {
 			if (item.getNoticeId() != null) {
-				purchaseNoticeDao.updateBySend(item.getNoticeId());
+			    Double sendQty = saleSendItemDao.getSendQtyByNoticeId(item.getNoticeId());
+				purchaseNoticeDao.updateBySend(item.getNoticeId(), sendQty);
+                logger.log("更新发货提醒发货数量", "ERP主动收料通知单/上传发货单更新发货提醒已发货数量",
+                        "发货单: " + item.getNoticeId() + ",更新数量: " + sendQty);
 				// 更新发货状态
 				updateNoticeStatus(item.getNoticeId());
 			}
@@ -474,18 +476,16 @@ public class PurchaseNoticeServiceImpl implements PurchaseNoticeService {
 
 	@Override
 	public void onSaleSendChange(List<SaleSendItem> sendItems) {
-		List<Long> ids = new ArrayList<>();
 		for (SaleSendItem item : sendItems) {
 			saleSendItemDao.updateByReply(item.getId(), item.getQty(), item.getReplyRemark());
 			if (item.getNoticeId() != null) {
-				purchaseNoticeDao.updateBySend(item.getNoticeId());
+			    Double sendQty = saleSendItemDao.getSendQtyByNoticeId(item.getNoticeId());
+				purchaseNoticeDao.updateBySend(item.getNoticeId(), sendQty);
+                logger.log("更新发货提醒发货数量", "ERP上传收料通知的确认数量更新发货提醒已发货数量",
+                        "发货单: " + item.getNoticeId() + ",更新数量: " + sendQty);
                 updateNoticeStatus(item.getNoticeId());
-				ids.add(item.getNoticeId());
 			}
 		}
-		List<PurchaseNotice> notices = purchaseNoticeDao.findAll(ids);
-		// 买家拒收之后给卖家发消息
-		ContextUtils.publishEvent(new SaleSendRefuseReleaseEvent(SaleSendItem.distinct(sendItems)));
 	}
 
     /**