| 
					
				 | 
			
			
				@@ -9,18 +9,27 @@ import com.zswl.dataservicestarter.domain.DataServicePaymentInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zswl.dataservicestarter.model.DataServiceGoodsModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zswl.dataservicestarter.model.DataServiceOrderInfoModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zswl.dataservicestarter.model.DataServicePaymentInfoModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.zswl.dataservicestarter.model.SyncDataModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zswl.dataservicestarter.type.DataServiceOrderType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.zswl.dataservicestarter.type.PlatFormNewDataEvent; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.zswl.dataservicestarter.type.ShopNewDataEvent; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zswl.dataservicestarter.utils.CommonUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zswl.dataservicestarter.utils.result.ResultContent; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import lombok.SneakyThrows; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.lang3.ObjectUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.BeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.context.ApplicationContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.context.event.EventListener; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.scheduling.annotation.Async; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 订单信息 管理 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -40,6 +49,9 @@ public class DataServiceOrderInfoService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     DataServicePaymentInfoDao paymentInfoDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ApplicationContext applicationContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 从平台同步订单信息到 数据服务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -119,9 +131,69 @@ public class DataServiceOrderInfoService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         orderInfoDao.save(orderInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 发送需要商铺同步数据的事件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        this.sendShopEventData(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return ResultContent.buildSuccess(hasCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 得到未同步到平台的数据  同步成功后调用 markSynced2Platform 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public ResultContent<SyncDataModel> getTop100NotSyncPlatformDatas() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SyncDataModel model = new SyncDataModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 查询来源是商铺的数据  未同步 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<DataServiceOrderInfo> orderInfos = orderInfoDao.findTop100ByOrderTypeAndIsSync2ShopOrderByCreateTimeAsc(DataServiceOrderType.Shop, Boolean.FALSE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        long totalElements = orderInfoDao.countByOrderTypeAndIsSync2Shop(DataServiceOrderType.Shop, Boolean.FALSE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<DataServiceOrderInfoModel> list = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtils.isNotEmpty(orderInfos)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            list = orderInfos.stream().map(this::toModel).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        model.setList(list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        model.setTotalElements(totalElements); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ResultContent.buildSuccess(model); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 查询未同步到渠道/商铺的数据 同步后要调用 markSynced2Shop 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public ResultContent<SyncDataModel> getTop100NotSyncShopDatas() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SyncDataModel model = new SyncDataModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 查询来源是平台的数据 未同步到商铺 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<DataServiceOrderInfo> orderInfos = orderInfoDao.findTop100ByOrderTypeAndIsSync2PlatformOrderByCreateTimeAsc(DataServiceOrderType.Platform, Boolean.FALSE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        long totalElements = orderInfoDao.countByOrderTypeAndIsSync2Platform(DataServiceOrderType.Platform, Boolean.FALSE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<DataServiceOrderInfoModel> list = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtils.isNotEmpty(orderInfos)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            list = orderInfos.stream().map(this::toModel).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        model.setList(list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        model.setTotalElements(totalElements); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ResultContent.buildSuccess(model); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public ResultContent sendPlatformEventData() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        PlatFormNewDataEvent testEvent = new PlatFormNewDataEvent(this); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        applicationContext.publishEvent(testEvent); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ResultContent.buildSuccess(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public ResultContent sendShopEventData() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ShopNewDataEvent testEvent = new ShopNewDataEvent(this); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        applicationContext.publishEvent(testEvent); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ResultContent.buildSuccess(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @EventListener(classes = PlatFormNewDataEvent.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Async 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @SneakyThrows 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void test(PlatFormNewDataEvent testEvent) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TimeUnit.SECONDS.sleep(10); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println("消息来了"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 根据订单号查询订单信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -137,6 +209,7 @@ public class DataServiceOrderInfoService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return ResultContent.buildSuccess(orderInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 更加HashCode验证支付信息是否存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -152,14 +225,71 @@ public class DataServiceOrderInfoService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 编辑信息是否同步到平台 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 编辑已同步到 商铺 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param dataId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param orderNos 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public ResultContent markSyncPlatform(String dataId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        int a = 100; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return ResultContent.buildSuccess(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public ResultContent<List<String>> markSynced2Shop(List<String> orderNos) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<String> syncedOrderNos = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtils.isNotEmpty(orderNos)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<DataServiceOrderInfo> saveList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<DataServiceOrderInfo> list = orderInfoDao.findByOrderNoIn(orderNos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (DataServiceOrderInfo orderInfo : list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 未同步的 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Boolean isSync2Shop = orderInfo.getIsSync2Shop(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (isSync2Shop == null || !isSync2Shop) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    orderInfo.setIsSync2Shop(Boolean.TRUE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    orderInfo.setSyncTime(System.currentTimeMillis()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    saveList.add(orderInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (ObjectUtils.isNotEmpty(saveList)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                syncedOrderNos = saveList.stream().map(it -> it.getOrderNo()).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ResultContent.buildSuccess(syncedOrderNos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 编辑已同步到 商铺 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param orderNos 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public ResultContent<List<String>> markSynced2Platform(List<String> orderNos) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<String> syncedOrderNos = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtils.isNotEmpty(orderNos)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<DataServiceOrderInfo> saveList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<DataServiceOrderInfo> list = orderInfoDao.findByOrderNoIn(orderNos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (DataServiceOrderInfo orderInfo : list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 未同步的 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Boolean isSync2Platform = orderInfo.getIsSync2Platform(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (isSync2Platform == null || !isSync2Platform) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    orderInfo.setIsSync2Platform(Boolean.TRUE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    orderInfo.setSyncTime(System.currentTimeMillis()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    saveList.add(orderInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (ObjectUtils.isNotEmpty(saveList)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                syncedOrderNos = saveList.stream().map(it -> it.getOrderNo()).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ResultContent.buildSuccess(syncedOrderNos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 订单信息 转Model 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param orderInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public DataServiceOrderInfoModel toModel(DataServiceOrderInfo orderInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        DataServiceOrderInfoModel model = new DataServiceOrderInfoModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtils.isNotEmpty(orderInfo)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            com.zswl.dataservicestarter.utils.BeanUtils.copyProperties(orderInfo, model); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return model; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |