|
|
|
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 {
|
|
|
|
//DataEase数据库名称
|
|
|
|
public static final String DB_NAME = "dataease";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取当前人员可以看到哪些数据集
|
|
|
|
*
|
|
|
|
* @param identity_id 身份id
|
|
|
|
* @return 数据集列表
|
|
|
|
*/
|
|
|
|
public List<Record> getDataSet(int identity_id) {
|
|
|
|
String sql = "select * from t_dp_dataset where owner_id=? order by dataease_id desc";
|
|
|
|
return Db.find(sql, identity_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取数据集对应的表
|
|
|
|
*
|
|
|
|
* @param dataset_id 数据集id
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<Record> getDataSetTableContent(int dataset_id) {
|
|
|
|
Record record = getTableName(dataset_id);
|
|
|
|
if (record == null) return null;
|
|
|
|
String sql = "select * from `" + record.getStr("table_name") + "`";
|
|
|
|
List<Record> list = Db.use(DB_NAME).find(sql);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据数据集id获取表名
|
|
|
|
*
|
|
|
|
* @param dataset_id 数据集id
|
|
|
|
* @return 表对象
|
|
|
|
*/
|
|
|
|
public 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) {
|
|
|
|
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<Record> list = new ArrayList<>();
|
|
|
|
for (int i = 0; i < ja.size(); i++) {
|
|
|
|
JSONObject jsonObject = ja.getJSONObject(i);
|
|
|
|
//遍历jo的每一个属性
|
|
|
|
// 或者使用keySet和for-each循环遍历
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定大屏中的地图配置信息
|
|
|
|
*
|
|
|
|
* @param bigScreenId 大屏ID
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<Record> getMap(long bigScreenId) {
|
|
|
|
String sql = "select id,custom_attr from dataease.core_chart_view where scene_id=? and type='map'";
|
|
|
|
List<Record> list = Db.find(sql, bigScreenId);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取城市编码
|
|
|
|
*
|
|
|
|
* @param cityName 城市名称
|
|
|
|
* @return 城市编码
|
|
|
|
*/
|
|
|
|
public String getCityCode(String cityName) {
|
|
|
|
String sql = "select area_code from t_city_code where area_name=?";
|
|
|
|
return Db.findFirst(sql, cityName).getStr("area_code");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 修改大屏的城市地图为指定的城市
|
|
|
|
*
|
|
|
|
* @param dataVisualizationName 大屏名称
|
|
|
|
* @param cityName 城市名称
|
|
|
|
*/
|
|
|
|
public void updateCity(String dataVisualizationName, String cityName) {
|
|
|
|
//取出大屏的ID值
|
|
|
|
String sql = "select * from dataease.data_visualization_info where name =?";
|
|
|
|
Record dataVisualizationInfo = Db.findFirst(sql, dataVisualizationName);
|
|
|
|
long bigScreenId = dataVisualizationInfo.getLong("id");
|
|
|
|
// 配置的内容
|
|
|
|
List<Record> list = getMap(bigScreenId);
|
|
|
|
for (Record record : list) {
|
|
|
|
long id = record.getLong("id");
|
|
|
|
com.alibaba.fastjson.JSONObject jo = com.alibaba.fastjson.JSONObject.parseObject(record.getStr("custom_attr"));
|
|
|
|
//获取城市编码
|
|
|
|
String area_code = getCityCode(cityName);
|
|
|
|
//修改城市编码
|
|
|
|
jo.getJSONObject("map").put("id", area_code);
|
|
|
|
jo.getJSONObject("map").put("level", "city");
|
|
|
|
//写到数据库
|
|
|
|
String jsonString = jo.toJSONString();
|
|
|
|
Db.update("update dataease.core_chart_view set custom_attr=? where id=?", jsonString, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|