From 2a64b537e8e3bce9ce030585a3da17d48379c0ad Mon Sep 17 00:00:00 2001 From: sfd <sun.sunshine@163.com> Date: 星期一, 26 五月 2025 15:04:45 +0800 Subject: [PATCH] 修改json类型转换错误 --- aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelineMoServiceImpl.java | 64 +++++++------------------------ 1 files changed, 15 insertions(+), 49 deletions(-) diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelineMoServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelineMoServiceImpl.java index 41d23c6..b326ae6 100644 --- a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelineMoServiceImpl.java +++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelineMoServiceImpl.java @@ -2,25 +2,18 @@ import cn.hutool.core.util.IdUtil; import com.aps.common.core.utils.DateUtils; +import com.aps.common.core.utils.poi.ExcelUtil; +import com.aps.common.security.utils.DictUtils; import com.aps.common.security.utils.SecurityUtils; import com.aps.core.domain.ApsGasPipelineMo; import com.aps.core.mapper.ApsGasPipelineMoMapper; import com.aps.core.service.IApsGasPipelineMoService; -import io.micrometer.common.util.StringUtils; import lombok.SneakyThrows; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.usermodel.WorkbookFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Date; import java.util.List; /** @@ -108,48 +101,21 @@ @Transactional(rollbackFor = Exception.class) @Override public int batchInsertGasPipelineMo(MultipartFile file) { - Workbook workbook = WorkbookFactory.create(file.getInputStream()); - Sheet sheet = workbook.getSheetAt(0); - int rows = sheet.getLastRowNum(); - if (rows > 0) { - List<ApsGasPipelineMo> list = new ArrayList<>(); + ExcelUtil<ApsGasPipelineMo> util = new ExcelUtil<>(ApsGasPipelineMo.class); + List<ApsGasPipelineMo> tempList = util.importExcel(file.getInputStream()); + DictUtils.CacheValue cacheValue = DictUtils.getCacheValue("aps_factory"); + tempList.forEach(apsGasPipelineMo -> { + apsGasPipelineMo.setId(IdUtil.getSnowflakeNextId()); + apsGasPipelineMo.setFactory(cacheValue.get(apsGasPipelineMo.getFactory())); + apsGasPipelineMo.setCreateBy(SecurityUtils.getUsername()); + apsGasPipelineMo.setCreateTime(DateUtils.getNowDate()); + }); - /*鏁版嵁鍒椾粠1寮�濮�*/ - for (int i = 1; i <= rows; i++) { - Row row = sheet.getRow(i); - if (row.getCell(0) == null){ - continue; - } - String mo = row.getCell(0).getStringCellValue(); - if (StringUtils.isEmpty(mo)){ - continue; - } - String factory = row.getCell(1).getStringCellValue(); - String materialNum = row.getCell(2).getStringCellValue(); - double quantity = row.getCell(3).getNumericCellValue(); - Date planEnd = row.getCell(4).getDateCellValue(); - if (StringUtils.isNotBlank(factory) && - StringUtils.isNotBlank(materialNum) && - planEnd != null) { - ApsGasPipelineMo apsGasPipelineMo = new ApsGasPipelineMo(); - apsGasPipelineMo.setMo(mo); - apsGasPipelineMo.setId(IdUtil.getSnowflakeNextId()); - apsGasPipelineMo.setFactory(factory); - apsGasPipelineMo.setCreateBy(SecurityUtils.getUsername()); - apsGasPipelineMo.setCreateTime(DateUtils.getNowDate()); - apsGasPipelineMo.setQuantity(new BigDecimal(quantity)); - apsGasPipelineMo.setPlanEnd(new Timestamp(planEnd.getTime())); - list.add(apsGasPipelineMo); - } - } - if (!list.isEmpty()) { - apsGasPipelineMoMapper.deleteAll(); - apsGasPipelineMoMapper.insert(list); - } - return list.size(); + if (!tempList.isEmpty()) { + apsGasPipelineMoMapper.deleteAll(); + apsGasPipelineMoMapper.insert(tempList); } - return 0; - + return tempList.size(); } } -- Gitblit v1.9.3