新增抄读记录表自定义仓储
This commit is contained in:
parent
83d8785ff4
commit
e836522e3a
@ -3,7 +3,10 @@ using JiShe.CollectBus.IotSystems.MessageIssueds;
|
||||
using JiShe.CollectBus.IotSystems.MessageReceiveds;
|
||||
using JiShe.CollectBus.IotSystems.MeterReadingRecords;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.MongoDB;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
@ -24,13 +27,34 @@ public class CollectBusMongoDbContext : AbpMongoDbContext, ICollectBusMongoDbCon
|
||||
public IMongoCollection<Device> Devices => Collection<Device>();
|
||||
public IMongoCollection<ProtocolInfo> ProtocolInfos => Collection<ProtocolInfo>();
|
||||
|
||||
public IMongoCollection<MeterReadingRecords> MeterReadingRecords => Collection<MeterReadingRecords>();
|
||||
/// <summary>
|
||||
/// 抄表记录,默认按天分表
|
||||
/// </summary>
|
||||
public IMongoCollection<MeterReadingRecords> MeterReadingRecordInfo => Database.GetCollection<MeterReadingRecords>(DateTime.Now.GetCollectionName<MeterReadingRecords>());
|
||||
|
||||
|
||||
protected override void CreateModel(IMongoModelBuilder modelBuilder)
|
||||
{
|
||||
base.CreateModel(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<MeterReadingRecords>(builder =>
|
||||
{
|
||||
// 创建索引
|
||||
builder.ConfigureIndexes(index =>
|
||||
{
|
||||
List<CreateIndexModel<BsonDocument>> createIndexModels = new List<CreateIndexModel<BsonDocument>>();
|
||||
createIndexModels.Add(new CreateIndexModel<BsonDocument>(
|
||||
Builders<BsonDocument>.IndexKeys.Ascending(nameof(MeterReadingRecords)),
|
||||
new CreateIndexOptions
|
||||
{
|
||||
Unique = true
|
||||
}
|
||||
));
|
||||
index.CreateMany(createIndexModels);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
modelBuilder.ConfigureCollectBus();
|
||||
}
|
||||
}
|
||||
|
||||
25
src/JiShe.CollectBus.MongoDB/MongoDB/CollectionHelper.cs
Normal file
25
src/JiShe.CollectBus.MongoDB/MongoDB/CollectionHelper.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.CollectBus.MongoDB
|
||||
{
|
||||
/// <summary>
|
||||
/// MongoDB集合帮助类
|
||||
/// </summary>
|
||||
public static class CollectionHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取集合名称
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="time"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetCollectionName<T>(this DateTime time)
|
||||
{
|
||||
return $"{typeof(T).Name}{time:yyyyMMddHHmm}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
using JiShe.CollectBus.IotSystems.MeterReadingRecords;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
|
||||
namespace JiShe.CollectBus.Repository.MeterReadingRecord
|
||||
{
|
||||
/// <summary>
|
||||
/// 抄读仓储接口
|
||||
/// </summary>
|
||||
public interface IMeterReadingRecordRepository: IRepository<MeterReadingRecords, Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// 批量插入
|
||||
/// </summary>
|
||||
/// <param name="entities"></param>
|
||||
/// <param name="dayTime"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task InsertManyAsync(List<MeterReadingRecords> entities, DateTime dayTime, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// 单个插入
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="dayTime"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task InsertOneAsync(MeterReadingRecords entity, DateTime dayTime, CancellationToken cancellationToken = default(CancellationToken));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
using JiShe.CollectBus.IotSystems.MeterReadingRecords;
|
||||
using JiShe.CollectBus.MongoDB;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Domain.Repositories.MongoDB;
|
||||
using Volo.Abp.MongoDB;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace JiShe.CollectBus.Repository.MeterReadingRecord
|
||||
{
|
||||
/// <summary>
|
||||
/// 抄读记录仓储
|
||||
/// </summary>
|
||||
public class MeterReadingRecordRepository : MongoDbRepository<CollectBusMongoDbContext, MeterReadingRecords, Guid>, IMeterReadingRecordRepository
|
||||
{
|
||||
public MeterReadingRecordRepository(IMongoDbContextProvider<CollectBusMongoDbContext> dbContextProvider)
|
||||
: base(dbContextProvider)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量插入
|
||||
/// </summary>
|
||||
/// <param name="entities"></param>
|
||||
/// <param name="dayTime"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task InsertManyAsync(List<MeterReadingRecords> entities, DateTime dayTime, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var collection = await GetCollectionAsync(cancellationToken);
|
||||
await collection.InsertManyAsync(entities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单条插入
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="dayTime"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task InsertOneAsync(MeterReadingRecords entity,DateTime dayTime, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var collection = await GetCollectionAsync(cancellationToken);
|
||||
await collection.InsertOneAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user