Browse Source

销售来源统计导出百分比处理

anderx 3 years ago
parent
commit
fea16e0f7a

+ 12 - 4
src/main/java/com/goafanti/common/utils/excel/Excel.java

@@ -9,7 +9,7 @@ import java.math.BigDecimal;
 
 /**
  * 自定义导出Excel数据注解
- * 
+ *
  * @author ruoyi
  */
 @Retention(RetentionPolicy.RUNTIME)
@@ -35,7 +35,7 @@ public @interface Excel
      * 如果是字典类型,请设置字典的type值 (如: sys_user_sex)
      */
     public String dictType() default "";
-    
+
     /**
      * 	枚举名称
      */
@@ -43,7 +43,7 @@ public @interface Excel
 
     /**
      *	 读取内容转表达式 (如: 0=男,1=女,2=未知)
-     *	
+     *
      */
     public String readConverterExp() default "";
 
@@ -83,6 +83,14 @@ public @interface Excel
      */
     public String suffix() default "";
 
+
+    /**
+     * 百分比
+     * 配合 suffix()使用,例如在后面加上%比后值需要乘以一百
+     * 则这个设置为1
+     */
+    public int percentage() default 0;
+
     /**
      * 当值为空时,字段的默认值
      */
@@ -175,4 +183,4 @@ public @interface Excel
             return this.value;
         }
     }
-}
+}

+ 42 - 38
src/main/java/com/goafanti/common/utils/excel/NewExcelUtil.java

