Browse Source

增加分离id批量查询发货提醒的方法

hejq 7 years ago
parent
commit
b8cd19a7c5

+ 13 - 9
src/main/java/com/uas/platform/b2b/dao/PurchaseInquiryItemDao.java

@@ -10,11 +10,11 @@ import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 import org.springframework.stereotype.Repository;
 
 
 import javax.transaction.Transactional;
 import javax.transaction.Transactional;
+import java.sql.SQLException;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
 
 
 @Repository
 @Repository
-@Transactional
 public interface PurchaseInquiryItemDao extends JpaSpecificationExecutor<PurchaseInquiryItem>, JpaRepository<PurchaseInquiryItem, Long> {
 public interface PurchaseInquiryItemDao extends JpaSpecificationExecutor<PurchaseInquiryItem>, JpaRepository<PurchaseInquiryItem, Long> {
 
 
 	/**
 	/**
@@ -57,13 +57,17 @@ public interface PurchaseInquiryItemDao extends JpaSpecificationExecutor<Purchas
 	@Query("from PurchaseInquiryItem d where d.inquiry.enUU = :enUU and d.inquiry.code = :code and d.number = :number")
 	@Query("from PurchaseInquiryItem d where d.inquiry.enUU = :enUU and d.inquiry.code = :code and d.number = :number")
 	List<PurchaseInquiryItem> findByEnUUAndCodeAndNumber(@Param("enUU") long enUU, @Param("code") String code, @Param("number") short number);
 	List<PurchaseInquiryItem> findByEnUUAndCodeAndNumber(@Param("enUU") long enUU, @Param("code") String code, @Param("number") short number);
 
 
-	/**
-	 * 按询价单明细ID更新采纳结果
-	 * 
-	 */
+    /**
+     * 按询价单明细ID更新采纳结果
+     *
+     * @param agreed 采纳结果
+     * @param decideStatus 采纳状态
+     * @param id 明细id
+     */
 	@Modifying(clearAutomatically = true)
 	@Modifying(clearAutomatically = true)
+	@Transactional(rollbackOn = SQLException.class)
 	@Query("update PurchaseInquiryItem p set p.agreed = :agreed,p.decideStatus = :decideStatus where p.id = :id")
 	@Query("update PurchaseInquiryItem p set p.agreed = :agreed,p.decideStatus = :decideStatus where p.id = :id")
-	public void updateDecideStatusByID(@Param("agreed") short agreed, @Param("decideStatus") short decideStatus, @Param("id") Long id);
+	void updateDecideStatusByID(@Param("agreed") short agreed, @Param("decideStatus") short decideStatus, @Param("id") Long id);
 
 
 	/**
 	/**
 	 * 按卖家企业ID和询价明细的报价信息传到卖家ERP的状态查找询价明细
 	 * 按卖家企业ID和询价明细的报价信息传到卖家ERP的状态查找询价明细
@@ -105,11 +109,11 @@ public interface PurchaseInquiryItemDao extends JpaSpecificationExecutor<Purchas
 	/**
 	/**
 	 * 根据企业UU号查询询价单(明细)总数量
 	 * 根据企业UU号查询询价单(明细)总数量
 	 * 
 	 * 
-	 * @param enUU
+	 * @param enUU 企业UU
 	 * @return
 	 * @return
 	 */
 	 */
 	@Query("select count(*) from PurchaseInquiryItem i where i.inquiry.enUU = :enUU")
 	@Query("select count(*) from PurchaseInquiryItem i where i.inquiry.enUU = :enUU")
-	public Long getCountByEnUU(@Param("enUU") long enUU);
+	Long getCountByEnUU(@Param("enUU") long enUU);
 
 
 	/**
 	/**
 	 * 根据企业UU号查询询价单(明细)总数量
 	 * 根据企业UU号查询询价单(明细)总数量
@@ -118,7 +122,7 @@ public interface PurchaseInquiryItemDao extends JpaSpecificationExecutor<Purchas
 	 * @return
 	 * @return
 	 */
 	 */
 	@Query("select count(*) from PurchaseInquiryItem i where i.inquiry.enUU = :enUU and i.vendToDate is not null and  i.vendToDate <= :date")
 	@Query("select count(*) from PurchaseInquiryItem i where i.inquiry.enUU = :enUU and i.vendToDate is not null and  i.vendToDate <= :date")
-	public Long getOverdueCountByEnUU(@Param("enUU") long enUU, @Param("date") Date date);
+	Long getOverdueCountByEnUU(@Param("enUU") long enUU, @Param("date") Date date);
 
 
 	/**
 	/**
 	 * 根据企业UU昊查询已报价询价单数量
 	 * 根据企业UU昊查询已报价询价单数量

+ 77 - 63
src/main/java/com/uas/platform/b2b/dao/PurchaseNoticeDao.java

@@ -9,37 +9,60 @@ import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 import org.springframework.stereotype.Repository;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
+import java.sql.SQLException;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
 
 
+/**
+ * 发货提醒
+ * 
+ * @author hejq
+ * @date 2018-07-19 11:12
+ */
 @Repository
 @Repository
-@Transactional
 public interface PurchaseNoticeDao extends JpaSpecificationExecutor<PurchaseNotice>, JpaRepository<PurchaseNotice, Long> {
 public interface PurchaseNoticeDao extends JpaSpecificationExecutor<PurchaseNotice>, JpaRepository<PurchaseNotice, Long> {
 
 
 	/**
 	/**
-	 * 按买家企业ID和送货提醒来源ID查找送货提醒单
-	 * 
+	 * 通过enUU和来源id查询发货提醒
+	 *
+	 * @param enUU 企业UU
+	 * @param sourceId 来源id
 	 * @return
 	 * @return
 	 */
 	 */
 	List<PurchaseNotice> findByEnUUAndSourceId(long enUU, long sourceId);
 	List<PurchaseNotice> findByEnUUAndSourceId(long enUU, long sourceId);
 
 
-	/**
-	 * 按供应商企业ID和传输状态查找送货提醒单
-	 * 
-	 * @return
-	 */
+    /**
+     * 通过企业UU和来源id查询发货提醒
+     *
+     * @param enUU 企业UU
+     * @param sourceIdList 来源ID
+     * @return
+     */
+    @Query("select n from PurchaseNotice n where n.enUU = :enUU and n.sourceId in (:sourceIdList)")
+    List<PurchaseNotice> findByEnUUAndSourceIdList(@Param("enUU") Long enUU, @Param("sourceIdList") List<Long> sourceIdList);
+
+    /**
+     * 按供应商企业ID和传输状态查找送货提醒单
+     *
+     * @param vendUU 供应商UU
+     * @param sendStatus 发货状态
+     * @return
+     */
 	List<PurchaseNotice> findByVendUUAndSendStatus(long vendUU, Short sendStatus);
 	List<PurchaseNotice> findByVendUUAndSendStatus(long vendUU, Short sendStatus);
 
 
-	/**
-	 * 按供应商企业ID、是否结案和结案状态查找送货提醒
-	 * 
-	 * @return
-	 */
+    /**
+     * 按供应商企业ID、是否结案和结案状态查找送货提醒
+     *
+     * @param vendUU 供应商UU
+     * @param endStatus 结案状态
+     * @return
+     */
 	List<PurchaseNotice> findByVendUUAndEndStatus(long vendUU, Short endStatus);
 	List<PurchaseNotice> findByVendUUAndEndStatus(long vendUU, Short endStatus);
 
 
 	/**
 	/**
 	 * 按ID集合查找送货提醒
 	 * 按ID集合查找送货提醒
-	 * 
+	 *
+     * @param ids 发货提醒ID
 	 * @return
 	 * @return
 	 */
 	 */
 	@Query("select n from PurchaseNotice n where n.id IN (:ids) and (n.endQty is null or n.endQty < n.qty)")
 	@Query("select n from PurchaseNotice n where n.id IN (:ids) and (n.endQty is null or n.endQty < n.qty)")
@@ -48,78 +71,69 @@ public interface PurchaseNoticeDao extends JpaSpecificationExecutor<PurchaseNoti
 	/**
 	/**
 	 * 按送货提醒单的供应商企业ID和送货提醒单状态来统计条数
 	 * 按送货提醒单的供应商企业ID和送货提醒单状态来统计条数
 	 * 
 	 * 
-	 * @param vendUU
-	 * @param status
+	 * @param vendUU 企业UU
+	 * @param status 发货提醒状态
 	 * @return
 	 * @return
 	 */
 	 */
 	@Query("select count(n) from PurchaseNotice n where n.vendUU = :vendUU and n.status = :status and n.waiting = 0")
 	@Query("select count(n) from PurchaseNotice n where n.vendUU = :vendUU and n.status = :status and n.waiting = 0")
-	public int getCountByVendUUAndStatus(@Param("vendUU") long vendUU, @Param("status") short status);
+	int getCountByVendUUAndStatus(@Param("vendUU") long vendUU, @Param("status") short status);
 
 
 	/**
 	/**
 	 * 按发货单更新通知单的发货数
 	 * 按发货单更新通知单的发货数
-	 * 
+	 * @param id 发货单id
 	 */
 	 */
 	@Modifying(clearAutomatically = true)
 	@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")
 	@Query("update PurchaseNotice n set n.endQty=(select sum(s.qty) from SaleSendItem s where s.notice=n) where n.id= :id")
-	public void updateBySend(@Param("id") long id);
+	void updateBySend(@Param("id") long id);
 	
 	
 	/**
 	/**
 	 * 根据截止日期获取(交货日期)
 	 * 根据截止日期获取(交货日期)
-	 * @param formDate
-	 * @param endDate
+     *
+	 * @param vendUU 供应商UU
+	 * @param endDate 截止日期
 	 * @return
 	 * @return
 	 */
 	 */
 	@Query("select p.id from PurchaseNotice p where p.vendUU=:vendUU and p.delivery <= :endDate")
 	@Query("select p.id from PurchaseNotice p where p.vendUU=:vendUU and p.delivery <= :endDate")
-	public List<Long> findByEndDate(@Param("vendUU")Long vendUU, @Param("endDate")Date endDate);
+	List<Long> findByEndDate(@Param("vendUU") Long vendUU, @Param("endDate") Date endDate);
 	
 	
 	/**
 	/**
 	 * 根据起始日期获取(交货日期)
 	 * 根据起始日期获取(交货日期)
-	 * @param formDate
-	 * @param endDate
+     *
+	 * @param formDate 起始日期
+	 * @param vendUU 供应商UU
 	 * @return
 	 * @return
 	 */
 	 */
 	@Query("select p.id from PurchaseNotice p where p.vendUU=:vendUU and p.delivery >= :fromDate")
 	@Query("select p.id from PurchaseNotice p where p.vendUU=:vendUU and p.delivery >= :fromDate")
-	public List<Long> findByFromDate(@Param("vendUU")Long vendUU, @Param("fromDate")Date formDate);
+	List<Long> findByFromDate(@Param("vendUU") Long vendUU, @Param("fromDate") Date formDate);
 	
 	
 	/**
 	/**
 	 * 按送货提醒单的企业UU和送货提醒单状态来统计已发货条数
 	 * 按送货提醒单的企业UU和送货提醒单状态来统计已发货条数
 	 * 
 	 * 
-	 * @param vendUU
-	 * @param status
+	 * @param enUU 企业UU
+	 * @param status 发货状态
 	 * @return
 	 * @return
 	 */
 	 */
 	@Query("select count(n) from PurchaseNotice n where n.enUU = :enUU and n.status = :status and n.waiting = 0")
 	@Query("select count(n) from PurchaseNotice n where n.enUU = :enUU and n.status = :status and n.waiting = 0")
-	public Long getCountByEnUUAndStatus(@Param("enUU") long enUU, @Param("status") short status);
-	
-	/**
-	 * 按送货提醒单的企业UU和送货提醒单状态来统计未发货条数
-	 * 
-	 * @param vendUU
-	 * @param status
-	 * @return
-	 */
-	@Query("select count(n) from PurchaseNotice n where n.enUU = :enUU and n.status = :status and n.waiting = 0")
-	public Long getTodoCountByEnUUAndStatus(@Param("enUU") long enUU, @Param("status") short status);
-	
-	/**
-	 * 按送货提醒单的企业UU来统计备货条数
-	 * 
-	 * @param vendUU
-	 * @param status
-	 * @return
-	 */
+	Long getCountByEnUUAndStatus(@Param("enUU") long enUU, @Param("status") short status);
+
+    /**
+     * 按送货提醒单的企业UU来统计备货条数
+     *
+     * @param enUU 企业UU
+     * @return
+     */
 	@Query("select count(n) from PurchaseNotice n where n.enUU = :enUU and n.waiting = 1")
 	@Query("select count(n) from PurchaseNotice n where n.enUU = :enUU and n.waiting = 1")
-	public Long getWatingCountByEnUUAndStatus(@Param("enUU") long enUU);
-	
-	/**
-	 * 按送货提醒单的企业UU来统计已取消条数
-	 * 
-	 * @param vendUU
-	 * @param status
-	 * @return
-	 */
+	Long getWatingCountByEnUUAndStatus(@Param("enUU") long enUU);
+
+    /**
+     * 按送货提醒单的企业UU来统计已取消条数
+     *
+     * @param enUU 企业UU
+     * @return
+     */
 	@Query("select count(n) from PurchaseNotice n where n.enUU = :enUU and n.end = 1")
 	@Query("select count(n) from PurchaseNotice n where n.enUU = :enUU and n.end = 1")
-	public Long getEndCountByEnUUAndStatus(@Param("enUU") long enUU);
+	Long getEndCountByEnUUAndStatus(@Param("enUU") long enUU);
 
 
 	/**
 	/**
 	 * 根据供应商UU号获取客户发发货提醒数量
 	 * 根据供应商UU号获取客户发发货提醒数量
@@ -127,14 +141,14 @@ public interface PurchaseNoticeDao extends JpaSpecificationExecutor<PurchaseNoti
 	 * @return
 	 * @return
 	 */
 	 */
 	@Query("select count(p) from PurchaseNotice p where p.vendUU = :vendUU")
 	@Query("select count(p) from PurchaseNotice p where p.vendUU = :vendUU")
-	public long countByVendUU(@Param("vendUU")Long vendUU);
+	Long countByVendUU(@Param("vendUU")Long vendUU);
 
 
-	/**
-	 * 获得每种单据状态的未读数量
-	 *
-	 * @Param ids 未读单据id
-	 * @return
-	 */
+    /**
+     * 获得每种单据状态的未读数量
+     *
+     * @Param ids 未读单据id
+     * @return
+     */
 	@Query("select count(p), p.status from PurchaseNotice p where p.id in :ids and (p.end is null or p.end = 0) and p.waiting=0 group by p.status")
 	@Query("select count(p), p.status from PurchaseNotice p where p.id in :ids and (p.end is null or p.end = 0) and p.waiting=0 group by p.status")
 	List<Object[]> getUnreadCountEveryStatus(@Param("ids") List<Long> ids);
 	List<Object[]> getUnreadCountEveryStatus(@Param("ids") List<Long> ids);
 
 

+ 21 - 0
src/main/java/com/uas/platform/b2b/erp/model/KeyEntity.java

@@ -0,0 +1,21 @@
+package com.uas.platform.b2b.erp.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+
+/**
+ * 获取关键字
+ *
+ * @author hejq
+ * @date 2018-07-19 10:53
+ */
+public abstract class KeyEntity {
+
+    /**
+     * 主键值
+     *
+     * @return
+     */
+    @JsonIgnore
+    public abstract Object getKey();
+}

+ 23 - 5
src/main/java/com/uas/platform/b2b/erp/model/PurchaseNotify.java

@@ -14,7 +14,7 @@ import java.util.Date;
  * @author yingp
  * @author yingp
  * 
  * 
  */
  */
-public class PurchaseNotify {
+public class PurchaseNotify extends KeyEntity {
 
 
 	/**
 	/**
 	 * 原id,erp id
 	 * 原id,erp id
@@ -52,8 +52,16 @@ public class PurchaseNotify {
 	 * 已发货数量
 	 * 已发货数量
 	 */
 	 */
 	private Double pn_endqty;
 	private Double pn_endqty;
-	private Double pr_zxbzs; // 物料最小包装数
-	private Long pn_b2bid; // b2bid
+
+	/**
+	 *  物料最小包装数
+	 */
+	private Double pr_zxbzs;
+
+	/**
+	 * b2bid
+	 */
+	private Long pn_b2bid;
 
 
 	public long getPn_id() {
 	public long getPn_id() {
 		return pn_id;
 		return pn_id;
@@ -166,7 +174,7 @@ public class PurchaseNotify {
 		notice.setOrderItem(orderItem);
 		notice.setOrderItem(orderItem);
 		notice.setStatus((short) Status.NOT_REPLY.value());
 		notice.setStatus((short) Status.NOT_REPLY.value());
 		notice.setSendStatus((short) Status.NOT_UPLOAD.value());
 		notice.setSendStatus((short) Status.NOT_UPLOAD.value());
-		notice.setMinPackQty(pr_zxbzs);// 物料最小包装数
+		notice.setMinPackQty(pr_zxbzs);
 		notice.setErpDate(new Date());
 		notice.setErpDate(new Date());
 		return notice;
 		return notice;
 	}
 	}
@@ -194,7 +202,7 @@ public class PurchaseNotify {
 		notice.setOrderItem(orderItem);
 		notice.setOrderItem(orderItem);
 		notice.setStatus((short) Status.NOT_REPLY.value());
 		notice.setStatus((short) Status.NOT_REPLY.value());
 		notice.setSendStatus((short) Status.NOT_UPLOAD.value());
 		notice.setSendStatus((short) Status.NOT_UPLOAD.value());
-		notice.setMinPackQty(pr_zxbzs);// 物料最小包装数
+		notice.setMinPackQty(pr_zxbzs);
 		notice.setErpDate(new Date());
 		notice.setErpDate(new Date());
 		return notice;
 		return notice;
 	}
 	}
@@ -210,4 +218,14 @@ public class PurchaseNotify {
 	}
 	}
 
 
 	public PurchaseNotify() {}
 	public PurchaseNotify() {}
+
+    /**
+     * 关键字
+     *
+     * @return
+     */
+    @Override
+    public Object getKey() {
+        return pn_id;
+    }
 }
 }

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

@@ -13,10 +13,7 @@ import com.uas.platform.b2b.model.*;
 import com.uas.platform.b2b.ps.service.PersonalProductService;
 import com.uas.platform.b2b.ps.service.PersonalProductService;
 import com.uas.platform.b2b.search.SearchService;
 import com.uas.platform.b2b.search.SearchService;
 import com.uas.platform.b2b.service.PurchaseNoticeService;
 import com.uas.platform.b2b.service.PurchaseNoticeService;
-import com.uas.platform.b2b.support.SPageUtils;
-import com.uas.platform.b2b.support.SystemSession;
-import com.uas.platform.b2b.support.UsageBufferedLogger;
-import com.uas.platform.b2b.support.XingePusher;
+import com.uas.platform.b2b.support.*;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.logging.BufferedLoggerManager;
 import com.uas.platform.core.logging.BufferedLoggerManager;
 import com.uas.platform.core.model.Constant;
 import com.uas.platform.core.model.Constant;
@@ -320,23 +317,22 @@ public class PurchaseNoticeServiceImpl implements PurchaseNoticeService {
 	public void end(List<PurchaseNotify> notifies) {
 	public void end(List<PurchaseNotify> notifies) {
 		long enUU = SystemSession.getUser().getEnterprise().getUu();
 		long enUU = SystemSession.getUser().getEnterprise().getUu();
 		List<PurchaseNotice> saveList = new ArrayList<>();
 		List<PurchaseNotice> saveList = new ArrayList<>();
-		for (PurchaseNotify notify : notifies) {
-			List<PurchaseNotice> notices = purchaseNoticeDao.findByEnUUAndSourceId(enUU, notify.getPn_id());
-			if (!CollectionUtils.isEmpty(notices)) {
-				PurchaseNotice notice = notices.get(0);
-				notice.setEnd(Constant.YES);
-				notice.setEndStatus((short) Status.NOT_UPLOAD.value());
-				notice.setErpDate(new Date(System.currentTimeMillis()));
-				saveList.add(notice);
-				// 推送结案送回提醒给采购单供应商联系人
-				Long vendUserUU = notice.getOrderItem().getOrder().getVendUserUU();
-				if (vendUserUU != null) {
-					UserBaseInfo user = userBaseInfoDao.findOne(vendUserUU);
-					XingePusher.pushByUser(user, "客户取消了送货提醒", "物料:" + notice.getOrderItem().getProduct().getTitle(), "",
-							"");
-				}
-			}
-		}
+		List<PurchaseNotice> noticeList = purchaseNoticeDao.findByEnUUAndSourceIdList(enUU, CollectionUtil.getKeyCollection(notifies));
+		if (!CollectionUtils.isEmpty(noticeList)) {
+		    for (PurchaseNotice notice : noticeList) {
+                notice.setEnd(Constant.YES);
+                notice.setEndStatus((short) Status.NOT_UPLOAD.value());
+                notice.setErpDate(new Date(System.currentTimeMillis()));
+                saveList.add(notice);
+                // 推送结案送回提醒给采购单供应商联系人
+                Long vendUserUU = notice.getOrderItem().getOrder().getVendUserUU();
+                if (vendUserUU != null) {
+                    UserBaseInfo user = userBaseInfoDao.findOne(vendUserUU);
+                    XingePusher.pushByUser(user, "客户取消了送货提醒", "物料:" + notice.getOrderItem().getProduct().getTitle(), "",
+                            "");
+                }
+            }
+        }
         purchaseNoticeDao.save(saveList);
         purchaseNoticeDao.save(saveList);
 		ContextUtils.publishEvent(new PurchaseNoticeEndReleaseEvent(saveList));
 		ContextUtils.publishEvent(new PurchaseNoticeEndReleaseEvent(saveList));
 	}
 	}

+ 36 - 0
src/main/java/com/uas/platform/b2b/support/CollectionUtil.java

@@ -0,0 +1,36 @@
+package com.uas.platform.b2b.support;
+
+import com.uas.platform.b2b.erp.model.KeyEntity;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 集合处理工具类
+ *
+ * @author hejq
+ * @date 2018-07-19 11:03
+ */
+public class CollectionUtil {
+
+    /**
+     * 用继承自KeyEntity的类,重写的getKey方法来取值,封装成List一次性查询数据
+     *
+     * @param paramArray
+     * @return
+     */
+    public static List<Long> getKeyCollection(Collection<? extends KeyEntity> paramArray) {
+        List<Long> idList = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(paramArray)) {
+            for (KeyEntity param : paramArray) {
+                Object val = param.getKey();
+                if (val != null) {
+                    idList.add(Long.valueOf(val.toString()));
+                }
+            }
+        }
+        return idList;
+    }
+}