| | |
| | | package org.springblade.mdm.commons.service; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.cxf.transport.http.HTTPConduit; |
| | | import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.apache.cxf.endpoint.Client; |
| | |
| | | |
| | | public void send(String fromid,String toids, String ccids, String bccids, String subject, String content, String[] paths) { |
| | | try { |
| | | |
| | | // 创建动态客户端工厂 |
| | | JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); |
| | | |
| | |
| | | //Client client = dcf.createClient("http://localhost:8080/services/EmailService?wsdl"); |
| | | Object[] result; |
| | | try (Client client = dcf.createClient(internalEmailProperties.getMailServiceAddr())) { |
| | | // 获取 HTTPConduit 并配置策略 |
| | | HTTPConduit conduit = (HTTPConduit) client.getConduit(); |
| | | HTTPClientPolicy policy = new HTTPClientPolicy(); |
| | | |
| | | // 设置连接超时(毫秒) |
| | | policy.setConnectionTimeout(10000); |
| | | // 设置接收响应超时(毫秒) |
| | | policy.setReceiveTimeout(10000); |
| | | // 设置重传次数 |
| | | policy.setMaxRetransmits(2); |
| | | conduit.setClient(policy); |
| | | |
| | | // 调用方法 |
| | | result = client.invoke("sendInternalMail", fromid, toids, ccids, bccids, subject, content, null); |
| | | |
| | | // 处理响应 |
| | | if (result != null && result.length > 0) { |
| | | System.out.println("响应: " + result[0]); |
| | | log.info("发送邮件响应:{} " ,result[0]); |
| | | } |
| | | } |
| | | }catch(Exception e) { |
| | |
| | | return R.data(pages); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/export") |
| | | @Operation(summary = "导出现场编制记录", description = "导出现场编制记录") |
| | | public void export(ProgramOnMachineQueryVO queryVO,HttpServletResponse response) throws IOException { |
| | |
| | | */ |
| | | public IPage<FlowVO> finishedPage(IPage<FlowVO> page, ProgramOnMachineQueryVO queryVO) { |
| | | //固化里路村官 |
| | | HistoricProcessInstanceQuery query = this.historyService.createHistoricProcessInstanceQuery().finished().processDefinitionKey(FlowConstant.CURE_PROCESS_KEY).includeProcessVariables(); |
| | | HistoricProcessInstanceQuery query = this.historyService.createHistoricProcessInstanceQuery().finished().processDefinitionKey(FlowConstant.TRY_PROCESS_KEY).includeProcessVariables(); |
| | | //.finished() // 只查询已完成的流程.unfinished() // 查询未完成的流程 |
| | | query.variableNotExists(FlowVariableConstant.EXCEPTION);//非异常流程 |
| | | query.variableValueEquals(FlowVariableConstant.PROGRAM_ON_MACHINE, FlowConstant.Y);//选择现场编制的 |
| | |
| | | } |
| | | try { |
| | | String prefix = UrlUtil.encode(AuthUtil.getNickName()+"-工控网导出"); |
| | | //String filename =AuthUtil.getNickName()+"-"+ DateUtil.format(DateUtil.now(), "yyyyMMddHHmm")+".zip"; |
| | | String filename = prefix+"-"+ DateUtil.format(DateUtil.now(), "yyyyMMddHHmm")+".zip"; |
| | | |
| | | response.setHeader("Content-Disposition", "attachment; filename="+filename); |
| | |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springblade.mdm.machinefile.entity.MachineFile; |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | | import org.springblade.mdm.program.service.programannotation.AnnotationProcessor; |
| | | import org.springblade.mdm.program.service.programannotation.AnnotationUtil; |
| | | import org.springblade.mdm.program.service.programannotation.MachineAnnotationConfig; |
| | | import org.springblade.mdm.program.service.programannotation.ProcessorHelper; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private ParamService paramService; |
| | | @Autowired |
| | | private ProgramAnnotationService programAnnotationService; |
| | | |
| | | @Autowired |
| | | private MachineAnnotationConfig annoConfig; |
| | | |
| | | /** |
| | | * 扫描所有机床的配置目录 |
| | |
| | | List<Path> files = Files.list(dirPath) |
| | | .filter(Files::isRegularFile).toList(); |
| | | |
| | | byte[] buffer = new byte[2048]; |
| | | |
| | | |
| | | //byte[] buffer = new byte[2048]; |
| | | List<DictBiz> annotatiionList = programAnnotationService.getAnnotionDictList(); |
| | | //boolean exists;//文件是否存在于数据库中 |
| | | for (Path filePath : files) { |
| | | try { |
| | | |
| | | |
| | | MachineFile mf = readFileToMachineFile(filePath,machine,dirType,annotatiionList); |
| | | |
| | | machineFileService.refreshFileData(mf); |
| | |
| | | * @return 状态的整数之和 |
| | | * @throws IOException |
| | | */ |
| | | int readProgramStatus(Path filePath,String controlSystem,List<DictBiz> annotatiionList) throws IOException { |
| | | public int readProgramStatus(Path filePath,String controlSystem,List<DictBiz> annotatiionList) throws IOException { |
| | | int programStatus = MachineFile.PROGRAM_STATUS_UNKNOWN; |
| | | try(InputStream ins = Files.newInputStream(filePath); |
| | | BufferedInputStream bis = new BufferedInputStream(ins)){ |
| | |
| | | return MachineFile.PROGRAM_STATUS_UNKNOWN; |
| | | } |
| | | bis.reset(); |
| | | String statusLine = FileContentUtil.readLineAt(ins,ProgramAnnotationService.STATUS_LINE_INDEX); |
| | | |
| | | AnnotationProcessor annoProcessor = ProcessorHelper.getProcessor(controlSystem,annoConfig); |
| | | String statusLine = FileContentUtil.readLineAt(ins, annoProcessor.getAnnotationProperties().getStatusLineIndex()); |
| | | if(AnnotationUtil.isAnnotation(statusLine,controlSystem,annotatiionList)){ |
| | | String progStatusTxt = programAnnotationService.removeAnnotation(controlSystem,statusLine,annotatiionList); |
| | | if(ProgramAnnotationService.SQ.equals(progStatusTxt)){ |
| | | String progStatusTxt = AnnotationUtil.removeAnnotation(controlSystem,statusLine,annotatiionList); |
| | | if(AnnotationUtil.SQ.equals(progStatusTxt)){ |
| | | programStatus = MachineFile.PROGRAM_STATUS_TRY; |
| | | }else if(ProgramAnnotationService.GH.equals(progStatusTxt)){ |
| | | }else if(AnnotationUtil.GH.equals(progStatusTxt)){ |
| | | programStatus = MachineFile.PROGRAM_STATUS_CURED; |
| | | }else if(ProgramAnnotationService.PL.equals(progStatusTxt)){ |
| | | }else if(AnnotationUtil.LG.equals(progStatusTxt)){ |
| | | programStatus = MachineFile.PROGRAM_STATUS_DIVIASTION; |
| | | } |
| | | } |
| | |
| | | zipOut.closeEntry(); |
| | | } |
| | | |
| | | /** |
| | | * 给导出文件增加注释,涉密网要用 |
| | | * @param inputStream |
| | | * @param filename |
| | | * @param machineCode |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | InputStream setAnnotations(InputStream inputStream,String filename,String machineCode) throws IOException { |
| | | Machine machine = this.machineService.getByCode(machineCode); |
| | | AnnotationProcessor annoProcessor = ProcessorHelper.getProcessor(machine.getControlSystem(),annoConfig); |
| | |
| | | |
| | | ByteArrayInputStream bais = new ByteArrayInputStream(IOUtils.toByteArray(inputStream)); |
| | | String statusLine = FileContentUtil.readLineAt(bais,annoProps.getStatusLineIndex()); |
| | | String status = programAnnotationService.removeAnnotation(machine.getControlSystem(),statusLine); |
| | | if(StringUtils.equalsAny(status,"SQ","GH","PL")){ |
| | | String text = programAnnotationService.removeAnnotation(machine.getControlSystem(),statusLine); |
| | | |
| | | if(AnnotationUtil.isStatusContent(text)){ |
| | | //是3种状态之一 |
| | | annoData.setProgramStatus(text); |
| | | }else{ |
| | | //没有按试切处理 |
| | | annoData.setProgramStatus(AnnotationUtil.SQ); |
| | | } |
| | | bais.reset(); |
| | | annoData.setProgramStatus("3"); |
| | | // |
| | | return annoProcessor.putAnnotation(annoData,bais); |
| | | } |
| | | } |
| | |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void check(MachineFile machineFile,List<MachineFile> allFilesInDir,Machine machine) throws IOException { |
| | | |
| | | String srcFilepath = MachineFileService.getBasePath(machine,machineFile.getDirType())+ File.separator+machineFile.getName(); |
| | | Path source = Paths.get(srcFilepath); |
| | | if(!source.toFile().exists()){ |
| | | log.info("开始检查文件{}",srcFilepath); |
| | | Path checkFilePath = Paths.get(srcFilepath); |
| | | if(!checkFilePath.toFile().exists()){ |
| | | return; |
| | | } |
| | | try(InputStream fileIns = Files.newInputStream(Paths.get(srcFilepath));) { |
| | | try(InputStream fileIns = Files.newInputStream(checkFilePath);) { |
| | | int excepType = MachineFile.EXCEPTION_OK; |
| | | if(!FileContentUtil.isTextFile(fileIns)){ |
| | | //非文本 |
| | | machineFile.setExceptionType(MachineFile.EXCEPTION_NOT_TEXT); |
| | | excepType = MachineFile.EXCEPTION_NOT_TEXT; |
| | | }else{ |
| | | Matcher matcher = RegExpConstants.PROGRAM_FILE_PATTERN.matcher(machineFile.getName()); |
| | | |
| | | boolean filenameValid = matcher.find(); |
| | | if(!filenameValid){ |
| | | machineFile.setExceptionType(MachineFile.EXCEPTION_BAD_FILENAME); |
| | | excepType = MachineFile.EXCEPTION_BAD_FILENAME; |
| | | }else { |
| | | ProgramNameVO progNameVO = ProgramFileNameParser.parseProgramName(machineFile.getName()); |
| | | String prefix = progNameVO.logicProgramName()+"-"; |
| | | long matchCount = allFilesInDir.stream().filter(file -> file.getName().startsWith(prefix)).count(); |
| | | if(matchCount != progNameVO.getSegmentCount()){//文件段数缺失 |
| | | machineFile.setExceptionType(MachineFile.EXCEPTION_LOST_FILES); |
| | | excepType = MachineFile.EXCEPTION_LOST_FILES; |
| | | }else{ |
| | | //检查是否匹配下发记录的段数 |
| | | //正负3秒作为查询时间 |
| | |
| | | ProgramNameVO sendProgNameVO = ProgramFileNameParser.parseProgramName(sendFile.getName()); |
| | | if(progNameVO.getSegmentCount() != sendProgNameVO.getSegmentCount()){ |
| | | //段数不匹配 |
| | | machineFile.setExceptionType(MachineFile.EXCEPTION_NOT_MATCH_SEND); |
| | | }else{ |
| | | machineFile.setExceptionType(MachineFile.EXCEPTION_OK); |
| | | excepType = MachineFile.EXCEPTION_NOT_MATCH_SEND; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | machineFile.setExceptionType(excepType); |
| | | log.info("检查文件结束{}",srcFilepath); |
| | | machineFileService.updateById(machineFile); |
| | | } |
| | | } |
| | |
| | | DncBackFile backFIle = this.getById(id); |
| | | |
| | | return ZipTextFileContentUtil.getTextContent(this.ossTemplate.statFileStream(backFIle.getOssName()),entryName); |
| | | /* |
| | | try(InputStream inputStream = this.ossTemplate.statFileStream(backFIle.getOssName());){ |
| | | Path tempZipFile = createTempFile(inputStream); |
| | | |
| | | ZipEntry entry; |
| | | try (java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(tempZipFile.toFile())) { |
| | | Enumeration<? extends ZipEntry> entries = zipFile.entries(); |
| | | while (entries.hasMoreElements()) { |
| | | entry = entries.nextElement(); |
| | | if (!entryName.equals(entry.getName())) { |
| | | continue; |
| | | } |
| | | try (InputStream fileIns = zipFile.getInputStream(zipFile.getEntry(entryName))) { |
| | | ByteArrayInputStream bos = new ByteArrayInputStream(fileIns.readAllBytes()); |
| | | boolean isText = StringUtils.endsWithIgnoreCase(entryName,".txt") || StringUtils.endsWithIgnoreCase(entryName,".nc")|| StringUtils.endsWithIgnoreCase(entryName,".xml"); |
| | | if(!isText) { |
| | | isText = FileContentUtil.isTextFile(bos); |
| | | } |
| | | if (isText) { |
| | | bos.reset(); |
| | | result = FileContentUtil.getContentFromStream(bos); |
| | | } else { |
| | | result = "<非文本文件>"; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | }*/ |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | approved.setStatus(NcProgramApproved.STATUS_EXPORTED); |
| | | approvedService.updateById(approved); |
| | | |
| | | NcNode pkgNode = this.ncNodeService.getById(approved.getNcNodeId()); |
| | | if(pkgNode.isDeviationProgram()){ |
| | | NcNodeHis pkgNodeHis = this.ncNodeHisService.getById(approved.getNcNodeId()); |
| | | if(pkgNodeHis.isDeviationProgram()){ |
| | | //偏离单的程序,如果审批导出记录是解锁形成的,还是需要锁定;普通试切过的,不锁定 |
| | | HistoricProcessInstance hisInst = historyService.createHistoricProcessInstanceQuery().processInstanceId(approved.getProcessInstanceId()).singleResult(); |
| | | if(hisInst != null && hisInst.getProcessDefinitionKey().equals(FlowConstant.UNLOCK_PROCESS_KEY)){ |
| | | pkgNode.lock("下发导出锁定"); |
| | | ncNodeService.updateById(pkgNode); |
| | | NcNode pkgNode = this.ncNodeService.getById(approved.getNcNodeId()); |
| | | if(pkgNode != null) { |
| | | pkgNode.lock("下发导出锁定"); |
| | | ncNodeService.updateById(pkgNode); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | * @param zipOut zip输出流 |
| | | * @param inputStream 输入流 |
| | | * @param entryName 文件名 |
| | | * @throws IOException |
| | | * @throws IOException 写文件异常 |
| | | */ |
| | | void addInputStreamToZip(ZipOutputStream zipOut, InputStream inputStream, String entryName) |
| | | throws IOException { |
| | |
| | | @Autowired |
| | | private IDictBizClient bizDictClient; |
| | | |
| | | private static final String DEFAULT_ANNOTATION_SETTING = "(,)"; |
| | | //private static final String DEFAULT_ANNOTATION_SETTING = "(,)"; |
| | | |
| | | public static final String ANNOTATION_DICT = "machine_annotation"; |
| | | /** |
| | | * 发送目录行索引(第2行) 0 based |
| | | */ |
| | | public static final int SENDPATH_LINE_INDEX = 1; |
| | | ///public static final int SENDPATH_LINE_INDEX = 2; |
| | | /** |
| | | * 状态行索引(第三行) 0 based |
| | | */ |
| | | public static final int STATUS_LINE_INDEX = 2; |
| | | //public static final int STATUS_LINE_INDEX = 3; |
| | | |
| | | /** |
| | | * 偏离单注释行索引号 0 based |
| | | */ |
| | | public static final int STATUS_DEVIATION_INDEX = 3; |
| | | //public static final int STATUS_DEVIATION_INDEX = 4; |
| | | |
| | | public static final String SQ = "SQ"; |
| | | public static final String GH = "GH"; |
| | | public static final String PL = "PL"; |
| | | |
| | | |
| | | public List<DictBiz> getAnnotionDictList(){ |
| | | List<DictBiz> annotationList; |
| | |
| | | |
| | | public class AnnotationUtil { |
| | | static String DEFAULT_ANNOTATION_SETTING = "(,)"; |
| | | public static final String SQ = "SQ"; |
| | | public static final String GH = "GH"; |
| | | public static final String LG = "LG"; |
| | | |
| | | /** |
| | | * 判断是否是注释行 |
| | | * @param text 文字 |
| | | * @return 是否 |
| | | */ |
| | | public static boolean isStatusContent(String text){ |
| | | return StringUtils.containsAny(text,SQ,GH,LG); |
| | | } |
| | | public static ProgramAnnotation getProgramAnnotationFormat(String systemDictVal, List<DictBiz> annoDictList){ |
| | | String begin; |
| | | String end; |
| | |
| | | return finishedStream; |
| | | } |
| | | |
| | | public static String removeAnnotation(String systemDictVal,String text,List<DictBiz> annotatiionList){ |
| | | return getProgramAnnotationFormat(systemDictVal,annotatiionList).cleanAnnotation(text); |
| | | } |
| | | } |
| | |
| | | private ParamService paramService; |
| | | @Autowired |
| | | private ReceiveFileCheckService receiveFileCheckService; |
| | | /** |
| | | * 文件默认保存小时数,0不限制 |
| | | */ |
| | | private static final int DEFAULT_HOUR = 0; |
| | | |
| | | // 每5秒执行一次 |
| | | //@Scheduled(fixedRate = 1000000) |
| | | //@Scheduled(cron = "0 1 0 * * ?") // 每天上午0点1分执行 |
| | | //@Scheduled(cron = "0 */3 * * * ?") |
| | | //@Scheduled(cron = "0 15 19 * * ?") //test |
| | | //@Scheduled(cron = "${task.cron.machine_file_scan}") |
| | | @Scheduled(cron = "${task.cron.machine_rec_check:0 */10 * * * ?}") |
| | | @Scheduled(cron = "${task.cron.machine_rec_check:0 */11 * * * ?}") |
| | | public void execute() { |
| | | String networkType = paramService.getParamValue(ParamService.NETWORK_TYPE,ParamService.NETWORK_TYPE_SHEMI); |
| | | |
| | | if(!ParamService.NETWORK_TYPE_SHEMI.equals(networkType)){ |
| | | //非涉密网,才扫描目录文件 |
| | | log.info("reccheckfile start"); |
| | | checkFiles(); |
| | | |
| | | log.info("reccheckfile end"); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | if(!ParamService.NETWORK_TYPE_SHEMI.equals(networkType)){ |
| | | //非涉密网,才扫描目录文件 |
| | | moveOverTimeFiles(); |
| | | moveValidateFiles(); |
| | | } |
| | | |
| | | } |
| | |
| | | /** |
| | | * 扫描数据库记录,超时则移动文件 |
| | | */ |
| | | public void moveOverTimeFiles() { |
| | | public void moveValidateFiles() { |
| | | List<Machine> machines = machineService.getEnableMachines(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | for (Machine machine : machines) { |
| | | int remainHours = machine.getReceiveDirExpiryHours() != null ?machine.getReceiveDirExpiryHours():DEFAULT_HOUR; |
| | | if(remainHours == 0){ |
| | | /*if(remainHours == 0){ |
| | | continue; |
| | | } |
| | | LocalDateTime earlyTime = now.minusHours(remainHours); |
| | | List<MachineFile> overTimeFiles = this.machineFileService.lambdaQuery().lt(MachineFile::getFileCreateTime,earlyTime) |
| | | }*/ |
| | | //LocalDateTime earlyTime = now.minusHours(remainHours); |
| | | List<MachineFile> pendingFiles = this.machineFileService.lambdaQuery() |
| | | .eq(MachineFile::getDirType,MachineFile.DIR_TYPE_REC) |
| | | .eq(MachineFile::getExceptionType,MachineFile.EXCEPTION_OK) |
| | | .eq(MachineFile::getMachineCode,machine.getCode()).list(); |
| | | //.lt(MachineFile::getFileCreateTime,earlyTime) |
| | | |
| | | for(MachineFile overTimeFile : overTimeFiles){ |
| | | for(MachineFile overTimeFile : pendingFiles){ |
| | | try { |
| | | moveFileToTemp(overTimeFile, machine); |
| | | }catch(Exception e){ |
| | | log.error("移动rec文件失败:"+overTimeFile.getName(),e); |
| | | log.error("移动rec文件失败:{}",overTimeFile.getName(),e); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | @GetMapping("/sendmail") |
| | | @Operation(summary = "sendmail", description = "sendmail") |
| | | public R<Void> sendmail(String code) throws IOException, MessagingException { |
| | | |
| | | public R<Void> sendmail(String from,String to,String subject,String content) throws IOException, MessagingException { |
| | | this.mailService.send(from,to,null,null,subject,content,null); |
| | | return R.success(); |
| | | } |
| | | |