change 项目结构改造DDD

This commit is contained in:
李鹏军 2024-02-27 16:22:42 +08:00
parent 87400bbeda
commit 1e9c1d9c7e
61 changed files with 1035 additions and 524 deletions

View File

@ -16,6 +16,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SJZY.Track.HttpApi", "src\S
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SJZY.Track.Test", "test\SJZY.Track.Test\SJZY.Track.Test.csproj", "{3A53539C-4A85-4E5D-A071-7B4B193AB0E0}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SJZY.Track.Test", "test\SJZY.Track.Test\SJZY.Track.Test.csproj", "{3A53539C-4A85-4E5D-A071-7B4B193AB0E0}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SJZY.Track.Domain", "src\SJZY.Track.Domain\SJZY.Track.Domain.csproj", "{073EB297-E752-49AC-BED8-B4AEBAB518F6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution items", "solution items", "{086C7812-46F9-49FD-B490-A769E2C0729E}"
ProjectSection(SolutionItems) = preProject
common.props = common.props
NuGet.Config = NuGet.Config
.gitignore = .gitignore
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -42,6 +51,10 @@ Global
{3A53539C-4A85-4E5D-A071-7B4B193AB0E0}.Debug|Any CPU.Build.0 = Debug|Any CPU {3A53539C-4A85-4E5D-A071-7B4B193AB0E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A53539C-4A85-4E5D-A071-7B4B193AB0E0}.Release|Any CPU.ActiveCfg = Release|Any CPU {3A53539C-4A85-4E5D-A071-7B4B193AB0E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A53539C-4A85-4E5D-A071-7B4B193AB0E0}.Release|Any CPU.Build.0 = Release|Any CPU {3A53539C-4A85-4E5D-A071-7B4B193AB0E0}.Release|Any CPU.Build.0 = Release|Any CPU
{073EB297-E752-49AC-BED8-B4AEBAB518F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{073EB297-E752-49AC-BED8-B4AEBAB518F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{073EB297-E752-49AC-BED8-B4AEBAB518F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{073EB297-E752-49AC-BED8-B4AEBAB518F6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -52,9 +65,10 @@ Global
{D9CF5706-1972-414F-821E-AA32C13B8570} = {DAC93270-5A25-40E5-B851-E7CA398DBC31} {D9CF5706-1972-414F-821E-AA32C13B8570} = {DAC93270-5A25-40E5-B851-E7CA398DBC31}
{390A44FB-0DB5-4B66-86AB-7712DC3030F5} = {DAC93270-5A25-40E5-B851-E7CA398DBC31} {390A44FB-0DB5-4B66-86AB-7712DC3030F5} = {DAC93270-5A25-40E5-B851-E7CA398DBC31}
{3A53539C-4A85-4E5D-A071-7B4B193AB0E0} = {0E2537C3-6EF3-4085-9BD2-CF923E53F82A} {3A53539C-4A85-4E5D-A071-7B4B193AB0E0} = {0E2537C3-6EF3-4085-9BD2-CF923E53F82A}
{073EB297-E752-49AC-BED8-B4AEBAB518F6} = {DAC93270-5A25-40E5-B851-E7CA398DBC31}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = { 8289A516 - 787C - 4D9D - B972 - E7047BDD206B} SolutionGuid = { 8289A516 - 787C - 4D9D - B972 - E7047BDD206B}
SolutionGuid = {C8AD8123-683D-406E-A8FB-1D0184C19472} SolutionGuid = {C8AD8123-683D-406E-A8FB-1D0184C19472}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

7
common.props Normal file
View File

@ -0,0 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<!-- <WarningsAsErrors>Nullable</WarningsAsErrors>-->
</PropertyGroup>
</Project>

View File

@ -13,7 +13,7 @@ try
.Host.AddAppSettingsSecretsJson() .Host.AddAppSettingsSecretsJson()
.UseAutofac(); .UseAutofac();
await builder.AddApplicationAsync<ApiModule>(); await builder.AddApplicationAsync<SJZYTrackApiModule>();
var app = builder.Build(); var app = builder.Build();
await app.InitializeApplicationAsync(); await app.InitializeApplicationAsync();
@ -21,5 +21,5 @@ try
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"项目启动失败,异常信息:{ex}"); Console.WriteLine($"项目启动失败,异常信息:{ex}");
} }

View File

@ -21,10 +21,12 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.2" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Volo.Abp.Autofac" Version="7.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SJZY.Track.Application\SJZY.Track.Application.csproj" /> <ProjectReference Include="..\SJZY.Track.Application\SJZY.Track.Application.csproj" />
<ProjectReference Include="..\SJZY.Track.Repository\SJZY.Track.Repository.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -9,6 +9,7 @@ using SJZY.Expand.ABP.Core.Prometheus;
using SJZY.Expand.ABP.Core.Redis; using SJZY.Expand.ABP.Core.Redis;
using SJZY.Expand.ABP.Core.Swagger; using SJZY.Expand.ABP.Core.Swagger;
using SJZY.Track.Application; using SJZY.Track.Application;
using SJZY.Track.Repository;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.AspNetCore.Serilog;
@ -17,7 +18,7 @@ using Volo.Abp.Autofac;
using Volo.Abp.Json; using Volo.Abp.Json;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
[assembly: HostingStartup(typeof(SJZY.Expand.ABP.Core.HostingStartup))] [assembly: HostingStartup(typeof(HostingStartup))]
namespace SJZY.Track.Api namespace SJZY.Track.Api
{ {
[DependsOn( [DependsOn(
@ -25,9 +26,10 @@ namespace SJZY.Track.Api
typeof(SjzyAbpCodeModule), typeof(SjzyAbpCodeModule),
typeof(ApplicationModule), typeof(ApplicationModule),
typeof(AbpAspNetCoreMvcModule), typeof(AbpAspNetCoreMvcModule),
typeof(AbpAspNetCoreSerilogModule) typeof(AbpAspNetCoreSerilogModule),
typeof(SJZYTrackRepositoryModule)
)] )]
public class ApiModule : AbpModule public class SJZYTrackApiModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {

View File

@ -7,8 +7,7 @@
} }
}, },
"ConnectionStrings": { "ConnectionStrings": {
"DefaultConnection": "server=mysql-dev.default.svc.cluster.local;Database=sjzy_openapi;Uid=sjzy_dev_user;Pwd=818f83e5;AllowLoadLocalInfile=true;SslMode=None;Charset=utf8mb4;", "DefaultConnection": "server=mysql-dev.default.svc.cluster.local;Database=sjzy_track;Uid=sjzy_dev_user;Pwd=818f83e5;AllowLoadLocalInfile=true;SslMode=None;Charset=utf8mb4;",
"BICenterConnection": "server=mysql-test.default.svc.cluster.local;Database=sjzy_bi_center;Uid=sjzy_test_user;Pwd=848c1c31;AllowLoadLocalInfile=true;SslMode=None;Charset=utf8mb4;"
}, },
"Redis": { "Redis": {
"Host": "redis-dev.default.svc.cluster.local:6379", "Host": "redis-dev.default.svc.cluster.local:6379",
@ -60,6 +59,12 @@
"BucketName": "cams3", "BucketName": "cams3",
"ReturnHttpsUrl": true "ReturnHttpsUrl": true
}, },
"ElasticSearch": {
"NodeUrls": [ "http://elasticsearch-dev.default.svc.cluster.local:9200" ],
"LoginName": "elastic",
"Password": "afyTgmVb8jq6",
"Base64PassPassword": "Basic ZWxhc3RpYzphZnlUZ21WYjhqcTY="
},
"RemoteServices": { "RemoteServices": {
"UserCenter": { "UserCenter": {
"BaseUrl": "http://192.168.80.55:5020/" "BaseUrl": "http://192.168.80.55:5020/"

View File

@ -1,5 +1,5 @@
using SJZY.Expand.ABP.Core.Localization; using SJZY.Track.Domain;
using SJZY.LoggerCenter.HttpApi; using SJZY.Expand.ABP.Core.Localization;
using SJZY.Track.Application.Localization; using SJZY.Track.Application.Localization;
using SJZY.UserCenter.Contracts; using SJZY.UserCenter.Contracts;
using SJZY.UserCenter.SharedModel; using SJZY.UserCenter.SharedModel;
@ -15,12 +15,11 @@ namespace SJZY.Track.Application
{ {
[DependsOn( [DependsOn(
typeof(AbpAutoMapperModule), typeof(AbpAutoMapperModule),
typeof(RepositoryModule),
typeof(AbpFluentValidationModule), typeof(AbpFluentValidationModule),
typeof(AbpLocalizationModule), typeof(AbpLocalizationModule),
typeof(AbpVirtualFileSystemModule), typeof(AbpVirtualFileSystemModule),
typeof(AbpHttpClientModule), typeof(AbpHttpClientModule),
typeof(LoggerCenterHttpApiModule) typeof(SJZYTrackDomainModule)
)] )]
public class ApplicationModule : AbpModule public class ApplicationModule : AbpModule
{ {
@ -37,8 +36,6 @@ namespace SJZY.Track.Application
options.ConventionalControllers.Create(typeof(ApplicationModule).Assembly);//创建动态api options.ConventionalControllers.Create(typeof(ApplicationModule).Assembly);//创建动态api
}); });
//添加虚拟文件系统 //添加虚拟文件系统
Configure<AbpVirtualFileSystemOptions>(options => Configure<AbpVirtualFileSystemOptions>(options =>
{ {
@ -54,9 +51,6 @@ namespace SJZY.Track.Application
.AddVirtualJson("/Localization/Resources"); .AddVirtualJson("/Localization/Resources");
}); });
//日志中心
context.Services.AddHttpClientProxies(typeof(LoggerCenterHttpApiModule).Assembly, "LoggerCenter", false);
//用户中心 //用户中心
context.Services.AddHttpClientProxies(typeof(SjzyUserCenterHttpApiModule).Assembly, "UserCenter", false); context.Services.AddHttpClientProxies(typeof(SjzyUserCenterHttpApiModule).Assembly, "UserCenter", false);
} }

View File

@ -1,33 +1,33 @@
using AutoMapper; using AutoMapper;
using SJZY.Track.Domain.DemoAggregate;
using SJZY.Track.Domain.DemoAggregate.Dtos;
using SJZY.Track.Application.Dtos.Demo; using SJZY.Track.Application.Dtos.Demo;
using SJZY.Track.Repository.Demo.ValueObjects;
namespace SJZY.Track.Application.AutoMapper namespace SJZY.Track.Application.AutoMapper;
internal class AutoMapperProfile : Profile
{ {
internal class AutoMapperProfile : Profile public AutoMapperProfile()
{ {
public AutoMapperProfile() CreateMap<UnifyPageResultDto<DemoEntity>, UnifyPageResultDto<GetDemoListByPageOutput>>(MemberList.None);
{
CreateMap<UnifyPageResultDto<DemoEntity>, UnifyPageResultDto<GetDemoListByPageOutput>>(MemberList.None);
CreateMap<GetDemoListByPageInput, DemoValueObject>(MemberList.None).ReverseMap(); CreateMap<GetDemoListByPageInput, DemoValueObject>(MemberList.None).ReverseMap();
CreateMap<UnifyPageResultDto<GetDemoListByPageInput>, UnifyPageResultDto<DemoValueObject>>(MemberList.None).ReverseMap(); CreateMap<UnifyPageResultDto<GetDemoListByPageInput>, UnifyPageResultDto<DemoValueObject>>(MemberList.None).ReverseMap();
/* /*
代码说明: 代码说明:
MemberList.None的意思是,忽略源对象和目标对象的属性匹配检查,其他可选值:MemberList.Source(检查是否映射了所有源成员)、MemberList.Destination(检查是否映射了所有目标成员) MemberList.None的意思是,忽略源对象和目标对象的属性匹配检查,其他可选值:MemberList.Source(检查是否映射了所有源成员)、MemberList.Destination(检查是否映射了所有目标成员)
.ReverseMap()的意思是配置双向调用关系,既一行代码既支持从 GetDemoListByPageInput -> DemoValueObject 的映射,同时也支持从 DemoValueObject -> GetDemoListByPageInput 的映射 .ReverseMap()的意思是配置双向调用关系,既一行代码既支持从 GetDemoListByPageInput -> DemoValueObject 的映射,同时也支持从 DemoValueObject -> GetDemoListByPageInput 的映射
如果对一对模型多次配置规则,会以最后一次为准,配置了这样规则后,最终执行结果是 Name + 444 如果对一对模型多次配置规则,会以最后一次为准,配置了这样规则后,最终执行结果是 Name + 444
CreateMap<DemoInput, DemoEntity>().ForMember(dest => dest.Description, opt => opt.MapFrom(m => m.Name + "22")); CreateMap<DemoInput, DemoEntity>().ForMember(dest => dest.Description, opt => opt.MapFrom(m => m.Name + "22"));
CreateMap<DemoInput, DemoEntity>().ForMember(dest => dest.Description, opt => opt.MapFrom(m => m.Name + "444")); CreateMap<DemoInput, DemoEntity>().ForMember(dest => dest.Description, opt => opt.MapFrom(m => m.Name + "444"));
*/ */
CreateMap<DemoEntity, DemoInput>(MemberList.None).ReverseMap(); CreateMap<DemoEntity, DemoInput>(MemberList.None).ReverseMap();
CreateMap<DemoEntity, GetDemoListByPageOutput>(MemberList.None); CreateMap<DemoEntity, GetDemoListByPageOutput>(MemberList.None);
CreateMap<DemoEntity, DemoDetailSaveInput>(MemberList.None).ReverseMap(); CreateMap<DemoEntity, DemoDetailSaveInput>(MemberList.None).ReverseMap();
}
} }
} }

View File

@ -0,0 +1,37 @@
namespace SJZY.Track.Application.Dtos.ProvideServices;
public class GetTrackInput
{
/// <summary>
/// 订单号
/// </summary>
public List<string> OrderNos { get; set; } = new();
/// <summary>
/// 时区 +8 +8.25 -8.5 -9
/// </summary>
public float TimeZone { get; set; }
/// <summary>
/// 排序方式
/// </summary>
public SortMethod SortMethod { get; set; }
}
public enum SortMethod
{
/// <summary>
/// 按轨迹发生时间排序
/// </summary>
ByTrackTime,
/// <summary>
/// 按轨迹发生时间降序
/// </summary>
ByTrackTimeDesc,
/// <summary>
/// 按订单模板排序
/// </summary>
ByTemplate
}

View File

@ -0,0 +1,21 @@
namespace SJZY.Track.Application.Dtos.ProvideServices;
public class GetTrackOutput
{
/// <summary>
/// 订单号
/// </summary>
public string OrderNo { get; set; }
public List<TrackDetail> TrackDetails { get; set; }
}
public class TrackDetail
{
public string Code { get; set; }
public string Status { get; set; }
public string Content { get; set; }
public string Location { get; set; }
public DateTime Date { get; set; }
public float TimeZone { get; set; }
}

View File

@ -3,7 +3,6 @@ global using Microsoft.Extensions.DependencyInjection;
global using SJZY.Expand.ABP.Common.Enums; global using SJZY.Expand.ABP.Common.Enums;
global using SJZY.Expand.ABP.Core.Common.Dto; global using SJZY.Expand.ABP.Core.Common.Dto;
global using SJZY.Track.Repository; global using SJZY.Track.Repository;
global using SJZY.Track.Repository.Demo.Entitys;
global using Volo.Abp; global using Volo.Abp;
global using Volo.Abp.Application.Services; global using Volo.Abp.Application.Services;
global using Volo.Abp.Validation; global using Volo.Abp.Validation;

View File

@ -23,11 +23,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SJZY.Track.Domain\SJZY.Track.Domain.csproj" />
<ProjectReference Include="..\SJZY.Track.HttpApi\SJZY.Track.HttpApi.csproj" /> <ProjectReference Include="..\SJZY.Track.HttpApi\SJZY.Track.HttpApi.csproj" />
<ProjectReference Include="..\SJZY.Track.Repository\SJZY.Track.Repository.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Interfaces\" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,7 +1,7 @@
using SJZY.Expand.ABP.Core.Common; using SJZY.Track.Domain.DemoAggregate;
using SJZY.Track.Domain.DemoAggregate.Dtos;
using SJZY.Expand.ABP.Core.Common;
using SJZY.Track.Application.Dtos.Demo; using SJZY.Track.Application.Dtos.Demo;
using SJZY.Track.Repository.Demo.Services;
using SJZY.Track.Repository.Demo.ValueObjects;
namespace SJZY.Track.Application.Services.Demo namespace SJZY.Track.Application.Services.Demo
{ {

View File

@ -0,0 +1,79 @@
using SJZY.Track.Domain.OrderAggregate;
using SJZY.Track.Domain.TrackTemplateAggregate;
using SJZY.Track.Application.Dtos.ProvideServices;
using SJZY.Track.Repository.TrackDetails;
namespace SJZY.Track.Application.Services.ProvideServices;
[ApiExplorerSettings(GroupName = "TrackQuery")]
public class TrackQueryService : ApplicationService
{
private readonly ITrackDetailsRepository _trackDetailsRepository;
private readonly IOrderRepository _orderRepository;
private readonly ITrackTemplateRepository _trackTemplateRepository;
public TrackQueryService(ITrackDetailsRepository trackDetailsRepository, IOrderRepository orderRepository,
ITrackTemplateRepository trackTemplateRepository)
{
_trackDetailsRepository = trackDetailsRepository;
_orderRepository = orderRepository;
_trackTemplateRepository = trackTemplateRepository;
}
[HttpPost("TrackQuery/GetTrack")]
public async Task<List<GetTrackOutput>> GetTrackAsync(GetTrackInput input)
{
if (input.OrderNos.Count > 500)
{
throw new BusinessException(message: "最多只能查询500单");
}
var res = new List<GetTrackOutput>();
var distinctOrderNumbers = input.OrderNos.Distinct().ToList();
var details = await _trackDetailsRepository.GetListAsync(distinctOrderNumbers);
var orderTemplates = await _orderRepository.GetOrderTemplatesAsync(distinctOrderNumbers);
var distinctTemplateIds = orderTemplates.Select(x => x.TrackTemplateId).Distinct().ToList();
var templateContents = await _trackTemplateRepository.GetTemplateContentsAsync(distinctTemplateIds);
foreach (var group in details.GroupBy(x => x.OrderId))
{
var item = new GetTrackOutput();
var trackDetails = group.ToList();
item.OrderNo = trackDetails.First().OrderNo;
item.TrackDetails = trackDetails.Select(x => new TrackDetail
{
Code = x.TrackCode,
Status = x.TrackStatus,
Content = x.TrackContent,
Location = x.TrackPlace,
Date = x.TrackTime.AddHours(input.TimeZone - x.TraceTimeZone),
TimeZone = x.TraceTimeZone
}).ToList();
TrackDetailSort(item, input.SortMethod);
res.Add(item);
}
return res;
}
private void TrackDetailSort(GetTrackOutput item, SortMethod sortMethod)
{
switch (sortMethod)
{
case SortMethod.ByTrackTime:
// tips:quick-sort 直接修改原list
item.TrackDetails.Sort((a, b) => a.Date.CompareTo(b.Date));
break;
case SortMethod.ByTrackTimeDesc:
item.TrackDetails.Sort((a, b) => b.Date.CompareTo(a.Date));
break;
case SortMethod.ByTemplate:
default:
throw new ArgumentOutOfRangeException(nameof(sortMethod), sortMethod, "不支持的排序方式");
}
}
}

View File

@ -0,0 +1,23 @@
namespace SJZY.Track.Domain.DemoAggregate;
[SugarTable("t_demo_detail")]
public class DemoDetailEntity
{
/// <summary>
/// Id
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true)]
public long Id { get; set; }
/// <summary>
/// t_demo.id
/// </summary>
[SugarColumn(ColumnName = "DemoId")]
public long DemoId { get; set; }
/// <summary>
/// 一些说明..
/// </summary>
[SugarColumn(ColumnName = "OtherInfo")]
public string OtherInfo { get; set; }
}

View File

@ -0,0 +1,37 @@
namespace SJZY.Track.Domain.DemoAggregate;
/// <summary>
/// 测试表
/// </summary>
[SugarTable("t_demo")]
public class DemoEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// Id
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public long Id { get; set; }
/// <summary>
/// 姓名
/// </summary>
[SugarColumn(ColumnName = "Name")]
public string Name { get; set; }
/// <summary>
/// 年龄
/// </summary>
[SugarColumn(ColumnName = "Age")]
public int Age { get; set; }
/// <summary>
/// 描述
/// </summary>
[SugarColumn(ColumnName = "Description")]
public string Description { get; set; }
[Navigate(NavigateType.OneToMany, nameof(DemoDetailEntity.DemoId))]
public List<DemoDetailEntity> DemoDetailList { get; set; }
}

View File

@ -1,4 +1,4 @@
namespace SJZY.Track.Repository.Demo.ValueObjects namespace SJZY.Track.Domain.DemoAggregate.Dtos
{ {
public class DemoValueObject public class DemoValueObject
{ {

View File

@ -1,7 +1,6 @@
using SJZY.Track.Repository.Demo.Entitys; using SJZY.Track.Domain.DemoAggregate.Dtos;
using SJZY.Track.Repository.Demo.ValueObjects;
namespace SJZY.Track.Repository.Demo.Services namespace SJZY.Track.Domain.DemoAggregate
{ {
public interface IDemoRepository public interface IDemoRepository
{ {

View File

@ -0,0 +1,9 @@
// Global using directives
global using System;
global using System.Collections.Generic;
global using System.Linq.Expressions;
global using System.Threading.Tasks;
global using SJZY.Expand.ABP.Core.Common.Dto;
global using SJZY.Expand.ABP.Core.SqlSugar.Entitys;
global using SqlSugar;

View File

@ -0,0 +1,97 @@
namespace SJZY.Track.Domain;
public interface IBasicRepository<T>
{
/// <summary>
/// top 1
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression);
Task<TResult> GetFirstAsync<TResult>(Expression<Func<T, bool>> whereExpression,Expression<Func<T, TResult>> resultExpression);
/// <summary>
/// get list
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression);
Task<List<TResult>> GetListAsync<TResult>(Expression<Func<T, bool>> whereExpression,Expression<Func<T, TResult>> resultExpression);
/// <summary>
/// count
/// </summary>
/// <param name="exp"></param>
/// <returns></returns>
Task<int> CountAsync(Expression<Func<T, bool>> exp);
/// <summary>
/// exists
/// </summary>
/// <param name="exp"></param>
/// <returns></returns>
Task<bool> IsAnyAsync(Expression<Func<T, bool>> exp);
/// <summary>
/// update
/// </summary>
/// <param name="entity"></param>
/// <param name="ignoreColumns">要忽略更新的列</param>
/// <returns></returns>
Task<bool> UpdateAsync(T entity, Expression<Func<T, object>> ignoreColumns);
/// <summary>
/// update
/// </summary>
/// <param name="entity"></param>
/// <param name="updateColumns">要更新的列</param>
/// <returns></returns>
Task<bool> UpdateColumnAsync(T entity, Expression<Func<T, object>> updateColumns);
/// <summary>
/// update
/// </summary>
/// <param name="entity"></param>
/// <param name="ignoreAllNullColumns">不更新null值列</param>
/// <param name="ignoreAllDefaultValue">不更新默认值列</param>
/// <returns></returns>
Task<bool> UpdateAsync(T entity, bool ignoreAllNullColumns = false, bool ignoreAllDefaultValue = false);
/// <summary>
/// 批量更新
/// </summary>
/// <param name="entities"></param>
/// <param name="updateColumns">要更新的列</param>
/// <returns></returns>
Task<bool> UpdateRangeAsync(List<T> entities, Expression<Func<T, object>> updateColumns = null);
/// <summary>
/// 软删
/// </summary>
/// <param name="where"></param>
/// <returns></returns>
Task<bool> SoftDeleteAsync(Expression<Func<T, bool>> where);
/// <summary>
/// insert
/// </summary>
/// <param name="insertObj"></param>
/// <returns></returns>
Task<bool> InsertAsync(T insertObj);
/// <summary>
/// 新增返回id
/// </summary>
/// <param name="insertObj"></param>
/// <returns></returns>
Task<int> InsertReturnIdentityAsync(T insertObj);
/// <summary>
/// 批量insert
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
Task<bool> InsertRangeAsync(List<T> entities);
}

View File

@ -0,0 +1,14 @@
namespace SJZY.Track.Domain.OrderAggregate.Dtos;
public class OrderTemplateDto
{
/// <summary>
/// 订单id
/// </summary>
public int OrderId { get; set; }
/// <summary>
/// 模板id
/// </summary>
public int TrackTemplateId { get; set; }
}

View File

@ -0,0 +1,13 @@
using SJZY.Track.Domain.OrderAggregate.Dtos;
namespace SJZY.Track.Domain.OrderAggregate;
public interface IOrderRepository : IBasicRepository<OrderEntity>
{
/// <summary>
/// 根据订单号,获取订单模板
/// </summary>
/// <param name="distinctOrderNumbers"></param>
/// <returns></returns>
Task<List<OrderTemplateDto>> GetOrderTemplatesAsync(List<string> distinctOrderNumbers);
}

View File

@ -0,0 +1,70 @@
namespace SJZY.Track.Domain.OrderAggregate;
/// <summary>
/// 轨迹订单主表
/// </summary>
[SugarTable("t_order")]
public class OrderEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 客户id(外部主体id)
/// </summary>
[SugarColumn(ColumnName = "CustomId")]
public int CustomId { get; set; }
/// <summary>
/// 订单是否完结(异步维护)
/// </summary>
[SugarColumn(ColumnName = "IsCompleted")]
public bool IsCompleted { get; set; }
/// <summary>
/// 最新轨迹内容(异步维护)
/// </summary>
[SugarColumn(ColumnName = "LatestTraceContent")]
public string LatestTraceContent { get; set; }
/// <summary>
/// 最新轨迹内容英文(异步维护)
/// </summary>
[SugarColumn(ColumnName = "LatestTraceEnContent")]
public string LatestTraceEnContent { get; set; }
/// <summary>
/// 最新轨迹时间(异步维护)
/// </summary>
[SugarColumn(ColumnName = "LatestTraceTime")]
public DateTime? LatestTraceTime { get; set; }
/// <summary>
/// 订单明细(json字符串)
/// </summary>
[SugarColumn(ColumnName = "OrderDetails")]
public string OrderDetails { get; set; }
/// <summary>
/// 订单号
/// </summary>
[SugarColumn(ColumnName = "OrderNo")]
public string OrderNo { get; set; }
/// <summary>
/// 订单类型(主数据枚举TrackOrderType)
/// </summary>
[SugarColumn(ColumnName = "OrderType")]
public int OrderType { get; set; }
/// <summary>
/// 子系统id
/// </summary>
[SugarColumn(ColumnName = "SubSystemId")]
public int SubSystemId { get; set; }
}

View File

@ -0,0 +1,28 @@
namespace SJZY.Track.Domain.OrderAggregate;
/// <summary>
/// 轨迹订单关联表(1:N)
/// </summary>
[SugarTable("t_order_link")]
public class OrderLinkEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 关联的订单id
/// </summary>
[SugarColumn(ColumnName = "LinkOrderId")]
public int LinkOrderId { get; set; }
/// <summary>
/// 订单id
/// </summary>
[SugarColumn(ColumnName = "OrderId")]
public int OrderId { get; set; }
}

View File

@ -0,0 +1,34 @@
namespace SJZY.Track.Domain.OrderAggregate;
/// <summary>
/// 轨迹订单模板表(1:N)
/// </summary>
[SugarTable("t_order_template")]
public class OrderTemplateEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 订单id
/// </summary>
[SugarColumn(ColumnName = "OrderId")]
public int OrderId { get; set; }
/// <summary>
/// 服务商id
/// </summary>
[SugarColumn(ColumnName = "ServiceProviderId")]
public int ServiceProviderId { get; set; }
/// <summary>
/// 模板id
/// </summary>
[SugarColumn(ColumnName = "TrackTemplateId")]
public int TrackTemplateId { get; set; }
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../common.props" />
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SJZY.Expand.ABP.Core" Version="7.7.1" />
<PackageReference Include="SJZY.Expand.ElasticSearch" Version="7.0.17" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,7 @@
using Volo.Abp.Modularity;
namespace SJZY.Track.Domain;
public class SJZYTrackDomainModule:AbpModule
{
}

View File

@ -0,0 +1,9 @@
namespace SJZY.Track.Repository.TrackDetails.Dtos;
public class TrackDetailsQueryInput : PageInfoInput
{
/// <summary>
/// 单号
/// </summary>
public List<string> OrderNos { get; set; } = new();
}

View File

@ -0,0 +1,13 @@
using SJZY.Track.Domain.TrackDetailsAggregate;
using SJZY.Track.Repository.TrackDetails.Dtos;
namespace SJZY.Track.Repository.TrackDetails;
public interface ITrackDetailsRepository
{
Task WriteTrack(TrackDetailsIndex index);
Task<List<TrackDetailsIndex>> GetListAsync(List<string> orderNos);
Task<(List<TrackDetailsIndex> list, long total)> GetListAsync(TrackDetailsQueryInput input);
}

View File

@ -0,0 +1,90 @@
using Nest;
using SJZY.Expand.ElasticSearch;
namespace SJZY.Track.Domain.TrackDetailsAggregate;
[ElasticsearchType(Name = IndexName)]
public class TrackDetailsIndex : IdBaseIndex
{
public const string IndexName = "sjzy_track_details";
/// <summary>
/// 订单Id
/// </summary>
public int OrderId { get; set; }
/// <summary>
/// 订单号
/// </summary>
public string OrderNo { get; set; }
/// <summary>
/// 订单类型(主数据枚举TrackOrderType)
/// </summary>
public string OrderType { get; set; }
/// <summary>
/// 轨迹状态
/// </summary>
public string TrackStatus { get; set; }
/// <summary>
/// 原轨迹状态
/// </summary>
public string OriginTrackStatus { get; set; }
/// <summary>
/// 轨迹内容代码
/// </summary>
public string TrackCode { get; set; }
/// <summary>
/// 轨迹内容
/// </summary>
public string TrackContent { get; set; }
/// <summary>
/// 原轨迹内容
/// </summary>
public string OriginTrackContent { get; set; }
/// <summary>
/// 原轨迹报文
/// </summary>
public string OriginTrackData { get; set; }
/// <summary>
/// 轨迹内容英文
/// </summary>
public string TrackEnContent { get; set; }
/// <summary>
/// 轨迹发生地
/// </summary>
public string TrackPlace { get; set; }
/// <summary>
/// 轨迹发生时间
/// </summary>
public DateTime TrackTime { get; set; }
/// <summary>
/// 轨迹发生时区
/// </summary>
public float TraceTimeZone { get; set; }
/// <summary>删除标记 0正常 1 已删除</summary>
public bool IsDeleted { get; set; }
/// <summary>创建人id</summary>
public int CreateUserId { get; set; }
/// <summary>创建时间</summary>
public DateTime CreateTime { get; set; }
/// <summary>修改人id</summary>
public int? UpdateUserId { get; set; }
/// <summary>修改时间</summary>
public DateTime? UpdateTime { get; set; }
}

View File

@ -0,0 +1,6 @@
namespace SJZY.Track.Domain.TrackTemplateAggregate.Dtos;
public class TemplateContentDto
{
}

View File

@ -0,0 +1,8 @@
using SJZY.Track.Domain.TrackTemplateAggregate.Dtos;
namespace SJZY.Track.Domain.TrackTemplateAggregate;
public interface ITrackTemplateRepository : IBasicRepository<TrackTemplateEntity>
{
Task<TemplateContentDto> GetTemplateContentsAsync(List<int> distinctTemplateIds);
}

View File

@ -0,0 +1,46 @@
namespace SJZY.Track.Domain.TrackTemplateAggregate;
/// <summary>
/// 轨迹模板内容表(1:N)
/// </summary>
[SugarTable("t_track_template_content")]
public class TrackTemplateContentEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 是否可删
/// </summary>
[SugarColumn(ColumnName = "IsCanDelete")]
public bool IsCanDelete { get; set; }
/// <summary>
/// 是否对外
/// </summary>
[SugarColumn(ColumnName = "IsExternal")]
public bool IsExternal { get; set; }
/// <summary>
/// 排序
/// </summary>
[SugarColumn(ColumnName = "Sort")]
public int Sort { get; set; }
/// <summary>
/// 轨迹内容id
/// </summary>
[SugarColumn(ColumnName = "TrackContentId")]
public int TrackContentId { get; set; }
/// <summary>
/// 模板id
/// </summary>
[SugarColumn(ColumnName = "TrackTemplateId")]
public int TrackTemplateId { get; set; }
}

View File

@ -0,0 +1,34 @@
namespace SJZY.Track.Domain.TrackTemplateAggregate;
/// <summary>
/// 轨迹模板表
/// </summary>
[SugarTable("t_track_template")]
public class TrackTemplateEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 模板代码
/// </summary>
[SugarColumn(ColumnName = "Code")]
public string Code { get; set; }
/// <summary>
/// 模板名称
/// </summary>
[SugarColumn(ColumnName = "Name")]
public string Name { get; set; }
/// <summary>
/// 子系统id
/// </summary>
[SugarColumn(ColumnName = "SubSystemId")]
public int SubSystemId { get; set; }
}

View File

@ -1,15 +1,72 @@
#pragma warning disable 1591 using System.Linq.Expressions;
namespace SJZY.Track.Repository using SJZY.Track.Domain;
using Volo.Abp;
namespace SJZY.Track.Repository;
/// <summary>
/// 仓储基类实现
/// </summary>
/// <typeparam name="T"></typeparam>
public class BasicRepository<T> : SimpleClient<T>,IBasicRepository<T> where T : class, new()
{ {
/// <summary> public BasicRepository()
/// 仓储基类
/// </summary>
/// <typeparam name="T"></typeparam>
public class BasicRepository<T> : SimpleClient<T> where T : class, new()
{ {
public BasicRepository() Context = SqlsugarScopeBasic.GetContextSafely("default");
{ }
Context = SqlsugarScopeBasic.GetContextSafely("default");
} public async Task<TResult> GetFirstAsync<TResult>(Expression<Func<T, bool>> whereExpression,
Expression<Func<T, TResult>> resultExpression)
{
return await Context.Queryable<T>().Where(whereExpression).Select(resultExpression).FirstAsync();
}
public async Task<List<TResult>> GetListAsync<TResult>(Expression<Func<T, bool>> whereExpression,
Expression<Func<T, TResult>> resultExpression)
{
return await Context.Queryable<T>().Where(whereExpression).Select(resultExpression).ToListAsync();
}
public async Task<bool> UpdateAsync(T entity, Expression<Func<T, object>> ignoreColumns)
{
return await Context.Updateable(entity)
.IgnoreColumnsIF(ignoreColumns != null, ignoreColumns)
.ExecuteCommandHasChangeAsync();
}
public async Task<bool> UpdateColumnAsync(T entity, Expression<Func<T, object>> updateColumns)
{
return await Context.Updateable(entity)
.UpdateColumnsIF(updateColumns != null, updateColumns)
.ExecuteCommandHasChangeAsync();
}
public async Task<bool> UpdateAsync(T entity, bool ignoreAllNullColumns = false, bool ignoreAllDefaultValue = false)
{
return await Context.Updateable(entity)
.IgnoreColumns(ignoreAllNullColumns: ignoreAllNullColumns, ignoreAllDefaultValue: ignoreAllDefaultValue)
.ExecuteCommandHasChangeAsync();
}
public async Task<bool> UpdateRangeAsync(List<T> entities, Expression<Func<T, object>> columns = null)
{
return await Context.Updateable(entities)
.UpdateColumnsIF(columns != null, columns)
.ExecuteCommandHasChangeAsync();
}
public async Task<bool> SoftDeleteAsync(Expression<Func<T, bool>> where)
{
if (!typeof(T).IsAssignableTo<ISoftDeleteBasicEntity>())
throw new BusinessException(
message: $"实体没有实现{nameof(ISoftDeleteBasicEntity)}不能调用{nameof(SoftDeleteAsync)}");
// tips: required where
if (where == default) return false;
return await Context.Updateable<T>()
.Where(where)
.SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), 1)
.ExecuteCommandHasChangeAsync();
} }
} }

View File

@ -1,24 +0,0 @@
namespace SJZY.Track.Repository.Demo.Entitys
{
[SugarTable("t_demo_detail")]
public class DemoDetailEntity
{
/// <summary>
/// Id
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true)]
public long Id { get; set; }
/// <summary>
/// t_demo.id
/// </summary>
[SugarColumn(ColumnName = "DemoId")]
public long DemoId { get; set; }
/// <summary>
/// 一些说明..
/// </summary>
[SugarColumn(ColumnName = "OtherInfo")]
public string OtherInfo { get; set; }
}
}

