zy-asrs-admin/src/views/base/mat/index.vue | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/controller/MatController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/Mat.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/template/MatTemplate.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
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> 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(); } } 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; zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/entity/template/MatTemplate.java
New file @@ -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); } }