diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/CcbFtpUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/CcbFtpUtils.groovy index 3fffa870c..74474aff6 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/CcbFtpUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/CcbFtpUtils.groovy @@ -57,6 +57,12 @@ class CcbFtpUtils { ftpUpload(dataCodeFileName)//上传加密码文件到FTP } + static def listFileNames(month){ + //上传到ftp + sftpChannel = reConnect(); + Vector files = sftp.listFiles(ftpPath+ month+"/", sftpChannel); + return files + } static main(args) { diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/ExportOracleEvaluationData.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/ExportOracleEvaluationData.groovy index edc128cf1..7258934fa 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/ExportOracleEvaluationData.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/ExportOracleEvaluationData.groovy @@ -3,8 +3,10 @@ package com.fangjia.script.ccbevaluation import com.fangjia.script.commData.CommonDatautils import com.fangjia.script.gj.ccb.FileUtils import com.fangjia.script.util.DateUtils +import com.jcraft.jsch.ChannelSftp import groovy.sql.Sql import com.fangjia.script.ccbevaluation.ronghe.SSHHelper +import org.apache.commons.codec.digest.DigestUtils class ExportOracleEvaluationData { def sqlInstance = Sql.newInstance("jdbc:oracle:thin:@192.168.0.236:1521:orcl", @@ -33,6 +35,8 @@ class ExportOracleEvaluationData { exportCommCaseDetailGj(curMonth) def curDate = curMonth.toString()+"28" +// 生成MD5文件 + exportMd5() SSHHelper jschCommand = new SSHHelper(); System.out.println(jschCommand.executeCommand("sh /home/ccb/output/gz_package.sh ${curDate}")); // ok文件 @@ -413,4 +417,23 @@ class ExportOracleEvaluationData { CcbFtpUtils.ftpUpload(null, dataCodeFileName, curDate) } + def exportMd5(){ + def curDate = DateUtils.formatDateByPattern(new Date(), "yyyyMM")+"28" + Vector files = CcbFtpUtils.listFileNames(curDate) + Iterator fileVec = files.iterator() + def fileRows = [] + while(fileVec.hasNext()){ + ChannelSftp.LsEntry file = fileVec.next() + if(org.apache.commons.lang.StringUtils.isNotBlank(file.getFilename()) && file.getFilename().endsWith(".dat")){ + fileRows << file.getFilename() +":"+ DigestUtils.md5Hex(file.getFilename()) + } + } + def fileName = "/ccb/md5.txt" + if(CommonDatautils.isWindow()){ + fileName = "D:\\房价网\\md5.txt" + } + FileUtils.createTxtFile(fileRows, fileName, "utf-8", false); + CcbFtpUtils.ftpUpload(null, fileName, curDate) + println "md5.txt 上传Ftp完成......" + } } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/ccb/FileUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/ccb/FileUtils.groovy index 3e4981856..23513b80b 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/ccb/FileUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/ccb/FileUtils.groovy @@ -50,4 +50,32 @@ class FileUtils { } out.close(); } + + static def createTxtFile(ret, fileName, charset, isAppend){ + File file = new File(fileName); + if (!file.getParentFile().exists()) { + boolean result = file.getParentFile().mkdirs(); + if (!result) { + System.out.println("创建目录失败"); + } + } + + OutputStream out = new FileOutputStream(fileName, isAppend); + def sb = new StringBuffer(); + out.write(sb.toString().getBytes(charset)); + sb.setLength(0) + def index = 0 + for(def row : ret){ + if(row){ + index++ + sb.append(row) + sb.append("\n"); + } + } + if(sb.length()>0){ + out.write(sb.toString().getBytes(charset)); + sb.setLength(0) + } + out.close(); + } }