13693261870
2022-10-20 93b9a4bd47bfec774894928392d52a61fca07c38
修改数据结构、业务数据映射
已重命名5个文件
已添加9个文件
已修改4个文件
3008 ■■■■■ 文件已修改
JavaCode/App.config 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/BsTemplate/Entity.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/BsTemplate/Mapper.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/FrmMain.Designer.cs 396 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/FrmMain.cs 684 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/FrmMyBatisPlus.Designer.cs 231 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/FrmMyBatisPlus.cs 120 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/FrmMyBatisPlus.resx 120 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/FrmSys.Designer.cs 410 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/FrmSys.cs 677 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/FrmSys.resx 120 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/JavaCode.csproj 40 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/SysTemplate/Controller.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/SysTemplate/Entity.java 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/SysTemplate/Mapper.java 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/SysTemplate/Mapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/SysTemplate/Service.java 补丁 | 查看 | 原始文档 | blame | 历史
JavaCode/SysTemplate/pg.sql 153 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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" />
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;
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});
}
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 çª—体设计器生成的代码
        #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.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;
    }
}
JavaCode/FrmMain.cs
@@ -1,14 +1,10 @@
using JavaCode.cs;
using System;
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;
@@ -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);
            FrmSys frmSys = new FrmSys();
            frmSys.Show();
        }
        #endregion
        #region æŸ¥è¯¢è¡¨ç»“æž„
        private void btnReadTab_Click(object sender, EventArgs e)
        private void btnMybatis_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;
        }
        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 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);
            }
            FrmMyBatisPlus mybatis = new FrmMyBatisPlus();
            mybatis.Show();
        }
        #endregion
    }
}
JavaCode/FrmMyBatisPlus.Designer.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,231 @@
namespace 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;
    }
}
JavaCode/FrmMyBatisPlus.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,120 @@
using 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();
        }
    }
}
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>
JavaCode/FrmSys.Designer.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,410 @@
namespace 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 çª—体设计器生成的代码
        /// <summary>
        /// è®¾è®¡å™¨æ”¯æŒæ‰€éœ€çš„æ–¹æ³• - ä¸è¦
        /// ä½¿ç”¨ä»£ç ç¼–辑器修改此方法的内容。
        /// </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;
    }
}
JavaCode/FrmSys.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,677 @@
using 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
    }
}
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>
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>
JavaCode/SysTemplate/Controller.java
ÎļþÃû´Ó JavaCode/Template/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);
JavaCode/SysTemplate/Entity.java
JavaCode/SysTemplate/Mapper.java
JavaCode/SysTemplate/Mapper.xml
ÎļþÃû´Ó JavaCode/Template/Mapper.xml ÐÞ¸Ä
@@ -51,8 +51,8 @@
    <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>
JavaCode/SysTemplate/Service.java
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,CURRENT_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','设计院/勘察室','正常', '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 '元数据ID';
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;
------------------------------------------------------------------------------