@@ -63,8 +63,8 @@ import com.goafanti.common.utils.excel.Excel.ColumnType;
 
 /**
  * 	Excel相关处理
- * 
- * 
+ *
+ *
  */
 public class NewExcelUtil<T> {
 	private static final Logger log = LoggerFactory.getLogger(NewExcelUtil.class);
@@ -73,12 +73,12 @@ public class NewExcelUtil<T> {
 	 * Excel sheet最大行数,默认65536
 	 */
 	public static final int sheetSize = 65536;
-	
+
 	public  String downloadPath = "";
 
 	public  String screen = "";
-	
-	
+
+
 
 	/**
 	 * 工作表名称
@@ -146,7 +146,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 对list数据源将其里面的数据导入到excel表单
-	 * 
+	 *
 	 * @param list      导出数据集合
 	 * @param sheetName 工作表的名称
 	 * @return 结果
@@ -155,7 +155,7 @@ public class NewExcelUtil<T> {
 		this.init(list, sheetName);
 		return exportExcel();
 	}
-	
+
 	/**
 	 * 	直接导出CXCEL表
 	 * @param list 导出数据集合
@@ -169,8 +169,8 @@ public class NewExcelUtil<T> {
 	}
 
 
-	
-	
+
+
 	/**
 	 * 	导出CXCEL表到指定目录
 	 * @param list 导出数据集合
@@ -249,8 +249,8 @@ public class NewExcelUtil<T> {
 			}
 		}
 	}
-	
-	
+
+
 
 
 	private String DateFilename(String sheetName) {
@@ -260,7 +260,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 对list数据源将其里面的数据导入到excel表单
-	 * 
+	 *
 	 * @param sheetName 工作表的名称
 	 * @return 结果
 	 */
@@ -271,7 +271,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 对list数据源将其里面的数据导入到excel表单
-	 * 
+	 *
 	 * @return 结果
 	 */
 	public Result exportExcel() {
@@ -338,7 +338,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 填充excel数据
-	 * 
+	 *
 	 * @param index 序号
 	 * @param row   单元格行
 	 */
@@ -363,7 +363,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 创建表格样式
-	 * 
+	 *
 	 * @param wb 工作薄对象
 	 * @return 样式列表
 	 */
@@ -445,7 +445,7 @@ public class NewExcelUtil<T> {
 		cell.setCellStyle(styles.get("header"));
 		return cell;
 	}
-	
+
 	/**
 	 * 创建单元格
 	 */
@@ -461,13 +461,17 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 设置单元格信息
-	 * 
+	 *
 	 * @param value 单元格值
 	 * @param attr  注解相关
 	 * @param cell  单元格信息
 	 */
 	public void setCellVo(Object value, Excel attr, Cell cell) {
 		if (ColumnType.STRING == attr.cellType()) {
+			if (attr.percentage()==1){
+				BigDecimal v=new BigDecimal(value.toString());
+				value=v.multiply(new BigDecimal(100)).stripTrailingZeros().toPlainString();
+			}
 			cell.setCellValue(StringUtils.isNull(value) ? attr.defaultValue() : value + attr.suffix());
 		} else if (ColumnType.NUMERIC == attr.cellType()) {
 			cell.setCellValue(StringUtils.contains(toStr(value), ".") ? toDouble(value) : toInt(value));
@@ -567,11 +571,11 @@ public class NewExcelUtil<T> {
 		return cell;
 	}
 
-		
+
 
 	/**
 	 * 设置 POI XSSFSheet 单元格提示
-	 * 
+	 *
 	 * @param sheet         表单
 	 * @param promptTitle   提示标题
 	 * @param promptContent 提示内容
@@ -593,7 +597,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 设置某些列的值只能输入预制的数据,显示下拉框.
-	 * 
+	 *
 	 * @param sheet    要设置的sheet.
 	 * @param textlist 下拉框显示的内容
 	 * @param firstRow 开始行
@@ -623,7 +627,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 解析导出值 0=男,1=女,2=未知
-	 * 
+	 *
 	 * @param propertyValue 参数值
 	 * @param converterExp  翻译注解
 	 * @param separator     分隔符
@@ -652,7 +656,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 反向解析值 男=0,女=1,未知=2
-	 * 
+	 *
 	 * @param propertyValue 参数值
 	 * @param converterExp  翻译注解
 	 * @param separator     分隔符
@@ -727,7 +731,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 获取下载路径
-	 * 
+	 *
 	 * @param filename 文件名称
 	 */
 	public String getAbsoluteFile(String filename) {
@@ -742,7 +746,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 获取bean中的属性值
-	 * 
+	 *
 	 * @param vo    实体对象
 	 * @param field 字段
 	 * @param excel 注解
@@ -767,7 +771,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 以类的属性的get方法方法形式获取值
-	 * 
+	 *
 	 * @param o
 	 * @param name
 	 * @return value
@@ -841,7 +845,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 创建工作表
-	 * 
+	 *
 	 * @param sheetNo sheet数量
 	 * @param index   序号
 	 */
@@ -858,7 +862,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 获取单元格值
-	 * 
+	 *
 	 * @param row    获取的行
 	 * @param column 获取单元格列号
 	 * @return 单元格值
@@ -901,7 +905,7 @@ public class NewExcelUtil<T> {
 	 * 转换为字符串<br>
 	 * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
 	 * 转换失败不会报错
-	 * 
+	 *
 	 * @param value 被转换的值
 	 * @return 结果
 	 */
@@ -913,7 +917,7 @@ public class NewExcelUtil<T> {
 	 * 转换为字符串<br>
 	 * 如果给定的值为null,或者转换失败,返回默认值<br>
 	 * 转换失败不会报错
-	 * 
+	 *
 	 * @param value        被转换的值
 	 * @param defaultValue 转换错误时的默认值
 	 * @return 结果
@@ -932,7 +936,7 @@ public class NewExcelUtil<T> {
 	 * 转换为double<br>
 	 * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
 	 * 转换失败不会报错
-	 * 
+	 *
 	 * @param value 被转换的值
 	 * @return 结果
 	 */
@@ -944,7 +948,7 @@ public class NewExcelUtil<T> {
 	 * 转换为double<br>
 	 * 如果给定的值为空,或者转换失败,返回默认值<br>
 	 * 转换失败不会报错
-	 * 
+	 *
 	 * @param value        被转换的值
 	 * @param defaultValue 转换错误时的默认值
 	 * @return 结果
@@ -975,7 +979,7 @@ public class NewExcelUtil<T> {
 	 * 转换为int<br>
 	 * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
 	 * 转换失败不会报错
-	 * 
+	 *
 	 * @param value 被转换的值
 	 * @return 结果
 	 */
@@ -987,7 +991,7 @@ public class NewExcelUtil<T> {
 	 * 转换为int<br>
 	 * 如果给定的值为空,或者转换失败,返回默认值<br>
 	 * 转换失败不会报错
-	 * 
+	 *
 	 * @param value        被转换的值
 	 * @param defaultValue 转换错误时的默认值
 	 * @return 结果
@@ -1015,7 +1019,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 获取文件类型
-	 * 
+	 *
 	 * @param photoByte 文件字节码
 	 * @return 后缀(不含".")
 	 */
@@ -1059,7 +1063,7 @@ public class NewExcelUtil<T> {
 
 	/**
 	 * 读取文件为字节数据
-	 * 
+	 *
 	 * @return 字节数据
 	 */
 	public static byte[] readFile(String url) {
@@ -1089,8 +1093,8 @@ public class NewExcelUtil<T> {
 		}
 	}
 
-	
 
-	
 
-}
+
+
+}

+ 8 - 8
src/main/java/com/goafanti/order/bo/OutOrderSalesSource.java

@@ -8,37 +8,37 @@ public class OutOrderSalesSource {
     private Integer province;
     @Excel(name = "省份")
     private String name;
-    @Excel(name = "签单金额(万元)")
+    @Excel(name = "签单金额(万元)",scale=6)
     private BigDecimal totalAmount;
     @Excel(name = "签单数(个)")
     private Integer counts;
     @Excel(name = "电话")
     private Integer dh;
-    @Excel(name = "电话占比",suffix = "%")
+    @Excel(name = "电话占比",suffix = "%",percentage = 1)
     private String dhl;
     @Excel(name = "网络")
     private Integer wl;
-    @Excel(name = "网络占比")
+    @Excel(name = "网络占比",suffix = "%",percentage = 1)
     private String wll;
     @Excel(name = "渠道")
     private Integer qd;
-    @Excel(name = "渠道占比")
+    @Excel(name = "渠道占比",suffix = "%",percentage = 1)
     private String qdl;
     @Excel(name = "转介绍")
     private Integer zjs;
-    @Excel(name = "转介绍占比")
+    @Excel(name = "转介绍占比",suffix = "%",percentage = 1)
     private String zjsl;
     @Excel(name = "其他")
     private Integer qt;
-    @Excel(name = "其他占比")
+    @Excel(name = "其他占比",suffix = "%",percentage = 1)
     private String qtl;
     @Excel(name = "高新复购")
     private Integer gxfg;
-    @Excel(name = "高新复购占比")
+    @Excel(name = "高新复购占比",suffix = "%",percentage = 1)
     private String gxfgl;
     @Excel(name = "其他复购")
     private Integer qtfg;
-    @Excel(name = "其他复购占比")
+    @Excel(name = "其他复购占比",suffix = "%",percentage = 1)
     private String qtfgl;
 
     public Integer getProvince() {