using Infrastructure.Attribute; using Infrastructure.Extensions; using Infrastructure.Model; using Newtonsoft.Json; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using ZR.Model.System.Generate; using ZR.Repository.System; using ZR.Service.System.IService; namespace ZR.Service.System { /// /// 代码生成表 /// [AppService(ServiceType = typeof(IGenTableService), ServiceLifetime = LifeTime.Transient)] public class GenTableService : IGenTableService { private GenTableRepository GenTableRepository; private IGenTableColumnService GenTableColumnService; public GenTableService(IGenTableColumnService genTableColumnService, GenTableRepository genTableRepository) { GenTableColumnService = genTableColumnService; GenTableRepository = genTableRepository; } /// /// 删除表 /// /// 需要删除的表id /// public int DeleteGenTableByIds(long[] tableIds) { GenTableRepository.Delete(f => tableIds.Contains(f.TableId)); return GenTableColumnService.DeleteGenTableColumn(tableIds); } /// /// 删除表根据表名 /// /// /// public int DeleteGenTableByTbName(string tableName) { return GenTableRepository.Delete(f => f.TableName == tableName); } /// /// 获取表信息 /// /// /// public GenTable GetGenTableInfo(long tableId) { return GenTableRepository.GetId(tableId); } /// /// 查询代码生成表信息 /// /// /// /// public PagedInfo GetGenTables(GenTable genTable, Model.PagerInfo pagerInfo) { var predicate = Expressionable.Create(); predicate = predicate.AndIF(genTable.TableName.IfNotEmpty(), it => it.TableName.Contains(genTable.TableName)); return GenTableRepository.GetPages(predicate.ToExpression(), pagerInfo); } /// /// 插入代码生成表 /// /// /// public int ImportGenTable(GenTable table) { table.Create_time = DateTime.Now; //导入前删除现有表 //DeleteGenTableByIds(new long[] { table.TableId }); DeleteGenTableByTbName(table.TableName); return GenTableRepository.Context.Insertable(table).IgnoreColumns(ignoreNullColumn: true).ExecuteReturnIdentity(); } /// /// 获取表数据 /// /// /// public List SelectDbTableListByNamess(string[] tableNames) { throw new NotImplementedException(); } public int UpdateGenTable(GenTable genTable) { var db = GenTableRepository.Context; genTable.Update_time = db.GetDate(); return db.Updateable(genTable).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } } /// /// 代码生成表列 /// [AppService(ServiceType = typeof(IGenTableColumnService), ServiceLifetime = LifeTime.Transient)] public class GenTableColumnService : IGenTableColumnService { private GenTableColumnRepository GetTableColumnRepository; public GenTableColumnService(GenTableColumnRepository genTableColumnRepository) { GetTableColumnRepository = genTableColumnRepository; } /// /// 删除表字段 /// /// /// public int DeleteGenTableColumn(long tableId) { return GetTableColumnRepository.DeleteGenTableColumn(new long[] { tableId }); } /// /// 根据表id批量删除表字段 /// /// /// public int DeleteGenTableColumn(long[] tableId) { return GetTableColumnRepository.DeleteGenTableColumn(tableId); } /// /// 根据表名删除字段 /// /// /// public int DeleteGenTableColumnByTableName(string tableName) { return GetTableColumnRepository.DeleteGenTableColumnByTableName(tableName); } /// /// 获取表所有字段 /// /// /// public List GenTableColumns(long tableId) { return GetTableColumnRepository.GenTableColumns(tableId); } /// /// 插入表字段 /// /// /// public int InsertGenTableColumn(List tableColumn) { return GetTableColumnRepository.InsertGenTableColumn(tableColumn); } /// /// 批量更新表字段 /// /// /// public int UpdateGenTableColumn(List tableColumn) { return GetTableColumnRepository.UpdateGenTableColumn(tableColumn); } } }