| | |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.flow.entity.ApproveRecord; |
| | | import org.springblade.mdm.flow.service.ApproveRecordService; |
| | | import org.springblade.mdm.gkw.programnode.entity.MachineFile; |
| | | import org.springblade.mdm.gkw.programnode.service.MachineFileService; |
| | | import org.springblade.mdm.machineback.entity.MachineBackFile; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.entity.NcProgram; |
| | |
| | | import org.springblade.mdm.program.service.NcProgramApprovedService; |
| | | import org.springblade.mdm.program.service.NcProgramService; |
| | | import org.springblade.mdm.program.vo.DncSendBackData; |
| | | import org.springblade.mdm.utils.ProgramFileNameParser; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipOutputStream; |
| | | |
| | |
| | | public class NcProgramExportInnerService extends BizServiceImpl<NcProgramExchangeMapper, NcProgramExchange> { |
| | | private final MachineBackFileService machineBackFileService; |
| | | private final NcProgramService progService; |
| | | |
| | | private final MachineFileService machineFileService; |
| | | private final NcNodeService ncNodeService; |
| | | private final OssTemplate ossTemplate; |
| | | |
| | |
| | | |
| | | /** |
| | | * 导出到涉密网 |
| | | * @param backFileIds |
| | | * @param machineFileIds |
| | | * @param os |
| | | * @throws IOException |
| | | */ |
| | | public void exportToInner(Long[] backFileIds, ServletOutputStream os) throws IOException { |
| | | public void exportToInner(List<Long> machineFileIds, ServletOutputStream os) throws IOException { |
| | | //FileOutputStream fos = new FileOutputStream("d:/exportDnc.zip"); |
| | | try (ZipOutputStream zipOut = new ZipOutputStream(os);) {//os |
| | | |
| | | ArrayList<Long> programIdList = new ArrayList<Long>(); |
| | | List<MachineFile> macineFiles = machineFileService.lambdaQuery().in(MachineFile::getId,machineFileIds).list(); |
| | | Map<String,List<MachineFile>> map = macineFiles.stream() |
| | | .collect(Collectors.groupingBy(s -> ProgramFileNameParser.parseProgramName(s.getName()).logicProgramName())); |
| | | |
| | | for (Long backId : backFileIds) { |
| | | MachineBackFile backFile = machineBackFileService.getById(backId); |
| | | programIdList.add(backFile.getNcProgramId()); |
| | | |
| | | NcProgram prog = progService.getById(backFile.getNcProgramId()); |
| | | |
| | | //1111,需要装在文件 |
| | | String filename = prog.getOssName(); |
| | | InputStream inputStream = ossTemplate.statFileStream(filename); |
| | | |
| | | addInputStreamToZip(zipOut, inputStream, prog.getName()); |
| | | for (Map.Entry<String, List<MachineFile>> entry : map.entrySet()) { |
| | | String programName = entry.getKey(); |
| | | List<MachineFile> progMachineFiles = entry.getValue(); |
| | | for (MachineFile mf : progMachineFiles) { |
| | | try(InputStream ins = machineFileService.getInputStream(mf)) { |
| | | addInputStreamToZip(zipOut,ins , programName + "/" + mf.getName()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | addDataJson(zipOut, programIdList); |
| | | } |
| | | |
| | | os.close(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 导入数据文件 |
| | | * @param zipOut |
| | | */ |
| | | void addDataJson(ZipOutputStream zipOut, List<Long> programIdList) throws IOException { |
| | | addProgramDataJson(zipOut, programIdList); |
| | | //addApproveRecordDataJson(zipOut, programIdList); |
| | | |
| | | addNcNodeDataJson(zipOut, programIdList); |
| | | } |
| | | |
| | | /** |
| | | * 导入程序记录 |
| | | * @param zipOut |
| | | * @param programIdList |
| | | */ |
| | | void addProgramDataJson(ZipOutputStream zipOut, List<Long> programIdList) throws IOException { |
| | | LambdaQueryWrapper<NcProgram> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.in(NcProgram::getId, programIdList); |
| | | List<NcProgram> programList = progService.list(queryWrapper); |
| | | JSONArray jsonArray = new JSONArray(); |
| | | for(NcProgram program : programList){ |
| | | JSONObject recObj = new JSONObject(); |
| | | recObj.put("id", program.getId()); |
| | | recObj.put("code", program.getCode()); |
| | | recObj.put("ossName",program.getOssName()); |
| | | recObj.put("isTextFile",program.getIsTextFile()); |
| | | recObj.put("isLastEdition",program.getIsLastEdition()); |
| | | recObj.put("category",program.getCategory()); |
| | | recObj.put("description",program.getDescription()); |
| | | recObj.put("name",program.getName()); |
| | | recObj.put("drawingNo",program.getDrawingNo()); |
| | | recObj.put("ncNodeId",program.getNcNodeId()); |
| | | recObj.put("bindNcNodeId",program.getBindNcNodeId()); |
| | | recObj.put("url",program.getUrl()); |
| | | recObj.put("isCured",program.getIsCured()); |
| | | recObj.put("isLocked",program.getIsLocked()); |
| | | recObj.put("isTest",program.getIsTest()); |
| | | recObj.put("machineCode",program.getMachineCode()); |
| | | recObj.put("processEdition",program.getProcessEdition()); |
| | | recObj.put("taskAssignTime",program.getTaskAssignTime()); |
| | | |
| | | addSuperProperties(recObj,program); |
| | | |
| | | jsonArray.add(recObj); |
| | | } |
| | | addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),PROGRAM_JSON_FILE); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 导入审批记录 |
| | | * @param zipOut |
| | | * @param programIdList 数控程序id列表 |
| | | */ |
| | | /* |
| | | void addApproveRecordDataJson(ZipOutputStream zipOut, List<Long> programIdList) throws IOException { |
| | | LambdaQueryWrapper<ApproveRecord> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.in(ApproveRecord::getNcProgramId, programIdList); |
| | | List<ApproveRecord> records = approveRecordService.list(queryWrapper); |
| | | JSONArray jsonArray = new JSONArray(); |
| | | for(ApproveRecord record : records){ |
| | | JSONObject recObj = new JSONObject(); |
| | | recObj.put("id", record.getId()); |
| | | recObj.put("comment", record.getComment()); |
| | | recObj.put("userId",record.getUserId()); |
| | | recObj.put("userNickname",record.getUserNickname()); |
| | | 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()); |
| | | |
| | | addSuperProperties(recObj,record); |
| | | |
| | | jsonArray.add(recObj); |
| | | } |
| | | addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),"exp_mdm_approve_record.json"); |
| | | |
| | | } |
| | | */ |
| | | /** |
| | | * 导入节点 |
| | | * @param zipOut |
| | | * @param programIdList |
| | | */ |
| | | void addNcNodeDataJson(ZipOutputStream zipOut, List<Long> programIdList) throws IOException { |
| | | LambdaQueryWrapper<NcProgram> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.in(NcProgram::getId, programIdList); |
| | | |
| | | List<NcProgram> programs = progService.list(queryWrapper); |
| | | JSONArray jsonArray = new JSONArray(); |
| | | |
| | | ArrayList<Long> exportNodeIdList = new ArrayList<>(); |
| | | for(NcProgram program : programs){ |
| | | //JSONObject recObj = new JSONObject(); |
| | | if(!exportNodeIdList.contains(program.getBindNcNodeId())){ |
| | | exportNodeIdList.add(program.getBindNcNodeId()); |
| | | } |
| | | NcNode ncNode = ncNodeService.getById(program.getBindNcNodeId());//从绑定的节点本身开始导出 |
| | | |
| | | if(StringUtils.isNotEmpty(ncNode.getParentIds())){ |
| | | List<Long> pids = Func.toLongList(ncNode.getParentIds()); |
| | | for(Long nodeId : pids){ |
| | | if(!exportNodeIdList.contains(nodeId)){ |
| | | exportNodeIdList.add(nodeId); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | LambdaQueryWrapper<NcNode> nodeQueryWrapper = new LambdaQueryWrapper<>(); |
| | | nodeQueryWrapper.in(NcNode::getId, exportNodeIdList); |
| | | List<NcNode> nodeList =ncNodeService.list(nodeQueryWrapper); |
| | | for(NcNode node : nodeList){ |
| | | JSONObject recObj = new JSONObject(); |
| | | |
| | | recObj.put("id", node.getId()); |
| | | recObj.put("nodeType", node.getNodeType()); |
| | | recObj.put("machineCode",node.getMachineCode()); |
| | | recObj.put("parentId",node.getParentId()); |
| | | recObj.put("description",node.getDescription()); |
| | | recObj.put("name",node.getName()); |
| | | recObj.put("remark",node.getRemark()); |
| | | recObj.put("drawingNo",node.getDrawingNo()); |
| | | recObj.put("parentIds",node.getParentIds()); |
| | | recObj.put("processName",node.getProcessName()); |
| | | |
| | | addSuperProperties(recObj,node); |
| | | |
| | | jsonArray.add(recObj); |
| | | } |
| | | addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),"exp_mdm_nc_node.json"); |
| | | } |
| | | |
| | | void addSuperProperties(JSONObject recObj, BizEntity entity){ |
| | | recObj.put("tenantId",entity.getTenantId()); |
| | | recObj.put("createTime",entity.getCreateTime()); |
| | | recObj.put("updateTime",entity.getUpdateTime()); |
| | | recObj.put("createUser",entity.getCreateUser()); |
| | | recObj.put("updateUser",entity.getUpdateUser()); |
| | | recObj.put("status",entity.getStatus()); |
| | | recObj.put("createDept",entity.getCreateDept()); |
| | | } |
| | | |
| | | public void addInputStreamToZip(ZipOutputStream zipOut, InputStream inputStream, String entryName) |
| | | throws IOException { |