|
@@ -11,12 +11,126 @@ import com.huaxu.model.ProgramItem;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
|
|
|
+import java.sql.*;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
import static com.google.common.collect.Lists.newArrayList;
|
|
import static com.google.common.collect.Lists.newArrayList;
|
|
|
|
|
|
public class TestOrgTree {
|
|
public class TestOrgTree {
|
|
- // @Test
|
|
|
|
|
|
+ static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
|
|
|
|
+ static final String DB_URL = "jdbc:mysql://114.135.61.188:33306/udip_unit?characterEncoding=utf8";
|
|
|
|
+
|
|
|
|
+ // MySQL 8.0 以上版本 - JDBC 驱动名及数据库 URL
|
|
|
|
+ //static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
|
|
|
|
+ //static final String DB_URL = "jdbc:mysql://localhost:3306/RUNOOB?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 数据库的用户名与密码,需要根据自己的设置
|
|
|
|
+ static final String USER = "root";
|
|
|
|
+ static final String PASS = "100Zone@123";
|
|
|
|
+ private void produceTableByWord(String inputUrl,String outputUrl, List<String[]> testList ){
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Map<String, String> testMap = new HashMap<String, String>();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ WordUtil.changWord(inputUrl, outputUrl, testMap, testList);
|
|
|
|
+ }
|
|
|
|
+ private void produceTable(String tableName, DatabaseMetaData dbMetaData){
|
|
|
|
+
|
|
|
|
+ try{
|
|
|
|
+ // 注册 JDBC 驱动
|
|
|
|
+ String inputUrl = "D:\\test\\2020\\10\\31\\tableModel.docx";
|
|
|
|
+ //新生产的模板文件
|
|
|
|
+ String outputUrl = "D:\\test\\2020\\10\\30\\"+tableName+".docx";
|
|
|
|
+ List<String[]> testList = new ArrayList<String[]>();
|
|
|
|
+ // 打开链接
|
|
|
|
+
|
|
|
|
+ String schemaName="udip_unit";
|
|
|
|
+ System.out.println(" 实例化表对象..."+tableName);
|
|
|
|
+ ResultSet rs = dbMetaData.getColumns(null, schemaName, tableName, "%");
|
|
|
|
+ List<TableSource>list =new ArrayList<>();
|
|
|
|
+ // 展开结果集数据库
|
|
|
|
+ while(rs.next()){
|
|
|
|
+ TableSource tableSource=new TableSource();
|
|
|
|
+ String columnName = rs.getString("COLUMN_NAME");// 列名
|
|
|
|
+ String dataTypeName = rs.getString("TYPE_NAME");// java.sql.Types类型名称
|
|
|
|
+ String comment = rs.getString("REMARKS");
|
|
|
|
+ int columnSize = rs.getInt("COLUMN_SIZE");// 列大小
|
|
|
|
+ tableSource.setCloumnName(columnName);
|
|
|
|
+ if(columnName.equals("create_date")){
|
|
|
|
+ comment="创建时间";
|
|
|
|
+ }
|
|
|
|
+ else if(columnName.equals("create_by")){
|
|
|
|
+ comment="创建人";
|
|
|
|
+ }
|
|
|
|
+ else if(columnName.equals("update_date")){
|
|
|
|
+ comment="更新时间";
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else if(columnName.equals("update_by")){
|
|
|
|
+ comment="更新人";
|
|
|
|
+ }else if(columnName.equals("status")){
|
|
|
|
+ comment="删除标识";
|
|
|
|
+ }
|
|
|
|
+ tableSource.setName(comment);
|
|
|
|
+ tableSource.setType(dataTypeName);
|
|
|
|
+ tableSource.setLength(columnSize);
|
|
|
|
+ list.add(tableSource);
|
|
|
|
+ testList.add(new String[]{tableSource.getName(),tableSource.getCloumnName()
|
|
|
|
+ ,tableSource.getType(),tableSource.getLength()+"","",
|
|
|
|
+ ""});
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ produceTableByWord(inputUrl,outputUrl,testList);
|
|
|
|
+ /* EasyExcel.write("D:\\test\\2020\\10\\31/"+tableName+".xlsx", TableSource.class)
|
|
|
|
+ .excelType(ExcelTypeEnum.XLSX)
|
|
|
|
+ .registerWriteHandler(new CustemhandlerUtils())
|
|
|
|
+ .registerWriteHandler(EasyExcelUtil.getStyleStrategy())
|
|
|
|
+ .sheet("Export")
|
|
|
|
+ .doWrite(list);*/
|
|
|
|
+ // 完成后关闭
|
|
|
|
+ rs.close();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }catch(SQLException se){
|
|
|
|
+ // 处理 JDBC 错误
|
|
|
|
+ se.printStackTrace();
|
|
|
|
+ }catch(Exception e){
|
|
|
|
+ // 处理 Class.forName 错误
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ @Test
|
|
|
|
+ public void test2() throws SQLException, ClassNotFoundException {
|
|
|
|
+ Class.forName(JDBC_DRIVER);
|
|
|
|
+ Connection conn = null;
|
|
|
|
+
|
|
|
|
+ conn = DriverManager.getConnection(DB_URL,USER,PASS);
|
|
|
|
+ DatabaseMetaData dbMetaData = conn.getMetaData();
|
|
|
|
+ System.out.println("连接数据库...");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 执行查询
|
|
|
|
+
|
|
|
|
+ /*String []tables={"SC_ROLE","SC_USER_ROLE","SC_PERMISSION","SC_ROLE_PERMISSION","SC_ROLE_PERMISSION","SC_ROLE_PERMISSION"
|
|
|
|
+ ,"SC_SITE","SC_SITE_PERMISSION","SC_SITE_USER","SC_LOGIN_LOG","SC_BUILDING","SC_COMMUNITY"
|
|
|
|
+ ,"SC_AREA","SC_MESSAGE","SC_DEVICE","SC_DEVICE_DATA_DIM","SC_METER_READ_RECORD","SC_SITE_PERMISSION","SC_SITE_PERMISSION",
|
|
|
|
+ "SC_SITE_PERMISSION","SC_SITE_PERMISSION","SC_SITE_PERMISSION",
|
|
|
|
+ "sc_stat_meter_read_rate_by_building","sc_stat_meter_read_rate_by_building_15day",
|
|
|
|
+ "sc_stat_meter_read_rate_by_building_month","sc_clearing_plan", "sc_clearing_record_item"};*/
|
|
|
|
+ String []tables={"udip_unit_profile_t","udip_unit_attribute_t","udip_unit_specs_t"
|
|
|
|
+ ,"udip_unit_method_t","udip_unit_param_t","udip_unit_t","udip_unit_data_t",
|
|
|
|
+ "udip_unit_command_t"};
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < tables.length; i++) {
|
|
|
|
+ produceTable(tables[i],dbMetaData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ conn.close();
|
|
|
|
+ }
|
|
|
|
+ // @Test
|
|
public void test(){
|
|
public void test(){
|
|
/* List<TestEXCEL>list =new ArrayList<>();
|
|
/* List<TestEXCEL>list =new ArrayList<>();
|
|
for(int i=0;i<1000000;i++){
|
|
for(int i=0;i<1000000;i++){
|