From 595428cd89e1f2779a96b55ea9dc0dc48fc0ee4d Mon Sep 17 00:00:00 2001
From: tongzhonghao <12345678>
Date: Thu, 9 Feb 2023 17:58:37 +0800
Subject: [PATCH] 修复 历史单据和出/入单据 时间不一致问题。

---
 src/main/java/com/huaheng/pc/monitor/job/task/RyTask.java | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/huaheng/pc/monitor/job/task/RyTask.java b/src/main/java/com/huaheng/pc/monitor/job/task/RyTask.java
index e9a4380..8d570da 100644
--- a/src/main/java/com/huaheng/pc/monitor/job/task/RyTask.java
+++ b/src/main/java/com/huaheng/pc/monitor/job/task/RyTask.java
@@ -37,12 +37,14 @@ import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
 import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
 import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
 import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
+import com.huaheng.pc.receipt.receiptHeaderHistory.domain.ReceiptHeaderHistory;
 import com.huaheng.pc.receipt.receiptHeaderHistory.service.ReceiptHeaderHistoryService;
 import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
 import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
 import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
 import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
 import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
+import com.huaheng.pc.shipment.shipmentHeaderHistory.domain.ShipmentHeaderHistory;
 import com.huaheng.pc.shipment.shipmentHeaderHistory.service.ShipmentHeaderHistoryService;
 import com.huaheng.pc.system.user.service.IUserService;
 import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
@@ -53,6 +55,7 @@ import org.apache.commons.collections.MapUtils;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -464,5 +467,69 @@ public class RyTask extends BaseController {
         }
     }
 
+    public void restoreHistoryDate(){
+        receiptRestore();
+        shipmentRestore();
+    }
+
+    public void receiptRestore(){
+        LambdaQueryWrapper<ReceiptHeaderHistory> query = Wrappers.lambdaQuery();
+        query.eq(ReceiptHeaderHistory::getVersion,0)
+                .orderByAsc(ReceiptHeaderHistory::getId)
+                .last("LIMIT 20");
+        List<ReceiptHeaderHistory> list = receiptHeaderHistoryService.list(query);
+
+        Set<String> codes = list.stream().map(ReceiptHeaderHistory::getCode).collect(Collectors.toSet());
+
+        LambdaQueryWrapper<ReceiptHeader> query1 = Wrappers.lambdaQuery();
+        query1.in(ReceiptHeader::getCode,codes);
+        List<ReceiptHeader> receiptHeaders = receiptHeaderService.list(query1);
+
+        HashMap<String,ReceiptHeader> map = new HashMap<>();
+        for (ReceiptHeader receiptHeader : receiptHeaders) {
+            map.put(receiptHeader.getCode(),receiptHeader);
+        }
+        List<ReceiptHeaderHistory> histories = new ArrayList<>();
+        for (ReceiptHeaderHistory receiptHeaderHistory : list) {
+            ReceiptHeader receiptHeader = map.get(receiptHeaderHistory.getCode());
+            if(receiptHeader !=null){
+                receiptHeaderHistory.setLastUpdated(receiptHeader.getLastUpdated());
+                receiptHeaderHistory.setCreated(receiptHeader.getCreated());
+                receiptHeaderHistory.setVersion(BigDecimal.ONE.intValue());
+                histories.add(receiptHeaderHistory);
+            }
+        }
+        receiptHeaderHistoryService.updateBatchById(histories);
+    }
+
+    public void shipmentRestore(){
+        LambdaQueryWrapper<ShipmentHeaderHistory> query = Wrappers.lambdaQuery();
+        query.eq(ShipmentHeaderHistory::getVersion,0)
+                .orderByAsc(ShipmentHeaderHistory::getId)
+                .last("LIMIT 20");
+        List<ShipmentHeaderHistory> shipmentHeaderHistorys = shipmentHeaderHistoryService.list(query);
+
+        Set<String> codes = shipmentHeaderHistorys.stream().map(ShipmentHeaderHistory::getCode).collect(Collectors.toSet());
+
+        LambdaQueryWrapper<ShipmentHeader> query1 = Wrappers.lambdaQuery();
+        query1.in(ShipmentHeader::getCode,codes);
+        List<ShipmentHeader> ShipmentHeaders = shipmentHeaderService.list(query1);
+
+        HashMap<String,ShipmentHeader> map = new HashMap<>();
+        for (ShipmentHeader shipmentHeader : ShipmentHeaders) {
+            map.put(shipmentHeader.getCode(),shipmentHeader);
+        }
+        List<ShipmentHeaderHistory> histories = new ArrayList<>();
+        for (ShipmentHeaderHistory shipmentHeaderHistory : shipmentHeaderHistorys) {
+            ShipmentHeader shipmentHeader = map.get(shipmentHeaderHistory.getCode());
+            if(shipmentHeader !=null){
+                shipmentHeaderHistory.setLastUpdated(shipmentHeader.getLastUpdated());
+                shipmentHeaderHistory.setCreated(shipmentHeader.getCreated());
+                shipmentHeaderHistory.setVersion(BigDecimal.ONE.intValue());
+                histories.add(shipmentHeaderHistory);
+            }
+        }
+        shipmentHeaderHistoryService.updateBatchById(histories);
+    }
 
 }
--
libgit2 0.22.2