diff --git a/acs/nladmin-system/pom.xml b/acs/nladmin-system/pom.xml index 5a6aee2..2095112 100644 --- a/acs/nladmin-system/pom.xml +++ b/acs/nladmin-system/pom.xml @@ -331,12 +331,17 @@ org.apache.poi poi - 3.17 + 4.1.2 org.apache.poi poi-ooxml - 3.17 + 4.1.2 + + + org.apache.poi + poi-ooxml-schemas + 4.1.2 xerces diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java index d477e95..3ac1e92 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java @@ -22,7 +22,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; @@ -118,6 +120,18 @@ public class DeviceController { return new ResponseEntity<>(deviceService.selectList(), HttpStatus.OK); } + + @PostMapping("/excelImport") + @Log("excel导入") + @ApiOperation("excel导入") + public ResponseEntity excelImport(@RequestParam("file") MultipartFile file, HttpServletRequest request) { + deviceService.excelImport(file, request); + return new ResponseEntity<>(HttpStatus.OK); + } + + + + @GetMapping("/region/{region}") @Log("根据区域查询设备") @ApiOperation("根据区域查询设备") diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java index 9083210..60d23f6 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java @@ -9,7 +9,9 @@ import org.nl.acs.device.service.dto.DeviceDto; import org.nl.acs.device.service.dto.StorageCellDto; import org.nl.acs.opc.Device; import org.springframework.data.domain.Pageable; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; @@ -118,6 +120,13 @@ public interface DeviceService { */ JSONArray selectList(); + /** + * excel导入 + * @param file + * @param request + */ + void excelImport(MultipartFile file, HttpServletRequest request); + /** * 前端输送设备下拉选列表 * diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java index 1bfa2f1..5ef5f0f 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java @@ -7,6 +7,8 @@ import cn.hutool.core.map.MapUtil; 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.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -43,9 +45,12 @@ import org.slf4j.LoggerFactory; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.InputStream; import java.util.*; /** @@ -335,6 +340,74 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial return result; } + @Override + @Transactional(rollbackFor = Exception.class) + public void excelImport(MultipartFile file, HttpServletRequest request) { + if (file.isEmpty()) { + throw new BadRequestException("文件为空,请添加数据后重新导入"); + } + Long currentUserId = SecurityUtils.getCurrentUserId(); + String nickName = SecurityUtils.getCurrentNickName(); + String now = DateUtil.now(); + // 1.获取上传文件输入流 + InputStream inputStream = null; + try { + inputStream = file.getInputStream(); + } catch (Exception e) { + e.printStackTrace(); + } + WQLObject wo = WQLObject.getWQLObject("acs_device"); + + // 调用用 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++) { + List list = read.get(i); + JSONObject param = new JSONObject(); + String device_code = list.get(0).toString(); + String device_name = list.get(1).toString(); + String device_type = list.get(2).toString(); + String is_config = list.get(3).toString(); + String is_route = list.get(4).toString(); + String region = list.get(5).toString(); + if (StrUtil.isEmpty(device_code)) { + throw new BadRequestException("设备编号为空!"); + } + if (StrUtil.isEmpty(device_name)) { + device_name = device_code; + } + if (StrUtil.isEmpty(device_type)) { + device_type = "conveyor"; + } + if (StrUtil.isEmpty(is_config)) { + is_config = "FALSE"; + } + if (StrUtil.isEmpty(is_route)) { + is_route = "false"; + } + DeviceDto dto = this.findByCode(device_code); + if (ObjectUtil.isNotEmpty(dto)) { + continue; + } + //按照列获取 + param.put("device_id", IdUtil.getSnowflake(1, 1).nextId()); + param.put("device_code", device_code); + param.put("device_name", device_name); + param.put("device_type", device_type); + param.put("is_config", is_config); + param.put("is_route", is_route); + param.put("create_by", nickName); + param.put("create_time", now); + param.put("update_by", nickName); + param.put("update_time", now); + param.put("region", region); + + wo.insert(param); + } + } + @Override public JSONArray selectConveyorList() { //设备基础信息表【acs_device】 diff --git a/acs/nladmin-ui/src/api/acs/device/device.js b/acs/nladmin-ui/src/api/acs/device/device.js index 9272096..85dd735 100644 --- a/acs/nladmin-ui/src/api/acs/device/device.js +++ b/acs/nladmin-ui/src/api/acs/device/device.js @@ -149,14 +149,14 @@ export function reload() { }) } - -export function selectRequestMethodList() { +export function excelImport(data) { return request({ - url: 'api/device/selectRequestMethodList', - method: 'get' + url: 'api/device/excelImport', + method: 'post', + data }) } export default { add, edit, del, selectDeviceList, selectDeviceListByRegion, callAgv, responseAgv, selectDeviceDevicerInfo, autoCreateTask, changeDeviceStatus, cleanTask, queryStorageExtra, selectConDeviceList, saveBarcode, selectDeviceListOne, selectDeviceListTwo, selectDeviceListThree, - addMaterial, cleanMaterial, reload, selectRequestMethodList } + addMaterial, cleanMaterial, reload, excelImport } diff --git a/acs/nladmin-ui/src/views/acs/device/UploadDialog.vue b/acs/nladmin-ui/src/views/acs/device/UploadDialog.vue new file mode 100644 index 0000000..b299a0e --- /dev/null +++ b/acs/nladmin-ui/src/views/acs/device/UploadDialog.vue @@ -0,0 +1,116 @@ + + + + diff --git a/acs/nladmin-ui/src/views/acs/device/index.vue b/acs/nladmin-ui/src/views/acs/device/index.vue index 7b2e169..fa87c1e 100644 --- a/acs/nladmin-ui/src/views/acs/device/index.vue +++ b/acs/nladmin-ui/src/views/acs/device/index.vue @@ -29,6 +29,16 @@ + + 导入 + - + 驱动配置 @@ -151,6 +161,7 @@ + @@ -162,6 +173,7 @@ import crudOperation from '@crud/CRUD.operation' import udOperation from '@crud/UD.operation' import pagination from '@crud/Pagination' import { get } from '@/api/system/dictDetail' +import UploadDialog from '@/views/acs/device/UploadDialog' const defaultForm = { manufacturer: null, @@ -184,7 +196,7 @@ const defaultForm = { } export default { name: 'Device', - components: { pagination, crudOperation, rrOperation, udOperation }, + components: { pagination, crudOperation, rrOperation, udOperation, UploadDialog }, mixins: [presenter(), header(), form(defaultForm), crud()], cruds() { return CRUD({ @@ -203,6 +215,7 @@ export default { del: ['admin', 'device:del'] }, device_types: [], + uploadShow: false, regions: [], rules: { device_code: [ @@ -235,6 +248,9 @@ export default { [CRUD.HOOK.beforeRefresh]() { return true }, + tableChanged3() { + this.crud.toQuery() + }, reload() { crudDevice.reload().then(res => { this.crud.toQuery()