保存进度!

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, filePath: string,
reportType: number, reportType: number,
hasCaption: boolean, firstRow: number,
sheetIndex: number, sheetIndex: number,
} }

View File

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

View File

@ -13,14 +13,17 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; 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.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory; 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; 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文件读取坐席的车非渗透率数据 * 从excel文件读取坐席的车非渗透率数据
* @param filePath 文件路径 * @param filePath 文件路径
* @param summaryDate 统计日期 * @param SheetIndex sheet索引
* @param firstRow 数据起始行
* @return 返回一个ArrayList保存的TelsalerAttachingRateRecord记录数组 * @return 返回一个ArrayList保存的TelsalerAttachingRateRecord记录数组
* @throws IOException 打开excel文件错误时抛出 * @throws IOException 打开excel文件错误时抛出
* @throws InvalidFormatException excel单元格格式错误时抛出 * @throws InvalidFormatException excel单元格格式错误时抛出
*/ */
public static ArrayList<BITelsalerAttachingRateRecord> importBITelsalerAttachingRateRecordFromXlsx( public static ArrayList<BITelsalerAttachingRateRecord> importBITelsalerAttachingRateRecordFromXlsx(
String filePath, int SheetIndex, boolean hasCaptionRow ) String filePath, int SheetIndex, int firstRow )
throws IOException, InvalidFormatException throws IOException, InvalidFormatException
{ {
ArrayList<BITelsalerAttachingRateRecord> records = new ArrayList<>( 200 ); ArrayList<BITelsalerAttachingRateRecord> records = new ArrayList<>( 200 );
@ -70,8 +135,8 @@ public final class ImportBIExcelData
String name = ""; String name = "";
int rowIndex = row.getRowNum(); int rowIndex = row.getRowNum();
// 判断是否要跳过标题行 // 从数据行开始
if ( hasCaptionRow == true && row.getRowNum() == 0 ) if ( row.getRowNum() < firstRow )
{ {
continue; continue;
} }
@ -156,7 +221,7 @@ public final class ImportBIExcelData
* @return * @return
*/ */
public static ArrayList<BITelsalerRenewalRateRecord> importBITelsalerRenewalRateFromXlsx( public static ArrayList<BITelsalerRenewalRateRecord> importBITelsalerRenewalRateFromXlsx(
String filePath, int sheetIndex, boolean hasCaptionRow, LocalDate summaryDate ) String filePath, int sheetIndex, int firstRow, LocalDate summaryDate )
throws IOException throws IOException
{ {
ArrayList<BITelsalerRenewalRateRecord> records = new ArrayList<>( 200 ); ArrayList<BITelsalerRenewalRateRecord> records = new ArrayList<>( 200 );
@ -174,7 +239,8 @@ public final class ImportBIExcelData
{ {
rowIndex = row.getRowNum(); rowIndex = row.getRowNum();
if ( hasCaptionRow == true && rowIndex == 0 ) // 从数据行开始
if ( row.getRowNum() < firstRow )
{ {
continue; continue;
} }
@ -228,7 +294,7 @@ public final class ImportBIExcelData
} }
public static ArrayList<BIDepartmentArchievementRecord> importBIDepartmentArchievementRecords( 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 ); ArrayList<BIDepartmentArchievementRecord> records = new ArrayList<>( 5 );
@ -245,7 +311,8 @@ public final class ImportBIExcelData
{ {
rowIndex = row.getRowNum(); rowIndex = row.getRowNum();
if ( hasCaptionRow == true && rowIndex == 0 ) // 从数据行开始
if ( row.getRowNum() < firstRow )
{ {
continue; continue;
} }

View File

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

View File

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

View File

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