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.

118 lines
4.0 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
9 months ago
public class DataEaseModel {
9 months ago
//DataEase数据库名称
public static final String DB_NAME = "dataease";
9 months ago
/**
*
*
* @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 dataease_id desc";
9 months ago
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") + "`";
9 months ago
List<Record> list = Db.use(DB_NAME).find(sql);
9 months ago
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
}
9 months ago
/**
* DataEase
*
* @param xzqhId ID
*/
public void updateCity(String xzqhId) {
//取出大屏的ID值
String sql = "select * from dataease.data_visualization_info where name ='黄海测试的市州地图'";
Record dataVisualizationInfo = Db.findFirst(sql);
long bigScreenId = dataVisualizationInfo.getLong("id");
// 配置的内容
sql = "select id,custom_attr from dataease.core_chart_view where scene_id=? and type='map'";
List<Record> list = Db.find(sql, bigScreenId);
for (Record record : list) {
long id = record.getLong("id");
JSONObject jo = JSONObject.fromObject(record.getStr("custom_attr"));
jo.getJSONObject("map").put("id", xzqhId);
System.out.println(jo.getJSONObject("map"));
//回写到数据库
String jsonString = jo.toString();
Db.update("update dataease.core_chart_view set custom_attr=? where id=?", jsonString, id);
}
/**
* json
* https://www.uutils.com/format/json.htm
*
* 20231
* https://blog.csdn.net/isworking/article/details/128630487
*/
}
9 months ago
}