| | |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.gkw.programnode.vo.ProgramNameVO; |
| | | import org.springblade.mdm.gkw.task.entity.MachineBackTask; |
| | | import org.springblade.mdm.gkw.task.service.MachineBackTaskService; |
| | | import org.springblade.mdm.machinefile.entity.MachineFile; |
| | | import org.springblade.mdm.machinefile.entity.MachineAcceptedFile; |
| | | import org.springblade.mdm.machinefile.mapper.MachineAcceptedFileMapper; |
| | | import org.springblade.mdm.machinefile.vo.MachineAcceptedFileHandleQueryVO; |
| | | import org.springblade.mdm.machinefile.vo.MachineBackFileQueryVO; |
| | | import org.springblade.mdm.machinefile.vo.MachineAcceptedFileVO; |
| | | import org.springblade.mdm.program.service.programannotation.AnnotationData; |
| | | import org.springblade.mdm.program.service.programannotation.AnnotationProcessor; |
| | | import org.springblade.mdm.program.service.programannotation.AnnotationProcessorHelper; |
| | | import org.springblade.mdm.utils.ProgramFileNameParser; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | import java.io.InputStream; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | @AllArgsConstructor |
| | | |
| | | @Service |
| | | public class MachineAcceptedFileService extends BizServiceImpl<MachineAcceptedFileMapper, MachineAcceptedFile> { |
| | | private final MachineFileService machineFileService; |
| | | private final OssTemplate ossTemplate; |
| | | @Autowired |
| | | private MachineFileService machineFileService; |
| | | @Autowired |
| | | private OssTemplate ossTemplate; |
| | | @Autowired |
| | | private MachineBackTaskService machineBackTaskService; |
| | | @Autowired |
| | | private AnnotationProcessorHelper annotationProcessorHelper; |
| | | /** |
| | | * 接受 |
| | | * @param ids |
| | | * @param ids 选定接受的id,逗号分隔 |
| | | */ |
| | | @Transactional |
| | | public void accept(String ids) throws IOException { |
| | |
| | | |
| | | /** |
| | | * 拒绝 |
| | | * @param ids |
| | | * @param ids 选定拒绝的id,逗号分隔 |
| | | */ |
| | | public void reject(String ids) { |
| | | List<Long> idList = Func.toLongList(ids); |
| | |
| | | /** |
| | | * 接收文件 |
| | | * @param machineFileId 机床文件id |
| | | * @throws IOException |
| | | * @throws IOException 文件操作异常 |
| | | */ |
| | | void acceptFile(Long machineFileId) throws IOException { |
| | | MachineFile machineFile = machineFileService.getById(machineFileId); |
| | |
| | | BladeFile bfile = ossTemplate.putFile(machineFile.getName(),inputStream); |
| | | machineAcceptedFile.setOssName(bfile.getName()); |
| | | } |
| | | try(InputStream inputStream = Files.newInputStream(Paths.get(fullPath));){ |
| | | //都数据 |
| | | //Machine machine = this.machineService.getByCode(record.getMachineCode()); |
| | | //AnnotationProcessor processor = annotationProcessorHelper.getProcessor(machine.getControlSystem()); |
| | | //AnnotationData annotationData = processor.readAnnotationData(inputStream); |
| | | machineAcceptedFile.setBackTaskId(getMachineBackTaskId(machineAcceptedFile.getName(),machineFile.getDeviation())); |
| | | } |
| | | |
| | | save(machineAcceptedFile); |
| | | } |
| | | |
| | | Long getMachineBackTaskId(String filename,String deviation){ |
| | | ProgramNameVO vo = ProgramFileNameParser.parseProgramName(filename); |
| | | MachineBackTask task = machineBackTaskService.queryMatchTaskByProgramName(vo,deviation); |
| | | if(task != null){ |
| | | return task.getId(); |
| | | }else{ |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | return this.getBaseMapper().handlePageQuery(Condition.getPage(query),query); |
| | | } |
| | | |
| | | /** |
| | | * 根据导出的接受文件id,获取其中现场编程的MachineFIle |
| | | * @param acceptedFiles 导出的接受文件列表 |
| | | * @return machineFile |
| | | */ |
| | | public List<MachineFile> exportedProgramOnMachineFiles(List<MachineAcceptedFile> acceptedFiles) { |
| | | |
| | | List<Long> backTaskIds = acceptedFiles.stream().map(MachineAcceptedFile::getBackTaskId).filter(Objects::nonNull).toList(); |
| | | |
| | | //现场编程的任务集合 |
| | | //List<MachineBackTask> onMachineTasks1 = machineBackTaskService.lambdaQuery().in(MachineBackTask::getId, backTaskIds).list(); |
| | | List<MachineBackTask> onMachineTasks = machineBackTaskService.lambdaQuery() |
| | | .eq(MachineBackTask::getTaskType,MachineBackTask.TASK_TYPE_ON_MACHINE) |
| | | .in(MachineBackTask::getId, backTaskIds).list(); |
| | | |
| | | List<Long> onMachineFileIds = new ArrayList<>(); |
| | | for(MachineAcceptedFile accFile : acceptedFiles){ |
| | | for(MachineBackTask backTask : onMachineTasks){ |
| | | if(backTask.getId().equals(accFile.getBackTaskId())){ |
| | | onMachineFileIds.add(accFile.getMachineFileId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return machineFileService.lambdaQuery().in(MachineFile::getId,onMachineFileIds).list(); |
| | | } |
| | | } |