|
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
|
|
|
import com.dgtly.common.config.Global;
|
|
import com.dgtly.common.config.Global;
|
|
|
import com.dgtly.common.utils.DateUtils;
|
|
import com.dgtly.common.utils.DateUtils;
|
|
|
import com.dgtly.common.utils.http.HttpUtils;
|
|
import com.dgtly.common.utils.http.HttpUtils;
|
|
|
|
|
+import com.dgtly.system.service.IMetaHanaDeliverSignService;
|
|
|
import com.dgtly.system.service.ISysUserOrderAuthorService;
|
|
import com.dgtly.system.service.ISysUserOrderAuthorService;
|
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -11,7 +12,6 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.sql.*;
|
|
import java.sql.*;
|
|
@@ -19,6 +19,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
import java.util.Enumeration;
|
|
import java.util.Enumeration;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
|
|
@Component
|
|
@Component
|
|
|
public class HanaOrderComponent {
|
|
public class HanaOrderComponent {
|
|
@@ -52,6 +53,10 @@ public class HanaOrderComponent {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ISysUserOrderAuthorService userOrderAuthorService;
|
|
private ISysUserOrderAuthorService userOrderAuthorService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IMetaHanaDeliverSignService metaHanaDeliverSignService;
|
|
|
|
|
+
|
|
|
public HanaOrderComponent() {
|
|
public HanaOrderComponent() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -109,6 +114,8 @@ public class HanaOrderComponent {
|
|
|
" T.NTGEW_MARA,\n"+
|
|
" T.NTGEW_MARA,\n"+
|
|
|
" T.PSTYV,\n"+
|
|
" T.PSTYV,\n"+
|
|
|
" T.UEPOS, \n"+
|
|
" T.UEPOS, \n"+
|
|
|
|
|
+ " T.MAABC, \n"+
|
|
|
|
|
+ " T.ZCODE8, \n"+
|
|
|
"\t replace(replace(T.BSTKD_E,CHAR(10),''),CHAR(13),'') BSTKD_E \n" +
|
|
"\t replace(replace(T.BSTKD_E,CHAR(10),''),CHAR(13),'') BSTKD_E \n" +
|
|
|
"FROM (\n" +
|
|
"FROM (\n" +
|
|
|
"\n" +
|
|
"\n" +
|
|
@@ -165,6 +172,8 @@ public class HanaOrderComponent {
|
|
|
" A.NTGEW_MARA,"+
|
|
" A.NTGEW_MARA,"+
|
|
|
" A.PSTYV,"+
|
|
" A.PSTYV,"+
|
|
|
" A.UEPOS,"+
|
|
" A.UEPOS,"+
|
|
|
|
|
+ " A.MAABC,"+
|
|
|
|
|
+ " A.ZCODE8,"+
|
|
|
" A.BSTKD_E "+
|
|
" A.BSTKD_E "+
|
|
|
"FROM \"_SYS_BIC\".\"com.sd/CAL_SALES\"" +
|
|
"FROM \"_SYS_BIC\".\"com.sd/CAL_SALES\"" +
|
|
|
"('PLACEHOLDER' = ('$$IP_ENDDATE$$',\n" +
|
|
"('PLACEHOLDER' = ('$$IP_ENDDATE$$',\n" +
|
|
@@ -191,8 +200,67 @@ public class HanaOrderComponent {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @description: C类产品订单标记
|
|
|
|
|
+ * @param: []
|
|
|
|
|
+ * @return: void
|
|
|
|
|
+ * @author: njs
|
|
|
|
|
+ * @date: 2025/5/7 13:24
|
|
|
|
|
+ */
|
|
|
|
|
+ public void hanaErpOrderSyncByC() throws Exception {
|
|
|
|
|
+ Connection con = this.getHanaConnection();
|
|
|
|
|
+ PreparedStatement pstmt = con.prepareStatement("SELECT MAABC,SPRAS,TMABC,MANDT FROM ERP.TMABCT");
|
|
|
|
|
+
|
|
|
|
|
+ Long startTime = System.currentTimeMillis();
|
|
|
|
|
+ ResultSet rs = pstmt.executeQuery();
|
|
|
|
|
+ Long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("TMABCT查询用时:" + (endTime - startTime)+"毫秒");
|
|
|
|
|
+ this.createTmabcTxt(rs);
|
|
|
|
|
+ this.runLoadTmabcTxt();
|
|
|
|
|
+ this.closeConnection(con, pstmt);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @description: 交货单电子签收数据同步
|
|
|
|
|
+ * @param: []
|
|
|
|
|
+ * @return: void
|
|
|
|
|
+ * @author: njs
|
|
|
|
|
+ * @date: 2024/12/31 10:14
|
|
|
|
|
+ */
|
|
|
|
|
+ public void hanaSalesDeliverSignatureSync() throws Exception {
|
|
|
|
|
+ Connection con = this.getHanaConnection();
|
|
|
|
|
+ PreparedStatement pstmt = con.prepareStatement("SELECT\n" +
|
|
|
|
|
+ "\t VBELN,\n" +
|
|
|
|
|
+ "\t POSNR,\n" +
|
|
|
|
|
+ "\t MATNR,\n" +
|
|
|
|
|
+ "\t VGBEL,\n" +
|
|
|
|
|
+ "\t VGPOS, \n"+
|
|
|
|
|
+ "\t ERDAT_SO,\n" +
|
|
|
|
|
+ "\t LFIMG,\n" +
|
|
|
|
|
+ "\t MODIFIEDVALUE,\n" +
|
|
|
|
|
+ "\t LFIMG_CY,\n" +
|
|
|
|
|
+ "\t ZDATE_KH,\n" +
|
|
|
|
|
+ "\t ZTIME_KH,\n" +
|
|
|
|
|
+ "\t ZVBELN_YCHH,\n" +
|
|
|
|
|
+ "\t ZSTATUS_HH,\n" +
|
|
|
|
|
+ "\t CONTRACTID, \n" +
|
|
|
|
|
+ "\t BIZNO, \n" +
|
|
|
|
|
+ "\t MANDT \n" +
|
|
|
|
|
+ " FROM ERP.ZSDT056 where ERDAT_SO between ADD_MONTHS(CURRENT_DATE, -3) AND CURRENT_DATE");
|
|
|
|
|
+
|
|
|
|
|
+ Long startTime = System.currentTimeMillis();
|
|
|
|
|
+ ResultSet rs = pstmt.executeQuery();
|
|
|
|
|
+ Long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("hanaSalesDeliverSignatureSync查询用时:" + (endTime - startTime)+"毫秒");
|
|
|
|
|
+ this.createDeliverSignatureTxt(rs);
|
|
|
|
|
+ this.runLoadDeliverSignature();
|
|
|
|
|
+ this.closeConnection(con, pstmt);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
/*批量插入*/
|
|
/*批量插入*/
|
|
|
- private void insertSalesOrderResult(ResultSet rs) throws Exception {
|
|
|
|
|
|
|
+ /* private void insertSalesOrderResult(ResultSet rs) throws Exception {
|
|
|
Connection conn = null;
|
|
Connection conn = null;
|
|
|
PreparedStatement pstm =null;
|
|
PreparedStatement pstm =null;
|
|
|
PreparedStatement pstm1 =null;
|
|
PreparedStatement pstm1 =null;
|
|
@@ -209,7 +277,7 @@ public class HanaOrderComponent {
|
|
|
if (rs.next()) {
|
|
if (rs.next()) {
|
|
|
long i=0;
|
|
long i=0;
|
|
|
ResultSetMetaData rsmd = rs.getMetaData();
|
|
ResultSetMetaData rsmd = rs.getMetaData();
|
|
|
- /*循环遍历数据,创建执行批量插入的sql语句*/
|
|
|
|
|
|
|
+ *//*循环遍历数据,创建执行批量插入的sql语句*//*
|
|
|
do {
|
|
do {
|
|
|
i++;
|
|
i++;
|
|
|
pstm.setString(1, rs.getString("VBELN"));
|
|
pstm.setString(1, rs.getString("VBELN"));
|
|
@@ -283,7 +351,192 @@ public class HanaOrderComponent {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+ //C类
|
|
|
|
|
+ private int createTmabcTxt(ResultSet result) throws Exception {
|
|
|
|
|
+ File file = null;
|
|
|
|
|
+ FileWriter fw = null;
|
|
|
|
|
+ Connection conn = null;
|
|
|
|
|
+ PreparedStatement pstm =null;
|
|
|
|
|
+ int j =0;
|
|
|
|
|
+ try {
|
|
|
|
|
+ long i =0;
|
|
|
|
|
+
|
|
|
|
|
+ //创建IO需求的条件,并声明输出路径
|
|
|
|
|
+ file = new File((Global.getTemdataPath()+"erpOrderByC/"));
|
|
|
|
|
+ log.info("erpOrderByC数据缓存路径:" + Global.getTemdataPath()+"erpOrderByC/");
|
|
|
|
|
+ if(!file.exists()){
|
|
|
|
|
+ file.mkdir();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ file = new File(Global.getTemdataPath()+"erpOrderByC/"+j+".txt");
|
|
|
|
|
+ if(!file.exists()){
|
|
|
|
|
+ file.createNewFile();
|
|
|
|
|
+ }else {
|
|
|
|
|
+ //取得这个目录下的所有子文件对象
|
|
|
|
|
+ File[] files = new File(Global.getTemdataPath()+"erpOrderByC/").listFiles();
|
|
|
|
|
+ //遍历该目录下的文件对象
|
|
|
|
|
+
|
|
|
|
|
+ for (File f: files){
|
|
|
|
|
+ f.delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ file.delete();
|
|
|
|
|
+ file.createNewFile();
|
|
|
|
|
+ }
|
|
|
|
|
+ fw = new FileWriter(file);
|
|
|
|
|
+ Long startTime = System.currentTimeMillis();
|
|
|
|
|
+ while (result.next()){
|
|
|
|
|
+
|
|
|
|
|
+ fw.write(
|
|
|
|
|
+ result.getString("MAABC")
|
|
|
|
|
+ +"$$"+ result.getString("SPRAS")
|
|
|
|
|
+ +"$$"+ result.getString("TMABC")
|
|
|
|
|
+ +"$$"+ result.getString("MANDT")
|
|
|
|
|
+ + "\r\n");
|
|
|
|
|
+
|
|
|
|
|
+ fw.flush();
|
|
|
|
|
+ i++;
|
|
|
|
|
+ if (i%50000==0){
|
|
|
|
|
+ j++;
|
|
|
|
|
+ //创建IO需求的条件,并声明输出路径
|
|
|
|
|
+ file = new File(Global.getTemdataPath()+"erpOrderByC/"+j+".txt");
|
|
|
|
|
+ if(!file.exists()){
|
|
|
|
|
+ file.createNewFile();
|
|
|
|
|
+ }else {
|
|
|
|
|
+ file.delete();
|
|
|
|
|
+ file.createNewFile();
|
|
|
|
|
+ }
|
|
|
|
|
+ fw = new FileWriter(file);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("生成erpOrderByC-TXT用时:" + (endTime - startTime) + "毫秒");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }finally {
|
|
|
|
|
+ fw.close();
|
|
|
|
|
+ if(pstm!=null){
|
|
|
|
|
+ try {
|
|
|
|
|
+ pstm.close();
|
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(conn!=null){
|
|
|
|
|
+ try {
|
|
|
|
|
+ conn.close();
|
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return j;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+//电子单签收
|
|
|
|
|
+
|
|
|
|
|
+ private int createDeliverSignatureTxt(ResultSet result) throws Exception {
|
|
|
|
|
+ File file = null;
|
|
|
|
|
+ FileWriter fw = null;
|
|
|
|
|
+ Connection conn = null;
|
|
|
|
|
+ PreparedStatement pstm =null;
|
|
|
|
|
+ int j =0;
|
|
|
|
|
+ try {
|
|
|
|
|
+ long i =0;
|
|
|
|
|
+
|
|
|
|
|
+ //创建IO需求的条件,并声明输出路径
|
|
|
|
|
+ file = new File((Global.getTemdataPath()+"deliverSignature/"));
|
|
|
|
|
+ log.info("deliverSignature数据缓存路径:" + Global.getTemdataPath()+"deliverSignature/");
|
|
|
|
|
+ if(!file.exists()){
|
|
|
|
|
+ file.mkdir();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ file = new File(Global.getTemdataPath()+"deliverSignature/"+j+".txt");
|
|
|
|
|
+ if(!file.exists()){
|
|
|
|
|
+ file.createNewFile();
|
|
|
|
|
+ }else {
|
|
|
|
|
+ //取得这个目录下的所有子文件对象
|
|
|
|
|
+ File[] files = new File(Global.getTemdataPath()+"deliverSignature/").listFiles();
|
|
|
|
|
+
|
|
|
|
|
+ for (File f: files){
|
|
|
|
|
+ f.delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ file.delete();
|
|
|
|
|
+ file.createNewFile();
|
|
|
|
|
+ }
|
|
|
|
|
+ fw = new FileWriter(file);
|
|
|
|
|
+ Long startTime = System.currentTimeMillis();
|
|
|
|
|
+ while (result.next()){
|
|
|
|
|
+
|
|
|
|
|
+ fw.write(
|
|
|
|
|
+ result.getString("VBELN")
|
|
|
|
|
+ +"$$"+ result.getString("POSNR")
|
|
|
|
|
+ +"$$"+ result.getString("MATNR")
|
|
|
|
|
+ +"$$"+ result.getString("VGBEL")
|
|
|
|
|
+ +"$$"+ result.getString("VGPOS")
|
|
|
|
|
+ +"$$"+ result.getString("ERDAT_SO")
|
|
|
|
|
+ +"$$"+ result.getString("LFIMG")
|
|
|
|
|
+ +"$$"+ result.getString("MODIFIEDVALUE")
|
|
|
|
|
+ +"$$"+ result.getString("LFIMG_CY")
|
|
|
|
|
+ +"$$"+ result.getString("ZDATE_KH")
|
|
|
|
|
+ +"$$"+ result.getString("ZTIME_KH")
|
|
|
|
|
+ +"$$"+ result.getString("ZVBELN_YCHH")
|
|
|
|
|
+ +"$$"+ result.getString("ZSTATUS_HH")
|
|
|
|
|
+ +"$$"+ result.getString("CONTRACTID")
|
|
|
|
|
+ +"$$"+ result.getString("BIZNO")
|
|
|
|
|
+ +"$$"+ result.getString("MANDT")
|
|
|
|
|
+ + "\r\n");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ fw.flush();
|
|
|
|
|
+ i++;
|
|
|
|
|
+ if (i%50000==0){
|
|
|
|
|
+ j++;
|
|
|
|
|
+ //创建IO需求的条件,并声明输出路径
|
|
|
|
|
+ file = new File(Global.getTemdataPath()+"deliverSignature/"+j+".txt");
|
|
|
|
|
+ if(!file.exists()){
|
|
|
|
|
+ file.createNewFile();
|
|
|
|
|
+ }else {
|
|
|
|
|
+ file.delete();
|
|
|
|
|
+ file.createNewFile();
|
|
|
|
|
+ }
|
|
|
|
|
+ fw = new FileWriter(file);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("生成deliverSignature-TXT用时:" + (endTime - startTime) + "毫秒");
|
|
|
|
|
+
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }finally {
|
|
|
|
|
+ fw.close();
|
|
|
|
|
+ if(pstm!=null){
|
|
|
|
|
+ try {
|
|
|
|
|
+ pstm.close();
|
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(conn!=null){
|
|
|
|
|
+ try {
|
|
|
|
|
+ conn.close();
|
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return j;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
//订单
|
|
//订单
|
|
|
private int createSalesOrderTxt(ResultSet result) throws Exception {
|
|
private int createSalesOrderTxt(ResultSet result) throws Exception {
|
|
|
File file = null;
|
|
File file = null;
|
|
@@ -375,6 +628,8 @@ public class HanaOrderComponent {
|
|
|
+"$$"+ result.getString("NTGEW_MARA")
|
|
+"$$"+ result.getString("NTGEW_MARA")
|
|
|
+"$$"+ result.getString("PSTYV")
|
|
+"$$"+ result.getString("PSTYV")
|
|
|
+"$$"+ result.getString("UEPOS")
|
|
+"$$"+ result.getString("UEPOS")
|
|
|
|
|
+ +"$$"+ result.getString("MAABC")
|
|
|
|
|
+ +"$$"+ result.getString("ZCODE8")
|
|
|
+"$$"+ result.getString("BSTKD_E")
|
|
+"$$"+ result.getString("BSTKD_E")
|
|
|
+ "\r\n");
|
|
+ "\r\n");
|
|
|
|
|
|
|
@@ -751,11 +1006,11 @@ public class HanaOrderComponent {
|
|
|
Long endTime = System.currentTimeMillis();
|
|
Long endTime = System.currentTimeMillis();
|
|
|
log.info("生成selfDeliverOrder-TXT用时:" + (endTime - startTime) + "毫秒");
|
|
log.info("生成selfDeliverOrder-TXT用时:" + (endTime - startTime) + "毫秒");
|
|
|
|
|
|
|
|
- conn = getMysqlConnection();
|
|
|
|
|
|
|
+ /* conn = getMysqlConnection();
|
|
|
//生产表
|
|
//生产表
|
|
|
String sql = "TRUNCATE TABLE meta_hana_self_deliver_order";
|
|
String sql = "TRUNCATE TABLE meta_hana_self_deliver_order";
|
|
|
pstm = conn.prepareStatement(sql);
|
|
pstm = conn.prepareStatement(sql);
|
|
|
- pstm.execute();
|
|
|
|
|
|
|
+ pstm.execute();*/
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}finally {
|
|
}finally {
|
|
@@ -903,7 +1158,7 @@ public class HanaOrderComponent {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*批量插入*/
|
|
/*批量插入*/
|
|
|
- private void insertDeliverOrderResult(ResultSet rs) throws Exception {
|
|
|
|
|
|
|
+ /*private void insertDeliverOrderResult(ResultSet rs) throws Exception {
|
|
|
Connection conn = null;
|
|
Connection conn = null;
|
|
|
PreparedStatement pstm =null;
|
|
PreparedStatement pstm =null;
|
|
|
PreparedStatement pstm1 =null;
|
|
PreparedStatement pstm1 =null;
|
|
@@ -921,7 +1176,7 @@ public class HanaOrderComponent {
|
|
|
long i =0;
|
|
long i =0;
|
|
|
ResultSetMetaData rsmd = rs.getMetaData();
|
|
ResultSetMetaData rsmd = rs.getMetaData();
|
|
|
int colNum = rsmd.getColumnCount();
|
|
int colNum = rsmd.getColumnCount();
|
|
|
- /*循环遍历数据,创建执行批量插入的sql语句*/
|
|
|
|
|
|
|
+ *//*循环遍历数据,创建执行批量插入的sql语句*//*
|
|
|
do {
|
|
do {
|
|
|
pstm.setString(1, rs.getString("VBELN"));
|
|
pstm.setString(1, rs.getString("VBELN"));
|
|
|
pstm.setString(2, rs.getString("POSNR"));
|
|
pstm.setString(2, rs.getString("POSNR"));
|
|
@@ -998,7 +1253,7 @@ public class HanaOrderComponent {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1024,26 +1279,27 @@ public class HanaOrderComponent {
|
|
|
}
|
|
}
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
-//订单
|
|
|
|
|
- public void runLoadSalesOrder() throws Exception{
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //订单C类标识
|
|
|
|
|
+ private void runLoadTmabcTxt()throws Exception{
|
|
|
//生产表
|
|
//生产表
|
|
|
Connection conn = null;
|
|
Connection conn = null;
|
|
|
PreparedStatement pstm =null;
|
|
PreparedStatement pstm =null;
|
|
|
try{
|
|
try{
|
|
|
conn = getMysqlConnection();
|
|
conn = getMysqlConnection();
|
|
|
- String sql = "TRUNCATE TABLE meta_hana_sales_order";
|
|
|
|
|
|
|
+ String sql = "TRUNCATE TABLE meta_hana_order_maabc";
|
|
|
pstm = conn.prepareStatement(sql);
|
|
pstm = conn.prepareStatement(sql);
|
|
|
pstm.execute();
|
|
pstm.execute();
|
|
|
- String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_sales_order fields terminated by '$$' lines terminated by '\\n'";
|
|
|
|
|
|
|
+ String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_order_maabc fields terminated by '$$' lines terminated by '\\n'";
|
|
|
long beginTime=System.currentTimeMillis();
|
|
long beginTime=System.currentTimeMillis();
|
|
|
- int rows=this.bulkLoadFromInputStream(testSql, mergeGetStream(new File((Global.getTemdataPath()+"salesOrder/"))));
|
|
|
|
|
|
|
+ int rows=this.bulkLoadFromInputStream(testSql, mergeGetStream(new File((Global.getTemdataPath()+"erpOrderByC/"))));
|
|
|
long endTime=System.currentTimeMillis();
|
|
long endTime=System.currentTimeMillis();
|
|
|
- log.info("importing salesOrder := "+rows+" rows data into mysql and cost "+(endTime-beginTime)+" ms!");
|
|
|
|
|
- String result = HttpUtils.sendGet(orderGetDataHook);
|
|
|
|
|
- log.info("清空salesOrder缓存:"+result);
|
|
|
|
|
|
|
+ log.info("importing erpOrderByC := "+rows+" rows data into mysql and cost "+(endTime-beginTime)+" ms!");
|
|
|
|
|
+
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
|
- String name ="meta_hana_sales_order订单表同步异常";
|
|
|
|
|
|
|
+ String name ="meta_hana_order_maabc订单C类标识表同步异常";
|
|
|
userOrderAuthorService.sendMailHanaWarning(name);
|
|
userOrderAuthorService.sendMailHanaWarning(name);
|
|
|
|
|
+ log.error(name, e);
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}finally {
|
|
}finally {
|
|
|
if(pstm!=null){
|
|
if(pstm!=null){
|
|
@@ -1063,29 +1319,32 @@ public class HanaOrderComponent {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- //测试表
|
|
|
|
|
-// String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table sap_hana_sales_order fields terminated by '?' lines terminated by '\\n'";
|
|
|
|
|
- //生产表
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void runLoadFreezeCustomer()throws Exception{
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //电子单签收状态
|
|
|
|
|
+ public void runLoadDeliverSignature () throws Exception{
|
|
|
//生产表
|
|
//生产表
|
|
|
Connection conn = null;
|
|
Connection conn = null;
|
|
|
PreparedStatement pstm =null;
|
|
PreparedStatement pstm =null;
|
|
|
- try {
|
|
|
|
|
|
|
+ try{
|
|
|
conn = getMysqlConnection();
|
|
conn = getMysqlConnection();
|
|
|
- //生产表
|
|
|
|
|
- String sql = "TRUNCATE TABLE meta_hana_not_freeze_customer";
|
|
|
|
|
|
|
+ String sql = "TRUNCATE TABLE meta_hana_deliver_sign";
|
|
|
pstm = conn.prepareStatement(sql);
|
|
pstm = conn.prepareStatement(sql);
|
|
|
pstm.execute();
|
|
pstm.execute();
|
|
|
- String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_not_freeze_customer fields terminated by '$$' lines terminated by '\\n'";
|
|
|
|
|
|
|
+ String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_deliver_sign fields terminated by '$$' lines terminated by '\\n'";
|
|
|
long beginTime=System.currentTimeMillis();
|
|
long beginTime=System.currentTimeMillis();
|
|
|
- int rows=this.bulkLoadFromInputStream(testSql, mergeGetStream(new File((Global.getTemdataPath()+"freezeCustomer/"))));
|
|
|
|
|
|
|
+ int rows=this.bulkLoadFromInputStream(testSql, mergeGetStream(new File((Global.getTemdataPath()+"deliverSignature/"))));
|
|
|
long endTime=System.currentTimeMillis();
|
|
long endTime=System.currentTimeMillis();
|
|
|
- log.info("importing freezeCustomer := "+rows+" rows data into mysql and cost "+(endTime-beginTime)+" ms!");
|
|
|
|
|
- } catch (SQLException e) {
|
|
|
|
|
- String name ="meta_hana_not_freeze_customer 未冻结经销商表同步异常";
|
|
|
|
|
|
|
+ log.info("importing salesOrder := "+rows+" rows data into mysql and cost "+(endTime-beginTime)+" ms!");
|
|
|
|
|
+ //预处理电子单签收数据
|
|
|
|
|
+ metaHanaDeliverSignService.pretreatmentHanaDeliverSign();
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ String name ="meta_hana_deliver_sign电子单签收表同步异常";
|
|
|
userOrderAuthorService.sendMailHanaWarning(name);
|
|
userOrderAuthorService.sendMailHanaWarning(name);
|
|
|
|
|
+ log.error(name, e);
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}finally {
|
|
}finally {
|
|
|
if(pstm!=null){
|
|
if(pstm!=null){
|
|
@@ -1105,27 +1364,117 @@ public class HanaOrderComponent {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+//订单
|
|
|
|
|
+ public void runLoadSalesOrder(){
|
|
|
|
|
+
|
|
|
|
|
+ try (
|
|
|
|
|
+ Connection conn = getMysqlConnection();
|
|
|
|
|
+ Statement stmt = conn.createStatement()
|
|
|
|
|
+ ) {
|
|
|
|
|
+ // 设置事务隔离级别
|
|
|
|
|
+ conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
|
|
|
|
|
+ // 开启事务
|
|
|
|
|
+ conn.setAutoCommit(false);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 1. 创建临时表
|
|
|
|
|
+ stmt.execute("CREATE TABLE IF NOT EXISTS meta_hana_sales_order_temp LIKE meta_hana_sales_order");
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 加载数据到临时表
|
|
|
|
|
+ String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_sales_order_temp fields terminated by '$$' lines terminated by '\\n'";
|
|
|
|
|
+ long beginTime = System.currentTimeMillis();
|
|
|
|
|
+ String filePath = Global.getTemdataPath() + "salesOrder/";
|
|
|
|
|
+ try (InputStream inputStream = mergeGetStream(new File(filePath))) {
|
|
|
|
|
+ int rows = this.bulkLoadFromInputStream(testSql, inputStream);
|
|
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("importing salesOrder := {} rows data into mysql from {} and cost {} ms!", rows, filePath, (endTime - beginTime));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //删除旧表
|
|
|
|
|
+ try (Connection tempConn = getMysqlConnection();
|
|
|
|
|
+ Statement tempStmt = tempConn.createStatement()) {
|
|
|
|
|
+ tempStmt.execute("DROP TABLE IF EXISTS meta_hana_sales_order_old");
|
|
|
|
|
+ log.info("成功删除旧表: meta_hana_sales_order_old");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("删除旧表失败,表名: meta_hana_sales_order_old", e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 先设置会话级锁等待超时为3秒
|
|
|
|
|
+ try (Statement timeOut = conn.createStatement()) {
|
|
|
|
|
+ timeOut.execute("SET SESSION innodb_lock_wait_timeout = 3");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 执行RENAME并设置语句级超时(原子切换表(RENAME是原子操作))
|
|
|
|
|
+ try (Statement renameTable = conn.createStatement()) {
|
|
|
|
|
+ renameTable.setQueryTimeout(3); // 语句执行超时3秒
|
|
|
|
|
+ renameTable.execute("RENAME TABLE meta_hana_sales_order TO meta_hana_sales_order_old, " +
|
|
|
|
|
+ "meta_hana_sales_order_temp TO meta_hana_sales_order");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 提交事务
|
|
|
|
|
+ conn.commit();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 清空缓存
|
|
|
|
|
+ String result = HttpUtils.sendGet(orderGetDataHook);
|
|
|
|
|
+ log.info("清空salesOrder缓存:{}", result);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 回滚事务
|
|
|
|
|
+ try {
|
|
|
|
|
+ conn.rollback();
|
|
|
|
|
+ // 清理临时表
|
|
|
|
|
+ try {
|
|
|
|
|
+ stmt.execute("DROP TABLE IF EXISTS meta_hana_sales_order_temp");
|
|
|
|
|
+ } catch (SQLException ex) {
|
|
|
|
|
+ log.error("清理临时表失败", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (SQLException ex) {
|
|
|
|
|
+ log.error("事务回滚失败", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ try {
|
|
|
|
|
+ conn.setAutoCommit(true);
|
|
|
|
|
+ } catch (SQLException ex) {
|
|
|
|
|
+ log.error("恢复自动提交模式失败", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ String name = "meta_hana_sales_order订单表同步异常";
|
|
|
|
|
+ userOrderAuthorService.sendMailHanaWarning(name);
|
|
|
|
|
+ log.error(name + ", 文件路径: " + Global.getTemdataPath() + "salesOrder/", e);
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- public void runLoadSelfReviewedDeliverOrder()throws Exception{
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public void runLoadFreezeCustomer()throws Exception{
|
|
|
//生产表
|
|
//生产表
|
|
|
Connection conn = null;
|
|
Connection conn = null;
|
|
|
PreparedStatement pstm =null;
|
|
PreparedStatement pstm =null;
|
|
|
try {
|
|
try {
|
|
|
conn = getMysqlConnection();
|
|
conn = getMysqlConnection();
|
|
|
//生产表
|
|
//生产表
|
|
|
- String sql = "TRUNCATE TABLE meta_hana_self_deliver_order";
|
|
|
|
|
|
|
+ String sql = "TRUNCATE TABLE meta_hana_not_freeze_customer";
|
|
|
pstm = conn.prepareStatement(sql);
|
|
pstm = conn.prepareStatement(sql);
|
|
|
pstm.execute();
|
|
pstm.execute();
|
|
|
- String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_self_deliver_order fields terminated by '$$' lines terminated by '\\n'";
|
|
|
|
|
|
|
+ String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_not_freeze_customer fields terminated by '$$' lines terminated by '\\n'";
|
|
|
long beginTime=System.currentTimeMillis();
|
|
long beginTime=System.currentTimeMillis();
|
|
|
- int rows=this.bulkLoadFromInputStream(testSql, mergeGetStream(new File((Global.getTemdataPath()+"selfDeliverOrder/"))));
|
|
|
|
|
|
|
+ int rows=this.bulkLoadFromInputStream(testSql, mergeGetStream(new File((Global.getTemdataPath()+"freezeCustomer/"))));
|
|
|
long endTime=System.currentTimeMillis();
|
|
long endTime=System.currentTimeMillis();
|
|
|
- log.info("importing selfDeliverOrder := "+rows+" rows data into mysql and cost "+(endTime-beginTime)+" ms!");
|
|
|
|
|
|
|
+ log.info("importing freezeCustomer := "+rows+" rows data into mysql and cost "+(endTime-beginTime)+" ms!");
|
|
|
} catch (SQLException e) {
|
|
} catch (SQLException e) {
|
|
|
- String name ="meta_hana_self_deliver_order 自提提前过账表同步异常";
|
|
|
|
|
|
|
+ String name ="meta_hana_not_freeze_customer 未冻结经销商表同步异常";
|
|
|
userOrderAuthorService.sendMailHanaWarning(name);
|
|
userOrderAuthorService.sendMailHanaWarning(name);
|
|
|
|
|
+ log.error(name, e);
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}finally {
|
|
}finally {
|
|
|
if(pstm!=null){
|
|
if(pstm!=null){
|
|
@@ -1148,47 +1497,177 @@ public class HanaOrderComponent {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- public void runLoadDeliverOrder() throws Exception{
|
|
|
|
|
- Connection conn = null;
|
|
|
|
|
- PreparedStatement pstm =null;
|
|
|
|
|
- //测试表
|
|
|
|
|
-// String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table sap_hana_deliver_order fields terminated by '?' lines terminated by '\\n'";
|
|
|
|
|
- //生产表
|
|
|
|
|
- try {
|
|
|
|
|
- conn = getMysqlConnection();
|
|
|
|
|
- //生产表
|
|
|
|
|
- String sql = "TRUNCATE TABLE meta_hana_deliver_order";
|
|
|
|
|
- pstm = conn.prepareStatement(sql);
|
|
|
|
|
- pstm.execute();
|
|
|
|
|
- String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_deliver_order fields terminated by '$$' lines terminated by '\\n'";
|
|
|
|
|
- long beginTime=System.currentTimeMillis();
|
|
|
|
|
- int rows=this.bulkLoadFromInputStream(testSql, mergeGetStream(new File((Global.getTemdataPath()+"deliverOrder/"))));
|
|
|
|
|
- long endTime=System.currentTimeMillis();
|
|
|
|
|
- log.info("importing deliverOrder := "+rows+" rows data into mysql and cost "+(endTime-beginTime)+" ms!");
|
|
|
|
|
- String result = HttpUtils.sendGet(deliverGetDataHook);
|
|
|
|
|
- log.info("清空deliverOrder缓存:"+result);
|
|
|
|
|
- } catch (SQLException e) {
|
|
|
|
|
- String name ="meta_hana_deliver_order 交货单表同步异常";
|
|
|
|
|
- userOrderAuthorService.sendMailHanaWarning(name);
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }finally {
|
|
|
|
|
- if(pstm!=null){
|
|
|
|
|
|
|
+ public void runLoadSelfReviewedDeliverOrder()throws Exception{
|
|
|
|
|
+ try (
|
|
|
|
|
+ Connection conn = getMysqlConnection();
|
|
|
|
|
+ Statement stmt = conn.createStatement()
|
|
|
|
|
+ ) {
|
|
|
|
|
+ // 设置事务隔离级别
|
|
|
|
|
+ conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
|
|
|
|
|
+ // 开启事务
|
|
|
|
|
+ conn.setAutoCommit(false);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 1. 创建临时表
|
|
|
|
|
+ stmt.execute("CREATE TABLE IF NOT EXISTS meta_hana_self_deliver_order_temp LIKE meta_hana_self_deliver_order");
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 加载数据到临时表
|
|
|
|
|
+ String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_self_deliver_order_temp fields terminated by '$$' lines terminated by '\\n'";
|
|
|
|
|
+ long beginTime = System.currentTimeMillis();
|
|
|
|
|
+ String filePath = Global.getTemdataPath() + "selfDeliverOrder/";
|
|
|
|
|
+ try (InputStream inputStream = mergeGetStream(new File(filePath))) {
|
|
|
|
|
+ int rows = this.bulkLoadFromInputStream(testSql, inputStream);
|
|
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("importing selfDeliverOrder := {} rows data into mysql from {} and cost {} ms!", rows, filePath, (endTime - beginTime));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //删除旧表
|
|
|
|
|
+ try (Connection tempConn = getMysqlConnection();
|
|
|
|
|
+ Statement tempStmt = tempConn.createStatement()) {
|
|
|
|
|
+ tempStmt.execute("DROP TABLE IF EXISTS meta_hana_self_deliver_order_old");
|
|
|
|
|
+ log.info("成功删除旧表: meta_hana_self_deliver_order_old");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("删除旧表失败,表名: meta_hana_self_deliver_order_old", e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 先设置会话级锁等待超时为3秒
|
|
|
|
|
+ try (Statement timeOut = conn.createStatement()) {
|
|
|
|
|
+ timeOut.execute("SET SESSION innodb_lock_wait_timeout = 3");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 执行RENAME并设置语句级超时(原子切换表(RENAME是原子操作))
|
|
|
|
|
+ try (Statement renameTable = conn.createStatement()) {
|
|
|
|
|
+ renameTable.setQueryTimeout(3); // 语句执行超时3秒
|
|
|
|
|
+ renameTable.execute("RENAME TABLE meta_hana_self_deliver_order TO meta_hana_self_deliver_order_old, " +
|
|
|
|
|
+ "meta_hana_self_deliver_order_temp TO meta_hana_self_deliver_order");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 提交事务
|
|
|
|
|
+ conn.commit();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 回滚事务
|
|
|
try {
|
|
try {
|
|
|
- pstm.close();
|
|
|
|
|
- } catch (SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- throw new RuntimeException(e);
|
|
|
|
|
|
|
+ conn.rollback();
|
|
|
|
|
+ // 清理临时表
|
|
|
|
|
+ try {
|
|
|
|
|
+ stmt.execute("DROP TABLE IF EXISTS meta_hana_self_deliver_order_temp");
|
|
|
|
|
+ } catch (SQLException ex) {
|
|
|
|
|
+ log.error("清理临时表失败", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (SQLException ex) {
|
|
|
|
|
+ log.error("事务回滚失败", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ try {
|
|
|
|
|
+ conn.setAutoCommit(true);
|
|
|
|
|
+ } catch (SQLException ex) {
|
|
|
|
|
+ log.error("恢复自动提交模式失败", ex);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if(conn!=null){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ String name = "meta_hana_self_deliver_order自提提前过账表同步异常";
|
|
|
|
|
+ userOrderAuthorService.sendMailHanaWarning(name);
|
|
|
|
|
+ log.error(name + ", 文件路径: " + Global.getTemdataPath() + "selfDeliverOrder/", e);
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public void runLoadDeliverOrder() throws Exception{
|
|
|
|
|
+ try (
|
|
|
|
|
+ Connection conn = getMysqlConnection();
|
|
|
|
|
+ Statement stmt = conn.createStatement()
|
|
|
|
|
+ ) {
|
|
|
|
|
+ // 设置事务隔离级别
|
|
|
|
|
+ conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
|
|
|
|
|
+ // 开启事务
|
|
|
|
|
+ conn.setAutoCommit(false);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 1. 创建临时表
|
|
|
|
|
+ stmt.execute("CREATE TABLE IF NOT EXISTS meta_hana_deliver_order_temp LIKE meta_hana_deliver_order");
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 加载数据到临时表
|
|
|
|
|
+ String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_deliver_order_temp fields terminated by '$$' lines terminated by '\\n'";
|
|
|
|
|
+ long beginTime = System.currentTimeMillis();
|
|
|
|
|
+ String filePath = Global.getTemdataPath() + "deliverOrder/";
|
|
|
|
|
+ try (InputStream inputStream = mergeGetStream(new File(filePath))) {
|
|
|
|
|
+ int rows = this.bulkLoadFromInputStream(testSql, inputStream);
|
|
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("importing deliverOrder := {} rows data into mysql from {} and cost {} ms!", rows, filePath, (endTime - beginTime));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //删除旧表
|
|
|
|
|
+ try (Connection tempConn = getMysqlConnection();
|
|
|
|
|
+ Statement tempStmt = tempConn.createStatement()) {
|
|
|
|
|
+ tempStmt.execute("DROP TABLE IF EXISTS meta_hana_deliver_order_old");
|
|
|
|
|
+ log.info("成功删除旧表: meta_hana_deliver_order_old");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("删除旧表失败,表名: meta_hana_deliver_order_old", e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 先设置会话级锁等待超时为3秒
|
|
|
|
|
+ try (Statement timeOut = conn.createStatement()) {
|
|
|
|
|
+ timeOut.execute("SET SESSION innodb_lock_wait_timeout = 3");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 执行RENAME并设置语句级超时(原子切换表(RENAME是原子操作))
|
|
|
|
|
+ try (Statement renameTable = conn.createStatement()) {
|
|
|
|
|
+ renameTable.setQueryTimeout(3); // 语句执行超时3秒
|
|
|
|
|
+ renameTable.execute("RENAME TABLE meta_hana_deliver_order TO meta_hana_deliver_order_old, " +
|
|
|
|
|
+ "meta_hana_deliver_order_temp TO meta_hana_deliver_order");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 提交事务
|
|
|
|
|
+ conn.commit();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 清空缓存
|
|
|
|
|
+ String result = HttpUtils.sendGet(orderGetDataHook);
|
|
|
|
|
+ log.info("清空deliverOrder缓存:{}", result);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 回滚事务
|
|
|
try {
|
|
try {
|
|
|
- conn.close();
|
|
|
|
|
- } catch (SQLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- throw new RuntimeException(e);
|
|
|
|
|
|
|
+ conn.rollback();
|
|
|
|
|
+ // 清理临时表
|
|
|
|
|
+ try {
|
|
|
|
|
+ stmt.execute("DROP TABLE IF EXISTS meta_hana_deliver_order_temp");
|
|
|
|
|
+ } catch (SQLException ex) {
|
|
|
|
|
+ log.error("清理临时表失败", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (SQLException ex) {
|
|
|
|
|
+ log.error("事务回滚失败", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ try {
|
|
|
|
|
+ conn.setAutoCommit(true);
|
|
|
|
|
+ } catch (SQLException ex) {
|
|
|
|
|
+ log.error("恢复自动提交模式失败", ex);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ String name = "meta_hana_deliver_order订单表同步异常";
|
|
|
|
|
+ userOrderAuthorService.sendMailHanaWarning(name);
|
|
|
|
|
+ log.error(name + ", 文件路径: " + Global.getTemdataPath() + "deliverOrder/", e);
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static InputStream mergeGetStream(File sourceFile) throws FileNotFoundException {
|
|
public static InputStream mergeGetStream(File sourceFile) throws FileNotFoundException {
|