commit cb8d256781e805c0b81f5651a991b1665ae12fa2 Author: lidy@connor.net.cn Date: Fri Nov 29 16:20:58 2024 +0800 20241129浠g爜涓婁紶 diff --git a/sendmail/.classpath b/sendmail/.classpath new file mode 100644 index 0000000..e3fc1c7 --- /dev/null +++ b/sendmail/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/sendmail/.project b/sendmail/.project new file mode 100644 index 0000000..775ee4a --- /dev/null +++ b/sendmail/.project @@ -0,0 +1,17 @@ + + + sendmail + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/sendmail/.settings/org.eclipse.jdt.core.prefs b/sendmail/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/sendmail/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/sendmail/bin/com/connor/mail/DatabaseInfomation.properties b/sendmail/bin/com/connor/mail/DatabaseInfomation.properties new file mode 100644 index 0000000..4145284 --- /dev/null +++ b/sendmail/bin/com/connor/mail/DatabaseInfomation.properties @@ -0,0 +1,10 @@ + +JdbcDriverClass=oracle.jdbc.driver.OracleDriver + +ConnectionString=jdbc:oracle:thin:@10.200.2.43:1521:jktc + +DbUser=infodba + +DbPass=infodba + +Mail=tanggg@china-goldcard.com,futt@china-goldcard.com diff --git a/sendmail/bin/com/connor/mail/Demo1.class b/sendmail/bin/com/connor/mail/Demo1.class new file mode 100644 index 0000000..d3be1d7 Binary files /dev/null and b/sendmail/bin/com/connor/mail/Demo1.class differ diff --git a/sendmail/bin/com/connor/mail/FileUtils.class b/sendmail/bin/com/connor/mail/FileUtils.class new file mode 100644 index 0000000..803c3e2 Binary files /dev/null and b/sendmail/bin/com/connor/mail/FileUtils.class differ diff --git a/sendmail/bin/com/connor/mail/FindCshSql.class b/sendmail/bin/com/connor/mail/FindCshSql.class new file mode 100644 index 0000000..1261f1b Binary files /dev/null and b/sendmail/bin/com/connor/mail/FindCshSql.class differ diff --git a/sendmail/bin/com/connor/mail/HSEmail.class b/sendmail/bin/com/connor/mail/HSEmail.class new file mode 100644 index 0000000..026bc46 Binary files /dev/null and b/sendmail/bin/com/connor/mail/HSEmail.class differ diff --git a/sendmail/bin/com/connor/mail/LogUtils.class b/sendmail/bin/com/connor/mail/LogUtils.class new file mode 100644 index 0000000..9910277 Binary files /dev/null and b/sendmail/bin/com/connor/mail/LogUtils.class differ diff --git a/sendmail/bin/com/connor/mail/SendMail.class b/sendmail/bin/com/connor/mail/SendMail.class new file mode 100644 index 0000000..88246da Binary files /dev/null and b/sendmail/bin/com/connor/mail/SendMail.class differ diff --git a/sendmail/bin/com/connor/mail/SqlUtil.class b/sendmail/bin/com/connor/mail/SqlUtil.class new file mode 100644 index 0000000..ae555eb Binary files /dev/null and b/sendmail/bin/com/connor/mail/SqlUtil.class differ diff --git a/sendmail/bin/com/connor/mail/mail.class b/sendmail/bin/com/connor/mail/mail.class new file mode 100644 index 0000000..081529b Binary files /dev/null and b/sendmail/bin/com/connor/mail/mail.class differ diff --git a/sendmail/bin/com/connor/mail/mail.properties b/sendmail/bin/com/connor/mail/mail.properties new file mode 100644 index 0000000..3a0292e --- /dev/null +++ b/sendmail/bin/com/connor/mail/mail.properties @@ -0,0 +1 @@ +\u53D1\u5E03\u63D0\u9192=\u60A8\u597D!\n PLM\u7CFB\u7EDF\u4E2D\uFF1A\n s%\u5DF2\u7ECF\u53D1\u5E03\uFF0C\u8BF7\u53CA\u65F6\u5728TC\u4E2D\u521B\u5EFA\u5BF9\u5E94\u7684MBOM\u3002\u8C22\u8C22\uFF01 diff --git a/sendmail/bin/config.properties b/sendmail/bin/config.properties new file mode 100644 index 0000000..4a4ead0 --- /dev/null +++ b/sendmail/bin/config.properties @@ -0,0 +1,4 @@ +MAIL_SERVER=mail.shdlgroup.com +MAIL_PORT=25 +MAIL_SENDER=plmadmin@ks.shdlgroup.com +MAIL_SENDER_PWD=shdl@PA diff --git a/sendmail/lib/mysql-connector-java-8.0.12.jar b/sendmail/lib/mysql-connector-java-8.0.12.jar new file mode 100644 index 0000000..87404ca Binary files /dev/null and b/sendmail/lib/mysql-connector-java-8.0.12.jar differ diff --git a/sendmail/mailapi.jar b/sendmail/mailapi.jar new file mode 100644 index 0000000..ab6365c Binary files /dev/null and b/sendmail/mailapi.jar differ diff --git a/sendmail/ojdbc6.jar b/sendmail/ojdbc6.jar new file mode 100644 index 0000000..ec3d6f1 Binary files /dev/null and b/sendmail/ojdbc6.jar differ diff --git a/sendmail/smtp.jar b/sendmail/smtp.jar new file mode 100644 index 0000000..2f4cec8 Binary files /dev/null and b/sendmail/smtp.jar differ diff --git a/sendmail/src/com/connor/mail/DatabaseInfomation.properties b/sendmail/src/com/connor/mail/DatabaseInfomation.properties new file mode 100644 index 0000000..4145284 --- /dev/null +++ b/sendmail/src/com/connor/mail/DatabaseInfomation.properties @@ -0,0 +1,10 @@ + +JdbcDriverClass=oracle.jdbc.driver.OracleDriver + +ConnectionString=jdbc:oracle:thin:@10.200.2.43:1521:jktc + +DbUser=infodba + +DbPass=infodba + +Mail=tanggg@china-goldcard.com,futt@china-goldcard.com diff --git a/sendmail/src/com/connor/mail/Demo1.java b/sendmail/src/com/connor/mail/Demo1.java new file mode 100644 index 0000000..631fdca --- /dev/null +++ b/sendmail/src/com/connor/mail/Demo1.java @@ -0,0 +1,88 @@ +package com.connor.mail; + +import java.util.Properties; + +import javax.mail.Address; +import javax.mail.Message; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; + + +public class Demo1 { + + /** + * @param args + * add by zxx ,Feb 5, 2009 + */ + public static void main(String[] args) throws Exception { + // TODO Auto-generated method stub +//// + args=new String[]{"ffff@@11hhhh","wangc@connor.net.cn","[任务名称:验证阶段;所在项目:@@11]##11hhhhh##11kkk"}; + System.out.println("邮件发送开始"); + if(args!=null&&args.length>=3){ + String s1=args[0]; + String s2=args[1]; + String s3=args[2]; + s1=s1.replaceAll("@@11", " "); + s3=s3.replaceAll("@@11", " "); + s1=s1.replaceAll("##11", "\n"); + s3=s3.replaceAll("##11", "\n"); + Demo1 de=new Demo1(); +// de.sendmail(s2,s1,s3); + de.sendmail(s1,s2,s3); + System.out.println("邮件发送成功"); + + }else{ + return; + } + + + } + + public void sendmail(String zt,String sjr,String nr) { + // TODO Auto-generated method stub + try { + Address[] sendAddress = null; + String[] sendToMails = sjr.split(","); + for(String s :sendToMails){ + System.out.println("s==============="+s); + } + String emailTitle = zt; + String emailtext=nr; + System.out.println("zt==============="+zt); + System.out.println("nr==============="+nr); + Properties props = new Properties(); + props.setProperty("mail.smtp.auth", "true"); + props.setProperty("mail.transport.protocol", "smtp"); + //props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + Session session = Session.getInstance(props); + session.setDebug(true); + Message msg = new MimeMessage(session); + //msg.set + msg.setSubject(emailTitle); + + msg.setText(emailtext); + + // msg.setText("您好:\n 您收到的是PLM项目组的测试邮件,如有打扰敬请谅解!\n\n谢谢\n\n祝您工作愉快!"); + msg.setFrom(new InternetAddress("plmadmin@ks.shdlgroup.com")); + Transport transport = session.getTransport(); +// transport.connect("smtp.exmail.qq.com", +// 25,"kunyu.liang@wfjt.com", "15958502268Lky"); + transport.connect("mail.shdlgroup.com", + 25,"plmadmin@ks.shdlgroup.com", "shdl@PA"); + + + sendAddress = new Address[sendToMails.length]; + for (int i = 0; i < sendToMails.length; i++) { + sendAddress[i] = new InternetAddress(sendToMails[i]); + } + transport.sendMessage(msg, sendAddress); + transport.close(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/sendmail/src/com/connor/mail/FileUtils.java b/sendmail/src/com/connor/mail/FileUtils.java new file mode 100644 index 0000000..79e7410 --- /dev/null +++ b/sendmail/src/com/connor/mail/FileUtils.java @@ -0,0 +1,225 @@ +package com.connor.mail; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +//创建新文件和目录 +public class FileUtils { + // 验证字符串是否为正确路径名的正则表达式 + private static String matches = "[A-Za-z]:\\\\[^:?\"><*]*"; + // 通过 sPath.matches(matches) 方法的返回值判断是否正确 + // sPath 为路径字符串 + boolean flag = false; + File file; + + public boolean DeleteFolder(String deletePath) {// 根据路径删除指定的目录或文件,无论存在与否 + flag = false; + if (deletePath.matches(matches)) { + file = new File(deletePath); + if (!file.exists()) {// 判断目录或文件是否存在 + return flag; // 不存在返回 false + } else { + + if (file.isFile()) {// 判断是否为文件 + return deleteFile(deletePath);// 为文件时调用删除文件方法 + } else { + return deleteDirectory(deletePath);// 为目录时调用删除目录方法 + } + } + } else { + System.out.println("要传入正确路径!"); + return false; + } + } + + public boolean deleteFile(String filePath) {// 删除单个文件 + flag = false; + file = new File(filePath); + if (file.isFile() && file.exists()) {// 路径为文件且不为空则进行删除 + file.delete();// 文件删除 + flag = true; + } + return flag; + } + + public boolean deleteDirectory(String dirPath) {// 删除目录(文件夹)以及目录下的文件 + // 如果sPath不以文件分隔符结尾,自动添加文件分隔符 + if (!dirPath.endsWith(File.separator)) { + dirPath = dirPath + File.separator; + } + File dirFile = new File(dirPath); + // 如果dir对应的文件不存在,或者不是一个目录,则退出 + if (!dirFile.exists() || !dirFile.isDirectory()) { + return false; + } + flag = true; + File[] files = dirFile.listFiles();// 获得传入路径下的所有文件 + for (int i = 0; i < files.length; i++) {// 循环遍历删除文件夹下的所有文件(包括子目录) + if (files[i].isFile()) {// 删除子文件 + flag = deleteFile(files[i].getAbsolutePath()); + System.out.println(files[i].getAbsolutePath() + " 删除成功"); + if (!flag) + break;// 如果删除失败,则跳出 + } else {// 运用递归,删除子目录 + flag = deleteDirectory(files[i].getAbsolutePath()); + if (!flag) + break;// 如果删除失败,则跳出 + } + } + if (!flag) + return false; + if (dirFile.delete()) {// 删除当前目录 + return true; + } else { + return false; + } + } + + // 创建单个文件 + public static boolean createFile(String filePath) { + File file = new File(filePath); + if (file.exists()) {// 判断文件是否存在 + System.out.println("目标文件已存在" + filePath); + return true; + } + if (filePath.endsWith(File.separator)) {// 判断文件是否为目录 + System.out.println("目标文件不能为目录!"); + return false; + } + if (!file.getParentFile().exists()) {// 判断目标文件所在的目录是否存在 + // 如果目标文件所在的文件夹不存在,则创建父文件夹 + System.out.println("目标文件所在目录不存在,准备创建它!"); + if (!file.getParentFile().mkdirs()) {// 判断创建目录是否成功 + System.out.println("创建目标文件所在的目录失败!"); + return false; + } + } + try { + if (file.createNewFile()) {// 创建目标文件 + System.out.println("创建文件成功:" + filePath); + return true; + } else { + System.out.println("创建文件失败!"); + return false; + } + } catch (IOException e) {// 捕获异常 + e.printStackTrace(); + System.out.println("创建文件失败!" + e.getMessage()); + return false; + } + } + + // 创建目录 + public static boolean createDir(String destDirName) { + File dir = new File(destDirName); + if (dir.exists()) {// 判断目录是否存在 + System.out.println("创建目录失败,目标目录已存在!"); + return true; + } + if (!destDirName.endsWith(File.separator)) {// 结尾是否以"/"结束 + destDirName = destDirName + File.separator; + } + if (dir.mkdirs()) {// 创建目标目录 + System.out.println("创建目录成功!" + destDirName); + return true; + } else { + System.out.println("创建目录失败!"); + return false; + } + } + + // 创建临时文件 + public static String createTempFile(String prefix, String suffix, + String dirName) { + File tempFile = null; + if (dirName == null) {// 目录如果为空 + try { + tempFile = File.createTempFile(prefix, suffix);// 在默认文件夹下创建临时文件 + return tempFile.getCanonicalPath();// 返回临时文件的路径 + } catch (IOException e) {// 捕获异常 + e.printStackTrace(); + System.out.println("创建临时文件失败:" + e.getMessage()); + return null; + } + } else { + // 指定目录存在 + File dir = new File(dirName);// 创建目录 + if (!dir.exists()) { + // 如果目录不存在则创建目录 + if (FileUtils.createDir(dirName)) { + System.out.println("创建临时文件失败,不能创建临时文件所在的目录!"); + return null; + } + } + try { + tempFile = File.createTempFile(prefix, suffix, dir);// 在指定目录下创建临时文件 + return tempFile.getCanonicalPath();// 返回临时文件的路径 + } catch (IOException e) {// 捕获异常 + e.printStackTrace(); + System.out.println("创建临时文件失败!" + e.getMessage()); + return null; + } + } + } + + //读取txt第一行 + public static String readFile(String fileName) + { + String fileContent = ""; + InputStreamReader read = null; + BufferedReader reader = null; + try + { + File f = new File(fileName); + if(f.isFile()&&f.exists()) + { + read = new InputStreamReader(new FileInputStream(f),"GBK"); + reader=new BufferedReader(read); + String line; + while ((line = reader.readLine()) != null) + { + fileContent += line; + } + reader.close(); + read.close(); + } + } catch (Exception e) + { + e.printStackTrace(); + } finally{ + if(reader!=null){ + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if(read!=null){ + try { + read.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + return fileContent; + } + + public static void main(String[] args) { + String dirName = "E:/createFile/";// 创建目录 + FileUtils.createDir(dirName);// 调用方法创建目录 + String fileName = dirName + "/file1.txt";// 创建文件 + FileUtils.createFile(fileName);// 调用方法创建文件 + String prefix = "temp";// 创建临时文件 + String surfix = ".txt";// 后缀 + for (int i = 0; i < 10; i++) {// 循环创建多个文件 + System.out.println("创建临时文件: "// 调用方法创建临时文件 + + FileUtils.createTempFile(prefix, surfix, + dirName)); + } + } +} diff --git a/sendmail/src/com/connor/mail/FindCshSql.java b/sendmail/src/com/connor/mail/FindCshSql.java new file mode 100644 index 0000000..42e2592 --- /dev/null +++ b/sendmail/src/com/connor/mail/FindCshSql.java @@ -0,0 +1,253 @@ +package com.connor.mail; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.text.DecimalFormat; +import java.util.HashMap; +import java.util.Map; + +public class FindCshSql { + + public static void main(String[] args) { + SqlUtil.getMySqlConnection(); + String nameString = args[0]; +// String nameString = "00085"; + String formula = args[1]; + String value = ""; +// String formula = "(%HW#^2+(2*%MO#+2*%MO#)^2)^0.5"; + try { + // String codeString = args[1]; + if(formula.contains("%") && formula.contains("#")) { + while (formula.contains("%") && formula.contains("#")) { + int indexOf = formula.indexOf('%'); + int indexOf2 = formula.indexOf('#'); + String format = formula.substring(indexOf + 1, indexOf2); + String oldChar = formula.substring(indexOf, indexOf2 + 1); +// System.out.println("format====" + format); + String sql = "select param_value from design_params_history where project_name like '%"+nameString+"%' and param_code = ? order by commit_num desc "; + ResultSet read = SqlUtil.read(sql,new String[] {format}); + if(read.next()) { + String paramVal = read.getString(1); + //这里加上去数据库取值的逻辑 用format去数据库去相应的值 + formula = formula.replace(oldChar, paramVal); + }else { + return; + } + } + if(formula.contains("(")) { + Map formulaMap = new HashMap(); + //遍历分别计算括号里面的公式获得新的公式 + substring(formula, formula, formulaMap); + formula = formulaMap.get("formula"); +// System.out.println("formula====" + formula); + value = getVal(formula); + }else { + value = getVal(formula); + } + }else { + String sql = "select param_value from design_params_history where project_name like '%"+nameString+"%' and param_code = ? order by commit_num desc "; + ResultSet read = SqlUtil.read(sql,new String[] {formula}); + if(read.next()) { + value = read.getString(1); + } + } + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + return; + }finally { + SqlUtil.freeAll(); + } + + double number = Double.parseDouble(value); + DecimalFormat df = null; + if(number > 1) { + df = new DecimalFormat("#.00"); + }else { + df = new DecimalFormat("0.00"); + } + System.out.println(df.format(number)); + + } + + private static int findMatchingParenthesis(String expression, int start) { + int count = 0; + for (int i = start + 1; i < expression.length(); i++) { + if (expression.charAt(i) == '(') { + count++; + } else if (expression.charAt(i) == ')') { + if (count == 0) { + return i; + }else { + count--; + } + } + } + throw new IllegalArgumentException("Mismatched parentheses"); + } + + + private static int getLastNumberLength(String expression, int start) { + int length = start + 1; + while (length < expression.length() + && expression.charAt(length) != '*' + && expression.charAt(length) != '+' + && expression.charAt(length) != '-' + && expression.charAt(length) != '/' + && expression.charAt(length) != '^') { + length++; + } + return length - 1; + } + private static int getBeforeNumberLength(String expression, int start) { + int length = start - 1; + while (length >= 0 + && expression.charAt(length) != '*' + && expression.charAt(length) != '+' + && expression.charAt(length) != '-' + && expression.charAt(length) != '/' + && expression.charAt(length) != '^') { + length--; + } + return length + 1; + } + + public static int countCharacter(String str, char characterToCount) { + int count = 0; + int index = str.indexOf(characterToCount); + while (index >= 0) { + count++; + index = str.indexOf(characterToCount, index + 1); + } + return count; + } + public static void substring(String formula, String expression,Map formulaMap) { + //有括号 + if(formula.contains("(")) { + int indexStart = formula.indexOf("("); + int indexEnd = findMatchingParenthesis(formula, indexStart); + //截取括号内的公式 + String formula2 = formula.substring(indexStart + 1, indexEnd); + if(formula2.contains("(")) { + //获取括号内容如果还有括号继续获取括号里面的公式 + substring(formula2, expression,formulaMap); + }else { + //没有括号计算获得值替换原有公式 + String value = getVal(formula2); + String formula3 = formula.replace("(" + formula2 + ")", value); + expression = expression.replace("(" + formula2 + ")", value); + + // expression = expression.replace("(" + formula + ")", formula3); + //判断替换过后的公式是否还有括号 + if(expression.contains("(")) { + int indexStart2 = expression.indexOf("("); + int indexEnd2 = findMatchingParenthesis(expression, indexStart2); + String formula4 = expression.substring(indexStart2 + 1, indexEnd2); + substring(formula4, expression,formulaMap); + } + } + }else { + //没有括号直接计算获得值替换原有公式 + String value = getVal(formula); + expression = expression.replace("(" + formula + ")", value); + //判断替换过后的公式是否还有括号 + if(expression.contains("(")) { + int indexStart2 = expression.indexOf("("); + int indexEnd2 = findMatchingParenthesis(expression, indexStart2); + String formula4 = expression.substring(indexStart2 + 1, indexEnd2); + substring(formula4, expression,formulaMap); + }else { + if(expression.contains("^") + || expression.contains("*") + || expression.contains("/") + || expression.contains("+") + || expression.contains("-")) { + expression = getVal(expression); + formulaMap.put("formula", expression); + }else { + formulaMap.put("formula", expression); + } + } + + } + } + public static String getVal(String formula2) { + int indexOfStart = 0; + int nextIndex = 0; + int beforeIndex = 0; + while (formula2.contains("^")) { + indexOfStart = formula2.indexOf("^"); + nextIndex = getLastNumberLength(formula2, indexOfStart); + beforeIndex = getBeforeNumberLength(formula2, indexOfStart); + formula2 = jisuan(formula2, indexOfStart, beforeIndex, nextIndex, "^"); + } + while (formula2.contains("*") || formula2.contains("/")) { + int indexOfStart2 = formula2.indexOf("*"); + int indexOfStart3 = formula2.indexOf("/"); + if(indexOfStart2 < 0) { + nextIndex = getLastNumberLength(formula2, indexOfStart3); + beforeIndex = getBeforeNumberLength(formula2, indexOfStart3); + formula2 = jisuan(formula2,indexOfStart3,beforeIndex, nextIndex,"/"); + }else if(indexOfStart3 < 0) { + nextIndex = getLastNumberLength(formula2, indexOfStart2); + beforeIndex = getBeforeNumberLength(formula2, indexOfStart2); + formula2 = jisuan(formula2,indexOfStart2,beforeIndex, nextIndex,"*"); + }else if(indexOfStart2 > indexOfStart3) { + nextIndex = getLastNumberLength(formula2, indexOfStart3); + beforeIndex = getBeforeNumberLength(formula2, indexOfStart3); + formula2 = jisuan(formula2,indexOfStart3,beforeIndex, nextIndex,"/"); + }else { + nextIndex = getLastNumberLength(formula2, indexOfStart2); + beforeIndex = getBeforeNumberLength(formula2, indexOfStart2); + formula2 = jisuan(formula2,indexOfStart2,beforeIndex, nextIndex,"*"); + } + + } + while (formula2.contains("+")) { + indexOfStart = formula2.indexOf("+"); + nextIndex = getLastNumberLength(formula2, indexOfStart); + beforeIndex = getBeforeNumberLength(formula2, indexOfStart); + formula2 = jisuan(formula2, indexOfStart, beforeIndex, nextIndex, "+"); + } + while (formula2.contains("-")) { + indexOfStart = formula2.indexOf("-"); + nextIndex = getLastNumberLength(formula2, indexOfStart); + beforeIndex = getBeforeNumberLength(formula2, indexOfStart); + formula2 = jisuan(formula2, indexOfStart, beforeIndex, nextIndex, "-"); + } + return formula2; + } + public static String jisuan(String formula, int index, int beforeIndex, int nextIndex, String operator) { + String subValue = formula.substring(beforeIndex, nextIndex + 1); +// System.out.println("subValue====" + subValue); + double firstValue = Double.parseDouble(formula.substring(beforeIndex, index)); + double secondValue = Double.parseDouble(formula.substring(index + 1, nextIndex + 1)); + double value = 0; + switch (operator) { + case "+": + value = firstValue + secondValue; + break; + case "-": + value = firstValue - secondValue; + break; + case "*": + value = firstValue * secondValue; + break; + case "/": + value = firstValue / secondValue; + break; + // Handle exponentiation + case "^": + value = Math.pow(firstValue, secondValue); + break; + default: + throw new IllegalArgumentException("Unknown operator: " + operator); + } + String result = formula.replace(subValue, value + ""); + return result; + } + +} diff --git a/sendmail/src/com/connor/mail/HSEmail.java b/sendmail/src/com/connor/mail/HSEmail.java new file mode 100644 index 0000000..024ca03 --- /dev/null +++ b/sendmail/src/com/connor/mail/HSEmail.java @@ -0,0 +1,108 @@ +package com.connor.mail; + +import java.util.Properties; + +import javax.mail.Address; +import javax.mail.Message; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; + + + + +public class HSEmail { + + /** + * @param args + * add by zxx ,Feb 5, 2009 + */ +// private static LogUtils log = new LogUtils(HSEmail.class); + public static void main(String[] args) throws Exception { + // TODO Auto-generated method stub + +// log.createLogFile("sendToMysql.txt"); + args=new String[]{"测试邮件","wangc@connor.net.cn","[任务名称:验证阶段;所在项目:@@11]##11hhhhh##11kkk"}; + System.out.println("邮件发送开始"); +// log.info( "arg"); +// +// for(String artString : args) { +// log.info(artString); +// } + + if(args!=null&&args.length>=3){ + + String s1=args[0]; + String s2=args[1]; + String s3=args[2]; + +// s1=s1.replaceAll("@@11", " "); +// s3=s3.replaceAll("@@11", " "); +// s1=s1.replaceAll("##11", "\n"); +// s3=s3.replaceAll("##11", "\n"); + HSEmail de=new HSEmail(); + de.sendmail(s1,s2,s3); + System.out.println("邮件发送成功"); + + }else{ + return; + } +// log.closeLogFile(); + + } + + public void sendmail(String zt,String sjr,String nr) { + // TODO Auto-generated method stub + try { + Address[] sendAddress = null; + String[] sendToMails = sjr.split(","); + for(String s :sendToMails){ + System.out.println("s==============="+s); + } + String emailTitle = zt; + emailTitle = emailTitle.replaceAll("###", " "); + emailTitle = emailTitle.replaceAll("--", "&"); + String emailtext=nr; + emailtext = emailtext.replaceAll("###", " "); + emailtext = emailtext.replaceAll("--", "&"); + System.out.println("zt==============="+zt); + System.out.println("nr==============="+nr); + Properties props = new Properties(); + props.setProperty("mail.smtp.auth", "true"); + props.setProperty("mail.transport.protocol", "smtp"); + props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + Session session = Session.getInstance(props); + session.setDebug(true); + Message msg = new MimeMessage(session); + //msg.set + msg.setSubject(emailTitle); + + msg.setText(emailtext); + + // msg.setText("您好:\n 您收到的是PLM项目组的测试邮件,如有打扰敬请谅解!\n\n谢谢\n\n祝您工作愉快!"); + Properties props1 = new Properties(); + props1.load(HSEmail.class.getResourceAsStream("/config.properties")); + String server = props1.getProperty("MAIL_SERVER"); + String port = props1.getProperty("MAIL_PORT"); + String from = props1.getProperty("MAIL_SENDER"); + String password = props1.getProperty("MAIL_SENDER_PWD"); + msg.setFrom(new InternetAddress(from)); + Transport transport = session.getTransport(); + transport.connect(server,Integer.parseInt(port),from, password); +// transport.connect("smtp.connor.net.cn", +// 25,"wangc@connor.net.cn", ""); + + + sendAddress = new Address[sendToMails.length]; + for (int i = 0; i < sendToMails.length; i++) { + sendAddress[i] = new InternetAddress(sendToMails[i]); + } + transport.sendMessage(msg, sendAddress); + transport.close(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/sendmail/src/com/connor/mail/LogUtils.java b/sendmail/src/com/connor/mail/LogUtils.java new file mode 100644 index 0000000..095754e --- /dev/null +++ b/sendmail/src/com/connor/mail/LogUtils.java @@ -0,0 +1,122 @@ +package com.connor.mail; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class LogUtils { + + private static String path = "D:\\Siemens\\Teamcenter12\\bin\\"; + private static SimpleDateFormat DateFormat_filename=new SimpleDateFormat("yyyyMMdd"); + private static SimpleDateFormat DateFormat_context=new SimpleDateFormat("yyyyMMdd HH:mm:ss"); + private BufferedWriter bw; + private String clazzStr; + + public LogUtils(Class clazz) { + // TODO Auto-generated constructor stub + clazzStr = clazz.toString(); + } + + public void createLogFile(String filename){ + try { + String logPath = path + DateFormat_filename.format(new Date()) + filename; + System.out.println("logPath = "+logPath); + if(FileUtils.createFile(logPath)){ + FileWriter fw = new FileWriter(logPath,true); + bw = new BufferedWriter(fw); + start(); + } + } catch (IOException e) { + e.printStackTrace(); + } + + } + + public void info(String context){ + StringBuilder sb = new StringBuilder(); + sb.append("["); + sb.append(DateFormat_context.format(new Date())); + sb.append(" info"); + sb.append("] "); + sb.append(context); + try { + bw.newLine(); + bw.write(sb.toString()); + bw.flush(); + System.out.println(sb.toString()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void error(String context){ + StringBuilder sb = new StringBuilder(); + sb.append("["); + sb.append(DateFormat_context.format(new Date())); + sb.append(" error"); + sb.append("] "); + sb.append(context); + try { + bw.newLine(); + bw.write(sb.toString()); + bw.flush(); + System.out.println(sb.toString()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + public void start(){ + StringBuilder sb = new StringBuilder(); + sb.append("["); + sb.append(DateFormat_context.format(new Date())); + sb.append("] "); + sb.append(clazzStr); + sb.append(".start"); + try { + bw.newLine(); + bw.newLine(); + bw.newLine(); + bw.newLine(); + bw.write(sb.toString()); + bw.flush(); + System.out.println(sb.toString()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void end(){ + StringBuilder sb = new StringBuilder(); + sb.append("["); + sb.append(DateFormat_context.format(new Date())); + sb.append("] "); + sb.append(clazzStr); + sb.append(".end"); + try { + bw.newLine(); + bw.write(sb.toString()); + bw.flush(); + System.out.println(sb.toString()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void closeLogFile(){ + if(bw!=null){ + try { + end(); + bw.flush(); + bw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + +} diff --git a/sendmail/src/com/connor/mail/SendMail.java b/sendmail/src/com/connor/mail/SendMail.java new file mode 100644 index 0000000..cbc0838 --- /dev/null +++ b/sendmail/src/com/connor/mail/SendMail.java @@ -0,0 +1,153 @@ +package com.connor.mail; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashMap; +import java.util.Properties; +import java.util.Vector; + +public class SendMail { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + SendMail s=new SendMail(); + s.getstr(); + + } + + private void getstr() { + // TODO Auto-generated method stub + System.out.println("start"); + Properties properties = new Properties(); + InputStream is = null; + is = this.getClass().getClassLoader().getResourceAsStream( + "com/connor/mail/DatabaseInfomation.properties"); + try { + properties.load(is); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String JdbcDriverClass = properties.getProperty("JdbcDriverClass");//"oracle.jdbc.driver.OracleDriver"; + System.out.println(JdbcDriverClass); + String strUrl =properties.getProperty("ConnectionString"); //"jdbc:oracle:thin:@10.201.5.203:1521:tc11"; + System.out.println(strUrl); + String strUserName =properties.getProperty("DbUser") ;//"infodba"; + System.out.println(strUserName); + String strPassword = properties.getProperty("DbPass");//"infodba"; + System.out.println(strPassword); + String mail = properties.getProperty("Mail");//"zhangl@connor.net.cn,hezq@connor.net.cn"; + System.out.println(mail); + String s=""; + try { + Class.forName(JdbcDriverClass); + Connection conn = DriverManager.getConnection(strUrl, strUserName, + strPassword);// 连接数据库 + String query1 = "select JK_BOM_ID,JK_BOM_REV from JK_BOM_PARENT_LINE_TABLE where JK_STATUS='2'"; + String query2 = "select JK_ITEM_ID,JK_ITEM_NAME from JK_MATERIAL_TABLE where JK_STATUS='2'"; + Statement stmt = conn.createStatement(); + ResultSet rs_get1 = stmt.executeQuery(query1); + + String rsStr1=""; + String rsStr2=""; + if (rs_get1 != null) { + ResultSetMetaData metaData = rs_get1.getMetaData(); + + int i_ColumnCount = metaData.getColumnCount(); + // System.out.println("i_ColumnCount:"+i_ColumnCount); + while (rs_get1.next()) { + // System.out.println("【BJZJ2】"+rs_get.getString("BJZJ2"));; + //HashMap hm_unit = new HashMap(); + String str=""; + for (int i = 1; i <= i_ColumnCount; i++) { + if(i==1){ + str=rs_get1.getString(i); + }else{ + str=str+"/"+rs_get1.getString(i); + } +// hm_unit.put(metaData.getColumnName(i), +// rs_get1.getString(i)); + // System.out.println("metaData.getColumnName(i):"+metaData.getColumnName(i)); + // System.out.println("rs_get.getString(i):"+rs_get.getString(i)); + } + System.out.println("str="+str); + if(!str.equals("")){ + rsStr1=rsStr1+","+str; + } + } + } + if(!rsStr1.equals("")){ + rsStr1=rsStr1.substring(1, rsStr1.length()); + s=s+"以下为传递失败的BOM:\r"+rsStr1; + } + ResultSet rs_get2 = stmt.executeQuery(query2); + if (rs_get2 != null) { + ResultSetMetaData metaData = rs_get2.getMetaData(); + + int i_ColumnCount = metaData.getColumnCount(); + // System.out.println("i_ColumnCount:"+i_ColumnCount); + while (rs_get2.next()) { + // System.out.println("【BJZJ2】"+rs_get.getString("BJZJ2"));; + //HashMap hm_unit = new HashMap(); + String str=""; + for (int i = 1; i <= i_ColumnCount; i++) { + if(i==1){ + str=rs_get2.getString(i); + }else{ + str=str+"-"+rs_get2.getString(i); + } +// hm_unit.put(metaData.getColumnName(i), +// rs_get1.getString(i)); + // System.out.println("metaData.getColumnName(i):"+metaData.getColumnName(i)); + // System.out.println("rs_get.getString(i):"+rs_get.getString(i)); + } + System.out.println("str="+str); + if(!str.equals("")){ + rsStr2=rsStr2+","+str; + } + } + } + if(!rsStr2.equals("")){ + rsStr2=rsStr2.substring(1, rsStr2.length()); + s=s+"\r\r以下为传递失败的ITEM:\r"+rsStr2; + } + //System.out.println("s="+s); + if(!s.equals("")){ + Demo1 d=new Demo1(); + d.sendmail("U8传递失败提示", mail, s); + System.out.println("mail="+mail); + System.out.println("s="+s); + } + if (rs_get1 != null) { + rs_get1.close(); + } + if (rs_get2 != null) { + rs_get2.close(); + } + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } + +} diff --git a/sendmail/src/com/connor/mail/SqlUtil.java b/sendmail/src/com/connor/mail/SqlUtil.java new file mode 100644 index 0000000..b57b9a4 --- /dev/null +++ b/sendmail/src/com/connor/mail/SqlUtil.java @@ -0,0 +1,123 @@ +package com.connor.mail; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +public class SqlUtil { + + public static Connection connection = null; + public static PreparedStatement ps = null; + public static ResultSet rs = null; + + public static Connection getMySqlConnection() { + String driver = "com.mysql.cj.jdbc.Driver";//reg.getString("SQL.DRIVER"); + String url ="jdbc:mysql://10.128.11.45:3399/parametric_design?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false";// reg.getString("SQL.URL"); ?useSSL=false + String user ="root";// reg.getString("SQL.USER"); + String password ="CH6#e7aEL$";// reg.getString("SQL.PASSWORD"); + if (connection != null) { + try { + connection.close(); + } catch (Exception e1) { + e1.printStackTrace(); + } + connection = null; + } + try { + // 加载驱动程序 + Class.forName(driver); + // 1.getConnection()方法,连接MySQL数据库!! + connection = DriverManager.getConnection(url, user, password); + connection.setAutoCommit(false); + } catch (ClassNotFoundException e) { + // 数据库驱动类异常处理 + e.printStackTrace(); + } catch (SQLException e) { + // 数据库连接失败异常处理 + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + return connection; + } + /** + * 释放资源(全部释放) + */ + public final static void freeAll() { + free(SqlUtil.rs, SqlUtil.ps, SqlUtil.connection); + } + /** + * 查询 + */ + public final static ResultSet read(String sql) throws SQLException { + return read(sql, null); + } + + /** + * 查询 + */ + public final static ResultSet read(Object[] argments, String sql) throws SQLException { + return read(sql, argments); + } + + /** + * 查询(所有查询最终都要调用此方法,方法里面不处理异常,抛出后由调用者处理,方便在finally语句中释放资源) + * + * @throws SQLException + */ + public final static ResultSet read(String sql, Object[] argments) throws SQLException { + return SqlUtil.rs = SqlUtil.getPs(argments, sql).executeQuery(); + } + /** 得到Statement + */ + public final static PreparedStatement getPs(Object[] argments, String sql) throws SQLException { + return getPs(sql, argments); + } + + /** + * 得到Statement + */ + public final static PreparedStatement getPs(String sql, Object[] argments) throws SQLException { + SqlUtil.ps = SqlUtil.connection.prepareStatement(sql); + if (argments != null) { + for (int i = 0; i < argments.length; i++) { + SqlUtil.ps.setObject(i + 1, argments[i]); + } + } + return SqlUtil.ps; + } + + /** + * 释放资源(传满参数也要全部释放) + */ + public final static void free(ResultSet resultSet, Statement statement, Connection connection) { + try { + if (resultSet != null) { + try { + resultSet.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } finally { + try { + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } finally { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + } +} diff --git a/sendmail/src/com/connor/mail/mail.java b/sendmail/src/com/connor/mail/mail.java new file mode 100644 index 0000000..4b271f7 --- /dev/null +++ b/sendmail/src/com/connor/mail/mail.java @@ -0,0 +1,106 @@ +package com.connor.mail; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import javax.mail.Address; +import javax.mail.Message; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; + + +public class mail { + + + /** + * @param args + * add by zxx ,Feb 5, 2009 + */ + public static void main(String[] args) throws Exception { + // TODO Auto-generated method stub +// + //args=new String[]{"ffff@@11hhhh","zhangl@connor.net.cn","[任务名称:验证阶段;所在项目:@@11]##11hhhhh##11kkk"}; + System.out.println("邮件发送开始"); + if(args!=null&&args.length>=3){ + String s1=args[0]; + String s2=args[1]; + String s3=args[2]; + mail de=new mail(); + s3=de.getstr(s1,s3); + de.sendmail(s1,s2,s3); + System.out.println("邮件发送成功"); + + }else{ + System.out.println("参数错误,发送失败"); + return; + } +// mail de=new mail(); +// de.sendmail(s1,s2,s3); + System.out.println("邮件发送成功"); + + } + + public String getstr(String s1,String s3) { + // TODO Auto-generated method stub + Properties properties = new Properties(); + InputStream is = null; + is =this.getClass().getClassLoader().getResourceAsStream( + "com/connor/mail/mail.properties"); + try { + properties.load(is); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String str = properties.getProperty(s1);//"oracle.jdbc.driver.OracleDriver"; + str=str.replaceAll("s%", s3); + System.out.println("邮箱内容:"+str); + return str; + + } + + public void sendmail(String zt,String sjr,String nr) { + // TODO Auto-generated method stub + try { + Address[] sendAddress = null; + String[] sendToMails = sjr.split(","); + for(String s :sendToMails){ + System.out.println("s==============="+s); + } + String emailTitle = zt; + String emailtext=nr; + System.out.println("zt==============="+zt); + System.out.println("nr==============="+nr); + Properties props = new Properties(); + props.setProperty("mail.smtp.auth", "true"); +// props.setProperty("mail.transport.protocol", "smtp"); + Session session = Session.getInstance(props); + session.setDebug(true); + Message msg = new MimeMessage(session); + //msg.set + msg.setSubject(emailTitle); + + msg.setText(emailtext); + + // msg.setText("您好:\n 您收到的是PLM项目组的测试邮件,如有打扰敬请谅解!\n\n谢谢\n\n祝您工作愉快!"); + msg.setFrom(new InternetAddress("plm@china-goldcard.com")); + Transport transport = session.getTransport(); + transport.connect("mail.china-goldcard.com", + 25,"plm@china-goldcard.com", "Goldcard1"); + + + sendAddress = new Address[sendToMails.length]; + for (int i = 0; i < sendToMails.length; i++) { + sendAddress[i] = new InternetAddress(sendToMails[i]); + } + transport.sendMessage(msg, sendAddress); + transport.close(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/sendmail/src/com/connor/mail/mail.properties b/sendmail/src/com/connor/mail/mail.properties new file mode 100644 index 0000000..3a0292e --- /dev/null +++ b/sendmail/src/com/connor/mail/mail.properties @@ -0,0 +1 @@ +\u53D1\u5E03\u63D0\u9192=\u60A8\u597D!\n PLM\u7CFB\u7EDF\u4E2D\uFF1A\n s%\u5DF2\u7ECF\u53D1\u5E03\uFF0C\u8BF7\u53CA\u65F6\u5728TC\u4E2D\u521B\u5EFA\u5BF9\u5E94\u7684MBOM\u3002\u8C22\u8C22\uFF01 diff --git a/sendmail/src/config.properties b/sendmail/src/config.properties new file mode 100644 index 0000000..4a4ead0 --- /dev/null +++ b/sendmail/src/config.properties @@ -0,0 +1,4 @@ +MAIL_SERVER=mail.shdlgroup.com +MAIL_PORT=25 +MAIL_SENDER=plmadmin@ks.shdlgroup.com +MAIL_SENDER_PWD=shdl@PA