View File

@ -1,40 +0,0 @@
namespace SJZY.Track.Repository.Demo.Entitys
{
/// <summary>
/// 测试表
/// </summary>
[SugarTable("t_demo")]
public class DemoEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// Id
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public long Id { get; set; }
/// <summary>
/// 姓名
/// </summary>
[SugarColumn(ColumnName = "Name")]
public string Name { get; set; }
/// <summary>
/// 年龄
/// </summary>
[SugarColumn(ColumnName = "Age")]
public int Age { get; set; }
/// <summary>
/// 描述
/// </summary>
[SugarColumn(ColumnName = "Description")]
public string Description { get; set; }
[Navigate(NavigateType.OneToMany, nameof(DemoDetailEntity.DemoId))]
public List<DemoDetailEntity> DemoDetailList { get; set; }
}
}

View File

@ -1,8 +1,8 @@
using SJZY.Track.Repository.Demo.Entitys; using System.Transactions;
using SJZY.Track.Repository.Demo.ValueObjects; using SJZY.Track.Domain.DemoAggregate;
using System.Transactions; using SJZY.Track.Domain.DemoAggregate.Dtos;
namespace SJZY.Track.Repository.Demo.Services namespace SJZY.Track.Repository
{ {
public class DemoRepository : BasicRepository<DemoEntity>, IDemoRepository, IScopedDependency public class DemoRepository : BasicRepository<DemoEntity>, IDemoRepository, IScopedDependency
{ {

View File

@ -1,71 +0,0 @@
namespace SJZY.Track.Repository.Order.Entitys
{
/// <summary>
/// 轨迹订单主表
/// </summary>
[SugarTable("t_order")]
public class OrderEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 客户id(外部主体id)
/// </summary>
[SugarColumn(ColumnName = "CustomId")]
public int CustomId { get; set; }
/// <summary>
/// 订单是否完结(异步维护)
/// </summary>
[SugarColumn(ColumnName = "IsCompleted")]
public bool IsCompleted { get; set; }
/// <summary>
/// 最新轨迹内容(异步维护)
/// </summary>
[SugarColumn(ColumnName = "LatestTraceContent")]
public string LatestTraceContent { get; set; }
/// <summary>
/// 最新轨迹内容英文(异步维护)
/// </summary>
[SugarColumn(ColumnName = "LatestTraceEnContent")]
public string LatestTraceEnContent { get; set; }
/// <summary>
/// 最新轨迹时间(异步维护)
/// </summary>
[SugarColumn(ColumnName = "LatestTraceTime")]
public DateTime? LatestTraceTime { get; set; }
/// <summary>
/// 订单明细(json字符串)
/// </summary>
[SugarColumn(ColumnName = "OrderDetails")]
public string OrderDetails { get; set; }
/// <summary>
/// 订单号
/// </summary>
[SugarColumn(ColumnName = "OrderNo")]
public string OrderNo { get; set; }
/// <summary>
/// 订单类型(主数据枚举TrackOrderType)
/// </summary>
[SugarColumn(ColumnName = "OrderType")]
public int OrderType { get; set; }
/// <summary>
/// 子系统id
/// </summary>
[SugarColumn(ColumnName = "SubSystemId")]
public int SubSystemId { get; set; }
}
}

View File

@ -1,9 +0,0 @@
using SJZY.Track.Repository.Order.Entitys;
namespace SJZY.Track.Repository.Order.Services
{
public interface IOrderRepository : ISimpleClient<OrderEntity>
{
}
}

View File

@ -1,9 +0,0 @@
using SJZY.Track.Repository.Order.Entitys;
namespace SJZY.Track.Repository.Order.Services
{
public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, IScopedDependency
{
}
}

View File

@ -1,29 +0,0 @@
namespace SJZY.Track.Repository.OrderLink.Entitys
{
/// <summary>
/// 轨迹订单关联表(1:N)
/// </summary>
[SugarTable("t_order_link")]
public class OrderLinkEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 关联的订单id
/// </summary>
[SugarColumn(ColumnName = "LinkOrderId")]
public int LinkOrderId { get; set; }
/// <summary>
/// 订单id
/// </summary>
[SugarColumn(ColumnName = "OrderId")]
public int OrderId { get; set; }
}
}

View File

@ -1,9 +0,0 @@
using SJZY.Track.Repository.OrderLink.Entitys;
namespace SJZY.Track.Repository.OrderLink.Services
{
public interface IOrderLinkRepository : ISimpleClient<OrderLinkEntity>
{
}
}

View File

@ -1,9 +0,0 @@
using SJZY.Track.Repository.OrderLink.Entitys;
namespace SJZY.Track.Repository.OrderLink.Services
{
public class OrderLinkRepository : BasicRepository<OrderLinkEntity>, IOrderLinkRepository, IScopedDependency
{
}
}

View File

@ -0,0 +1,16 @@
using SJZY.Track.Domain.OrderAggregate;
using SJZY.Track.Domain.OrderAggregate.Dtos;
namespace SJZY.Track.Repository;
public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, ITransientDependency
{
public async Task<List<OrderTemplateDto>> GetOrderTemplatesAsync(List<string> distinctOrderNumbers)
{
return await AsQueryable()
.LeftJoin<OrderTemplateEntity>((a, b) => a.Id == b.OrderId)
.Where(a => distinctOrderNumbers.Contains(a.OrderNo))
.Select<OrderTemplateDto>()
.ToListAsync();
}
}

View File

@ -1,35 +0,0 @@
namespace SJZY.Track.Repository.OrderTemplate.Entitys
{
/// <summary>
/// 轨迹订单模板表(1:N)
/// </summary>
[SugarTable("t_order_template")]
public class OrderTemplateEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 订单id
/// </summary>
[SugarColumn(ColumnName = "OrderId")]
public int OrderId { get; set; }
/// <summary>
/// 服务商id
/// </summary>
[SugarColumn(ColumnName = "ServiceProviderId")]
public int ServiceProviderId { get; set; }
/// <summary>
/// 模板id
/// </summary>
[SugarColumn(ColumnName = "TrackTemplateId")]
public int TrackTemplateId { get; set; }
}
}

View File

@ -1,9 +0,0 @@
using SJZY.Track.Repository.OrderTemplate.Entitys;
namespace SJZY.Track.Repository.OrderTemplate.Services
{
public interface IOrderTemplateRepository : ISimpleClient<OrderTemplateEntity>
{
}
}

View File

@ -1,9 +0,0 @@
using SJZY.Track.Repository.OrderTemplate.Entitys;
namespace SJZY.Track.Repository.OrderTemplate.Services
{
public class OrderTemplateRepository : BasicRepository<OrderTemplateEntity>, IOrderTemplateRepository, IScopedDependency
{
}
}

View File

@ -1,33 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
using SJZY.Expand.ABP.Core.SqlSugar.Options;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
namespace SJZY.Track.Repository
{
/// <summary>
/// 仓储模块
/// </summary>
[DependsOn(typeof(AbpAutofacModule))]
public class RepositoryModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
context.Services.AddSqlsugar(options =>
{
options.AddRange(new List<SqlsugarOptions> {
new SqlsugarOptions()
{
ConnectionString = configuration["ConnectionStrings:DefaultConnection"],
DbType = DbType.MySql,
IsAutoCloseConnection = true,
ConfigId = "default"
}
}
);
}, DataBaseContext.OnExcutingAction, "SJZY.Track.Repository");
}
}
}

