修复租户数据库差异问题及商品类型分类

master
ZR20090193-陈敬勇 9 months ago
parent 66c8d40696
commit 4b3e396f88

@ -152,6 +152,14 @@ public static class MultiLanguageConst
[Description("工作流实例已完成")] [Description("工作流实例已完成")]
public const string FlowInstanceFinished = "FlowInstance_Finished"; public const string FlowInstanceFinished = "FlowInstance_Finished";
#endregion #endregion
#region 基础信息
[Description("商品类型已存在")]
public const string CodeGoodsTypeExist = "Code_Goods_Type_Exist";
[Description("商品类型导入无数据")]
public const string CodeGoodsTypeImportNoData = "Code_Goods_Type_Import_No_Data";
[Description("存在已导入的商品类型")]
public const string CodeGoodsTypeImportAlready = "Code_Goods_Type_Import_Already";
#endregion
} }

@ -9,4 +9,9 @@ public class IdModel
/// 主键id /// 主键id
/// </summary> /// </summary>
public string Id { get; set; } public string Id { get; set; }
/// <summary>
/// 主键ids
/// </summary>
public long[] Ids { get; set; }
} }

@ -22,8 +22,13 @@ public interface ISaasDbService
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public ISqlSugarClient GetBizDbById(object configId); public ISqlSugarClient GetBizDbById(object configId);
/// <summary>
/// 主库根据Id获取业务库Scope
/// </summary>
/// <param name="configId"></param>
/// <returns></returns>
public SqlSugarScopeProvider GetBizDbScopeById(object configId);
/// <summary> /// <summary>
/// 获取业务库Scope /// 获取业务库Scope
/// </summary> /// </summary>

