huanghongfa
2021-09-02 177249c76aeea0b4bf8d8816d4994e3b445b45ce
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComCvtServeExcelListen.java
@@ -1,5 +1,8 @@
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;
@@ -8,10 +11,8 @@
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: 便民服务导入监听
@@ -21,18 +22,14 @@
@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) {
@@ -44,7 +41,7 @@
            if (!R.isOk(r)) {
                throw new ServiceException(r.getMsg());
            }
            //清空list
            // 清空list
            list.clear();
        }
@@ -53,15 +50,15 @@
    @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
@@ -72,8 +69,8 @@
        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());
        }
    }