View File

@ -11,20 +11,19 @@
<Compile Remove="DataCenter\**" /> <Compile Remove="DataCenter\**" />
<EmbeddedResource Remove="DataCenter\**" /> <EmbeddedResource Remove="DataCenter\**" />
<None Remove="DataCenter\**" /> <None Remove="DataCenter\**" />
<Compile Remove="TrackTemplate\ValueObjects\**" />
<EmbeddedResource Remove="TrackTemplate\ValueObjects\**" />
<None Remove="TrackTemplate\ValueObjects\**" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="SJZY.Expand.ABP.Core" Version="7.7.1" />
<PackageReference Include="SJZY.LoggerCenter.HttpApi" Version="7.0.5" /> <PackageReference Include="SJZY.LoggerCenter.HttpApi" Version="7.0.5" />
<PackageReference Include="Volo.Abp.Autofac" Version="7.0.2" /> <PackageReference Include="Volo.Abp.Autofac" Version="7.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="OrderLink\ValueObjects\" />
<Folder Include="OrderTemplate\ValueObjects\" />
<Folder Include="Order\ValueObjects\" />
<Folder Include="TrackContentMap\ValueObjects\" /> <Folder Include="TrackContentMap\ValueObjects\" />
<Folder Include="TrackContent\ValueObjects\" /> <Folder Include="TrackContent\ValueObjects\" />
<Folder Include="TrackFlag\ValueObjects\" /> <Folder Include="TrackFlag\ValueObjects\" />
@ -36,8 +35,11 @@
<Folder Include="TrackPushRecordDetails\ValueObjects\" /> <Folder Include="TrackPushRecordDetails\ValueObjects\" />
<Folder Include="TrackPushRecord\ValueObjects\" /> <Folder Include="TrackPushRecord\ValueObjects\" />
<Folder Include="TrackStatus\ValueObjects\" /> <Folder Include="TrackStatus\ValueObjects\" />
<Folder Include="TrackTemplateContent\ValueObjects\" /> </ItemGroup>
<Folder Include="TrackTemplate\ValueObjects\" />
<ItemGroup>
<ProjectReference Include="..\SJZY.Track.Domain\SJZY.Track.Domain.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,48 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SJZY.Expand.ABP.Core.SqlSugar.Options;
using SJZY.Expand.ElasticSearch;
using SJZY.Track.Domain;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
namespace SJZY.Track.Repository;
/// <summary>
/// 仓储模块
/// </summary>
[DependsOn(typeof(AbpAutofacModule))]
[DependsOn(typeof(SJZYTrackDomainModule))]
public class SJZYTrackRepositoryModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
context.Services.AddSqlsugar(options =>
{
options.AddRange(new List<SqlsugarOptions> {
new()
{
ConnectionString = configuration["ConnectionStrings:DefaultConnection"],
DbType = DbType.MySql,
IsAutoCloseConnection = true,
ConfigId = "default"
}
}
);
}, DataBaseContext.OnExcutingAction, "SJZY.Track.Repository");
context.Services.AddScoped(typeof(IBasicRepository<>), typeof(BasicRepository<>));
context.Services.AddElasticSearch(options =>
{
options.NodeUrls = configuration.GetSection("ElasticSearch:NodeUrls").Get<List<string>>();
options.LoginName = configuration["ElasticSearch:LoginName"];
options.Password = configuration["ElasticSearch:Password"];
options.Base64PassPassword = configuration["ElasticSearch:Base64PassPassword"];
});
}
}

