添加项目文件。
This commit is contained in:
180
src/BarCode.Web.Api/Controllers/SysConfigController.cs
Normal file
180
src/BarCode.Web.Api/Controllers/SysConfigController.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
using AutoMapper;
|
||||
using BarCode.Web.Core.Dto.Erp;
|
||||
using BarCode.Web.Core.Dto.Erp.Org;
|
||||
using BarCode.Web.Core.Dto.Erp.Supplier;
|
||||
using BarCode.Web.Core.Dto.Login;
|
||||
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.Options;
|
||||
using BarCode.Web.Domain.Values;
|
||||
using BarCode.Web.Domain.Values.Single;
|
||||
using BarCode.Web.Repositories;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NPOI.POIFS.FileSystem;
|
||||
using System.ComponentModel.Design;
|
||||
|
||||
namespace BarCode.Web.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统配置
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class SysConfigController : ControllerBase
|
||||
{
|
||||
private readonly ILoginService _loginService;
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
private readonly IErpService _erpService;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
|
||||
private readonly ILogger<SysConfigController> _logger;
|
||||
private ErpOptions _erpOptions;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
|
||||
public SysConfigController(ILoginService loginService, IBasicsRepositories basicsRepositories, IOptions<ErpOptions> erpOptions, IErpService erpService, ISingleDataService singleDataService, IMemoryCache memoryCache,
|
||||
IMapper mapper, IErpBasicDataExtendService erpBasicDataExtendService,
|
||||
ILogger<SysConfigController> logger)
|
||||
{
|
||||
this._erpOptions = erpOptions?.Value;
|
||||
this._memoryCache = memoryCache;
|
||||
_loginService = loginService;
|
||||
_basicsRepositories = basicsRepositories;
|
||||
_erpService = erpService;
|
||||
_singleDataService = singleDataService;
|
||||
_mapper = mapper;
|
||||
_erpBasicDataExtendService = erpBasicDataExtendService;
|
||||
_logger = logger;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取物料;通过规格型号
|
||||
/// </summary>
|
||||
/// <param name="speci"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("GetMaterialList")]
|
||||
public async Task<ResultList<ErpMaterialDto>> GetMaterialList([FromQuery] string speci)
|
||||
{
|
||||
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
||||
if (loginInfo == null || loginInfo.UserInfo == null)
|
||||
return ResultList<ErpMaterialDto>.ReFailure(ResultCodes.Token_Invalid_Error);
|
||||
|
||||
var materials = _memoryCache.Get<List<ErpMaterialDto>>(_erpOptions.cache_materail_key);
|
||||
if (materials == null)
|
||||
{
|
||||
var res = await _erpService.BillQueryForMaterial();
|
||||
if (res.IsSuccess)
|
||||
materials = res.Data.ToList();
|
||||
}
|
||||
if (materials == null) return ResultList<ErpMaterialDto>.ReFailure(ResultCodes.MateriaNoData);
|
||||
//没有物料Id 32进制的也过滤掉
|
||||
var result = materials.Where(x => x.Specifications.Contains(speci)
|
||||
&& !string.IsNullOrEmpty(x.IdConvertBar.Trim())).Take(30).ToList();
|
||||
return ResultList<ErpMaterialDto>.ReSuccess(result);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取供应商-erp基础数据
|
||||
/// 使用code做键
|
||||
/// </summary>
|
||||
/// <param name="name">供应商名字</param>
|
||||
/// <param name="orgCode">组织编码</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("GetSupplierOrOrg")]
|
||||
public async Task<ResultList<PullDownStrResponse>> GetSupplierOrOrg([FromQuery] string? name, [FromQuery] string orgCode)
|
||||
{
|
||||
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
||||
if (loginInfo == null)
|
||||
return ResultList<PullDownStrResponse>.ReFailure(ResultCodes.Token_Invalid_Error);
|
||||
|
||||
var result = await _singleDataService.GetSingleDataNoCache<ResultList<SingleDataResponse>, NameRequest, SysConfigAction>(
|
||||
new NameRequest(name, loginInfo.UserInfo.CompanyId), SysConfigAction.GetSupplierByNameAndCompany, SingleControllerType.SysConfig);
|
||||
if (!result.IsSuccess)
|
||||
return ResultList<PullDownStrResponse>.ReFailure(result.Message, result.Status);
|
||||
|
||||
List<SingleDataResponse> suppliers = result.Data.ToList();
|
||||
//suppliers = suppliers.Where(w => w.ErpOrgCode.Equals(orgCode)).ToList();
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
suppliers = suppliers.Where(w => w.Name.Contains(name)).ToList();
|
||||
List<PullDownStrResponse> pullList = new List<PullDownStrResponse>();
|
||||
foreach (var c in suppliers)
|
||||
{
|
||||
pullList.Add(new PullDownStrResponse()
|
||||
{
|
||||
Id = "s_" + c.Id.ToString(),
|
||||
Name = c.Name,
|
||||
Code = "s_" + c.Code
|
||||
});
|
||||
}
|
||||
|
||||
//var org_result = await _erpService.BillQueryForOrg();
|
||||
//List<ErpOrgDto> orgs = org_result.Data.ToList();
|
||||
//if (!string.IsNullOrEmpty(name))
|
||||
// orgs = orgs.Where(w => w.Name.Contains(name)).ToList();
|
||||
//foreach (var c in orgs)
|
||||
//{
|
||||
// pullList.Add(new PullDownStrResponse()
|
||||
// {
|
||||
// Id = "o_" + c.Id.ToString(),
|
||||
// Name = c.Name,
|
||||
// Code = "o_" + c.Number
|
||||
// });
|
||||
//}
|
||||
|
||||
return ResultList<PullDownStrResponse>.ReSuccess(pullList);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取组织-erp基础数据
|
||||
/// 使用 code做键
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("GetOrg")]
|
||||
public async Task<ResultList<PullDownStrResponse>> GetOrg([FromQuery] string? name)
|
||||
{
|
||||
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
||||
if (loginInfo == null)
|
||||
return ResultList<PullDownStrResponse>.ReFailure(ResultCodes.Token_Invalid_Error);
|
||||
|
||||
List<PullDownStrResponse> pullList = new List<PullDownStrResponse>();
|
||||
|
||||
if (loginInfo.UserInfo.Identity == 2)
|
||||
{
|
||||
pullList.Add(new PullDownStrResponse()
|
||||
{
|
||||
Id = loginInfo.UserInfo.SupplierId.ToString(),
|
||||
Name = loginInfo.UserInfo.SupplierName,
|
||||
Code = "s_" + loginInfo.UserInfo.SupplierCode,
|
||||
IsDefault = true
|
||||
}); ;
|
||||
return ResultList<PullDownStrResponse>.ReSuccess(pullList);
|
||||
}
|
||||
var result = await _singleDataService.GetSingleDataNoCache<ResultList<OrgAllResponse>, UserRequest, SysConfigAction>(
|
||||
new UserRequest(loginInfo.UserInfo.UcId), SysConfigAction.GetOrgByUser, SingleControllerType.SysConfig);
|
||||
if (!result.IsSuccess)
|
||||
return ResultList<PullDownStrResponse>.ReFailure(result.Message, result.Status);
|
||||
|
||||
List<OrgAllResponse> orgs = result.Data.ToList();
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
orgs = orgs.Where(w => w.Name.Contains(name)).ToList();
|
||||
foreach (var c in orgs)
|
||||
{
|
||||
pullList.Add(new PullDownStrResponse()
|
||||
{
|
||||
Id = c.Id.ToString(),
|
||||
Name = c.Name,
|
||||
Code = "o_" + c.ErpOrgCode
|
||||
});
|
||||
}
|
||||
//默认显示第一个
|
||||
pullList.First().IsDefault = true;
|
||||
|
||||
return ResultList<PullDownStrResponse>.ReSuccess(pullList);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user