导入物料
This commit is contained in:
@@ -16,6 +16,7 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -101,4 +102,12 @@ public class MaterialbaseController {
|
|||||||
public ResponseEntity<Object> getProductSeries() {
|
public ResponseEntity<Object> getProductSeries() {
|
||||||
return new ResponseEntity<>(materialBaseService.getProductSeries("1527572574832300032"), HttpStatus.OK);
|
return new ResponseEntity<>(materialBaseService.getProductSeries("1527572574832300032"), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Log("导入物料信息")
|
||||||
|
@ApiOperation("导入物料信息")
|
||||||
|
@PostMapping("/excelImport")
|
||||||
|
public ResponseEntity<Object> excelImport(@RequestBody MultipartFile file) {
|
||||||
|
materialBaseService.excelImport(file);
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.nl.wms.basedata.service.dto.MaterialbaseDto;
|
import org.nl.wms.basedata.service.dto.MaterialbaseDto;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -94,4 +95,5 @@ public interface MaterialbaseService {
|
|||||||
JSONArray getProductSeries(String parent_class_id);
|
JSONArray getProductSeries(String parent_class_id);
|
||||||
|
|
||||||
|
|
||||||
|
void excelImport(MultipartFile file);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,17 @@ import cn.hutool.core.map.MapUtil;
|
|||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.excel.EasyExcel;
|
||||||
|
import com.alibaba.excel.ExcelReader;
|
||||||
|
import com.alibaba.excel.read.metadata.ReadSheet;
|
||||||
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.nl.modules.common.exception.BadRequestException;
|
import org.nl.modules.common.exception.BadRequestException;
|
||||||
|
import org.nl.modules.common.utils.FileUtil;
|
||||||
import org.nl.modules.common.utils.SecurityUtils;
|
import org.nl.modules.common.utils.SecurityUtils;
|
||||||
import org.nl.modules.wql.WQL;
|
import org.nl.modules.wql.WQL;
|
||||||
import org.nl.modules.wql.core.bean.WQLObject;
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
@@ -21,10 +26,15 @@ import org.nl.wms.basedata.eum.MaterOptTypeEnum;
|
|||||||
import org.nl.wms.basedata.service.ClassstandardService;
|
import org.nl.wms.basedata.service.ClassstandardService;
|
||||||
import org.nl.wms.basedata.service.MaterialbaseService;
|
import org.nl.wms.basedata.service.MaterialbaseService;
|
||||||
import org.nl.wms.basedata.service.dto.MaterialbaseDto;
|
import org.nl.wms.basedata.service.dto.MaterialbaseDto;
|
||||||
|
import org.nl.wms.util.CommonUtils;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -240,4 +250,49 @@ public class MaterialbaseServiceImpl implements MaterialbaseService {
|
|||||||
return newParentArray;
|
return newParentArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void excelImport(MultipartFile multipartFile) {
|
||||||
|
File file = FileUtil.toFile(multipartFile);
|
||||||
|
String type = FileUtil.getType(file);
|
||||||
|
if (!"xlsx".equals(type) && !"xls".equals(type)) {
|
||||||
|
throw new BadRequestException("只能上传 xls 或 xlsx 文件");
|
||||||
|
}
|
||||||
|
ExcelReader excelReader = EasyExcel.read(file).build();
|
||||||
|
List<ReadSheet> sheets = excelReader.excelExecutor().sheetList();
|
||||||
|
|
||||||
|
WQLObject materialTable = WQLObject.getWQLObject("md_me_materialbase");
|
||||||
|
JSONObject material = new JSONObject();
|
||||||
|
Long userId = SecurityUtils.getCurrentUserId();
|
||||||
|
String nickName = SecurityUtils.getCurrentNickName();
|
||||||
|
String now = DateUtil.now();
|
||||||
|
|
||||||
|
for (ReadSheet sheet : sheets) {
|
||||||
|
List<Map<Integer, String>> materials = EasyExcel.read(file).sheet(sheet.getSheetNo()).doReadSync();
|
||||||
|
for (Map<Integer, String> materialMap : materials) {
|
||||||
|
material.put("material_id", IdUtil.getSnowflake(1L, 1L).nextId());
|
||||||
|
String material_code = materialMap.get(1);
|
||||||
|
material.put("material_code", material_code);
|
||||||
|
material.put("material_name", materialMap.get(2));
|
||||||
|
material.put("base_unit", materialMap.get(3));
|
||||||
|
material.put("pack_qty", materialMap.get(4) == null ? 0 : Double.parseDouble(materialMap.get(4)));
|
||||||
|
|
||||||
|
material.put("is_used", '1');
|
||||||
|
material.put("is_delete", '0');
|
||||||
|
if (ObjectUtil.isNotEmpty(materialTable.query("material_code = '" + material_code + "'").uniqueResult(0))) {
|
||||||
|
material.put("update_optid", userId);
|
||||||
|
material.put("update_optname", nickName);
|
||||||
|
material.put("update_time", now);
|
||||||
|
materialTable.update(material);
|
||||||
|
} else {
|
||||||
|
material.put("create_id", userId);
|
||||||
|
material.put("create_name", nickName);
|
||||||
|
material.put("create_time", now);
|
||||||
|
material.put("update_optid", userId);
|
||||||
|
material.put("update_optname", nickName);
|
||||||
|
material.put("update_time", now);
|
||||||
|
materialTable.insert(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,4 +55,12 @@ export function getProductSeries() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { add, edit, del, getMaterOptType, isAlongMaterType, synchronize, getProductSeries }
|
export function excelImport(data) {
|
||||||
|
return request({
|
||||||
|
url: 'api/Materialbase/excelImport',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { add, edit, del, getMaterOptType, isAlongMaterType, synchronize, getProductSeries, excelImport }
|
||||||
|
|||||||
116
lms/nladmin-ui/src/views/wms/basedata/material/UploadDialog.vue
Normal file
116
lms/nladmin-ui/src/views/wms/basedata/material/UploadDialog.vue
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
title="导入Excel文件"
|
||||||
|
append-to-body
|
||||||
|
:visible.sync="dialogVisible"
|
||||||
|
destroy-on-close
|
||||||
|
width="400px"
|
||||||
|
:show-close="true"
|
||||||
|
@close="close"
|
||||||
|
@open="open"
|
||||||
|
>
|
||||||
|
<el-upload
|
||||||
|
ref="upload"
|
||||||
|
class="upload-demo"
|
||||||
|
action=""
|
||||||
|
drag
|
||||||
|
:on-exceed="is_one"
|
||||||
|
:limit="1"
|
||||||
|
:auto-upload="false"
|
||||||
|
:multiple="false"
|
||||||
|
:show-file-list="true"
|
||||||
|
:on-change="uploadByJsqd"
|
||||||
|
:file-list="fileList"
|
||||||
|
accept=".xlsx,.xls"
|
||||||
|
>
|
||||||
|
<i class="el-icon-upload" />
|
||||||
|
<div class="el-upload__text">
|
||||||
|
将文件拖到此处,或
|
||||||
|
<em>点击上传</em>
|
||||||
|
</div>
|
||||||
|
<div slot="tip" class="el-upload__tip">只能上传Excel文件,且不超过10MB</div>
|
||||||
|
</el-upload>
|
||||||
|
<span slot="footer" class="dialog-footer">
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
<el-button type="primary" @click="submit">确 定</el-button>
|
||||||
|
</span>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import crudMaterialbase from '@/api/wms/basedata/materialbase'
|
||||||
|
import CRUD, { crud } from '@crud/crud'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'UploadDialog',
|
||||||
|
mixins: [crud()],
|
||||||
|
components: {},
|
||||||
|
props: {
|
||||||
|
dialogShow: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
openParam: {
|
||||||
|
type: String
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
dialogVisible: false,
|
||||||
|
fileList: [],
|
||||||
|
file1: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
dialogShow: {
|
||||||
|
handler(newValue, oldValue) {
|
||||||
|
this.dialogVisible = newValue
|
||||||
|
}
|
||||||
|
},
|
||||||
|
openParam: {
|
||||||
|
handler(newValue, oldValue) {
|
||||||
|
this.opendtlParam = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
open() {
|
||||||
|
},
|
||||||
|
close() {
|
||||||
|
this.$emit('update:dialogShow', false)
|
||||||
|
},
|
||||||
|
is_one() {
|
||||||
|
this.crud.notify('只能上传一个excel文件!', CRUD.NOTIFICATION_TYPE.WARNING)
|
||||||
|
},
|
||||||
|
// 文件校验方法
|
||||||
|
beforeAvatarUpload(file) {
|
||||||
|
// 不能导入大小超过2Mb的文件
|
||||||
|
if (file.size > 10 * 1024 * 1024) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
// 文件发生改变就会触发的事件
|
||||||
|
uploadByJsqd(file) {
|
||||||
|
this.file1 = file
|
||||||
|
},
|
||||||
|
submit() {
|
||||||
|
if (this.beforeAvatarUpload(this.file1)) {
|
||||||
|
this.fileList.name = this.file1.name
|
||||||
|
this.fileList.url = ''
|
||||||
|
var formdata = new FormData()
|
||||||
|
formdata.append('file', this.file1.raw)
|
||||||
|
// excelImport:请求接口 formdata:传递参数
|
||||||
|
crudMaterialbase.excelImport(formdata).then((res) => {
|
||||||
|
this.crud.notify('导入成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
||||||
|
this.$emit('tableChanged3', '')
|
||||||
|
this.$emit('update:dialogShow', false)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.crud.notify('文件过大,请上传小于10MB的文件〜', CRUD.NOTIFICATION_TYPE.WARNING)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
@@ -58,16 +58,26 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
||||||
<crudOperation :permission="permission">
|
<crudOperation :permission="permission">
|
||||||
|
<!-- <el-button-->
|
||||||
|
<!-- v-if="false"-->
|
||||||
|
<!-- slot="right"-->
|
||||||
|
<!-- class="filter-item"-->
|
||||||
|
<!-- type="success"-->
|
||||||
|
<!-- icon="el-icon-position"-->
|
||||||
|
<!-- size="mini"-->
|
||||||
|
<!-- @click="synchronize()"-->
|
||||||
|
<!-- >-->
|
||||||
|
<!-- 同步-->
|
||||||
|
<!-- </el-button>-->
|
||||||
<el-button
|
<el-button
|
||||||
v-if="false"
|
|
||||||
slot="right"
|
slot="right"
|
||||||
class="filter-item"
|
class="filter-item"
|
||||||
type="success"
|
type="warning"
|
||||||
icon="el-icon-position"
|
icon="el-icon-upload2"
|
||||||
size="mini"
|
size="mini"
|
||||||
@click="synchronize()"
|
@click="uploadShow = true"
|
||||||
>
|
>
|
||||||
同步
|
导入
|
||||||
</el-button>
|
</el-button>
|
||||||
</crudOperation>
|
</crudOperation>
|
||||||
<!--表单组件-->
|
<!--表单组件-->
|
||||||
@@ -227,6 +237,7 @@
|
|||||||
</el-table>
|
</el-table>
|
||||||
<!--分页组件-->
|
<!--分页组件-->
|
||||||
<pagination />
|
<pagination />
|
||||||
|
<UploadDialog :dialog-show.sync="uploadShow" @tableChanged3="tableChanged3" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -242,6 +253,7 @@ import Treeselect, { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
|
|||||||
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
|
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
|
||||||
import crudClassstandard from '@/api/wms/basedata/classstandard'
|
import crudClassstandard from '@/api/wms/basedata/classstandard'
|
||||||
import crudMdPbMeasureunit from '@/api/wms/basedata/mdPbMeasureunit'
|
import crudMdPbMeasureunit from '@/api/wms/basedata/mdPbMeasureunit'
|
||||||
|
import UploadDialog from '@/views/wms/basedata/material/UploadDialog.vue'
|
||||||
|
|
||||||
const defaultForm = {
|
const defaultForm = {
|
||||||
material_id: null,
|
material_id: null,
|
||||||
@@ -284,7 +296,7 @@ export default {
|
|||||||
name: 'Materialbase',
|
name: 'Materialbase',
|
||||||
// 数据字典
|
// 数据字典
|
||||||
dicts: ['is_used'],
|
dicts: ['is_used'],
|
||||||
components: { pagination, crudOperation, rrOperation, udOperation, Treeselect },
|
components: { UploadDialog, pagination, crudOperation, rrOperation, udOperation, Treeselect },
|
||||||
mixins: [presenter(), header(), form(defaultForm), crud()],
|
mixins: [presenter(), header(), form(defaultForm), crud()],
|
||||||
cruds() {
|
cruds() {
|
||||||
return CRUD({
|
return CRUD({
|
||||||
@@ -305,6 +317,7 @@ export default {
|
|||||||
measure_unit: [],
|
measure_unit: [],
|
||||||
productSeries: [],
|
productSeries: [],
|
||||||
permission: {},
|
permission: {},
|
||||||
|
uploadShow: false,
|
||||||
rules: {
|
rules: {
|
||||||
material_id: [
|
material_id: [
|
||||||
{ required: true, message: '物料号不能为空', trigger: 'blur' }
|
{ required: true, message: '物料号不能为空', trigger: 'blur' }
|
||||||
@@ -346,6 +359,9 @@ export default {
|
|||||||
[CRUD.HOOK.beforeRefresh]() {
|
[CRUD.HOOK.beforeRefresh]() {
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
|
tableChanged3() {
|
||||||
|
this.crud.toQuery()
|
||||||
|
},
|
||||||
initClass1() {
|
initClass1() {
|
||||||
const param = {
|
const param = {
|
||||||
parent_class_code: '09'
|
parent_class_code: '09'
|
||||||
|
|||||||
Reference in New Issue
Block a user