This commit is contained in:
Kane Wang 2021-06-22 11:41:13 +08:00
parent 83c26ecec9
commit 92d5d75e59
9 changed files with 502 additions and 92 deletions

View File

@ -25,9 +25,8 @@ public class DataImport
* @Author: 王炜
* @Date: 2021/6/21
*/
public static ArrayList<TelsalePolicyRecord> readTelsalePolicyDataFromXlsx(String fileName, int sheetIndex) throws
IOException,
SQLException,
public static ArrayList<TelsalePolicyRecord> readTelsalePolicyDataFromXlsx( String fileName, int sheetIndex )
throws IOException,
XlsFileFormatException
{
ArrayList<TelsalePolicyRecord> policyList = new ArrayList<TelsalePolicyRecord>();
@ -41,30 +40,77 @@ public class DataImport
int rowIndex = 0;
int rowCount = 0;
int errorCount = 0;
String errorMessage = "数据错误,请修正后重新上传!<br>\n";
try {
try
{
xlsxFile = new FileInputStream( fileName );
workBook = new HSSFWorkbook( xlsxFile );
sheet = workBook.getSheetAt( sheetIndex );
rowIndex = sheet.getFirstRowNum() + 1;
rowIndex = sheet.getFirstRowNum();
rowCount = sheet.getLastRowNum();
row = sheet.getRow(rowIndex);
while (rowIndex <= rowCount) {
while ( rowIndex <= rowCount )
{
//用第一个单元格判断是不是空行如果cell为null视为空行
row = sheet.getRow( rowIndex );
HSSFCell cell = row.getCell( 0 );
if (cell == null) {
if ( cell == null )
{
rowIndex++;
continue;
}
String policyNo = cell.getStringCellValue();
String operatorCode = getStringValueFromHSSFCell( row.getCell( 1 ) );
//判断数据是否有效
if ( policyNo.length() != 20 || operatorCode.length() == 0 || operatorCode.length() > 6 )
{
errorMessage += "" + ( rowIndex + 1 ) + "行,";
if ( policyNo.length() != 20 )
{
//以后再加入正则表达式判断
errorMessage += "保单号" + policyNo + "错误!";
}
} catch (IOException error) {
if ( operatorCode.length() == 0 || operatorCode.length() > 6 )
{
errorMessage += "经办人" + operatorCode + "错误!";
}
errorMessage += "<br>\n";
rowIndex++;
errorCount++;
continue;
}
//读取数据
record = new TelsalePolicyRecord( policyNo, operatorCode );
policyList.add( record );
rowIndex++;
}
}
finally
{
if ( workBook != null )
{
workBook.close();
xlsxFile.close();
}
}
//判断是否要抛出读取错误
if ( errorCount > 0 )
{
throw new XlsFileFormatException( errorMessage );
}
return policyList;
@ -84,8 +130,8 @@ public class DataImport
*/
public static String importTelsalePolicyDataFromXlsx( String fileName,
String telsalePolicyOperatorListTableName,
String informixURL) throws
IOException,
String informixURL )
throws IOException,
ClassNotFoundException,
SQLException,
XlsFileFormatException
@ -103,14 +149,16 @@ public class DataImport
HSSFSheet sheet = null;
HSSFRow row = null;
try {
try
{
xlsFileIn = new FileInputStream( fileName );
xlsFile = new HSSFWorkbook( xlsFileIn );
sheet = xlsFile.getSheetAt( 0 ); //第一个sheet
rowIndex = sheet.getFirstRowNum() + 1;
rowCount = sheet.getLastRowNum();
row = sheet.getRow( rowIndex );
} catch (IOException error) //有文件格式错误的可能
}
catch ( IOException error ) //有文件格式错误的可能
{
xlsFile.close();
xlsFileIn.close();
@ -164,11 +212,13 @@ public class DataImport
StaffInfo staff = null;
boolean isSuccess = true; //标志位用来指示在保存过程中是否出现错误
while (rowIndex <= rowCount) {
while ( rowIndex <= rowCount )
{
//用来判断是不是空行
HSSFCell cell = row.getCell( 0 );
if (cell == null) {
if ( cell == null )
{
rowIndex++;
continue;
}
@ -177,14 +227,16 @@ public class DataImport
operatorCode = getStringValueFromHSSFCell( row.getCell( 1 ) );
//判断一下是不是空的单元格
if (policyNo.length() == 0 || operatorCode.length() == 0) {
if ( policyNo.length() == 0 || operatorCode.length() == 0 )
{
importResult = importResult + "" + rowIndex + "行数据为空。<br>";
//isSuccess = false;
}
else //不是空单元格进行处理
{
try {
try
{
//取得经办人信息
staff = new StaffInfo( operatorCode );
@ -206,7 +258,9 @@ public class DataImport
importResult = importResult + "" + rowIndex + "行,保单号" + policyNo + ",转介绍信息入成功!<br>";
successCount++;
} catch (StaffCodeNotExistException error) {
}
catch ( StaffCodeNotExistException error )
{
//经办人不存在
importResult = importResult + "" + rowIndex + "行,保单号" + policyNo + ",经办人" + operatorCode + "不存在。<br>";
@ -215,7 +269,9 @@ public class DataImport
//计数
failCount++;
} catch (OracleConnectionException error) {
}
catch ( OracleConnectionException error )
{
//查询工号失败
importResult = importResult + "" + rowIndex + "行,保单号" + policyNo + ",经办人" + operatorCode + ",查询工号失败。<br>";
@ -224,10 +280,13 @@ public class DataImport
//计数
failCount++;
} catch (SQLException error) {
}
catch ( SQLException error )
{
int errorCode = error.getErrorCode();
switch (errorCode) {
switch ( errorCode )
{
case -268: //保单号重复
importResult = importResult + "" + rowIndex + "行,保单号" + policyNo + ",已录入过转介绍信息!" + error.getCause() + "。<br>";
break;
@ -243,7 +302,9 @@ public class DataImport
//计数
failCount++;
} catch (Exception error) {
}
catch ( Exception error )
{
//写入错误
importResult = importResult + "" + rowIndex + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。<br>";
@ -252,7 +313,9 @@ public class DataImport
//计数
failCount++;
} finally {
}
finally
{
ifxConn.commit();
}
}
@ -302,33 +365,41 @@ public class DataImport
{
String value = null;
if (cell == null) {
if ( cell == null )
{
return "";
}
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC: {
switch ( cell.getCellType() )
{
case HSSFCell.CELL_TYPE_NUMERIC:
{
//判断是不是整数
double dValue = cell.getNumericCellValue();
if (dValue == (int) dValue) {
if ( dValue == (int) dValue )
{
value = String.valueOf( (int) dValue );
}
else {
else
{
value = String.valueOf( dValue );
}
break;
}
case HSSFCell.CELL_TYPE_STRING: {
case HSSFCell.CELL_TYPE_STRING:
{
value = cell.getStringCellValue();
break;
}
case HSSFCell.CELL_TYPE_BLANK: {
case HSSFCell.CELL_TYPE_BLANK:
{
value = "";
break;
}
default: {
default:
{
value = "";
break;
}
@ -336,6 +407,14 @@ public class DataImport
return value;
}
public static void saveTelsalePolicyDataToOracle( String dbURL,
String userName,
String password,
ArrayList<TelsalePolicyRecord> policyList )
{
}
}

View File

@ -16,6 +16,138 @@ public class TelsalePolicyRecord
* @Date: 2021/6/21 */
public TelsalePolicyRecord( String policyNo, String operatorCode )
{
this.policyNo = policyNo;
this.operatorCode = operatorCode;
}
public String getPolicyNo()
{
return policyNo;
}
public void setPolicyNo( String policyNo )
{
this.policyNo = policyNo;
}
public String getOperatorCode()
{
return operatorCode;
}
public void setOperatorCode( String operatorCode )
{
this.operatorCode = operatorCode;
}
public String getOperatorName()
{
return operatorName;
}
public void setOperatorName( String operatorName )
{
this.operatorName = operatorName;
}
public String getOperatorSectionOfficeCode()
{
return operatorSectionOfficeCode;
}
public void setOperatorSectionOfficeCode( String operatorSectionOfficeCode )
{
this.operatorSectionOfficeCode = operatorSectionOfficeCode;
}
public String getOperatorSectionOfficeName()
{
return operatorSectionOfficeName;
}
public void setOperatorSectionOfficeName( String operatorSectionOfficeName )
{
this.operatorSectionOfficeName = operatorSectionOfficeName;
}
public String getOperatorSectionDepartmentCode()
{
return operatorSectionDepartmentCode;
}
public void setOperatorSectionDepartmentCode( String operatorSectionDepartmentCode )
{
this.operatorSectionDepartmentCode = operatorSectionDepartmentCode;
}
public String getOperatorSectionDepartmentName()
{
return operatorSectionDepartmentName;
}
public void setOperatorSectionDepartmentName( String operatorSectionDepartmentName )
{
this.operatorSectionDepartmentName = operatorSectionDepartmentName;
}
public String getEntryStaffCode()
{
return entryStaffCode;
}
public void setEntryStaffCode( String entryStaffCode )
{
this.entryStaffCode = entryStaffCode;
}
public String getEntryStaffName()
{
return entryStaffName;
}
public void setEntryStaffName( String entryStaffName )
{
this.entryStaffName = entryStaffName;
}
public String getEntryStaffSectionOfficeCode()
{
return entryStaffSectionOfficeCode;
}
public void setEntryStaffSectionOfficeCode( String entryStaffSectionOfficeCode )
{
this.entryStaffSectionOfficeCode = entryStaffSectionOfficeCode;
}
public String getEntryStaffSectionOfficeName()
{
return entryStaffSectionOfficeName;
}
public void setEntryStaffSectionOfficeName( String entryStaffSectionOfficeName )
{
this.entryStaffSectionOfficeName = entryStaffSectionOfficeName;
}
public String getEntryStaffSectionDepartmentCode()
{
return entryStaffSectionDepartmentCode;
}
public void setEntryStaffSectionDepartmentCode( String entryStaffSectionDepartmentCode )
{
this.entryStaffSectionDepartmentCode = entryStaffSectionDepartmentCode;
}
public String getEntryStaffSectionDepartmentName()
{
return entryStaffSectionDepartmentName;
}
public void setEntryStaffSectionDepartmentName( String entryStaffSectionDepartmentName )
{
this.entryStaffSectionDepartmentName = entryStaffSectionDepartmentName;
}
private String policyNo;

View File

@ -4,6 +4,7 @@ package com.cpic.telsale.uploadData;
* Created by Kane on 2017/3/27.
*/
import com.cpic.telsale.TelsalePolicyRecord;
import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
@ -26,7 +27,9 @@ public class uploadDataProcessor extends HttpServlet
private String telsalePolicyOperatorListTableName; //informix库电销转介绍表名
@Override
public void init( ServletConfig config ) throws ServletException
public void init( ServletConfig config )
throws
ServletException
{
//获取参数
oracleURL = (String) config.getServletContext().getInitParameter( "oracleURL" );
@ -35,14 +38,20 @@ public class uploadDataProcessor extends HttpServlet
//informix
informixURL = (String) config.getServletContext().getInitParameter( "informixURL" );
telsalePolicyOperatorListTableName = (String)config.getServletContext().getInitParameter( "telsalePolicyOperatorListTableName" );
telsalePolicyOperatorListTableName = (String) config.getServletContext()
.getInitParameter( "telsalePolicyOperatorListTableName" );
}
@Override
public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
public void doPost( HttpServletRequest request, HttpServletResponse response )
throws
ServletException,
IOException
{
tempPathRoot = (String) request.getSession().getAttribute( "临时文件根目录" );
String importMessage = null;
ArrayList<TelsalePolicyRecord> policyRecordList = new ArrayList<TelsalePolicyRecord>();
try
{
@ -64,9 +73,12 @@ public class uploadDataProcessor extends HttpServlet
//保存上传的文件返回文件完整路径
String upLoadedFileName = saveUploadedFile( fileItem );
importMessage = DataImport.importTelsalePolicyDataFromXlsx( upLoadedFileName,
telsalePolicyOperatorListTableName,
informixURL );
//测试
policyRecordList = DataImport.readTelsalePolicyDataFromXlsx( upLoadedFileName, 0 );
// importMessage = DataImport.importTelsalePolicyDataFromXlsx( upLoadedFileName,
// telsalePolicyOperatorListTableName,
// informixURL );
}
}
}
@ -104,7 +116,9 @@ public class uploadDataProcessor extends HttpServlet
* @return
* @throws Exception
*/
private String saveUploadedFile( FileItem item ) throws Exception
private String saveUploadedFile( FileItem item )
throws
Exception
{
String fileName = item.getName();

View File

@ -4,14 +4,51 @@ CREATE OR REPLACE PACKAGE telsale_policy_check_pkg IS
-- Created : 2021/6/21 10:18:01
-- Purpose : µçÏú±£µ¥Êý¾ÝÑéÖ¤
/***************************************************************************/
--定义异常
--保单号不存在
POLICYNO_NOT_EXIST_EXCEPT_CODE CONSTANT INTEGER := -20000;
POLICYNO_NOT_EXIST_EXCEPT_TEXT CONSTANT VARCHAR2(100) := '保单号不存在。';
--经办人不存在
OPERATOE_CODE_NOT_EXIST_EXCEPT_CODE CONSTANT INTEGER := -20001;
OPERATOE_CODE_NOT_EXIST_EXCEPT_TEXT CONSTANT VARCHAR2(100) := '经办人工号不存在。';
--录入人不存在
ENTRY_STAFF_CODE_NOT_EXIST_EXCEPT_CODE CONSTANT INTEGER := -20002;
ENTRY_STAFF_CODE_NOT_EXIST_EXCEPT_TEXT CONSTANT VARCHAR2(100) := '录入人工号不存在。';
--经办人工号所在科室与保单不匹配
OPERATOE_CODE_NOT_MATCH_EXCEPT_CODE CONSTANT INTEGER := -20003;
OPERATOE_CODE_NOT_MATCH_EXCEPT_TEXT CONSTANT VARCHAR2(100) := '经办人工号所在科室与保单归属不匹配。';
/***************************************************************************/
FUNCTION policy_check(a_policy_no VARCHAR2) RETURN BOOLEAN;
FUNCTION staff_check(a_stuff_code VARCHAR2) RETURN BOOLEAN;
PROCEDURE save_policy
(
a_policy_no IN VARCHAR2,
a_operator_code IN VARCHAR2,
a_operator_name OUT VARCHAR2,
a_operator_sectionoffice_code OUT VARCHAR2,
a_operator_sectionoffice_name OUT VARCHAR2,
a_operator_department_code OUT VARCHAR2,
a_operator_department_name OUT VARCHAR2,
a_entry_staff_code IN VARCHAR2,
a_entry_staff_name OUT VARCHAR2,
a_entry_staff_sectionoffice_code OUT VARCHAR2,
a_entry_staff_sectionoffice_name OUT VARCHAR2,
a_entry_staff_department_code OUT VARCHAR2,
a_entry_staff_department_name OUT VARCHAR2
);
END telsale_policy_check_pkg;
/
CREATE OR REPLACE PACKAGE BODY telsale_policy_check_pkg IS
/*********************************************************************************/
FUNCTION staff_check(a_stuff_code VARCHAR2) RETURN BOOLEAN IS
l_count INTEGER;
BEGIN
@ -28,6 +65,7 @@ CREATE OR REPLACE PACKAGE BODY telsale_policy_check_pkg IS
RETURN TRUE;
END;
/*********************************************************************************/
FUNCTION policy_check(a_policy_no VARCHAR2) RETURN BOOLEAN IS
l_count INTEGER;
BEGIN
@ -43,6 +81,33 @@ CREATE OR REPLACE PACKAGE BODY telsale_policy_check_pkg IS
RETURN TRUE;
END;
/*********************************************************************************/
PROCEDURE save_policy
(
a_policy_no IN VARCHAR2,
a_operator_code IN VARCHAR2,
a_operator_name OUT VARCHAR2,
a_operator_sectionoffice_code OUT VARCHAR2,
a_operator_sectionoffice_name OUT VARCHAR2,
a_operator_department_code OUT VARCHAR2,
a_operator_department_name OUT VARCHAR2,
a_entry_staff_code IN VARCHAR2,
a_entry_staff_name OUT VARCHAR2,
a_entry_staff_sectionoffice_code OUT VARCHAR2,
a_entry_staff_sectionoffice_name OUT VARCHAR2,
a_entry_staff_department_code OUT VARCHAR2,
a_entry_staff_department_name OUT VARCHAR2
) IS
l_policy_section_code VARCHAR2(6);
l_policy_department_code VARCHAR2(6);
BEGIN
NULL;
--判断保单号是否存在,以及保单号的科室部门和经办人是否相同
END;
BEGIN
NULL;
END telsale_policy_check_pkg;

View File

@ -0,0 +1,100 @@
CREATE OR REPLACE PACKAGE telsale_policy_check_pkg IS
-- Author : 王炜
-- Created : 2021/6/21 10:18:01
-- Purpose : 电销保单数据验证
--定义异常
--保单号不存在
POLICYNO_NOT_EXIST_EXCEPT_CODE CONSTANT INTEGER := -20000;
POLICYNO_NOT_EXIST_EXCEPT_TEXT CONSTANT VARCHAR2(100) := '保单号不存在。';
FUNCTION policy_check(a_policy_no VARCHAR2) RETURN BOOLEAN;
FUNCTION staff_check(a_stuff_code VARCHAR2) RETURN BOOLEAN;
PROCEDURE save_policy
(
a_policy_no IN VARCHAR2,
a_operator_code IN VARCHAR2,
a_operator_name OUT VARCHAR2,
a_operator_sectionoffice_code OUT VARCHAR2,
a_operator_sectionoffice_name OUT VARCHAR2,
a_operator_department_code OUT VARCHAR2,
a_operator_department_name OUT VARCHAR2,
a_entry_staff_code IN VARCHAR2,
a_entry_staff_name OUT VARCHAR2,
a_entry_staff_sectionoffice_code OUT VARCHAR2,
a_entry_staff_sectionoffice_name OUT VARCHAR2,
a_entry_staff_department_code OUT VARCHAR2,
a_entry_staff_department_name OUT VARCHAR2
);
END telsale_policy_check_pkg;
/
CREATE OR REPLACE PACKAGE BODY telsale_policy_check_pkg IS
/*********************************************************************************/
FUNCTION staff_check(a_stuff_code VARCHAR2) RETURN BOOLEAN IS
l_count INTEGER;
BEGIN
SELECT COUNT(*)
INTO l_count
FROM idst0.rydm_t@xmcx1.cpicxm ry
WHERE ry.staff_code = a_stuff_code;
IF l_count = 0
THEN
RETURN FALSE;
END IF;
RETURN TRUE;
END;
/*********************************************************************************/
FUNCTION policy_check(a_policy_no VARCHAR2) RETURN BOOLEAN IS
l_count INTEGER;
BEGIN
SELECT COUNT(*)
INTO l_count
FROM idst0.auto_agreement_t@xmcx1.cpicxm a
WHERE a.policy_no = a_policy_no;
IF l_count = 0
THEN
RETURN FALSE;
END IF;
RETURN TRUE;
END;
/*********************************************************************************/
PROCEDURE save_policy
(
a_policy_no IN VARCHAR2,
a_operator_code IN VARCHAR2,
a_operator_name OUT VARCHAR2,
a_operator_sectionoffice_code OUT VARCHAR2,
a_operator_sectionoffice_name OUT VARCHAR2,
a_operator_department_code OUT VARCHAR2,
a_operator_department_name OUT VARCHAR2,
a_entry_staff_code IN VARCHAR2,
a_entry_staff_name OUT VARCHAR2,
a_entry_staff_sectionoffice_code OUT VARCHAR2,
a_entry_staff_sectionoffice_name OUT VARCHAR2,
a_entry_staff_department_code OUT VARCHAR2,
a_entry_staff_department_name OUT VARCHAR2
) IS
l_policy_section_code VARCHAR2(6);
l_policy_department_code VARCHAR2(6);
BEGIN
NULL;
--判断保单号是否存在,以及保单号的科室部门和经办人是否相同
END;
BEGIN
NULL;
END telsale_policy_check_pkg;
/

View File

@ -3,10 +3,30 @@ PL/SQL Developer Project Desktop
[Desktop]
SavePath=D:\develop\projects_win\2018\telsale_management_2017\代码\oracle\项目\
Index=1
Filename=D:\develop\projects_win\2018\telsale_management_2017\덜쯤\oracle\淃커\관\telsale_policy_check_pkg.pck
VCSDBObject=0
Connection=282441544404455840724370446043583456492241804558450434903180323832003290342849744968477032763302336047784788
DPI=96
Left=0
Top=0
Width=1329
Height=719
State=0
Type=3
ChildListIndex=1
Pinned=0
Index=2
Filename=
Connection=226450024772463846324866505249184048433046445054493639223676363836323754389245424568427437403734382438343844
[Files]
[MRU]
3,D:\develop\projects_win\2018\telsale_management_2017\덜쯤\oracle\淃커\관\telsale_policy_check_pkg.pck
1,D:\develop\projects_win\2018\telsale_management_2017\代码\oracle\项目\建表\电销保单信息表.sql
1,D:\develop\projects_win\2018\telsale_management_2017\덜쯤\oracle\淃커\쉔깊\든饋괏데斤口쩌흙휑羚깊.sql
[Layout]
Group=

Binary file not shown.

Binary file not shown.

Binary file not shown.