From 291693e396d5a057a30357712f7e7446078c0a29 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期二, 24 九月 2024 16:48:59 +0800
Subject: [PATCH] #
---
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/template/MatTemplate.java | 171 ++++++++++++++++++++++++++++
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/Mat.java | 6
zy-asrs-admin/src/views/base/mat/index.vue | 71 +++++++++++
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/controller/MatController.java | 79 ++++++++++++
4 files changed, 321 insertions(+), 6 deletions(-)
diff --git a/zy-asrs-admin/src/views/base/mat/index.vue b/zy-asrs-admin/src/views/base/mat/index.vue
index cb4596f..b5ca1aa 100644
--- a/zy-asrs-admin/src/views/base/mat/index.vue
+++ b/zy-asrs-admin/src/views/base/mat/index.vue
@@ -3,10 +3,15 @@
import { useRouter } from "vue-router";
import { get, post, postBlob, postForm } from '@/utils/request.js'
import { message, Modal } from 'ant-design-vue';
-import { logout } from '@/config.js';
+import { globalState, logout } from '@/config.js';
import EditView from './edit.vue'
import { formatMessage } from '@/utils/localeUtils.js';
import useTableSearch from '@/utils/tableUtils.jsx';
+import {
+ DownOutlined,
+ UploadOutlined,
+ DownloadOutlined,
+} from "@ant-design/icons-vue";
const context = getCurrentInstance()?.appContext.config.globalProperties;
const router = useRouter();
@@ -333,6 +338,7 @@
dataIndex: 'oper',
key: 'oper',
width: 140,
+ fixed: 'right',
})
state.columns = tmp;
@@ -429,6 +435,45 @@
})
}
+const handleSyncMatClick = (e) => {
+ if (e.key == 'import') {
+ importTemplate()
+ } else if (e.key == 'export') {
+ exportTemplate()
+ }
+}
+
+const importTemplate = () => {
+ //瀵煎叆妯℃澘
+}
+
+const exportTemplate = () => {
+ //妯℃澘瀵煎嚭
+ postBlob('/api/mat/exportTemplate', {}).then(result => {
+ const blob = new Blob([result.data], { type: 'application/vnd.ms-excel' });
+ window.location.href = window.URL.createObjectURL(blob);
+ return true;
+ })
+}
+
+const fileList = ref([]);
+const handleUploadChange = info => {
+ if (info.file.status !== 'uploading') {
+ // console.log(info.file, info.fileList);
+ }
+ if (info.file.status === 'done') {
+ let result = info.file.response;
+ if (result.code == 200) {
+ message.success(`${info.file.name} ${formatMessage('page.upload.success', '涓婁紶鎴愬姛')}`);
+ getPage()
+ } else {
+ message.error(result.msg);
+ }
+ } else if (info.file.status === 'error') {
+ message.error(`${info.file.name} file upload failed.`);
+ }
+};
+
</script>
<script>
@@ -444,6 +489,30 @@
<a-input-search v-model:value="searchInput" :placeholder="formatMessage('page.input', '璇疯緭鍏�')"
style="width: 200px;" @search="onSearch" />
<div class="table-header-right">
+ <a-dropdown>
+ <template #overlay>
+ <a-menu @click="handleSyncMatClick">
+ <a-menu-item key="import">
+ <a-upload v-model:file-list="fileList" name="file" action="/api/mat/upload"
+ @change="handleUploadChange" :showUploadList="false" :headers="{
+ Authorization: globalState.token
+ }">
+ <UploadOutlined />
+ {{ formatMessage('page.mat.import', '鍟嗗搧瀵煎叆') }}
+ </a-upload>
+ </a-menu-item>
+
+ <a-menu-item key="export">
+ <DownloadOutlined />
+ {{ formatMessage('page.mat.export.template', '瀵煎嚭妯℃澘') }}
+ </a-menu-item>
+ </a-menu>
+ </template>
+ <a-button>
+ {{ formatMessage('page.mat.sync', '鏁版嵁鍚屾') }}
+ <DownOutlined />
+ </a-button>
+ </a-dropdown>
<a-button @click="handleEdit(null)" type="primary">{{ formatMessage('page.add', '娣诲姞') }}</a-button>
<a-button @click="handleExport">{{ formatMessage('page.export', '瀵煎嚭') }}</a-button>
</div>
diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/controller/MatController.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/controller/MatController.java
index eed691f..b11d721 100644
--- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/controller/MatController.java
+++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/controller/MatController.java
@@ -3,15 +3,18 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
-import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
+import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wms.asrs.entity.MatField;
import com.zy.asrs.wms.asrs.entity.MatFieldValue;
+import com.zy.asrs.wms.asrs.entity.Tag;
+import com.zy.asrs.wms.asrs.entity.template.MatTemplate;
import com.zy.asrs.wms.asrs.service.MatFieldService;
import com.zy.asrs.wms.asrs.service.MatFieldValueService;
+import com.zy.asrs.wms.asrs.service.TagService;
import com.zy.asrs.wms.common.annotation.OperationLog;
import com.zy.asrs.wms.common.domain.BaseParam;
import com.zy.asrs.wms.common.domain.KeyValVo;
@@ -22,7 +25,9 @@
import com.zy.asrs.wms.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
@@ -37,6 +42,8 @@
private MatFieldService matFieldService;
@Autowired
private MatFieldValueService matFieldValueService;
+ @Autowired
+ private TagService tagService;
@PreAuthorize("hasAuthority('asrs:mat:list')")
@PostMapping("/mat/page")
@@ -129,7 +136,7 @@
ExcelUtil.build(ExcelUtil.create(list, Mat.class, matFields), response);
}
- private void setMatField(HashMap<String, Object> param, Mat mat) {
+ private void setMatField(Map<String, Object> param, Mat mat) {
//鑾峰彇鎵╁睍瀛楁
List<MatField> matFields = matFieldService.list();
for (MatField matField : matFields) {
@@ -137,19 +144,83 @@
MatFieldValue fieldValue = matFieldValueService.getOne(new LambdaQueryWrapper<MatFieldValue>()
.eq(MatFieldValue::getMatId, mat.getId())
.eq(MatFieldValue::getFieldId, matField.getId()));
+ Object valueObj = param.get(matField.getName());
+ String value = "";
+ if(valueObj != null) {
+ value = valueObj.toString();
+ }
+
if (fieldValue == null) {
fieldValue = new MatFieldValue();
fieldValue.setMatId(mat.getId());
fieldValue.setFieldId(matField.getId());
fieldValue.setName(matField.getName());
- fieldValue.setValue(param.get(matField.getName()).toString());
+ fieldValue.setValue(value);
matFieldValueService.save(fieldValue);
}else {
- fieldValue.setValue(param.get(matField.getName()).toString());
+ fieldValue.setValue(value);
matFieldValueService.updateById(fieldValue);
}
}
}
}
+ @PreAuthorize("hasAuthority('asrs:mat:list')")
+ @PostMapping("/mat/exportTemplate")
+ public void exportTemplate(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
+ ArrayList<MatTemplate> list = new ArrayList<>();
+ List<MatField> matFields = matFieldService.getMatFields();
+ ExcelUtil.build(ExcelUtil.create(list, MatTemplate.class, matFields), response);
+ }
+
+ @PostMapping("/mat/upload")
+ @Transactional
+ public R upload(@RequestParam("file") MultipartFile file) {
+ List<MatTemplate> list = ExcelUtil.parseExcelFile(file, MatTemplate.class);
+ for (MatTemplate matTemplate : list) {
+ String firstTag = matTemplate.getFirstTag();
+ String secondTag = matTemplate.getSecondTag();
+ Tag tag1 = null;
+ Long tagId = null;
+
+ if (!Cools.isEmpty(firstTag)) {
+ Tag tag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, firstTag));
+ if (tag == null) {
+ tag = new Tag();
+ tag.setName(firstTag);
+ tag.setParentId(0L);
+ tagService.save(tag);
+ }
+
+ tagId = tag.getId();
+ tag1 = tag;
+ }
+
+ if (!Cools.isEmpty(secondTag)) {
+ if (tag1 != null) {
+ Tag tag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, secondTag).eq(Tag::getParentId, tag1.getId()));
+ if (tag == null) {
+ tag = new Tag();
+ tag.setName(secondTag);
+ tag.setParentId(tag1.getId());
+ tagService.save(tag);
+ }
+
+ tagId = tag.getId();
+ }
+ }
+
+
+ Mat mat = new Mat();
+ mat.sync(matTemplate);
+ mat.setTagId(tagId);
+ if (!matService.save(mat)) {
+ throw new CoolException("鍒涘缓鍟嗗搧澶辫触");
+ }
+ //璁剧疆鎵╁睍瀛楁
+ setMatField(matTemplate.getDynamicFields(), mat);
+ }
+ return R.ok();
+ }
+
}
diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/Mat.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/Mat.java
index 835c395..721af0a 100644
--- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/Mat.java
+++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/Mat.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
+import com.zy.asrs.common.utils.Synchro;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.SpringUtils;
import com.zy.asrs.wms.asrs.service.TagService;
@@ -69,7 +70,6 @@
*/
@ApiModelProperty(value = "鏄惁鍒犻櫎 1: 鏄� 0: 鍚� ")
@TableLogic
- @TableField(fill = FieldFill.INSERT)
private Integer deleted;
/**
@@ -428,6 +428,10 @@
return null;
}
+ public void sync(Object source) {
+ Synchro.Copy(source, this);
+ }
+
//鍔ㄦ�佹墿灞曞瓧娈�
public transient Map<String, Object> dynamicFields;
diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/template/MatTemplate.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/template/MatTemplate.java
new file mode 100644
index 0000000..e53308e
--- /dev/null
+++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/template/MatTemplate.java
@@ -0,0 +1,171 @@
+package com.zy.asrs.wms.asrs.entity.template;
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter;
+import com.zy.asrs.common.utils.Synchro;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+@Data
+public class MatTemplate {
+
+ //涓�绾у垎绫�
+ @ApiModelProperty(value= "涓�绾у垎绫�")
+ private String firstTag;
+
+ //浜岀骇鍒嗙被
+ @ApiModelProperty(value= "浜岀骇鍒嗙被")
+ private String secondTag;
+
+ //鍟嗗搧缂栧彿
+ @ApiModelProperty(value= "鍟嗗搧缂栧彿")
+ private String matnr;
+
+ //鍟嗗搧鍚嶇О
+ @ApiModelProperty(value= "鍟嗗搧鍚嶇О")
+ private String maktx;
+
+ //鍒悕
+ @ApiModelProperty(value= "鍒悕")
+ private String name;
+
+ //瑙勬牸
+ @ApiModelProperty(value= "瑙勬牸")
+ private String specs;
+
+ //鍨嬪彿
+ @ApiModelProperty(value= "鍨嬪彿")
+ private String model;
+
+ //棰滆壊
+ @ApiModelProperty(value= "棰滆壊")
+ private String color;
+
+ //鍝佺墝
+ @ApiModelProperty(value= "鍝佺墝")
+ private String brand;
+
+ //鍗曚綅
+ @ApiModelProperty(value= "鍗曚綅")
+ private String unit;
+
+ //鍗曚环
+ @ApiModelProperty(value= "鍗曚环")
+ private Double price;
+
+ //sku
+ @ApiModelProperty(value= "sku")
+ private String sku;
+
+ //鍗曚綅閲�
+ @ApiModelProperty(value= "鍗曚綅閲�")
+ private String units;
+
+ //鏉$爜
+ @ApiModelProperty(value= "鏉$爜")
+ private String barcode;
+
+ //浜у湴
+ @ApiModelProperty(value= "浜у湴")
+ private String origin;
+
+ //鍘傚
+ @ApiModelProperty(value= "鍘傚")
+ private String manu;
+
+ //鐢熶骇鏃ユ湡
+ @ApiModelProperty(value= "鐢熶骇鏃ユ湡")
+ private String manuDate;
+
+ //鍝侀」鏁�
+ @ApiModelProperty(value= "鍝侀」鏁�")
+ private String itemNum;
+
+ //閲嶉噺
+ @ApiModelProperty(value= "閲嶉噺")
+ private String weight;
+
+ //闀垮害
+ @ApiModelProperty(value= "闀垮害")
+ private String length;
+
+ //浣撶Н
+ @ApiModelProperty(value= "浣撶Н")
+ private String volume;
+
+ //涓夋柟缂栫爜
+ @ApiModelProperty(value= "涓夋柟缂栫爜")
+ private String threeCode;
+
+ //渚涘簲鍟�
+ @ApiModelProperty(value= "渚涘簲鍟�")
+ private String supp;
+
+ //渚涘簲鍟嗙紪鐮�
+ @ApiModelProperty(value= "渚涘簲鍟嗙紪鐮�")
+ private String suppCode;
+
+ //淇濊川鏈�
+ @ApiModelProperty(value= "淇濊川鏈�")
+ private String deadTime;
+
+ //瀹夊叏搴撳瓨涓婇檺
+ @ApiModelProperty(value= "瀹夊叏搴撳瓨涓婇檺")
+ private Double safeStockLimit;
+
+ //瀹夊叏搴撳瓨涓嬮檺
+ @ApiModelProperty(value= "瀹夊叏搴撳瓨涓嬮檺")
+ private Double safeStockMinimum;
+
+ //鏈夋晥鏈�
+ @ApiModelProperty(value= "鏈夋晥鏈�")
+ private String validity;
+
+ //澶囨敞
+ @ApiModelProperty(value= "澶囨敞")
+ private String memo;
+
+ public void sync(Object source) {
+ Synchro.Copy(source, this);
+ }
+
+ //鍔ㄦ�佹墿灞曞瓧娈�
+ public transient Map<String, Object> dynamicFields = new HashMap<>();
+
+ @JsonAnyGetter
+ public Map<String,Object> getDynamicFields() {
+ return dynamicFields;
+ }
+
+ public void syncFieldMap(Map<String, Object> map) {
+ ArrayList<String> keys = new ArrayList<>();
+ Field[] fields = this.getClass().getDeclaredFields();
+ for (Field field : fields) {
+ keys.add(field.getName());
+ }
+ keys.add("detlId");
+
+ Map<String, Object> dynamicFields = new HashMap<>();
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
+ if (keys.contains(entry.getKey())) {
+ continue;
+ }
+ dynamicFields.put(entry.getKey(), entry.getValue());
+ }
+
+ this.dynamicFields = dynamicFields;
+ }
+
+ public String getFieldString(String key) {
+ return dynamicFields.get(key).toString();
+ }
+
+ public void setField(String key, Object value) {
+ dynamicFields.put(key, value);
+ }
+
+}
--
Gitblit v1.9.1