whycxzp
2022-07-27 1029121318da3bdcbef373cdc67b5adfe9841ab0
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 {
@@ -53,6 +50,7 @@
            link2.setDealDesc("工单被经理驳回,驳回信息:"+link.getDealReason());
            link2.setLinkStatus(0);
            link2.setEnableArchive(0);
            link2.setRejectVersion(link.getRejectVersion());
            linkMapper.insert(link2);
            //更新主表状态
            mainService.updateStatusById(link.getMainId(),0);
@@ -66,6 +64,7 @@
            link2.setDealDesc("工单被经理审核通过,信息:"+link.getDealReason());
            link2.setLinkStatus(0);
            link2.setEnableArchive(1);
            link2.setRejectVersion(link.getRejectVersion());
            linkMapper.insert(link2);
            //更新主表状态
            mainService.updateStatusById(link.getMainId(),2);
@@ -89,6 +88,7 @@
            link2.setDealDesc("工单被经理驳回,驳回信息:"+link.getDealReason());
            link2.setLinkStatus(0);
            link2.setEnableArchive(0);
            link2.setRejectVersion(link.getRejectVersion());
            linkMapper.insert(link2);
            //更新主表状态
            mainService.updateStatusById(link.getMainId(),0);
@@ -105,22 +105,74 @@
            //删除? 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;
            //更新到product_bom_history,需要sVersion和eVersion
            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());
            //更新到product_bom
            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());
            historyService.addBatch(newHistoryList);
            /*更新产品的当前版本,更新到最新的版本*/
            //当前版本的所有bom的eVersion更新,排除被修改的子件
            List<ProductBomHistory> newVersionCurrentHistoryList = currentHistoryList.stream()
                    .filter(currentHistory -> !approvingUpdateSubNameList.contains(currentHistory.getSubName()))
                    .collect(Collectors.toList());
            newVersionCurrentHistoryList.forEach(history->{history.setEVersion(nextVersion);});
            historyService.updateVersionBatch(newVersionCurrentHistoryList);
            /*更新到product_bom*/
            //查询新的版本
            List<ProductBomHistory> newBomList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), nextVersion);
            bomService.updateNewBom(newBomList);
            /*String projectDir = CommonUtil.getProjectDir();
            FileUtil.copyDir()*/
            //将产品bom表的url修正,更新到正式表
            //将产品bom表的url修正,更新到正式表 TODO
        }
    }
@@ -153,7 +205,7 @@
        return linkMapper.getInfoList3(userId,statusExp);
    }
    public String getApprovingUser(Integer mainId) {
    public DocUser getApprovingUser(Integer mainId) {
        return linkMapper.getApprovingUser(mainId);
    }
}