commit 240d453337ed6e4e5075d6a3b6db118ba0ae186a Author: WenG <450292408@qq.com> Date: Sun Mar 7 17:26:55 2021 +0800 fc diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..fb561b7 --- /dev/null +++ b/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + ink.wgink + code-factory + 1.0-SNAPSHOT + + + 8 + 8 + + + + + org.openjfx + javafx-controls + 15.0.1 + + + + mysql + mysql-connector-java + 5.1.49 + + + + org.apache.commons + commons-lang3 + 3.11 + + + + + com.belerweb + pinyin4j + 2.5.1 + + + + + + + + org.openjfx + javafx-maven-plugin + 0.0.5 + + HelloFX + + + + + + \ No newline at end of file diff --git a/src/main/java/ink/wgink/code/factory/StartUp.java b/src/main/java/ink/wgink/code/factory/StartUp.java new file mode 100644 index 0000000..3a9d206 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/StartUp.java @@ -0,0 +1,31 @@ +package ink.wgink.code.factory; + +import javafx.application.Application; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: StartUp + * @Description: 启动 + * @Author: WangGeng + * @Date: 2021/3/2 12:54 + * @Version: 1.0 + **/ +public class StartUp extends Application { + @Override + public void start(Stage primaryStage) throws Exception { + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/route/main.fxml")); + primaryStage.setScene(new Scene(fxmlLoader.load())); + primaryStage.show(); + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/src/main/java/ink/wgink/code/factory/controller/GenerateController.java b/src/main/java/ink/wgink/code/factory/controller/GenerateController.java new file mode 100644 index 0000000..e0973b3 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/controller/GenerateController.java @@ -0,0 +1,94 @@ +package ink.wgink.code.factory.controller; + +import ink.wgink.code.factory.factory.CheckBoxTableCellFactory; +import ink.wgink.code.factory.factory.ChoiceBoxTableCellFactory; +import ink.wgink.code.factory.service.FieldService; +import ink.wgink.code.factory.service.GenerateService; +import ink.wgink.code.factory.vos.TableVO; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.CheckBox; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.TextField; +import javafx.scene.control.cell.PropertyValueFactory; + +import java.net.URL; +import java.util.ResourceBundle; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: GenerateController + * @Description: 生成器 + * @Author: WangGeng + * @Date: 2021/3/6 10:11 + * @Version: 1.0 + **/ +public class GenerateController implements Initializable { + + @FXML + private CheckBox apiCheckBox; + @FXML + private CheckBox appCheckBox; + @FXML + private CheckBox resourceCheckBox; + @FXML + private CheckBox iServiceCheckBox; + @FXML + private CheckBox serviceImplCheckBox; + @FXML + private CheckBox iDaoCheckBox; + @FXML + private CheckBox mysqlCheckBox; + @FXML + private TextField tablePrefixTextField; + @FXML + private CheckBox htmlCheckBox; + @FXML + private CheckBox thymeleafCheckBox; + @FXML + private CheckBox routeCheckBox; + @FXML + private TextField contextTextField; + @FXML + private TextField packageTextField; + @FXML + private TableView fieldTableView; + + private TableVO tableVO; + private FieldService fieldService; + private GenerateService generateService; + + @Override + public void initialize(URL location, ResourceBundle resources) { + initTableView(); + } + + private void initTableView() { + ObservableList tableColumns = fieldTableView.getColumns(); + tableColumns.get(0).setCellValueFactory(new PropertyValueFactory<>("rowNumber")); + tableColumns.get(1).setCellValueFactory(new PropertyValueFactory<>("columnName")); + tableColumns.get(2).setCellValueFactory(new PropertyValueFactory<>("columnComment")); + tableColumns.get(3).setCellValueFactory(new PropertyValueFactory<>("columnDefault")); + tableColumns.get(4).setCellValueFactory(new PropertyValueFactory<>("columnType")); + tableColumns.get(5).setCellValueFactory(new PropertyValueFactory<>("propertyName")); + tableColumns.get(6).setCellValueFactory(new PropertyValueFactory<>("propertyType")); + tableColumns.get(7).setCellValueFactory(new PropertyValueFactory<>("propertyLength")); + tableColumns.get(8).setCellValueFactory(new CheckBoxTableCellFactory("isFormShow")); + tableColumns.get(9).setCellValueFactory(new CheckBoxTableCellFactory("isListShow")); + tableColumns.get(10).setCellValueFactory(new CheckBoxTableCellFactory("isNotNull")); + tableColumns.get(11).setCellValueFactory(new ChoiceBoxTableCellFactory("formFieldType")); + } + + public void setTableVO(TableVO tableVO) { + this.tablePrefixTextField.setText(tableVO.getTableName().split("\\_")[0] + "_"); + this.tableVO = tableVO; + fieldService = new FieldService(fieldTableView, tableVO.getTableName()); + generateService = new GenerateService(fieldTableView); + fieldService.showField(); + } + +} diff --git a/src/main/java/ink/wgink/code/factory/controller/LoginController.java b/src/main/java/ink/wgink/code/factory/controller/LoginController.java new file mode 100644 index 0000000..42214ff --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/controller/LoginController.java @@ -0,0 +1,35 @@ +package ink.wgink.code.factory.controller; + +import com.sun.javafx.robot.impl.FXRobotHelper; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.stage.Stage; + +import java.io.IOException; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: LoginController + * @Description: 登录 + * @Author: WangGeng + * @Date: 2021/3/2 21:25 + * @Version: 1.0 + **/ +public class LoginController { + + @FXML + private Button clickButton; + + @FXML + public void onAction(ActionEvent actionEvent) throws IOException { + Scene scene = new Scene(FXMLLoader.load(getClass().getResource("/route/main.fxml")), 400, 300); + Stage stage = FXRobotHelper.getStages().get(0); + stage.setScene(scene); + } + +} diff --git a/src/main/java/ink/wgink/code/factory/controller/MainController.java b/src/main/java/ink/wgink/code/factory/controller/MainController.java new file mode 100644 index 0000000..f010de7 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/controller/MainController.java @@ -0,0 +1,160 @@ +package ink.wgink.code.factory.controller; + +import ink.wgink.code.factory.service.TableService; +import ink.wgink.code.factory.utils.MsgUtil; +import ink.wgink.code.factory.vos.TableVO; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.input.KeyEvent; +import javafx.scene.input.MouseEvent; +import javafx.stage.Modality; +import javafx.stage.Stage; +import javafx.stage.StageStyle; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: MainController + * @Description: 主页 + * @Author: WangGeng + * @Date: 2021/3/3 20:02 + * @Version: 1.0 + **/ +public class MainController implements Initializable { + + @FXML + private TextField dbUrlField; + @FXML + private TextField dbPortField; + @FXML + private TextField dbNameField; + @FXML + private TextField dbUsernameField; + @FXML + private PasswordField dbPasswordField; + @FXML + private Button connectionDatabaseButton; + @FXML + private TableView dbTableTableView; + private TableService tableService; + + + @Override + public void initialize(URL location, ResourceBundle resources) { + initDBTableTableView(); + this.tableService = new TableService(dbTableTableView); + } + + /** + * 初始化 数据库表 TableView + */ + private void initDBTableTableView() { + ObservableList> tableColumns = dbTableTableView.getColumns(); + tableColumns.get(0).setCellValueFactory(new PropertyValueFactory<>("rowNumber")); + tableColumns.get(1).setCellValueFactory(new PropertyValueFactory<>("tableName")); + tableColumns.get(2).setCellValueFactory(new PropertyValueFactory<>("tableComment")); + tableColumns.get(3).setCellValueFactory(new PropertyValueFactory<>("tableCollation")); + } + + @FXML + public void onConnectDatabase(ActionEvent event) { + String dbUrl = dbUrlField.getText(); + if (StringUtils.isBlank(dbUrl)) { + MsgUtil.errorAlert("数据库地址不能为空"); + return; + } + String dbPort = dbPortField.getText(); + if (StringUtils.isBlank(dbPort)) { + MsgUtil.errorAlert("数据库端口不能为空"); + return; + } + String dbName = dbNameField.getText(); + if (StringUtils.isBlank(dbName)) { + MsgUtil.errorAlert("数据库名不能为空"); + return; + } + String dbUsername = dbUsernameField.getText(); + if (StringUtils.isBlank(dbUsername)) { + MsgUtil.errorAlert("数据库用户名不能为空"); + return; + } + String dbPassword = dbPasswordField.getText(); + if (StringUtils.isBlank(dbPassword)) { + MsgUtil.errorAlert("数据库密码不能为空"); + return; + } + tableService.connectionDatabase(dbUrl, dbPort, dbName, dbUsername, dbPassword); + } + + @FXML + public void onTableRowClick(MouseEvent event) throws IOException { + if (event.getClickCount() == 2) { + TableVO tableVO = (TableVO) this.dbTableTableView.getSelectionModel().getSelectedItem(); + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/route/generate.fxml")); + Stage stage = new Stage(StageStyle.DECORATED); + stage.setScene(new Scene(fxmlLoader.load(), 800D, 600D)); + stage.initModality(Modality.APPLICATION_MODAL); + stage.setTitle("生成代码【" + tableVO.getTableName() + "】"); + stage.show(); + + GenerateController generateController = fxmlLoader.getController(); + generateController.setTableVO(tableVO); + } + } + + @FXML + public void dbUrlReleased(KeyEvent keyEvent) { + String port = dbUrlField.getText(); + if (StringUtils.isBlank(port)) { + dbUrlField.setText(""); + return; + } + } + + @FXML + public void dbNameReleased(KeyEvent keyEvent) { + String port = dbNameField.getText(); + if (StringUtils.isBlank(port)) { + dbNameField.setText(""); + return; + } + } + + @FXML + public void dbUsernameReleased(KeyEvent keyEvent) { + String port = dbUsernameField.getText(); + if (StringUtils.isBlank(port)) { + dbUsernameField.setText(""); + return; + } + } + + @FXML + public void dbPortReleased(KeyEvent keyEvent) { + String port = dbPortField.getText(); + if (StringUtils.isBlank(port)) { + dbPortField.setText(""); + return; + } + if (!NumberUtils.isDigits(port)) { + MsgUtil.alert(AlertType.ERROR, "端口号只能是数字"); + dbPortField.setText(""); + } + } + +} diff --git a/src/main/java/ink/wgink/code/factory/enums/ColumnDataTypeEnum.java b/src/main/java/ink/wgink/code/factory/enums/ColumnDataTypeEnum.java new file mode 100644 index 0000000..4f5e15b --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/enums/ColumnDataTypeEnum.java @@ -0,0 +1,69 @@ +package ink.wgink.code.factory.enums; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: DataTypeEnum + * @Description: 数据类型 + * @Author: WangGeng + * @Date: 2019/11/15 8:20 下午 + * @Version: 1.0 + **/ +public enum ColumnDataTypeEnum { + + /** + * 整形 + */ + INT("int"), + /** + * 长整形 + */ + BIGINT("bigint"), + /** + * 双精度 + */ + DOUBLE("double"), + /** + * 时间戳 + */ + DATETIME("datetime"), + /** + * 日期 + */ + DATE("date"), + /** + * 字符串 + */ + VARCHAR("varchar"), + /** + * 字符 + */ + CHAR("char"), + /** + * 文本 + */ + TEXT("text"), + /** + * 长文本 + */ + LONGTEXT("longtext"), + /** + * ID和名称 + */ + ID_AND_NAME("idAndName"), + /** + * ID列表和名称列表 + */ + IDS_AND_NAMES("idsAndNames"); + + private String value; + + ColumnDataTypeEnum(String value) { + this.value = value; + } + + public String getValue() { + return value == null ? "" : value.trim(); + } +} diff --git a/src/main/java/ink/wgink/code/factory/enums/ColumnIsNullableEnum.java b/src/main/java/ink/wgink/code/factory/enums/ColumnIsNullableEnum.java new file mode 100644 index 0000000..dec4717 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/enums/ColumnIsNullableEnum.java @@ -0,0 +1,27 @@ +package ink.wgink.code.factory.enums; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: ColumnIsNullable + * @Description: 可为空 + * @Author: WangGeng + * @Date: 2019/11/15 9:28 下午 + * @Version: 1.0 + **/ +public enum ColumnIsNullableEnum { + + YES("YES"), + NO("NO"); + + String value; + + ColumnIsNullableEnum(String value) { + this.value = value; + } + + public String getValue() { + return value == null ? "" : value.trim(); + } +} diff --git a/src/main/java/ink/wgink/code/factory/enums/FormFieldRequireTypeEnum.java b/src/main/java/ink/wgink/code/factory/enums/FormFieldRequireTypeEnum.java new file mode 100644 index 0000000..23c47b4 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/enums/FormFieldRequireTypeEnum.java @@ -0,0 +1,33 @@ +package ink.wgink.code.factory.enums; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: FieldRequireTypeEnum + * @Description: 字段校验类型 + * @Author: WangGeng + * @Date: 2019/12/4 17:29 + * @Version: 1.0 + **/ +public enum FormFieldRequireTypeEnum { + NONE("none"), + REQUIRED("required"), + PHONE("phone"), + EMAIL("email"), + URL("url"), + NUMBER("number"), + DATE("date"), + IDENTITY("identity"), + CUSTOM("custom"); + + private String value; + + FormFieldRequireTypeEnum(String value) { + this.value = value; + } + + public String getValue() { + return value == null ? "" : value; + } +} diff --git a/src/main/java/ink/wgink/code/factory/enums/FormFieldTypeEnum.java b/src/main/java/ink/wgink/code/factory/enums/FormFieldTypeEnum.java new file mode 100644 index 0000000..0c73a6e --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/enums/FormFieldTypeEnum.java @@ -0,0 +1,114 @@ +package ink.wgink.code.factory.enums; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: DynamicFormEnum + * @Description: 动态表单 + * @Author: WangGeng + * @Date: 2019/12/2 5:28 下午 + * @Version: 1.0 + **/ +public enum FormFieldTypeEnum { + + /** + * 文本 + */ + TEXT("text"), + /** + * 时间戳 + */ + DATETIME("datetime"), + /** + * 日期 + */ + DATE("date"), + /** + * 整形 + */ + NUMBER("number"), + /** + * 双精度 + */ + DOUBLE("double"), + /** + * 文本域 + */ + TEXTAREA("textarea"), + /** + * 富文本 + */ + RICH_TEXT("richText"), + /** + * ID 选择 + */ + ID_SELECT("idSelect"), + /** + * 下拉选择 + */ + SELECT("select"), + /** + * 复选 + */ + CHECKBOX("checkbox"), + /** + * 单选 + */ + RADIO("radio"), + /** + * 选择人员 + */ + SELECT_USER("selectUser"), + /** + * 选择部门 + */ + SELECT_DEPARTMENT("selectDepartment"), + /** + * 文件 + */ + FILE("file"), + /** + * 图片 + */ + IMAGE("image"), + /** + * 视频 + */ + VIDEO("video"), + /** + * 音频 + */ + AUDIO("audio"), + /** + * 当前用户 + */ + CURRENT_USER("currentUser"), + /** + * 当前部门 + */ + CURRENT_DEPARTMENT("currentDepartment"), + /** + * 当前角色 + */ + CURRENT_ROLE("currentRole"), + /** + * 当前组 + */ + CURRENT_GROUP("currentGroup"), + /** + * 当前职位 + */ + CURRENT_POSITION("currentPosition"); + + private String value; + + FormFieldTypeEnum(String value) { + this.value = value; + } + + public String getValue() { + return value == null ? "" : value.trim(); + } + +} diff --git a/src/main/java/ink/wgink/code/factory/enums/PropertyTypeEnum.java b/src/main/java/ink/wgink/code/factory/enums/PropertyTypeEnum.java new file mode 100644 index 0000000..09cfe41 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/enums/PropertyTypeEnum.java @@ -0,0 +1,28 @@ +package ink.wgink.code.factory.enums; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: PropertyTypeEnum + * @Description: Java属性类型 + * @Author: WangGeng + * @Date: 2021/3/7 10:31 + * @Version: 1.0 + **/ +public enum PropertyTypeEnum { + STRING("string"), + DOUBLE("double"), + INTEGER("integer"), + LONG("long"); + + private String value; + + PropertyTypeEnum(String value) { + this.value = value; + } + + public String getValue() { + return value == null ? "" : value.trim(); + } +} diff --git a/src/main/java/ink/wgink/code/factory/factory/CheckBoxTableCellFactory.java b/src/main/java/ink/wgink/code/factory/factory/CheckBoxTableCellFactory.java new file mode 100644 index 0000000..1830de2 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/factory/CheckBoxTableCellFactory.java @@ -0,0 +1,48 @@ +package ink.wgink.code.factory.factory; + +import ink.wgink.code.factory.vos.FieldVO; +import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.beans.value.ObservableValue; +import javafx.scene.control.CheckBox; +import javafx.scene.control.TableColumn; +import javafx.util.Callback; +import org.apache.commons.lang3.StringUtils; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: CheckboxTableCellFactory + * @Description: 表格checkbox + * @Author: WangGeng + * @Date: 2021/3/6 18:46 + * @Version: 1.0 + **/ +public class CheckBoxTableCellFactory implements Callback, ObservableValue> { + public static final String IS_FORM_SHOW = "isFormShow"; + public static final String IS_LIST_SHOW = "isListShow"; + public static final String IS_NOT_NULL = "isNotNull"; + private final String property; + + public CheckBoxTableCellFactory(String property) { + this.property = property; + } + + @Override + public ObservableValue call(TableColumn.CellDataFeatures param) { + CheckBox checkBox = new CheckBox(); + if (StringUtils.equals(IS_FORM_SHOW, property)) { + Boolean isFormShow = param.getValue().getFormShow(); + checkBox.setSelected(isFormShow == null || !isFormShow ? false : true); + } + if (StringUtils.equals(IS_LIST_SHOW, property)) { + Boolean isListShow = param.getValue().getListShow(); + checkBox.setSelected(isListShow == null || !isListShow ? false : true); + } + if (StringUtils.equals(IS_NOT_NULL, property)) { + Boolean isNotNull = param.getValue().getNotNull(); + checkBox.setSelected(isNotNull == null || !isNotNull ? false : true); + } + return new ReadOnlyObjectWrapper<>(checkBox); + } +} diff --git a/src/main/java/ink/wgink/code/factory/factory/ChoiceBoxTableCellFactory.java b/src/main/java/ink/wgink/code/factory/factory/ChoiceBoxTableCellFactory.java new file mode 100644 index 0000000..12b1922 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/factory/ChoiceBoxTableCellFactory.java @@ -0,0 +1,59 @@ +package ink.wgink.code.factory.factory; + +import ink.wgink.code.factory.enums.FormFieldTypeEnum; +import ink.wgink.code.factory.vos.FieldVO; +import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.scene.control.ChoiceBox; +import javafx.scene.control.TableColumn; +import javafx.util.Callback; +import org.apache.commons.lang3.StringUtils; + +import java.text.Normalizer; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: SelectTableCellFactory + * @Description: 表格下拉列表 + * @Author: WangGeng + * @Date: 2021/3/7 10:52 + * @Version: 1.0 + **/ +public class ChoiceBoxTableCellFactory implements Callback, ObservableValue>> { + + private final String property; + private ObservableList normalSelect = FXCollections.observableArrayList( + "", FormFieldTypeEnum.TEXT.getValue(), FormFieldTypeEnum.NUMBER.getValue(), + FormFieldTypeEnum.DOUBLE.getValue(), FormFieldTypeEnum.TEXTAREA.getValue(), + FormFieldTypeEnum.SELECT_USER.getValue(), FormFieldTypeEnum.SELECT_DEPARTMENT.getValue(), + FormFieldTypeEnum.FILE.getValue(), FormFieldTypeEnum.IMAGE.getValue(), + FormFieldTypeEnum.AUDIO.getValue(), FormFieldTypeEnum.VIDEO.getValue(), + FormFieldTypeEnum.CHECKBOX.getValue() + ); + private ObservableList singleSelect = FXCollections.observableArrayList( + "", + FormFieldTypeEnum.RADIO.getValue(), + FormFieldTypeEnum.SELECT.getValue() + ); + + public ChoiceBoxTableCellFactory(String property) { + this.property = property; + } + + @Override + public ObservableValue> call(TableColumn.CellDataFeatures param) { + ChoiceBox choiceBox = new ChoiceBox(); + choiceBox.setPrefWidth(150); + if (StringUtils.equalsIgnoreCase(FormFieldTypeEnum.ID_SELECT.getValue(), param.getValue().getFormFieldType())) { + choiceBox.setItems(singleSelect); + } else { + choiceBox.setItems(normalSelect); + } + choiceBox.getSelectionModel().select(param.getValue().getFormFieldType()); + return new ReadOnlyObjectWrapper<>(choiceBox); + } +} diff --git a/src/main/java/ink/wgink/code/factory/manager/JdbcManager.java b/src/main/java/ink/wgink/code/factory/manager/JdbcManager.java new file mode 100644 index 0000000..4f9e1cd --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/manager/JdbcManager.java @@ -0,0 +1,97 @@ +package ink.wgink.code.factory.manager; + +import ink.wgink.code.factory.utils.JdbcUtil; + +import java.sql.*; +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: JdbcManager + * @Description: JDBC管理 + * @Author: WangGeng + * @Date: 2021/3/5 21:23 + * @Version: 1.0 + **/ +public class JdbcManager { + + private static JdbcManager jdbcManager = JdbcManagerBuilder.jdbcManager; + private String dbUrl; + private String dbPort; + private String dbName; + private String dbUsername; + private String dbPassword; + private Connection connection; + + static { + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + private JdbcManager() { + } + + public static JdbcManager getInstance() { + return jdbcManager; + } + + public void setDatabaseInfo(String dbUrl, String dbPort, String dbName, String dbUsername, String dbPassword) { + this.dbUrl = dbUrl; + this.dbPort = dbPort; + this.dbName = dbName; + this.dbUsername = dbUsername; + this.dbPassword = dbPassword; + } + + /** + * 数据库链接 + * + * @return + * @throws SQLException + */ + public Connection getConnection() throws SQLException { + if (connection == null || connection.isClosed()) { + this.connection = DriverManager.getConnection(String.format("jdbc:mysql://%s:%s/%s", dbUrl, dbPort, dbName), dbUsername, dbPassword); + } + return connection; + } + + /** + * 数据库表列表 + * + * @return + * @throws SQLException + */ + public List> listDatabaseTable() throws SQLException { + String SQL = "SELECT * FROM `information_schema`.`TABLES` WHERE TABLE_SCHEMA = ?"; + PreparedStatement preparedStatement = getConnection().prepareStatement(SQL); + preparedStatement.setString(1, this.dbName); + return JdbcUtil.listResult(preparedStatement.executeQuery()); + } + + /** + * 表字段列表 + * + * @param tableName + * @return + * @throws SQLException + */ + public List> listTableField(String tableName) throws SQLException { + String SQL = "SELECT * FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?"; + PreparedStatement preparedStatement = getConnection().prepareStatement(SQL); + preparedStatement.setString(1, this.dbName); + preparedStatement.setString(2, tableName); + return JdbcUtil.listResult(preparedStatement.executeQuery()); + } + + private static class JdbcManagerBuilder { + public static JdbcManager jdbcManager = new JdbcManager(); + } + +} diff --git a/src/main/java/ink/wgink/code/factory/service/FieldService.java b/src/main/java/ink/wgink/code/factory/service/FieldService.java new file mode 100644 index 0000000..1848df8 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/service/FieldService.java @@ -0,0 +1,135 @@ +package ink.wgink.code.factory.service; + +import ink.wgink.code.factory.enums.ColumnDataTypeEnum; +import ink.wgink.code.factory.enums.ColumnIsNullableEnum; +import ink.wgink.code.factory.enums.FormFieldTypeEnum; +import ink.wgink.code.factory.enums.PropertyTypeEnum; +import ink.wgink.code.factory.manager.JdbcManager; +import ink.wgink.code.factory.utils.WStringUtil; +import ink.wgink.code.factory.vos.FieldVO; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.concurrent.Service; +import javafx.concurrent.Task; +import javafx.scene.control.TableView; +import org.apache.commons.lang3.StringUtils; + +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: FieldService + * @Description: 字段业务 + * @Author: WangGeng + * @Date: 2021/3/6 16:11 + * @Version: 1.0 + **/ +public class FieldService { + + private static final String DEFAULT_FIELD_ID = "id"; + private static final String DEFAULT_FIELD_CREATOR = "creator"; + private static final String DEFAULT_FIELD_GMT_CREATE = "gmtCreate"; + private static final String DEFAULT_FIELD_MODIFIER = "modifier"; + private static final String DEFAULT_FIELD_GMT_MODIFIED = "gmtModified"; + private static final String DEFAULT_FIELD_IS_DELETE = "isDelete"; + + private ObservableList fieldVOObservableList = FXCollections.observableArrayList(); + private TableView tableView; + private String tableName; + + public FieldService(TableView tableView, String tableName) { + this.tableView = tableView; + this.tableName = tableName; + } + + /** + * 表单字段类型 + * + * @param columnDataType + * @return + */ + public String getFormFieldType(String columnDataType) { + if (StringUtils.equalsIgnoreCase(ColumnDataTypeEnum.INT.getValue(), columnDataType)) { + return FormFieldTypeEnum.NUMBER.getValue(); + } else if (StringUtils.equalsIgnoreCase(ColumnDataTypeEnum.BIGINT.getValue(), columnDataType)) { + return FormFieldTypeEnum.NUMBER.getValue(); + } else if (StringUtils.equalsIgnoreCase(ColumnDataTypeEnum.DOUBLE.getValue(), columnDataType)) { + return FormFieldTypeEnum.DOUBLE.getValue(); + } else if (StringUtils.equalsIgnoreCase(ColumnDataTypeEnum.DATETIME.getValue(), columnDataType)) { + return FormFieldTypeEnum.DATETIME.getValue(); + } else if (StringUtils.equalsIgnoreCase(ColumnDataTypeEnum.DATE.getValue(), columnDataType)) { + return FormFieldTypeEnum.DATE.getValue(); + } else if (StringUtils.equalsIgnoreCase(ColumnDataTypeEnum.TEXT.getValue(), columnDataType)) { + return FormFieldTypeEnum.TEXTAREA.getValue(); + } else if (StringUtils.equalsIgnoreCase(ColumnDataTypeEnum.LONGTEXT.getValue(), columnDataType)) { + return FormFieldTypeEnum.RICH_TEXT.getValue(); + } else if (StringUtils.equalsIgnoreCase(ColumnDataTypeEnum.CHAR.getValue(), columnDataType)) { + return FormFieldTypeEnum.ID_SELECT.getValue(); + } + return FormFieldTypeEnum.TEXT.getValue(); + } + + /** + * Java属性栏类型 + * + * @param columnDataType + * @return + */ + public String getPropertyType(String columnDataType) { + if (StringUtils.equalsIgnoreCase(ColumnDataTypeEnum.INT.getValue(), columnDataType)) { + return PropertyTypeEnum.INTEGER.getValue(); + } else if (StringUtils.equalsIgnoreCase(ColumnDataTypeEnum.BIGINT.getValue(), columnDataType)) { + return PropertyTypeEnum.LONG.getValue(); + } else if (StringUtils.equalsIgnoreCase(ColumnDataTypeEnum.DOUBLE.getValue(), columnDataType)) { + return PropertyTypeEnum.DOUBLE.getValue(); + } + return PropertyTypeEnum.STRING.getValue(); + } + + public void showField() { + new Service() { + + @Override + protected Task createTask() { + return new Task() { + @Override + protected Integer call() throws Exception { + List> tableFields = JdbcManager.getInstance().listTableField(tableName); + fieldVOObservableList.clear(); + for (int i = 0; i < tableFields.size(); i++) { + Map field = tableFields.get(i); + System.out.println(field); + + FieldVO fieldVO = new FieldVO(); + fieldVO.setRowNumber(i + 1); + fieldVO.setColumnName(field.get("COLUMN_NAME").toString()); + fieldVO.setColumnType(field.get("COLUMN_TYPE").toString()); + fieldVO.setDataType(field.get("DATA_TYPE").toString()); + fieldVO.setCharacterMaximum(field.get("CHARACTER_MAXIMUM") == null ? 0 : Integer.valueOf(field.get("CHARACTER_MAXIMUM").toString())); + fieldVO.setNumericPrecision(field.get("NUMERIC_PRECISION") == null ? 0 : Integer.valueOf(field.get("NUMERIC_PRECISION").toString())); + fieldVO.setNumericScale(field.get("NUMERIC_SCALE") == null ? 0 : Integer.valueOf(field.get("NUMERIC_SCALE").toString())); + fieldVO.setColumnComment(field.get("COLUMN_COMMENT") == null ? "" : field.get("COLUMN_COMMENT").toString()); + fieldVO.setColumnDefault(field.get("COLUMN_DEFAULT") == null ? "" : field.get("COLUMN_DEFAULT").toString()); + fieldVO.setPropertyName(WStringUtil.underLine2LowerUpper(fieldVO.getColumnName())); + fieldVO.setNotNull(StringUtils.equalsIgnoreCase(ColumnIsNullableEnum.YES.getValue(), field.get("IS_NULLABLE").toString()) ? false : true); + fieldVO.setPropertyType(getPropertyType(fieldVO.getDataType())); + fieldVO.setFormFieldType(getFormFieldType(fieldVO.getDataType())); + fieldVOObservableList.add(fieldVO); + } + return 0; + } + }; + } + + @Override + protected void succeeded() { + tableView.setItems(fieldVOObservableList); + super.succeeded(); + } + }.start(); + } + +} diff --git a/src/main/java/ink/wgink/code/factory/service/GenerateService.java b/src/main/java/ink/wgink/code/factory/service/GenerateService.java new file mode 100644 index 0000000..644569d --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/service/GenerateService.java @@ -0,0 +1,29 @@ +package ink.wgink.code.factory.service; + +import ink.wgink.code.factory.vos.FieldVO; +import javafx.collections.FXCollections; +import javafx.collections.ObservableArray; +import javafx.collections.ObservableList; +import javafx.scene.control.TableView; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: GenerateService + * @Description: 代码生成 + * @Author: WangGeng + * @Date: 2021/3/6 16:11 + * @Version: 1.0 + **/ +public class GenerateService { + + private TableView tableView; + + public GenerateService(TableView tableView) { + this.tableView = tableView; + } + + public void showField() { + } +} diff --git a/src/main/java/ink/wgink/code/factory/service/TableService.java b/src/main/java/ink/wgink/code/factory/service/TableService.java new file mode 100644 index 0000000..223f6e8 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/service/TableService.java @@ -0,0 +1,80 @@ +package ink.wgink.code.factory.service; + +import ink.wgink.code.factory.manager.JdbcManager; +import ink.wgink.code.factory.vos.TableVO; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.concurrent.Service; +import javafx.concurrent.Task; +import javafx.scene.control.TableView; + +import java.util.List; +import java.util.Map; + + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: TableService + * @Description: 表 + * @Author: WangGeng + * @Date: 2021/3/5 21:18 + * @Version: 1.0 + **/ +public class TableService { + + private TableView dbTableTableView; + private ObservableList tableVOObservableList = FXCollections.observableArrayList(); + + public TableService(TableView dbTableTableView) { + this.dbTableTableView = dbTableTableView; + } + + /** + * 链接数据库 + * + * @param dbUrl 数据库链接 + * @param dbPort 数据库端口 + * @param dbName 数据库名称 + * @param dbUsername 数据库用户名 + * @param dbPassword 数据库密码 + */ + public void connectionDatabase(String dbUrl, String dbPort, String dbName, String dbUsername, String dbPassword) { + JdbcManager.getInstance().setDatabaseInfo(dbUrl, dbPort, dbName, dbUsername, dbPassword); + showTable(); + } + + private void showTable() { + new Service() { + @Override + protected Task createTask() { + return new Task() { + @Override + protected Integer call() throws Exception { + List> tables = JdbcManager.getInstance().listDatabaseTable(); + tableVOObservableList.clear(); + for (int i = 0; i < tables.size(); i++) { + Map table = tables.get(i); + TableVO tableVO = new TableVO(); + tableVO.setRowNumber(i + 1); + tableVO.setTableName(table.get("TABLE_NAME").toString()); + tableVO.setTableComment(table.get("TABLE_COMMENT").toString()); + tableVO.setTableCollation(table.get("TABLE_COLLATION").toString()); + tableVOObservableList.add(tableVO); + } + return 0; + } + + @Override + protected void succeeded() { + dbTableTableView.setItems(tableVOObservableList); + super.succeeded(); + } + }; + } + }.start(); + + + } +} diff --git a/src/main/java/ink/wgink/code/factory/utils/JdbcUtil.java b/src/main/java/ink/wgink/code/factory/utils/JdbcUtil.java new file mode 100644 index 0000000..beb5710 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/utils/JdbcUtil.java @@ -0,0 +1,57 @@ +package ink.wgink.code.factory.utils; + +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @ClassName: JdbcUtil + * @Description: Jdbc + * @Author: WangGeng + * @Date: 2019-07-14 18:53 + * @Version: 1.0 + **/ +public class JdbcUtil { + + /** + * 获取单条信息 + * + * @param resultSet + * @return + */ + public static Map getResult(ResultSet resultSet) { + List> resultList = listResult(resultSet); + if (resultList.isEmpty()) { + return null; + } + return resultList.get(0); + } + + /** + * 查询列表 + * + * @param resultSet + * @return + */ + public static List> listResult(ResultSet resultSet) { + List> resultList = new ArrayList<>(); + try { + ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + int columnCount = resultSetMetaData.getColumnCount(); + while (resultSet.next()) { + Map row = new HashMap<>(16); + for (int i = 0; i < columnCount; i++) { + row.put(resultSetMetaData.getColumnLabel(i + 1), resultSet.getObject(i + 1)); + } + resultList.add(row); + } + } catch (Exception e) { + return new ArrayList<>(); + } + return resultList; + } + +} diff --git a/src/main/java/ink/wgink/code/factory/utils/MsgUtil.java b/src/main/java/ink/wgink/code/factory/utils/MsgUtil.java new file mode 100644 index 0000000..c8cc2cb --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/utils/MsgUtil.java @@ -0,0 +1,123 @@ +package ink.wgink.code.factory.utils; + +import com.sun.javafx.robot.FXRobot; +import com.sun.javafx.robot.impl.FXRobotHelper; +import javafx.application.Platform; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyDoubleProperty; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.beans.property.ReadOnlyStringProperty; +import javafx.concurrent.Service; +import javafx.concurrent.Task; +import javafx.concurrent.Worker; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Pane; +import javafx.scene.layout.StackPane; +import javafx.stage.Modality; +import javafx.stage.Stage; +import javafx.stage.StageStyle; + +import javax.xml.soap.Text; +import java.util.Stack; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: MessageUtil + * @Description: 消息工具 + * @Author: WangGeng + * @Date: 2021/3/3 21:25 + * @Version: 1.0 + **/ +public class MsgUtil { + + /** + * 错误 + * + * @param msg + */ + public static void errorAlert(String msg) { + alert(AlertType.NONE, msg); + } + + /** + * 确定 + * + * @param alertType + * @param msg + */ + public static void alert(Alert.AlertType alertType, String msg) { + + Alert alert = new Alert(alertType, msg, ButtonType.CLOSE); + alert.setTitle("提示"); + alert.getDialogPane().setPrefWidth(150); + alert.show(); + } + + /** + * 提醒 + * + * @param msg + */ + public static void msg(final String msg) { + HBox hBox = new HBox(); + hBox.setPadding(new Insets(5, 5, 5, 5)); + hBox.setAlignment(Pos.CENTER); + + Label label = new Label(msg); + label.setId("msgLabel"); + hBox.getChildren().add(label); + Stage stage = new Stage(StageStyle.UNDECORATED); + stage.setScene(new Scene(hBox)); + stage.show(); + +// Platform.runLater(() -> { +// // 子线程更新主线程UI的代码 +// stage.close(); +// }); + // + + // 这种方式提倡,call中编写代码,successed方法中填写刷新UI的操作, + Service service = new Service() { + @Override + protected Task createTask() { + return new Task() { + @Override + protected String call() throws Exception { + Thread.sleep(2000); + return "success"; + } + + @Override + protected void scheduled() { + // 任务开始, 填写刷新UI的操作 + super.scheduled(); + } + + @Override + protected void running() { + // 任务执行 + super.running(); + } + + // 任务成功之后,关闭提示 + @Override + protected void succeeded() { + // 任务执行成功 + stage.close(); + super.succeeded(); + } + }; + } + }; + service.start(); + + } + +} diff --git a/src/main/java/ink/wgink/code/factory/utils/WStringUtil.java b/src/main/java/ink/wgink/code/factory/utils/WStringUtil.java new file mode 100644 index 0000000..e6c335f --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/utils/WStringUtil.java @@ -0,0 +1,285 @@ +package ink.wgink.code.factory.utils; + + +import net.sourceforge.pinyin4j.PinyinHelper; +import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; +import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; +import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; +import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; +import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 字符串相关方法 + */ +public class WStringUtil { + + static final Pattern LOWER_UPPER_PATTERN = Pattern.compile("[A-Z][a-z]*"); + static final Pattern PHONE_PATTERN = Pattern.compile("1\\d{10}"); + static final Pattern EMAIL_PATTERN = Pattern.compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"); + + /** + * 是否是电话 + * + * @param value + * @return + */ + public static boolean isPhone(String value) { + return PHONE_PATTERN.matcher(value).matches(); + } + + /** + * 是否是邮箱 + * + * @param value + * @return + */ + public static boolean isEmail(String value) { + return EMAIL_PATTERN.matcher(value).matches(); + } + + /** + * 将以逗号分隔的字符串转换成字符串数组 + * + * @param valStr + * @return String[] + */ + public static String[] StrList(String valStr) { + int i = 0; + String TempStr = valStr; + String[] returnStr = new String[valStr.length() + 1 - TempStr.replace(",", "").length()]; + valStr = valStr + ","; + while (valStr.indexOf(',') > 0) { + returnStr[i] = valStr.substring(0, valStr.indexOf(',')); + valStr = valStr.substring(valStr.indexOf(',') + 1, valStr.length()); + + i++; + } + return returnStr; + } + + /** + * 获取字符串编码 + * + * @param str + * @return + */ + public static String getEncoding(String str) { + String encode = "GB2312"; + try { + if (str.equals(new String(str.getBytes(encode), encode))) { + String s = encode; + return s; + } + } catch (Exception exception) { + } + encode = "ISO-8859-1"; + try { + if (str.equals(new String(str.getBytes(encode), encode))) { + String s1 = encode; + return s1; + } + } catch (Exception exception1) { + } + encode = "UTF-8"; + try { + if (str.equals(new String(str.getBytes(encode), encode))) { + String s2 = encode; + return s2; + } + } catch (Exception exception2) { + } + encode = "GBK"; + try { + if (str.equals(new String(str.getBytes(encode), encode))) { + String s3 = encode; + return s3; + } + } catch (Exception exception3) { + } + return ""; + } + + /** + * 第一个字母转小写,英文 + * + * @param str + * @return + */ + public static String firstToLower(String str) { + return str.substring(0, 1).toLowerCase() + str.substring(1); + } + + /** + * 第一个字母大写、英文 + * + * @param str + * @return + */ + public static String firstToUpper(String str) { + return str.substring(0, 1).toUpperCase() + str.substring(1); + } + + /** + *

+ * title 驼峰名称转下划线名称 + *

+ *

+ * description 驼峰名称转小写名称用下划线名称 + *

+ * + * @param str + * @return + * @author WenG + * @date 2018年2月28日 下午4:28:45 + * @modifier WenG + * @date 2018年2月28日 下午4:28:45 + */ + public static String lowerUpper2UnderLine(String str) { + Matcher matcher = LOWER_UPPER_PATTERN.matcher(str); + while (matcher.find()) { + String group = matcher.group(); + String lower = "_" + group.toLowerCase(); + str = str.replaceFirst(group, lower); + matcher = LOWER_UPPER_PATTERN.matcher(str); + } + if (str.startsWith("_")) { + str = str.substring(1, str.length()); + } + return str; + } + + /** + *

+ * title 下划线分割转驼峰式 + *

+ *

+ * description 下划线分割转驼峰式 + *

+ * + * @param str + * @return + * @author WenG + * @date 2018年2月28日 下午4:49:13 + * @modifier WenG + * @date 2018年2月28日 下午4:49:13 + */ + public static String underLine2LowerUpper(String str) { + String[] strs = str.split("_"); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < strs.length; i++) { + String letter = strs[i].toLowerCase(); + if (letter.length() == 0) { + continue; + } + if (i == 0) { + sb.append(letter); + } else { + int firstLetter = letter.charAt(0); + firstLetter -= 32; + sb.append((char) firstLetter).append(letter.substring(1)); + } + } + if (sb.length() > 0) { + return sb.toString(); + } + return str; + } + + /** + *

+ * title 下划线分割转驼峰式 + *

+ *

+ * description 下划线分割转驼峰式 + *

+ * + * @param str + * @param firstLower 第一个字母小写 + * @return + * @author WenG + * @date 2018年2月28日 下午4:56:28 + * @modifier WenG + * @date 2018年2月28日 下午4:56:28 + */ + public static String underLine2LowerUpper(String str, boolean firstLower) { + String result = underLine2LowerUpper(str); + if (firstLower) { + int first = result.charAt(0) + 32; + result = ((char) first) + result.substring(1, result.length()); + } + return result; + } + + /** + * 获取拼音 + * + * @param src + * @return + */ + public static String getPingYin(String src) { + char[] t1 = null; + t1 = src.toCharArray(); + String[] t2 = new String[t1.length]; + HanyuPinyinOutputFormat t3 = new HanyuPinyinOutputFormat(); + t3.setCaseType(HanyuPinyinCaseType.LOWERCASE); + t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + t3.setVCharType(HanyuPinyinVCharType.WITH_V); + String t4 = ""; + int t0 = t1.length; + try { + for (int i = 0; i < t0; i++) { + // 判断是否为汉字字符 + if (Character.toString(t1[i]).matches("[\\u4E00-\\u9FA5]+")) { + t2 = PinyinHelper.toHanyuPinyinStringArray(t1[i], t3); + t4 += t2[0]; + } else { + t4 += Character.toString(t1[i]); + } + } + return t4; + } catch (BadHanyuPinyinOutputFormatCombination e1) { + e1.printStackTrace(); + } + return t4; + } + + /** + * 获取中文首字母 + * + * @param str + * @return + */ + public static String getPinYinHeadChar(String str) { + String convert = ""; + for (int j = 0; j < str.length(); j++) { + char word = str.charAt(j); + String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word); + if (pinyinArray != null) { + convert += pinyinArray[0].charAt(0); + } else { + convert += word; + } + } + return convert; + } + + /** + * 汉字转ASCII码 + * + * @param cnStr + * @return + */ + public static String getCnASCII(String cnStr) { + StringBuffer strBuf = new StringBuffer(); + byte[] bGBK = cnStr.getBytes(); + for (int i = 0; i < bGBK.length; i++) { + // System.out.println(Integer.toHexString(bGBK[i]&0xff)); + strBuf.append(Integer.toHexString(bGBK[i] & 0xff)); + } + return strBuf.toString(); + } + +} diff --git a/src/main/java/ink/wgink/code/factory/vos/FieldVO.java b/src/main/java/ink/wgink/code/factory/vos/FieldVO.java new file mode 100644 index 0000000..fb34e44 --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/vos/FieldVO.java @@ -0,0 +1,205 @@ +package ink.wgink.code.factory.vos; + +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleStringProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: FieldVO + * @Description: 字段 + * @Author: WangGeng + * @Date: 2021/3/6 17:35 + * @Version: 1.0 + **/ +public class FieldVO { + + private SimpleIntegerProperty rowNumber; + private SimpleStringProperty columnName; + private SimpleStringProperty columnComment; + private SimpleStringProperty columnDefault; + private String dataType; + private SimpleStringProperty columnType; + private Integer characterMaximum; + private Integer numericPrecision; + private Integer numericScale; + private SimpleStringProperty propertyName; + private SimpleStringProperty propertyType; + private SimpleIntegerProperty propertyLength; + private String formFieldType; + private Boolean isFormShow; + private Boolean isListShow; + private Boolean isNotNull; + + public FieldVO() { + this.rowNumber = new SimpleIntegerProperty(0); + this.columnName = new SimpleStringProperty(); + this.columnComment = new SimpleStringProperty(); + this.columnDefault = new SimpleStringProperty(); + this.columnType = new SimpleStringProperty(); + this.propertyName = new SimpleStringProperty(); + this.propertyType = new SimpleStringProperty(); + this.propertyLength = new SimpleIntegerProperty(0); + } + + public int getRowNumber() { + return rowNumber.get(); + } + + public SimpleIntegerProperty rowNumberProperty() { + return rowNumber; + } + + public void setRowNumber(int rowNumber) { + this.rowNumber.set(rowNumber); + } + + public String getColumnName() { + return columnName.get(); + } + + public SimpleStringProperty columnNameProperty() { + return columnName; + } + + public void setColumnName(String columnName) { + this.columnName.set(columnName); + } + + public String getColumnComment() { + return columnComment.get(); + } + + public SimpleStringProperty columnCommentProperty() { + return columnComment; + } + + public void setColumnComment(String columnComment) { + this.columnComment.set(columnComment); + } + + public String getColumnDefault() { + return columnDefault.get(); + } + + public SimpleStringProperty columnDefaultProperty() { + return columnDefault; + } + + public void setColumnDefault(String columnDefault) { + this.columnDefault.set(columnDefault); + } + + public String getDataType() { + return dataType == null ? "" : dataType.trim(); + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getColumnType() { + return columnType.get(); + } + + public SimpleStringProperty columnTypeProperty() { + return columnType; + } + + public void setColumnType(String columnType) { + this.columnType.set(columnType); + } + + public Integer getCharacterMaximum() { + return characterMaximum; + } + + public void setCharacterMaximum(Integer characterMaximum) { + this.characterMaximum = characterMaximum; + } + + public Integer getNumericPrecision() { + return numericPrecision; + } + + public void setNumericPrecision(Integer numericPrecision) { + this.numericPrecision = numericPrecision; + } + + public Integer getNumericScale() { + return numericScale; + } + + public void setNumericScale(Integer numericScale) { + this.numericScale = numericScale; + } + + public String getPropertyName() { + return propertyName.get(); + } + + public SimpleStringProperty propertyNameProperty() { + return propertyName; + } + + public void setPropertyName(String propertyName) { + this.propertyName.set(propertyName); + } + + public String getPropertyType() { + return propertyType.get(); + } + + public SimpleStringProperty propertyTypeProperty() { + return propertyType; + } + + public void setPropertyType(String propertyType) { + this.propertyType.set(propertyType); + } + + public int getPropertyLength() { + return propertyLength.get(); + } + + public SimpleIntegerProperty propertyLengthProperty() { + return propertyLength; + } + + public void setPropertyLength(int propertyLength) { + this.propertyLength.set(propertyLength); + } + + public String getFormFieldType() { + return formFieldType == null ? "" : formFieldType.trim(); + } + + public void setFormFieldType(String formFieldType) { + this.formFieldType = formFieldType; + } + + public Boolean getFormShow() { + return isFormShow; + } + + public void setFormShow(Boolean formShow) { + isFormShow = formShow; + } + + public Boolean getListShow() { + return isListShow; + } + + public void setListShow(Boolean listShow) { + isListShow = listShow; + } + + public Boolean getNotNull() { + return isNotNull; + } + + public void setNotNull(Boolean notNull) { + isNotNull = notNull; + } +} diff --git a/src/main/java/ink/wgink/code/factory/vos/TableVO.java b/src/main/java/ink/wgink/code/factory/vos/TableVO.java new file mode 100644 index 0000000..a195c5d --- /dev/null +++ b/src/main/java/ink/wgink/code/factory/vos/TableVO.java @@ -0,0 +1,84 @@ +package ink.wgink.code.factory.vos; + +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleStringProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: TableVO + * @Description: + * @Author: WangGeng + * @Date: 2021/3/3 14:07 + * @Version: 1.0 + **/ +public class TableVO { + + private SimpleIntegerProperty rowNumber; + private SimpleStringProperty tableName; + private SimpleStringProperty tableCollation; + private SimpleStringProperty tableComment; + + public TableVO() { + this.rowNumber = new SimpleIntegerProperty(); + this.tableName = new SimpleStringProperty(); + this.tableCollation = new SimpleStringProperty(); + this.tableComment = new SimpleStringProperty(); + } + + public TableVO(Integer rowNumber, String tableName, String tableCollation, String tableComment) { + this.rowNumber = new SimpleIntegerProperty(rowNumber); + this.tableName = new SimpleStringProperty(tableName); + this.tableCollation = new SimpleStringProperty(tableCollation); + this.tableComment = new SimpleStringProperty(tableComment); + } + + public int getRowNumber() { + return rowNumber.get(); + } + + public SimpleIntegerProperty rowNumberProperty() { + return rowNumber; + } + + public void setRowNumber(int rowNumber) { + this.rowNumber.set(rowNumber); + } + + public String getTableName() { + return tableName.get(); + } + + public SimpleStringProperty tableNameProperty() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName.set(tableName); + } + + public String getTableCollation() { + return tableCollation.get(); + } + + public SimpleStringProperty tableCollationProperty() { + return tableCollation; + } + + public void setTableCollation(String tableCollation) { + this.tableCollation.set(tableCollation); + } + + public String getTableComment() { + return tableComment.get(); + } + + public SimpleStringProperty tableCommentProperty() { + return tableComment; + } + + public void setTableComment(String tableComment) { + this.tableComment.set(tableComment); + } +} diff --git a/src/main/resources/assets/css/style.css b/src/main/resources/assets/css/style.css new file mode 100644 index 0000000..68f6a45 --- /dev/null +++ b/src/main/resources/assets/css/style.css @@ -0,0 +1,3 @@ +table { + -fx-alignment: center; +} \ No newline at end of file diff --git a/src/main/resources/route/generate.fxml b/src/main/resources/route/generate.fxml new file mode 100644 index 0000000..26b5172 --- /dev/null +++ b/src/main/resources/route/generate.fxml @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +