Commit c1c96728 authored by 刘帅's avatar 刘帅

1.增加物资导入功能

parent cf54279f
package com.maintain.business.controller; package com.maintain.business.controller;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Arrays; import java.util.Arrays;
import com.maintain.business.domain.bo.ErpCarBo;
import com.maintain.business.domain.vo.ErpCarVo;
import com.maintain.business.listener.ErpCarImportListener;
import com.maintain.business.listener.ErpMaterialImportListener;
import com.maintain.common.excel.ExcelResult;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import com.maintain.common.annotation.RepeatSubmit; import com.maintain.common.annotation.RepeatSubmit;
...@@ -22,6 +29,7 @@ import com.maintain.business.domain.vo.ErpMaterialVo; ...@@ -22,6 +29,7 @@ import com.maintain.business.domain.vo.ErpMaterialVo;
import com.maintain.business.domain.bo.ErpMaterialBo; import com.maintain.business.domain.bo.ErpMaterialBo;
import com.maintain.business.service.IErpMaterialService; import com.maintain.business.service.IErpMaterialService;
import com.maintain.common.core.page.TableDataInfo; import com.maintain.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
/** /**
* 物资 * 物资
...@@ -46,6 +54,27 @@ public class ErpMaterialController extends BaseController { ...@@ -46,6 +54,27 @@ public class ErpMaterialController extends BaseController {
return iErpMaterialService.queryPageList(bo, pageQuery); return iErpMaterialService.queryPageList(bo, pageQuery);
} }
/**
* 物料导入模板下载
*/
@PostMapping("/importTemplate")
public void importTemplate(ErpMaterialBo bo, HttpServletResponse response) {
ExcelUtil.exportExcel(new ArrayList<>(), "物料导入", ErpMaterialVo.class, response);
}
/**
* 导入数据
*
* @param file 导入文件
* @param updateSupport 是否更新已存在数据
*/
@Log(title = "物料导入", businessType = BusinessType.IMPORT)
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception {
ExcelResult<ErpMaterialVo> result = ExcelUtil.importExcel(file.getInputStream(), ErpMaterialVo.class, new ErpMaterialImportListener(updateSupport));
return R.ok(result.getAnalysis());
}
/** /**
* 导出物资列表 * 导出物资列表
*/ */
......
...@@ -28,17 +28,6 @@ public class ErpMaterialVo implements Serializable { ...@@ -28,17 +28,6 @@ public class ErpMaterialVo implements Serializable {
*/ */
private Long id; private Long id;
/**
* 物资分类ID
*/
private Long materialTypeId;
/**
* 物资分类名称
*/
@ExcelProperty(value = "物资分类名称")
private String materialTypeName;
/** /**
* 部门ID * 部门ID
*/ */
...@@ -48,30 +37,35 @@ public class ErpMaterialVo implements Serializable { ...@@ -48,30 +37,35 @@ public class ErpMaterialVo implements Serializable {
* 部门名称 * 部门名称
*/ */
private String deptName; private String deptName;
/** /**
* 仓库ID * 仓库货位ID
*/ */
private Long warehouseId; private Long warehouseLocationId;
/** /**
* 仓库名称 * 物资编码
*/ */
private String warehouseName; @ExcelProperty(value = "物资编码")
private String materialCode;
/** /**
* 仓库货位ID * 物资名称
*/ */
private Long warehouseLocationId; @ExcelProperty(value = "物资名称")
private String materialName;
/** /**
* 仓库货位编码 * 物资规格
*/ */
private String warehouseLocationCode; @ExcelProperty(value = "物资规格")
private String materialSpecifications;
/** /**
* 仓库货位类型 * 物资单位
*/ */
@ExcelProperty(value = "仓库货位类型") @ExcelProperty(value = "物资单位")
@ColumnWidth(30) private String materialUnit;
private String warehouseLocationType;
/** /**
* 供应商ID * 供应商ID
...@@ -85,28 +79,37 @@ public class ErpMaterialVo implements Serializable { ...@@ -85,28 +79,37 @@ public class ErpMaterialVo implements Serializable {
private String vendorName; private String vendorName;
/** /**
* 物资编码 * 物资分类ID
*/ */
@ExcelProperty(value = "物资编码") private Long materialTypeId;
private String materialCode;
/** /**
* 物资名称 * 物资分类名称
*/ */
@ExcelProperty(value = "物资名称") @ExcelProperty(value = "物资分类名称")
private String materialName; private String materialTypeName;
/** /**
* 物资规格 * 仓库ID
*/ */
@ExcelProperty(value = "物资规格") private Long warehouseId;
private String materialSpecifications;
/** /**
* 物资单位 * 仓库名称
*/ */
@ExcelProperty(value = "物资单位") private String warehouseName;
private String materialUnit;
/**
* 仓库货位编码
*/
private String warehouseLocationCode;
/**
* 仓库货位类型
*/
@ExcelProperty(value = "仓库货位类型")
@ColumnWidth(30)
private String warehouseLocationType;
/** /**
* 物资品牌 * 物资品牌
...@@ -130,7 +133,7 @@ public class ErpMaterialVo implements Serializable { ...@@ -130,7 +133,7 @@ public class ErpMaterialVo implements Serializable {
/** /**
* 质保期(月) * 质保期(月)
*/ */
@ExcelProperty(value = "质保期") @ExcelProperty(value = "质保期(月)")
private Integer materialWarrantyPeriod; private Integer materialWarrantyPeriod;
/** /**
......
...@@ -93,6 +93,7 @@ public class ErpMaterialServiceImpl implements IErpMaterialService { ...@@ -93,6 +93,7 @@ public class ErpMaterialServiceImpl implements IErpMaterialService {
lqw.eq(StringUtils.isNotBlank(bo.getIsEnable()), ErpMaterial::getIsEnable, bo.getIsEnable()); lqw.eq(StringUtils.isNotBlank(bo.getIsEnable()), ErpMaterial::getIsEnable, bo.getIsEnable());
lqw.eq(StringUtils.isNotBlank(bo.getIsUniversal()), ErpMaterial::getIsUniversal, bo.getIsUniversal()); lqw.eq(StringUtils.isNotBlank(bo.getIsUniversal()), ErpMaterial::getIsUniversal, bo.getIsUniversal());
lqw.eq(ErpMaterial::getIsDelete, IsDeleteStatus.NO.getCode()); lqw.eq(ErpMaterial::getIsDelete, IsDeleteStatus.NO.getCode());
lqw.orderByDesc(ErpMaterial::getCreateTime);
return lqw; return lqw;
} }
......
...@@ -9,7 +9,7 @@ import { saveAs } from 'file-saver' ...@@ -9,7 +9,7 @@ import { saveAs } from 'file-saver'
let downloadLoadingInstance; let downloadLoadingInstance;
// 是否显示重新登录 // 是否显示重新登录
export let isRelogin = { show: false }; export let isRelogin = { show: true };
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
// 对应国际化资源文件后缀 // 对应国际化资源文件后缀
...@@ -19,7 +19,7 @@ const service = axios.create({ ...@@ -19,7 +19,7 @@ const service = axios.create({
// axios中请求配置有baseURL选项,表示请求URL公共部分 // axios中请求配置有baseURL选项,表示请求URL公共部分
baseURL: process.env.VUE_APP_BASE_API, baseURL: process.env.VUE_APP_BASE_API,
// 超时 // 超时
timeout: 50000 timeout: 10000
}) })
// request拦截器 // request拦截器
......
...@@ -120,6 +120,16 @@ ...@@ -120,6 +120,16 @@
v-hasPermi="['business:material:export']" v-hasPermi="['business:material:export']"
>导出</el-button> >导出</el-button>
</el-col> </el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-upload2"
size="mini"
@click="handleImport"
v-hasPermi="['business:material:import']"
>导入</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
...@@ -310,6 +320,36 @@ ...@@ -310,6 +320,36 @@
<el-button @click="cancel">取 消</el-button> <el-button @click="cancel">取 消</el-button>
</div> </div>
</el-dialog> </el-dialog>
<!-- 导入对话框 -->
<el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
<el-upload
ref="upload"
:limit="1"
accept=".xlsx, .xls"
:headers="upload.headers"
:action="upload.url + '?updateSupport=' + upload.updateSupport"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:auto-upload="false"
drag
>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<div class="el-upload__tip text-center" slot="tip">
<!-- <div class="el-upload__tip" slot="tip">-->
<!-- <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据-->
<!-- </div>-->
<span>仅允许导入xls、xlsx格式文件。</span>
<el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
</div>
</el-upload>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitFileForm">确 定</el-button>
<el-button @click="upload.open = false">取 消</el-button>
</div>
</el-dialog>
</div> </div>
</template> </template>
...@@ -321,6 +361,7 @@ import '@riophae/vue-treeselect/dist/vue-treeselect.css' ...@@ -321,6 +361,7 @@ import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { listWarehouseLocation } from '../../../api/business/warehouseLocation' import { listWarehouseLocation } from '../../../api/business/warehouseLocation'
import { listMaterialVendor, listMaterialVendorAll } from '../../../api/business/materialVendor' import { listMaterialVendor, listMaterialVendorAll } from '../../../api/business/materialVendor'
import { listSiteWarehouse, listWarehouseAll } from '@/api/business/siteWarehouse' import { listSiteWarehouse, listWarehouseAll } from '@/api/business/siteWarehouse'
import {getToken} from "@/utils/auth";
export default { export default {
name: "Material", name: "Material",
...@@ -375,6 +416,21 @@ export default { ...@@ -375,6 +416,21 @@ export default {
isUniversal: undefined, isUniversal: undefined,
isCheck: undefined, isCheck: undefined,
}, },
// 导入参数
upload: {
// 是否显示弹出层
open: false,
// 弹出层标题
title: "",
// 是否禁用上传
isUploading: false,
// 是否更新已经存在的数据
updateSupport: 0,
// 设置上传的请求头部
headers: { Authorization: "Bearer " + getToken() },
// 上传的地址
url: process.env.VUE_APP_BASE_API + "business/material/importData"
},
// 表单参数 // 表单参数
form: {}, form: {},
// 表单校验 // 表单校验
...@@ -589,7 +645,32 @@ export default { ...@@ -589,7 +645,32 @@ export default {
this.download('business/material/export', { this.download('business/material/export', {
...this.queryParams ...this.queryParams
}, `物资列表_${new Date().getTime()}.xlsx`) }, `物资列表_${new Date().getTime()}.xlsx`)
} },
/** 导入按钮操作 */
handleImport() {
this.upload.title = "物资导入";
this.upload.open = true;
},
/** 下载模板操作 */
importTemplate() {
this.download('business/material/importTemplate', {}, `物资导入模板`)
},
// 文件上传中处理
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true;
},
// 文件上传成功处理
handleFileSuccess(response, file, fileList) {
this.upload.open = false;
this.upload.isUploading = false;
this.$refs.upload.clearFiles();
this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
this.getList();
},
// 提交上传文件
submitFileForm() {
this.$refs.upload.submit();
},
} }
}; };
</script> </script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment