using Furion.DatabaseAccessor;
|
using Furion.DependencyInjection;
|
using Furion.DistributedIDGenerator;
|
using Microsoft.EntityFrameworkCore;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace ApiTools.Core
|
{
|
public class ChannelWalletTransactionRepository : BaseRepository<ChannelWalletTransaction, MasterDbContextLocator>, IScoped
|
{
|
public ChannelWalletTransactionRepository(IRepository<ChannelWalletTransaction, MasterDbContextLocator> rep) : base(rep)
|
{
|
}
|
|
public Task<bool> CheckExist(string code, Guid? id)
|
{
|
return GetQueryableIgnoreFilter()
|
.AnyAsync(it => it.Code == code && it.Id != id);
|
}
|
|
/// <summary>
|
/// 设置编号
|
/// </summary>
|
/// <param name="entity"></param>
|
/// <returns></returns>
|
public async Task SetCode(ChannelWalletTransaction entity)
|
{
|
entity.Code = $"{DateTime.Now:yyyyMMddHHmmss}{new Random(IDGen.NextID().GetHashCode()).Next(1000, 9999)}";
|
var exist = await CheckExist(entity.Code, entity.Id);
|
if (exist)
|
{
|
await SetCode(entity);
|
}
|
}
|
|
}
|
}
|