From 93b9a4bd47bfec774894928392d52a61fca07c38 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 20 十月 2022 10:37:32 +0800 Subject: [PATCH] 修改数据结构、业务数据映射 --- JavaCode/FrmMyBatisPlus.resx | 120 ++ JavaCode/BsTemplate/Entity.java | 21 JavaCode/App.config | 5 JavaCode/SysTemplate/Mapper.java | 0 JavaCode/FrmMain.Designer.cs | 398 ------- JavaCode/SysTemplate/Entity.java | 0 JavaCode/FrmMyBatisPlus.cs | 120 ++ JavaCode/JavaCode.csproj | 40 JavaCode/FrmSys.cs | 677 +++++++++++++ JavaCode/SysTemplate/Mapper.xml | 10 JavaCode/SysTemplate/Service.java | 0 JavaCode/SysTemplate/Controller.java | 2 JavaCode/BsTemplate/Mapper.java | 25 JavaCode/FrmSys.resx | 120 ++ JavaCode/SysTemplate/pg.sql | 153 +++ JavaCode/FrmSys.Designer.cs | 410 ++++++++ JavaCode/FrmMain.cs | 684 ------------- JavaCode/FrmMyBatisPlus.Designer.cs | 231 ++++ 18 files changed, 1,961 insertions(+), 1,055 deletions(-) diff --git a/JavaCode/App.config b/JavaCode/App.config index 0a36549..ef04e9b 100644 --- a/JavaCode/App.config +++ b/JavaCode/App.config @@ -1,7 +1,10 @@ 锘�<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> - <add key="pgConn" value="Server=127.0.0.1;Port=5432;Database=langfang;User Id=postgres;Password=postgres;"/> + <!-- 69701 --> + <!--<add key="pgConn" value="Server=127.0.0.1;Port=5432;Database=langfang;User Id=postgres;Password=postgres;"/>--> + <!-- 20582 --> + <add key="pgConn" value="Server=192.168.20.39;Port=5433;Database=langfang;User Id=postgres;Password=postgres;"/> </appSettings> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> diff --git a/JavaCode/BsTemplate/Entity.java b/JavaCode/BsTemplate/Entity.java new file mode 100644 index 0000000..1eaf19f --- /dev/null +++ b/JavaCode/BsTemplate/Entity.java @@ -0,0 +1,21 @@ +package {entityNS}; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +import java.io.Serializable; +import java.sql.Timestamp; + +/** + * {bak} + * @author WWW + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("{tabName}") +public class {entityName} implements Serializable { + private static final long serialVersionUID = {uid}L; diff --git a/JavaCode/BsTemplate/Mapper.java b/JavaCode/BsTemplate/Mapper.java new file mode 100644 index 0000000..774d0d6 --- /dev/null +++ b/JavaCode/BsTemplate/Mapper.java @@ -0,0 +1,25 @@ +package {mapperNS}; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import {entityNS}.{entityName}; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.springframework.stereotype.Repository; + +/** + * {bak} + * @author WWW + */ +@Mapper +@Repository +public interface {mapperName} extends BaseMapper<{entityName}> { + /** + * 鏌ヨ涓�鏉� + * + * @param {id} + * @return + */ + @Select("{selectSql}") + {entityName} selectOne(@Param("{id}") Integer {id}); +} diff --git a/JavaCode/FrmMain.Designer.cs b/JavaCode/FrmMain.Designer.cs index cf64b9d..ccb57a1 100644 --- a/JavaCode/FrmMain.Designer.cs +++ b/JavaCode/FrmMain.Designer.cs @@ -3,14 +3,14 @@ partial class FrmMain { /// <summary> - /// 蹇呴渶鐨勮璁″櫒鍙橀噺銆� + /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> - /// 娓呯悊鎵�鏈夋鍦ㄤ娇鐢ㄧ殑璧勬簮銆� + /// Clean up any resources being used. /// </summary> - /// <param name="disposing">濡傛灉搴旈噴鏀炬墭绠¤祫婧愶紝涓� true锛涘惁鍒欎负 false銆�</param> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) @@ -20,391 +20,57 @@ base.Dispose(disposing); } - #region Windows 绐椾綋璁捐鍣ㄧ敓鎴愮殑浠g爜 + #region Windows Form Designer generated code /// <summary> - /// 璁捐鍣ㄦ敮鎸佹墍闇�鐨勬柟娉� - 涓嶈 - /// 浣跨敤浠g爜缂栬緫鍣ㄤ慨鏀规鏂规硶鐨勫唴瀹广�� + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { - this.tabList = new System.Windows.Forms.ListBox(); - this.btnReadTab = new System.Windows.Forms.Button(); - this.txtTabPre = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); - this.txtTabNS = new System.Windows.Forms.TextBox(); - this.txtMapperNS = new System.Windows.Forms.TextBox(); - this.label2 = new System.Windows.Forms.Label(); - this.txtEntityNS = new System.Windows.Forms.TextBox(); - this.label3 = new System.Windows.Forms.Label(); - this.button4 = new System.Windows.Forms.Button(); - this.dgvTab = new System.Windows.Forms.DataGridView(); - this.label4 = new System.Windows.Forms.Label(); - this.txtInsert = new System.Windows.Forms.TextBox(); - this.txtUpdate = new System.Windows.Forms.TextBox(); - this.label5 = new System.Windows.Forms.Label(); - this.button5 = new System.Windows.Forms.Button(); - this.button6 = new System.Windows.Forms.Button(); - this.button1 = new System.Windows.Forms.Button(); - this.txtNS = new System.Windows.Forms.TextBox(); - this.button2 = new System.Windows.Forms.Button(); - this.button3 = new System.Windows.Forms.Button(); - this.txtServiceNS = new System.Windows.Forms.TextBox(); - this.label6 = new System.Windows.Forms.Label(); - this.txtControllerNS = new System.Windows.Forms.TextBox(); - this.label7 = new System.Windows.Forms.Label(); - this.txtApiTag = new System.Windows.Forms.TextBox(); - this.label8 = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize)(this.dgvTab)).BeginInit(); + this.btnSys = new System.Windows.Forms.Button(); + this.btnMybatis = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // tabList + // btnSys // - this.tabList.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.tabList.FormattingEnabled = true; - this.tabList.ItemHeight = 16; - this.tabList.Location = new System.Drawing.Point(12, 49); - this.tabList.Name = "tabList"; - this.tabList.Size = new System.Drawing.Size(353, 244); - this.tabList.TabIndex = 0; - this.tabList.SelectedIndexChanged += new System.EventHandler(this.tabList_SelectedIndexChanged); + this.btnSys.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnSys.Location = new System.Drawing.Point(142, 63); + this.btnSys.Name = "btnSys"; + this.btnSys.Size = new System.Drawing.Size(183, 25); + this.btnSys.TabIndex = 13; + this.btnSys.Text = "鐢� 鎴� 绯� 缁� 琛�"; + this.btnSys.UseVisualStyleBackColor = true; + this.btnSys.Click += new System.EventHandler(this.btnSys_Click); // - // btnReadTab + // btnMybatis // - this.btnReadTab.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.btnReadTab.Location = new System.Drawing.Point(247, 13); - this.btnReadTab.Name = "btnReadTab"; - this.btnReadTab.Size = new System.Drawing.Size(118, 23); - this.btnReadTab.TabIndex = 1; - this.btnReadTab.Text = "璇诲彇鏁版嵁搴撹〃"; - this.btnReadTab.UseVisualStyleBackColor = true; - this.btnReadTab.Click += new System.EventHandler(this.btnReadTab_Click); - // - // txtTabPre - // - this.txtTabPre.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.txtTabPre.Location = new System.Drawing.Point(129, 10); - this.txtTabPre.Name = "txtTabPre"; - this.txtTabPre.Size = new System.Drawing.Size(100, 26); - this.txtTabPre.TabIndex = 2; - this.txtTabPre.Text = "sys_"; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label1.Location = new System.Drawing.Point(437, 18); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(88, 16); - this.label1.TabIndex = 6; - this.label1.Text = "琛ㄥ悕鍓嶇紑锛�"; - // - // txtTabNS - // - this.txtTabNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.txtTabNS.Location = new System.Drawing.Point(529, 13); - this.txtTabNS.Name = "txtTabNS"; - this.txtTabNS.Size = new System.Drawing.Size(339, 26); - this.txtTabNS.TabIndex = 7; - this.txtTabNS.Text = "lf."; - // - // txtMapperNS - // - this.txtMapperNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.txtMapperNS.Location = new System.Drawing.Point(529, 51); - this.txtMapperNS.Name = "txtMapperNS"; - this.txtMapperNS.Size = new System.Drawing.Size(339, 26); - this.txtMapperNS.TabIndex = 9; - this.txtMapperNS.Text = "com.lf.server.mapper.sys"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label2.Location = new System.Drawing.Point(389, 56); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(136, 16); - this.label2.TabIndex = 8; - this.label2.Text = "Mapper鍚嶇О绌洪棿锛�"; - // - // txtEntityNS - // - this.txtEntityNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.txtEntityNS.Location = new System.Drawing.Point(529, 88); - this.txtEntityNS.Name = "txtEntityNS"; - this.txtEntityNS.Size = new System.Drawing.Size(339, 26); - this.txtEntityNS.TabIndex = 11; - this.txtEntityNS.Text = "com.lf.server.entity.sys"; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label3.Location = new System.Drawing.Point(389, 93); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(136, 16); - this.label3.TabIndex = 10; - this.label3.Text = "Entity鍚嶇О绌洪棿锛�"; - // - // button4 - // - this.button4.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.button4.Location = new System.Drawing.Point(885, 202); - this.button4.Name = "button4"; - this.button4.Size = new System.Drawing.Size(183, 25); - this.button4.TabIndex = 12; - this.button4.Text = "鐢� 鎴� 鎵� 鏈� 鏂� 浠�"; - this.button4.UseVisualStyleBackColor = true; - this.button4.Click += new System.EventHandler(this.generateAll_Click); - // - // dgvTab - // - this.dgvTab.AllowUserToAddRows = false; - this.dgvTab.AllowUserToDeleteRows = false; - this.dgvTab.BackgroundColor = System.Drawing.SystemColors.ButtonFace; - this.dgvTab.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dgvTab.Location = new System.Drawing.Point(12, 312); - this.dgvTab.Margin = new System.Windows.Forms.Padding(0); - this.dgvTab.MultiSelect = false; - this.dgvTab.Name = "dgvTab"; - this.dgvTab.ReadOnly = true; - this.dgvTab.RowHeadersWidth = 40; - this.dgvTab.RowTemplate.Height = 23; - this.dgvTab.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.dgvTab.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.dgvTab.Size = new System.Drawing.Size(1056, 300); - this.dgvTab.TabIndex = 13; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label4.Location = new System.Drawing.Point(387, 241); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(136, 16); - this.label4.TabIndex = 14; - this.label4.Text = "鎻掑叆鏃舵帓闄ゅ瓧娈碉細"; - // - // txtInsert - // - this.txtInsert.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.txtInsert.Location = new System.Drawing.Point(529, 236); - this.txtInsert.Name = "txtInsert"; - this.txtInsert.Size = new System.Drawing.Size(339, 26); - this.txtInsert.TabIndex = 15; - this.txtInsert.Text = "id,update_user,update_time"; - // - // txtUpdate - // - this.txtUpdate.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.txtUpdate.Location = new System.Drawing.Point(529, 271); - this.txtUpdate.Name = "txtUpdate"; - this.txtUpdate.Size = new System.Drawing.Size(339, 26); - this.txtUpdate.TabIndex = 17; - this.txtUpdate.Text = "id,create_user,create_time"; - // - // label5 - // - this.label5.AutoSize = true; - this.label5.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label5.Location = new System.Drawing.Point(387, 276); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(136, 16); - this.label5.TabIndex = 16; - this.label5.Text = "鏇存柊鏃舵帓闄ゅ瓧娈碉細"; - // - // button5 - // - this.button5.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.button5.Location = new System.Drawing.Point(885, 14); - this.button5.Name = "button5"; - this.button5.Size = new System.Drawing.Size(183, 25); - this.button5.TabIndex = 18; - this.button5.Text = "鐢� 鎴� Mapper.xml"; - this.button5.UseVisualStyleBackColor = true; - this.button5.Click += new System.EventHandler(this.mapperXml_Click); - // - // button6 - // - this.button6.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.button6.Location = new System.Drawing.Point(885, 52); - this.button6.Name = "button6"; - this.button6.Size = new System.Drawing.Size(183, 25); - this.button6.TabIndex = 19; - this.button6.Text = "鐢� 鎴� Mapper.java"; - this.button6.UseVisualStyleBackColor = true; - this.button6.Click += new System.EventHandler(this.mapperJava_Click); - // - // button1 - // - this.button1.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.button1.Location = new System.Drawing.Point(885, 89); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(183, 25); - this.button1.TabIndex = 20; - this.button1.Text = "鐢� 鎴� Entity.java"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.entityJava_Click); - // - // txtNS - // - this.txtNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.txtNS.Location = new System.Drawing.Point(12, 10); - this.txtNS.Name = "txtNS"; - this.txtNS.Size = new System.Drawing.Size(100, 26); - this.txtNS.TabIndex = 21; - this.txtNS.Text = "69701"; - // - // button2 - // - this.button2.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.button2.Location = new System.Drawing.Point(885, 127); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(183, 25); - this.button2.TabIndex = 22; - this.button2.Text = "鐢� 鎴� Service.java"; - this.button2.UseVisualStyleBackColor = true; - this.button2.Click += new System.EventHandler(this.serviceJava_Click); - // - // button3 - // - this.button3.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.button3.Location = new System.Drawing.Point(885, 165); - this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(183, 25); - this.button3.TabIndex = 23; - this.button3.Text = "鐢熸垚 Controller.java"; - this.button3.UseVisualStyleBackColor = true; - this.button3.Click += new System.EventHandler(this.controllerJava_Click); - // - // txtServiceNS - // - this.txtServiceNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.txtServiceNS.Location = new System.Drawing.Point(529, 126); - this.txtServiceNS.Name = "txtServiceNS"; - this.txtServiceNS.Size = new System.Drawing.Size(339, 26); - this.txtServiceNS.TabIndex = 25; - this.txtServiceNS.Text = "com.lf.server.service.sys"; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label6.Location = new System.Drawing.Point(381, 131); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(144, 16); - this.label6.TabIndex = 24; - this.label6.Text = "Service鍚嶇О绌洪棿锛�"; - // - // txtControllerNS - // - this.txtControllerNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.txtControllerNS.Location = new System.Drawing.Point(529, 164); - this.txtControllerNS.Name = "txtControllerNS"; - this.txtControllerNS.Size = new System.Drawing.Size(339, 26); - this.txtControllerNS.TabIndex = 27; - this.txtControllerNS.Text = "com.lf.server.controller.sys"; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label7.Location = new System.Drawing.Point(365, 169); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(160, 16); - this.label7.TabIndex = 26; - this.label7.Text = "Controller鍚嶇О绌洪棿:"; - // - // txtApiTag - // - this.txtApiTag.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.txtApiTag.Location = new System.Drawing.Point(529, 201); - this.txtApiTag.Name = "txtApiTag"; - this.txtApiTag.Size = new System.Drawing.Size(339, 26); - this.txtApiTag.TabIndex = 29; - this.txtApiTag.Text = "杩愮淮绠$悊\\\\{bak}"; - // - // label8 - // - this.label8.AutoSize = true; - this.label8.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label8.Location = new System.Drawing.Point(445, 206); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(80, 16); - this.label8.TabIndex = 28; - this.label8.Text = "Api鏍囪瘑锛�"; + this.btnMybatis.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnMybatis.Location = new System.Drawing.Point(142, 134); + this.btnMybatis.Name = "btnMybatis"; + this.btnMybatis.Size = new System.Drawing.Size(183, 25); + this.btnMybatis.TabIndex = 14; + this.btnMybatis.Text = "鐢� 鎴� Mybatis Plus"; + this.btnMybatis.UseVisualStyleBackColor = true; + this.btnMybatis.Click += new System.EventHandler(this.btnMybatis_Click); // // FrmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1095, 630); - this.Controls.Add(this.txtApiTag); - this.Controls.Add(this.label8); - this.Controls.Add(this.txtControllerNS); - this.Controls.Add(this.label7); - this.Controls.Add(this.txtServiceNS); - this.Controls.Add(this.label6); - this.Controls.Add(this.button3); - this.Controls.Add(this.button2); - this.Controls.Add(this.txtNS); - this.Controls.Add(this.button1); - this.Controls.Add(this.button6); - this.Controls.Add(this.button5); - this.Controls.Add(this.txtUpdate); - this.Controls.Add(this.label5); - this.Controls.Add(this.txtInsert); - this.Controls.Add(this.label4); - this.Controls.Add(this.dgvTab); - this.Controls.Add(this.button4); - this.Controls.Add(this.txtEntityNS); - this.Controls.Add(this.label3); - this.Controls.Add(this.txtMapperNS); - this.Controls.Add(this.label2); - this.Controls.Add(this.txtTabNS); - this.Controls.Add(this.label1); - this.Controls.Add(this.txtTabPre); - this.Controls.Add(this.btnReadTab); - this.Controls.Add(this.tabList); + this.ClientSize = new System.Drawing.Size(484, 261); + this.Controls.Add(this.btnMybatis); + this.Controls.Add(this.btnSys); this.Name = "FrmMain"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "FrmMain"; - this.Load += new System.EventHandler(this.FrmMain_Load); - ((System.ComponentModel.ISupportInitialize)(this.dgvTab)).EndInit(); this.ResumeLayout(false); - this.PerformLayout(); } #endregion - private System.Windows.Forms.ListBox tabList; - private System.Windows.Forms.Button btnReadTab; - private System.Windows.Forms.TextBox txtTabPre; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox txtTabNS; - private System.Windows.Forms.TextBox txtMapperNS; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.TextBox txtEntityNS; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.Button button4; - private System.Windows.Forms.DataGridView dgvTab; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.TextBox txtInsert; - private System.Windows.Forms.TextBox txtUpdate; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.Button button5; - private System.Windows.Forms.Button button6; - private System.Windows.Forms.Button button1; - private System.Windows.Forms.TextBox txtNS; - private System.Windows.Forms.Button button2; - private System.Windows.Forms.Button button3; - private System.Windows.Forms.TextBox txtServiceNS; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.TextBox txtControllerNS; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.TextBox txtApiTag; - private System.Windows.Forms.Label label8; + private System.Windows.Forms.Button btnSys; + private System.Windows.Forms.Button btnMybatis; } -} - +} \ No newline at end of file diff --git a/JavaCode/FrmMain.cs b/JavaCode/FrmMain.cs index 65fa1f5..36ce72f 100644 --- a/JavaCode/FrmMain.cs +++ b/JavaCode/FrmMain.cs @@ -1,14 +1,10 @@ -锘縰sing JavaCode.cs; -using System; +锘縰sing System; using System.Collections.Generic; using System.ComponentModel; using System.Data; -using System.Diagnostics; using System.Drawing; -using System.IO; using System.Linq; using System.Text; -using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; @@ -16,689 +12,23 @@ { public partial class FrmMain : Form { - #region 鎴愬憳鍙橀噺+鏋勯�犲嚱鏁� - string baseDir = AppDomain.CurrentDomain.BaseDirectory; - private PostgreHelper _dbHelper; - - private List<TabInfo> _list; public FrmMain() { InitializeComponent(); } - private void FrmMain_Load(object sender, EventArgs e) + private void btnSys_Click(object sender, EventArgs e) { - _dbHelper = new PostgreHelper(DbEnum.langfang); - } - #endregion - - #region 鏌ヨ琛ㄧ粨鏋� - private void btnReadTab_Click(object sender, EventArgs e) - { - string txtTab = this.txtTabPre.Text.Trim(); - string sql = "select c.relname as \"tab\", cast(obj_description(c.oid) as varchar) as \"desc\", a.attnum as \"num\", a.attname as \"col\", concat_ws('', t.typname, SUBSTRING(format_type(a.atttypid, a.atttypmod) from '\\(.*\\)')) as \"type\", d.description as \"bak\" from pg_attribute a left join pg_description d on d.objoid = a.attrelid and d.objsubid = a.attnum left join pg_class c on a.attrelid = c.oid left join pg_type t on a.atttypid = t.oid where a.attnum >= 0 and c.relname like '" + txtTab + "%' and obj_description(c.oid) is not null and relnamespace=" + this.txtNS.Text.Trim() + " order by c.relname desc, a.attnum asc"; - - DataTable dt = _dbHelper.GetDataTable(sql, null); - - _list = ModelHandler.FillModel<TabInfo>(dt); - if (_list == null || _list.Count == 0) - { - MessageBox.Show("娌℃湁鏌ヨ鍒版暟鎹紒"); - return; - } - - List<string> tabList = new List<string>(); - foreach (TabInfo ti in _list) - { - if (!tabList.Contains(ti.tab)) - { - tabList.Add(ti.tab); - } - } - - this.tabList.DataSource = tabList; + FrmSys frmSys = new FrmSys(); + frmSys.Show(); } - private void tabList_SelectedIndexChanged(object sender, EventArgs e) + private void btnMybatis_Click(object sender, EventArgs e) { - string tab = this.tabList.SelectedItem as string; - List<TabInfo> tabs = (from p in _list where p.tab == tab orderby p.num select p).ToList<TabInfo>(); - - this.dgvTab.DataSource = new BindingList<TabInfo>(tabs); - if (tabs != null && tabs.Count > 1) - { - this.dgvTab.Rows[1].Selected = true; - this.dgvTab.CurrentCell = this.dgvTab.Rows[1].Cells[0]; - } + FrmMyBatisPlus mybatis = new FrmMyBatisPlus(); + mybatis.Show(); } - - private void selectAll_Click(object sender, EventArgs e) - { - for (int i = 0; i < this.tabList.Items.Count; i++) - { - this.tabList.SetSelected(i, true); - } - } - - private void selectFlag_Click(object sender, EventArgs e) - { - for (int i = 0; i < this.tabList.Items.Count; i++) - { - bool flag = this.tabList.GetSelected(i); - this.tabList.SetSelected(i, !flag); - } - } - - private void selectNone_Click(object sender, EventArgs e) - { - for (int i = 0; i < this.tabList.Items.Count; i++) - { - this.tabList.SetSelected(i, false); - } - } - #endregion - - #region 鐢熸垚 Mapper.Xml - private void mapperXml_Click(object sender, EventArgs e) - { - try - { - string name = this.tabList.SelectedItem as string; - List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); - - GenerateMapperXml(name, tabs); - - string path = Path.Combine(baseDir, "Generate"); - OpenFolder(path); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - private void GenerateMapperXml(string name, List<TabInfo> tabs) - { - string tabName = this.txtTabNS.Text.Trim() + name; - name = name.Replace(this.txtTabPre.Text, ""); - - string shortName = NameConvert(name, true); - string mapperNS = this.txtMapperNS.Text.Trim(); - string mapperName = shortName + "Mapper"; - string entityNS = this.txtEntityNS.Text.Trim(); - string entityName = shortName + "Entity"; - - int idx = this.dgvTab.CurrentRow.Index; - TabInfo selectTabInfo = tabs[idx]; - - string colType = GetJavaType(selectTabInfo); - string colName = NameConvert(selectTabInfo.col, false); - string testExpr = colName + " != null"; - string testWhere = selectTabInfo.col + (colType == "String" ? " like " : " = ") + "#{" + colName + "}"; - - string insertCols = GetInsertCols(tabs); - string insertVal = GetInsertVal(tabs); - string insertVals = GetInsertVals(tabs); - string updateVal = GetUpdateVal(tabs); - string updateVals = GetUpdateVals(tabs); - - string xml = File.ReadAllText(Path.Combine(baseDir, "Template\\Mapper.xml")); - xml = xml - .Replace("{mapperNS}", mapperNS) - .Replace("{mapperName}", mapperName) - .Replace("{tabName}", tabName) - .Replace("{testExpr}", testExpr) - .Replace("{testWhere}", testWhere) - .Replace("{entityNS}", entityNS) - .Replace("{entityName}", entityName) - .Replace("{insertCols}", insertCols) - .Replace("{insertVal}", insertVal) - .Replace("{insertVals}", insertVals) - .Replace("{updateVal}", updateVal) - .Replace("{updateVals}", updateVals); - - string path = Path.Combine(baseDir, "Generate"); - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - - string fileName = shortName + "Mapper.xml"; - File.WriteAllText(Path.Combine(path, fileName), xml); - } - - private static string NameConvert(string name, bool firstUpper) - { - string[] strs = name.Split(new char[] { '_' }); - - string str = ""; - for (int i = 0, c = strs.Length; i < c; i++) - { - if (i == 0 && !firstUpper) - { - str += strs[i]; - continue; - } - str += ToUpperFirst(strs[i]); - } - - return str; - } - - public static string ToUpperFirst(string str) - { - return Regex.Replace(str, @"^\w", t => t.Value.ToUpper()); - } - - public string GetInsertCols(List<TabInfo> tabs) - { - List<string> excluds = this.txtInsert.Text.Trim().Split(new char[] { ',' }).ToList<string>(); - - StringBuilder sb = new StringBuilder(); - foreach (TabInfo ti in tabs) - { - if (excluds.Contains(ti.col)) - { - continue; - } - - sb.Append(ti.col + ","); - } - - if (sb.Length > 0) - { - sb.Remove(sb.Length - 1, 1); - } - - return sb.ToString(); - } - - public string GetInsertVal(List<TabInfo> tabs) - { - List<string> excluds = this.txtInsert.Text.Trim().Split(new char[] { ',' }).ToList<string>(); - - StringBuilder sb = new StringBuilder(); - foreach (TabInfo ti in tabs) - { - if (excluds.Contains(ti.col)) - { - continue; - } - if (ti.type == "timestamp(6)") - { - sb.Append("now(),"); - continue; - } - - sb.Append("#{" + NameConvert(ti.col, false) + "},"); - } - - if (sb.Length > 0) - { - sb.Remove(sb.Length - 1, 1); - } - - return sb.ToString(); - } - - public string GetInsertVals(List<TabInfo> tabs) - { - List<string> excluds = this.txtInsert.Text.Trim().Split(new char[] { ',' }).ToList<string>(); - - StringBuilder sb = new StringBuilder(); - foreach (TabInfo ti in tabs) - { - if (excluds.Contains(ti.col)) - { - continue; - } - if (ti.type == "timestamp(6)") - { - sb.Append("now(),"); - continue; - } - - sb.Append("#{item." + NameConvert(ti.col, false) + "},"); - } - - if (sb.Length > 0) - { - sb.Remove(sb.Length - 1, 1); - } - - return sb.ToString(); - } - - public string GetUpdateVal(List<TabInfo> tabs) - { - List<string> excluds = this.txtUpdate.Text.Trim().Split(new char[] { ',' }).ToList<string>(); - - StringBuilder sb = new StringBuilder(); - foreach (TabInfo ti in tabs) - { - if (excluds.Contains(ti.col)) - { - continue; - } - if (ti.type == "timestamp(6)") - { - sb.Append(ti.col + "=now(),"); - continue; - } - - sb.Append(ti.col + "=#{" + NameConvert(ti.col, false) + "},"); - } - - if (sb.Length > 0) - { - sb.Remove(sb.Length - 1, 1); - } - - return sb.ToString(); - } - - public string GetUpdateVals(List<TabInfo> tabs) - { - List<string> excluds = this.txtUpdate.Text.Trim().Split(new char[] { ',' }).ToList<string>(); - - StringBuilder sb = new StringBuilder(); - foreach (TabInfo ti in tabs) - { - if (excluds.Contains(ti.col)) - { - continue; - } - if (ti.type == "timestamp(6)") - { - sb.Append(ti.col + "=now(),"); - continue; - } - - sb.Append(ti.col + "=#{item." + NameConvert(ti.col, false) + "},"); - } - - if (sb.Length > 0) - { - sb.Remove(sb.Length - 1, 1); - } - - return sb.ToString(); - } - - private static void OpenFolder(string folderPath) - { - if (string.IsNullOrEmpty(folderPath)) return; - - Process process = new Process(); - ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe"); - psi.Arguments = folderPath; - process.StartInfo = psi; - - try - { - process.Start(); - } - catch (Exception ex) - { - throw ex; - } - finally - { - process.Close(); - } - } - #endregion - - #region 鐢熸垚 Mapper.java - private void mapperJava_Click(object sender, EventArgs e) - { - try - { - string name = this.tabList.SelectedItem as string; - List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); - - GenerateMapperJava(name, tabs); - - string path = Path.Combine(baseDir, "Generate"); - OpenFolder(path); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - private void GenerateMapperJava(string name, List<TabInfo> tabs) - { - name = name.Replace(this.txtTabPre.Text, ""); - - string shortName = NameConvert(name, true); - string mapperNS = this.txtMapperNS.Text.Trim(); - string entityNS = this.txtEntityNS.Text.Trim(); - string mapperName = shortName + "Mapper"; - string entityName = shortName + "Entity"; - string bak = tabs[0].desc.Replace("琛�", ""); - - int idx = this.dgvTab.CurrentRow.Index; - TabInfo selectTabInfo = tabs[idx]; - - string colType = GetJavaType(selectTabInfo); - string colName = NameConvert(selectTabInfo.col, false); - string queryCol = colType + " " + colName; - string colBak = selectTabInfo.bak; - - string xml = File.ReadAllText(Path.Combine(baseDir, "Template\\Mapper.java")); - xml = xml - .Replace("{mapperNS}", mapperNS) - .Replace("{mapperName}", mapperName) - .Replace("{entityNS}", entityNS) - .Replace("{entityName}", entityName) - .Replace("{colName}", colName) - .Replace("{colBak}", colBak) - .Replace("{bak}", bak) - .Replace("{queryCol}", queryCol); - - string path = Path.Combine(baseDir, "Generate"); - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - - string fileName = shortName + "Mapper.java"; - File.WriteAllText(Path.Combine(path, fileName), xml); - } - - private string GetJavaType(TabInfo ti) - { - string type = ti.type.Split(new char[] { '(' })[0]; - switch (type) - { - case "timestamp": - return "Timestamp"; - case "float4": // float - return "Float"; - case "float8": // double - return "Double"; - case "bool": // boolean - return "Boolean"; - case "numeric": - return "BigDecimal"; - case "int8": // long - return "Long"; - case "int2": - case "int4": // int - return "Integer"; - default: - return "String"; - } - } - - private String GetType(TabInfo ti) - { - string type = ti.type.Split(new char[] { '(' })[0]; - switch (type) - { - case "timestamp": - return "Timestamp"; - case "float4": - return "float"; - case "float8": - return "double"; - case "bool": - return "boolean"; - case "numeric": - return "BigDecimal"; - case "int8": - return "long"; - case "int2": - case "int4": - return "int"; - default: - return "String"; - } - } - #endregion - - #region 鐢熸垚 Entity.java - private void entityJava_Click(object sender, EventArgs e) - { - try - { - string name = this.tabList.SelectedItem as string; - List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); - - GenerateEntityJava(name, tabs); - - string path = Path.Combine(baseDir, "Generate"); - OpenFolder(path); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - private void GenerateEntityJava(string name, List<TabInfo> tabs) - { - name = name.Replace(this.txtTabPre.Text, ""); - - string shortName = NameConvert(name, true); - string entityNS = this.txtEntityNS.Text.Trim(); - string entityName = shortName + "Entity"; - string bak = tabs[0].desc.Replace("琛�", ""); - long uid = (long)Math.Floor((new Random()).NextDouble() * 1000000000000000000D); - - int idx = this.dgvTab.CurrentRow.Index; - TabInfo selectTabInfo = tabs[idx]; - - string xml = File.ReadAllText(Path.Combine(baseDir, "Template\\Entity.java")); - xml = xml - .Replace("{entityNS}", entityNS) - .Replace("{entityName}", entityName) - .Replace("{bak}", bak) - .Replace("{uid}", uid.ToString()); - - StringBuilder sb = new StringBuilder(); - foreach (TabInfo ti in tabs) - { - string type = GetType(ti); - string colName = NameConvert(ti.col, false); - sb.Append("\r\n private " + type + " " + colName + ";\r\n"); - } - - sb.Append("\r\n public " + entityName + "() {\r\n }\r\n"); - - foreach (TabInfo ti in tabs) - { - string type = GetType(ti); - string col1 = NameConvert(ti.col, true); - string col2 = NameConvert(ti.col, false); - - sb.Append("\r\n public " + type + " get" + col1 + "() {\r\n return " + col2 + ";\r\n }\r\n"); - sb.Append("\r\n public void set" + col1 + "(" + type + " " + col2 + ") {\r\n this." + col2 + " = " + col2 + ";\r\n }\r\n"); - } - sb.Append("}\r\n"); - - string path = Path.Combine(baseDir, "Generate"); - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - - sb.Insert(0, xml); - - string fileName = shortName + "Entity.java"; - File.WriteAllText(Path.Combine(path, fileName), sb.ToString()); - } - #endregion - - #region 鐢熸垚 Service.java - private void serviceJava_Click(object sender, EventArgs e) - { - try - { - string name = this.tabList.SelectedItem as string; - List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); - - GenerateServiceJava(name, tabs); - - string path = Path.Combine(baseDir, "Generate"); - OpenFolder(path); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - private void GenerateServiceJava(string name, List<TabInfo> tabs) - { - name = name.Replace(this.txtTabPre.Text, ""); - - string shortName = NameConvert(name, true); - string mapperNS = this.txtMapperNS.Text.Trim(); - string entityNS = this.txtEntityNS.Text.Trim(); - string serviceNS = this.txtServiceNS.Text.Trim(); - string mapperName = shortName + "Mapper"; - string minMapperName = NameConvert(name, false) + "Mapper"; - string entityName = shortName + "Entity"; - string serviceName = shortName + "Service"; - string bak = tabs[0].desc.Replace("琛�", ""); - - int idx = this.dgvTab.CurrentRow.Index; - TabInfo selectTabInfo = tabs[idx]; - - string colType = GetJavaType(selectTabInfo); - string colName = NameConvert(selectTabInfo.col, false); - string queryCol = colType + " " + colName; - - //string where = isString ? "\r\n " + colName + " = \"%\" + (StringHelper.isNull(" + colName + ") ? \"\" : " + colName + ".trim()) + \"%\";\r\n" : ""; - string where = colType == "String" ? "\r\n " + colName + " = StringHelper.isNull(" + colName + ") ? null : \"%\" + " + colName + ".trim() + \"%\";\r\n" : ""; - - string xml = File.ReadAllText(Path.Combine(baseDir, "Template\\Service.java")); - xml = xml - .Replace("{mapperNS}", mapperNS) - .Replace("{mapperName}", mapperName) - .Replace("{minMapperName}", minMapperName) - .Replace("{entityNS}", entityNS) - .Replace("{entityName}", entityName) - .Replace("{serviceNS}", serviceNS) - .Replace("{serviceName}", serviceName) - .Replace("{bak}", bak) - .Replace("{queryCol}", queryCol) - .Replace("{colName}", colName) - .Replace("{where}", where); - - string path = Path.Combine(baseDir, "Generate"); - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - - string fileName = shortName + "Service.java"; - File.WriteAllText(Path.Combine(path, fileName), xml); - } - #endregion - - #region 鐢熸垚 Controller.java - private void controllerJava_Click(object sender, EventArgs e) - { - try - { - string name = this.tabList.SelectedItem as string; - List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); - - GenerateControllerJava(name, tabs); - - string path = Path.Combine(baseDir, "Generate"); - OpenFolder(path); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - private void GenerateControllerJava(string name, List<TabInfo> tabs) - { - name = name.Replace(this.txtTabPre.Text, ""); - - string shortName = NameConvert(name, true); - string mapperNS = this.txtMapperNS.Text.Trim(); - string entityNS = this.txtEntityNS.Text.Trim(); - string serviceNS = this.txtServiceNS.Text.Trim(); - string controllerNS = this.txtControllerNS.Text.Trim(); - string apiTag = this.txtApiTag.Text.Trim(); - string mapperName = shortName + "Mapper"; - string entityName = shortName + "Entity"; - string serviceName = shortName + "Service"; - string minServiceName = NameConvert(name, false) + "Service"; - string controllerName = shortName + "Controller"; - string bak = tabs[0].desc.Replace("琛�", ""); - string apiName = NameConvert(name, false); - - int idx = this.dgvTab.CurrentRow.Index; - TabInfo selectTabInfo = tabs[idx]; - - string colType = GetJavaType(selectTabInfo); - string colName = NameConvert(selectTabInfo.col, false); - string queryCol = colType + " " + colName; - string colBak = selectTabInfo.bak; - - string xml = File.ReadAllText(Path.Combine(baseDir, "Template\\Controller.java")); - xml = xml - .Replace("{mapperNS}", mapperNS) - .Replace("{mapperName}", mapperName) - .Replace("{entityNS}", entityNS) - .Replace("{entityName}", entityName) - .Replace("{serviceNS}", serviceNS) - .Replace("{serviceName}", serviceName) - .Replace("{controllerNS}", controllerNS) - .Replace("{controllerName}", controllerName) - .Replace("{minServiceName}", minServiceName) - .Replace("{queryCol}", queryCol) - .Replace("{colName}", colName) - .Replace("{colBak}", colBak) - .Replace("{colType}", colType) - .Replace("{apiTag}", apiTag) - .Replace("{apiName}", apiName) - .Replace("{bak}", bak); - - string path = Path.Combine(baseDir, "Generate"); - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - - string fileName = shortName + "Controller.java"; - File.WriteAllText(Path.Combine(path, fileName), xml); - } - #endregion - - #region 鐢熸垚鎵�鏈夋枃浠� - private void generateAll_Click(object sender, EventArgs e) - { - try - { - string name = this.tabList.SelectedItem as string; - List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); - - GenerateMapperXml(name, tabs); - GenerateMapperJava(name, tabs); - GenerateEntityJava(name, tabs); - GenerateServiceJava(name, tabs); - GenerateControllerJava(name, tabs); - - string path = Path.Combine(baseDir, "Generate"); - OpenFolder(path); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - #endregion } } diff --git a/JavaCode/FrmMyBatisPlus.Designer.cs b/JavaCode/FrmMyBatisPlus.Designer.cs new file mode 100644 index 0000000..950f38a --- /dev/null +++ b/JavaCode/FrmMyBatisPlus.Designer.cs @@ -0,0 +1,231 @@ +锘縩amespace JavaCode +{ + partial class FrmMyBatisPlus + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + this.txtNS = new System.Windows.Forms.TextBox(); + this.txtTabPre = new System.Windows.Forms.TextBox(); + this.btnReadTab = new System.Windows.Forms.Button(); + this.tabList = new System.Windows.Forms.ListBox(); + this.dgvTab = new System.Windows.Forms.DataGridView(); + this.txtEntityNS = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtMapperNS = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.btnGenerate = new System.Windows.Forms.Button(); + this.btnAll = new System.Windows.Forms.Button(); + this.btnAnti = new System.Windows.Forms.Button(); + this.btnNone = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dgvTab)).BeginInit(); + this.SuspendLayout(); + // + // txtNS + // + this.txtNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtNS.Location = new System.Drawing.Point(12, 13); + this.txtNS.Name = "txtNS"; + this.txtNS.Size = new System.Drawing.Size(104, 26); + this.txtNS.TabIndex = 25; + this.txtNS.Text = "29257,20582"; + // + // txtTabPre + // + this.txtTabPre.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtTabPre.Location = new System.Drawing.Point(136, 13); + this.txtTabPre.Name = "txtTabPre"; + this.txtTabPre.Size = new System.Drawing.Size(98, 26); + this.txtTabPre.TabIndex = 24; + // + // btnReadTab + // + this.btnReadTab.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnReadTab.Location = new System.Drawing.Point(247, 15); + this.btnReadTab.Name = "btnReadTab"; + this.btnReadTab.Size = new System.Drawing.Size(118, 23); + this.btnReadTab.TabIndex = 23; + this.btnReadTab.Text = "璇诲彇鏁版嵁搴撹〃"; + this.btnReadTab.UseVisualStyleBackColor = true; + this.btnReadTab.Click += new System.EventHandler(this.btnReadTab_Click); + // + // tabList + // + this.tabList.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.tabList.FormattingEnabled = true; + this.tabList.ItemHeight = 16; + this.tabList.Location = new System.Drawing.Point(12, 86); + this.tabList.Name = "tabList"; + this.tabList.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple; + this.tabList.Size = new System.Drawing.Size(353, 212); + this.tabList.TabIndex = 22; + this.tabList.SelectedIndexChanged += new System.EventHandler(this.tabList_SelectedIndexChanged); + // + // dgvTab + // + this.dgvTab.AllowUserToAddRows = false; + this.dgvTab.AllowUserToDeleteRows = false; + this.dgvTab.BackgroundColor = System.Drawing.SystemColors.ButtonFace; + this.dgvTab.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvTab.Location = new System.Drawing.Point(12, 312); + this.dgvTab.Margin = new System.Windows.Forms.Padding(0); + this.dgvTab.MultiSelect = false; + this.dgvTab.Name = "dgvTab"; + this.dgvTab.ReadOnly = true; + this.dgvTab.RowHeadersWidth = 40; + this.dgvTab.RowTemplate.Height = 23; + this.dgvTab.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.dgvTab.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dgvTab.Size = new System.Drawing.Size(825, 300); + this.dgvTab.TabIndex = 26; + // + // txtEntityNS + // + this.txtEntityNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtEntityNS.Location = new System.Drawing.Point(525, 61); + this.txtEntityNS.Name = "txtEntityNS"; + this.txtEntityNS.Size = new System.Drawing.Size(312, 26); + this.txtEntityNS.TabIndex = 30; + this.txtEntityNS.Text = "com.lf.server.entity.db"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label3.Location = new System.Drawing.Point(385, 66); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(136, 16); + this.label3.TabIndex = 29; + this.label3.Text = "Entity鍚嶇О绌洪棿锛�"; + // + // txtMapperNS + // + this.txtMapperNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtMapperNS.Location = new System.Drawing.Point(525, 15); + this.txtMapperNS.Name = "txtMapperNS"; + this.txtMapperNS.Size = new System.Drawing.Size(312, 26); + this.txtMapperNS.TabIndex = 32; + this.txtMapperNS.Text = "com.lf.server.mapper.db"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label2.Location = new System.Drawing.Point(385, 20); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(136, 16); + this.label2.TabIndex = 31; + this.label2.Text = "Mapper鍚嶇О绌洪棿锛�"; + // + // btnGenerate + // + this.btnGenerate.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnGenerate.Location = new System.Drawing.Point(525, 115); + this.btnGenerate.Name = "btnGenerate"; + this.btnGenerate.Size = new System.Drawing.Size(312, 25); + this.btnGenerate.TabIndex = 33; + this.btnGenerate.Text = "鐢� 鎴� 鏂� 浠�"; + this.btnGenerate.UseVisualStyleBackColor = true; + this.btnGenerate.Click += new System.EventHandler(this.btnGenerate_Click); + // + // btnAll + // + this.btnAll.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnAll.Location = new System.Drawing.Point(12, 53); + this.btnAll.Name = "btnAll"; + this.btnAll.Size = new System.Drawing.Size(104, 23); + this.btnAll.TabIndex = 34; + this.btnAll.Text = "鍏� 閫�"; + this.btnAll.UseVisualStyleBackColor = true; + this.btnAll.Click += new System.EventHandler(this.btnAll_Click); + // + // btnAnti + // + this.btnAnti.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnAnti.Location = new System.Drawing.Point(136, 52); + this.btnAnti.Name = "btnAnti"; + this.btnAnti.Size = new System.Drawing.Size(98, 23); + this.btnAnti.TabIndex = 35; + this.btnAnti.Text = "鍙� 閫�"; + this.btnAnti.UseVisualStyleBackColor = true; + this.btnAnti.Click += new System.EventHandler(this.btnAnti_Click); + // + // btnNone + // + this.btnNone.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnNone.Location = new System.Drawing.Point(247, 52); + this.btnNone.Name = "btnNone"; + this.btnNone.Size = new System.Drawing.Size(118, 23); + this.btnNone.TabIndex = 36; + this.btnNone.Text = "鍏� 涓� 閫�"; + this.btnNone.UseVisualStyleBackColor = true; + this.btnNone.Click += new System.EventHandler(this.btnNone_Click); + // + // FrmMyBatisPlus + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(852, 628); + this.Controls.Add(this.btnNone); + this.Controls.Add(this.btnAnti); + this.Controls.Add(this.btnAll); + this.Controls.Add(this.btnGenerate); + this.Controls.Add(this.txtMapperNS); + this.Controls.Add(this.label2); + this.Controls.Add(this.txtEntityNS); + this.Controls.Add(this.label3); + this.Controls.Add(this.dgvTab); + this.Controls.Add(this.txtNS); + this.Controls.Add(this.txtTabPre); + this.Controls.Add(this.btnReadTab); + this.Controls.Add(this.tabList); + this.Name = "FrmMyBatisPlus"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "FrmMyBatisPlus"; + this.Load += new System.EventHandler(this.FrmMyBatisPlus_Load); + ((System.ComponentModel.ISupportInitialize)(this.dgvTab)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox txtNS; + private System.Windows.Forms.TextBox txtTabPre; + private System.Windows.Forms.Button btnReadTab; + private System.Windows.Forms.ListBox tabList; + private System.Windows.Forms.DataGridView dgvTab; + private System.Windows.Forms.TextBox txtEntityNS; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtMapperNS; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button btnGenerate; + private System.Windows.Forms.Button btnAll; + private System.Windows.Forms.Button btnAnti; + private System.Windows.Forms.Button btnNone; + } +} \ No newline at end of file diff --git a/JavaCode/FrmMyBatisPlus.cs b/JavaCode/FrmMyBatisPlus.cs new file mode 100644 index 0000000..9958b53 --- /dev/null +++ b/JavaCode/FrmMyBatisPlus.cs @@ -0,0 +1,120 @@ +锘縰sing JavaCode.cs; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JavaCode +{ + public partial class FrmMyBatisPlus : Form + { + #region 鎴愬憳鍙橀噺+鏋勯�犲嚱鏁� + string baseDir = AppDomain.CurrentDomain.BaseDirectory; + + private PostgreHelper _dbHelper; + + private List<TabInfo> _list; + + public FrmMyBatisPlus() + { + InitializeComponent(); + } + + private void FrmMyBatisPlus_Load(object sender, EventArgs e) + { + _dbHelper = new PostgreHelper(DbEnum.langfang); + } + #endregion + + // 135502,69701 29257,20582 + private void btnReadTab_Click(object sender, EventArgs e) + { + try + { + string tabName = this.txtTabPre.Text.Trim(); + string tabFilter = string.IsNullOrEmpty(tabName) ? "" : string.Format("and c.relname like '{0}%'", tabName); + + string sql = string.Format("select c.relname as \"tab\", cast(obj_description(c.oid) as varchar) as \"desc\", a.attnum as \"num\", a.attname as \"col\",concat_ws('', t.typname, SUBSTRING(format_type(a.atttypid, a.atttypmod) from '(.*)')) as \"type\", d.description as \"bak\" from pg_attribute a left join pg_description d on d.objoid = a.attrelid and d.objsubid = a.attnum left join pg_class c on a.attrelid = c.oid left join pg_type t on a.atttypid = t.oid where a.attnum >= 0 and reltype>0 and relnamespace in ({0}) {1} order by c.relname desc, a.attnum asc", this.txtNS.Text.Trim(), tabFilter); + + DataTable dt = _dbHelper.GetDataTable(sql, null); + _list = ModelHandler.FillModel<TabInfo>(dt); + if (_list == null || _list.Count == 0) + { + MessageBox.Show("娌℃湁鏌ヨ鍒版暟鎹紒"); + return; + } + + List<string> tabList = new List<string>(); + foreach (TabInfo ti in _list) + { + if (!tabList.Contains(ti.tab)) + { + tabList.Add(ti.tab); + } + } + this.tabList.DataSource = tabList; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void btnAll_Click(object sender, EventArgs e) + { + for (int i = 0; i < this.tabList.Items.Count; i++) + { + this.tabList.SetSelected(i, true); + } + } + + private void btnAnti_Click(object sender, EventArgs e) + { + for (int i = 0; i < this.tabList.Items.Count; i++) + { + bool flag = this.tabList.GetSelected(i); + this.tabList.SetSelected(i, !flag); + } + } + + private void btnNone_Click(object sender, EventArgs e) + { + for (int i = 0; i < this.tabList.Items.Count; i++) + { + this.tabList.SetSelected(i, false); + } + } + + private void tabList_SelectedIndexChanged(object sender, EventArgs e) + { + string tab = this.tabList.SelectedItem as string; + List<TabInfo> tabs = (from p in _list where p.tab == tab orderby p.num select p).ToList<TabInfo>(); + + this.dgvTab.DataSource = new BindingList<TabInfo>(tabs); + if (tabs != null && tabs.Count > 1) + { + this.dgvTab.Rows[1].Selected = true; + this.dgvTab.CurrentCell = this.dgvTab.Rows[1].Cells[0]; + } + } + + private void btnGenerate_Click(object sender, EventArgs e) + { + // + } + + private String QueryPrimaryKey(string tab) + { + string sql = string.Format("select pg_attribute.attname as colname from pg_constraint inner join pg_class on pg_constraint.conrelid = pg_class.oid inner join pg_attribute on pg_attribute.attrelid = pg_class.oid and pg_attribute.attnum = pg_constraint.conkey[1] inner join pg_type on pg_type.oid = pg_attribute.atttypid where pg_class.relname = '{0}' and pg_constraint.contype='p'", tab); + + object obj = _dbHelper.GetScalar(sql, null); + + return obj == null ? null : obj.ToString(); + } + } +} diff --git a/JavaCode/FrmMyBatisPlus.resx b/JavaCode/FrmMyBatisPlus.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JavaCode/FrmMyBatisPlus.resx @@ -0,0 +1,120 @@ +锘�<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root> \ No newline at end of file diff --git a/JavaCode/FrmSys.Designer.cs b/JavaCode/FrmSys.Designer.cs new file mode 100644 index 0000000..1f245e1 --- /dev/null +++ b/JavaCode/FrmSys.Designer.cs @@ -0,0 +1,410 @@ +锘縩amespace JavaCode +{ + partial class FrmSys + { + /// <summary> + /// 蹇呴渶鐨勮璁″櫒鍙橀噺銆� + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// 娓呯悊鎵�鏈夋鍦ㄤ娇鐢ㄧ殑璧勬簮銆� + /// </summary> + /// <param name="disposing">濡傛灉搴旈噴鏀炬墭绠¤祫婧愶紝涓� true锛涘惁鍒欎负 false銆�</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 绐椾綋璁捐鍣ㄧ敓鎴愮殑浠g爜 + + /// <summary> + /// 璁捐鍣ㄦ敮鎸佹墍闇�鐨勬柟娉� - 涓嶈 + /// 浣跨敤浠g爜缂栬緫鍣ㄤ慨鏀规鏂规硶鐨勫唴瀹广�� + /// </summary> + private void InitializeComponent() + { + this.tabList = new System.Windows.Forms.ListBox(); + this.btnReadTab = new System.Windows.Forms.Button(); + this.txtTabPre = new System.Windows.Forms.TextBox(); + this.txtMapperNS = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.txtEntityNS = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.button4 = new System.Windows.Forms.Button(); + this.dgvTab = new System.Windows.Forms.DataGridView(); + this.label4 = new System.Windows.Forms.Label(); + this.txtInsert = new System.Windows.Forms.TextBox(); + this.txtUpdate = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.button5 = new System.Windows.Forms.Button(); + this.button6 = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.txtNS = new System.Windows.Forms.TextBox(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.txtServiceNS = new System.Windows.Forms.TextBox(); + this.label6 = new System.Windows.Forms.Label(); + this.txtControllerNS = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.txtApiTag = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.txtTabNS = new System.Windows.Forms.TextBox(); + ((System.ComponentModel.ISupportInitialize)(this.dgvTab)).BeginInit(); + this.SuspendLayout(); + // + // tabList + // + this.tabList.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.tabList.FormattingEnabled = true; + this.tabList.ItemHeight = 16; + this.tabList.Location = new System.Drawing.Point(12, 49); + this.tabList.Name = "tabList"; + this.tabList.Size = new System.Drawing.Size(353, 244); + this.tabList.TabIndex = 0; + this.tabList.SelectedIndexChanged += new System.EventHandler(this.tabList_SelectedIndexChanged); + // + // btnReadTab + // + this.btnReadTab.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnReadTab.Location = new System.Drawing.Point(247, 13); + this.btnReadTab.Name = "btnReadTab"; + this.btnReadTab.Size = new System.Drawing.Size(118, 23); + this.btnReadTab.TabIndex = 1; + this.btnReadTab.Text = "璇诲彇鏁版嵁搴撹〃"; + this.btnReadTab.UseVisualStyleBackColor = true; + this.btnReadTab.Click += new System.EventHandler(this.btnReadTab_Click); + // + // txtTabPre + // + this.txtTabPre.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtTabPre.Location = new System.Drawing.Point(129, 10); + this.txtTabPre.Name = "txtTabPre"; + this.txtTabPre.Size = new System.Drawing.Size(100, 26); + this.txtTabPre.TabIndex = 2; + this.txtTabPre.Text = "sys_"; + // + // txtMapperNS + // + this.txtMapperNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtMapperNS.Location = new System.Drawing.Point(529, 51); + this.txtMapperNS.Name = "txtMapperNS"; + this.txtMapperNS.Size = new System.Drawing.Size(339, 26); + this.txtMapperNS.TabIndex = 9; + this.txtMapperNS.Text = "com.lf.server.mapper.sys"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label2.Location = new System.Drawing.Point(389, 56); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(136, 16); + this.label2.TabIndex = 8; + this.label2.Text = "Mapper鍚嶇О绌洪棿锛�"; + // + // txtEntityNS + // + this.txtEntityNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtEntityNS.Location = new System.Drawing.Point(529, 88); + this.txtEntityNS.Name = "txtEntityNS"; + this.txtEntityNS.Size = new System.Drawing.Size(339, 26); + this.txtEntityNS.TabIndex = 11; + this.txtEntityNS.Text = "com.lf.server.entity.sys"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label3.Location = new System.Drawing.Point(389, 93); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(136, 16); + this.label3.TabIndex = 10; + this.label3.Text = "Entity鍚嶇О绌洪棿锛�"; + // + // button4 + // + this.button4.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button4.Location = new System.Drawing.Point(885, 202); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(183, 25); + this.button4.TabIndex = 12; + this.button4.Text = "鐢� 鎴� 鎵� 鏈� 鏂� 浠�"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.generateAll_Click); + // + // dgvTab + // + this.dgvTab.AllowUserToAddRows = false; + this.dgvTab.AllowUserToDeleteRows = false; + this.dgvTab.BackgroundColor = System.Drawing.SystemColors.ButtonFace; + this.dgvTab.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvTab.Location = new System.Drawing.Point(12, 312); + this.dgvTab.Margin = new System.Windows.Forms.Padding(0); + this.dgvTab.MultiSelect = false; + this.dgvTab.Name = "dgvTab"; + this.dgvTab.ReadOnly = true; + this.dgvTab.RowHeadersWidth = 40; + this.dgvTab.RowTemplate.Height = 23; + this.dgvTab.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.dgvTab.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dgvTab.Size = new System.Drawing.Size(1056, 300); + this.dgvTab.TabIndex = 13; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label4.Location = new System.Drawing.Point(387, 241); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(136, 16); + this.label4.TabIndex = 14; + this.label4.Text = "鎻掑叆鏃舵帓闄ゅ瓧娈碉細"; + // + // txtInsert + // + this.txtInsert.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtInsert.Location = new System.Drawing.Point(529, 236); + this.txtInsert.Name = "txtInsert"; + this.txtInsert.Size = new System.Drawing.Size(339, 26); + this.txtInsert.TabIndex = 15; + this.txtInsert.Text = "id,update_user,update_time"; + // + // txtUpdate + // + this.txtUpdate.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtUpdate.Location = new System.Drawing.Point(529, 271); + this.txtUpdate.Name = "txtUpdate"; + this.txtUpdate.Size = new System.Drawing.Size(339, 26); + this.txtUpdate.TabIndex = 17; + this.txtUpdate.Text = "id,create_user,create_time"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label5.Location = new System.Drawing.Point(387, 276); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(136, 16); + this.label5.TabIndex = 16; + this.label5.Text = "鏇存柊鏃舵帓闄ゅ瓧娈碉細"; + // + // button5 + // + this.button5.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button5.Location = new System.Drawing.Point(885, 14); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(183, 25); + this.button5.TabIndex = 18; + this.button5.Text = "鐢� 鎴� Mapper.xml"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.mapperXml_Click); + // + // button6 + // + this.button6.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button6.Location = new System.Drawing.Point(885, 52); + this.button6.Name = "button6"; + this.button6.Size = new System.Drawing.Size(183, 25); + this.button6.TabIndex = 19; + this.button6.Text = "鐢� 鎴� Mapper.java"; + this.button6.UseVisualStyleBackColor = true; + this.button6.Click += new System.EventHandler(this.mapperJava_Click); + // + // button1 + // + this.button1.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button1.Location = new System.Drawing.Point(885, 89); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(183, 25); + this.button1.TabIndex = 20; + this.button1.Text = "鐢� 鎴� Entity.java"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.entityJava_Click); + // + // txtNS + // + this.txtNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtNS.Location = new System.Drawing.Point(12, 10); + this.txtNS.Name = "txtNS"; + this.txtNS.Size = new System.Drawing.Size(100, 26); + this.txtNS.TabIndex = 21; + this.txtNS.Text = "20582"; + // + // button2 + // + this.button2.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button2.Location = new System.Drawing.Point(885, 127); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(183, 25); + this.button2.TabIndex = 22; + this.button2.Text = "鐢� 鎴� Service.java"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.serviceJava_Click); + // + // button3 + // + this.button3.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.button3.Location = new System.Drawing.Point(885, 165); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(183, 25); + this.button3.TabIndex = 23; + this.button3.Text = "鐢熸垚 Controller.java"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.controllerJava_Click); + // + // txtServiceNS + // + this.txtServiceNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtServiceNS.Location = new System.Drawing.Point(529, 126); + this.txtServiceNS.Name = "txtServiceNS"; + this.txtServiceNS.Size = new System.Drawing.Size(339, 26); + this.txtServiceNS.TabIndex = 25; + this.txtServiceNS.Text = "com.lf.server.service.sys"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label6.Location = new System.Drawing.Point(381, 131); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(144, 16); + this.label6.TabIndex = 24; + this.label6.Text = "Service鍚嶇О绌洪棿锛�"; + // + // txtControllerNS + // + this.txtControllerNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtControllerNS.Location = new System.Drawing.Point(529, 164); + this.txtControllerNS.Name = "txtControllerNS"; + this.txtControllerNS.Size = new System.Drawing.Size(339, 26); + this.txtControllerNS.TabIndex = 27; + this.txtControllerNS.Text = "com.lf.server.controller.sys"; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label7.Location = new System.Drawing.Point(365, 169); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(160, 16); + this.label7.TabIndex = 26; + this.label7.Text = "Controller鍚嶇О绌洪棿:"; + // + // txtApiTag + // + this.txtApiTag.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtApiTag.Location = new System.Drawing.Point(529, 201); + this.txtApiTag.Name = "txtApiTag"; + this.txtApiTag.Size = new System.Drawing.Size(339, 26); + this.txtApiTag.TabIndex = 29; + this.txtApiTag.Text = "杩愮淮绠$悊\\\\{bak}"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label8.Location = new System.Drawing.Point(445, 206); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(80, 16); + this.label8.TabIndex = 28; + this.label8.Text = "Api鏍囪瘑锛�"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label1.Location = new System.Drawing.Point(437, 18); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(88, 16); + this.label1.TabIndex = 6; + this.label1.Text = "琛ㄥ悕鍓嶇紑锛�"; + // + // txtTabNS + // + this.txtTabNS.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.txtTabNS.Location = new System.Drawing.Point(529, 13); + this.txtTabNS.Name = "txtTabNS"; + this.txtTabNS.Size = new System.Drawing.Size(339, 26); + this.txtTabNS.TabIndex = 7; + this.txtTabNS.Text = "lf."; + // + // FrmSys + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1095, 630); + this.Controls.Add(this.txtApiTag); + this.Controls.Add(this.label8); + this.Controls.Add(this.txtControllerNS); + this.Controls.Add(this.label7); + this.Controls.Add(this.txtServiceNS); + this.Controls.Add(this.label6); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.txtNS); + this.Controls.Add(this.button1); + this.Controls.Add(this.button6); + this.Controls.Add(this.button5); + this.Controls.Add(this.txtUpdate); + this.Controls.Add(this.label5); + this.Controls.Add(this.txtInsert); + this.Controls.Add(this.label4); + this.Controls.Add(this.dgvTab); + this.Controls.Add(this.button4); + this.Controls.Add(this.txtEntityNS); + this.Controls.Add(this.label3); + this.Controls.Add(this.txtMapperNS); + this.Controls.Add(this.label2); + this.Controls.Add(this.txtTabNS); + this.Controls.Add(this.label1); + this.Controls.Add(this.txtTabPre); + this.Controls.Add(this.btnReadTab); + this.Controls.Add(this.tabList); + this.Name = "FrmSys"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "FrmSys"; + this.Load += new System.EventHandler(this.FrmMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dgvTab)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ListBox tabList; + private System.Windows.Forms.Button btnReadTab; + private System.Windows.Forms.TextBox txtTabPre; + private System.Windows.Forms.TextBox txtMapperNS; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtEntityNS; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.DataGridView dgvTab; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox txtInsert; + private System.Windows.Forms.TextBox txtUpdate; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.Button button6; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.TextBox txtNS; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.TextBox txtServiceNS; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox txtControllerNS; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.TextBox txtApiTag; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txtTabNS; + } +} + diff --git a/JavaCode/FrmSys.cs b/JavaCode/FrmSys.cs new file mode 100644 index 0000000..5632b57 --- /dev/null +++ b/JavaCode/FrmSys.cs @@ -0,0 +1,677 @@ +锘縰sing JavaCode.cs; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JavaCode +{ + public partial class FrmSys : Form + { + #region 鎴愬憳鍙橀噺+鏋勯�犲嚱鏁� + string baseDir = AppDomain.CurrentDomain.BaseDirectory; + + private PostgreHelper _dbHelper; + + private List<TabInfo> _list; + + public FrmSys() + { + InitializeComponent(); + } + + private void FrmMain_Load(object sender, EventArgs e) + { + _dbHelper = new PostgreHelper(DbEnum.langfang); + } + #endregion + + #region 鏌ヨ琛ㄧ粨鏋� + private void btnReadTab_Click(object sender, EventArgs e) + { + string txtTab = this.txtTabPre.Text.Trim(); + string sql = "select c.relname \"tab\", cast(obj_description(c.oid) as varchar) \"desc\", a.attnum \"num\", a.attname \"col\", t.typname \"type\", d.description \"bak\" from pg_attribute a left join pg_description d on d.objoid = a.attrelid and d.objsubid = a.attnum left join pg_class c on a.attrelid = c.oid left join pg_type t on a.atttypid = t.oid where a.attnum >= 0 and c.relname like '" + txtTab + "%' and obj_description(c.oid) is not null and relnamespace=" + this.txtNS.Text.Trim() + " order by c.relname desc, a.attnum asc"; + + DataTable dt = _dbHelper.GetDataTable(sql, null); + + _list = ModelHandler.FillModel<TabInfo>(dt); + if (_list == null || _list.Count == 0) + { + MessageBox.Show("娌℃湁鏌ヨ鍒版暟鎹紒"); + return; + } + + List<string> tabList = new List<string>(); + foreach (TabInfo ti in _list) + { + if (!tabList.Contains(ti.tab)) + { + tabList.Add(ti.tab); + } + } + + this.tabList.DataSource = tabList; + } + + private void tabList_SelectedIndexChanged(object sender, EventArgs e) + { + string tab = this.tabList.SelectedItem as string; + List<TabInfo> tabs = (from p in _list where p.tab == tab orderby p.num select p).ToList<TabInfo>(); + + this.dgvTab.DataSource = new BindingList<TabInfo>(tabs); + if (tabs != null && tabs.Count > 1) + { + this.dgvTab.Rows[1].Selected = true; + this.dgvTab.CurrentCell = this.dgvTab.Rows[1].Cells[0]; + } + } + #endregion + + #region 鐢熸垚 Mapper.Xml + private void mapperXml_Click(object sender, EventArgs e) + { + try + { + string name = this.tabList.SelectedItem as string; + List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); + + GenerateMapperXml(name, tabs); + + string path = Path.Combine(baseDir, "SysGenerate"); + OpenFolder(path); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void GenerateMapperXml(string name, List<TabInfo> tabs) + { + string tabName = this.txtTabNS.Text.Trim() + name; + name = name.Replace(this.txtTabPre.Text, ""); + + string shortName = NameConvert(name, true); + string mapperNS = this.txtMapperNS.Text.Trim(); + string mapperName = shortName + "Mapper"; + string entityNS = this.txtEntityNS.Text.Trim(); + string entityName = shortName + "Entity"; + + int idx = this.dgvTab.CurrentRow.Index; + TabInfo selectTabInfo = tabs[idx]; + + string colType = GetJavaType(selectTabInfo); + string colName = NameConvert(selectTabInfo.col, false); + string testExpr = colName + " != null"; + string testWhere = selectTabInfo.col + (colType == "String" ? " like " : " = ") + "#{" + colName + "}"; + + string insertCols = GetInsertCols(tabs); + string insertVal = GetInsertVal(tabs); + string insertVals = GetInsertVals(tabs); + string updateVal = GetUpdateVal(tabs); + string updateVals = GetUpdateVals(tabs); + + string xml = File.ReadAllText(Path.Combine(baseDir, "SysTemplate\\Mapper.xml")); + xml = xml + .Replace("{mapperNS}", mapperNS) + .Replace("{mapperName}", mapperName) + .Replace("{tabName}", tabName) + .Replace("{testExpr}", testExpr) + .Replace("{testWhere}", testWhere) + .Replace("{entityNS}", entityNS) + .Replace("{entityName}", entityName) + .Replace("{insertCols}", insertCols) + .Replace("{insertVal}", insertVal) + .Replace("{insertVals}", insertVals) + .Replace("{updateVal}", updateVal) + .Replace("{updateVals}", updateVals); + + string path = Path.Combine(baseDir, "SysGenerate"); + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + string fileName = shortName + "Mapper.xml"; + File.WriteAllText(Path.Combine(path, fileName), xml); + } + + private static string NameConvert(string name, bool firstUpper) + { + string[] strs = name.Split(new char[] { '_' }); + + string str = ""; + for (int i = 0, c = strs.Length; i < c; i++) + { + if (i == 0 && !firstUpper) + { + str += strs[i]; + continue; + } + str += ToUpperFirst(strs[i]); + } + + return str; + } + + public static string ToUpperFirst(string str) + { + return Regex.Replace(str, @"^\w", t => t.Value.ToUpper()); + } + + public string GetInsertCols(List<TabInfo> tabs) + { + List<string> excluds = this.txtInsert.Text.Trim().Split(new char[] { ',' }).ToList<string>(); + + StringBuilder sb = new StringBuilder(); + foreach (TabInfo ti in tabs) + { + if (excluds.Contains(ti.col)) + { + continue; + } + + sb.Append(ti.col + ","); + } + + if (sb.Length > 0) + { + sb.Remove(sb.Length - 1, 1); + } + + return sb.ToString(); + } + + public string GetInsertVal(List<TabInfo> tabs) + { + List<string> excluds = this.txtInsert.Text.Trim().Split(new char[] { ',' }).ToList<string>(); + + StringBuilder sb = new StringBuilder(); + foreach (TabInfo ti in tabs) + { + if (excluds.Contains(ti.col)) + { + continue; + } + if (ti.type == "timestamp") + { + sb.Append("now(),"); + continue; + } + + sb.Append("#{" + NameConvert(ti.col, false) + "},"); + } + + if (sb.Length > 0) + { + sb.Remove(sb.Length - 1, 1); + } + + return sb.ToString(); + } + + public string GetInsertVals(List<TabInfo> tabs) + { + List<string> excluds = this.txtInsert.Text.Trim().Split(new char[] { ',' }).ToList<string>(); + + StringBuilder sb = new StringBuilder(); + foreach (TabInfo ti in tabs) + { + if (excluds.Contains(ti.col)) + { + continue; + } + if (ti.type == "timestamp") + { + sb.Append("now(),"); + continue; + } + + sb.Append("#{item." + NameConvert(ti.col, false) + "},"); + } + + if (sb.Length > 0) + { + sb.Remove(sb.Length - 1, 1); + } + + return sb.ToString(); + } + + public string GetUpdateVal(List<TabInfo> tabs) + { + List<string> excluds = this.txtUpdate.Text.Trim().Split(new char[] { ',' }).ToList<string>(); + + StringBuilder sb = new StringBuilder(); + foreach (TabInfo ti in tabs) + { + if (excluds.Contains(ti.col)) + { + continue; + } + if (ti.type == "timestamp") + { + sb.Append(ti.col + "=now(),"); + continue; + } + + sb.Append(ti.col + "=#{" + NameConvert(ti.col, false) + "},"); + } + + if (sb.Length > 0) + { + sb.Remove(sb.Length - 1, 1); + } + + return sb.ToString(); + } + + public string GetUpdateVals(List<TabInfo> tabs) + { + List<string> excluds = this.txtUpdate.Text.Trim().Split(new char[] { ',' }).ToList<string>(); + + StringBuilder sb = new StringBuilder(); + foreach (TabInfo ti in tabs) + { + if (excluds.Contains(ti.col)) + { + continue; + } + if (ti.type == "timestamp") + { + sb.Append(ti.col + "=now(),"); + continue; + } + + sb.Append(ti.col + "=#{item." + NameConvert(ti.col, false) + "},"); + } + + if (sb.Length > 0) + { + sb.Remove(sb.Length - 1, 1); + } + + return sb.ToString(); + } + + private static void OpenFolder(string folderPath) + { + if (string.IsNullOrEmpty(folderPath)) return; + + Process process = new Process(); + ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe"); + psi.Arguments = folderPath; + process.StartInfo = psi; + + try + { + process.Start(); + } + catch (Exception ex) + { + throw ex; + } + finally + { + process.Close(); + } + } + #endregion + + #region 鐢熸垚 Mapper.java + private void mapperJava_Click(object sender, EventArgs e) + { + try + { + string name = this.tabList.SelectedItem as string; + List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); + + GenerateMapperJava(name, tabs); + + string path = Path.Combine(baseDir, "SysGenerate"); + OpenFolder(path); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void GenerateMapperJava(string name, List<TabInfo> tabs) + { + name = name.Replace(this.txtTabPre.Text, ""); + + string shortName = NameConvert(name, true); + string mapperNS = this.txtMapperNS.Text.Trim(); + string entityNS = this.txtEntityNS.Text.Trim(); + string mapperName = shortName + "Mapper"; + string entityName = shortName + "Entity"; + string bak = tabs[0].desc.Replace("琛�", ""); + + int idx = this.dgvTab.CurrentRow.Index; + TabInfo selectTabInfo = tabs[idx]; + + string colType = GetJavaType(selectTabInfo); + string colName = NameConvert(selectTabInfo.col, false); + string queryCol = colType + " " + colName; + string colBak = selectTabInfo.bak; + + string xml = File.ReadAllText(Path.Combine(baseDir, "SysTemplate\\Mapper.java")); + xml = xml + .Replace("{mapperNS}", mapperNS) + .Replace("{mapperName}", mapperName) + .Replace("{entityNS}", entityNS) + .Replace("{entityName}", entityName) + .Replace("{colName}", colName) + .Replace("{colBak}", colBak) + .Replace("{bak}", bak) + .Replace("{queryCol}", queryCol); + + string path = Path.Combine(baseDir, "SysGenerate"); + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + string fileName = shortName + "Mapper.java"; + File.WriteAllText(Path.Combine(path, fileName), xml); + } + + private string GetJavaType(TabInfo ti) + { + switch (ti.type) + { + case "timestamp": + return "Timestamp"; + case "float4": // float + return "Float"; + case "float8": // double + return "Double"; + case "bool": // boolean + return "Boolean"; + case "numeric": + return "BigDecimal"; + case "int8": // long + return "Long"; + case "int2": + case "int4": // int + return "Integer"; + default: + return "String"; + } + } + + private String GetType(TabInfo ti) + { + switch (ti.type) + { + case "timestamp": + return "Timestamp"; + case "float4": + return "float"; + case "float8": + return "double"; + case "bool": + return "boolean"; + case "numeric": + return "BigDecimal"; + case "int8": + return "long"; + case "int2": + case "int4": + return "int"; + default: + return "String"; + } + } + #endregion + + #region 鐢熸垚 Entity.java + private void entityJava_Click(object sender, EventArgs e) + { + try + { + string name = this.tabList.SelectedItem as string; + List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); + + GenerateEntityJava(name, tabs); + + string path = Path.Combine(baseDir, "SysGenerate"); + OpenFolder(path); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void GenerateEntityJava(string name, List<TabInfo> tabs) + { + name = name.Replace(this.txtTabPre.Text, ""); + + string shortName = NameConvert(name, true); + string entityNS = this.txtEntityNS.Text.Trim(); + string entityName = shortName + "Entity"; + string bak = tabs[0].desc.Replace("琛�", ""); + long uid = (long)Math.Floor((new Random()).NextDouble() * 1000000000000000000D); + + int idx = this.dgvTab.CurrentRow.Index; + TabInfo selectTabInfo = tabs[idx]; + + string xml = File.ReadAllText(Path.Combine(baseDir, "SysTemplate\\Entity.java")); + xml = xml + .Replace("{entityNS}", entityNS) + .Replace("{entityName}", entityName) + .Replace("{bak}", bak) + .Replace("{uid}", uid.ToString()); + + StringBuilder sb = new StringBuilder(); + foreach (TabInfo ti in tabs) + { + string type = GetType(ti); + string colName = NameConvert(ti.col, false); + sb.Append("\r\n private " + type + " " + colName + ";\r\n"); + } + + sb.Append("\r\n public " + entityName + "() {\r\n }\r\n"); + + foreach (TabInfo ti in tabs) + { + string type = GetType(ti); + string col1 = NameConvert(ti.col, true); + string col2 = NameConvert(ti.col, false); + + sb.Append("\r\n public " + type + " get" + col1 + "() {\r\n return " + col2 + ";\r\n }\r\n"); + sb.Append("\r\n public void set" + col1 + "(" + type + " " + col2 + ") {\r\n this." + col2 + " = " + col2 + ";\r\n }\r\n"); + } + sb.Append("}\r\n"); + + string path = Path.Combine(baseDir, "SysGenerate"); + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + sb.Insert(0, xml); + + string fileName = shortName + "Entity.java"; + File.WriteAllText(Path.Combine(path, fileName), sb.ToString()); + } + #endregion + + #region 鐢熸垚 Service.java + private void serviceJava_Click(object sender, EventArgs e) + { + try + { + string name = this.tabList.SelectedItem as string; + List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); + + GenerateServiceJava(name, tabs); + + string path = Path.Combine(baseDir, "SysGenerate"); + OpenFolder(path); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void GenerateServiceJava(string name, List<TabInfo> tabs) + { + name = name.Replace(this.txtTabPre.Text, ""); + + string shortName = NameConvert(name, true); + string mapperNS = this.txtMapperNS.Text.Trim(); + string entityNS = this.txtEntityNS.Text.Trim(); + string serviceNS = this.txtServiceNS.Text.Trim(); + string mapperName = shortName + "Mapper"; + string minMapperName = NameConvert(name, false) + "Mapper"; + string entityName = shortName + "Entity"; + string serviceName = shortName + "Service"; + string bak = tabs[0].desc.Replace("琛�", ""); + + int idx = this.dgvTab.CurrentRow.Index; + TabInfo selectTabInfo = tabs[idx]; + + string colType = GetJavaType(selectTabInfo); + string colName = NameConvert(selectTabInfo.col, false); + string queryCol = colType + " " + colName; + + //string where = isString ? "\r\n " + colName + " = \"%\" + (StringHelper.isNull(" + colName + ") ? \"\" : " + colName + ".trim()) + \"%\";\r\n" : ""; + string where = colType == "String" ? "\r\n " + colName + " = StringHelper.isNull(" + colName + ") ? null : \"%\" + " + colName + ".trim() + \"%\";\r\n" : ""; + + string xml = File.ReadAllText(Path.Combine(baseDir, "SysTemplate\\Service.java")); + xml = xml + .Replace("{mapperNS}", mapperNS) + .Replace("{mapperName}", mapperName) + .Replace("{minMapperName}", minMapperName) + .Replace("{entityNS}", entityNS) + .Replace("{entityName}", entityName) + .Replace("{serviceNS}", serviceNS) + .Replace("{serviceName}", serviceName) + .Replace("{bak}", bak) + .Replace("{queryCol}", queryCol) + .Replace("{colName}", colName) + .Replace("{where}", where); + + string path = Path.Combine(baseDir, "SysGenerate"); + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + string fileName = shortName + "Service.java"; + File.WriteAllText(Path.Combine(path, fileName), xml); + } + #endregion + + #region 鐢熸垚 Controller.java + private void controllerJava_Click(object sender, EventArgs e) + { + try + { + string name = this.tabList.SelectedItem as string; + List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); + + GenerateControllerJava(name, tabs); + + string path = Path.Combine(baseDir, "SysGenerate"); + OpenFolder(path); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void GenerateControllerJava(string name, List<TabInfo> tabs) + { + name = name.Replace(this.txtTabPre.Text, ""); + + string shortName = NameConvert(name, true); + string mapperNS = this.txtMapperNS.Text.Trim(); + string entityNS = this.txtEntityNS.Text.Trim(); + string serviceNS = this.txtServiceNS.Text.Trim(); + string controllerNS = this.txtControllerNS.Text.Trim(); + string apiTag = this.txtApiTag.Text.Trim(); + string mapperName = shortName + "Mapper"; + string entityName = shortName + "Entity"; + string serviceName = shortName + "Service"; + string minServiceName = NameConvert(name, false) + "Service"; + string controllerName = shortName + "Controller"; + string bak = tabs[0].desc.Replace("琛�", ""); + string apiName = NameConvert(name, false); + + int idx = this.dgvTab.CurrentRow.Index; + TabInfo selectTabInfo = tabs[idx]; + + string colType = GetJavaType(selectTabInfo); + string colName = NameConvert(selectTabInfo.col, false); + string queryCol = colType + " " + colName; + string colBak = selectTabInfo.bak; + + string xml = File.ReadAllText(Path.Combine(baseDir, "SysTemplate\\Controller.java")); + xml = xml + .Replace("{mapperNS}", mapperNS) + .Replace("{mapperName}", mapperName) + .Replace("{entityNS}", entityNS) + .Replace("{entityName}", entityName) + .Replace("{serviceNS}", serviceNS) + .Replace("{serviceName}", serviceName) + .Replace("{controllerNS}", controllerNS) + .Replace("{controllerName}", controllerName) + .Replace("{minServiceName}", minServiceName) + .Replace("{queryCol}", queryCol) + .Replace("{colName}", colName) + .Replace("{colBak}", colBak) + .Replace("{colType}", colType) + .Replace("{apiTag}", apiTag) + .Replace("{apiName}", apiName) + .Replace("{bak}", bak); + + string path = Path.Combine(baseDir, "SysGenerate"); + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + string fileName = shortName + "Controller.java"; + File.WriteAllText(Path.Combine(path, fileName), xml); + } + #endregion + + #region 鐢熸垚鎵�鏈夋枃浠� + private void generateAll_Click(object sender, EventArgs e) + { + try + { + string name = this.tabList.SelectedItem as string; + List<TabInfo> tabs = (from p in _list where p.tab == name orderby p.num select p).ToList<TabInfo>(); + + GenerateMapperXml(name, tabs); + GenerateMapperJava(name, tabs); + GenerateEntityJava(name, tabs); + GenerateServiceJava(name, tabs); + GenerateControllerJava(name, tabs); + + string path = Path.Combine(baseDir, "SysGenerate"); + OpenFolder(path); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + #endregion + } +} diff --git a/JavaCode/FrmSys.resx b/JavaCode/FrmSys.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JavaCode/FrmSys.resx @@ -0,0 +1,120 @@ +锘�<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root> \ No newline at end of file diff --git a/JavaCode/JavaCode.csproj b/JavaCode/JavaCode.csproj index 7634961..95aa489 100644 --- a/JavaCode/JavaCode.csproj +++ b/JavaCode/JavaCode.csproj @@ -62,10 +62,29 @@ <Compile Include="FrmMain.Designer.cs"> <DependentUpon>FrmMain.cs</DependentUpon> </Compile> + <Compile Include="FrmSys.cs"> + <SubType>Form</SubType> + </Compile> + <Compile Include="FrmSys.Designer.cs"> + <DependentUpon>FrmSys.cs</DependentUpon> + </Compile> + <Compile Include="FrmMyBatisPlus.cs"> + <SubType>Form</SubType> + </Compile> + <Compile Include="FrmMyBatisPlus.Designer.cs"> + <DependentUpon>FrmMyBatisPlus.cs</DependentUpon> + </Compile> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <EmbeddedResource Include="FrmMain.resx"> <DependentUpon>FrmMain.cs</DependentUpon> + <SubType>Designer</SubType> + </EmbeddedResource> + <EmbeddedResource Include="FrmSys.resx"> + <DependentUpon>FrmSys.cs</DependentUpon> + </EmbeddedResource> + <EmbeddedResource Include="FrmMyBatisPlus.resx"> + <DependentUpon>FrmMyBatisPlus.cs</DependentUpon> </EmbeddedResource> <EmbeddedResource Include="Properties\Resources.resx"> <Generator>ResXFileCodeGenerator</Generator> @@ -87,24 +106,33 @@ </Compile> </ItemGroup> <ItemGroup> - <None Include="App.config" /> + <None Include="App.config"> + <SubType>Designer</SubType> + </None> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="BsTemplate\Entity.java"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </EmbeddedResource> + <EmbeddedResource Include="BsTemplate\Mapper.java"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </EmbeddedResource> <Content Include="DLL\Mono.Security.dll" /> <Content Include="DLL\Npgsql.dll" /> - <EmbeddedResource Include="Template\Controller.java"> + <Content Include="SysTemplate\pg.sql" /> + <EmbeddedResource Include="SysTemplate\Controller.java"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </EmbeddedResource> - <EmbeddedResource Include="Template\Entity.java"> + <EmbeddedResource Include="SysTemplate\Entity.java"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </EmbeddedResource> - <EmbeddedResource Include="Template\Service.java"> + <EmbeddedResource Include="SysTemplate\Service.java"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </EmbeddedResource> - <EmbeddedResource Include="Template\Mapper.java"> + <EmbeddedResource Include="SysTemplate\Mapper.java"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </EmbeddedResource> - <EmbeddedResource Include="Template\Mapper.xml"> + <EmbeddedResource Include="SysTemplate\Mapper.xml"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <SubType>Designer</SubType> </EmbeddedResource> diff --git a/JavaCode/Template/Controller.java b/JavaCode/SysTemplate/Controller.java similarity index 99% rename from JavaCode/Template/Controller.java rename to JavaCode/SysTemplate/Controller.java index 451101c..8ae55d9 100644 --- a/JavaCode/Template/Controller.java +++ b/JavaCode/SysTemplate/Controller.java @@ -82,10 +82,12 @@ if (pageSize < 1 || pageIndex < 1) { return fail("姣忛〉椤垫暟鎴栧垎椤垫暟灏忎簬1", null); } + int count = {minServiceName}.selectCount({colName}); if (count == 0) { return success(0, null); } + List<{entityName}> rs = {minServiceName}.selectByPage({colName}, pageSize, pageSize * (pageIndex - 1)); return success(count, rs); diff --git a/JavaCode/Template/Entity.java b/JavaCode/SysTemplate/Entity.java similarity index 100% rename from JavaCode/Template/Entity.java rename to JavaCode/SysTemplate/Entity.java diff --git a/JavaCode/Template/Mapper.java b/JavaCode/SysTemplate/Mapper.java similarity index 100% rename from JavaCode/Template/Mapper.java rename to JavaCode/SysTemplate/Mapper.java diff --git a/JavaCode/Template/Mapper.xml b/JavaCode/SysTemplate/Mapper.xml similarity index 91% rename from JavaCode/Template/Mapper.xml rename to JavaCode/SysTemplate/Mapper.xml index 198c313..db2ca19 100644 --- a/JavaCode/Template/Mapper.xml +++ b/JavaCode/SysTemplate/Mapper.xml @@ -51,15 +51,15 @@ <delete id="deletes"> delete from {tabName} where id in - <foreach item="ids" collection="list" index="index" open="(" separator="," close=")"> - #{ids} + <foreach item="id" collection="ids" index="index" open="(" separator="," close=")"> + #{id} </foreach> </delete> <update id="update"> - update {tabName} - set {updateVal} - where id=#{id} + update {tabName} + set {updateVal} + where id=#{id} </update> <update id="updates"> diff --git a/JavaCode/Template/Service.java b/JavaCode/SysTemplate/Service.java similarity index 100% rename from JavaCode/Template/Service.java rename to JavaCode/SysTemplate/Service.java diff --git a/JavaCode/SysTemplate/pg.sql b/JavaCode/SysTemplate/pg.sql new file mode 100644 index 0000000..f9880ed --- /dev/null +++ b/JavaCode/SysTemplate/pg.sql @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + +select * from stationseries; +select * from sitepoint order by gid; +update sitepoint set sitename='杞崡棣栫珯' where gid=55; +------------------------------------------------------------------------------ SQL璇彞 +select * from data_dir; +select * from meta_data; +select table_name as name from data_dictionary group by table_name; +update meta_data set create_time=CURRENT_TIMESTAMP,create_user='admin' where 1=1; -- CURRENT_TIME锛孋URRENT_DATE + +select * from data_files; +select * from style_data; commit; +delete from style_data where id > 22; +select * from data_dictionary order by id; +select *,queryLevel(path_id) as path from meta_data; +select queryLevel(2005); + +select count(*) from meta_data where Upper(name) like '%A%'; +select *,queryLevel(path_id) path from meta_data where Upper(name) like '%A%' order by id limit 2 offset 0; + +alter table style_data add column path varchar(255); comment on column style_data.path is '瀛樺偍璺緞'; +alter table style_data add column img varchar(255); comment on column style_data.img is '棰勮鍥剧墖'; + +INSERT INTO public.meta_data( + name, path_id, create_time, create_user, type, format, up_unit, status, version, x_min, y_min, x_max, y_max, coor_sys, accuracy, operation, remarks, s_url) + VALUES ('SITEPOINT.shp',2007, CURRENT_TIMESTAMP, 'admin', 'SHP', '.shp','璁捐闄�/鍕樺療瀹�','姝e父', 'v1.0', 0, 0, 0, 0, 'CGCS200', '1:2000', 'upload', '', ''); +------------------------------------------------------------------------------ 鏁版嵁鐩綍 +DROP TABLE IF EXISTS public.data_dir; + +CREATE TABLE public.data_dir +( + id integer, + name character varying(60), + pid integer NOT NULL, + oid integer DEFAULT 1, + PRIMARY KEY (id) +); + +COMMENT ON TABLE public.data_dir IS '鏁版嵁鐩綍'; +COMMENT ON COLUMN public.data_dir.id IS 'ID'; +COMMENT ON COLUMN public.data_dir.name IS '鍚嶇О'; +COMMENT ON COLUMN public.data_dir.pid IS '鐖惰妭鐐�'; +COMMENT ON COLUMN public.data_dir.oid IS '搴忓彿'; + +SELECT COALESCE(MAX(id),1) FROM public.data_dir; +select * from public.data_dir; + +DELETE FROM public.data_dir where id<1000; +SELECT id,name,pid,oid FROM public.data_dir order by id; +------------------------------------------------------------------------------ 涓婁紶鏂囦欢 +DROP TABLE IF EXISTS public.data_files; + +create table public.data_files +( + id serial primary key, + mid integer, + guid varchar(40), + name varchar(255), + ext varchar(10), + path varchar(1024), + subs varchar(1024), + remark varchar(1024) +); + +COMMENT ON TABLE public.data_files IS '涓婁紶鏂囦欢'; +COMMENT ON COLUMN public.data_files.id IS 'ID'; +COMMENT ON COLUMN public.data_files.mid IS '鍏冩暟鎹甀D'; +COMMENT ON COLUMN public.data_files.guid IS 'GUID'; +COMMENT ON COLUMN public.data_files.name IS '鍚嶇О'; +COMMENT ON COLUMN public.data_files.ext IS '鎵╁睍鍚�'; +COMMENT ON COLUMN public.data_files.path IS '璺緞'; +COMMENT ON COLUMN public.data_files.subs IS '瀛愭枃浠�'; +COMMENT ON COLUMN public.data_files.remark IS '澶囨敞'; + +select * from data_files; +------------------------------------------------------------------------------ 鏌ヨ灞傜骇 +with recursive rs as( + select id,name,pid,oid from public.data_dir where id = 2005 + union + select a.id,a.name,a.pid,a.oid from public.data_dir a, rs b where a.id=b.pid +) select id,name,pid,oid FROM rs order by id,oid; + + +CREATE OR REPLACE FUNCTION queryLevel(id INTEGER) +RETURNS VARCHAR as $$ + declare + str varchar=''; + rec varchar; -- public.data_dir%ROWTYPE; + begin + for rec in execute 'with recursive rs as(' || + 'select id,name,pid,oid from public.data_dir where id=' || id || + ' union select a.id,a.name,a.pid,a.oid from public.data_dir a, rs b where a.id=b.pid '|| + ') select name FROM rs order by id,oid' + loop + str = str || '\' || rec; -- rec.name; + end loop; + + if (char_length(str) > 1) then + str = SUBSTRING(str, 2); + end if; + + return str; + end; +$$ LANGUAGE PLPGSQL; + +-- 涓縿涓滅嚎绠¢亾宸ョ▼鍗楁\鍕樺療鏁版嵁\鍩虹鍦拌川\鍖哄煙鍦拌川 +select queryLevel(2005); + +select id,name,pid,oid,queryLevel(id) from data_dir where 1=1 order by id limit 10; + +------------------------------------------------------------------------------ 鏌ヨ灞傜骇ID +--drop function queryDir(id INTEGER); +CREATE OR REPLACE FUNCTION queryDir(id INTEGER) +RETURNS integer[] as $$ + declare + ids integer[]; + sid integer; + begin + for sid in execute 'with recursive rs as(' || + 'select id,pid from public.data_dir where id=' || id || + ' union select a.id,a.pid from public.data_dir a, rs b where a.pid=b.id '|| + ') select id FROM rs order by id' + loop + select array_append(ids, sid) into ids; + end loop; + + return ids; + end; +$$ LANGUAGE PLPGSQL; + +-- {2003,2004,2005,2006,2007,2008,2009} +select queryDir(2003); + +select * from data_dir order by id; +select * from meta_data where (path_id = ANY(array[2001,2002,2003,2005])); +select * from meta_data where (path_id = ANY((select queryDir(2005))::integer[])) order by id; +select * from meta_data where path_id=ANY(queryDir(2005)) order by id; +------------------------------------------------------------------------------ -- Gitblit v1.9.3