海南版本提交

This commit is contained in:
hzj
2024-03-18 15:21:28 +08:00
parent 5b7763b265
commit 5fff26c276
27 changed files with 1647 additions and 274 deletions

View File

@@ -60,5 +60,10 @@
<artifactId>harmonic-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
</project>

View File

@@ -36,7 +36,8 @@ public enum AdvanceResponseEnum {
DATA_UNDERRUN("A0104","数据量不足,请根据模版上传充足近两周数据"),
DOCUMENT_FORMAT_ERROR("A0105","数据缺失,导入失败!请检查导入文档的格式是否正确"),
USER_LOST("A0106","干扰源用户缺失"),
UNCOMPLETE_STRATEGY("A0106","配置安全III级预警,II级预警,I级预警4条完整策略"),
EXISTENCE_EVALUATION_RESULT("A0104","存在评结果结果,如要评估,请删除后评估"),
SG_USER_NAME_REPEAT("A0102","业务用户名重复"),
SG_USER_ID_MISS("A0102","业务用户id缺失"),

View File

@@ -0,0 +1,286 @@
package com.njcn.advance.pojo.carrycapacity.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.converters.localdatetime.LocalDateTimeStringConverter;
import com.njcn.advance.utils.EasyExcelUtil;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2022/5/12 9:13
*/
@Data
public class CarryCapcityDataEexcel {
@ExcelProperty(index = 0,value = "时间",converter = LocalDateTimeStringConverter.class)
private LocalDateTime time;
@ExcelProperty(index =1,value = {"电压","A"})
private Double u_a;
@ExcelProperty(index =2,value = {"电压","B"})
private Double u_b;
@ExcelProperty(index =3,value = {"电压","C"})
private Double u_c;
@ExcelProperty(index =4,value = {"有功功率","A"})
private Double p_a;
@ExcelProperty(index =5,value = {"有功功率","B"})
private Double p_b;
@ExcelProperty(index =6,value = {"有功功率","C"})
private Double p_c;
@ExcelProperty(index =7,value = {"无功功率","A"})
private Double q_a;
@ExcelProperty(index =8,value = {"无功功率","B"})
private Double q_b;
@ExcelProperty(index =9,value = {"无功功率","C"})
private Double q_c;
@ExcelProperty(index =10,value = {"电流","2次","A"})
private Double i2_a;
@ExcelProperty(index =11,value = {"电流","2次","B"})
private Double i2_b;
@ExcelProperty(index =12,value = {"电流","2次","C"})
private Double i2_c;
@ExcelProperty(index =13,value = {"电流","3次","A"})
private Double i3_a;
@ExcelProperty(index =14,value = {"电流","3次","B"})
private Double i3_b;
@ExcelProperty(index =15,value = {"电流","3次","C"})
private Double i3_c;
@ExcelProperty(index =16,value = {"电流","4次","A"})
private Double i4_a;
@ExcelProperty(index =17,value = {"电流","4次","B"})
private Double i4_b;
@ExcelProperty(index =18,value = {"电流","4次","C"})
private Double i4_c;
@ExcelProperty(index =19,value = {"电流","5次","A"})
private Double i5_a;
@ExcelProperty(index =20,value = {"电流","5次","B"})
private Double i5_b;
@ExcelProperty(index =21,value = {"电流","5次","C"})
private Double i5_c;
@ExcelProperty(index =22,value = {"电流","6次","A"})
private Double i6_a;
@ExcelProperty(index =23,value = {"电流","6次","B"})
private Double i6_b;
@ExcelProperty(index =24,value = {"电流","6次","C"})
private Double i6_c;
@ExcelProperty(index =25,value = {"电流","7次","A"})
private Double i7_a;
@ExcelProperty(index =26,value = {"电流","7次","B"})
private Double i7_b;
@ExcelProperty(index =27,value = {"电流","7次","C"})
private Double i7_c;
@ExcelProperty(index =28,value = {"电流","8次","A"})
private Double i8_a;
@ExcelProperty(index =29,value = {"电流","8次","B"})
private Double i8_b;
@ExcelProperty(index =30,value = {"电流","8次","C"})
private Double i8_c;
@ExcelProperty(index =31,value = {"电流","9次","A"})
private Double i9_a;
@ExcelProperty(index =32,value = {"电流","9次","B"})
private Double i9_b;
@ExcelProperty(index =33,value = {"电流","9次","C"})
private Double i9_c;
@ExcelProperty(index =34,value = {"电流","10次","A"})
private Double i10_a;
@ExcelProperty(index =35,value = {"电流","10次","B"})
private Double i10_b;
@ExcelProperty(index =36,value = {"电流","10次","C"})
private Double i10_c;
@ExcelProperty(index =37,value = {"电流","11次","A"})
private Double i11_a;
@ExcelProperty(index =38,value = {"电流","11次","B"})
private Double i11_b;
@ExcelProperty(index =39,value = {"电流","11次","C"})
private Double i11_c;
@ExcelProperty(index =40,value = {"电流","12次","A"})
private Double i12_a;
@ExcelProperty(index =41,value = {"电流","12次","B"})
private Double i12_b;
@ExcelProperty(index =42,value = {"电流","12次","C"})
private Double i12_c;
@ExcelProperty(index =43,value = {"电流","13次","A"})
private Double i13_a;
@ExcelProperty(index =44,value = {"电流","13次","B"})
private Double i13_b;
@ExcelProperty(index =45,value = {"电流","13次","C"})
private Double i13_c;
@ExcelProperty(index =46,value = {"电流","14次","A"})
private Double i14_a;
@ExcelProperty(index =47,value = {"电流","14次","B"})
private Double i14_b;
@ExcelProperty(index =48,value = {"电流","14次","C"})
private Double i14_c;
@ExcelProperty(index =49,value = {"电流","15次","A"})
private Double i15_a;
@ExcelProperty(index =50,value = {"电流","15次","B"})
private Double i15_b;
@ExcelProperty(index =51,value = {"电流","15次","C"})
private Double i15_c;
@ExcelProperty(index =52,value = {"电流","16次","A"})
private Double i16_a;
@ExcelProperty(index =53,value = {"电流","16次","B"})
private Double i16_b;
@ExcelProperty(index =54,value = {"电流","16次","C"})
private Double i16_c;
@ExcelProperty(index =55,value = {"电流","17次","A"})
private Double i17_a;
@ExcelProperty(index =56,value = {"电流","17次","B"})
private Double i17_b;
@ExcelProperty(index =57,value = {"电流","17次","C"})
private Double i17_c;
@ExcelProperty(index =58,value = {"电流","18次","A"})
private Double i18_a;
@ExcelProperty(index =59,value = {"电流","18次","B"})
private Double i18_b;
@ExcelProperty(index =60,value = {"电流","18次","C"})
private Double i18_c;
@ExcelProperty(index =61,value = {"电流","19次","A"})
private Double i19_a;
@ExcelProperty(index =62,value = {"电流","19次","B"})
private Double i19_b;
@ExcelProperty(index =63,value = {"电流","19次","C"})
private Double i19_c;
@ExcelProperty(index =64,value = {"电流","20次","A"})
private Double i20_a;
@ExcelProperty(index =65,value = {"电流","20次","B"})
private Double i20_b;
@ExcelProperty(index =66,value = {"电流","20次","C"})
private Double i20_c;
@ExcelProperty(index =67,value = {"电流","21次","A"})
private Double i21_a;
@ExcelProperty(index =68,value = {"电流","21次","B"})
private Double i21_b;
@ExcelProperty(index =69,value = {"电流","21次","C"})
private Double i21_c;
@ExcelProperty(index =70,value = {"电流","22次","A"})
private Double i22_a;
@ExcelProperty(index =71,value = {"电流","22次","B"})
private Double i22_b;
@ExcelProperty(index =72,value = {"电流","22次","C"})
private Double i22_c;
@ExcelProperty(index =73,value = {"电流","23次","A"})
private Double i23_a;
@ExcelProperty(index =74,value = {"电流","23次","B"})
private Double i23_b;
@ExcelProperty(index =75,value = {"电流","23次","C"})
private Double i23_c;
@ExcelProperty(index =76,value = {"电流","24次","A"})
private Double i24_a;
@ExcelProperty(index =77,value = {"电流","24次","B"})
private Double i24_b;
@ExcelProperty(index =78,value = {"电流","24次","C"})
private Double i24_c;
@ExcelProperty(index =79,value = {"电流","25次","A"})
private Double i25_a;
@ExcelProperty(index =80,value = {"电流","25次","B"})
private Double i25_b;
@ExcelProperty(index =81,value = {"电流","25次","C"})
private Double i25_c;
public static void main(String[] args) {
List<CarryCapcityDataEexcel> objects = EasyExcelUtil.syncReadModel("C:\\Users\\无名\\Desktop\\11.xlsx", CarryCapcityDataEexcel.class, 0,3);
System.out.println(objects);
// String sheetName = "sheetName";
// List<CarryCapcityDataEexcel> excels = new ArrayList<>();
// CarryCapcityDataEexcel exportHeadersExcel = new CarryCapcityDataEexcel();
// excels.add(exportHeadersExcel);
//
// EasyExcel.write("C:\\\\Users\\\\无名\\\\Desktop\\\\22.xlsx", CarryCapcityDataEexcel.class)
// .sheet(sheetName)
// .doWrite(excels);
}
}

View File

@@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
@@ -21,17 +23,21 @@ import java.util.List;
@AllArgsConstructor
public class CarryCapacityEvaluateParam {
@ApiModelProperty(value = "接线类型不可为空\"星型接法_0\", \"三角型接法_1\", \"开口三角型接法_2\"")
@NotBlank(message = "接线类型不能为空")
private String ptType;
@ApiModelProperty(value = "变压器连接方式")
private String connectionMode;
@ApiModelProperty(value = "功率因数0.95-1之间")
@NotNull(message = "功率因数不能为空")
private Double k;
@ApiModelProperty(value = "专变用户,公变用户")
@NotBlank(message = "用户类型不能为空")
private String userMode;
@ApiModelProperty(name = "scale",value = "电压等级")
@NotBlank(message = "电压等级不能为空")
private String scale;
@ApiModelProperty(name = "shortCapacity",value = "短路容量")

View File

@@ -19,6 +19,8 @@ import javax.validation.constraints.NotNull;
@AllArgsConstructor
@NoArgsConstructor
public class CarryCapacityStrategyParam {
private String id;
/**
* 总承载能力评估结果1-安全2-III级预警3-II级预警4-I 级预警)
*/

View File

@@ -89,7 +89,7 @@ public class CarryCapacityUserParam {
@NotNull(message="显示条数不能为空!")
@ApiModelProperty(value = "显示条数",name = "pageSize",dataType ="Integer",required = true)
private Integer pageSize;
private String voltage;
@ApiModelProperty(value="起始时间")
private String startTime;

View File

@@ -78,7 +78,7 @@ public class CarryCapacityResultPO extends BaseEntity {
private Integer iLevel;
/**
* 总结果等级1-安全2-III级预警3-II级预警4-I 级预警)
* 总结果等级1-安全2-III级预警3-II级预警4-I 级预警,5-禁止接入6-允许接入
*/
@TableField(value = "reslut_level")
private Integer reslutLevel;
@@ -100,9 +100,30 @@ public class CarryCapacityResultPO extends BaseEntity {
@TableField(value = "first_result")
private Double firstResult;
private double firstResult;
@TableField(value = "i_result_list")
private String iResultList;
@TableField(value = "pt_type")
private String ptType;
@TableField(value = "connection_mode")
private String connectionMode;
@TableField(value = "k")
private Double k;
@TableField(value = "user_mode")
private String userMode;
@TableField(value = "scale")
private String scale;
@TableField(value = "short_capacity")
private Float shortCapacity;
@TableField(value = "device_capacity")
private Float deviceCapacity;
}

View File

@@ -0,0 +1,98 @@
package com.njcn.advance.pojo.carrycapacity.po;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.bo.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*
* Description:
* Date: 2024/3/15 10:45【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "carry_capacity_strategy_dhl")
public class CarryCapacityStrategyDhlPO extends BaseEntity {
/**
* id
*/
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
/**
* 充电桩,电弧炉,电气化铁路
*/
@TableField(value = "`type`")
private String type;
/**
* 一级评估比较符
*/
@TableField(value = "comparison_operators_1")
private String comparisonOperators1;
/**
* 一级评估数量
*/
@TableField(value = "count_1")
private Integer count1;
/**
* 二级级评估2~20次谐波合格个数比较符
*/
@TableField(value = "comparison_operators_2")
private String comparisonOperators2;
/**
* 二级评估2~20次谐波合格个数数量
*/
@TableField(value = "count_2")
private Integer count2;
/**
* 二级级评估(奇数谐波合格个数)比较符
*/
@TableField(value = "comparison_operators_3")
private String comparisonOperators3;
/**
* 二级评估(奇数次谐波合格)个数数量
*/
@TableField(value = "count_3")
private Integer count3;
/**
* 初始配置1客户配置2
*/
@TableField(value = "proto_flag")
private Integer protoFlag;
/**
* 二级级评估(偶数谐波合格个数)比较符
*/
@TableField(value = "comparison_operators_4")
private String comparisonOperators4;
/**
* 二级评估(偶数次谐波合格)个数数量
*/
@TableField(value = "count_4")
private Integer count4;
/**
* 启用配置1不启用配置2
*/
@TableField(value = "user_flag")
private Integer userFlag;
}

View File

@@ -55,4 +55,7 @@ public class CarryCapacityStrategyPO extends BaseEntity {
@TableField(value = "user_flag")
private Integer userFlag;
@TableField(value = "id")
private String id;
}

View File

@@ -1,5 +1,6 @@
package com.njcn.advance.pojo.carrycapacity.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -79,6 +80,21 @@ public class CarryCapacityDResultVO {
private List<CarryCapacityDResultVO.CarryCapacityIResult> iResultList;
@TableField(value = "pt_type")
private String connectionMode;
private Double k;
private String userMode;
private String scale;
private Float shortCapacity;
private Float deviceCapacity;
@Data
public static class CarryCapacityIResult {

View File

@@ -0,0 +1,76 @@
package com.njcn.advance.pojo.carrycapacity.vo;
import lombok.Data;
/**
*
* Description:
* Date: 2024/3/15 10:45【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Data
public class CarryCapacityStrategyDhlVO {
/**
* id
*/
private String id;
/**
* 充电桩,电弧炉,电气化铁路
*/
private String type;
/**
* 一级评估比较符
*/
private String comparisonOperators1;
/**
* 一级评估数量
*/
private Integer count1;
/**
* 二级级评估2~20次谐波合格个数比较符
*/
private String comparisonOperators2;
/**
* 二级评估2~20次谐波合格个数数量
*/
private Integer count2;
/**
* 二级级评估(奇数谐波合格个数)比较符
*/
private String comparisonOperators3;
/**
* 二级评估(奇数次谐波合格)个数数量
*/
private Integer count3;
/**
* 初始配置1客户配置2
*/
private Integer protoFlag;
/**
* 二级级评估(偶数谐波合格个数)比较符
*/
private String comparisonOperators4;
/**
* 二级评估(偶数次谐波合格)个数数量
*/
private Integer count4;
/**
* 启用配置1不启用配置2
*/
private Integer userFlag;
}

View File

@@ -3,6 +3,8 @@ package com.njcn.advance.pojo.carrycapacity.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* Description:
* Date: 2024/3/5 10:47【需求编号】
@@ -12,29 +14,46 @@ import lombok.Data;
*/
@Data
public class CarryCapacityStrategyVO {
/**
* 总承载能力评估结果1-安全2-III级预警3-II级预警4-I 级预警)
*/
@ApiModelProperty(value = "总承载能力评估结果1-安全2-III级预警3-II级预警4-I 级预警)")
private Integer result;
/**
* 指标评估结果1-安全2-III级预警3-II级预警4-I 级预警)
*/
@ApiModelProperty(value = "指标评估结果1-安全2-III级预警3-II级预警4-I 级预警)")
private Integer indexResult;
/**
* 比较符
*/
@ApiModelProperty(value = "比较符")
private String comparisonOperators;
/**
* 数量
*/
@ApiModelProperty(value = "数量")
private Integer count;
private List<CarryCapacityStrategysingleVO> capacityStrategysingleVOList;
@Data
public static class CarryCapacityStrategysingleVO {
private String id;
private List<CarryCapacityStrategyIndexVO> carryCapacityStrategyIndexVOList;
@Data
public static class CarryCapacityStrategyIndexVO {
/**
* 指标评估结果1-安全2-III级预警3-II级预警4-I 级预警)
*/
@ApiModelProperty(value = "指标评估结果1-安全2-III级预警3-II级预警4-I 级预警)")
private Integer indexResult;
/**
* 比较符
*/
@ApiModelProperty(value = "比较符")
private String comparisonOperators;
/**
* 数量
*/
@ApiModelProperty(value = "数量")
private Integer count;
}
}
}

View File

@@ -0,0 +1,88 @@
package com.njcn.advance.utils;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelDataConvertException;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Description:
* Date: 2024/3/15 16:02【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Slf4j
public abstract class EasyExcelDefaultListener<T> extends AnalysisEventListener<T> {
/**
* 批处理阈值
*/
private static final int BATCH_COUNT = 20;
/**
* 用来存放待处理的数据
*/
@Getter
private List<T> list = new ArrayList<>(BATCH_COUNT);
/**
* 读取excel数据前操作 <br>
*
* 只有不读取表头数据时才会触发此方法)
*/
@Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
log.info("======================================================");
log.info("======================================================");
}
/**
* 读取excel数据操作
* @param obj
* @param context
*/
@Override
public void invoke(T obj, AnalysisContext context) {
list.add(obj);
if (list.size() >= BATCH_COUNT) {
//将数据保存到数据库中
fun(list);
list.clear();
}
}
/**
* 具体业务
*/
protected abstract void fun(List<T> list);
/**
* 读取完excel数据后的操作
*/
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
if (list.size() > 0) {
fun(list);
}
}
/**
* 在读取excel异常 获取其他异常下会调用本接口。抛出异常则停止读取。如果这里不抛出异常则 继续读取下一行。
*/
@Override
public void onException(Exception exception, AnalysisContext context) {
log.error("解析失败,但是继续解析下一行:{}", exception.getMessage());
if (exception instanceof ExcelDataConvertException) {
ExcelDataConvertException ex = (ExcelDataConvertException) exception;
log.error("第{}行,第{}列解析异常,数据为:{}", ex.getRowIndex(), ex.getColumnIndex(), ex.getCellData());
}
}
}

View File

@@ -0,0 +1,379 @@
package com.njcn.advance.utils;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.write.handler.WriteHandler;
import lombok.SneakyThrows;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Description:
* Date: 2024/3/15 15:58【需求编号】
*
* @author clam
* @version V1.0.0
*/
public class EasyExcelUtil {
//====================================================无JAVA模型读取excel数据===============================================================
/**
* 同步无模型读默认读取sheet0,从第2行开始读
* @param file excel文件的绝对路径
*/
public static List<Map<Integer, String>> syncRead(String file) {
return EasyExcelFactory.read(file).sheet().doReadSync();
}
/**
* 同步无模型读自定义读取sheetX从第2行开始读
* @param file excel文件的绝对路径
* @param sheetNum sheet页号从0开始
*/
public static List<Map<Integer, String>> syncRead(String file, Integer sheetNum) {
return EasyExcelFactory.read(file).sheet(sheetNum).doReadSync();
}
/**
* 同步无模型读指定sheet和表头占的行数
* @param file
* @param sheetNum sheet页号从0开始
* @param headNum 表头占的行数从0开始如果要连表头一起读出来则传0
*/
public static List<Map<Integer, String>> syncRead(String file, Integer sheetNum, Integer headNum) {
return EasyExcelFactory.read(file).sheet(sheetNum).headRowNumber(headNum).doReadSync();
}
/**
* 同步无模型读指定sheet和表头占的行数
* @param inputStream
* @param sheetNum sheet页号从0开始
* @param headNum 表头占的行数从0开始如果要连表头一起读出来则传0
*/
public static List<Map<Integer, String>> syncRead(InputStream inputStream, Integer sheetNum, Integer headNum) {
return EasyExcelFactory.read(inputStream).sheet(sheetNum).headRowNumber(headNum).doReadSync();
}
/**
* 同步无模型读指定sheet和表头占的行数
* @param file
* @param sheetNum sheet页号从0开始
* @param headNum 表头占的行数从0开始如果要连表头一起读出来则传0
*/
public static List<Map<Integer, String>> syncRead(File file, Integer sheetNum, Integer headNum) {
return EasyExcelFactory.read(file).sheet(sheetNum).headRowNumber(headNum).doReadSync();
}
//====================================================无JAVA模型读取excel数据===============================================================
//====================================================将excel数据同步到JAVA模型属性里===============================================================
/**
* 同步按模型读默认读取sheet0,不读取表头从第2行开始读
* @param file
* @param clazz 模型的类类型excel数据会按该类型转换成对象
*/
public static <T> List<T> syncReadModel(String file, Class clazz) {
return EasyExcelFactory.read(file).sheet().head(clazz).doReadSync();
}
/**
* 同步按模型读默认表头占一行不读取表头从第2行开始读
* @param file
* @param clazz 模型的类类型excel数据会按该类型转换成对象
* @param sheetNum sheet页号从0开始
*/
public static <T> List<T> syncReadModel(String file, Class clazz, Integer sheetNum, Integer headNum) {
return EasyExcelFactory.read(file).sheet(sheetNum).headRowNumber(headNum).head(clazz).doReadSync();
}
/**
* 同步按模型读指定sheet,不读取表头)
* @param inputStream
* @param clazz 模型的类类型excel数据会按该类型转换成对象
* @param sheetNum sheet页号从0开始
*/
public static <T> List<T> syncReadModel(InputStream inputStream, Class clazz, Integer sheetNum, Integer headNum) {
return EasyExcelFactory.read(inputStream).sheet(sheetNum).headRowNumber(headNum).head(clazz).doReadSync();
}
/**
* 同步按模型读指定sheet,不读取表头)
* @param file
* @param clazz 模型的类类型excel数据会按该类型转换成对象
* @param sheetNum sheet页号从0开始
*/
public static <T> List<T> syncReadModel(File file, Class clazz, Integer sheetNum, Integer headNum) {
return EasyExcelFactory.read(file).sheet(sheetNum).headRowNumber(headNum).head(clazz).doReadSync();
}
//====================================================将excel数据同步到JAVA模型属性里===============================================================
//====================================================异步读取excel数据===============================================================
/**
* 异步无模型读默认读取sheet0,不读取表头,从第2行开始读
* @param listener 监听器在监听器中可以处理行数据LinkedHashMap表头数据异常处理等
* @param file 表头占的行数从0开始如果要连表头一起读出来则传0
*/
public static <T> void asyncRead(String file, AnalysisEventListener<T> listener) {
EasyExcelFactory.read(file, listener).sheet().doRead();
}
/**
* 异步无模型读(默认表头占一行,不读取表头,从第2行开始读
* @param file 表头占的行数从0开始如果要连表头一起读出来则传0
* @param listener 监听器在监听器中可以处理行数据LinkedHashMap表头数据异常处理等
* @param sheetNum sheet页号从0开始
*/
public static <T> void asyncRead(String file, AnalysisEventListener<T> listener, Integer sheetNum) {
EasyExcelFactory.read(file, listener).sheet(sheetNum).doRead();
}
/**
* 异步无模型读指定sheet和表头占的行数
* @param inputStream
* @param listener 监听器在监听器中可以处理行数据LinkedHashMap表头数据异常处理等
* @param sheetNum sheet页号从0开始
* @param headNum 表头占的行数从0开始如果要连表头一起读出来则传0
*/
public static <T> void asyncRead(InputStream inputStream, AnalysisEventListener<T> listener, Integer sheetNum, Integer headNum) {
EasyExcelFactory.read(inputStream, listener).sheet(sheetNum).headRowNumber(headNum).doRead();
}
/**
* 异步无模型读指定sheet和表头占的行数
* @param file
* @param listener 监听器在监听器中可以处理行数据LinkedHashMap表头数据异常处理等
* @param sheetNum sheet页号从0开始
* @param headNum 表头占的行数从0开始如果要连表头一起读出来则传0
*/
public static <T> void asyncRead(File file, AnalysisEventListener<T> listener, Integer sheetNum, Integer headNum) {
EasyExcelFactory.read(file, listener).sheet(sheetNum).headRowNumber(headNum).doRead();
}
/**
* 异步无模型读指定sheet和表头占的行数
* @param file
* @param listener 监听器在监听器中可以处理行数据LinkedHashMap表头数据异常处理等
* @param sheetNum sheet页号从0开始
* @param headNum 表头占的行数从0开始如果要连表头一起读出来则传0
* @return
*/
public static <T> void asyncRead(String file, AnalysisEventListener<T> listener, Integer sheetNum, Integer headNum) {
EasyExcelFactory.read(file, listener).sheet(sheetNum).headRowNumber(headNum).doRead();
}
//====================================================异步读取excel数据===============================================================
//====================================================将excel数据异步到JAVA模型属性里===============================================================
/**
* 异步按模型读取默认读取sheet0,不读取表头,从第2行开始读
* @param file
* @param listener 监听器在监听器中可以处理行数据LinkedHashMap表头数据异常处理等
* @param clazz 模型的类类型excel数据会按该类型转换成对象
*/
public static <T> void asyncReadModel(String file, AnalysisEventListener<T> listener, Class clazz) {
EasyExcelFactory.read(file, clazz, listener).sheet().doRead();
}
/**
* 异步按模型读取(默认表头占一行,不读取表头,从第2行开始读
* @param file
* @param listener 监听器在监听器中可以处理行数据LinkedHashMap表头数据异常处理等
* @param clazz 模型的类类型excel数据会按该类型转换成对象
* @param sheetNum sheet页号从0开始
*/
public static <T> void asyncReadModel(String file, AnalysisEventListener<T> listener, Class clazz, Integer sheetNum) {
EasyExcelFactory.read(file, clazz, listener).sheet(sheetNum).doRead();
}
/**
* 异步按模型读取
* @param file
* @param listener 监听器在监听器中可以处理行数据LinkedHashMap表头数据异常处理等
* @param clazz 模型的类类型excel数据会按该类型转换成对象
* @param sheetNum sheet页号从0开始
*/
public static <T> void asyncReadModel(File file, AnalysisEventListener<T> listener, Class clazz, Integer sheetNum) {
EasyExcelFactory.read(file, clazz, listener).sheet(sheetNum).doRead();
}
/**
* 异步按模型读取
* @param inputStream
* @param listener 监听器在监听器中可以处理行数据LinkedHashMap表头数据异常处理等
* @param clazz 模型的类类型excel数据会按该类型转换成对象
* @param sheetNum sheet页号从0开始
*/
public static <T> void asyncReadModel(InputStream inputStream, AnalysisEventListener<T> listener, Class clazz, Integer sheetNum) {
EasyExcelFactory.read(inputStream, clazz, listener).sheet(sheetNum).doRead();
}
//====================================================将excel数据异步到JAVA模型属性里===============================================================
//====================================================无JAVA模型写文件===============================================================
/**
* 无模板写文件
* @param file
* @param head 表头数据
* @param data 表内容数据
*/
public static void write(String file, List<List<String>> head, List<List<Object>> data) {
EasyExcel.write(file).head(head).sheet().doWrite(data);
}
/**
* 无模板写文件
* @param file
* @param head 表头数据
* @param data 表内容数据
* @param sheetNum sheet页号从0开始
* @param sheetName sheet名称
*/
public static void write(String file, List<List<String>> head, List<List<Object>> data, Integer sheetNum, String sheetName) {
EasyExcel.write(file).head(head).sheet(sheetNum, sheetName).doWrite(data);
}
//====================================================无JAVA模型写文件===============================================================
//====================================================有Excel模板写文件===============================================================
/**
* 根据excel模板文件写入文件可以实现向已有文件中添加数据的功能
* @param file
* @param template
* @param data
*/
public static <T> void writeTemplate(String file, String template, List<T> data) {
EasyExcel.write(file).withTemplate(template).sheet().doWrite(data);
}
/**
* 根据excel模板文件写入文件
* @param file
* @param template
* @param clazz
* @param data
*/
public static <T> void writeTemplate(String file, String template, Class clazz, List<T> data) {
EasyExcel.write(file, clazz).withTemplate(template).sheet().doWrite(data);
}
//====================================================无模板写文件===============================================================
//====================================================有模板写文件===============================================================
/**
* 按模板写文件
* @param file
* @param clazz 表头模板
* @param data 数据
*/
public static <T> void write(String file, Class clazz, List<T> data) {
EasyExcel.write(file, clazz).sheet().doWrite(data);
}
/**
* 按模板写文件
* @param file
* @param clazz 表头模板
* @param data 数据
* @param sheetNum sheet页号从0开始
* @param sheetName sheet名称
*/
public static <T> void write(String file, Class clazz, List<T> data, Integer sheetNum, String sheetName) {
EasyExcel.write(file, clazz).sheet(sheetNum, sheetName).doWrite(data);
}
/**
* 按模板写文件
* @param file
* @param clazz 表头模板
* @param data 数据
* @param writeHandler 自定义的处理器比如设置table样式设置超链接、单元格下拉框等等功能都可以通过这个实现需要注册多个则自己通过链式去调用
* @param sheetNum sheet页号从0开始
* @param sheetName sheet名称
*/
public static <T> void write(String file, Class clazz, List<T> data, WriteHandler writeHandler, Integer sheetNum, String sheetName) {
EasyExcel.write(file, clazz).registerWriteHandler(writeHandler).sheet(sheetNum, sheetName).doWrite(data);
}
/**
* 按模板写文件(包含某些字段)
* @param file
* @param clazz 表头模板
* @param data 数据
* @param includeCols 包含字段集合,根据字段名称显示
* @param sheetNum sheet页号从0开始
* @param sheetName sheet名称
*/
public static <T> void writeInclude(String file, Class clazz, List<T> data, Set<String> includeCols, Integer sheetNum, String sheetName) {
EasyExcel.write(file, clazz).includeColumnFiledNames(includeCols).sheet(sheetNum, sheetName).doWrite(data);
}
/**
* 按模板写文件(排除某些字段)
* @param file
* @param clazz 表头模板
* @param data 数据
* @param excludeCols 过滤排除的字段,根据字段名称过滤
* @param sheetNum sheet页号从0开始
* @param sheetName sheet名称
*/
public static <T> void writeExclude(String file, Class clazz, List<T> data, Set<String> excludeCols, Integer sheetNum, String sheetName) {
EasyExcel.write(file, clazz).excludeColumnFiledNames(excludeCols).sheet(sheetNum, sheetName).doWrite(data);
}
//------------------------------------------------------------------------------------------------
/**
* 多个sheet页的数据链式写入
*
* @param file
*/
public static EasyExcelWriteTool writeWithSheets(String file) {
return new EasyExcelWriteTool(file);
}
/**
* 多个sheet页的数据链式写入
*
* @param file
*/
public static EasyExcelWriteTool writeWithSheets(File file) {
return new EasyExcelWriteTool(file);
}
/**
* 多个sheet页的数据链式写入
*
* @param outputStream
*/
public static EasyExcelWriteTool writeWithSheets(OutputStream outputStream) {
return new EasyExcelWriteTool(outputStream);
}
/**
* 多个sheet页的数据链式写入失败了会返回一个有部分数据的Excel
*
* @param response
* @param exportFileName 导出的文件名称
*/
@SneakyThrows
public static EasyExcelWriteTool writeWithSheetsWeb(HttpServletResponse response, String exportFileName) throws IOException {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
// 这里URLEncoder.encode可以防止中文乱码
String fileName = URLEncoder.encode(exportFileName, "UTF-8");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
return new EasyExcelWriteTool(response.getOutputStream());
}
}

View File

@@ -0,0 +1,68 @@
package com.njcn.advance.utils;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import org.apache.poi.ss.formula.functions.T;
import java.io.File;
import java.io.OutputStream;
import java.util.List;
/**
* Description:
* Date: 2024/3/15 16:00【需求编号】
*
* @author clam
* @version V1.0.0
*/
public class EasyExcelWriteTool {
private int sheetNum;
private ExcelWriter excelWriter;
public EasyExcelWriteTool(OutputStream outputStream) {
excelWriter = EasyExcel.write(outputStream).build();
}
public EasyExcelWriteTool(File file) {
excelWriter = EasyExcel.write(file).build();
}
public EasyExcelWriteTool(String filePath) {
excelWriter = EasyExcel.write(filePath).build();
}
/**
* 链式模板表头写入
* @param clazz 表头格式
* @param data 数据 List<ExcelModel> 或者List<List<Object>>
* @return
*/
public <T> EasyExcelWriteTool writeModel(Class clazz, List<T> data, String sheetName) {
final WriteSheet writeSheet = EasyExcel.writerSheet(this.sheetNum++, sheetName).head(clazz).build();
excelWriter.write(data, writeSheet);
return this;
}
/**
* 链式自定义表头写入
* @param head
* @param data 数据 List<ExcelModel> 或者List<List<Object>>
* @param sheetName
* @return
*/
public EasyExcelWriteTool write(List<List<String>> head, List<T> data, String sheetName) {
final WriteSheet writeSheet = EasyExcel.writerSheet(this.sheetNum++, sheetName).head(head).build();
excelWriter.write(data, writeSheet);
return this;
}
/**
* 使用此类结束后,一定要关闭流
*/
public void finish() {
excelWriter.finish();
}
}