1438 发货管理-基础信息-老鼠图页面添加导入导出功能

This commit is contained in:
10001392 2026-04-17 15:05:48 +08:00
parent 79bad56f77
commit ff37f00ec2
8 changed files with 798 additions and 0 deletions

View File

@ -0,0 +1,96 @@
package com.nflg.wms.common.pojo.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import org.ttzero.excel.annotation.ExcelColumn;
import org.ttzero.excel.annotation.MediaColumn;
import java.math.BigDecimal;
@Data
@Accessors(chain = true)
public class ShipmentMaterialExcelExportDTO {
/**
* 物料编号
*/
@ExcelColumn("物料编号")
private String no;
/**
* 物料描述
*/
@ExcelColumn("物料描述")
private String describe;
/**
* 英文描述
*/
@ExcelColumn("英文描述")
private String describeEn;
/**
* 图号
*/
@ExcelColumn("图号")
private String drawingNo;
/**
* 重量
*/
@ExcelColumn("重量")
private BigDecimal weight;
/**
* 长度
*/
@ExcelColumn("长度")
private BigDecimal length;
/**
* 宽度
*/
@ExcelColumn("宽度")
private BigDecimal width;
/**
* 高度
*/
@ExcelColumn("高度")
private BigDecimal height;
/**
* 图片URL
*/
@MediaColumn
private String image;
/**
* 图片类型
*/
private String imageType;
//
// /**
// * 创建人
// */
// @ExcelColumn("创建人")
// private String createBy;
//
// /**
// * 创建时间
// */
// @ExcelColumn("创建时间")
// private String createTime;
//
// /**
// * 最后更新人
// */
// @ExcelColumn("最后更新人")
// private String updateBy;
//
// /**
// * 最后更新时间
// */
// @ExcelColumn("最后更新时间")
// private String updateTime;
}

View File

@ -0,0 +1,56 @@
package com.nflg.wms.common.pojo.dto;
import lombok.Data;
import org.ttzero.excel.annotation.ExcelColumn;
@Data
public class ShipmentMaterialExcelImportDTO {
/**
* 物料编号
*/
@ExcelColumn("*物料编号")
private String no;
/**
* 物料描述
*/
@ExcelColumn("物料描述")
private String describe;
/**
* 重量
*/
@ExcelColumn("*重量")
private String weight;
/**
* 长度
*/
@ExcelColumn("*长度")
private String length;
/**
* 宽度
*/
@ExcelColumn("*宽度")
private String width;
/**
* 高度
*/
@ExcelColumn("*高度")
private String height;
/**
* 图片URL
*/
@ExcelColumn("图片URL")
private String image;
/**
* 错误信息
*/
@ExcelColumn("错误信息")
private String error;
}

View File

@ -0,0 +1,41 @@
package com.nflg.wms.common.pojo.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import org.ttzero.excel.annotation.ExcelColumn;
@Data
@Accessors(chain = true)
public class ShipmentMaterialExcelTemplateExportDTO {
/**
* 物料编号
*/
@ExcelColumn("*物料编号")
private String no;
/**
* 重量
*/
@ExcelColumn("*重量")
private String weight;
/**
* 长度
*/
@ExcelColumn("*长度")
private String length;
/**
* 宽度
*/
@ExcelColumn("*宽度")
private String width;
/**
* 高度
*/
@ExcelColumn("*高度")
private String height;
}

View File

