yangys
2025-08-20 432198337fb3d8a99fadb4b7825771d68bb10b9e
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.*;
@@ -27,6 +29,7 @@
@AllArgsConstructor
public class NcNodeService extends BizServiceImpl<NcNodeMapper, NcNode> {
   private final MachineService machineService;
   public void saveNcCode(NcNodeVO vo) {
      NcNode ncNode = new NcNode();
@@ -73,7 +76,7 @@
    * @return
    */
   public List<NcNodeVO> lazyList(Long parentId) {
// 判断点击搜索但是没有查询条件的情况
      // 判断点击搜索但是没有查询条件的情况
      if (Func.isEmpty(parentId)) {
         parentId = 0L;
      }
@@ -101,7 +104,6 @@
   public List<NcNodeVO> searchList(NcNodeQueryVO queryVO) {
      //1.根据关进字和节点类型查询初始列表,查询的原始列表,需要hasChild字段,所以使用mapper.xml
      List<NcNodeVO> oriList = this.getBaseMapper().searchList(queryVO);
      //List<NcNode> list = this.lambdaQuery().eq(NcNode::getNodeType, queryVO.getNodeType()).like(NcNode::getName, queryVO.getName()).list();
      if ("10".equals(queryVO.getNodeType())) {
         //搜索的根级别,直接返回
         return oriList;
@@ -159,7 +161,9 @@
    * @return 程序报包名的节点
    */
   public NcNode getProgramPackageByName(String programName) {
      List<NcNode> pkgs = this.lambdaQuery().eq(NcNode::getName, programName).eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE).list();
      List<NcNode> pkgs = this.lambdaQuery().eq(NcNode::getName, programName)
         .eq(NcNode::getIsLastEdition,1)
         .eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE).list();
      if(pkgs.isEmpty()){
         return null;
      }else{
@@ -181,13 +185,17 @@
    }
   /**
    * 获取“程序包名”的最新版本
    * 获取“程序包名”试切的最新版本
    * @param name 节点名称
    * @return 最新版本程序报名节点
    */
   public NcNode getLastEditionProgramPackage(String name){
   public NcNode getLastEditionTryingProgramPackage(String name){
      //.or(NcNode::getIsCured,0)
      List<NcNode> pkgList = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
         .eq(NcNode::getName, name).eq(NcNode::getIsLastEdition,1).orderByDesc(NcNode::getCreateTime).list();
         .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();
      if(pkgList.isEmpty()){
         return null;
@@ -219,7 +227,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())
    }
   /**
@@ -239,7 +247,46 @@
    */
   public NcNode getLastEditionCuredProgramPackage(String programPkgName) {
      List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
         .eq(NcNode::getName, programPkgName).eq(NcNode::getIsCured,1)
         .eq(NcNode::getName, programPkgName).likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1)
         .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()){
         return null;
      }else {
         return nodes.get(0);
      }
   }
   /**
    * 获取最新版本的 偏离节点
    * @param programPkgName 程序包名
    * @return 偏离的程序节点
    */
   public NcNode getLastEditionDeviationProgramPackage(String programPkgName) {
      List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
         .eq(NcNode::getName, programPkgName).likeRight(NcNode::getParentIds,"0,3,")
         .eq(NcNode::getIsLastEdition,1).list();
      if(nodes.isEmpty()){
@@ -266,4 +313,43 @@
   public void deleteSubNodes(Long nodeId) {
      this.baseMapper.deleteSubNodes(nodeId);
   }
   /**
    * 获取程序包下所有层序文件节点
    * @param packageNodeId 程序包名 节点id
    * @return 包下属的程序文件
    */
   public List<NcNode> getProgramFilesByPackageId(Long packageNodeId) {
      return this.lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_FILE)
         .eq(NcNode::getParentId,packageNodeId).eq(NcNode::getIsLastEdition,1).list();
   }
   /**
    * 升级版本号(+1)
    * @param nodeId 节点id
    */
   @Transactional
   public void upgradeVersionNumber(Long nodeId) {
      NcNode node = this.getById(nodeId);
      node.upgradeVersionNumber();
      this.updateById(node);
   }
   /**
    * 锁定节点
    * @param id 程序包节点id
    */
   @Transactional
    public void lock(Long id) {
      NcNode node = this.getById(id);
      node.lock();
      this.updateById(node);
    }
   @Transactional
   public void unlock(Long id) {
      NcNode node = this.getById(id);
      node.unlock();
      this.updateById(node);
   }
}