86 lines
2.9 KiB
C#
86 lines
2.9 KiB
C#
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.BasicData.Interfaces;
|
|
using Tnb.WarehouseMgr.Entities.Enums;
|
|
|
|
namespace Tnb.BasicData
|
|
{
|
|
/// <summary>
|
|
/// 库位资料服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
public class BasLocationService : IBasLocationService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
public BasLocationService(ISqlSugarRepository<BasLocation> repository)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
}
|
|
/// <summary>
|
|
/// 获取非存储库位载具列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<dynamic> GetUnStoreLocationListByCarryId([FromRoute] string carryId)
|
|
{
|
|
|
|
List<BasLocation> items = await _db.Queryable<BasLocation>().Where(it => !string.IsNullOrEmpty(it.is_type) && Convert.ToInt32(it.is_type) != (int)EnumLocationType.存储库位).ToListAsync();
|
|
return items;
|
|
}
|
|
|
|
|
|
public async Task<List<BasLocation>> GetLocationInfobyIds(IEnumerable<string> locIds)
|
|
{
|
|
if (locIds == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(locIds));
|
|
}
|
|
|
|
if (!locIds.Any())
|
|
{
|
|
throw new ArithmeticException($"parameter locIds.Count is not be empty");
|
|
}
|
|
|
|
List<BasLocation> items = await _db.Queryable<BasLocation>().Where(it => locIds.Contains(it.id)).ToListAsync();
|
|
return items;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 根据库位编码,清空库位
|
|
/// </summary>
|
|
/// <param name="dic"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<string> ModifyClearLocation(Dictionary<string,string> dic)
|
|
{
|
|
try
|
|
{
|
|
var location_code = dic["code"].ToString();
|
|
if (string.IsNullOrEmpty(location_code))
|
|
throw Oops.Bah("库位编码不能为空");
|
|
|
|
var location = await _db.Queryable<BasLocation>().Where(r => r.location_code == location_code).FirstAsync();
|
|
if (location == null)
|
|
throw Oops.Bah($"库位编号{location_code}不存在");
|
|
await _db.Ado.BeginTranAsync();
|
|
//把状态改为空闲
|
|
await _db.Updateable<BasLocation>().SetColumns(r => r.is_use == "0").Where(r=>r.id==location.id).ExecuteCommandAsync();
|
|
await _db.Ado.CommitTranAsync();
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
await _db.Ado.RollbackTranAsync();
|
|
throw Oops.Bah(e.Message);
|
|
}
|
|
return "成功";
|
|
}
|
|
}
|
|
}
|