whyclxw
2025-02-27 5636f3f0e6005cc30dca08ce33f5e6f1e7cd457f
src/main/java/com/whyc/service/ProductBomApprovingService.java
@@ -7,25 +7,18 @@
import com.whyc.mapper.ProductBomApprovingMapper;
import com.whyc.pojo.DocUser;
import com.whyc.pojo.ProductBomApproving;
import com.whyc.pojo.WorksheetMain;
import com.whyc.util.*;
import io.swagger.models.auth.In;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.io.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class ProductBomApprovingService {
@@ -131,8 +124,11 @@
        File parentFile = new File(filePath);
        String originalFilename = file.getOriginalFilename();
        File zipFile = new File(filePath+File.separator+ originalFilename);
        if(!zipFile.exists()){
        /*if(!zipFile.exists()){
            zipFile.mkdirs();
        }*/
        if (!parentFile.exists()) {
            parentFile.mkdirs();
        }
        file.transferTo(zipFile);
        //解压文件夹
@@ -145,8 +141,8 @@
        List<FileUrlDTO> dwgExistsList = getDwgList(fileList);
        for (int i = 0; i < fileList.size(); i++) {
            String fileTempUrl = fileList.get(i);
            //查询到需上传的bom数据
            if(fileTempUrl.contains(".xls") && fileTempUrl.contains("(BOM)-erp")){
            //查询需上传的bom数据
            if(fileTempUrl.contains(".xls") && fileTempUrl.contains("(BOM)")){
                Workbook workbook = null;
                InputStream inputStream = new FileInputStream(new File(fileTempUrl));
                workbook = WorkbookFactory.create(inputStream);
@@ -160,29 +156,32 @@
                short lastCellNum = row2.getLastCellNum();
                for (int k = 2; k < lastRowNum+1; k++) {
                    ProductBomApproving bomApproving = new ProductBomApproving();
                    for (int j = 1; j < lastCellNum; j++) {
                    for (int j = 0; j < lastCellNum; j++) {
                        Row row = sheet.getRow(k);
                        Cell cell = row.getCell(j);
                        String cellValue = null;
                        Double cellValueInt = 0d;
                        if(j == 9){
                        if(j == 9 ||j== 0){
                            cellValueInt = cell.getNumericCellValue();
                        }else if(j!=15){
                            cellValue = cell.getStringCellValue();
                        }
                        switch (j){
                            case 0:{bomApproving.setId(cellValueInt.intValue());}break;
                            case 1:{bomApproving.setParentCode(cellValue);}break;
                            case 2:{bomApproving.setParentName(cellValue);}break;
                            case 3:{bomApproving.setParentModel(cellValue);}break;
                            case 4:{bomApproving.setCategory(cellValue);}break;
                            case 5:{
                                bomApproving.setSubCode(cellValue);
                            case 5:{bomApproving.setSubCode(cellValue); }break;
                            case 6:{bomApproving.setSubName(cellValue);}break;
                            case 7:{
                                bomApproving.setSubModel(cellValue);
                                //判断图纸查看是否存在
                                bomApproving.setDwgExist(0);
                                String dwgFileName = cellValue+".dwg";
                                for (int n = 0; n < dwgExistsList.size(); n++) {
                                    FileUrlDTO fileUrlDTO = dwgExistsList.get(n);
                                    if(dwgFileName.equals(fileUrlDTO.getFileName())){
                                    if(dwgFileName.toUpperCase().equals(fileUrlDTO.getFileName().toUpperCase())){
                                        //存在
                                        bomApproving.setDwgExist(1);
                                        bomApproving.setDwgUrl(fileUrlDTO.getHttpFileUrl());
@@ -190,8 +189,6 @@
                                    }
                                }
                            }break;
                            case 6:{bomApproving.setSubName(cellValue);}break;
                            case 7:{bomApproving.setSubModel(cellValue);}break;
                            case 8:{bomApproving.setUnit(cellValue);}break;
                            case 9:{bomApproving.setQuantity(cellValueInt.intValue());}break;
                            case 10:{bomApproving.setProducer(cellValue);}break;
@@ -201,18 +198,18 @@
                            case 14:{bomApproving.setNotes(cellValue);}break;
                            case 15:{
                                //图片,从0开始,到图片size为止
                                int m = i-2;
                                int m = k-2;
                                if(m<allPictures.size()){
                                    PictureData pictureData = allPictures.get(m);
                                    //图片存储 product_approving/username/2022-07/
                                    String approvingPath = rootFile + File.separator + "product_approving" + File.separator + user.getName() + File.separator + dateFormat;
                                    String approvingPath = rootFile + File.separator + "product_approving" + File.separator + user.getName() + File.separator + dateFormat+ File.separator + timeStamp;
                                    File provingFile = new File(approvingPath);
                                    if(!provingFile.exists()){
                                        provingFile.mkdirs();
                                    }
                                    String suffix = pictureData.suggestFileExtension();
                                    String picturePath = approvingPath + File.separator + bomApproving.getSubModel() + "." + suffix;
                                    String picturePathFront = "doc_file" + File.separator + "product_approving" + File.separator + user.getName() + File.separator + dateFormat + File.separator + bomApproving.getSubModel() + "." + suffix;
                                    String picturePathFront = "doc_file" + File.separator + "product_approving" + File.separator + user.getName() + File.separator + dateFormat + File.separator + timeStamp + File.separator + bomApproving.getSubModel() + "." + suffix;
                                    byte[] data = pictureData.getData();
                                    FileOutputStream fileOutputStream = null;
                                    File pictureFile = new File(picturePath);
@@ -227,7 +224,7 @@
                    bomList.add(bomApproving);
                }
            }
            //这个是子表数据,用做对比校验
            /*//这个是子表数据,用做对比校验
            else if(fileTempUrl.contains(".xls")){
                File fileTemp = new File(fileTempUrl);
                Workbook workbook = null;
@@ -250,7 +247,8 @@
                for (int l = 9; l < lastRowNum-1; l++) {
                    ProductBomApproving bomApproving = new ProductBomApproving();
                    bomApproving.setParentModel(productModel);
                    bomApproving.setParentVersion(productVersion);
                    //lxw注释
                    //bomApproving.setParentVersion(productVersion);
                    bomApproving.setType(type);
                    bomApproving.setExcelName(fileTempUrl.substring(fileTempUrl.lastIndexOf(File.separator)+1));
@@ -326,7 +324,7 @@
                    }
                    list.add(bomApproving);
                }
            }
            }*/
        }
        /*String parentModel = list.get(0).getParentModel();
        for (int i = 0; i < list.size(); i++) {
@@ -337,7 +335,7 @@
        //通过包名,查询工单流程审批标题
        //String nextTitle = mainService.getNextTitle(originalFilename);
        //子表,逐条对比bom表,子料编码/子料型号/子料数量
        /*//子表,逐条对比bom表,子料编码/子料型号/子料数量
        for (ProductBomApproving sub:list){
            String subCode = sub.getSubCode();
            String subModel = sub.getSubModel();
@@ -361,9 +359,24 @@
            if(!exists){
                return response.set(1,false,excelName+"中货品编码:"+subCode+"在bom表中不存在");
            }
        }
        }*/
        /*//处理名称重复的子件
        List<ProductBomApproving> newBomList = new LinkedList<>();
        Map<String, List<ProductBomApproving>> subNameMap = bomList.stream().collect(Collectors.groupingBy(ProductBomApproving::getSubName));
        subNameMap.forEach((subName,approvingList)->{
            if(approvingList.size()>1){
                for (int i = 0; i < approvingList.size(); i++) {
                    ProductBomApproving bomApproving = approvingList.get(i);
                    bomApproving.setSubName(subName+(i+1));
                    newBomList.add(bomApproving);
                }
            }else{
                newBomList.addAll(approvingList);
            }
        });*/
        List<ProductBomApproving> collect = bomList.stream().sorted(Comparator.comparing(ProductBomApproving::getId)).collect(Collectors.toList());
        String nextTitle = originalFilename.substring(0,originalFilename.lastIndexOf("."));
        return response.setIII(1,true,bomList,nextTitle,"解析完成");
        return response.setIII(1,true,collect,nextTitle,filePath);
    }
    private List<FileUrlDTO> getDwgList(List<String> fileList) {
@@ -379,31 +392,45 @@
        return list;
    }
    /**
     *
     * @param dwgUrl 预览dwg图纸文件,后追加预览word文档
     * @return
     * @throws IOException
     */
    public Response dwgReview(String dwgUrl) throws IOException {
        String fileSuffix = dwgUrl.substring(dwgUrl.lastIndexOf(".") + 1);
        //绝对路径xxx/doc_file
        String rootFile = CommonUtil.getRootFile();
        String dwgSubFilePath = dwgUrl.substring(dwgUrl.indexOf("doc_file")+8);
        String dwgSubFileDirPath = dwgSubFilePath.substring(0,dwgSubFilePath.lastIndexOf(File.separator));
        File dwgFile = new File(rootFile + dwgSubFilePath);
        String dwgPdfUrl = dwgFile.getParent() + File.separator + dwgFile.getName().substring(0, dwgFile.getName().lastIndexOf(".")) + "-dwg.pdf";
        File dwgPdfFile = new File(dwgPdfUrl);
        String pdfFileName = null;
        if(!dwgPdfFile.exists()) {
            pdfFileName = DwgToPdfUtil.dwg2Pdf(dwgFile);
        }else{
            pdfFileName = dwgPdfFile.getName();
        String pdfUrl = "";
        if(fileSuffix.equals("dwg")) {
            pdfUrl = dwgFile.getParent() + File.separator + dwgFile.getName().substring(0, dwgFile.getName().lastIndexOf(".")) + "-dwg.pdf";
        }else if(fileSuffix.contains("doc")){
            pdfUrl = dwgFile.getParent() + File.separator + dwgFile.getName().substring(0, dwgFile.getName().lastIndexOf(".")) + "-doc.pdf";
        }
        File pdfFile = new File(pdfUrl);
        String pdfFileName = null;
        if(!pdfFile.exists()) {
            if(fileSuffix.equals("dwg")) {
                //pdfFileName = DwgToPdfUtil.dwg2Pdf(dwgFile);
                DwgToPdfUtil.dwg2Pdf(dwgFile);
            }else if(fileSuffix.contains("doc")){
                Word2PdfAsposeUtil.doc2pdf(dwgFile.getAbsolutePath(),pdfUrl);
            }
        }/*else{
            pdfFileName = pdfFile.getName();
        }*/
        pdfFileName = pdfFile.getName();
        return new Response().set(1,"doc_file"+dwgSubFileDirPath+File.separator+pdfFileName);
    }
    public int getRejectVersion(Integer mainId) {
    public List<ProductBomApproving> getList(Integer productApprovingId) {
        QueryWrapper<ProductBomApproving> query = Wrappers.query();
        query.select("reject_version").eq("main_id",mainId).orderByDesc("id").last(" limit 1");
        ProductBomApproving bomApproving = mapper.selectOne(query);
        if(bomApproving==null){
            return -1;
        }else{
            return bomApproving.getRejectVersion();
        }
        query.eq("product_approving_id",productApprovingId);
        return mapper.selectList(query);
    }
}