| | |
| | | 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.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.mapper.NcNodeMapper; |
| | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 程序节点 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询节点的历史列表(节点的上级节点”程序包名“因为存在多个版本,所以历史记录也需要根据不同版本程序包名进行查询) |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Transactional(readOnly = true) |
| | | public List<NcNodeVO> historyByNodeId(Long id) { |
| | | NcNode node = this.getById(id); |
| | | NcNode parentNode = this.getById(node.getParentId()); |
| | | return this.baseMapper.historyByParentIdAndName(node.getName(),parentNode); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取“程序包名”试切的最新版本 |
| | | * @param name 节点名称 |
| | | * @return 最新版本程序报名节点 |
| | | */ |
| | | public NcNode getLastEditionTryingProgramPackage(String name,String processEdition){ |
| | | public NcNode getLastEditionTryingProgramPackage(String name){ |
| | | //.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).eq(NcNode::getProcessEdition,processEdition).orderByDesc(NcNode::getCreateTime).list(); |
| | | .eq(NcNode::getIsLastEdition,1).orderByDesc(NcNode::getCreateTime).list();//.eq(NcNode::getProcessEdition,processEdition) |
| | | |
| | | if(pkgList.isEmpty()){ |
| | | return null; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取node的历史列表(同一个父节点下,同名的所有节点) |
| | | * 获取试切节点node的历史列表(零组件号,工序号,工序版本,机床组) |
| | | * @param pkgNode node |
| | | * @return 历史列表,报错节点本身 |
| | | */ |
| | | public List<NcNode> getNodeHistory(NcNode pkgNode) { |
| | | public List<NcNode> getTryNodeHistory(NcNode pkgNode) { |
| | | return this.lambdaQuery().eq(NcNode::getDrawingNo,pkgNode.getDrawingNo()) |
| | | .eq(NcNode::getProcessNo,pkgNode.getProcessNo()) |
| | | .eq(NcNode::getProcessEdition,pkgNode.getProcessEdition()) |
| | | .eq(NcNode::getMachineGroupCode,pkgNode.getMachineGroupCode()) |
| | | .likeLeft(NcNode::getParentIds,"0,1,") |
| | | .list();//.ne(NcNode::getId,pkgNode.getId()) |
| | | /* |
| | | return this.lambdaQuery().eq(NcNode::getParentId,pkgNode.getParentId()) |
| | | .eq(NcNode::getName,pkgNode.getName()).list();//.ne(NcNode::getId,pkgNode.getId()) |
| | | |
| | | */ |
| | | } |
| | | |
| | | /** |
| | | * 计算历史序号,根据零组件号,工序号,工序版次,机床组查询,查询道则使用该历史编号,查询不到使用新生成的 |
| | | */ |
| | | public long calculateHistorySerial(NcNode pkgNode) { |
| | | NcNode node = this.lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE).eq(NcNode::getDrawingNo,pkgNode.getDrawingNo()) |
| | | .eq(NcNode::getProcessNo,pkgNode.getProcessNo()).eq(NcNode::getProcessEdition,pkgNode.getProcessEdition()) |
| | | .eq(NcNode::getMachineGroupCode,pkgNode.getMachineGroupCode()).last("limit 1").one(); |
| | | |
| | | if(node != null && node.getHisSerial()!=null){ |
| | | return node.getHisSerial(); |
| | | }else{ |
| | | //以往没有,生成一个新的 |
| | | return System.currentTimeMillis();//使用当前毫秒数 |
| | | } |
| | | } |
| | | |
| | | public int calculateVersionNumber(NcNode pkgNode) { |
| | | NcNode node = this.lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE).eq(NcNode::getDrawingNo,pkgNode.getDrawingNo()) |
| | | .eq(NcNode::getProcessNo,pkgNode.getProcessNo()).eq(NcNode::getProcessEdition,pkgNode.getProcessEdition()) |
| | | .eq(NcNode::getMachineGroupCode,pkgNode.getMachineGroupCode()).last("limit 1").one(); |
| | | |
| | | if(node != null && node.getVersionNumber()!=null){ |
| | | return node.getVersionNumber()+1; |
| | | }else{ |
| | | //以往没有,生成一个新的 |
| | | return 1; |
| | | } |
| | | } |
| | | /** |
| | | * 生成程序包名/程序名称 |
| | | * @param drawingNo 零组件号 |
| | | * @param processNo 工序版次 |
| | | * @return 程序包名/程序名称 |
| | | */ |
| | | public static String genProgramName(String drawingNo,String processNo){ |
| | | return drawingNo+"-"+processNo; |
| | | public static String genProgramName(String drawingNo,String processNo,String processEdition){ |
| | | return drawingNo+"-"+processNo+"-"+processEdition; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param programPkgName |
| | | * @return |
| | | */ |
| | | public NcNode getLastEditionCuredProgramPackage(String programPkgName,String processEdition) { |
| | | public NcNode getLastEditionCuredProgramPackage(String programPkgName) { |
| | | 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::getProcessEdition, processEdition) |
| | | .eq(NcNode::getIsLastEdition,1).list(); |
| | | |
| | | if(nodes.isEmpty()){ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取最新的固化程序,不用工序版次匹配 |
| | | * @param drawingNo |
| | | * @param processNo |
| | | * @param machineCode |
| | | * @return |
| | | */ |
| | | public NcNode getLastCuredProgramWithoutProcessEdition(String drawingNo, String processNo, 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::getDrawingNo, drawingNo).eq(NcNode::getProcessNo, processNo) |
| | | .likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1) |
| | | .in(!machineCodesInGroup.isEmpty(),NcNode::getMachineCode,machineCodesInGroup) |
| | | .eq(NcNode::getIsLastEdition,1).orderByDesc(NcNode::getCreateTime).list(); |
| | | |
| | | if(nodes.isEmpty()){ |
| | | return null; |
| | | }else { |
| | | return nodes.get(0); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取最新版本的 偏离节点 |
| | | * @param programPkgName 程序包名 |
| | | * @return 偏离的程序节点 |
| | | */ |
| | | public NcNode getLastEditionDeviationProgramPackage(String programPkgName,String processEdition) { |
| | | public NcNode getLastEditionDeviationProgramPackage(String programPkgName) {//,String processEdition |
| | | List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE) |
| | | .eq(NcNode::getName, programPkgName) |
| | | .eq(NcNode::getProcessEdition, processEdition) |
| | | //.eq(NcNode::getProcessEdition, processEdition) |
| | | .likeRight(NcNode::getParentIds,"0,3,") |
| | | .eq(NcNode::getIsLastEdition,1).list(); |
| | | |
| | |
| | | return this.lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_FILE) |
| | | .eq(NcNode::getParentId,packageNodeId).eq(NcNode::getIsLastEdition,1).list(); |
| | | } |
| | | |
| | | /** |
| | | * 升级版本号(+1) |
| | | * @param nodeId 节点id |
| | |
| | | this.updateById(node); |
| | | } |
| | | @Transactional |
| | | public void lock(Long id,String remark) { |
| | | NcNode node = this.getById(id); |
| | | node.lock(remark); |
| | | this.updateById(node); |
| | | } |
| | | @Transactional |
| | | public void unlock(Long id) { |
| | | NcNode node = this.getById(id); |
| | | node.unlock(); |
| | | this.updateById(node); |
| | | } |
| | | |
| | | /** |
| | | * 查询偏离单的序号 |
| | | * @param programPkgNode 偏离单的程序包名节点 |
| | | * @return 序号 |
| | | */ |
| | | /* |
| | | public long getDeviationSerialForNode(NcNode programPkgNode) { |
| | | return lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE) |
| | | .eq(NcNode::getName,programPkgNode.getName()) |
| | | |
| | | .eq(NcNode::getDrawingNo,programPkgNode.getDrawingNo()) |
| | | .eq(NcNode::getProcessNo,programPkgNode.getProcessNo()) |
| | | .eq(NcNode::getProcessEdition,programPkgNode.getProcessEdition()) |
| | | |
| | | .isNotNull(NcNode::getDeviation) |
| | | .le(NcNode::getCreateTime,programPkgNode.getCreateTime()) //时间小于等于当前节点 |
| | | .count(); |
| | | } |
| | | */ |
| | | |
| | | /** |
| | | * 根据上级节点id,移动下面的加工机床节点 |
| | | * @param parentId 上级节点id |
| | | */ |
| | | /* |
| | | public void deleteMachineGroupNodeByParentId(Long parentId) { |
| | | baseMapper.deleteMachineGroupNodeByParentId(parentId); |
| | | }*/ |
| | | |
| | | /** |
| | | * 删除所偶非最新版本的数据(hodeHIs里面已经保存过) |
| | | */ |
| | | public void deleteOldEditionNodeData() { |
| | | baseMapper.deleteOldEditionNodeData(); |
| | | } |
| | | |
| | | /** |
| | | * //更新已固化的,同名、不同机床组的程序为锁定状态 |
| | | * @param packageNode |
| | | */ |
| | | public void lockSameNameOtherMachineGroupProgramPackage(NcNode packageNode) { |
| | | lambdaUpdate().eq(NcNode::getDrawingNo,packageNode.getDrawingNo()) |
| | | .eq(NcNode::getProcessNo,packageNode.getProcessNo()) |
| | | .eq(NcNode::getName,packageNode.getName()) |
| | | .ne(NcNode::getMachineGroupCode,packageNode.getMachineGroupCode()) |
| | | .eq(NcNode::getIsCured,1) |
| | | .eq(NcNode::getIsLastEdition,1) |
| | | .set(NcNode::getIsLocked,NcNode.LOCKED) |
| | | .set(NcNode::getRemark,"回传固化同名程序锁定") |
| | | .update(); |
| | | } |
| | | } |