Browse Source

feat(notice):新增代采自动发货

Hu Jie 7 năm trước cách đây
mục cha
commit
80c49c67e9

+ 6 - 17
src/main/java/com/uas/platform/b2b/erp/service/impl/PurchaseNotifyServiceImpl.java

@@ -57,23 +57,12 @@ public class PurchaseNotifyServiceImpl implements PurchaseNotifyService {
 			List<PurchaseNotice> existNotices = purchaseNoticeDao.findByEnUUAndSourceId(notice.getEnUU(), notice.getSourceId());
 			// sourceId不存在新增保存
 			if (CollectionUtils.isEmpty(existNotices)) {
-				// 终端供应商uu存在
-				if (!StringUtils.isEmpty(notify.getPn_terminalvenduu()) && notify.getPn_terminalvenduu() != 0) {
-					List<PurchaseOrderItem> itemList = purchaseOrderItemDao.findByCustpurchasecodeAndCustpurchasedetno(notice.getVendUU(), notice.getOrderItem().getOrder().getCode(),
-							notice.getOrderItem().getNumber());
-					if (!CollectionUtils.isEmpty(itemList)) {
-						notice.setOrderItemId(itemList.get(0).getId());
-						notice.setOrderItem(null);
-						notices.add(notice);
-					}
-				} else {
-					List<Long> idList = purchaseOrderItemDao.findIdByEnUUAndOrderCodeAndNumber(notice.getEnUU(),
-							notice.getOrderItem().getOrder().getCode(), notice.getOrderItem().getNumber());
-					if (!CollectionUtils.isEmpty(idList)) {
-						notice.setOrderItemId(idList.get(0));
-						notice.setOrderItem(null);
-						notices.add(notice);
-					}
+				List<Long> idList = purchaseOrderItemDao.findIdByEnUUAndOrderCodeAndNumber(notice.getEnUU(),
+						notice.getOrderItem().getOrder().getCode(), notice.getOrderItem().getNumber());
+				if (!CollectionUtils.isEmpty(idList)) {
+					notice.setOrderItemId(idList.get(0));
+					notice.setOrderItem(null);
+					notices.add(notice);
 				}
 				// 对现有的单据,修改
 			} else {

+ 13 - 1
src/main/java/com/uas/platform/b2b/event/SaleSendAgentEvent.java

@@ -1,6 +1,7 @@
 package com.uas.platform.b2b.event;
 
 import com.uas.platform.b2b.model.PurchaseNotice;
+import com.uas.platform.b2b.model.SaleSend;
 import org.springframework.context.ApplicationEvent;
 
 /**
@@ -14,9 +15,12 @@ public class SaleSendAgentEvent extends ApplicationEvent {
 
     private PurchaseNotice notice;
 
-    public SaleSendAgentEvent(PurchaseNotice notice) {
+    private SaleSend saleSend;
+
+    public SaleSendAgentEvent(PurchaseNotice notice, SaleSend saleSend) {
         super(notice);
         this.notice = notice;
+        this.saleSend = saleSend;
     }
 
     public PurchaseNotice getNotice() {
@@ -26,4 +30,12 @@ public class SaleSendAgentEvent extends ApplicationEvent {
     public void setNotice(PurchaseNotice notice) {
         this.notice = notice;
     }
+
+    public SaleSend getSaleSend() {
+        return saleSend;
+    }
+
+    public void setSaleSend(SaleSend saleSend) {
+        this.saleSend = saleSend;
+    }
 }

+ 25 - 0
src/main/java/com/uas/platform/b2b/event/SaleSendAgentListener.java

@@ -1,17 +1,27 @@
 package com.uas.platform.b2b.event;
 
 import com.uas.platform.b2b.model.PurchaseNotice;
+import com.uas.platform.b2b.model.SaleSend;
+import com.uas.platform.b2b.service.SaleSendAgentService;
 import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationListener;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
 
 /**
  * @Author: huj
  * @Date: Created in 17:29 2018/12/10.
  */
 @Component
+@EnableAsync
 public class SaleSendAgentListener implements ApplicationListener<SaleSendAgentEvent> {
 
+    @Autowired
+    SaleSendAgentService saleSendService;
+
     private final static Logger LOGGER = Logger.getLogger(SaleSendAgentListener.class);
 
     /**
@@ -19,9 +29,24 @@ public class SaleSendAgentListener implements ApplicationListener<SaleSendAgentE
      *
      * @param event the event to respond to
      */
+    @Async
     @Override
     public void onApplicationEvent(SaleSendAgentEvent event) {
         PurchaseNotice notice = event.getNotice();
+        SaleSend saleSend = event.getSaleSend();
         // do something
+//        try {
+//            Thread.sleep(10000);//让线程休眠,根据输出结果判断主线程和从线程是同步还是异步
+//            System.out.println("异步threadId:"+Thread.currentThread().getId());
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+        LOGGER.info(String.format("代采订单开始发货,客户送货提醒id:%s,送货提醒id:%s", notice.getSaleNoticeId(), notice.getId()));
+        SaleSend send = saleSendService.send(notice, saleSend);
+        if (!StringUtils.isEmpty(send)) {
+            LOGGER.info(String.format("代采订单发货成功,客户送货提醒id:%s,送货提醒id:%s", notice.getSaleNoticeId(), notice.getId()));
+        } else {
+            LOGGER.error(String.format("代采订单发货失败,客户送货提醒id:%s,送货提醒id:%s", notice.getSaleNoticeId(), notice.getId()));
+        }
     }
 }

+ 16 - 0
src/main/java/com/uas/platform/b2b/model/PurchaseNotice.java

@@ -141,6 +141,22 @@ public class PurchaseNotice implements Serializable {
 	@Column(name = "pn_erpdate")
 	private Date erpDate;
 
+	/**
+	 * 客户送货提醒号(代采)
+	 *
+	 * @return
+	 */
+	@Column(name = "pn_salenoticeid")
+	private Long saleNoticeId;
+
+	public Long getSaleNoticeId() {
+		return saleNoticeId;
+	}
+
+	public void setSaleNoticeId(Long saleNoticeId) {
+		this.saleNoticeId = saleNoticeId;
+	}
+
 	public Long getId() {
 		return id;
 	}

+ 19 - 0
src/main/java/com/uas/platform/b2b/service/SaleSendAgentService.java

@@ -0,0 +1,19 @@
+package com.uas.platform.b2b.service;
+
+import com.uas.platform.b2b.model.PurchaseNotice;
+import com.uas.platform.b2b.model.SaleSend;
+
+/**
+ * @Author: huj
+ * @Date: Created in 09:16 2018/12/11.
+ */
+public interface SaleSendAgentService {
+
+    /**
+     * 代采订单发货
+     * @param purchaseNotice 发货提醒
+     * @param saleSend 发货单
+     * @return 送货单
+     */
+    SaleSend send(PurchaseNotice notice, SaleSend saleSend);
+}

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

@@ -50,6 +50,7 @@ import com.uas.platform.core.model.Status;
 import com.uas.platform.core.persistence.criteria.PredicateUtils;
 import com.uas.search.b2b.model.SPage;
 import org.apache.commons.collections.CollectionUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
@@ -363,13 +364,6 @@ public class PurchaseNoticeServiceImpl implements PurchaseNoticeService {
 			// 未收料
 			send.setVerifystatus(Constant.NO);
 			send.setCustUU(notice.getEnUU());
-			/*
-			if (!StringUtils.isEmpty(notice.getOrderItem().getCustPurchaseCode())) {
-				send.setCustUserUU(enterpriseDao.findOne(notice.getEnUU()).getEnAdminuu());
-			} else {
-				send.setCustUserUU(order.getUserUU());
-			}
-			 */
 			send.setCustUserUU(order.getUserUU());
 			send.setDate(new Date());
 			send.setEnUU(SystemSession.getUser().getEnterprise().getUu());
@@ -397,14 +391,13 @@ public class PurchaseNoticeServiceImpl implements PurchaseNoticeService {
 			}
 			// 我的产品库更新
             personalProductService.covertPersonalProduct(notice.getOrderItem().getProductId(), "单个发货");
+			SaleSend saleSend = new SaleSend();
+			BeanUtils.copyProperties(sendItems.get(0).getSend(), saleSend);
 			// 代采发货单
 			if (!StringUtils.isEmpty(notice.getOrderItem().getCustPurchaseCode())) {
-				//send.setCustUserUU(enterpriseDao.findOne(notice.getEnUU()).getEnAdminuu());
-				ContextUtils.publishEvent(new SaleSendAgentEvent(notice));
-			} else {
-				send.setCustUserUU(order.getUserUU());
+				ContextUtils.publishEvent(new SaleSendAgentEvent(notice, send));
 			}
-			return sendItems.get(0).getSend();
+			return saleSend;
 		} else {
 			throw new IllegalOperatorException("请对有效的送货提醒发货!");
 		}
@@ -478,6 +471,19 @@ public class PurchaseNoticeServiceImpl implements PurchaseNoticeService {
 			}
             purchaseNoticeDao.save(noticeList);
             sendItems = saleSendItemDao.save(sendItems);
+			for (SaleSendItem sendItem : sendItems) {
+				Long noticeId = sendItem.getNoticeId();
+				for (PurchaseNotice notice : noticeList) {
+					if (notice.getId().equals(noticeId) && !StringUtils.isEmpty(notice.getOrderItem().getCustPurchaseCode())) {
+						SaleSend send = new SaleSend();
+						send.setRecorder(sendItem.getSend().getRecorder());
+						Set<SaleSendItem> set = new HashSet<>();
+						set.add(sendItem);
+						send.setSendItems(set);
+						ContextUtils.publishEvent(new SaleSendAgentEvent(notice, send));
+					}
+				}
+			}
 			if (!CollectionUtils.isEmpty(sendItems)) {
 				List<SaleSend> saleSends = new ArrayList<>();
 				saleSends.add(sendItems.get(0).getSend());

+ 101 - 0
src/main/java/com/uas/platform/b2b/service/impl/SaleSendAgentServiceImpl.java

@@ -0,0 +1,101 @@
+package com.uas.platform.b2b.service.impl;
+
+import com.uas.platform.b2b.dao.PurchaseNoticeDao;
+import com.uas.platform.b2b.dao.SaleSendDao;
+import com.uas.platform.b2b.dao.SaleSendItemDao;
+import com.uas.platform.b2b.model.PurchaseNotice;
+import com.uas.platform.b2b.model.PurchaseOrder;
+import com.uas.platform.b2b.model.SaleSend;
+import com.uas.platform.b2b.model.SaleSendItem;
+import com.uas.platform.b2b.service.SaleSendAgentService;
+import com.uas.platform.b2b.support.SystemSession;
+import com.uas.platform.b2b.support.TokenService;
+import com.uas.platform.core.exception.IllegalOperatorException;
+import com.uas.platform.core.model.Constant;
+import com.uas.platform.core.model.Status;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.ui.ModelMap;
+import org.springframework.util.StringUtils;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Author: huj
+ * @Date: Created in 09:16 2018/12/11.
+ */
+@Service
+public class SaleSendAgentServiceImpl implements SaleSendAgentService {
+
+
+    @Autowired
+    private PurchaseNoticeDao purchaseNoticeDao;
+
+    @Autowired
+    private SaleSendItemDao saleSendItemDao;
+
+    @Autowired
+    private TokenService tokenService;
+
+
+    @Autowired
+    private SaleSendDao saleSendDao;
+
+    private final static Logger LOGGER = Logger.getLogger(SaleSendAgentServiceImpl.class);
+
+    /**
+     * 代采订单发货
+     * @param purchaseNotice 发货提醒
+     * @param saleSend 发货单
+     * @return 送货单
+     */
+    @Override
+    public SaleSend send(PurchaseNotice purchaseNotice, SaleSend saleSend) {
+        PurchaseNotice notice = purchaseNoticeDao.findOne(purchaseNotice.getSaleNoticeId());
+        SaleSend send = saleSend;
+        ModelMap map = tokenService.getToken("salenotice", notice.getEnUU());
+        String token = (String) map.get("token");
+        send.setUuid(token);
+        List<SaleSend> sends = saleSendDao.findByUuid(send.getUuid());
+        if (!StringUtils.isEmpty(notice) && CollectionUtils.isEmpty(sends)) {
+            PurchaseOrder order = notice.getOrderItem().getOrder();
+            send.setCurrency(order.getCurrency());
+            send.setBackStatus((short) Status.NOT_UPLOAD.value());
+            send.setSendStatus((short) Status.NOT_UPLOAD.value());
+            // 未收料
+            send.setVerifystatus(Constant.NO);
+            send.setCustUU(notice.getEnUU());
+            send.setCustUserUU(order.getUserUU());
+            send.setDate(new Date());
+            send.setEnUU(order.getVendUU());
+            send.setPayments(order.getPayments());
+            send.setRate(order.getRate());
+            send.setRecorder(saleSend.getRecorder());
+            send.setId(null);
+            short number = 0;
+            for (SaleSendItem item : send.getSendItems()) {
+                item.setId(null);
+                item.setNoticeId(notice.getId());
+                item.setNotice(notice);
+                item.setNumber(++number);
+                item.setOrderItem(notice.getOrderItem());
+                item.setOrderItemId(notice.getOrderItem().getId());
+                item.setPrice(notice.getOrderItem().getPrice());
+                item.setSend(send);
+            }
+            List<SaleSendItem> sendItems = saleSendItemDao.save(send.getSendItems());
+            notice.setEndQty(purchaseNotice.getEndQty());
+            notice.setStatus(purchaseNotice.getStatus());
+            purchaseNoticeDao.save(notice);
+            LOGGER.info(String.format("代采订单发货成功,客户送货提醒id:%s,送货提醒id:%s", notice.getId(), purchaseNotice.getId()));
+            return sendItems.get(0).getSend();
+        } else {
+            LOGGER.error(String.format("代采订单发货失败,客户送货提醒id:%s,送货提醒id:%s", purchaseNotice.getSaleNoticeId(),
+                    purchaseNotice.getId()));
+            throw new IllegalOperatorException("请对有效的送货提醒发货!");
+        }
+    }
+}