@ -0,0 +1,129 @@
package com.nflg.wms.scheduled.processor;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.nflg.wms.common.pojo.dto.BomMaterialDTO;
import com.nflg.wms.repository.entity.WmsShipmentMaterial;
import com.nflg.wms.repository.service.IWmsShipmentMaterialService;
import com.nflg.wms.starter.service.BomMaterialService;
import com.nflg.wms.starter.service.FileUploadService;
import jakarta.annotation.Resource;
import org.apache.commons.io.FilenameUtils;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
import tech.powerjob.worker.log.OmsLogger;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@Component(value = "shipmentMaterialZipImportProcessor")
public class ShipmentMaterialZipImportProcessor implements BasicProcessor {
@Resource
private IWmsShipmentMaterialService shipmentMaterialService;
@Resource
private BomMaterialService bomMaterialService;
@Resource
private FileUploadService fileUploadService;
@Override
public ProcessResult process(TaskContext context) throws Exception {
OmsLogger omsLogger = context.getOmsLogger();
List<String> params = StrUtil.split(context.getInstanceParams(), "|");
String zipUrl = CollectionUtil.get(params, 0);
String userName = CollectionUtil.get(params, 1);
if (StrUtil.isBlank(zipUrl)) {
omsLogger.error("无效的zip地址");
return new ProcessResult(false, "无效的zip地址");
}
try (InputStream is = new URL(zipUrl).openStream(); ZipInputStream zis = new ZipInputStream(is)) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String name = entry.getName();
omsLogger.info("开始处理文件:{}", name);
if (!entry.isDirectory()) {
ByteArrayOutputStream osOut = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = zis.read(buffer)) > 0) {
osOut.write(buffer, 0, len);
}
String materialNo = name.substring(0, name.lastIndexOf("."));
omsLogger.info("物料编号:{}", materialNo);
BomMaterialDTO bomMaterialDTO = bomMaterialService.getMaterialInfo(materialNo);
if (Objects.isNull(bomMaterialDTO)) {
omsLogger.error("主数据中未查找到该物料:{}", materialNo);
} else {
String picUrl = "";
try (ByteArrayInputStream isIn = new ByteArrayInputStream(osOut.toByteArray())) {
picUrl = fileUploadService.upload(buildFilePath(name), isIn, MediaType.IMAGE_JPEG_VALUE);
omsLogger.info("上传后的图片地址:{}", picUrl);
} catch (Exception ex) {
omsLogger.error("上传图片失败:{}", ex.getMessage());
}
WmsShipmentMaterial old = shipmentMaterialService.lambdaQuery()
.eq(WmsShipmentMaterial::getNo, materialNo)
.orderByDesc(WmsShipmentMaterial::getId)
.last("LIMIT 1")
.one();
if (Objects.isNull(old) || StrUtil.isNotBlank(old.getImage())) {
omsLogger.info("添加老鼠图");
WmsShipmentMaterial material = new WmsShipmentMaterial()
.setNo(bomMaterialDTO.getMaterialNo())
.setDescribe(bomMaterialDTO.getMaterialDesc())
.setDrawingNo(bomMaterialDTO.getDrawingNo())
.setImage(picUrl)
.setWeight(BigDecimal.ZERO)
.setLength(BigDecimal.ZERO)
.setWidth(BigDecimal.ZERO)
.setHeight(BigDecimal.ZERO)
.setCreateBy(userName)
.setCreateTime(LocalDateTime.now());
if (shipmentMaterialService.save(material)) {
omsLogger.info("保存成功,id:" + material.getId());
} else {
omsLogger.error("保存失败");
}
} else {
omsLogger.info("更新老鼠图");
old.setImage(picUrl);
old.setUpdateBy(userName);
old.setUpdateTime(LocalDateTime.now());
if (shipmentMaterialService.updateById(old)) {
omsLogger.info("更新成功,id:" + old.getId());
} else {
omsLogger.error("更新失败");
}
}
}
}
omsLogger.info("处理完毕");
omsLogger.info("-----------------------------------------");
zis.closeEntry();
}
}
return new ProcessResult(true, "处理完毕");
}
private String buildFilePath(String fileName) {
String fileType = "." + FilenameUtils.getExtension(fileName);
return StrUtil.format("admin/task/{}/{}/{}{}", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
, RandomUtil.randomString(4), IdUtil.fastUUID(), fileType);
}
}

View File

