|
|
|
@ -0,0 +1,119 @@
|
|
|
|
|
package com.dsideal.base.Test;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Snowflake;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import com.dsideal.base.BaseApplication;
|
|
|
|
|
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 net.sf.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
public class CityScreenCopy {
|
|
|
|
|
//获取数据可视化名称
|
|
|
|
|
public static String dataVisualizationName = BaseApplication.PropKit.get("dataEase.dataVisualizationName");
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 利用雪花算法获取唯一ID
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static long getSnowId() {
|
|
|
|
|
//雪花算法生成唯一ID
|
|
|
|
|
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
|
|
|
|
return snowflake.nextId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成随机字符串
|
|
|
|
|
* @param len
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
static String randomString(int len) {
|
|
|
|
|
String alphabetsInUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
|
String alphabetsInLowerCase = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
String numbers = "0123456789";
|
|
|
|
|
String allCharacters = alphabetsInLowerCase + alphabetsInUpperCase + numbers;
|
|
|
|
|
StringBuilder randomString = new StringBuilder();
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
|
int randomIndex = random.nextInt(allCharacters.length());
|
|
|
|
|
randomString.append(allCharacters.charAt(randomIndex));
|
|
|
|
|
}
|
|
|
|
|
return randomString.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
LocalMysqlConnectUtil.Init();
|
|
|
|
|
//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 xpack_share WHERE resource_id=?";
|
|
|
|
|
Record motherShareRecord = Db.use(DataEaseModel.DB_NAME).findFirst(sql, motherId);
|
|
|
|
|
|
|
|
|
|
//2、需要生成16个城市,这16个城市是哪些
|
|
|
|
|
DataEaseModel dm = new DataEaseModel();
|
|
|
|
|
List<String> cityNameList = dm.getCityNameList();
|
|
|
|
|
|
|
|
|
|
for (String cityName : cityNameList) {
|
|
|
|
|
//(1)复制16个大屏
|
|
|
|
|
//复制record对象
|
|
|
|
|
Record cityRecord = new Record().setColumns(motherRecord);
|
|
|
|
|
cityRecord.set("name", "教育决策支持系统【市州】" + cityName);
|
|
|
|
|
long bigScreenId = getSnowId();
|
|
|
|
|
cityRecord.set("id", bigScreenId);
|
|
|
|
|
Db.save("data_visualization_info", "id", cityRecord);
|
|
|
|
|
|
|
|
|
|
// (2) 复制16个大屏的细节配置信息
|
|
|
|
|
List<Record> writeList = new ArrayList<>();
|
|
|
|
|
for (Record rMotherChart : motherChartList) {
|
|
|
|
|
Record rCityChart = new Record().setColumns(rMotherChart);//克隆出来
|
|
|
|
|
//修改大屏ID
|
|
|
|
|
rCityChart.set("scene_id", bigScreenId);
|
|
|
|
|
writeList.add(rCityChart);
|
|
|
|
|
}
|
|
|
|
|
//批量保存
|
|
|
|
|
Db.use(DataEaseModel.DB_NAME).batchSave("core_chart_view", writeList, 100);
|
|
|
|
|
|
|
|
|
|
// (3) 修改地图中城市
|
|
|
|
|
List<Record> list = dm.getMap(bigScreenId);
|
|
|
|
|
//core_chart_view表
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
long id = record.getLong("id");
|
|
|
|
|
JSONObject jo = JSONObject.fromObject(record.getStr("custom_attr"));
|
|
|
|
|
//获取城市编码
|
|
|
|
|
String area_code = dm.getCityCode(cityName);
|
|
|
|
|
//修改前
|
|
|
|
|
System.out.println("修改前=" + jo.getJSONObject("map"));
|
|
|
|
|
|
|
|
|
|
//修改城市编码
|
|
|
|
|
jo.getJSONObject("map").put("id", area_code);
|
|
|
|
|
jo.getJSONObject("map").put("level", "city");
|
|
|
|
|
|
|
|
|
|
System.out.println("修改后=" + jo.getJSONObject("map"));
|
|
|
|
|
//写到数据库
|
|
|
|
|
String jsonString = jo.toString();
|
|
|
|
|
Db.use(DataEaseModel.DB_NAME).update("update core_chart_view set custom_attr=? where id=?", jsonString, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// (4) 发布共享链接
|
|
|
|
|
Record shareRecord = new Record().setColumns(motherShareRecord);
|
|
|
|
|
shareRecord.set("resource_id", bigScreenId);
|
|
|
|
|
shareRecord.set("id", getSnowId());
|
|
|
|
|
shareRecord.set("uuid",randomString(8));//大小写字母和数字组合,长度为8
|
|
|
|
|
Db.save("xpack_share", "id", shareRecord);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("生成完毕");
|
|
|
|
|
}
|
|
|
|
|
}
|