@ -81,7 +81,27 @@ public class SaasDbService : ISaasDbService
return db.GetConnection(configId); return db.GetConnection(configId);
} }
/// <summary>
/// 主库根据Id获取业务库Scope
/// </summary>
/// <param name="configId"></param>
/// <returns></returns>
public SqlSugarScopeProvider GetBizDbScopeById(object configId)
{
if(!db.IsAnyConnection(configId))
{
var connInfo = GetMasterDb().Queryable<SysTenantLink>().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.GetConnectionScope(configId);
}
public SqlSugarScopeProvider GetMasterDbScope() public SqlSugarScopeProvider GetMasterDbScope()
{ {
return db.GetConnectionScope("1288018625843826688"); return db.GetConnectionScope("1288018625843826688");

@ -0,0 +1,63 @@
using DS.Module.Core;
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Code.Interface;
using DS.WMS.Core.System.Dtos;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.AdminApi.Controllers;
/// <summary>
/// 商品类型服务
/// </summary>
public class CodeGoodsTypeController : ApiController
{
private readonly ICodeGoodsTypeService _invokeService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="invokeService"></param>
public CodeGoodsTypeController(ICodeGoodsTypeService invokeService)
{
_invokeService = invokeService;
}
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
[Route("GetCodeGoodsTypeList")]
public DataResult<List<CodeGoodsTypeRes>> GetCodeGoodsTypeList([FromBody] PageRequest request)
{
var res = _invokeService.GetListByPage(request);
return res;
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
[Route("EditCodeGoodsType")]
public DataResult EditCodeGoodsType([FromBody] CodeGoodsTypeReq model)
{
var res = _invokeService.EditCodeGoodsType(model);
return res;
}
/// <summary>
/// 详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
[Route("GetCodeGoodsTypeInfo")]
public DataResult<CodeGoodsTypeRes> GetCodeGoodsTypeInfo([FromQuery] string id)
{
var res = _invokeService.GetCodeGoodsTypeInfo(id);
return res;
}
}

@ -92,7 +92,7 @@ public class TenantController : ApiController
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[Route("GetSaasTableDifference")] [Route("GetSaasTableDifference")]
public DataResult<TableDifferenceProvider> GetSaasTableDifference([FromQuery] string id) public DataResult<List<TableDifferenceInfo>> GetSaasTableDifference([FromQuery] string id)
{ {
var res = _invokeService.GetSaasTableDifference(id); var res = _invokeService.GetSaasTableDifference(id);
return res; return res;

@ -432,3 +432,24 @@
2024-02-23 08:53:35.0867 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.AdminApi\bin\Debug\net8.0\nlog.config 2024-02-23 08:53:35.0867 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.AdminApi\bin\Debug\net8.0\nlog.config
2024-02-23 08:53:35.1429 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile 2024-02-23 08:53:35.1429 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-02-23 08:53:35.2826 Info Configuration initialized. 2024-02-23 08:53:35.2826 Info Configuration initialized.
2024-02-27 14:44:14.8688 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-02-27 14:44:14.9742 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-02-27 14:44:14.9970 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-02-27 14:44:15.0409 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-02-27 14:44:15.0754 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.AdminApi\bin\Debug\net8.0\nlog.config
2024-02-27 14:44:15.0983 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-02-27 14:44:15.1414 Info Configuration initialized.
2024-02-27 15:30:37.2092 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-02-27 15:30:37.2648 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-02-27 15:30:37.2800 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-02-27 15:30:37.3128 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-02-27 15:30:37.3342 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.AdminApi\bin\Debug\net8.0\nlog.config
2024-02-27 15:30:37.3485 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-02-27 15:30:37.3695 Info Configuration initialized.
2024-02-27 15:44:08.9411 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-02-27 15:44:09.0170 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-02-27 15:44:09.0418 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-02-27 15:44:09.0958 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-02-27 15:44:09.1366 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.AdminApi\bin\Debug\net8.0\nlog.config
2024-02-27 15:44:09.1586 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-02-27 15:44:09.2059 Info Configuration initialized.

@ -0,0 +1,58 @@
using DS.Module.Core;
using FluentValidation;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 商品类型请求实体
/// </summary>
public class CodeGoodsTypeReq
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 商品类型代码
/// </summary>
public string GoodsTypeCode { get; set; }
/// <summary>
/// 商品类型名称
/// </summary>
public string GoodsTypeName { get; set; }
/// <summary>
/// 英文名称
/// </summary>
public string EnName { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 备注
/// </summary>
public string Note { get; set; } = "";
}
/// <summary>
/// 验证
/// </summary>
public class CodeGoodsTypeValidator : AbstractValidator<CodeGoodsTypeReq>
{
/// <summary>
/// 构造函数
/// </summary>
public CodeGoodsTypeValidator()
{
this.RuleFor(o => o.GoodsTypeCode)
.NotEmpty().WithName("商品类型代码");
this.RuleFor(o => o.GoodsTypeName)
.NotEmpty().WithName("商品类型名称");
}
}

@ -0,0 +1,44 @@
using DS.Module.Core;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 商品类型返回
/// </summary>
public class CodeGoodsTypeRes
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 商品类型代码
/// </summary>
public string GoodsTypeCode { get; set; }
/// <summary>
/// 商品类型名称
/// </summary>
public string GoodsTypeName { get; set; }
/// <summary>
/// 英文名称
/// </summary>
public string EnName { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 备注
/// </summary>
public string Note { get; set; } = "";
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateTime { get; set; }
}

@ -15,52 +15,46 @@ public class CodePort: BaseModel<long>
[SugarColumn(ColumnDescription = "港口英文名称", Length = 60)] [SugarColumn(ColumnDescription = "港口英文名称", Length = 60)]
public string PortName { get; set; } public string PortName { get; set; }
/// <summary> /// <summary>
/// 集装箱类型 /// 港口中文名称
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "集装箱类型", Length = 5)] [SugarColumn(ColumnDescription = "港口中文名称", Length = 60)]
public string CtnSize { get; set; } public string CnName { get; set; }
/// <summary> /// <summary>
/// 集装箱尺寸 /// 国家名称
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "集装箱尺寸", Length = 10)] [SugarColumn(ColumnDescription = "国家名称", Length = 80)]
public string CtnType { get; set; } public string CountryName { get; set; }
/// <summary> /// <summary>
/// EDI代码 /// 所在大洲
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "EDI代码", Length = 5)] [SugarColumn(ColumnDescription = "所在大洲",IsNullable = true, Length = 60)]
public string EdiCode { get; set; } public string Chau { get; set; }
/// <summary> /// <summary>
/// 箱皮重 /// 说明
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "箱皮重", Length = 18,DecimalDigits = 3,DefaultValue ="0")] [SugarColumn(ColumnDescription = "说明",IsNullable = true, Length = 2000)]
public decimal CtnWeight { get; set; } public string Explain { get; set; }
/// <summary> /// <summary>
/// 中文说明 /// 港口类型
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "中文说明", Length = 100)] [SugarColumn(ColumnDescription = "港口类型",IsNullable = true, Length = 10)]
public string CnExplain { get; set; } public string PortType { get; set; }
/// <summary> /// <summary>
/// 英文说明 /// 国家Id
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "英文说明", Length = 100)] [SugarColumn(ColumnDescription = "国家Id")]
public string EnExplain { get; set; } public long CountryId { get; set; }
/// <summary> /// <summary>
/// AFR代码 /// 航线Id
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "AFR代码", Length = 10)] [SugarColumn(ColumnDescription = "航线Id")]
public string AfrCode { get; set; } public long LaneId { get; set; }
/// <summary> /// <summary>
/// 默认限重 /// EDI代码
/// </summary>
[SugarColumn(ColumnDescription = "默认限重", Length = 18,DecimalDigits = 3,DefaultValue ="0")]
public decimal LimitWeight { get; set; }
/// <summary>
/// TEU
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "TEU", Length = 8,DecimalDigits = 2,DefaultValue ="0")] [SugarColumn(ColumnDescription = "EDI代码", Length = 5)]
public decimal TEU { get; set; } public string EdiCode { get; set; }
/// <summary> /// <summary>
/// 状态 0启用 1禁用 /// 状态 0启用 1禁用
/// </summary> /// </summary>

