You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.6 KiB

9 months ago
package com.dsideal.base.DataEase.Model;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
9 months ago
import static com.dsideal.base.Tools.InitDataEaseDataSet.DB_NAME;
9 months ago
public class DataEaseModel {
/**
*
*
* @param identity_id id
* @return
*/
9 months ago
public List<Record> getDataSet(int identity_id) {
9 months ago
String sql = "select * from t_dp_dataset where owner_id=? order by dataset_name";
return Db.find(sql, identity_id);
}
/**
*
*
* @param dataset_id id
* @return
*/
9 months ago
public List<Record> getDataSetTableContent(int dataset_id) {
Record record = getTableName(dataset_id);
9 months ago
if (record == null) return null;
9 months ago
String sql = "select * from `" + record.getStr("table_name") + "`";
List<Record> list=Db.use(DB_NAME).find(sql);
return list;
9 months ago
}
/**
* id
*
* @param dataset_id id
* @return
*/
9 months ago
public Record getTableName(int dataset_id) {
9 months ago
String sql = "select * from t_dp_dataset where id=?";
return Db.findFirst(sql, dataset_id);
}
/**
*
*
* @param dataset_id id
* @param ja json
*/
public void saveDataSetTable(int identity_id, int dataset_id, String xmqh, JSONArray ja) {
9 months ago
System.out.println(ja);
9 months ago
String tableName = getTableName(dataset_id).getStr("table_name");
if (identity_id > 1) {
String sql = "delete from dataease.`" + tableName + "` where `行政区划`=?";
Db.update(sql, xmqh);
9 months ago
} else {
String sql = "delete from dataease.`" + tableName + "`";
Db.update(sql);
9 months ago
}
9 months ago
List<Record> list = new ArrayList<>();
9 months ago
for (int i = 0; i < ja.size(); i++) {
JSONObject jsonObject = ja.getJSONObject(i);
//遍历jo的每一个属性
// 或者使用keySet和for-each循环遍历
9 months ago
Record record = new Record();
9 months ago
for (Object key : jsonObject.keySet()) {
Object value = jsonObject.get(key);
9 months ago
if (value.equals("null")) value = null;
9 months ago
record.set(key.toString(), value);
}
9 months ago
list.add(record);
9 months ago
}
9 months ago
Db.use("dataease").batchSave(tableName, list, 100);
9 months ago
}
}