Files
WMS-Api/src/WMS.Web.Repositories/BasicsRepositories.cs
tongfei d63f2320e0 test
2023-11-06 16:56:23 +08:00

112 lines
3.9 KiB
C#

using AutoMapper;
using Microsoft.EntityFrameworkCore.Storage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WMS.Web.Core.Dto.SingleData;
using WMS.Web.Core.Internal.Results;
using WMS.Web.Domain.Infrastructure;
using WMS.Web.Domain.IService.Public;
using WMS.Web.Domain.Values;
using WMS.Web.Domain.Values.Single;
using WMS.Web.Repositories.Configuration;
namespace WMS.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;
public BasicsRepositories(RepositoryDbContext context, IMapper mapper, IServiceProvider serviceProvider,
ILoginRepositories loginService, ISingleDataService singleDataService)
{
_context = context;
_mapper = mapper;
_serviceProvider = serviceProvider;
_loginService = loginService;
_singleDataService = singleDataService;
}
/// <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();
}
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;
}
}
}