@ -0,0 +1,45 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using SqlSugar;
namespace DS.WMS.Core.Code.Entity;
/// <summary>
/// 船名信息表
/// </summary>
[SqlSugar.SugarTable("op_code_vessel","船名信息表")]
public class CodeVessel: BaseModel<long>
{
/// <summary>
/// 船名
/// </summary>
[SugarColumn(ColumnDescription = "船名", Length = 60)]
public string VesselName { get; set; }
/// <summary>
/// 中文说明
/// </summary>
[SugarColumn(ColumnDescription = "中文说明", Length = 100)]
public string CnName { get; set; }
/// <summary>
/// 船公司Id
/// </summary>
[SugarColumn(ColumnDescription = "船公司Id")]
public long CarrierId { get; set; }
/// <summary>
/// 船运代理
/// </summary>
[SugarColumn(ColumnDescription = "船运代理",IsNullable = true, Length = 100)]
public string ShipAgency { get; set; }
/// <summary>
/// EDI代码-船舶呼号
/// </summary>
[SugarColumn(ColumnDescription = "EDI代码-船舶呼号", Length = 5)]
public string EdiCode { get; set; }
/// <summary>
/// 状态 0启用 1禁用
/// </summary>
[SugarColumn(ColumnDescription = "状态",DefaultValue = "0")]
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
}

@ -0,0 +1,70 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using SqlSugar;
namespace DS.WMS.Core.Code.Entity;
/// <summary>
/// 航次信息表
/// </summary>
[SqlSugar.SugarTable("op_code_voyno","航次信息表")]
public class CodeVoyno: BaseModel<long>
{
/// <summary>
/// 船名Id
/// </summary>
[SugarColumn(ColumnDescription = "船名Id")]
public long VesselId { get; set; }
/// <summary>
/// 航次
/// </summary>
[SugarColumn(ColumnDescription = "航次", Length = 10)]
public string VoyNo { get; set; }
/// <summary>
/// 装货港
/// </summary>
[SugarColumn(ColumnDescription = "装货港", Length = 60)]
public string LoadPort { get; set; }
/// <summary>
/// 中转港
/// </summary>
[SugarColumn(ColumnDescription = "中转港", Length = 60)]
public string EnterPort { get; set; }
/// <summary>
/// 卸货港
/// </summary>
[SugarColumn(ColumnDescription = "卸货港", Length = 60)]
public string DischargePort { get; set; }
/// <summary>
/// 开船日期
/// </summary>
[SugarColumn(ColumnDescription = "开船日期")]
public DateTime? ETD { get; set; }
/// <summary>
/// 预抵日期
/// </summary>
[SugarColumn(ColumnDescription = "预抵日期")]
public DateTime? ETA { get; set; }
/// <summary>
/// ATD
/// </summary>
[SugarColumn(ColumnDescription = "ATD")]
public DateTime? ATD { get; set; }
/// <summary>
/// 截单时间
/// </summary>
[SugarColumn(ColumnDescription = "截单时间")]
public DateTime? CloseDoDate { get; set; }
/// <summary>
/// 默认场站码头Id
/// </summary>
[SugarColumn(ColumnDescription = "默认场站码头Id")]
public long YardId { get; set; }
/// <summary>
/// 状态 0启用 1禁用
/// </summary>
[SugarColumn(ColumnDescription = "状态",DefaultValue = "0")]
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
}

