he wei
2022-07-29 fcb3dbb71a668ac1f0d1689645e94c5b758f439b
src/main/java/com/whyc/service/WorksheetLinkService.java
@@ -5,11 +5,15 @@
import com.whyc.mapper.ProductBomApprovingMapper;
import com.whyc.mapper.WorksheetLinkMapper;
import com.whyc.pojo.*;
import com.whyc.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@@ -161,8 +165,9 @@
                    .filter(currentHistory -> !approvingUpdateSubNameList.contains(currentHistory.getSubName()))
                    .collect(Collectors.toList());
            newVersionCurrentHistoryList.forEach(history->{history.setEVersion(nextVersion);});
            historyService.updateVersionBatch(newVersionCurrentHistoryList);
            if(newVersionCurrentHistoryList.size()!=0) {
                historyService.updateVersionBatch(newVersionCurrentHistoryList);
            }
            /*更新到product_bom*/
            //查询新的版本
            List<ProductBomHistory> newBomList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), nextVersion);
@@ -172,7 +177,43 @@
            FileUtil.copyDir()*/
            //将产品bom表的url修正,更新到正式表 TODO
            /*将产品bom表的url修正,更新到正式表*/
            //审批完后,将本次的bom带url的全部复制到正式文件夹中
            List<ProductBomApproving> fileBomApprovingList = approvingList.stream()
                    .filter(productBomApproving ->
                            productBomApproving.getPictureUrl() != null || productBomApproving.getDwgUrl() != null
                    ).collect(Collectors.toList());
            String projectDir = CommonUtil.getProjectDir();
            fileBomApprovingList.forEach(fileBom->{
                try {
                    String pictureUrl = fileBom.getPictureUrl();
                    String dwgUrl = fileBom.getDwgUrl();
                    if(pictureUrl !=null){
                        String newPictureUrl ="doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel()+File.separator+ pictureUrl.substring(pictureUrl.lastIndexOf(File.separator)+1);
                        File newPictureDir = new File(projectDir + File.separator + "doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel());
                        if(!newPictureDir.exists()){
                            newPictureDir.mkdirs();
                        }
                        FileCopyUtils.copy(new File(projectDir+File.separator+ pictureUrl),
                                new File(projectDir+File.separator+newPictureUrl));
                        fileBom.setPictureUrl(newPictureUrl);
                    }
                    if(dwgUrl !=null){
                        String newDwgUrl ="doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel()+File.separator+ dwgUrl.substring(dwgUrl.lastIndexOf(File.separator)+1);
                        File newDwgDir = new File(projectDir + File.separator + "doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel());
                        if(!newDwgDir.exists()){
                            newDwgDir.mkdirs();
                        }
                        FileCopyUtils.copy(new File(projectDir+File.separator+ dwgUrl),
                                new File(projectDir + File.separator + newDwgUrl));
                        fileBom.setDwgUrl(newDwgUrl);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
            //更新正式bom的对应url
            bomService.updateUrl(fileBomApprovingList);
        }
    }