diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java index a615372862..d68ba40e01 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java @@ -22,6 +22,7 @@ import cn.afterturn.easypoi.excel.entity.ExportParams; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelReader; import com.alibaba.excel.read.metadata.ReadSheet; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -41,7 +42,6 @@ import com.epmet.commons.tools.redis.common.bean.GridInfoCache; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.CustomerGridConstant; -import com.epmet.constant.ImportErrorMsgConstants; import com.epmet.constants.ImportTaskConstants; import com.epmet.dao.CustomerGridDao; import com.epmet.dao.IcBuildingDao; @@ -50,7 +50,6 @@ import com.epmet.dao.IcPropertyManagementDao; import com.epmet.dto.*; import com.epmet.dto.form.ImportInfoFormDTO; import com.epmet.dto.form.ImportTaskCommonFormDTO; -import com.epmet.dto.result.ImportResultDTO; import com.epmet.dto.result.ImportTaskCommonResultDTO; import com.epmet.dto.result.InfoByNamesResultDTO; import com.epmet.dto.result.UploadImgResultDTO; @@ -62,7 +61,6 @@ import com.epmet.model.ImportNeighborHoodInfoListener; import com.epmet.model.NeighborHoodInfoModel; import com.epmet.redis.IcHouseRedis; import com.epmet.service.*; -import com.epmet.util.ExcelPoiUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; @@ -73,8 +71,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.http.entity.ContentType; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; @@ -85,6 +81,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.*; +import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; /** @@ -117,6 +114,8 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl page(Map params) { @@ -232,35 +231,42 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl importTask) throws IOException { -// importNeighbor(formDTO,file,importTask); - ExcelReader excelReader = null; - try { - InputStream inputStream = null; + public Result neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file,Result importTask) { + log.info("neighborhoodImport start====="); + executorService.submit(() -> { + // importNeighbor(formDTO,file,importTask); + log.info("neighborhoodImport thread start====="); + ExcelReader excelReader = null; try { - inputStream = file.getInputStream(); - } catch (IOException e) { - return new Result().error("读取文件失败"); - } + InputStream inputStream = null; + try { + inputStream = file.getInputStream(); + } catch (IOException e) { + throw new EpmetException("读取文件失败"); + } - excelReader = EasyExcel.read(inputStream).build(); - // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener - ReadSheet readSheet = EasyExcel.readSheet(0).head(NeighborHoodInfoModel.class) - .registerReadListener(new ImportNeighborHoodInfoListener(formDTO,icHouseRedis,icBuildingDao,this,propertyManagementDao,epmetCommonServiceOpenFeignClient,importTask.getData().getTaskId())) - .build(); - excelReader.read(readSheet); - } catch (Exception e){ - ImportTaskCommonFormDTO input = new ImportTaskCommonFormDTO(); - input.setOperatorId(formDTO.getUserId()); - input.setTaskId(importTask.getData().getTaskId()); - input.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); - epmetCommonServiceOpenFeignClient.finishImportTask(input); - } finally { - if (excelReader != null) { - excelReader.finish(); + excelReader = EasyExcel.read(inputStream).build(); + // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener + ReadSheet readSheet = EasyExcel.readSheet(0).head(NeighborHoodInfoModel.class) + .registerReadListener(new ImportNeighborHoodInfoListener(formDTO,icHouseRedis,icBuildingDao,this,propertyManagementDao,epmetCommonServiceOpenFeignClient,importTask.getData().getTaskId())) + .build(); + log.info("neighborhoodImport build readSheet num:{}",readSheet.getSheetNo()); + excelReader.read(readSheet); + } catch (Exception e){ + log.error("neighborhoodImport import exception", e); + ImportTaskCommonFormDTO input = new ImportTaskCommonFormDTO(); + input.setOperatorId(formDTO.getUserId()); + input.setTaskId(importTask.getData().getTaskId()); + input.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); + Result result = epmetCommonServiceOpenFeignClient.finishImportTask(input); + log.info("neighborhoodImport finishImportTask result:{}", JSON.toJSONString(result)); + } finally { + if (excelReader != null) { + excelReader.finish(); + } } - } + log.info("neighborhoodImport thread end====="); + }); return new Result<>(); }