@ -0,0 +1,70 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using DS.WMS.Core.Code.Dtos;
namespace DS.WMS.Core.Code.Interface;
public interface ICodeGoodsTypeService
{
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
DataResult<List<CodeGoodsTypeRes>> GetListByPage(PageRequest request);
/// <summary>
/// 编辑
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
DataResult EditCodeGoodsType(CodeGoodsTypeReq req);
/// <summary>
/// 获取详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
DataResult<CodeGoodsTypeRes> GetCodeGoodsTypeInfo(string id);
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
DataResult<List<CodeGoodsTypeRes>> GetClientListByPage(PageRequest request);
/// <summary>
/// 编辑-客户端
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
DataResult EditClientCodeGoodsType(CodeGoodsTypeReq req);
/// <summary>
/// 获取详情 -客户端
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<CodeGoodsTypeRes> GetClientCodeGoodsTypeInfo(string id);
/// <summary>
/// 获取商品类型列表-基础库
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
DataResult<List<CodeGoodsTypeRes>> GetCodeGoodsTypeList(PageRequest request);
/// <summary>
/// 导入商品类型列表
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
DataResult ImportCodeGoodsType(IdModel req);
/// <summary>
/// 获取当前租户已有的商品类型
/// </summary>
/// <returns></returns>
public DataResult<List<string>> GetExistCodeGoodsTypeList();
}

