whycxzp
2022-07-27 ec08a42903bc8967f177bee0a3c7a048f26edbf2
src/main/java/com/whyc/service/WorksheetLinkService.java
@@ -4,19 +4,16 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.mapper.ProductBomApprovingMapper;
import com.whyc.mapper.WorksheetLinkMapper;
import com.whyc.pojo.ProductBomApproving;
import com.whyc.pojo.WorksheetLink;
import com.whyc.pojo.WorksheetMain;
import com.whyc.util.CommonUtil;
import org.aspectj.util.FileUtil;
import com.whyc.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.naming.CommunicationException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class WorksheetLinkService {
@@ -105,16 +102,61 @@
            //删除? TODO 需要约定逻辑
            //查询部件最新的版本号
            Integer version = bomService.getProduct(approvingList.get(0).getParentModel()).getVersion();
            if(version==null){
                version = 0;
            Integer currentVersion = bomService.getProduct(approvingList.get(0).getParentModel()).getVersion();
            if(currentVersion==null){
                currentVersion = 0;
            }
            Integer nextVersion = version+1;
            Integer nextVersion = currentVersion+1;
            //更新到product_bom_history,需要sVersion和eVersion
            //增加所有部件,排查出相关的原部件,非也是更新
            //historyService.get
            List<ProductBomHistory> currentHistoryList = historyService.getListByParentModel(approvingList.get(0).getParentModel(),currentVersion);
            List<String> currentSubNameList = currentHistoryList.stream().map(ProductBomHistory::getSubName).collect(Collectors.toList());
            List<ProductBomHistory> newHistoryList = new LinkedList<>();
            approvingList.forEach(approvingBom->{
                if(currentSubNameList.contains(approvingBom.getSubName())){
                    approvingBom.setVersion(1);
                }else{
                    approvingBom.setVersion(0);
                }
                //转化为productBomHistory
                ProductBomHistory his = new ProductBomHistory();
                his.setCategory(approvingBom.getCategory());
                his.setCreateDate(approvingBom.getCreateDate());
                his.setDwgUrl(approvingBom.getDwgUrl());
                his.seteVersion(nextVersion);
                his.setFileUrl(approvingBom.getFileUrl());
                his.setMaterial(approvingBom.getMaterial());
                his.setNotes(approvingBom.getNotes());
                his.setParentCode(approvingBom.getParentCode());
                his.setParentModel(approvingBom.getParentModel());
                his.setParentName(approvingBom.getParentName());
                his.setParentVersion(approvingBom.getParentVersion());
                his.setPictureUrl(approvingBom.getPictureUrl());
                his.setProducer(approvingBom.getProducer());
                his.setQuantity(approvingBom.getQuantity());
                his.setSubCode(approvingBom.getSubCode());
                his.setSubModel(approvingBom.getSubModel());
                his.setSubName(approvingBom.getSubName());
                his.setSurfaceDetail(approvingBom.getSurfaceDetail());
                his.setsVersion(nextVersion);
                his.setThickness(approvingBom.getThickness());
                his.setType(approvingBom.getType());
                his.setUnit(approvingBom.getUnit());
                his.setUpdateDate(approvingBom.getUpdateDate());
                his.setUpUser(approvingBom.getUpUser());
                newHistoryList.add(his);
            });
            //本次审核中子件被修改的子件集合
            List<String> approvingUpdateSubNameList = approvingList.stream().filter(approvingBom -> approvingBom.getVersion() == 1).map(ProductBomApproving::getSubName).collect(Collectors.toList());
            //更新到product_bom
            historyService.addBatch(newHistoryList);
            /*更新产品的当前版本,更新到最新的版本*/
            //当前版本的所有bom,排除
            //currentHistoryList.stream().filter(currentHistory->currentHistory.getSubName());
            /*String projectDir = CommonUtil.getProjectDir();
            FileUtil.copyDir()*/
@@ -153,7 +195,7 @@
        return linkMapper.getInfoList3(userId,statusExp);
    }
    public String getApprovingUser(Integer mainId) {
    public DocUser getApprovingUser(Integer mainId) {
        return linkMapper.getApprovingUser(mainId);
    }
}