Browse Source

2026-03-23

SOP文件上传
master
fengyuan_yang 3 months ago
parent
commit
365f9bd969
  1. 18
      src/main/java/com/gaotao/modules/pms/controller/QcController.java
  2. 12
      src/main/java/com/gaotao/modules/sop/entity/FileManagementEntity.java
  3. 9
      src/main/java/com/gaotao/modules/sop/service/SopFileService.java
  4. 93
      src/main/java/com/gaotao/modules/sop/service/impl/SopFileServiceImpl.java

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

@ -13,6 +13,7 @@ import com.gaotao.modules.pms.entity.vo.PartInformationVo;
import com.gaotao.modules.pms.entity.vo.PartLabelTemplateVo;
import com.gaotao.modules.pms.service.QcBaseInfoService;
import com.gaotao.modules.pms.service.QcService;
import com.gaotao.modules.sop.service.SopFileService;
import com.gaotao.modules.pms.util.ResponseData;
import com.gaotao.modules.sys.entity.SysRoleEntity;
import com.gaotao.modules.sys.entity.SysSceneDynamicControlModelEntity;
@ -35,6 +36,9 @@ public class QcController {
@Autowired
private QcBaseInfoService qcBaseInfoService;
@Autowired
private SopFileService sopFileService;
// ======================= 检验方法API =======================
/**
@ -1886,6 +1890,20 @@ public class QcController {
return R.ok().put("page", page);
}
/**
* 物料档案 SOP批量本地上传落盘 D:\sop_files 并直接写入 file_management不调用存储过程
**/
@PostMapping("/sopFileBatchUpload")
public R sopFileBatchUpload(
@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);
return R.ok().put("rows", rows);
}
/**
* 保存SOP文件关联
**/

12
src/main/java/com/gaotao/modules/sop/entity/FileManagementEntity.java

@ -24,7 +24,8 @@ public class FileManagementEntity {
private String fileNo;
private String newFileName;
private String fileName;
private String urlAddRess; // 注意: DB是 url_add_ress
@TableField("url_add_ress")
private String urlAddRess;
private String fileType;
private String fileSuffix;
private String sopRevNo;
@ -38,18 +39,19 @@ public class FileManagementEntity {
private String status;
private String checksum;
@TableField(exist = false)
private String updateFlag; // 'Y' or 'N'
private String updateFlag; // 'Y' or 'N' UspInsertSOP 参数用不落表
/**
* 公共文件标识
* 公共文件标识对应 public_flag
*/
@TableField(exist = false)
private String publicFlag; // 'Y' or 'N'
@TableField("public_flag")
private String publicFlag;
@TableField(exist = false)
private String orderRef1;
@TableField(exist = false)
private String orderRef2;
@TableField(exist = false)
private String orderRef3;
@TableField("workcenter_no")
private String workCenterNo;
}

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

@ -2,6 +2,10 @@ package com.gaotao.modules.sop.service;
import com.gaotao.modules.sop.dto.SopFileRequestDto;
import com.gaotao.modules.sop.dto.SopFileResponseDto;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
/**
* SOP文件服务接口
@ -14,4 +18,9 @@ public interface SopFileService {
* @return 响应结果
*/
SopFileResponseDto processSopFile(SopFileRequestDto request);
/**
* 物料档案本机多文件上传落盘 D:\sop_files 并直接 INSERT file_management不调用存储过程
*/
List<Map<String, Object>> batchUploadLocalToFileManagement(MultipartFile[] files, String site, String buNo, String partNo, String createdBy);
}

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

@ -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;
}
}
Loading…
Cancel
Save