diff --git a/code/web/task_schedule/src/utils/BIReport.ts b/code/web/task_schedule/src/utils/BIReport.ts index a88a612..3690ad0 100644 --- a/code/web/task_schedule/src/utils/BIReport.ts +++ b/code/web/task_schedule/src/utils/BIReport.ts @@ -20,7 +20,7 @@ interface ImportBIReportRequest { filePath: string, reportType: number, - hasCaption: boolean, + firstRow: number, sheetIndex: number, } diff --git a/code/web/task_schedule/src/views/data/bi/BiDataUploadView.vue b/code/web/task_schedule/src/views/data/bi/BiDataUploadView.vue index 6fe2dcc..40b7de0 100644 --- a/code/web/task_schedule/src/views/data/bi/BiDataUploadView.vue +++ b/code/web/task_schedule/src/views/data/bi/BiDataUploadView.vue @@ -14,13 +14,14 @@ 报表类型 - + @@ -33,10 +34,13 @@ - 标题行 + 起始行 - - + + + + + *从0开始计数 @@ -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, }; diff --git a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/data/ImportBIExcelData.java b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/data/ImportBIExcelData.java index 1aa620e..99d3867 100644 --- a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/data/ImportBIExcelData.java +++ b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/data/ImportBIExcelData.java @@ -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 importBITelsalerAttachingRateRecordFromXlsx( - String filePath, int SheetIndex, boolean hasCaptionRow ) + String filePath, int SheetIndex, int firstRow ) throws IOException, InvalidFormatException { ArrayList 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 importBITelsalerRenewalRateFromXlsx( - String filePath, int sheetIndex, boolean hasCaptionRow, LocalDate summaryDate ) + String filePath, int sheetIndex, int firstRow, LocalDate summaryDate ) throws IOException { ArrayList 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 importBIDepartmentArchievementRecords( - String filePath, int sheetIndex, boolean hasCaptionRow ) throws IOException + String filePath, int sheetIndex, int firstRow ) throws IOException { ArrayList 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; } diff --git a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/web/controllers/dataimport/bi/ImportBIDataController.java b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/web/controllers/dataimport/bi/ImportBIDataController.java index 93c25bc..e7d5312 100644 --- a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/web/controllers/dataimport/bi/ImportBIDataController.java +++ b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/web/controllers/dataimport/bi/ImportBIDataController.java @@ -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 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 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 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 ); diff --git a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/web/controllers/dataimport/bi/ImportBIDataRequest.java b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/web/controllers/dataimport/bi/ImportBIDataRequest.java index e7a008b..538fea2 100644 --- a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/web/controllers/dataimport/bi/ImportBIDataRequest.java +++ b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/web/controllers/dataimport/bi/ImportBIDataRequest.java @@ -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 + "]"; } diff --git a/code/后端/desktop_archievement_backend/src/test/java/com/cpic/xim/DesktopArchievement/test/BatchInsertTest.java b/code/后端/desktop_archievement_backend/src/test/java/com/cpic/xim/DesktopArchievement/test/BatchInsertTest.java index 8be8fd7..0eac61e 100644 --- a/code/后端/desktop_archievement_backend/src/test/java/com/cpic/xim/DesktopArchievement/test/BatchInsertTest.java +++ b/code/后端/desktop_archievement_backend/src/test/java/com/cpic/xim/DesktopArchievement/test/BatchInsertTest.java @@ -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 );