main
黄海 2 years ago
parent 844b1bf2d9
commit a83e1b417e

@ -1,29 +0,0 @@
package UnitTest;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.QingLong.Util.SimilarayUtil;
import java.text.ParseException;
public class XiangSiDu {
public static void main(String[] args) throws ParseException {
//测试用例1
//String str = "长春市第103中学";
//String[] array = {"长春市第102中学", "长春市第104中学", "长春第一零三中学"};
//测试用例2
//String str = "公主岭三中";
//String[] array = {"长春市第102中学", "公主岭市第三中学校", "长春市希望高中"};
//测试用例3
String str = "希望高中";
String[] array = {"长春市第102中学", "公主岭市第三中学校", "长春市希望高级中学","长春市希望学校"};
JSONObject jo = SimilarayUtil.Get(str, array);
int idx = jo.getInteger("idx");
String name = array[idx];
double similary = jo.getDouble("similary");
System.out.println("系统推荐:" + name + ",索引号:" + idx + ",相似度:" + similary);
}
}

@ -8,6 +8,8 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.QingLong.Util.RedisKit;
import com.dsideal.QingLong.Util.SimilarayUtil;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.io.File;
@ -21,7 +23,7 @@ public class Study {
public static BaseModel bm = new BaseModel();
static long start, end;
static long start;
static boolean logFirst = false;
static String LOG_FILE = null;
static String directoryPath = null;
@ -64,7 +66,7 @@ public class Study {
SyncUtil.init();
//从天喻获取所有单位名单
List<JSONObject> list = new ArrayList<>();
List<JSONObject> tyList = new ArrayList<>();
if (!RedisKit.Exists(KEY)) {
//获取所有机构+学校
List<JSONObject> jBureauList = bm.getBureauList();
@ -74,21 +76,43 @@ public class Study {
JSONObject jo2 = new JSONObject();
jo2.put("org_id", org_id);
jo2.put("org_name", org_name);
list.add(jo2);
tyList.add(jo2);
}
//缓存到 Redis中有效期12小时
RedisKit.Set(KEY, list.toString());
RedisKit.Set(KEY, tyList.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));
for (int i = 0; i < ja.size(); i++) tyList.add(ja.getJSONObject(i));
}
//resultA是拼装好的List集合
SortClass sort = new SortClass();
Collections.sort(list, sort);
System.out.println(list);
String[] array = new String[tyList.size()];
for (int i = 0; i < tyList.size(); i++) {
array[i] = tyList.get(i).getString("org_name");
}
//我们系统中的单位名称
String sql = "select org_id,org_name from t_base_organization where bureau_id=org_id and is_virtual=0 and third_party_id is null";
List<Record> ourList = Db.find(sql);
for (Record record : ourList) {
String org_name = record.getStr("org_name");
String org_id = record.getStr("org_id");
JSONObject jo = SimilarayUtil.Get(org_name, array);
int idx = jo.getInteger("idx");
String ty_org_name = array[idx];
double similary = jo.getDouble("similary");
String ty_org_id = tyList.get(idx).getString("org_id");
if (Math.abs(similary - 1.0) < 0.0001) {
sql = "update t_base_organization set third_party_id=? where org_id=?";
Db.update(sql, ty_org_id, org_id);
} else {
System.out.println("QingLong系统 org_id:" + org_id + ",org_name" + org_name + "\n天喻平台 ty_org_id:" + ty_org_id + ",ty_org_name" + ty_org_name );
System.out.println("相似度:" + similary);
System.out.println();
}
}
// 关闭连接
if (SyncUtil.conn != null && !SyncUtil.conn.isClosed()) SyncUtil.conn.close();
}

Loading…
Cancel
Save