@ -135,6 +135,21 @@
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-client</artifactId>
<exclusions>
<exclusion>
<artifactId>checker-qual</artifactId>
<groupId>org.checkerframework</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,27 @@
package com.nflg.wms.shipment.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import tech.powerjob.client.PowerJobClient;
@Configuration
@Lazy
public class PowerJobClientConfig {
@Value("${powerjob.worker.server-address}")
private String serverAddress;
@Value("${powerjob.worker.app-name}")
private String appName;
@Value("${powerjob.client.password}")
private String password;
@Bean
@Lazy
public PowerJobClient initPowerJobClient() {
return new PowerJobClient(serverAddress, appName, password);
}
}

View File

@ -16,17 +16,23 @@ import com.nflg.wms.common.util.UserUtil;
import com.nflg.wms.common.util.VUtil;
import com.nflg.wms.repository.entity.WmsShipmentMaterial;
import com.nflg.wms.repository.service.IWmsShipmentMaterialService;
import com.nflg.wms.shipment.service.ShipmentMaterialControllerService;
import com.nflg.wms.starter.BaseController;
import com.nflg.wms.starter.service.BomMaterialService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@ -45,6 +51,9 @@ public class MaterialController extends BaseController {
@Resource
private BomMaterialService bomMaterialService;
@Resource
private ShipmentMaterialControllerService shipmentMaterialControllerService;
/**
* 新增图纸
*/
@ -188,4 +197,52 @@ public class MaterialController extends BaseController {
shipmentMaterialService.remove(new LambdaQueryWrapper<WmsShipmentMaterial>().in(WmsShipmentMaterial::getNo, nos));
return ApiResult.success();
}
/**
* 导出选择的数据
* @param ids id列表为空时导出模板
*/
@PostMapping("exportSelect")
public void exportSelect(HttpServletResponse response, @RequestBody(required = false) List<Long> ids) throws Exception {
shipmentMaterialControllerService.exportSelect(response, ids);
}
/**
* 导出搜索结果
* @param request 搜索参数
*/
@PostMapping("exportSearch")
public void exportSearch(HttpServletResponse response, @Valid @RequestBody ShipmentMaterialSearchQO request) throws Exception {
shipmentMaterialControllerService.exportSearch(response, request);
}
/**
* 导入
* @param file 文件
*/
@Transactional
@PostMapping("import")
public ApiResult importFromExcel(@RequestParam(value = "file") MultipartFile file) throws IOException {
return shipmentMaterialControllerService.importFromExcel(file);
}
/**
* 批量上传物料图片
* @param files 文件列表
*/
@Transactional
@PostMapping("uploadPics")
public ApiResult uploadPics(@Valid @RequestParam("files") @NotEmpty List<MultipartFile> files) throws Exception {
return shipmentMaterialControllerService.uploadPics(files);
}
/**
* 上传物料图片zip压缩包
* @param file zip压缩包
*/
@Transactional
@PostMapping("uploadZip")
public ApiResult uploadZip(@Valid @RequestParam("file") @NotNull MultipartFile file) throws Exception {
return shipmentMaterialControllerService.uploadZip(file);
}
}

View File

