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.

76 lines
3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package Tools.DataEase;
import Tools.DataEase.Util.DataEaseUtil;
import cn.hutool.core.io.FileUtil;
import com.dsideal.QingLong.Util.CommonUtil;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class ExcelExportTemplate {
public static void main(String[] args) throws IOException {
DataEaseUtil.Init();
//文本文件
if (!FileUtil.exist(DataEaseUtil.DataEaseDirectory)) FileUtil.mkdir(DataEaseUtil.DataEaseDirectory);
String sql = "select id,name from dataset_table where create_by='admin' and type='excel'";
List<Record> listAll = Db.find(sql);
int cnt = 0;
for (Record record : listAll) {
StringBuilder sb = new StringBuilder();
String table_id = record.getStr("id");
String name = record.getStr("name");
String tableName = "ds_" + table_id.replace("-", "_");
sb.append("/*\r\n表名:\r\n" + tableName + "\r\n");
sb.append("\r\n");
sb.append("业务名称:" + name + "\r\n");
//教师职称---> vs---> table
//这张表中有多个数据项目
Map<String, String> _map = DataEaseUtil.getColumnMap(tableName);
sql = "select * from " + tableName;
List<Record> list = Db.find(sql);
List<String> cList = DataEaseUtil.getColumns(tableName);
if (cList.size() > 2) {
sb.append("类型:集合\r\n");
} else {
sb.append("类型:单个\r\n");
}
String t = "字段顺序:";
boolean flag = false;
for (int i = 0; i < cList.size(); i++) {//每一列
String colName = cList.get(i).toLowerCase();
if (_map.containsKey(colName)) {
t += _map.get(colName) + ",";
flag = true;
}
}
if (flag) {
sb.append(t.substring(0, t.length() - 1) + "\r\n");
sb.append("数据行数:" + list.size() + "\r\n");
}
sb.append("温馨提示:\r\n");
sb.append("1、使用注释请使用 -- 开头。\r\n");
sb.append("2、支持多行SQL语句每个SQL语句需要以;号结尾,最后一条也要以;号结尾!\r\n");
sb.append("*/" + "\r\n");
cnt++;
FileUtil.writeUtf8String(sb.toString(), new File(DataEaseUtil.DataEaseDirectory + "/" + cnt + "_" + name + ".txt"));
}
CommonUtil.log("恭喜,所有脚本生成成功!");
//直接打开生成脚本的目录
try {
Runtime.getRuntime().exec("cmd /c start explorer " + DataEaseUtil.DataEaseDirectory);
} catch (Exception e) {
e.printStackTrace();
}
}
}