yangys
2025-08-22 43b6b4b905fb272e2d7d9c0738610c4204c958ce
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java
@@ -5,6 +5,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BizServiceImpl;
import org.springblade.core.tool.utils.Func;
import org.springblade.mdm.basesetting.machine.MachineService;
import org.springblade.mdm.basesetting.machine.entity.Machine;
import org.springblade.mdm.program.entity.NcNode;
import org.springblade.mdm.program.mapper.NcNodeMapper;
import org.springblade.mdm.program.vo.*;
@@ -16,6 +18,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
 * 程序节点
@@ -27,6 +30,7 @@
@AllArgsConstructor
public class NcNodeService extends BizServiceImpl<NcNodeMapper, NcNode> {
   private final MachineService machineService;
   public void saveNcCode(NcNodeVO vo) {
      NcNode ncNode = new NcNode();
@@ -94,11 +98,32 @@
   /**
    * 车讯节点
    * @param queryVO
    * @return
    */
   /*
   public List<Long> searchDrawing(NcNodeQueryVO queryVO) {
      List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_DRAWING_NO)
         .eq(NcNode::getIsLastEdition,1)
         .eq(NcNode::getName,queryVO.getDrawingNo())
         .ge(queryVO.getCreateTimeBegin()!=null,NcNode::getCreateTime,queryVO.getCreateTimeBegin())
         .le(queryVO.getCreateTimeEnd()!=null,NcNode::getCreateTime,queryVO.getCreateTimeEnd())
         .and(i->{
            i.or().likeRight(queryVO.getProgramStatus().contains("1"),NcNode::getParentIds,"0,1,");
            i.or().likeRight(queryVO.getProgramStatus().contains("2"),NcNode::getParentIds,"0,2,");
            i.or().likeRight(queryVO.getProgramStatus().contains("3"),NcNode::getParentIds,"0,3,");
         }).list();
      return nodes.stream().map(NcNode::getId).toList();
   }*/
   /**
    * 首页树查询
    * @param queryVO
    * @return
    */
   public List<NcNodeVO> searchList(NcNodeQueryVO queryVO) {
   public List<NcNodeVO> searchList(NcNodeOldQueryVO queryVO) {
      //1.根据关进字和节点类型查询初始列表,查询的原始列表,需要hasChild字段,所以使用mapper.xml
      List<NcNodeVO> oriList = this.getBaseMapper().searchList(queryVO);
      if ("10".equals(queryVO.getNodeType())) {
@@ -108,8 +133,6 @@
      List<NcNodeVO> allVos = new ArrayList<NcNodeVO>();//已经加入过的节点,用于去重
      List<NcNodeVO> rootVos = new ArrayList<NcNodeVO>();
      //List<NcNode> rootNodes = new ArrayList<>();
      for(NcNodeVO vo : oriList){
         allVos.add(vo);
@@ -126,6 +149,40 @@
      for(NcNodeVO root : rootVos){
         addNodeChildren(root, allVos);
      }
      return rootVos;
   }
   /**
    * 首页搜索 新的
    * @param queryVO 查询参数
    * @return
    */
   public List<NcNodeVO> searchList2(NcNodeQueryVO queryVO) {
      //1.根据零组件号和创建时间查询初始列表,查询的原始列表,需要hasChild字段,所以使用mapper.xml
      if(queryVO.getCreateTimeEnd()!=null){
         queryVO.setCreateTimeEnd(queryVO.getCreateTimeEnd().plusDays(1));
      }
      List<NcNodeVO> oriList = this.getBaseMapper().searchList2(queryVO);
      List<NcNodeVO> allVos = new ArrayList<>();//已经加入过的节点,用于去重
      List<NcNodeVO> rootVos = new ArrayList<>();
      for(NcNodeVO vo : oriList){
         allVos.add(vo);
         //上级各级的节点
         List<NcNodeVO> parents = this.getBaseMapper().searchListInIds(Func.toLongList(vo.getParentIds()));
         for(NcNodeVO pvo : parents){
            if(pvo.getParentId() == 0L){
               rootVos.add(pvo);
            }
            allVos.add(pvo);
         }
      }
      for(NcNodeVO root : rootVos){
         addNodeChildren(root, allVos);
      }
      return rootVos;
   }
@@ -186,13 +243,13 @@
    * @param name 节点名称
    * @return 最新版本程序报名节点
    */
   public NcNode getLastEditionTryingProgramPackage(String name){
   public NcNode getLastEditionTryingProgramPackage(String name,String processEdition){
      //.or(NcNode::getIsCured,0)
      List<NcNode> pkgList = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
         .eq(NcNode::getName, name).and(i->{
            i.eq(NcNode::getIsCured, 0).or().isNull(NcNode::getIsCured);
         }).likeRight(NcNode::getParentIds,"0,1,")
         .eq(NcNode::getIsLastEdition,1).orderByDesc(NcNode::getCreateTime).list();
         .eq(NcNode::getIsLastEdition,1).eq(NcNode::getProcessEdition,processEdition).orderByDesc(NcNode::getCreateTime).list();
      if(pkgList.isEmpty()){
         return null;
@@ -224,7 +281,7 @@
    */
    public List<NcNode> getNodeHistory(NcNode pkgNode) {
      return this.lambdaQuery().eq(NcNode::getParentId,pkgNode.getParentId())
         .eq(NcNode::getName,pkgNode.getName()).list();
         .eq(NcNode::getName,pkgNode.getName()).list();//.ne(NcNode::getId,pkgNode.getId())
    }
   /**
@@ -242,9 +299,32 @@
    * @param programPkgName
    * @return
    */
   public NcNode getLastEditionCuredProgramPackage(String programPkgName) {
   public NcNode getLastEditionCuredProgramPackage(String programPkgName,String processEdition) {
      List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
         .eq(NcNode::getName, programPkgName).likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1)
         .eq(NcNode::getProcessEdition, processEdition)
         .eq(NcNode::getIsLastEdition,1).list();
      if(nodes.isEmpty()){
         return null;
      }else {
         return nodes.get(0);
      }
   }
   /**
    * 获取最新版本的 已固化节点
    * @param programPkgName 程序包名
    * @param machineCode 机床编号
    * @return
    */
   public NcNode getCuredProgramPackage(String programPkgName,String machineCode) {
      Machine machine = machineService.getByCode(machineCode);
      List<Machine> sameGroupMachines = machineService.lambdaQuery().eq(Machine::getMachineGroupCode,machine.getMachineGroupCode()).list();
      List<String> machineCodesInGroup = sameGroupMachines.stream().map(Machine::getCode).toList();
      List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
         .eq(NcNode::getName, programPkgName).likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1)
         .in(!machineCodesInGroup.isEmpty(),NcNode::getMachineCode,machineCodesInGroup)
         .eq(NcNode::getIsLastEdition,1).list();
      if(nodes.isEmpty()){
@@ -259,9 +339,11 @@
    * @param programPkgName 程序包名
    * @return 偏离的程序节点
    */
   public NcNode getLastEditionDeviationProgramPackage(String programPkgName) {
   public NcNode getLastEditionDeviationProgramPackage(String programPkgName,String processEdition) {
      List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
         .eq(NcNode::getName, programPkgName).likeRight(NcNode::getParentIds,"0,3,")
         .eq(NcNode::getName, programPkgName)
         .eq(NcNode::getProcessEdition, processEdition)
         .likeRight(NcNode::getParentIds,"0,3,")
         .eq(NcNode::getIsLastEdition,1).list();
      if(nodes.isEmpty()){
@@ -306,7 +388,7 @@
   @Transactional
   public void upgradeVersionNumber(Long nodeId) {
      NcNode node = this.getById(nodeId);
      node.upgradeVersionNUmber();
      node.upgradeVersionNumber();
      this.updateById(node);
   }