|
|
package com.dsideal.base.DataEase.Util;
|
|
|
|
|
|
import cn.hutool.core.lang.Snowflake;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import com.dsideal.base.DataEase.Model.DataEaseModel;
|
|
|
import com.dsideal.base.Tools.Util.LocalMysqlConnectUtil;
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
public class SyncCityScreenNew {
|
|
|
|
|
|
/*
|
|
|
开启数据库SQL执行日志
|
|
|
SHOW VARIABLES LIKE 'general_log%';
|
|
|
SET GLOBAL general_log = 'ON';
|
|
|
SET GLOBAL general_log = 'OFF';
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
* 利用雪花算法获取唯一ID
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public static long getSnowId() throws InterruptedException {
|
|
|
//雪花算法生成唯一ID
|
|
|
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
|
|
Thread.sleep(2);
|
|
|
return snowflake.nextId();
|
|
|
}
|
|
|
|
|
|
public static DataEaseModel dm = new DataEaseModel();
|
|
|
|
|
|
/**
|
|
|
* @param dataVisualizationName
|
|
|
* @throws InterruptedException
|
|
|
*/
|
|
|
public static void SyncScreen(String dataVisualizationName) throws InterruptedException {
|
|
|
//1、获取母屏数据
|
|
|
String sql = "select * from data_visualization_info where name =?";
|
|
|
Record motherRecord = Db.use(DataEaseModel.DB_NAME).findFirst(sql, dataVisualizationName);
|
|
|
long motherId = motherRecord.getLong("id");
|
|
|
//母屏细节表
|
|
|
sql = "select * from core_chart_view where scene_id=?";
|
|
|
List<Record> motherChartList = Db.use(DataEaseModel.DB_NAME).find(sql, motherId);
|
|
|
|
|
|
//母屏的可视化资源表
|
|
|
sql = "select * from core_opt_recent where resource_id=?";
|
|
|
Record motherOptRecord = Db.use(DataEaseModel.DB_NAME).findFirst(sql, motherId);
|
|
|
|
|
|
//母屏的linkJump
|
|
|
sql = "select * from visualization_link_jump where source_dv_id=?";
|
|
|
List<Record> motherLinkJumpList = Db.use(DataEaseModel.DB_NAME).find(sql, motherId);
|
|
|
|
|
|
|
|
|
//(1)复制大屏
|
|
|
Record cityRecord = new Record().setColumns(motherRecord);//复制record对象
|
|
|
cityRecord.set("name", dataVisualizationName + "_copy");
|
|
|
long bigScreenId = getSnowId();
|
|
|
cityRecord.set("id", bigScreenId);
|
|
|
Db.use(DataEaseModel.DB_NAME).save("data_visualization_info", "id", cityRecord);
|
|
|
Map<Long, Long> mcMap = new HashMap<>();
|
|
|
// (2) 复制大屏的细节表
|
|
|
List<Record> writeList = new ArrayList<>();
|
|
|
for (Record rMotherChart : motherChartList) {
|
|
|
long motherChartId = rMotherChart.getLong("id");
|
|
|
Record rCityChart = new Record().setColumns(rMotherChart);//克隆出来
|
|
|
//修改大屏ID
|
|
|
rCityChart.set("id", getSnowId());
|
|
|
rCityChart.set("scene_id", bigScreenId);
|
|
|
writeList.add(rCityChart);
|
|
|
//保存母屏的组件IDS 与复制品组件IDS之间的对应关系
|
|
|
mcMap.put(motherChartId, rCityChart.getLong("id"));
|
|
|
}
|
|
|
//批量保存
|
|
|
Db.use(DataEaseModel.DB_NAME).batchSave("core_chart_view", writeList, 100);//需要修改
|
|
|
|
|
|
//回头修改一下主表
|
|
|
sql = "select component_data from data_visualization_info where id=?";
|
|
|
Record rChild = Db.use(DataEaseModel.DB_NAME).findFirst(sql, bigScreenId);
|
|
|
String component_data = rChild.getStr("component_data");
|
|
|
//遍历map
|
|
|
for (Map.Entry<Long, Long> entry : mcMap.entrySet()) {
|
|
|
Long key = entry.getKey();
|
|
|
Long value = entry.getValue();
|
|
|
component_data = component_data.replace(key.toString(), value.toString());
|
|
|
}
|
|
|
// 更新回去
|
|
|
sql = "update data_visualization_info set component_data=? where id=?";
|
|
|
Db.use(DataEaseModel.DB_NAME).update(sql, component_data, bigScreenId);
|
|
|
|
|
|
// (5) 插入可视化资源表
|
|
|
Record optRecord = new Record().setColumns(motherOptRecord);
|
|
|
optRecord.set("resource_id", bigScreenId);
|
|
|
optRecord.set("id", getSnowId());
|
|
|
Db.use(DataEaseModel.DB_NAME).save("core_opt_recent", "id", optRecord);
|
|
|
|
|
|
|
|
|
// (6) 插入跳转配置表
|
|
|
for (Record rMotherLinkJump : motherLinkJumpList) {
|
|
|
Record rCityLinkJump = new Record().setColumns(rMotherLinkJump);//克隆出来
|
|
|
rCityLinkJump.set("id", getSnowId());
|
|
|
rCityLinkJump.set("source_dv_id", bigScreenId);
|
|
|
Db.use(DataEaseModel.DB_NAME).save("visualization_link_jump", "id", rCityLinkJump);
|
|
|
}
|
|
|
|
|
|
System.out.println("生成完毕");
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) throws InterruptedException {
|
|
|
LocalMysqlConnectUtil.Init();
|
|
|
//获取数据可视化名称
|
|
|
String dataVisualizationName = "黄海测试的气泡地图";
|
|
|
SyncScreen(dataVisualizationName);
|
|
|
}
|
|
|
}
|