|
|
|
@ -3,6 +3,7 @@ package com.gaotao.modules.sop.service.impl; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.gaotao.common.utils.Base64FileUtil; |
|
|
|
import com.gaotao.common.utils.DateUtils; |
|
|
|
import com.gaotao.common.utils.RandomUtil; |
|
|
|
import com.gaotao.modules.oa.dto.ProductionRoutingItemDto; |
|
|
|
import com.gaotao.modules.report.dao.ProcedureDao; |
|
|
|
import com.gaotao.modules.sop.dao.FileManagementDao; |
|
|
|
@ -16,11 +17,16 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.nio.file.StandardCopyOption; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@ -255,4 +261,91 @@ public class SopFileServiceImpl implements SopFileService { |
|
|
|
log.debug("调用存储过程UspInsertSOP成功, 订单号: {}, 序号: {}", item.getOrderNo(), item.getItemNo()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public List<Map<String, Object>> batchUploadLocalToFileManagement(MultipartFile[] files, String site, String buNo, String partNo, String createdBy) { |
|
|
|
if (files == null || files.length == 0) { |
|
|
|
throw new RuntimeException("上传文件不能为空"); |
|
|
|
} |
|
|
|
if (!StringUtils.hasText(site) || !StringUtils.hasText(buNo)) { |
|
|
|
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"); |
|
|
|
Date now = new Date(); |
|
|
|
for (MultipartFile file : files) { |
|
|
|
if (file == null || file.isEmpty()) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
String originalFilename = file.getOriginalFilename(); |
|
|
|
if (!StringUtils.hasText(originalFilename)) { |
|
|
|
originalFilename = "file"; |
|
|
|
} |
|
|
|
int lastDot = originalFilename.lastIndexOf('.'); |
|
|
|
String suffix = lastDot >= 0 ? originalFilename.substring(lastDot) : ""; |
|
|
|
String fileSuffix = ""; |
|
|
|
if (lastDot > 0 && lastDot < originalFilename.length() - 1) { |
|
|
|
fileSuffix = originalFilename.substring(lastDot + 1).toLowerCase(); |
|
|
|
} |
|
|
|
if (!StringUtils.hasText(fileSuffix) && suffix.length() > 1) { |
|
|
|
fileSuffix = suffix.substring(1).toLowerCase(); |
|
|
|
} |
|
|
|
if (!StringUtils.hasText(fileSuffix)) { |
|
|
|
fileSuffix = "bin"; |
|
|
|
} |
|
|
|
String dateDir = dateFormat.format(now); |
|
|
|
String targetDir = SOP_ROOT_DIR + File.separator + dateDir; |
|
|
|
File dir = new File(targetDir); |
|
|
|
if (!dir.exists() && !dir.mkdirs()) { |
|
|
|
throw new RuntimeException("无法创建目录: " + targetDir); |
|
|
|
} |
|
|
|
String timePrefix = timeFormat.format(now); |
|
|
|
String newFileNameOnDisk = timePrefix + "_" + originalFilename; |
|
|
|
String fullPath = targetDir + File.separator + newFileNameOnDisk; |
|
|
|
try (InputStream is = file.getInputStream()) { |
|
|
|
Files.copy(is, Paths.get(fullPath), StandardCopyOption.REPLACE_EXISTING); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("保存SOP文件失败: {}", fullPath, e); |
|
|
|
throw new RuntimeException("保存文件失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
FileManagementEntity entity = new FileManagementEntity(); |
|
|
|
entity.setSite(site); |
|
|
|
entity.setBuNo(buNo); |
|
|
|
entity.setOrderNo(""); |
|
|
|
entity.setItemNo(""); |
|
|
|
entity.setPartNo(""); |
|
|
|
entity.setFileNo(originalFilename); |
|
|
|
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.setSourceSystem("MES"); |
|
|
|
entity.setCreateDate(now); |
|
|
|
entity.setCreatedBy(operator); |
|
|
|
entity.setStatusTb("0"); |
|
|
|
entity.setStatus("有效"); |
|
|
|
entity.setPublicFlag("N"); |
|
|
|
entity.setWorkCenterNo(null); |
|
|
|
entity.setChecksum(null); |
|
|
|
fileManagementDao.insert(entity); |
|
|
|
Map<String, Object> row = new HashMap<>(); |
|
|
|
row.put("fileNo", originalFilename); |
|
|
|
row.put("fileName", originalFilename); |
|
|
|
row.put("sopUrl", fullPath); |
|
|
|
rows.add(row); |
|
|
|
} |
|
|
|
if (rows.isEmpty()) { |
|
|
|
throw new RuntimeException("没有有效的上传文件"); |
|
|
|
} |
|
|
|
return rows; |
|
|
|
} |
|
|
|
|
|
|
|
} |