| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.flowable.engine.*; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.mdm.basesetting.machine.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.program.mapper.NcProgramMapper; |
| | | import org.springblade.mdm.program.entity.NcProgram; |
| | | import org.springblade.mdm.program.vo.DncSendBackData; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | @AllArgsConstructor |
| | | public class NcProgramService extends BizServiceImpl<NcProgramMapper, NcProgram> { |
| | | |
| | | private final ObjectMapper objectMapper; |
| | | private final RepositoryService repositoryService; |
| | | private final RuntimeService runtimeService; |
| | | private final HistoryService historyService; |
| | | private final TaskService taskService; |
| | | private final ProcessEngine processEngine; |
| | | private final MachineService machineService; |
| | | |
| | | private final OssTemplate ossTemplate; |
| | | /** |
| | | * 查询现有固化的程序,暂定条件:零组件号相同,且是同一机床组 |
| | | * @param partNo |
| | |
| | | return this.getBaseMapper().getCuredNcProgram(partNo,machine.getMachineGroupCode()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 上传程序文件到指定节点 |
| | | * @param file |
| | | * @param nodeId |
| | | * @param category |
| | | * @param category 文件分类(程序文件/其他文件) |
| | | */ |
| | | public void uploadNcFile(MultipartFile file, Long nodeId, String category) { |
| | | public void uploadProgramFile(MultipartFile file, Long nodeId, String category) { |
| | | BladeFile bfile = ossTemplate.putFile(file); |
| | | String link = bfile.getLink(); |
| | | //保存profame |
| | | NcProgram prog = new NcProgram(); |
| | | prog.setName(file.getOriginalFilename()); |
| | | prog.setNcNodeId(nodeId); |
| | | prog.setOssName(bfile.getName()); |
| | | boolean isTextFile = false; |
| | | try { |
| | | isTextFile = FileContentUtil.isTextFile(file.getInputStream()); |
| | | } catch (IOException e) { |
| | | log.warn("判断是否文本文件异常",e); |
| | | } |
| | | prog.setIsTextFile(isTextFile); |
| | | prog.setUrl(link); |
| | | prog.setCategory(category); |
| | | |
| | | this.save(prog); |
| | | } |
| | | |
| | | /** |
| | | * 删除一个程序 |
| | | * @param id |
| | | */ |
| | | public String getFileContent(Long id) { |
| | | String result =""; |
| | | |
| | | NcProgram prog = this.getById(id); |
| | | String fileName = prog.getOssName(); |
| | | try (InputStream inputStream = ossTemplate.statFileStream(fileName)) { |
| | | result = IOUtils.toString(inputStream, StandardCharsets.UTF_8); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return result; |
| | | } |
| | | /** |
| | | * 删除一个程序 |
| | | * @param id |
| | | */ |
| | | public void removeProgram(Long id) { |
| | | NcProgram prog = this.getById(id); |
| | | ossTemplate.removeFile(prog.getOssName()); |
| | | this.getBaseMapper().deleteById(id); |
| | | } |
| | | } |