|
|
@@ -0,0 +1,130 @@
|
|
|
+package com.uas.platform.b2b.purc;
|
|
|
+
|
|
|
+import com.uas.platform.b2b.BaseJunitTest;
|
|
|
+import com.uas.platform.b2b.dao.PurchaseNoticeDao;
|
|
|
+import com.uas.platform.b2b.dao.PurchaseOrderItemDao;
|
|
|
+import com.uas.platform.b2b.model.PurchaseNotice;
|
|
|
+import com.uas.platform.b2b.model.PurchaseOrderItem;
|
|
|
+import org.junit.Test;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.test.context.transaction.TransactionConfiguration;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.persistence.EntityManager;
|
|
|
+import javax.persistence.EntityManagerFactory;
|
|
|
+import javax.persistence.EntityTransaction;
|
|
|
+import javax.persistence.PersistenceContext;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class PurchaseNotify extends BaseJunitTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseOrderItemDao purchaseOrderItemDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseNoticeDao purchaseNoticeDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EntityManagerFactory entityManagerFactory;
|
|
|
+
|
|
|
+ @PersistenceContext
|
|
|
+ protected EntityManager em;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void batchInsert(List list) {
|
|
|
+ for(int i = 0; i < list.size(); i++) {
|
|
|
+ em.persist(list.get(i));
|
|
|
+ if(i % 30== 0) {
|
|
|
+ em.flush();
|
|
|
+ em.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testFindTime() {
|
|
|
+ Long orderItemId = 37053424L;
|
|
|
+// String orderCode = "B2BYBMP180100104";
|
|
|
+// Long enuu = 10041166L;
|
|
|
+// Short number = 1;
|
|
|
+
|
|
|
+ String orderCode = "130000443-73";
|
|
|
+ Long enuu = 10006098L;
|
|
|
+ Short number = 2;
|
|
|
+ long time1 = System.currentTimeMillis();
|
|
|
+ List<Long> orderItemIds = purchaseOrderItemDao.findIdByEnUUAndOrderCodeAndNumber(enuu, orderCode, number);
|
|
|
+ long time2 = System.currentTimeMillis();
|
|
|
+ List<PurchaseOrderItem> orderItems = purchaseOrderItemDao.findByEnUUAndOrderCodeAndNumber(enuu, orderCode, number);
|
|
|
+ long time3 = System.currentTimeMillis();
|
|
|
+ System.out.println("time1: " + (time2 - time1) + " , time2: " + (time3 - time2));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testSaveTime() {
|
|
|
+ String orderCode = "130000443-73";
|
|
|
+ Long enuu = 10006098L;
|
|
|
+ Short number = 2;
|
|
|
+ List<PurchaseNotice> purchaseNotices = new ArrayList<>();
|
|
|
+ for (int i = 0; i < 100; i ++) {
|
|
|
+ purchaseNotices.add(createNotice());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PurchaseNotice> purchaseNotices2 = new ArrayList<>();
|
|
|
+ for (int i = 0; i < 100; i ++) {
|
|
|
+ purchaseNotices2.add(createNotice());
|
|
|
+ }
|
|
|
+ long time1 = System.currentTimeMillis();
|
|
|
+ batchInsert(purchaseNotices);
|
|
|
+ long time2 = System.currentTimeMillis();
|
|
|
+ purchaseNoticeDao.save(purchaseNotices2);
|
|
|
+ long time3 = System.currentTimeMillis();
|
|
|
+ System.out.println("time1: " + (time2 - time1) + " , time2: " + (time3 - time2));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void persistByEntityManager(Iterable<?> entities) {
|
|
|
+ EntityManager entityManager = null;
|
|
|
+ EntityTransaction transaction = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ entityManager = entityManagerFactory.createEntityManager();
|
|
|
+ transaction = entityManager.getTransaction();
|
|
|
+ transaction.begin();
|
|
|
+
|
|
|
+ Iterator iterator = entities.iterator();
|
|
|
+ while(iterator.hasNext()){
|
|
|
+ entityManager.persist(iterator.next());
|
|
|
+ }
|
|
|
+ transaction.commit();
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ if ( transaction != null &&
|
|
|
+ transaction.isActive()) {
|
|
|
+ transaction.rollback();
|
|
|
+ }
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ if (entityManager != null) {
|
|
|
+ entityManager.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private PurchaseNotice createNotice() {
|
|
|
+ PurchaseNotice notice = new PurchaseNotice();
|
|
|
+ notice.setQty((double) 1);
|
|
|
+ notice.setDelivery(new Date());
|
|
|
+ notice.setStatus((short) 201);
|
|
|
+ notice.setSendStatus((short) 201);
|
|
|
+ notice.setEndQty((double) 0);
|
|
|
+ notice.setDate(new Date());
|
|
|
+ notice.setEnUU(10041166L);
|
|
|
+ notice.setErpDate(new Date());
|
|
|
+ notice.setVendUU(10030994L);
|
|
|
+ notice.setOrderItemId(37120085L);
|
|
|
+ return notice;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|