修改校验

web_backend_develope
chenlw 8 years ago
parent fbc725a351
commit ac8e453aa1

@ -1,6 +1,7 @@
package com.platform.controller; package com.platform.controller;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -16,12 +17,15 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.base.BaseController; import com.base.BaseController;
import com.platform.dao.GatherOracleDao;
import com.platform.entities.GatherOracleInfo;
import com.platform.entities.oracleForm; import com.platform.entities.oracleForm;
import com.platform.service.ILogRead; import com.platform.service.ILogRead;
import com.platform.service.IOracleExtractService; import com.platform.service.IOracleExtractService;
import com.platform.service.thread.ThreadExtractOracle; import com.platform.service.thread.ThreadExtractOracle;
import com.platform.service.thread.ThreadGainOracleConnect; import com.platform.service.thread.ThreadGainOracleConnect;
import com.platform.utils.Configs; import com.platform.utils.Configs;
import com.platform.utils.Constant;
/** oracle /** oracle
* @author chen * @author chen
@ -35,30 +39,51 @@ public class OracleController extends BaseController {
@Resource(name = "logReadService") @Resource(name = "logReadService")
private ILogRead 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, public void oracleStandardExtract(HttpServletRequest res, HttpServletResponse req,
@RequestBody oracleForm form) throws Exception { @RequestBody oracleForm form) throws Exception {
Configs.CONSOLE_LOGGER.error("/oracle/{name}/StandardExtract"); Configs.CONSOLE_LOGGER.info("/oracle//StandardExtract");
// res.setCharacterEncoding("UTF-8"); // res.setCharacterEncoding("UTF-8");
Configs.CONSOLE_LOGGER.info(form.getInneed().get(0).getName());
boolean isConnect = false; boolean isConnect = false;
//5秒内是否能获得oracle连接否则认为超时。 //5秒内是否能获得oracle连接否则认为超时。
if (null != form.getTarget()) { if (null != form.getTarget()) {
ThreadGainOracleConnect thOrcl = new ThreadGainOracleConnect(form, OracleExtract); // 汇总库的信息
thOrcl.start(); GatherOracleInfo oracleInfo = null;
for (int i = 0; i < 10; i++) { List<GatherOracleInfo> oracleConnects = gatherOracleDao.selectAllOracle();
Thread.sleep(400); for (GatherOracleInfo info : oracleConnects) {
isConnect = thOrcl.isConnect(); //抽取标准表的汇总库
if (isConnect) { if (Constant.ORACLE_EXTRACT_TYPE_ONE.equals(info.getType())) {
oracleInfo = info;
break; 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; break;
} }
Thread.sleep(100); else {
if (thOrcl.isExcept()) {
break;
}
Thread.sleep(100);
}
} }
} }
} }
if (isConnect) if (isConnect)
req.setStatus(200); req.setStatus(200);

@ -54,16 +54,17 @@ public class OracleConnector {
public synchronized static ResultSet getSQLExecResultSet(Connection conn, String sql, String filePath) { public synchronized static ResultSet getSQLExecResultSet(Connection conn, String sql, String filePath) {
ResultSet resultSet = null; ResultSet resultSet = null;
filePath = filePath.replace(".log", "");
try { try {
Statement statement = conn Statement statement = conn
.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, .createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE); ResultSet.CONCUR_UPDATABLE);
resultSet = statement.executeQuery(sql); resultSet = statement.executeQuery(sql);
FileOperateHelper FileOperateHelper
.fileWrite(filePath, sql+ "\r\n"+"OK \r\n"); .fileWrite(filePath+".log", sql+ "\r\n"+"OK \r\n");
} catch (SQLException e) { } catch (SQLException e) {
FileOperateHelper 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); new CustomException(Custom4exception.OracleSQL_Except, e);
} }
@ -88,13 +89,14 @@ public class OracleConnector {
* @return true:sql * @return true:sql
*/ */
public synchronized static boolean execOracleSQL(Connection conn, String sql, String filePath) { public synchronized static boolean execOracleSQL(Connection conn, String sql, String filePath) {
filePath = filePath.replace(".log", "");
boolean flag = false; boolean flag = false;
try { try {
Statement statement = conn.createStatement(); Statement statement = conn.createStatement();
statement.execute(sql); statement.execute(sql);
flag = true; flag = true;
FileOperateHelper FileOperateHelper
.fileWrite(filePath, sql+ "\r\n"+"OK \r\n"); .fileWrite(filePath+".log", sql+ "\r\n"+"OK \r\n");
} catch (SQLException e) { } catch (SQLException e) {
flag = false; flag = false;
FileOperateHelper FileOperateHelper
@ -110,6 +112,7 @@ public class OracleConnector {
* @return true:1 * @return true:1
*/ */
public synchronized static boolean execUpdateOracleSQL(Connection conn, String sql, String filePath) { public synchronized static boolean execUpdateOracleSQL(Connection conn, String sql, String filePath) {
filePath = filePath.replace(".log", "");
boolean flag = false; boolean flag = false;
try { try {
Statement statement = conn.createStatement(); Statement statement = conn.createStatement();
@ -117,7 +120,7 @@ public class OracleConnector {
{ {
flag = true; flag = true;
FileOperateHelper FileOperateHelper
.fileWrite(filePath, sql+ "\r\n"+"OK \r\n"); .fileWrite(filePath+".log", sql+ "\r\n"+"OK \r\n");
} }
} catch (SQLException e) { } catch (SQLException e) {
flag = false; flag = false;

@ -26,6 +26,7 @@ public class OracleExtractHelper {
* @return * @return
*/ */
private boolean hasSameNameDBLink(Connection conn, String linkName, String filePath) { private boolean hasSameNameDBLink(Connection conn, String linkName, String filePath) {
boolean flag = false; boolean flag = false;
String sql = "SELECT * FROM ALL_DB_LINKS WHERE DB_LINK='" + linkName+"'"; String sql = "SELECT * FROM ALL_DB_LINKS WHERE DB_LINK='" + linkName+"'";
ResultSet rSet = null; ResultSet rSet = null;
@ -64,7 +65,7 @@ public class OracleExtractHelper {
+ ")))(CONNECT_DATA =(SERVICE_NAME =" + oc.getDatabaseName() + ")))(CONNECT_DATA =(SERVICE_NAME =" + oc.getDatabaseName()
+ ")))\'"; + ")))\'";
if (null != oc) { 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 " String deleteSql = "DROP PUBLIC DATABASE LINK "
+ linkName; + linkName;
// FileOperateHelper // FileOperateHelper
@ -78,7 +79,7 @@ public class OracleExtractHelper {
} else { } else {
Configs.CONSOLE_LOGGER.error("删除已有的DBLink失败,无法创建新的DBLink!"); Configs.CONSOLE_LOGGER.error("删除已有的DBLink失败,无法创建新的DBLink!");
FileOperateHelper.fileWrite(Configs.EXTRACT_LOG_LOCALTION FileOperateHelper.fileWrite(Configs.EXTRACT_LOG_LOCALTION
+ oc.getName(), "删除已有的DBLink失败,无法创建新的DBLink!"+"\r\n"); + oc.getName()+".log", "删除已有的DBLink失败,无法创建新的DBLink!"+"\r\n");
} }
} else { } else {

@ -426,42 +426,38 @@ public class CheckoutServiceImpl implements ICheckoutService {
String pay = ck.getPayResult(); String pay = ck.getPayResult();
String exec = ck.getExecResult(); String exec = ck.getExecResult();
ck.setCheckResult("是"); ck.setCheckResult("是");
if (Constant.CHECKOUT_STATUS_ZERO.equals(ck.getPayResultLast())) { if ("y".equals(pay) || "Y".equals(pay)) {
if ("y".equals(pay) || "Y".equals(pay)) { String payFilePath = FileOperateHelper.addLastSeparator(ck.getPath())+Constant.standard_pay
String payFilePath = FileOperateHelper.addLastSeparator(ck.getPath())+Constant.standard_pay + ck.getAreaCode().toLowerCase()+ck.getSysCode()+".sql";
+ ck.getAreaCode().toLowerCase()+ck.getSysCode()+".sql"; File f = new File(payFilePath);
File f = new File(payFilePath); if(f.exists()){
if(f.exists()){ ck.setPayResultLast(Constant.CHECKOUT_STATUS_THREE);
ck.setPayResultLast(Constant.CHECKOUT_STATUS_THREE);
}
else
{
ck.setPayResultLast(Constant.CHECKOUT_STATUS_FOUR);
}
} }
else { else
//校验结果:成功或失败 0未校验1不需校验2正在校验3校验成功4校验失败5待抽取6正在抽取7抽取完成 {
ck.setPayResultLast(Constant.CHECKOUT_STATUS_ONE); ck.setPayResultLast(Constant.CHECKOUT_STATUS_FOUR);
} }
} }
if (Constant.CHECKOUT_STATUS_ZERO.equals(ck.getExecResultLast())){ else {
if ("y".equals(exec) || "Y".equals(exec)) { //校验结果:成功或失败 0未校验1不需校验2正在校验3校验成功4校验失败5待抽取6正在抽取7抽取完成
String execFilePath = FileOperateHelper.addLastSeparator(ck.getPath())+Constant.standard_indicate ck.setPayResultLast(Constant.CHECKOUT_STATUS_ONE);
+ ck.getAreaCode().toLowerCase()+ck.getSysCode()+".sql"; }
File f = new File(execFilePath); if ("y".equals(exec) || "Y".equals(exec)) {
if (f.exists()) { String execFilePath = FileOperateHelper.addLastSeparator(ck.getPath())+Constant.standard_indicate
ck.setExecResultLast(Constant.CHECKOUT_STATUS_THREE); + ck.getAreaCode().toLowerCase()+ck.getSysCode()+".sql";
} File f = new File(execFilePath);
else if (f.exists()) {
{ ck.setExecResultLast(Constant.CHECKOUT_STATUS_THREE);
ck.setExecResultLast(Constant.CHECKOUT_STATUS_FOUR); }
} 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已校验-- // 1已校验--
ck.setCheckoutFlag(Constant.CHECKOUTFLAG_ONE); ck.setCheckoutFlag(Constant.CHECKOUTFLAG_ONE);
return ck; return ck;

@ -56,7 +56,7 @@ public class OracleExtractServiceImpl implements IOracleExtractService {
+ oracleModel.getDatabaseName(), oracleModel.getUser(), oracleModel.getPassword(),dataInfolist.get(0)); + oracleModel.getDatabaseName(), oracleModel.getUser(), oracleModel.getPassword(),dataInfolist.get(0));
if (null == conn) { if (null == conn) {
FileOperateHelper.fileWrite(Configs.EXTRACT_LOG_LOCALTION 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; return false;
} }
for (OracleConnectorParams collectOracle : datainfos) { for (OracleConnectorParams collectOracle : datainfos) {
@ -132,7 +132,7 @@ public class OracleExtractServiceImpl implements IOracleExtractService {
+ oracleModel.getDatabaseName(), oracleModel.getUser(), oracleModel.getPassword(),dataInfolist.get(0)); + oracleModel.getDatabaseName(), oracleModel.getUser(), oracleModel.getPassword(),dataInfolist.get(0));
if (null == conn) { if (null == conn) {
FileOperateHelper.fileWrite(Configs.EXTRACT_LOG_LOCALTION 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; return false;
} }
for (OracleConnectorParams collectOracle : datainfos) { for (OracleConnectorParams collectOracle : datainfos) {

@ -15,7 +15,9 @@ import com.platform.dao.DataInfoDao;
import com.platform.entities.CheckoutEntity; import com.platform.entities.CheckoutEntity;
import com.platform.entities.DataInfoEntity; import com.platform.entities.DataInfoEntity;
import com.platform.entities.GatherOracleInfo; import com.platform.entities.GatherOracleInfo;
import com.platform.entities.OracleConnectorParams;
import com.platform.oracle.OracleConnector; import com.platform.oracle.OracleConnector;
import com.platform.service.OracleExtractHelper;
import com.platform.utils.Configs; import com.platform.utils.Configs;
import com.platform.utils.Constant; import com.platform.utils.Constant;
import com.platform.utils.FileOperateHelper; import com.platform.utils.FileOperateHelper;
@ -26,6 +28,11 @@ import com.platform.utils.FileOperateHelper;
*/ */
public class ThreadExtractStandardSqlServer extends Thread{ public class ThreadExtractStandardSqlServer extends Thread{
/**
*
*/
private OracleExtractHelper oracleExtract = new OracleExtractHelper();
/** 汇总库 */ /** 汇总库 */
private GatherOracleInfo oracleConnect; private GatherOracleInfo oracleConnect;
@ -61,11 +68,20 @@ public class ThreadExtractStandardSqlServer extends Thread{
} }
File paySql = new File(payFilePath); File paySql = new File(payFilePath);
try { 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); FileInputStream fis = new FileInputStream(paySql);
BufferedReader br = new BufferedReader(new InputStreamReader(fis,"GBK")); BufferedReader br = new BufferedReader(new InputStreamReader(fis,"GBK"));
String sql = br.readLine(); 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) { while (sql != null) {
//TODO 执行sql //TODO 执行sql
sql = br.readLine(); sql = br.readLine();
@ -150,5 +166,7 @@ public class ThreadExtractStandardSqlServer extends Thread{
} }
} }
} }
} }

Loading…
Cancel
Save