| | |
| | | package com.panzhihua.common.listen; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.alibaba.excel.exception.ExcelDataConvertException; |
| | |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.ComCvtServeExcelVO; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @description: 便民服务导入监听 |
| | |
| | | @Slf4j |
| | | public class ComCvtServeExcelListen extends AnalysisEventListener<ComCvtServeExcelVO> { |
| | | |
| | | private static final int BATCH_COUNT = 5000; |
| | | private CommunityService communityService; |
| | | |
| | | private Long communityId; |
| | | |
| | | private List<ComCvtServeExcelVO> list = new ArrayList<>(); |
| | | public ComCvtServeExcelListen(CommunityService communityService, Long communityId) { |
| | | this.communityService = communityService; |
| | | this.communityId = communityId; |
| | | } |
| | | |
| | | |
| | | private static final int BATCH_COUNT = 5000; |
| | | private List<ComCvtServeExcelVO> list = new ArrayList<>(); |
| | | |
| | | @Override |
| | | public void invoke(ComCvtServeExcelVO comCvtServeExcelVO, AnalysisContext analysisContext) { |
| | |
| | | if (!R.isOk(r)) { |
| | | throw new ServiceException(r.getMsg()); |
| | | } |
| | | //清空list |
| | | // 清空list |
| | | list.clear(); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
| | | log.info("excel导入数据【{}】", JSONObject.toJSONString(list)); |
| | | R r = this.communityService.listSaveConvenientServeExcelVO(list, this.communityId);//确保最后遗留的数据保存在数据库中 |
| | | R r = this.communityService.listSaveConvenientServeExcelVO(list, this.communityId);// 确保最后遗留的数据保存在数据库中 |
| | | if (!R.isOk(r)) { |
| | | throw new ServiceException(r.getMsg()); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 在转换异常 |
| | | * |
| | | * @param exception |
| | | * @param context |
| | | * @throws Exception |
| | |
| | | if (exception instanceof ExcelDataConvertException) { |
| | | ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception; |
| | | log.error("第{}行,第{}列解析异常,数据为:{}", excelDataConvertException.getRowIndex(), |
| | | excelDataConvertException.getColumnIndex(), excelDataConvertException.getCellData()); |
| | | }else{ |
| | | excelDataConvertException.getColumnIndex(), excelDataConvertException.getCellData()); |
| | | } else { |
| | | throw new ServiceException(exception.getMessage()); |
| | | } |
| | | } |