View File

@ -0,0 +1,73 @@
using Nest;
using SJZY.Track.Domain.TrackDetailsAggregate;
using SJZY.Expand.ABP.Core.Logger;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Expand.ElasticSearch.Services;
using SJZY.Track.Repository.TrackDetails;
using SJZY.Track.Repository.TrackDetails.Dtos;
namespace SJZY.Track.Repository;
internal class TrackDetailsRepository : ElasticSearchContextAbstract<TrackDetailsIndex>, ITrackDetailsRepository,
ITransientDependency
{
public TrackDetailsRepository(ConnectionFactory connectionFactory) : base(connectionFactory)
{
}
public async Task WriteTrack(TrackDetailsIndex index)
{
try
{
//await Context.IndexDocumentAsync(idx);
var response = await Context.IndexAsync(index,
request => request.Index($"{TrackDetailsIndex.IndexName}-{DateTime.Now:yyyy.MM.dd}"));
if (!response.IsValid) LogHelper.Error("数据添加失败,原因:" + response.DebugInformation);
}
catch (Exception ex)
{
LogHelper.Error($"日志插入ES失败:{ex.Message}。{index.ToJson()}");
}
}
public async Task<List<TrackDetailsIndex>> GetListAsync(List<string> orderNos)
{
if (orderNos.Count < 1) return new List<TrackDetailsIndex>();
var data = await Context.SearchAsync<TrackDetailsIndex>(x => x
.Source(s => s.Includes(fd => fd
.Field(f => f.TrackStatus)
.Field(f => f.TrackCode)
.Field(f => f.TrackContent)
.Field(f => f.TrackPlace)
.Field(f => f.TrackTime)
.Field(f => f.TraceTimeZone)
))
.Query(q => q.Terms(t => t
.Field(f => f.OrderNo)
.Terms(orderNos)))
);
return data.Documents.ToList();
}
public async Task<(List<TrackDetailsIndex> list, long total)> GetListAsync(TrackDetailsQueryInput input)
{
if (input.OrderNos.Count < 1) return default;
var distinctOrderNumbers = input.OrderNos.Distinct();
var finalSize = input.PageSize > 500 ? 500 : input.PageSize;
var data = await Context.SearchAsync<TrackDetailsIndex>(x => x
.Query(q => q.Terms(t => t
.Field(f => f.OrderNo)
.Terms(distinctOrderNumbers)))
.Sort(s => s.Field(f => f.CreateTime, SortOrder.Descending))
.From((input.PageIndex - 1) * input.PageSize)
.Size(finalSize)
.TrackTotalHits() // todo: 聚合获取匹配查询条件的文档总数,而不受"index.max_result_window"的限制
);
return (data.Documents.ToList(), data.Total);
}
}

