Browse Source

2026-03-31

物料档案管理-》SOP清单页签优化上传文件功能
master
fengyuan_yang 2 weeks ago
parent
commit
311d14b28e
  1. 7
      src/main/java/com/gaotao/modules/pms/controller/QcController.java
  2. 2
      src/main/java/com/gaotao/modules/sop/service/SopFileService.java
  3. 76
      src/main/java/com/gaotao/modules/sop/service/impl/SopFileServiceImpl.java

7
src/main/java/com/gaotao/modules/pms/controller/QcController.java

@ -1898,9 +1898,10 @@ public class QcController {
@RequestParam("file") MultipartFile[] files,
@RequestParam("site") String site,
@RequestParam("buNo") String buNo,
@RequestParam(value = "partNo", required = false) String partNo,
@RequestParam(value = "createBy", required = false) String createBy) {
List<Map<String, Object>> rows = sopFileService.batchUploadLocalToFileManagement(files, site, buNo, partNo, createBy);
@RequestParam(value = "createBy", required = false) String createBy,
@RequestParam(value = "fileMetaData", required = false) String fileMetaData) {
List<Map<String, Object>> rows = sopFileService.batchUploadLocalToFileManagement(
files, site, buNo, createBy, fileMetaData);
return R.ok().put("rows", rows);
}

2
src/main/java/com/gaotao/modules/sop/service/SopFileService.java

@ -22,5 +22,5 @@ public interface SopFileService {
/**
* 物料档案本机多文件上传落盘 D:\sop_files 并直接 INSERT file_management不调用存储过程
*/
List<Map<String, Object>> batchUploadLocalToFileManagement(MultipartFile[] files, String site, String buNo, String partNo, String createdBy);
List<Map<String, Object>> batchUploadLocalToFileManagement(MultipartFile[] files, String site, String buNo, String createdBy, String fileMetaData);
}

76
src/main/java/com/gaotao/modules/sop/service/impl/SopFileServiceImpl.java

@ -18,6 +18,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.*;
import java.nio.file.Files;
@ -263,7 +266,7 @@ public class SopFileServiceImpl implements SopFileService {
@Override
@Transactional(rollbackFor = Exception.class)
public List<Map<String, Object>> batchUploadLocalToFileManagement(MultipartFile[] files, String site, String buNo, String partNo, String createdBy) {
public List<Map<String, Object>> batchUploadLocalToFileManagement(MultipartFile[] files, String site, String buNo, String createdBy, String fileMetaData) {
if (files == null || files.length == 0) {
throw new RuntimeException("上传文件不能为空");
}
@ -271,12 +274,23 @@ public class SopFileServiceImpl implements SopFileService {
throw new RuntimeException("site、buNo 不能为空");
}
String operator = StringUtils.hasText(createdBy) ? createdBy : "MES_UPLOAD";
String partNoVal = StringUtils.hasText(partNo) ? partNo.trim() : null;
List<Map<String, Object>> rows = new ArrayList<>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
SimpleDateFormat parseFormat = new SimpleDateFormat("yyyy-MM-dd");
Date now = new Date();
for (MultipartFile file : files) {
JSONArray metaDataArray = null;
if (StringUtils.hasText(fileMetaData)) {
try {
metaDataArray = JSON.parseArray(fileMetaData);
} catch (Exception e) {
log.error("解析fileMetaData失败", e);
}
}
for (int i = 0; i < files.length; i++) {
MultipartFile file = files[i];
if (file == null || file.isEmpty()) {
continue;
}
@ -311,22 +325,64 @@ public class SopFileServiceImpl implements SopFileService {
log.error("保存SOP文件失败: {}", fullPath, e);
throw new RuntimeException("保存文件失败: " + e.getMessage());
}
JSONObject metaData = null;
if (metaDataArray != null && metaDataArray.size() > i) {
metaData = metaDataArray.getJSONObject(i);
}
String currentFileNo = originalFilename;
String currentSopType = "SOP";
String currentVersion = "A0";
String currentItemNo = "";
Date phaseInDate = now;
Date phaseOutDate = null;
if (metaData != null) {
if (StringUtils.hasText(metaData.getString("fileNo"))) {
currentFileNo = metaData.getString("fileNo");
}
if (StringUtils.hasText(metaData.getString("sopType"))) {
currentSopType = metaData.getString("sopType");
}
if (StringUtils.hasText(metaData.getString("version"))) {
currentVersion = metaData.getString("version");
}
if (StringUtils.hasText(metaData.getString("itemNo"))) {
currentItemNo = metaData.getString("itemNo");
}
if (StringUtils.hasText(metaData.getString("phaseInDate"))) {
try {
phaseInDate = parseFormat.parse(metaData.getString("phaseInDate"));
} catch (Exception e) {
log.error("解析生效日期失败: {}", metaData.getString("phaseInDate"));
}
}
if (StringUtils.hasText(metaData.getString("phaseOutDate"))) {
try {
phaseOutDate = parseFormat.parse(metaData.getString("phaseOutDate"));
} catch (Exception e) {
log.error("解析失效日期失败: {}", metaData.getString("phaseOutDate"));
}
}
}
FileManagementEntity entity = new FileManagementEntity();
entity.setSite(site);
entity.setBuNo(buNo);
entity.setOrderNo("");
entity.setItemNo("");
entity.setItemNo(currentItemNo);
entity.setPartNo("");
entity.setFileNo(originalFilename);
entity.setFileNo(currentFileNo);
entity.setFileName(originalFilename);
entity.setNewFileName(newFileNameOnDisk);
entity.setUrlAddRess(fullPath);
entity.setFileType("FORMATTACH");
entity.setFileSuffix(fileSuffix);
entity.setSopRevNo("A0");
entity.setSopType("SOP");
entity.setPhaseInDate(now);
entity.setPhaseOutDate(null);
entity.setSopRevNo(currentVersion);
entity.setSopType(currentSopType);
entity.setPhaseInDate(phaseInDate);
entity.setPhaseOutDate(phaseOutDate);
entity.setSourceSystem("MES");
entity.setCreateDate(now);
entity.setCreatedBy(operator);
@ -337,7 +393,7 @@ public class SopFileServiceImpl implements SopFileService {
entity.setChecksum(null);
fileManagementDao.insert(entity);
Map<String, Object> row = new HashMap<>();
row.put("fileNo", originalFilename);
row.put("fileNo", currentFileNo);
row.put("fileName", originalFilename);
row.put("sopUrl", fullPath);
rows.add(row);

Loading…
Cancel
Save