From d8d129a2e41f7099968cb4f4dc1b028ab985135f Mon Sep 17 00:00:00 2001
From: Fixiaobai <fixiaobai@163.com>
Date: 星期四, 16 十一月 2023 20:20:47 +0800
Subject: [PATCH] Changes14
---
mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/DocumentServiceImpl.java | 101 ++++++++++++++++++++++++++++++++++++++------------
1 files changed, 76 insertions(+), 25 deletions(-)
diff --git a/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/DocumentServiceImpl.java b/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/DocumentServiceImpl.java
index a9a9068..67c46ad 100644
--- a/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/DocumentServiceImpl.java
+++ b/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/DocumentServiceImpl.java
@@ -17,6 +17,7 @@
package com.chinaztt.mes.technology.service.impl;
import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.BooleanUtil;
@@ -53,6 +54,7 @@
import com.chinaztt.mes.technology.entity.*;
import com.chinaztt.mes.technology.excel.DocumentTestStandardData;
import com.chinaztt.mes.technology.excel.MaterialCostData;
+import com.chinaztt.mes.technology.feign.MesFileApi;
import com.chinaztt.mes.technology.mapper.*;
import com.chinaztt.mes.technology.service.DocumentJgtService;
import com.chinaztt.mes.technology.service.DocumentService;
@@ -72,13 +74,13 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.time.LocalDateTime;
@@ -127,6 +129,13 @@
private DocumentJgtMapper documentJgtMapper;
private DocumentJgtService documentJgtService;
private DocumentSamplingRuleMapper documentSamplingRuleMapper;
+
+ @Autowired
+ private MesFileApi mesFileApi;
+
+ private static final String locationImg="D:/file/img";
+
+ private static final String file_img_url = "http://127.0.0.1:6066/Image/img";
/**
* @Author: Hans
@@ -600,23 +609,61 @@
@SneakyThrows
@Override
- public R uploadJgt(List<MultipartFile> file, Long documentId) {
- List<DocumentJgt> list = new ArrayList<>();
- for (MultipartFile multipartFile:file) {
- String fileName = IdUtil.simpleUUID() + StrUtil.DOT + FileUtil.extName(multipartFile.getOriginalFilename());
- minioTemplate.putObject(OSS_BUCKET, fileName, multipartFile.getInputStream());
- DocumentJgt jgt = new DocumentJgt();
- jgt.setFileName(fileName);
- jgt.setDocumentId(documentId);
- list.add(jgt);
- }
- //宸ヨ壓涓昏〃鏇存柊鏃堕棿锛屾洿鏂颁汉
- Document document = new Document();
- document.setId(documentId);
- baseMapper.updateById(doUpdateRealUser(document));
- documentJgtService.saveBatch(list);
- List<String> fileNameList = list.stream().map(a -> a.getFileName()).collect(Collectors.toList());
- return R.ok(org.apache.commons.lang3.StringUtils.join(fileNameList,","));
+ public R uploadJgt(MultipartFile file, Long documentId) {
+ String requestUrl="";
+ String fileName = IdUtil.simpleUUID() + StrUtil.DOT + FileUtil.extName(file.getOriginalFilename());
+ //minioTemplate.putObject(OSS_BUCKET, fileName, multipartFile.getInputStream());
+ //鍒涘缓鏂囦欢澶�
+ String timeForder= DateUtil.format(DateUtil.date(),"yyyy/MM/dd");
+ String forder=locationImg+"/"+OSS_BUCKET+"/"+timeForder;
+ File filePath = new File(forder);
+ if(!filePath.exists()){
+ filePath.mkdirs();
+ }
+ //鍚堝苟鏂囦欢
+ RandomAccessFile raFile = null;
+ BufferedInputStream inputStream=null;
+ try{
+ File dirFile = new File(forder, fileName);
+ //浠ヨ鍐欑殑鏂瑰紡鎵撳紑鐩爣鏂囦欢
+ raFile = new RandomAccessFile(dirFile, "rw");
+ raFile.seek(raFile.length());
+ inputStream = new BufferedInputStream(file.getInputStream());
+ byte[] buf = new byte[1024];
+ int length = 0;
+ while ((length = inputStream.read(buf)) != -1) {
+ raFile.write(buf, 0, length);
+ }
+ requestUrl=OSS_BUCKET+"/"+timeForder+"/"+fileName;
+ }catch(Exception e){
+ e.printStackTrace();
+ }finally{
+ try {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ if (raFile != null) {
+ raFile.close();
+ }
+ }catch(Exception ignored){
+
+ }
+ }
+ String url = requestUrl;
+ QueryWrapper<DocumentJgt>queryWrapper=new QueryWrapper<>();
+ queryWrapper.lambda().eq(DocumentJgt::getDocumentId,documentId);
+ DocumentJgt documentJgt = documentJgtMapper.selectOne(queryWrapper);
+ if(Objects.nonNull(documentJgt)){
+ UpdateWrapper<DocumentJgt>updateWrapper=new UpdateWrapper<>();
+ updateWrapper.lambda().eq(DocumentJgt::getDocumentId,documentId).set(DocumentJgt::getFileName,locationImg+"/"+url);
+ documentJgtMapper.update(null,updateWrapper);
+ }else {
+ DocumentJgt jgt=new DocumentJgt();
+ jgt.setDocumentId(documentId);
+ jgt.setFileName(locationImg+"/"+url);
+ documentJgtMapper.insert(jgt);
+ }
+ return R.ok(locationImg+"/"+url);
}
@SneakyThrows
@@ -668,7 +715,7 @@
@Override
public void getFile(String fileName, HttpServletResponse response) {
- try (InputStream inputStream = minioTemplate.getObject(OSS_BUCKET, fileName)) {
+ try (InputStream inputStream = new FileInputStream(fileName)) {
response.setContentType("application/octet-stream; charset=UTF-8");
IoUtil.copy(inputStream, response.getOutputStream());
} catch (Exception e) {
@@ -792,11 +839,15 @@
if (CollectionUtil.isEmpty(routings)) {
throw new RuntimeException("淇濆瓨澶辫触锛岄浂浠讹細" + document.getPartNo() + "鏃犲伐鑹鸿矾绾�");
}
- Routing routing = routings.get(0);
- joinDocumentBomRouting.setRoutingId(routing.getId());
- joinDocumentBomRouting.setBomId(routing.getBomId());
- joinDocumentBomRoutingMapper.insertAndGetId(joinDocumentBomRouting);
- // 娣诲姞妫�娴嬫爣鍑�
+ Routing routing = routings.get(0);
+ joinDocumentBomRouting.setRoutingId(routing.getId());
+ joinDocumentBomRouting.setBomId(routing.getBomId());
+ Routing routing1 = routingMapper.selectById(joinDocumentBomRouting.getRoutingId());
+ if(Objects.equals(routing1.getState(),RoutingStateStringValues.DRAFT)){
+ throw new RuntimeException("宸ヨ壓璺嚎鐘舵�佹湭閫氳繃锛�");
+ }
+ joinDocumentBomRoutingMapper.insertAndGetId(joinDocumentBomRouting);
+ // 娣诲姞妫�娴嬫爣鍑�
addDocTestStandard(joinDocumentBomRouting);
// 璁剧疆瀛愯妭鐐规暟鎹�
addBomRoutingPartByBomId(joinDocumentBomRouting.getId(), routing.getBomId(),
--
Gitblit v1.9.3