whycxzp
2023-06-25 ca3c7bac6c32443d54b5d717d82c0f0761e2f625
问题修复
1个文件已修改
36 ■■■■ 已修改文件
src/main/java/com/whyc/service/SOPService.java 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/SOPService.java
@@ -18,11 +18,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
@@ -311,7 +309,7 @@
        sopProductList.forEach(product -> product.setSopId(sop.getId()));
        productService.insertBatch(sopProductList);
        //文件转移
        String fileUrl = sop.getFileUrl();
        /*String fileUrl = sop.getFileUrl();
        String projectDir = CommonUtil.getProjectDir();
        String filePathFrom = projectDir + File.separator + fileUrl.replace("sop","sop_submit");
        File fileFrom = new File(filePathFrom);
@@ -320,7 +318,7 @@
        if(!fileTo.getParentFile().exists()){
            fileTo.getParentFile().mkdirs();
        }
        FileCopyUtils.copy(fileFrom,fileTo);
        FileCopyUtils.copy(fileFrom,fileTo);*/
        //新增的文件类型,追加到表中
        List<SOPFileType> typeList = new LinkedList<>();
@@ -339,22 +337,26 @@
            }
        }
        List<SOPFileType> recordListInDB = fileTypeService.getAllInDB(typeList);
        List<SOPFileType> newRecordList = new LinkedList<>();
        if(typeList.size()!=recordListInDB.size()) {
            List<SOPFileType> newRecordList = new LinkedList<>();
        List<String> uploadTypeStrList = typeList.stream().map(type -> type.getType1() + ";" + type.getType2()).collect(Collectors.toList());
        List<String> dbTypeStrList = recordListInDB.stream().map(type -> type.getType1() + ";" + type.getType2()).collect(Collectors.toList());
        Date now = new Date();
        for (int i = 0; i < uploadTypeStrList.size(); i++) {
            String uploadTypeStr = uploadTypeStrList.get(i);
            if(!dbTypeStrList.contains(uploadTypeStr)){
                SOPFileType sopFileType = new SOPFileType();
                sopFileType.setType1(uploadTypeStr.split(";")[0]);
                sopFileType.setType2(uploadTypeStr.split(";")[1]);
                sopFileType.setCreateTime(now);
                newRecordList.add(sopFileType);
            List<String> uploadTypeStrList = typeList.stream().map(type -> type.getType1() + ";" + type.getType2()).collect(Collectors.toList());
            List<String> dbTypeStrList = recordListInDB.stream().map(type -> type.getType1() + ";" + type.getType2()).collect(Collectors.toList());
            Date now = new Date();
            for (int i = 0; i < uploadTypeStrList.size(); i++) {
                String uploadTypeStr = uploadTypeStrList.get(i);
                if (!dbTypeStrList.contains(uploadTypeStr)) {
                    SOPFileType sopFileType = new SOPFileType();
                    sopFileType.setType1(uploadTypeStr.split(";")[0]);
                    sopFileType.setType2(uploadTypeStr.split(";")[1]);
                    sopFileType.setCreateTime(now);
                    newRecordList.add(sopFileType);
                }
            }
            if (newRecordList.size() > 0) {
                fileTypeService.addBatch(newRecordList);
            }
        }
        fileTypeService.addBatch(newRecordList);
        return new Response().setII(1,"上传完成");
    }