@ -0,0 +1,169 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Code.Interface;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.Code.Method;
public class CodeGoodsTypeService:ICodeGoodsTypeService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public CodeGoodsTypeService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
}
public DataResult<List<CodeGoodsTypeRes>> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<CodeGoodsType>()
.Where(whereList)
.Select<CodeGoodsTypeRes>().ToQueryPage(request.PageCondition);
return data;
}
public DataResult EditCodeGoodsType(CodeGoodsTypeReq req)
{
if (req.Id == 0)
{
if (db.Queryable<CodeGoodsType>().Where(x=>x.GoodsTypeCode == req.GoodsTypeCode.Trim()).Any())
{
return DataResult.Failed("商品类型已存在!",MultiLanguageConst.CodeGoodsTypeExist);
}
var data = req.Adapt<CodeGoodsType>();
var entity = db.Insertable(data).ExecuteReturnEntity();
return DataResult.Successed("添加成功!", entity.Id,MultiLanguageConst.DataCreateSuccess);
}
else
{
var info = db.Queryable<CodeGoodsType>().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
}
}
public DataResult<CodeGoodsTypeRes> GetCodeGoodsTypeInfo(string id)
{
var data = db.Queryable<CodeGoodsType>()
.Where(a => a.Id == long.Parse(id))
.Select<CodeGoodsTypeRes>()
.First();
return DataResult<CodeGoodsTypeRes>.Success(data,MultiLanguageConst.DataQuerySuccess);
}
public DataResult<List<CodeGoodsTypeRes>> GetClientListByPage(PageRequest request)
{
var tenantDb = saasService.GetBizDbById(user.TenantId);
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = tenantDb.Queryable<CodeGoodsType>()
.Where(whereList)
.Select<CodeGoodsTypeRes>().ToQueryPage(request.PageCondition);
return data;
}
public DataResult EditClientCodeGoodsType(CodeGoodsTypeReq req)
{
var tenantDb = saasService.GetBizDbById(user.TenantId);
if (req.Id == 0)
{
if (tenantDb.Queryable<CodeGoodsType>().Where(x=>x.GoodsTypeCode == req.GoodsTypeCode.Trim()).Any())
{
return DataResult.Failed("商品类型已存在!",MultiLanguageConst.CodeGoodsTypeExist);
}
var data = req.Adapt<CodeGoodsType>();
var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
return DataResult.Successed("添加成功!", entity.Id,MultiLanguageConst.DataCreateSuccess);
}
else
{
var info = tenantDb.Queryable<CodeGoodsType>().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
}
}
public DataResult<CodeGoodsTypeRes> GetClientCodeGoodsTypeInfo(string id)
{
var tenantDb = saasService.GetBizDbById(user.TenantId);
var data = tenantDb.Queryable<CodeGoodsType>()
.Where(a => a.Id == long.Parse(id))
.Select<CodeGoodsTypeRes>()
.First();
return DataResult<CodeGoodsTypeRes>.Success(data,MultiLanguageConst.DataQuerySuccess);
}
public DataResult<List<CodeGoodsTypeRes>> GetCodeGoodsTypeList(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<CodeGoodsType>().Where(x=>x.Status == StatusEnum.Enable)
.Where(whereList)
.Select<CodeGoodsTypeRes>().ToQueryPage(request.PageCondition);
return data;
}
public DataResult ImportCodeGoodsType(IdModel req)
{
var tenantDb = saasService.GetBizDbById(user.TenantId);
var list = db.Queryable<CodeGoodsType>().Where(x =>req.Ids.Contains(x.Id) ).ToList();
if (list.Count == 0)
{
return DataResult.Failed("商品类型导入无数据!",MultiLanguageConst.CodeGoodsTypeImportNoData);
}
if (tenantDb.Queryable<CodeGoodsType>().Where(x =>req.Ids.Contains(x.Id) ).Any())
{
return DataResult.Failed("存在已导入的商品类型!",MultiLanguageConst.CodeGoodsTypeImportAlready);
}
tenantDb.Insertable(list).ExecuteCommand();
return DataResult.Successed("引入成功!",MultiLanguageConst.DataImportSuccess);
}
/// <summary>
/// 获取当前租户已有的商品类型
/// </summary>
/// <returns></returns>
public DataResult<List<string>> GetExistCodeGoodsTypeList()
{
var tenantDb = saasService.GetBizDbById(user.TenantId);
var data = tenantDb.Queryable<CodeGoodsType>()
.Select(n=>n.Id.ToString())
.ToList();
return DataResult<List<string>>.Success(data);
}
}

@ -24,9 +24,6 @@
<Folder Include="BaseInfo\Entity\" /> <Folder Include="BaseInfo\Entity\" />
<Folder Include="BaseInfo\Interface\" /> <Folder Include="BaseInfo\Interface\" />
<Folder Include="BaseInfo\Method\" /> <Folder Include="BaseInfo\Method\" />
<Folder Include="Code\Dtos\" />
<Folder Include="Code\Interface\" />
<Folder Include="Code\Method\" />
<Folder Include="Template\Dtos\" /> <Folder Include="Template\Dtos\" />
<Folder Include="Template\Entity\" /> <Folder Include="Template\Entity\" />
<Folder Include="Template\Interface\" /> <Folder Include="Template\Interface\" />

@ -47,7 +47,7 @@ public interface ITenantService
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
public DataResult<TableDifferenceProvider> GetSaasTableDifference(string id); public DataResult<List<TableDifferenceInfo>> GetSaasTableDifference(string id);
/// <summary> /// <summary>
/// 更新租户表差异 /// 更新租户表差异

