1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data;
- using System.Web;
- using Newtonsoft.Json.Linq;
- using YiSha.Data.Repository;
- using YiSha.CodeGenerator.Model;
- using YiSha.Util;
- using YiSha.Util.Extension;
- using YiSha.Util.Model;
- using YiSha.Entity.SystemManage;
- using YiSha.Enum.SystemManage;
- using YiSha.Business.Cache;
- using YiSha.Entity;
- using YiSha.Business.Cache.IBusiness;
- using YiSha.Enum;
- namespace YiSha.CodeGenerator.Template
- {
- public class SingleTableTemplate
- {
- #region GetBaseConfig
- public BaseConfigModel GetBaseConfig(string path, string userName, string tableName, string tableDescription, List<string> tableFieldList)
- {
- path = GetProjectRootPath(path);
- int defaultField = 2; // 默认显示2个字段
- BaseConfigModel baseConfigModel = new BaseConfigModel();
- baseConfigModel.TableName = tableName;
- baseConfigModel.TableNameUpper = tableName;
- #region FileConfigModel
- baseConfigModel.FileConfig = new FileConfigModel();
- baseConfigModel.FileConfig.ClassPrefix = TableMappingHelper.GetClassNamePrefix(tableName);
- baseConfigModel.FileConfig.ClassDescription = tableDescription;
- baseConfigModel.FileConfig.CreateName = userName;
- baseConfigModel.FileConfig.CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
- baseConfigModel.FileConfig.EntityName = string.Format("{0}Entity", baseConfigModel.FileConfig.ClassPrefix);
- baseConfigModel.FileConfig.EntityMapName = string.Format("{0}Map", baseConfigModel.FileConfig.ClassPrefix);
- baseConfigModel.FileConfig.EntityParamName = string.Format("{0}Param", baseConfigModel.FileConfig.ClassPrefix);
- baseConfigModel.FileConfig.BusinessName = string.Format("{0}BLL", baseConfigModel.FileConfig.ClassPrefix);
- baseConfigModel.FileConfig.IBusinessName = string.Format("I{0}BLL", baseConfigModel.FileConfig.ClassPrefix);
- baseConfigModel.FileConfig.ServiceName = string.Format("{0}Service", baseConfigModel.FileConfig.ClassPrefix);
- baseConfigModel.FileConfig.IServiceName = string.Format("I{0}Service", baseConfigModel.FileConfig.ClassPrefix);
- baseConfigModel.FileConfig.ControllerName = string.Format("{0}Controller", baseConfigModel.FileConfig.ClassPrefix);
- baseConfigModel.FileConfig.PageIndexName = string.Format("{0}Index", baseConfigModel.FileConfig.ClassPrefix);
- baseConfigModel.FileConfig.PageFormName = string.Format("{0}Form", baseConfigModel.FileConfig.ClassPrefix);
- #endregion
- #region OutputConfigModel
- baseConfigModel.OutputConfig = new OutputConfigModel();
- baseConfigModel.OutputConfig.OutputModule = string.Empty;
- baseConfigModel.OutputConfig.OutputEntity = Path.Combine(path, "YiSha.Entity");
- baseConfigModel.OutputConfig.OutputBusiness = Path.Combine(path, "YiSha.Business");
- baseConfigModel.OutputConfig.OutputWeb = Path.Combine(path, "YiSha.Web", "YiSha.Admin.Web");
- string areasModule = Path.Combine(baseConfigModel.OutputConfig.OutputWeb, "Areas");
- if (Directory.Exists(areasModule))
- {
- baseConfigModel.OutputConfig.ModuleList = Directory.GetDirectories(areasModule).Select(p => Path.GetFileName(p)).Where(p => p != "DemoManage").ToList();
- }
- else
- {
- baseConfigModel.OutputConfig.ModuleList = new List<string> { "TestManage" };
- }
- #endregion
- #region PageIndexModel
- baseConfigModel.PageIndex = new PageIndexModel();
- baseConfigModel.PageIndex.IsSearch = 1;
- baseConfigModel.PageIndex.IsPagination = 1;
- baseConfigModel.PageIndex.ButtonList = new List<string>();
- baseConfigModel.PageIndex.ColumnList = new List<string>();
- baseConfigModel.PageIndex.ColumnList.AddRange(tableFieldList.Take(defaultField));
- #endregion
- #region PageFormModel
- baseConfigModel.PageForm = new PageFormModel();
- baseConfigModel.PageForm.ShowMode = 1;
- baseConfigModel.PageForm.FieldList = new List<string>();
- baseConfigModel.PageForm.FieldList.AddRange(tableFieldList.Take(defaultField));
- #endregion
- return baseConfigModel;
- }
- #endregion
- #region BuildEntity
- public string BuildEntity(BaseConfigModel baseConfigModel, DataTable dt)
- {
- string baseEntity = GetBaseEntity(dt);
- StringBuilder sb = new StringBuilder();
- sb.AppendLine("using System;");
- sb.AppendLine("using Newtonsoft.Json;");
- sb.AppendLine("using System.ComponentModel.DataAnnotations.Schema;");
- sb.AppendLine("using YiSha.Util;");
- sb.AppendLine();
- sb.AppendLine("namespace YiSha.Entity." + baseConfigModel.OutputConfig.OutputModule);
- sb.AppendLine("{");
- SetClassDescription("实体类", baseConfigModel, sb);
- sb.AppendLine(" [Table(\"" + baseConfigModel.TableName + "\")]");
- sb.AppendLine(" public partial class " + baseConfigModel.FileConfig.EntityName + " : " + baseEntity);
- sb.AppendLine(" {");
- string column = string.Empty;
- string remark = string.Empty;
- string datatype = string.Empty;
- foreach (DataRow dr in dt.Rows)
- {
- column = dr["TableColumn"].ToString();
- if (BaseField.BaseFieldList.Where(p => p.ToLower() == column.ToLower()).Any())
- {
- // 基础字段不需要生成,继承合适的BaseEntity即可。
- continue;
- }
- remark = dr["Remark"].ToString();
- datatype = dr["Datatype"].ToString();
- datatype = TableMappingHelper.GetPropertyDatatype(datatype);
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// " + remark);
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <returns></returns>");
- switch (datatype)
- {
- case "long?":
- sb.AppendLine(" [JsonConverter(typeof(StringJsonConverter))]");
- break;
- case "DateTime?":
- sb.AppendLine(" [JsonConverter(typeof(DateTimeJsonConverter))]");
- break;
- }
- sb.AppendLine(" public " + datatype + " " + column + " { get; set; }");
- }
- sb.AppendLine(" }");
- sb.AppendLine("}");
- return sb.ToString();
- }
- #endregion
- #region BuildEntityParam
- public string BuildEntityParam(BaseConfigModel baseConfigModel)
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine("using System;");
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using Newtonsoft.Json;");
- sb.AppendLine("using YiSha.Util;");
- sb.AppendLine();
- sb.AppendLine("namespace YiSha.Model.Param." + baseConfigModel.OutputConfig.OutputModule);
- sb.AppendLine("{");
- SetClassDescription("实体查询类", baseConfigModel, sb);
- sb.AppendLine(" public class " + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam"));
- sb.AppendLine(" {");
- sb.AppendLine(" }");
- sb.AppendLine("}");
- return sb.ToString();
- }
- #endregion
- #region BuildService
- public string BuildService(BaseConfigModel baseConfigModel, DataTable dt)
- {
- string baseEntity = GetBaseEntity(dt);
- StringBuilder sb = new StringBuilder();
- string method = string.Empty;
- sb.AppendLine("using System;");
- sb.AppendLine("using System.Linq;");
- sb.AppendLine("using System.Text;");
- sb.AppendLine("using System.Data.Common;");
- sb.AppendLine("using System.Linq.Expressions;");
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using System.Threading.Tasks;");
- sb.AppendLine("using YiSha.Util;");
- sb.AppendLine("using YiSha.Util.Extension;");
- sb.AppendLine("using YiSha.Util.Model;");
- sb.AppendLine("using YiSha.Data;");
- sb.AppendLine("using YiSha.Data.Repository;");
- sb.AppendLine("using YiSha.Enum;");
- sb.AppendLine("using System.ComponentModel.DataAnnotations.Schema;");
- sb.AppendLine("using YiSha.Entity." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.Model.Param." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.IService." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine();
- sb.AppendLine("namespace YiSha.Service." + baseConfigModel.OutputConfig.OutputModule);
- sb.AppendLine("{");
- SetClassDescription("服务实现类", baseConfigModel, sb);
- sb.AppendLine(" public partial class " + baseConfigModel.FileConfig.ServiceName + " : I" + baseConfigModel.FileConfig.IServiceName + "");
- sb.AppendLine(" {");
- sb.AppendLine(" private DBConnectTypeEnum dbConnectType = " + GetDBConnectTypeEnum(baseConfigModel.DBConnectType) + ";");
- sb.AppendLine(" #region 获取数据");
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取列表数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"param\">请求参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<List<" + baseConfigModel.FileConfig.EntityName + ">> GetList(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param)");
- sb.AppendLine(" {");
- sb.AppendLine(" var expression = ListFilterPartial(param);");
- sb.AppendLine(" var list = await _baseRepository.BaseRepository(dbConnectType).FindList(expression);");
- sb.AppendLine(" return list.ToList();");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取分页数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"param\">请求参数</param>");
- sb.AppendLine(" /// <param name=\"pagination\">分页条件</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<List<" + baseConfigModel.FileConfig.EntityName + ">> GetPageList(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param, Pagination pagination)");
- sb.AppendLine(" {");
- sb.AppendLine(" var expression = ListFilterPartial(param);");
- sb.AppendLine(" var list = await _baseRepository.BaseRepository(dbConnectType).FindList(expression, pagination);");
- sb.AppendLine(" return list.ToList();");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取指定列数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"column\">表字段列</param>");
- sb.AppendLine(" /// <param name=\"where\">条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">条件参数</param>");
- sb.AppendLine(" /// <param name=\"sort\">排序列</param>");
- sb.AppendLine(" /// <param name=\"sortType\">排序类型</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<List<" + baseConfigModel.FileConfig.EntityName + ">> GetListColumn(string column, string where, List<DbParameter> parameters, string groupBy = \"\", string sort = \"basecreatetime\", string sortType = \"desc\")");
- sb.AppendLine(" {");
- sb.AppendLine(" if (string.IsNullOrEmpty(column) || string.IsNullOrEmpty(where))");
- sb.AppendLine(" return new List<" + baseConfigModel.FileConfig.EntityName + ">();");
- sb.AppendLine(" if (!string.IsNullOrEmpty(groupBy))");
- sb.AppendLine(" groupBy = $\" group by {groupBy} \";");
- sb.AppendLine(" string tableName = typeof(" + baseConfigModel.FileConfig.EntityName + ").GetAttributeValue((TableAttribute ta) => ta.Name);");
- if (baseEntity.Equals("BaseExtensionEntity"))
- {
- sb.AppendLine(" string selectSql = $\"select {column} from {tableName} where baseisdelete = @baseisdelete and {where} {groupBy} order by {sort} {sortType}\";");
- sb.AppendLine(" parameters.Add(DbParameterExtension.CreateDbParameter(\"@baseisdelete\", (int)IsDeleteEnum.No, dbConnectType));");
- }
- else
- {
- sb.AppendLine(" string selectSql = $\"select {column} from {tableName} where 1 = 1 and {where} {groupBy} order by {sort} {sortType}\";");
- }
- sb.AppendLine(" var result = await _baseRepository.BaseRepository(dbConnectType).FindList<" + baseConfigModel.FileConfig.EntityName + ">(selectSql, DbParameterExtension.ToDbParameter(parameters.ToArray()));");
- sb.AppendLine(" return result.ToList();");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据主键Id获取数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"id\">主键id</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<" + baseConfigModel.FileConfig.EntityName + "> GetEntity(int id)");
- sb.AppendLine(" {");
- sb.AppendLine(" return await _baseRepository.BaseRepository(dbConnectType).FindEntity<" + baseConfigModel.FileConfig.EntityName + ">(id);");
- sb.AppendLine(" }");
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" #region 提交数据");
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 保存数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"entity\">实体参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task SaveForm(" + baseConfigModel.FileConfig.EntityName + " entity)");
- sb.AppendLine(" {");
- sb.AppendLine(" if (entity.Id.IsNullOrZero())");
- sb.AppendLine(" {");
- sb.AppendLine(" " + GetSaveFormCreate(baseEntity));
- sb.AppendLine(" await _baseRepository.BaseRepository(dbConnectType).Insert(entity);");
- sb.AppendLine(" }");
- sb.AppendLine(" else");
- sb.AppendLine(" {");
- sb.AppendLine(" " + GetSaveFormModify(baseEntity));
- sb.AppendLine(" await _baseRepository.BaseRepository(dbConnectType).Update(entity);");
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 保存多条数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"list\">数据列表</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<int> InsertMany(List<" + baseConfigModel.FileConfig.EntityName + "> list)");
- sb.AppendLine(" {");
- sb.AppendLine(" return await _baseRepository.BaseRepository(dbConnectType).Insert(list);");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据主键Id删除数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"ids\">主键Id</param>");
- sb.AppendLine(" /// <param name=\"del\">是否真删除 true真删除 false软删除 默认false</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<int> DeleteFormById(string ids, bool del = false)");
- sb.AppendLine(" {");
- sb.AppendLine(" if (string.IsNullOrWhiteSpace(ids) || !ids.Split(\", \").Any())");
- sb.AppendLine(" {");
- sb.AppendLine(" return await Task.FromResult(-1);");
- sb.AppendLine(" }");
- sb.AppendLine(" ids = $\"{ string.Join(\",\", ids.Split(\",\"))}\";");
- sb.AppendLine(" string tableName = typeof(" + baseConfigModel.FileConfig.EntityName + ").GetAttributeValue((TableAttribute ta) => ta.Name);");
- if (baseEntity.Equals("BaseExtensionEntity"))
- {
- sb.AppendLine(" string deleteSql = $\"update {tableName} set baseisdelete = @baseisdelete where FIND_IN_SET (id,@id)\";");
- sb.AppendLine(" if (del)");
- sb.AppendLine(" {");
- sb.AppendLine(" deleteSql = $\"delete from {tableName} where FIND_IN_SET (id,@id)\";");
- sb.AppendLine(" }");
- sb.AppendLine(" List<DbParameter> parameters = new List<DbParameter>();");
- sb.AppendLine(" parameters.Add(DbParameterExtension.CreateDbParameter(\"@baseisdelete\", (int)IsDeleteEnum.Yes, dbConnectType));");
- sb.AppendLine(" parameters.Add(DbParameterExtension.CreateDbParameter(\"@id\", ids, dbConnectType));");
- }
- else
- {
- var where = "";
- DBConnectHelper.GetInstance.GetDBConnectInfo(baseConfigModel.DBConnectType, out string dbType, out string dbConnectionString);
- sb.AppendLine(" List<DbParameter> parameters = new List<DbParameter>();");
- if (dbType.ToLower() == "mysql")
- {
- where = "where FIND_IN_SET (id,@id)";
- sb.AppendLine(" parameters.Add(DbParameterExtension.CreateDbParameter(\"@id\", ids, dbConnectType));");
- }
- else
- where = "where id in ({ids})";
- sb.AppendLine(" string deleteSql = $\"delete from {tableName} " + where + "\";");
- }
- sb.AppendLine(" return await _baseRepository.BaseRepository(dbConnectType).ExecuteBySql(deleteSql, DbParameterExtension.ToDbParameter(parameters.ToArray()));");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据条件删除数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"where\">where条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">参数</param>");
- sb.AppendLine(" /// <param name=\"del\">是否真删除 true真删除 false软删除 默认false</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<int> DeleteFormByWhere(string where, List<DbParameter> parameters, bool del = false)");
- sb.AppendLine(" {");
- sb.AppendLine(" if (string.IsNullOrWhiteSpace(where))");
- sb.AppendLine(" {");
- sb.AppendLine(" return await Task.FromResult(-1);");
- sb.AppendLine(" }");
- sb.AppendLine(" string tableName = typeof(" + baseConfigModel.FileConfig.EntityName + ").GetAttributeValue((TableAttribute ta) => ta.Name);");
- if (baseEntity.Equals("BaseExtensionEntity"))
- {
- sb.AppendLine(" string deleteSql = $\"update {tableName} set baseisdelete = @baseisdelete where {where}\";");
- sb.AppendLine(" if (del)");
- sb.AppendLine(" {");
- sb.AppendLine(" deleteSql = $\"delete from {tableName} where {where}\";");
- sb.AppendLine(" }");
- sb.AppendLine(" parameters.Add(DbParameterExtension.CreateDbParameter(\"@baseisdelete\", (int)IsDeleteEnum.Yes, dbConnectType));");
- }
- else
- {
- sb.AppendLine(" string deleteSql = $\"delete from {tableName} where {where}\";");
- }
- sb.AppendLine(" return await _baseRepository.BaseRepository(dbConnectType).ExecuteBySql(deleteSql, DbParameterExtension.ToDbParameter(parameters.ToArray()));");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 修改多条数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"list\">数据列表</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<int> UpdateMany(List<" + baseConfigModel.FileConfig.EntityName + "> list)");
- sb.AppendLine(" {");
- sb.AppendLine(" return await _baseRepository.BaseRepository(dbConnectType).Update(list);");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据条件修改数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"setField\">修改字段</param>");
- sb.AppendLine(" /// <param name=\"where\">where条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<int> UpdateFormByWhere(string setField, string where, List<DbParameter> parameters)");
- sb.AppendLine(" {");
- sb.AppendLine(" if (string.IsNullOrWhiteSpace(setField) || string.IsNullOrWhiteSpace(where))");
- sb.AppendLine(" {");
- sb.AppendLine(" return await Task.FromResult(-1);");
- sb.AppendLine(" }");
- sb.AppendLine(" string tableName = typeof(" + baseConfigModel.FileConfig.EntityName + ").GetAttributeValue((TableAttribute ta) => ta.Name);");
- sb.AppendLine(" string updateSql = $\"update {tableName} set {setField} where {where}\";");
- sb.AppendLine(" return await _baseRepository.BaseRepository(dbConnectType).ExecuteBySql(updateSql, DbParameterExtension.ToDbParameter(parameters.ToArray()));");
- sb.AppendLine(" }");
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" #region 私有方法");
- sb.AppendLine(" ///// <summary>");
- sb.AppendLine(" ///// 列表条件过滤");
- sb.AppendLine(" ///// 建议该方法放在Partial部分类中,因为代码生成时当前类会被覆盖(该方法在生成时将会被注释)");
- sb.AppendLine(" ///// </summary>");
- sb.AppendLine(" ///// <param name=\"param\"></param>");
- sb.AppendLine(" ///// <returns></returns>");
- sb.AppendLine(" //private Expression<Func<" + baseConfigModel.FileConfig.EntityName + ", bool>> ListFilter(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param)");
- sb.AppendLine(" //{");
- sb.AppendLine(" // var expression = LinqExtensions.True<" + baseConfigModel.FileConfig.EntityName + ">();");
- sb.AppendLine(" // expression = expression.And(t => t.BaseIsDelete == (int)IsDeleteEnum.No);");
- sb.AppendLine(" // if (param != null)");
- sb.AppendLine(" // {");
- sb.AppendLine(" // }");
- sb.AppendLine(" // return expression;");
- sb.AppendLine(" //}");
- sb.AppendLine(" #endregion");
- sb.AppendLine(" }");
- sb.AppendLine("}");
- return sb.ToString();
- }
- #endregion
- #region BuildService_Partial
- public string BuildService_Partial(BaseConfigModel baseConfigModel, DataTable dt)
- {
- string baseEntity = GetBaseEntity(dt);
- StringBuilder sb = new StringBuilder();
- string method = string.Empty;
- sb.AppendLine("using System;");
- sb.AppendLine("using System.Linq;");
- sb.AppendLine("using System.Text;");
- sb.AppendLine("using System.Data.Common;");
- sb.AppendLine("using System.Linq.Expressions;");
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using System.Threading.Tasks;");
- sb.AppendLine("using YiSha.Util;");
- sb.AppendLine("using YiSha.Util.Extension;");
- sb.AppendLine("using YiSha.Util.Model;");
- sb.AppendLine("using YiSha.Data;");
- sb.AppendLine("using YiSha.Data.Repository;");
- sb.AppendLine("using YiSha.Enum;");
- sb.AppendLine("using System.ComponentModel.DataAnnotations.Schema;");
- sb.AppendLine("using YiSha.Entity." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.Model.Param." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.IService." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine();
- sb.AppendLine("namespace YiSha.Service." + baseConfigModel.OutputConfig.OutputModule);
- sb.AppendLine("{");
- SetClassDescription("服务实现类(部分类)", baseConfigModel, sb);
- sb.AppendLine(" public partial class " + baseConfigModel.FileConfig.ServiceName + "");
- sb.AppendLine(" {");
- sb.AppendLine(" private IRepositoryFactory _baseRepository;");
- sb.AppendLine(" public " + baseConfigModel.FileConfig.ServiceName + "(IRepositoryFactory baseRepository)");
- sb.AppendLine(" {");
- sb.AppendLine(" _baseRepository = baseRepository;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #region 私有方法");
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 列表条件过滤");
- sb.AppendLine(" /// 建议该方法放在Partial部分类中,因为代码生成时当前类会被覆盖(该方法在生成时将会被注释)");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"param\"></param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" private Expression<Func<" + baseConfigModel.FileConfig.EntityName + ", bool>> ListFilterPartial(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param)");
- sb.AppendLine(" {");
- sb.AppendLine(" var expression = LinqExtensions.True<" + baseConfigModel.FileConfig.EntityName + ">();");
- //只有BaseExtensionEntity实体才会存在BaseIsDelete字段
- if (baseEntity.Equals("BaseExtensionEntity"))
- sb.AppendLine(" expression = expression.And(t => t.BaseIsDelete == (int)IsDeleteEnum.No);");
- sb.AppendLine(" if (param != null)");
- sb.AppendLine(" {");
- sb.AppendLine(" }");
- sb.AppendLine(" return expression;");
- sb.AppendLine(" }");
- sb.AppendLine(" #endregion");
- sb.AppendLine(" }");
- sb.AppendLine("}");
- return sb.ToString();
- }
- #endregion
- #region BuildIService
- public string BuildIService(BaseConfigModel baseConfigModel)
- {
- StringBuilder sb = new StringBuilder();
- string method = string.Empty;
- sb.AppendLine("using YiSha.Util.Model;");
- sb.AppendLine("using System.Data.Common;");
- sb.AppendLine("using System.Threading.Tasks;");
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using YiSha.Entity." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.Model.Param." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine();
- sb.AppendLine("namespace YiSha.IService." + baseConfigModel.OutputConfig.OutputModule);
- sb.AppendLine("{");
- SetClassDescription("服务接口类", baseConfigModel, sb);
- sb.AppendLine(" public partial interface I" + baseConfigModel.FileConfig.ServiceName + "");
- sb.AppendLine(" {");
- sb.AppendLine(" #region 获取数据");
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取列表数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"param\">请求参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<List<" + baseConfigModel.FileConfig.EntityName + ">> GetList(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取分页数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"param\">请求参数</param>");
- sb.AppendLine(" /// <param name=\"pagination\">分页条件</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<List<" + baseConfigModel.FileConfig.EntityName + ">> GetPageList(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param, Pagination pagination);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取指定列数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"column\">表字段列</param>");
- sb.AppendLine(" /// <param name=\"where\">条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">条件参数</param>");
- sb.AppendLine(" /// <param name=\"sort\">排序列</param>");
- sb.AppendLine(" /// <param name=\"sortType\">排序类型</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<List<" + baseConfigModel.FileConfig.EntityName + ">> GetListColumn(string column, string where, List<DbParameter> parameters, string groupBy = \"\", string sort = \"basecreatetime\", string sortType = \"desc\");");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据主键Id获取数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"id\">主键id</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<" + baseConfigModel.FileConfig.EntityName + "> GetEntity(int id);");
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" #region 提交数据");
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 保存数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"entity\">实体参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task SaveForm(" + baseConfigModel.FileConfig.EntityName + " entity);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 保存多条数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"list\">数据列表</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<int> InsertMany(List<" + baseConfigModel.FileConfig.EntityName + "> list);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据主键Id删除数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"ids\">主键Id</param>");
- sb.AppendLine(" /// <param name=\"del\">是否真删除 true真删除 false软删除 默认false</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<int> DeleteFormById(string ids, bool del = false);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据条件删除数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"where\">where条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">参数</param>");
- sb.AppendLine(" /// <param name=\"del\">是否真删除 true真删除 false软删除 默认false</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<int> DeleteFormByWhere(string where, List<DbParameter> parameters, bool del = false);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 修改多条数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"list\">数据列表</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<int> UpdateMany(List<" + baseConfigModel.FileConfig.EntityName + "> list);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据条件修改数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"setField\">修改字段</param>");
- sb.AppendLine(" /// <param name=\"where\">where条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<int> UpdateFormByWhere(string setField, string where, List<DbParameter> parameters);");
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" #region 私有方法");
- sb.AppendLine(" ///// <summary>");
- sb.AppendLine(" ///// 列表条件过滤");
- sb.AppendLine(" ///// 建议该方法放在Partial部分类中,因为代码生成时当前类会被覆盖(该方法在生成时将会被注释)");
- sb.AppendLine(" ///// </summary>");
- sb.AppendLine(" ///// <param name=\"param\"></param>");
- sb.AppendLine(" ///// <returns></returns>");
- sb.AppendLine(" //Expression<Func<" + baseConfigModel.FileConfig.EntityName + ", bool>> ListFilter(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param);");
- sb.AppendLine(" #endregion");
- sb.AppendLine(" }");
- sb.AppendLine("}");
- return sb.ToString();
- }
- #endregion
- #region BuildIService_Partial
- public string BuildIService_Partial(BaseConfigModel baseConfigModel)
- {
- StringBuilder sb = new StringBuilder();
- string method = string.Empty;
- sb.AppendLine("using YiSha.Util.Model;");
- sb.AppendLine("using System.Data.Common;");
- sb.AppendLine("using System.Threading.Tasks;");
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using YiSha.Entity." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.Model.Param." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine();
- sb.AppendLine("namespace YiSha.IService." + baseConfigModel.OutputConfig.OutputModule);
- sb.AppendLine("{");
- SetClassDescription("服务接口类(部分类)", baseConfigModel, sb);
- sb.AppendLine(" public partial interface I" + baseConfigModel.FileConfig.ServiceName + "");
- sb.AppendLine(" {");
- sb.AppendLine(" }");
- sb.AppendLine("}");
- return sb.ToString();
- }
- #endregion
- #region BuildBusiness
- public string BuildBusiness(BaseConfigModel baseConfigModel)
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using System.Threading.Tasks;");
- sb.AppendLine("using YiSha.Util.Extension;");
- sb.AppendLine("using YiSha.Util.Model;");
- sb.AppendLine("using System.Data.Common;");
- sb.AppendLine("using YiSha.Entity." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.Model.Param." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.IService." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.IBusiness." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine();
- sb.AppendLine("namespace YiSha.Business." + baseConfigModel.OutputConfig.OutputModule);
- sb.AppendLine("{");
- SetClassDescription("业务实现类", baseConfigModel, sb);
- sb.AppendLine(" public partial class " + baseConfigModel.FileConfig.BusinessName + " : I" + baseConfigModel.FileConfig.IBusinessName + "");
- sb.AppendLine(" {");
- sb.AppendLine(" #region 获取数据");
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取列表数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"param\">请求参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<TData<List<" + baseConfigModel.FileConfig.EntityName + ">>> GetList(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData<List<" + baseConfigModel.FileConfig.EntityName + ">> obj = new TData<List<" + baseConfigModel.FileConfig.EntityName + ">>();");
- sb.AppendLine(" obj.Data = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + ".GetList(param);");
- sb.AppendLine(" obj.Total = obj.Data.Count;");
- sb.AppendLine(" obj.Tag = 1;");
- sb.AppendLine(" return obj;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取分页数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"param\">请求参数</param>");
- sb.AppendLine(" /// <param name=\"pagination\">分页条件</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<TData<List<" + baseConfigModel.FileConfig.EntityName + ">>> GetPageList(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param, Pagination pagination)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData<List<" + baseConfigModel.FileConfig.EntityName + ">> obj = new TData<List<" + baseConfigModel.FileConfig.EntityName + ">>();");
- sb.AppendLine(" obj.Data = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + ".GetPageList(param, pagination);");
- sb.AppendLine(" obj.Total = pagination.TotalCount;");
- sb.AppendLine(" obj.Tag = 1;");
- sb.AppendLine(" return obj;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取指定列数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"column\">表字段列</param>");
- sb.AppendLine(" /// <param name=\"where\">条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">条件参数</param>");
- sb.AppendLine(" /// <param name=\"sort\">排序列</param>");
- sb.AppendLine(" /// <param name=\"sortType\">排序类型</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<TData<List<" + baseConfigModel.FileConfig.EntityName + ">>> GetListColumn(string column, string where, List<DbParameter> parameters, string groupBy = \"\", string sort = \"basecreatetime\", string sortType = \"desc\")");
- sb.AppendLine(" {");
- sb.AppendLine(" TData<List<" + baseConfigModel.FileConfig.EntityName + ">> obj = new TData<List<" + baseConfigModel.FileConfig.EntityName + ">>();");
- sb.AppendLine(" obj.Data = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + ".GetListColumn(column, where, parameters, groupBy, sort, sortType);");
- sb.AppendLine(" obj.Total = obj.Data.Count;");
- sb.AppendLine(" obj.Tag = 1;");
- sb.AppendLine(" return obj;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据主键Id获取数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"id\">主键id</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<TData<" + baseConfigModel.FileConfig.EntityName + ">> GetEntity(int id)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData<" + baseConfigModel.FileConfig.EntityName + "> obj = new TData<" + baseConfigModel.FileConfig.EntityName + ">();");
- sb.AppendLine(" obj.Data = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + ".GetEntity(id);");
- sb.AppendLine(" if (obj.Data != null)");
- sb.AppendLine(" {");
- sb.AppendLine(" obj.Tag = 1;");
- sb.AppendLine(" }");
- sb.AppendLine(" return obj;");
- sb.AppendLine(" }");
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" #region 提交数据");
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 保存数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"entity\">实体参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<TData<int>> SaveForm(" + baseConfigModel.FileConfig.EntityName + " entity)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData<int> obj = new TData<int>();");
- sb.AppendLine(" await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + ".SaveForm(entity);");
- sb.AppendLine(" obj.Data = entity.Id;");
- sb.AppendLine(" obj.Tag = 1;");
- sb.AppendLine(" return obj;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据主键Id删除数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"ids\">主键Id</param>");
- sb.AppendLine(" /// <param name=\"del\">是否真删除 true真删除 false软删除 默认false</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<TData> DeleteFormById(string ids, bool del = false)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData obj = new TData();");
- sb.AppendLine(" obj.Tag = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + ".DeleteFormById(ids, del);");
- sb.AppendLine(" return obj;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据条件删除数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"where\">where条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">参数</param>");
- sb.AppendLine(" /// <param name=\"del\">是否真删除 true真删除 false软删除 默认false</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<TData> DeleteFormByWhere(string where, List<DbParameter> parameters, bool del = false)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData obj = new TData();");
- sb.AppendLine(" obj.Tag = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + ".DeleteFormByWhere(where, parameters, del);");
- sb.AppendLine(" return obj;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据条件修改数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"setField\">修改字段</param>");
- sb.AppendLine(" /// <param name=\"where\">where条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" public async Task<TData> UpdateFormByWhere(string setField, string where, List<DbParameter> parameters)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData obj = new TData();");
- sb.AppendLine(" obj.Tag = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + ".UpdateFormByWhere(setField, where, parameters);");
- sb.AppendLine(" return obj;");
- sb.AppendLine(" }");
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" #region 私有方法");
- sb.AppendLine(" #endregion");
- sb.AppendLine(" }");
- sb.AppendLine("}");
- return sb.ToString();
- }
- #endregion
- #region BuildBusiness_Partial
- public string BuildBusiness_Partial(BaseConfigModel baseConfigModel)
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using System.Threading.Tasks;");
- sb.AppendLine("using YiSha.Util.Extension;");
- sb.AppendLine("using YiSha.Util.Model;");
- sb.AppendLine("using System.Data.Common;");
- sb.AppendLine("using YiSha.Entity." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.Model.Param." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.IService." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.IBusiness." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine();
- sb.AppendLine("namespace YiSha.Business." + baseConfigModel.OutputConfig.OutputModule);
- sb.AppendLine("{");
- SetClassDescription("业务实现类(部分类)", baseConfigModel, sb);
- sb.AppendLine(" public partial class " + baseConfigModel.FileConfig.BusinessName + "");
- sb.AppendLine(" {");
- sb.AppendLine(" private I" + baseConfigModel.FileConfig.ServiceName + " _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + ";");
- sb.AppendLine(" public " + baseConfigModel.FileConfig.BusinessName + " (I" + baseConfigModel.FileConfig.ServiceName + " " + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + ")");
- sb.AppendLine(" {");
- sb.AppendLine(" _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + " = " + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.ServiceName) + ";");
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine("}");
- return sb.ToString();
- }
- #endregion
- #region BuildIBusiness
- public string BuildIBusiness(BaseConfigModel baseConfigModel)
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine("using YiSha.Util.Model;");
- sb.AppendLine("using System.Data.Common;");
- sb.AppendLine("using System.Threading.Tasks;");
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using YiSha.Entity." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.Model.Param." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("namespace YiSha.IBusiness." + baseConfigModel.OutputConfig.OutputModule);
- sb.AppendLine("{");
- SetClassDescription("业务接口类", baseConfigModel, sb);
- sb.AppendLine(" public partial interface I" + baseConfigModel.FileConfig.BusinessName);
- sb.AppendLine(" {");
- sb.AppendLine(" #region 获取数据");
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取列表数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"param\">请求参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<TData<List<" + baseConfigModel.FileConfig.EntityName + ">>> GetList(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取分页数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"param\">请求参数</param>");
- sb.AppendLine(" /// <param name=\"pagination\">分页条件</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<TData<List<" + baseConfigModel.FileConfig.EntityName + ">>> GetPageList(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param, Pagination pagination);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 获取指定列数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"column\">表字段列</param>");
- sb.AppendLine(" /// <param name=\"where\">条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">条件参数</param>");
- sb.AppendLine(" /// <param name=\"sort\">排序列</param>");
- sb.AppendLine(" /// <param name=\"sortType\">排序类型</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<TData<List<" + baseConfigModel.FileConfig.EntityName + ">>> GetListColumn(string column, string where, List<DbParameter> parameters, string groupBy = \"\", string sort = \"basecreatetime\", string sortType = \"desc\");");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据主键Id获取数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"id\">主键id</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<TData<" + baseConfigModel.FileConfig.EntityName + ">> GetEntity(int id);");
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" #region 提交数据");
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 保存数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"entity\">实体参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<TData<int>> SaveForm(" + baseConfigModel.FileConfig.EntityName + " entity);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据主键Id删除数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"ids\">主键Id</param>");
- sb.AppendLine(" /// <param name=\"del\">是否真删除 true真删除 false软删除 默认false</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<TData> DeleteFormById(string ids, bool del = false);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据条件删除数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"where\">where条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">参数</param>");
- sb.AppendLine(" /// <param name=\"del\">是否真删除 true真删除 false软删除 默认false</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<TData> DeleteFormByWhere(string where, List<DbParameter> parameters, bool del = false);");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 根据条件修改数据");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"setField\">修改字段</param>");
- sb.AppendLine(" /// <param name=\"where\">where条件</param>");
- sb.AppendLine(" /// <param name=\"parameters\">参数</param>");
- sb.AppendLine(" /// <returns></returns>");
- sb.AppendLine(" Task<TData> UpdateFormByWhere(string setField, string where, List<DbParameter> parameters);");
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" #region 私有方法");
- sb.AppendLine(" #endregion");
- sb.AppendLine(" }");
- sb.AppendLine("}");
- return sb.ToString();
- }
- #endregion
- #region BuildIBusiness_Partial
- public string BuildIBusiness_Partial(BaseConfigModel baseConfigModel)
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine("using YiSha.Util.Model;");
- sb.AppendLine("using System.Data.Common;");
- sb.AppendLine("using System.Threading.Tasks;");
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using YiSha.Entity." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.Model.Param." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("namespace YiSha.IBusiness." + baseConfigModel.OutputConfig.OutputModule);
- sb.AppendLine("{");
- SetClassDescription("业务接口类(部分类)", baseConfigModel, sb);
- sb.AppendLine(" public partial interface I" + baseConfigModel.FileConfig.BusinessName);
- sb.AppendLine(" {");
- sb.AppendLine(" }");
- sb.AppendLine("}");
- return sb.ToString();
- }
- #endregion
- #region BuildController
- public string BuildController(BaseConfigModel baseConfigModel)
- {
- string modulePrefix = GetModulePrefix(baseConfigModel);
- string classPrefix = baseConfigModel.FileConfig.ClassPrefix.ToLower();
- StringBuilder sb = new StringBuilder();
- sb.AppendLine("using System;");
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using System.Threading.Tasks;");
- sb.AppendLine("using System.Linq;");
- sb.AppendLine("using System.Web;");
- sb.AppendLine("using Microsoft.AspNetCore.Mvc;");
- sb.AppendLine("using YiSha.Util;");
- sb.AppendLine("using YiSha.Util.Model;");
- sb.AppendLine("using YiSha.Entity;");
- sb.AppendLine("using YiSha.Model;");
- sb.AppendLine("using YiSha.Admin.Web.Controllers;");
- sb.AppendLine("using YiSha.Entity." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.IService." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.Model.Param." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine("using YiSha.IBusiness." + baseConfigModel.OutputConfig.OutputModule + ";");
- sb.AppendLine();
- sb.AppendLine("namespace YiSha.Admin.Web.Areas." + baseConfigModel.OutputConfig.OutputModule + ".Controllers");
- sb.AppendLine("{");
- SetClassDescription("控制器类", baseConfigModel, sb);
- sb.AppendLine(" [Area(\"" + baseConfigModel.OutputConfig.OutputModule + "\")]");
- sb.AppendLine(" public class " + baseConfigModel.FileConfig.ControllerName + " : BaseController");
- sb.AppendLine(" {");
- sb.AppendLine(" private I" + baseConfigModel.FileConfig.IBusinessName + " _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.IBusinessName) + ";");
- sb.AppendLine();
- sb.AppendLine(" public " + baseConfigModel.FileConfig.ControllerName + "(I" + baseConfigModel.FileConfig.IBusinessName + " " + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.IBusinessName) + ")");
- sb.AppendLine(" {");
- sb.AppendLine(" _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.IBusinessName) + " = " + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.IBusinessName) + ";");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #region 视图功能");
- sb.AppendLine(" [AuthorizeFilter(\"" + string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, "view") + "\")]");
- sb.AppendLine(" public ActionResult " + baseConfigModel.FileConfig.PageIndexName + "()");
- sb.AppendLine(" {");
- sb.AppendLine(" return View();");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" public ActionResult " + baseConfigModel.FileConfig.PageFormName + "()");
- sb.AppendLine(" {");
- sb.AppendLine(" return View();");
- sb.AppendLine(" }");
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" #region 获取数据");
- sb.AppendLine(" [HttpGet]");
- sb.AppendLine(" [AuthorizeFilter(\"" + string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, "search") + "\")]");
- sb.AppendLine(" public async Task<ActionResult> GetListJson(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData<List<" + baseConfigModel.FileConfig.EntityName + ">> obj = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.IBusinessName) + ".GetList(param);");
- sb.AppendLine(" return Json(obj);");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" [HttpGet]");
- sb.AppendLine(" [AuthorizeFilter(\"" + string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, "search") + "\")]");
- sb.AppendLine(" public async Task<ActionResult> GetPageListJson(" + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam") + " param, Pagination pagination)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData<List<" + baseConfigModel.FileConfig.EntityName + ">> obj = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.IBusinessName) + ".GetPageList(param, pagination);");
- sb.AppendLine(" return Json(obj);");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" [HttpGet]");
- sb.AppendLine(" public async Task<ActionResult> GetFormJson(int id)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData<" + baseConfigModel.FileConfig.EntityName + "> obj = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.IBusinessName) + ".GetEntity(id);");
- sb.AppendLine(" return Json(obj);");
- sb.AppendLine(" }");
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" #region 提交数据");
- sb.AppendLine(" [HttpPost]");
- sb.AppendLine(" [AuthorizeFilter(\"" + string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, "add") + "," + string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, "edit") + "\")]");
- sb.AppendLine(" public async Task<ActionResult> SaveFormJson(" + baseConfigModel.FileConfig.EntityName + " entity)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData<int> obj = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.IBusinessName) + ".SaveForm(entity);");
- sb.AppendLine(" return Json(obj);");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" [HttpPost]");
- sb.AppendLine(" [AuthorizeFilter(\"" + string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, "delete") + "\")]");
- sb.AppendLine(" public async Task<ActionResult> DeleteFormJson(string ids)");
- sb.AppendLine(" {");
- sb.AppendLine(" TData obj = await _" + TableMappingHelper.FirstLetterLowercase(baseConfigModel.FileConfig.IBusinessName) + ".DeleteFormById(ids);");
- sb.AppendLine(" return Json(obj);");
- sb.AppendLine(" }");
- sb.AppendLine(" #endregion");
- sb.AppendLine(" }");
- sb.AppendLine("}");
- return sb.ToString();
- }
- #endregion
- #region BuildIndex
- public string BuildIndex(BaseConfigModel baseConfigModel)
- {
- #region 初始化集合
- if (baseConfigModel.PageIndex.ButtonList == null)
- {
- baseConfigModel.PageIndex.ButtonList = new List<string>();
- }
- if (baseConfigModel.PageIndex.ColumnList == null)
- {
- baseConfigModel.PageIndex.ColumnList = new List<string>();
- }
- #endregion
- StringBuilder sb = new StringBuilder();
- sb.AppendLine("@{");
- sb.AppendLine(" Layout = \"~/Views/Shared/_Index.cshtml\";");
- sb.AppendLine(" }");
- sb.AppendLine("<div class=\"container-div\">");
- sb.AppendLine(" <div class=\"row\">");
- #region 是否显示搜索
- if (baseConfigModel.PageIndex.IsSearch == 1)
- {
- string fieldName = TextHelper.GetCustomValue(baseConfigModel.PageIndex.ColumnList.FirstOrDefault(), "fieldName");
- string fieldNameLower = TableMappingHelper.FirstLetterLowercase(fieldName);
- sb.AppendLine(" <div id=\"searchDiv\" class=\"col-sm-12 search-collapse\">");
- sb.AppendLine(" <div class=\"select-list\">");
- sb.AppendLine(" <ul>");
- sb.AppendLine(" <li>");
- sb.AppendLine(" " + fieldName + ":<input id=\"" + fieldNameLower + "\" col=\"" + fieldName + "\" type=\"text\" autocomplete=\"off\" />");
- sb.AppendLine(" </li>");
- sb.AppendLine(" <li>");
- sb.AppendLine(" <a id=\"btnSearch\" class=\"btn btn-primary btn-sm\" onclick=\"searchGrid()\"><i class=\"fa fa-search\"></i> 搜索</a>");
- sb.AppendLine(" </li>");
- sb.AppendLine(" </ul>");
- sb.AppendLine(" </div>");
- sb.AppendLine(" </div>");
- }
- #endregion
- #region 是否显示工具栏
- if (baseConfigModel.PageIndex.ButtonList.Where(p => p != "btnSearch").Any())
- {
- sb.AppendLine(" <div class=\"btn-group-sm hidden-xs\" id=\"toolbar\">");
- if (baseConfigModel.PageIndex.ButtonList.Where(p => p == "btnAdd").Any())
- {
- sb.AppendLine(" <a id=\"btnAdd\" class=\"btn btn-success\" onclick=\"showSaveForm(true)\"><i class=\"fa fa-plus\"></i> 新增</a>");
- }
- if (baseConfigModel.PageIndex.ButtonList.Where(p => p == "btnEdit").Any())
- {
- sb.AppendLine(" <a id=\"btnEdit\" class=\"btn btn-primary disabled\" onclick=\"showSaveForm(false)\"><i class=\"fa fa-edit\"></i> 修改</a>");
- }
- if (baseConfigModel.PageIndex.ButtonList.Where(p => p == "btnDelete").Any())
- {
- sb.AppendLine(" <a id=\"btnDelete\" class=\"btn btn-danger disabled\" onclick=\"deleteForm()\"><i class=\"fa fa-remove\"></i> 删除</a>");
- }
- sb.AppendLine(" </div>");
- }
- #endregion
- sb.AppendLine(" <div class=\"col-sm-12 select-table table-striped\">");
- sb.AppendLine(" <table id=\"gridTable\" data-mobile-responsive=\"true\"></table>");
- sb.AppendLine(" </div>");
- sb.AppendLine(" </div>");
- sb.AppendLine("</div>");
- sb.AppendLine("");
- sb.AppendLine("<script type=\"text/javascript\">");
- sb.AppendLine(" $(function () {");
- sb.AppendLine(" initGrid();");
- sb.AppendLine(" });");
- sb.AppendLine("");
- sb.AppendLine(" function initGrid() {");
- sb.AppendLine(" var queryUrl = '@Url.Content(\"~/" + baseConfigModel.OutputConfig.OutputModule + "/" + baseConfigModel.FileConfig.ClassPrefix + "/GetPageListJson\")';");
- sb.AppendLine(" $('#gridTable').ysTable({");
- sb.AppendLine(" url: queryUrl,");
- sb.AppendLine(" columns: [");
- sb.AppendLine(" { checkbox: true, visible: true },");
- sb.AppendLine(" { field: 'Id', title: 'Id', visible: false },");
- foreach (string column in baseConfigModel.PageIndex.ColumnList)
- {
- sb.AppendLine(" { field: '" + column + "', title: '" + column + "' },");
- }
- sb.AppendLine(" ],");
- if (baseConfigModel.PageIndex.IsPagination == 0)
- {
- sb.AppendLine(" pagination: false,");
- }
- sb.AppendLine(" queryParams: function (params) {");
- sb.AppendLine(" var pagination = $('#gridTable').ysTable('getPagination', params);");
- sb.AppendLine(" var queryString = $('#searchDiv').getWebControls(pagination);");
- sb.AppendLine(" return queryString;");
- sb.AppendLine(" }");
- sb.AppendLine(" });");
- sb.AppendLine(" }");
- sb.AppendLine("");
- sb.AppendLine(" function searchGrid() {");
- sb.AppendLine(" $('#gridTable').ysTable('search');");
- sb.AppendLine(" resetToolbarStatus();");
- sb.AppendLine(" }");
- sb.AppendLine("");
- #region 新增和修改方法
- if (baseConfigModel.PageIndex.ButtonList.Where(p => p == "btnAdd" || p == "btnEdit").Any())
- {
- sb.AppendLine(" function showSaveForm(bAdd) {");
- sb.AppendLine(" var id = '';");
- sb.AppendLine(" if (!bAdd) {");
- sb.AppendLine(" var selectedRow = $('#gridTable').bootstrapTable('getSelections');");
- sb.AppendLine(" if (!ys.checkRowEdit(selectedRow)) {");
- sb.AppendLine(" return;");
- sb.AppendLine(" }");
- sb.AppendLine(" else {");
- sb.AppendLine(" id = selectedRow[0].Id;");
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine(" ys.openDialog({");
- sb.AppendLine(" title: !ys.isNullOrEmpty(id) ? '编辑' : '添加',");
- sb.AppendLine(" content: '@Url.Content(\"~/" + baseConfigModel.OutputConfig.OutputModule + "/" + baseConfigModel.FileConfig.ClassPrefix + "/" + baseConfigModel.FileConfig.ClassPrefix + "Form\")' + '?id=\' + id,");
- sb.AppendLine(" width: '768px',");
- sb.AppendLine(" height: '550px',");
- sb.AppendLine(" callback: function (index, layero) {");
- sb.AppendLine(" var iframeWin = window[layero.find('iframe')[0]['name']];");
- sb.AppendLine(" iframeWin.saveForm(index);");
- sb.AppendLine(" }");
- sb.AppendLine(" });");
- sb.AppendLine(" }");
- }
- #endregion
- sb.AppendLine("");
- #region 删除方法
- if (baseConfigModel.PageIndex.ButtonList.Where(p => p == "btnDelete").Any())
- {
- sb.AppendLine(" function deleteForm() {");
- sb.AppendLine(" var selectedRow = $('#gridTable').bootstrapTable('getSelections');");
- sb.AppendLine(" if (ys.checkRowDelete(selectedRow)) {");
- sb.AppendLine(" ys.confirm('确认要删除选中的' + selectedRow.length + '条数据吗?', function () {");
- sb.AppendLine(" var ids = ys.getIds(selectedRow);");
- sb.AppendLine(" ys.ajax({");
- sb.AppendLine(" url: '@Url.Content(\"~/" + baseConfigModel.OutputConfig.OutputModule + "/" + baseConfigModel.FileConfig.ClassPrefix + "/DeleteFormJson\")' + '?ids=' + ids,");
- sb.AppendLine(" type: 'post',");
- sb.AppendLine(" success: function (obj) {");
- sb.AppendLine(" if (obj.Success) {");
- sb.AppendLine(" ys.msgSuccess(obj.Message);");
- sb.AppendLine(" searchGrid();");
- sb.AppendLine(" }");
- sb.AppendLine(" else {");
- sb.AppendLine(" ys.msgError(obj.Message);");
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine(" });");
- sb.AppendLine(" });");
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- }
- #endregion
- sb.AppendLine("</script>");
- return sb.ToString();
- }
- #endregion
- #region BuildForm
- public string BuildForm(BaseConfigModel baseConfigModel)
- {
- #region 初始化集合
- if (baseConfigModel.PageForm.FieldList == null)
- {
- baseConfigModel.PageForm.FieldList = new List<string>();
- }
- #endregion
- StringBuilder sb = new StringBuilder();
- sb.AppendLine("@{");
- sb.AppendLine(" Layout = \"~/Views/Shared/_FormWhite.cshtml\";");
- sb.AppendLine("}");
- sb.AppendLine("");
- sb.AppendLine("<div class=\"wrapper animated fadeInRight\">");
- sb.AppendLine(" <form id=\"form\" class=\"form-horizontal m\">");
- #region 表单控件
- if (baseConfigModel.PageForm.FieldList.Count > 0)
- {
- string field = string.Empty;
- string fieldLower = string.Empty;
- switch (baseConfigModel.PageForm.ShowMode)
- {
- case 1:
- for (int i = 0; i < baseConfigModel.PageForm.FieldList.Count; i++)
- {
- field = baseConfigModel.PageForm.FieldList[i];
- fieldLower = TableMappingHelper.FirstLetterLowercase(field);
- sb.AppendLine(" <div class=\"form-group\">");
- sb.AppendLine(" <label class=\"col-sm-3 control-label \">" + field + (i == 0 ? "<font class=\"red\"> *</font>" : string.Empty) + "</label>");
- sb.AppendLine(" <div class=\"col-sm-8\">");
- sb.AppendLine(" <input id=\"" + fieldLower + "\" col=\"" + field + "\" type=\"text\" class=\"form-control\" autocomplete=\"off\" />");
- sb.AppendLine(" </div>");
- sb.AppendLine(" </div>");
- }
- break;
- case 2:
- for (int i = 0; i < baseConfigModel.PageForm.FieldList.Count; i++)
- {
- field = baseConfigModel.PageForm.FieldList[i];
- fieldLower = TableMappingHelper.FirstLetterLowercase(field);
- if (i % 2 == 0)
- {
- sb.AppendLine(" <div class=\"form-group\">");
- }
- sb.AppendLine(" <label class=\"col-sm-2 control-label \">" + field + "<font class=\"red\"> *</font></label>");
- sb.AppendLine(" <div class=\"col-sm-4\">");
- sb.AppendLine(" <input id=\"" + fieldLower + "\" col=\"" + field + "\" type=\"text\" class=\"form-control\" autocomplete=\"off\" />");
- sb.AppendLine(" </div>");
- if (i % 2 == 1)
- {
- sb.AppendLine(" </div>");
- }
- }
- break;
- }
- }
- #endregion
- sb.AppendLine(" </form>");
- sb.AppendLine("</div>");
- sb.AppendLine("");
- sb.AppendLine("<script type=\"text/javascript\">");
- sb.AppendLine(" var id = ys.request(\"id\");");
- sb.AppendLine(" $(function () {");
- sb.AppendLine(" getForm();");
- sb.AppendLine("");
- sb.AppendLine(" $('#form').validate({");
- sb.AppendLine(" rules: {");
- sb.AppendLine(" " + TextHelper.GetCustomValue(TableMappingHelper.FirstLetterLowercase(baseConfigModel.PageForm.FieldList.FirstOrDefault()), "fieldName") + ": { required: true }");
- sb.AppendLine(" }");
- sb.AppendLine(" });");
- sb.AppendLine(" });");
- sb.AppendLine("");
- sb.AppendLine(" function getForm() {");
- sb.AppendLine(" if (!ys.isNullOrEmpty(id)) {");
- sb.AppendLine(" ys.ajax({");
- sb.AppendLine(" url: '@Url.Content(\"~/" + baseConfigModel.OutputConfig.OutputModule + "/" + baseConfigModel.FileConfig.ClassPrefix + "/GetFormJson\")' + '?id=' + id,");
- sb.AppendLine(" type: 'get',");
- sb.AppendLine(" success: function (obj) {");
- sb.AppendLine(" if (obj.Success) {");
- sb.AppendLine(" $('#form').setWebControls(obj.Data);");
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine(" });");
- sb.AppendLine(" }");
- sb.AppendLine(" else {");
- sb.AppendLine(" var defaultData = {};");
- sb.AppendLine(" $('#form').setWebControls(defaultData);");
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine("");
- sb.AppendLine(" function saveForm(index) {");
- sb.AppendLine(" if ($('#form').validate().form()) {");
- sb.AppendLine(" var postData = $('#form').getWebControls({ Id: id });");
- sb.AppendLine(" ys.ajax({");
- sb.AppendLine(" url: '@Url.Content(\"~/" + baseConfigModel.OutputConfig.OutputModule + "/" + baseConfigModel.FileConfig.ClassPrefix + "/SaveFormJson\")',");
- sb.AppendLine(" type: 'post',");
- sb.AppendLine(" data: postData,");
- sb.AppendLine(" success: function (obj) {");
- sb.AppendLine(" if (obj.Success) {");
- sb.AppendLine(" ys.msgSuccess(obj.Message);");
- sb.AppendLine(" parent.searchGrid();");
- sb.AppendLine(" parent.layer.close(index);");
- sb.AppendLine(" }");
- sb.AppendLine(" else {");
- sb.AppendLine(" ys.msgError(obj.Message);");
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine(" });");
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine("</script>");
- sb.AppendLine("");
- return sb.ToString();
- }
- #endregion
- #region BuildMenu
- public string BuildMenu(BaseConfigModel baseConfigModel)
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine();
- sb.AppendLine(" 菜单路径:" + baseConfigModel.OutputConfig.OutputModule + "/" + baseConfigModel.FileConfig.ClassPrefix + "/" + baseConfigModel.FileConfig.PageIndexName);
- sb.AppendLine();
- string modulePrefix = GetModulePrefix(baseConfigModel);
- string classPrefix = baseConfigModel.FileConfig.ClassPrefix.ToLower();
- sb.AppendLine(" 页面显示权限:" + string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, "view"));
- sb.AppendLine();
- List<KeyValue> list = GetButtonAuthorizeList();
- if (baseConfigModel.PageIndex.IsSearch == 1)
- {
- KeyValue button = list.Where(p => p.Key == "btnSearch").FirstOrDefault();
- sb.AppendLine(" 按钮" + button.Description + "权限:" + string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, button.Value));
- }
- foreach (string btn in baseConfigModel.PageIndex.ButtonList)
- {
- KeyValue button = list.Where(p => p.Key == btn).FirstOrDefault();
- sb.AppendLine(" 按钮" + button.Description + "权限:" + string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, button.Value));
- }
- sb.AppendLine();
- return sb.ToString();
- }
- #endregion
- #region CreateCode
- public async Task<List<KeyValue>> CreateCode(BaseConfigModel baseConfigModel, string code, IMenuCacheBusiness menuCacheBusiness)
- {
- List<KeyValue> result = new List<KeyValue>();
- JObject param = code.ToJObject();
- #region 实体类
- if (!string.IsNullOrEmpty(param["CodeEntity"].ParseToString()))
- {
- string codeEntity = HttpUtility.HtmlDecode(param["CodeEntity"].ToString());
- string codePath = Path.Combine(baseConfigModel.OutputConfig.OutputEntity, "YiSha.Entity", baseConfigModel.OutputConfig.OutputModule, baseConfigModel.FileConfig.EntityName + ".cs");
- CreateCodeFile(codePath, codeEntity, out bool isAdd, true);
- result.Add(new KeyValue { Key = "实体类", Value = codePath });
- }
- #endregion
- #region 实体查询类
- if (!param["CodeEntityParam"].IsEmpty())
- {
- string codeListEntity = HttpUtility.HtmlDecode(param["CodeEntityParam"].ToString());
- string codePath = Path.Combine(baseConfigModel.OutputConfig.OutputEntity, "YiSha.Model", "Param", baseConfigModel.OutputConfig.OutputModule, baseConfigModel.FileConfig.EntityParamName + ".cs");
- CreateCodeFile(codePath, codeListEntity, out bool isAdd); //查询实体不需要生成
- result.Add(new KeyValue { Key = "实体查询类", Value = codePath });
- }
- #endregion
- #region 服务接口类
- if (!param["CodeIService"].IsEmpty())
- {
- string codeService = HttpUtility.HtmlDecode(param["CodeIService"].ToString());
- string codePath = Path.Combine(baseConfigModel.OutputConfig.OutputBusiness, "YiSha.IService", baseConfigModel.OutputConfig.OutputModule, "I" + baseConfigModel.FileConfig.IServiceName + ".cs");
- CreateCodeFile(codePath, codeService, out bool isAdd, true);
- result.Add(new KeyValue { Key = "服务接口类", Value = codePath });
- }
- #endregion
- #region 服务接口类(部分类)
- if (!param["CodeIServicePartial"].IsEmpty())
- {
- string codeService = HttpUtility.HtmlDecode(param["CodeIServicePartial"].ToString());
- string partialPath = Path.Combine(baseConfigModel.OutputConfig.OutputBusiness, "YiSha.IService", baseConfigModel.OutputConfig.OutputModule, "Partial");
- CreatePartialFilePath(partialPath);
- string codePath = Path.Combine(partialPath, "I" + baseConfigModel.FileConfig.IServiceName + ".cs");
- CreateCodeFile(codePath, codeService, out bool isAdd);
- result.Add(new KeyValue { Key = "服务接口类(部分类)", Value = codePath });
- }
- #endregion
- #region 服务实现类
- if (!param["CodeService"].IsEmpty())
- {
- string codeService = HttpUtility.HtmlDecode(param["CodeService"].ToString());
- string codePath = Path.Combine(baseConfigModel.OutputConfig.OutputBusiness, "YiSha.Service", baseConfigModel.OutputConfig.OutputModule, baseConfigModel.FileConfig.ServiceName + ".cs");
- CreateCodeFile(codePath, codeService, out bool isAdd, true);
- result.Add(new KeyValue { Key = "服务实现类", Value = codePath });
- }
- #endregion
- #region 服务实现类(部分类)
- if (!param["CodeServicePartial"].IsEmpty())
- {
- string codeService = HttpUtility.HtmlDecode(param["CodeServicePartial"].ToString());
- string partialPath = Path.Combine(baseConfigModel.OutputConfig.OutputBusiness, "YiSha.Service", baseConfigModel.OutputConfig.OutputModule, "Partial");
- CreatePartialFilePath(partialPath);
- string codePath = Path.Combine(partialPath, baseConfigModel.FileConfig.ServiceName + ".cs");
- CreateCodeFile(codePath, codeService, out bool isAdd);
- result.Add(new KeyValue { Key = "服务实现类(部分类)", Value = codePath });
- }
- #endregion
- #region 业务接口类
- if (!param["CodeIBusiness"].IsEmpty())
- {
- string codeBusiness = HttpUtility.HtmlDecode(param["CodeIBusiness"].ToString());
- string codePath = Path.Combine(baseConfigModel.OutputConfig.OutputBusiness, "YiSha.IBusiness", baseConfigModel.OutputConfig.OutputModule, "I" + baseConfigModel.FileConfig.IBusinessName + ".cs");
- CreateCodeFile(codePath, codeBusiness, out bool isAdd, true);
- result.Add(new KeyValue { Key = "业务接口类", Value = codePath });
- }
- #endregion
- #region 业务接口类(部分类)
- if (!param["CodeIBusinessPartial"].IsEmpty())
- {
- string codeBusiness = HttpUtility.HtmlDecode(param["CodeIBusinessPartial"].ToString());
- string partialPath = Path.Combine(baseConfigModel.OutputConfig.OutputBusiness, "YiSha.IBusiness", baseConfigModel.OutputConfig.OutputModule, "Partial");
- CreatePartialFilePath(partialPath);
- string codePath = Path.Combine(partialPath, "I" + baseConfigModel.FileConfig.IBusinessName + ".cs");
- CreateCodeFile(codePath, codeBusiness, out bool isAdd);
- result.Add(new KeyValue { Key = "业务接口类(部分类)", Value = codePath });
- }
- #endregion
- #region 业务实现类
- if (!param["CodeBusiness"].IsEmpty())
- {
- string codeBusiness = HttpUtility.HtmlDecode(param["CodeBusiness"].ToString());
- string codePath = Path.Combine(baseConfigModel.OutputConfig.OutputBusiness, "YiSha.Business", baseConfigModel.OutputConfig.OutputModule, baseConfigModel.FileConfig.BusinessName + ".cs");
- CreateCodeFile(codePath, codeBusiness, out bool isAdd, true);
- result.Add(new KeyValue { Key = "业务实现类", Value = codePath });
- }
- #endregion
- #region 业务实现类(部分类)
- if (!param["CodeBusinessPartial"].IsEmpty())
- {
- string codeBusiness = HttpUtility.HtmlDecode(param["CodeBusinessPartial"].ToString());
- string partialPath = Path.Combine(baseConfigModel.OutputConfig.OutputBusiness, "YiSha.Business", baseConfigModel.OutputConfig.OutputModule, "Partial");
- CreatePartialFilePath(partialPath);
- string codePath = Path.Combine(partialPath, baseConfigModel.FileConfig.BusinessName + ".cs");
- CreateCodeFile(codePath, codeBusiness, out bool isAdd);
- result.Add(new KeyValue { Key = "业务实现类(部分类)", Value = codePath });
- }
- #endregion
- #region 控制器
- if (!param["CodeController"].IsEmpty())
- {
- string codeController = HttpUtility.HtmlDecode(param["CodeController"].ToString());
- string codePath = Path.Combine(baseConfigModel.OutputConfig.OutputWeb, "Areas", baseConfigModel.OutputConfig.OutputModule, "Controllers", baseConfigModel.FileConfig.ControllerName + ".cs");
- CreateCodeFile(codePath, codeController, out bool isAdd);
- result.Add(new KeyValue { Key = "控制器", Value = codePath });
- }
- #endregion
- #region 列表页
- if (!param["CodeIndex"].IsEmpty())
- {
- //代码生成器,生成菜单按钮权限默认获取系统数据库数据
- DBConnectTypeEnum dbConnectType = DBConnectTypeEnum.SystemDB;
- string codeIndex = HttpUtility.HtmlDecode(param["CodeIndex"].ToString());
- string codePath = Path.Combine(baseConfigModel.OutputConfig.OutputWeb, "Areas", baseConfigModel.OutputConfig.OutputModule, "Views", baseConfigModel.FileConfig.ClassPrefix, baseConfigModel.FileConfig.PageIndexName + ".cshtml");
- CreateCodeFile(codePath, codeIndex, out bool isAdd);
- result.Add(new KeyValue { Key = "列表页", Value = codePath });
- if (isAdd)
- {
- //列表页面添加成功后,才生成菜单权限
- // 生成菜单
- RepositoryFactory repositoryFactory = new RepositoryFactory();
- List<KeyValue> buttonAuthorizeList = GetButtonAuthorizeList();
- string menuUrl = baseConfigModel.OutputConfig.OutputModule + "/" + baseConfigModel.FileConfig.ClassPrefix + "/" + baseConfigModel.FileConfig.PageIndexName;
- string modulePrefix = GetModulePrefix(baseConfigModel);
- string classPrefix = baseConfigModel.FileConfig.ClassPrefix.ToLower();
- MenuEntity menuEntity = new MenuEntity
- {
- MenuName = baseConfigModel.FileConfig.ClassDescription,
- MenuUrl = menuUrl,
- MenuType = (int)MenuTypeEnum.Menu,
- Authorize = string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, "view")
- };
- TData obj = await AddMenu(repositoryFactory, menuEntity, dbConnectType);
- if (obj.Success)
- {
- result.Add(new KeyValue { Key = "菜单(刷新页面可见)", Value = menuUrl });
- if (baseConfigModel.PageIndex.IsSearch == 1)
- {
- // 按钮搜索权限
- KeyValue button = buttonAuthorizeList.Where(p => p.Key == "btnSearch").FirstOrDefault();
- MenuEntity buttonEntity = new MenuEntity
- {
- ParentId = menuEntity.Id,
- MenuName = baseConfigModel.FileConfig.ClassDescription + button.Description,
- MenuType = (int)MenuTypeEnum.Button,
- Authorize = string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, button.Value)
- };
- await AddMenu(repositoryFactory, buttonEntity, dbConnectType);
- }
- foreach (string btn in baseConfigModel.PageIndex.ButtonList)
- {
- KeyValue button = buttonAuthorizeList.Where(p => p.Key == btn).FirstOrDefault();
- MenuEntity buttonEntity = new MenuEntity
- {
- ParentId = menuEntity.Id,
- MenuName = baseConfigModel.FileConfig.ClassDescription + button.Description,
- MenuType = (int)MenuTypeEnum.Button,
- Authorize = string.Format("{0}:{1}:{2}", modulePrefix, classPrefix, button.Value)
- };
- await AddMenu(repositoryFactory, buttonEntity, dbConnectType);
- }
- menuCacheBusiness.Remove();
- }
- }
- }
- #endregion
- #region 表单页
- if (!param["CodeForm"].IsEmpty())
- {
- string codeSave = HttpUtility.HtmlDecode(param["CodeForm"].ToString());
- string codePath = Path.Combine(baseConfigModel.OutputConfig.OutputWeb, "Areas", baseConfigModel.OutputConfig.OutputModule, "Views", baseConfigModel.FileConfig.ClassPrefix, baseConfigModel.FileConfig.PageFormName + ".cshtml");
- CreateCodeFile(codePath, codeSave, out bool isAdd);
- result.Add(new KeyValue { Key = "表单页", Value = codePath });
- }
- #endregion
- return result;
- }
- private async Task<TData> AddMenu(RepositoryFactory repositoryFactory, MenuEntity menuEntity, DBConnectTypeEnum dbConnectType)
- {
- TData obj = new TData();
- IEnumerable<MenuEntity> menuList = await repositoryFactory.BaseRepository(dbConnectType).FindList<MenuEntity>();
- if (!menuList.Where(p => p.MenuName == menuEntity.MenuName && p.Authorize == menuEntity.Authorize).Any())
- {
- menuEntity.MenuSort = menuList.Max(p => p.MenuSort) + 1;
- menuEntity.MenuStatus = 1;
- await menuEntity.Create();
- await repositoryFactory.BaseRepository(dbConnectType).Insert(menuEntity);
- obj.Tag = 1;
- }
- return obj;
- }
- #endregion
- #region 私有方法
- #region GetProjectRootPath
- private string GetProjectRootPath(string path)
- {
- path = path.ParseToString();
- path = path.Trim('\\');
- if (GlobalContext.SystemConfig.Debug)
- {
- // 向上找二级
- path = Directory.GetParent(path).FullName;
- path = Directory.GetParent(path).FullName;
- }
- return path;
- }
- #endregion
- #region SetClassDescription
- private void SetClassDescription(string type, BaseConfigModel baseConfigModel, StringBuilder sb)
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// 创 建:" + baseConfigModel.FileConfig.CreateName);
- sb.AppendLine(" /// 日 期:" + baseConfigModel.FileConfig.CreateDate);
- sb.AppendLine(" /// 描 述:" + baseConfigModel.FileConfig.ClassDescription + type);
- sb.AppendLine(" /// </summary>");
- }
- #endregion
- #region GetButtonAuthorizeList
- private List<KeyValue> GetButtonAuthorizeList()
- {
- var list = new List<KeyValue>();
- list.Add(new KeyValue { Key = "btnSearch", Value = "search", Description = "搜索" });
- list.Add(new KeyValue { Key = "btnAdd", Value = "add", Description = "新增" });
- list.Add(new KeyValue { Key = "btnEdit", Value = "edit", Description = "修改" });
- list.Add(new KeyValue { Key = "btnDelete", Value = "delete", Description = "删除" });
- return list;
- }
- #endregion
- private string GetModulePrefix(BaseConfigModel baseConfigModel)
- {
- return baseConfigModel.OutputConfig.OutputModule.Replace("Manage", string.Empty).ToLower();
- }
- private string GetBaseEntity(DataTable dt)
- {
- string entity = string.Empty;
- var columnList = dt.AsEnumerable().Select(p => p["TableColumn"].ParseToString()).ToList();
- bool id = columnList.Where(p => p.ToLower().Equals("Id".ToLower())).Any();
- bool baseIsDelete = columnList.Where(p => p.ToLower().Equals("BaseIsDelete".ToLower())).Any();
- bool baseVersion = columnList.Where(p => p.ToLower().Equals("BaseVersion".ToLower())).Any();
- bool baseModifyTime = columnList.Where(p => p.ToLower().Equals("BaseModifyTime".ToLower())).Any();
- bool baseModifierId = columnList.Where(p => p.ToLower().Equals("BaseModifierId".ToLower())).Any();
- bool baseCreateTime = columnList.Where(p => p.ToLower().Equals("BaseCreateTime".ToLower())).Any();
- bool baseCreatorId = columnList.Where(p => p.ToLower().Equals("BaseCreatorId".ToLower())).Any();
- if (!id)
- {
- throw new Exception("数据库表必须有主键Id字段");
- }
- if (baseIsDelete && baseVersion && baseModifyTime && baseModifierId && baseCreateTime && baseCreatorId)
- {
- entity = "BaseExtensionEntity";
- }
- else if (baseVersion && baseModifyTime && baseModifierId && baseCreateTime && baseCreatorId)
- {
- entity = "BaseModifyEntity";
- }
- else if (baseCreateTime && baseCreatorId)
- {
- entity = "BaseCreateEntity";
- }
- else
- {
- entity = "BaseEntity";
- }
- return entity;
- }
- private string GetSaveFormCreate(string entity)
- {
- string line = string.Empty;
- switch (entity)
- {
- case "BaseEntity":
- line = "entity.Create();";
- break;
- case "BaseCreateEntity":
- line = "await entity.Create();";
- break;
- case "BaseModifyEntity":
- line = "await entity.Create();";
- break;
- case "BaseExtensionEntity":
- line = "await entity.Create();";
- break;
- }
- return line;
- }
- private string GetSaveFormModify(string entity)
- {
- string line = string.Empty;
- switch (entity)
- {
- case "BaseEntity":
- line = string.Empty;
- break;
- case "BaseCreateEntity":
- line = string.Empty;
- break;
- case "BaseModifyEntity":
- line = "await entity.Modify();";
- break;
- case "BaseExtensionEntity":
- line = "await entity.Modify();";
- break;
- }
- return line;
- }
- /// <summary>
- /// 创建部分类文件路径
- /// </summary>
- /// <param name="partialPath"></param>
- private void CreatePartialFilePath(string partialPath)
- {
- if (!Directory.Exists(partialPath))
- Directory.CreateDirectory(partialPath);
- }
- /// <summary>
- /// 创建代码文件
- /// </summary>
- /// <param name="codePath">地址</param>
- /// <param name="codeContent">内容</param>
- /// <param name="isAdd">是否添加成功 true成功,false未添加</param>
- /// <param name="isCovered">是否覆盖 true覆盖,false不覆盖 默认不覆盖</param>
- private void CreateCodeFile(string codePath, string codeContent, out bool isAdd, bool isCovered = false)
- {
- isAdd = false;
- if (!File.Exists(codePath))
- {
- isAdd = true;
- //代码不存在直接创建
- FileHelper.CreateFile(codePath, codeContent);
- }
- else
- {
- //代码已存在,判断是否需要覆盖
- if (isCovered)
- {
- isAdd = true;
- File.Delete(codePath);
- FileHelper.CreateFile(codePath, codeContent);
- }
- }
- }
- /// <summary>
- /// 获取数据库操作类型
- /// </summary>
- /// <param name="dbConnectType"></param>
- /// <returns></returns>
- private string GetDBConnectTypeEnum(DBConnectTypeEnum dbConnectType)
- {
- //默认空,如果数据库操作类型不存在,生成的代码则会报错
- var result = "";
- switch (dbConnectType)
- {
- case DBConnectTypeEnum.KjhDB:
- result = "DBConnectTypeEnum.KjhDB";
- break;
- case DBConnectTypeEnum.SystemDB:
- result = "DBConnectTypeEnum.SystemDB";
- break;
- case DBConnectTypeEnum.TkDB:
- result = "DBConnectTypeEnum.TkDB";
- break;
- case DBConnectTypeEnum.ZxDB:
- result = "DBConnectTypeEnum.ZxDB";
- break;
- }
- return result;
- }
- #endregion
- }
- }
|