diff --git a/src/com/platform/controller/OracleController.java b/src/com/platform/controller/OracleController.java index fcb7416f..bd354129 100644 --- a/src/com/platform/controller/OracleController.java +++ b/src/com/platform/controller/OracleController.java @@ -1,6 +1,7 @@ package com.platform.controller; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.annotation.Resource; @@ -16,12 +17,15 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.base.BaseController; +import com.platform.dao.GatherOracleDao; +import com.platform.entities.GatherOracleInfo; import com.platform.entities.oracleForm; import com.platform.service.ILogRead; import com.platform.service.IOracleExtractService; import com.platform.service.thread.ThreadExtractOracle; import com.platform.service.thread.ThreadGainOracleConnect; import com.platform.utils.Configs; +import com.platform.utils.Constant; /** oracle相关业务 * @author chen @@ -35,30 +39,51 @@ public class OracleController extends BaseController { @Resource(name = "logReadService") private ILogRead logReadService; + + @Resource(name = "gatherOracleDao") + private GatherOracleDao gatherOracleDao; - @RequestMapping(value = "/oracle/{name}/StandardExtract", method = RequestMethod.POST) + @RequestMapping(value = "/oracle/{id}/StandardExtract", method = RequestMethod.POST) public void oracleStandardExtract(HttpServletRequest res, HttpServletResponse req, @RequestBody oracleForm form) throws Exception { - Configs.CONSOLE_LOGGER.error("/oracle/{name}/StandardExtract"); + Configs.CONSOLE_LOGGER.info("/oracle//StandardExtract"); // res.setCharacterEncoding("UTF-8"); + Configs.CONSOLE_LOGGER.info(form.getInneed().get(0).getName()); boolean isConnect = false; //5秒内是否能获得oracle连接,否则认为超时。 if (null != form.getTarget()) { - ThreadGainOracleConnect thOrcl = new ThreadGainOracleConnect(form, OracleExtract); - thOrcl.start(); - for (int i = 0; i < 10; i++) { - Thread.sleep(400); - isConnect = thOrcl.isConnect(); - if (isConnect) { + // 汇总库的信息 + GatherOracleInfo oracleInfo = null; + List oracleConnects = gatherOracleDao.selectAllOracle(); + for (GatherOracleInfo info : oracleConnects) { + //抽取标准表的汇总库 + if (Constant.ORACLE_EXTRACT_TYPE_ONE.equals(info.getType())) { + oracleInfo = info; break; } - else { - if (thOrcl.isExcept()) { + } + if (null == oracleInfo) { + isConnect = false; + } + else { + form.setTarget(oracleInfo); + ThreadGainOracleConnect thOrcl = new ThreadGainOracleConnect(form, OracleExtract); + thOrcl.start(); + for (int i = 0; i < 10; i++) { + Thread.sleep(400); + isConnect = thOrcl.isConnect(); + if (isConnect) { break; } - Thread.sleep(100); + else { + if (thOrcl.isExcept()) { + break; + } + Thread.sleep(100); + } } } + } if (isConnect) req.setStatus(200); diff --git a/src/com/platform/oracle/OracleConnector.java b/src/com/platform/oracle/OracleConnector.java index 6dda56f6..9badca72 100644 --- a/src/com/platform/oracle/OracleConnector.java +++ b/src/com/platform/oracle/OracleConnector.java @@ -54,16 +54,17 @@ public class OracleConnector { public synchronized static ResultSet getSQLExecResultSet(Connection conn, String sql, String filePath) { ResultSet resultSet = null; + filePath = filePath.replace(".log", ""); try { Statement statement = conn .createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); resultSet = statement.executeQuery(sql); FileOperateHelper - .fileWrite(filePath, sql+ "\r\n"+"OK \r\n"); + .fileWrite(filePath+".log", sql+ "\r\n"+"OK \r\n"); } catch (SQLException e) { FileOperateHelper - .fileWrite(filePath, sql+ "\r\n"+e.getMessage()+"\r\n"); + .fileWrite(filePath+".log", sql+ "\r\n"+e.getMessage()+"\r\n"); new CustomException(Custom4exception.OracleSQL_Except, e); } @@ -88,13 +89,14 @@ public class OracleConnector { * @return true:执行的不返回集合数据的sql成功, 是否执行成功 */ public synchronized static boolean execOracleSQL(Connection conn, String sql, String filePath) { + filePath = filePath.replace(".log", ""); boolean flag = false; try { Statement statement = conn.createStatement(); statement.execute(sql); flag = true; FileOperateHelper - .fileWrite(filePath, sql+ "\r\n"+"OK \r\n"); + .fileWrite(filePath+".log", sql+ "\r\n"+"OK \r\n"); } catch (SQLException e) { flag = false; FileOperateHelper @@ -110,6 +112,7 @@ public class OracleConnector { * @return true:执行结果大于1,即有数据 是否执行成功 */ public synchronized static boolean execUpdateOracleSQL(Connection conn, String sql, String filePath) { + filePath = filePath.replace(".log", ""); boolean flag = false; try { Statement statement = conn.createStatement(); @@ -117,7 +120,7 @@ public class OracleConnector { { flag = true; FileOperateHelper - .fileWrite(filePath, sql+ "\r\n"+"OK \r\n"); + .fileWrite(filePath+".log", sql+ "\r\n"+"OK \r\n"); } } catch (SQLException e) { flag = false; diff --git a/src/com/platform/service/OracleExtractHelper.java b/src/com/platform/service/OracleExtractHelper.java index 0bd18ca3..46e89a84 100644 --- a/src/com/platform/service/OracleExtractHelper.java +++ b/src/com/platform/service/OracleExtractHelper.java @@ -26,6 +26,7 @@ public class OracleExtractHelper { * @return */ private boolean hasSameNameDBLink(Connection conn, String linkName, String filePath) { + boolean flag = false; String sql = "SELECT * FROM ALL_DB_LINKS WHERE DB_LINK='" + linkName+"'"; ResultSet rSet = null; @@ -64,7 +65,7 @@ public class OracleExtractHelper { + ")))(CONNECT_DATA =(SERVICE_NAME =" + oc.getDatabaseName() + ")))\'"; if (null != oc) { - if (hasSameNameDBLink(conn, linkName, Configs.EXTRACT_LOG_LOCALTION + oc.getName())) { // 如果dblink已经存在,先删除dblink,在创建dblink + if (hasSameNameDBLink(conn, linkName, Configs.EXTRACT_LOG_LOCALTION + oc.getName()+".log")) { // 如果dblink已经存在,先删除dblink,在创建dblink String deleteSql = "DROP PUBLIC DATABASE LINK " + linkName; // FileOperateHelper @@ -78,7 +79,7 @@ public class OracleExtractHelper { } else { Configs.CONSOLE_LOGGER.error("删除已有的DBLink失败,无法创建新的DBLink!"); FileOperateHelper.fileWrite(Configs.EXTRACT_LOG_LOCALTION - + oc.getName(), "删除已有的DBLink失败,无法创建新的DBLink!"+"\r\n"); + + oc.getName()+".log", "删除已有的DBLink失败,无法创建新的DBLink!"+"\r\n"); } } else { diff --git a/src/com/platform/service/impl/CheckoutServiceImpl.java b/src/com/platform/service/impl/CheckoutServiceImpl.java index 73070acc..0239d9b6 100644 --- a/src/com/platform/service/impl/CheckoutServiceImpl.java +++ b/src/com/platform/service/impl/CheckoutServiceImpl.java @@ -426,42 +426,38 @@ public class CheckoutServiceImpl implements ICheckoutService { String pay = ck.getPayResult(); String exec = ck.getExecResult(); ck.setCheckResult("是"); - if (Constant.CHECKOUT_STATUS_ZERO.equals(ck.getPayResultLast())) { - if ("y".equals(pay) || "Y".equals(pay)) { - String payFilePath = FileOperateHelper.addLastSeparator(ck.getPath())+Constant.standard_pay - + ck.getAreaCode().toLowerCase()+ck.getSysCode()+".sql"; - File f = new File(payFilePath); - if(f.exists()){ - ck.setPayResultLast(Constant.CHECKOUT_STATUS_THREE); - } - else - { - ck.setPayResultLast(Constant.CHECKOUT_STATUS_FOUR); - } + if ("y".equals(pay) || "Y".equals(pay)) { + String payFilePath = FileOperateHelper.addLastSeparator(ck.getPath())+Constant.standard_pay + + ck.getAreaCode().toLowerCase()+ck.getSysCode()+".sql"; + File f = new File(payFilePath); + if(f.exists()){ + ck.setPayResultLast(Constant.CHECKOUT_STATUS_THREE); } - else { - //校验结果:成功或失败 0:未校验,1:不需校验,2:正在校验,3:校验成功,4:校验失败,5:待抽取,6:正在抽取,7:抽取完成 - ck.setPayResultLast(Constant.CHECKOUT_STATUS_ONE); + else + { + ck.setPayResultLast(Constant.CHECKOUT_STATUS_FOUR); } } - if (Constant.CHECKOUT_STATUS_ZERO.equals(ck.getExecResultLast())){ - if ("y".equals(exec) || "Y".equals(exec)) { - String execFilePath = FileOperateHelper.addLastSeparator(ck.getPath())+Constant.standard_indicate - + ck.getAreaCode().toLowerCase()+ck.getSysCode()+".sql"; - File f = new File(execFilePath); - if (f.exists()) { - ck.setExecResultLast(Constant.CHECKOUT_STATUS_THREE); - } - else - { - ck.setExecResultLast(Constant.CHECKOUT_STATUS_FOUR); - } + else { + //校验结果:成功或失败 0:未校验,1:不需校验,2:正在校验,3:校验成功,4:校验失败,5:待抽取,6:正在抽取,7:抽取完成 + ck.setPayResultLast(Constant.CHECKOUT_STATUS_ONE); + } + if ("y".equals(exec) || "Y".equals(exec)) { + String execFilePath = FileOperateHelper.addLastSeparator(ck.getPath())+Constant.standard_indicate + + ck.getAreaCode().toLowerCase()+ck.getSysCode()+".sql"; + File f = new File(execFilePath); + if (f.exists()) { + ck.setExecResultLast(Constant.CHECKOUT_STATUS_THREE); + } + else + { + ck.setExecResultLast(Constant.CHECKOUT_STATUS_FOUR); } - else { - //校验结果:成功或失 0:未校验,1:不需校验,2:正在校验,3:校验成功,4:校验失败,5:待抽取,6:正在抽取,7:抽取完成 - ck.setExecResultLast(Constant.CHECKOUT_STATUS_ONE); - } } + else { + //校验结果:成功或失 0:未校验,1:不需校验,2:正在校验,3:校验成功,4:校验失败,5:待抽取,6:正在抽取,7:抽取完成 + ck.setExecResultLast(Constant.CHECKOUT_STATUS_ONE); + } // 1:已校验-- ck.setCheckoutFlag(Constant.CHECKOUTFLAG_ONE); return ck; diff --git a/src/com/platform/service/impl/OracleExtractServiceImpl.java b/src/com/platform/service/impl/OracleExtractServiceImpl.java index 4cc96b11..14e5d4d4 100644 --- a/src/com/platform/service/impl/OracleExtractServiceImpl.java +++ b/src/com/platform/service/impl/OracleExtractServiceImpl.java @@ -56,7 +56,7 @@ public class OracleExtractServiceImpl implements IOracleExtractService { + oracleModel.getDatabaseName(), oracleModel.getUser(), oracleModel.getPassword(),dataInfolist.get(0)); if (null == conn) { FileOperateHelper.fileWrite(Configs.EXTRACT_LOG_LOCALTION - + dataInfolist.get(0).getName(), "创建oracle连接失败: [" + conn + "]\r\n"); + + dataInfolist.get(0).getName()+".log", "创建oracle连接失败: [" + conn + "]\r\n"); return false; } for (OracleConnectorParams collectOracle : datainfos) { @@ -132,7 +132,7 @@ public class OracleExtractServiceImpl implements IOracleExtractService { + oracleModel.getDatabaseName(), oracleModel.getUser(), oracleModel.getPassword(),dataInfolist.get(0)); if (null == conn) { FileOperateHelper.fileWrite(Configs.EXTRACT_LOG_LOCALTION - + dataInfolist.get(0).getName(), "创建oracle连接失败: [" + conn + "]\r\n"); + + dataInfolist.get(0).getName()+".log", "创建oracle连接失败: [" + conn + "]\r\n"); return false; } for (OracleConnectorParams collectOracle : datainfos) { diff --git a/src/com/platform/service/thread/ThreadExtractStandardSqlServer.java b/src/com/platform/service/thread/ThreadExtractStandardSqlServer.java index 2650f170..19fd39b3 100644 --- a/src/com/platform/service/thread/ThreadExtractStandardSqlServer.java +++ b/src/com/platform/service/thread/ThreadExtractStandardSqlServer.java @@ -15,7 +15,9 @@ import com.platform.dao.DataInfoDao; import com.platform.entities.CheckoutEntity; import com.platform.entities.DataInfoEntity; import com.platform.entities.GatherOracleInfo; +import com.platform.entities.OracleConnectorParams; import com.platform.oracle.OracleConnector; +import com.platform.service.OracleExtractHelper; import com.platform.utils.Configs; import com.platform.utils.Constant; import com.platform.utils.FileOperateHelper; @@ -26,6 +28,11 @@ import com.platform.utils.FileOperateHelper; */ public class ThreadExtractStandardSqlServer extends Thread{ + /** + * 抽取 + */ + private OracleExtractHelper oracleExtract = new OracleExtractHelper(); + /** 汇总库 */ private GatherOracleInfo oracleConnect; @@ -61,11 +68,20 @@ public class ThreadExtractStandardSqlServer extends Thread{ } File paySql = new File(payFilePath); try { + //获取连接 + Connection conn = OracleConnector.ConnectionBuilder("jdbc:oracle:thin:@" + oracleConnect.getIp() + ":" + oracleConnect.getPort() + ":" + + oracleConnect.getDatabaseName(), oracleConnect.getUser(), oracleConnect.getPassword(), null); + //设置 日志 的 文件名 + OracleConnectorParams collectOracle = new OracleConnectorParams(); + collectOracle.setName("CQ"+ element.getAreaCode().toLowerCase()+"_"+element.getSysCode()+"_"+element.getDataVersion()); + // 创建表空间 创建 抽取标准表的 用户并授权 + oracleExtract.createTableSpace(conn, collectOracle , oracleConnect); // + oracleExtract.createOnlyUser(conn, collectOracle, oracleConnect);// + + //读取文件流 FileInputStream fis = new FileInputStream(paySql); BufferedReader br = new BufferedReader(new InputStreamReader(fis,"GBK")); String sql = br.readLine(); - Connection conn = OracleConnector.ConnectionBuilder("jdbc:oracle:thin:@" + oracleConnect.getIp() + ":" + oracleConnect.getPort() + ":" - + oracleConnect.getDatabaseName(), oracleConnect.getUser(), oracleConnect.getPassword(), null); while (sql != null) { //TODO 执行sql sql = br.readLine(); @@ -150,5 +166,7 @@ public class ThreadExtractStandardSqlServer extends Thread{ } } } + + }