| | |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | 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.flow.entity.ApproveRecord; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.service.ApproveRecordService; |
| | |
| | | import org.springblade.mdm.program.entity.NcProgramExchange; |
| | | import org.springblade.mdm.program.mapper.NcProgramExchangeMapper; |
| | | import org.springblade.mdm.program.vo.DncSendBackData; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.*; |
| | |
| | | @AllArgsConstructor |
| | | public class NcProgramExportDNCService extends BizServiceImpl<NcProgramExchangeMapper, NcProgramExchange> { |
| | | |
| | | private final NcProgramService progService; |
| | | //private final NcProgramService progService; |
| | | private final MachineService machineService; |
| | | private final NcProgramApprovedService approvedService; |
| | | private final ApproveRecordService approveRecordService; |
| | | private final NcNodeService ncNodeService; |
| | | private final OssTemplate ossTemplate; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | public static final String PROGRAM_JSON_FILE = "exp_mdm_nc_program.json"; |
| | | //public static final String PROGRAM_JSON_FILE = "exp_mdm_nc_program.json"; |
| | | public static final String NODE_JSON_FILE = "exp_mdm_nc_node.json"; |
| | | public static final String APPROVE_RECORD_JSON_FILE = "exp_mdm_approve_record.json"; |
| | | |
| | | /** |
| | | * 是否压缩包内的数据文件 |
| | | * @param filename 文件名称 |
| | | * @return |
| | | */ |
| | | public static boolean isDataFile(String filename){ |
| | | return StringUtils.equals(filename, PROGRAM_JSON_FILE) || StringUtils.equals(filename, NODE_JSON_FILE) || StringUtils.equals(filename, APPROVE_RECORD_JSON_FILE); |
| | | } |
| | | /** |
| | | * 分页查询 |
| | | * @param query 查询参数 |
| | |
| | | |
| | | for (Long approvedId : approvedIdArr) { |
| | | NcProgramApproved approved = approvedService.getById(approvedId); |
| | | programPackageNodeIdList.add(approved.getNodeId()); |
| | | programPackageNodeIdList.add(approved.getNcNodeId()); |
| | | |
| | | /* |
| | | String filename = prog.getOssName(); |
| | | InputStream inputStream = ossTemplate.statFileStream(filename); |
| | | |
| | | addInputStreamToZip(zipOut, inputStream, prog.getName()); |
| | | */ |
| | | addProgramPackageToZip(zipOut,approved); |
| | | } |
| | | addDataJson(zipOut, programPackageNodeIdList); |
| | |
| | | zipOut.putNextEntry(zipEntry); |
| | | zipOut.closeEntry(); |
| | | |
| | | List<NcNode> programNodes = ncNodeService.lambdaQuery().eq(NcNode::getParentId, approved.getNodeId()).list(); |
| | | List<NcNode> programNodes = ncNodeService.lambdaQuery().eq(NcNode::getParentId, approved.getNcNodeId()).list(); |
| | | |
| | | FlowProgramFile programFile; |
| | | |
| | | for (NcNode node : programNodes) { |
| | | String filePathInZip = packageFolder + node.getName(); |
| | | ZipEntry fileEntry = new ZipEntry(filePathInZip); |
| | | |
| | | zipOut.putNextEntry(fileEntry); |
| | | programFile = this.flowProgramFileService.getById(node.getFlowProgramFileId()); |
| | | |
| | | InputStream inputStream = ossTemplate.statFileStream(programFile.getOssName()); |
| | | byte[] buffer = new byte[1024]; |
| | | int length; |
| | | while ((length = inputStream.read(buffer)) >= 0) { |
| | | zipOut.write(buffer, 0, length); |
| | | } |
| | | zipOut.closeEntry(); |
| | | Machine machine = machineService.getByCode(node.getMachineCode()); |
| | | InputStream addedIns = addSendPath(inputStream,machine.getProgSendDir()); |
| | | this.addInputStreamToZip(zipOut,addedIns,filePathInZip); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 加入机床下发路径 |
| | | * @param inputStream |
| | | * @return |
| | | */ |
| | | InputStream addSendPath(InputStream inputStream,String machineSendPath) throws IOException { |
| | | return FileContentUtil.insertLine(inputStream,1,machineSendPath); |
| | | |
| | | } |
| | | /** |
| | | * 导入数据文件 |
| | | * @param zipOut |
| | | */ |
| | | void addDataJson(ZipOutputStream zipOut, List<Long> programPackageNodeIdList) throws IOException { |
| | | //addProgramDataJson(zipOut, programPackageNodeIdList); |
| | | addNodeDataJson(zipOut, programPackageNodeIdList); |
| | | addApproveRecordDataJson(zipOut, programPackageNodeIdList); |
| | | } |
| | |
| | | allNodeIds.add(node.getId()); |
| | | } |
| | | //加入程序包下级的程序节点 |
| | | List<NcNode> programNodes = ncNodeService.lambdaQuery().in(NcNode::getParentId, pkgNodes.stream().map(NcNode::getId)).list(); |
| | | List<NcNode> programNodes = ncNodeService.lambdaQuery().in(NcNode::getParentId, pkgNodes.stream().map(NcNode::getId).toList()).list(); |
| | | |
| | | allNodeIds.addAll(programNodes.stream().map(NcNode::getId).toList()); |
| | | List<Long> distinctIds = allNodeIds.stream().distinct().toList(); |
| | |
| | | addSuperProperties(recObj,node); |
| | | jsonArray.add(recObj); |
| | | } |
| | | addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),PROGRAM_JSON_FILE); |
| | | addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),NODE_JSON_FILE); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | recObj.put("machineCode", node.getMachineCode()); |
| | | recObj.put("flowProgramFileId", node.getFlowProgramFileId()); |
| | | recObj.put("processInstanceId", node.getProcessInstanceId()); |
| | | return recObj; |
| | | } |
| | | |
| | |
| | | * @param programPackageNodeIdList 程序包名的id列表 |
| | | */ |
| | | void addApproveRecordDataJson(ZipOutputStream zipOut, List<Long> programPackageNodeIdList) throws IOException { |
| | | List<String> instanceIds = this.ncNodeService.lambdaQuery().in(NcNode::getProcessInstanceId, programPackageNodeIdList) |
| | | /* |
| | | List<String> instanceIds = this.ncNodeService.lambdaQuery().in(NcNode::getId, programPackageNodeIdList) |
| | | .list().stream().map(NcNode::getProcessInstanceId).toList(); |
| | | |
| | | List<ApproveRecord> records = approveRecordService.lambdaQuery().in(ApproveRecord::getProcessInstanceId, instanceIds).list(); |
| | | */ |
| | | //List<ApproveRecord> records = approveRecordService.lambdaQuery().in(ApproveRecord::getProcessInstanceId, instanceIds).list(); |
| | | List<ApproveRecord> records = approveRecordService.lambdaQuery().in(ApproveRecord::getNcNodeId, programPackageNodeIdList).list(); |
| | | |
| | | JSONArray jsonArray = new JSONArray(); |
| | | for(ApproveRecord record : records){ |
| | |
| | | recObj.put("operateTime",record.getOperateTime()); |
| | | recObj.put("operateResult",record.getOperateResult()); |
| | | recObj.put("taskName",record.getTaskName()); |
| | | recObj.put("ncProgramId",record.getNcProgramId()); |
| | | recObj.put("processInstanceId",record.getProcessInstanceId()); |
| | | |
| | | recObj.put("ncNodeId",record.getNcNodeId()); |
| | | addSuperProperties(recObj,record); |
| | | |
| | | jsonArray.add(recObj); |
| | |
| | | recObj.put("createDept",entity.getCreateDept()); |
| | | } |
| | | |
| | | public void addInputStreamToZip(ZipOutputStream zipOut, InputStream inputStream, String entryName) |
| | | /** |
| | | * 将 输入流 中的内容写入zip |
| | | * @param zipOut zip输出流 |
| | | * @param inputStream 输入流 |
| | | * @param entryName 文件名 |
| | | * @throws IOException |
| | | */ |
| | | void addInputStreamToZip(ZipOutputStream zipOut, InputStream inputStream, String entryName) |
| | | throws IOException { |
| | | // 创建新的 ZIP 条目 |
| | | ZipEntry zipEntry = new ZipEntry(entryName); |