|
|
|
@ -1,139 +0,0 @@
|
|
|
|
|
package Tools.NginxLog;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.dsideal.QingLong.Hk.Bean.HkSubjectBean;
|
|
|
|
|
import com.dsideal.QingLong.Util.CommonUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.IdCardGenerator;
|
|
|
|
|
import com.dsideal.QingLong.Util.PgSqlUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.RsaUtils;
|
|
|
|
|
import com.github.javafaker.Faker;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
|
import com.jfinal.plugin.activerecord.DbKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
|
|
|
|
|
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
|
|
|
|
import net.sf.json.JSONArray;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 此部分功能需要与张永嘉沟通:
|
|
|
|
|
* 1、获取全量数据
|
|
|
|
|
* 2、获取增量数据
|
|
|
|
|
* 此功能应该是以Java Class形式提供,然后用XXL-JOB定时每10分钟同步一次增量数量
|
|
|
|
|
* 全量数据可以手动执行以同步到数据库中。
|
|
|
|
|
*/
|
|
|
|
|
public class FakeDataTestPG {
|
|
|
|
|
public static void Init() {
|
|
|
|
|
PropKit.use("application.properties");
|
|
|
|
|
|
|
|
|
|
HikariCpPlugin hp = CommonUtil.createHikariCpPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim(), PropKit.get("driverClassName"));
|
|
|
|
|
hp.start();
|
|
|
|
|
|
|
|
|
|
ActiveRecordPlugin arp = new ActiveRecordPlugin(hp);
|
|
|
|
|
arp.setDevMode(false);
|
|
|
|
|
arp.setDialect(new PostgreSqlDialect());
|
|
|
|
|
arp.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static JSONArray InitSubject() {
|
|
|
|
|
String sql = "select * from t_hk_subject where b_use=1 order by parent_id,id";
|
|
|
|
|
List<Record> list = Db.find(sql);
|
|
|
|
|
var obj = HkSubjectBean.convertListForTreeTable(list);
|
|
|
|
|
var ja = JSONArray.fromObject(obj).getJSONObject(0).getJSONArray("children");
|
|
|
|
|
return ja;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws SQLException, IllegalAccessException, URISyntaxException {
|
|
|
|
|
Init();
|
|
|
|
|
Faker faker = new Faker(Locale.CHINA);
|
|
|
|
|
PgSqlUtil.Truncate("t_hk_student");
|
|
|
|
|
CommonUtil.log("数据清空成功完成!");
|
|
|
|
|
|
|
|
|
|
Set<String> _set = new HashSet<>();
|
|
|
|
|
var ja = InitSubject();
|
|
|
|
|
|
|
|
|
|
String hk_code = "202309";
|
|
|
|
|
String sql = "insert into t_hk_student(kjh,student_name,pwd,school_name,school_code,hk_code,xb,xjh,sfzh,type_id,jmwz_id,ywj_id,km_json,res_json) " +
|
|
|
|
|
"values(?,?,?,?,?,?,?,?,?,?,?,?,?,'')";
|
|
|
|
|
for (int k = 1; k <= 5100; k++) {
|
|
|
|
|
// 声明数据库连接
|
|
|
|
|
Connection conn = null;
|
|
|
|
|
try {
|
|
|
|
|
conn = DbKit.getConfig().getDataSource().getConnection();
|
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
|
PreparedStatement pstmt = conn.prepareStatement(sql);
|
|
|
|
|
IdCardGenerator id = new IdCardGenerator();
|
|
|
|
|
for (int i = 1; i <= 2000; i++) {
|
|
|
|
|
String student_name = faker.name().fullName();
|
|
|
|
|
pstmt.setString(1, "KJH" + String.format("%07d", (k - 1) * 10000 + i));
|
|
|
|
|
pstmt.setString(2, student_name);
|
|
|
|
|
String idCardNo = id.generate();
|
|
|
|
|
while (idCardNo.length() != 18 || _set.contains(idCardNo)) idCardNo = id.generate();
|
|
|
|
|
_set.add(idCardNo);
|
|
|
|
|
String pwd = RsaUtils.encryptedDataOnJava(idCardNo.substring(12), RsaUtils.PUBLICKEY);
|
|
|
|
|
pstmt.setString(3, pwd);
|
|
|
|
|
pstmt.setString(4, "长春市 > 长春市区 > 长春市第一中学");
|
|
|
|
|
pstmt.setString(5, "0001");
|
|
|
|
|
pstmt.setString(6, hk_code);
|
|
|
|
|
pstmt.setString(7, (i % 2 == 1) ? "男" : "女");
|
|
|
|
|
|
|
|
|
|
pstmt.setString(8, "G" + idCardNo);
|
|
|
|
|
pstmt.setString(9, idCardNo);
|
|
|
|
|
pstmt.setInt(10, i % 2);
|
|
|
|
|
|
|
|
|
|
//随机三种文字
|
|
|
|
|
String wzArray[] = {
|
|
|
|
|
"[{\"wz_id\":1,\"wz_name\":\"汉文\"}]",
|
|
|
|
|
"[{\"wz_id\":1,\"wz_name\":\"汉文\"},{\"wz_id\":2,\"wz_name\":\"朝文\"}]",
|
|
|
|
|
"[{\"wz_id\":1,\"wz_name\":\"汉文\"},{\"wz_id\":3,\"wz_name\":\"蒙文\"}]"
|
|
|
|
|
};
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
int randomNumber = random.nextInt(3);
|
|
|
|
|
pstmt.setString(11, wzArray[randomNumber]);
|
|
|
|
|
|
|
|
|
|
//应届还是往届
|
|
|
|
|
pstmt.setInt(12, i % 2 + 1);
|
|
|
|
|
//var ja2 = JSONArray.fromObject(ja.toString());//复制出来一个
|
|
|
|
|
pstmt.setString(13, ja.toString());
|
|
|
|
|
pstmt.addBatch();
|
|
|
|
|
}
|
|
|
|
|
// 执行批量插入操作
|
|
|
|
|
pstmt.executeBatch();
|
|
|
|
|
conn.commit();
|
|
|
|
|
CommonUtil.log("第" + k + "批次提交成功!");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
CommonUtil.log("事务操作失败");
|
|
|
|
|
System.out.println(e);
|
|
|
|
|
try {
|
|
|
|
|
conn.rollback();
|
|
|
|
|
} catch (SQLException eSql) {
|
|
|
|
|
CommonUtil.log("Connection 回滚失败");
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
if (null != conn) {
|
|
|
|
|
conn.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//回写学生信息,方便测试
|
|
|
|
|
String str = FileUtil.readUtf8String(new File(CommonUtil.getClassPath() + "Student.txt"));
|
|
|
|
|
String[] array = str.split("\r\n");
|
|
|
|
|
sql = "update t_hk_student set student_name=?,sfzh=?,pwd=? where id=?";
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < array.length; i++) {
|
|
|
|
|
String[] b = array[i].split(" ");
|
|
|
|
|
Db.update(sql, b[1], b[2], RsaUtils.encryptedDataOnJava(b[2].substring(12), RsaUtils.PUBLICKEY), b[0]);
|
|
|
|
|
}
|
|
|
|
|
CommonUtil.log("恭喜,所有操作成功完成!");
|
|
|
|
|
}
|
|
|
|
|
}
|