sunpengfei
2025-11-20 a47038826eb7d1c152a50e95b3c9be177a130e8d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
{
    /// <summary>
    /// 企业钱包仓库
    /// </summary>
    public class ChannelWalletRepository : BaseRepository<ChannelWallet, MasterDbContextLocator>, IScoped
    {
        public ChannelWalletRepository(IRepository<ChannelWallet, MasterDbContextLocator> rep) : base(rep)
        {
        }
 
        public override IQueryable<ChannelWallet> 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<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(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);
            }
        }
 
    }
}