Commit de1267a6 authored by wangqiang's avatar wangqiang

添加:使用EasyExcel插件创建IED excelvo

parent dc093fad
package com.yonde.dcs.plan.common.vo;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import lombok.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@EqualsAndHashCode(callSuper = false)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExtIEDPlanExcelVO {
@ExcelProperty(value = {"IED计划","操作*"},index = 0)
@ColumnWidth(15)
private String operation;
/**
* 文件类型
*/
@ExcelProperty(value = {"IED计划","文件类型*"},index = 1)
@ColumnWidth(15)
private Integer fileType;
/**
* 文件分类
*/
@ExcelProperty(value = {"IED计划","文件分类*"},index = 2)
@ColumnWidth(15)
private Integer fileClassify;
/**
* 文件编号
*/
@ExcelProperty(value = {"IED计划","文件编号*"},index = 3)
@ColumnWidth(15)
private String fileNumber;
/**
* 文件代号
*/
@ExcelProperty(value = {"IED计划","文件代号*"},index = 4)
@ColumnWidth(15)
private String fileCode;
/**
* 管理员系统编码
*/
@ExcelProperty(value = {"IED计划","管理员系统编码*"},index = 5)
@ColumnWidth(15)
private String systemNumber;
/**
* 设备编号
*/
@ExcelProperty(value = {"IED计划","设备编号*"},index = 6)
@ColumnWidth(15)
private String deviceNumber;
/**
* 阶段
*/
@ExcelProperty(value = {"IED计划","阶段*"},index = 7)
@ColumnWidth(15)
private String phase;
/**
* 节点审核时间
*/
@ExcelProperty(value = {"IED计划","节点审核时间*"},index = 8)
@ColumnWidth(15)
private LocalDateTime auditTime;
/**
* 文件提交时间
*/
@ExcelProperty(value = {"IED计划","文件提交时间*"},index = 9)
@ColumnWidth(15)
private LocalDateTime fileSubmitTimee;
/**
* 编写者
*/
@ExcelProperty(value = {"IED计划","编写*"},index = 10)
@ColumnWidth(15)
private String editor;
/**
* 校核者
*/
@ExcelProperty(value = {"IED计划","校核*"},index = 11)
@ColumnWidth(15)
private String checker;
/**
* 审核者
*/
@ExcelProperty(value = {"IED计划","审核*"},index = 12)
@ColumnWidth(15)
private String auditor;
/**
* 审定者
*/
@ExcelProperty(value = {"IED计划","审定*"},index = 13)
@ColumnWidth(15)
private String investigator;
/**
* 批准者
*/
@ExcelProperty(value = {"IED计划","批准*"},index = 14)
@ColumnWidth(15)
private String ratifier;
/**
* 备注
*/
@ExcelProperty(value = {"IED计划","备注*"},index = 15)
@ColumnWidth(15)
private String note;
/**
* 密级
*/
@ExcelProperty(value = {"IED计划","密级*"},index = 16)
@ColumnWidth(15)
private String secretCode;
public static void main(String[] args) {
List<ExtIEDPlanExcelVO> list = new ArrayList<>();
for (int i=0;i<=1;i++){
ExtIEDPlanExcelVO extIEDPlanExcelVO = new ExtIEDPlanExcelVO();
extIEDPlanExcelVO.setNote("测试"+i);
list.add(extIEDPlanExcelVO);
}
EasyExcel.write(
"F:\\yangyi\\项目\\清华核研院\\核研院设计文档及原型\\IED计划导入模板22.xlsx", ExtIEDPlanExcelVO.class)
.sheet("采购计划").doWrite(list);
}
}
package com.yonde.dcs.plan.core.listener;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.util.ListUtils;
import com.yonde.dcs.plan.common.constants.Constants;
import com.yonde.dcs.plan.common.vo.ExtIDEPlanVO;
import com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO;
import com.yonde.dcs.plan.common.vo.ExtPuchasePlanExcelVO;
import com.yonde.dcs.plan.core.service.ExtDistributeRecordService;
import com.yonde.dcs.plan.core.service.ExtIDEPlanService;
import com.yonde.dex.basedata.entity.data.OperatorType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@Slf4j
public class IEDPlanExcelListenner extends AnalysisEventListener<ExtIDEPlanVO> {
@Autowired
private ExtIDEPlanService extIDEPlanService;
/**
* 每隔100条处理下,然后清理list ,方便内存回收
*/
private static final int BATCH_COUNT = 100;
/**
* 缓存的数据
*/
private List<ExtPuchasePlanExcelVO> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
@Override
public void invoke(ExtIDEPlanVO extIDEPlanVO, AnalysisContext analysisContext) {
log.info("解析到一条数据:{}", extIDEPlanVO);
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
// 收尾工作,处理剩下的缓存数据。。。
log.info("sheet={} 所有数据解析完成!", analysisContext.readSheetHolder().getSheetName());
}
/**
*
* @param exception
* @param context
* @throws Exception
*/
@Override
public void onException(Exception exception, AnalysisContext context) throws Exception {
log.error("======>>>解析异常:", exception);
throw exception;
}
}
......@@ -7,8 +7,10 @@ import com.yonde.dcs.plan.common.constants.Constants;
import com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO;
import com.yonde.dcs.plan.common.vo.ExtPuchasePlanExcelVO;
import com.yonde.dcs.plan.core.service.ExtDistributeRecordService;
import com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService;
import com.yonde.dex.basedata.entity.data.OperatorType;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -19,7 +21,7 @@ import java.util.List;
public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchasePlanExcelVO> {
@Autowired
private ExtDistributeRecordService extDistributeRecordService;
private ExtPuchasePlanAttributeService extPuchasePlanAttributeService;
/**
* 每隔100条处理下,然后清理list ,方便内存回收
......@@ -40,7 +42,7 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
//根据excle中操作符执行 新增、更新、删除
if(Constants.EXCEL_ADD.equals(extPuchasePlanExcelVO.getOperation())){
extPuchasePlanAttributeVO.setOperator(OperatorType.ADD);
extDistributeRecordService.saveRecursion(transformObject(extPuchasePlanAttributeVO,extPuchasePlanExcelVO));
extPuchasePlanAttributeService.saveRecursion(transformObject(extPuchasePlanAttributeVO,extPuchasePlanExcelVO));
}else if (Constants.EXCEL_UPDATE.equals(extPuchasePlanExcelVO.getOperation())){
extPuchasePlanAttributeVO.setOperator(OperatorType.MODIFY);
......@@ -89,4 +91,14 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
return extPuchasePlanAttributeVO;
}
/**
* 检查采购计划数据的合法性
* @param extPuchasePlanExcelVO
* @return
*/
public StringBuffer checkPurchasePlanExcelData(ExtPuchasePlanExcelVO extPuchasePlanExcelVO){
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment