管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2023-08-08 5b2c27902205fbcf32bd996aab9ef65e0165264a
JavaCode/FrmMyBatisPlus.cs
@@ -4,12 +4,10 @@
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
@@ -17,7 +15,7 @@
    public partial class FrmMyBatisPlus : Form
    {
        #region 成员变量+构造函数
        private static List<string> excludes = new List<string>() { "gid", "objectid", "eventid", "dirid", "depid", "verid", "createtime", "createuser", "updateuser", "updatetime", "geom", "shape_leng", "shape_area" };
        private static List<string> excludes = new List<string>() { "gid", "parentid", "objectid", "eventid", "dirid", "depid", "verid", "createtime", "createuser", "updateuser", "updatetime", "geom", "shape_leng", "shape_area" };
        string baseDir = AppDomain.CurrentDomain.BaseDirectory;
@@ -44,7 +42,7 @@
                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 \"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 reltype>0 and relnamespace in ({0}) {1} order by c.relname desc, a.attnum asc", this.txtNS.Text.Trim(), tabFilter);
                string sql = string.Format("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 reltype>0 and relnamespace in ({0}) {1} and position('pg.dropped' in a.attname) = 0 order by c.relname desc, a.attnum asc", this.txtTabNS.Text.Trim(), tabFilter);
                DataTable dt = _dbHelper.GetDataTable(sql, null);
                _list = ModelHandler.FillModel<TabInfo>(dt);
@@ -151,30 +149,6 @@
                MessageBox.Show(ex.Message);
            }
        }
        private void btnGeneAll_Click(object sender, EventArgs e)
        {
            try
            {
                string mapperPath = Path.Combine(baseDir, "BsGenerate\\Mapper");
                string entityPath = Path.Combine(baseDir, "BsGenerate\\Entity");
                List<string> names = GetTabList();
                foreach (string name in names)
                {
                    List<TabInfo> tabs = GetTabInfo(name);
                    GenerateMapper(mapperPath, name, tabs);
                    GenerateEntity(entityPath, name, tabs);
                }
                string path = Path.Combine(baseDir, "BsGenerate");
                OpenFolder(path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion
        #region 生成 Mapper
@@ -182,7 +156,7 @@
        {
            if (!Directory.Exists(path)) Directory.CreateDirectory(path);
            string tabName = this.txtTabNS.Text.Trim() + name;
            string tabName = this.txtTabPrefix.Text.Trim() + name;
            //string shortName = NameConvert(name, true);
            string shortName = GetEntityName(name, true);
@@ -192,6 +166,7 @@
            string entityNS = this.txtEntityNS.Text.Trim();
            string entityName = shortName + "Entity";
            string ns = this.txtNS.Text.Trim();
            string bak = string.IsNullOrWhiteSpace(tabs[0].desc) ? shortName : tabs[0].desc.Replace("表", "");
            //if (this.HasGeom(tabs)) return;
@@ -202,6 +177,7 @@
                .Replace("{mapperName}", mapperName)
                .Replace("{entityNS}", entityNS)
                .Replace("{entityName}", entityName)
                .Replace("{ns}", ns)
                .Replace("{bak}", bak);
            string fileName = shortName + "Mapper.java";
@@ -214,13 +190,14 @@
        {
            if (!Directory.Exists(path)) Directory.CreateDirectory(path);
            string tabName = this.txtTabNS.Text.Trim() + name;
            string tabName = this.txtTabPrefix.Text.Trim() + name;
            //string shortName = NameConvert(name, true);
            string shortName = GetEntityName(name, true);
            string entityNS = this.txtEntityNS.Text.Trim();
            string entityName = shortName + "Entity";
            string ns = this.txtNS.Text.Trim();
            string bak = string.IsNullOrWhiteSpace(tabs[0].desc) ? shortName : tabs[0].desc.Replace("表", "");
            long uid = (long)Math.Floor((new Random()).NextDouble() * 1000000000000000000D);
@@ -232,6 +209,7 @@
                .Replace("{entityName}", entityName)
                .Replace("{bak}", bak)
                .Replace("{tabName}", tabName)
                .Replace("{ns}", ns)
                .Replace("{uid}", uid.ToString());
            StringBuilder sb = new StringBuilder();
@@ -249,7 +227,7 @@
                    //sb.Append("\r\n    @TableField(value = \"class\")");
                    //ti.col = "clazz";
                    //ti.col = "classes";
                    MessageBox.Show(ti.tab);
                    MessageBox.Show(ti.tab + "." + ti.col);
                    return;
                }
@@ -274,6 +252,50 @@
            string fileName = shortName + "Entity.java";
            File.WriteAllText(Path.Combine(path, fileName), sb.ToString());
        }
        #endregion
        #region 生成所有
        private void btnGeneAll_Click(object sender, EventArgs e)
        {
            try
            {
                string mapperPath = Path.Combine(baseDir, "BsGenerate\\Mapper");
                string entityPath = Path.Combine(baseDir, "BsGenerate\\Entity");
                List<string> names = GetTabList();
                foreach (string name in names)
                {
                    List<TabInfo> tabs = GetTabInfo(name);
                    GenerateMapper(mapperPath, name, tabs);
                    GenerateEntity(entityPath, name, tabs);
                }
                string path = Path.Combine(baseDir, "BsGenerate");
                OpenFolder(path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void txtTabPrefix_TextChanged(object sender, EventArgs e)
        {
            txtChanged(sender, e);
        }
        private void txtNS_TextChanged(object sender, EventArgs e)
        {
            txtChanged(sender, e);
        }
        private void txtChanged(object sender, EventArgs e)
        {
            string pre = txtTabPrefix.Text.Replace(".", "").Trim();
            string ns = txtNS.Text.Trim();
            txtMapperNS.Text = "com.lf.server.mapper.bd".Replace("lf", ns).Replace("bd", pre);
            txtEntityNS.Text = "com.lf.server.entity.bd".Replace("lf", ns).Replace("bd", pre);
        }
        #endregion
@@ -320,6 +342,10 @@
                str += strs[i].Length == 1 ? strs[i] : ToUpperFirst(strs[i]);
            }
            if (str.Length == 1 && firstUpper)
            {
                return str.ToUpper();
            }
            return str;
        }