| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.flowable.engine.*; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.text.DecimalFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | |
| | | /** |
| | | * 工作流服务实现类 |
| | |
| | | public class NcProgramService extends BizServiceImpl<NcProgramMapper, NcProgram> { |
| | | |
| | | private final MachineService machineService; |
| | | |
| | | private final OssTemplate ossTemplate; |
| | | private final NcNodeService nodeService; |
| | | |
| | | private final ProgramSeqMapper seqMapper; |
| | | /** |
| | | * 查询现有固化的程序,暂定条件:零组件号相同,且是同一机床组 |
| | | * @param partNo |
| | | * @param drwaingNo |
| | | * @param machineCode |
| | | * @return |
| | | */ |
| | | public List<NcProgram> getCuredNcProgram(String partNo,String machineCode) { |
| | | public List<NcProgram> getCuredNcProgram(String drwaingNo,String machineCode) { |
| | | Machine machine = machineService.getByCode(machineCode); |
| | | return this.getBaseMapper().getCuredNcProgram(partNo,machine.getMachineGroupCode()); |
| | | return this.getBaseMapper().getCuredNcProgram(drwaingNo,machine.getMachineGroupCode()); |
| | | } |
| | | |
| | | |
| | |
| | | prog.setName(file.getOriginalFilename()); |
| | | prog.setNcNodeId(uploadVO.getNodeId()); |
| | | prog.setOssName(bfile.getName()); |
| | | prog.setPartNo(uploadVO.getPartNo()); |
| | | prog.setDrawingNo(uploadVO.getDrawingNo()); |
| | | prog.setProcessEdition(uploadVO.getProcessEdition()); |
| | | prog.setIsLastEdition(1); |
| | | boolean isTextFile = false; |
| | |
| | | prog.setName(file.getOriginalFilename()); |
| | | prog.setNcNodeId(uploadVO.getNodeId()); |
| | | prog.setOssName(bfile.getName()); |
| | | prog.setPartNo(uploadVO.getPartNo()); |
| | | prog.setDrawingNo(uploadVO.getDrawingNo()); |
| | | prog.setProcessEdition(uploadVO.getProcessEdition()); |
| | | prog.setIsLastEdition(1); |
| | | prog.setMachineCode(uploadVO.getMachineCode()); |
| | | prog.setProcessName(uploadVO.getProcessName()); |
| | | boolean isTextFile = false; |
| | | try { |
| | | isTextFile = FileContentUtil.isTextFile(file.getInputStream()); |
| | |
| | | node.setName(prog.getName()); |
| | | node.setMachineCode(uploadVO.getMachineCode()); |
| | | node.setParentId(uploadVO.getNodeId()); |
| | | node.setPartNo(uploadVO.getPartNo()); |
| | | node.setDrawingNo(uploadVO.getDrawingNo()); |
| | | node.setProcessName(uploadVO.getProcessName()); |
| | | |
| | | nodeService.save(node); |
| | |
| | | |
| | | /** |
| | | * 升版(升级工序版次),升级工序版本(包括程序和其他附件) |
| | | * @param id 程序文件id |
| | | * @param bindNcNodeId 程序文件绑定的节点id |
| | | * @param newProcessEdition 新版次 |
| | | */ |
| | | public void upgradeProcessEdition(long id,String newProcessEdition) { |
| | | NcProgram prog = this.getById(id); |
| | | public void upgradeProcessEdition(Long bindNcNodeId,String newProcessEdition) { |
| | | //NcProgram prog = this.getById(id); |
| | | NcProgram prog = getByBindNodeId(bindNcNodeId); |
| | | |
| | | //将现有程序更新为非最新版本 |
| | | this.update(Wrappers.lambdaUpdate(NcProgram.class).eq(NcProgram::getId,id).set(NcProgram::getIsLastEdition,0)); |
| | | this.update(Wrappers.lambdaUpdate(NcProgram.class).eq(NcProgram::getBindNcNodeId,bindNcNodeId).set(NcProgram::getIsLastEdition,0)); |
| | | |
| | | NcProgram newVerProg = new NcProgram(); |
| | | BeanUtils.copyProperties(prog, newVerProg); |
| | |
| | | public IPage<NcProgramVO> pageQuery(NcNodeProgramQueryVO query) { |
| | | return this.getBaseMapper().pageQuery(Condition.getPage(query),query); |
| | | } |
| | | |
| | | /** |
| | | * 下发给你机床 |
| | | * @param bindNcNodeId 与程序绑定的节点id |
| | | */ |
| | | public void sendByBindNodeId(Long bindNcNodeId) throws IOException { |
| | | //NcNode node = this.nodeService.getById(bindNodeId); |
| | | LambdaQueryWrapper<NcProgram> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(NcProgram::getBindNcNodeId, bindNcNodeId); |
| | | wrapper.eq(NcProgram::getIsLastEdition,1); |
| | | NcProgram prog = this.getOne(wrapper); |
| | | String filePath = prog.getName(); |
| | | try(InputStream ins = ossTemplate.statFileStream(prog.getOssName());){ |
| | | File targetFile = new File(filePath); |
| | | FileUtils.copyInputStreamToFile(ins, targetFile); |
| | | } |
| | | } |
| | | |
| | | String getFilePath(NcProgram prog){ |
| | | Machine machine = machineService.getByCode(prog.getMachineCode()); |
| | | String dirPath = machine.getProgSendDir(); |
| | | |
| | | dirPath = StringUtils.removeEnd(StringUtils.removeEnd(dirPath,"/"),"\\"); |
| | | File dirs = new File(dirPath); |
| | | if(!dirs.exists()){ |
| | | dirs.mkdirs(); |
| | | } |
| | | |
| | | return dirPath+File.separator+prog.getName(); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param bindNcNodeId |
| | | * @return |
| | | */ |
| | | public NcProgram getByBindNodeId(Long bindNcNodeId) { |
| | | |
| | | LambdaQueryWrapper<NcProgram> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(NcProgram::getBindNcNodeId, bindNcNodeId); |
| | | wrapper.eq(NcProgram::getIsLastEdition,1); |
| | | |
| | | Optional<NcProgram> progOpt = this.getOneOpt(wrapper); |
| | | |
| | | return progOpt.orElse(null); |
| | | } |
| | | } |