|
|
@ -3,6 +3,8 @@ package org.nl.wms.database.material.service.impl; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.poi.excel.ExcelReader; |
|
|
|
import cn.hutool.poi.excel.ExcelUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
@ -19,7 +21,11 @@ import org.nl.wms.database.material.service.dto.MdBaseMaterialQuery; |
|
|
|
import org.nl.wms.ext.mes.service.dao.mapper.MesRequestMapper; |
|
|
|
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 javax.servlet.http.HttpServletRequest; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
@ -117,4 +123,26 @@ public class MdBaseMaterialServiceImpl extends ServiceImpl<MdBaseMaterialMapper, |
|
|
|
return pages; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void excelImport(MultipartFile file, HttpServletRequest request) { |
|
|
|
if (file.isEmpty()) { |
|
|
|
throw new BadRequestException("文件为空,请添加数据后重新导入"); |
|
|
|
} |
|
|
|
// 1.获取上传文件输入流
|
|
|
|
InputStream inputStream = null; |
|
|
|
try { |
|
|
|
inputStream = file.getInputStream(); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
// 调用用 hutool 方法读取数据 默认调用第一个sheet
|
|
|
|
ExcelReader excelReader = ExcelUtil.getReader(inputStream); |
|
|
|
// 从第二行开始获取数据 excelReader.read的结果是一个2纬的list,外层是行,内层是行对应的所有列
|
|
|
|
List<List<Object>> read = excelReader.read(1, excelReader.getRowCount()); |
|
|
|
// 循环获取的数据
|
|
|
|
for (int i = 0; i < read.size(); i++) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|