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.
80 lines
2.7 KiB
80 lines
2.7 KiB
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;
|
|
|
|
public class DataEaseModel {
|
|
/**
|
|
* 获取当前人员可以看到哪些数据集
|
|
*
|
|
* @param identity_id 身份id
|
|
* @return 数据集列表
|
|
*/
|
|
public List<com.jfinal.plugin.activerecord.Record> getDataSet(int identity_id) {
|
|
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
|
|
*/
|
|
public List<com.jfinal.plugin.activerecord.Record> getDataSetTableContent(int dataset_id) {
|
|
com.jfinal.plugin.activerecord.Record record = getTableName(dataset_id);
|
|
if (record == null) return null;
|
|
String sql = "select * from dataease.`" + record.getStr("table_name") + "`";
|
|
return Db.find(sql);
|
|
}
|
|
|
|
/**
|
|
* 根据数据集id获取表名
|
|
*
|
|
* @param dataset_id 数据集id
|
|
* @return 表对象
|
|
*/
|
|
public com.jfinal.plugin.activerecord.Record getTableName(int dataset_id) {
|
|
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) {
|
|
|
|
System.out.println(ja);
|
|
String tableName = getTableName(dataset_id).getStr("table_name");
|
|
if (identity_id > 1) {
|
|
String sql = "delete from dataease.`" + tableName + "` where `行政区划`=?";
|
|
Db.update(sql, xmqh);
|
|
} else {
|
|
String sql = "delete from dataease.`" + tableName + "`";
|
|
Db.update(sql);
|
|
}
|
|
List<com.jfinal.plugin.activerecord.Record> list = new ArrayList<>();
|
|
for (int i = 0; i < ja.size(); i++) {
|
|
JSONObject jsonObject = ja.getJSONObject(i);
|
|
//遍历jo的每一个属性
|
|
// 或者使用keySet和for-each循环遍历
|
|
com.jfinal.plugin.activerecord.Record record = new Record();
|
|
for (Object key : jsonObject.keySet()) {
|
|
Object value = jsonObject.get(key);
|
|
if (value.equals("null")) value = null;
|
|
record.set(key.toString(), value);
|
|
}
|
|
list.add(record);
|
|
}
|
|
Db.use("dataease").batchSave(tableName, list, 100);
|
|
}
|
|
}
|