diff --git a/ds-wms-service/DS.Module.SqlSugar/ISaasDbService.cs b/ds-wms-service/DS.Module.SqlSugar/ISaasDbService.cs index 9c1be3a3..8cd0e01b 100644 --- a/ds-wms-service/DS.Module.SqlSugar/ISaasDbService.cs +++ b/ds-wms-service/DS.Module.SqlSugar/ISaasDbService.cs @@ -16,12 +16,7 @@ public interface ISaasDbService /// /// public ISqlSugarClient GetMasterDb(); - - /// - /// 主库根据Id获取业务库 - /// - /// - public ISqlSugarClient GetBizDbById(object configId); + /// /// 主库根据Id获取业务库Scope diff --git a/ds-wms-service/DS.Module.SqlSugar/SaasDbService.cs b/ds-wms-service/DS.Module.SqlSugar/SaasDbService.cs index d6e9baf0..409c08cb 100644 --- a/ds-wms-service/DS.Module.SqlSugar/SaasDbService.cs +++ b/ds-wms-service/DS.Module.SqlSugar/SaasDbService.cs @@ -1,3 +1,4 @@ +using DS.Module.Core.Data; using DS.Module.UserModule; using Microsoft.Extensions.DependencyInjection; using SqlSugar; @@ -61,26 +62,7 @@ public class SaasDbService : ISaasDbService return db.GetConnection("1288018625843826688"); } - /// - /// 主库根据Id获取业务库 - /// - /// - public ISqlSugarClient GetBizDbById(object configId) - { - if(!db.IsAnyConnection(configId)) - { - var connInfo = GetMasterDb().Queryable().First(x => x.TenantId == Convert.ToInt64(configId)); - //用非默认ConfigId进行测试 - //添加业务库只在当前上下文有效(原理:SqlSugarScope模式入门文档去看) - db.AddConnection(new ConnectionConfig() { - ConfigId = configId, - ConnectionString = connInfo.Connection, - DbType = connInfo.DbType, - IsAutoCloseConnection = true }); - } - return db.GetConnection(configId); - } /// /// 主库根据Id获取业务库Scope /// @@ -88,20 +70,48 @@ public class SaasDbService : ISaasDbService /// public SqlSugarScopeProvider GetBizDbScopeById(object configId) { - if(!db.IsAnyConnection(configId)) + if (!db.IsAnyConnection(configId)) { - var connInfo = GetMasterDb().Queryable().First(x => x.TenantId == Convert.ToInt64(configId)); + var connInfo = GetMasterDb().Queryable().First(x => x.TenantId == Convert.ToInt64(configId)); //用非默认ConfigId进行测试 //添加业务库只在当前上下文有效(原理:SqlSugarScope模式入门文档去看) - db.AddConnection(new ConnectionConfig() { - ConfigId = configId, - ConnectionString = connInfo.Connection, + db.AddConnection(new ConnectionConfig() + { + ConfigId = configId, + ConnectionString = connInfo.Connection, DbType = connInfo.DbType, - IsAutoCloseConnection = true }); + IsAutoCloseConnection = true + }); + var dbProvider = db.GetConnectionScope(configId); + dbProvider.Ado.CommandTimeOut = 30; + dbProvider.Aop.OnLogExecuting = (sql, pars) => + { + //执行前事件 + //Logger.Log(LogLevel.Info, + // DateTime.Now.ToString() + "\r\n" + + // UtilMethods.GetSqlString(c.DbType, sql, pars)); + Console.WriteLine("执行的sql:" + sql); + }; + + //数据处理事件 + dbProvider.Aop.DataExecuting = (oldValue, entityInfo) => + { + // 新增操作 + SqlsugarHelper.InsertByObjectForSqlsugar(entityInfo, user); + // 更新操作 + SqlsugarHelper.UpdateByObjectForSqlsugar(entityInfo, user); + }; + + dbProvider.Aop.OnDiffLogEvent = (it) => { }; + //全局过滤机构Id + dbProvider.QueryFilter.AddTableFilter(m => m.OrgId == user.GetOrgId()); + //全局软删除过滤 + dbProvider.QueryFilter.AddTableFilter(m => m.Deleted == false); } return db.GetConnectionScope(configId); } + public SqlSugarScopeProvider GetMasterDbScope() { return db.GetConnectionScope("1288018625843826688"); diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodeCountryService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodeCountryService.cs index b2985a22..1a54eacf 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodeCountryService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodeCountryService.cs @@ -78,7 +78,7 @@ public class CodeCountryService:ICodeCountryService public DataResult> GetClientListByPage(PageRequest request) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = tenantDb.Queryable() @@ -89,7 +89,7 @@ public class CodeCountryService:ICodeCountryService public DataResult EditClientCodeCountry(CodeCountryReq req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { @@ -117,7 +117,7 @@ public class CodeCountryService:ICodeCountryService public DataResult GetClientCodeCountryInfo(string id) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() @@ -137,7 +137,7 @@ public class CodeCountryService:ICodeCountryService public DataResult ImportCodeCountry(IdModel req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var list = db.Queryable().Where(x =>req.Ids.Contains(x.Id) ).ToList(); if (list.Count == 0) { @@ -159,7 +159,7 @@ public class CodeCountryService:ICodeCountryService /// public DataResult> GetExistCodeCountryList() { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Select(n=>n.Id.ToString()) .ToList(); diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodeCtnService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodeCtnService.cs index 1dfc63c4..80cba297 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodeCtnService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodeCtnService.cs @@ -78,7 +78,7 @@ public class CodeCtnService:ICodeCtnService public DataResult> GetClientListByPage(PageRequest request) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = tenantDb.Queryable() @@ -89,7 +89,7 @@ public class CodeCtnService:ICodeCtnService public DataResult EditClientCodeCtn(CodeCtnReq req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { @@ -117,7 +117,7 @@ public class CodeCtnService:ICodeCtnService public DataResult GetClientCodeCtnInfo(string id) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() @@ -137,7 +137,7 @@ public class CodeCtnService:ICodeCtnService public DataResult ImportCodeCtn(IdModel req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var list = db.Queryable().Where(x =>req.Ids.Contains(x.Id) ).ToList(); if (list.Count == 0) { @@ -159,7 +159,7 @@ public class CodeCtnService:ICodeCtnService /// public DataResult> GetExistCodeCtnList() { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Select(n=>n.Id.ToString()) .ToList(); diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodeGoodsService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodeGoodsService.cs index 5ffa0416..01eac52e 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodeGoodsService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodeGoodsService.cs @@ -79,7 +79,7 @@ public class CodeGoodsService:ICodeGoodsService public DataResult> GetClientListByPage(PageRequest request) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = tenantDb.Queryable() @@ -91,7 +91,7 @@ public class CodeGoodsService:ICodeGoodsService public DataResult EditClientCodeGoods(CodeGoodsReq req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { @@ -119,7 +119,7 @@ public class CodeGoodsService:ICodeGoodsService public DataResult GetClientCodeGoodsInfo(string id) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() @@ -140,7 +140,7 @@ public class CodeGoodsService:ICodeGoodsService public DataResult ImportCodeGoods(IdModel req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var list = db.Queryable().Where(x =>req.Ids.Contains(x.Id) ).ToList(); if (list.Count == 0) { @@ -162,7 +162,7 @@ public class CodeGoodsService:ICodeGoodsService /// public DataResult> GetExistCodeGoodsList() { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .LeftJoin((a, b) => a.GoodsTypeId == b.Id) .Select(n=>n.Id.ToString()) diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodeGoodsTypeService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodeGoodsTypeService.cs index 0203e5c4..15ac8c0e 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodeGoodsTypeService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodeGoodsTypeService.cs @@ -78,7 +78,7 @@ public class CodeGoodsTypeService:ICodeGoodsTypeService public DataResult> GetClientListByPage(PageRequest request) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = tenantDb.Queryable() @@ -89,7 +89,7 @@ public class CodeGoodsTypeService:ICodeGoodsTypeService public DataResult EditClientCodeGoodsType(CodeGoodsTypeReq req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { @@ -117,7 +117,7 @@ public class CodeGoodsTypeService:ICodeGoodsTypeService public DataResult GetClientCodeGoodsTypeInfo(string id) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() @@ -137,7 +137,7 @@ public class CodeGoodsTypeService:ICodeGoodsTypeService public DataResult ImportCodeGoodsType(IdModel req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var list = db.Queryable().Where(x =>req.Ids.Contains(x.Id) ).ToList(); if (list.Count == 0) { @@ -159,7 +159,7 @@ public class CodeGoodsTypeService:ICodeGoodsTypeService /// public DataResult> GetExistCodeGoodsTypeList() { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Select(n=>n.Id.ToString()) .ToList(); diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodeIssueTypeService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodeIssueTypeService.cs index 60b12274..62d6e99d 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodeIssueTypeService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodeIssueTypeService.cs @@ -78,7 +78,7 @@ public class CodeIssueTypeService:ICodeIssueTypeService public DataResult> GetClientListByPage(PageRequest request) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = tenantDb.Queryable() @@ -89,7 +89,7 @@ public class CodeIssueTypeService:ICodeIssueTypeService public DataResult EditClientCodeIssueType(CodeIssueTypeReq req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { @@ -117,7 +117,7 @@ public class CodeIssueTypeService:ICodeIssueTypeService public DataResult GetClientCodeIssueTypeInfo(string id) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() @@ -137,7 +137,7 @@ public class CodeIssueTypeService:ICodeIssueTypeService public DataResult ImportCodeIssueType(IdModel req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var list = db.Queryable().Where(x =>req.Ids.Contains(x.Id) ).ToList(); if (list.Count == 0) { @@ -159,7 +159,7 @@ public class CodeIssueTypeService:ICodeIssueTypeService /// public DataResult> GetExistCodeIssueTypeList() { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Select(n=>n.Id.ToString()) .ToList(); diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodePackageService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodePackageService.cs index 3226a687..e2223267 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodePackageService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodePackageService.cs @@ -78,7 +78,7 @@ public class CodePackageService:ICodePackageService public DataResult> GetClientListByPage(PageRequest request) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = tenantDb.Queryable() @@ -89,7 +89,7 @@ public class CodePackageService:ICodePackageService public DataResult EditClientCodePackage(CodePackageReq req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { @@ -117,7 +117,7 @@ public class CodePackageService:ICodePackageService public DataResult GetClientCodePackageInfo(string id) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() @@ -137,7 +137,7 @@ public class CodePackageService:ICodePackageService public DataResult ImportCodePackage(IdModel req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var list = db.Queryable().Where(x =>req.Ids.Contains(x.Id) ).ToList(); if (list.Count == 0) { @@ -159,7 +159,7 @@ public class CodePackageService:ICodePackageService /// public DataResult> GetExistCodePackageList() { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Select(n=>n.Id.ToString()) .ToList(); diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodePortService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodePortService.cs index d41cd131..7bd450d4 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodePortService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodePortService.cs @@ -78,7 +78,7 @@ public class CodePortService:ICodePortService public DataResult> GetClientListByPage(PageRequest request) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = tenantDb.Queryable() @@ -89,7 +89,7 @@ public class CodePortService:ICodePortService public DataResult EditClientCodePort(CodePortReq req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { @@ -117,7 +117,7 @@ public class CodePortService:ICodePortService public DataResult GetClientCodePortInfo(string id) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() @@ -137,7 +137,7 @@ public class CodePortService:ICodePortService public DataResult ImportCodePort(IdModel req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var list = db.Queryable().Where(x =>req.Ids.Contains(x.Id) ).ToList(); if (list.Count == 0) { @@ -159,7 +159,7 @@ public class CodePortService:ICodePortService /// public DataResult> GetExistCodePortList() { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Select(n=>n.Id.ToString()) .ToList(); diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodeSourceDetailService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodeSourceDetailService.cs index 287fa58e..ba7db725 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodeSourceDetailService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodeSourceDetailService.cs @@ -78,7 +78,7 @@ public class CodeSourceDetailService:ICodeSourceDetailService public DataResult> GetClientListByPage(PageRequest request) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = tenantDb.Queryable() @@ -89,7 +89,7 @@ public class CodeSourceDetailService:ICodeSourceDetailService public DataResult EditClientCodeSourceDetail(CodeSourceDetailReq req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { @@ -117,7 +117,7 @@ public class CodeSourceDetailService:ICodeSourceDetailService public DataResult GetClientCodeSourceDetailInfo(string id) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodeSourceService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodeSourceService.cs index 1577b6e5..82be4a54 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodeSourceService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodeSourceService.cs @@ -78,7 +78,7 @@ public class CodeSourceService:ICodeSourceService public DataResult> GetClientListByPage(PageRequest request) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = tenantDb.Queryable() @@ -89,7 +89,7 @@ public class CodeSourceService:ICodeSourceService public DataResult EditClientCodeSource(CodeSourceReq req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { @@ -117,7 +117,7 @@ public class CodeSourceService:ICodeSourceService public DataResult GetClientCodeSourceInfo(string id) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() @@ -137,7 +137,7 @@ public class CodeSourceService:ICodeSourceService public DataResult ImportCodeSource(IdModel req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var list = db.Queryable().Where(x =>req.Ids.Contains(x.Id) ).ToList(); if (list.Count == 0) { @@ -164,7 +164,7 @@ public class CodeSourceService:ICodeSourceService /// public DataResult> GetExistCodeSourceList() { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Select(n=>n.Id.ToString()) .ToList(); diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodeVesselService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodeVesselService.cs index 70a8a4f3..05a3d1d5 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodeVesselService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodeVesselService.cs @@ -78,7 +78,7 @@ public class CodeVesselService:ICodeVesselService public DataResult> GetClientListByPage(PageRequest request) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = tenantDb.Queryable() @@ -89,7 +89,7 @@ public class CodeVesselService:ICodeVesselService public DataResult EditClientCodeVessel(CodeVesselReq req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { @@ -117,7 +117,7 @@ public class CodeVesselService:ICodeVesselService public DataResult GetClientCodeVesselInfo(string id) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() @@ -137,7 +137,7 @@ public class CodeVesselService:ICodeVesselService public DataResult ImportCodeVessel(IdModel req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var list = db.Queryable().Where(x =>req.Ids.Contains(x.Id) ).ToList(); if (list.Count == 0) { @@ -159,7 +159,7 @@ public class CodeVesselService:ICodeVesselService /// public DataResult> GetExistCodeVesselList() { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Select(n=>n.Id.ToString()) .ToList(); diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodeVoynoService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodeVoynoService.cs index 1dccf819..ffa3d131 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodeVoynoService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodeVoynoService.cs @@ -79,7 +79,7 @@ public class CodeVoynoService:ICodeVoynoService public DataResult> GetClientListByPage(PageRequest request) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = tenantDb.Queryable() @@ -91,7 +91,7 @@ public class CodeVoynoService:ICodeVoynoService public DataResult EditClientCodeVoyno(CodeVoynoReq req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { @@ -119,7 +119,7 @@ public class CodeVoynoService:ICodeVoynoService public DataResult GetClientCodeVoynoInfo(string id) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .LeftJoin((a,b)=>a.VesselId==b.Id) .Where(a => a.Id == long.Parse(id)) @@ -141,7 +141,7 @@ public class CodeVoynoService:ICodeVoynoService public DataResult ImportCodeVoyno(IdModel req) { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var list = db.Queryable().Where(x =>req.Ids.Contains(x.Id) ).ToList(); if (list.Count == 0) { @@ -163,7 +163,7 @@ public class CodeVoynoService:ICodeVoynoService /// public DataResult> GetExistCodeVoynoList() { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .LeftJoin((a,b)=>a.VesselId==b.Id) .Select(n=>n.Id.ToString()) diff --git a/ds-wms-service/DS.WMS.Core/System/Dtos/SysSequenceReq.cs b/ds-wms-service/DS.WMS.Core/System/Dtos/SysSequenceReq.cs new file mode 100644 index 00000000..a8134bc8 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/System/Dtos/SysSequenceReq.cs @@ -0,0 +1,85 @@ +using DS.Module.Core; +using FluentValidation; + +namespace DS.WMS.Core.System.Dtos; + +/// +/// 数据权限请求实体 +/// +public class SysSequenceReq +{ + /// + /// 主键Id + /// + public long Id { get; set; } + /// + /// 权限ID + /// + public long PermissionId { get; set; } + /// + /// 权限实体 + /// + public string PermissionEntity { get; set; }= ""; + + /// + /// 名称 + /// + public string SequenceName { get; set; }= ""; + /// + /// 分隔符 + /// + public string SequenceDelimiter { get; set; }= ""; + + /// + /// 序号重置规则 + /// + public string SequenceReset { get; set; } = ""; + + /// + /// 步长 + /// + public int Step { get; set; } = 0; + /// + /// 当前值 + /// + public int CurrentNo { get; set; }= 0; + /// + /// 当前编码 + /// + public string CurrentCode { get; set; }= ""; + /// + /// 当前重置依赖,即最后一次获取编码的日期 + /// + public string CurrentReset { get; set; }= ""; + /// + /// 排序 + /// + public int? OrderNo { get; set; } = 100; + + /// + /// 状态 0 启用 1 禁用 + /// + public StatusEnum? Status { get; set; } = StatusEnum.Enable; + /// + /// 备注 + /// + public string Note { get; set; } = ""; +} + + +/// +/// 验证 +/// +public class SysSequenceReqValidator : AbstractValidator +{ + /// + /// 构造函数 + /// + public SysSequenceReqValidator() + { + this.RuleFor(o => o.PermissionId) + .NotEmpty().WithName("权限模块Id"); + this.RuleFor(o => o.SequenceName) + .NotEmpty().WithName("名称"); + } +} \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/System/Dtos/SysSequenceRes.cs b/ds-wms-service/DS.WMS.Core/System/Dtos/SysSequenceRes.cs new file mode 100644 index 00000000..4de0814d --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/System/Dtos/SysSequenceRes.cs @@ -0,0 +1,71 @@ +using DS.Module.Core; + +namespace DS.WMS.Core.System.Dtos; + +/// +/// 数据权限返回实体 +/// +public class SysSequenceRes +{ + /// + /// 主键Id + /// + public long Id { get; set; } + /// + /// 权限ID + /// + public long PermissionId { get; set; } + /// + /// 权限实体 + /// + public string PermissionEntity { get; set; }= ""; + + /// + /// 名称 + /// + public string SequenceName { get; set; }= ""; + /// + /// 分隔符 + /// + public string SequenceDelimiter { get; set; }= ""; + + /// + /// 序号重置规则 + /// + public string SequenceReset { get; set; } = ""; + + /// + /// 步长 + /// + public int Step { get; set; } = 0; + /// + /// 当前值 + /// + public int CurrentNo { get; set; }= 0; + /// + /// 当前编码 + /// + public string CurrentCode { get; set; }= ""; + /// + /// 当前重置依赖,即最后一次获取编码的日期 + /// + public string CurrentReset { get; set; }= ""; + + /// + /// 状态 0 启用 1 禁用 + /// + public StatusEnum? Status { get; set; } = StatusEnum.Enable; + /// + /// 备注 + /// + public string Note { get; set; } = ""; + /// + /// 排序 + /// + public int? OrderNo { get; set; } = 100; + + /// + /// 创建时间 + /// + public DateTime CreateTime { get; set; } +} \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/System/Entity/SysSequence.cs b/ds-wms-service/DS.WMS.Core/System/Entity/SysSequence.cs new file mode 100644 index 00000000..2e0971a3 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/System/Entity/SysSequence.cs @@ -0,0 +1,58 @@ +using DS.Module.Core; +using DS.Module.Core.Data; + +namespace DS.WMS.Core.System.Entity; + +/// +/// 系统编码表 +/// +[SqlSugar.SugarTable("sys_sequence","系统编码表")] +public class SysSequence : BaseTenantModel +{ + /// + /// 权限ID + /// + public long PermissionId { get; set; } + /// + /// 权限实体 + /// + public string PermissionEntity { get; set; } + + /// + /// 名称 + /// + public string SequenceName { get; set; } + /// + /// 分隔符 + /// + public string SequenceDelimiter { get; set; } + /// + /// 序号重置规则 + /// + public string SequenceReset { get; set; } + /// + /// 步长 + /// + public int Step { get; set; } + /// + /// 当前值 + /// + public int CurrentNo { get; set; } + /// + /// 当前编码 + /// + public string CurrentCode { get; set; } + /// + /// 当前重置依赖,即最后一次获取编码的日期 + /// + public string CurrentReset { get; set; } + /// + /// 状态 + /// + [SqlSugar.SugarColumn(ColumnDescription = "状态")] + public StatusEnum? Status { get; set; } = StatusEnum.Enable; + /// + /// 排序号 + /// + public string OrderNo { get; set; } +} \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/System/Entity/SysSequenceRule.cs b/ds-wms-service/DS.WMS.Core/System/Entity/SysSequenceRule.cs new file mode 100644 index 00000000..5da150cc --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/System/Entity/SysSequenceRule.cs @@ -0,0 +1,51 @@ +using DS.Module.Core; +using DS.Module.Core.Data; + +namespace DS.WMS.Core.System.Entity; + +/// +/// 系统编码规则表 +/// +[SqlSugar.SugarTable("sys_sequence_rule","系统编码表")] +public class SysSequenceRule : BaseTenantModel +{ + /// + /// 权限ID + /// + public long PermissionId { get; set; } + + /// + /// 单据Id + /// + public long SequenceId { get; set; } + + /// + /// 取规则类别,timestamp、const、number + /// + public string RuleType { get; set; } + /// + /// 规则参数,如 YYMMDD + /// + public string RuleValue { get; set; } + /// + /// 补齐方向,left或right + /// + public string PaddingSide { get; set; } + /// + /// 补齐宽度 + /// + public int PaddingWidth { get; set; } + /// + /// 填充字符 + /// + public string PaddingChar { get; set; } + /// + /// 状态 + /// + [SqlSugar.SugarColumn(ColumnDescription = "状态")] + public StatusEnum? Status { get; set; } = StatusEnum.Enable; + /// + /// 排序号 + /// + public string OrderNo { get; set; } +} \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs b/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs index 47da2b89..f68d3fc4 100644 --- a/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs +++ b/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs @@ -805,7 +805,7 @@ public class CommonService : ICommonService /// public DataResult> GetClientGoodsTypeList() { - var tenantDb = saasService.GetBizDbById(user.TenantId); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var list = tenantDb.Queryable() .Select(a => new ApiSelectViewModel { diff --git a/ds-wms-service/DS.WMS.Core/System/Method/TenantApplyService.cs b/ds-wms-service/DS.WMS.Core/System/Method/TenantApplyService.cs index c34742b9..5d80c49a 100644 --- a/ds-wms-service/DS.WMS.Core/System/Method/TenantApplyService.cs +++ b/ds-wms-service/DS.WMS.Core/System/Method/TenantApplyService.cs @@ -279,7 +279,7 @@ public class TenantApplyService : ITenantApplyService DbType = link.DbType, IsAutoCloseConnection = true }); } - var tenantDb = saasService.GetBizDbById(tenant.Id); + var tenantDb = saasService.GetBizDbScopeById(tenant.Id); StaticConfig.CodeFirst_MySqlCollate="utf8mb4_0900_ai_ci";//较高版本支持 //初始化数库 tenantDb.DbMaintenance.CreateDatabase();