mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-21 07:17:15 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
83
src/bnhtrade.Core/Logic/Account/GetAccountCodeInfo.cs
Normal file
83
src/bnhtrade.Core/Logic/Account/GetAccountCodeInfo.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Account
|
||||
{
|
||||
public class GetAccountCodeInfo
|
||||
{
|
||||
private string sqlConnectionString;
|
||||
private Data.Database.Account.ReadAccountCode readAccountCode;
|
||||
private Dictionary<int, Model.Account.AccountCode> cache;
|
||||
|
||||
public GetAccountCodeInfo(string sqlConnectionString)
|
||||
{
|
||||
this.sqlConnectionString = sqlConnectionString;
|
||||
readAccountCode = new Data.Database.Account.ReadAccountCode(sqlConnectionString);
|
||||
cache = new Dictionary<int, Model.Account.AccountCode>();
|
||||
}
|
||||
|
||||
public void CacheClear()
|
||||
{
|
||||
cache.Clear();
|
||||
}
|
||||
|
||||
public void CacheFill()
|
||||
{
|
||||
CacheClear();
|
||||
|
||||
var resultList = readAccountCode.All();
|
||||
foreach (var result in resultList)
|
||||
{
|
||||
cache.Add(result.AccountCodeId, result);
|
||||
}
|
||||
}
|
||||
|
||||
public void CacheFill(List<int> accountCodeList, bool forceDbRead = false)
|
||||
{
|
||||
if (accountCodeList == null || !accountCodeList.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var accountCodeQueryList = new List<int>();
|
||||
foreach (var code in accountCodeList.Distinct().ToList())
|
||||
{
|
||||
if (forceDbRead)
|
||||
{
|
||||
cache.Remove(code);
|
||||
accountCodeQueryList.Add(code);
|
||||
}
|
||||
else if (!cache.ContainsKey(code))
|
||||
{
|
||||
accountCodeQueryList.Add(code);
|
||||
}
|
||||
}
|
||||
|
||||
// get db list
|
||||
var dbList = readAccountCode.ByAccountCode(accountCodeQueryList);
|
||||
|
||||
// add to cache
|
||||
foreach (var item in dbList)
|
||||
{
|
||||
cache.Add(item.AccountCodeId, item);
|
||||
}
|
||||
}
|
||||
|
||||
public Model.Account.AccountCode ByAccountCode(int accountCode, bool forceDbRead = false)
|
||||
{
|
||||
CacheFill(new List<int> { accountCode }, forceDbRead);
|
||||
|
||||
if (cache.ContainsKey(accountCode))
|
||||
{
|
||||
return cache[accountCode];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user