Commit dc093fad authored by wangqiang's avatar wangqiang

添加:使用EasyExcel插件实现采购计划导入数据功能

parent 84248c81
...@@ -393,4 +393,12 @@ public class Constants { ...@@ -393,4 +393,12 @@ public class Constants {
* 外部技术联系单 * 外部技术联系单
*/ */
public static final String EXT_CONTACT = "ExtContactList"; public static final String EXT_CONTACT = "ExtContactList";
/**
* excel 操作符
*/
public static final String EXCEL_ADD = "新增";
public static final String EXCEL_DELETE = "删除";
public static final String EXCEL_UPDATE = "更新";
} }
...@@ -11,6 +11,7 @@ import lombok.EqualsAndHashCode; ...@@ -11,6 +11,7 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellType;
import java.io.File;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -19,10 +20,10 @@ import java.util.List; ...@@ -19,10 +20,10 @@ import java.util.List;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class ExtPuchasePlanExcelVO { public class ExtPuchasePlanExcelVO {
@ExcelProperty(value = {"采购计划","操作*"},index = 0) @ExcelProperty(value = {"采购计划","操作*"},index = 0)
@ColumnWidth(20) @ColumnWidth(20)
private String operation; private String operation;
...@@ -54,7 +55,7 @@ public class ExtPuchasePlanExcelVO { ...@@ -54,7 +55,7 @@ public class ExtPuchasePlanExcelVO {
*/ */
@ExcelProperty(value = {"采购计划","合同交付时间*"},index = 4) @ExcelProperty(value = {"采购计划","合同交付时间*"},index = 4)
@ColumnWidth(20) @ColumnWidth(20)
private String contractActualDeliveryTime; private LocalDateTime contractActualDeliveryTime;
/** /**
* 采购技术文件负责人 * 采购技术文件负责人
...@@ -85,6 +86,13 @@ public class ExtPuchasePlanExcelVO { ...@@ -85,6 +86,13 @@ public class ExtPuchasePlanExcelVO {
@ColumnWidth(20) @ColumnWidth(20)
private String secretCode; private String secretCode;
/**
* 计划编码
*/
@ExcelProperty(value = {"采购计划","计划编码*"},index = 0)
@ColumnWidth(20)
private String planCode;
/** /**
* 备注 * 备注
...@@ -105,6 +113,7 @@ public class ExtPuchasePlanExcelVO { ...@@ -105,6 +113,7 @@ public class ExtPuchasePlanExcelVO {
EasyExcel.write( EasyExcel.write(
"F:\\yangyi\\项目\\清华核研院\\核研院设计文档及原型\\采购计划导入模板.xlsx", ExtPuchasePlanExcelVO.class) "F:\\yangyi\\项目\\清华核研院\\核研院设计文档及原型\\采购计划导入模板.xlsx", ExtPuchasePlanExcelVO.class)
.sheet("采购计划").doWrite(list); .sheet("采购计划").doWrite(list);
} }
} }
......
package com.yonde.dcs.plan.common.listener; package com.yonde.dcs.plan.core.listener;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.util.ListUtils; import com.alibaba.excel.util.ListUtils;
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.common.vo.ExtPuchasePlanExcelVO;
import com.yonde.dcs.plan.core.service.ExtDistributeRecordService;
import com.yonde.dex.basedata.entity.data.OperatorType;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
@Component
@Slf4j @Slf4j
public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchasePlanExcelVO> { public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchasePlanExcelVO> {
@Autowired
private ExtDistributeRecordService extDistributeRecordService;
/** /**
* 每隔100条处理下,然后清理list ,方便内存回收 * 每隔100条处理下,然后清理list ,方便内存回收
*/ */
...@@ -25,15 +34,22 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase ...@@ -25,15 +34,22 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
@Override @Override
public void invoke(ExtPuchasePlanExcelVO extPuchasePlanExcelVO, AnalysisContext analysisContext) { public void invoke(ExtPuchasePlanExcelVO extPuchasePlanExcelVO, AnalysisContext analysisContext) {
ExtPuchasePlanAttributeVO extPuchasePlanAttributeVO = new ExtPuchasePlanAttributeVO();
log.info("解析到一条数据:{}", extPuchasePlanExcelVO); log.info("解析到一条数据:{}", extPuchasePlanExcelVO);
cachedDataList.add(extPuchasePlanExcelVO);
if (cachedDataList.size() >= BATCH_COUNT) {
// 处理缓存的数据,比如说入库。。。
// 然后清空
//todo 需要处理采购计划数据到数据库 //todo 需要处理采购计划数据到数据库
cachedDataList.clear(); //根据excle中操作符执行 新增、更新、删除
if(Constants.EXCEL_ADD.equals(extPuchasePlanExcelVO.getOperation())){
extPuchasePlanAttributeVO.setOperator(OperatorType.ADD);
extDistributeRecordService.saveRecursion(transformObject(extPuchasePlanAttributeVO,extPuchasePlanExcelVO));
}else if (Constants.EXCEL_UPDATE.equals(extPuchasePlanExcelVO.getOperation())){
extPuchasePlanAttributeVO.setOperator(OperatorType.MODIFY);
}else if (Constants.EXCEL_DELETE.equals(extPuchasePlanExcelVO.getOperation())){
extPuchasePlanAttributeVO.setOperator(OperatorType.REMOVE);
}else{
log.info("sheet={} ,操作符={}无效!", analysisContext.readSheetHolder().getSheetName(),extPuchasePlanExcelVO.getOperation());
} }
} }
@Override @Override
...@@ -54,9 +70,23 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase ...@@ -54,9 +70,23 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
throw exception; throw exception;
} }
//todo wq测试代码 /**
// public static void main(String[] args) { * 将excel中的数据转换成VO对象
// String fileName = "F:\\yangyi\\项目\\清华核研院\\核研院设计文档及原型\\采购计划导入模板.xlsx"; * @param extPuchasePlanAttributeVO
// EasyExcel.read(fileName, ExtPuchasePlanExcelVO.class, new PurchasePlanExcelListenner()).sheet().doRead(); * @param extPuchasePlanExcelVO
// } */
public ExtPuchasePlanAttributeVO transformObject(ExtPuchasePlanAttributeVO extPuchasePlanAttributeVO,ExtPuchasePlanExcelVO extPuchasePlanExcelVO){
extPuchasePlanAttributeVO.setOutsourceProjectName(extPuchasePlanExcelVO.getOutsourceProjectName());
extPuchasePlanAttributeVO.setPurDesignFileSubmitTime(extPuchasePlanExcelVO.getPurDesignFileSubmitTime());
extPuchasePlanAttributeVO.setContractSigningTime(extPuchasePlanExcelVO.getContractActualSigningTime());
extPuchasePlanAttributeVO.setContractDeliveryTime(extPuchasePlanExcelVO.getContractActualDeliveryTime());
extPuchasePlanAttributeVO.setPurDesignFileManager(extPuchasePlanExcelVO.getPurDesignFileManager());
extPuchasePlanAttributeVO.setPurchaseBudget(extPuchasePlanExcelVO.getPurchaseBudget());
extPuchasePlanAttributeVO.setSecretCode(extPuchasePlanExcelVO.getSecretCode());
extPuchasePlanAttributeVO.setPlanCode(extPuchasePlanExcelVO.getPlanCode());
extPuchasePlanAttributeVO.setNote(extPuchasePlanExcelVO.getNote());
//todo wq:excel中的项目代号对应项目属性中什么?
return extPuchasePlanAttributeVO;
}
} }
...@@ -2,6 +2,9 @@ package com.yonde.dcs.plan.core.service; ...@@ -2,6 +2,9 @@ package com.yonde.dcs.plan.core.service;
import com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO; import com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO;
import com.yonde.dcs.plan.core.service.shadow.ExtPuchasePlanAttributeServiceShadow; import com.yonde.dcs.plan.core.service.shadow.ExtPuchasePlanAttributeServiceShadow;
import java.io.File;
/** /**
* @description: ExtPuchasePlanAttribute-service * @description: ExtPuchasePlanAttribute-service
* @author: dexadmin * @author: dexadmin
...@@ -10,4 +13,6 @@ import com.yonde.dcs.plan.core.service.shadow.ExtPuchasePlanAttributeServiceShad ...@@ -10,4 +13,6 @@ import com.yonde.dcs.plan.core.service.shadow.ExtPuchasePlanAttributeServiceShad
**/ **/
public interface ExtPuchasePlanAttributeService<V extends ExtPuchasePlanAttributeVO> extends ExtPuchasePlanAttributeServiceShadow<V> { public interface ExtPuchasePlanAttributeService<V extends ExtPuchasePlanAttributeVO> extends ExtPuchasePlanAttributeServiceShadow<V> {
public String ExportPurchasePlan(File file);
} }
...@@ -2,6 +2,8 @@ package com.yonde.dcs.plan.core.service.impl; ...@@ -2,6 +2,8 @@ package com.yonde.dcs.plan.core.service.impl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import java.io.File;
import java.util.List; import java.util.List;
import com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO; import com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
...@@ -29,6 +31,11 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut ...@@ -29,6 +31,11 @@ public class ExtPuchasePlanAttributeServiceImpl<V extends ExtPuchasePlanAttribut
@Autowired @Autowired
ExtPuchasePlanAttributeRepository<ExtPuchasePlanAttribute> extPuchasePlanAttributeRepository; ExtPuchasePlanAttributeRepository<ExtPuchasePlanAttribute> extPuchasePlanAttributeRepository;
@Override
public String ExportPurchasePlan(File file) {
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