diff --git a/代码/jsp/.gitignore b/代码/jsp/.gitignore index 0054f52..3f75a2e 100644 --- a/代码/jsp/.gitignore +++ b/代码/jsp/.gitignore @@ -1,3 +1,2 @@ .idea/workspace.xml -out/ -dataSources/ + diff --git a/代码/jsp/.idea/codeStyles/codeStyleConfig.xml b/代码/jsp/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..c9f793b --- /dev/null +++ b/代码/jsp/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/代码/jsp/src/com/cpic/telsale/DataImport/DataImport.java b/代码/jsp/src/com/cpic/telsale/DataImport/DataImport.java index 84ad985..a439d92 100644 --- a/代码/jsp/src/com/cpic/telsale/DataImport/DataImport.java +++ b/代码/jsp/src/com/cpic/telsale/DataImport/DataImport.java @@ -24,21 +24,18 @@ public class DataImport /** * 读取xls表格插入数据,要么全部成功,要么全部失败。 - * @param fileName xls文件名 - * @param oracleURL oracle数据库URL - * @param oracleUserName oracle用户名 - * @param oraclePassword oracle密码 - * @param informixURL informix数据库URL + * + * @param fileName xls文件名 + * @param telsalePolicyOperatorListTableName informix库电销转介绍表名 + * @param informixURL informix数据库URL * @return * @throws IOException * @throws ClassNotFoundException - * @throws SQLException 数据库异常 + * @throws SQLException 数据库异常 * @throws XlsFileFormatException xls文件格式错误异常 */ public static String importTelsalePolicyDataFromXlsx( String fileName, - String oracleURL, - String oracleUserName, - String oraclePassword, + String telsalePolicyOperatorListTableName, String informixURL ) throws IOException, ClassNotFoundException, @@ -47,9 +44,9 @@ public class DataImport { String importResult = ""; String importMessage = null; - int rowCount = 1; - int successCount = 0; - int failCount = 0; + int rowCount = 1; //excel文件行索引 + int successCount = 0; //成功写入的行计数 + int failCount = 0; //写入失败的行计数 //excel相关 FileInputStream xlsFileIn = null; @@ -61,7 +58,7 @@ public class DataImport { xlsFileIn = new FileInputStream( fileName ); xlsFile = new HSSFWorkbook( xlsFileIn ); - sheet = xlsFile.getSheet( "Sheet1" ); + sheet = xlsFile.getSheetAt( 0 ); //第一个sheet row = sheet.getRow( rowCount ); } catch( IOException error ) //有文件格式错误的可能。 @@ -72,47 +69,10 @@ public class DataImport throw new XlsFileFormatException( "文件格式错误,请检查是否xls格式文件。" ); } - //oracle相关 - Class.forName( "oracle.jdbc.driver.OracleDriver" ); - - Connection oracleConn = null; - PreparedStatement oracleStmt = null; - String oraSql = - "INSERT INTO telsale_oper_lst\n" + - " (policy_no,\n" + - " operator_code,\n" + - " operator_name,\n" + - " section_office_code,\n" + - " section_office_name,\n" + - " department_code,\n" + - " department_name,\n" + - " autotrader_code,\n" + - " insruant_name,\n" + - " plate_no,\n" + - " entry_staff_code,\n" + - " entry_date)\n" + - "VALUES\n" + - " (?,\n" + - " ?,\n" + - " ?,\n" + - " ?,\n" + - " ?,\n" + - " ?,\n" + - " ?,\n" + - " ?,\n" + - " ?,\n" + - " ?,\n" + - " '800',\n" + - " SYSDATE)"; - - oracleConn = DriverManager.getConnection( oracleURL, oracleUserName, oraclePassword ); - oracleConn.setAutoCommit( false );//关闭自动提交,整个表格要么全部成写入,要么全部失败。 - oracleStmt = oracleConn.prepareStatement( oraSql ); - //informix相关 Class.forName( "com.informix.jdbc.IfxDriver" ); String ifxSql = - "INSERT INTO w_dxbd_i\n" + + "INSERT INTO " + telsalePolicyOperatorListTableName + " \n" + " (bdh,\n" + " zhjywy,\n" + " zhjywymc,\n" + @@ -174,20 +134,6 @@ public class DataImport //取得经办人信息 staff = new StaffInfo( operatorCode ); - //写入oracle -// oracleStmt.setString( 1, policyNo ); -// oracleStmt.setString( 2, staff.getStaffCode() ); -// oracleStmt.setString( 3, staff.getStaffName() ); -// oracleStmt.setString( 4, staff.getSectionOfficeCode() ); -// oracleStmt.setString( 5, staff.getSectionOfficeName() ); -// oracleStmt.setString( 6, staff.getDepartmentCode() ); -// oracleStmt.setString( 7, staff.getDepartmentName() ); -// oracleStmt.setString( 8, getStringValueFromHSSFCell( row.getCell( 6 ) ) ); -// oracleStmt.setString( 9, getStringValueFromHSSFCell( row.getCell( 3 ) ) ); -// oracleStmt.setString( 10, getStringValueFromHSSFCell( row.getCell( 2 ) ) ); -// -// oracleStmt.execute(); - //写入informix ifxStmt.setString( 1, policyNo ); ifxStmt.setString( 2, staff.getStaffCode() ); @@ -201,6 +147,8 @@ public class DataImport ifxStmt.setString( 10, getStringValueFromHSSFCell( row.getCell( 2 ) ) ); ifxStmt.execute(); + + successCount++; } catch( StaffCodeNotExistException error ) { @@ -209,6 +157,9 @@ public class DataImport //标志位 isSuccess = false; + + //计数 + failCount++; } catch( SQLException error ) { @@ -217,6 +168,20 @@ public class DataImport //标志位 isSuccess = false; + + //计数 + failCount++; + } + catch( Exception error ) + { + //写入错误 + importResult = importResult + "第" + rowCount + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。
"; + + //标志位 + isSuccess = false; + + //计数 + failCount++; } } @@ -227,25 +192,36 @@ public class DataImport //判断标志位,如果为false,则说明在保存过程中出现了错误,放弃所有过程,进行回滚。 if ( isSuccess == true ) { - oracleConn.commit(); + //oracleConn.commit(); ifxConn.commit(); } else { - oracleConn.rollback(); ifxConn.rollback(); } //清理 - oracleConn.close(); xlsFile.close(); xlsFileIn.close(); //日志 - importMessage = "记录数量:" + (rowCount - 1) + - "
导入成功数量:" + successCount + - "
导入失败数量:" + failCount + - "
" + importResult; + importMessage = "读取记录数量:" + (rowCount - 1) + + "
正确记录数量:" + successCount + + "
错误记录数量:" + failCount; + + if ( failCount != 0 ) + { + //有错误的记录,输出提示 + importMessage += "
请根据错误提示修正后重新导入!
"; + } + else + { + //无错误的记录,输出成功提示 + importMessage += "
文件已成功导入!
"; + } + + //追加导入记录 + importMessage += importResult; return importMessage; } diff --git a/代码/jsp/src/com/cpic/telsale/uploadData/uploadDataProcessor.java b/代码/jsp/src/com/cpic/telsale/uploadData/uploadDataProcessor.java index 6b01c35..108966c 100644 --- a/代码/jsp/src/com/cpic/telsale/uploadData/uploadDataProcessor.java +++ b/代码/jsp/src/com/cpic/telsale/uploadData/uploadDataProcessor.java @@ -19,24 +19,23 @@ import com.cpic.telsale.DataImport.*; public class uploadDataProcessor extends HttpServlet { private String tempPathRoot; //临时文件目录 - private String oracleURL; - private String oracleUserName; - private String oraclePassword; +// private String oracleURL; +// private String oracleUserName; +// private String oraclePassword; private String informixURL; + private String telsalePolicyOperatorListTableName; //informix库电销转介绍表名 @Override public void init( ServletConfig config ) throws ServletException { //获取参数 - //tempPathRoot = ( String )config.getServletContext().getAttribute( "临时文件根目录" ); - - //oracle - oracleURL = ( String )config.getServletContext().getInitParameter( "oracleURL" ); - oracleUserName = ( String )config.getServletContext().getInitParameter( "oracleUserName" ); - oraclePassword = ( String )config.getServletContext().getInitParameter( "oraclePassword" ); +// oracleURL = ( String )config.getServletContext().getInitParameter( "oracleURL" ); +// oracleUserName = ( String )config.getServletContext().getInitParameter( "oracleUserName" ); +// oraclePassword = ( String )config.getServletContext().getInitParameter( "oraclePassword" ); //informix informixURL = ( String )config.getServletContext().getInitParameter( "informixURL" ); + telsalePolicyOperatorListTableName = (String)config.getServletContext().getInitParameter( "telsalePolicyOperatorListTableName" ); } @Override @@ -66,9 +65,7 @@ public class uploadDataProcessor extends HttpServlet String upLoadedFileName = saveUploadedFile( fileItem ); importMessage = DataImport.importTelsalePolicyDataFromXlsx( upLoadedFileName, - oracleURL, - oracleUserName, - oraclePassword, + telsalePolicyOperatorListTableName, informixURL ); } } diff --git a/代码/jsp/web/WEB-INF/web.xml b/代码/jsp/web/WEB-INF/web.xml index 526cfd3..b70bb92 100644 --- a/代码/jsp/web/WEB-INF/web.xml +++ b/代码/jsp/web/WEB-INF/web.xml @@ -35,6 +35,10 @@ informixURL jdbc:informix-sqli://10.39.0.92:16192/ywgl_xm:INFORMIXSERVER=xmcx2;newcodeset=GBK,8859-1,819;user=ccx99;password=c92IT09 + + telsalePolicyOperatorListTableName + w_dxbd_i1 + diff --git a/代码/jsp/web/doc/电销转介绍导入模板.xls b/代码/jsp/web/doc/电销转介绍导入模板.xls new file mode 100644 index 0000000..1fe9cef Binary files /dev/null and b/代码/jsp/web/doc/电销转介绍导入模板.xls differ diff --git a/代码/jsp/web/uploadPolicyData/uploadPolicyData.jsp b/代码/jsp/web/uploadPolicyData/uploadPolicyData.jsp index eeab53b..dce187f 100644 --- a/代码/jsp/web/uploadPolicyData/uploadPolicyData.jsp +++ b/代码/jsp/web/uploadPolicyData/uploadPolicyData.jsp @@ -26,6 +26,8 @@ +ģ +

עšƺšˡ˴롢̴Ϊ

<% int uploadCount = 0; diff --git a/代码/oracle/建表/电网销转介绍清单表.sql b/代码/oracle/建表/电网销转介绍清单表.sql new file mode 100644 index 0000000..0d08de5 --- /dev/null +++ b/代码/oracle/建表/电网销转介绍清单表.sql @@ -0,0 +1,18 @@ +DROP TABLE telsale_oper_lst; +CREATE TABLE telsale_oper_lst +( + policy_no VARCHAR2(20) PRIMARY KEY, + operator_code VARCHAR2(6) NOT NULL, + operator_name VARCHAR2(100 CHAR) NOT NULL, + section_office_code VARCHAR2(6) NOT NULL, + section_office_name VARCHAR2(100 CHAR) NOT NULL, + department_code VARCHAR2(6), + department_name VARCHAR2(100 CHAR), + autotrader_code VARCHAR2(30), --̴ + insruant_name VARCHAR2(200 CHAR), -- + plate_no VARCHAR2(7 CHAR), --ƺ + entry_staff_code VARCHAR2(6) NOT NULL, + entry_date DATE DEFAULT SYSDATE +); + +CREATE INDEX telsale_oper_lst_i ON telsale_oper_lst(POLICY_NO,operator_code); diff --git a/代码/oracle/测试/测试语句.sql b/代码/oracle/测试/测试语句.sql new file mode 100644 index 0000000..1d1c5dd --- /dev/null +++ b/代码/oracle/测试/测试语句.sql @@ -0,0 +1,32 @@ +/* +truncate table telsale_oper_lst; +*/ +/* +INSERT INTO telsale_oper_lst + (policy_no, + operator_code, + operator_name, + section_office_code, + section_office_name, + department_code, + department_name, + autotrader_code, + insruant_name, + plate_no, + entry_staff_code, + entry_date) +VALUES + (?, + ?, + ?, + ?, + ?, + ?, + ?, + ?, + ?, + ?, + '800', + SYSDATE) +*/ +SELECT * FROM telsale_oper_lst; diff --git a/数据/导入20170110-1.xls b/数据/导入20170110-1.xls new file mode 100644 index 0000000..56ef5b9 Binary files /dev/null and b/数据/导入20170110-1.xls differ diff --git a/数据/无重复.xls b/数据/无重复.xls new file mode 100644 index 0000000..132b5df Binary files /dev/null and b/数据/无重复.xls differ diff --git a/数据/有重复.xls b/数据/有重复.xls new file mode 100644 index 0000000..93232fa Binary files /dev/null and b/数据/有重复.xls differ