From a81a164ed0e6207228333a149308f5be5f2878e3 Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Wed, 22 May 2024 10:23:41 +0800 Subject: [PATCH] =?UTF-8?q?add:=E7=89=A9=E6=96=99=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MdBaseMaterialController.java | 9 ++++++ .../wms/ext/mes/service/WmsToMesService.java | 4 +++ .../mes/service/impl/WmsToMesServiceImpl.java | 31 +++++++++++++++++++ .../src/views/wms/basedata/material/index.vue | 27 +++++++++++++--- .../wms/basedata/material/mdBaseMaterial.js | 10 +++++- 5 files changed, 75 insertions(+), 6 deletions(-) diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/database/material/controller/MdBaseMaterialController.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/database/material/controller/MdBaseMaterialController.java index 5aa9026..e8656c7 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/database/material/controller/MdBaseMaterialController.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/database/material/controller/MdBaseMaterialController.java @@ -14,7 +14,9 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import java.util.Map; import java.util.Set; @@ -73,4 +75,11 @@ public class MdBaseMaterialController { wmsToMesService.synchronizeMaterialInfo(); return new ResponseEntity<>(HttpStatus.OK); } + + @PostMapping("/excelImport") + @Log("excel导入") + public ResponseEntity excelImport(@RequestParam("file") MultipartFile file, HttpServletRequest request) { + wmsToMesService.excelImport(file, request); + return new ResponseEntity<>(HttpStatus.OK); + } } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/WmsToMesService.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/WmsToMesService.java index 65412f3..4e2bb45 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/WmsToMesService.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/WmsToMesService.java @@ -6,7 +6,9 @@ import org.nl.wms.database.brick.service.dao.MdBaseBrickInfo; import org.nl.wms.ext.mes.service.dto.*; import org.nl.wms.pdm.workorder.service.dao.PdmBdWorkorder; import org.nl.wms.sch.group.service.dao.SchBaseVehiclematerialgroup; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import java.util.List; /** @@ -193,4 +195,6 @@ public interface WmsToMesService { * @param entity */ void addScrap(ScrapDto entity); + + void excelImport(MultipartFile file, HttpServletRequest request); } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/impl/WmsToMesServiceImpl.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/impl/WmsToMesServiceImpl.java index b04d076..fdeeb2c 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/impl/WmsToMesServiceImpl.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/impl/WmsToMesServiceImpl.java @@ -3,13 +3,18 @@ package org.nl.wms.ext.mes.service.impl; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.poi.excel.ExcelReader; +import cn.hutool.poi.excel.ExcelUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.extern.slf4j.Slf4j; import org.nl.common.domain.query.PageQuery; import org.nl.common.exception.BadRequestException; +import org.nl.common.utils.SecurityUtils; import org.nl.system.service.notice.ISysNoticeService; import org.nl.wms.database.brick.service.dao.MdBaseBrickInfo; import org.nl.wms.database.material.service.IMdBaseMaterialService; @@ -31,7 +36,11 @@ import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; 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.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -510,6 +519,28 @@ public class WmsToMesServiceImpl implements WmsToMesService { mesRequestMapper.reportSemiProductGXPF(semiProductGXPFDo); } + @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> read = excelReader.read(1, excelReader.getRowCount()); + // 循环获取的数据 + for (int i = 0; i < read.size(); i++) { + } + } + /** * 转换 * diff --git a/lms/nladmin-ui/src/views/wms/basedata/material/index.vue b/lms/nladmin-ui/src/views/wms/basedata/material/index.vue index f393c9b..3d1852f 100644 --- a/lms/nladmin-ui/src/views/wms/basedata/material/index.vue +++ b/lms/nladmin-ui/src/views/wms/basedata/material/index.vue @@ -48,15 +48,25 @@ + + + + + + + + + + - 同步 + 导入 @@ -202,6 +212,7 @@ + @@ -214,6 +225,8 @@ import rrOperation from '@crud/RR.operation' import crudOperation from '@crud/CRUD.operation' import udOperation from '@crud/UD.operation' import pagination from '@crud/Pagination' +import UploadDialog from './UploadDialog' + const defaultForm = { material_id: null, @@ -240,7 +253,7 @@ const defaultForm = { export default { name: 'MdBaseMaterial', dicts: ['vehicle_type'], - components: { pagination, crudOperation, rrOperation, udOperation, Treeselect }, + components: { pagination, crudOperation, rrOperation, udOperation, Treeselect, UploadDialog }, mixins: [presenter(), header(), form(defaultForm), crud()], cruds() { return CRUD({ @@ -258,6 +271,7 @@ export default { }, rules: { }, + uploadShow: false, fullscreenLoading: false, workShopList: [] } @@ -284,6 +298,9 @@ export default { this.workShopList = res }) }, + tableChanged3() { + this.crud.toQuery() + }, // 获取子节点数据 loadChildNodes({ action, parentNode, callback }) { // if (action === LOAD_CHILDREN_OPTIONS) { diff --git a/lms/nladmin-ui/src/views/wms/basedata/material/mdBaseMaterial.js b/lms/nladmin-ui/src/views/wms/basedata/material/mdBaseMaterial.js index aab7d60..4961c1d 100644 --- a/lms/nladmin-ui/src/views/wms/basedata/material/mdBaseMaterial.js +++ b/lms/nladmin-ui/src/views/wms/basedata/material/mdBaseMaterial.js @@ -32,4 +32,12 @@ export function synchronize(data) { }) } -export default { add, edit, del, synchronize } +export function excelImport(data) { + return request({ + url: 'api/mdBaseMaterial/excelImport', + method: 'post', + data + }) +} + +export default { add, edit, del, synchronize, excelImport }