| | |
| | | |
| | | package org.springblade.mdm.program.service; |
| | | |
| | | import com.alibaba.csp.sentinel.util.StringUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.springblade.core.mp.base.BizEntity; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | |
| | | import org.springblade.mdm.flow.service.ApproveRecordService; |
| | | import org.springblade.mdm.flow.service.FlowProgramFileService; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.entity.NcProgram; |
| | | import org.springblade.mdm.program.entity.NcProgramApproved; |
| | | 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.springblade.system.feign.IDictClient; |
| | | import org.springblade.system.feign.ISysClient; |
| | | import org.springblade.system.pojo.entity.Dict; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | private final NcNodeService ncNodeService; |
| | | private final OssTemplate ossTemplate; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final ProgramAnnotationService programAnnotationService; |
| | | //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"; |
| | | //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"; |
| | | |
| | | public static final String ANNOTATION_DICT = "machine_annotation"; |
| | | |
| | |
| | | |
| | | /** |
| | | * 导出dnc压缩包 |
| | | * @param approvedIdArr 待导出审批表id数组 |
| | | * @param approvedIdArray 待导出审批表id数组 |
| | | */ |
| | | public void exportDnc(Long[] approvedIdArr, OutputStream os) throws IOException { |
| | | public void exportDnc(Long[] approvedIdArray, OutputStream os) throws IOException { |
| | | //FileOutputStream fos = new FileOutputStream("d:/exportDnc.zip"); |
| | | try (ZipOutputStream zipOut = new ZipOutputStream(os);) {//os |
| | | |
| | | ArrayList<Long> programPackageNodeIdList = new ArrayList<Long>(); |
| | | //ArrayList<Long> programPackageNodeIdList = new ArrayList<Long>(); |
| | | |
| | | for (Long approvedId : approvedIdArr) { |
| | | for (Long approvedId : approvedIdArray) { |
| | | NcProgramApproved approved = approvedService.getById(approvedId); |
| | | programPackageNodeIdList.add(approved.getNcNodeId()); |
| | | //programPackageNodeIdList.add(approved.getNcNodeId()); |
| | | |
| | | addProgramPackageToZip(zipOut,approved); |
| | | } |
| | | addDataJson(zipOut, programPackageNodeIdList); |
| | | |
| | | //状态修改为已导出 |
| | | approvedService.lambdaUpdate().in(NcProgramApproved::getId, approvedIdArray) |
| | | .set(NcProgramApproved::getStatus,NcProgramApproved.STATUS_EXPORTED).update(); |
| | | //addDataJson(zipOut, programPackageNodeIdList); |
| | | } |
| | | |
| | | os.close(); |
| | |
| | | |
| | | FlowProgramFile programFile; |
| | | NcNode programPackageNode = this.ncNodeService.getById(approved.getNcNodeId()); |
| | | String status = "试切"; |
| | | if(programPackageNode.isDeviation()){ |
| | | status = "偏离"; |
| | | String status = "SQ"; |
| | | if(programPackageNode.isDeviationProgram()){ |
| | | status = "PL"; |
| | | }else if(programPackageNode.hasCured()){ |
| | | status = "固化"; |
| | | status = "GH"; |
| | | } |
| | | List<Dict> annotationList = getAnnotionList(); |
| | | List<Dict> annotationList = programAnnotationService.getAnnotionList(); |
| | | for (NcNode node : programNodes) { |
| | | String filePathInZip = packageFolder + node.getName(); |
| | | programFile = this.flowProgramFileService.getById(node.getFlowProgramFileId()); |
| | |
| | | * @return |
| | | */ |
| | | InputStream addSendDirAnnotation(InputStream inputStream,Machine machine,List<Dict> annotationList) throws IOException { |
| | | return FileContentUtil.insertLine(inputStream,1,generateAnnotation(machine.getProgSendDir(),machine.getMachineGroupCode(),annotationList)); |
| | | //检测第二行是否是路径 |
| | | String annotationText = programAnnotationService.generateAnnotation(machine.getProgSendDir()==null? StringUtil.EMPTY:machine.getProgSendDir(),machine.getMachineGroupCode(),annotationList); |
| | | |
| | | //TODO 改判断行内容 |
| | | return FileContentUtil.insertLine(inputStream,1,annotationText); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws IOException |
| | | */ |
| | | InputStream addProgramStatusAnnotation(InputStream inputStream,String status,Machine machine,List<Dict> annotationList) throws IOException { |
| | | return FileContentUtil.insertLine(inputStream,2,generateAnnotation(status,machine.getMachineGroupCode(),annotationList)); |
| | | String annoText= programAnnotationService.generateAnnotation(status,machine.getMachineGroupCode(),annotationList); |
| | | |
| | | return FileContentUtil.insertLine(inputStream,2,annoText); |
| | | } |
| | | |
| | | /** |
| | | * 判断一行文本是否是注释 |
| | | * @param line |
| | | * @param annotationList |
| | | * @return |
| | | */ |
| | | boolean isAnnotation(String line,List<Dict> annotationList){ |
| | | boolean isAnno = false; |
| | | |
| | | return isAnno; |
| | | } |
| | | |
| | | |
| | | |
| | | String generateAnnotation(String oriTest,String machineGroupCode,List<Dict> annotationList) { |
| | | R<List<Dict>> dictsResult = dictClient.getList(ANNOTATION_DICT); |
| | |
| | | * 导入数据文件 |
| | | * @param zipOut |
| | | */ |
| | | /* |
| | | void addDataJson(ZipOutputStream zipOut, List<Long> programPackageNodeIdList) throws IOException { |
| | | addNodeDataJson(zipOut, programPackageNodeIdList); |
| | | addApproveRecordDataJson(zipOut, programPackageNodeIdList); |
| | | } |
| | | |
| | | */ |
| | | |
| | | /** |
| | | * zip保重加入节点的数据 |
| | |
| | | * @param pkgNodeIdList |
| | | * @throws IOException |
| | | */ |
| | | /* |
| | | void addNodeDataJson(ZipOutputStream zipOut,List<Long> pkgNodeIdList) throws IOException { |
| | | List<NcNode> pkgNodes = this.ncNodeService.lambdaQuery().in(NcNode::getId, pkgNodeIdList).list(); |
| | | |
| | |
| | | addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),NODE_JSON_FILE); |
| | | |
| | | } |
| | | |
| | | */ |
| | | /* |
| | | @NotNull |
| | | private static JSONObject getNodeJsonObject(NcNode node) { |
| | | JSONObject recObj = new JSONObject(); |
| | |
| | | recObj.put("processInstanceId", node.getProcessInstanceId()); |
| | | return recObj; |
| | | } |
| | | |
| | | */ |
| | | /** |
| | | * 导入审批记录 |
| | | * @param zipOut |
| | | * @param programPackageNodeIdList 程序包名的id列表 |
| | | */ |
| | | /* |
| | | void addApproveRecordDataJson(ZipOutputStream zipOut, List<Long> programPackageNodeIdList) throws IOException { |
| | | /* |
| | | 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::getNcNodeId, programPackageNodeIdList).list(); |
| | | |
| | |
| | | } |
| | | addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),"exp_mdm_approve_record.json"); |
| | | |
| | | } |
| | | }*/ |
| | | |
| | | void addSuperProperties(JSONObject recObj, BizEntity entity){ |
| | | recObj.put("tenantId",entity.getTenantId()); |