View File

@ -1,35 +0,0 @@
namespace SJZY.Track.Repository.TrackTemplate.Entitys
{
/// <summary>
/// 轨迹模板表
/// </summary>
[SugarTable("t_track_template")]
public class TrackTemplateEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 模板代码
/// </summary>
[SugarColumn(ColumnName = "Code")]
public string Code { get; set; }
/// <summary>
/// 模板名称
/// </summary>
[SugarColumn(ColumnName = "Name")]
public string Name { get; set; }
/// <summary>
/// 子系统id
/// </summary>
[SugarColumn(ColumnName = "SubSystemId")]
public int SubSystemId { get; set; }
}
}

View File

@ -1,9 +0,0 @@
using SJZY.Track.Repository.TrackTemplate.Entitys;
namespace SJZY.Track.Repository.TrackTemplate.Services
{
public interface ITrackTemplateRepository : ISimpleClient<TrackTemplateEntity>
{
}
}

View File

@ -1,9 +0,0 @@
using SJZY.Track.Repository.TrackTemplate.Entitys;
namespace SJZY.Track.Repository.TrackTemplate.Services
{
public class TrackTemplateRepository : BasicRepository<TrackTemplateEntity>, ITrackTemplateRepository, IScopedDependency
{
}
}

View File

@ -1,47 +0,0 @@
namespace SJZY.Track.Repository.TrackTemplateContent.Entitys
{
/// <summary>
/// 轨迹模板内容表(1:N)
/// </summary>
[SugarTable("t_track_template_content")]
public class TrackTemplateContentEntity : IFullAuditedBasicEntitys
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 是否可删
/// </summary>
[SugarColumn(ColumnName = "IsCanDelete")]
public bool IsCanDelete { get; set; }
/// <summary>
/// 是否对外
/// </summary>
[SugarColumn(ColumnName = "IsExternal")]
public bool IsExternal { get; set; }
/// <summary>
/// 排序
/// </summary>
[SugarColumn(ColumnName = "Sort")]
public int Sort { get; set; }
/// <summary>
/// 轨迹内容id
/// </summary>
[SugarColumn(ColumnName = "TrackContentId")]
public int TrackContentId { get; set; }
/// <summary>
/// 模板id
/// </summary>
[SugarColumn(ColumnName = "TrackTemplateId")]
public int TrackTemplateId { get; set; }
}
}

