修复bug

This commit is contained in:
王炜 2018-07-26 17:34:22 +08:00
parent 36c0025da4
commit 332d77a208
2 changed files with 23 additions and 11 deletions

View File

@ -44,7 +44,8 @@ public class DataImport
{ {
String importResult = ""; String importResult = "";
String importMessage = null; String importMessage = null;
int rowCount = 1; //excel文件行索引 int rowIndex = 1; //excel文件行索引
int rowCount = -1;
int successCount = 0; //成功写入的行计数 int successCount = 0; //成功写入的行计数
int failCount = 0; //写入失败的行计数 int failCount = 0; //写入失败的行计数
@ -59,7 +60,9 @@ public class DataImport
xlsFileIn = new FileInputStream( fileName ); xlsFileIn = new FileInputStream( fileName );
xlsFile = new HSSFWorkbook( xlsFileIn ); xlsFile = new HSSFWorkbook( xlsFileIn );
sheet = xlsFile.getSheetAt( 0 ); //第一个sheet sheet = xlsFile.getSheetAt( 0 ); //第一个sheet
row = sheet.getRow( rowCount ); rowIndex = sheet.getFirstRowNum() + 1;
rowCount = sheet.getLastRowNum();
row = sheet.getRow( rowIndex );
} }
catch( IOException error ) //有文件格式错误的可能 catch( IOException error ) //有文件格式错误的可能
{ {
@ -115,15 +118,24 @@ public class DataImport
StaffInfo staff = null; StaffInfo staff = null;
boolean isSuccess = true; //标志位用来指示在保存过程中是否出现错误 boolean isSuccess = true; //标志位用来指示在保存过程中是否出现错误
while ( row != null ) while ( rowIndex <= rowCount )
{ {
//用来判断是不是空行
HSSFCell cell = row.getCell( 0 );
if ( cell == null)
{
rowIndex++;
continue;
}
policyNo = row.getCell( 0 ).getStringCellValue().trim(); policyNo = row.getCell( 0 ).getStringCellValue().trim();
operatorCode = getStringValueFromHSSFCell( row.getCell( 1 ) ); operatorCode = getStringValueFromHSSFCell( row.getCell( 1 ) );
//判断一下是不是空的单元格 //判断一下是不是空的单元格
if ( policyNo.length() == 0 || operatorCode.length() == 0 ) if ( policyNo.length() == 0 || operatorCode.length() == 0 )
{ {
importResult = importResult + "" + rowCount + "行数据为空。<br>"; importResult = importResult + "" + rowIndex + "行数据为空。<br>";
//isSuccess = false; //isSuccess = false;
} }
@ -153,7 +165,7 @@ public class DataImport
catch( StaffCodeNotExistException error ) catch( StaffCodeNotExistException error )
{ {
//经办人不存在 //经办人不存在
importResult = importResult + "" + rowCount + "行,保单号" + policyNo + ",经办人" + operatorCode + "不存在。<br>"; importResult = importResult + "" + rowIndex + "行,保单号" + policyNo + ",经办人" + operatorCode + "不存在。<br>";
//标志位 //标志位
isSuccess = false; isSuccess = false;
@ -164,7 +176,7 @@ public class DataImport
catch( SQLException error ) catch( SQLException error )
{ {
//写入错误 //写入错误
importResult = importResult + "" + rowCount + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。<br>"; importResult = importResult + "" + rowIndex + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。<br>";
//标志位 //标志位
isSuccess = false; isSuccess = false;
@ -175,7 +187,7 @@ public class DataImport
catch( Exception error ) catch( Exception error )
{ {
//写入错误 //写入错误
importResult = importResult + "" + rowCount + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。<br>"; importResult = importResult + "" + rowIndex + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。<br>";
//标志位 //标志位
isSuccess = false; isSuccess = false;
@ -185,8 +197,8 @@ public class DataImport
} }
} }
rowCount++; rowIndex++;
row = sheet.getRow( rowCount ); row = sheet.getRow( rowIndex );
} }
//判断标志位如果为false则说明在保存过程中出现了错误放弃所有过程进行回滚 //判断标志位如果为false则说明在保存过程中出现了错误放弃所有过程进行回滚
@ -205,7 +217,7 @@ public class DataImport
xlsFileIn.close(); xlsFileIn.close();
//日志 //日志
importMessage = "读取记录数量:" + (rowCount - 1) + importMessage = "读取记录数量:" + (rowIndex - 1) +
"<br>正确记录数量:" + successCount + "<br>正确记录数量:" + successCount +
"<br>错误记录数量:" + failCount; "<br>错误记录数量:" + failCount;

View File

@ -33,7 +33,7 @@
</context-param> </context-param>
<context-param> <context-param>
<param-name>informixURL</param-name> <param-name>informixURL</param-name>
<param-value>jdbc:informix-sqli://10.39.0.92:16192/ywgl_xm:INFORMIXSERVER=xmcx2;newcodeset=GBK,8859-1,819;user=ccx99;password=c92IT09</param-value> <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>
<context-param> <context-param>
<param-name>telsalePolicyOperatorListTableName</param-name> <param-name>telsalePolicyOperatorListTableName</param-name>