main
黄海 2 years ago
parent a77a7b56b7
commit b5144b64b9

@ -0,0 +1,16 @@
package com.YunXiao;
import com.alibaba.fastjson.JSONObject;
import java.util.Comparator;
public class SortClass implements Comparator {
@Override
public int compare(Object o1, Object o2) {
JSONObject map1 = (JSONObject) o1;
JSONObject map2 = (JSONObject) o2;
//sort字段是集合的排序字段
int flag = map1.get("org_name").toString().compareTo(map2.get("org_name").toString());
return flag;
}
}

@ -1,92 +1,94 @@
package com.YunXiao;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileWriter;
import com.YunXiao.Dict.Const;
import com.YunXiao.Model.BaseModel;
import com.YunXiao.Model.ResourceModel;
import com.YunXiao.Util.SyncUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aspose.words.DocumentBuilder;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Db;
import com.dsideal.QingLong.Util.RedisKit;
import com.jfinal.plugin.activerecord.Record;
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ExecutionException;
import static com.YunXiao.Util.SyncUtil.resourceHandleTool;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Study {
//Model层的实例在此层不允许调用Dao层只能对接Model层
public static BaseModel bm;
//结果
public static Map<String, Integer> res = new HashMap<>();
public static List<JSONObject> jBureauList;
public static BaseModel bm = new BaseModel();
static long start, end;
static boolean logFirst = false;
static String LOG_FILE = null;
static String directoryPath = null;
/**
*
*
* @param msg
*/
public static void log(String msg) {
if (!logFirst) {
// 记录到日志文件
LOG_FILE = SyncUtil.WEBPATH + "/Logs/{start_time}.log";
// 创建 File 对象
File file = new File(LOG_FILE);
// 获取目录部分
directoryPath = file.getParent();
// 判断目录是否存在,如果不存在则创建
File directory = new File(directoryPath);
if (!directory.exists()) {
if (directory.mkdirs()) {
System.out.println(DateTime.now() + " 目录已创建:" + directoryPath);
} else {
System.out.println("创建日志目录失败,请检查!");
System.exit(0);
}
}
LOG_FILE = LOG_FILE.replace("{start_time}", String.valueOf(start));
logFirst = true;
}
System.out.println(DateTime.now() + " " + msg);
FileWriter writer = new FileWriter(LOG_FILE, StandardCharsets.UTF_8);
writer.append(DateTime.now() + " " + msg + "\n");
}
public static String KEY = "TY_BUREAU";
public static void main(String[] args) throws Exception {
//初始化
SyncUtil.init();
// //获取所有机构和学校
// String org_id = Const.CcOrgId;
// JSONArray ja = getChildList(org_id, -1).getJSONArray("result");
// List<JSONObject> jList = new ArrayList<>();
// for (int i = 0; i < ja.size(); i++) {
// jList.add(ja.getJSONObject(i));
// }
// List<JSONObject> j2List = batchBureauList(jList);
// for (JSONObject jo : j2List) {
// System.out.println(jo.getString("area_code"));
// System.out.println(jo.getString("org_id"));
// System.out.println(jo.getString("org_name"));
// System.out.println(jo.getString("org_category_title"));
// System.out.println();
// }
//初始化
bm = new BaseModel();
//删除天喻的所有临时表
SyncUtil.delAllTable();
//获取所有机构+学校
jBureauList = bm.getBureauList();
//可以采用定时获取的办法,防止每次使用时调用太慢
List<JSONObject> list = bm.batchBureauList(jBureauList);
List<JSONObject> list = new ArrayList<>();
if (!RedisKit.Exists(KEY)) {
//获取所有机构+学校
List<JSONObject> jBureauList = bm.getBureauList();
for (JSONObject jo : jBureauList) {
String org_id = jo.getString("org_id");
String org_name = jo.getString("org_name");
JSONObject jo2 = new JSONObject();
jo2.put("org_id", org_id);
jo2.put("org_name", org_name);
list.add(jo2);
}
//缓存到 Redis中有效期12小时
RedisKit.Set(KEY, list.toString());
RedisKit.Expire(KEY, 60 * 60 * 12);
} else {
String json = RedisKit.Get(KEY);
JSONArray ja = JSONArray.parseArray(json);
for (int i = 0; i < ja.size(); i++) list.add(ja.getJSONObject(i));
}
//resultA是拼装好的List集合
SortClass sort = new SortClass();
Collections.sort(list, sort);
System.out.println(list);
//2、获取指定机构学校下的部门信息
// batchOrgList();
//
// //3、获取指定机构学校下的教师信息
// getTeacherList();
//
// //4、获取指定机构学校下的班级
// getClasstList();
//
// //5、获取指定机构学校下的学生信息
// getStudentList();
//
// //处理年级数据
// handleGrade();
// 关闭连接
if (SyncUtil.conn != null && !SyncUtil.conn.isClosed()) SyncUtil.conn.close();
}

@ -16,6 +16,7 @@ import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Mac;
@ -225,6 +226,11 @@ public class SyncUtil {
}
masterArp.setDialect(new PostgreSqlDialect());
masterArp.start();
// 用于缓存模块的redis服务
RedisPlugin redis = new RedisPlugin("Redis", PropKit.get("redis_ip"), PropKit.getInt("redis_port"), 10 * 1000);
//启动redis组件
redis.start();
}
/**

Loading…
Cancel
Save