View File

@ -1,9 +0,0 @@
using SJZY.Track.Repository.TrackTemplateContent.Entitys;
namespace SJZY.Track.Repository.TrackTemplateContent.Services
{
public interface ITrackTemplateContentRepository : ISimpleClient<TrackTemplateContentEntity>
{
}
}

View File

@ -1,9 +0,0 @@
using SJZY.Track.Repository.TrackTemplateContent.Entitys;
namespace SJZY.Track.Repository.TrackTemplateContent.Services
{
public class TrackTemplateContentRepository : BasicRepository<TrackTemplateContentEntity>, ITrackTemplateContentRepository, IScopedDependency
{
}
}

View File

@ -0,0 +1,13 @@
using SJZY.Track.Domain.TrackTemplateAggregate;
using SJZY.Track.Domain.TrackTemplateAggregate.Dtos;
namespace SJZY.Track.Repository.TrackTemplate
{
public class TrackTemplateRepository : BasicRepository<TrackTemplateEntity>, ITrackTemplateRepository, IScopedDependency
{
public Task<TemplateContentDto> GetTemplateContentsAsync(List<int> distinctTemplateIds)
{
throw new NotImplementedException();
}
}
}

View File

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SJZY.Track.Test;
namespace SJZY.OpenApi.Test namespace SJZY.OpenApi.Test
{ {

View File

@ -13,55 +13,53 @@ using Volo.Abp.Modularity;
using Volo.Abp.Threading; using Volo.Abp.Threading;
[assembly: HostingStartup(typeof(SJZY.Expand.ABP.Core.HostingStartup))] [assembly: HostingStartup(typeof(SJZY.Expand.ABP.Core.HostingStartup))]
namespace SJZY.OpenApi.Test namespace SJZY.Track.Test;
[DependsOn(
typeof(AbpAspNetCoreTestBaseModule),
typeof(AbpAutofacModule),
typeof(AbpAuthorizationModule),
typeof(SJZYTrackRepositoryModule),
typeof(ApplicationModule),
typeof(SJZYTrackApiModule),
typeof(AbpHttpClientModule) //添加abp的http代理模块
)]
[assembly: HostingStartup(typeof(Expand.ABP.Core.HostingStartup))]
public class TestModule : AbpModule
{ {
[DependsOn(
typeof(AbpAspNetCoreTestBaseModule),
typeof(AbpAutofacModule),
typeof(AbpAuthorizationModule),
typeof(RepositoryModule),
typeof(ApplicationModule),
typeof(ApiModule),
typeof(AbpHttpClientModule) //添加abp的http代理模块
)]
[assembly: HostingStartup(typeof(Expand.ABP.Core.HostingStartup))] public override void ConfigureServices(ServiceConfigurationContext context)
public class TestModule : AbpModule
{ {
context.Services.AddAlwaysAllowAuthorization();
public override void ConfigureServices(ServiceConfigurationContext context) //添加内网服务
{ //context.Services.AddHttpClientProxies(typeof(LoggerCenterHttpApiModule).Assembly, "LoggerCenter", false);
context.Services.AddAlwaysAllowAuthorization();
//添加内网服务
//context.Services.AddHttpClientProxies(typeof(LoggerCenterHttpApiModule).Assembly, "LoggerCenter", false);
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedTestData(context);
}
public override void OnApplicationShutdown(ApplicationShutdownContext context)
{
//根据业务场景决定,是否需要删除测试数据
}
/// <summary>
/// 生成种子测试数据
/// </summary>
/// <param name="context"></param>
private static void SeedTestData(ApplicationInitializationContext context)
{
AsyncHelper.RunSync(async () =>
{
using (var scope = context.ServiceProvider.CreateScope())
{
await scope.ServiceProvider
.GetRequiredService<IDataSeeder>()
.SeedAsync();
}
});
}
} }
} public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedTestData(context);
}
public override void OnApplicationShutdown(ApplicationShutdownContext context)
{
//根据业务场景决定,是否需要删除测试数据
}
/// <summary>
/// 生成种子测试数据
/// </summary>
/// <param name="context"></param>
private static void SeedTestData(ApplicationInitializationContext context)
{
AsyncHelper.RunSync(async () =>
{
using (var scope = context.ServiceProvider.CreateScope())
{
await scope.ServiceProvider
.GetRequiredService<IDataSeeder>()
.SeedAsync();
}
});
}
}