@ -194,15 +194,21 @@ public class TenantService : ITenantService
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
public DataResult<TableDifferenceProvider> GetSaasTableDifference(string id) public DataResult<List<TableDifferenceInfo>> GetSaasTableDifference(string id)
{ {
Type[] types= Assembly var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
.LoadFrom("DS.WMS.Core.dll")//如果 .dll报错可以换成 xxx.exe 有些生成的是exe var referencedAssemblies = Directory.GetFiles(path, "DS.WMS.Core.dll").Select(Assembly.LoadFrom).ToArray();
.GetTypes().Where(it=>it.FullName != null && it.FullName.Contains("DS.WMS.Core.Code."))//命名空间过滤,当然你也可以写其他条件过滤 var types = referencedAssemblies
.ToArray(); .SelectMany(a => a.DefinedTypes)
var tenantDb = saasService.GetBizDbById(id); .Select(type => type.AsType())
var data = db.CodeFirst.GetDifferenceTables(types); .Where(it=>it.FullName.Contains("DS.WMS.Core.Code.Entity.")).ToArray();
return DataResult<TableDifferenceProvider>.Success("获取数据成功!", data, MultiLanguageConst.DataQuerySuccess); // Type[] types= Assembly
// .LoadFrom("DS.WMS.Core.dll")//如果 .dll报错可以换成 xxx.exe 有些生成的是exe
// .GetTypes().Where(it=>it.FullName.Contains("DS.WMS.Core.Code.Entity."))//命名空间过滤,当然你也可以写其他条件过滤
// .ToArray();
var tenantDb = saasService.GetBizDbScopeById(id);
var data = tenantDb.CodeFirst.GetDifferenceTables(types).ToDiffList();
return DataResult<List<TableDifferenceInfo>>.Success("获取数据成功!", data, MultiLanguageConst.DataQuerySuccess);
} }
/// <summary> /// <summary>
/// 更新租户表差异 /// 更新租户表差异
@ -211,11 +217,17 @@ public class TenantService : ITenantService
/// <returns></returns> /// <returns></returns>
public DataResult UpdateSaasTableInfo(IdModel req) public DataResult UpdateSaasTableInfo(IdModel req)
{ {
Type[] types= Assembly // Type[] types= Assembly
.LoadFrom("DS.WMS.Core.dll")//如果 .dll报错可以换成 xxx.exe 有些生成的是exe // .LoadFrom("DS.WMS.Core.dll")//如果 .dll报错可以换成 xxx.exe 有些生成的是exe
.GetTypes().Where(it=>it.FullName != null && it.FullName.Contains("DS.WMS.Core.Code."))//命名空间过滤,当然你也可以写其他条件过滤 // .GetTypes().Where(it=>it.FullName.Contains("DS.WMS.Core.Code.Entity."))//命名空间过滤,当然你也可以写其他条件过滤
.ToArray(); // .ToArray();
var tenantDb = saasService.GetBizDbById(req.Id); var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
var referencedAssemblies = Directory.GetFiles(path, "DS.WMS.Core.dll").Select(Assembly.LoadFrom).ToArray();
var types = referencedAssemblies
.SelectMany(a => a.DefinedTypes)
.Select(type => type.AsType())
.Where(it=>it.FullName.Contains("DS.WMS.Core.Code.Entity.")).ToArray();
var tenantDb = saasService.GetBizDbScopeById(req.Id);
StaticConfig.CodeFirst_MySqlCollate="utf8mb4_0900_ai_ci";//较高版本支持 StaticConfig.CodeFirst_MySqlCollate="utf8mb4_0900_ai_ci";//较高版本支持
tenantDb.CodeFirst.InitTables(types); tenantDb.CodeFirst.InitTables(types);
return DataResult.Successed("更新租户表信息成功!", MultiLanguageConst.DataUpdateSuccess); return DataResult.Successed("更新租户表信息成功!", MultiLanguageConst.DataUpdateSuccess);

@ -0,0 +1,100 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Code.Interface;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.MainApi.Controllers;
/// <summary>
/// 商品类型服务
/// </summary>
public class CodeGoodsTypeController : ApiController
{
private readonly ICodeGoodsTypeService _invokeService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="invokeService"></param>
public CodeGoodsTypeController(ICodeGoodsTypeService invokeService)
{
_invokeService = invokeService;
}
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
[Route("GetCodeGoodsTypeList")]
public DataResult<List<CodeGoodsTypeRes>> GetCodeGoodsTypeList([FromBody] PageRequest request)
{
var res = _invokeService.GetClientListByPage(request);
return res;
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
[Route("EditCodeGoodsType")]
public DataResult EditCodeGoodsType([FromBody] CodeGoodsTypeReq model)
{
var res = _invokeService.EditClientCodeGoodsType(model);
return res;
}
/// <summary>
/// 详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
[Route("GetCodeGoodsTypeInfo")]
public DataResult<CodeGoodsTypeRes> GetCodeGoodsTypeInfo([FromQuery] string id)
{
var res = _invokeService.GetClientCodeGoodsTypeInfo(id);
return res;
}
/// <summary>
/// 获取商品类型列表-基础库
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
[Route("GetBasicsCodeGoodsTypeList")]
public DataResult<List<CodeGoodsTypeRes>> GetBasicsCodeGoodsTypeList([FromBody] PageRequest request)
{
var res = _invokeService.GetCodeGoodsTypeList(request);
return res;
}
/// <summary>
/// 导入商品类型列表-基础库
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[Route("ImportCodeGoodsType")]
public DataResult ImportCodeGoodsType([FromBody] IdModel req)
{
var res = _invokeService.ImportCodeGoodsType(req);
return res;
}
/// <summary>
/// 获取当前租户已有的商品类型
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("GetExistCodeGoodsTypeList")]
public DataResult<List<string>> GetExistCodeGoodsTypeList()
{
var res = _invokeService.GetExistCodeGoodsTypeList();
return res;
}
}

@ -159,3 +159,24 @@
2024-02-23 08:54:46.6245 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.MainApi\bin\Debug\net8.0\nlog.config 2024-02-23 08:54:46.6245 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.MainApi\bin\Debug\net8.0\nlog.config
2024-02-23 08:54:46.6406 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile 2024-02-23 08:54:46.6406 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-02-23 08:54:46.6758 Info Configuration initialized. 2024-02-23 08:54:46.6758 Info Configuration initialized.
2024-02-27 15:29:36.5412 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-02-27 15:29:36.7449 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-02-27 15:29:36.8067 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-02-27 15:29:36.9606 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-02-27 15:29:37.0360 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.MainApi\bin\Debug\net8.0\nlog.config
2024-02-27 15:29:37.0586 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-02-27 15:29:37.1284 Info Configuration initialized.
2024-02-27 15:38:18.1402 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-02-27 15:38:18.2060 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-02-27 15:38:18.2172 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-02-27 15:38:18.2437 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-02-27 15:38:18.2600 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.MainApi\bin\Debug\net8.0\nlog.config
2024-02-27 15:38:18.2753 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-02-27 15:38:18.3234 Info Configuration initialized.
2024-02-27 15:42:56.3736 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-02-27 15:42:56.4650 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-02-27 15:42:56.4939 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-02-27 15:42:56.5748 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-02-27 15:42:56.6300 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.MainApi\bin\Debug\net8.0\nlog.config
2024-02-27 15:42:56.6611 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-02-27 15:42:56.7151 Info Configuration initialized.

@ -23,14 +23,14 @@ public class SaasTest
} }
[Fact] [Fact]
public void TreeTest1() public void SaasTest1()
{ {
Type[] types= Assembly Type[] types= Assembly
.LoadFrom("DS.WMS.Core.dll")//如果 .dll报错可以换成 xxx.exe 有些生成的是exe .LoadFrom("DS.WMS.Core.dll")//如果 .dll报错可以换成 xxx.exe 有些生成的是exe
.GetTypes().Where(it=>it.FullName.Contains("DS.WMS.Core.Code."))//命名空间过滤,当然你也可以写其他条件过滤 .GetTypes().Where(it=>it.FullName.Contains("DS.WMS.Core.Code.Entity."))//命名空间过滤,当然你也可以写其他条件过滤
.ToArray(); .ToArray();
var tenantDb = saasService.GetBizDbById("1750335377144680448"); var tenantDb = saasService.GetBizDbScopeById("1750335377144680448");
var temp = db.CodeFirst.GetDifferenceTables(types); var temp = tenantDb.CodeFirst.GetDifferenceTables(types);
// var diffString= tenantDb.CodeFirst.GetDifferenceTables(types).ToDiffString(); // var diffString= tenantDb.CodeFirst.GetDifferenceTables(types).ToDiffString();
// StaticConfig.CodeFirst_MySqlCollate="utf8mb4_0900_ai_ci";//较高版本支持 // StaticConfig.CodeFirst_MySqlCollate="utf8mb4_0900_ai_ci";//较高版本支持
// tenantDb.CodeFirst.InitTables(types); // tenantDb.CodeFirst.InitTables(types);

Loading…
Cancel
Save