13 changed files with 211 additions and 39 deletions
@ -0,0 +1,52 @@ |
|||||
|
package com.easy.admin.modules.huzhou.listener; |
||||
|
|
||||
|
import com.alibaba.excel.context.AnalysisContext; |
||||
|
import com.alibaba.excel.read.listener.ReadListener; |
||||
|
import com.easy.admin.modules.huzhou.entity.HuzhouPlaninfo; |
||||
|
import com.easy.admin.modules.huzhou.service.IHuzhouPlaninfoService; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
|
||||
|
/** |
||||
|
* 自定义监听器读数据 |
||||
|
* |
||||
|
* @author gjh |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
public class ProjectPlanListener implements ReadListener<HuzhouPlaninfo> { |
||||
|
|
||||
|
@Autowired |
||||
|
private IHuzhouPlaninfoService planInfoService; |
||||
|
|
||||
|
private final String projectId; |
||||
|
|
||||
|
|
||||
|
public ProjectPlanListener(IHuzhouPlaninfoService planInfoService, String projectId) { |
||||
|
this.planInfoService = planInfoService; |
||||
|
this.projectId = projectId; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 每读一行数据都会调用这个方法 |
||||
|
* |
||||
|
* @param planInfo |
||||
|
* @param analysisContext |
||||
|
*/ |
||||
|
@Override |
||||
|
public void invoke(HuzhouPlaninfo planInfo, AnalysisContext analysisContext) { |
||||
|
planInfo.setProjectId(projectId); |
||||
|
planInfoService.save(planInfo); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 读完整个excel之后再调用这个方法 |
||||
|
* |
||||
|
* @param analysisContext |
||||
|
*/ |
||||
|
@Override |
||||
|
public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
||||
|
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue