Optimized code

dev
ehlxr 2020-12-09 17:34:05 +08:00
parent a552a39e4d
commit 2254853ef4
30 changed files with 1424 additions and 1615 deletions

View File

@ -20,7 +20,6 @@ public class PrintMatrixClockWisely {
* 1 (start,columns-1-start+1) => (start,endX-1)
* 1 (start+1,columns-1+1) => (start+1,endY-1)
*
* @author WangSai
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

View File

@ -17,8 +17,6 @@ package me.ehlxr.cache;
* Company:
* </p>
*
* @author Deepblue 2008-11-11
* @version 1.0
*/
public class Cache {
private String key;// 缓存ID

View File

@ -1,6 +1,8 @@
package me.ehlxr.cache;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
/**
@ -16,16 +18,14 @@ import java.util.Map.Entry;
* <p>
* Copyright: Copyright (c) 2008
* </p>
*
*
* <p>
* Company:
* </p>
*
* @author Deepblue 2008-11-11
* @version 1.0
*
*/
public class CacheManager {
private static HashMap<String, Object> cacheMap = new HashMap<String, Object>();
private static final HashMap<String, Object> cacheMap = new HashMap<String, Object>();
// 单实例构造方法
private CacheManager() {
@ -55,7 +55,7 @@ public class CacheManager {
try {
while (i.hasNext()) {
Entry<String, Object> entry = i.next();
key = (String) entry.getKey();
key = entry.getKey();
if (key.startsWith(type)) { // 如果匹配则删除掉
arr.add(key);
}
@ -118,11 +118,9 @@ public class CacheManager {
}
long nowDt = System.currentTimeMillis(); // 系统当前的毫秒数
long cacheDt = cache.getTimeOut(); // 缓存内的过期毫秒数
if (cacheDt <= 0 || cacheDt > nowDt) { // 过期时间小于等于零时,或者过期时间大于当前时间时则为FALSE
return false;
} else { // 大于过期时间 即过期
return true;
}
// 过期时间小于等于零时,或者过期时间大于当前时间时则为FALSE
// 大于过期时间 即过期
return cacheDt > 0 && cacheDt <= nowDt;
}
// 获取缓存中的大小
@ -138,7 +136,7 @@ public class CacheManager {
try {
while (i.hasNext()) {
Entry<String, Object> entry = i.next();
key = (String) entry.getKey();
key = entry.getKey();
if (key.indexOf(type) != -1) { // 如果匹配则删除掉
k++;
}
@ -157,7 +155,7 @@ public class CacheManager {
Iterator<Entry<String, Object>> i = cacheMap.entrySet().iterator();
while (i.hasNext()) {
Entry<String, Object> entry = i.next();
a.add((String) entry.getKey());
a.add(entry.getKey());
}
} catch (Exception ex) {
}
@ -172,7 +170,7 @@ public class CacheManager {
Iterator<Entry<String, Object>> i = cacheMap.entrySet().iterator();
while (i.hasNext()) {
Entry<String, Object> entry = i.next();
key = (String) entry.getKey();
key = entry.getKey();
if (key.indexOf(type) != -1) {
a.add(key);
}

View File

@ -1,202 +1,188 @@
package me.ehlxr.pack;
import java.awt.Component;
import java.awt.Point;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class FileUtil {
private static int sumError = 0;
private static int sumExistError = 0;
private static int sumNotFoundError = 0;
private static int sumSuccess = 0;
private static int sumNum = 1;
private static int sumError = 0;
private static int sumExistError = 0;
private static int sumNotFoundError = 0;
private static int sumSuccess = 0;
private static int sumNum = 1;
private static String getDate(Date date) {
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sd.format(date).toString();
}
private static String getDate(Date date) {
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sd.format(date);
}
private static BufferedReader getBufferedReader(String path) throws FileNotFoundException {
return new BufferedReader(new InputStreamReader(new FileInputStream(path)));
}
private static BufferedReader getBufferedReader(String path) throws FileNotFoundException {
return new BufferedReader(new InputStreamReader(new FileInputStream(path)));
}
public static void setInfo(String info, JFrame root) {
sumError += 1;
info.equals("");
public static void setInfo(String info, JFrame root) {
sumError += 1;
info.equals("");
Component[] components = root.getRootPane().getContentPane().getComponents();
for (int i = 0; i < components.length; i++) {
if (components[i].getClass().toString().equals("class javax.swing.JScrollPane")) {
JTextArea textarea = (JTextArea) ((JScrollPane) components[i]).getViewport().getView();
if (info.equals("")) {
sumError = 0;
sumExistError = 0;
sumNotFoundError = 0;
sumSuccess = 0;
sumNum = 1;
textarea.setText("");
} else if ((textarea.getText().equals("")) || (textarea.getText() == null)) {
textarea.setText(sumNum + ". " + info);
} else {
textarea.setText(textarea.getText() + "\n" + sumNum + ". " + info);
}
}
}
}
Component[] components = root.getRootPane().getContentPane().getComponents();
for (int i = 0; i < components.length; i++) {
if (components[i].getClass().toString().equals("class javax.swing.JScrollPane")) {
JTextArea textarea = (JTextArea) ((JScrollPane) components[i]).getViewport().getView();
if (info.equals("")) {
sumError = 0;
sumExistError = 0;
sumNotFoundError = 0;
sumSuccess = 0;
sumNum = 1;
textarea.setText("");
} else if ((textarea.getText().equals("")) || (textarea.getText() == null)) {
textarea.setText(sumNum + ". " + info);
} else {
textarea.setText(textarea.getText() + "\n" + sumNum + ". " + info);
}
}
}
}
private static boolean copy(String from, String dirPath, JFrame root) {
boolean isCommon = true;
File fromFile = new File(from);
if (!fromFile.exists()) {
sumExistError += 1;
setInfo(from + "-------未找到!", root);
private static boolean copy(String from, String dirPath, JFrame root) {
boolean isCommon = true;
File fromFile = new File(from);
if (!fromFile.exists()) {
sumExistError += 1;
setInfo(from + "-------未找到!", root);
System.out.println(from + "---------------未找到!");
return false;
}
makeDirs(dirPath);
try {
File toFile = new File(dirPath + File.separatorChar + fromFile.getName());
if (toFile.exists()) {
sumNotFoundError += 1;
int k = checkFileVersion(fromFile, toFile);
if (k == -1) {
setInfo(fromFile.getAbsolutePath() + "--输出失败(已存在!)", root);
System.out.println(
"文件版本在目标版本之前,处理为不覆盖!若要处理请人工处理!\n原文件:" + fromFile.getAbsolutePath() + "\n目标文件:" + toFile.getAbsolutePath());
JOptionPane jp = new JOptionPane();
jp.setBounds(new Rectangle(new Point(400, 400)));
System.out.println(from + "---------------未找到!");
return false;
}
makeDirs(dirPath);
try {
File toFile = new File(dirPath + File.separatorChar + fromFile.getName());
if (toFile.exists()) {
sumNotFoundError += 1;
int k = checkFileVersion(fromFile, toFile);
if (k == -1) {
setInfo(fromFile.getAbsolutePath() + "--输出失败(已存在!)", root);
System.out.println(
"文件版本在目标版本之前,处理为不覆盖!若要处理请人工处理!\n原文件:" + fromFile.getAbsolutePath() + "\n目标文件:" + toFile.getAbsolutePath());
JOptionPane jp = new JOptionPane();
jp.setBounds(new Rectangle(new Point(400, 400)));
int isYes = JOptionPane.showConfirmDialog(root, "发现相同的文件,文件版本在目标版本之前!是否要进行覆盖?\n当前文件" +
int isYes = JOptionPane.showConfirmDialog(root, "发现相同的文件,文件版本在目标版本之前!是否要进行覆盖?\n当前文件" +
fromFile.getAbsolutePath() + ",修改日期:" + getDate(new Date(fromFile.lastModified())) + "\n目标文件"
+ toFile.getAbsolutePath() + ",修改日期:" + getDate(new Date(toFile.lastModified())));
if (isYes == 0) {
isCommon = false;
System.out.println("您选择了是!");
} else {
return false;
}
}
if (k == 0) {
setInfo(fromFile.getAbsolutePath() + "--输出失败(已存在)", root);
System.out
.println("相同文件重复,处理为不覆盖!若要处理请人工处理!\n原文件:" + fromFile.getAbsolutePath() + "\n目标文件:" + toFile.getAbsolutePath());
return true;
}
if (k == 1) {
isCommon = false;
}
} else if (!toFile.exists()) {
toFile.createNewFile();
isCommon = false;
}
if (!isCommon) {
InputStream is = new FileInputStream(fromFile);
OutputStream out = new FileOutputStream(toFile);
byte[] b = new byte[1024];
int len = -1;
while ((len = is.read(b)) != -1) {
out.write(b, 0, len);
}
out.flush();
out.close();
is.close();
toFile.setLastModified(fromFile.lastModified());
sumSuccess += 1;
return true;
}
} catch (Exception e) {
System.out.println("Copy Error!");
}
return false;
}
fromFile.getAbsolutePath() + ",修改日期:" + getDate(new Date(fromFile.lastModified())) + "\n目标文件"
+ toFile.getAbsolutePath() + ",修改日期:" + getDate(new Date(toFile.lastModified())));
if (isYes == 0) {
isCommon = false;
System.out.println("您选择了是!");
} else {
return false;
}
}
if (k == 0) {
setInfo(fromFile.getAbsolutePath() + "--输出失败(已存在)", root);
System.out
.println("相同文件重复,处理为不覆盖!若要处理请人工处理!\n原文件:" + fromFile.getAbsolutePath() + "\n目标文件:" + toFile.getAbsolutePath());
return true;
}
if (k == 1) {
isCommon = false;
}
} else if (!toFile.exists()) {
toFile.createNewFile();
isCommon = false;
}
if (!isCommon) {
InputStream is = new FileInputStream(fromFile);
OutputStream out = new FileOutputStream(toFile);
byte[] b = new byte[1024];
int len = -1;
while ((len = is.read(b)) != -1) {
out.write(b, 0, len);
}
out.flush();
out.close();
is.close();
toFile.setLastModified(fromFile.lastModified());
sumSuccess += 1;
return true;
}
} catch (Exception e) {
System.out.println("Copy Error!");
}
return false;
}
private static void makeDirs(String path) {
File f = new File(path);
if (!f.exists()) {
f.mkdirs();
}
}
private static void makeDirs(String path) {
File f = new File(path);
if (!f.exists()) {
f.mkdirs();
}
}
private static int checkFileVersion(File file1, File file2) {
long file1LastTime = file1.lastModified();
long file2LastTime = file2.lastModified();
if (file1LastTime > file2LastTime) {
return 1;
}
if (file1LastTime < file2LastTime) {
return -1;
}
return 0;
}
private static int checkFileVersion(File file1, File file2) {
long file1LastTime = file1.lastModified();
long file2LastTime = file2.lastModified();
if (file1LastTime > file2LastTime) {
return 1;
}
if (file1LastTime < file2LastTime) {
return -1;
}
return 0;
}
public static boolean becomePackage(String fileList, String cutStr, String dir, JFrame root) throws Exception {
dir = dir + "\\";
public static boolean becomePackage(String fileList, String cutStr, String dir, JFrame root) throws Exception {
dir = dir + "\\";
String filePath = null;
String addStr = null;
String fromFile = null;
String toFile = null;
boolean flag = false;
try {
BufferedReader br = getBufferedReader(fileList);
addStr = br.readLine();
addStr = addStr.trim();
setInfo("", root);
while ((filePath = br.readLine()) != null) {
sumNum += 1;
if (!"".equals(filePath.trim())) {
filePath = filePath.replaceAll("/", "\\\\");
String filePath = null;
String addStr = null;
String fromFile = null;
String toFile = null;
boolean flag = false;
try {
BufferedReader br = getBufferedReader(fileList);
addStr = br.readLine();
addStr = addStr.trim();
setInfo("", root);
while ((filePath = br.readLine()) != null) {
sumNum += 1;
if (!"".equals(filePath.trim())) {
filePath = filePath.replaceAll("/", "\\\\");
System.out.println(filePath.replaceAll("\\\\", "/"));
if (filePath.startsWith(cutStr)) {
fromFile = filePath.trim();
toFile = dir + addStr + File.separatorChar + getCenter(cutStr, fromFile);
flag = copy(fromFile, toFile, root);
} else {
fromFile = cutStr + File.separatorChar + filePath.trim();
toFile = dir + addStr + File.separatorChar + filePath.substring(0, filePath.trim().lastIndexOf("\\"));
System.out.println(filePath.replaceAll("\\\\", "/"));
if (filePath.startsWith(cutStr)) {
fromFile = filePath.trim();
toFile = dir + addStr + File.separatorChar + getCenter(cutStr, fromFile);
flag = copy(fromFile, toFile, root);
} else {
fromFile = cutStr + File.separatorChar + filePath.trim();
toFile = dir + addStr + File.separatorChar + filePath.substring(0, filePath.trim().lastIndexOf("\\"));
flag = copy(fromFile, toFile, root);
}
}
}
br.close();
setInfo("----成功:" + sumSuccess + "\n" + "----失败:" + sumError + "\n" + "--------未找到:" + sumNotFoundError + "\n" + "--------已存在:"
+ sumExistError, root);
return flag;
} catch (FileNotFoundException e) {
System.out.println("列表文件没有找到!");
throw new Exception("列表文件没有找到!");
} catch (IOException e) {
System.out.println("列表文件读取出错!");
throw new Exception("列表文件读取出错!");
}
}
flag = copy(fromFile, toFile, root);
}
}
}
br.close();
setInfo("----成功:" + sumSuccess + "\n" + "----失败:" + sumError + "\n" + "--------未找到:" + sumNotFoundError + "\n" + "--------已存在:"
+ sumExistError, root);
return flag;
} catch (FileNotFoundException e) {
System.out.println("列表文件没有找到!");
throw new Exception("列表文件没有找到!");
} catch (IOException e) {
System.out.println("列表文件读取出错!");
throw new Exception("列表文件读取出错!");
}
}
private static String getCenter(String flag, String message) {
int k1 = message.trim().indexOf(flag);
int k2 = message.trim().lastIndexOf("\\");
if ((k1 != -1) && (k2 != -1)) {
return message.substring(flag.length() + 1, k2 + 1);
}
return null;
}
private static String getCenter(String flag, String message) {
int k1 = message.trim().indexOf(flag);
int k2 = message.trim().lastIndexOf("\\");
if ((k1 != -1) && (k2 != -1)) {
return message.substring(flag.length() + 1, k2 + 1);
}
return null;
}
}

View File

@ -1,270 +1,260 @@
package me.ehlxr.pack;
import java.awt.Color;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileSystemView;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileSystemView;
@SuppressWarnings("serial")
public class PackView extends JFrame {
private JButton jb = new JButton();
private JButton jb1 = new JButton();
private JButton jb2 = new JButton();
private String inputPath = "D:\\wins-dsp";
private String outputPath = "C:\\Users\\ehlxr\\Desktop";
private JLabel jl0 = new JLabel();
private JButton cancel = new JButton("退出");
private JTextPane jText1 = new JTextPane();
private JTextPane jText2 = new JTextPane();
public JTextArea jArea = new JTextArea();
public JScrollPane p = new JScrollPane(this.jArea);
private final JButton jb = new JButton();
private final JButton jb1 = new JButton();
private final JButton jb2 = new JButton();
private final JLabel jl0 = new JLabel();
private final JButton cancel = new JButton("退出");
private final JTextPane jText1 = new JTextPane();
private final JTextPane jText2 = new JTextPane();
public JTextArea jArea = new JTextArea();
public JScrollPane p = new JScrollPane(this.jArea);
private String inputPath = "D:\\wins-dsp";
private String outputPath = "C:\\Users\\ehlxr\\Desktop";
private PackView() {
setTitle("打包工具By:Henry");
setBounds(400, 400, 500, 300);
setLayout(null);
setResizable(false);
this.jb.setText("打包清单");
this.jb1.setText("打包根目录");
this.jb2.setText("输出目录");
private PackView() {
setTitle("打包工具By:Henry");
setBounds(400, 400, 500, 300);
setLayout(null);
setResizable(false);
this.jb.setText("打包清单");
this.jb1.setText("打包根目录");
this.jb2.setText("输出目录");
this.jText1.setText(this.inputPath);
this.jText2.setText(this.outputPath);
this.jText1.setText(this.inputPath);
this.jText2.setText(this.outputPath);
this.jb.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
if (PackView.this.packs()) {
PackView.this.jl0.setText("成功打包!");
PackView.this.jb.setText("...继续");
} else {
PackView.this.jl0.setText("打包失败!");
}
}
this.jb.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
if (PackView.this.packs()) {
PackView.this.jl0.setText("成功打包!");
PackView.this.jb.setText("...继续");
} else {
PackView.this.jl0.setText("打包失败!");
}
}
public void mousePressed(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
});
this.jb1.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
PackView.this.choosePath(1);
PackView.this.jText1.setText(PackView.this.inputPath);
}
public void mouseClicked(MouseEvent e) {
}
});
this.jb1.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
PackView.this.choosePath(1);
PackView.this.jText1.setText(PackView.this.inputPath);
}
public void mousePressed(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
});
this.jb2.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
PackView.this.choosePath(2);
PackView.this.jText2.setText(PackView.this.outputPath);
}
public void mouseClicked(MouseEvent e) {
}
});
this.jb2.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
PackView.this.choosePath(2);
PackView.this.jText2.setText(PackView.this.outputPath);
}
public void mousePressed(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
});
this.cancel.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
PackView.this.close();
}
public void mouseClicked(MouseEvent e) {
}
});
this.cancel.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
PackView.this.close();
}
public void mousePressed(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
});
this.jb1.setBounds(10, 5, 100, 30);
this.jText1.setBounds(120, 5, 250, 30);
public void mouseClicked(MouseEvent e) {
}
});
this.jb1.setBounds(10, 5, 100, 30);
this.jText1.setBounds(120, 5, 250, 30);
this.jb2.setBounds(10, 40, 100, 30);
this.jText2.setBounds(120, 40, 250, 30);
this.jb2.setBounds(10, 40, 100, 30);
this.jText2.setBounds(120, 40, 250, 30);
this.jb.setBounds(10, 100, 100, 30);
this.cancel.setBounds(120, 100, 100, 30);
this.jl0.setBounds(230, 100, 100, 30);
this.jArea.setLineWrap(true);
this.jArea.setForeground(Color.red);
this.jArea.setEditable(false);
this.jb.setBounds(10, 100, 100, 30);
this.cancel.setBounds(120, 100, 100, 30);
this.jl0.setBounds(230, 100, 100, 30);
this.jArea.setLineWrap(true);
this.jArea.setForeground(Color.red);
this.jArea.setEditable(false);
this.p.setBounds(10, 130, 480, 130);
this.p.setBounds(10, 130, 480, 130);
this.p.setVerticalScrollBarPolicy(22);
this.p.setHorizontalScrollBarPolicy(32);
this.p.setVerticalScrollBarPolicy(22);
this.p.setHorizontalScrollBarPolicy(32);
add(this.jb1);
add(this.jText1);
add(this.jb2);
add(this.jText2);
add(this.jb);
add(this.cancel);
add(this.jl0);
add(this.jb1);
add(this.jText1);
add(this.jb2);
add(this.jText2);
add(this.jb);
add(this.cancel);
add(this.jl0);
add(this.p);
setVisible(true);
setDefaultCloseOperation(3);
}
add(this.p);
setVisible(true);
setDefaultCloseOperation(3);
}
private List<String> chooseFile(int chooseMode) {
try {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(true);
fileChooser.setDialogTitle("文件打包");
fileChooser.setDragEnabled(true);
fileChooser.setAutoscrolls(true);
public static void main(String[] args) {
new PackView();
}
fileChooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
if ((f.getName().endsWith(".TXT")) || (f.getName().endsWith(".txt"))) {
return true;
}
return false;
}
private List<String> chooseFile(int chooseMode) {
try {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(true);
fileChooser.setDialogTitle("文件打包");
fileChooser.setDragEnabled(true);
fileChooser.setAutoscrolls(true);
public String getDescription() {
return ".txt";
}
});
fileChooser.setCurrentDirectory(FileSystemView.getFileSystemView().getHomeDirectory());
fileChooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
return (f.getName().endsWith(".TXT")) || (f.getName().endsWith(".txt"));
}
fileChooser.setOpaque(true);
fileChooser.setDoubleBuffered(true);
int returnVal = -1;
switch (chooseMode) {
case 1:
returnVal = fileChooser.showOpenDialog(this);
break;
case 2:
returnVal = fileChooser.showSaveDialog(this);
}
File[] fileName;
if (returnVal == 0) {
fileName = fileChooser.getSelectedFiles();
} else {
fileName = (File[]) null;
}
List<String> list = new ArrayList<String>();
System.out.println("打包文件路径列表:");
String filePath = null;
for (int i = 0; i < fileName.length; i++) {
filePath = fileName[i].getAbsolutePath();
if (filePath.toUpperCase().endsWith("TXT")) {
list.add(filePath);
System.out.println("序号 " + i + " " + filePath);
} else {
System.out.println("序号 " + i + " " + filePath + " >>该文件不能作为打包文件! ");
}
}
return list;
} catch (Exception e) {
}
return null;
}
public String getDescription() {
return ".txt";
}
});
fileChooser.setCurrentDirectory(FileSystemView.getFileSystemView().getHomeDirectory());
private boolean choosePath(int id) {
try {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(true);
switch (id) {
case 1:
fileChooser.setDialogTitle("打包文件根目录");
fileChooser.setCurrentDirectory(new File(this.inputPath));
break;
case 2:
fileChooser.setDialogTitle("输出文件目录");
fileChooser.setCurrentDirectory(new File(this.outputPath));
}
fileChooser.setDragEnabled(true);
fileChooser.setAutoscrolls(true);
fileChooser.setAcceptAllFileFilterUsed(true);
fileChooser.setOpaque(true);
fileChooser.setDoubleBuffered(true);
fileChooser.setFileSelectionMode(1);
fileChooser.setOpaque(true);
fileChooser.setDoubleBuffered(true);
int returnVal = -1;
switch (chooseMode) {
case 1:
returnVal = fileChooser.showOpenDialog(this);
break;
case 2:
returnVal = fileChooser.showSaveDialog(this);
}
File[] fileName;
if (returnVal == 0) {
fileName = fileChooser.getSelectedFiles();
} else {
fileName = null;
}
List<String> list = new ArrayList<String>();
System.out.println("打包文件路径列表:");
String filePath = null;
for (int i = 0; i < fileName.length; i++) {
filePath = fileName[i].getAbsolutePath();
if (filePath.toUpperCase().endsWith("TXT")) {
list.add(filePath);
System.out.println("序号 " + i + " " + filePath);
} else {
System.out.println("序号 " + i + " " + filePath + " >>该文件不能作为打包文件! ");
}
}
return list;
} catch (Exception e) {
}
return null;
}
fileChooser.showOpenDialog(this);
switch (id) {
case 1:
this.inputPath = fileChooser.getSelectedFile().toString();
break;
case 2:
this.outputPath = fileChooser.getSelectedFile().toString();
}
return true;
} catch (Exception e) {
}
return false;
}
private boolean choosePath(int id) {
try {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(true);
switch (id) {
case 1:
fileChooser.setDialogTitle("打包文件根目录");
fileChooser.setCurrentDirectory(new File(this.inputPath));
break;
case 2:
fileChooser.setDialogTitle("输出文件目录");
fileChooser.setCurrentDirectory(new File(this.outputPath));
}
fileChooser.setDragEnabled(true);
fileChooser.setAutoscrolls(true);
fileChooser.setAcceptAllFileFilterUsed(true);
fileChooser.setOpaque(true);
fileChooser.setDoubleBuffered(true);
fileChooser.setFileSelectionMode(1);
private void close() {
dispose();
}
fileChooser.showOpenDialog(this);
switch (id) {
case 1:
this.inputPath = fileChooser.getSelectedFile().toString();
break;
case 2:
this.outputPath = fileChooser.getSelectedFile().toString();
}
return true;
} catch (Exception e) {
}
return false;
}
private boolean packs() {
boolean flag = true;
List<String> fileName = chooseFile(1);
if ((fileName == null) || (fileName.size() <= 0)) {
System.out.println("打包原始文件没有找到");
flag = false;
} else {
for (int i = 0; i < fileName.size(); i++) {
try {
flag = FileUtil.becomePackage((String) fileName.get(i), this.inputPath, this.outputPath, this);
} catch (Exception e) {
return false;
}
}
}
return flag;
}
private void close() {
dispose();
}
public static void main(String[] args) {
new PackView();
}
private boolean packs() {
boolean flag = true;
List<String> fileName = chooseFile(1);
if ((fileName == null) || (fileName.size() <= 0)) {
System.out.println("打包原始文件没有找到");
flag = false;
} else {
for (int i = 0; i < fileName.size(); i++) {
try {
flag = FileUtil.becomePackage(fileName.get(i), this.inputPath, this.outputPath, this);
} catch (Exception e) {
return false;
}
}
}
return flag;
}
}

