using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Furion.DistributedIDGenerator;
using Furion.FriendlyException;
using Microsoft.EntityFrameworkCore;
using pingan.openbank.api.sdk.enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ApiTools.Core
{
///
/// 企业钱包仓库
///
public class ChannelWalletRepository : BaseRepository, IScoped
{
public ChannelWalletRepository(IRepository rep) : base(rep)
{
}
public override IQueryable GetQueryable(bool noTracking = true)
{
var q = rep.GetQueryable(noTracking);
if (logier != null)
{
switch (logier.Type)
{
case EnumUserType.Channel:
q = q.Where(it => it.ChannelId == logier.ChannelId);
break;
case EnumUserType.Operation:
break;
default:
break;
}
}
return q;
}
public Task CheckExist(string code, Guid? id)
{
return GetQueryableIgnoreFilter()
.AnyAsync(it => it.Code == code && it.Id != id);
}
///
/// 设置编号
///
///
///
public async Task SetCode(ChannelWallet 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);
}
}
}
}