...
This commit is contained in:
parent
22eb976740
commit
f1e93989cb
@ -7,7 +7,6 @@ package com.cpic.telsale.DataImport;
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import com.cpic.telsale.TelsalePolicyRecord;
|
||||
@ -26,7 +25,7 @@ public class DataImport
|
||||
* @Author: 王炜
|
||||
* @Date: 2021/6/21
|
||||
*/
|
||||
public static ArrayList<TelsalePolicyRecord> readTelsalePolicyDataFromXlsx( String fileName, int sheetIndex )
|
||||
private static ArrayList<TelsalePolicyRecord> readTelsalePolicyDataFromXlsx( String fileName, int sheetIndex )
|
||||
throws IOException,
|
||||
XlsFileFormatException
|
||||
{
|
||||
@ -409,16 +408,25 @@ public class DataImport
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void saveTelsalePolicyDataToOracle( String dbURL,
|
||||
String userName,
|
||||
String password,
|
||||
/***
|
||||
* @Description: 将电销保单数据写入到oracle数据库,通过数据库验证保单和经办人有效性,并获取经办人和录入人详细信息。
|
||||
* 要么全表成功,要么全表失败。
|
||||
* 错误信息保存在errorMessage,全表完成后检查错误数量,有错误就抛出errorMessage。
|
||||
* @Param: dbURL oracle的链接字符串
|
||||
* @Param: userName 用户名
|
||||
* @Param: password 密码
|
||||
* @Param: policyList 保存电销保单数据的ArrayList
|
||||
* @return: void
|
||||
* @Author: 王炜
|
||||
* @Date: 2021/6/23
|
||||
*/
|
||||
private static void saveTelsalePolicyDataToOracle( Connection oracleConnection,
|
||||
ArrayList<TelsalePolicyRecord> policyList )
|
||||
throws NullPointerException,
|
||||
TesalePolicyDataSaveToOracleException,
|
||||
TelsalePolicyDataSaveToOracleException,
|
||||
SQLException
|
||||
|
||||
{
|
||||
Connection conn = null;
|
||||
CallableStatement callStmt = null;
|
||||
|
||||
String callProcedureSql = "{call telsale_policy_check_pkg.save_policy(?,?,?,?,?,?,?,?,?,?,?,?,?)}";
|
||||
@ -435,10 +443,9 @@ public class DataImport
|
||||
try
|
||||
{
|
||||
Class.forName( "oracle.jdbc.driver.OracleDriver" );
|
||||
conn = DriverManager.getConnection( dbURL, userName, password );
|
||||
callStmt = conn.prepareCall( callProcedureSql );
|
||||
callStmt = oracleConnection.prepareCall( callProcedureSql );
|
||||
|
||||
conn.setAutoCommit( false );
|
||||
oracleConnection.setAutoCommit( false );
|
||||
|
||||
for ( TelsalePolicyRecord recordIterator : policyList )
|
||||
{
|
||||
@ -495,40 +502,166 @@ public class DataImport
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( SQLException error )
|
||||
{
|
||||
throw error;
|
||||
}
|
||||
catch ( ClassNotFoundException error )
|
||||
{
|
||||
error.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
//关闭连接
|
||||
try
|
||||
{
|
||||
if ( errorCount == 0 )
|
||||
{
|
||||
conn.commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
conn.rollback();
|
||||
}
|
||||
|
||||
conn.close();
|
||||
}
|
||||
catch ( SQLException error )
|
||||
{
|
||||
//不处理了
|
||||
}
|
||||
}
|
||||
|
||||
//根据错误数量,判断是否抛出异常
|
||||
if ( errorCount > 0 )
|
||||
{
|
||||
throw new TesalePolicyDataSaveToOracleException( errorMessage );
|
||||
throw new TelsalePolicyDataSaveToOracleException( errorMessage );
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveTelsalePolicyDataToInformix( Connection conn, ArrayList<TelsalePolicyRecord> policyList )
|
||||
throws ClassNotFoundException,
|
||||
SQLException,
|
||||
TelsalePolicyDataSaveToInformixException
|
||||
{
|
||||
if ( policyList == null )
|
||||
{
|
||||
throw new NullPointerException( "policyList参数为null!" );
|
||||
}
|
||||
|
||||
//Connection conn = null;
|
||||
PreparedStatement statement = null;
|
||||
|
||||
int errorCount = 0;
|
||||
String errorMessage = "写入数据错误,请根据提示修正后重新上传!";
|
||||
String insertSQL =
|
||||
"INSERT INTO dxbd_test \n" +
|
||||
" (bdh,\n" +
|
||||
" zhjywy,\n" +
|
||||
" zhjywymc,\n" +
|
||||
" kshdm,\n" +
|
||||
" kshmc,\n" +
|
||||
" zhjywybm,\n" +
|
||||
" zhjywybmm,\n" +
|
||||
" khjl,\n" +
|
||||
" khjllx,\n" +
|
||||
" jjbj,\n" +
|
||||
" czydm,\n" +
|
||||
" czrq)\n" +
|
||||
"VALUES\n" +
|
||||
" (?,\n" +
|
||||
" ?,\n" +
|
||||
" ?,\n" +
|
||||
" ?,\n" +
|
||||
" ?,\n" +
|
||||
" ?,\n" +
|
||||
" ?,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 1,\n" +
|
||||
" '800',\n" +
|
||||
" today)";
|
||||
|
||||
|
||||
statement = conn.prepareStatement( insertSQL );
|
||||
|
||||
for ( TelsalePolicyRecord recordIterator : policyList )
|
||||
{
|
||||
statement.setString( 1, recordIterator.getPolicyNo() );
|
||||
statement.setString( 2, recordIterator.getOperatorCode() );
|
||||
statement.setString( 3, recordIterator.getOperatorName() );
|
||||
statement.setString( 4, recordIterator.getOperatorSectionOfficeCode() );
|
||||
statement.setString( 5, recordIterator.getOperatorSectionOfficeName() );
|
||||
statement.setString( 6, recordIterator.getOperatorDepartmentCode() );
|
||||
statement.setString( 7, recordIterator.getOperatorDepartmentName() );
|
||||
|
||||
try
|
||||
{
|
||||
statement.execute();
|
||||
}
|
||||
catch ( SQLException error )
|
||||
{
|
||||
//捕捉写入错误
|
||||
errorMessage += "保单号" +
|
||||
recordIterator.getPolicyNo() +
|
||||
"保存失败,错误提示:" +
|
||||
error.getMessage() + "<br>\n";
|
||||
|
||||
errorCount++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Param:
|
||||
* @return: void
|
||||
* @Author: 王炜
|
||||
* @Date: 2021/6/23
|
||||
*/
|
||||
public static void saveTelsalePolicyData( String filePath,
|
||||
String oracleURL,
|
||||
String oracleUserName,
|
||||
String oraclePassword,
|
||||
String informixURL )
|
||||
throws ClassNotFoundException,
|
||||
IOException,
|
||||
XlsFileFormatException,
|
||||
SQLException,
|
||||
TelsalePolicyDataSaveToDatabaseException
|
||||
{
|
||||
|
||||
//读取文件
|
||||
ArrayList<TelsalePolicyRecord> policyList = null;
|
||||
|
||||
policyList = readTelsalePolicyDataFromXlsx( filePath, 0 );
|
||||
|
||||
Class.forName( "com.informix.jdbc.IfxDriver" );
|
||||
Class.forName( "oracle.jdbc.driver.OracleDriver" );
|
||||
|
||||
Connection oracleConnection = null;
|
||||
Connection informixConnection = null;
|
||||
|
||||
//打开连接
|
||||
oracleConnection = DriverManager.getConnection( oracleURL, oracleUserName, oraclePassword );
|
||||
informixConnection = DriverManager.getConnection( informixURL );
|
||||
|
||||
try
|
||||
{
|
||||
saveTelsalePolicyDataToOracle( oracleConnection, policyList );
|
||||
//saveTelsalePolicyDataToInformix( informixConnection, policyList );
|
||||
}
|
||||
catch ( TelsalePolicyDataSaveToOracleException error )
|
||||
{
|
||||
//写入oracle错误,回滚两个数据库,再抛出异常
|
||||
oracleConnection.rollback();
|
||||
informixConnection.rollback();
|
||||
|
||||
throw new TelsalePolicyDataSaveToDatabaseException( error.getMessage() );
|
||||
}
|
||||
// catch ( TelsalePolicyDataSaveToInformixException error )
|
||||
// {
|
||||
// //写入informix错误,回滚两个数据库,再抛出异常
|
||||
// oracleConnection.rollback();
|
||||
// informixConnection.rollback();
|
||||
//
|
||||
// throw new TelsalePolicyDataSaveToDatabaseException( error.getMessage() );
|
||||
// }
|
||||
catch (SQLException error )
|
||||
{
|
||||
//任何其他sql错误,回滚两个数据库,再抛出异常
|
||||
oracleConnection.rollback();
|
||||
informixConnection.rollback();
|
||||
|
||||
throw error;
|
||||
}
|
||||
finally
|
||||
{
|
||||
//无论如何要关闭连接
|
||||
try
|
||||
{
|
||||
oracleConnection.close();
|
||||
informixConnection.close();
|
||||
}
|
||||
catch ( SQLException error )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.cpic.telsale.DataImport;
|
||||
|
||||
/**
|
||||
* @program: 2018版电销管理系统
|
||||
* @description: 111
|
||||
* @author: Kane Wang
|
||||
* @create: 2021-06-23 15:23
|
||||
**/
|
||||
public class TelsalePolicyDataSaveToDatabaseException extends Exception
|
||||
{
|
||||
public TelsalePolicyDataSaveToDatabaseException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.cpic.telsale.DataImport;
|
||||
|
||||
/**
|
||||
* @program: 2018版电销管理系统
|
||||
* @description: 保存电销数据至informix数据库错误。
|
||||
* @author: Kane Wang
|
||||
* @create: 2021-06-23 14:33
|
||||
**/
|
||||
public class TelsalePolicyDataSaveToInformixException extends Exception
|
||||
{
|
||||
public TelsalePolicyDataSaveToInformixException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
}
|
@ -6,9 +6,9 @@ package com.cpic.telsale.DataImport;
|
||||
* @author: Kane Wang
|
||||
* @create: 2021-06-23 11:29
|
||||
**/
|
||||
public class TesalePolicyDataSaveToOracleException extends Exception
|
||||
public class TelsalePolicyDataSaveToOracleException extends Exception
|
||||
{
|
||||
public TesalePolicyDataSaveToOracleException( String message )
|
||||
public TelsalePolicyDataSaveToOracleException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
@ -13,11 +13,12 @@ import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import com.cpic.telsale.DataImport.*;
|
||||
|
||||
import static com.cpic.telsale.DataImport.DataImport.saveTelsalePolicyDataToOracle;
|
||||
import static com.cpic.telsale.DataImport.DataImport.saveTelsalePolicyData;
|
||||
|
||||
public class uploadDataProcessor extends HttpServlet
|
||||
{
|
||||
@ -75,17 +76,12 @@ public class uploadDataProcessor extends HttpServlet
|
||||
//保存上传的文件,返回文件完整路径。
|
||||
String upLoadedFileName = saveUploadedFile( fileItem );
|
||||
|
||||
//测试
|
||||
policyRecordList = DataImport.readTelsalePolicyDataFromXlsx( upLoadedFileName, 0 );
|
||||
saveTelsalePolicyDataToOracle( oracleURL,
|
||||
//写入数据
|
||||
saveTelsalePolicyData( upLoadedFileName,
|
||||
oracleURL,
|
||||
oracleUserName,
|
||||
oraclePassword,
|
||||
policyRecordList );
|
||||
|
||||
// importMessage = DataImport.importTelsalePolicyDataFromXlsx( upLoadedFileName,
|
||||
// telsalePolicyOperatorListTableName,
|
||||
// informixURL );
|
||||
|
||||
informixURL );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,9 +95,9 @@ public class uploadDataProcessor extends HttpServlet
|
||||
//文件格式异常
|
||||
importMessage = error.getMessage();
|
||||
}
|
||||
catch ( TesalePolicyDataSaveToOracleException error )
|
||||
catch ( TelsalePolicyDataSaveToDatabaseException error )
|
||||
{
|
||||
//保存到oracle异常
|
||||
//保存到数据库异常
|
||||
importMessage = error.getMessage();
|
||||
}
|
||||
catch ( IOException error )
|
||||
@ -109,6 +105,10 @@ public class uploadDataProcessor extends HttpServlet
|
||||
//包装一下重新抛出
|
||||
throw new ServletException( error.getMessage() );
|
||||
}
|
||||
catch ( SQLException error )
|
||||
{
|
||||
throw new ServletException( error.getMessage() );
|
||||
}
|
||||
catch ( Exception error )
|
||||
{
|
||||
throw new ServletException( error.getMessage() );
|
||||
|
@ -35,13 +35,17 @@
|
||||
<param-name>informixURL</param-name>
|
||||
<param-value>jdbc:informix-sqli://10.187.11.163:9096/ywgl_xm:INFORMIXSERVER=pxmcx2;newcodeset=GBK,8859-1,819;user=ccx99;password=ct0IT17!</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>ora_telsale_url</param-name>
|
||||
<param-value>jdbc:oracle:thin:@10.39.0.85:1521:dev01;user=telsale;password=Cpic%231234;</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>ora_xmcx1_url</param-name>
|
||||
<param-value>jdbc:oracle:thin:@10.39.0.86:1521:xmcx1;user=ywglxt;password=ywglxt";</param-value>
|
||||
<param-value>jdbc:oracle:thin:@10.39.0.86:1521:xmcx1;user=ywglxt;password=ywglxt;</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>ora_jgy_url</param-name>
|
||||
<param-value>jdbc:oracle:thin:@10.187.11.164:1521:xmcx1;user=ywglxt;password=ywglxt";</param-value>
|
||||
<param-value>jdbc:oracle:thin:@10.187.11.164:1521:xmcx1;user=ywglxt;password=ywglxt;</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>telsalePolicyOperatorListTableName</param-name>
|
||||
|
Loading…
x
Reference in New Issue
Block a user