@ -0,0 +1,377 @@
package com.nflg.wms.shipment.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.nflg.wms.common.pojo.ApiResult;
import com.nflg.wms.common.pojo.dto.*;
import com.nflg.wms.common.pojo.qo.ShipmentMaterialSearchQO;
import com.nflg.wms.common.util.DateTimeUtil;
import com.nflg.wms.common.util.EecExcelUtil;
import com.nflg.wms.common.util.UserUtil;
import com.nflg.wms.common.util.VUtil;
import com.nflg.wms.repository.entity.WmsShipmentMaterial;
import com.nflg.wms.repository.service.IWmsShipmentMaterialService;
import com.nflg.wms.starter.service.BomMaterialService;
import com.nflg.wms.starter.service.FileUploadService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.ttzero.excel.entity.ListSheet;
import org.ttzero.excel.entity.Workbook;
import tech.powerjob.client.PowerJobClient;
import tech.powerjob.common.request.query.JobInfoQuery;
import tech.powerjob.common.response.JobInfoDTO;
import tech.powerjob.common.response.ResultDTO;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Component
public class ShipmentMaterialControllerService {
@Resource
private IWmsShipmentMaterialService shipmentMaterialService;
@Resource
private BomMaterialService bomMaterialService;
@Resource
private FileUploadService fileUploadService;
@Resource
private PowerJobClient powerJobClient;
/**
* 导出选择的数据
* @param response HTTP响应
* @param ids id列表为空时导出模板
*/
public void exportSelect(HttpServletResponse response, List<Long> ids) throws IOException {
if (CollectionUtil.isEmpty(ids)) {
exportTemplate(response);
} else {
List<WmsShipmentMaterial> materials = shipmentMaterialService.listByIds(ids);
List<ShipmentMaterialExcelExportDTO> datas = materials.stream()
.map(model -> Convert.convert(ShipmentMaterialExcelExportDTO.class, model))
.collect(Collectors.toList());
// 设置图片类型
datas.forEach(dto -> {
if (StrUtil.isNotBlank(dto.getImage())) {
String image = dto.getImage();
int lastDotIndex = image.lastIndexOf(".");
if (lastDotIndex > 0 && lastDotIndex < image.length() - 1) {
dto.setImageType(image.substring(lastDotIndex + 1));
}
}
});
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("老鼠图导出.xlsx", StandardCharsets.UTF_8));
if (CollectionUtil.isEmpty(datas)) {
exportTemplate(response);
} else {
new Workbook()
.addSheet(new ListSheet<>(datas).setRowHeight(100))
.writeTo(response.getOutputStream());
}
}
}
/**
* 导出模板
*/
private void exportTemplate(HttpServletResponse response) throws IOException {
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("老鼠图导入模板.xlsx", StandardCharsets.UTF_8));
List<ShipmentMaterialExcelTemplateExportDTO> datas = new ArrayList<>();
datas.add(new ShipmentMaterialExcelTemplateExportDTO()
.setNo("")
.setWeight("")
.setLength("")
.setWidth("")
.setHeight(""));
new Workbook()
.addSheet(new ListSheet<>(datas))
.writeTo(response.getOutputStream());
}
/**
* 导出搜索结果
*/
public void exportSearch(HttpServletResponse response, @Valid ShipmentMaterialSearchQO request) throws IOException {
List<WmsShipmentMaterial> list = shipmentMaterialService.lambdaQuery()
.like(StrUtil.isNotBlank(request.getNo()), WmsShipmentMaterial::getNo, request.getNo())
.like(StrUtil.isNotBlank(request.getDescribe()), WmsShipmentMaterial::getDescribe, request.getDescribe())
.like(StrUtil.isNotBlank(request.getDrawingNo()), WmsShipmentMaterial::getDrawingNo, request.getDrawingNo())
.orderByDesc(WmsShipmentMaterial::getId)
.list();
List<ShipmentMaterialExcelExportDTO> datas = list.stream()
.map(model -> Convert.convert(ShipmentMaterialExcelExportDTO.class, model))
.collect(Collectors.toList());
// 设置图片类型
datas.forEach(dto -> {
if (StrUtil.isNotBlank(dto.getImage())) {
String image = dto.getImage();
int lastDotIndex = image.lastIndexOf(".");
if (lastDotIndex > 0 && lastDotIndex < image.length() - 1) {
dto.setImageType(image.substring(lastDotIndex + 1));
}
}
});
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("老鼠图导出.xlsx", StandardCharsets.UTF_8));
new Workbook()
.addSheet(new ListSheet<>(datas).setRowHeight(100))
.writeTo(response.getOutputStream());
}
/**
* 从Excel导入
*/
@Transactional
public ApiResult importFromExcel(MultipartFile file) throws IOException {
List<ShipmentMaterialExcelImportDTO> data = EecExcelUtil.getExcelContext(file.getInputStream(), ShipmentMaterialExcelImportDTO.class);
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(data)).throwMessage("导入文件内容为空");
if (checkAndImport(data)) {
return ApiResult.success();
} else {
try (ByteArrayOutputStream osOut = new ByteArrayOutputStream()) {
new Workbook()
.addSheet(new ListSheet<>(data))
.writeTo(osOut);
try (ByteArrayInputStream isIn = new ByteArrayInputStream(osOut.toByteArray())) {
String errorFileUrl = fileUploadService.upload("temp/" + DateTimeUtil.format(LocalDate.now(), "yyyyMMdd") + "/" + IdUtil.fastUUID() + ".xlsx", isIn, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
return ApiResult.error("导入文件失败,错误文件:" + errorFileUrl);
}
} catch (Exception e) {
return ApiResult.error("保存文件出错");
}
}
}
/**
* 校验并导入数据
*/
@Transactional
public boolean checkAndImport(List<ShipmentMaterialExcelImportDTO> data) {
List<WmsShipmentMaterial> forAdd = new ArrayList<>();
List<WmsShipmentMaterial> forUpdate = new ArrayList<>();
// 获取已存在的物料
List<String> materialNos = data.stream()
.map(ShipmentMaterialExcelImportDTO::getNo)
.filter(StrUtil::isNotBlank)
.distinct()
.collect(Collectors.toList());
List<WmsShipmentMaterial> dbMaterials = CollectionUtil.isNotEmpty(materialNos)
? shipmentMaterialService.lambdaQuery()
.in(WmsShipmentMaterial::getNo, materialNos)
.list()
: new ArrayList<>();
// 从BOM系统获取物料信息
List<BomMaterialDTO> bomMaterials = bomMaterialService.getList(
data.stream().map(ShipmentMaterialExcelImportDTO::getNo).collect(Collectors.toSet())
);
for (ShipmentMaterialExcelImportDTO dto : data) {
StringBuilder sb = new StringBuilder();
WmsShipmentMaterial material = new WmsShipmentMaterial();
// 校验物料编号
if (StrUtil.isBlank(dto.getNo())) {
sb.append("物料编号不能为空;");
} else {
BomMaterialDTO bomMaterial = bomMaterials.stream()
.filter(m -> StrUtil.equals(dto.getNo(), m.getMaterialNo()))
.findFirst()
.orElse(null);
if (Objects.isNull(bomMaterial)) {
sb.append("物料编号无效;");
} else {
WmsShipmentMaterial existingMaterial = dbMaterials.stream()
.filter(m -> StrUtil.equals(m.getNo(), dto.getNo()))
.findFirst()
.orElse(null);
if (Objects.nonNull(existingMaterial)) {
material.setId(existingMaterial.getId());
material.setUpdateBy(UserUtil.getUserName());
material.setUpdateTime(LocalDateTime.now());
forUpdate.add(material);
} else {
material.setCreateBy(UserUtil.getUserName());
material.setCreateTime(LocalDateTime.now());
forAdd.add(material);
}
material.setNo(dto.getNo());
material.setDescribe(bomMaterial.getMaterialDesc());
material.setDescribeEn(bomMaterial.getMaterialDescEn());
material.setDrawingNo(bomMaterial.getDrawingNo());
}
}
// 校验重量
if (StrUtil.isNotBlank(dto.getWeight())) {
if (!NumberUtils.isCreatable(dto.getWeight())) {
sb.append("重量无效;");
} else {
material.setWeight(new BigDecimal(dto.getWeight()));
}
}
// 校验长度
if (StrUtil.isNotBlank(dto.getLength())) {
if (!NumberUtils.isCreatable(dto.getLength())) {
sb.append("长度无效;");
} else {
material.setLength(new BigDecimal(dto.getLength()));
}
}
// 校验宽度
if (StrUtil.isNotBlank(dto.getWidth())) {
if (!NumberUtils.isCreatable(dto.getWidth())) {
sb.append("宽度无效;");
} else {
material.setWidth(new BigDecimal(dto.getWidth()));
}
}
// 校验高度
if (StrUtil.isNotBlank(dto.getHeight())) {
if (!NumberUtils.isCreatable(dto.getHeight())) {
sb.append("高度无效;");
} else {
material.setHeight(new BigDecimal(dto.getHeight()));
}
}
material.setImage(dto.getImage());
dto.setError(sb.toString());
}
// 如果没有错误执行保存
if (data.stream().noneMatch(it -> StrUtil.isNotBlank(it.getError()))) {
if (CollectionUtil.isNotEmpty(forAdd)) {
shipmentMaterialService.saveBatch(forAdd, 1000);
}
if (CollectionUtil.isNotEmpty(forUpdate)) {
shipmentMaterialService.updateBatchById(forUpdate, 1000);
}
return true;
}
return false;
}
/**
* 批量上传老鼠图
*/
@Transactional
public ApiResult uploadPics(List<MultipartFile> files) throws Exception {
List<String> pics = new ArrayList<>();
List<WmsShipmentMaterial> materials = new ArrayList<>();
for (MultipartFile file : files) {
String name = file.getOriginalFilename();
VUtil.trueThrowBusinessError(StrUtil.isBlank(name)).throwMessage("文件名不能为空");
String materialNo = name.substring(0, name.lastIndexOf("."));
BomMaterialDTO bomMaterialDTO = bomMaterialService.getMaterialInfo(materialNo);
if (Objects.isNull(bomMaterialDTO)) {
pics.add(name);
} else {
String url = fileUploadService.upload(buildFilePath(name), file);
WmsShipmentMaterial existingMaterial = shipmentMaterialService.lambdaQuery()
.eq(WmsShipmentMaterial::getNo, materialNo)
.one();
if (Objects.isNull(existingMaterial) || StrUtil.isNotBlank(existingMaterial.getImage())) {
WmsShipmentMaterial material = new WmsShipmentMaterial()
.setNo(bomMaterialDTO.getMaterialNo())
.setDescribe(bomMaterialDTO.getMaterialDesc())
.setDescribeEn(bomMaterialDTO.getMaterialDescEn())
.setDrawingNo(bomMaterialDTO.getDrawingNo())
.setImage(url)
.setCreateBy(UserUtil.getUserName())
.setCreateTime(LocalDateTime.now());
materials.add(material);
} else {
existingMaterial.setImage(url);
existingMaterial.setUpdateBy(UserUtil.getUserName());
existingMaterial.setUpdateTime(LocalDateTime.now());
materials.add(existingMaterial);
}
}
}
if (CollectionUtil.isEmpty(pics)) {
if (CollectionUtil.isNotEmpty(materials)) {
shipmentMaterialService.saveOrUpdateBatch(materials);
}
return ApiResult.success();
} else {
return ApiResult.error("以下图片物料编号无效:" + StrUtil.join(",", pics));
}
}
/**
* 构建文件路径
*/
private String buildFilePath(String fileName) {
String fileType = "." + FilenameUtils.getExtension(fileName);
return StrUtil.format("shipment/{}/{}/{}/{}{}",
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")),
UserUtil.getUserId(),
RandomUtil.randomString(4),
IdUtil.fastUUID(),
fileType);
}
/**
* 上传老鼠图zip压缩包
*/
@Transactional
public ApiResult uploadZip(@Valid @NotEmpty MultipartFile file) throws Exception {
String name = file.getOriginalFilename();
VUtil.trueThrowBusinessError(!StrUtil.endWith(name, ".zip")).throwMessage("请上传zip格式的压缩包");
String url = fileUploadService.upload(buildFilePath(name), file);
JobInfoQuery query = new JobInfoQuery();
query.setJobNameEq("老鼠图zip导入");
ResultDTO<List<JobInfoDTO>> result = powerJobClient.queryJob(query);
if (result.isSuccess()) {
powerJobClient.runJob(result.getData().get(0).getId(),
url + "|" + UserUtil.getUserName(),
0);
return ApiResult.success("任务已提交");
} else {
return ApiResult.error(result.getMessage());
}
}
}