From e805bf914bcb31067a95ecf6f33a181323abb642 Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Mon, 9 Oct 2023 18:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=AF=BB=E5=8F=96=E8=BD=A6?= =?UTF-8?q?=E9=9D=9E=E6=B8=97=E9=80=8F=E8=A1=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pojo/TelsalerAttachingRateRecord.java | 121 ++++++++++++++++-- .../utils/data/TelsalerArchievementData.java | 87 ++++++++++++- .../com/cpic/xim/utils/poi/MyPOIUtils.java | 39 +++++- 3 files changed, 230 insertions(+), 17 deletions(-) diff --git a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/mybatis/pojo/TelsalerAttachingRateRecord.java b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/mybatis/pojo/TelsalerAttachingRateRecord.java index 8a35eb7..74e2393 100644 --- a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/mybatis/pojo/TelsalerAttachingRateRecord.java +++ b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/mybatis/pojo/TelsalerAttachingRateRecord.java @@ -15,34 +15,110 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class TelsalerAttachingRateRecord { // 统计日期 - @JsonProperty("summaryDate") + @JsonProperty( "summaryDate" ) private LocalDate summaryDate; - + // 坐席名称 - @JsonProperty("telsalerName") + @JsonProperty( "telsalerName" ) private String telsalerName; // 车险保费 - @JsonProperty("motoPremium") + @JsonProperty( "motoPremium" ) private double motoPremium; // 非车险保费 - @JsonProperty("nomotoPremium") + @JsonProperty( "nomotoPremium" ) private double nomotoPremium; // 车险保费占比 - @JsonProperty("motoPremiumProportion") + @JsonProperty( "motoPremiumProportion" ) private double motoPremiumProportion; // 渗透率 - @JsonProperty("attachingRate") + @JsonProperty( "attachingRate" ) private double attachingRate; // 渗透率环比上月 - @JsonProperty("attachingRateChange") + @JsonProperty( "attachingRateChange" ) private double attachingRateChange; - public TelsalerAttachingRateRecord() {} + // 当月客户渗透率 + @JsonProperty( "customerHandleRateCell" ) + private double customerHandleRateCell; + + // 客户渗透率环比上月 + @JsonProperty( "customerHandleRateChangeCell" ) + private double customerHandleRateChangeCell; + + // 当月车非客均保费 + @JsonProperty( "noMotoPremiumPerCustomerCell" ) + private double noMotoPremiumPerCustomerCell; + + // 客均保费环比上月 + @JsonProperty( "noMotoPremiumPerCustomerChangeCell" ) + private double noMotoPremiumPerCustomerChangeCell; + + public TelsalerAttachingRateRecord() + {} + + public TelsalerAttachingRateRecord( LocalDate summaryDate, String telsalerName, + double motoPremium, double nomotoPremium, double motoPremiumProportion, + double attachingRate, double attachingRateChange, double customerHandleRateCell, + double customerHandleRateChangeCell, double noMotoPremiumPerCustomerCell, + double noMotoPremiumPerCustomerChangeCell ) + { + this.summaryDate = summaryDate; + this.telsalerName = telsalerName; + this.motoPremium = motoPremium; + this.nomotoPremium = nomotoPremium; + this.motoPremiumProportion = motoPremiumProportion; + this.attachingRate = attachingRate; + this.attachingRateChange = attachingRateChange; + this.customerHandleRateCell = customerHandleRateCell; + this.customerHandleRateChangeCell = customerHandleRateChangeCell; + this.noMotoPremiumPerCustomerCell = noMotoPremiumPerCustomerCell; + this.noMotoPremiumPerCustomerChangeCell = noMotoPremiumPerCustomerChangeCell; + } + + public double getCustomerHandleRateCell() + { + return customerHandleRateCell; + } + + public void setCustomerHandleRateCell( double customerHandleRateCell ) + { + this.customerHandleRateCell = customerHandleRateCell; + } + + public double getCustomerHandleRateChangeCell() + { + return customerHandleRateChangeCell; + } + + public void setCustomerHandleRateChangeCell( double customerHandleRateChangeCell ) + { + this.customerHandleRateChangeCell = customerHandleRateChangeCell; + } + + public double getNoMotoPremiumPerCustomerCell() + { + return noMotoPremiumPerCustomerCell; + } + + public void setNoMotoPremiumPerCustomerCell( double noMotoPremiumPerCustomerCell ) + { + this.noMotoPremiumPerCustomerCell = noMotoPremiumPerCustomerCell; + } + + public double getNoMotoPremiumPerCustomerChangeCell() + { + return noMotoPremiumPerCustomerChangeCell; + } + + public void setNoMotoPremiumPerCustomerChangeCell( double noMotoPremiumPerCustomerChangeCell ) + { + this.noMotoPremiumPerCustomerChangeCell = noMotoPremiumPerCustomerChangeCell; + } @Override public String toString() @@ -50,7 +126,12 @@ public class TelsalerAttachingRateRecord return "TelsalerAttachingRateRecord [summaryDate=" + summaryDate + ", telsalerName=" + telsalerName + ", motoPremium=" + motoPremium + ", nomotoPremium=" + nomotoPremium + ", motoPremiumProportion=" + motoPremiumProportion + ", attachingRate=" - + attachingRate + ", attachingRateChange=" + attachingRateChange + "]"; + + attachingRate + ", attachingRateChange=" + attachingRateChange + + ", customerHandleRateCell=" + customerHandleRateCell + + ", customerHandleRateChangeCell=" + customerHandleRateChangeCell + + ", noMotoPremiumPerCustomerCell=" + noMotoPremiumPerCustomerCell + + ", noMotoPremiumPerCustomerChangeCell=" + noMotoPremiumPerCustomerChangeCell + + "]"; } @Override @@ -71,6 +152,14 @@ public class TelsalerAttachingRateRecord result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits( attachingRateChange ); result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits( customerHandleRateCell ); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits( customerHandleRateChangeCell ); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits( noMotoPremiumPerCustomerCell ); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits( noMotoPremiumPerCustomerChangeCell ); + result = prime * result + (int) (temp ^ (temp >>> 32)); return result; } @@ -113,6 +202,18 @@ public class TelsalerAttachingRateRecord if ( Double.doubleToLongBits( attachingRateChange ) != Double .doubleToLongBits( other.attachingRateChange ) ) return false; + if ( Double.doubleToLongBits( customerHandleRateCell ) != Double + .doubleToLongBits( other.customerHandleRateCell ) ) + return false; + if ( Double.doubleToLongBits( customerHandleRateChangeCell ) != Double + .doubleToLongBits( other.customerHandleRateChangeCell ) ) + return false; + if ( Double.doubleToLongBits( noMotoPremiumPerCustomerCell ) != Double + .doubleToLongBits( other.noMotoPremiumPerCustomerCell ) ) + return false; + if ( Double.doubleToLongBits( noMotoPremiumPerCustomerChangeCell ) != Double + .doubleToLongBits( other.noMotoPremiumPerCustomerChangeCell ) ) + return false; return true; } diff --git a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/data/TelsalerArchievementData.java b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/data/TelsalerArchievementData.java index 9d1ead9..4b1b361 100644 --- a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/data/TelsalerArchievementData.java +++ b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/data/TelsalerArchievementData.java @@ -11,22 +11,35 @@ package com.cpic.xim.utils.data; 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.openxml4j.opc.OPCPackage; +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 org.apache.poi.xssf.usermodel.XSSFWorkbook; import com.cpic.xim.mybatis.pojo.TelsalerAttachingRateRecord; +import com.cpic.xim.utils.poi.MyPOIUtils; /** * 坐席业绩相关的数据操作方法。 */ public class TelsalerArchievementData { + private static Logger logger = LoggerFactory.getLogger( TelsalerArchievementData.class ); + + /** + * + * @param filePath 文件路径 + * @param summaryDate 统计日期 + * @return 返回一个ArrayList保存的TelsalerAttachingRateRecord记录数组。 + * @throws IOException 打开excel文件错误时抛出。 + * @throws InvalidFormatException excel单元格格式错误时抛出 + */ public static ArrayList importTelsalerAttachingRateRecordFromXlsx( - String filePath ) throws IOException, InvalidFormatException + String filePath, LocalDate summaryDate, boolean hasCaptionRow ) throws IOException, InvalidFormatException { ArrayList records = new ArrayList<>( 200 ); @@ -35,8 +48,72 @@ public class TelsalerArchievementData try { - wb = WorkbookFactory.create( new File(filePath)); - sheet = wb.getSheet("经办"); + wb = WorkbookFactory.create( new File( filePath ) ); + sheet = wb.getSheet( "经办" ); + + for ( Row row : sheet ) + { + String name = ""; + int rowIndex = row.getRowNum(); + + // 判断是否要跳过标题行 + if ( hasCaptionRow == true && row.getRowNum() == 0 ) + { + continue; + } + + try + { + // 坐席名称 + name = MyPOIUtils.getStringCellValue( row, 1 ); + + if ( name.equals( "全流程" ) || name.equals( "其他" ) || name.isEmpty() ) + { + continue; + } + + // 车险保费 + double motoPremium = MyPOIUtils.getNumbericCellValue( row, 2 ); + // 非车险保费 + double nomotoPremium = MyPOIUtils.getNumbericCellValue( row, 4 ); + // 车险保费占比 + double motoPremiumProPortion = MyPOIUtils.getNumbericCellValue( row, 3 ); + // 当月保费渗透率 + double attachingRate = MyPOIUtils.getNumbericCellValue( row, 5 ); + // 保费手头率环比上月 + double attachingRateChange = MyPOIUtils.getNumbericCellValue( row, 6 ); + // 当月客户渗透率 + double customerHandleRateCell = MyPOIUtils.getNumbericCellValue( row, 7 ); + // 客户渗透率环比上月 + double customerHandleRateChangeCell = MyPOIUtils.getNumbericCellValue( row, 8 ); + // 当月车非客均保费 + double noMotoPremiumPerCustomerCell = MyPOIUtils.getNumbericCellValue( row, 9 ); + // 客均保费环比上月 + double noMotoPremiumPerCustomerChangeCell = + MyPOIUtils.getNumbericCellValue( row, 10 ); + + TelsalerAttachingRateRecord record = new TelsalerAttachingRateRecord( + summaryDate, name, motoPremium, nomotoPremium, motoPremiumProPortion, + attachingRate, attachingRateChange, customerHandleRateCell, + customerHandleRateChangeCell, noMotoPremiumPerCustomerCell, + noMotoPremiumPerCustomerChangeCell ); + + records.add( record ); + } + catch ( IllegalStateException error ) + { + error.printStackTrace(); + } + catch ( NumberFormatException error ) + { + error.printStackTrace(); + } + catch ( NullPointerException error ) + { + String message = "第" + String.valueOf(rowIndex) + "行出现NullPointerException异常"; + logger.error(message, error); + } + } } finally { diff --git a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/poi/MyPOIUtils.java b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/poi/MyPOIUtils.java index 19d964d..90af375 100644 --- a/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/poi/MyPOIUtils.java +++ b/code/后端/desktop_archievement_backend/src/main/java/com/cpic/xim/utils/poi/MyPOIUtils.java @@ -15,7 +15,7 @@ import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; public class MyPOIUtils { - public String getStringCellValue( Cell cell ) + public static String getStringCellValue( Cell cell ) { switch( cell.getCellType() ) { @@ -26,7 +26,7 @@ public class MyPOIUtils } } - public String getStringCellValue( Row row, int columnIndex ) + public static String getStringCellValue( Row row, int columnIndex ) { Cell cell = row.getCell(columnIndex, MissingCellPolicy.RETURN_NULL_AND_BLANK); @@ -38,4 +38,39 @@ public class MyPOIUtils return ""; } } + + public static double getNumbericCellValue( Cell cell ) + { + double value = 0.0; + + switch ( cell.getCellType() ) + { + case NUMERIC: + value = cell.getNumericCellValue(); + break; + default: + value = 0.0; + break; + } + + return value; + } + + public static double getNumbericCellValue( Row row, int columnIndex ) + { + double value = 0.0; + Cell cell = row.getCell( columnIndex, MissingCellPolicy.RETURN_NULL_AND_BLANK ); + + switch ( cell.getCellType() ) + { + case NUMERIC: + value = cell.getNumericCellValue(); + break; + default: + value = 0.0; + break; + } + + return value; + } } \ No newline at end of file