添加项目文件。
This commit is contained in:
197
src/BarCode.Web.Repositories/BasicsRepositories.cs
Normal file
197
src/BarCode.Web.Repositories/BasicsRepositories.cs
Normal file
@@ -0,0 +1,197 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BarCode.Web.Core.Dto.SingleData;
|
||||
using BarCode.Web.Core.Internal.Results;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Domain.Values;
|
||||
using BarCode.Web.Domain.Values.Single;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
using System.ComponentModel.Design;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础数据
|
||||
/// </summary>
|
||||
public class BasicsRepositories : IBasicsRepositories
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private RepositoryDbContext _context;
|
||||
private readonly ILoginRepositories _loginService;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
|
||||
public BasicsRepositories(RepositoryDbContext context, IMapper mapper, IServiceProvider serviceProvider,
|
||||
ILoginRepositories loginService, ISingleDataService singleDataService,
|
||||
IMemoryCache memoryCache)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_serviceProvider = serviceProvider;
|
||||
_loginService = loginService;
|
||||
_singleDataService = singleDataService;
|
||||
_memoryCache = memoryCache;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取所有人员
|
||||
/// </summary>
|
||||
/// <param name="CompanyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<SysStaffResponse>> GetStaffListAsync(int CompanyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<SysStaffResponse>, SingleDataRequest>
|
||||
(new SingleDataRequest(CompanyId),
|
||||
SysConfigAction.GetStaffByCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<UcStockResponse>> GetSubUcStockAsync(int stockId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<UcStockResponse>, SubStockRequest>
|
||||
(new SubStockRequest(stockId),
|
||||
SysConfigAction.GetChildWarehouseByPid);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<UcSubStockResponse>> GetSubUcStockAsync(string systemCode, string name, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<UcSubStockResponse>, SystemCodeRequest>
|
||||
(new SystemCodeRequest(systemCode, name, companyId),
|
||||
SysConfigAction.GetWmsSubWarehouseBySystemCodeAndNameAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取仓位详情:根据仓位ID和公司ID
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="companyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<UcSubStockResponse> GetSubUcStockAsync(int id, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<Result<UcSubStockResponse>, IdRequest>
|
||||
(new IdRequest(id, companyId),
|
||||
SysConfigAction.GetWmsSubWarehouseByIdAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取仓位集合:根据仓位ID集合和公司ID
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="companyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<UcSubStockResponse>> GetSubUcStockAsync(List<int> ids, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<UcSubStockResponse>, IdsRequest>
|
||||
(new IdsRequest(ids, companyId),
|
||||
SysConfigAction.GetWmsSubWarehouseByIdsAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取仓位详情:根据仓位编码和公司ID
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="companyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<UcSubStockResponse> GetSubUcStockAsync(string code, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<Result<UcSubStockResponse>, CodeRequest>
|
||||
(new CodeRequest(code, companyId),
|
||||
SysConfigAction.GetWmsSubWarehouseByCodeAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取仓位集合:根据仓位编码集合和公司ID
|
||||
/// </summary>
|
||||
/// <param name="codes"></param>
|
||||
/// <param name="companyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<UcSubStockResponse>> GetSubUcStockAsync(List<string> codes, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<UcSubStockResponse>, CodesRequest>
|
||||
(new CodesRequest(codes, companyId),
|
||||
SysConfigAction.GetWmsSubWarehouseByCodesAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
public async Task<List<UcStockResponse>> GetUcStockAsync(string systemCode, string name, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<UcStockResponse>, SystemCodeRequest>
|
||||
(new SystemCodeRequest(systemCode, name, companyId),
|
||||
SysConfigAction.GetWmsWarehouseBySystemCodeAndNameAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
|
||||
public IDbContextTransaction GetTransaction()
|
||||
{
|
||||
return _context.Database.BeginTransaction();
|
||||
}
|
||||
|
||||
public bool CommitTransaction(bool isRollback, IDbContextTransaction transaction)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (transaction == null)
|
||||
return true;
|
||||
|
||||
if (isRollback)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据用户名精确匹配用户
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public Task<List<int>> GetUserIdsAsync(string name, int companyId)
|
||||
{
|
||||
var cache_key = SingleAction.Users + "_" + companyId + "_IdGetName";
|
||||
var dic = _memoryCache.Get<Dictionary<int, string>>(cache_key);
|
||||
if (dic == null)
|
||||
{
|
||||
var str = _singleDataService.GetSingleData(SingleAction.Users, companyId, 0);
|
||||
dic = _memoryCache.Get<Dictionary<int, string>>(cache_key);
|
||||
if (dic == null)
|
||||
return Task.FromResult(new List<int>());
|
||||
}
|
||||
|
||||
var v = from d in dic where d.Value.Equals(name) select d;
|
||||
return Task.FromResult(v.Select(s => s.Key).ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user