feat: 物料、单位导入数据、导出模板功能
This commit is contained in:
@@ -17,6 +17,7 @@ package org.nl.common.utils;
|
|||||||
|
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.URLUtil;
|
||||||
import cn.hutool.poi.excel.BigExcelWriter;
|
import cn.hutool.poi.excel.BigExcelWriter;
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
@@ -25,6 +26,7 @@ import org.nl.common.exception.BadRequestException;
|
|||||||
import org.nl.config.language.LangProcess;
|
import org.nl.config.language.LangProcess;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
@@ -344,4 +346,20 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
return getMd5(getByte(file));
|
return getMd5(getByte(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] getByteByTemplate(String templateName) throws IOException {
|
||||||
|
// 使用 ClassPathResource 获取资源
|
||||||
|
ClassPathResource resource = new ClassPathResource(templateName);
|
||||||
|
InputStream inputStream = resource.getInputStream();
|
||||||
|
return IoUtil.readBytes(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void download(String fileName, byte[] fileBytes, HttpServletResponse response) throws IOException {
|
||||||
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLUtil.encode(fileName));
|
||||||
|
response.addHeader("Content-Length", "" + fileBytes.length);
|
||||||
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||||
|
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||||
|
IoUtil.write(response.getOutputStream(), true, fileBytes);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,14 @@ import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
|
|||||||
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
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 javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -69,5 +73,18 @@ public class MaterialbaseController {
|
|||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/importExcel")
|
||||||
|
@Log("导入物料")
|
||||||
|
public ResponseEntity<Object> importExcel(@RequestPart("file") MultipartFile file) {
|
||||||
|
iMdMeMaterialbaseService.importExcel(file);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log("下载导入模板")
|
||||||
|
@GetMapping(value = "/downloadImportMaterialTemplate", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
||||||
|
public void downloadImportUserTemplate(HttpServletResponse response) {
|
||||||
|
iMdMeMaterialbaseService.downloadImportMaterialTemplate(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,13 @@ import org.nl.wms.basedata_manage.service.IMdPbMeasureunitService;
|
|||||||
import org.nl.wms.basedata_manage.service.dao.MdPbMeasureunit;
|
import org.nl.wms.basedata_manage.service.dao.MdPbMeasureunit;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
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 javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -61,4 +64,17 @@ public class MeasureUnitController {
|
|||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/importExcel")
|
||||||
|
@Log("导入单位")
|
||||||
|
public ResponseEntity<Object> importExcel(@RequestPart("file") MultipartFile file) {
|
||||||
|
iMdPbMeasureunitService.importExcel(file);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Log("下载导入模板")
|
||||||
|
@GetMapping(value = "/downloadImportUnitTemplate", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
||||||
|
public void downloadImportUnitTemplate(HttpServletResponse response) {
|
||||||
|
iMdPbMeasureunitService.downloadImportUnitTemplate(response);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import org.nl.common.domain.query.PageQuery;
|
import org.nl.common.domain.query.PageQuery;
|
||||||
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -55,7 +57,12 @@ public interface IMdMeMaterialbaseService extends IService<MdMeMaterialbase> {
|
|||||||
/**
|
/**
|
||||||
* 根据编码获取物料
|
* 根据编码获取物料
|
||||||
* @param material_code 物料编码
|
* @param material_code 物料编码
|
||||||
|
* @param flag 为空是否抛出异常
|
||||||
* @return 返回结果
|
* @return 返回结果
|
||||||
*/
|
*/
|
||||||
MdMeMaterialbase getByCode(String material_code);
|
MdMeMaterialbase getByCode(String material_code, Boolean flag);
|
||||||
|
|
||||||
|
void importExcel(MultipartFile file);
|
||||||
|
|
||||||
|
void downloadImportMaterialTemplate(HttpServletResponse response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import org.nl.common.domain.query.PageQuery;
|
import org.nl.common.domain.query.PageQuery;
|
||||||
import org.nl.wms.basedata_manage.service.dao.MdPbMeasureunit;
|
import org.nl.wms.basedata_manage.service.dao.MdPbMeasureunit;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -49,6 +51,9 @@ public interface IMdPbMeasureunitService extends IService<MdPbMeasureunit> {
|
|||||||
* @param unit_code 编码
|
* @param unit_code 编码
|
||||||
* @return 实体类
|
* @return 实体类
|
||||||
*/
|
*/
|
||||||
MdPbMeasureunit getByCode(String unit_code);
|
MdPbMeasureunit getByCode(String unit_code, Boolean flag);
|
||||||
|
|
||||||
|
void importExcel(MultipartFile file);
|
||||||
|
|
||||||
|
void downloadImportUnitTemplate(HttpServletResponse response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
package org.nl.wms.basedata_manage.service.impl;
|
package org.nl.wms.basedata_manage.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.URLUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.nl.common.domain.query.PageQuery;
|
import org.nl.common.domain.query.PageQuery;
|
||||||
import org.nl.common.exception.BadRequestException;
|
import org.nl.common.exception.BadRequestException;
|
||||||
|
import org.nl.common.utils.FileUtil;
|
||||||
import org.nl.common.utils.IdUtil;
|
import org.nl.common.utils.IdUtil;
|
||||||
import org.nl.common.utils.SecurityUtils;
|
import org.nl.common.utils.SecurityUtils;
|
||||||
import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
|
import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
|
||||||
@@ -18,9 +22,14 @@ import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
|||||||
import org.nl.wms.basedata_manage.service.dao.mapper.MdMeMaterialbaseMapper;
|
import org.nl.wms.basedata_manage.service.dao.mapper.MdMeMaterialbaseMapper;
|
||||||
import org.nl.wms.ext_manage.service.WmsToErpService;
|
import org.nl.wms.ext_manage.service.WmsToErpService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
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 javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -43,6 +52,8 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
|||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private WmsToErpService wmsToErpService;
|
private WmsToErpService wmsToErpService;
|
||||||
|
@Autowired
|
||||||
|
private IMdMeMaterialbaseService materialbaseService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<MdMeMaterialbase> queryAll(Map whereJson, PageQuery page) {
|
public IPage<MdMeMaterialbase> queryAll(Map whereJson, PageQuery page) {
|
||||||
@@ -62,7 +73,7 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(MdMeMaterialbase dto) {
|
public void create(MdMeMaterialbase dto) {
|
||||||
// 根据物料编码查询是否有相同物料编码的物料
|
// 根据物料编码查询是否有相同物料编码的物料
|
||||||
MdMeMaterialbase mdMeMaterialbase = this.baseMapper.selectOne(
|
MdMeMaterialbase mdMeMaterialbase = this.baseMapper.selectOne(
|
||||||
@@ -85,7 +96,7 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(MdMeMaterialbase dto) {
|
public void update(MdMeMaterialbase dto) {
|
||||||
MdMeMaterialbase mdMeMaterialbase = this.baseMapper.selectById(dto.getMaterial_id());
|
MdMeMaterialbase mdMeMaterialbase = this.baseMapper.selectById(dto.getMaterial_id());
|
||||||
if (ObjectUtil.isEmpty(mdMeMaterialbase)) {
|
if (ObjectUtil.isEmpty(mdMeMaterialbase)) {
|
||||||
@@ -100,13 +111,13 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Set<String> ids) {
|
public void delete(Set<String> ids) {
|
||||||
this.baseMapper.deleteBatchIds(ids);
|
this.baseMapper.deleteBatchIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void materialSync(JSONObject whereJson) {
|
public void materialSync(JSONObject whereJson) {
|
||||||
JSONObject resultJson = wmsToErpService.materialSync(whereJson);
|
JSONObject resultJson = wmsToErpService.materialSync(whereJson);
|
||||||
List<JSONObject> dataList = resultJson.getJSONArray("data").toJavaList(JSONObject.class);
|
List<JSONObject> dataList = resultJson.getJSONArray("data").toJavaList(JSONObject.class);
|
||||||
@@ -145,16 +156,76 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MdMeMaterialbase getByCode(String materialCode) {
|
public MdMeMaterialbase getByCode(String materialCode, Boolean flag) {
|
||||||
MdMeMaterialbase one = this.getOne(
|
MdMeMaterialbase one = this.getOne(
|
||||||
new QueryWrapper<MdMeMaterialbase>().lambda().nested(r -> {
|
new QueryWrapper<MdMeMaterialbase>().lambda().nested(r -> {
|
||||||
r.eq(MdMeMaterialbase::getMaterial_id, materialCode)
|
r.eq(MdMeMaterialbase::getMaterial_id, materialCode)
|
||||||
.or()
|
.or()
|
||||||
.eq(MdMeMaterialbase::getMaterial_code, materialCode);
|
.eq(MdMeMaterialbase::getMaterial_code, materialCode);
|
||||||
}));
|
}));
|
||||||
if (ObjectUtil.isEmpty(one)) {
|
if (ObjectUtil.isEmpty(one) && flag) {
|
||||||
throw new BadRequestException("物料信息为【" + materialCode + "】不存在!");
|
throw new BadRequestException("物料信息为【" + materialCode + "】不存在!");
|
||||||
}
|
}
|
||||||
return one;
|
return one;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void importExcel(MultipartFile file) {
|
||||||
|
// 1. 校验文件
|
||||||
|
if (file.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("上传文件不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
try (InputStream inputStream = file.getInputStream();
|
||||||
|
Workbook workbook = WorkbookFactory.create(inputStream)) {
|
||||||
|
|
||||||
|
// 2. 获取第一个Sheet
|
||||||
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
// 3. 从第二行开始遍历 (索引1)
|
||||||
|
List<MdMeMaterialbase> dataList = new ArrayList<>();
|
||||||
|
for (int rowIndex = 1; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
||||||
|
Row row = sheet.getRow(rowIndex);
|
||||||
|
if (row == null) continue; // 跳过空行
|
||||||
|
Cell materialCodeCell = row.getCell(0);
|
||||||
|
MdMeMaterialbase byCode = materialbaseService.getByCode(String.valueOf(materialCodeCell), false);
|
||||||
|
if (ObjectUtil.isNotEmpty(byCode)) {
|
||||||
|
throw new BadRequestException("物料[" + materialCodeCell + "]已存在!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 读取6个字段
|
||||||
|
MdMeMaterialbase entity = new MdMeMaterialbase();
|
||||||
|
entity.setMaterial_id(IdUtil.getStringId());
|
||||||
|
entity.setMaterial_code(String.valueOf(materialCodeCell));
|
||||||
|
entity.setMaterial_name(String.valueOf(row.getCell(1)));
|
||||||
|
entity.setMaterial_spec(String.valueOf(row.getCell(2)));
|
||||||
|
entity.setMaterial_model(String.valueOf(row.getCell(3)));
|
||||||
|
entity.setBase_unit_id(String.valueOf(row.getCell(4)));
|
||||||
|
entity.setAss_unit_id(String.valueOf(row.getCell(5)));
|
||||||
|
entity.setCreate_id(SecurityUtils.getCurrentUserId());
|
||||||
|
entity.setCreate_name(SecurityUtils.getCurrentNickName());
|
||||||
|
entity.setCreate_time(DateUtil.now());
|
||||||
|
dataList.add(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. 批量保存(根据实际持久层实现)
|
||||||
|
materialbaseService.saveBatch(dataList);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("文件读取失败: " + e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("导入失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downloadImportMaterialTemplate(HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
byte[] byteByTemplate = FileUtil.getByteByTemplate("excel/material_template.xlsx");
|
||||||
|
FileUtil.download("物料导入模板.xlsx", byteByTemplate, response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(">>> 下载导入模板失败:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,17 +8,27 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.nl.common.domain.query.PageQuery;
|
import org.nl.common.domain.query.PageQuery;
|
||||||
import org.nl.common.exception.BadRequestException;
|
import org.nl.common.exception.BadRequestException;
|
||||||
|
import org.nl.common.utils.FileUtil;
|
||||||
import org.nl.common.utils.IdUtil;
|
import org.nl.common.utils.IdUtil;
|
||||||
import org.nl.common.utils.SecurityUtils;
|
import org.nl.common.utils.SecurityUtils;
|
||||||
import org.nl.wms.basedata_manage.enums.BaseDataEnum;
|
import org.nl.wms.basedata_manage.enums.BaseDataEnum;
|
||||||
import org.nl.wms.basedata_manage.service.IMdPbMeasureunitService;
|
import org.nl.wms.basedata_manage.service.IMdPbMeasureunitService;
|
||||||
|
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||||
import org.nl.wms.basedata_manage.service.dao.MdPbMeasureunit;
|
import org.nl.wms.basedata_manage.service.dao.MdPbMeasureunit;
|
||||||
import org.nl.wms.basedata_manage.service.dao.mapper.MdPbMeasureunitMapper;
|
import org.nl.wms.basedata_manage.service.dao.mapper.MdPbMeasureunitMapper;
|
||||||
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 javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -95,14 +105,72 @@ public class MdPbMeasureunitServiceImpl extends ServiceImpl<MdPbMeasureunitMappe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MdPbMeasureunit getByCode(String unit_code) {
|
public MdPbMeasureunit getByCode(String unit_code, Boolean flag) {
|
||||||
MdPbMeasureunit one = this.getOne(
|
MdPbMeasureunit one = this.getOne(
|
||||||
new QueryWrapper<MdPbMeasureunit>().lambda()
|
new QueryWrapper<MdPbMeasureunit>().lambda()
|
||||||
.eq(MdPbMeasureunit::getUnit_code, unit_code)
|
.eq(MdPbMeasureunit::getUnit_code, unit_code)
|
||||||
);
|
);
|
||||||
if (ObjectUtil.isEmpty(one)) {
|
if (ObjectUtil.isEmpty(one) && flag) {
|
||||||
throw new BadRequestException("计量单位编码为【"+unit_code+"】不存在!");
|
throw new BadRequestException("计量单位编码为【"+unit_code+"】不存在!");
|
||||||
}
|
}
|
||||||
return one;
|
return one;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void importExcel(MultipartFile file) {
|
||||||
|
// 1. 校验文件
|
||||||
|
if (file.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("上传文件不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
try (InputStream inputStream = file.getInputStream();
|
||||||
|
Workbook workbook = WorkbookFactory.create(inputStream)) {
|
||||||
|
|
||||||
|
// 2. 获取第一个Sheet
|
||||||
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
// 3. 从第二行开始遍历 (索引1)
|
||||||
|
List<MdPbMeasureunit> dataList = new ArrayList<>();
|
||||||
|
for (int rowIndex = 1; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
||||||
|
Row row = sheet.getRow(rowIndex);
|
||||||
|
if (row == null) {
|
||||||
|
continue; // 跳过空行
|
||||||
|
}
|
||||||
|
Cell cell1 = row.getCell(0);
|
||||||
|
MdPbMeasureunit byCode = this.getByCode(String.valueOf(cell1), false);
|
||||||
|
if (ObjectUtil.isNotEmpty(byCode)) {
|
||||||
|
throw new BadRequestException("物料[" + cell1 + "]已存在!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 读取6个字段
|
||||||
|
MdPbMeasureunit entity = new MdPbMeasureunit();
|
||||||
|
entity.setMeasure_unit_id(IdUtil.getStringId());
|
||||||
|
entity.setUnit_code(String.valueOf(cell1));
|
||||||
|
entity.setUnit_name(String.valueOf(row.getCell(1)));
|
||||||
|
entity.setQty_precision(new BigDecimal(String.valueOf(row.getCell(2))));
|
||||||
|
entity.setCreate_id(SecurityUtils.getCurrentUserId());
|
||||||
|
entity.setCreate_name(SecurityUtils.getCurrentNickName());
|
||||||
|
entity.setCreate_time(DateUtil.now());
|
||||||
|
dataList.add(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. 批量保存
|
||||||
|
this.saveBatch(dataList);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("文件读取失败: " + e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("导入失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downloadImportUnitTemplate(HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
byte[] byteByTemplate = FileUtil.getByteByTemplate("excel/unit_template.xlsx");
|
||||||
|
FileUtil.download("单位导入模板.xlsx", byteByTemplate, response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(">>> 下载导入模板失败:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ public class PdaIosInServiceImpl implements PdaIosInService {
|
|||||||
// 数量
|
// 数量
|
||||||
String qty = whereJson.getString("qty");
|
String qty = whereJson.getString("qty");
|
||||||
MdPbStoragevehicleinfo vehicleDao = iMdPbStoragevehicleinfoService.getByCode(whereJson.getString("vehicle_code"));
|
MdPbStoragevehicleinfo vehicleDao = iMdPbStoragevehicleinfoService.getByCode(whereJson.getString("vehicle_code"));
|
||||||
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(materialId);
|
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(materialId, true);
|
||||||
MdPbMeasureunit unitDao = iMdPbMeasureunitService.getById(materDao.getBase_unit_id());
|
MdPbMeasureunit unitDao = iMdPbMeasureunitService.getById(materDao.getBase_unit_id());
|
||||||
// 校验
|
// 校验
|
||||||
if (ObjectUtil.isEmpty(vehicleDao) || ObjectUtil.isEmpty(materDao) || ObjectUtil.isEmpty(materDao)) {
|
if (ObjectUtil.isEmpty(vehicleDao) || ObjectUtil.isEmpty(materDao) || ObjectUtil.isEmpty(materDao)) {
|
||||||
@@ -657,7 +657,7 @@ public class PdaIosInServiceImpl implements PdaIosInService {
|
|||||||
ArrayList<HashMap> tableData = new ArrayList<>();
|
ArrayList<HashMap> tableData = new ArrayList<>();
|
||||||
HashMap<String, String> dtl = new HashMap<>();
|
HashMap<String, String> dtl = new HashMap<>();
|
||||||
GroupPlate plateDao = plateDaoList.get(0);
|
GroupPlate plateDao = plateDaoList.get(0);
|
||||||
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(plateDao.getMaterial_id());
|
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(plateDao.getMaterial_id(), true);
|
||||||
dtl.put("storagevehicle_code", plateDao.getStoragevehicle_code());
|
dtl.put("storagevehicle_code", plateDao.getStoragevehicle_code());
|
||||||
dtl.put("material_id", materDao.getMaterial_id());
|
dtl.put("material_id", materDao.getMaterial_id());
|
||||||
dtl.put("material_code", materDao.getMaterial_code());
|
dtl.put("material_code", materDao.getMaterial_code());
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -28,7 +28,10 @@
|
|||||||
将文件拖到此处,或
|
将文件拖到此处,或
|
||||||
<em>点击上传</em>
|
<em>点击上传</em>
|
||||||
</div>
|
</div>
|
||||||
<div slot="tip" class="el-upload__tip">只能上传Excel文件,且不超过10MB</div>
|
<div slot="tip" class="el-upload__tip">
|
||||||
|
只能上传Excel文件,且不超过10MB
|
||||||
|
<el-button type="text" @click="downloadImportTemplate">下载模板</el-button>
|
||||||
|
</div>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
<span slot="footer" class="dialog-footer">
|
<span slot="footer" class="dialog-footer">
|
||||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
@@ -96,6 +99,35 @@ export default {
|
|||||||
uploadByJsqd(file) {
|
uploadByJsqd(file) {
|
||||||
this.file1 = file
|
this.file1 = file
|
||||||
},
|
},
|
||||||
|
downloadImportTemplate() {
|
||||||
|
crudMaterial.downloadImportMaterialTemplate().then(res => {
|
||||||
|
// 1. 创建Blob对象
|
||||||
|
const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
||||||
|
|
||||||
|
// 2. 创建临时下载链接
|
||||||
|
const downloadUrl = window.URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
// 3. 创建隐藏的<a>标签
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = downloadUrl;
|
||||||
|
|
||||||
|
// 设置下载文件名(根据后端返回或固定名称)
|
||||||
|
link.download = '物料导入模板.xlsx';
|
||||||
|
|
||||||
|
// 4. 添加到DOM并触发点击
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
|
||||||
|
// 5. 清理资源
|
||||||
|
document.body.removeChild(link);
|
||||||
|
window.URL.revokeObjectURL(downloadUrl);
|
||||||
|
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('下载失败:', error);
|
||||||
|
// 这里可以添加错误提示,如ElementUI的Message
|
||||||
|
this.$message.error('模板下载失败,请重试');
|
||||||
|
})
|
||||||
|
},
|
||||||
submit() {
|
submit() {
|
||||||
if (this.beforeAvatarUpload(this.file1)) {
|
if (this.beforeAvatarUpload(this.file1)) {
|
||||||
this.fileList.name = this.file1.name
|
this.fileList.name = this.file1.name
|
||||||
|
|||||||
@@ -62,4 +62,12 @@ export function excelImport(data) {
|
|||||||
data
|
data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
export default { add, edit, del, excelImport, getMaterOptType, isAlongMaterType, getProductSeries, materialSync }
|
|
||||||
|
export function downloadImportMaterialTemplate(data) {
|
||||||
|
return request({
|
||||||
|
url: 'api/Materia/downloadImportMaterialTemplate',
|
||||||
|
method: 'get',
|
||||||
|
responseType: 'blob'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
export default { add, edit, del, excelImport, getMaterOptType, isAlongMaterType, getProductSeries, materialSync, downloadImportMaterialTemplate }
|
||||||
|
|||||||
157
lms/nladmin-ui/src/views/wms/basedata/measure/UploadDialog.vue
Normal file
157
lms/nladmin-ui/src/views/wms/basedata/measure/UploadDialog.vue
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
<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
|
||||||
|
<el-button type="text" @click="downloadImportTemplate">下载模板</el-button>
|
||||||
|
</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 crudmeasure from './mdPbMeasureunit'
|
||||||
|
import CRUD, { crud } from '@crud/crud'
|
||||||
|
import { download2 } from '@/api/data'
|
||||||
|
import { downloadFile } from '@/utils'
|
||||||
|
|
||||||
|
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
|
||||||
|
},
|
||||||
|
downloadImportTemplate() {
|
||||||
|
crudmeasure.downloadImportUnitTemplate().then(res => {
|
||||||
|
// 1. 创建Blob对象
|
||||||
|
const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
||||||
|
|
||||||
|
// 2. 创建临时下载链接
|
||||||
|
const downloadUrl = window.URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
// 3. 创建隐藏的<a>标签
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = downloadUrl;
|
||||||
|
|
||||||
|
// 设置下载文件名(根据后端返回或固定名称)
|
||||||
|
link.download = '单位导入模板.xlsx';
|
||||||
|
|
||||||
|
// 4. 添加到DOM并触发点击
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
|
||||||
|
// 5. 清理资源
|
||||||
|
document.body.removeChild(link);
|
||||||
|
window.URL.revokeObjectURL(downloadUrl);
|
||||||
|
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('下载失败:', error);
|
||||||
|
// 这里可以添加错误提示,如ElementUI的Message
|
||||||
|
this.$message.error('模板下载失败,请重试');
|
||||||
|
})
|
||||||
|
},
|
||||||
|
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:传递参数
|
||||||
|
crudmeasure.excelImport(formdata).then((res) => {
|
||||||
|
this.crud.notify('导入成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
||||||
|
this.$emit('tableChanged3', '')
|
||||||
|
this.$emit('update:dialogShow', false)
|
||||||
|
}).catch(err => {
|
||||||
|
|
||||||
|
const list = err.response.data.message
|
||||||
|
download2('/api/produceWorkorder/download', list).then(result => {
|
||||||
|
downloadFile(result, '错误信息汇总', 'xlsx')
|
||||||
|
crud.downloadLoading = false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.crud.notify('文件过大,请上传小于10MB的文件〜', CRUD.NOTIFICATION_TYPE.WARNING)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
@@ -13,7 +13,18 @@
|
|||||||
/>
|
/>
|
||||||
<rrOperation />
|
<rrOperation />
|
||||||
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
||||||
<crudOperation :permission="permission" />
|
<crudOperation :permission="permission">
|
||||||
|
<el-button
|
||||||
|
slot="right"
|
||||||
|
class="filter-item"
|
||||||
|
type="warning"
|
||||||
|
icon="el-icon-upload2"
|
||||||
|
size="mini"
|
||||||
|
@click="uploadShow = true"
|
||||||
|
>
|
||||||
|
导入
|
||||||
|
</el-button>
|
||||||
|
</crudOperation>
|
||||||
<!--表单组件-->
|
<!--表单组件-->
|
||||||
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
|
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
|
||||||
<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
|
<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
|
||||||
@@ -70,6 +81,7 @@
|
|||||||
<!--分页组件-->
|
<!--分页组件-->
|
||||||
<pagination />
|
<pagination />
|
||||||
</div>
|
</div>
|
||||||
|
<upload-dialog :dialog-show.sync="uploadShow"/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -80,11 +92,12 @@ import rrOperation from '@crud/RR.operation'
|
|||||||
import crudOperation from '@crud/CRUD.operation'
|
import crudOperation from '@crud/CRUD.operation'
|
||||||
import udOperation from '@crud/UD.operation'
|
import udOperation from '@crud/UD.operation'
|
||||||
import pagination from '@crud/Pagination'
|
import pagination from '@crud/Pagination'
|
||||||
|
import UploadDialog from './UploadDialog.vue'
|
||||||
const defaultForm = { measure_unit_id: null, unit_code: null, unit_name: null, qty_precision: null, is_used: '1', create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null, is_delete: null, ext_id: null }
|
const defaultForm = { measure_unit_id: null, unit_code: null, unit_name: null, qty_precision: null, is_used: '1', create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null, is_delete: null, ext_id: null }
|
||||||
export default {
|
export default {
|
||||||
dicts: ['is_used'],
|
dicts: ['is_used'],
|
||||||
name: 'MdPbMeasureunit',
|
name: 'MdPbMeasureunit',
|
||||||
components: { pagination, crudOperation, rrOperation, udOperation },
|
components: { UploadDialog, pagination, crudOperation, rrOperation, udOperation },
|
||||||
mixins: [presenter(), header(), form(defaultForm), crud()],
|
mixins: [presenter(), header(), form(defaultForm), crud()],
|
||||||
cruds() {
|
cruds() {
|
||||||
return CRUD({ title: '计量单位',
|
return CRUD({ title: '计量单位',
|
||||||
@@ -101,6 +114,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
permission: {
|
permission: {
|
||||||
},
|
},
|
||||||
|
uploadShow: false,
|
||||||
rules: {
|
rules: {
|
||||||
measure_unit_id: [
|
measure_unit_id: [
|
||||||
{ required: true, message: '不能为空', trigger: 'blur' }
|
{ required: true, message: '不能为空', trigger: 'blur' }
|
||||||
|
|||||||
@@ -32,4 +32,20 @@ export function getUnit(params) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { add, edit, del, getUnit }
|
export function excelImport(data) {
|
||||||
|
return request({
|
||||||
|
url: 'api/mdPbMeasureunit/importExcel',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function downloadImportUnitTemplate(data) {
|
||||||
|
return request({
|
||||||
|
url: 'api/mdPbMeasureunit/downloadImportUnitTemplate',
|
||||||
|
method: 'get',
|
||||||
|
responseType: 'blob'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { add, edit, del, getUnit, excelImport, downloadImportUnitTemplate }
|
||||||
|
|||||||
Reference in New Issue
Block a user