保存进度!

This commit is contained in:
unknown 2023-10-22 01:15:34 +08:00
parent b794e99694
commit 8b31ffb6d6
6 changed files with 112 additions and 39 deletions

View File

@ -20,7 +20,7 @@ interface ImportBIReportRequest
{
filePath: string,
reportType: number,
hasCaption: boolean,
firstRow: number,
sheetIndex: number,
}

View File

@ -14,13 +14,14 @@
<el-col :span="4">
<span>报表类型</span>
</el-col>
<el-col :span="10">
<el-col :span="9">
<el-select v-model="ui.selectedReportType">
<el-option
v-for="item in ui.reportType"
:key="item.reportTypeCode"
:label="item.reportTypeName"
:value="item.reportTypeCode"
width="100%"
/>
</el-select>
</el-col>
@ -33,10 +34,13 @@
</el-row>
<el-row :gutter="10">
<el-col :span="4">
<span>标题</span>
<span>起始</span>
</el-col>
<el-col :span="8">
<el-switch v-model="ui.hasCaption" />
<el-col :span="9">
<el-input v-model.lazy.number="ui.firstRow" />
</el-col>
<el-col :span="11">
<span style="text-align:left;color:red;">*从0开始计数</span>
</el-col>
</el-row>
</div>
@ -76,6 +80,7 @@ interface UI
selectedReportType: number,
reportType: BIReportType[],
sheetIndex: number,
firstRow: number,
hasCaption: boolean,
uploadParameters: any,
showFileList: boolean,
@ -109,6 +114,7 @@ export default {
reportTypeName: "部门车非渗透率续保率",
},],
sheetIndex: 0,
firstRow: 2,
hasCaption: true,
uploadParameters: {
"task-name": "1234",
@ -147,7 +153,7 @@ export default {
const request: ImportBIReportRequest = {
filePath: response.fileList[0],
reportType: ui.selectedReportType,
hasCaption: ui.hasCaption,
firstRow: ui.firstRow,
sheetIndex: ui.sheetIndex,
};

View File

@ -13,14 +13,17 @@ import java.io.File;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import com.cpic.xim.mybatis.pojo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.cpic.xim.mybatis.pojo.BIDepartmentArchievementRecord;
import com.cpic.xim.mybatis.pojo.BITelsalerAttachingRateRecord;
import com.cpic.xim.mybatis.pojo.BITelsalerRenewalRateRecord;
import com.cpic.xim.utils.poi.MyPOIUtils;
/**
@ -43,16 +46,78 @@ public final class ImportBIExcelData
{ "部门", "目标值-机构", "目标差距", "车险保费(万)", "车险保费占比", "非车保费(万)", "当月保费渗透率", "保费渗透率环比上月", "当月客户渗透率",
"客户渗透率环比上月", "当月车非客均保费", "客均保费环比上月"};
/**
* 用于通过对比标题行判断excel文件格式的函数
* @param sheet
* @param caption 标题行文字
* @param captionRowIndex 标题行索引
* @param title 字段行文字数组
* @param titleRowIndex 字段行索引
* @return 返回判断结果
*/
private static boolean checkExcelFormat( Sheet sheet, String caption, int captionRowIndex,
String[] title, int titleRowIndex ) throws InvalidFormatException
{
boolean result = true;
Row captionRow = sheet.getRow( captionRowIndex );
Row titleRow = sheet.getRow( titleRowIndex );
if ( caption != null && !caption.isEmpty() )
{
try
{
int captionCellNum = captionRow.getFirstCellNum();
String captionString = MyPOIUtils.getStringCellValue( captionRow, captionCellNum );
if ( !caption.equals( captionString ) )
{
result = false;
}
}
catch ( NullPointerException error )
{
result = false;
}
}
if ( title.length != 0 )
{
int cellIndex = 0;
try
{
for ( Cell cell : titleRow )
{
String cellString = MyPOIUtils.getStringCellValue( cell );
if ( !cellString.equals( title[cellIndex] ) )
{
result = false;
break;
}
}
}
catch ( NullPointerException error )
{
result = false;
}
}
return result;
}
/**
* 从excel文件读取坐席的车非渗透率数据
* @param filePath 文件路径
* @param summaryDate 统计日期
* @param SheetIndex sheet索引
* @param firstRow 数据起始行
* @return 返回一个ArrayList保存的TelsalerAttachingRateRecord记录数组
* @throws IOException 打开excel文件错误时抛出
* @throws InvalidFormatException excel单元格格式错误时抛出
*/
public static ArrayList<BITelsalerAttachingRateRecord> importBITelsalerAttachingRateRecordFromXlsx(
String filePath, int SheetIndex, boolean hasCaptionRow )
String filePath, int SheetIndex, int firstRow )
throws IOException, InvalidFormatException
{
ArrayList<BITelsalerAttachingRateRecord> records = new ArrayList<>( 200 );
@ -70,8 +135,8 @@ public final class ImportBIExcelData
String name = "";
int rowIndex = row.getRowNum();
// 判断是否要跳过标题行
if ( hasCaptionRow == true && row.getRowNum() == 0 )
// 从数据行开始
if ( row.getRowNum() < firstRow )
{
continue;
}
@ -156,7 +221,7 @@ public final class ImportBIExcelData
* @return
*/
public static ArrayList<BITelsalerRenewalRateRecord> importBITelsalerRenewalRateFromXlsx(
String filePath, int sheetIndex, boolean hasCaptionRow, LocalDate summaryDate )
String filePath, int sheetIndex, int firstRow, LocalDate summaryDate )
throws IOException
{
ArrayList<BITelsalerRenewalRateRecord> records = new ArrayList<>( 200 );
@ -174,7 +239,8 @@ public final class ImportBIExcelData
{
rowIndex = row.getRowNum();
if ( hasCaptionRow == true && rowIndex == 0 )
// 从数据行开始
if ( row.getRowNum() < firstRow )
{
continue;
}
@ -228,7 +294,7 @@ public final class ImportBIExcelData
}
public static ArrayList<BIDepartmentArchievementRecord> importBIDepartmentArchievementRecords(
String filePath, int sheetIndex, boolean hasCaptionRow ) throws IOException
String filePath, int sheetIndex, int firstRow ) throws IOException
{
ArrayList<BIDepartmentArchievementRecord> records = new ArrayList<>( 5 );
@ -245,7 +311,8 @@ public final class ImportBIExcelData
{
rowIndex = row.getRowNum();
if ( hasCaptionRow == true && rowIndex == 0 )
// 从数据行开始
if ( row.getRowNum() < firstRow )
{
continue;
}

View File

@ -43,7 +43,7 @@ public class ImportBIDataController
ImportBIDataResponse response = new ImportBIDataResponse();
String filePath = request.getFilePath();
ReportType type = request.getReportType();
boolean hasCaption = request.isHasCaption();
int firstRow = request.getFirstRow();
int sheetIndex = request.getSheetIndex();
int importedCount = 0;
@ -51,15 +51,15 @@ public class ImportBIDataController
{
if ( type == ReportType.TelsalerAttachingRateReport )
{
importedCount = importBITelsalerAttachingRate( filePath, sheetIndex, hasCaption );
importedCount = importBITelsalerAttachingRate( filePath, sheetIndex, firstRow );
}
else if ( type == ReportType.TelsalerRenewalRateReport )
{
importedCount = importBITeslsalerRenewalRate( filePath, sheetIndex, hasCaption );
importedCount = importBITeslsalerRenewalRate( filePath, sheetIndex, firstRow );
}
else if ( type == ReportType.DepartmentAttachingRenewalRateReport )
{
importedCount = importBIDepartmentArchievement( filePath, sheetIndex, hasCaption );
importedCount = importBIDepartmentArchievement( filePath, sheetIndex, firstRow );
}
response.setImportedCount(importedCount);
@ -96,7 +96,7 @@ public class ImportBIDataController
private static int importBITelsalerAttachingRate( String filePath, int sheetIndex,
boolean hasCaption ) throws PersistenceException, IOException, InvalidFormatException
int firstRow ) throws PersistenceException, IOException, InvalidFormatException
{
SqlSession session = null;
int importedCount = 0;
@ -105,7 +105,7 @@ public class ImportBIDataController
{
ArrayList<BITelsalerAttachingRateRecord> records =
ImportBIExcelData.importBITelsalerAttachingRateRecordFromXlsx( filePath,
sheetIndex, hasCaption );
sheetIndex, firstRow );
session = MybatisUtils.getSqlSessionBatch();
ImportBIArchievementDataMapper mapper =
@ -135,7 +135,7 @@ public class ImportBIDataController
}
private static int importBITeslsalerRenewalRate( String filePath, int sheetIndex,
boolean hasCaption ) throws PersistenceException, IOException, InvalidFormatException
int firstRow ) throws PersistenceException, IOException, InvalidFormatException
{
ArrayList<BITelsalerRenewalRateRecord> records = null;
SqlSession session = null;
@ -145,7 +145,7 @@ public class ImportBIDataController
try
{
records = ImportBIExcelData.importBITelsalerRenewalRateFromXlsx( filePath, sheetIndex,
hasCaption, LocalDate.now() );
firstRow, LocalDate.now() );
session = MybatisUtils.getSqlSessionBatch();
mapper = session.getMapper( ImportBIArchievementDataMapper.class );
@ -175,7 +175,7 @@ public class ImportBIDataController
}
private static int importBIDepartmentArchievement( String filePath, int sheetIndex,
boolean hasCaption ) throws PersistenceException, IOException, InvalidFormatException
int firstRow ) throws PersistenceException, IOException, InvalidFormatException
{
ArrayList<BIDepartmentArchievementRecord> records = null;
SqlSession session = null;
@ -185,7 +185,7 @@ public class ImportBIDataController
try
{
records = ImportBIExcelData.importBIDepartmentArchievementRecords( filePath, sheetIndex,
hasCaption );
firstRow );
session = MybatisUtils.getSqlSessionBatch();
mapper = session.getMapper( ImportBIArchievementDataMapper.class );

View File

@ -28,8 +28,8 @@ public class ImportBIDataRequest
private ReportType reportType;
// 是否有标题行
@JsonProperty( "hasCaption" )
private boolean hasCaption;
@JsonProperty( "firstRow" )
private int firstRow;
// sheet索引
@JsonProperty( "sheetIndex" )
@ -38,14 +38,14 @@ public class ImportBIDataRequest
public ImportBIDataRequest()
{}
public boolean isHasCaption()
public int getFirstRow()
{
return hasCaption;
return firstRow;
}
public void setHasCaption( boolean hasCaption )
public void setFirstRow( int firstRow )
{
this.hasCaption = hasCaption;
this.firstRow = firstRow;
}
public int getSheetIndex()
@ -85,7 +85,7 @@ public class ImportBIDataRequest
int result = 1;
result = prime * result + ((filePath == null) ? 0 : filePath.hashCode());
result = prime * result + ((reportType == null) ? 0 : reportType.hashCode());
result = prime * result + (hasCaption ? 1231 : 1237);
result = prime * result + firstRow;
result = prime * result + sheetIndex;
return result;
}
@ -109,7 +109,7 @@ public class ImportBIDataRequest
return false;
if ( reportType != other.reportType )
return false;
if ( hasCaption != other.hasCaption )
if ( firstRow != other.firstRow )
return false;
if ( sheetIndex != other.sheetIndex )
return false;
@ -120,7 +120,7 @@ public class ImportBIDataRequest
public String toString()
{
return "ImportBIDataRequest [filePath=" + filePath + ", reportType=" + reportType
+ ", hasCaption=" + hasCaption + ", sheetIndex=" + sheetIndex + "]";
+ ", firstRow=" + firstRow + ", sheetIndex=" + sheetIndex + "]";
}

View File

@ -31,7 +31,7 @@ public class BatchInsertTest
try
{
records = ImportBIExcelData.importBITelsalerAttachingRateRecordFromXlsx( filePath, 0,
true );
1 );
session = MybatisUtils.getSqlSessionBatch();
mapper = session.getMapper( ImportBIArchievementDataMapper.class );
@ -73,7 +73,7 @@ public class BatchInsertTest
try
{
records = ImportBIExcelData.importBITelsalerRenewalRateFromXlsx( filePath, 0, true,
records = ImportBIExcelData.importBITelsalerRenewalRateFromXlsx( filePath, 0, 1,
null );
session = MybatisUtils.getSqlSessionBatch();
@ -116,7 +116,7 @@ public class BatchInsertTest
try
{
records =
ImportBIExcelData.importBIDepartmentArchievementRecords( filePath, 0, true );
ImportBIExcelData.importBIDepartmentArchievementRecords( filePath, 0, 1 );
session = MybatisUtils.getSqlSessionBatch();
mapper = session.getMapper( ImportBIArchievementDataMapper.class );