View File

@ -12,7 +12,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* @since 2019-07-19.
*/
public class RateBarrier {
private AtomicInteger op = new AtomicInteger(0);
private final AtomicInteger op = new AtomicInteger(0);
private List<Integer> source;
private int base;
private int rate;

View File

@ -1,176 +1,167 @@
package me.ehlxr.sftp;
import com.jcraft.jsch.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.InputStream;
import java.util.Properties;
import java.util.Vector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
/**
* SFTP
*
* @author ehlxr
*
* @author ehlxr
*/
public class SFTPUtil {
private static Log log = LogFactory.getLog(SFTPUtil.class);
private static String ip;
private static String user;
private static String psw;
private static int port;
private static final Log log = LogFactory.getLog(SFTPUtil.class);
private static String ip;
private static String user;
private static String psw;
private static int port;
private static Session session = null;
private static Channel channel = null;
private static Session session = null;
private static Channel channel = null;
static {
try {
InputStream propFile = SFTPUtil.class.getResourceAsStream("sftp.properties");
if (propFile != null) {
Properties p = new Properties();
p.load(propFile);
ip = p.getProperty("sftp.ip");
user = p.getProperty("sftp.user");
psw = p.getProperty("sftp.psw");
String portStr = p.getProperty("sftp.port");
port = (portStr != null ? Integer.parseInt(portStr) : -1);
propFile.close();
propFile = null;
}
} catch (Exception e) {
log.error("读取sftp配置文件失败" + e.getMessage());
e.printStackTrace();
}
}
static {
try {
InputStream propFile = SFTPUtil.class.getResourceAsStream("sftp.properties");
if (propFile != null) {
Properties p = new Properties();
p.load(propFile);
ip = p.getProperty("sftp.ip");
user = p.getProperty("sftp.user");
psw = p.getProperty("sftp.psw");
String portStr = p.getProperty("sftp.port");
port = (portStr != null ? Integer.parseInt(portStr) : -1);
propFile.close();
propFile = null;
}
} catch (Exception e) {
log.error("读取sftp配置文件失败" + e.getMessage());
e.printStackTrace();
}
}
private static ChannelSftp getSFTP() throws Exception {
log.info("正在连接服务器[" + ip + "].....");
ChannelSftp sftp = null;
JSch jsch = new JSch();
if (port <= 0) {
// 连接服务器,采用默认端口
session = jsch.getSession(user, ip);
} else {
// 采用指定的端口连接服务器
session = jsch.getSession(user, ip, port);
}
private static ChannelSftp getSFTP() throws Exception {
log.info("正在连接服务器[" + ip + "].....");
ChannelSftp sftp = null;
JSch jsch = new JSch();
if (port <= 0) {
// 连接服务器,采用默认端口
session = jsch.getSession(user, ip);
} else {
// 采用指定的端口连接服务器
session = jsch.getSession(user, ip, port);
}
// 如果服务器连接不上,则抛出异常
if (session == null) {
log.error("连接服务器[" + ip + "]失败.....");
throw new Exception("session is null");
}
// 如果服务器连接不上,则抛出异常
if (session == null) {
log.error("连接服务器[" + ip + "]失败.....");
throw new Exception("session is null");
}
// 设置登陆主机的密码
session.setPassword(psw);// 设置密码
// 设置第一次登陆的时候提示,可选值:(ask | yes | no)
session.setConfig("StrictHostKeyChecking", "no");
// 设置登陆超时时间
session.connect(30000);
// 设置登陆主机的密码
session.setPassword(psw);// 设置密码
// 设置第一次登陆的时候提示,可选值:(ask | yes | no)
session.setConfig("StrictHostKeyChecking", "no");
// 设置登陆超时时间
session.connect(30000);
try {
// 创建sftp通信通道
channel = (Channel) session.openChannel("sftp");
channel.connect(1000);
sftp = (ChannelSftp) channel;
log.info("连接服务器[" + ip + "]成功.....");
} catch (Exception e) {
log.error("服务器[" + ip + "]创建sftp通信通道失败" + e.getMessage());
e.printStackTrace();
closeSFTP();
}
return sftp;
}
try {
// 创建sftp通信通道
channel = session.openChannel("sftp");
channel.connect(1000);
sftp = (ChannelSftp) channel;
log.info("连接服务器[" + ip + "]成功.....");
} catch (Exception e) {
log.error("服务器[" + ip + "]创建sftp通信通道失败" + e.getMessage());
e.printStackTrace();
closeSFTP();
}
return sftp;
}
private static void closeSFTP() {
if (session != null && session.isConnected()) {
session.disconnect();
}
if (channel != null && channel.isConnected()) {
channel.disconnect();
}
}
private static void closeSFTP() {
if (session != null && session.isConnected()) {
session.disconnect();
}
if (channel != null && channel.isConnected()) {
channel.disconnect();
}
}
/**
* SFTP
*
* @param desPath
* ftp
* @param desFileName
*
* @param resFile
*
* @throws Exception
*/
public static void putFile(String desPath, String desFileName, File resFile) {
try {
ChannelSftp sftp = getSFTP();
mkdirs(sftp, desPath);
/**
* SFTP
*
* @param desPath ftp
* @param desFileName
* @param resFile
* @throws Exception
*/
public static void putFile(String desPath, String desFileName, File resFile) {
try {
ChannelSftp sftp = getSFTP();
mkdirs(sftp, desPath);
// 进入服务器指定的文件夹
sftp.cd(desPath);
// 进入服务器指定的文件夹
sftp.cd(desPath);
sftp.put(resFile.getAbsolutePath(), desFileName, ChannelSftp.OVERWRITE);
log.info("文件[" + desPath + desFileName + "]上传完成...");
closeSFTP();
} catch (Exception e) {
log.error("文件[" + desPath + desFileName + "]上传失败:" + e.getMessage());
e.printStackTrace();
closeSFTP();
}
}
sftp.put(resFile.getAbsolutePath(), desFileName, ChannelSftp.OVERWRITE);
log.info("文件[" + desPath + desFileName + "]上传完成...");
closeSFTP();
} catch (Exception e) {
log.error("文件[" + desPath + desFileName + "]上传失败:" + e.getMessage());
e.printStackTrace();
closeSFTP();
}
}
public static void main(String[] args) {
try {
SFTPUtil.putFile("/upload/222/1111", "212321.txt", new File("D:/1.txt"));
public static void main(String[] args) {
try {
SFTPUtil.putFile("/upload/222/1111", "212321.txt", new File("D:/1.txt"));
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*
*
* @param sftp
* @param desPath
* @throws Exception
*/
private static void mkdirs(ChannelSftp sftp, String desPath) throws Exception {
String[] paths = desPath.split("/");
String path = "";
for (int i = 0; i < paths.length; i++) {
path += paths[i] + "/";
if (!isExistDir(sftp, path)) {
sftp.mkdir(path);
}
}
}
/**
*
*
* @param sftp
* @param desPath
* @throws Exception
*/
private static void mkdirs(ChannelSftp sftp, String desPath) throws Exception {
String[] paths = desPath.split("/");
String path = "";
for (int i = 0; i < paths.length; i++) {
path += paths[i] + "/";
if (!isExistDir(sftp, path)) {
sftp.mkdir(path);
}
}
}
/**
*
*
* @param sftp
* @param desPath
* @return
*/
private static boolean isExistDir(ChannelSftp sftp, String desPath) {
boolean isExist = false;
try {
Vector<?> content = sftp.ls(desPath);
if (content != null) {
isExist = true;
}
} catch (SftpException e) {
isExist = false;
}
return isExist;
}
/**
*
*
* @param sftp
* @param desPath
* @return
*/
private static boolean isExistDir(ChannelSftp sftp, String desPath) {
boolean isExist = false;
try {
Vector<?> content = sftp.ls(desPath);
if (content != null) {
isExist = true;
}
} catch (SftpException e) {
isExist = false;
}
return isExist;
}
}

View File

@ -4,7 +4,7 @@ import java.util.Arrays;
/**
*
*
* <p>
*
*
*

View File

@ -4,28 +4,29 @@ import java.io.File;
import java.io.FilenameFilter;
public class DirList {
public static void main(String[] args) {
File path = new File("D://");
String arg = "dsp_impclk_15";
String[] list;
if (arg.length() == 0)
list = path.list();
else
list = path.list(new DirFilter(arg));
for (int i = 0; i < list.length; ++i) {
System.out.println(list[i]);
}
}
public static void main(String[] args) {
File path = new File("D://");
String arg = "dsp_impclk_15";
String[] list;
if (arg.length() == 0)
list = path.list();
else
list = path.list(new DirFilter(arg));
for (int i = 0; i < list.length; ++i) {
System.out.println(list[i]);
}
}
}
class DirFilter implements FilenameFilter {
String afn;
DirFilter(String afn) {
this.afn = afn;
}
String afn;
public boolean accept(File dir, String name) {
String f = new File(name).getName();
return f.indexOf(afn) != -1;
}
DirFilter(String afn) {
this.afn = afn;
}
public boolean accept(File dir, String name) {
String f = new File(name).getName();
return f.indexOf(afn) != -1;
}
}

View File

@ -2,60 +2,58 @@ package me.ehlxr.test;
import java.io.BufferedReader;
import java.io.FileReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
public class ExecBaics50Log {
public static void main(String[] args) throws Exception {
StringBuffer sb = new StringBuffer("");
public static void main(String[] args) throws Exception {
StringBuffer sb = new StringBuffer();
FileReader reader = new FileReader("C:\\Users\\ehlxr\\Desktop\\minisite\\20160606\\3\\2016-06-06(3、4、5).txt");
BufferedReader br = new BufferedReader(reader);
String str = null;
while ((str = br.readLine()) != null) {
String[] split = str.split(",");
String ssString = "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
FileReader reader = new FileReader("C:\\Users\\ehlxr\\Desktop\\minisite\\20160606\\3\\2016-06-06(3、4、5).txt");
BufferedReader br = new BufferedReader(reader);
String str = null;
while ((str = br.readLine()) != null) {
String[] split = str.split(",");
String ssString = "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (String s : split) {
for (String s : split) {
String substring = s.substring(s.indexOf("=") + 1);
if (substring.contains("CST")) {
substring = formatDate(substring);
ssString += "'" + substring + "'";
}else{
ssString += "'" + substring + "',";
}
}
String substring = s.substring(s.indexOf("=") + 1);
if (substring.contains("CST")) {
substring = formatDate(substring);
System.out.println(
"insert into user_info (`u_name`, `u_gender`, `u_tel`, `u_province`, `u_city`, `u_dealername`,`u_dealercode`, `u_scheduledtime`, `addtime`) VALUES("
+ ssString + ");");
}
br.close();
reader.close();
}
private static String formatDate(String date) throws Exception{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", java.util.Locale.ENGLISH);
TimeZone tz = TimeZone.getTimeZone("CST");
sdf1.setTimeZone(tz);
sdf.setTimeZone(tz);
Calendar c = Calendar.getInstance();
c.setTime(sdf1.parse(date));
c.set(Calendar.HOUR, c.get(Calendar.HOUR) - 1);
return sdf.format(c.getTime());
}
ssString += "'" + substring + "'";
} else {
ssString += "'" + substring + "',";
}
}
System.out.println(
"insert into user_info (`u_name`, `u_gender`, `u_tel`, `u_province`, `u_city`, `u_dealername`,`u_dealercode`, `u_scheduledtime`, `addtime`) VALUES("
+ ssString + ");");
}
br.close();
reader.close();
}
private static String formatDate(String date) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", java.util.Locale.ENGLISH);
TimeZone tz = TimeZone.getTimeZone("CST");
sdf1.setTimeZone(tz);
sdf.setTimeZone(tz);
Calendar c = Calendar.getInstance();
c.setTime(sdf1.parse(date));
c.set(Calendar.HOUR, c.get(Calendar.HOUR) - 1);
return sdf.format(c.getTime());
}
}

View File

@ -3,21 +3,21 @@ package me.ehlxr.test;
import java.math.BigDecimal;
public interface IChargeCounter {
/**
*
*
* @param campaignid
* @param groupid
* @param cost
*/
public void chargeForThisResult(String campaignid, String groupid, BigDecimal cost);
/**
*
*
* @param campaignid
* @param groupid
* @param cost
*/
void chargeForThisResult(String campaignid, String groupid, BigDecimal cost);
/**
*
*
* @param groupid
* @param count
* @param type
*/
public void counterControlForThisSumResult(String groupid, int count, String type);
/**
*
*
* @param groupid
* @param count
* @param type
*/
void counterControlForThisSumResult(String groupid, int count, String type);
}

View File

@ -7,7 +7,7 @@ import me.ehlxr.redis.JedisUtil;
*/
public class Main {
public static void main(String[] args) {
JedisUtil.set("test_20160614","20160614");
JedisUtil.set("test_20160614", "20160614");
System.out.println(JedisUtil.getStr("test_20160614"));
}
}

View File

@ -6,8 +6,8 @@ package me.ehlxr.test;
public class Test {
public static void main(String[] args) {
String s0 = "kvill";
String s1 = new String("kvill");
String s2 = new String("kvill");
String s1 = "kvill";
String s2 = "kvill";
System.out.println(s0 == s1);
System.out.println("**********");
s1.intern();

View File

@ -3,9 +3,9 @@ package me.ehlxr.test;
import me.ehlxr.utils.HttpClientUtil;
public class TestAudiQ2 {
public static String URL = "http://127.0.0.1:8080/Audi2016Q2Wap/getUserInfo";
public static String URL = "http://127.0.0.1:8080/Audi2016Q2Wap/getUserInfo";
public static void main(String[] args) throws Exception {
System.out.println(HttpClientUtil.sendPostJSONData(URL, ""));
}
public static void main(String[] args) throws Exception {
System.out.println(HttpClientUtil.sendPostJSONData(URL, ""));
}
}

View File

@ -2,11 +2,7 @@ package me.ehlxr.test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.TimeZone;
import java.util.*;
public class TestCode {
@ -28,14 +24,14 @@ public class TestCode {
// Map<String, Object> resultMap = new HashMap<String, Object>();
// System.out.println((String)resultMap.get("dd"));
// try {
// String str = null;
// str.equals("");
// } catch (Exception e) {
// System.out.println(e.getMessage());
// e.printStackTrace();
// }
// System.out.println("fffff");
// try {
// String str = null;
// str.equals("");
// } catch (Exception e) {
// System.out.println(e.getMessage());
// e.printStackTrace();
// }
// System.out.println("fffff");
// String[] s = {"111","eee"};
// System.out.println(Arrays.toString(s));
@ -114,217 +110,217 @@ public class TestCode {
// System.out.println(jj.optString("pring"));
// // 根据网卡取本机配置的IP
// InetAddress inet = null;
// try {
// inet = InetAddress.getLocalHost();
// } catch (UnknownHostException e) {
// e.printStackTrace();
// }
// String ipAddress = inet.getHostAddress();
//
// System.out.println(ipAddress);
// // 根据网卡取本机配置的IP
// InetAddress inet = null;
// try {
// inet = InetAddress.getLocalHost();
// } catch (UnknownHostException e) {
// e.printStackTrace();
// }
// String ipAddress = inet.getHostAddress();
//
// System.out.println(ipAddress);
// TestCode test = new TestCode();
// System.out.println(test.dd("ddd"));
// TestCode test = new TestCode();
// System.out.println(test.dd("ddd"));
// Package pkg = Package.getPackage("osc.git.eh3.test");
// Annotation[] annotations = pkg.getAnnotations();
// for (Annotation annotation : annotations) {
// System.out.println(annotation);
// }
// Package pkg = Package.getPackage("osc.git.eh3.test");
// Annotation[] annotations = pkg.getAnnotations();
// for (Annotation annotation : annotations) {
// System.out.println(annotation);
// }
// String[] arrs = new String[]{"111","111","2222"};
// for (String string : Array2Set(arrs)) {
//
// System.out.println(string);
// }
// String[] arrs = new String[]{"111","111","2222"};
// for (String string : Array2Set(arrs)) {
//
// System.out.println(string);
// }
// Class<?> clazz = StatisByHourModel.class;
// Method[] methods = clazz.getMethods();
// for (Method method : methods) {
// System.out.println(method.getName());
// }
// Object dd = new Date();
//
// System.out.println(dd instanceof Date);
//
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
// System.out.println(sdf.format(dd));
// Class<?> clazz = StatisByHourModel.class;
// Method[] methods = clazz.getMethods();
// for (Method method : methods) {
// System.out.println(method.getName());
// }
// Object dd = new Date();
//
// System.out.println(dd instanceof Date);
//
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
// System.out.println(sdf.format(dd));
// JSONObject groupAdxs = JSONObject.fromObject("{\"4ebdb328-5d4b-42e6-80c3-a6aaaecdcea1\":[\"1e03319c-425d-4a17-a6bf-eeec2f48db29\",\"1fed4171-9925-4834-aa7b-9b4d3a58841b\",\"ce579246-e707-4cb9-b982-88cad7944b92\"],\"9262cbe8-a9dc-4f4e-888b-cf3ffe65defd\":\"ce579246-e707-4cb9-b982-88cad7944b92\"}");
// Set<String> keySet = groupAdxs.keySet();
// for (Object object : keySet) {
// System.out.println(groupAdxs.get(object).getClass().isArray());
// }
// JSONObject groupAdxs = JSONObject.fromObject("{\"4ebdb328-5d4b-42e6-80c3-a6aaaecdcea1\":[\"1e03319c-425d-4a17-a6bf-eeec2f48db29\",\"1fed4171-9925-4834-aa7b-9b4d3a58841b\",\"ce579246-e707-4cb9-b982-88cad7944b92\"],\"9262cbe8-a9dc-4f4e-888b-cf3ffe65defd\":\"ce579246-e707-4cb9-b982-88cad7944b92\"}");
// Set<String> keySet = groupAdxs.keySet();
// for (Object object : keySet) {
// System.out.println(groupAdxs.get(object).getClass().isArray());
// }
// System.out.println(UUID.randomUUID().toString());
// System.out.println(UUID.randomUUID().toString());
// System.out.println(new Integer(0x11));
// System.out.println(Integer.toBinaryString(30000));
// System.out.println(Integer.valueOf("11", 16));
// System.out.println(Integer.valueOf("11", 2));
// System.out.println(new Integer(0x11));
// System.out.println(Integer.toBinaryString(30000));
// System.out.println(Integer.valueOf("11", 16));
// System.out.println(Integer.valueOf("11", 2));
// System.out.println(AESTool.encrypt("ehlxr"));
// System.out.println(AESTool.decrypt(AESEncrypter.encrypt("ehlxr")));
// System.out.println(AESTool.encrypt("ehlxr"));
// System.out.println(AESTool.decrypt(AESEncrypter.encrypt("ehlxr")));
// System.out.println(AESTool.encrypt("liixangrong","adjdjfjfjfjdkdkd"));
// System.out.println(AESTool.decrypt("bfb0c038342ffead45511879853279bf","adjdjfjfjfjdkdkd"));
// System.out.println(Base64.encodeToString(AESTool.encrypt("fa4d7d90618dcba5fa1d969cffc04def","002020202").getBytes(), false));
// System.out.println(AESTool.encrypt("liixangrong","adjdjfjfjfjdkdkd"));
// System.out.println(AESTool.decrypt("bfb0c038342ffead45511879853279bf","adjdjfjfjfjdkdkd"));
// System.out.println(Base64.encodeToString(AESTool.encrypt("fa4d7d90618dcba5fa1d969cffc04def","002020202").getBytes(), false));
// byte[] bytes = "ehlxr".getBytes();
// for (int i = 0; i < bytes.length; i++) {
// System.out.println(bytes[i]);
// }
// byte[] bytes = "ehlxr".getBytes();
// for (int i = 0; i < bytes.length; i++) {
// System.out.println(bytes[i]);
// }
// System.out.println(Base64.encodeToString("ehlxr".getBytes(), false));
// System.out.println(Base64.encodeToString("ehlxr".getBytes(), false));
// double lon1 = 109.0145193759;
// double lat1 = 34.236080797698;
// System.out.println(GeoHash.encode(lat1, lon1));
// System.out.println(GeoHash.decode("wmtdgn5esrb1")[0]+" "+GeoHash.decode("wmtdgn5esrb1")[1]);
// double lon1 = 109.0145193759;
// double lat1 = 34.236080797698;
// System.out.println(GeoHash.encode(lat1, lon1));
// System.out.println(GeoHash.decode("wmtdgn5esrb1")[0]+" "+GeoHash.decode("wmtdgn5esrb1")[1]);
// String url = "http://api.map.baidu.com/place/v2/search?query=银行&location=39.915,116.404&radius=2000&output=json&ak=LCG4dyrXyadeD8hFhi8SGCv6";
// System.out.println(HttpClientUtil.sendGet(url));
// String url = "http://api.map.baidu.com/place/v2/search?query=银行&location=39.915,116.404&radius=2000&output=json&ak=LCG4dyrXyadeD8hFhi8SGCv6";
// System.out.println(HttpClientUtil.sendGet(url));
// JSONArray array = new JSONArray();
// array.add("1");
// array.add("2");
// array.add("3");
// array.add("4");
// array.add("5");
// List<String> list = JSONArray.toList(array, new String(), new JsonConfig());
// System.out.println(list);
// JSONArray array = new JSONArray();
// array.add("1");
// array.add("2");
// array.add("3");
// array.add("4");
// array.add("5");
// List<String> list = JSONArray.toList(array, new String(), new JsonConfig());
// System.out.println(list);
// System.out.println(System.nanoTime());
// System.out.println(System.nanoTime());
// System.out.println(System.nanoTime());
// System.out.println(System.nanoTime());
// Map<String, String> postParam = new HashMap<String, String>();
// postParam.put("groupid", "100003");
// postParam.put("count", "1");
// postParam.put("type", "m");
// for(int i=0;i<5;i++){
// try {
// HttpClientUtil.sendPostParam("http://192.168.1.135:8080/dsp-counter/remote/chargeCounter/counterControlForThisSumResult", postParam);
//// HttpClientUtil.sendPost("http://192.168.1.135:8080/dsp-counter/remote/chargeCounter/counterControlForThisSumResult", "groupid=100003&count=1&type=m");
// break;
// } catch (Exception e) {
// System.out.println(e.getMessage());
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e1) {
// e1.printStackTrace();
// }
// }
// }
// Map<String, String> postParam = new HashMap<String, String>();
// postParam.put("groupid", "100003");
// postParam.put("count", "1");
// postParam.put("type", "m");
// for(int i=0;i<5;i++){
// try {
// HttpClientUtil.sendPostParam("http://192.168.1.135:8080/dsp-counter/remote/chargeCounter/counterControlForThisSumResult", postParam);
//// HttpClientUtil.sendPost("http://192.168.1.135:8080/dsp-counter/remote/chargeCounter/counterControlForThisSumResult", "groupid=100003&count=1&type=m");
// break;
// } catch (Exception e) {
// System.out.println(e.getMessage());
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e1) {
// e1.printStackTrace();
// }
// }
// }
// String str = "0,";
// System.out.println(str.split(",").length);
// String str = "0,";
// System.out.println(str.split(",").length);
// System.out.println(JedisUtil.getStr("0000"));
// Map<String,Integer> result = new HashMap<String, Integer>();
// System.out.println(result.get("jj"));
// double budgets = 10000;
// System.out.println((budgets/100));
// System.out.println(JedisUtil.getStr("0000"));
// Map<String,Integer> result = new HashMap<String, Integer>();
// System.out.println(result.get("jj"));
// double budgets = 10000;
// System.out.println((budgets/100));
// String str = null;
// BigDecimal budget = new BigDecimal(str);
// budget = budget.subtract(new BigDecimal(10));
// if (budget.compareTo(new BigDecimal(0)) <= 0) {
// System.out.println("1");
// } else {
// System.out.println("2");
// }
// System.out.println(budget.doubleValue());
// String str = null;
// BigDecimal budget = new BigDecimal(str);
// budget = budget.subtract(new BigDecimal(10));
// if (budget.compareTo(new BigDecimal(0)) <= 0) {
// System.out.println("1");
// } else {
// System.out.println("2");
// }
// System.out.println(budget.doubleValue());
// String REG_FLOAT = "^[1-9]\\d*.?\\d+$"; // 浮点正数
// System.out.println(Pattern.compile(REG_FLOAT).matcher("1.21").matches());
// String REG_FLOAT = "^[1-9]\\d*.?\\d+$"; // 浮点正数
// System.out.println(Pattern.compile(REG_FLOAT).matcher("1.21").matches());
// String str ="浮点数sss";
// String s1 = new String(str.getBytes("utf-8"),"gbk");
// System.out.println(s1);
// System.out.println(new String(s1.getBytes("gbk")));
// System.out.println();
////
// String s2 = URLEncoder.encode(str, "utf-8");
// System.out.println(s2);
// System.out.println(URLDecoder.decode(s2,"utf-8"));
// String str ="浮点数sss";
// String s1 = new String(str.getBytes("utf-8"),"gbk");
// System.out.println(s1);
// System.out.println(new String(s1.getBytes("gbk")));
// System.out.println();
////
// String s2 = URLEncoder.encode(str, "utf-8");
// System.out.println(s2);
// System.out.println(URLDecoder.decode(s2,"utf-8"));
//System.out.println(new String(Hex.decodeHex("E8AFB7E6B182E5A4B1E8B4A5EFBC8CE8AFB7E7A88DE5908EE9878DE8AF95".toCharArray()), "utf-8"));
// Object object = null;
// JSONObject creativeGroupObj = JSONObject.fromObject(object);
// System.out.println(creativeGroupObj.isEmpty());
//
// System.out.println(UUID.randomUUID().toString());
// Object object = null;
// JSONObject creativeGroupObj = JSONObject.fromObject(object);
// System.out.println(creativeGroupObj.isEmpty());
//
// System.out.println(UUID.randomUUID().toString());
// JSONArray putTime = JSONArray.fromObject("[{\"monday\":[\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"tuesday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"wednesday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"thursday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"friday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"saturday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"sunday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]}]");
// JSONArray periods = new JSONArray();
// for (Object object : putTime) {
// JSONObject putTimeObj = JSONObject.fromObject(object);
// if (!putTimeObj.isEmpty()) {
// Set<String> keySet = putTimeObj.keySet();
// JSONObject period = new JSONObject();
// for (String key : keySet) {
// JSONArray value = putTimeObj.optJSONArray(key);
// int start = -1,end = -1;
// StringBuffer sb = new StringBuffer();
// for (int i = 0; i < value.size(); i++) {
// Object object2 = value.get(i);
// // 第一次出现 1
// if (object2.equals("1") && start==-1) {
// start=i;
// end = 0;
// }
// // 出现1后的第一次出现0结束
// if (object2.equals("0") && start>-1) {
// end=i-1;
// sb.append(start+"-"+end+",");
// start = -1;end = -1;
// }
// }
// period.put("week", key);
// period.put("ranges",sb.toString().substring(0, (sb.length()-1)));
// }
// periods.add(period);
// }
// }
// System.out.println(periods.toString());
// JSONArray putTime = JSONArray.fromObject("[{\"monday\":[\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"tuesday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"wednesday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"thursday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"friday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"saturday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]},{\"sunday\":[\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]}]");
// JSONArray periods = new JSONArray();
// for (Object object : putTime) {
// JSONObject putTimeObj = JSONObject.fromObject(object);
// if (!putTimeObj.isEmpty()) {
// Set<String> keySet = putTimeObj.keySet();
// JSONObject period = new JSONObject();
// for (String key : keySet) {
// JSONArray value = putTimeObj.optJSONArray(key);
// int start = -1,end = -1;
// StringBuffer sb = new StringBuffer();
// for (int i = 0; i < value.size(); i++) {
// Object object2 = value.get(i);
// // 第一次出现 1
// if (object2.equals("1") && start==-1) {
// start=i;
// end = 0;
// }
// // 出现1后的第一次出现0结束
// if (object2.equals("0") && start>-1) {
// end=i-1;
// sb.append(start+"-"+end+",");
// start = -1;end = -1;
// }
// }
// period.put("week", key);
// period.put("ranges",sb.toString().substring(0, (sb.length()-1)));
// }
// periods.add(period);
// }
// }
// System.out.println(periods.toString());
// JSONObject period = new JSONObject();
// period.put("test", 100.32);
// System.out.println(period.optString("test"));
// JSONObject period = new JSONObject();
// period.put("test", 100.32);
// System.out.println(period.optString("test"));
// BigDecimal clicks = new BigDecimal(100.23);
// System.out.println(clicks.intValue());
// BigDecimal clicks = new BigDecimal(100.23);
// System.out.println(clicks.intValue());
// System.out.println(Long.parseLong("8000.01"));
// System.out.println(Long.parseLong("8000.01"));
// JSONObject jsonParam = new JSONObject();
// JSONArray jsonArray = new JSONArray();
// jsonArray.add("000000");
// jsonParam.put("app", jsonArray);
// System.out.println(jsonParam);
// JSONObject jsonParam = new JSONObject();
// JSONArray jsonArray = new JSONArray();
// jsonArray.add("000000");
// jsonParam.put("app", jsonArray);
// System.out.println(jsonParam);
// String head = "00,";
// head = head.substring(0, head.lastIndexOf(","));
// System.out.println(head);
//
// String ip = "127, 0, 0,1";
// // String [] s = ip.split(".");
// String[] s = ip.split("\\,");
// for (String string : s) {
// System.out.println(string);
// }
//
// Object str = null;
//// String dd = (String)str;
// String dd = String.valueOf(str);
// System.out.println(String.valueOf(str) == String.valueOf("null"));
// String head = "00,";
// head = head.substring(0, head.lastIndexOf(","));
// System.out.println(head);
//
// String ip = "127, 0, 0,1";
// // String [] s = ip.split(".");
// String[] s = ip.split("\\,");
// for (String string : s) {
// System.out.println(string);
// }
//
// Object str = null;
//// String dd = (String)str;
// String dd = String.valueOf(str);
// System.out.println(String.valueOf(str) == String.valueOf("null"));
//String sr = "2016-05-25 00:39:33,285 zanadu INFO \"39.159.247.16\" \"Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H321 Safari/600.1.4\" \"http://site.pxene.com/Audi2016Q2Wap/?bid=7ef9ab83e32c4f9c80312b92fba261b1&mapid=0055cb29-dee1-4e77-81bb-0991d2d644c8\" \"load success:Audi load success:bid=7ef9ab83e32c4f9c80312b92fba261b1&mapid=0055cb29-dee1-4e77-81bb-0991d2d644c8\"";
@ -385,9 +381,9 @@ public class TestCode {
Long n = 19000000L;
if ((n >= min && n <= mx)||(n >= min && n <= mx)){
if ((n >= min && n <= mx) || (n >= min && n <= mx)) {
System.out.println("ture");
}else {
} else {
System.out.println("false");
}

View File

@ -1,11 +1,11 @@
package me.ehlxr.test;
public class TestCounter {
public static void main(String[] args) throws Exception {
for (int i = 0; i < 8000; i++) {
new Thread(new TestThread()).start();
// Thread.sleep(5);
}
}
public static void main(String[] args) throws Exception {
for (int i = 0; i < 8000; i++) {
new Thread(new TestThread()).start();
// Thread.sleep(5);
}
}
}

View File

@ -2,6 +2,8 @@ package me.ehlxr.test;
import org.apache.commons.codec.binary.Hex;
import java.nio.charset.StandardCharsets;
/**
* Created by ehlxr on 2016/9/12.
*/
@ -9,7 +11,7 @@ public class TestDecodeHex {
// 十六进制转字符串
public static void main(String[] args) throws Exception {
String data = "E88194E7B3BBE4BABAE6B7BBE58AA0E5A4B1E8B4A5";
System.out.println(new String(Hex.decodeHex(data.toCharArray()), "utf-8"));
System.out.println(new String(Hex.decodeHex(data.toCharArray()), StandardCharsets.UTF_8));
System.out.println(Hex.encodeHexString("测试粗我".getBytes()));

View File

@ -6,32 +6,32 @@ import java.io.FileReader;
import java.io.IOException;
public class TestFile {
public static void main(String[] args) {
File file = new File("C:\\Users\\ehlxr\\Desktop\\20160628\\161845");
BufferedReader reader = null;
try {
public static void main(String[] args) {
File file = new File("C:\\Users\\ehlxr\\Desktop\\20160628\\161845");
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
String[] tempArr = tempString.split("\\|");
long time = Long.parseLong(tempArr[0]);
long rang = 1467100800000L;
if (time < rang) {
System.out.println(tempString);
}
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
reader = new BufferedReader(new FileReader(file));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
String[] tempArr = tempString.split("\\|");
long time = Long.parseLong(tempArr[0]);
long rang = 1467100800000L;
if (time < rang) {
System.out.println(tempString);
}
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
}
}

View File

@ -3,34 +3,34 @@ package me.ehlxr.test;
import me.ehlxr.utils.GeoHash;
public class TestGeoHash {
public static void main(String[] args) {
// double lon1 = 109.014520;
// double lat1 = 34.236080;
//
// double lon2 = 108.9644583556;
// double lat2 = 34.286439088548;
// double dist;
// String geocode;
//
// dist = CommonUtils.getDistance(lon1, lat1, lon2, lat2);
// System.out.println("两点相距:" + dist + " 米");
//
// geocode = GeoHash.encode(lat1, lon1);
// System.out.println("当前位置编码:" + geocode);
//
// geocode = GeoHash.encode(lat2, lon2);
// System.out.println("远方位置编码:" + geocode);
//
// System.out.println(GeoHash.decode("wqjdb8mzw7vspswfydscen0002")[0]+" "+GeoHash.decode("wqjdb8mzw7vspswfydscen0002")[1]);
double lon1 = 112.014520;
double lat1 = 69.236080;
System.out.println(GeoHash.encode(lat1, lon1));
double lat = 34.236088;
double lon = 109.01455;
System.out.println(GeoHash.encode(lat, lon));
}
public static void main(String[] args) {
// double lon1 = 109.014520;
// double lat1 = 34.236080;
//
// double lon2 = 108.9644583556;
// double lat2 = 34.286439088548;
// double dist;
// String geocode;
//
// dist = CommonUtils.getDistance(lon1, lat1, lon2, lat2);
// System.out.println("两点相距:" + dist + " 米");
//
// geocode = GeoHash.encode(lat1, lon1);
// System.out.println("当前位置编码:" + geocode);
//
// geocode = GeoHash.encode(lat2, lon2);
// System.out.println("远方位置编码:" + geocode);
//
// System.out.println(GeoHash.decode("wqjdb8mzw7vspswfydscen0002")[0]+" "+GeoHash.decode("wqjdb8mzw7vspswfydscen0002")[1]);
double lon1 = 112.014520;
double lat1 = 69.236080;
System.out.println(GeoHash.encode(lat1, lon1));
double lat = 34.236088;
double lon = 109.01455;
System.out.println(GeoHash.encode(lat, lon));
}
}

View File

@ -1,92 +1,83 @@
package me.ehlxr.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import me.ehlxr.redis.JedisUtil;
import net.sf.json.JSONObject;
import java.sql.*;
import java.util.Date;
import java.util.*;
public class TestJdbc {
private static Connection getConn() {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.3.11:3306/wins-dsp-new?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&connectTimeout=60000&socketTimeout=60000";
String username = "root";
String password = "pxene";
Connection conn = null;
try {
Class.forName(driver); // classLoader,加载对应驱动
conn = (Connection) DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
private static Connection getConn() {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.3.11:3306/wins-dsp-new?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&connectTimeout=60000&socketTimeout=60000";
String username = "root";
String password = "pxene";
Connection conn = null;
try {
Class.forName(driver); // classLoader,加载对应驱动
conn = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
private static Integer getAll() {
Connection conn = getConn();
String sql = "SELECT v.* FROM dsp_v_app_motionclick_day_count v WHERE v.time BETWEEN 1433088000000 AND 1453046400000 ";
// String sql = "SELECT * FROM dsp_t_ad_group_adx_creative WHERE groupid
// = 'd092c630-abfd-45a1-92f3-d0530c1caee8' LIMIT 1,3;";
PreparedStatement pstmt;
try {
pstmt = (PreparedStatement) conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
ResultSetMetaData metaData = rs.getMetaData();
while (rs.next()) {
JSONObject jsonObject = new JSONObject();
String time = "";
String mapid = "";
String appid = "";
String adxtype = "";
for (int i = 1; i <= metaData.getColumnCount(); i++) {
String columnName = metaData.getColumnName(i);
if ("time".equals(columnName)) {
time = rs.getString(i);
}
if ("mapid".equals(columnName)) {
mapid = rs.getString(i);
}
if ("appid".equals(columnName)) {
appid = rs.getString(i);
}
if ("adxtype".equals(columnName)) {
adxtype = rs.getString(i);
}
private static Integer getAll() {
Connection conn = getConn();
String sql = "SELECT v.* FROM dsp_v_app_motionclick_day_count v WHERE v.time BETWEEN 1433088000000 AND 1453046400000 ";
// String sql = "SELECT * FROM dsp_t_ad_group_adx_creative WHERE groupid
// = 'd092c630-abfd-45a1-92f3-d0530c1caee8' LIMIT 1,3;";
PreparedStatement pstmt;
try {
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
ResultSetMetaData metaData = rs.getMetaData();
while (rs.next()) {
JSONObject jsonObject = new JSONObject();
String time = "";
String mapid = "";
String appid = "";
String adxtype = "";
for (int i = 1; i <= metaData.getColumnCount(); i++) {
String columnName = metaData.getColumnName(i);
if ("time".equals(columnName)) {
time = rs.getString(i);
}
if ("mapid".equals(columnName)) {
mapid = rs.getString(i);
}
if ("appid".equals(columnName)) {
appid = rs.getString(i);
}
if ("adxtype".equals(columnName)) {
adxtype = rs.getString(i);
}
jsonObject.put(columnName, rs.getString(i));
}
Map<String, String> map = new HashMap<>();
map.put(time + "_" + appid + "_" + adxtype, jsonObject.toString());
JedisUtil.hset("HistoryAPPData_" + mapid, map);
jsonObject.put(columnName, rs.getString(i));
}
Map<String, String> map = new HashMap<>();
map.put(time + "_" + appid + "_" + adxtype, jsonObject.toString());
JedisUtil.hset("HistoryAPPData_" + mapid, map);
// JedisUtil.lpush("HistoryAPPData_"+mapid+"_"+time,
// jsonObject.toString());
System.out.println("HistoryAPPData_" + mapid);
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
// JedisUtil.lpush("HistoryAPPData_"+mapid+"_"+time,
// jsonObject.toString());
System.out.println("HistoryAPPData_" + mapid);
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
insertData();
// getAll();
// JedisUtil.deleteByPattern("HistoryAPPData_*");
public static void main(String[] args) {
insertData();
// getAll();
// JedisUtil.deleteByPattern("HistoryAPPData_*");
/*
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date start = new Date();
@ -110,44 +101,44 @@ public class TestJdbc {
System.out.println(sdf.format(start));
System.out.println(sdf.format(end));
*/
}
}
private static List<String> getMapid() {
List<String> mapids = new ArrayList<String>();
Connection conn = getConn();
String sql = "SELECT t2.id AS mapid FROM dsp_t_ad_group_creative t2 LEFT JOIN dsp_t_ad_group t3 ON t2.groupid = t3.id LEFT JOIN dsp_t_campaign t4 ON t3.campaignid = t4.id LEFT JOIN dsp_t_advertiser_account t5 ON t4.accountid = t5.id LEFT JOIN dsp_t_advertiser t6 ON t5.advertiserid = t6.id WHERE ( t4.accountid IN ( SELECT id FROM dsp_t_advertiser_account t6 WHERE t6.advertiserid IN ( SELECT id FROM dsp_t_advertiser t7 WHERE t7.parentid = 'dfecbd8a-2d7e-4941-bd89-e39c576c5ee5' ) ) OR t4.accountid = 'dfecbd8a-2d7e-4941-bd89-e39c576c5ee5' )";
// String sql = "SELECT * FROM dsp_t_ad_group_adx_creative WHERE groupid
// = 'd092c630-abfd-45a1-92f3-d0530c1caee8' LIMIT 1,3;";
PreparedStatement pstmt;
try {
pstmt = (PreparedStatement) conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
ResultSetMetaData metaData = rs.getMetaData();
while (rs.next()) {
for (int i = 1; i <= metaData.getColumnCount(); i++) {
mapids.add(rs.getString(i));
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return mapids;
}
private static List<String> getMapid() {
List<String> mapids = new ArrayList<String>();
Connection conn = getConn();
String sql = "SELECT t2.id AS mapid FROM dsp_t_ad_group_creative t2 LEFT JOIN dsp_t_ad_group t3 ON t2.groupid = t3.id LEFT JOIN dsp_t_campaign t4 ON t3.campaignid = t4.id LEFT JOIN dsp_t_advertiser_account t5 ON t4.accountid = t5.id LEFT JOIN dsp_t_advertiser t6 ON t5.advertiserid = t6.id WHERE ( t4.accountid IN ( SELECT id FROM dsp_t_advertiser_account t6 WHERE t6.advertiserid IN ( SELECT id FROM dsp_t_advertiser t7 WHERE t7.parentid = 'dfecbd8a-2d7e-4941-bd89-e39c576c5ee5' ) ) OR t4.accountid = 'dfecbd8a-2d7e-4941-bd89-e39c576c5ee5' )";
// String sql = "SELECT * FROM dsp_t_ad_group_adx_creative WHERE groupid
// = 'd092c630-abfd-45a1-92f3-d0530c1caee8' LIMIT 1,3;";
PreparedStatement pstmt;
try {
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
ResultSetMetaData metaData = rs.getMetaData();
while (rs.next()) {
for (int i = 1; i <= metaData.getColumnCount(); i++) {
mapids.add(rs.getString(i));
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return mapids;
}
private static void insertData(){
Connection conn = getConn();
System.out.println(new Date());
for (int i = 0; i > -1; i++) {
String cid = UUID.randomUUID().toString();
String sql = "INSERT INTO `dsp_t_statis_by_day` (`time`, `creativeid`, `category`, `imprs`, `clks`, `cost`, `downloads`, `regists`, `flag`, `createtime`) VALUES ('2014-12-06 00:00:00', '"+cid+"', '2', '961', '9', '201860.7000', '0', '0', '0', '2015-09-14 15:07:42');";
PreparedStatement pstmt;
try {
pstmt = (PreparedStatement) conn.prepareStatement(sql);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println(new Date());
}
private static void insertData() {
Connection conn = getConn();
System.out.println(new Date());
for (int i = 0; i > -1; i++) {
String cid = UUID.randomUUID().toString();
String sql = "INSERT INTO `dsp_t_statis_by_day` (`time`, `creativeid`, `category`, `imprs`, `clks`, `cost`, `downloads`, `regists`, `flag`, `createtime`) VALUES ('2014-12-06 00:00:00', '" + cid + "', '2', '961', '9', '201860.7000', '0', '0', '0', '2015-09-14 15:07:42');";
PreparedStatement pstmt;
try {
pstmt = conn.prepareStatement(sql);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println(new Date());
}
}

View File

@ -5,66 +5,65 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;
import java.util.UUID;
public class TestJdbc143 {
private static Connection getConn() {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://111.235.158.31:3306/wins-dsp-new?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&connectTimeout=60000&socketTimeout=60000";
String username = "root";
String password = "pxene";
Connection conn = null;
try {
Class.forName(driver); // classLoader,加载对应驱动
conn = (Connection) DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
private static Connection getConn() {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://111.235.158.31:3306/wins-dsp-new?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&connectTimeout=60000&socketTimeout=60000";
String username = "root";
String password = "pxene";
Connection conn = null;
try {
Class.forName(driver); // classLoader,加载对应驱动
conn = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public static void main(String[] args) {
insertData();
// updateData();
}
public static void main(String[] args) {
insertData();
// updateData();
}
private static void insertData(){
Connection conn = getConn();
System.out.println(new Date());
for (int i = 0; i < 1; i++) {
// String cid = UUID.randomUUID().toString();
String cid = "0123456789";
String sql = "INSERT INTO `dsp_t_statis_by_day` (`time`, `creativeid`, `category`, `imprs`, `clks`, `cost`, `downloads`, `regists`, `flag`, `createtime`) VALUES ('2014-12-06 00:00:00', '"+cid+"', '2', '961', '9', '201860.7000', '0', '0', '0', '2015-09-14 15:07:42');";
PreparedStatement pstmt;
try {
pstmt = (PreparedStatement) conn.prepareStatement(sql);
pstmt.executeUpdate();
if(i%200 == 0){
Thread.sleep(200);
}
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(new Date());
}
private static void updateData(){
Connection conn = getConn();
System.out.println(new Date());
for (int i = 0; i < 800; i++) {
String sql = "UPDATE `dsp_t_statis_by_day` SET `clks`='"+i+"' WHERE `creativeid`='068860ba-2df2-42cb-bf66-f0515c5a83aa'";
PreparedStatement pstmt;
try {
pstmt = (PreparedStatement) conn.prepareStatement(sql);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println(new Date());
}
private static void insertData() {
Connection conn = getConn();
System.out.println(new Date());
for (int i = 0; i < 1; i++) {
// String cid = UUID.randomUUID().toString();
String cid = "0123456789";
String sql = "INSERT INTO `dsp_t_statis_by_day` (`time`, `creativeid`, `category`, `imprs`, `clks`, `cost`, `downloads`, `regists`, `flag`, `createtime`) VALUES ('2014-12-06 00:00:00', '" + cid + "', '2', '961', '9', '201860.7000', '0', '0', '0', '2015-09-14 15:07:42');";
PreparedStatement pstmt;
try {
pstmt = conn.prepareStatement(sql);
pstmt.executeUpdate();
if (i % 200 == 0) {
Thread.sleep(200);
}
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(new Date());
}
private static void updateData() {
Connection conn = getConn();
System.out.println(new Date());
for (int i = 0; i < 800; i++) {
String sql = "UPDATE `dsp_t_statis_by_day` SET `clks`='" + i + "' WHERE `creativeid`='068860ba-2df2-42cb-bf66-f0515c5a83aa'";
PreparedStatement pstmt;
try {
pstmt = conn.prepareStatement(sql);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println(new Date());
}
}

View File

@ -8,61 +8,61 @@ import java.util.Date;
import java.util.UUID;
public class TestJdbc26 {
private static Connection getConn() {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://111.235.158.26:3306/wins-dsp-new?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&connectTimeout=60000&socketTimeout=60000";
String username = "root";
String password = "pxene";
Connection conn = null;
try {
Class.forName(driver); // classLoader,加载对应驱动
conn = (Connection) DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
private static Connection getConn() {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://111.235.158.26:3306/wins-dsp-new?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&connectTimeout=60000&socketTimeout=60000";
String username = "root";
String password = "pxene";
Connection conn = null;
try {
Class.forName(driver); // classLoader,加载对应驱动
conn = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public static void main(String[] args) {
insertData();
// updateData();
}
public static void main(String[] args) {
insertData();
// updateData();
}
private static void insertData(){
Connection conn = getConn();
System.out.println(new Date());
for (int i = 0; i > -1; i++) {
String cid = UUID.randomUUID().toString();
String sql = "INSERT INTO `dsp_t_statis_by_day` (`time`, `creativeid`, `category`, `imprs`, `clks`, `cost`, `downloads`, `regists`, `flag`, `createtime`) VALUES ('2014-12-06 00:00:00', '"+cid+"', '2', '961', '9', '201860.7000', '0', '0', '0', '2015-09-14 15:07:42');";
PreparedStatement pstmt;
try {
pstmt = (PreparedStatement) conn.prepareStatement(sql);
pstmt.executeUpdate();
if(i%200 == 0){
Thread.sleep(200);
}
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(new Date());
}
private static void updateData(){
Connection conn = getConn();
System.out.println(new Date());
for (int i = 0; i < 800; i++) {
String sql = "UPDATE `dsp_t_statis_by_day` SET `clks`='"+i+"' WHERE `creativeid`='068860ba-2df2-42cb-bf66-f0515c5a83aa'";
PreparedStatement pstmt;
try {
pstmt = (PreparedStatement) conn.prepareStatement(sql);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println(new Date());
}
private static void insertData() {
Connection conn = getConn();
System.out.println(new Date());
for (int i = 0; i > -1; i++) {
String cid = UUID.randomUUID().toString();
String sql = "INSERT INTO `dsp_t_statis_by_day` (`time`, `creativeid`, `category`, `imprs`, `clks`, `cost`, `downloads`, `regists`, `flag`, `createtime`) VALUES ('2014-12-06 00:00:00', '" + cid + "', '2', '961', '9', '201860.7000', '0', '0', '0', '2015-09-14 15:07:42');";
PreparedStatement pstmt;
try {
pstmt = conn.prepareStatement(sql);
pstmt.executeUpdate();
if (i % 200 == 0) {
Thread.sleep(200);
}
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(new Date());
}
private static void updateData() {
Connection conn = getConn();
System.out.println(new Date());
for (int i = 0; i < 800; i++) {
String sql = "UPDATE `dsp_t_statis_by_day` SET `clks`='" + i + "' WHERE `creativeid`='068860ba-2df2-42cb-bf66-f0515c5a83aa'";
PreparedStatement pstmt;
try {
pstmt = conn.prepareStatement(sql);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println(new Date());
}
}

View File

@ -11,94 +11,92 @@ import java.util.Map;
public class TestReadFile {
public static void readFile() {
File file = new File("C:/Users/ehlxr/Desktop/IPB.txt");
BufferedReader reader = null;
Map<String, Object> resultMap = null;
List<Long> startList = null;
List<Long> endList = null;
try {
resultMap = new HashMap<String, Object>();
startList = new ArrayList<Long>();
endList = new ArrayList<Long>();
public static void readFile() {
File file = new File("C:/Users/ehlxr/Desktop/IPB.txt");
BufferedReader reader = null;
Map<String, Object> resultMap = null;
List<Long> startList = null;
List<Long> endList = null;
try {
resultMap = new HashMap<String, Object>();
startList = new ArrayList<Long>();
endList = new ArrayList<Long>();
reader = new BufferedReader(new FileReader(file));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
String[] tempArr = tempString.split(" ");
reader = new BufferedReader(new FileReader(file));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
String[] tempArr = tempString.split(" ");
resultMap.put(tempArr[0], tempArr);
startList.add(Long.parseLong(tempArr[0]));
endList.add(Long.parseLong(tempArr[1]));
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
long des = 17301504l;
long key = binarySearch(startList.toArray(new Long[startList.size()]), des);
String[] tempArr = (String[]) resultMap.get(key);
for (int i = 0; i < tempArr.length; i++) {
System.out.println(tempArr[i]);
}
}
resultMap.put(tempArr[0], tempArr);
startList.add(Long.parseLong(tempArr[0]));
endList.add(Long.parseLong(tempArr[1]));
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
public static void readFile1() {
File file = new File("C:\\Users\\ehlxr\\Desktop\\白名单\\IMEI\\000000_0");
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
System.out.println(tempString);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignored) {
}
}
}
}
long des = 17301504l;
long key = binarySearch(startList.toArray(new Long[startList.size()]), des);
String[] tempArr = (String[]) resultMap.get(key);
for (int i = 0; i < tempArr.length; i++) {
System.out.println(tempArr[i]);
}
}
public static void main(String[] args) {
readFile1();
}
public static void readFile1() {
File file = new File("C:\\Users\\ehlxr\\Desktop\\白名单\\IMEI\\000000_0");
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
System.out.println(tempString);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignored) {
}
}
}
}
/**
* * * *
*
* @param srcArray
* *
* @param des
* *
* @return des-1
*/
public static long binarySearch(Long[] srcArray, long des) {
int low = 0;
int high = srcArray.length - 1;
while (low <= high) {
int middle = (low + high) / 2;
if (des == srcArray[middle]) {
return middle;
} else if (des < srcArray[middle]) {
high = middle - 1;
} else {
low = middle + 1;
}
}
return -1;
}
public static void main(String[] args) {
readFile1();
}
/**
* * * *
*
* @param srcArray *
* @param des *
* @return des-1
*/
public static long binarySearch(Long[] srcArray, long des) {
int low = 0;
int high = srcArray.length - 1;
while (low <= high) {
int middle = (low + high) / 2;
if (des == srcArray[middle]) {
return middle;
} else if (des < srcArray[middle]) {
high = middle - 1;
} else {
low = middle + 1;
}
}
return -1;
}
}

View File

@ -1,214 +1,213 @@
package me.ehlxr.test;
import com.caucho.hessian.client.HessianProxyFactory;
import me.ehlxr.readlogs.IReadLogs;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.caucho.hessian.client.HessianProxyFactory;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import me.ehlxr.readlogs.IReadLogs;
public class TestSyncLogData {
public static void main(String[] args) throws Exception {
List<String> mapids = new ArrayList<String>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd_HH");
public static void main(String[] args) throws Exception {
List<String> mapids = new ArrayList<String>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd_HH");
// 测试数据
mapids.add("ad2176a7-74f2-4eab-965f-04c509653a93");
mapids.add("63cae342-3288-4591-8097-53a9ac8bbe48");
mapids.add("b38749f5-d5f9-441f-89de-a97c9b35adb0");
mapids.add("3bc9a763-b5ad-4ade-a46c-12ce6f7a9479");
mapids.add("cf384c11-0b25-4462-80ae-8a7eaedbf765");
mapids.add("e9d823fe-379a-4d86-b9cd-93bb21c085a3");
mapids.add("fa3c7262-4538-4192-bbca-ac1114f690c1");
mapids.add("441af98d-917a-423a-ad3d-6faa8609e722");
mapids.add("60112069-7c05-4135-8430-836ed61576e8");
mapids.add("62367312-d881-426d-81b4-fe635d1db989");
mapids.add("c41c1d40-1f71-44d2-88ab-478a584cd030");
mapids.add("5f9735cf-6036-4902-9cff-5c7a40c76f24");
// 测试数据
mapids.add("ad2176a7-74f2-4eab-965f-04c509653a93");
mapids.add("63cae342-3288-4591-8097-53a9ac8bbe48");
mapids.add("b38749f5-d5f9-441f-89de-a97c9b35adb0");
mapids.add("3bc9a763-b5ad-4ade-a46c-12ce6f7a9479");
mapids.add("cf384c11-0b25-4462-80ae-8a7eaedbf765");
mapids.add("e9d823fe-379a-4d86-b9cd-93bb21c085a3");
mapids.add("fa3c7262-4538-4192-bbca-ac1114f690c1");
mapids.add("441af98d-917a-423a-ad3d-6faa8609e722");
mapids.add("60112069-7c05-4135-8430-836ed61576e8");
mapids.add("62367312-d881-426d-81b4-fe635d1db989");
mapids.add("c41c1d40-1f71-44d2-88ab-478a584cd030");
mapids.add("5f9735cf-6036-4902-9cff-5c7a40c76f24");
Map<String, Double> adxs = new HashMap<>();
adxs.put("15", 1.0000);
adxs.put("14", 1.0000);
adxs.put("2", 1.0000);
adxs.put("8", 1.0000);
adxs.put("11", 1.0000);
adxs.put("1122331", 1.0000);
adxs.put("1", 1.0000);
adxs.put("4", 1.0000);
adxs.put("9", 1.0000);
adxs.put("13", 1.0000);
adxs.put("10", 1.0000);
adxs.put("5", 1.0000);
adxs.put("7", 1.0000);
adxs.put("112233", 1.0000);
adxs.put("3", 0.1569);
Map<String, Double> adxs = new HashMap<>();
adxs.put("15", 1.0000);
adxs.put("14", 1.0000);
adxs.put("2", 1.0000);
adxs.put("8", 1.0000);
adxs.put("11", 1.0000);
adxs.put("1122331", 1.0000);
adxs.put("1", 1.0000);
adxs.put("4", 1.0000);
adxs.put("9", 1.0000);
adxs.put("13", 1.0000);
adxs.put("10", 1.0000);
adxs.put("5", 1.0000);
adxs.put("7", 1.0000);
adxs.put("112233", 1.0000);
adxs.put("3", 0.1569);
HessianProxyFactory factory = new HessianProxyFactory();
IReadLogs readLogs = (IReadLogs) factory.create(IReadLogs.class, "http://localhost:8080/sync-logs/remote/readlogs");
String results = readLogs.readFile(sdf.parse("2016-02-24 09"), sdf.parse("2016-02-24 10"), mapids,
"6692a223-2ae1-439a-93f4-09fb36e718ef",adxs);
System.out.println(results);
JSONArray dataArr = new JSONArray();
dataArr = JSONArray.fromObject(results);
// List<StatisByHourModel> dataList = (List<StatisByHourModel>)
// JSONArray.toCollection(dataArr, StatisByHourModel.class);
HessianProxyFactory factory = new HessianProxyFactory();
IReadLogs readLogs = (IReadLogs) factory.create(IReadLogs.class, "http://localhost:8080/sync-logs/remote/readlogs");
String results = readLogs.readFile(sdf.parse("2016-02-24 09"), sdf.parse("2016-02-24 10"), mapids,
"6692a223-2ae1-439a-93f4-09fb36e718ef", adxs);
System.out.println(results);
JSONArray dataArr = new JSONArray();
dataArr = JSONArray.fromObject(results);
// List<StatisByHourModel> dataList = (List<StatisByHourModel>)
// JSONArray.toCollection(dataArr, StatisByHourModel.class);
// List<Map<String, Object>> result = new ArrayList<Map<String,
// Object>>();
// for (Object object : dataArr) {
// if(object == null) {
// continue;
// }
// JSONObject data = JSONObject.fromObject(object);
// String time = data.optString("time");
// if (result.size() <= 0) {
// Map<String, Object> resultMap = new HashMap<String, Object>();
// resultMap.put("time", time);
// resultMap.put("imprs",data.optInt("imprs"));
// resultMap.put("clks", data.optInt("clks"));
// resultMap.put("cost", data.optDouble("cost"));
//
// result.add(resultMap);
// continue;
// }
// List<Map<String, Object>> temp = new ArrayList<Map<String,
// Object>>();
// for (Map<String, Object> map : result) {
// if (time.equals(map.get("time"))) {
// map.put("imprs",((null == map.get("imprs") ||
// "".equals(map.get("imprs"))) ? 0 :
// Integer.parseInt(map.get("imprs").toString())) +
// data.optInt("imprs"));
// map.put("clks",((null == map.get("clks") ||
// "".equals(map.get("clks"))) ? 0 :
// Integer.parseInt(map.get("clks").toString())) + data.optInt("clks"));
// map.put("cost", ((null == map.get("cost") ||
// "".equals(map.get("cost"))) ? 0 :
// Double.parseDouble(map.get("cost").toString()))+
// data.optDouble("cost"));
// } else {
// Map<String, Object> resultMap = new HashMap<String, Object>();
// resultMap.put("time", time);
// resultMap.put("imprs", data.optInt("imprs"));
// resultMap.put("clks", data.optInt("clks"));
// resultMap.put("cost",data.optInt("cost"));
//
// temp.add(resultMap);
// }
// }
// result.addAll(temp);
// }
// System.out.println(result);
// List<Map<String, Object>> result = new ArrayList<Map<String,
// Object>>();
// for (Object object : dataArr) {
// if(object == null) {
// continue;
// }
// JSONObject data = JSONObject.fromObject(object);
// String time = data.optString("time");
// if (result.size() <= 0) {
// Map<String, Object> resultMap = new HashMap<String, Object>();
// resultMap.put("time", time);
// resultMap.put("imprs",data.optInt("imprs"));
// resultMap.put("clks", data.optInt("clks"));
// resultMap.put("cost", data.optDouble("cost"));
//
// result.add(resultMap);
// continue;
// }
// List<Map<String, Object>> temp = new ArrayList<Map<String,
// Object>>();
// for (Map<String, Object> map : result) {
// if (time.equals(map.get("time"))) {
// map.put("imprs",((null == map.get("imprs") ||
// "".equals(map.get("imprs"))) ? 0 :
// Integer.parseInt(map.get("imprs").toString())) +
// data.optInt("imprs"));
// map.put("clks",((null == map.get("clks") ||
// "".equals(map.get("clks"))) ? 0 :
// Integer.parseInt(map.get("clks").toString())) + data.optInt("clks"));
// map.put("cost", ((null == map.get("cost") ||
// "".equals(map.get("cost"))) ? 0 :
// Double.parseDouble(map.get("cost").toString()))+
// data.optDouble("cost"));
// } else {
// Map<String, Object> resultMap = new HashMap<String, Object>();
// resultMap.put("time", time);
// resultMap.put("imprs", data.optInt("imprs"));
// resultMap.put("clks", data.optInt("clks"));
// resultMap.put("cost",data.optInt("cost"));
//
// temp.add(resultMap);
// }
// }
// result.addAll(temp);
// }
// System.out.println(result);
// JSONArray dataList = new JSONArray();
// dataList.addAll(JSONArray.toCollection(JSONArray.fromObject(results)));
// List<StatisByHourModel> result = (List<StatisByHourModel>)
// JSONArray.toCollection(dataList, StatisByHourModel.class);
// for (StatisByHourModel statisByHourModel : result) {
// if(null==statisByHourModel){
// continue;
// }
// System.out.println(statisByHourModel.getCreativeid());
// }
// JSONArray dataList = new JSONArray();
// dataList.addAll(JSONArray.toCollection(JSONArray.fromObject(results)));
// List<StatisByHourModel> result = (List<StatisByHourModel>)
// JSONArray.toCollection(dataList, StatisByHourModel.class);
// for (StatisByHourModel statisByHourModel : result) {
// if(null==statisByHourModel){
// continue;
// }
// System.out.println(statisByHourModel.getCreativeid());
// }
// dataArr.addAll(JSONArray.toCollection(JSONArray.fromObject(results)));
// List<StatisByHourModel> dataList = (List<StatisByHourModel>)
// JSONArray.toCollection(dataArr, StatisByHourModel.class);
// dataArr.addAll(JSONArray.toCollection(JSONArray.fromObject(results)));
// List<StatisByHourModel> dataList = (List<StatisByHourModel>)
// JSONArray.toCollection(dataArr, StatisByHourModel.class);
// List<StatisByHourModel> result = new ArrayList<StatisByHourModel>();
// Map<String, StatisByHourModel> result = new HashMap<>();
//
// for (StatisByHourModel data : dataList) {
// if(data == null) {
// continue;
// }
// String time = dateToStrLong(data.getTime());
//
// if(result.containsKey(time)){
// StatisByHourModel tempData = result.get(time);
// tempData.setImprs(tempData.getImprs()+data.getImprs());
// tempData.setClks(tempData.getClks()+data.getClks());
// tempData.setCost(tempData.getCost().add(data.getCost()));
// }else{
// result.put(time, data);
// }
// }
// List<StatisByHourModel> result = new ArrayList<StatisByHourModel>();
// Map<String, StatisByHourModel> result = new HashMap<>();
//
// for (StatisByHourModel data : dataList) {
// if(data == null) {
// continue;
// }
// String time = dateToStrLong(data.getTime());
//
// if(result.containsKey(time)){
// StatisByHourModel tempData = result.get(time);
// tempData.setImprs(tempData.getImprs()+data.getImprs());
// tempData.setClks(tempData.getClks()+data.getClks());
// tempData.setCost(tempData.getCost().add(data.getCost()));
// }else{
// result.put(time, data);
// }
// }
// Map<String, Map<String, Object>> resultMap = new HashMap<>();
// for (StatisByHourModel data : dataList) {
// if(data == null) {
// continue;
// }
// Map<String, Object> tData = new HashMap<>();
// tData.put("time", sdf.format(data.getTime()));
// tData.put("imprs", data.getImprs());
// tData.put("clks", data.getClks());
// tData.put("cost", data.getCost());
//
// String time = dateToStrLong(data.getTime());
// if(resultMap.containsKey(time)){
// Map<String, Object> tempData = resultMap.get(time);
// tempData.put("imprs",((null == tempData.get("imprs") ||
// "".equals(tempData.get("imprs"))) ? 0 :
// Integer.parseInt(tempData.get("imprs").toString())) +
// data.getImprs());
// tempData.put("clks",((null == tempData.get("clks") ||
// "".equals(tempData.get("clks"))) ? 0 :
// Integer.parseInt(tempData.get("clks").toString())) + data.getClks());
// tempData.put("cost", ((null == tempData.get("cost") ||
// "".equals(tempData.get("cost"))) ? BigDecimal.ZERO : new
// BigDecimal(tempData.get("cost").toString())).add(data.getCost()));
// }else{
// resultMap.put(time, tData);
// }
// }
//
// List dd = new ArrayList<>();
// for (String key : resultMap.keySet()) {
// dd.add(resultMap.get(key));
// }
// System.out.println(dd);
// Map<String, Map<String, Object>> resultMap = new HashMap<>();
// for (StatisByHourModel data : dataList) {
// if(data == null) {
// continue;
// }
// Map<String, Object> tData = new HashMap<>();
// tData.put("time", sdf.format(data.getTime()));
// tData.put("imprs", data.getImprs());
// tData.put("clks", data.getClks());
// tData.put("cost", data.getCost());
//
// String time = dateToStrLong(data.getTime());
// if(resultMap.containsKey(time)){
// Map<String, Object> tempData = resultMap.get(time);
// tempData.put("imprs",((null == tempData.get("imprs") ||
// "".equals(tempData.get("imprs"))) ? 0 :
// Integer.parseInt(tempData.get("imprs").toString())) +
// data.getImprs());
// tempData.put("clks",((null == tempData.get("clks") ||
// "".equals(tempData.get("clks"))) ? 0 :
// Integer.parseInt(tempData.get("clks").toString())) + data.getClks());
// tempData.put("cost", ((null == tempData.get("cost") ||
// "".equals(tempData.get("cost"))) ? BigDecimal.ZERO : new
// BigDecimal(tempData.get("cost").toString())).add(data.getCost()));
// }else{
// resultMap.put(time, tData);
// }
// }
//
// List dd = new ArrayList<>();
// for (String key : resultMap.keySet()) {
// dd.add(resultMap.get(key));
// }
// System.out.println(dd);
Map<String, JSONObject> resultMap = new HashMap<>();
for (Object object : dataArr) {
try {
if (object == null) {
continue;
}
JSONObject data = JSONObject.fromObject(object);
String time = data.optString("time");
if (resultMap.containsKey(time)) {
JSONObject tempData = resultMap.get(time);
tempData.put("imprs", tempData.optInt("imprs") + data.optInt("imprs"));
tempData.put("clks", tempData.optInt("clks") + data.optInt("clks"));
tempData.put("cost", tempData.optInt("cost") + data.optInt("cost"));
} else {
data.put("time", sdf.format(sdf1.parse(time)));
resultMap.put(time, data);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
Map<String, JSONObject> resultMap = new HashMap<>();
for (Object object : dataArr) {
try {
if (object == null) {
continue;
}
JSONObject data = JSONObject.fromObject(object);
String time = data.optString("time");
if (resultMap.containsKey(time)) {
JSONObject tempData = resultMap.get(time);
tempData.put("imprs", tempData.optInt("imprs") + data.optInt("imprs"));
tempData.put("clks", tempData.optInt("clks") + data.optInt("clks"));
tempData.put("cost", tempData.optInt("cost") + data.optInt("cost"));
} else {
data.put("time", sdf.format(sdf1.parse(time)));
resultMap.put(time, data);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
List dd = new ArrayList<>();
for (String key : resultMap.keySet()) {
dd.add(resultMap.get(key));
}
System.out.println(dd);
List dd = new ArrayList<>();
for (String key : resultMap.keySet()) {
dd.add(resultMap.get(key));
}
System.out.println(dd);
}
}
public static String dateToStrLong(java.util.Date dateDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(dateDate);
return dateString;
}
public static String dateToStrLong(java.util.Date dateDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(dateDate);
return dateString;
}
}

View File

@ -1,49 +1,49 @@
package me.ehlxr.test;
import me.ehlxr.utils.HttpClientUtil;
import java.util.HashMap;
import java.util.Map;
import me.ehlxr.utils.HttpClientUtil;
public class TestThread implements Runnable {
@Override
public void run() {
// HessianProxyFactory factory = new HessianProxyFactory();
// IChargeCounter readLogs;
// for(int i=0;i<5;i++){
// try {
// readLogs = (IChargeCounter) factory.create(IChargeCounter.class, "http://localhost:8080/dsp-counter/remote/chargeCounter");
// readLogs.counterControlForThisSumResult("100003", 1, "m");
// //System.out.println(JedisUtil.getStr("dsp_counter_100003"));
// break;
// } catch (Exception e) {
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e1) {
// e1.printStackTrace();
// }
// }
// }
Map<String, String> postParam = new HashMap<String, String>();
postParam.put("groupid", "100003");
postParam.put("count", "1");
postParam.put("type", "m");
for(int i=0;i<5;i++){
try {
HttpClientUtil.sendPostParam("http://192.168.1.135:8080/dsp-counter/remote/chargeCounter/counterControlForThisSumResult", postParam);
// HttpClientUtil.sendPost("http://192.168.1.135:8080/dsp-counter/remote/chargeCounter/counterControlForThisSumResult", "groupid=100003&count=1&type=m");
break;
} catch (Exception e) {
System.out.println(e.getMessage());
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
@Override
public void run() {
// HessianProxyFactory factory = new HessianProxyFactory();
// IChargeCounter readLogs;
// for(int i=0;i<5;i++){
// try {
// readLogs = (IChargeCounter) factory.create(IChargeCounter.class, "http://localhost:8080/dsp-counter/remote/chargeCounter");
// readLogs.counterControlForThisSumResult("100003", 1, "m");
// //System.out.println(JedisUtil.getStr("dsp_counter_100003"));
// break;
// } catch (Exception e) {
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e1) {
// e1.printStackTrace();
// }
// }
// }
Map<String, String> postParam = new HashMap<String, String>();
postParam.put("groupid", "100003");
postParam.put("count", "1");
postParam.put("type", "m");
for (int i = 0; i < 5; i++) {
try {
HttpClientUtil.sendPostParam("http://192.168.1.135:8080/dsp-counter/remote/chargeCounter/counterControlForThisSumResult", postParam);
// HttpClientUtil.sendPost("http://192.168.1.135:8080/dsp-counter/remote/chargeCounter/counterControlForThisSumResult", "groupid=100003&count=1&type=m");
break;
} catch (Exception e) {
System.out.println(e.getMessage());
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
}

View File

@ -1,127 +0,0 @@
package me.ehlxr.test;
import java.math.BigInteger;
import java.util.Date;
import java.util.Random;
import java.util.zip.CRC32;
/**
* IntelliJ IDEA 14.0.1
*
* @author ehlxr
*
*/
public class keygen {
/**
* @param s
* @param i
* @param bytes
* @return
*/
public static short getCRC(String s, int i, byte bytes[]) {
CRC32 crc32 = new CRC32();
if (s != null) {
for (int j = 0; j < s.length(); j++) {
char c = s.charAt(j);
crc32.update(c);
}
}
crc32.update(i);
crc32.update(i >> 8);
crc32.update(i >> 16);
crc32.update(i >> 24);
for (int k = 0; k < bytes.length - 2; k++) {
byte byte0 = bytes[k];
crc32.update(byte0);
}
return (short) (int) crc32.getValue();
}
/**
* @param biginteger
* @return String
*/
public static String encodeGroups(BigInteger biginteger) {
BigInteger beginner1 = BigInteger.valueOf(0x39aa400L);
StringBuilder sb = new StringBuilder();
for (int i = 0; biginteger.compareTo(BigInteger.ZERO) != 0; i++) {
int j = biginteger.mod(beginner1).intValue();
String s1 = encodeGroup(j);
if (i > 0) {
sb.append("-");
}
sb.append(s1);
biginteger = biginteger.divide(beginner1);
}
return sb.toString();
}
/**
* @param i
* @return
*/
public static String encodeGroup(int i) {
StringBuilder sb = new StringBuilder();
for (int j = 0; j < 5; j++) {
int k = i % 36;
char c;
if (k < 10) {
c = (char) (48 + k);
} else {
c = (char) ((65 + k) - 10);
}
sb.append(c);
i /= 36;
}
return sb.toString();
}
/**
* @param name
* @param days
* @param id
* @param prtype
* @return
*/
public static String MakeKey(String name, int days, int id) {
id %= 100000;
byte bkey[] = new byte[12];
bkey[0] = (byte) 1; // Product type: IntelliJ IDEA is 1
bkey[1] = 14; // version
Date d = new Date();
long ld = (d.getTime() >> 16);
bkey[2] = (byte) (ld & 255);
bkey[3] = (byte) ((ld >> 8) & 255);
bkey[4] = (byte) ((ld >> 16) & 255);
bkey[5] = (byte) ((ld >> 24) & 255);
days &= 0xffff;
bkey[6] = (byte) (days & 255);
bkey[7] = (byte) ((days >> 8) & 255);
bkey[8] = 105;
bkey[9] = -59;
bkey[10] = 0;
bkey[11] = 0;
int w = getCRC(name, id % 100000, bkey);
bkey[10] = (byte) (w & 255);
bkey[11] = (byte) ((w >> 8) & 255);
BigInteger pow = new BigInteger("89126272330128007543578052027888001981", 10);
BigInteger mod = new BigInteger("86f71688cdd2612ca117d1f54bdae029", 16);
BigInteger k0 = new BigInteger(bkey);
BigInteger k1 = k0.modPow(pow, mod);
String s0 = Integer.toString(id);
String sz = "0";
while (s0.length() != 5) {
s0 = sz.concat(s0);
}
s0 = s0.concat("-");
String s1 = encodeGroups(k1);
s0 = s0.concat(s1);
return s0;
}
public static void main(String[] args) {
Random r = new Random();
String userid = "elvin";
System.out.println(userid+":"+MakeKey(userid, 0, r.nextInt(100000)));
}
}

View File

@ -9,22 +9,18 @@ import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.util.encoders.Hex;
/**
* AES encryption and decryption tool.
*
* @author ben
* @creation 2014320
*/
public class AESTool {
private static byte[] initVector = { 0x32, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,
0x38, 0x27, 0x36, 0x35, 0x33, 0x23, 0x32, 0x31 };
public class AESTool {
private static final byte[] initVector = {0x32, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,
0x38, 0x27, 0x36, 0x35, 0x33, 0x23, 0x32, 0x31};
/**
* Encrypt the content with a given key using aes algorithm.
*
*
* @param content
* @param key
* must contain exactly 32 characters
* @param key must contain exactly 32 characters
* @return
* @throws Exception
* @throws Exception
*/
public static String encrypt(String content, String key) throws Exception {
if (key == null) {

View File

@ -77,8 +77,6 @@ import java.util.Arrays;
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @version 2.2
* @author Mikael Grev Date: 2004-aug-02 Time: 11:31:11
*/
public class Base64 {

View File

@ -1,13 +1,12 @@
package me.ehlxr.utils;
/**
* Created by ehlxr on 2017/3/15.
*/
import java.io.File;
import java.io.IOException;
import java.net.URL;
/**
* Created by ehlxr on 2017/3/15.
*/
public class MyUrlDemo {
@ -45,9 +44,9 @@ public class MyUrlDemo {
// 第四种: D:\git\daotie\daotie
System.out.println(System.getProperty("user.dir"));
/*
* C:\Documents and Settings\Administrator\workspace\projectName
*
*/
* C:\Documents and Settings\Administrator\workspace\projectName
*
*/
// 第五种: 获取所有的类路径 包括jar包的路径
System.out.println(System.getProperty("java.class.path"));

View File

@ -1,15 +1,12 @@
###author liuling
###token生成和校验相关配置
[tokenVersion<1>]
[tokenVersion<1>]=
###生成token时的密钥
create_token_key=QJ=*S:y^s0$!@#&*()%xZ~&U8($*_+r?
###自校验时的密钥
check_token_key=QJs#!@%er!#E#$%^%@@!@=**I()^%?
###取MD5加密后的哪几位做为自校验位共计4字节32位。最大数字不能超过16
check=1,4,6,7
[tokenVersion<2>]
[tokenVersion<2>]=
###生成token时的密钥
create_token_key=D#$%^@W#Rj8)@9o%&rgyYL_+!Ldcr5td
###自校验时的密钥