|
|
|
@ -0,0 +1,227 @@
|
|
|
|
|
package com.dsideal.base.DataEase.Util;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.dsideal.base.DataEase.Model.DataEaseModel;
|
|
|
|
|
import com.dsideal.base.Tools.Util.LocalMysqlConnectUtil;
|
|
|
|
|
import com.dsideal.base.Util.CommonUtil;
|
|
|
|
|
import com.dsideal.base.Util.FileUtil;
|
|
|
|
|
import com.jfinal.kit.PathKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import static com.dsideal.base.DataEase.Model.DataEaseModel.DB_NAME;
|
|
|
|
|
|
|
|
|
|
public class CopyOuterParamsScreenToFilterScreen {
|
|
|
|
|
//DataEase部署的地址
|
|
|
|
|
public static String urlPrefix = "http://10.10.14.203";
|
|
|
|
|
|
|
|
|
|
public static DataEaseModel dm = new DataEaseModel();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取DataEase的Token
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String getToken() {
|
|
|
|
|
//读取Data目录下DataEaseLogin.json文件
|
|
|
|
|
JSONObject jo = FileUtil.readJsonFile(PathKit.getRootClassPath() + "/Data/DataEaseLogin.json");
|
|
|
|
|
String url = urlPrefix + "/de2api/login/localLogin";
|
|
|
|
|
String res = HttpUtil.createPost(url).contentType("application/json").body(jo.toString()).execute().body();
|
|
|
|
|
return JSONObject.parseObject(res).getJSONObject("data").getString("token");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 清理指定名称大屏的所有副本,为了再次生成不重复
|
|
|
|
|
*
|
|
|
|
|
* @param bigScreenName 大屏名称
|
|
|
|
|
*/
|
|
|
|
|
public static void clearScreen(String bigScreenName) {
|
|
|
|
|
//一、先删除后插入保持健康
|
|
|
|
|
// 保留:【云南省教育决策支持系统【市州拷贝】】,删除掉云南省教育决策支持系统【市州拷贝】+昆明市,云南省教育决策支持系统【市州】+楚雄州等数据
|
|
|
|
|
String sql = "select * from data_visualization_info where name like '%" + bigScreenName + "%' and name <>'" + bigScreenName + "'";
|
|
|
|
|
List<Record> toDelList = Db.use(DB_NAME).find(sql);
|
|
|
|
|
for (Record record : toDelList) {
|
|
|
|
|
long id = record.getLong("id");
|
|
|
|
|
//(1) 删除关联的表core_chart_view
|
|
|
|
|
sql = "delete from core_chart_view where scene_id=?";
|
|
|
|
|
Db.use(DB_NAME).update(sql, id);
|
|
|
|
|
//(2) 删除共享链接表
|
|
|
|
|
sql = "delete from xpack_share where resource_id=?";
|
|
|
|
|
Db.use(DB_NAME).update(sql, id);
|
|
|
|
|
//(3) 删除可视化资源表
|
|
|
|
|
sql = "delete from core_opt_recent where resource_id=?";
|
|
|
|
|
Db.use(DB_NAME).update(sql, id);
|
|
|
|
|
// (4) 跳转记录表
|
|
|
|
|
sql = "delete from visualization_link_jump where source_dv_id=?";
|
|
|
|
|
Db.use(DB_NAME).update(sql, id);
|
|
|
|
|
// (5) 跳转配置表
|
|
|
|
|
sql = "select * from visualization_link_jump_info where target_dv_id=?";
|
|
|
|
|
List<Record> jumpList = Db.use(DB_NAME).find(sql, id);
|
|
|
|
|
for (Record r : jumpList) {
|
|
|
|
|
long jumpId = r.getLong("id");
|
|
|
|
|
sql = "delete from visualization_link_jump_target_view_info where link_jump_info_id =?";
|
|
|
|
|
Db.use(DB_NAME).update(sql, jumpId);
|
|
|
|
|
sql = "delete from visualization_link_jump_info where id=?";
|
|
|
|
|
Db.use(DB_NAME).update(sql, jumpId);
|
|
|
|
|
}
|
|
|
|
|
//(7) 删除主表数据
|
|
|
|
|
Db.use(DB_NAME).deleteById("data_visualization_info", id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取指定大屏的信息
|
|
|
|
|
*
|
|
|
|
|
* @param dataVisualizationNameCity
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static Record getVisualizationByName(String dataVisualizationNameCity) {
|
|
|
|
|
String sql = "select * from data_visualization_info where name =?";
|
|
|
|
|
return Db.use(DataEaseModel.DB_NAME).findFirst(sql, dataVisualizationNameCity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 调用API拷贝大屏
|
|
|
|
|
*
|
|
|
|
|
* @param screenName 目标大屏名称
|
|
|
|
|
* @param id 源大屏ID
|
|
|
|
|
* @param pid 源大屏所属文件夹id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static long callApiToCopy(String screenName, long id, long pid) throws InterruptedException {
|
|
|
|
|
//拷贝API
|
|
|
|
|
String url = urlPrefix + "/de2api/dataVisualization/copy";
|
|
|
|
|
JSONObject jo = new JSONObject();
|
|
|
|
|
jo.put("nodeType", "leaf");
|
|
|
|
|
jo.put("name", screenName);
|
|
|
|
|
jo.put("type", "dataV");
|
|
|
|
|
jo.put("id", id);
|
|
|
|
|
jo.put("pid", pid);
|
|
|
|
|
String res = HttpUtil.createPost(url).contentType("application/json")
|
|
|
|
|
.header("x-de-token", getToken()).body(jo.toString()).execute().body();
|
|
|
|
|
Thread.sleep(1500);
|
|
|
|
|
long childId = Long.parseLong(JSONObject.parseObject(res).getString("data"));
|
|
|
|
|
|
|
|
|
|
//更新pid,没有这步的话,在界面上看不到拷贝出来的大屏!
|
|
|
|
|
String sql = "update data_visualization_info set pid=? where id=?";
|
|
|
|
|
Db.use(DB_NAME).update(sql, pid, childId);
|
|
|
|
|
return childId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 拷贝城市大屏
|
|
|
|
|
*
|
|
|
|
|
* @param dataVisualizationNameCity
|
|
|
|
|
*/
|
|
|
|
|
public static void copyOuterParamsScreenToFilterScreen(String dataVisualizationNameCity) throws InterruptedException {
|
|
|
|
|
//母屏信息
|
|
|
|
|
Record motherRecord = getVisualizationByName(dataVisualizationNameCity);
|
|
|
|
|
long motherId = motherRecord.getLong("id");//母屏ID
|
|
|
|
|
long pid = motherRecord.getLong("pid"); //隶属文件夹
|
|
|
|
|
|
|
|
|
|
//母屏共享链接
|
|
|
|
|
String sql = "select * from xpack_share where resource_id=?";
|
|
|
|
|
Record motherShareRecord = Db.use(DataEaseModel.DB_NAME).findFirst(sql, motherId);
|
|
|
|
|
|
|
|
|
|
String cityName = "昆明市";
|
|
|
|
|
|
|
|
|
|
String screenName = LocalMysqlConnectUtil.PropKit.get("dataEase.dataVisualizationNameCity");//要拷贝出来的屏幕名称
|
|
|
|
|
long childId = callApiToCopy(screenName, motherId, pid);
|
|
|
|
|
|
|
|
|
|
// 修改地图中城市
|
|
|
|
|
List<Record> listMap = dm.getMap(childId);
|
|
|
|
|
//获取城市编码
|
|
|
|
|
String area_code = dm.getCityCode(cityName);
|
|
|
|
|
//core_chart_view表
|
|
|
|
|
for (Record record : listMap) {
|
|
|
|
|
long id = record.getLong("id");
|
|
|
|
|
JSONObject jo = JSONObject.parseObject(record.getStr("custom_attr"));
|
|
|
|
|
//修改城市编码
|
|
|
|
|
jo.getJSONObject("map").put("id", area_code);
|
|
|
|
|
jo.getJSONObject("map").put("level", "city");
|
|
|
|
|
//写到数据库
|
|
|
|
|
String jsonString = jo.toString();
|
|
|
|
|
Db.use(DB_NAME).update("update core_chart_view set custom_attr=? where id=?", jsonString, id);
|
|
|
|
|
}
|
|
|
|
|
//更改过滤器
|
|
|
|
|
sql = "select * from core_chart_view where scene_id=?";
|
|
|
|
|
List<Record> list = Db.use(DB_NAME).find(sql, childId);
|
|
|
|
|
String custom_filter_json = cn.hutool.core.io.FileUtil.readUtf8String(PathKit.getRootClassPath() + "/Data/filter.json");
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
long id = record.getLong("id");
|
|
|
|
|
String custom_filter = record.getStr("custom_filter");
|
|
|
|
|
JSONObject jo = JSONObject.parseObject(custom_filter);
|
|
|
|
|
if (jo.getJSONArray("items") == null) {
|
|
|
|
|
jo.put("items", JSONArray.parseArray(custom_filter_json));
|
|
|
|
|
} else {
|
|
|
|
|
jo.getJSONArray("items").add(JSONObject.parseObject(custom_filter_json));
|
|
|
|
|
}
|
|
|
|
|
sql = "update core_chart_view set custom_filter=? where id=?";
|
|
|
|
|
Db.use(DB_NAME).update(sql, jo.toString(), id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sql = "update core_chart_view set custom_filter=replace(custom_filter,'昆明市','" + cityName + "') where scene_id=?";
|
|
|
|
|
Db.use(DB_NAME).update(sql, childId);
|
|
|
|
|
|
|
|
|
|
//发布共享链接
|
|
|
|
|
publishShare(motherShareRecord, childId);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发布共享链接
|
|
|
|
|
*
|
|
|
|
|
* @param motherShareRecord
|
|
|
|
|
* @param childId
|
|
|
|
|
*/
|
|
|
|
|
public static void publishShare(Record motherShareRecord, long childId) {
|
|
|
|
|
//发布共享链接
|
|
|
|
|
Record shareRecord = new Record().setColumns(motherShareRecord);
|
|
|
|
|
shareRecord.set("resource_id", childId);
|
|
|
|
|
shareRecord.set("id", CommonUtil.getSnowId());
|
|
|
|
|
shareRecord.set("uuid", CommonUtil.randomString(8));//大小写字母和数字组合,长度为8
|
|
|
|
|
Db.use(DataEaseModel.DB_NAME).save("xpack_share", "id", shareRecord);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取城市的共享链接
|
|
|
|
|
*
|
|
|
|
|
* @param dataVisualizationName
|
|
|
|
|
* @param cityName
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String getCityShare(String dataVisualizationName, String cityName) {
|
|
|
|
|
String screenName = dataVisualizationName + cityName;
|
|
|
|
|
String sql = "select * from data_visualization_info where name =?";
|
|
|
|
|
Record record = Db.use(DataEaseModel.DB_NAME).findFirst(sql, screenName);
|
|
|
|
|
long id = record.getLong("id");
|
|
|
|
|
sql = "select * from xpack_share where resource_id=?";
|
|
|
|
|
Record shareRecord = Db.use(DataEaseModel.DB_NAME).findFirst(sql, id);
|
|
|
|
|
System.out.println(cityName + "的共享链接:" + shareRecord.getStr("uuid"));
|
|
|
|
|
return shareRecord.getStr("uuid");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws InterruptedException {
|
|
|
|
|
//连接本地数据库系统
|
|
|
|
|
LocalMysqlConnectUtil.Init();
|
|
|
|
|
|
|
|
|
|
//清理掉旧的数据
|
|
|
|
|
String dataVisualizationNameCity = LocalMysqlConnectUtil.PropKit.get("dataEase.dataVisualizationNameCity");
|
|
|
|
|
//清理掉旧的数据
|
|
|
|
|
clearScreen(dataVisualizationNameCity);
|
|
|
|
|
|
|
|
|
|
//获取市州级外链参数大屏名称
|
|
|
|
|
String dataVisualizationOuterParamsNameCity = LocalMysqlConnectUtil.PropKit.get("dataEase.dataVisualizationOuterParamsNameCity");
|
|
|
|
|
|
|
|
|
|
//拷贝外部参数大屏到过滤器大屏
|
|
|
|
|
copyOuterParamsScreenToFilterScreen(dataVisualizationOuterParamsNameCity);
|
|
|
|
|
|
|
|
|
|
System.out.println("过滤器大屏拷贝完成!");
|
|
|
|
|
}
|
|
|
|
|
}
|