|
|
|
@ -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); |
|
|
|
|