增加测试类
parent
a748c47e88
commit
8bf8e2beaa
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,3 @@
|
|||
package com.ljsd.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.NameValuePair;
|
||||
|
|
|
@ -1,2 +1,245 @@
|
|||
package PACKAGE_NAME;public class JsonExample {
|
||||
import io.netty.handler.codec.http.HttpUtil;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JsonExample {
|
||||
public static void main(String[] args) throws Exception {
|
||||
getForecRank();
|
||||
// String path1 = "D:\\yuenan_data\\1\\";
|
||||
// String path2 = "D:\\yuenan_data\\2\\";
|
||||
// String path3 = "D:\\yuenan_data\\3\\";
|
||||
// genCross(path1,1);
|
||||
// genCross(path2,2);
|
||||
// genCross(path3,3);
|
||||
// String path = "D:\\龙珠\\龙珠序列帧\\";
|
||||
// changeAllNames(path);
|
||||
// File file = new File(path);
|
||||
// Workbook wb = new HSSFWorkbook();
|
||||
// if(file.exists()){
|
||||
// File[] files = file.listFiles();
|
||||
// for (File file1 : files) {
|
||||
// if (file1.isDirectory()) {
|
||||
// continue;
|
||||
// }
|
||||
// int lastIndex = file1.getName().lastIndexOf(".");
|
||||
// String name = file1.getName().substring(0,lastIndex);
|
||||
// FileInputStream fis = new FileInputStream(file1);
|
||||
// InputStreamReader isr = new InputStreamReader(fis);
|
||||
// BufferedReader br = new BufferedReader(isr);
|
||||
// String line;
|
||||
// StringBuffer sb = new StringBuffer();
|
||||
// while ((line = br.readLine()) != null) {
|
||||
// sb.append(line);
|
||||
// }
|
||||
// JSONArray jsonArray = new JSONArray(new JSONTokener(sb.toString()));
|
||||
// Sheet sheet = wb.createSheet(name);
|
||||
// Row titleRow = sheet.createRow(0);
|
||||
// Cell titleCell1 = titleRow.createCell(0);
|
||||
// titleCell1.setCellValue("用户id");
|
||||
// Cell titleCell2 = titleRow.createCell(1);
|
||||
// titleCell2.setCellValue("法宝召唤");
|
||||
// Cell titleCell3 = titleRow.createCell(2);
|
||||
// titleCell3.setCellValue("服务器id");
|
||||
// int serverId = 10000+ Integer.parseInt(name);
|
||||
// // 打印数组中的每个元素(例如,打印出每个对象的某个字段)
|
||||
// for (int i = 0; i < jsonArray.length(); i++) {
|
||||
// int index = i+1;
|
||||
// JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||
// String id = jsonObject.getString("_id");
|
||||
// int num = Integer.parseInt(jsonObject.getString("totalAmount"));
|
||||
// Row row = sheet.createRow(index);
|
||||
// Cell cell1 = row.createCell(0);
|
||||
// cell1.setCellValue(id);
|
||||
// Cell cell2 = row.createCell(1);
|
||||
// cell2.setCellValue(num);
|
||||
// Cell cell3 = row.createCell(2);
|
||||
// cell3.setCellValue(serverId);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// FileOutputStream out = new FileOutputStream("D:\\yuenan_out\\法宝召唤.xls");
|
||||
// wb.write(out);
|
||||
}
|
||||
|
||||
public static void testF5(){
|
||||
String url = "https://ms-test.r2games.com/idip/sfzb/pay/f5Notify";
|
||||
// String response = HttpUtil.getP
|
||||
}
|
||||
|
||||
public static void genCross(String path,int cross) throws Exception {
|
||||
File file = new File(path);
|
||||
String outPath = "D:\\yuenan_out\\" + cross + ".txt";
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(outPath));
|
||||
StringBuffer content = new StringBuffer("");
|
||||
if(file.exists()){
|
||||
File[] files = file.listFiles();
|
||||
for (File file1 : files) {
|
||||
if (file1.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
FileInputStream fis = new FileInputStream(file1);
|
||||
InputStreamReader isr = new InputStreamReader(fis);
|
||||
BufferedReader br = new BufferedReader(isr);
|
||||
String line;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
JSONArray jsonArray = new JSONArray(new JSONTokener(sb.toString()));
|
||||
// 打印数组中的每个元素(例如,打印出每个对象的某个字段)
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
int index = i+1;
|
||||
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||
String id = jsonObject.getString("_id");
|
||||
int num = Integer.parseInt(jsonObject.getString("totalAmount"));
|
||||
content.append("\"ZINCRBY CROSS_FABAO_RANK:"+cross +": ").append(num).append(" ").append(id).append("\"\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
bufferedWriter.write(content.toString());
|
||||
bufferedWriter.close();
|
||||
}
|
||||
|
||||
public static void changeAllNames(String path) throws Exception {
|
||||
File folder = new File(path);
|
||||
File[] files = folder.listFiles();
|
||||
// changeFileName(files);
|
||||
changeFileName2(folder,files);
|
||||
}
|
||||
|
||||
public static void changeFileName( File[] files){
|
||||
for(int i = 0; i < files.length; i++){
|
||||
File file = files[i];
|
||||
// 检查是否为文件
|
||||
if (file.isFile()) {
|
||||
// 获取文件名
|
||||
String fileName = file.getName();
|
||||
int index = fileName.lastIndexOf("】");
|
||||
if(index!= -1){
|
||||
String newName = fileName.substring(index+1);
|
||||
String path = file.getParent();
|
||||
// System.out.println("---------" + path);
|
||||
File newFile = new File(path + File.separator + newName);
|
||||
file.renameTo(newFile);
|
||||
// System.out.println("---------" + newName);
|
||||
}
|
||||
}else{
|
||||
changeFileName(file.listFiles());
|
||||
//子文件都修改完,再修改文件夹的名称
|
||||
String fileName = file.getName();
|
||||
int index = fileName.lastIndexOf("【");
|
||||
if(index!= -1){
|
||||
String newName = fileName.substring(0,index);
|
||||
String path = file.getParent();
|
||||
File newFile = new File(path + File.separator + newName);
|
||||
file.renameTo(newFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改父文件夹名称
|
||||
* @param parentFile
|
||||
* @param files
|
||||
*/
|
||||
public static void changeFileName2( File parentFile,File[] files){
|
||||
for(int i = 0; i < files.length; i++){
|
||||
File file = files[i];
|
||||
// 检查是否为文件
|
||||
if (file.isFile()) {
|
||||
// 获取文件名
|
||||
String fileName = file.getName();
|
||||
int index = fileName.lastIndexOf("-idle");
|
||||
if(index == -1){
|
||||
index = fileName.lastIndexOf("-stand");
|
||||
}
|
||||
if(index!= -1){
|
||||
String newName = fileName.substring(0,index) + "_立绘";
|
||||
String path = parentFile.getParent();
|
||||
System.out.println(file.getParent() + "---------" + path + File.separator + newName);
|
||||
File newFile = new File(path + File.separator + newName);
|
||||
parentFile.renameTo(newFile);
|
||||
//修改过就直接跳出循环
|
||||
break;
|
||||
}else{
|
||||
index = fileName.lastIndexOf("-");
|
||||
String newName = fileName.substring(0,index) + "_小人";
|
||||
String path = parentFile.getParent();
|
||||
File newFile = new File(path + File.separator + newName);
|
||||
parentFile.renameTo(newFile);
|
||||
System.out.println(file.getParent() + "---------" + path + File.separator + newName);
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
//是文件夹继续遍历子文件
|
||||
changeFileName2(file,file.listFiles());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void getForecRank() throws Exception {
|
||||
String url = "http://47.236.255.71:8888/gamotaGetForceRank";
|
||||
int limit = 10;
|
||||
String hash = "test";
|
||||
List<com.alibaba.fastjson.JSONArray> list = new ArrayList<>();
|
||||
for(int i=1;i<=53;i++){
|
||||
int serverId = 10000 + i;
|
||||
String req = url + "?server_id=" + serverId + "&limit=" + limit + "&hash=" + hash;
|
||||
String resp = HttpUtils.httpGetRequest(req);
|
||||
com.alibaba.fastjson.JSONObject jobj = com.alibaba.fastjson.JSONObject.parseObject(resp);
|
||||
com.alibaba.fastjson.JSONArray arr = jobj.getJSONArray("data");
|
||||
if(arr!=null){
|
||||
list.add(arr);
|
||||
}
|
||||
}
|
||||
genExcel(list);
|
||||
}
|
||||
|
||||
public static void genExcel(List<com.alibaba.fastjson.JSONArray> list) throws Exception {
|
||||
Workbook wb = new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("战力排行");
|
||||
Row titleRow = sheet.createRow(0);
|
||||
Cell titleCell1 = titleRow.createCell(0);
|
||||
titleCell1.setCellValue("用户id");
|
||||
Cell titleCell2 = titleRow.createCell(1);
|
||||
titleCell2.setCellValue("战力");
|
||||
Cell titleCell3 = titleRow.createCell(2);
|
||||
titleCell3.setCellValue("服务器id");
|
||||
// 打印数组中的每个元素(例如,打印出每个对象的某个字段)
|
||||
int index = 1;
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
com.alibaba.fastjson.JSONArray arr = list.get(j);
|
||||
if(arr != null && arr.size() > 0){
|
||||
for(int i=0;i<arr.size();i++){
|
||||
com.alibaba.fastjson.JSONObject jsonObject = arr.getJSONObject(i);
|
||||
String uid = jsonObject.getString("role_id");
|
||||
String power = jsonObject.getString("power");
|
||||
String serverId = jsonObject.getString("server_id");
|
||||
Row row = sheet.createRow(index);
|
||||
Cell cell1 = row.createCell(0);
|
||||
cell1.setCellValue(uid);
|
||||
Cell cell2 = row.createCell(1);
|
||||
cell2.setCellValue(power);
|
||||
Cell cell3 = row.createCell(2);
|
||||
cell3.setCellValue(serverId);
|
||||
index ++;
|
||||
}
|
||||
}
|
||||
index ++;
|
||||
}
|
||||
FileOutputStream out = new FileOutputStream("D:\\yuenan_out\\战力.xls");
|
||||
wb.write(out);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue