| | |
| | | public FrmEtown() |
| | | { |
| | | InitializeComponent(); |
| | | this.Load += new System.EventHandler(this.FrmMyBatisPlus_Load); |
| | | this.Load += new System.EventHandler(this.FrmEtown_Load); |
| | | } |
| | | |
| | | private void FrmMyBatisPlus_Load(object sender, EventArgs e) |
| | | private void FrmEtown_Load(object sender, EventArgs e) |
| | | { |
| | | _dbHelper = new PostgreHelper(DbEnum.langfang); |
| | | _dbHelper = new PostgreHelper(DbEnum.etown); |
| | | } |
| | | #endregion |
| | | |
| | |
| | | { |
| | | try |
| | | { |
| | | string path = Path.Combine(baseDir, "EtownTemplate\\Mapper"); |
| | | string path = Path.Combine(baseDir, "Result\\Mapper"); |
| | | |
| | | List<string> names = GetTabList(); |
| | | foreach (string name in names) |
| | |
| | | { |
| | | try |
| | | { |
| | | string path = Path.Combine(baseDir, "EtownTemplate\\Entity"); |
| | | string path = Path.Combine(baseDir, "Result\\Entity"); |
| | | |
| | | List<string> names = GetTabList(); |
| | | foreach (string name in names) |
| | |
| | | if (!Directory.Exists(path)) Directory.CreateDirectory(path); |
| | | |
| | | string tabName = this.txtTabPrefix.Text.Trim() + name; |
| | | string shortName = GetEntityName(name, true); |
| | | string shortName = GetEntityName(name); |
| | | |
| | | string mapperNS = this.txtMapperNS.Text.Trim(); |
| | | string mapperName = shortName + "Mapper"; |
| | |
| | | string entityName = shortName + "Entity"; |
| | | |
| | | string ns = this.txtTabPrefix.Text.Trim(); |
| | | string bak = string.IsNullOrWhiteSpace(tabs[0].desc) ? shortName : tabs[0].desc.Replace("表", ""); |
| | | string bak = shortName; |
| | | if (!string.IsNullOrEmpty(tabs[0].desc)) bak = tabs[0].desc.Replace("表", ""); |
| | | |
| | | List<SysDict> dicts = SelectSysDicts(tabName); |
| | | if (dicts != null) bak = dicts[0].descr; |
| | | |
| | | string javaFile = "Mapper.java"; |
| | | string xml = File.ReadAllText(Path.Combine(baseDir, "EtownTemplate\\" + javaFile)); |
| | |
| | | |
| | | string tabName = this.txtTabPrefix.Text.Trim() + name; |
| | | //string shortName = NameConvert(name, true); |
| | | string shortName = GetEntityName(name, true); |
| | | string shortName = GetEntityName(name); |
| | | |
| | | string entityNS = this.txtEntityNS.Text.Trim(); |
| | | string entityName = shortName + "Entity"; |
| | | |
| | | string ns = this.txtTabPrefix.Text.Trim(); |
| | | string bak = string.IsNullOrWhiteSpace(tabs[0].desc) ? shortName : tabs[0].desc.Replace("表", ""); |
| | | long uid = (long)Math.Floor((new Random()).NextDouble() * 1000000000000000000D); |
| | | |
| | | string bak = shortName; |
| | | if (!string.IsNullOrEmpty(tabs[0].desc)) bak = tabs[0].desc.Replace("表", ""); |
| | | List<SysDict> dicts = SelectSysDicts(tabName); |
| | | if (dicts != null) bak = dicts[0].descr; |
| | | |
| | | string javaFile = "Entity.java"; |
| | | string xml = File.ReadAllText(Path.Combine(baseDir, "EtownTemplate\\" + javaFile)); |
| | |
| | | .Replace("{date}", DateTime.Now.ToString("yyyy-MM-dd")); |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.Append("\r\n public " + entityName + "() {\r\n }\r\n"); |
| | | foreach (TabInfo ti in tabs) |
| | | { |
| | | string type = GetJavaType(ti); |
| | |
| | | |
| | | sb.Append("\r\n"); |
| | | string colName = NameConvert(ti.col, false); |
| | | if ("references" == colName) sb.Append(" @TableField(value = \"\\\"references\\\"\")").Append("\r\n"); |
| | | //if ("references" == colName) sb.Append(" @TableField(value = \"\\\"references\\\"\")").Append("\r\n"); |
| | | |
| | | SysDict dict = FindSysDict(dicts, ti.col); |
| | | string alias = null == dict || string.IsNullOrEmpty(dict.alias) ? (string.IsNullOrEmpty(ti.bak) ? "" : ti.bak.Trim()) : dict.alias.Trim(); |
| | | sb.Append(" @ApiModelProperty(value = \"" + alias + "\")\r\n"); |
| | | |
| | | sb.Append(" private " + type + " " + colName + ";\r\n"); |
| | | } |
| | | sb.Append("\r\n public " + entityName + "() {\r\n }\r\n"); |
| | | |
| | | foreach (TabInfo ti in tabs) |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | string mapperPath = Path.Combine(baseDir, "EtownTemplate\\Mapper"); |
| | | string entityPath = Path.Combine(baseDir, "EtownTemplate\\Entity"); |
| | | string mapperPath = Path.Combine(baseDir, "Result\\Mapper"); |
| | | string entityPath = Path.Combine(baseDir, "Result\\Entity"); |
| | | |
| | | List<string> names = GetTabList(); |
| | | foreach (string name in names) |
| | | { |
| | | List<TabInfo> tabs = GetTabInfo(name); |
| | | GenerateMapper(mapperPath, name, tabs); |
| | | GenerateEntity(entityPath, name, tabs); |
| | | try |
| | | { |
| | | List<TabInfo> tabs = GetTabInfo(name); |
| | | GenerateMapper(mapperPath, name, tabs); |
| | | GenerateEntity(entityPath, name, tabs); |
| | | } |
| | | catch (Exception ec) |
| | | { |
| | | MessageBox.Show(name + "\r\n" + ec.Message); |
| | | } |
| | | } |
| | | |
| | | string path = Path.Combine(baseDir, "EtownTemplate"); |
| | | string path = Path.Combine(baseDir, "Result"); |
| | | OpenFolder(path); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | 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(); |
| | |
| | | #endregion |
| | | |
| | | #region 公共方法 |
| | | private List<SysDict> SelectSysDicts(string table) |
| | | { |
| | | string[] strs = table.Split(new char[] { '.' }); |
| | | string sql = string.Format("select id,ns||'.'||tab table, descr, field, alias, type from se.sys_dict where ns='{0}' and tab='{1}' order by orderid", strs[0], strs[1]); |
| | | |
| | | DataTable dt = _dbHelper.GetDataTable(sql, null); |
| | | |
| | | List<SysDict> list = ModelHandler.FillModel<SysDict>(dt); |
| | | |
| | | return null == list || list.Count == 0 ? null : list; |
| | | } |
| | | |
| | | private SysDict FindSysDict(List<SysDict> list, string field) |
| | | { |
| | | if (null == list) return null; |
| | | |
| | | return (from sd in list where sd.field == field select sd).FirstOrDefault(); |
| | | } |
| | | |
| | | private List<string> GetTabList() |
| | | { |
| | | List<string> list = new List<string>(); |
| | |
| | | return tabs; |
| | | } |
| | | |
| | | private static string GetEntityName(string name, bool firstUpper) |
| | | private static string GetEntityName(string name) |
| | | { |
| | | return firstUpper ? ToUpperFirst(name.Replace("_", "")) : name.Replace("_", ""); |
| | | string[] strs = name.ToLower().Split(new char[] { '_' }); |
| | | for (int i = 0, c = strs.Length; i < c; i++) |
| | | { |
| | | strs[i] = ToUpperFirst(strs[i]); |
| | | } |
| | | |
| | | return string.Join("", strs); |
| | | } |
| | | |
| | | private static string NameConvert(string name, bool firstUpper) |
| | | { |
| | | string[] strs = name.Split(new char[] { '_' }); |
| | | |
| | | string[] strs = name.ToLower().Split(new char[] { '_' }); |
| | | for (int i = 0, c = strs.Length; i < c; i++) |
| | | { |
| | | if (0 == i && !firstUpper) |
| | | { |
| | | continue; |
| | | } |
| | | if (0 == i && !firstUpper) continue; |
| | | |
| | | strs[i] = char.IsDigit(strs[i][0]) ? "_" + strs[i] : ToUpperFirst(strs[i]); |
| | | strs[i] = ToUpperFirst(strs[i]); |
| | | } |
| | | |
| | | return string.Join("", strs); |