This commit is contained in:
parent
7350061d49
commit
6b33a25627
|
|
@ -2,6 +2,7 @@ package com.nflg.qms.admin.controller;
|
|||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.wms.common.constant.STATE;
|
||||
import com.nflg.wms.common.exception.NflgException;
|
||||
import com.nflg.wms.common.pojo.ApiResult;
|
||||
|
|
@ -28,9 +29,12 @@ import org.springframework.web.bind.annotation.*;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.ttzero.excel.entity.ListSheet;
|
||||
import org.ttzero.excel.entity.Workbook;
|
||||
import org.ttzero.excel.reader.Drawings;
|
||||
import org.ttzero.excel.reader.ExcelReader;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
|
@ -175,12 +179,39 @@ public class QmsInspectionItemController extends BaseController {
|
|||
*/
|
||||
@Transactional
|
||||
@PostMapping("import")
|
||||
public ApiResult<String> importFromExcel(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
public ApiResult<String> importFromExcel(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
List<QmsInspectionItemImportDTO> data = EecExcelUtil.getExcelContext(file.getInputStream(), QmsInspectionItemImportDTO.class);
|
||||
if (CollectionUtil.isEmpty(data)) {
|
||||
throw new NflgException(STATE.BusinessError, "导入文件内容为空");
|
||||
}
|
||||
|
||||
|
||||
// 2. 读取 Excel 里的所有图片(EEC 标准方式)
|
||||
List<Drawings.Picture> pictures = new ExcelReader(file.getInputStream()).listPictures();
|
||||
|
||||
// 3. 遍历 DTO,遇到 DISPIMG 就上传图片并替换地址
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
QmsInspectionItemImportDTO dto = data.get(i);
|
||||
String legend = dto.getLegend();
|
||||
|
||||
// 如果是图片公式,就取图片上传,把地址填回去
|
||||
if (StrUtil.isNotBlank(legend) && legend.startsWith("=DISPIMG(")) {
|
||||
if (i < pictures.size()) {
|
||||
Drawings.Picture pic = pictures.get(i);
|
||||
FileInputStream fis = new FileInputStream(pic.getLocalPath().toFile());
|
||||
// 上传图片 → 获取地址
|
||||
String imageUrl = fileUploadService.upload(
|
||||
"image/" + IdUtil.fastUUID() + ".png",
|
||||
fis,
|
||||
"image/png"
|
||||
);
|
||||
dto.setLegend(imageUrl); // 把地址塞回去
|
||||
} else {
|
||||
dto.setLegend(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 校验必填字段
|
||||
boolean hasError = false;
|
||||
for (QmsInspectionItemImportDTO dto : data) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue